@php-wasm/progress 0.6.5 → 0.6.7
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/index.cjs +1 -1
- package/index.js +194 -184
- package/package.json +3 -3
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=(r,t,e)=>{if(!t.has(r))throw TypeError("Cannot "+e)};var a=(r,t,e)=>(E(r,t,"read from private field"),e?e.call(r):t.get(r)),f=(r,t,e)=>{if(t.has(r))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(r):t.set(r,e)},_=(r,t,e,s)=>(E(r,t,"write to private field"),s?s.call(r,e):t.set(r,e),e);var w=(r,t,e,s)=>({set _(n){_(r,t,n,e)},get _(){return a(r,t,s)}}),p=(r,t,e)=>(E(r,t,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=function(){var r;return typeof process<"u"&&((r=process.release)==null?void 0:r.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(C==="NODE"){let r=function(e){return new Promise(function(s,n){e.onload=e.onerror=function(i){e.onload=e.onerror=null,i.type==="load"?s(e.result):n(new Error("Failed to read the blob/file"))}})},t=function(){const e=new Uint8Array([1,2,3,4]),n=new File([e],"test").stream();try{return n.getReader({mode:"byob"}),!0}catch{return!1}};if(typeof File>"u"){class e extends Blob{constructor(n,i,l){super(n);let o;l!=null&&l.lastModified&&(o=new Date),(!o||isNaN(o.getFullYear()))&&(o=new Date),this.lastModifiedDate=o,this.lastModified=o.getMilliseconds(),this.name=i||""}}global.File=e}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const s=new FileReader;return s.readAsArrayBuffer(this),r(s)}),typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const s=new FileReader;return s.readAsText(this),r(s)}),(typeof Blob.prototype.stream>"u"||!t())&&(Blob.prototype.stream=function(){let e=0;const s=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(n){const i=n.byobRequest.view,o=await s.slice(e,e+i.byteLength).arrayBuffer(),h=new Uint8Array(o);new Uint8Array(i.buffer).set(h);const d=h.byteLength;n.byobRequest.respond(d),e+=d,e>=s.size&&n.close()}})})}if(C==="NODE"&&typeof CustomEvent>"u"){class r extends Event{constructor(e,s={}){super(e,s),this.detail=s.detail}initCustomEvent(){}}globalThis.CustomEvent=r}const I=5*1024*1024;var g,u,v,S,b,L;class k extends EventTarget{constructor(){super();f(this,v);f(this,b);f(this,g,{});f(this,u,{});p(this,v,S).call(this)}expectAssets(e){for(const[s,n]of Object.entries(e)){const i="http://example.com/",o=new URL(s,i).pathname.split("/").pop();o in a(this,g)||(a(this,g)[o]=n),o in a(this,u)||(a(this,u)[o]=0)}}async monitorFetch(e){const s=await e;return R(s,i=>{p(this,b,L).call(this,s.url,i.detail.loaded,i.detail.total)})}}g=new WeakMap,u=new WeakMap,v=new WeakSet,S=function(){const e=WebAssembly.instantiateStreaming;WebAssembly.instantiateStreaming=async(s,...n)=>{const i=await s,l=i.url.substring(new URL(i.url).origin.length+1),o=R(i,({detail:{loaded:h,total:d}})=>p(this,b,L).call(this,l,h,d));return e(o,...n)}},b=new WeakSet,L=function(e,s,n){const i=new URL(e,"http://example.com").pathname.split("/").pop();n||(n=a(this,g)[i]),i in a(this,u)||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,u)[i]=s,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:B(a(this,u)),total:B(a(this,g))}}))};function B(r){return Object.values(r).reduce((t,e)=>t+e,0)}function R(r,t){const e=r.headers.get("content-length")||"",s=parseInt(e,10)||I;function n(i,l){t(new CustomEvent("progress",{detail:{loaded:i,total:l}}))}return new Response(new ReadableStream({async start(i){if(!r.body){i.close();return}const l=r.body.getReader();let o=0;for(;;)try{const{done:h,value:d}=await l.read();if(d&&(o+=d.byteLength),h){n(o,o),i.close();break}else n(o,s),i.enqueue(d)}catch(h){console.error({e:h}),i.error(h);break}}}),{status:r.status,statusText:r.statusText,headers:r.headers})}var c,y,m,T;class x extends EventTarget{constructor(){super(...arguments);f(this,m);f(this,c,void 0);f(this,y,void 0);_(this,c,{}),_(this,y,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(e,s=""){const n=++w(this,y)._;return a(this,c)[n]=0,i=>{const{loaded:l,total:o}=(i==null?void 0:i.detail)||{};a(this,c)[n]=l/o*e,p(this,m,T).call(this,this.totalProgress,"REAL_TIME",s)}}slowlyIncrementBy(e){const s=++w(this,y)._;a(this,c)[s]=e,p(this,m,T).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(a(this,c)).reduce((e,s)=>e+s,0)}}c=new WeakMap,y=new WeakMap,m=new WeakSet,T=function(e,s,n){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:e,mode:s,caption:n}}))};const P=1e-5;class O extends EventTarget{constructor({weight:t=1,caption:e="",fillTime:s=4}={}){super(),this._selfWeight=1,this._selfDone=!1,this._selfProgress=0,this._selfCaption="",this._isFilling=!1,this._subTrackers=[],this._weight=t,this._selfCaption=e,this._fillTime=s}stage(t,e=""){if(t||(t=this._selfWeight),this._selfWeight-t<-P)throw new Error(`Cannot add a stage with weight ${t} as the total weight of registered stages would exceed 1.`);this._selfWeight-=t;const s=new O({caption:e,weight:t,fillTime:this._fillTime});return this._subTrackers.push(s),s.addEventListener("progress",()=>this.notifyProgress()),s.addEventListener("done",()=>{this.done&&this.notifyDone()}),s}fillSlowly({stopBeforeFinishing:t=!0}={}){if(this._isFilling)return;this._isFilling=!0;const e=100,s=this._fillTime/e;this._fillInterval=setInterval(()=>{this.set(this._selfProgress+1),t&&this._selfProgress>=99&&clearInterval(this._fillInterval)},s)}set(t){this._selfProgress=Math.min(t,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 t=this._subTrackers.length-1;t>=0;t--)if(!this._subTrackers[t].done){const e=this._subTrackers[t].caption;if(e)return e}return this._selfCaption}setCaption(t){this._selfCaption=t,this.notifyProgress()}get done(){return this.progress+P>=100}get progress(){if(this._selfDone)return 100;const t=this._subTrackers.reduce((e,s)=>e+s.progress*s.weight,this._selfProgress*this._selfWeight);return Math.round(t*1e4)/1e4}get weight(){return this._weight}get observer(){return this._progressObserver||(this._progressObserver=t=>{this.set(t)}),this._progressObserver}get loadingListener(){return this._loadingListener||(this._loadingListener=t=>{this.set(t.detail.loaded/t.detail.total*100)}),this._loadingListener}pipe(t){t.setProgress({progress:this.progress,caption:this.caption}),this.addEventListener("progress",e=>{t.setProgress({progress:e.detail.progress,caption:e.detail.caption})}),this.addEventListener("done",()=>{t.setLoaded()})}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}notifyProgress(){const t=this;this.dispatchEvent(new CustomEvent("progress",{detail:{get progress(){return t.progress},get caption(){return t.caption}}}))}notifyDone(){this.dispatchEvent(new CustomEvent("done"))}}exports.EmscriptenDownloadMonitor=k;exports.ProgressObserver=x;exports.ProgressTracker=O;exports.cloneResponseMonitorProgress=R;
|
package/index.js
CHANGED
|
@@ -1,89 +1,99 @@
|
|
|
1
|
-
var
|
|
2
|
-
if (!
|
|
3
|
-
throw TypeError("Cannot " +
|
|
1
|
+
var E = (r, t, e) => {
|
|
2
|
+
if (!t.has(r))
|
|
3
|
+
throw TypeError("Cannot " + e);
|
|
4
4
|
};
|
|
5
|
-
var a = (
|
|
6
|
-
if (
|
|
5
|
+
var a = (r, t, e) => (E(r, t, "read from private field"), e ? e.call(r) : t.get(r)), f = (r, t, e) => {
|
|
6
|
+
if (t.has(r))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
|
-
|
|
9
|
-
}, _ = (
|
|
10
|
-
var
|
|
8
|
+
t instanceof WeakSet ? t.add(r) : t.set(r, e);
|
|
9
|
+
}, _ = (r, t, e, s) => (E(r, t, "write to private field"), s ? s.call(r, e) : t.set(r, e), e);
|
|
10
|
+
var w = (r, t, e, s) => ({
|
|
11
11
|
set _(n) {
|
|
12
|
-
_(
|
|
12
|
+
_(r, t, n, e);
|
|
13
13
|
},
|
|
14
14
|
get _() {
|
|
15
|
-
return a(
|
|
15
|
+
return a(r, t, s);
|
|
16
16
|
}
|
|
17
|
-
}),
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
}), p = (r, t, e) => (E(r, t, "access private method"), e);
|
|
18
|
+
const C = function() {
|
|
19
|
+
var r;
|
|
20
|
+
return typeof process < "u" && ((r = process.release) == null ? void 0 : r.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
typeof WorkerGlobalScope < "u" && // @ts-ignore
|
|
23
|
+
self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
|
|
24
|
+
);
|
|
25
|
+
}();
|
|
26
|
+
if (C === "NODE") {
|
|
27
|
+
let r = function(e) {
|
|
28
|
+
return new Promise(function(s, n) {
|
|
29
|
+
e.onload = e.onerror = function(i) {
|
|
30
|
+
e.onload = e.onerror = null, i.type === "load" ? s(e.result) : n(new Error("Failed to read the blob/file"));
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}, t = function() {
|
|
34
|
+
const e = new Uint8Array([1, 2, 3, 4]), n = new File([e], "test").stream();
|
|
35
|
+
try {
|
|
36
|
+
return n.getReader({ mode: "byob" }), !0;
|
|
37
|
+
} catch {
|
|
38
|
+
return !1;
|
|
24
39
|
}
|
|
40
|
+
};
|
|
41
|
+
if (typeof File > "u") {
|
|
42
|
+
class e extends Blob {
|
|
43
|
+
constructor(n, i, l) {
|
|
44
|
+
super(n);
|
|
45
|
+
let o;
|
|
46
|
+
l != null && l.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = i || "";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
global.File = e;
|
|
25
50
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
s
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
52
|
+
const s = new FileReader();
|
|
53
|
+
return s.readAsArrayBuffer(this), r(s);
|
|
54
|
+
}), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
55
|
+
const s = new FileReader();
|
|
56
|
+
return s.readAsText(this), r(s);
|
|
57
|
+
}), (typeof Blob.prototype.stream > "u" || !t()) && (Blob.prototype.stream = function() {
|
|
58
|
+
let e = 0;
|
|
59
|
+
const s = this;
|
|
60
|
+
return new ReadableStream({
|
|
61
|
+
type: "bytes",
|
|
62
|
+
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
63
|
+
// this if needed.
|
|
64
|
+
autoAllocateChunkSize: 512 * 1024,
|
|
65
|
+
async pull(n) {
|
|
66
|
+
const i = n.byobRequest.view, o = await s.slice(
|
|
67
|
+
e,
|
|
68
|
+
e + i.byteLength
|
|
69
|
+
).arrayBuffer(), h = new Uint8Array(o);
|
|
70
|
+
new Uint8Array(i.buffer).set(h);
|
|
71
|
+
const d = h.byteLength;
|
|
72
|
+
n.byobRequest.respond(d), e += d, e >= s.size && n.close();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
33
75
|
});
|
|
34
76
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
40
|
-
const e = new FileReader();
|
|
41
|
-
return e.readAsText(this), B(e);
|
|
42
|
-
});
|
|
43
|
-
function A() {
|
|
44
|
-
const s = new Uint8Array([1, 2, 3, 4]), t = new File([s], "test").stream();
|
|
45
|
-
try {
|
|
46
|
-
return t.getReader({ mode: "byob" }), !0;
|
|
47
|
-
} catch {
|
|
48
|
-
return !1;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
(typeof Blob.prototype.stream > "u" || !A()) && (Blob.prototype.stream = function() {
|
|
52
|
-
let s = 0;
|
|
53
|
-
const e = this;
|
|
54
|
-
return new ReadableStream({
|
|
55
|
-
type: "bytes",
|
|
56
|
-
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
57
|
-
// this if needed.
|
|
58
|
-
autoAllocateChunkSize: 512 * 1024,
|
|
59
|
-
async pull(t) {
|
|
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
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
if (typeof CustomEvent > "u") {
|
|
68
|
-
class s extends Event {
|
|
69
|
-
constructor(t, i = {}) {
|
|
70
|
-
super(t, i), this.detail = i.detail;
|
|
77
|
+
if (C === "NODE" && typeof CustomEvent > "u") {
|
|
78
|
+
class r extends Event {
|
|
79
|
+
constructor(e, s = {}) {
|
|
80
|
+
super(e, s), this.detail = s.detail;
|
|
71
81
|
}
|
|
72
82
|
initCustomEvent() {
|
|
73
83
|
}
|
|
74
84
|
}
|
|
75
|
-
globalThis.CustomEvent =
|
|
85
|
+
globalThis.CustomEvent = r;
|
|
76
86
|
}
|
|
77
|
-
const
|
|
78
|
-
var
|
|
79
|
-
class
|
|
87
|
+
const x = 5 * 1024 * 1024;
|
|
88
|
+
var g, u, v, I, b, P;
|
|
89
|
+
class A extends EventTarget {
|
|
80
90
|
constructor() {
|
|
81
91
|
super();
|
|
82
92
|
/**
|
|
83
93
|
* Replaces the default WebAssembly.instantiateStreaming with a version
|
|
84
94
|
* that monitors the download #progress.
|
|
85
95
|
*/
|
|
86
|
-
|
|
96
|
+
f(this, v);
|
|
87
97
|
/**
|
|
88
98
|
* Notifies about the download #progress of a file.
|
|
89
99
|
*
|
|
@@ -91,58 +101,58 @@ class k extends EventTarget {
|
|
|
91
101
|
* @param loaded The number of bytes of that file loaded so far.
|
|
92
102
|
* @param fileSize The total number of bytes in the loaded file.
|
|
93
103
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
f(this, b);
|
|
105
|
+
f(this, g, {});
|
|
106
|
+
f(this, u, {});
|
|
107
|
+
p(this, v, I).call(this);
|
|
98
108
|
}
|
|
99
|
-
expectAssets(
|
|
100
|
-
for (const [
|
|
101
|
-
const
|
|
102
|
-
o in a(this,
|
|
109
|
+
expectAssets(e) {
|
|
110
|
+
for (const [s, n] of Object.entries(e)) {
|
|
111
|
+
const i = "http://example.com/", o = new URL(s, i).pathname.split("/").pop();
|
|
112
|
+
o in a(this, g) || (a(this, g)[o] = n), o in a(this, u) || (a(this, u)[o] = 0);
|
|
103
113
|
}
|
|
104
114
|
}
|
|
105
|
-
async monitorFetch(
|
|
106
|
-
const
|
|
107
|
-
return
|
|
108
|
-
|
|
115
|
+
async monitorFetch(e) {
|
|
116
|
+
const s = await e;
|
|
117
|
+
return B(s, (i) => {
|
|
118
|
+
p(this, b, P).call(this, s.url, i.detail.loaded, i.detail.total);
|
|
109
119
|
});
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
WebAssembly.instantiateStreaming = async (
|
|
115
|
-
const
|
|
116
|
-
new URL(
|
|
117
|
-
), o =
|
|
118
|
-
|
|
119
|
-
({ detail: { loaded:
|
|
122
|
+
g = new WeakMap(), u = new WeakMap(), v = new WeakSet(), I = function() {
|
|
123
|
+
const e = WebAssembly.instantiateStreaming;
|
|
124
|
+
WebAssembly.instantiateStreaming = async (s, ...n) => {
|
|
125
|
+
const i = await s, l = i.url.substring(
|
|
126
|
+
new URL(i.url).origin.length + 1
|
|
127
|
+
), o = B(
|
|
128
|
+
i,
|
|
129
|
+
({ detail: { loaded: h, total: d } }) => p(this, b, P).call(this, l, h, d)
|
|
120
130
|
);
|
|
121
|
-
return
|
|
131
|
+
return e(o, ...n);
|
|
122
132
|
};
|
|
123
|
-
}, b = new WeakSet(), P = function(
|
|
124
|
-
const
|
|
125
|
-
n || (n = a(this,
|
|
126
|
-
`Registered a download #progress of an unregistered file "${
|
|
127
|
-
), a(this,
|
|
133
|
+
}, b = new WeakSet(), P = function(e, s, n) {
|
|
134
|
+
const i = new URL(e, "http://example.com").pathname.split("/").pop();
|
|
135
|
+
n || (n = a(this, g)[i]), i in a(this, u) || console.warn(
|
|
136
|
+
`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.`
|
|
137
|
+
), a(this, u)[i] = s, this.dispatchEvent(
|
|
128
138
|
new CustomEvent("progress", {
|
|
129
139
|
detail: {
|
|
130
|
-
loaded:
|
|
131
|
-
total:
|
|
140
|
+
loaded: T(a(this, u)),
|
|
141
|
+
total: T(a(this, g))
|
|
132
142
|
}
|
|
133
143
|
})
|
|
134
144
|
);
|
|
135
145
|
};
|
|
136
|
-
function
|
|
137
|
-
return Object.values(
|
|
146
|
+
function T(r) {
|
|
147
|
+
return Object.values(r).reduce((t, e) => t + e, 0);
|
|
138
148
|
}
|
|
139
|
-
function
|
|
140
|
-
const
|
|
141
|
-
function n(
|
|
142
|
-
|
|
149
|
+
function B(r, t) {
|
|
150
|
+
const e = r.headers.get("content-length") || "", s = parseInt(e, 10) || x;
|
|
151
|
+
function n(i, l) {
|
|
152
|
+
t(
|
|
143
153
|
new CustomEvent("progress", {
|
|
144
154
|
detail: {
|
|
145
|
-
loaded:
|
|
155
|
+
loaded: i,
|
|
146
156
|
total: l
|
|
147
157
|
}
|
|
148
158
|
})
|
|
@@ -150,80 +160,80 @@ function C(s, e) {
|
|
|
150
160
|
}
|
|
151
161
|
return new Response(
|
|
152
162
|
new ReadableStream({
|
|
153
|
-
async start(
|
|
154
|
-
if (!
|
|
155
|
-
|
|
163
|
+
async start(i) {
|
|
164
|
+
if (!r.body) {
|
|
165
|
+
i.close();
|
|
156
166
|
return;
|
|
157
167
|
}
|
|
158
|
-
const l =
|
|
168
|
+
const l = r.body.getReader();
|
|
159
169
|
let o = 0;
|
|
160
170
|
for (; ; )
|
|
161
171
|
try {
|
|
162
|
-
const { done:
|
|
163
|
-
if (
|
|
164
|
-
n(o, o),
|
|
172
|
+
const { done: h, value: d } = await l.read();
|
|
173
|
+
if (d && (o += d.byteLength), h) {
|
|
174
|
+
n(o, o), i.close();
|
|
165
175
|
break;
|
|
166
176
|
} else
|
|
167
|
-
n(o,
|
|
168
|
-
} catch (
|
|
169
|
-
console.error({ e:
|
|
177
|
+
n(o, s), i.enqueue(d);
|
|
178
|
+
} catch (h) {
|
|
179
|
+
console.error({ e: h }), i.error(h);
|
|
170
180
|
break;
|
|
171
181
|
}
|
|
172
182
|
}
|
|
173
183
|
}),
|
|
174
184
|
{
|
|
175
|
-
status:
|
|
176
|
-
statusText:
|
|
177
|
-
headers:
|
|
185
|
+
status: r.status,
|
|
186
|
+
statusText: r.statusText,
|
|
187
|
+
headers: r.headers
|
|
178
188
|
}
|
|
179
189
|
);
|
|
180
190
|
}
|
|
181
|
-
var
|
|
182
|
-
class
|
|
191
|
+
var c, y, m, R;
|
|
192
|
+
class F extends EventTarget {
|
|
183
193
|
constructor() {
|
|
184
194
|
super(...arguments);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
_(this,
|
|
195
|
+
f(this, m);
|
|
196
|
+
f(this, c, void 0);
|
|
197
|
+
f(this, y, void 0);
|
|
198
|
+
_(this, c, {}), _(this, y, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
|
|
189
199
|
}
|
|
190
|
-
partialObserver(
|
|
191
|
-
const n = ++
|
|
192
|
-
return a(this,
|
|
193
|
-
const { loaded: l, total: o } = (
|
|
194
|
-
a(this,
|
|
200
|
+
partialObserver(e, s = "") {
|
|
201
|
+
const n = ++w(this, y)._;
|
|
202
|
+
return a(this, c)[n] = 0, (i) => {
|
|
203
|
+
const { loaded: l, total: o } = (i == null ? void 0 : i.detail) || {};
|
|
204
|
+
a(this, c)[n] = l / o * e, p(this, m, R).call(this, this.totalProgress, "REAL_TIME", s);
|
|
195
205
|
};
|
|
196
206
|
}
|
|
197
|
-
slowlyIncrementBy(
|
|
198
|
-
const
|
|
199
|
-
a(this,
|
|
207
|
+
slowlyIncrementBy(e) {
|
|
208
|
+
const s = ++w(this, y)._;
|
|
209
|
+
a(this, c)[s] = e, p(this, m, R).call(this, this.totalProgress, "SLOWLY_INCREMENT");
|
|
200
210
|
}
|
|
201
211
|
get totalProgress() {
|
|
202
|
-
return Object.values(a(this,
|
|
203
|
-
(
|
|
212
|
+
return Object.values(a(this, c)).reduce(
|
|
213
|
+
(e, s) => e + s,
|
|
204
214
|
0
|
|
205
215
|
);
|
|
206
216
|
}
|
|
207
217
|
}
|
|
208
|
-
|
|
218
|
+
c = new WeakMap(), y = new WeakMap(), m = new WeakSet(), R = function(e, s, n) {
|
|
209
219
|
this.dispatchEvent(
|
|
210
220
|
new CustomEvent("progress", {
|
|
211
221
|
detail: {
|
|
212
|
-
progress:
|
|
213
|
-
mode:
|
|
222
|
+
progress: e,
|
|
223
|
+
mode: s,
|
|
214
224
|
caption: n
|
|
215
225
|
}
|
|
216
226
|
})
|
|
217
227
|
);
|
|
218
228
|
};
|
|
219
229
|
const L = 1e-5;
|
|
220
|
-
class
|
|
230
|
+
class O extends EventTarget {
|
|
221
231
|
constructor({
|
|
222
|
-
weight:
|
|
223
|
-
caption:
|
|
224
|
-
fillTime:
|
|
232
|
+
weight: t = 1,
|
|
233
|
+
caption: e = "",
|
|
234
|
+
fillTime: s = 4
|
|
225
235
|
} = {}) {
|
|
226
|
-
super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight =
|
|
236
|
+
super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight = t, this._selfCaption = e, this._fillTime = s;
|
|
227
237
|
}
|
|
228
238
|
/**
|
|
229
239
|
* Creates a new sub-tracker with a specific weight.
|
|
@@ -260,20 +270,20 @@ class x extends EventTarget {
|
|
|
260
270
|
* subTracker1.set(100);
|
|
261
271
|
* ```
|
|
262
272
|
*/
|
|
263
|
-
stage(
|
|
264
|
-
if (
|
|
273
|
+
stage(t, e = "") {
|
|
274
|
+
if (t || (t = this._selfWeight), this._selfWeight - t < -L)
|
|
265
275
|
throw new Error(
|
|
266
|
-
`Cannot add a stage with weight ${
|
|
276
|
+
`Cannot add a stage with weight ${t} as the total weight of registered stages would exceed 1.`
|
|
267
277
|
);
|
|
268
|
-
this._selfWeight -=
|
|
269
|
-
const
|
|
270
|
-
caption:
|
|
271
|
-
weight:
|
|
278
|
+
this._selfWeight -= t;
|
|
279
|
+
const s = new O({
|
|
280
|
+
caption: e,
|
|
281
|
+
weight: t,
|
|
272
282
|
fillTime: this._fillTime
|
|
273
283
|
});
|
|
274
|
-
return this._subTrackers.push(
|
|
284
|
+
return this._subTrackers.push(s), s.addEventListener("progress", () => this.notifyProgress()), s.addEventListener("done", () => {
|
|
275
285
|
this.done && this.notifyDone();
|
|
276
|
-
}),
|
|
286
|
+
}), s;
|
|
277
287
|
}
|
|
278
288
|
/**
|
|
279
289
|
* Fills the progress bar slowly over time, simulating progress.
|
|
@@ -293,32 +303,32 @@ class x extends EventTarget {
|
|
|
293
303
|
*
|
|
294
304
|
* @param options Optional options.
|
|
295
305
|
*/
|
|
296
|
-
fillSlowly({ stopBeforeFinishing:
|
|
306
|
+
fillSlowly({ stopBeforeFinishing: t = !0 } = {}) {
|
|
297
307
|
if (this._isFilling)
|
|
298
308
|
return;
|
|
299
309
|
this._isFilling = !0;
|
|
300
|
-
const
|
|
310
|
+
const e = 100, s = this._fillTime / e;
|
|
301
311
|
this._fillInterval = setInterval(() => {
|
|
302
|
-
this.set(this._selfProgress + 1),
|
|
303
|
-
},
|
|
312
|
+
this.set(this._selfProgress + 1), t && this._selfProgress >= 99 && clearInterval(this._fillInterval);
|
|
313
|
+
}, s);
|
|
304
314
|
}
|
|
305
|
-
set(
|
|
306
|
-
this._selfProgress = Math.min(
|
|
315
|
+
set(t) {
|
|
316
|
+
this._selfProgress = Math.min(t, 100), this.notifyProgress(), this._selfProgress + L >= 100 && this.finish();
|
|
307
317
|
}
|
|
308
318
|
finish() {
|
|
309
319
|
this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
|
|
310
320
|
}
|
|
311
321
|
get caption() {
|
|
312
|
-
for (let
|
|
313
|
-
if (!this._subTrackers[
|
|
314
|
-
const
|
|
315
|
-
if (
|
|
316
|
-
return
|
|
322
|
+
for (let t = this._subTrackers.length - 1; t >= 0; t--)
|
|
323
|
+
if (!this._subTrackers[t].done) {
|
|
324
|
+
const e = this._subTrackers[t].caption;
|
|
325
|
+
if (e)
|
|
326
|
+
return e;
|
|
317
327
|
}
|
|
318
328
|
return this._selfCaption;
|
|
319
329
|
}
|
|
320
|
-
setCaption(
|
|
321
|
-
this._selfCaption =
|
|
330
|
+
setCaption(t) {
|
|
331
|
+
this._selfCaption = t, this.notifyProgress();
|
|
322
332
|
}
|
|
323
333
|
get done() {
|
|
324
334
|
return this.progress + L >= 100;
|
|
@@ -326,54 +336,54 @@ class x extends EventTarget {
|
|
|
326
336
|
get progress() {
|
|
327
337
|
if (this._selfDone)
|
|
328
338
|
return 100;
|
|
329
|
-
const
|
|
330
|
-
(
|
|
339
|
+
const t = this._subTrackers.reduce(
|
|
340
|
+
(e, s) => e + s.progress * s.weight,
|
|
331
341
|
this._selfProgress * this._selfWeight
|
|
332
342
|
);
|
|
333
|
-
return Math.round(
|
|
343
|
+
return Math.round(t * 1e4) / 1e4;
|
|
334
344
|
}
|
|
335
345
|
get weight() {
|
|
336
346
|
return this._weight;
|
|
337
347
|
}
|
|
338
348
|
get observer() {
|
|
339
|
-
return this._progressObserver || (this._progressObserver = (
|
|
340
|
-
this.set(
|
|
349
|
+
return this._progressObserver || (this._progressObserver = (t) => {
|
|
350
|
+
this.set(t);
|
|
341
351
|
}), this._progressObserver;
|
|
342
352
|
}
|
|
343
353
|
get loadingListener() {
|
|
344
|
-
return this._loadingListener || (this._loadingListener = (
|
|
345
|
-
this.set(
|
|
354
|
+
return this._loadingListener || (this._loadingListener = (t) => {
|
|
355
|
+
this.set(t.detail.loaded / t.detail.total * 100);
|
|
346
356
|
}), this._loadingListener;
|
|
347
357
|
}
|
|
348
|
-
pipe(
|
|
349
|
-
|
|
358
|
+
pipe(t) {
|
|
359
|
+
t.setProgress({
|
|
350
360
|
progress: this.progress,
|
|
351
361
|
caption: this.caption
|
|
352
|
-
}), this.addEventListener("progress", (
|
|
353
|
-
|
|
354
|
-
progress:
|
|
355
|
-
caption:
|
|
362
|
+
}), this.addEventListener("progress", (e) => {
|
|
363
|
+
t.setProgress({
|
|
364
|
+
progress: e.detail.progress,
|
|
365
|
+
caption: e.detail.caption
|
|
356
366
|
});
|
|
357
367
|
}), this.addEventListener("done", () => {
|
|
358
|
-
|
|
368
|
+
t.setLoaded();
|
|
359
369
|
});
|
|
360
370
|
}
|
|
361
|
-
addEventListener(
|
|
362
|
-
super.addEventListener(
|
|
371
|
+
addEventListener(t, e) {
|
|
372
|
+
super.addEventListener(t, e);
|
|
363
373
|
}
|
|
364
|
-
removeEventListener(
|
|
365
|
-
super.removeEventListener(
|
|
374
|
+
removeEventListener(t, e) {
|
|
375
|
+
super.removeEventListener(t, e);
|
|
366
376
|
}
|
|
367
377
|
notifyProgress() {
|
|
368
|
-
const
|
|
378
|
+
const t = this;
|
|
369
379
|
this.dispatchEvent(
|
|
370
380
|
new CustomEvent("progress", {
|
|
371
381
|
detail: {
|
|
372
382
|
get progress() {
|
|
373
|
-
return
|
|
383
|
+
return t.progress;
|
|
374
384
|
},
|
|
375
385
|
get caption() {
|
|
376
|
-
return
|
|
386
|
+
return t.caption;
|
|
377
387
|
}
|
|
378
388
|
}
|
|
379
389
|
})
|
|
@@ -384,8 +394,8 @@ class x extends EventTarget {
|
|
|
384
394
|
}
|
|
385
395
|
}
|
|
386
396
|
export {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
397
|
+
A as EmscriptenDownloadMonitor,
|
|
398
|
+
F as ProgressObserver,
|
|
399
|
+
O as ProgressTracker,
|
|
400
|
+
B as cloneResponseMonitorProgress
|
|
391
401
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/progress",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
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": "c4c52563eee8997b94cd4a0875e10fb5d8ccda42",
|
|
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.6.
|
|
38
|
+
"@php-wasm/node-polyfills": "0.6.7"
|
|
39
39
|
}
|
|
40
40
|
}
|