@php-wasm/progress 0.5.6 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={};exports.default=e;
|
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var w=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var a=(s,e,t)=>(w(s,e,"read from private field"),t?t.call(s):e.get(s)),h=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)},_=(s,e,t,r)=>(w(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t);var E=(s,e,t,r)=>({set _(n){_(s,e,n,t)},get _(){return a(s,e,r)}}),g=(s,e,t)=>(w(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});if(typeof File>"u"){class s extends Blob{constructor(t,r,n){super(t);let i;n!=null&&n.lastModified&&(i=new Date),(!i||isNaN(i.getFullYear()))&&(i=new Date),this.lastModifiedDate=i,this.lastModified=i.getMilliseconds(),this.name=r||""}}global.File=s}function I(s){return new Promise(function(e,t){s.onload=s.onerror=function(r){s.onload=s.onerror=null,r.type==="load"?e(s.result):t(new Error("Failed to read the blob/file"))}})}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const e=new FileReader;return e.readAsArrayBuffer(this),I(e)});typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const e=new FileReader;return e.readAsText(this),I(e)});function x(){const s=new Uint8Array([1,2,3,4]),t=new File([s],"test").stream();try{return t.getReader({mode:"byob"}),!0}catch{return!1}}(typeof Blob.prototype.stream>"u"||!x())&&(Blob.prototype.stream=function(){let s=0;const e=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(t){const r=t.byobRequest.view,i=await e.slice(s,s+r.byteLength).arrayBuffer(),l=new Uint8Array(i);new Uint8Array(r.buffer).set(l);const o=l.byteLength;t.byobRequest.respond(o),s+=o,s>=e.size&&t.close()}})});if(typeof CustomEvent>"u"){class s extends Event{constructor(t,r={}){super(t,r),this.detail=r.detail}initCustomEvent(){}}globalThis.CustomEvent=s}typeof crypto>"u"&&Promise.resolve().then(()=>require("./__vite-browser-external-b3701507.cjs")).then(s=>{global.crypto=s});const A=5*1024*1024;var u,d,v,S,b,L;class F extends EventTarget{constructor(){super();h(this,v);h(this,b);h(this,u,{});h(this,d,{});g(this,v,S).call(this)}expectAssets(t){for(const[r,n]of Object.entries(t)){const i="http://example.com/",o=new URL(r,i).pathname.split("/").pop();o in a(this,u)||(a(this,u)[o]=n),o in a(this,d)||(a(this,d)[o]=0)}}async monitorFetch(t){const r=await t;return T(r,i=>{g(this,b,L).call(this,r.url,i.detail.loaded,i.detail.total)})}}u=new WeakMap,d=new WeakMap,v=new WeakSet,S=function(){const t=WebAssembly.instantiateStreaming;WebAssembly.instantiateStreaming=async(r,...n)=>{const i=await r,l=i.url.substring(new URL(i.url).origin.length+1),o=T(i,({detail:{loaded:c,total:y}})=>g(this,b,L).call(this,l,c,y));return t(o,...n)}},b=new WeakSet,L=function(t,r,n){const i=new URL(t,"http://example.com").pathname.split("/").pop();n||(n=a(this,u)[i]),i in a(this,d)||console.warn(`Registered a download #progress of an unregistered file "${i}". This may cause a sudden **decrease** in the #progress percentage as the total number of bytes increases during the download.`),a(this,d)[i]=r,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:B(a(this,d)),total:B(a(this,u))}}))};function B(s){return Object.values(s).reduce((e,t)=>e+t,0)}function T(s,e){const t=s.headers.get("content-length")||"",r=parseInt(t,10)||A;function n(i,l){e(new CustomEvent("progress",{detail:{loaded:i,total:l}}))}return new Response(new ReadableStream({async start(i){if(!s.body){i.close();return}const l=s.body.getReader();let o=0;for(;;)try{const{done:c,value:y}=await l.read();if(y&&(o+=y.byteLength),c){n(o,o),i.close();break}else n(o,r),i.enqueue(y)}catch(c){console.error({e:c}),i.error(c);break}}}),{status:s.status,statusText:s.statusText,headers:s.headers})}var f,p,m,R;class M extends EventTarget{constructor(){super(...arguments);h(this,m);h(this,f,void 0);h(this,p,void 0);_(this,f,{}),_(this,p,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(t,r=""){const n=++E(this,p)._;return a(this,f)[n]=0,i=>{const{loaded:l,total:o}=(i==null?void 0:i.detail)||{};a(this,f)[n]=l/o*t,g(this,m,R).call(this,this.totalProgress,"REAL_TIME",r)}}slowlyIncrementBy(t){const r=++E(this,p)._;a(this,f)[r]=t,g(this,m,R).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(a(this,f)).reduce((t,r)=>t+r,0)}}f=new WeakMap,p=new WeakMap,m=new WeakSet,R=function(t,r,n){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:t,mode:r,caption:n}}))};const P=1e-5;class C extends EventTarget{constructor({weight:e=1,caption:t="",fillTime:r=4}={}){super(),this._selfWeight=1,this._selfDone=!1,this._selfProgress=0,this._selfCaption="",this._isFilling=!1,this._subTrackers=[],this._weight=e,this._selfCaption=t,this._fillTime=r}stage(e,t=""){if(e||(e=this._selfWeight),this._selfWeight-e<-P)throw new Error(`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`);this._selfWeight-=e;const r=new C({caption:t,weight:e,fillTime:this._fillTime});return this._subTrackers.push(r),r.addEventListener("progress",()=>this.notifyProgress()),r.addEventListener("done",()=>{this.done&&this.notifyDone()}),r}fillSlowly({stopBeforeFinishing:e=!0}={}){if(this._isFilling)return;this._isFilling=!0;const t=100,r=this._fillTime/t;this._fillInterval=setInterval(()=>{this.set(this._selfProgress+1),e&&this._selfProgress>=99&&clearInterval(this._fillInterval)},r)}set(e){this._selfProgress=Math.min(e,100),this.notifyProgress(),this._selfProgress+P>=100&&this.finish()}finish(){this._fillInterval&&clearInterval(this._fillInterval),this._selfDone=!0,this._selfProgress=100,this._isFilling=!1,this._fillInterval=void 0,this.notifyProgress(),this.notifyDone()}get caption(){for(let e=this._subTrackers.length-1;e>=0;e--)if(!this._subTrackers[e].done){const t=this._subTrackers[e].caption;if(t)return t}return this._selfCaption}setCaption(e){this._selfCaption=e,this.notifyProgress()}get done(){return this.progress+P>=100}get progress(){if(this._selfDone)return 100;const e=this._subTrackers.reduce((t,r)=>t+r.progress*r.weight,this._selfProgress*this._selfWeight);return Math.round(e*1e4)/1e4}get weight(){return this._weight}get observer(){return this._progressObserver||(this._progressObserver=e=>{this.set(e)}),this._progressObserver}get loadingListener(){return this._loadingListener||(this._loadingListener=e=>{this.set(e.detail.loaded/e.detail.total*100)}),this._loadingListener}pipe(e){e.setProgress({progress:this.progress,caption:this.caption}),this.addEventListener("progress",t=>{e.setProgress({progress:t.detail.progress,caption:t.detail.caption})}),this.addEventListener("done",()=>{e.setLoaded()})}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}notifyProgress(){const e=this;this.dispatchEvent(new CustomEvent("progress",{detail:{get progress(){return e.progress},get caption(){return e.caption}}}))}notifyDone(){this.dispatchEvent(new CustomEvent("done"))}}exports.EmscriptenDownloadMonitor=F;exports.ProgressObserver=M;exports.ProgressTracker=C;exports.cloneResponseMonitorProgress=T;
|
package/index.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
var
|
|
2
|
-
if (!e.has(
|
|
1
|
+
var w = (s, e, t) => {
|
|
2
|
+
if (!e.has(s))
|
|
3
3
|
throw TypeError("Cannot " + t);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
if (e.has(
|
|
5
|
+
var a = (s, e, t) => (w(s, e, "read from private field"), t ? t.call(s) : e.get(s)), h = (s, e, t) => {
|
|
6
|
+
if (e.has(s))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
|
-
e instanceof WeakSet ? e.add(
|
|
9
|
-
},
|
|
10
|
-
var
|
|
8
|
+
e instanceof WeakSet ? e.add(s) : e.set(s, t);
|
|
9
|
+
}, _ = (s, e, t, i) => (w(s, e, "write to private field"), i ? i.call(s, t) : e.set(s, t), t);
|
|
10
|
+
var E = (s, e, t, i) => ({
|
|
11
11
|
set _(n) {
|
|
12
|
-
|
|
12
|
+
_(s, e, n, t);
|
|
13
13
|
},
|
|
14
14
|
get _() {
|
|
15
|
-
return
|
|
15
|
+
return a(s, e, i);
|
|
16
16
|
}
|
|
17
|
-
}),
|
|
17
|
+
}), g = (s, e, t) => (w(s, e, "access private method"), t);
|
|
18
18
|
if (typeof File > "u") {
|
|
19
|
-
class
|
|
20
|
-
constructor(t,
|
|
19
|
+
class s extends Blob {
|
|
20
|
+
constructor(t, i, n) {
|
|
21
21
|
super(t);
|
|
22
|
-
let
|
|
23
|
-
n != null && n.lastModified && (
|
|
22
|
+
let r;
|
|
23
|
+
n != null && n.lastModified && (r = /* @__PURE__ */ new Date()), (!r || isNaN(r.getFullYear())) && (r = /* @__PURE__ */ new Date()), this.lastModifiedDate = r, this.lastModified = r.getMilliseconds(), this.name = i || "";
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
global.File =
|
|
26
|
+
global.File = s;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function B(s) {
|
|
29
29
|
return new Promise(function(e, t) {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
s.onload = s.onerror = function(i) {
|
|
31
|
+
s.onload = s.onerror = null, i.type === "load" ? e(s.result) : t(new Error("Failed to read the blob/file"));
|
|
32
32
|
};
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
36
36
|
const e = new FileReader();
|
|
37
|
-
return e.readAsArrayBuffer(this),
|
|
37
|
+
return e.readAsArrayBuffer(this), B(e);
|
|
38
38
|
});
|
|
39
39
|
typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
40
40
|
const e = new FileReader();
|
|
41
|
-
return e.readAsText(this),
|
|
41
|
+
return e.readAsText(this), B(e);
|
|
42
42
|
});
|
|
43
43
|
function A() {
|
|
44
|
-
const
|
|
44
|
+
const s = new Uint8Array([1, 2, 3, 4]), t = new File([s], "test").stream();
|
|
45
45
|
try {
|
|
46
46
|
return t.getReader({ mode: "byob" }), !0;
|
|
47
47
|
} catch {
|
|
@@ -49,7 +49,7 @@ function A() {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
(typeof Blob.prototype.stream > "u" || !A()) && (Blob.prototype.stream = function() {
|
|
52
|
-
let
|
|
52
|
+
let s = 0;
|
|
53
53
|
const e = this;
|
|
54
54
|
return new ReadableStream({
|
|
55
55
|
type: "bytes",
|
|
@@ -57,39 +57,36 @@ function A() {
|
|
|
57
57
|
// this if needed.
|
|
58
58
|
autoAllocateChunkSize: 512 * 1024,
|
|
59
59
|
async pull(t) {
|
|
60
|
-
const
|
|
61
|
-
new Uint8Array(
|
|
62
|
-
const o =
|
|
63
|
-
t.byobRequest.respond(o),
|
|
60
|
+
const i = t.byobRequest.view, r = await e.slice(s, s + i.byteLength).arrayBuffer(), l = new Uint8Array(r);
|
|
61
|
+
new Uint8Array(i.buffer).set(l);
|
|
62
|
+
const o = l.byteLength;
|
|
63
|
+
t.byobRequest.respond(o), s += o, s >= e.size && t.close();
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
if (typeof CustomEvent > "u") {
|
|
68
|
-
class
|
|
69
|
-
constructor(t,
|
|
70
|
-
super(t,
|
|
68
|
+
class s extends Event {
|
|
69
|
+
constructor(t, i = {}) {
|
|
70
|
+
super(t, i), this.detail = i.detail;
|
|
71
71
|
}
|
|
72
72
|
initCustomEvent() {
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
globalThis.CustomEvent =
|
|
75
|
+
globalThis.CustomEvent = s;
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
typeof crypto > "u" && import("./__vite-browser-external-2447137e.js").then((s) => {
|
|
78
|
+
global.crypto = s;
|
|
79
|
+
});
|
|
80
|
+
const F = 5 * 1024 * 1024;
|
|
81
|
+
var u, d, v, I, b, P;
|
|
82
|
+
class k extends EventTarget {
|
|
83
|
+
constructor() {
|
|
81
84
|
super();
|
|
82
85
|
/**
|
|
83
86
|
* Replaces the default WebAssembly.instantiateStreaming with a version
|
|
84
87
|
* that monitors the download #progress.
|
|
85
88
|
*/
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Creates a `dataFileDownloads` Proxy object that can be passed
|
|
89
|
-
* to `startPHP` to monitor the download #progress of the data
|
|
90
|
-
* dependencies.
|
|
91
|
-
*/
|
|
92
|
-
d(this, E);
|
|
89
|
+
h(this, v);
|
|
93
90
|
/**
|
|
94
91
|
* Notifies about the download #progress of a file.
|
|
95
92
|
*
|
|
@@ -97,159 +94,139 @@ class W extends EventTarget {
|
|
|
97
94
|
* @param loaded The number of bytes of that file loaded so far.
|
|
98
95
|
* @param fileSize The total number of bytes in the loaded file.
|
|
99
96
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
h(this, b);
|
|
98
|
+
h(this, u, {});
|
|
99
|
+
h(this, d, {});
|
|
100
|
+
g(this, v, I).call(this);
|
|
104
101
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
102
|
+
expectAssets(t) {
|
|
103
|
+
for (const [i, n] of Object.entries(t)) {
|
|
104
|
+
const r = "http://example.com/", o = new URL(i, r).pathname.split("/").pop();
|
|
105
|
+
o in a(this, u) || (a(this, u)[o] = n), o in a(this, d) || (a(this, d)[o] = 0);
|
|
106
|
+
}
|
|
109
107
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
o in s ? s[o] : 0,
|
|
116
|
-
n.dependenciesTotalSize
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
return s;
|
|
120
|
-
}, {})), y(this, p, Object.fromEntries(
|
|
121
|
-
Object.entries(l(this, g)).map(([s]) => [s, 0])
|
|
122
|
-
));
|
|
108
|
+
async monitorFetch(t) {
|
|
109
|
+
const i = await t;
|
|
110
|
+
return C(i, (r) => {
|
|
111
|
+
g(this, b, P).call(this, i.url, r.detail.loaded, r.detail.total);
|
|
112
|
+
});
|
|
123
113
|
}
|
|
124
114
|
}
|
|
125
|
-
|
|
115
|
+
u = new WeakMap(), d = new WeakMap(), v = new WeakSet(), I = function() {
|
|
126
116
|
const t = WebAssembly.instantiateStreaming;
|
|
127
|
-
WebAssembly.instantiateStreaming = async (
|
|
128
|
-
const
|
|
129
|
-
new URL(
|
|
130
|
-
), o =
|
|
131
|
-
|
|
132
|
-
({ detail: { loaded:
|
|
117
|
+
WebAssembly.instantiateStreaming = async (i, ...n) => {
|
|
118
|
+
const r = await i, l = r.url.substring(
|
|
119
|
+
new URL(r.url).origin.length + 1
|
|
120
|
+
), o = C(
|
|
121
|
+
r,
|
|
122
|
+
({ detail: { loaded: c, total: y } }) => g(this, b, P).call(this, l, c, y)
|
|
133
123
|
);
|
|
134
124
|
return t(o, ...n);
|
|
135
125
|
};
|
|
136
|
-
},
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return u(o = t, b, v).call(o, i, a.loaded, a.total), n[i] = new Proxy(JSON.parse(JSON.stringify(a)), {
|
|
142
|
-
set(h, c, M) {
|
|
143
|
-
var x;
|
|
144
|
-
return h[c] = M, u(x = t, b, v).call(x, i, h.loaded, h.total), !0;
|
|
145
|
-
}
|
|
146
|
-
}), !0;
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}, b = new WeakSet(), v = function(t, s, n) {
|
|
150
|
-
const i = new URL(t, "http://example.com").pathname.split("/").pop();
|
|
151
|
-
n || (n = l(this, g)[i]), i in l(this, p) || console.warn(
|
|
152
|
-
`Registered a download #progress of an unregistered file "${i}". This may cause a sudden **decrease** in the #progress percentage as the total number of bytes increases during the download.`
|
|
153
|
-
), l(this, p)[i] = s, this.dispatchEvent(
|
|
126
|
+
}, b = new WeakSet(), P = function(t, i, n) {
|
|
127
|
+
const r = new URL(t, "http://example.com").pathname.split("/").pop();
|
|
128
|
+
n || (n = a(this, u)[r]), r in a(this, d) || console.warn(
|
|
129
|
+
`Registered a download #progress of an unregistered file "${r}". This may cause a sudden **decrease** in the #progress percentage as the total number of bytes increases during the download.`
|
|
130
|
+
), a(this, d)[r] = i, this.dispatchEvent(
|
|
154
131
|
new CustomEvent("progress", {
|
|
155
132
|
detail: {
|
|
156
|
-
loaded:
|
|
157
|
-
total:
|
|
133
|
+
loaded: R(a(this, d)),
|
|
134
|
+
total: R(a(this, u))
|
|
158
135
|
}
|
|
159
136
|
})
|
|
160
137
|
);
|
|
161
138
|
};
|
|
162
|
-
function
|
|
163
|
-
return Object.values(
|
|
139
|
+
function R(s) {
|
|
140
|
+
return Object.values(s).reduce((e, t) => e + t, 0);
|
|
164
141
|
}
|
|
165
|
-
function
|
|
166
|
-
const t =
|
|
167
|
-
function n(
|
|
142
|
+
function C(s, e) {
|
|
143
|
+
const t = s.headers.get("content-length") || "", i = parseInt(t, 10) || F;
|
|
144
|
+
function n(r, l) {
|
|
168
145
|
e(
|
|
169
146
|
new CustomEvent("progress", {
|
|
170
147
|
detail: {
|
|
171
|
-
loaded:
|
|
172
|
-
total:
|
|
148
|
+
loaded: r,
|
|
149
|
+
total: l
|
|
173
150
|
}
|
|
174
151
|
})
|
|
175
152
|
);
|
|
176
153
|
}
|
|
177
154
|
return new Response(
|
|
178
155
|
new ReadableStream({
|
|
179
|
-
async start(
|
|
180
|
-
if (!
|
|
181
|
-
|
|
156
|
+
async start(r) {
|
|
157
|
+
if (!s.body) {
|
|
158
|
+
r.close();
|
|
182
159
|
return;
|
|
183
160
|
}
|
|
184
|
-
const
|
|
161
|
+
const l = s.body.getReader();
|
|
185
162
|
let o = 0;
|
|
186
163
|
for (; ; )
|
|
187
164
|
try {
|
|
188
|
-
const { done:
|
|
189
|
-
if (
|
|
190
|
-
n(o, o),
|
|
165
|
+
const { done: c, value: y } = await l.read();
|
|
166
|
+
if (y && (o += y.byteLength), c) {
|
|
167
|
+
n(o, o), r.close();
|
|
191
168
|
break;
|
|
192
169
|
} else
|
|
193
|
-
n(o,
|
|
194
|
-
} catch (
|
|
195
|
-
console.error({ e:
|
|
170
|
+
n(o, i), r.enqueue(y);
|
|
171
|
+
} catch (c) {
|
|
172
|
+
console.error({ e: c }), r.error(c);
|
|
196
173
|
break;
|
|
197
174
|
}
|
|
198
175
|
}
|
|
199
176
|
}),
|
|
200
177
|
{
|
|
201
|
-
status:
|
|
202
|
-
statusText:
|
|
203
|
-
headers:
|
|
178
|
+
status: s.status,
|
|
179
|
+
statusText: s.statusText,
|
|
180
|
+
headers: s.headers
|
|
204
181
|
}
|
|
205
182
|
);
|
|
206
183
|
}
|
|
207
|
-
var f,
|
|
208
|
-
class
|
|
184
|
+
var f, p, m, T;
|
|
185
|
+
class M extends EventTarget {
|
|
209
186
|
constructor() {
|
|
210
187
|
super(...arguments);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
188
|
+
h(this, m);
|
|
189
|
+
h(this, f, void 0);
|
|
190
|
+
h(this, p, void 0);
|
|
191
|
+
_(this, f, {}), _(this, p, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
|
|
215
192
|
}
|
|
216
|
-
partialObserver(t,
|
|
217
|
-
const n = ++
|
|
218
|
-
return
|
|
219
|
-
const { loaded:
|
|
220
|
-
|
|
193
|
+
partialObserver(t, i = "") {
|
|
194
|
+
const n = ++E(this, p)._;
|
|
195
|
+
return a(this, f)[n] = 0, (r) => {
|
|
196
|
+
const { loaded: l, total: o } = (r == null ? void 0 : r.detail) || {};
|
|
197
|
+
a(this, f)[n] = l / o * t, g(this, m, T).call(this, this.totalProgress, "REAL_TIME", i);
|
|
221
198
|
};
|
|
222
199
|
}
|
|
223
200
|
slowlyIncrementBy(t) {
|
|
224
|
-
const
|
|
225
|
-
|
|
201
|
+
const i = ++E(this, p)._;
|
|
202
|
+
a(this, f)[i] = t, g(this, m, T).call(this, this.totalProgress, "SLOWLY_INCREMENT");
|
|
226
203
|
}
|
|
227
204
|
get totalProgress() {
|
|
228
|
-
return Object.values(
|
|
229
|
-
(t,
|
|
205
|
+
return Object.values(a(this, f)).reduce(
|
|
206
|
+
(t, i) => t + i,
|
|
230
207
|
0
|
|
231
208
|
);
|
|
232
209
|
}
|
|
233
210
|
}
|
|
234
|
-
f = new WeakMap(),
|
|
211
|
+
f = new WeakMap(), p = new WeakMap(), m = new WeakSet(), T = function(t, i, n) {
|
|
235
212
|
this.dispatchEvent(
|
|
236
213
|
new CustomEvent("progress", {
|
|
237
214
|
detail: {
|
|
238
215
|
progress: t,
|
|
239
|
-
mode:
|
|
216
|
+
mode: i,
|
|
240
217
|
caption: n
|
|
241
218
|
}
|
|
242
219
|
})
|
|
243
220
|
);
|
|
244
221
|
};
|
|
245
|
-
const
|
|
246
|
-
class
|
|
222
|
+
const L = 1e-5;
|
|
223
|
+
class x extends EventTarget {
|
|
247
224
|
constructor({
|
|
248
225
|
weight: e = 1,
|
|
249
226
|
caption: t = "",
|
|
250
|
-
fillTime:
|
|
227
|
+
fillTime: i = 4
|
|
251
228
|
} = {}) {
|
|
252
|
-
super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight = e, this._selfCaption = t, this._fillTime =
|
|
229
|
+
super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight = e, this._selfCaption = t, this._fillTime = i;
|
|
253
230
|
}
|
|
254
231
|
/**
|
|
255
232
|
* Creates a new sub-tracker with a specific weight.
|
|
@@ -287,19 +264,19 @@ class I extends EventTarget {
|
|
|
287
264
|
* ```
|
|
288
265
|
*/
|
|
289
266
|
stage(e, t = "") {
|
|
290
|
-
if (e || (e = this._selfWeight), this._selfWeight - e < -
|
|
267
|
+
if (e || (e = this._selfWeight), this._selfWeight - e < -L)
|
|
291
268
|
throw new Error(
|
|
292
269
|
`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
|
|
293
270
|
);
|
|
294
271
|
this._selfWeight -= e;
|
|
295
|
-
const
|
|
272
|
+
const i = new x({
|
|
296
273
|
caption: t,
|
|
297
274
|
weight: e,
|
|
298
275
|
fillTime: this._fillTime
|
|
299
276
|
});
|
|
300
|
-
return this._subTrackers.push(
|
|
277
|
+
return this._subTrackers.push(i), i.addEventListener("progress", () => this.notifyProgress()), i.addEventListener("done", () => {
|
|
301
278
|
this.done && this.notifyDone();
|
|
302
|
-
}),
|
|
279
|
+
}), i;
|
|
303
280
|
}
|
|
304
281
|
/**
|
|
305
282
|
* Fills the progress bar slowly over time, simulating progress.
|
|
@@ -323,13 +300,13 @@ class I extends EventTarget {
|
|
|
323
300
|
if (this._isFilling)
|
|
324
301
|
return;
|
|
325
302
|
this._isFilling = !0;
|
|
326
|
-
const t = 100,
|
|
303
|
+
const t = 100, i = this._fillTime / t;
|
|
327
304
|
this._fillInterval = setInterval(() => {
|
|
328
305
|
this.set(this._selfProgress + 1), e && this._selfProgress >= 99 && clearInterval(this._fillInterval);
|
|
329
|
-
},
|
|
306
|
+
}, i);
|
|
330
307
|
}
|
|
331
308
|
set(e) {
|
|
332
|
-
this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress +
|
|
309
|
+
this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + L >= 100 && this.finish();
|
|
333
310
|
}
|
|
334
311
|
finish() {
|
|
335
312
|
this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
|
|
@@ -347,13 +324,13 @@ class I extends EventTarget {
|
|
|
347
324
|
this._selfCaption = e, this.notifyProgress();
|
|
348
325
|
}
|
|
349
326
|
get done() {
|
|
350
|
-
return this.progress +
|
|
327
|
+
return this.progress + L >= 100;
|
|
351
328
|
}
|
|
352
329
|
get progress() {
|
|
353
330
|
if (this._selfDone)
|
|
354
331
|
return 100;
|
|
355
332
|
const e = this._subTrackers.reduce(
|
|
356
|
-
(t,
|
|
333
|
+
(t, i) => t + i.progress * i.weight,
|
|
357
334
|
this._selfProgress * this._selfWeight
|
|
358
335
|
);
|
|
359
336
|
return Math.round(e * 1e4) / 1e4;
|
|
@@ -410,8 +387,8 @@ class I extends EventTarget {
|
|
|
410
387
|
}
|
|
411
388
|
}
|
|
412
389
|
export {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
390
|
+
k as EmscriptenDownloadMonitor,
|
|
391
|
+
M as ProgressObserver,
|
|
392
|
+
x as ProgressTracker,
|
|
393
|
+
C as cloneResponseMonitorProgress
|
|
417
394
|
};
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export interface MonitoredModule {
|
|
2
|
-
dependencyFilename: string;
|
|
3
|
-
dependenciesTotalSize: number;
|
|
4
|
-
}
|
|
5
1
|
/**
|
|
6
2
|
* Monitors the download #progress of Emscripten modules
|
|
7
3
|
*
|
|
@@ -21,11 +17,9 @@ export interface MonitoredModule {
|
|
|
21
17
|
*/
|
|
22
18
|
export declare class EmscriptenDownloadMonitor extends EventTarget {
|
|
23
19
|
#private;
|
|
24
|
-
constructor(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
setModules(modules: MonitoredModule[]): void;
|
|
20
|
+
constructor();
|
|
21
|
+
expectAssets(assets: Record<string, number>): void;
|
|
22
|
+
monitorFetch(fetchPromise: Promise<Response>): Promise<Response>;
|
|
29
23
|
}
|
|
30
24
|
export default EmscriptenDownloadMonitor;
|
|
31
25
|
export interface DownloadProgress {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/progress",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "PHP.wasm – loading progress monitoring",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"main": "index.js",
|
|
31
31
|
"types": "index.d.ts",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "171b22b853786b8912d9624ea064eaa1e985e96b",
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=18.18.2",
|
|
35
35
|
"npm": ">=8.11.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@php-wasm/node-polyfills": "0.
|
|
38
|
+
"@php-wasm/node-polyfills": "0.6.1"
|
|
39
39
|
}
|
|
40
40
|
}
|