Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+299
View File
@@ -0,0 +1,299 @@
/**@license
*
* favloader v. 0.4.4
*
* Vanilla JavaScript library for loading animation in favicon
*
* Copyright (c) 2018-2019 Jakub T. Jankiewicz <https://jcubic.pl/me>
* Released under the MIT license
*
* Build: Sat, 22 May 2021 11:37:31 +0000
*/
/* global define, module, global, Worker, Blob, BlobBuilder, setTimeout, parseGIF */
(function(factory) {
var root = typeof window !== 'undefined' ? window : global;
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
// istanbul ignore next
define([], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = factory();
} else {
// Browser
// istanbul ignore next
root.favloader = factory();
}
})(function(undefined) {
// we use web worker to trigger interval since browser main thread is limited
// when tab is not active
function fworker(fn) {
// ref: https://stackoverflow.com/a/10372280/387194
var str = '(' + fn.toString() + ')()';
var URL = window.URL || window.webkitURL;
var blob;
try {
blob = new Blob([str], {type: 'application/javascript'});
} catch (e) { // Backwards-compatibility
window.BlobBuilder = window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder;
blob = new BlobBuilder();
blob.append(str);
blob = blob.getBlob();
}
return new Worker(URL.createObjectURL(blob));
}
// ----------------------------------------------------------------------------------
var interval = (function() {
var worker = fworker(function() {
// rAF polyfil without setTimeout, ref: https://gist.github.com/paulirish/1579671
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !self.requestAnimationFrame; ++x) {
self.requestAnimationFrame = self[vendors[x]+'RequestAnimationFrame'];
self.cancelAnimationFrame = self[vendors[x]+'CancelAnimationFrame']
|| self[vendors[x]+'CancelRequestAnimationFrame'];
}
var raf = {};
self.addEventListener('message', function(response) {
var data = response.data;
var id = data.id;
if (data.type !== 'RPC' || id === null) {
return;
}
if (data.method == 'setInterval') {
var interval_id = data.params[0];
if (typeof interval_id === 'number') {
raf[interval_id] = self.setInterval(function() {
self.postMessage({ type: 'interval', id: interval_id });
}, data.params[1]);
self.postMessage({ type: 'RPC', id: id, result: interval_id });
} else {
self.postMessage({
type: 'RPC',
id: id,
result: null,
error: 'Invalid Argument, expected number'
});
}
} else if (data.method == 'clearInterval') {
self.clearInterval(raf[data.params[0]]);
delete raf[data.params[0]];
}
});
});
var callbacks = {};
var rpc = (function() {
var id = 0;
return function rpc(method, params) {
var _id = ++id;
return new Promise(function(resolve, reject) {
worker.addEventListener('message', function handler(response) {
var data = response.data;
if (data && data.type === 'RPC' && data.id === _id) {
if (data.error) {
reject(data.error);
} else {
resolve(data.result);
}
worker.removeEventListener('message', handler);
}
});
worker.postMessage({ type: 'RPC', method: method, id: _id, params: params });
});
};
})();
worker.addEventListener('message', function(response) {
var data = response.data;
if (data && data.type === 'interval' && callbacks[data.id]) {
callbacks[data.id]();
}
});
return {
set: function(fn, interval) {
var interval_id = Date.now();
callbacks[interval_id] = fn;
rpc('setInterval', [interval_id, interval]);
return interval_id;
},
clear: function(id) {
delete callbacks[id];
return rpc('clearInterval', [id]);
}
};
})();
// ----------------------------------------------------------------------------------
var hidden, visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
// ----------------------------------------------------------------------------------
function warn(message) {
if (console && console.warn) {
console.warn(message);
} else {
setTimeout(function() {
throw new Error(message);
}, 0);
}
}
// ----------------------------------------------------------------------------------
var ctx,
c,
link,
icon,
id,
progress = 0,
duration,
initialized,
settings,
gif,
type,
initial_turns = -.25,
interval_id,
step;
// ----------------------------------------------------------------------------------
function init(options) {
if (document.readyState !== "complete") {
setTimeout(init.bind(this, options), 100);
return;
}
settings = Object.assign({
size: 16,
radius: 6,
thickness: 2,
color: '#0F60A8',
duration: 5000
}, options);
if (!link) {
link = document.querySelector('link[rel*="icon"]');
if (!link) {
link = document.createElement('link');
link.setAttribute('rel', 'icon');
document.head.appendChild(link);
warn("No default icon found, restore state will not work");
} else {
icon = link.getAttribute('href');
type = link.getAttribute('type');
}
}
clear();
if (settings.gif) {
if (typeof parseGIF === 'undefined') {
throw new Error('parseGIF not defined, please include parseGIF.js file');
}
parseGIF(settings.gif).then(function(data) {
gif = data;
});
} else {
if (!c) {
c = document.createElement('canvas');
}
c.width = c.height = settings.size;
ctx = c.getContext('2d');
ctx.lineCap = "round";
ctx.lineWidth = settings.thickness;
ctx.strokeStyle = settings.color;
duration = settings.duration;
}
initialized = true;
}
// ----------------------------------------------------------------------------------
function clear() {
if (interval_id) {
interval.clear(interval_id);
interval_id = null;
}
}
// ----------------------------------------------------------------------------------
function restore() {
if (icon) {
link.setAttribute('href', icon + '?' + Date.now());
link.setAttribute('type', type);
} else if (link) {
link.parentNode.removeChild(link);
}
clear();
}
// ----------------------------------------------------------------------------------
function animate() {
if (!initialized) {
setTimeout(animate, 100);
return;
}
if (interval_id) {
return;
}
progress = 0;
if (settings.gif && parseGIF) {
if (!gif) {
setTimeout(animate, 100);
return;
}
interval_id = interval.set(animateGIF, 300);
} else {
interval_id = interval.set(draw, 300);
}
}
// ----------------------------------------------------------------------------------
function turn(x) {
return (x + initial_turns) * 2 * Math.PI;
}
// ----------------------------------------------------------------------------------
function animateGIF() {
progress++;
if (progress >= gif.uris.length) {
progress = 0;
}
update(gif.uris[progress]);
}
// ----------------------------------------------------------------------------------
function arcStart(pos) {
return turn(pos + initial_turns) + turn(Math.max(0, pos * 2 - 1));
}
// ----------------------------------------------------------------------------------
function arcEnd(pos) {
return turn(pos + initial_turns) + turn(Math.min(1, pos * 2));
}
// ----------------------------------------------------------------------------------
function update(dataURI) {
var newIcon, icon = document.querySelector('link[rel*="icon"]');
(newIcon = icon.cloneNode(true)).setAttribute('href', dataURI);
icon.parentNode.replaceChild(newIcon, icon);
link = newIcon;
}
// ----------------------------------------------------------------------------------
function draw() {
ctx.clearRect(0, 0, settings.size, settings.size);
if (typeof settings.frame === 'function') {
settings.frame(ctx);
} else {
var position = progress % duration / duration;
ctx.beginPath();
var center = Math.round(settings.size / 2);
ctx.arc(center, center, settings.radius, arcStart(position), arcEnd(position));
ctx.stroke();
}
update(ctx.canvas.toDataURL());
progress += duration / 100;
}
// ----------------------------------------------------------------------------------
return {
init: init,
start: animate,
stop: restore,
version: '0.4.4'
};
});
@@ -0,0 +1 @@
(function(e){var t=typeof window!=="undefined"?window:global;if(typeof define==="function"&&define.amd){define([],e)}else if(typeof module==="object"&&module.exports){module.exports=e()}else{t.parseGIF=e()}})(function(e){var c=function(e){return e.reduce(function(e,t){return e*2+t},0)};var f=function(e){var t=[];for(var r=7;r>=0;r--){t.push(!!(e&1<<r))}return t};var n=function(e){this.data=e;this.len=this.data.length;this.pos=0;this.readByte=function(){if(this.pos>=this.data.length){throw new Error("Attempted to read past end of stream.")}return e.charCodeAt(this.pos++)&255};this.readBytes=function(e){var t=[];for(var r=0;r<e;r++){t.push(this.readByte())}return t};this.read=function(e){var t="";for(var r=0;r<e;r++){t+=String.fromCharCode(this.readByte())}return t};this.readUnsigned=function(){var e=this.readBytes(2);return(e[1]<<8)+e[0]}};var u=function(t,a){var n=0;var e=function(e){var t=0;for(var r=0;r<e;r++){if(a.charCodeAt(n>>3)&1<<(n&7)){t|=1<<r}n++}return t};var r=[];var i=1<<t;var o=i+1;var s=t+1;var d=[];var c=function(){d=[];s=t+1;for(var e=0;e<i;e++){d[e]=[e]}d[i]=[];d[o]=null};var f;var u;while(true){u=f;f=e(s);if(f===i){c();continue}if(f===o)break;if(f<d.length){if(u!==i){d.push(d[u].concat(d[f][0]))}}else{if(f!==d.length)throw new Error("Invalid LZW code.");d.push(d[u].concat(d[u][0]))}r.push.apply(r,d[f]);if(d.length===1<<s&&s<12){s++}}return r};var i=function(o,s){s||(s={});var n=function(e){var t=[];for(var r=0;r<e;r++){t.push(o.readBytes(3))}return t};var d=function(){var e,t;t="";do{e=o.readByte();t+=o.read(e)}while(e!==0);return t};var e=function(){var e={};e.sig=o.read(3);e.ver=o.read(3);if(e.sig!=="GIF")throw new Error("Not a GIF file.");e.width=o.readUnsigned();e.height=o.readUnsigned();var t=f(o.readByte());e.gctFlag=t.shift();e.colorRes=c(t.splice(0,3));e.sorted=t.shift();e.gctSize=c(t.splice(0,3));e.bgColor=o.readByte();e.pixelAspectRatio=o.readByte();if(e.gctFlag){e.gct=n(1<<e.gctSize+1)}s.hdr&&s.hdr(e)};var t=function(e){var t=function(e){var t=o.readByte();var r=f(o.readByte());e.reserved=r.splice(0,3);e.disposalMethod=c(r.splice(0,3));e.userInput=r.shift();e.transparencyGiven=r.shift();e.delayTime=o.readUnsigned();e.transparencyIndex=o.readByte();e.terminator=o.readByte();s.gce&&s.gce(e)};var r=function(e){e.comment=d();s.com&&s.com(e)};var a=function(e){var t=o.readByte();e.ptHeader=o.readBytes(12);e.ptData=d();s.pte&&s.pte(e)};var n=function(e){var t=function(e){var t=o.readByte();e.unknown=o.readByte();e.iterations=o.readUnsigned();e.terminator=o.readByte();s.app&&s.app.NETSCAPE&&s.app.NETSCAPE(e)};var r=function(e){e.appData=d();s.app&&s.app[e.identifier]&&s.app[e.identifier](e)};var a=o.readByte();e.identifier=o.read(8);e.authCode=o.read(3);switch(e.identifier){case"NETSCAPE":t(e);break;default:r(e);break}};var i=function(e){e.data=d();s.unknown&&s.unknown(e)};e.label=o.readByte();switch(e.label){case 249:e.extType="gce";t(e);break;case 254:e.extType="com";r(e);break;case 1:e.extType="pte";a(e);break;case 255:e.extType="app";n(e);break;default:e.extType="unknown";i(e);break}};var r=function(e){var t=function(a,n){var i=new Array(a.length);var e=a.length/n;var t=function(e,t){var r=a.slice(t*n,(t+1)*n);i.splice.apply(i,[e*n,n].concat(r))};var r=[0,4,2,1];var o=[8,8,4,2];var s=0;for(var d=0;d<4;d++){for(var c=r[d];c<e;c+=o[d]){t(c,s);s++}}return i};e.leftPos=o.readUnsigned();e.topPos=o.readUnsigned();e.width=o.readUnsigned();e.height=o.readUnsigned();var r=f(o.readByte());e.lctFlag=r.shift();e.interlaced=r.shift();e.sorted=r.shift();e.reserved=r.splice(0,2);e.lctSize=c(r.splice(0,3));if(e.lctFlag){e.lct=n(1<<e.lctSize+1)}e.lzwMinCodeSize=o.readByte();var a=d();e.pixels=u(e.lzwMinCodeSize,a);if(e.interlaced){e.pixels=t(e.pixels,e.width)}s.img&&s.img(e)};var a=function(){var e={};e.sentinel=o.readByte();switch(String.fromCharCode(e.sentinel)){case"!":e.type="ext";t(e);break;case",":e.type="img";r(e);break;case";":e.type="eof";s.eof&&s.eof(e);break;default:throw new Error("Unknown block: 0x"+e.sentinel.toString(16))}if(e.type!=="eof")setTimeout(a,0)};var i=function(){e();setTimeout(a,0)};i()};function o(a){return new Promise(function(t,e){var r=new XMLHttpRequest;r.overrideMimeType("text/plain; charset=x-user-defined");r.onload=function(e){t(new n(r.responseText))};r.onerror=e;r.open("GET",a,true);r.send()})}function s(t,e){var r=document.createElement("canvas");r.setAttribute("width",e[0].width);r.setAttribute("height",e[0].height);var i=r.getContext("2d");var o=[];e.forEach(function(r,e){i.clearRect(r.leftPos,r.topPos,r.width,r.height);var a=i.getImageData(r.leftPos,r.topPos,r.width,r.height);var n=r.lctFlag?r.lct:t.gtc;r.pixels.forEach(function(e,t){if(r.transparency!==e){a.data[t*4+0]=n[e][0];a.data[t*4+1]=n[e][1];a.data[t*4+2]=n[e][2];a.data[t*4+3]=255}else{if(r.disposalMethod===2||r.disposalMethod===3){a.data[t*4+3]=0}else{}}});i.putImageData(a,r.leftPos,r.topPos);o.push(i.canvas.toDataURL())});return o}return function(e){return new Promise(function(t){var r={};var a=[];Line truncated