@php-wasm/progress 0.7.0 → 0.7.3
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 +3 -1
- package/index.js +308 -144
- package/package.json +4 -3
package/index.cjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
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)),u=(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)},y=(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){y(s,e,n,t)},get _(){return a(s,e,r)}}),b=(s,e,t)=>(w(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=function(){var s;return typeof process<"u"&&((s=process.release)==null?void 0:s.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(I==="NODE"){let s=function(t){return new Promise(function(r,n){t.onload=t.onerror=function(i){t.onload=t.onerror=null,i.type==="load"?r(t.result):n(new Error("Failed to read the blob/file"))}})},e=function(){const t=new Uint8Array([1,2,3,4]),n=new File([t],"test").stream();try{return n.getReader({mode:"byob"}),!0}catch{return!1}};if(typeof File>"u"){class t 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=t}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const r=new FileReader;return r.readAsArrayBuffer(this),s(r)}),typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const r=new FileReader;return r.readAsText(this),s(r)}),(typeof Blob.prototype.stream>"u"||!e())&&(Blob.prototype.stream=function(){let t=0;const r=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(n){const i=n.byobRequest.view,o=await r.slice(t,t+i.byteLength).arrayBuffer(),c=new Uint8Array(o);new Uint8Array(i.buffer).set(c);const g=c.byteLength;n.byobRequest.respond(g),t+=g,t>=r.size&&n.close()}})})}if(I==="NODE"&&typeof CustomEvent>"u"){class s extends Event{constructor(t,r={}){super(t,r),this.detail=r.detail}initCustomEvent(){}}globalThis.CustomEvent=s}const O=(s,...e)=>{switch(s.severity){case"Debug":console.debug(s.message,...e);break;case"Info":console.info(s.message,...e);break;case"Warn":console.warn(s.message,...e);break;case"Error":console.error(s.message,...e);break;case"Fatal":console.error(s.message,...e);break;default:console.log(s.message,...e)}},S=(s,...e)=>[typeof s=="object"?JSON.stringify(s):s,...e.map(t=>JSON.stringify(t))].join(" "),R=[],P=s=>{R.push(s)},x=s=>{if(s.raw===!0)P(s.message);else{const e=F(typeof s.message=="object"?S(s.message):s.message,s.severity??"Info",s.prefix??"JavaScript");P(e)}};class B extends EventTarget{constructor(e=[]){super(),this.handlers=e,this.fatalErrorEvent="playground-fatal-error"}getLogs(){return this.handlers.includes(x)?[...R]:(this.error(`Logs aren't stored because the logToMemory handler isn't registered.
|
|
2
|
+
If you're using a custom logger instance, make sure to register logToMemory handler.
|
|
3
|
+
`),[])}logMessage(e,...t){for(const r of this.handlers)r(e,...t)}log(e,...t){this.logMessage({message:e,severity:void 0,prefix:"JavaScript",raw:!1},...t)}debug(e,...t){this.logMessage({message:e,severity:"Debug",prefix:"JavaScript",raw:!1},...t)}info(e,...t){this.logMessage({message:e,severity:"Info",prefix:"JavaScript",raw:!1},...t)}warn(e,...t){this.logMessage({message:e,severity:"Warn",prefix:"JavaScript",raw:!1},...t)}error(e,...t){this.logMessage({message:e,severity:"Error",prefix:"JavaScript",raw:!1},...t)}}const k=new B([x,O]),F=(s,e,t)=>{const r=new Date,n=new Intl.DateTimeFormat("en-GB",{year:"numeric",month:"short",day:"2-digit",timeZone:"UTC"}).format(r).replace(/ /g,"-"),i=new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZone:"UTC",timeZoneName:"short"}).format(r);return`[${n+" "+i}] ${t} ${e}: ${s}`},A=5*1024*1024;var f,h,v,C;class N extends EventTarget{constructor(){super(...arguments);u(this,v);u(this,f,{});u(this,h,{})}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,f)||(a(this,f)[o]=n),o in a(this,h)||(a(this,h)[o]=0)}}async monitorFetch(t){const r=await t;return D(r,i=>{b(this,v,C).call(this,r.url,i.detail.loaded,i.detail.total)})}}f=new WeakMap,h=new WeakMap,v=new WeakSet,C=function(t,r,n){const i=new URL(t,"http://example.com").pathname.split("/").pop();n?i in a(this,f)||(a(this,f)[i]=n,a(this,h)[i]=r):n=a(this,f)[i],i in a(this,h)||k.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,h)[i]=r,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:M(a(this,h)),total:M(a(this,f))}}))};function M(s){return Object.values(s).reduce((e,t)=>e+t,0)}function D(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:g}=await l.read();if(g&&(o+=g.byteLength),c){n(o,o),i.close();break}else n(o,r),i.enqueue(g)}catch(c){k.error({e:c}),i.error(c);break}}}),{status:s.status,statusText:s.statusText,headers:s.headers})}var d,p,m,T;class W extends EventTarget{constructor(){super(...arguments);u(this,m);u(this,d,void 0);u(this,p,void 0);y(this,d,{}),y(this,p,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(t,r=""){const n=++E(this,p)._;return a(this,d)[n]=0,i=>{const{loaded:l,total:o}=(i==null?void 0:i.detail)||{};a(this,d)[n]=l/o*t,b(this,m,T).call(this,this.totalProgress,"REAL_TIME",r)}}slowlyIncrementBy(t){const r=++E(this,p)._;a(this,d)[r]=t,b(this,m,T).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(a(this,d)).reduce((t,r)=>t+r,0)}}d=new WeakMap,p=new WeakMap,m=new WeakSet,T=function(t,r,n){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:t,mode:r,caption:n}}))};const _=1e-5;class L 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<-_)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 L({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+_>=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+_>=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=N;exports.ProgressObserver=W;exports.ProgressTracker=L;exports.cloneResponseMonitorProgress=D;
|
package/index.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
var
|
|
2
|
-
if (!
|
|
3
|
-
throw TypeError("Cannot " +
|
|
1
|
+
var w = (s, e, t) => {
|
|
2
|
+
if (!e.has(s))
|
|
3
|
+
throw TypeError("Cannot " + t);
|
|
4
4
|
};
|
|
5
|
-
var a = (
|
|
6
|
-
if (
|
|
5
|
+
var a = (s, e, t) => (w(s, e, "read from private field"), t ? t.call(s) : e.get(s)), u = (s, e, t) => {
|
|
6
|
+
if (e.has(s))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
var E = (
|
|
8
|
+
e instanceof WeakSet ? e.add(s) : e.set(s, t);
|
|
9
|
+
}, y = (s, e, t, r) => (w(s, e, "write to private field"), r ? r.call(s, t) : e.set(s, t), t);
|
|
10
|
+
var E = (s, e, t, r) => ({
|
|
11
11
|
set _(n) {
|
|
12
|
-
|
|
12
|
+
y(s, e, n, t);
|
|
13
13
|
},
|
|
14
14
|
get _() {
|
|
15
|
-
return a(
|
|
15
|
+
return a(s, e, r);
|
|
16
16
|
}
|
|
17
|
-
}),
|
|
18
|
-
const
|
|
19
|
-
var
|
|
20
|
-
return typeof process < "u" && ((
|
|
17
|
+
}), b = (s, e, t) => (w(s, e, "access private method"), t);
|
|
18
|
+
const x = function() {
|
|
19
|
+
var s;
|
|
20
|
+
return typeof process < "u" && ((s = process.release) == null ? void 0 : s.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
21
21
|
// @ts-ignore
|
|
22
22
|
typeof WorkerGlobalScope < "u" && // @ts-ignore
|
|
23
23
|
self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
|
|
24
24
|
);
|
|
25
25
|
}();
|
|
26
|
-
if (
|
|
27
|
-
let
|
|
28
|
-
return new Promise(function(
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
if (x === "NODE") {
|
|
27
|
+
let s = function(t) {
|
|
28
|
+
return new Promise(function(r, n) {
|
|
29
|
+
t.onload = t.onerror = function(i) {
|
|
30
|
+
t.onload = t.onerror = null, i.type === "load" ? r(t.result) : n(new Error("Failed to read the blob/file"));
|
|
31
31
|
};
|
|
32
32
|
});
|
|
33
|
-
},
|
|
34
|
-
const
|
|
33
|
+
}, e = function() {
|
|
34
|
+
const t = new Uint8Array([1, 2, 3, 4]), n = new File([t], "test").stream();
|
|
35
35
|
try {
|
|
36
36
|
return n.getReader({ mode: "byob" }), !0;
|
|
37
37
|
} catch {
|
|
@@ -39,54 +39,218 @@ if (R === "NODE") {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
if (typeof File > "u") {
|
|
42
|
-
class
|
|
42
|
+
class t extends Blob {
|
|
43
43
|
constructor(n, i, l) {
|
|
44
44
|
super(n);
|
|
45
45
|
let o;
|
|
46
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
47
|
}
|
|
48
48
|
}
|
|
49
|
-
global.File =
|
|
49
|
+
global.File = t;
|
|
50
50
|
}
|
|
51
51
|
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
52
|
-
const
|
|
53
|
-
return
|
|
52
|
+
const r = new FileReader();
|
|
53
|
+
return r.readAsArrayBuffer(this), s(r);
|
|
54
54
|
}), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
55
|
-
const
|
|
56
|
-
return
|
|
57
|
-
}), (typeof Blob.prototype.stream > "u" || !
|
|
58
|
-
let
|
|
59
|
-
const
|
|
55
|
+
const r = new FileReader();
|
|
56
|
+
return r.readAsText(this), s(r);
|
|
57
|
+
}), (typeof Blob.prototype.stream > "u" || !e()) && (Blob.prototype.stream = function() {
|
|
58
|
+
let t = 0;
|
|
59
|
+
const r = this;
|
|
60
60
|
return new ReadableStream({
|
|
61
61
|
type: "bytes",
|
|
62
62
|
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
63
63
|
// this if needed.
|
|
64
64
|
autoAllocateChunkSize: 512 * 1024,
|
|
65
65
|
async pull(n) {
|
|
66
|
-
const i = n.byobRequest.view, o = await
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
).arrayBuffer(),
|
|
70
|
-
new Uint8Array(i.buffer).set(
|
|
71
|
-
const
|
|
72
|
-
n.byobRequest.respond(
|
|
66
|
+
const i = n.byobRequest.view, o = await r.slice(
|
|
67
|
+
t,
|
|
68
|
+
t + i.byteLength
|
|
69
|
+
).arrayBuffer(), c = new Uint8Array(o);
|
|
70
|
+
new Uint8Array(i.buffer).set(c);
|
|
71
|
+
const g = c.byteLength;
|
|
72
|
+
n.byobRequest.respond(g), t += g, t >= r.size && n.close();
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
if (
|
|
78
|
-
class
|
|
79
|
-
constructor(
|
|
80
|
-
super(
|
|
77
|
+
if (x === "NODE" && typeof CustomEvent > "u") {
|
|
78
|
+
class s extends Event {
|
|
79
|
+
constructor(t, r = {}) {
|
|
80
|
+
super(t, r), this.detail = r.detail;
|
|
81
81
|
}
|
|
82
82
|
initCustomEvent() {
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
globalThis.CustomEvent =
|
|
85
|
+
globalThis.CustomEvent = s;
|
|
86
86
|
}
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const B = (s, ...e) => {
|
|
88
|
+
switch (s.severity) {
|
|
89
|
+
case "Debug":
|
|
90
|
+
console.debug(s.message, ...e);
|
|
91
|
+
break;
|
|
92
|
+
case "Info":
|
|
93
|
+
console.info(s.message, ...e);
|
|
94
|
+
break;
|
|
95
|
+
case "Warn":
|
|
96
|
+
console.warn(s.message, ...e);
|
|
97
|
+
break;
|
|
98
|
+
case "Error":
|
|
99
|
+
console.error(s.message, ...e);
|
|
100
|
+
break;
|
|
101
|
+
case "Fatal":
|
|
102
|
+
console.error(s.message, ...e);
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
console.log(s.message, ...e);
|
|
106
|
+
}
|
|
107
|
+
}, D = (s, ...e) => [
|
|
108
|
+
typeof s == "object" ? JSON.stringify(s) : s,
|
|
109
|
+
...e.map((t) => JSON.stringify(t))
|
|
110
|
+
].join(" "), I = [], T = (s) => {
|
|
111
|
+
I.push(s);
|
|
112
|
+
}, M = (s) => {
|
|
113
|
+
if (s.raw === !0)
|
|
114
|
+
T(s.message);
|
|
115
|
+
else {
|
|
116
|
+
const e = S(
|
|
117
|
+
typeof s.message == "object" ? D(s.message) : s.message,
|
|
118
|
+
s.severity ?? "Info",
|
|
119
|
+
s.prefix ?? "JavaScript"
|
|
120
|
+
);
|
|
121
|
+
T(e);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
class O extends EventTarget {
|
|
125
|
+
// constructor
|
|
126
|
+
constructor(e = []) {
|
|
127
|
+
super(), this.handlers = e, this.fatalErrorEvent = "playground-fatal-error";
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get all logs.
|
|
131
|
+
* @returns string[]
|
|
132
|
+
*/
|
|
133
|
+
getLogs() {
|
|
134
|
+
return this.handlers.includes(M) ? [...I] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
|
|
135
|
+
If you're using a custom logger instance, make sure to register logToMemory handler.
|
|
136
|
+
`), []);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Log message with severity.
|
|
140
|
+
*
|
|
141
|
+
* @param message any
|
|
142
|
+
* @param severity LogSeverity
|
|
143
|
+
* @param raw boolean
|
|
144
|
+
* @param args any
|
|
145
|
+
*/
|
|
146
|
+
logMessage(e, ...t) {
|
|
147
|
+
for (const r of this.handlers)
|
|
148
|
+
r(e, ...t);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Log message
|
|
152
|
+
*
|
|
153
|
+
* @param message any
|
|
154
|
+
* @param args any
|
|
155
|
+
*/
|
|
156
|
+
log(e, ...t) {
|
|
157
|
+
this.logMessage(
|
|
158
|
+
{
|
|
159
|
+
message: e,
|
|
160
|
+
severity: void 0,
|
|
161
|
+
prefix: "JavaScript",
|
|
162
|
+
raw: !1
|
|
163
|
+
},
|
|
164
|
+
...t
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Log debug message
|
|
169
|
+
*
|
|
170
|
+
* @param message any
|
|
171
|
+
* @param args any
|
|
172
|
+
*/
|
|
173
|
+
debug(e, ...t) {
|
|
174
|
+
this.logMessage(
|
|
175
|
+
{
|
|
176
|
+
message: e,
|
|
177
|
+
severity: "Debug",
|
|
178
|
+
prefix: "JavaScript",
|
|
179
|
+
raw: !1
|
|
180
|
+
},
|
|
181
|
+
...t
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Log info message
|
|
186
|
+
*
|
|
187
|
+
* @param message any
|
|
188
|
+
* @param args any
|
|
189
|
+
*/
|
|
190
|
+
info(e, ...t) {
|
|
191
|
+
this.logMessage(
|
|
192
|
+
{
|
|
193
|
+
message: e,
|
|
194
|
+
severity: "Info",
|
|
195
|
+
prefix: "JavaScript",
|
|
196
|
+
raw: !1
|
|
197
|
+
},
|
|
198
|
+
...t
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Log warning message
|
|
203
|
+
*
|
|
204
|
+
* @param message any
|
|
205
|
+
* @param args any
|
|
206
|
+
*/
|
|
207
|
+
warn(e, ...t) {
|
|
208
|
+
this.logMessage(
|
|
209
|
+
{
|
|
210
|
+
message: e,
|
|
211
|
+
severity: "Warn",
|
|
212
|
+
prefix: "JavaScript",
|
|
213
|
+
raw: !1
|
|
214
|
+
},
|
|
215
|
+
...t
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Log error message
|
|
220
|
+
*
|
|
221
|
+
* @param message any
|
|
222
|
+
* @param args any
|
|
223
|
+
*/
|
|
224
|
+
error(e, ...t) {
|
|
225
|
+
this.logMessage(
|
|
226
|
+
{
|
|
227
|
+
message: e,
|
|
228
|
+
severity: "Error",
|
|
229
|
+
prefix: "JavaScript",
|
|
230
|
+
raw: !1
|
|
231
|
+
},
|
|
232
|
+
...t
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const R = new O([M, B]), S = (s, e, t) => {
|
|
237
|
+
const r = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
|
|
238
|
+
year: "numeric",
|
|
239
|
+
month: "short",
|
|
240
|
+
day: "2-digit",
|
|
241
|
+
timeZone: "UTC"
|
|
242
|
+
}).format(r).replace(/ /g, "-"), i = new Intl.DateTimeFormat("en-GB", {
|
|
243
|
+
hour: "2-digit",
|
|
244
|
+
minute: "2-digit",
|
|
245
|
+
second: "2-digit",
|
|
246
|
+
hour12: !1,
|
|
247
|
+
timeZone: "UTC",
|
|
248
|
+
timeZoneName: "short"
|
|
249
|
+
}).format(r);
|
|
250
|
+
return `[${n + " " + i}] ${t} ${e}: ${s}`;
|
|
251
|
+
}, F = 5 * 1024 * 1024;
|
|
252
|
+
var f, h, v, C;
|
|
253
|
+
class W extends EventTarget {
|
|
90
254
|
constructor() {
|
|
91
255
|
super(...arguments);
|
|
92
256
|
/**
|
|
@@ -96,43 +260,43 @@ class x extends EventTarget {
|
|
|
96
260
|
* @param loaded The number of bytes of that file loaded so far.
|
|
97
261
|
* @param fileSize The total number of bytes in the loaded file.
|
|
98
262
|
*/
|
|
99
|
-
u(this,
|
|
100
|
-
u(this,
|
|
263
|
+
u(this, v);
|
|
264
|
+
u(this, f, {});
|
|
101
265
|
u(this, h, {});
|
|
102
266
|
}
|
|
103
|
-
expectAssets(
|
|
104
|
-
for (const [
|
|
105
|
-
const i = "http://example.com/", o = new URL(
|
|
106
|
-
o in a(this,
|
|
267
|
+
expectAssets(t) {
|
|
268
|
+
for (const [r, n] of Object.entries(t)) {
|
|
269
|
+
const i = "http://example.com/", o = new URL(r, i).pathname.split("/").pop();
|
|
270
|
+
o in a(this, f) || (a(this, f)[o] = n), o in a(this, h) || (a(this, h)[o] = 0);
|
|
107
271
|
}
|
|
108
272
|
}
|
|
109
|
-
async monitorFetch(
|
|
110
|
-
const
|
|
111
|
-
return
|
|
112
|
-
|
|
273
|
+
async monitorFetch(t) {
|
|
274
|
+
const r = await t;
|
|
275
|
+
return A(r, (i) => {
|
|
276
|
+
b(this, v, C).call(this, r.url, i.detail.loaded, i.detail.total);
|
|
113
277
|
});
|
|
114
278
|
}
|
|
115
279
|
}
|
|
116
|
-
|
|
117
|
-
const i = new URL(
|
|
118
|
-
n || (
|
|
280
|
+
f = new WeakMap(), h = new WeakMap(), v = new WeakSet(), C = function(t, r, n) {
|
|
281
|
+
const i = new URL(t, "http://example.com").pathname.split("/").pop();
|
|
282
|
+
n ? i in a(this, f) || (a(this, f)[i] = n, a(this, h)[i] = r) : n = a(this, f)[i], i in a(this, h) || R.warn(
|
|
119
283
|
`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.`
|
|
120
|
-
), a(this, h)[i] =
|
|
284
|
+
), a(this, h)[i] = r, this.dispatchEvent(
|
|
121
285
|
new CustomEvent("progress", {
|
|
122
286
|
detail: {
|
|
123
287
|
loaded: P(a(this, h)),
|
|
124
|
-
total: P(a(this,
|
|
288
|
+
total: P(a(this, f))
|
|
125
289
|
}
|
|
126
290
|
})
|
|
127
291
|
);
|
|
128
292
|
};
|
|
129
|
-
function P(
|
|
130
|
-
return Object.values(
|
|
293
|
+
function P(s) {
|
|
294
|
+
return Object.values(s).reduce((e, t) => e + t, 0);
|
|
131
295
|
}
|
|
132
|
-
function
|
|
133
|
-
const
|
|
296
|
+
function A(s, e) {
|
|
297
|
+
const t = s.headers.get("content-length") || "", r = parseInt(t, 10) || F;
|
|
134
298
|
function n(i, l) {
|
|
135
|
-
|
|
299
|
+
e(
|
|
136
300
|
new CustomEvent("progress", {
|
|
137
301
|
detail: {
|
|
138
302
|
loaded: i,
|
|
@@ -144,79 +308,79 @@ function I(r, t) {
|
|
|
144
308
|
return new Response(
|
|
145
309
|
new ReadableStream({
|
|
146
310
|
async start(i) {
|
|
147
|
-
if (!
|
|
311
|
+
if (!s.body) {
|
|
148
312
|
i.close();
|
|
149
313
|
return;
|
|
150
314
|
}
|
|
151
|
-
const l =
|
|
315
|
+
const l = s.body.getReader();
|
|
152
316
|
let o = 0;
|
|
153
317
|
for (; ; )
|
|
154
318
|
try {
|
|
155
|
-
const { done:
|
|
156
|
-
if (
|
|
319
|
+
const { done: c, value: g } = await l.read();
|
|
320
|
+
if (g && (o += g.byteLength), c) {
|
|
157
321
|
n(o, o), i.close();
|
|
158
322
|
break;
|
|
159
323
|
} else
|
|
160
|
-
n(o,
|
|
161
|
-
} catch (
|
|
162
|
-
|
|
324
|
+
n(o, r), i.enqueue(g);
|
|
325
|
+
} catch (c) {
|
|
326
|
+
R.error({ e: c }), i.error(c);
|
|
163
327
|
break;
|
|
164
328
|
}
|
|
165
329
|
}
|
|
166
330
|
}),
|
|
167
331
|
{
|
|
168
|
-
status:
|
|
169
|
-
statusText:
|
|
170
|
-
headers:
|
|
332
|
+
status: s.status,
|
|
333
|
+
statusText: s.statusText,
|
|
334
|
+
headers: s.headers
|
|
171
335
|
}
|
|
172
336
|
);
|
|
173
337
|
}
|
|
174
|
-
var d,
|
|
175
|
-
class
|
|
338
|
+
var d, p, m, L;
|
|
339
|
+
class J extends EventTarget {
|
|
176
340
|
constructor() {
|
|
177
341
|
super(...arguments);
|
|
178
|
-
u(this,
|
|
342
|
+
u(this, m);
|
|
179
343
|
u(this, d, void 0);
|
|
180
|
-
u(this,
|
|
181
|
-
|
|
344
|
+
u(this, p, void 0);
|
|
345
|
+
y(this, d, {}), y(this, p, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
|
|
182
346
|
}
|
|
183
|
-
partialObserver(
|
|
184
|
-
const n = ++E(this,
|
|
347
|
+
partialObserver(t, r = "") {
|
|
348
|
+
const n = ++E(this, p)._;
|
|
185
349
|
return a(this, d)[n] = 0, (i) => {
|
|
186
350
|
const { loaded: l, total: o } = (i == null ? void 0 : i.detail) || {};
|
|
187
|
-
a(this, d)[n] = l / o *
|
|
351
|
+
a(this, d)[n] = l / o * t, b(this, m, L).call(this, this.totalProgress, "REAL_TIME", r);
|
|
188
352
|
};
|
|
189
353
|
}
|
|
190
|
-
slowlyIncrementBy(
|
|
191
|
-
const
|
|
192
|
-
a(this, d)[
|
|
354
|
+
slowlyIncrementBy(t) {
|
|
355
|
+
const r = ++E(this, p)._;
|
|
356
|
+
a(this, d)[r] = t, b(this, m, L).call(this, this.totalProgress, "SLOWLY_INCREMENT");
|
|
193
357
|
}
|
|
194
358
|
get totalProgress() {
|
|
195
359
|
return Object.values(a(this, d)).reduce(
|
|
196
|
-
(
|
|
360
|
+
(t, r) => t + r,
|
|
197
361
|
0
|
|
198
362
|
);
|
|
199
363
|
}
|
|
200
364
|
}
|
|
201
|
-
d = new WeakMap(),
|
|
365
|
+
d = new WeakMap(), p = new WeakMap(), m = new WeakSet(), L = function(t, r, n) {
|
|
202
366
|
this.dispatchEvent(
|
|
203
367
|
new CustomEvent("progress", {
|
|
204
368
|
detail: {
|
|
205
|
-
progress:
|
|
206
|
-
mode:
|
|
369
|
+
progress: t,
|
|
370
|
+
mode: r,
|
|
207
371
|
caption: n
|
|
208
372
|
}
|
|
209
373
|
})
|
|
210
374
|
);
|
|
211
375
|
};
|
|
212
|
-
const
|
|
213
|
-
class
|
|
376
|
+
const _ = 1e-5;
|
|
377
|
+
class k extends EventTarget {
|
|
214
378
|
constructor({
|
|
215
|
-
weight:
|
|
216
|
-
caption:
|
|
217
|
-
fillTime:
|
|
379
|
+
weight: e = 1,
|
|
380
|
+
caption: t = "",
|
|
381
|
+
fillTime: r = 4
|
|
218
382
|
} = {}) {
|
|
219
|
-
super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight =
|
|
383
|
+
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;
|
|
220
384
|
}
|
|
221
385
|
/**
|
|
222
386
|
* Creates a new sub-tracker with a specific weight.
|
|
@@ -253,20 +417,20 @@ class B extends EventTarget {
|
|
|
253
417
|
* subTracker1.set(100);
|
|
254
418
|
* ```
|
|
255
419
|
*/
|
|
256
|
-
stage(
|
|
257
|
-
if (
|
|
420
|
+
stage(e, t = "") {
|
|
421
|
+
if (e || (e = this._selfWeight), this._selfWeight - e < -_)
|
|
258
422
|
throw new Error(
|
|
259
|
-
`Cannot add a stage with weight ${
|
|
423
|
+
`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
|
|
260
424
|
);
|
|
261
|
-
this._selfWeight -=
|
|
262
|
-
const
|
|
263
|
-
caption:
|
|
264
|
-
weight:
|
|
425
|
+
this._selfWeight -= e;
|
|
426
|
+
const r = new k({
|
|
427
|
+
caption: t,
|
|
428
|
+
weight: e,
|
|
265
429
|
fillTime: this._fillTime
|
|
266
430
|
});
|
|
267
|
-
return this._subTrackers.push(
|
|
431
|
+
return this._subTrackers.push(r), r.addEventListener("progress", () => this.notifyProgress()), r.addEventListener("done", () => {
|
|
268
432
|
this.done && this.notifyDone();
|
|
269
|
-
}),
|
|
433
|
+
}), r;
|
|
270
434
|
}
|
|
271
435
|
/**
|
|
272
436
|
* Fills the progress bar slowly over time, simulating progress.
|
|
@@ -286,87 +450,87 @@ class B extends EventTarget {
|
|
|
286
450
|
*
|
|
287
451
|
* @param options Optional options.
|
|
288
452
|
*/
|
|
289
|
-
fillSlowly({ stopBeforeFinishing:
|
|
453
|
+
fillSlowly({ stopBeforeFinishing: e = !0 } = {}) {
|
|
290
454
|
if (this._isFilling)
|
|
291
455
|
return;
|
|
292
456
|
this._isFilling = !0;
|
|
293
|
-
const
|
|
457
|
+
const t = 100, r = this._fillTime / t;
|
|
294
458
|
this._fillInterval = setInterval(() => {
|
|
295
|
-
this.set(this._selfProgress + 1),
|
|
296
|
-
},
|
|
459
|
+
this.set(this._selfProgress + 1), e && this._selfProgress >= 99 && clearInterval(this._fillInterval);
|
|
460
|
+
}, r);
|
|
297
461
|
}
|
|
298
|
-
set(
|
|
299
|
-
this._selfProgress = Math.min(
|
|
462
|
+
set(e) {
|
|
463
|
+
this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + _ >= 100 && this.finish();
|
|
300
464
|
}
|
|
301
465
|
finish() {
|
|
302
466
|
this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
|
|
303
467
|
}
|
|
304
468
|
get caption() {
|
|
305
|
-
for (let
|
|
306
|
-
if (!this._subTrackers[
|
|
307
|
-
const
|
|
308
|
-
if (
|
|
309
|
-
return
|
|
469
|
+
for (let e = this._subTrackers.length - 1; e >= 0; e--)
|
|
470
|
+
if (!this._subTrackers[e].done) {
|
|
471
|
+
const t = this._subTrackers[e].caption;
|
|
472
|
+
if (t)
|
|
473
|
+
return t;
|
|
310
474
|
}
|
|
311
475
|
return this._selfCaption;
|
|
312
476
|
}
|
|
313
|
-
setCaption(
|
|
314
|
-
this._selfCaption =
|
|
477
|
+
setCaption(e) {
|
|
478
|
+
this._selfCaption = e, this.notifyProgress();
|
|
315
479
|
}
|
|
316
480
|
get done() {
|
|
317
|
-
return this.progress +
|
|
481
|
+
return this.progress + _ >= 100;
|
|
318
482
|
}
|
|
319
483
|
get progress() {
|
|
320
484
|
if (this._selfDone)
|
|
321
485
|
return 100;
|
|
322
|
-
const
|
|
323
|
-
(
|
|
486
|
+
const e = this._subTrackers.reduce(
|
|
487
|
+
(t, r) => t + r.progress * r.weight,
|
|
324
488
|
this._selfProgress * this._selfWeight
|
|
325
489
|
);
|
|
326
|
-
return Math.round(
|
|
490
|
+
return Math.round(e * 1e4) / 1e4;
|
|
327
491
|
}
|
|
328
492
|
get weight() {
|
|
329
493
|
return this._weight;
|
|
330
494
|
}
|
|
331
495
|
get observer() {
|
|
332
|
-
return this._progressObserver || (this._progressObserver = (
|
|
333
|
-
this.set(
|
|
496
|
+
return this._progressObserver || (this._progressObserver = (e) => {
|
|
497
|
+
this.set(e);
|
|
334
498
|
}), this._progressObserver;
|
|
335
499
|
}
|
|
336
500
|
get loadingListener() {
|
|
337
|
-
return this._loadingListener || (this._loadingListener = (
|
|
338
|
-
this.set(
|
|
501
|
+
return this._loadingListener || (this._loadingListener = (e) => {
|
|
502
|
+
this.set(e.detail.loaded / e.detail.total * 100);
|
|
339
503
|
}), this._loadingListener;
|
|
340
504
|
}
|
|
341
|
-
pipe(
|
|
342
|
-
|
|
505
|
+
pipe(e) {
|
|
506
|
+
e.setProgress({
|
|
343
507
|
progress: this.progress,
|
|
344
508
|
caption: this.caption
|
|
345
|
-
}), this.addEventListener("progress", (
|
|
346
|
-
|
|
347
|
-
progress:
|
|
348
|
-
caption:
|
|
509
|
+
}), this.addEventListener("progress", (t) => {
|
|
510
|
+
e.setProgress({
|
|
511
|
+
progress: t.detail.progress,
|
|
512
|
+
caption: t.detail.caption
|
|
349
513
|
});
|
|
350
514
|
}), this.addEventListener("done", () => {
|
|
351
|
-
|
|
515
|
+
e.setLoaded();
|
|
352
516
|
});
|
|
353
517
|
}
|
|
354
|
-
addEventListener(
|
|
355
|
-
super.addEventListener(
|
|
518
|
+
addEventListener(e, t) {
|
|
519
|
+
super.addEventListener(e, t);
|
|
356
520
|
}
|
|
357
|
-
removeEventListener(
|
|
358
|
-
super.removeEventListener(
|
|
521
|
+
removeEventListener(e, t) {
|
|
522
|
+
super.removeEventListener(e, t);
|
|
359
523
|
}
|
|
360
524
|
notifyProgress() {
|
|
361
|
-
const
|
|
525
|
+
const e = this;
|
|
362
526
|
this.dispatchEvent(
|
|
363
527
|
new CustomEvent("progress", {
|
|
364
528
|
detail: {
|
|
365
529
|
get progress() {
|
|
366
|
-
return
|
|
530
|
+
return e.progress;
|
|
367
531
|
},
|
|
368
532
|
get caption() {
|
|
369
|
-
return
|
|
533
|
+
return e.caption;
|
|
370
534
|
}
|
|
371
535
|
}
|
|
372
536
|
})
|
|
@@ -377,8 +541,8 @@ class B extends EventTarget {
|
|
|
377
541
|
}
|
|
378
542
|
}
|
|
379
543
|
export {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
544
|
+
W as EmscriptenDownloadMonitor,
|
|
545
|
+
J as ProgressObserver,
|
|
546
|
+
k as ProgressTracker,
|
|
547
|
+
A as cloneResponseMonitorProgress
|
|
384
548
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/progress",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "PHP.wasm – loading progress monitoring",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,12 +29,13 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"main": "index.js",
|
|
31
31
|
"types": "index.d.ts",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "e8fedf92bbead5cec963c8d6976e7143d8e68721",
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=18.18.0",
|
|
35
35
|
"npm": ">=8.11.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@php-wasm/node-polyfills": "0.7.
|
|
38
|
+
"@php-wasm/node-polyfills": "0.7.3",
|
|
39
|
+
"@php-wasm/logger": "0.7.3"
|
|
39
40
|
}
|
|
40
41
|
}
|