@php-wasm/progress 0.5.6 → 0.6.1

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.
@@ -0,0 +1,4 @@
1
+ const e = {};
2
+ export {
3
+ e as default
4
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={};exports.default=e;
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}typeof crypto>"u"&&Promise.resolve().then(()=>require("./__vite-browser-external-b3701507.cjs")).then(s=>{global.crypto=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,36 @@ 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
+ typeof crypto > "u" && import("./__vite-browser-external-2447137e.js").then((s) => {
78
+ global.crypto = s;
79
+ });
80
+ const F = 5 * 1024 * 1024;
81
+ var u, d, v, I, b, P;
82
+ class k extends EventTarget {
83
+ constructor() {
81
84
  super();
82
85
  /**
83
86
  * Replaces the default WebAssembly.instantiateStreaming with a version
84
87
  * that monitors the download #progress.
85
88
  */
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);
89
+ h(this, v);
93
90
  /**
94
91
  * Notifies about the download #progress of a file.
95
92
  *
@@ -97,159 +94,139 @@ class W extends EventTarget {
97
94
  * @param loaded The number of bytes of that file loaded so far.
98
95
  * @param fileSize The total number of bytes in the loaded file.
99
96
  */
100
- d(this, b);
101
- d(this, g, {});
102
- d(this, p, {});
103
- this.setModules(t), u(this, w, S).call(this);
97
+ h(this, b);
98
+ h(this, u, {});
99
+ h(this, d, {});
100
+ g(this, v, I).call(this);
104
101
  }
105
- getEmscriptenOptions() {
106
- return {
107
- dataFileDownloads: u(this, E, B).call(this)
108
- };
102
+ expectAssets(t) {
103
+ for (const [i, n] of Object.entries(t)) {
104
+ const r = "http://example.com/", o = new URL(i, r).pathname.split("/").pop();
105
+ o in a(this, u) || (a(this, u)[o] = n), o in a(this, d) || (a(this, d)[o] = 0);
106
+ }
109
107
  }
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
- ));
108
+ async monitorFetch(t) {
109
+ const i = await t;
110
+ return C(i, (r) => {
111
+ g(this, b, P).call(this, i.url, r.detail.loaded, r.detail.total);
112
+ });
123
113
  }
124
114
  }
125
- g = new WeakMap(), p = new WeakMap(), w = new WeakSet(), S = function() {
115
+ u = new WeakMap(), d = new WeakMap(), v = new WeakSet(), I = function() {
126
116
  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)
117
+ WebAssembly.instantiateStreaming = async (i, ...n) => {
118
+ const r = await i, l = r.url.substring(
119
+ new URL(r.url).origin.length + 1
120
+ ), o = C(
121
+ r,
122
+ ({ detail: { loaded: c, total: y } }) => g(this, b, P).call(this, l, c, y)
133
123
  );
134
124
  return t(o, ...n);
135
125
  };
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(
126
+ }, b = new WeakSet(), P = function(t, i, n) {
127
+ const r = new URL(t, "http://example.com").pathname.split("/").pop();
128
+ n || (n = a(this, u)[r]), r in a(this, d) || console.warn(
129
+ `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.`
130
+ ), a(this, d)[r] = i, this.dispatchEvent(
154
131
  new CustomEvent("progress", {
155
132
  detail: {
156
- loaded: C(l(this, p)),
157
- total: C(l(this, g))
133
+ loaded: R(a(this, d)),
134
+ total: R(a(this, u))
158
135
  }
159
136
  })
160
137
  );
161
138
  };
162
- function C(r) {
163
- return Object.values(r).reduce((e, t) => e + t, 0);
139
+ function R(s) {
140
+ return Object.values(s).reduce((e, t) => e + t, 0);
164
141
  }
165
- function O(r, e) {
166
- const t = r.headers.get("content-length") || "", s = parseInt(t, 10) || D;
167
- function n(i, a) {
142
+ function C(s, e) {
143
+ const t = s.headers.get("content-length") || "", i = parseInt(t, 10) || F;
144
+ function n(r, l) {
168
145
  e(
169
146
  new CustomEvent("progress", {
170
147
  detail: {
171
- loaded: i,
172
- total: a
148
+ loaded: r,
149
+ total: l
173
150
  }
174
151
  })
175
152
  );
176
153
  }
177
154
  return new Response(
178
155
  new ReadableStream({
179
- async start(i) {
180
- if (!r.body) {
181
- i.close();
156
+ async start(r) {
157
+ if (!s.body) {
158
+ r.close();
182
159
  return;
183
160
  }
184
- const a = r.body.getReader();
161
+ const l = s.body.getReader();
185
162
  let o = 0;
186
163
  for (; ; )
187
164
  try {
188
- const { done: h, value: c } = await a.read();
189
- if (c && (o += c.byteLength), h) {
190
- n(o, o), i.close();
165
+ const { done: c, value: y } = await l.read();
166
+ if (y && (o += y.byteLength), c) {
167
+ n(o, o), r.close();
191
168
  break;
192
169
  } else
193
- n(o, s), i.enqueue(c);
194
- } catch (h) {
195
- console.error({ e: h }), i.error(h);
170
+ n(o, i), r.enqueue(y);
171
+ } catch (c) {
172
+ console.error({ e: c }), r.error(c);
196
173
  break;
197
174
  }
198
175
  }
199
176
  }),
200
177
  {
201
- status: r.status,
202
- statusText: r.statusText,
203
- headers: r.headers
178
+ status: s.status,
179
+ statusText: s.statusText,
180
+ headers: s.headers
204
181
  }
205
182
  );
206
183
  }
207
- var f, m, _, R;
208
- class N extends EventTarget {
184
+ var f, p, m, T;
185
+ class M extends EventTarget {
209
186
  constructor() {
210
187
  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 = "";
188
+ h(this, m);
189
+ h(this, f, void 0);
190
+ h(this, p, void 0);
191
+ _(this, f, {}), _(this, p, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
215
192
  }
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);
193
+ partialObserver(t, i = "") {
194
+ const n = ++E(this, p)._;
195
+ return a(this, f)[n] = 0, (r) => {
196
+ const { loaded: l, total: o } = (r == null ? void 0 : r.detail) || {};
197
+ a(this, f)[n] = l / o * t, g(this, m, T).call(this, this.totalProgress, "REAL_TIME", i);
221
198
  };
222
199
  }
223
200
  slowlyIncrementBy(t) {
224
- const s = ++P(this, m)._;
225
- l(this, f)[s] = t, u(this, _, R).call(this, this.totalProgress, "SLOWLY_INCREMENT");
201
+ const i = ++E(this, p)._;
202
+ a(this, f)[i] = t, g(this, m, T).call(this, this.totalProgress, "SLOWLY_INCREMENT");
226
203
  }
227
204
  get totalProgress() {
228
- return Object.values(l(this, f)).reduce(
229
- (t, s) => t + s,
205
+ return Object.values(a(this, f)).reduce(
206
+ (t, i) => t + i,
230
207
  0
231
208
  );
232
209
  }
233
210
  }
234
- f = new WeakMap(), m = new WeakMap(), _ = new WeakSet(), R = function(t, s, n) {
211
+ f = new WeakMap(), p = new WeakMap(), m = new WeakSet(), T = function(t, i, n) {
235
212
  this.dispatchEvent(
236
213
  new CustomEvent("progress", {
237
214
  detail: {
238
215
  progress: t,
239
- mode: s,
216
+ mode: i,
240
217
  caption: n
241
218
  }
242
219
  })
243
220
  );
244
221
  };
245
- const T = 1e-5;
246
- class I extends EventTarget {
222
+ const L = 1e-5;
223
+ class x extends EventTarget {
247
224
  constructor({
248
225
  weight: e = 1,
249
226
  caption: t = "",
250
- fillTime: s = 4
227
+ fillTime: i = 4
251
228
  } = {}) {
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;
229
+ 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
230
  }
254
231
  /**
255
232
  * Creates a new sub-tracker with a specific weight.
@@ -287,19 +264,19 @@ class I extends EventTarget {
287
264
  * ```
288
265
  */
289
266
  stage(e, t = "") {
290
- if (e || (e = this._selfWeight), this._selfWeight - e < -T)
267
+ if (e || (e = this._selfWeight), this._selfWeight - e < -L)
291
268
  throw new Error(
292
269
  `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
293
270
  );
294
271
  this._selfWeight -= e;
295
- const s = new I({
272
+ const i = new x({
296
273
  caption: t,
297
274
  weight: e,
298
275
  fillTime: this._fillTime
299
276
  });
300
- return this._subTrackers.push(s), s.addEventListener("progress", () => this.notifyProgress()), s.addEventListener("done", () => {
277
+ return this._subTrackers.push(i), i.addEventListener("progress", () => this.notifyProgress()), i.addEventListener("done", () => {
301
278
  this.done && this.notifyDone();
302
- }), s;
279
+ }), i;
303
280
  }
304
281
  /**
305
282
  * Fills the progress bar slowly over time, simulating progress.
@@ -323,13 +300,13 @@ class I extends EventTarget {
323
300
  if (this._isFilling)
324
301
  return;
325
302
  this._isFilling = !0;
326
- const t = 100, s = this._fillTime / t;
303
+ const t = 100, i = this._fillTime / t;
327
304
  this._fillInterval = setInterval(() => {
328
305
  this.set(this._selfProgress + 1), e && this._selfProgress >= 99 && clearInterval(this._fillInterval);
329
- }, s);
306
+ }, i);
330
307
  }
331
308
  set(e) {
332
- this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + T >= 100 && this.finish();
309
+ this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + L >= 100 && this.finish();
333
310
  }
334
311
  finish() {
335
312
  this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
@@ -347,13 +324,13 @@ class I extends EventTarget {
347
324
  this._selfCaption = e, this.notifyProgress();
348
325
  }
349
326
  get done() {
350
- return this.progress + T >= 100;
327
+ return this.progress + L >= 100;
351
328
  }
352
329
  get progress() {
353
330
  if (this._selfDone)
354
331
  return 100;
355
332
  const e = this._subTrackers.reduce(
356
- (t, s) => t + s.progress * s.weight,
333
+ (t, i) => t + i.progress * i.weight,
357
334
  this._selfProgress * this._selfWeight
358
335
  );
359
336
  return Math.round(e * 1e4) / 1e4;
@@ -410,8 +387,8 @@ class I extends EventTarget {
410
387
  }
411
388
  }
412
389
  export {
413
- W as EmscriptenDownloadMonitor,
414
- N as ProgressObserver,
415
- I as ProgressTracker,
416
- O as cloneResponseMonitorProgress
390
+ k as EmscriptenDownloadMonitor,
391
+ M as ProgressObserver,
392
+ x as ProgressTracker,
393
+ C as cloneResponseMonitorProgress
417
394
  };
@@ -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.6",
3
+ "version": "0.6.1",
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": "72e190ebb407051ccb5ef544e2a62018395395a0",
32
+ "gitHead": "171b22b853786b8912d9624ea064eaa1e985e96b",
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.6"
38
+ "@php-wasm/node-polyfills": "0.6.1"
39
39
  }
40
40
  }