@php-wasm/progress 0.1.32 → 0.1.35
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 +15 -10
- package/lib/progress-tracker.d.ts +1 -0
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=5*1024*1024;class p extends EventTarget{#e={};#t={};constructor(e=[]){super(),this.setModules(e),this.#s()}getEmscriptenOptions(){return{dataFileDownloads:this.#i()}}setModules(e){this.#e=e.reduce((t,s)=>{if(s.dependenciesTotalSize>0){const r="http://example.com/",n=new URL(s.dependencyFilename,r).pathname.split("/").pop();t[n]=Math.max(n in t?t[n]:0,s.dependenciesTotalSize)}return t},{}),this.#t=Object.fromEntries(Object.entries(this.#e).map(([t])=>[t,0]))}#s(){const e=WebAssembly.instantiateStreaming;WebAssembly.instantiateStreaming=async(t,...s)=>{const r=await t,i=r.url.substring(new URL(r.url).origin.length+1),n=u(r,({detail:{loaded:a,total:l}})=>this.#r(i,a,l));return e(n,...s)}}#i(){const e=this,t={};return new Proxy(t,{set(s,r,i){return e.#r(r,i.loaded,i.total),s[r]=new Proxy(JSON.parse(JSON.stringify(i)),{set(n,a,l){return n[a]=l,e.#r(r,n.loaded,n.total),!0}}),!0}})}#r(e,t,s){const r=new URL(e,"http://example.com").pathname.split("/").pop();s||(s=this.#e[r]),r in this.#t||console.warn(`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.`),this.#t[
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=5*1024*1024;class p extends EventTarget{#e={};#t={};constructor(e=[]){super(),this.setModules(e),this.#s()}getEmscriptenOptions(){return{dataFileDownloads:this.#i()}}setModules(e){this.#e=e.reduce((t,s)=>{if(s.dependenciesTotalSize>0){const r="http://example.com/",n=new URL(s.dependencyFilename,r).pathname.split("/").pop();t[n]=Math.max(n in t?t[n]:0,s.dependenciesTotalSize)}return t},{}),this.#t=Object.fromEntries(Object.entries(this.#e).map(([t])=>[t,0]))}#s(){const e=WebAssembly.instantiateStreaming;WebAssembly.instantiateStreaming=async(t,...s)=>{const r=await t,i=r.url.substring(new URL(r.url).origin.length+1),n=u(r,({detail:{loaded:a,total:l}})=>this.#r(i,a,l));return e(n,...s)}}#i(){const e=this,t={};return new Proxy(t,{set(s,r,i){return e.#r(r,i.loaded,i.total),s[r]=new Proxy(JSON.parse(JSON.stringify(i)),{set(n,a,l){return n[a]=l,e.#r(r,n.loaded,n.total),!0}}),!0}})}#r(e,t,s){const r=new URL(e,"http://example.com").pathname.split("/").pop();s||(s=this.#e[r]),r in this.#t||console.warn(`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.`),this.#t[r]=t,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:c(this.#t),total:c(this.#e)}}))}}function c(o){return Object.values(o).reduce((e,t)=>e+t,0)}function u(o,e){const t=o.headers.get("content-length")||"",s=parseInt(t,10)||f;function r(i,n){e(new CustomEvent("progress",{detail:{loaded:i,total:n}}))}return new Response(new ReadableStream({async start(i){if(!o.body){i.close();return}const n=o.body.getReader();let a=0;for(;;)try{const{done:l,value:h}=await n.read();if(h&&(a+=h.byteLength),l){r(a,a),i.close();break}else r(a,s),i.enqueue(h)}catch(l){console.error({e:l}),i.error(l);break}}}),{status:o.status,statusText:o.statusText,headers:o.headers})}class _ extends EventTarget{constructor(){super(...arguments),this.#e={},this.#t=0,this.progress=0,this.mode="REAL_TIME",this.caption=""}#e;#t;partialObserver(e,t=""){const s=++this.#t;return this.#e[s]=0,r=>{const{loaded:i,total:n}=r?.detail||{};this.#e[s]=i/n*e,this.#s(this.totalProgress,"REAL_TIME",t)}}slowlyIncrementBy(e){const t=++this.#t;this.#e[t]=e,this.#s(this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(this.#e).reduce((e,t)=>e+t,0)}#s(e,t,s){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:e,mode:t,caption:s}}))}}const d=1e-5;class g extends EventTarget{constructor({weight:e=1,caption:t="",fillTime:s=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=s}stage(e,t=""){if(e||(e=this._selfWeight),this._selfWeight-e<-d)throw new Error(`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`);this._selfWeight-=e;const s=new g({caption:t,weight:e,fillTime:this._fillTime});return this._subTrackers.push(s),s.addEventListener("progress",()=>this.notifyProgress()),s.addEventListener("done",()=>{this.done&&this.notifyDone()}),s}fillSlowly({stopBeforeFinishing:e=!0}={}){if(this._isFilling)return;this._isFilling=!0;const t=100,s=this._fillTime/t;this._fillInterval=setInterval(()=>{this.set(this._selfProgress+1),e&&this._selfProgress>=99&&clearInterval(this._fillInterval)},s)}set(e){this._selfProgress=Math.min(e,100),this.notifyProgress(),this._selfProgress+d>=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+d>=100}get progress(){if(this._selfDone)return 100;const e=this._subTrackers.reduce((t,s)=>t+s.progress*s.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=p;exports.ProgressObserver=_;exports.ProgressTracker=g;exports.cloneResponseMonitorProgress=u;
|
package/index.js
CHANGED
|
@@ -32,7 +32,7 @@ class f extends EventTarget {
|
|
|
32
32
|
WebAssembly.instantiateStreaming = async (t, ...s) => {
|
|
33
33
|
const i = await t, r = i.url.substring(
|
|
34
34
|
new URL(i.url).origin.length + 1
|
|
35
|
-
), n =
|
|
35
|
+
), n = c(
|
|
36
36
|
i,
|
|
37
37
|
({ detail: { loaded: a, total: l } }) => this.#i(r, a, l)
|
|
38
38
|
);
|
|
@@ -67,7 +67,7 @@ class f extends EventTarget {
|
|
|
67
67
|
const i = new URL(e, "http://example.com").pathname.split("/").pop();
|
|
68
68
|
s || (s = this.#e[i]), i in this.#t || console.warn(
|
|
69
69
|
`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.`
|
|
70
|
-
), this.#t[
|
|
70
|
+
), this.#t[i] = t, this.dispatchEvent(
|
|
71
71
|
new CustomEvent("progress", {
|
|
72
72
|
detail: {
|
|
73
73
|
loaded: g(this.#t),
|
|
@@ -80,7 +80,7 @@ class f extends EventTarget {
|
|
|
80
80
|
function g(o) {
|
|
81
81
|
return Object.values(o).reduce((e, t) => e + t, 0);
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function c(o, e) {
|
|
84
84
|
const t = o.headers.get("content-length") || "", s = parseInt(t, 10) || 5242880;
|
|
85
85
|
function i(r, n) {
|
|
86
86
|
e(
|
|
@@ -158,13 +158,13 @@ class p extends EventTarget {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
const d = 1e-5;
|
|
161
|
-
class
|
|
161
|
+
class u extends EventTarget {
|
|
162
162
|
constructor({
|
|
163
163
|
weight: e = 1,
|
|
164
164
|
caption: t = "",
|
|
165
165
|
fillTime: s = 4
|
|
166
166
|
} = {}) {
|
|
167
|
-
super(), this._selfWeight = 1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight = e, this._selfCaption = t, this._fillTime = s;
|
|
167
|
+
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 = s;
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
170
|
* Creates a new sub-tracker with a specific weight.
|
|
@@ -207,7 +207,7 @@ class c extends EventTarget {
|
|
|
207
207
|
`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
|
|
208
208
|
);
|
|
209
209
|
this._selfWeight -= e;
|
|
210
|
-
const s = new
|
|
210
|
+
const s = new u({
|
|
211
211
|
caption: t,
|
|
212
212
|
weight: e,
|
|
213
213
|
fillTime: this._fillTime
|
|
@@ -247,7 +247,7 @@ class c extends EventTarget {
|
|
|
247
247
|
this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + d >= 100 && this.finish();
|
|
248
248
|
}
|
|
249
249
|
finish() {
|
|
250
|
-
this._fillInterval && clearInterval(this._fillInterval), this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
|
|
250
|
+
this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
|
|
251
251
|
}
|
|
252
252
|
get caption() {
|
|
253
253
|
for (let e = this._subTrackers.length - 1; e >= 0; e--)
|
|
@@ -265,6 +265,8 @@ class c extends EventTarget {
|
|
|
265
265
|
return this.progress + d >= 100;
|
|
266
266
|
}
|
|
267
267
|
get progress() {
|
|
268
|
+
if (this._selfDone)
|
|
269
|
+
return 100;
|
|
268
270
|
const e = this._subTrackers.reduce(
|
|
269
271
|
(t, s) => t + s.progress * s.weight,
|
|
270
272
|
this._selfProgress * this._selfWeight
|
|
@@ -285,7 +287,10 @@ class c extends EventTarget {
|
|
|
285
287
|
}), this._loadingListener;
|
|
286
288
|
}
|
|
287
289
|
pipe(e) {
|
|
288
|
-
|
|
290
|
+
e.setProgress({
|
|
291
|
+
progress: this.progress,
|
|
292
|
+
caption: this.caption
|
|
293
|
+
}), this.addEventListener("progress", (t) => {
|
|
289
294
|
e.setProgress({
|
|
290
295
|
progress: t.detail.progress,
|
|
291
296
|
caption: t.detail.caption
|
|
@@ -322,6 +327,6 @@ class c extends EventTarget {
|
|
|
322
327
|
export {
|
|
323
328
|
f as EmscriptenDownloadMonitor,
|
|
324
329
|
p as ProgressObserver,
|
|
325
|
-
|
|
326
|
-
|
|
330
|
+
u as ProgressTracker,
|
|
331
|
+
c as cloneResponseMonitorProgress
|
|
327
332
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/progress",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"description": "PHP.wasm – loading progress monitoring",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"main": "index.js",
|
|
31
31
|
"types": "index.d.ts",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "0962f89a2b1a438997960a25c26f5341db063a3e",
|
|
33
33
|
"dependencies": {}
|
|
34
34
|
}
|