compressed-script-loader 1.2.10 → 1.2.14
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 +50 -26
- package/index.d.ts +5 -3
- package/package.json +2 -1
- package/umd/index.js +10 -10
- package/webpack/index.js +10 -10
- package/webpack-esm/index.mjs +10 -10
package/README.md
CHANGED
|
@@ -7,16 +7,16 @@
|
|
|
7
7
|
[1]:https://github.com/101arrowz/fflate
|
|
8
8
|
[2]:https://www.w3.org/TR/SRI/
|
|
9
9
|
|
|
10
|
-
# compressed-script-loader
|
|
10
|
+
#  compressed-script-loader
|
|
11
11
|
|
|
12
12
|
Reduces network traffic for huge source files built by webpack etc.
|
|
13
13
|
|
|
14
|
-
## Motivation
|
|
14
|
+
## ✨ Motivation
|
|
15
15
|
|
|
16
16
|
Today's web server hosts support compression transfer with `content-encoding`,
|
|
17
17
|
but for some servers that do not perform compression transfer, this module can be expected to significantly reduce network traffic.
|
|
18
18
|
|
|
19
|
-
## Details
|
|
19
|
+
## 📇 Details
|
|
20
20
|
|
|
21
21
|
+ Use code with **comment** extraction feature added to `unzipSync` of [`fflate`][1].
|
|
22
22
|
+ **comment** is used to embed [**SRI**][2]. (`script.integrity`)
|
|
@@ -25,9 +25,24 @@ the unziped code will be bound to the `text` property of `script` element.
|
|
|
25
25
|
You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the prefix `sha###-` is omit able because the hash method is automatically detected by the length of the [**SRI**][2].
|
|
26
26
|
+ [SRI online tool](https://www.srihash.org/)
|
|
27
27
|
|
|
28
|
+
+ example `script` element by `compressed-script-loader`
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script id="system-coordinate-map-mini.js"
|
|
32
|
+
integrity="sha384-X21iVQnEaPD0mdNEF66lHUBS4f63TQQHaDVxvRwIDm4yi+IE+ulVIpDJDAoKW3BP"
|
|
33
|
+
crossorigin="anonymous"
|
|
34
|
+
src="blob:https://jeffy-g.github.io/b4e7bdbd-f4c8-41af-b170-93fb979317fd">
|
|
35
|
+
</script>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
28
39
|
+ [**`cslpack`**](#cslpack-cli-since-v12x) cli - simple zip tool is available (since v1.2.x)
|
|
29
40
|
|
|
30
|
-
##
|
|
41
|
+
## 🖌️ TODO
|
|
42
|
+
|
|
43
|
+
+ `type="module"`
|
|
44
|
+
|
|
45
|
+
## 🦯 Use for SPA
|
|
31
46
|
|
|
32
47
|
> #### Load automatically
|
|
33
48
|
|
|
@@ -102,7 +117,7 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
102
117
|
</script>
|
|
103
118
|
```
|
|
104
119
|
|
|
105
|
-
## `cslpack` cli (since v1.2.x)
|
|
120
|
+
##  `cslpack` cli (since v1.2.x)
|
|
106
121
|
|
|
107
122
|
uses [fflate][1]'s `zipSync` feature
|
|
108
123
|
|
|
@@ -126,15 +141,17 @@ $ cslpack build/{cjs,esm}/*
|
|
|
126
141
|
> NOTE: \`cslpack\` does not keep directory path
|
|
127
142
|
|
|
128
143
|
|
|
129
|
-
## Loader API
|
|
144
|
+
##  Loader API
|
|
130
145
|
|
|
131
146
|
```ts
|
|
132
147
|
declare global {
|
|
133
|
-
var cslCallback:
|
|
148
|
+
var cslCallback: TCSLCallbak;
|
|
134
149
|
interface Window {
|
|
135
|
-
cslCallback:
|
|
150
|
+
cslCallback: TCSLCallbak;
|
|
151
|
+
[cslCallbackName: string]: TCSLCallbak;
|
|
136
152
|
}
|
|
137
153
|
}
|
|
154
|
+
export declare type TCSLCallbak = ((err?: Error[]) => void) | undefined;
|
|
138
155
|
export interface UnzipFileInfo {
|
|
139
156
|
name: string;
|
|
140
157
|
size: number;
|
|
@@ -159,7 +176,8 @@ $ cslpack build/{cjs,esm}/*
|
|
|
159
176
|
base: string;
|
|
160
177
|
selector?: string;
|
|
161
178
|
load: string[];
|
|
162
|
-
callback?:
|
|
179
|
+
callback?: string;
|
|
180
|
+
cleanup?: true;
|
|
163
181
|
};
|
|
164
182
|
|
|
165
183
|
declare var NsLoader: {
|
|
@@ -174,7 +192,7 @@ $ cslpack build/{cjs,esm}/*
|
|
|
174
192
|
}
|
|
175
193
|
```
|
|
176
194
|
|
|
177
|
-
## Config definition
|
|
195
|
+
##  Config definition
|
|
178
196
|
|
|
179
197
|
```ts
|
|
180
198
|
/**
|
|
@@ -220,22 +238,28 @@ $ cslpack build/{cjs,esm}/*
|
|
|
220
238
|
*/
|
|
221
239
|
load: string[];
|
|
222
240
|
/**
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
callback?:
|
|
241
|
+
* can be omit, default: "cslCallback"
|
|
242
|
+
*
|
|
243
|
+
* Please specify if you need to use another name
|
|
244
|
+
*
|
|
245
|
+
* ```js
|
|
246
|
+
* var cslCallback = () => {
|
|
247
|
+
* runEVEWorld(() => {
|
|
248
|
+
* window.setTimeout(() => {
|
|
249
|
+
* document.querySelectorAll("script[src^='./loader/'],script[src*='compressed-script-loader']").forEach(script => script.remove());
|
|
250
|
+
* delete window.NsLoader;
|
|
251
|
+
* }, 1000);
|
|
252
|
+
* });
|
|
253
|
+
* };
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
callback?: string;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* need cleanup?
|
|
260
|
+
* @default undefined
|
|
261
|
+
*/
|
|
262
|
+
cleanup?: true;
|
|
239
263
|
};
|
|
240
264
|
```
|
|
241
265
|
|
package/index.d.ts
CHANGED
|
@@ -14,16 +14,18 @@ declare global {
|
|
|
14
14
|
cslCallback: TCSLCallbak;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
export declare type TCSLCallbak = (() => void) | undefined;
|
|
17
|
+
export declare type TCSLCallbak = ((err?: Error[]) => void) | undefined;
|
|
18
18
|
export declare type TCSLConfig = {
|
|
19
19
|
base: string;
|
|
20
20
|
selector?: string;
|
|
21
21
|
load: string[];
|
|
22
|
-
callback?:
|
|
22
|
+
callback?: string;
|
|
23
|
+
cleanup?: true;
|
|
24
|
+
moduleDetect?: true;
|
|
23
25
|
};
|
|
24
26
|
declare let unzipSync: typeof Uz.unzipSync;
|
|
25
27
|
declare let cleanUp: () => void;
|
|
26
28
|
declare let setConfig: (base: string, insertionSelector?: string | undefined) => void;
|
|
27
29
|
declare let loadCompressedScript: (baseName: string, log?: (msg: string) => void) => Promise<void>;
|
|
28
|
-
declare
|
|
30
|
+
declare let version: string;
|
|
29
31
|
export { setConfig, loadCompressedScript, cleanUp, unzipSync, version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "compressed-script-loader",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.14",
|
|
4
4
|
"description": "Reduces network traffic for huge source files built by webpack etc.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./webpack/index.js",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"script",
|
|
40
40
|
"compression",
|
|
41
41
|
"loader",
|
|
42
|
+
"network traffic",
|
|
42
43
|
"SPA",
|
|
43
44
|
"html",
|
|
44
45
|
"dhtml"
|
package/umd/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
2
|
((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:()=>q,loadCompressedScript:()=>Y,setConfig:()=>F,unzipSync:()=>B,version:()=>H})
|
|
3
|
-
;const n=Uint8Array,o=Uint16Array,r=Uint32Array,
|
|
4
|
-
;if(n){
|
|
5
|
-
},x=["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"],$=(e,t,n)=>{const o=new Error(t||x[e]);if(o.code=e,Error.captureStackTrace&&Error.captureStackTrace(o,$),!n)throw o;return o},
|
|
6
|
-
|
|
7
|
-
;if(o>264){const t=o-257,r=
|
|
8
|
-
for(;1!=
|
|
9
|
-
;for(;101010256!=
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
;const n=Uint8Array,o=Uint16Array,r=Uint32Array,l=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]),a=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]),i=new n([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),c=(e,t)=>{const n=new o(31);for(let o=0;o<31;++o)n[o]=t+=1<<e[o-1];const l=new r(n[30]);for(let e=1;e<30;++e)for(let t=n[e];t<n[e+1];++t)l[t]=t-n[e]<<5|e;return[n,l]},[s,f]=c(l,2);s[28]=258,f[258]=28;const[d,u]=c(a,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 p=(e,t,n)=>{const r=e.length;let l=0;const a=new o(t);for(;l<r;++l)e[l]&&++a[e[l]-1];const i=new o(t);for(l=0;l<t;++l)i[l]=i[l-1]+a[l-1]<<1;let c
|
|
4
|
+
;if(n){c=new o(1<<t);const n=15-t;for(l=0;l<r;++l)if(e[l]){const o=l<<4|e[l],r=t-e[l];let a=i[e[l]-1]++<<r;for(const e=a|(1<<r)-1;a<=e;++a)c[g[a]>>>n]=o}}else for(c=new o(r),l=0;l<r;++l)e[l]&&(c[l]=g[i[e[l]-1]++]>>>15-e[l]);return c},y=new n(288);for(let e=0;e<144;++e)y[e]=8;for(let e=144;e<256;++e)y[e]=9;for(let e=256;e<280;++e)y[e]=7;for(let e=280;e<288;++e)y[e]=8;const h=new n(32);for(let e=0;e<32;++e)h[e]=5;const b=p(y,9,1),m=p(h,5,1),w=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},S=(e,t)=>{const n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},C=[,n,o,,r],k=(e,t,n)=>{(!t||t<0)&&(t=0),(!n||n>e.length)&&(n=e.length);const o=new C[e.BYTES_PER_ELEMENT](n-t);return o.set(e.subarray(t,n)),o
|
|
5
|
+
},x=["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"],$=(e,t,n)=>{const o=new Error(t||x[e]);if(o.code=e,Error.captureStackTrace&&Error.captureStackTrace(o,$),!n)throw o;return o},E=(e,t,o)=>{const r=e.length;if(!r||o&&o.f&&!o.l)return t||new n(0);const c=!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,y=o.p||0,h=o.b||0,C=o.l,x=o.d,E=o.m,T=o.n;const j=8*r;do{if(!C){g=v(e,y,1);const l=v(e,y+1,3);if(y+=3,!l){const n=4+((y+7)/8|0),l=e[n-4]|e[n-3]<<8,a=n+l;if(a>r){f&&$(0);break}
|
|
6
|
+
c&&u(h+l),t.set(e.subarray(n,a),h),o.b=h+=l,o.p=y=8*a,o.f=g;continue}if(1===l)C=b,x=m,E=9,T=5;else if(2===l){const t=v(e,y,31)+257,o=v(e,y+10,15)+4,r=t+v(e,y+5,31)+1;y+=14;const l=new n(r),a=new n(19);for(let t=0;t<o;++t)a[i[t]]=v(e,y+3*t,7);y+=3*o;const c=w(a),s=(1<<c)-1,f=p(a,c,1);for(let t=0;t<r;){const n=f[v(e,y,s)];y+=15&n;const o=n>>>4;if(o<16)l[t++]=o;else{let n=0,r=0;for(16===o?(r=3+v(e,y,3),y+=2,n=l[t-1]):17===o?(r=3+v(e,y,7),y+=3):18===o&&(r=11+v(e,y,127),y+=7);r--;)l[t++]=n}}const d=l.subarray(0,t),u=l.subarray(t);E=w(d),T=w(u),C=p(d,E,1),x=p(u,T,1)}else $(1);if(y>j){f&&$(0);break}}c&&u(h+131072);const k=(1<<E)-1,O=(1<<T)-1;let z=y;for(;;z=y){const n=C[S(e,y)&k],o=n>>>4;if(y+=15&n,y>j){f&&$(0);break}if(n||$(2),o<256)t[h++]=o;else{if(256===o){z=y,C=void 0;break}{let n=o-254
|
|
7
|
+
;if(o>264){const t=o-257,r=l[t];n=v(e,y,(1<<r)-1)+s[t],y+=r}const r=x[S(e,y)&O],i=r>>>4;r||$(3),y+=15&r;let g=d[i];if(i>3){const t=a[i];g+=S(e,y)&(1<<t)-1,y+=t}if(y>j){f&&$(0);break}c&&u(h+131072);const p=h+n;for(;h<p;h+=4)t[h]=t[h-g],t[h+1]=t[h+1-g],t[h+2]=t[h+2-g],t[h+3]=t[h+3-g];h=p}}}o.l=C,o.p=z,o.b=h,o.f=g,C&&(g=1,o.m=E,o.d=x,o.n=T)}while(!g);return h===t.length?t:k(t,0,h)},T=(e,t)=>e[t]|e[t+1]<<8,j=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,O=(e,t)=>j(e,t)+4294967296*j(e,t+4),z=(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),l=M(e.subarray(t+46,t+46+r),o),a=t+46+r,i=j(e,t+20),[c,s,f]=n&&4294967295===i?P(e,a):[i,j(e,t+24),j(e,t+42)],d=a+T(e,t+30);return[T(e,t+10),c,s,l,a+T(e,t+30)+T(e,t+32),f,M(e.subarray(d,d+T(e,t+32)),o)]},P=(e,t)=>{
|
|
8
|
+
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 A;const L=new n(0);try{const e=new TextDecoder;e.decode(L,{stream:!0}),A=e}catch{}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(A)return A.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,k(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&&$(8),t}}let N,R,_=new TextDecoder,B=function(e,t){const o={};let r=e.length-22
|
|
9
|
+
;for(;101010256!=j(e,r);--r)(!r||e.length-r>65558)&&$(13);let l=T(e,r+8);if(!l)return{};let a=j(e,r+16);const i=4294967295===a;i&&(r=j(e,r-12),101075792!=j(e,r)&&$(13),l=j(e,r+32),a=j(e,r+48));const c=t&&t.filter;for(let t=0;t<l;++t){const[t,r,l,s,f,d,u]=U(e,a,i),g=z(e,d);if(a=f,!c||c({name:s,size:r,originalSize:l,compression:t,comment:u})){let a;t?8===t?a=E(e.subarray(g,g+r),new n(l)):$(14,"unknown compression type "+t):a=k(e,g,g+r),a&&(o[s]={data:a,comment:u})}}return o},q=()=>{_=void 0,J=F=Y=q=void 0,N=R=void 0,D=B=void 0},D=e=>{let t=/^(?:sha\d{3}-)?([a-z0-9+/=]{44,88})$/i.exec(e);if(t){let n=(e=t[1]).length;if(!(88^n&&64^n&&44^n))return`sha${64==n?384:88==n?512:256}-${e}`}},F=(e,t)=>{N=e,R=t||""},J=(e,t,n,o)=>{let r=()=>{n(),console.log(`script ${t} is ready`)
|
|
10
|
+
},l=R?document.querySelector(R).nextSibling:void 0,a=document.head[l?"insertBefore":"appendChild"](document.createElement("script"),l);if(a.id=t,o){let t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));a.integrity=o,a.crossOrigin="",a.onload=r,a.src=t}else a.text=e,r()},Y=async(e,t=console.log)=>{let n=e+".zip",o=await fetch(`${N||"."}/${n}`).then((async e=>{let n=!!e.headers.get("content-encoding"),o=e.body.getReader(),r=(l=+e.headers.get("content-length"),n?1.3*l|0:l);var l;let a=new Uint8Array(r),i=0;for(;;){let e=await o.read();if(e.done)break;a.set(e.value,i),i+=e.value.length,t(`loading zip: ${i.toLocaleString()} bytes(${i/r*100|0}%)`)}return n?a.slice(0,i):a})).catch((e=>{console.error(e)}));if(o&&o.length){t(`loaded ${n}, decompressing binary...`),
|
|
11
|
+
console.time(`unzip: ${n}`);let e=B(o);return console.timeEnd(`unzip: ${n}`),t(`${n} decompressed 😃`),new Promise((t=>{let n=Object.keys(e),o=n.length,r=()=>{!--o&&t()};for(let t,o=0;t=n[o++];){let n=e[t];J(_.decode(n.data),t,r,D(n.comment))}}))}throw new Error(`Could not load "${n}"`)},G=async()=>{G=void 0;let e=document.querySelector("script[data-csl-config]");if(e){let t=e.dataset.cslConfig;if(t){let e;t=JSON.parse(t),t.load?(F(t.base,t.selector),e=t.load):e=Array.isArray(t)?t:"string"==typeof t?[t]:[];let n="function"==typeof cslCallback?cslCallback:window[t.callback||"cslCallback"],o=[];for(let t of e)o.push(Y(t).catch((e=>e)));let r=(await Promise.all(o)).filter((e=>e&&e.name));"function"==typeof n&&n(r.length?r:void 0),t.cleanup&&q()}}};setTimeout(G,99);let H="v1.2.14";return t
|
|
12
|
+
})()));
|
package/webpack/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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)
|
|
4
|
-
;for(let e=280;e<288;++e)
|
|
5
|
-
Error.captureStackTrace&&Error.captureStackTrace(
|
|
6
|
-
;const
|
|
7
|
-
|
|
8
|
-
for(let t="",n=0;;){let
|
|
9
|
-
})){let
|
|
10
|
-
|
|
11
|
-
;
|
|
2
|
+
(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},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:()=>D,loadCompressedScript:()=>Y,setConfig:()=>N,unzipSync:()=>q,version:()=>H});const n=Uint8Array,r=Uint16Array,o=Uint32Array,l=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]),a=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]),c=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 r(31);for(let r=0;r<31;++r)n[r]=t+=1<<e[r-1];const l=new o(n[30])
|
|
3
|
+
;for(let e=1;e<30;++e)for(let t=n[e];t<n[e+1];++t)l[t]=t-n[e]<<5|e;return[n,l]},[s,f]=i(l,2);s[28]=258,f[258]=28;const[d,u]=i(a,0),g=new r(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 o=e.length;let l=0;const a=new r(t);for(;l<o;++l)e[l]&&++a[e[l]-1];const c=new r(t);for(l=0;l<t;++l)c[l]=c[l-1]+a[l-1]<<1;let i;if(n){i=new r(1<<t);const n=15-t;for(l=0;l<o;++l)if(e[l]){const r=l<<4|e[l],o=t-e[l];let a=c[e[l]-1]++<<o;for(const e=a|(1<<o)-1;a<=e;++a)i[g[a]>>>n]=r}}else for(i=new r(o),l=0;l<o;++l)e[l]&&(i[l]=g[c[e[l]-1]++]>>>15-e[l]);return i},p=new n(288);for(let e=0;e<144;++e)p[e]=8;for(let e=144;e<256;++e)p[e]=9;for(let e=256;e<280;++e)p[e]=7
|
|
4
|
+
;for(let e=280;e<288;++e)p[e]=8;const y=new n(32);for(let e=0;e<32;++e)y[e]=5;const m=h(p,9,1),b=h(y,5,1),w=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 r=t/8|0;return(e[r]|e[r+1]<<8)>>(7&t)&n},S=(e,t)=>{const n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},C=[,n,r,,o],k=(e,t,n)=>{(!t||t<0)&&(t=0),(!n||n>e.length)&&(n=e.length);const r=new C[e.BYTES_PER_ELEMENT](n-t);return r.set(e.subarray(t,n)),r},$=["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"],E=(e,t,n)=>{const r=new Error(t||$[e]);if(r.code=e,
|
|
5
|
+
Error.captureStackTrace&&Error.captureStackTrace(r,E),!n)throw r;return r},x=(e,t,r)=>{const o=e.length;if(!o||r&&r.f&&!r.l)return t||new n(0);const i=!t||!!r,f=!r||r.i;!r&&(r={}),!t&&(t=new n(3*o));const u=e=>{let r=t.length;if(e>r){const o=new n(Math.max(2*r,e));o.set(t),t=o}};let g=r.f||0,p=r.p||0,y=r.b||0,C=r.l,$=r.d,x=r.m,O=r.n;const T=8*o;do{if(!C){g=v(e,p,1);const l=v(e,p+1,3);if(p+=3,!l){const n=4+((p+7)/8|0),l=e[n-4]|e[n-3]<<8,a=n+l;if(a>o){f&&E(0);break}i&&u(y+l),t.set(e.subarray(n,a),y),r.b=y+=l,r.p=p=8*a,r.f=g;continue}if(1===l)C=m,$=b,x=9,O=5;else if(2===l){const t=v(e,p,31)+257,r=v(e,p+10,15)+4,o=t+v(e,p+5,31)+1;p+=14;const l=new n(o),a=new n(19);for(let t=0;t<r;++t)a[c[t]]=v(e,p+3*t,7);p+=3*r;const i=w(a),s=(1<<i)-1,f=h(a,i,1);for(let t=0;t<o;){const n=f[v(e,p,s)];p+=15&n
|
|
6
|
+
;const r=n>>>4;if(r<16)l[t++]=r;else{let n=0,o=0;for(16===r?(o=3+v(e,p,3),p+=2,n=l[t-1]):17===r?(o=3+v(e,p,7),p+=3):18===r&&(o=11+v(e,p,127),p+=7);o--;)l[t++]=n}}const d=l.subarray(0,t),u=l.subarray(t);x=w(d),O=w(u),C=h(d,x,1),$=h(u,O,1)}else E(1);if(p>T){f&&E(0);break}}i&&u(y+131072);const k=(1<<x)-1,z=(1<<O)-1;let U=p;for(;;U=p){const n=C[S(e,p)&k],r=n>>>4;if(p+=15&n,p>T){f&&E(0);break}if(n||E(2),r<256)t[y++]=r;else{if(256===r){U=p,C=void 0;break}{let n=r-254;if(r>264){const t=r-257,o=l[t];n=v(e,p,(1<<o)-1)+s[t],p+=o}const o=$[S(e,p)&z],c=o>>>4;o||E(3),p+=15&o;let g=d[c];if(c>3){const t=a[c];g+=S(e,p)&(1<<t)-1,p+=t}if(p>T){f&&E(0);break}i&&u(y+131072);const h=y+n;for(;y<h;y+=4)t[y]=t[y-g],t[y+1]=t[y+1-g],t[y+2]=t[y+2-g],t[y+3]=t[y+3-g];y=h}}}r.l=C,r.p=U,r.b=y,r.f=g,C&&(g=1,r.m=x,r.d=$,
|
|
7
|
+
r.n=O)}while(!g);return y===t.length?t:k(t,0,y)},O=(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,z=(e,t)=>T(e,t)+4294967296*T(e,t+4),U=(e,t)=>t+30+O(e,t+26)+O(e,t+28),j=(e,t,n)=>{const r=!(2048&O(e,t+8)),o=O(e,t+28),l=M(e.subarray(t+46,t+46+o),r),a=t+46+o,c=T(e,t+20),[i,s,f]=n&&4294967295===c?P(e,a):[c,T(e,t+24),T(e,t+42)],d=a+O(e,t+30);return[O(e,t+10),i,s,l,a+O(e,t+30)+O(e,t+32),f,M(e.subarray(d,d+O(e,t+32)),r)]},P=(e,t)=>{for(;1!=O(e,t);t+=4+O(e,t+2));return[z(e,t+12),z(e,t+4),z(e,t+20)]};let A;const L=new n(0);try{const e=new TextDecoder;e.decode(L,{stream:!0}),A=e}catch{}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(A)return A.decode(e);{const[t,n]=(e=>{
|
|
8
|
+
for(let t="",n=0;;){let r=e[n++];const o=+(r>127)+ +(r>223)+ +(r>239);if(n+o>e.length)return[t,k(e,n-1)];o?3===o?(r=((15&r)<<18|(63&e[n++])<<12|(63&e[n++])<<6|63&e[n++])-65536,t+=String.fromCharCode(55296|r>>10,56320|1023&r)):t+=1&o?String.fromCharCode((31&r)<<6|63&e[n++]):String.fromCharCode((15&r)<<12|(63&e[n++])<<6|63&e[n++]):t+=String.fromCharCode(r)}})(e);return n.length&&E(8),t}}let R,_,B=new TextDecoder,q=function(e,t){const r={};let o=e.length-22;for(;101010256!=T(e,o);--o)(!o||e.length-o>65558)&&E(13);let l=O(e,o+8);if(!l)return{};let a=T(e,o+16);const c=4294967295===a;c&&(o=T(e,o-12),101075792!=T(e,o)&&E(13),l=T(e,o+32),a=T(e,o+48));const i=t&&t.filter;for(let t=0;t<l;++t){const[t,o,l,s,f,d,u]=j(e,a,c),g=U(e,d);if(a=f,!i||i({name:s,size:o,originalSize:l,compression:t,comment:u
|
|
9
|
+
})){let a;t?8===t?a=x(e.subarray(g,g+o),new n(l)):E(14,"unknown compression type "+t):a=k(e,g,g+o),a&&(r[s]={data:a,comment:u})}}return r},D=()=>{B=void 0,J=N=Y=D=void 0,R=_=void 0,F=q=void 0},F=e=>{let t=/^(?:sha\d{3}-)?([a-z0-9+/=]{44,88})$/i.exec(e);if(t){let n=(e=t[1]).length;if(!(88^n&&64^n&&44^n))return`sha${64==n?384:88==n?512:256}-${e}`}},N=(e,t)=>{R=e,_=t||""},J=(e,t,n,r)=>{let o=()=>{n(),console.log(`script ${t} is ready`)},l=_?document.querySelector(_).nextSibling:void 0,a=document.head[l?"insertBefore":"appendChild"](document.createElement("script"),l);if(a.id=t,r){let t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));a.integrity=r,a.crossOrigin="",a.onload=o,a.src=t}else a.text=e,o()},Y=async(e,t=console.log)=>{
|
|
10
|
+
let n=e+".zip",r=await fetch(`${R||"."}/${n}`).then((async e=>{let n=!!e.headers.get("content-encoding"),r=e.body.getReader(),o=(l=+e.headers.get("content-length"),n?1.3*l|0:l);var l;let a=new Uint8Array(o),c=0;for(;;){let e=await r.read();if(e.done)break;a.set(e.value,c),c+=e.value.length,t(`loading zip: ${c.toLocaleString()} bytes(${c/o*100|0}%)`)}return n?a.slice(0,c):a})).catch((e=>{console.error(e)}));if(r&&r.length){t(`loaded ${n}, decompressing binary...`),console.time(`unzip: ${n}`);let e=q(r);return console.timeEnd(`unzip: ${n}`),t(`${n} decompressed 😃`),new Promise((t=>{let n=Object.keys(e),r=n.length,o=()=>{!--r&&t()};for(let t,r=0;t=n[r++];){let n=e[t];J(B.decode(n.data),t,o,F(n.comment))}}))}throw new Error(`Could not load "${n}"`)},G=async()=>{G=void 0
|
|
11
|
+
;let e=document.querySelector("script[data-csl-config]");if(e){let t=e.dataset.cslConfig;if(t){let e;t=JSON.parse(t),t.load?(N(t.base,t.selector),e=t.load):e=Array.isArray(t)?t:"string"==typeof t?[t]:[];let n="function"==typeof cslCallback?cslCallback:window[t.callback||"cslCallback"],r=[];for(let t of e)r.push(Y(t).catch((e=>e)));let o=(await Promise.all(r)).filter((e=>e&&e.name));"function"==typeof n&&n(o.length?o:void 0),t.cleanup&&D()}}};setTimeout(G,99);let H="v1.2.14";module.exports=t})();
|
package/webpack-esm/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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,g[e]=((65280&t)>>>8|(255&t)<<8)>>>1}const h=(e,t,n)=>{const
|
|
4
|
-
const n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},k=[,n,o
|
|
5
|
-
}};let g=
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
t+=String.fromCharCode(55296|
|
|
9
|
-
R=B=void 0,
|
|
10
|
-
|
|
11
|
-
n=
|
|
2
|
+
var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{Lx:()=>F,aN:()=>_,v6:()=>M,GZ:()=>D,i8:()=>Y});const n=Uint8Array,r=Uint16Array,o=Uint32Array,l=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]),a=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]),c=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 r(31);for(let r=0;r<31;++r)n[r]=t+=1<<e[r-1];const l=new o(n[30]);for(let e=1;e<30;++e)for(let t=n[e];t<n[e+1];++t)l[t]=t-n[e]<<5|e;return[n,l]},[s,f]=i(l,2);s[28]=258,f[258]=28;const[d,u]=i(a,0),g=new r(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,g[e]=((65280&t)>>>8|(255&t)<<8)>>>1}const h=(e,t,n)=>{const o=e.length;let l=0;const a=new r(t);for(;l<o;++l)e[l]&&++a[e[l]-1];const c=new r(t);for(l=0;l<t;++l)c[l]=c[l-1]+a[l-1]<<1;let i;if(n){i=new r(1<<t);const n=15-t;for(l=0;l<o;++l)if(e[l]){const r=l<<4|e[l],o=t-e[l];let a=c[e[l]-1]++<<o;for(const e=a|(1<<o)-1;a<=e;++a)i[g[a]>>>n]=r}}else for(i=new r(o),l=0;l<o;++l)e[l]&&(i[l]=g[c[e[l]-1]++]>>>15-e[l]);return i},p=new n(288);for(let e=0;e<144;++e)p[e]=8;for(let e=144;e<256;++e)p[e]=9;for(let e=256;e<280;++e)p[e]=7;for(let e=280;e<288;++e)p[e]=8;const m=new n(32);for(let e=0;e<32;++e)m[e]=5;const w=h(p,9,1),y=h(m,5,1),b=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 r=t/8|0;return(e[r]|e[r+1]<<8)>>(7&t)&n},C=(e,t)=>{
|
|
4
|
+
const n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},k=[,n,r,,o],S=(e,t,n)=>{(!t||t<0)&&(t=0),(!n||n>e.length)&&(n=e.length);const r=new k[e.BYTES_PER_ELEMENT](n-t);return r.set(e.subarray(t,n)),r},$=["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"],x=(e,t,n)=>{const r=new Error(t||$[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,x),!n)throw r;return r},E=(e,t,r)=>{const o=e.length;if(!o||r&&r.f&&!r.l)return t||new n(0);const i=!t||!!r,f=!r||r.i;!r&&(r={}),!t&&(t=new n(3*o));const u=e=>{let r=t.length;if(e>r){const o=new n(Math.max(2*r,e));o.set(t),t=o
|
|
5
|
+
}};let g=r.f||0,p=r.p||0,m=r.b||0,k=r.l,$=r.d,E=r.m,z=r.n;const O=8*o;do{if(!k){g=v(e,p,1);const l=v(e,p+1,3);if(p+=3,!l){const n=4+((p+7)/8|0),l=e[n-4]|e[n-3]<<8,a=n+l;if(a>o){f&&x(0);break}i&&u(m+l),t.set(e.subarray(n,a),m),r.b=m+=l,r.p=p=8*a,r.f=g;continue}if(1===l)k=w,$=y,E=9,z=5;else if(2===l){const t=v(e,p,31)+257,r=v(e,p+10,15)+4,o=t+v(e,p+5,31)+1;p+=14;const l=new n(o),a=new n(19);for(let t=0;t<r;++t)a[c[t]]=v(e,p+3*t,7);p+=3*r;const i=b(a),s=(1<<i)-1,f=h(a,i,1);for(let t=0;t<o;){const n=f[v(e,p,s)];p+=15&n;const r=n>>>4;if(r<16)l[t++]=r;else{let n=0,o=0;for(16===r?(o=3+v(e,p,3),p+=2,n=l[t-1]):17===r?(o=3+v(e,p,7),p+=3):18===r&&(o=11+v(e,p,127),p+=7);o--;)l[t++]=n}}const d=l.subarray(0,t),u=l.subarray(t);E=b(d),z=b(u),k=h(d,E,1),$=h(u,z,1)}else x(1);if(p>O){f&&x(0);break}}
|
|
6
|
+
i&&u(m+131072);const S=(1<<E)-1,T=(1<<z)-1;let U=p;for(;;U=p){const n=k[C(e,p)&S],r=n>>>4;if(p+=15&n,p>O){f&&x(0);break}if(n||x(2),r<256)t[m++]=r;else{if(256===r){U=p,k=void 0;break}{let n=r-254;if(r>264){const t=r-257,o=l[t];n=v(e,p,(1<<o)-1)+s[t],p+=o}const o=$[C(e,p)&T],c=o>>>4;o||x(3),p+=15&o;let g=d[c];if(c>3){const t=a[c];g+=C(e,p)&(1<<t)-1,p+=t}if(p>O){f&&x(0);break}i&&u(m+131072);const h=m+n;for(;m<h;m+=4)t[m]=t[m-g],t[m+1]=t[m+1-g],t[m+2]=t[m+2-g],t[m+3]=t[m+3-g];m=h}}}r.l=k,r.p=U,r.b=m,r.f=g,k&&(g=1,r.m=E,r.d=$,r.n=z)}while(!g);return m===t.length?t:S(t,0,m)},z=(e,t)=>e[t]|e[t+1]<<8,O=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,T=(e,t)=>O(e,t)+4294967296*O(e,t+4),U=(e,t)=>t+30+z(e,t+26)+z(e,t+28),A=(e,t,n)=>{
|
|
7
|
+
const r=!(2048&z(e,t+8)),o=z(e,t+28),l=N(e.subarray(t+46,t+46+o),r),a=t+46+o,c=O(e,t+20),[i,s,f]=n&&4294967295===c?L(e,a):[c,O(e,t+24),O(e,t+42)],d=a+z(e,t+30);return[z(e,t+10),i,s,l,a+z(e,t+30)+z(e,t+32),f,N(e.subarray(d,d+z(e,t+32)),r)]},L=(e,t)=>{for(;1!=z(e,t);t+=4+z(e,t+2));return[T(e,t+12),T(e,t+4),T(e,t+20)]};let j;const P=new n(0);try{const e=new TextDecoder;e.decode(P,{stream:!0}),j=e}catch{}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(j)return j.decode(e);{const[t,n]=(e=>{for(let t="",n=0;;){let r=e[n++];const o=+(r>127)+ +(r>223)+ +(r>239);if(n+o>e.length)return[t,S(e,n-1)];o?3===o?(r=((15&r)<<18|(63&e[n++])<<12|(63&e[n++])<<6|63&e[n++])-65536,
|
|
8
|
+
t+=String.fromCharCode(55296|r>>10,56320|1023&r)):t+=1&o?String.fromCharCode((31&r)<<6|63&e[n++]):String.fromCharCode((15&r)<<12|(63&e[n++])<<6|63&e[n++]):t+=String.fromCharCode(r)}})(e);return n.length&&x(8),t}}let R,B,q=new TextDecoder,D=function(e,t){const r={};let o=e.length-22;for(;101010256!=O(e,o);--o)(!o||e.length-o>65558)&&x(13);let l=z(e,o+8);if(!l)return{};let a=O(e,o+16);const c=4294967295===a;c&&(o=O(e,o-12),101075792!=O(e,o)&&x(13),l=O(e,o+32),a=O(e,o+48));const i=t&&t.filter;for(let t=0;t<l;++t){const[t,o,l,s,f,d,u]=A(e,a,c),g=U(e,d);if(a=f,!i||i({name:s,size:o,originalSize:l,compression:t,comment:u})){let a;t?8===t?a=E(e.subarray(g,g+o),new n(l)):x(14,"unknown compression type "+t):a=S(e,g,g+o),a&&(r[s]={data:a,comment:u})}}return r},F=()=>{q=void 0,Z=M=_=F=void 0,
|
|
9
|
+
R=B=void 0,G=D=void 0},G=e=>{let t=/^(?:sha\d{3}-)?([a-z0-9+/=]{44,88})$/i.exec(e);if(t){let n=(e=t[1]).length;if(!(88^n&&64^n&&44^n))return`sha${64==n?384:88==n?512:256}-${e}`}},M=(e,t)=>{R=e,B=t||""},Z=(e,t,n,r)=>{let o=()=>{n(),console.log(`script ${t} is ready`)},l=B?document.querySelector(B).nextSibling:void 0,a=document.head[l?"insertBefore":"appendChild"](document.createElement("script"),l);if(a.id=t,r){let t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));a.integrity=r,a.crossOrigin="",a.onload=o,a.src=t}else a.text=e,o()},_=async(e,t=console.log)=>{let n=e+".zip",r=await fetch(`${R||"."}/${n}`).then((async e=>{let n=!!e.headers.get("content-encoding"),r=e.body.getReader(),o=(l=+e.headers.get("content-length"),n?1.3*l|0:l);var l;let a=new Uint8Array(o),c=0;for(;;){
|
|
10
|
+
let e=await r.read();if(e.done)break;a.set(e.value,c),c+=e.value.length,t(`loading zip: ${c.toLocaleString()} bytes(${c/o*100|0}%)`)}return n?a.slice(0,c):a})).catch((e=>{console.error(e)}));if(r&&r.length){t(`loaded ${n}, decompressing binary...`),console.time(`unzip: ${n}`);let e=D(r);return console.timeEnd(`unzip: ${n}`),t(`${n} decompressed 😃`),new Promise((t=>{let n=Object.keys(e),r=n.length,o=()=>{!--r&&t()};for(let t,r=0;t=n[r++];){let n=e[t];Z(q.decode(n.data),t,o,G(n.comment))}}))}throw new Error(`Could not load "${n}"`)},J=async()=>{J=void 0;let e=document.querySelector("script[data-csl-config]");if(e){let t=e.dataset.cslConfig;if(t){let e;t=JSON.parse(t),t.load?(M(t.base,t.selector),e=t.load):e=Array.isArray(t)?t:"string"==typeof t?[t]:[]
|
|
11
|
+
;let n="function"==typeof cslCallback?cslCallback:window[t.callback||"cslCallback"],r=[];for(let t of e)r.push(_(t).catch((e=>e)));let o=(await Promise.all(r)).filter((e=>e&&e.name));"function"==typeof n&&n(o.length?o:void 0),t.cleanup&&F()}}};setTimeout(J,99);let Y="v1.2.14";var H=t.Lx,I=t.aN,K=t.v6,Q=t.GZ,V=t.i8;export{H as cleanUp,I as loadCompressedScript,K as setConfig,Q as unzipSync,V as version};
|