@php-wasm/progress 0.5.5 → 0.6.0

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