compressed-script-loader 1.0.3 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -1
- package/compressed-script-loader.d.ts +13 -1
- package/package.json +1 -1
- package/umd/index.js +10 -10
- package/webpack/index.js +9 -9
- package/webpack-esm/index.mjs +9 -9
package/README.md
CHANGED
|
@@ -1,3 +1,130 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# compressed-script-loader
|
|
2
4
|
|
|
3
|
-
+ Use code with comment extraction
|
|
5
|
+
+ Use code with comment extraction feature added to `unzipSync` of `fflate`.
|
|
6
|
+
|
|
7
|
+
## Use for SPA
|
|
8
|
+
|
|
9
|
+
> Load automatically
|
|
10
|
+
|
|
11
|
+
+ Specifying config in the `data-csl-config` attribute of the `script` element
|
|
12
|
+
will automatically load the zip file and insert it as a `script` element in the header section of the html page.
|
|
13
|
+
|
|
14
|
+
```html
|
|
15
|
+
<script>
|
|
16
|
+
let onLoadDone = () => {
|
|
17
|
+
onLoadDone = void 0;
|
|
18
|
+
runEVEWorld(() => {
|
|
19
|
+
window.setTimeout(() => {
|
|
20
|
+
document.querySelectorAll("script[src^='./loader/'],script[src*='compressed-script-loader']").forEach(script => script.remove());
|
|
21
|
+
delete window.NsLoader;
|
|
22
|
+
}, 1000);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
</script>
|
|
26
|
+
<script
|
|
27
|
+
data-csl-config='{
|
|
28
|
+
"base": "./libs",
|
|
29
|
+
"selector": "script[src*=css-2d-renderer]",
|
|
30
|
+
"load": [
|
|
31
|
+
"system-coordinate-map-mini"
|
|
32
|
+
],
|
|
33
|
+
"callback": "onLoadDone"
|
|
34
|
+
}'
|
|
35
|
+
type="text/javascript"
|
|
36
|
+
src="https://cdn.jsdelivr.net/npm/compressed-script-loader@latest/umd/index.js"
|
|
37
|
+
></script>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
> Load manually
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<script src="https://cdn.jsdelivr.net/npm/compressed-script-loader@latest/umd/index.js"></script>
|
|
44
|
+
<script>
|
|
45
|
+
(async () => {
|
|
46
|
+
const SCRIPT_BASENAME = "system-coordinate-map-mini";
|
|
47
|
+
NsLoader.setConfig("./libs", "script[src*=css-2d-renderer]");
|
|
48
|
+
await NsLoader.loadCompressedScript(SCRIPT_BASENAME);
|
|
49
|
+
NsLoader.cleanUp();
|
|
50
|
+
runEVEWorld(() => {
|
|
51
|
+
window.setTimeout(() => {
|
|
52
|
+
document.querySelectorAll("script[src^='./loader/'],script[src*='compressed-script-loader']").forEach(script => script.remove());
|
|
53
|
+
delete window.NsLoader;
|
|
54
|
+
}, 1000);
|
|
55
|
+
});
|
|
56
|
+
})();
|
|
57
|
+
</script>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
+ Config definition
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
/**
|
|
64
|
+
* @version 1.0
|
|
65
|
+
*/
|
|
66
|
+
export type TCSLLoaderConfig = {
|
|
67
|
+
/**
|
|
68
|
+
* Specifies the directory that contains the zip file
|
|
69
|
+
*
|
|
70
|
+
* ```js
|
|
71
|
+
* base: "./lib" // or https://example.com/lib
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
base: string;
|
|
75
|
+
/**
|
|
76
|
+
* #### Insertion selector
|
|
77
|
+
*
|
|
78
|
+
* + can be omit. In the current specification, specify element inside `head`
|
|
79
|
+
* element to insert into` head` element.
|
|
80
|
+
*
|
|
81
|
+
* + If omitted, it will be inserted after `document.head.lastElementChild`
|
|
82
|
+
*
|
|
83
|
+
* NOTE: This will change in the near future
|
|
84
|
+
*
|
|
85
|
+
* ```js
|
|
86
|
+
* selector: "script[src*=css-2d-renderer]"
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
selector?: string;
|
|
90
|
+
/**
|
|
91
|
+
* list of zip files you want to load
|
|
92
|
+
*
|
|
93
|
+
* + The comment attached to the zip file entry is used for `script.integrity`
|
|
94
|
+
*
|
|
95
|
+
* NOTE: Omit the `.zip` extension
|
|
96
|
+
*
|
|
97
|
+
* ```js
|
|
98
|
+
* // actually, "system-coordinate-map-mini.zip", "bundle.zip"
|
|
99
|
+
* load: ["system-coordinate-map-mini", "bundle"]
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
load: string[];
|
|
103
|
+
/**
|
|
104
|
+
* can be omit, default: "cslCallback"
|
|
105
|
+
*
|
|
106
|
+
* Please specify if you need to use another name
|
|
107
|
+
*
|
|
108
|
+
* ```js
|
|
109
|
+
* const cslCallback = () => {
|
|
110
|
+
* runEVEWorld(() => {
|
|
111
|
+
* window.setTimeout(() => {
|
|
112
|
+
* document.querySelectorAll("script[src^='./loader/'],script[src*='compressed-script-loader']").forEach(script => script.remove());
|
|
113
|
+
* delete window.NsLoader;
|
|
114
|
+
* }, 1000);
|
|
115
|
+
* });
|
|
116
|
+
* };
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
callback?: keyof Window;
|
|
120
|
+
};
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
> ## Authors
|
|
124
|
+
|
|
125
|
+
- **jeffy-g** - [jeffy-g](https://github.com/jeffy-g)
|
|
126
|
+
|
|
127
|
+
> ## License
|
|
128
|
+
|
|
129
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
|
|
130
|
+
|
|
@@ -6,8 +6,20 @@
|
|
|
6
6
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
8
|
import * as Uz from "./unzip-sync";
|
|
9
|
+
declare global {
|
|
10
|
+
const cslCallback: () => void;
|
|
11
|
+
interface Window {
|
|
12
|
+
cslCallback: () => void;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare type TCSLLoaderConfig = {
|
|
16
|
+
base: string;
|
|
17
|
+
selector?: string;
|
|
18
|
+
load: string[];
|
|
19
|
+
callback?: keyof Window;
|
|
20
|
+
};
|
|
9
21
|
declare let unzipSync: typeof Uz.unzipSync;
|
|
10
22
|
declare let cleanUp: () => void;
|
|
11
|
-
declare let setConfig: (base: string,
|
|
23
|
+
declare let setConfig: (base: string, insertionSelector?: string | undefined) => void;
|
|
12
24
|
declare let loadCompressedScript: (baseName: string, log?: (msg: string) => void) => Promise<void>;
|
|
13
25
|
export { setConfig, loadCompressedScript, cleanUp, unzipSync };
|
package/package.json
CHANGED
package/umd/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){'object'==typeof exports&&'object'==typeof module?module.exports=t():'function'==typeof define&&define.amd?define([],t):'object'==typeof exports?exports.NsLoader=t():e.NsLoader=t()}(globalThis,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{'undefined'!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(e,'__esModule',{value:!0})}},t={};e.r(t),e.d(t,{cleanUp:()=>
|
|
3
|
-
;const n=Uint8Array,o=Uint16Array,r=Uint32Array,c=new n([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),s=new n([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),
|
|
4
|
-
;if(n){
|
|
5
|
-
;return s.set(e.subarray(t,c)),s},C=['unexpected EOF','invalid block type','invalid length/literal','invalid distance','stream finished','no stream handler',,'no callback','invalid UTF-8 data','extra field too long','date not in range 1980-2099','filename too long','stream finishing','invalid zip data'],
|
|
6
|
-
;return[T(e,t+10),a,
|
|
7
|
-
;return n.length&&
|
|
8
|
-
let n=0,r=0;for(16==o?(r=3+S(e,h,3),h+=2,n=c[t-1]):17==o?(r=3+S(e,h,7),h+=3):18==o&&(r=11+S(e,h,127),h+=7);r--;)c[t++]=n}}const d=c.subarray(0,t),u=c.subarray(t);
|
|
9
|
-
;return
|
|
10
|
-
;
|
|
11
|
-
}}));if(
|
|
2
|
+
!function(e,t){'object'==typeof exports&&'object'==typeof module?module.exports=t():'function'==typeof define&&define.amd?define([],t):'object'==typeof exports?exports.NsLoader=t():e.NsLoader=t()}(globalThis,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{'undefined'!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(e,'__esModule',{value:!0})}},t={};e.r(t),e.d(t,{cleanUp:()=>B,loadCompressedScript:()=>F,setConfig:()=>q,unzipSync:()=>A})
|
|
3
|
+
;const n=Uint8Array,o=Uint16Array,r=Uint32Array,c=new n([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),s=new n([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),l=new n([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),i=(e,t)=>{const n=new o(31);for(let o=0;o<31;++o)n[o]=t+=1<<e[o-1];const c=new r(n[30]);for(let e=1;e<30;++e)for(let t=n[e];t<n[e+1];++t)c[t]=t-n[e]<<5|e;return[n,c]},[a,f]=i(c,2);a[28]=258,f[258]=28;const[d,u]=i(s,0),p=new o(32768);for(let e=0;e<32768;++e){let t=(43690&e)>>>1|(21845&e)<<1;t=(52428&t)>>>2|(13107&t)<<2,t=(61680&t)>>>4|(3855&t)<<4,p[e]=((65280&t)>>>8|(255&t)<<8)>>>1}const g=(e,t,n)=>{const r=e.length;let c=0;const s=new o(t);for(;c<r;++c)e[c]&&++s[e[c]-1];const l=new o(t);for(c=0;c<t;++c)l[c]=l[c-1]+s[c-1]<<1;let i
|
|
4
|
+
;if(n){i=new o(1<<t);const n=15-t;for(c=0;c<r;++c)if(e[c]){const o=c<<4|e[c],r=t-e[c];let s=l[e[c]-1]++<<r;for(const e=s|(1<<r)-1;s<=e;++s)i[p[s]>>>n]=o}}else for(i=new o(r),c=0;c<r;++c)e[c]&&(i[c]=p[l[e[c]-1]++]>>>15-e[c]);return i},h=new n(288);for(let e=0;e<144;++e)h[e]=8;for(let e=144;e<256;++e)h[e]=9;for(let e=256;e<280;++e)h[e]=7;for(let e=280;e<288;++e)h[e]=8;const m=new n(32);for(let e=0;e<32;++e)m[e]=5;const y=g(h,9,1),b=g(m,5,1),w=e=>{let t=e[0];for(let n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},S=(e,t,n)=>{const o=t/8|0;return(e[o]|e[o+1]<<8)>>(7&t)&n},v=(e,t)=>{const n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},E=(e,t,c)=>{(null==t||t<0)&&(t=0),(null==c||c>e.length)&&(c=e.length);const s=new(2==e.BYTES_PER_ELEMENT?o:4==e.BYTES_PER_ELEMENT?r:n)(c-t)
|
|
5
|
+
;return s.set(e.subarray(t,c)),s},C=['unexpected EOF','invalid block type','invalid length/literal','invalid distance','stream finished','no stream handler',,'no callback','invalid UTF-8 data','extra field too long','date not in range 1980-2099','filename too long','stream finishing','invalid zip data'],k=(e,t,n)=>{const o=new Error(t||C[e]);if(o.code=e,Error.captureStackTrace&&Error.captureStackTrace(o,k),!n)throw o;return o},T=(e,t)=>e[t]|e[t+1]<<8,x=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,j=(e,t)=>x(e,t)+4294967296*x(e,t+4),O=(e,t)=>t+30+T(e,t+26)+T(e,t+28),U=(e,t,n)=>{const o=!(2048&T(e,t+8)),r=T(e,t+28),c=P(e.subarray(t+46,t+46+r),o),s=t+46+r,l=x(e,t+20),[i,a,f]=n&&4294967295==l?$(e,s):[l,x(e,t+24),x(e,t+42)],d=s+T(e,t+30)
|
|
6
|
+
;return[T(e,t+10),i,a,c,s+T(e,t+30)+T(e,t+32),f,P(e.subarray(d,d+T(e,t+32)),o)]},$=(e,t)=>{for(;1!=T(e,t);t+=4+T(e,t+2));return[j(e,t+12),j(e,t+4),j(e,t+20)]};let z;const L=new n(0);try{const e=new TextDecoder;e.decode(L,{stream:!0}),z=e}catch(e){}function P(e,t){if(t){let t="";for(let n=0;n<e.length;n+=16384)t+=String.fromCharCode.apply(null,e.subarray(n,n+16384));return t}if(z)return z.decode(e);{const[t,n]=(e=>{for(let t='',n=0;;){let o=e[n++];const r=+(o>127)+ +(o>223)+ +(o>239);if(n+r>e.length)return[t,E(e,n-1)];r?3==r?(o=((15&o)<<18|(63&e[n++])<<12|(63&e[n++])<<6|63&e[n++])-65536,t+=String.fromCharCode(55296|o>>10,56320|1023&o)):t+=1&r?String.fromCharCode((31&o)<<6|63&e[n++]):String.fromCharCode((15&o)<<12|(63&e[n++])<<6|63&e[n++]):t+=String.fromCharCode(o)}})(e)
|
|
7
|
+
;return n.length&&k(8),t}}function M(e,t){return((e,t,o)=>{const r=e.length;if(!r||o&&o.f&&!o.l)return t||new n(0);const i=!t||o,f=!o||o.i;o||(o={}),t||(t=new n(3*r));const u=e=>{let o=t.length;if(e>o){const r=new n(Math.max(2*o,e));r.set(t),t=r}};let p=o.f||0,h=o.p||0,m=o.b||0,C=o.l,T=o.d,x=o.m,j=o.n;const O=8*r;do{if(!C){p=S(e,h,1);const c=S(e,h+1,3);if(h+=3,!c){const n=4+((h+7)/8|0),c=e[n-4]|e[n-3]<<8,s=n+c;if(s>r){f&&k(0);break}i&&u(m+c),t.set(e.subarray(n,s),m),o.b=m+=c,o.p=h=8*s,o.f=p;continue}if(1==c)C=y,T=b,x=9,j=5;else if(2==c){const t=S(e,h,31)+257,o=S(e,h+10,15)+4,r=t+S(e,h+5,31)+1;h+=14;const c=new n(r),s=new n(19);for(let t=0;t<o;++t)s[l[t]]=S(e,h+3*t,7);h+=3*o;const i=w(s),a=(1<<i)-1,f=g(s,i,1);for(let t=0;t<r;){const n=f[S(e,h,a)];h+=15&n;const o=n>>>4;if(o<16)c[t++]=o;else{
|
|
8
|
+
let n=0,r=0;for(16==o?(r=3+S(e,h,3),h+=2,n=c[t-1]):17==o?(r=3+S(e,h,7),h+=3):18==o&&(r=11+S(e,h,127),h+=7);r--;)c[t++]=n}}const d=c.subarray(0,t),u=c.subarray(t);x=w(d),j=w(u),C=g(d,x,1),T=g(u,j,1)}else k(1);if(h>O){f&&k(0);break}}i&&u(m+131072);const E=(1<<x)-1,U=(1<<j)-1;let $=h;for(;;$=h){const n=C[v(e,h)&E],o=n>>>4;if(h+=15&n,h>O){f&&k(0);break}if(n||k(2),o<256)t[m++]=o;else{if(256==o){$=h,C=void 0;break}{let n=o-254;if(o>264){const t=o-257,r=c[t];n=S(e,h,(1<<r)-1)+a[t],h+=r}const r=T[v(e,h)&U],l=r>>>4;r||k(3),h+=15&r;let p=d[l];if(l>3){const t=s[l];p+=v(e,h)&(1<<t)-1,h+=t}if(h>O){f&&k(0);break}i&&u(m+131072);const g=m+n;for(;m<g;m+=4)t[m]=t[m-p],t[m+1]=t[m+1-p],t[m+2]=t[m+2-p],t[m+3]=t[m+3-p];m=g}}}o.l=C,o.p=$,o.b=m,o.f=p,C&&(p=1,o.m=x,o.d=T,o.n=j)}while(!p)
|
|
9
|
+
;return m==t.length?t:E(t,0,m)})(e,t)}let _,N,R=new TextDecoder,A=function(e,t){const o={};let r=e.length-22;for(;101010256!=x(e,r);--r)(!r||e.length-r>65558)&&k(13);let c=T(e,r+8);if(!c)return{};let s=x(e,r+16);const l=4294967295==s;l&&(r=x(e,r-12),101075792!=x(e,r)&&k(13),c=x(e,r+32),s=x(e,r+48));const i=t&&t.filter;for(let t=0;t<c;++t){const[t,r,c,a,f,d,u]=U(e,s,l),p=O(e,d);if(s=f,!i||i({name:a,size:r,originalSize:c,compression:t})){let s;t?8===t?s=M(e.subarray(p,p+r),new n(c)):k(14,'unknown compression type '+t):s=E(e,p,p+r),s&&(o[a]={data:s,comment:u})}}return o},B=()=>{R=void 0,D=q=F=B=void 0,_=N=void 0,A=void 0},q=(e,t)=>{_=e,N=t||""},D=(e,t,n)=>{const o=document.createElement("script"),r=N?document.querySelector(N).nextSibling:document.head.lastElementChild
|
|
10
|
+
;if(document.head.insertBefore(o,r),o.id=t,n){const t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));o.integrity=n,o.src=t}else o.text=e},F=async(e,t=console.log)=>{const n=e+".js",o=await fetch(`${_}/${e}.zip`).then((async e=>{const n=!!e.headers.get("content-encoding"),o=e.body.getReader(),r=(c=+e.headers.get("content-length"),n?1.3*c|0:c);var c;const s=new Uint8Array(r);let l=0;for(;;){const e=await o.read();if(e.done)break;s.set(e.value,l),l+=e.value.length,t(`loading script: ${l.toLocaleString()} bytes(${Math.round(l/r*100)}%)`)}return n?s.slice(0,l):s})).catch((e=>(console.error(e),null)));if(o&&o.length){t(`loaded script ${n}, decompressing binary...`),console.time(`unzip: ${n}`);const e=A(o);console.timeEnd(`unzip: ${n}`),t(`${n} decompressed 😃`);const r=e[n]
|
|
11
|
+
;D(R.decode(r.data,{stream:!1}),n,r.comment)}},Y=()=>{Y=void 0;const e=document.querySelector("script[data-csl-config]");if(e){const t=e.dataset.cslConfig;if(t){const e=JSON.parse(t);q(e.base,e.selector);const n=[];for(const t of e.load)n.push(F(t));try{Promise.all(n).then((()=>{const t=window[e.callback||"cslCallback"];"function"==typeof t&&(t(),B())}))}catch(e){console.error(e)}}}};return setTimeout(Y,333),t})()));
|
package/webpack/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
(()=>{"use strict";var e={d:(t,n)=>{for(var
|
|
3
|
-
;for(let e=1;e<30;++e)for(let t=n[e];t<n[e+1];++t)c[t]=t-n[e]<<5|e;return[n,c]},[i,f]=a(c,2);i[28]=258,f[258]=28;const[d,u]=a(
|
|
4
|
-
;for(let e=280;e<288;++e)
|
|
5
|
-
Error.captureStackTrace&&Error.captureStackTrace(
|
|
6
|
-
const[t,n]=(e=>{for(let t='',n=0;;){let
|
|
7
|
-
f&&k(0);break}a&&u(
|
|
8
|
-
let n=
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{'undefined'!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(e,'__esModule',{value:!0})}},t={};e.r(t),e.d(t,{cleanUp:()=>N,loadCompressedScript:()=>F,setConfig:()=>q,unzipSync:()=>B});const n=Uint8Array,o=Uint16Array,r=Uint32Array,c=new n([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),s=new n([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),l=new n([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),a=(e,t)=>{const n=new o(31);for(let o=0;o<31;++o)n[o]=t+=1<<e[o-1];const c=new r(n[30])
|
|
3
|
+
;for(let e=1;e<30;++e)for(let t=n[e];t<n[e+1];++t)c[t]=t-n[e]<<5|e;return[n,c]},[i,f]=a(c,2);i[28]=258,f[258]=28;const[d,u]=a(s,0),g=new o(32768);for(let e=0;e<32768;++e){let t=(43690&e)>>>1|(21845&e)<<1;t=(52428&t)>>>2|(13107&t)<<2,t=(61680&t)>>>4|(3855&t)<<4,g[e]=((65280&t)>>>8|(255&t)<<8)>>>1}const h=(e,t,n)=>{const r=e.length;let c=0;const s=new o(t);for(;c<r;++c)e[c]&&++s[e[c]-1];const l=new o(t);for(c=0;c<t;++c)l[c]=l[c-1]+s[c-1]<<1;let a;if(n){a=new o(1<<t);const n=15-t;for(c=0;c<r;++c)if(e[c]){const o=c<<4|e[c],r=t-e[c];let s=l[e[c]-1]++<<r;for(const e=s|(1<<r)-1;s<=e;++s)a[g[s]>>>n]=o}}else for(a=new o(r),c=0;c<r;++c)e[c]&&(a[c]=g[l[e[c]-1]++]>>>15-e[c]);return a},m=new n(288);for(let e=0;e<144;++e)m[e]=8;for(let e=144;e<256;++e)m[e]=9;for(let e=256;e<280;++e)m[e]=7
|
|
4
|
+
;for(let e=280;e<288;++e)m[e]=8;const p=new n(32);for(let e=0;e<32;++e)p[e]=5;const y=h(m,9,1),b=h(p,5,1),w=e=>{let t=e[0];for(let n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},S=(e,t,n)=>{const o=t/8|0;return(e[o]|e[o+1]<<8)>>(7&t)&n},v=(e,t)=>{const n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},E=(e,t,c)=>{(null==t||t<0)&&(t=0),(null==c||c>e.length)&&(c=e.length);const s=new(2==e.BYTES_PER_ELEMENT?o:4==e.BYTES_PER_ELEMENT?r:n)(c-t);return s.set(e.subarray(t,c)),s},C=['unexpected EOF','invalid block type','invalid length/literal','invalid distance','stream finished','no stream handler',,'no callback','invalid UTF-8 data','extra field too long','date not in range 1980-2099','filename too long','stream finishing','invalid zip data'],k=(e,t,n)=>{const o=new Error(t||C[e]);if(o.code=e,
|
|
5
|
+
Error.captureStackTrace&&Error.captureStackTrace(o,k),!n)throw o;return o},T=(e,t)=>e[t]|e[t+1]<<8,x=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,O=(e,t)=>x(e,t)+4294967296*x(e,t+4),U=(e,t)=>t+30+T(e,t+26)+T(e,t+28),$=(e,t,n)=>{const o=!(2048&T(e,t+8)),r=T(e,t+28),c=M(e.subarray(t+46,t+46+r),o),s=t+46+r,l=x(e,t+20),[a,i,f]=n&&4294967295==l?j(e,s):[l,x(e,t+24),x(e,t+42)],d=s+T(e,t+30);return[T(e,t+10),a,i,c,s+T(e,t+30)+T(e,t+32),f,M(e.subarray(d,d+T(e,t+32)),o)]},j=(e,t)=>{for(;1!=T(e,t);t+=4+T(e,t+2));return[O(e,t+12),O(e,t+4),O(e,t+20)]};let z;const P=new n(0);try{const e=new TextDecoder;e.decode(P,{stream:!0}),z=e}catch(e){}function M(e,t){if(t){let t="";for(let n=0;n<e.length;n+=16384)t+=String.fromCharCode.apply(null,e.subarray(n,n+16384));return t}if(z)return z.decode(e);{
|
|
6
|
+
const[t,n]=(e=>{for(let t='',n=0;;){let o=e[n++];const r=+(o>127)+ +(o>223)+ +(o>239);if(n+r>e.length)return[t,E(e,n-1)];r?3==r?(o=((15&o)<<18|(63&e[n++])<<12|(63&e[n++])<<6|63&e[n++])-65536,t+=String.fromCharCode(55296|o>>10,56320|1023&o)):t+=1&r?String.fromCharCode((31&o)<<6|63&e[n++]):String.fromCharCode((15&o)<<12|(63&e[n++])<<6|63&e[n++]):t+=String.fromCharCode(o)}})(e);return n.length&&k(8),t}}function _(e,t){return((e,t,o)=>{const r=e.length;if(!r||o&&o.f&&!o.l)return t||new n(0);const a=!t||o,f=!o||o.i;o||(o={}),t||(t=new n(3*r));const u=e=>{let o=t.length;if(e>o){const r=new n(Math.max(2*o,e));r.set(t),t=r}};let g=o.f||0,m=o.p||0,p=o.b||0,C=o.l,T=o.d,x=o.m,O=o.n;const U=8*r;do{if(!C){g=S(e,m,1);const c=S(e,m+1,3);if(m+=3,!c){const n=4+((m+7)/8|0),c=e[n-4]|e[n-3]<<8,s=n+c;if(s>r){
|
|
7
|
+
f&&k(0);break}a&&u(p+c),t.set(e.subarray(n,s),p),o.b=p+=c,o.p=m=8*s,o.f=g;continue}if(1==c)C=y,T=b,x=9,O=5;else if(2==c){const t=S(e,m,31)+257,o=S(e,m+10,15)+4,r=t+S(e,m+5,31)+1;m+=14;const c=new n(r),s=new n(19);for(let t=0;t<o;++t)s[l[t]]=S(e,m+3*t,7);m+=3*o;const a=w(s),i=(1<<a)-1,f=h(s,a,1);for(let t=0;t<r;){const n=f[S(e,m,i)];m+=15&n;const o=n>>>4;if(o<16)c[t++]=o;else{let n=0,r=0;for(16==o?(r=3+S(e,m,3),m+=2,n=c[t-1]):17==o?(r=3+S(e,m,7),m+=3):18==o&&(r=11+S(e,m,127),m+=7);r--;)c[t++]=n}}const d=c.subarray(0,t),u=c.subarray(t);x=w(d),O=w(u),C=h(d,x,1),T=h(u,O,1)}else k(1);if(m>U){f&&k(0);break}}a&&u(p+131072);const E=(1<<x)-1,$=(1<<O)-1;let j=m;for(;;j=m){const n=C[v(e,m)&E],o=n>>>4;if(m+=15&n,m>U){f&&k(0);break}if(n||k(2),o<256)t[p++]=o;else{if(256==o){j=m,C=void 0;break}{
|
|
8
|
+
let n=o-254;if(o>264){const t=o-257,r=c[t];n=S(e,m,(1<<r)-1)+i[t],m+=r}const r=T[v(e,m)&$],l=r>>>4;r||k(3),m+=15&r;let g=d[l];if(l>3){const t=s[l];g+=v(e,m)&(1<<t)-1,m+=t}if(m>U){f&&k(0);break}a&&u(p+131072);const h=p+n;for(;p<h;p+=4)t[p]=t[p-g],t[p+1]=t[p+1-g],t[p+2]=t[p+2-g],t[p+3]=t[p+3-g];p=h}}}o.l=C,o.p=j,o.b=p,o.f=g,C&&(g=1,o.m=x,o.d=T,o.n=O)}while(!g);return p==t.length?t:E(t,0,p)})(e,t)}let L,R,A=new TextDecoder,B=function(e,t){const o={};let r=e.length-22;for(;101010256!=x(e,r);--r)(!r||e.length-r>65558)&&k(13);let c=T(e,r+8);if(!c)return{};let s=x(e,r+16);const l=4294967295==s;l&&(r=x(e,r-12),101075792!=x(e,r)&&k(13),c=x(e,r+32),s=x(e,r+48));const a=t&&t.filter;for(let t=0;t<c;++t){const[t,r,c,i,f,d,u]=$(e,s,l),g=U(e,d);if(s=f,!a||a({name:i,size:r,originalSize:c,compression:t})){
|
|
9
|
+
let s;t?8===t?s=_(e.subarray(g,g+r),new n(c)):k(14,'unknown compression type '+t):s=E(e,g,g+r),s&&(o[i]={data:s,comment:u})}}return o},N=()=>{A=void 0,D=q=F=N=void 0,L=R=void 0,B=void 0},q=(e,t)=>{L=e,R=t||""},D=(e,t,n)=>{const o=document.createElement("script"),r=R?document.querySelector(R).nextSibling:document.head.lastElementChild;if(document.head.insertBefore(o,r),o.id=t,n){const t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));o.integrity=n,o.src=t}else o.text=e},F=async(e,t=console.log)=>{const n=e+".js",o=await fetch(`${L}/${e}.zip`).then((async e=>{const n=!!e.headers.get("content-encoding"),o=e.body.getReader(),r=(c=+e.headers.get("content-length"),n?1.3*c|0:c);var c;const s=new Uint8Array(r);let l=0;for(;;){const e=await o.read();if(e.done)break;s.set(e.value,l),
|
|
10
|
+
l+=e.value.length,t(`loading script: ${l.toLocaleString()} bytes(${Math.round(l/r*100)}%)`)}return n?s.slice(0,l):s})).catch((e=>(console.error(e),null)));if(o&&o.length){t(`loaded script ${n}, decompressing binary...`),console.time(`unzip: ${n}`);const e=B(o);console.timeEnd(`unzip: ${n}`),t(`${n} decompressed 😃`);const r=e[n];D(A.decode(r.data,{stream:!1}),n,r.comment)}},Y=()=>{Y=void 0;const e=document.querySelector("script[data-csl-config]");if(e){const t=e.dataset.cslConfig;if(t){const e=JSON.parse(t);q(e.base,e.selector);const n=[];for(const t of e.load)n.push(F(t));try{Promise.all(n).then((()=>{const t=window[e.callback||"cslCallback"];"function"==typeof t&&(t(),N())}))}catch(e){console.error(e)}}}};setTimeout(Y,333),module.exports=t})();
|
package/webpack-esm/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*! For license information please see index.mjs.LICENSE.txt */
|
|
2
|
-
var e={d:(t,n)=>{for(var
|
|
3
|
-
t=(61680&t)>>>4|(3855&t)<<4,
|
|
4
|
-
const n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},
|
|
5
|
-
const
|
|
6
|
-
t+=String.fromCharCode(55296|
|
|
7
|
-
;const
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{Lx:()=>_,aN:()=>F,v6:()=>q,GZ:()=>M});const n=Uint8Array,o=Uint16Array,r=Uint32Array,c=new n([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),s=new n([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),a=new n([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=(e,t)=>{const n=new o(31);for(let o=0;o<31;++o)n[o]=t+=1<<e[o-1];const c=new r(n[30]);for(let e=1;e<30;++e)for(let t=n[e];t<n[e+1];++t)c[t]=t-n[e]<<5|e;return[n,c]},[i,f]=l(c,2);i[28]=258,f[258]=28;const[d,u]=l(s,0),h=new o(32768);for(let e=0;e<32768;++e){let t=(43690&e)>>>1|(21845&e)<<1;t=(52428&t)>>>2|(13107&t)<<2,
|
|
3
|
+
t=(61680&t)>>>4|(3855&t)<<4,h[e]=((65280&t)>>>8|(255&t)<<8)>>>1}const g=(e,t,n)=>{const r=e.length;let c=0;const s=new o(t);for(;c<r;++c)e[c]&&++s[e[c]-1];const a=new o(t);for(c=0;c<t;++c)a[c]=a[c-1]+s[c-1]<<1;let l;if(n){l=new o(1<<t);const n=15-t;for(c=0;c<r;++c)if(e[c]){const o=c<<4|e[c],r=t-e[c];let s=a[e[c]-1]++<<r;for(const e=s|(1<<r)-1;s<=e;++s)l[h[s]>>>n]=o}}else for(l=new o(r),c=0;c<r;++c)e[c]&&(l[c]=h[a[e[c]-1]++]>>>15-e[c]);return l},m=new n(288);for(let e=0;e<144;++e)m[e]=8;for(let e=144;e<256;++e)m[e]=9;for(let e=256;e<280;++e)m[e]=7;for(let e=280;e<288;++e)m[e]=8;const p=new n(32);for(let e=0;e<32;++e)p[e]=5;const w=g(m,9,1),b=g(p,5,1),y=e=>{let t=e[0];for(let n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},v=(e,t,n)=>{const o=t/8|0;return(e[o]|e[o+1]<<8)>>(7&t)&n},E=(e,t)=>{
|
|
4
|
+
const n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},S=(e,t,c)=>{(null==t||t<0)&&(t=0),(null==c||c>e.length)&&(c=e.length);const s=new(2==e.BYTES_PER_ELEMENT?o:4==e.BYTES_PER_ELEMENT?r:n)(c-t);return s.set(e.subarray(t,c)),s},C=['unexpected EOF','invalid block type','invalid length/literal','invalid distance','stream finished','no stream handler',,'no callback','invalid UTF-8 data','extra field too long','date not in range 1980-2099','filename too long','stream finishing','invalid zip data'],k=(e,t,n)=>{const o=new Error(t||C[e]);if(o.code=e,Error.captureStackTrace&&Error.captureStackTrace(o,k),!n)throw o;return o},x=(e,t)=>e[t]|e[t+1]<<8,T=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,U=(e,t)=>T(e,t)+4294967296*T(e,t+4),$=(e,t)=>t+30+x(e,t+26)+x(e,t+28),z=(e,t,n)=>{
|
|
5
|
+
const o=!(2048&x(e,t+8)),r=x(e,t+28),c=N(e.subarray(t+46,t+46+r),o),s=t+46+r,a=T(e,t+20),[l,i,f]=n&&4294967295==a?L(e,s):[a,T(e,t+24),T(e,t+42)],d=s+x(e,t+30);return[x(e,t+10),l,i,c,s+x(e,t+30)+x(e,t+32),f,N(e.subarray(d,d+x(e,t+32)),o)]},L=(e,t)=>{for(;1!=x(e,t);t+=4+x(e,t+2));return[U(e,t+12),U(e,t+4),U(e,t+20)]};let O;const j=new n(0);try{const e=new TextDecoder;e.decode(j,{stream:!0}),O=e}catch(e){}function N(e,t){if(t){let t="";for(let n=0;n<e.length;n+=16384)t+=String.fromCharCode.apply(null,e.subarray(n,n+16384));return t}if(O)return O.decode(e);{const[t,n]=(e=>{for(let t='',n=0;;){let o=e[n++];const r=+(o>127)+ +(o>223)+ +(o>239);if(n+r>e.length)return[t,S(e,n-1)];r?3==r?(o=((15&o)<<18|(63&e[n++])<<12|(63&e[n++])<<6|63&e[n++])-65536,
|
|
6
|
+
t+=String.fromCharCode(55296|o>>10,56320|1023&o)):t+=1&r?String.fromCharCode((31&o)<<6|63&e[n++]):String.fromCharCode((15&o)<<12|(63&e[n++])<<6|63&e[n++]):t+=String.fromCharCode(o)}})(e);return n.length&&k(8),t}}function P(e,t){return((e,t,o)=>{const r=e.length;if(!r||o&&o.f&&!o.l)return t||new n(0);const l=!t||o,f=!o||o.i;o||(o={}),t||(t=new n(3*r));const u=e=>{let o=t.length;if(e>o){const r=new n(Math.max(2*o,e));r.set(t),t=r}};let h=o.f||0,m=o.p||0,p=o.b||0,C=o.l,x=o.d,T=o.m,U=o.n;const $=8*r;do{if(!C){h=v(e,m,1);const c=v(e,m+1,3);if(m+=3,!c){const n=4+((m+7)/8|0),c=e[n-4]|e[n-3]<<8,s=n+c;if(s>r){f&&k(0);break}l&&u(p+c),t.set(e.subarray(n,s),p),o.b=p+=c,o.p=m=8*s,o.f=h;continue}if(1==c)C=w,x=b,T=9,U=5;else if(2==c){const t=v(e,m,31)+257,o=v(e,m+10,15)+4,r=t+v(e,m+5,31)+1;m+=14
|
|
7
|
+
;const c=new n(r),s=new n(19);for(let t=0;t<o;++t)s[a[t]]=v(e,m+3*t,7);m+=3*o;const l=y(s),i=(1<<l)-1,f=g(s,l,1);for(let t=0;t<r;){const n=f[v(e,m,i)];m+=15&n;const o=n>>>4;if(o<16)c[t++]=o;else{let n=0,r=0;for(16==o?(r=3+v(e,m,3),m+=2,n=c[t-1]):17==o?(r=3+v(e,m,7),m+=3):18==o&&(r=11+v(e,m,127),m+=7);r--;)c[t++]=n}}const d=c.subarray(0,t),u=c.subarray(t);T=y(d),U=y(u),C=g(d,T,1),x=g(u,U,1)}else k(1);if(m>$){f&&k(0);break}}l&&u(p+131072);const S=(1<<T)-1,z=(1<<U)-1;let L=m;for(;;L=m){const n=C[E(e,m)&S],o=n>>>4;if(m+=15&n,m>$){f&&k(0);break}if(n||k(2),o<256)t[p++]=o;else{if(256==o){L=m,C=void 0;break}{let n=o-254;if(o>264){const t=o-257,r=c[t];n=v(e,m,(1<<r)-1)+i[t],m+=r}const r=x[E(e,m)&z],a=r>>>4;r||k(3),m+=15&r;let h=d[a];if(a>3){const t=s[a];h+=E(e,m)&(1<<t)-1,m+=t}if(m>$){f&&k(0);break
|
|
8
|
+
}l&&u(p+131072);const g=p+n;for(;p<g;p+=4)t[p]=t[p-h],t[p+1]=t[p+1-h],t[p+2]=t[p+2-h],t[p+3]=t[p+3-h];p=g}}}o.l=C,o.p=L,o.b=p,o.f=h,C&&(h=1,o.m=T,o.d=x,o.n=U)}while(!h);return p==t.length?t:S(t,0,p)})(e,t)}let R,A,B=new TextDecoder,M=function(e,t){const o={};let r=e.length-22;for(;101010256!=T(e,r);--r)(!r||e.length-r>65558)&&k(13);let c=x(e,r+8);if(!c)return{};let s=T(e,r+16);const a=4294967295==s;a&&(r=T(e,r-12),101075792!=T(e,r)&&k(13),c=T(e,r+32),s=T(e,r+48));const l=t&&t.filter;for(let t=0;t<c;++t){const[t,r,c,i,f,d,u]=z(e,s,a),h=$(e,d);if(s=f,!l||l({name:i,size:r,originalSize:c,compression:t})){let s;t?8===t?s=P(e.subarray(h,h+r),new n(c)):k(14,'unknown compression type '+t):s=S(e,h,h+r),s&&(o[i]={data:s,comment:u})}}return o},_=()=>{B=void 0,D=q=F=_=void 0,R=A=void 0,M=void 0
|
|
9
|
+
},q=(e,t)=>{R=e,A=t||""},D=(e,t,n)=>{const o=document.createElement("script"),r=A?document.querySelector(A).nextSibling:document.head.lastElementChild;if(document.head.insertBefore(o,r),o.id=t,n){const t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));o.integrity=n,o.src=t}else o.text=e},F=async(e,t=console.log)=>{const n=e+".js",o=await fetch(`${R}/${e}.zip`).then((async e=>{const n=!!e.headers.get("content-encoding"),o=e.body.getReader(),r=(c=+e.headers.get("content-length"),n?1.3*c|0:c);var c;const s=new Uint8Array(r);let a=0;for(;;){const e=await o.read();if(e.done)break;s.set(e.value,a),a+=e.value.length,t(`loading script: ${a.toLocaleString()} bytes(${Math.round(a/r*100)}%)`)}return n?s.slice(0,a):s})).catch((e=>(console.error(e),null)));if(o&&o.length){
|
|
10
|
+
t(`loaded script ${n}, decompressing binary...`),console.time(`unzip: ${n}`);const e=M(o);console.timeEnd(`unzip: ${n}`),t(`${n} decompressed 😃`);const r=e[n];D(B.decode(r.data,{stream:!1}),n,r.comment)}},G=()=>{G=void 0;const e=document.querySelector("script[data-csl-config]");if(e){const t=e.dataset.cslConfig;if(t){const e=JSON.parse(t);q(e.base,e.selector);const n=[];for(const t of e.load)n.push(F(t));try{Promise.all(n).then((()=>{const t=window[e.callback||"cslCallback"];"function"==typeof t&&(t(),_())}))}catch(e){console.error(e)}}}};setTimeout(G,333);var Y=t.Lx,Z=t.aN,J=t.v6,H=t.GZ;export{Y as cleanUp,Z as loadCompressedScript,J as setConfig,H as unzipSync};
|