@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.
Files changed (3) hide show
  1. package/index.cjs +1 -1
  2. package/index.js +194 -184
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -1 +1 @@
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}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;
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 w = (s, e, t) => {
2
- if (!e.has(s))
3
- throw TypeError("Cannot " + t);
1
+ var E = (r, t, e) => {
2
+ if (!t.has(r))
3
+ throw TypeError("Cannot " + e);
4
4
  };
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))
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
- 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) => ({
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
- _(s, e, n, t);
12
+ _(r, t, n, e);
13
13
  },
14
14
  get _() {
15
- return a(s, e, i);
15
+ return a(r, t, s);
16
16
  }
17
- }), g = (s, e, t) => (w(s, e, "access private method"), t);
18
- if (typeof File > "u") {
19
- class s extends Blob {
20
- constructor(t, i, n) {
21
- super(t);
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 || "";
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
- global.File = s;
27
- }
28
- function B(s) {
29
- return new Promise(function(e, t) {
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
- };
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
- typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
36
- const e = new FileReader();
37
- return e.readAsArrayBuffer(this), B(e);
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 = s;
85
+ globalThis.CustomEvent = r;
76
86
  }
77
- const F = 5 * 1024 * 1024;
78
- var u, d, v, I, b, P;
79
- class k extends EventTarget {
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
- h(this, v);
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
- h(this, b);
95
- h(this, u, {});
96
- h(this, d, {});
97
- g(this, v, I).call(this);
104
+ f(this, b);
105
+ f(this, g, {});
106
+ f(this, u, {});
107
+ p(this, v, I).call(this);
98
108
  }
99
- expectAssets(t) {
100
- for (const [i, n] of Object.entries(t)) {
101
- const r = "http://example.com/", o = new URL(i, r).pathname.split("/").pop();
102
- o in a(this, u) || (a(this, u)[o] = n), o in a(this, d) || (a(this, d)[o] = 0);
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(t) {
106
- const i = await t;
107
- return C(i, (r) => {
108
- g(this, b, P).call(this, i.url, r.detail.loaded, r.detail.total);
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
- u = new WeakMap(), d = new WeakMap(), v = new WeakSet(), I = function() {
113
- const t = WebAssembly.instantiateStreaming;
114
- WebAssembly.instantiateStreaming = async (i, ...n) => {
115
- const r = await i, l = r.url.substring(
116
- new URL(r.url).origin.length + 1
117
- ), o = C(
118
- r,
119
- ({ detail: { loaded: c, total: y } }) => g(this, b, P).call(this, l, c, y)
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 t(o, ...n);
131
+ return e(o, ...n);
122
132
  };
123
- }, b = new WeakSet(), P = function(t, i, n) {
124
- const r = new URL(t, "http://example.com").pathname.split("/").pop();
125
- n || (n = a(this, u)[r]), r in a(this, d) || console.warn(
126
- `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.`
127
- ), a(this, d)[r] = i, this.dispatchEvent(
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: R(a(this, d)),
131
- total: R(a(this, u))
140
+ loaded: T(a(this, u)),
141
+ total: T(a(this, g))
132
142
  }
133
143
  })
134
144
  );
135
145
  };
136
- function R(s) {
137
- return Object.values(s).reduce((e, t) => e + t, 0);
146
+ function T(r) {
147
+ return Object.values(r).reduce((t, e) => t + e, 0);
138
148
  }
139
- function C(s, e) {
140
- const t = s.headers.get("content-length") || "", i = parseInt(t, 10) || F;
141
- function n(r, l) {
142
- e(
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: r,
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(r) {
154
- if (!s.body) {
155
- r.close();
163
+ async start(i) {
164
+ if (!r.body) {
165
+ i.close();
156
166
  return;
157
167
  }
158
- const l = s.body.getReader();
168
+ const l = r.body.getReader();
159
169
  let o = 0;
160
170
  for (; ; )
161
171
  try {
162
- const { done: c, value: y } = await l.read();
163
- if (y && (o += y.byteLength), c) {
164
- n(o, o), r.close();
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, i), r.enqueue(y);
168
- } catch (c) {
169
- console.error({ e: c }), r.error(c);
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: s.status,
176
- statusText: s.statusText,
177
- headers: s.headers
185
+ status: r.status,
186
+ statusText: r.statusText,
187
+ headers: r.headers
178
188
  }
179
189
  );
180
190
  }
181
- var f, p, m, T;
182
- class M extends EventTarget {
191
+ var c, y, m, R;
192
+ class F extends EventTarget {
183
193
  constructor() {
184
194
  super(...arguments);
185
- h(this, m);
186
- h(this, f, void 0);
187
- h(this, p, void 0);
188
- _(this, f, {}), _(this, p, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
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(t, i = "") {
191
- const n = ++E(this, p)._;
192
- return a(this, f)[n] = 0, (r) => {
193
- const { loaded: l, total: o } = (r == null ? void 0 : r.detail) || {};
194
- a(this, f)[n] = l / o * t, g(this, m, T).call(this, this.totalProgress, "REAL_TIME", i);
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(t) {
198
- const i = ++E(this, p)._;
199
- a(this, f)[i] = t, g(this, m, T).call(this, this.totalProgress, "SLOWLY_INCREMENT");
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, f)).reduce(
203
- (t, i) => t + i,
212
+ return Object.values(a(this, c)).reduce(
213
+ (e, s) => e + s,
204
214
  0
205
215
  );
206
216
  }
207
217
  }
208
- f = new WeakMap(), p = new WeakMap(), m = new WeakSet(), T = function(t, i, n) {
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: t,
213
- mode: i,
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 x extends EventTarget {
230
+ class O extends EventTarget {
221
231
  constructor({
222
- weight: e = 1,
223
- caption: t = "",
224
- fillTime: i = 4
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 = e, this._selfCaption = t, this._fillTime = i;
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(e, t = "") {
264
- if (e || (e = this._selfWeight), this._selfWeight - e < -L)
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 ${e} as the total weight of registered stages would exceed 1.`
276
+ `Cannot add a stage with weight ${t} as the total weight of registered stages would exceed 1.`
267
277
  );
268
- this._selfWeight -= e;
269
- const i = new x({
270
- caption: t,
271
- weight: e,
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(i), i.addEventListener("progress", () => this.notifyProgress()), i.addEventListener("done", () => {
284
+ return this._subTrackers.push(s), s.addEventListener("progress", () => this.notifyProgress()), s.addEventListener("done", () => {
275
285
  this.done && this.notifyDone();
276
- }), i;
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: e = !0 } = {}) {
306
+ fillSlowly({ stopBeforeFinishing: t = !0 } = {}) {
297
307
  if (this._isFilling)
298
308
  return;
299
309
  this._isFilling = !0;
300
- const t = 100, i = this._fillTime / t;
310
+ const e = 100, s = this._fillTime / e;
301
311
  this._fillInterval = setInterval(() => {
302
- this.set(this._selfProgress + 1), e && this._selfProgress >= 99 && clearInterval(this._fillInterval);
303
- }, i);
312
+ this.set(this._selfProgress + 1), t && this._selfProgress >= 99 && clearInterval(this._fillInterval);
313
+ }, s);
304
314
  }
305
- set(e) {
306
- this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + L >= 100 && this.finish();
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 e = this._subTrackers.length - 1; e >= 0; e--)
313
- if (!this._subTrackers[e].done) {
314
- const t = this._subTrackers[e].caption;
315
- if (t)
316
- return t;
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(e) {
321
- this._selfCaption = e, this.notifyProgress();
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 e = this._subTrackers.reduce(
330
- (t, i) => t + i.progress * i.weight,
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(e * 1e4) / 1e4;
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 = (e) => {
340
- this.set(e);
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 = (e) => {
345
- this.set(e.detail.loaded / e.detail.total * 100);
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(e) {
349
- e.setProgress({
358
+ pipe(t) {
359
+ t.setProgress({
350
360
  progress: this.progress,
351
361
  caption: this.caption
352
- }), this.addEventListener("progress", (t) => {
353
- e.setProgress({
354
- progress: t.detail.progress,
355
- caption: t.detail.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
- e.setLoaded();
368
+ t.setLoaded();
359
369
  });
360
370
  }
361
- addEventListener(e, t) {
362
- super.addEventListener(e, t);
371
+ addEventListener(t, e) {
372
+ super.addEventListener(t, e);
363
373
  }
364
- removeEventListener(e, t) {
365
- super.removeEventListener(e, t);
374
+ removeEventListener(t, e) {
375
+ super.removeEventListener(t, e);
366
376
  }
367
377
  notifyProgress() {
368
- const e = this;
378
+ const t = this;
369
379
  this.dispatchEvent(
370
380
  new CustomEvent("progress", {
371
381
  detail: {
372
382
  get progress() {
373
- return e.progress;
383
+ return t.progress;
374
384
  },
375
385
  get caption() {
376
- return e.caption;
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
- k as EmscriptenDownloadMonitor,
388
- M as ProgressObserver,
389
- x as ProgressTracker,
390
- C as cloneResponseMonitorProgress
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.5",
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": "eb45486a61d06a8a9e62cbd65348bfb274ff9e7c",
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.5"
38
+ "@php-wasm/node-polyfills": "0.6.7"
39
39
  }
40
40
  }