compressed-script-loader 1.2.6 → 1.2.9
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 +53 -33
- package/bin/cslpack.js +16 -15
- package/index.d.ts +4 -2
- package/package.json +2 -2
- package/umd/index.js +11 -11
- package/unzip-sync.d.ts +1 -2
- package/webpack/index.js +10 -10
- package/webpack-esm/index.mjs +10 -10
package/README.md
CHANGED
|
@@ -5,36 +5,27 @@
|
|
|
5
5
|

|
|
6
6
|
|
|
7
7
|
[1]:https://github.com/101arrowz/fflate
|
|
8
|
+
[2]:https://www.w3.org/TR/SRI/
|
|
8
9
|
|
|
9
10
|
# compressed-script-loader
|
|
10
11
|
|
|
12
|
+
Reduces network traffic for huge source files built by webpack etc.
|
|
13
|
+
|
|
14
|
+
## Motivation
|
|
15
|
+
|
|
16
|
+
Today's web server hosts support compression transfer with `content-encoding`,
|
|
17
|
+
but for some servers that do not perform compression transfer, this module can be expected to significantly reduce network traffic.
|
|
18
|
+
|
|
11
19
|
## Details
|
|
12
20
|
|
|
13
21
|
+ Use code with **comment** extraction feature added to `unzipSync` of [`fflate`][1].
|
|
14
|
-
+ **comment** is used to embed **SRI
|
|
15
|
-
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],
|
|
16
24
|
the unziped code will be bound to the `text` property of `script` element.
|
|
17
|
-
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].
|
|
18
26
|
+ [SRI online tool](https://www.srihash.org/)
|
|
19
27
|
|
|
20
|
-
+ **`cslpack`** - simple zip tool is available (since v1.2.x)
|
|
21
|
-
uses [fflate][1]'s `zip` feature
|
|
22
|
-
|
|
23
|
-
`$ cslpack <js file> <js file> ... [-(d|dest) <output zip path>]`
|
|
24
|
-
|
|
25
|
-
+ option `-(d|dest)` - output zip path. when omited will be output to **`./dist/bundle.zip`**
|
|
26
|
-
+ This tool uses the `sha384` method
|
|
27
|
-
|
|
28
|
-
**example:**
|
|
29
|
-
|
|
30
|
-
```shell
|
|
31
|
-
# apply just `sha384`
|
|
32
|
-
cslpack -d dist/lib/bundle.zip build/{bundle,data}.js
|
|
33
|
-
# or
|
|
34
|
-
cslpack build/{cjs,esm}/* -dest dist/lib/bundle.zip
|
|
35
|
-
# will be output to "./dist/bundle.zip"
|
|
36
|
-
cslpack build/{cjs,esm}/*
|
|
37
|
-
```
|
|
28
|
+
+ [**`cslpack`**](#cslpack-cli-since-v12x) cli - simple zip tool is available (since v1.2.x)
|
|
38
29
|
|
|
39
30
|
## Use for SPA
|
|
40
31
|
|
|
@@ -65,12 +56,13 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
65
56
|
"callback": "onLoadDone"
|
|
66
57
|
}'
|
|
67
58
|
type="text/javascript"
|
|
68
|
-
src="https://cdn.jsdelivr.net/npm/compressed-script-loader
|
|
59
|
+
src="https://cdn.jsdelivr.net/npm/compressed-script-loader/umd/index.js"
|
|
69
60
|
></script>
|
|
70
61
|
```
|
|
71
62
|
|
|
72
63
|
+ Supports simple `data-csl-config` (since v1.2.6)
|
|
73
|
-
+ In this case, the packed zip file must be deployed in the same directory as the page and
|
|
64
|
+
+ In this case, the packed zip file must be deployed in the same directory as the page and
|
|
65
|
+
If need a callback, define it as `cslCallback`.
|
|
74
66
|
|
|
75
67
|
```html
|
|
76
68
|
<script
|
|
@@ -87,16 +79,16 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
87
79
|
> #### Load manually
|
|
88
80
|
|
|
89
81
|
```html
|
|
90
|
-
<script src="https://cdn.jsdelivr.net/npm/compressed-script-loader
|
|
82
|
+
<script src="https://cdn.jsdelivr.net/npm/compressed-script-loader/umd/index.js"></script>
|
|
91
83
|
<script>
|
|
92
84
|
// global variable `NsLoader` is available (umd)
|
|
93
85
|
(async () => {
|
|
94
|
-
const
|
|
86
|
+
const ZIPNAME = "system-coordinate-map-mini";
|
|
95
87
|
// If the packed zip file is located in the same directory as the page
|
|
96
88
|
// and you don't care where the script is inserted, you can skip this step.
|
|
97
89
|
NsLoader.setConfig("./libs"/*, "script[src*=css-2d-renderer]"*/);
|
|
98
90
|
|
|
99
|
-
await NsLoader.loadCompressedScript(
|
|
91
|
+
await NsLoader.loadCompressedScript(ZIPNAME);
|
|
100
92
|
// If you don't use it anymore, this step will destroy the loader api
|
|
101
93
|
NsLoader.cleanUp();
|
|
102
94
|
|
|
@@ -110,20 +102,48 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
110
102
|
</script>
|
|
111
103
|
```
|
|
112
104
|
|
|
113
|
-
|
|
105
|
+
## `cslpack` cli (since v1.2.x)
|
|
106
|
+
|
|
107
|
+
uses [fflate][1]'s `zipSync` feature
|
|
108
|
+
|
|
109
|
+
`$ cslpack <jspath> <jspath>... [-(d|dest) <output zip path>] [-sha <256|384|512>]`
|
|
110
|
+
|
|
111
|
+
+ options
|
|
112
|
+
* `-(d|dest)` - output zip path. when omited will be output to **`./dist/bundle.zip`**
|
|
113
|
+
+ `-sha` - [256|384|512] when omited use 384 "sha384" (since v1.2.8)
|
|
114
|
+
|
|
115
|
+
**example:**
|
|
116
|
+
|
|
117
|
+
```shell
|
|
118
|
+
# apply just `sha384`
|
|
119
|
+
$ cslpack -d dist/lib/bundle.zip build/{bundle,data}.js
|
|
120
|
+
# or
|
|
121
|
+
$ cslpack build/{cjs,esm}/* -dest dist/lib/bundle.zip -sha 512
|
|
122
|
+
# will be output to "./dist/bundle.zip"
|
|
123
|
+
$ cslpack build/{cjs,esm}/*
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
> NOTE: \`cslpack\` does not keep directory path
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
## Loader API
|
|
114
130
|
|
|
115
131
|
```ts
|
|
116
132
|
declare global {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
133
|
+
var cslCallback: (() => void) | undefined;
|
|
134
|
+
interface Window {
|
|
135
|
+
cslCallback: (() => void) | undefined;
|
|
136
|
+
}
|
|
121
137
|
}
|
|
122
138
|
export interface UnzipFileInfo {
|
|
123
139
|
name: string;
|
|
124
140
|
size: number;
|
|
125
141
|
originalSize: number;
|
|
126
142
|
compression: number;
|
|
143
|
+
/**
|
|
144
|
+
* @since v1.2.9
|
|
145
|
+
*/
|
|
146
|
+
comment?: string;
|
|
127
147
|
}
|
|
128
148
|
export declare type UnzipFileFilter = (file: UnzipFileInfo) => boolean;
|
|
129
149
|
export interface UnzipOptions {
|
|
@@ -142,7 +162,7 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
142
162
|
callback?: keyof Window;
|
|
143
163
|
};
|
|
144
164
|
|
|
145
|
-
declare
|
|
165
|
+
declare var NsLoader: {
|
|
146
166
|
unzipSync: (data: Uint8Array, opts?: UnzipOptions) => Unzipped;
|
|
147
167
|
cleanUp: () => void;
|
|
148
168
|
setConfig: (base: string, insertionSelector?: string | undefined) => void;
|
|
@@ -150,7 +170,7 @@ You can use `sha256`, `sha384`, and `sha512` in `script.integrity`, and the pref
|
|
|
150
170
|
readonly version: string;
|
|
151
171
|
};
|
|
152
172
|
declare interface Window {
|
|
153
|
-
|
|
173
|
+
NsLoader: typeof NsLoader;
|
|
154
174
|
}
|
|
155
175
|
```
|
|
156
176
|
|
package/bin/cslpack.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*! For license information please see cslpack.js.LICENSE.txt */
|
|
3
|
-
(()=>{var _wm_={274:module=>{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
;
|
|
9
|
-
for(
|
|
10
|
-
|
|
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
|
-
u:v
|
|
3
|
+
(()=>{var _wm_={274:module=>{function getExtraArgs(argsConfig,debug=!1){debug&&console.log("process.argv: ",process.argv);let cfg=argsConfig||{};cfg=Object.assign({startIndex:2,prefix:"-"},cfg);const vIdx=cfg.prefix.length,eIdx=cfg.startIndex||2,params={};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(cfg.prefix)){let v=cArgs[idx];void 0===v||v.startsWith(cfg.prefix)?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++),params[opt.substring(vIdx)]=v}else{let e=params.args;!e&&(params.args=e=[]),e.push(opt)}}}return params}
|
|
4
|
+
module.exports=getExtraArgs}},_wmc_={};function _wr_(e){var r=_wmc_[e];if(void 0!==r)return r.exports;var t=_wmc_[e]={exports:{}};return _wm_[e](t,t.exports,_wr_),t.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 t=_wr_(274);const n=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 t=new o(31),n=0;n<31;++n)t[n]=r+=1<<e[n-1];var a=new i(t[30]);for(n=1;n<30;++n)for(var s=t[n];s<t[n+1];++s)a[s]=s-t[n]<<5|n;return[t,a]},u=l(s,2),v=u[0],p=u[1];v[28]=258,p[258]=28;for(var g=l(f,0),d=(g[0],g[1]),h=new o(32768),_=0;_<32768;++_){var m=(43690&_)>>>1|(21845&_)<<1;m=(61680&(m=(52428&m)>>>2|(13107&m)<<2))>>>4|(3855&m)<<4,h[_]=((65280&m)>>>8|(255&m)<<8)>>>1}var w=function(e,r,t){for(var n=e.length,a=0,i=new o(r);a<n;++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(t){
|
|
6
|
+
s=new o(1<<r);var c=15-r;for(a=0;a<n;++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[h[v]>>>c]=l}else for(s=new o(n),a=0;a<n;++a)e[a]&&(s[a]=h[f[e[a]-1]++]>>>15-e[a]);return s},x=new a(288);for(_=0;_<144;++_)x[_]=8;for(_=144;_<256;++_)x[_]=9;for(_=256;_<280;++_)x[_]=7;for(_=280;_<288;++_)x[_]=8;var b=new a(32);for(_=0;_<32;++_)b[_]=5;var y=w(x,9,0),k=w(b,5,0),E=function(e){return(e+7)/8|0},M=function(e,r,t){(null==r||r<0)&&(r=0),(null==t||t>e.length)&&(t=e.length);var n=new(2==e.BYTES_PER_ELEMENT?o:4==e.BYTES_PER_ELEMENT?i:a)(t-r);return n.set(e.subarray(r,t)),n
|
|
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,t){var n=new Error(r||z[e]);if(n.code=e,Error.captureStackTrace&&Error.captureStackTrace(n,T),!t)throw n;return n},A=function(e,r,t){t<<=7&r;var n=r/8|0;e[n]|=t,e[n+1]|=t>>>8},S=function(e,r,t){t<<=7&r;var n=r/8|0;e[n]|=t,e[n+1]|=t>>>8,e[n+2]|=t>>>16},j=function(e,r){for(var t=[],n=0;n<e.length;++n)e[n]&&t.push({s:n,f:e[n]});var i=t.length,s=t.slice();if(!i)return[D,0];if(1==i){var f=new a(t[0].s+1);return f[t[0].s]=1,[f,1]}t.sort((function(e,r){return e.f-r.f})),t.push({s:-1,f:25001})
|
|
8
|
+
;var c=t[0],l=t[1],u=0,v=1,p=2;for(t[0]={s:-1,f:c.f+l.f,l:c,r:l};v!=i-1;)c=t[t[u].f<t[p].f?u++:p++],l=t[u!=v&&t[u].f<t[p].f?u++:p++],t[v++]={s:-1,f:c.f+l.f,l:c,r:l};var g=s[0].s;for(n=1;n<i;++n)s[n].s>g&&(g=s[n].s);var d=new o(g+1),h=O(t[v-1],d,0);if(h>r){n=0;var _=0,m=h-r,w=1<<m;for(s.sort((function(e,r){return d[r.s]-d[e.s]||e.f-r.f}));n<i;++n){var x=s[n].s;if(!(d[x]>r))break;_+=w-(1<<h-d[x]),d[x]=r}for(_>>>=m;_>0;){var b=s[n].s;d[b]<r?_-=1<<r-d[b]++-1:++n}for(;n>=0&&_;--n){var y=s[n].s;d[y]==r&&(--d[y],++_)}h=r}return[new a(d),h]},O=function(e,r,t){return-1==e.s?Math.max(O(e.l,r,t+1),O(e.r,r,t+1)):r[e.s]=t},q=function(e){for(var r=e.length;r&&!e[--r];);for(var t=new o(++r),n=0,a=e[0],i=1,s=function(e){t[n++]=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[t.subarray(0,n),r]},$=function(e,r){for(var t=0,n=0;n<r.length;++n)t+=e[n]*r[n];return t},I=function(e,r,t){var n=t.length,a=E(r+2);e[a]=255&n,e[a+1]=n>>>8,e[a+2]=255^e[a],e[a+3]=255^e[a+1];for(var o=0;o<n;++o)e[a+o+4]=t[o];return 8*(a+4+n)},F=function(e,r,t,n,a,i,l,u,v,p,g){A(r,g++,t),++a[256];for(var d=j(a,15),h=d[0],_=d[1],m=j(i,15),E=m[0],M=m[1],z=q(h),T=z[0],O=z[1],F=q(E),C=F[0],D=F[1],R=new o(19),P=0;P<T.length;++P)R[31&T[P]]++;for(P=0;P<C.length;++P)R[31&C[P]]++;for(var U=j(R,7),N=U[0],Y=U[1],B=19;B>4&&!N[c[B-1]];--B);
|
|
10
|
+
var L,W,H,G,J=p+5<<3,K=$(a,x)+$(i,b)+l,Q=$(a,h)+$(i,E)+l+14+3*B+$(R,N)+(2*R[16]+3*R[17]+7*R[18]);if(J<=K&&J<=Q)return I(r,g,e.subarray(v,v+p));if(A(r,g,1+(Q<K)),g+=2,Q<K){L=w(h,_,0),W=h,H=w(E,M,0),G=E;var V=w(N,Y,0);A(r,g,O-257),A(r,g+5,D-1),A(r,g+10,B-4),g+=14;for(P=0;P<B;++P)A(r,g+3*P,N[c[P]]);g+=3*B;for(var X=[T,C],Z=0;Z<2;++Z){var ee=X[Z];for(P=0;P<ee.length;++P){var re=31&ee[P];A(r,g,V[re]),g+=N[re],re>15&&(A(r,g,ee[P]>>>5&127),g+=ee[P]>>>12)}}}else L=y,W=x,H=k,G=b;for(P=0;P<u;++P)if(n[P]>255){re=n[P]>>>18&31;S(r,g,L[re+257]),g+=W[re+257],re>7&&(A(r,g,n[P]>>>23&31),g+=s[re]);var te=31&n[P];S(r,g,H[te]),g+=G[te],te>3&&(S(r,g,n[P]>>>5&8191),g+=f[te])}else S(r,g,L[n[P]]),g+=W[n[P]];return S(r,g,L[256]),g+W[256]
|
|
11
|
+
},C=new i([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),D=new a(0),R=function(e,r,t,n,c,l){var u=e.length,v=new a(n+u+5*(1+Math.ceil(u/7e3))+c),g=v.subarray(n,v.length-c),h=0;if(!r||u<8)for(var _=0;_<=u;_+=65535){var m=_+65535;m>=u&&(g[h>>3]=l),h=I(g,h+1,e.subarray(_,m))}else{for(var w=C[r-1],x=w>>>13,b=8191&w,y=(1<<t)-1,k=new o(32768),z=new o(y+1),T=Math.ceil(t/3),A=2*T,S=function(r){return(e[r]^e[r+1]<<T^e[r+2]<<A)&y},j=new i(25e3),O=new o(288),q=new o(32),$=0,R=0,P=(_=0,0),U=0,N=0;_<u;++_){var Y=S(_),B=32767&_,L=z[Y];if(k[B]=L,z[Y]=B,U<=_){var W=u-_;if(($>7e3||P>24576)&&W>423){h=F(e,g,0,j,O,q,R,P,N,_-N,h),P=$=R=0,N=_;for(var H=0;H<286;++H)O[H]=0;for(H=0;H<30;++H)q[H]=0}var G=2,J=0,K=b,Q=B-L&32767
|
|
12
|
+
;if(W>2&&Y==S(_-Q))for(var V=Math.min(x,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),te=0;for(H=0;H<re;++H){var ne=_-Q+H+32768&32767,ae=ne-k[ne]+32768&32767;ae>te&&(te=ae,L=ne)}}}Q+=(B=L)-(L=k[B])+32768&32767}if(J){j[P++]=268435456|p[G]<<18|d[J];var oe=31&p[G],ie=31&d[J];R+=s[oe]+f[ie],++O[257+oe],++q[ie],U=_+G,++$}else j[P++]=e[_],++O[e[_]]}}h=F(e,g,l,j,O,q,R,P,N,_-N,h),!l&&7&h&&(h=I(g,h+1,D))}return M(v,0,n+E(h)+c)},P=function(){for(var e=new Int32Array(256),r=0;r<256;++r){for(var t=r,n=9;--n;)t=(1&t&&-306674912)^t>>>1;e[r]=t}return e}(),U=function(){var e=-1;return{p:function(r){for(var t=e,n=0;n<r.length;++n)t=P[255&t^r[n]]^t>>>8;e=t},d:function(){
|
|
13
|
+
return~e}}},N=function(e,r,t,n,a){return R(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,t,n,!a)},Y=function(e,r){var t={};for(var n in e)t[n]=e[n];for(var n in r)t[n]=r[n];return t},B=function(e,r,t){for(;t;++r)e[r]=t,t>>>=8};function L(e,r){return N(e,r||{},0,0)}var W=function(e,r,t,n){for(var o in e){var i=e[o],s=r+o,f=n;Array.isArray(i)&&(f=Y(n,i[1]),i=i[0]),i instanceof a?t[s]=[i,f]:(t[s+='/']=[new a(0),f],W(i,s,t,n))}},H='undefined'!=typeof TextEncoder&&new TextEncoder,G='undefined'!=typeof TextDecoder&&new TextDecoder;try{G.decode(D,{stream:!0}),1}catch(e){}function J(e,r){if(r){for(var t=new a(e.length),n=0;n<e.length;++n)t[n]=e.charCodeAt(n);return t}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(n=0;n<o;++n){if(s+5>i.length){var c=new a(s+8+(o-n<<1));c.set(i),i=c}var l=e.charCodeAt(n);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(++n))>>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 t in e){var n=e[t].length;n>65535&&T(9),r+=n+4}return r},Q=function(e,r,t,n,a,o,i,s){var f=n.length,c=t.extra,l=s&&s.length,u=K(c);B(e,r,null!=i?33639248:67324752),r+=4,null!=i&&(e[r++]=20,e[r++]=t.os),e[r]=20,r+=2,e[r++]=t.flag<<1|(null==o&&8),e[r++]=a&&8,e[r++]=255&t.compression,e[r++]=t.compression>>8
|
|
15
|
+
;var v=new Date(null==t.mtime?Date.now():t.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,t.crc),B(e,r+4,o),B(e,r+8,t.size)),B(e,r+12,f),B(e,r+14,u),r+=16,null!=i&&(B(e,r,l),B(e,r+6,t.attrs),B(e,r+10,i),r+=14),e.set(n,r),r+=f,u)for(var g in c){var d=c[g],h=d.length;B(e,r,+g),B(e,r+2,h),e.set(d,r+4),r+=4+h}return l&&(e.set(s,r),r+=l),r},V=function(e,r,t,n,a){B(e,r,101010256),B(e,r+8,t),B(e,r+10,t),B(e,r+12,n),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=t();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 te=new class{zipObj={};add(r,t){const a=n.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:t}])}emit(r){const t=`[fflate.zip:${r}]`;console.time(t);const o=function(e,r){r||(r={});var t={},n=[];W(e,'',t,r);var o=0,i=0;for(var s in t){var f=t[s],c=f[0],l=f[1],u=0==l.level?0:8,v=(E=J(s)).length,p=l.comment,g=p&&J(p),d=g&&g.length,h=K(l.extra);v>65535&&T(11);var _=u?L(c,l):c,m=_.length,w=U();w.p(c),n.push(Y(l,{size:c.length,crc:w.d(),c:_,f:E,m:g,u:v!=s.length||g&&p.length!=d,o,compression:u})),o+=30+v+h+m,i+=76+2*(v+h)+(d||0)+m}for(var x=new a(i+22),b=o,y=i-o,k=0;k<n.length;++k){var E=n[k];Q(x,E.o,E,E.f,E.u,E.c.length);var M=30+E.f.length+K(E.extra);x.set(E.c,E.o+M),Q(x,o,E,E.f,E.u,E.c.length,E.o,E.m),o+=16+M+(E.m?E.m.length:0)}return V(x,o,n.length,y,b),x}(this.zipObj,{});(r=>{const t=n.dirname(r);e.existsSync(t)||e.mkdirSync(t,{recursive:!0})})(r),
|
|
18
|
+
e.writeFile(r,o,"binary",(()=>{console.timeEnd(t),this.zipObj={}}))}clear(){this.zipObj={}}};let ne=re.sha+"";/256|384|512/.test(ne)||(ne="384");for(const t of re.args){if(e.statSync(t).isFile()){const e=r.execSync(`bash -c "echo -n $(openssl dgst -sha${ne} -binary ${t} | openssl base64 -A)"`,{encoding:"utf8"});te.add(t,e)}}te.emit(re.d||re.dest||"./dist/bundle.zip")})(),module.exports=_we_})();
|
package/index.d.ts
CHANGED
|
@@ -6,8 +6,10 @@
|
|
|
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
|
+
var NsLoader: typeof import("./umd");
|
|
12
|
+
var cslCallback: (() => void) | undefined;
|
|
11
13
|
interface Window {
|
|
12
14
|
cslCallback: (() => void) | undefined;
|
|
13
15
|
}
|
|
@@ -22,5 +24,5 @@ declare let unzipSync: typeof Uz.unzipSync;
|
|
|
22
24
|
declare let cleanUp: () => void;
|
|
23
25
|
declare let setConfig: (base: string, insertionSelector?: string | undefined) => void;
|
|
24
26
|
declare let loadCompressedScript: (baseName: string, log?: (msg: string) => void) => Promise<void>;
|
|
25
|
-
declare const version = "v1.2.
|
|
27
|
+
declare const version = "v1.2.9";
|
|
26
28
|
export { setConfig, loadCompressedScript, cleanUp, unzipSync, version };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "compressed-script-loader",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.9",
|
|
4
|
+
"description": "Reduces network traffic for huge source files built by webpack etc.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./webpack/index.js",
|
|
7
7
|
"module": "./webpack-esm/index.mjs",
|
package/umd/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
|
|
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]),
|
|
4
|
-
;if(n){
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
;
|
|
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,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},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=g(y,9,1),m=g(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},j=(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,y=o.p||0,h=o.b||0,C=o.l,x=o.d,j=o.m,E=o.n;const T=8*r;do{if(!C){p=v(e,y,1);const c=v(e,y+1,3);if(y+=3,!c){const n=4+((y+7)/8|0),c=e[n-4]|e[n-3]<<8,s=n+c;if(s>r){f&&$(0);break}
|
|
6
|
+
i&&u(h+c),t.set(e.subarray(n,s),h),o.b=h+=c,o.p=y=8*s,o.f=p;continue}if(1===c)C=b,x=m,j=9,E=5;else if(2===c){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 c=new n(r),s=new n(19);for(let t=0;t<o;++t)s[l[t]]=v(e,y+3*t,7);y+=3*o;const i=w(s),a=(1<<i)-1,f=g(s,i,1);for(let t=0;t<r;){const n=f[v(e,y,a)];y+=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,y,3),y+=2,n=c[t-1]):17===o?(r=3+v(e,y,7),y+=3):18===o&&(r=11+v(e,y,127),y+=7);r--;)c[t++]=n}}const d=c.subarray(0,t),u=c.subarray(t);j=w(d),E=w(u),C=g(d,j,1),x=g(u,E,1)}else $(1);if(y>T){f&&$(0);break}}i&&u(h+131072);const k=(1<<j)-1,O=(1<<E)-1;let z=y;for(;;z=y){const n=C[S(e,y)&k],o=n>>>4;if(y+=15&n,y>T){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=c[t];n=v(e,y,(1<<r)-1)+a[t],y+=r}const r=x[S(e,y)&O],l=r>>>4;r||$(3),y+=15&r;let p=d[l];if(l>3){const t=s[l];p+=S(e,y)&(1<<t)-1,y+=t}if(y>T){f&&$(0);break}i&&u(h+131072);const g=h+n;for(;h<g;h+=4)t[h]=t[h-p],t[h+1]=t[h+1-p],t[h+2]=t[h+2-p],t[h+3]=t[h+3-p];h=g}}}o.l=C,o.p=z,o.b=h,o.f=p,C&&(p=1,o.m=j,o.d=x,o.n=E)}while(!p);return h===t.length?t:k(t,0,h)},E=(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,O=(e,t)=>T(e,t)+4294967296*T(e,t+4),z=(e,t)=>t+30+E(e,t+26)+E(e,t+28),U=(e,t,n)=>{const o=!(2048&E(e,t+8)),r=E(e,t+28),c=M(e.subarray(t+46,t+46+r),o),s=t+46+r,l=T(e,t+20),[i,a,f]=n&&4294967295===l?P(e,s):[l,T(e,t+24),T(e,t+42)],d=s+E(e,t+30);return[E(e,t+10),i,a,c,s+E(e,t+30)+E(e,t+32),f,M(e.subarray(d,d+E(e,t+32)),o)]},P=(e,t)=>{
|
|
8
|
+
for(;1!=E(e,t);t+=4+E(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!=T(e,r);--r)(!r||e.length-r>65558)&&$(13);let c=E(e,r+8);if(!c)return{};let s=T(e,r+16);const l=4294967295===s;l&&(r=T(e,r-12),101075792!=T(e,r)&&$(13),c=T(e,r+32),s=T(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=z(e,d);if(s=f,!i||i({name:a,size:r,originalSize:c,compression:t,comment:u})){let s;t?8===t?s=j(e.subarray(p,p+r),new n(c)):$(14,"unknown compression type "+t):s=k(e,p,p+r),s&&(o[a]={data:s,comment:u})}}return o},q=()=>{_=void 0,J=F=Y=q=void 0,N=R=void 0,D=B=void 0},D=e=>{const t=/^(?:sha\d{3}-)?([a-z0-9+/=]{44,88})$/i.exec(e);if(t){const 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)=>{const r=()=>{n(),console.log(`script ${t} is ready`)}
|
|
10
|
+
;let c=R?document.querySelector(R).nextSibling:void 0;const s=document.head[c?"insertBefore":"appendChild"](document.createElement("script"),c);if(s.id=t,o){const t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));s.integrity=o,s.crossOrigin="anonymous",s.onload=r,s.src=t}else s.text=e,r()},Y=async(e,t=console.log)=>{const n=e+".zip",o=await fetch(`${N||"."}/${n}`).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 zip: ${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){
|
|
11
|
+
t(`loaded ${n}, decompressing binary...`),console.time(`unzip: ${n}`);const e=B(o);return console.timeEnd(`unzip: ${n}`),t(`${n} decompressed 😃`),new Promise((t=>{const n=Object.keys(e);let o=n.length;const r=()=>{!--o&&t()};for(let t,o=0;t=n[o++];){const n=e[t];J(_.decode(n.data,{stream:!1}),t,r,D(n.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);let n;"object"==typeof e?(F(e.base,e.selector),n=e.load):n=Array.isArray(e)?e:"string"==typeof e?[e]:[];try{const t=[];for(const e of n)t.push(Y(e));Promise.all(t).then((()=>{const t="function"==typeof cslCallback?cslCallback:window[e.callback||"cslCallback"];"function"==typeof t&&t(),q()}))}catch(e){console.error(e)}}}};setTimeout(G,250)
|
|
12
|
+
;const H="v1.2.9";return t})()));
|
package/unzip-sync.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export declare function strFromU8(dat: Uint8Array, latin1?: boolean): string;
|
|
2
|
-
export declare function inflateSync(data: Uint8Array, out?: Uint8Array): Uint8Array;
|
|
3
1
|
export interface FlateError extends Error {
|
|
4
2
|
code: number;
|
|
5
3
|
}
|
|
@@ -8,6 +6,7 @@ export interface UnzipFileInfo {
|
|
|
8
6
|
size: number;
|
|
9
7
|
originalSize: number;
|
|
10
8
|
compression: number;
|
|
9
|
+
comment?: string;
|
|
11
10
|
}
|
|
12
11
|
export declare type UnzipFileFilter = (file: UnzipFileInfo) => boolean;
|
|
13
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 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
|
-
;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
|
|
4
|
-
;for(let e=280;e<288;++e)
|
|
5
|
-
Error.captureStackTrace&&Error.captureStackTrace(o,E),!n)throw o;return o},
|
|
6
|
-
;const o=n>>>4;if(o<16)c[t++]=o;else{let n=0,r=0;for(16
|
|
7
|
-
}while(!g);return
|
|
8
|
-
let o=e[n++];const r=+(o>127)+ +(o>223)+ +(o>239);if(n+r>e.length)return[t,
|
|
9
|
-
;t?8===t?s=
|
|
10
|
-
const n=e+".zip",o=await fetch(`${
|
|
11
|
-
;const e=document.querySelector("script[data-csl-config]");if(e){const t=e.dataset.cslConfig;if(t){const e=JSON.parse(t);let n;"object"==typeof e?(
|
|
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:()=>D,loadCompressedScript:()=>Y,setConfig:()=>N,unzipSync:()=>q,version:()=>H});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 y=(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},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
|
|
4
|
+
;for(let e=280;e<288;++e)h[e]=8;const p=new n(32);for(let e=0;e<32;++e)p[e]=5;const m=y(h,9,1),b=y(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},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},$=["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 o=new Error(t||$[e]);if(o.code=e,
|
|
5
|
+
Error.captureStackTrace&&Error.captureStackTrace(o,E),!n)throw o;return o},x=(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,h=o.p||0,p=o.b||0,C=o.l,$=o.d,x=o.m,O=o.n;const T=8*r;do{if(!C){g=v(e,h,1);const c=v(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&&E(0);break}a&&u(p+c),t.set(e.subarray(n,s),p),o.b=p+=c,o.p=h=8*s,o.f=g;continue}if(1===c)C=m,$=b,x=9,O=5;else if(2===c){const t=v(e,h,31)+257,o=v(e,h+10,15)+4,r=t+v(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]]=v(e,h+3*t,7);h+=3*o;const a=w(s),i=(1<<a)-1,f=y(s,a,1);for(let t=0;t<r;){const n=f[v(e,h,i)];h+=15&n
|
|
6
|
+
;const o=n>>>4;if(o<16)c[t++]=o;else{let n=0,r=0;for(16===o?(r=3+v(e,h,3),h+=2,n=c[t-1]):17===o?(r=3+v(e,h,7),h+=3):18===o&&(r=11+v(e,h,127),h+=7);r--;)c[t++]=n}}const d=c.subarray(0,t),u=c.subarray(t);x=w(d),O=w(u),C=y(d,x,1),$=y(u,O,1)}else E(1);if(h>T){f&&E(0);break}}a&&u(p+131072);const k=(1<<x)-1,z=(1<<O)-1;let j=h;for(;;j=h){const n=C[S(e,h)&k],o=n>>>4;if(h+=15&n,h>T){f&&E(0);break}if(n||E(2),o<256)t[p++]=o;else{if(256===o){j=h,C=void 0;break}{let n=o-254;if(o>264){const t=o-257,r=c[t];n=v(e,h,(1<<r)-1)+i[t],h+=r}const r=$[S(e,h)&z],l=r>>>4;r||E(3),h+=15&r;let g=d[l];if(l>3){const t=s[l];g+=S(e,h)&(1<<t)-1,h+=t}if(h>T){f&&E(0);break}a&&u(p+131072);const y=p+n;for(;p<y;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=y}}}o.l=C,o.p=j,o.b=p,o.f=g,C&&(g=1,o.m=x,o.d=$,
|
|
7
|
+
o.n=O)}while(!g);return p===t.length?t:k(t,0,p)},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),j=(e,t)=>t+30+O(e,t+26)+O(e,t+28),U=(e,t,n)=>{const o=!(2048&O(e,t+8)),r=O(e,t+28),c=L(e.subarray(t+46,t+46+r),o),s=t+46+r,l=T(e,t+20),[a,i,f]=n&&4294967295===l?P(e,s):[l,T(e,t+24),T(e,t+42)],d=s+O(e,t+30);return[O(e,t+10),a,i,c,s+O(e,t+30)+O(e,t+32),f,L(e.subarray(d,d+O(e,t+32)),o)]},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 M=new n(0);try{const e=new TextDecoder;e.decode(M,{stream:!0}),A=e}catch{}function L(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 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&&E(8),t}}let R,_,B=new TextDecoder,q=function(e,t){const o={};let r=e.length-22;for(;101010256!=T(e,r);--r)(!r||e.length-r>65558)&&E(13);let c=O(e,r+8);if(!c)return{};let s=T(e,r+16);const l=4294967295===s;l&&(r=T(e,r-12),101075792!=T(e,r)&&E(13),c=T(e,r+32),s=T(e,r+48));const a=t&&t.filter;for(let t=0;t<c;++t){const[t,r,c,i,f,d,u]=U(e,s,l),g=j(e,d);if(s=f,!a||a({name:i,size:r,originalSize:c,compression:t,comment:u
|
|
9
|
+
})){let s;t?8===t?s=x(e.subarray(g,g+r),new n(c)):E(14,"unknown compression type "+t):s=k(e,g,g+r),s&&(o[i]={data:s,comment:u})}}return o},D=()=>{B=void 0,J=N=Y=D=void 0,R=_=void 0,F=q=void 0},F=e=>{const t=/^(?:sha\d{3}-)?([a-z0-9+/=]{44,88})$/i.exec(e);if(t){const 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,o)=>{const r=()=>{n(),console.log(`script ${t} is ready`)};let c=_?document.querySelector(_).nextSibling:void 0;const s=document.head[c?"insertBefore":"appendChild"](document.createElement("script"),c);if(s.id=t,o){const t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));s.integrity=o,s.crossOrigin="anonymous",s.onload=r,s.src=t}else s.text=e,r()},Y=async(e,t=console.log)=>{
|
|
10
|
+
const n=e+".zip",o=await fetch(`${R||"."}/${n}`).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 zip: ${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 ${n}, decompressing binary...`),console.time(`unzip: ${n}`);const e=q(o);return console.timeEnd(`unzip: ${n}`),t(`${n} decompressed 😃`),new Promise((t=>{const n=Object.keys(e);let o=n.length;const r=()=>{!--o&&t()};for(let t,o=0;t=n[o++];){const n=e[t];J(B.decode(n.data,{stream:!1}),t,r,F(n.comment))}}))}},G=()=>{G=void 0
|
|
11
|
+
;const e=document.querySelector("script[data-csl-config]");if(e){const t=e.dataset.cslConfig;if(t){const e=JSON.parse(t);let n;"object"==typeof e?(N(e.base,e.selector),n=e.load):n=Array.isArray(e)?e:"string"==typeof e?[e]:[];try{const t=[];for(const e of n)t.push(Y(e));Promise.all(t).then((()=>{const t="function"==typeof cslCallback?cslCallback:window[e.callback||"cslCallback"];"function"==typeof t&&t(),D()}))}catch(e){console.error(e)}}}};setTimeout(G,250);const H="v1.2.9";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 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:()=>
|
|
3
|
-
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
|
|
4
|
-
const n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},S=(e,t,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const o=!(2048
|
|
8
|
-
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
|
|
9
|
-
|
|
10
|
-
;for(;;){const e=await o.read();if(e.done)break;s.set(e.value,
|
|
11
|
-
;try{const t=[];for(const e of n)t.push(
|
|
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:()=>D,aN:()=>_,v6:()=>G,GZ:()=>q,i8:()=>Y});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),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,
|
|
3
|
+
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 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[g[s]>>>n]=o}}else for(l=new o(r),c=0;c<r;++c)e[c]&&(l[c]=g[a[e[c]-1]++]>>>15-e[c]);return l},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 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 o=t/8|0;return(e[o]|e[o+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,o,,r],S=(e,t,n)=>{(!t||t<0)&&(t=0),(!n||n>e.length)&&(n=e.length);const o=new k[e.BYTES_PER_ELEMENT](n-t);return o.set(e.subarray(t,n)),o},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 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
|
|
5
|
+
}};let g=o.f||0,p=o.p||0,y=o.b||0,k=o.l,x=o.d,E=o.m,z=o.n;const O=8*r;do{if(!k){g=v(e,p,1);const c=v(e,p+1,3);if(p+=3,!c){const n=4+((p+7)/8|0),c=e[n-4]|e[n-3]<<8,s=n+c;if(s>r){f&&$(0);break}l&&u(y+c),t.set(e.subarray(n,s),y),o.b=y+=c,o.p=p=8*s,o.f=g;continue}if(1===c)k=m,x=b,E=9,z=5;else if(2===c){const t=v(e,p,31)+257,o=v(e,p+10,15)+4,r=t+v(e,p+5,31)+1;p+=14;const c=new n(r),s=new n(19);for(let t=0;t<o;++t)s[a[t]]=v(e,p+3*t,7);p+=3*o;const l=w(s),i=(1<<l)-1,f=h(s,l,1);for(let t=0;t<r;){const n=f[v(e,p,i)];p+=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,p,3),p+=2,n=c[t-1]):17===o?(r=3+v(e,p,7),p+=3):18===o&&(r=11+v(e,p,127),p+=7);r--;)c[t++]=n}}const d=c.subarray(0,t),u=c.subarray(t);E=w(d),z=w(u),k=h(d,E,1),x=h(u,z,1)}else $(1);if(p>O){f&&$(0);break}}
|
|
6
|
+
l&&u(y+131072);const S=(1<<E)-1,T=(1<<z)-1;let U=p;for(;;U=p){const n=k[C(e,p)&S],o=n>>>4;if(p+=15&n,p>O){f&&$(0);break}if(n||$(2),o<256)t[y++]=o;else{if(256===o){U=p,k=void 0;break}{let n=o-254;if(o>264){const t=o-257,r=c[t];n=v(e,p,(1<<r)-1)+i[t],p+=r}const r=x[C(e,p)&T],a=r>>>4;r||$(3),p+=15&r;let g=d[a];if(a>3){const t=s[a];g+=C(e,p)&(1<<t)-1,p+=t}if(p>O){f&&$(0);break}l&&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}}}o.l=k,o.p=U,o.b=y,o.f=g,k&&(g=1,o.m=E,o.d=x,o.n=z)}while(!g);return y===t.length?t:S(t,0,y)},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),j=(e,t,n)=>{
|
|
7
|
+
const o=!(2048&z(e,t+8)),r=z(e,t+28),c=N(e.subarray(t+46,t+46+r),o),s=t+46+r,a=O(e,t+20),[l,i,f]=n&&4294967295===a?A(e,s):[a,O(e,t+24),O(e,t+42)],d=s+z(e,t+30);return[z(e,t+10),l,i,c,s+z(e,t+30)+z(e,t+32),f,N(e.subarray(d,d+z(e,t+32)),o)]},A=(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 L;const P=new n(0);try{const e=new TextDecoder;e.decode(P,{stream:!0}),L=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(L)return L.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,
|
|
8
|
+
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 R,B,M=new TextDecoder,q=function(e,t){const o={};let r=e.length-22;for(;101010256!=O(e,r);--r)(!r||e.length-r>65558)&&$(13);let c=z(e,r+8);if(!c)return{};let s=O(e,r+16);const a=4294967295===s;a&&(r=O(e,r-12),101075792!=O(e,r)&&$(13),c=O(e,r+32),s=O(e,r+48));const l=t&&t.filter;for(let t=0;t<c;++t){const[t,r,c,i,f,d,u]=j(e,s,a),g=U(e,d);if(s=f,!l||l({name:i,size:r,originalSize:c,compression:t,comment:u})){let s;t?8===t?s=E(e.subarray(g,g+r),new n(c)):$(14,"unknown compression type "+t):s=S(e,g,g+r),s&&(o[i]={data:s,comment:u})}}return o},D=()=>{M=void 0,Z=G=_=D=void 0,
|
|
9
|
+
R=B=void 0,F=q=void 0},F=e=>{const t=/^(?:sha\d{3}-)?([a-z0-9+/=]{44,88})$/i.exec(e);if(t){const n=(e=t[1]).length;if(!(88^n&&64^n&&44^n))return`sha${64==n?384:88==n?512:256}-${e}`}},G=(e,t)=>{R=e,B=t||""},Z=(e,t,n,o)=>{const r=()=>{n(),console.log(`script ${t} is ready`)};let c=B?document.querySelector(B).nextSibling:void 0;const s=document.head[c?"insertBefore":"appendChild"](document.createElement("script"),c);if(s.id=t,o){const t=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));s.integrity=o,s.crossOrigin="anonymous",s.onload=r,s.src=t}else s.text=e,r()},_=async(e,t=console.log)=>{const n=e+".zip",o=await fetch(`${R||"."}/${n}`).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
|
|
10
|
+
;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 zip: ${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){t(`loaded ${n}, decompressing binary...`),console.time(`unzip: ${n}`);const e=q(o);return console.timeEnd(`unzip: ${n}`),t(`${n} decompressed 😃`),new Promise((t=>{const n=Object.keys(e);let o=n.length;const r=()=>{!--o&&t()};for(let t,o=0;t=n[o++];){const n=e[t];Z(M.decode(n.data,{stream:!1}),t,r,F(n.comment))}}))}},J=()=>{J=void 0;const e=document.querySelector("script[data-csl-config]");if(e){const t=e.dataset.cslConfig;if(t){const e=JSON.parse(t);let n;"object"==typeof e?(G(e.base,e.selector),
|
|
11
|
+
n=e.load):n=Array.isArray(e)?e:"string"==typeof e?[e]:[];try{const t=[];for(const e of n)t.push(_(e));Promise.all(t).then((()=>{const t="function"==typeof cslCallback?cslCallback:window[e.callback||"cslCallback"];"function"==typeof t&&t(),D()}))}catch(e){console.error(e)}}}};setTimeout(J,250);const Y="v1.2.9";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};
|