compressed-script-loader 1.2.8 → 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 +83 -48
- package/bin/cslpack.js +16 -16
- package/index.d.ts +9 -5
- package/package.json +2 -1
- package/umd/index.js +11 -10
- package/unzip-sync.d.ts +1 -1
- package/webpack/index.js +10 -10
- package/webpack-esm/index.mjs +10 -10
package/README.md
CHANGED
|
@@ -5,46 +5,44 @@
|
|
|
5
5
|

|
|
6
6
|
|
|
7
7
|
[1]:https://github.com/101arrowz/fflate
|
|
8
|
+
[2]:https://www.w3.org/TR/SRI/
|
|
8
9
|
|
|
9
|
-
# compressed-script-loader
|
|
10
|
+
#  compressed-script-loader
|
|
10
11
|
|
|
11
12
|
Reduces network traffic for huge source files built by webpack etc.
|
|
12
13
|
|
|
13
|
-
## Motivation
|
|
14
|
+
## ✨ Motivation
|
|
14
15
|
|
|
15
16
|
Today's web server hosts support compression transfer with `content-encoding`,
|
|
16
17
|
but for some servers that do not perform compression transfer, this module can be expected to significantly reduce network traffic.
|
|
17
18
|
|
|
18
|
-
## Details
|
|
19
|
+
## 📇 Details
|
|
19
20
|
|
|
20
21
|
+ Use code with **comment** extraction feature added to `unzipSync` of [`fflate`][1].
|
|
21
|
-
+ **comment** is used to embed **SRI
|
|
22
|
-
If comment is omitted or does not pass to verify process that it is **SRI
|
|
22
|
+
+ **comment** is used to embed [**SRI**][2]. (`script.integrity`)
|
|
23
|
+
If comment is omitted or does not pass to verify process that it is [**SRI**][2],
|
|
23
24
|
the unziped code will be bound to the `text` property of `script` element.
|
|
24
|
-
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
|
|
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].
|
|
25
26
|
+ [SRI online tool](https://www.srihash.org/)
|
|
26
27
|
|
|
27
|
-
+
|
|
28
|
-
uses [fflate][1]'s `zip` feature
|
|
28
|
+
+ example `script` element by `compressed-script-loader`
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
```
|
|
35
37
|
|
|
36
|
-
**example:**
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# or
|
|
42
|
-
cslpack build/{cjs,esm}/* -dest dist/lib/bundle.zip -sha 512
|
|
43
|
-
# will be output to "./dist/bundle.zip"
|
|
44
|
-
cslpack build/{cjs,esm}/*
|
|
45
|
-
```
|
|
39
|
+
+ [**`cslpack`**](#cslpack-cli-since-v12x) cli - simple zip tool is available (since v1.2.x)
|
|
40
|
+
|
|
41
|
+
## 🖌️ TODO
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
+ `type="module"`
|
|
44
|
+
|
|
45
|
+
## 🦯 Use for SPA
|
|
48
46
|
|
|
49
47
|
> #### Load automatically
|
|
50
48
|
|
|
@@ -119,20 +117,50 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
119
117
|
</script>
|
|
120
118
|
```
|
|
121
119
|
|
|
122
|
-
|
|
120
|
+
##  `cslpack` cli (since v1.2.x)
|
|
121
|
+
|
|
122
|
+
uses [fflate][1]'s `zipSync` feature
|
|
123
|
+
|
|
124
|
+
`$ cslpack <jspath> <jspath>... [-(d|dest) <output zip path>] [-sha <256|384|512>]`
|
|
125
|
+
|
|
126
|
+
+ options
|
|
127
|
+
* `-(d|dest)` - output zip path. when omited will be output to **`./dist/bundle.zip`**
|
|
128
|
+
+ `-sha` - [256|384|512] when omited use 384 "sha384" (since v1.2.8)
|
|
129
|
+
|
|
130
|
+
**example:**
|
|
131
|
+
|
|
132
|
+
```shell
|
|
133
|
+
# apply just `sha384`
|
|
134
|
+
$ cslpack -d dist/lib/bundle.zip build/{bundle,data}.js
|
|
135
|
+
# or
|
|
136
|
+
$ cslpack build/{cjs,esm}/* -dest dist/lib/bundle.zip -sha 512
|
|
137
|
+
# will be output to "./dist/bundle.zip"
|
|
138
|
+
$ cslpack build/{cjs,esm}/*
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
> NOTE: \`cslpack\` does not keep directory path
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
##  Loader API
|
|
123
145
|
|
|
124
146
|
```ts
|
|
125
147
|
declare global {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
148
|
+
var cslCallback: TCSLCallbak;
|
|
149
|
+
interface Window {
|
|
150
|
+
cslCallback: TCSLCallbak;
|
|
151
|
+
[cslCallbackName: string]: TCSLCallbak;
|
|
152
|
+
}
|
|
130
153
|
}
|
|
154
|
+
export declare type TCSLCallbak = ((err?: Error[]) => void) | undefined;
|
|
131
155
|
export interface UnzipFileInfo {
|
|
132
156
|
name: string;
|
|
133
157
|
size: number;
|
|
134
158
|
originalSize: number;
|
|
135
159
|
compression: number;
|
|
160
|
+
/**
|
|
161
|
+
* @since v1.2.9
|
|
162
|
+
*/
|
|
163
|
+
comment?: string;
|
|
136
164
|
}
|
|
137
165
|
export declare type UnzipFileFilter = (file: UnzipFileInfo) => boolean;
|
|
138
166
|
export interface UnzipOptions {
|
|
@@ -148,10 +176,11 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
148
176
|
base: string;
|
|
149
177
|
selector?: string;
|
|
150
178
|
load: string[];
|
|
151
|
-
callback?:
|
|
179
|
+
callback?: string;
|
|
180
|
+
cleanup?: true;
|
|
152
181
|
};
|
|
153
182
|
|
|
154
|
-
declare
|
|
183
|
+
declare var NsLoader: {
|
|
155
184
|
unzipSync: (data: Uint8Array, opts?: UnzipOptions) => Unzipped;
|
|
156
185
|
cleanUp: () => void;
|
|
157
186
|
setConfig: (base: string, insertionSelector?: string | undefined) => void;
|
|
@@ -159,11 +188,11 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
159
188
|
readonly version: string;
|
|
160
189
|
};
|
|
161
190
|
declare interface Window {
|
|
162
|
-
|
|
191
|
+
NsLoader: typeof NsLoader;
|
|
163
192
|
}
|
|
164
193
|
```
|
|
165
194
|
|
|
166
|
-
## Config definition
|
|
195
|
+
##  Config definition
|
|
167
196
|
|
|
168
197
|
```ts
|
|
169
198
|
/**
|
|
@@ -209,22 +238,28 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
209
238
|
*/
|
|
210
239
|
load: string[];
|
|
211
240
|
/**
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
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;
|
|
228
263
|
};
|
|
229
264
|
```
|
|
230
265
|
|
package/bin/cslpack.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*! For license information please see cslpack.js.LICENSE.txt */
|
|
3
|
-
(()=>{var _wm_={274:module=>{function
|
|
4
|
-
|
|
5
|
-
;var a=Uint8Array,o=Uint16Array,i=Uint32Array,
|
|
6
|
-
|
|
7
|
-
},z=['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'],
|
|
8
|
-
;var c=
|
|
9
|
-
for(;i>138;i-=138)
|
|
10
|
-
var
|
|
11
|
-
},
|
|
12
|
-
;if(W>2&&
|
|
13
|
-
return~e}}},
|
|
14
|
-
;var o=e.length,i=new a(e.length+(e.length>>1)),
|
|
15
|
-
;var v=new Date(null==
|
|
16
|
-
;const X=require("util"),Z=["zip","gz","png","jpg","jpeg","pdf","doc","docx","ppt","pptx","xls","xlsx","heic","heif","7z","bz2","rar","gif","webp","webm","mp4","mov","mp3","aifc"],ee=new X.TextEncoder;const re=
|
|
17
|
-
;var
|
|
18
|
-
;/256|384|512/.test(
|
|
3
|
+
(()=>{var _wm_={274:module=>{function tinArgs(acfg,dbg=!1){dbg&&console.log("process.argv: ",process.argv),acfg=acfg||{};const pfix=acfg.prefix||"-",vIdx=pfix.length,eIdx=acfg.startIndex||2,pms={};if(process.argv.length>eIdx){const cArgs=process.argv;for(let idx=eIdx;idx<cArgs.length;){const opt=cArgs[idx++];if(opt)if(opt.startsWith(pfix)){let v=cArgs[idx];void 0===v||v.startsWith(pfix)?v=!0:(/^\[.+\]$/.test(v)||/^\/[^/]+\/[gimuys]{0,6}$/.test(v)?v=eval(v):/\\,/.test(v)?v=v.replace(/\\,/g,","):/,/.test(v)?v=v.split(","):/^(?:-?\.?\d+(?:\.\d*)?|0x[\da-f]+)$/i.test(v)&&(v=+v),idx++),pms[opt.substring(vIdx)]=v}else(pms.args||(pms.args=[])).push(opt)}}return pms}module.exports=tinArgs}},_wmc_={};function _wr_(e){var r=_wmc_[e]
|
|
4
|
+
;if(void 0!==r)return r.exports;var n=_wmc_[e]={exports:{}};return _wm_[e](n,n.exports,_wr_),n.exports}_wr_.r=e=>{'undefined'!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:'Module'}),Object.defineProperty(e,'__esModule',{value:!0})};var _we_={};(()=>{"use strict";_wr_.r(_we_);const e=require("fs"),r=require("child_process");var n=_wr_(274);const t=require("path")
|
|
5
|
+
;var a=Uint8Array,o=Uint16Array,i=Uint32Array,s=new a([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]),f=new a([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 a([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l=function(e,r){for(var n=new o(31),t=0;t<31;++t)n[t]=r+=1<<e[t-1];var a=new i(n[30]);for(t=1;t<30;++t)for(var s=n[t];s<n[t+1];++s)a[s]=s-n[t]<<5|t;return[n,a]},u=l(s,2),v=u[0],p=u[1];v[28]=258,p[258]=28;for(var d=l(f,0),h=(d[0],d[1]),g=new o(32768),_=0;_<32768;++_){var m=(43690&_)>>>1|(21845&_)<<1;m=(61680&(m=(52428&m)>>>2|(13107&m)<<2))>>>4|(3855&m)<<4,g[_]=((65280&m)>>>8|(255&m)<<8)>>>1}var w=function(e,r,n){for(var t=e.length,a=0,i=new o(r);a<t;++a)e[a]&&++i[e[a]-1];var s,f=new o(r);for(a=0;a<r;++a)f[a]=f[a-1]+i[a-1]<<1;if(n){
|
|
6
|
+
s=new o(1<<r);var c=15-r;for(a=0;a<t;++a)if(e[a])for(var l=a<<4|e[a],u=r-e[a],v=f[e[a]-1]++<<u,p=v|(1<<u)-1;v<=p;++v)s[g[v]>>>c]=l}else for(s=new o(t),a=0;a<t;++a)e[a]&&(s[a]=g[f[e[a]-1]++]>>>15-e[a]);return s},b=new a(288);for(_=0;_<144;++_)b[_]=8;for(_=144;_<256;++_)b[_]=9;for(_=256;_<280;++_)b[_]=7;for(_=280;_<288;++_)b[_]=8;var x=new a(32);for(_=0;_<32;++_)x[_]=5;var y=w(b,9,0),k=w(x,5,0),E=function(e){return(e+7)/8|0},M=function(e,r,n){(null==r||r<0)&&(r=0),(null==n||n>e.length)&&(n=e.length);var t=new(2==e.BYTES_PER_ELEMENT?o:4==e.BYTES_PER_ELEMENT?i:a)(n-r);return t.set(e.subarray(r,n)),t
|
|
7
|
+
},z=['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'],T=function(e,r,n){var t=new Error(r||z[e]);if(t.code=e,Error.captureStackTrace&&Error.captureStackTrace(t,T),!n)throw t;return t},A=function(e,r,n){n<<=7&r;var t=r/8|0;e[t]|=n,e[t+1]|=n>>>8},S=function(e,r,n){n<<=7&r;var t=r/8|0;e[t]|=n,e[t+1]|=n>>>8,e[t+2]|=n>>>16},j=function(e,r){for(var n=[],t=0;t<e.length;++t)e[t]&&n.push({s:t,f:e[t]});var i=n.length,s=n.slice();if(!i)return[R,0];if(1==i){var f=new a(n[0].s+1);return f[n[0].s]=1,[f,1]}n.sort((function(e,r){return e.f-r.f})),n.push({s:-1,f:25001})
|
|
8
|
+
;var c=n[0],l=n[1],u=0,v=1,p=2;for(n[0]={s:-1,f:c.f+l.f,l:c,r:l};v!=i-1;)c=n[n[u].f<n[p].f?u++:p++],l=n[u!=v&&n[u].f<n[p].f?u++:p++],n[v++]={s:-1,f:c.f+l.f,l:c,r:l};var d=s[0].s;for(t=1;t<i;++t)s[t].s>d&&(d=s[t].s);var h=new o(d+1),g=q(n[v-1],h,0);if(g>r){t=0;var _=0,m=g-r,w=1<<m;for(s.sort((function(e,r){return h[r.s]-h[e.s]||e.f-r.f}));t<i;++t){var b=s[t].s;if(!(h[b]>r))break;_+=w-(1<<g-h[b]),h[b]=r}for(_>>>=m;_>0;){var x=s[t].s;h[x]<r?_-=1<<r-h[x]++-1:++t}for(;t>=0&&_;--t){var y=s[t].s;h[y]==r&&(--h[y],++_)}g=r}return[new a(h),g]},q=function(e,r,n){return-1==e.s?Math.max(q(e.l,r,n+1),q(e.r,r,n+1)):r[e.s]=n},O=function(e){for(var r=e.length;r&&!e[--r];);for(var n=new o(++r),t=0,a=e[0],i=1,s=function(e){n[t++]=e},f=1;f<=r;++f)if(e[f]==a&&f!=r)++i;else{if(!a&&i>2){
|
|
9
|
+
for(;i>138;i-=138)s(32754);i>2&&(s(i>10?i-11<<5|28690:i-3<<5|12305),i=0)}else if(i>3){for(s(a),--i;i>6;i-=6)s(8304);i>2&&(s(i-3<<5|8208),i=0)}for(;i--;)s(a);i=1,a=e[f]}return[n.subarray(0,t),r]},$=function(e,r){for(var n=0,t=0;t<r.length;++t)n+=e[t]*r[t];return n},I=function(e,r,n){var t=n.length,a=E(r+2);e[a]=255&t,e[a+1]=t>>>8,e[a+2]=255^e[a],e[a+3]=255^e[a+1];for(var o=0;o<t;++o)e[a+o+4]=n[o];return 8*(a+4+t)},F=function(e,r,n,t,a,i,l,u,v,p,d){A(r,d++,n),++a[256];for(var h=j(a,15),g=h[0],_=h[1],m=j(i,15),E=m[0],M=m[1],z=O(g),T=z[0],q=z[1],F=O(E),D=F[0],R=F[1],P=new o(19),U=0;U<T.length;++U)P[31&T[U]]++;for(U=0;U<D.length;++U)P[31&D[U]]++;for(var C=j(P,7),N=C[0],Y=C[1],B=19;B>4&&!N[c[B-1]];--B);
|
|
10
|
+
var L,W,H,G,J=p+5<<3,K=$(a,b)+$(i,x)+l,Q=$(a,g)+$(i,E)+l+14+3*B+$(P,N)+(2*P[16]+3*P[17]+7*P[18]);if(J<=K&&J<=Q)return I(r,d,e.subarray(v,v+p));if(A(r,d,1+(Q<K)),d+=2,Q<K){L=w(g,_,0),W=g,H=w(E,M,0),G=E;var V=w(N,Y,0);A(r,d,q-257),A(r,d+5,R-1),A(r,d+10,B-4),d+=14;for(U=0;U<B;++U)A(r,d+3*U,N[c[U]]);d+=3*B;for(var X=[T,D],Z=0;Z<2;++Z){var ee=X[Z];for(U=0;U<ee.length;++U){var re=31&ee[U];A(r,d,V[re]),d+=N[re],re>15&&(A(r,d,ee[U]>>>5&127),d+=ee[U]>>>12)}}}else L=y,W=b,H=k,G=x;for(U=0;U<u;++U)if(t[U]>255){re=t[U]>>>18&31;S(r,d,L[re+257]),d+=W[re+257],re>7&&(A(r,d,t[U]>>>23&31),d+=s[re]);var ne=31&t[U];S(r,d,H[ne]),d+=G[ne],ne>3&&(S(r,d,t[U]>>>5&8191),d+=f[ne])}else S(r,d,L[t[U]]),d+=W[t[U]];return S(r,d,L[256]),d+W[256]
|
|
11
|
+
},D=new i([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),R=new a(0),P=function(e,r,n,t,c,l){var u=e.length,v=new a(t+u+5*(1+Math.ceil(u/7e3))+c),d=v.subarray(t,v.length-c),g=0;if(!r||u<8)for(var _=0;_<=u;_+=65535){var m=_+65535;m>=u&&(d[g>>3]=l),g=I(d,g+1,e.subarray(_,m))}else{for(var w=D[r-1],b=w>>>13,x=8191&w,y=(1<<n)-1,k=new o(32768),z=new o(y+1),T=Math.ceil(n/3),A=2*T,S=function(r){return(e[r]^e[r+1]<<T^e[r+2]<<A)&y},j=new i(25e3),q=new o(288),O=new o(32),$=0,P=0,U=(_=0,0),C=0,N=0;_<u;++_){var Y=S(_),B=32767&_,L=z[Y];if(k[B]=L,z[Y]=B,C<=_){var W=u-_;if(($>7e3||U>24576)&&W>423){g=F(e,d,0,j,q,O,P,U,N,_-N,g),U=$=P=0,N=_;for(var H=0;H<286;++H)q[H]=0;for(H=0;H<30;++H)O[H]=0}var G=2,J=0,K=x,Q=B-L&32767
|
|
12
|
+
;if(W>2&&Y==S(_-Q))for(var V=Math.min(b,W)-1,X=Math.min(32767,_),Z=Math.min(258,W);Q<=X&&--K&&B!=L;){if(e[_+G]==e[_+G-Q]){for(var ee=0;ee<Z&&e[_+ee]==e[_+ee-Q];++ee);if(ee>G){if(G=ee,J=Q,ee>V)break;var re=Math.min(Q,ee-2),ne=0;for(H=0;H<re;++H){var te=_-Q+H+32768&32767,ae=te-k[te]+32768&32767;ae>ne&&(ne=ae,L=te)}}}Q+=(B=L)-(L=k[B])+32768&32767}if(J){j[U++]=268435456|p[G]<<18|h[J];var oe=31&p[G],ie=31&h[J];P+=s[oe]+f[ie],++q[257+oe],++O[ie],C=_+G,++$}else j[U++]=e[_],++q[e[_]]}}g=F(e,d,l,j,q,O,P,U,N,_-N,g),!l&&7&g&&(g=I(d,g+1,R))}return M(v,0,t+E(g)+c)},U=function(){for(var e=new Int32Array(256),r=0;r<256;++r){for(var n=r,t=9;--t;)n=(1&n&&-306674912)^n>>>1;e[r]=n}return e}(),C=function(){var e=-1;return{p:function(r){for(var n=e,t=0;t<r.length;++t)n=U[255&n^r[t]]^n>>>8;e=n},d:function(){
|
|
13
|
+
return~e}}},N=function(e,r,n,t,a){return P(e,null==r.level?6:r.level,null==r.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(e.length)))):12+r.mem,n,t,!a)},Y=function(e,r){var n={};for(var t in e)n[t]=e[t];for(var t in r)n[t]=r[t];return n},B=function(e,r,n){for(;n;++r)e[r]=n,n>>>=8};function L(e,r){return N(e,r||{},0,0)}var W=function(e,r,n,t){for(var o in e){var i=e[o],s=r+o,f=t;Array.isArray(i)&&(f=Y(t,i[1]),i=i[0]),i instanceof a?n[s]=[i,f]:(n[s+='/']=[new a(0),f],W(i,s,n,t))}},H='undefined'!=typeof TextEncoder&&new TextEncoder,G='undefined'!=typeof TextDecoder&&new TextDecoder;try{G.decode(R,{stream:!0}),1}catch(e){}function J(e,r){if(r){for(var n=new a(e.length),t=0;t<e.length;++t)n[t]=e.charCodeAt(t);return n}if(H)return H.encode(e)
|
|
14
|
+
;var o=e.length,i=new a(e.length+(e.length>>1)),s=0,f=function(e){i[s++]=e};for(t=0;t<o;++t){if(s+5>i.length){var c=new a(s+8+(o-t<<1));c.set(i),i=c}var l=e.charCodeAt(t);l<128||r?f(l):l<2048?(f(192|l>>6),f(128|63&l)):l>55295&&l<57344?(f(240|(l=65536+(1047552&l)|1023&e.charCodeAt(++t))>>18),f(128|l>>12&63),f(128|l>>6&63),f(128|63&l)):(f(224|l>>12),f(128|l>>6&63),f(128|63&l))}return M(i,0,s)}var K=function(e){var r=0;if(e)for(var n in e){var t=e[n].length;t>65535&&T(9),r+=t+4}return r},Q=function(e,r,n,t,a,o,i,s){var f=t.length,c=n.extra,l=s&&s.length,u=K(c);B(e,r,null!=i?33639248:67324752),r+=4,null!=i&&(e[r++]=20,e[r++]=n.os),e[r]=20,r+=2,e[r++]=n.flag<<1|(null==o&&8),e[r++]=a&&8,e[r++]=255&n.compression,e[r++]=n.compression>>8
|
|
15
|
+
;var v=new Date(null==n.mtime?Date.now():n.mtime),p=v.getFullYear()-1980;if((p<0||p>119)&&T(10),B(e,r,p<<25|v.getMonth()+1<<21|v.getDate()<<16|v.getHours()<<11|v.getMinutes()<<5|v.getSeconds()>>>1),r+=4,null!=o&&(B(e,r,n.crc),B(e,r+4,o),B(e,r+8,n.size)),B(e,r+12,f),B(e,r+14,u),r+=16,null!=i&&(B(e,r,l),B(e,r+6,n.attrs),B(e,r+10,i),r+=14),e.set(t,r),r+=f,u)for(var d in c){var h=c[d],g=h.length;B(e,r,+d),B(e,r+2,g),e.set(h,r+4),r+=4+g}return l&&(e.set(s,r),r+=l),r},V=function(e,r,n,t,a){B(e,r,101010256),B(e,r+8,n),B(e,r+10,n),B(e,r+12,t),B(e,r+16,a)};'function'==typeof queueMicrotask?queueMicrotask:'function'==typeof setTimeout&&setTimeout
|
|
16
|
+
;const X=require("util"),Z=["zip","gz","png","jpg","jpeg","pdf","doc","docx","ppt","pptx","xls","xlsx","heic","heif","7z","bz2","rar","gif","webp","webm","mp4","mov","mp3","aifc"],ee=new X.TextEncoder;const re=n();console.log(re),Object.keys(re).length&&re.args||(console.log("\n> ERROR: the file to pack is required\n\n$ cslpack <jspath> <jspath>... [-(d|dest) <output zip path>] [-sha <256|384|512>]\n\n -(d|dest) : zip output path. when omited will be output to ./dist/bundle.zip\n -sha : [256|384|512] when omited use 384 \"sha384\"\n\n NOTE: `cslpack` does not keep directory path\n"),process.exit(0));const ne=new class{zipObj={};add(r,n){const a=t.parse(r),o=`${a.dir}/${a.base}`,i=ee.encode(e.readFileSync(o,"utf8"));i&&(this.zipObj[a.base]=[i,{level:-1===Z.indexOf(a.ext)?6:0,
|
|
17
|
+
comment:n}])}emit(r){const n=`[fflate.zip:${r}]`;console.time(n);const o=function(e,r){r||(r={});var n={},t=[];W(e,'',n,r);var o=0,i=0;for(var s in n){var f=n[s],c=f[0],l=f[1],u=0==l.level?0:8,v=(E=J(s)).length,p=l.comment,d=p&&J(p),h=d&&d.length,g=K(l.extra);v>65535&&T(11);var _=u?L(c,l):c,m=_.length,w=C();w.p(c),t.push(Y(l,{size:c.length,crc:w.d(),c:_,f:E,m:d,u:v!=s.length||d&&p.length!=h,o,compression:u})),o+=30+v+g+m,i+=76+2*(v+g)+(h||0)+m}for(var b=new a(i+22),x=o,y=i-o,k=0;k<t.length;++k){var E=t[k];Q(b,E.o,E,E.f,E.u,E.c.length);var M=30+E.f.length+K(E.extra);b.set(E.c,E.o+M),Q(b,o,E,E.f,E.u,E.c.length,E.o,E.m),o+=16+M+(E.m?E.m.length:0)}return V(b,o,t.length,y,x),b}(this.zipObj,{});(r=>{const n=t.dirname(r);e.existsSync(n)||e.mkdirSync(n,{recursive:!0})})(r),
|
|
18
|
+
e.writeFile(r,o,"binary",(()=>{console.timeEnd(n),this.zipObj={}}))}clear(){this.zipObj={}}};let te=re.sha;/256|384|512/.test(te)||(te="384");for(const n of re.args){if(e.statSync(n).isFile()){const e=r.execSync(`bash -c "echo -n $(openssl dgst -sha${te} -binary ${n} | openssl base64 -A)"`,{encoding:"utf8"});ne.add(n,e)}}ne.emit(re.d||re.dest||"./dist/bundle.zip")})(),module.exports=_we_})();
|
package/index.d.ts
CHANGED
|
@@ -6,22 +6,26 @@
|
|
|
6
6
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
8
|
import * as Uz from "./unzip-sync";
|
|
9
|
+
export type { UnzipFileFilter, FlateError, UnzipFileInfo, UnzipOptions, Unzipped } from "./unzip-sync";
|
|
9
10
|
declare global {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
var NsLoader: typeof import("./umd");
|
|
12
|
+
var cslCallback: TCSLCallbak;
|
|
12
13
|
interface Window {
|
|
13
|
-
cslCallback:
|
|
14
|
+
cslCallback: TCSLCallbak;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
17
|
+
export declare type TCSLCallbak = ((err?: Error[]) => void) | undefined;
|
|
16
18
|
export declare type TCSLConfig = {
|
|
17
19
|
base: string;
|
|
18
20
|
selector?: string;
|
|
19
21
|
load: string[];
|
|
20
|
-
callback?:
|
|
22
|
+
callback?: string;
|
|
23
|
+
cleanup?: true;
|
|
24
|
+
moduleDetect?: true;
|
|
21
25
|
};
|
|
22
26
|
declare let unzipSync: typeof Uz.unzipSync;
|
|
23
27
|
declare let cleanUp: () => void;
|
|
24
28
|
declare let setConfig: (base: string, insertionSelector?: string | undefined) => void;
|
|
25
29
|
declare let loadCompressedScript: (baseName: string, log?: (msg: string) => void) => Promise<void>;
|
|
26
|
-
declare
|
|
30
|
+
declare let version: string;
|
|
27
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,11 +1,12 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
|
|
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
|
-
console.time(`unzip: ${n}`);
|
|
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,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/unzip-sync.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare function strFromU8(dat: Uint8Array, latin1?: boolean): string;
|
|
2
1
|
export interface FlateError extends Error {
|
|
3
2
|
code: number;
|
|
4
3
|
}
|
|
@@ -7,6 +6,7 @@ export interface UnzipFileInfo {
|
|
|
7
6
|
size: number;
|
|
8
7
|
originalSize: number;
|
|
9
8
|
compression: number;
|
|
9
|
+
comment?: string;
|
|
10
10
|
}
|
|
11
11
|
export declare type UnzipFileFilter = (file: UnzipFileInfo) => boolean;
|
|
12
12
|
export interface UnzipOptions {
|
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)p[e]=8;const y=new n(32);for(let e=0;e<32;++e)y[e]=5;const
|
|
5
|
-
Error.captureStackTrace&&Error.captureStackTrace(
|
|
6
|
-
;const
|
|
7
|
-
|
|
8
|
-
for(let t="",n=0;;){let
|
|
9
|
-
;t?8===t?
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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};
|