@php-wasm/progress 0.5.2 → 0.5.4

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 +136 -76
  3. package/package.json +6 -4
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var P=(i,e,t)=>{if(!e.has(i))throw TypeError("Cannot "+t)};var l=(i,e,t)=>(P(i,e,"read from private field"),t?t.call(i):e.get(i)),d=(i,e,t)=>{if(e.has(i))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(i):e.set(i,t)},_=(i,e,t,s)=>(P(i,e,"write to private field"),s?s.call(i,t):e.set(i,t),t);var L=(i,e,t,s)=>({set _(n){_(i,e,n,t)},get _(){return l(i,e,s)}}),g=(i,e,t)=>(P(i,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=5*1024*1024;var f,p,y,M,w,C,m,E;class k extends EventTarget{constructor(t=[]){super();d(this,y);d(this,w);d(this,m);d(this,f,{});d(this,p,{});this.setModules(t),g(this,y,M).call(this)}getEmscriptenOptions(){return{dataFileDownloads:g(this,w,C).call(this)}}setModules(t){_(this,f,t.reduce((s,n)=>{if(n.dependenciesTotalSize>0){const r="http://example.com/",o=new URL(n.dependencyFilename,r).pathname.split("/").pop();s[o]=Math.max(o in s?s[o]:0,n.dependenciesTotalSize)}return s},{})),_(this,p,Object.fromEntries(Object.entries(l(this,f)).map(([s])=>[s,0])))}}f=new WeakMap,p=new WeakMap,y=new WeakSet,M=function(){const t=WebAssembly.instantiateStreaming;WebAssembly.instantiateStreaming=async(s,...n)=>{const r=await s,a=r.url.substring(new URL(r.url).origin.length+1),o=x(r,({detail:{loaded:h,total:u}})=>g(this,m,E).call(this,a,h,u));return t(o,...n)}},w=new WeakSet,C=function(){const t=this,s={};return new Proxy(s,{set(n,r,a){var o;return g(o=t,m,E).call(o,r,a.loaded,a.total),n[r]=new Proxy(JSON.parse(JSON.stringify(a)),{set(h,u,D){var O;return h[u]=D,g(O=t,m,E).call(O,r,h.loaded,h.total),!0}}),!0}})},m=new WeakSet,E=function(t,s,n){const r=new URL(t,"http://example.com").pathname.split("/").pop();n||(n=l(this,f)[r]),r in l(this,p)||console.warn(`Registered a download #progress of an unregistered file "${r}". This may cause a sudden **decrease** in the #progress percentage as the total number of bytes increases during the download.`),l(this,p)[r]=s,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:R(l(this,p)),total:R(l(this,f))}}))};function R(i){return Object.values(i).reduce((e,t)=>e+t,0)}function x(i,e){const t=i.headers.get("content-length")||"",s=parseInt(t,10)||F;function n(r,a){e(new CustomEvent("progress",{detail:{loaded:r,total:a}}))}return new Response(new ReadableStream({async start(r){if(!i.body){r.close();return}const a=i.body.getReader();let o=0;for(;;)try{const{done:h,value:u}=await a.read();if(u&&(o+=u.byteLength),h){n(o,o),r.close();break}else n(o,s),r.enqueue(u)}catch(h){console.error({e:h}),r.error(h);break}}}),{status:i.status,statusText:i.statusText,headers:i.headers})}var c,v,b,I;class W extends EventTarget{constructor(){super(...arguments);d(this,b);d(this,c,void 0);d(this,v,void 0);_(this,c,{}),_(this,v,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(t,s=""){const n=++L(this,v)._;return l(this,c)[n]=0,r=>{const{loaded:a,total:o}=(r==null?void 0:r.detail)||{};l(this,c)[n]=a/o*t,g(this,b,I).call(this,this.totalProgress,"REAL_TIME",s)}}slowlyIncrementBy(t){const s=++L(this,v)._;l(this,c)[s]=t,g(this,b,I).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(l(this,c)).reduce((t,s)=>t+s,0)}}c=new WeakMap,v=new WeakMap,b=new WeakSet,I=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=x;
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"}),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;
package/index.js CHANGED
@@ -1,35 +1,95 @@
1
- var L = (i, e, t) => {
2
- if (!e.has(i))
1
+ var L = (r, e, t) => {
2
+ if (!e.has(r))
3
3
  throw TypeError("Cannot " + t);
4
4
  };
5
- var l = (i, e, t) => (L(i, e, "read from private field"), t ? t.call(i) : e.get(i)), d = (i, e, t) => {
6
- if (e.has(i))
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))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
- e instanceof WeakSet ? e.add(i) : e.set(i, t);
9
- }, _ = (i, e, t, s) => (L(i, e, "write to private field"), s ? s.call(i, t) : e.set(i, t), t);
10
- var P = (i, e, t, s) => ({
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) => ({
11
11
  set _(n) {
12
- _(i, e, n, t);
12
+ y(r, e, n, t);
13
13
  },
14
14
  get _() {
15
- return l(i, e, s);
15
+ return l(r, e, s);
16
16
  }
17
- }), g = (i, e, t) => (L(i, e, "access private method"), t);
18
- var f, p, y, O, w, R, m, b;
19
- class A extends EventTarget {
17
+ }), u = (r, e, t) => (L(r, e, "access private method"), t);
18
+ if (typeof File > "u") {
19
+ class r extends Blob {
20
+ constructor(t, s, n) {
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 || "";
24
+ }
25
+ }
26
+ global.File = r;
27
+ }
28
+ function F(r) {
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"));
32
+ };
33
+ });
34
+ }
35
+ typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
36
+ const e = new FileReader();
37
+ return e.readAsArrayBuffer(this), F(e);
38
+ });
39
+ typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
40
+ const e = new FileReader();
41
+ return e.readAsText(this), F(e);
42
+ });
43
+ function A() {
44
+ const r = new Uint8Array([1, 2, 3, 4]), t = new File([r], "test").stream();
45
+ try {
46
+ return t.getReader({ mode: "byob" }), 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 r = 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 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();
64
+ }
65
+ });
66
+ });
67
+ if (typeof CustomEvent > "u") {
68
+ class r extends Event {
69
+ constructor(t, s = {}) {
70
+ super(t, s), this.detail = s.detail;
71
+ }
72
+ initCustomEvent() {
73
+ }
74
+ }
75
+ globalThis.CustomEvent = r;
76
+ }
77
+ const D = 5 * 1024 * 1024;
78
+ var g, p, w, S, E, B, b, v;
79
+ class W extends EventTarget {
20
80
  constructor(t = []) {
21
81
  super();
22
82
  /**
23
83
  * Replaces the default WebAssembly.instantiateStreaming with a version
24
84
  * that monitors the download #progress.
25
85
  */
26
- d(this, y);
86
+ d(this, w);
27
87
  /**
28
88
  * Creates a `dataFileDownloads` Proxy object that can be passed
29
89
  * to `startPHP` to monitor the download #progress of the data
30
90
  * dependencies.
31
91
  */
32
- d(this, w);
92
+ d(this, E);
33
93
  /**
34
94
  * Notifies about the download #progress of a file.
35
95
  *
@@ -37,78 +97,78 @@ class A extends EventTarget {
37
97
  * @param loaded The number of bytes of that file loaded so far.
38
98
  * @param fileSize The total number of bytes in the loaded file.
39
99
  */
40
- d(this, m);
41
- d(this, f, {});
100
+ d(this, b);
101
+ d(this, g, {});
42
102
  d(this, p, {});
43
- this.setModules(t), g(this, y, O).call(this);
103
+ this.setModules(t), u(this, w, S).call(this);
44
104
  }
45
105
  getEmscriptenOptions() {
46
106
  return {
47
- dataFileDownloads: g(this, w, R).call(this)
107
+ dataFileDownloads: u(this, E, B).call(this)
48
108
  };
49
109
  }
50
110
  setModules(t) {
51
- _(this, f, t.reduce((s, n) => {
111
+ y(this, g, t.reduce((s, n) => {
52
112
  if (n.dependenciesTotalSize > 0) {
53
- const r = "http://example.com/", o = new URL(n.dependencyFilename, r).pathname.split("/").pop();
113
+ const i = "http://example.com/", o = new URL(n.dependencyFilename, i).pathname.split("/").pop();
54
114
  s[o] = Math.max(
55
115
  o in s ? s[o] : 0,
56
116
  n.dependenciesTotalSize
57
117
  );
58
118
  }
59
119
  return s;
60
- }, {})), _(this, p, Object.fromEntries(
61
- Object.entries(l(this, f)).map(([s]) => [s, 0])
120
+ }, {})), y(this, p, Object.fromEntries(
121
+ Object.entries(l(this, g)).map(([s]) => [s, 0])
62
122
  ));
63
123
  }
64
124
  }
65
- f = new WeakMap(), p = new WeakMap(), y = new WeakSet(), O = function() {
125
+ g = new WeakMap(), p = new WeakMap(), w = new WeakSet(), S = function() {
66
126
  const t = WebAssembly.instantiateStreaming;
67
127
  WebAssembly.instantiateStreaming = async (s, ...n) => {
68
- const r = await s, a = r.url.substring(
69
- new URL(r.url).origin.length + 1
70
- ), o = D(
71
- r,
72
- ({ detail: { loaded: h, total: c } }) => g(this, m, b).call(this, a, h, c)
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)
73
133
  );
74
134
  return t(o, ...n);
75
135
  };
76
- }, w = new WeakSet(), R = function() {
136
+ }, E = new WeakSet(), B = function() {
77
137
  const t = this, s = {};
78
138
  return new Proxy(s, {
79
- set(n, r, a) {
139
+ set(n, i, a) {
80
140
  var o;
81
- return g(o = t, m, b).call(o, r, a.loaded, a.total), n[r] = new Proxy(JSON.parse(JSON.stringify(a)), {
82
- set(h, c, F) {
83
- var S;
84
- return h[c] = F, g(S = t, m, b).call(S, r, h.loaded, h.total), !0;
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;
85
145
  }
86
146
  }), !0;
87
147
  }
88
148
  });
89
- }, m = new WeakSet(), b = function(t, s, n) {
90
- const r = new URL(t, "http://example.com").pathname.split("/").pop();
91
- n || (n = l(this, f)[r]), r in l(this, p) || console.warn(
92
- `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.`
93
- ), l(this, p)[r] = s, this.dispatchEvent(
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(
94
154
  new CustomEvent("progress", {
95
155
  detail: {
96
156
  loaded: C(l(this, p)),
97
- total: C(l(this, f))
157
+ total: C(l(this, g))
98
158
  }
99
159
  })
100
160
  );
101
161
  };
102
- function C(i) {
103
- return Object.values(i).reduce((e, t) => e + t, 0);
162
+ function C(r) {
163
+ return Object.values(r).reduce((e, t) => e + t, 0);
104
164
  }
105
- function D(i, e) {
106
- const t = i.headers.get("content-length") || "", s = parseInt(t, 10) || 5242880;
107
- function n(r, a) {
165
+ function O(r, e) {
166
+ const t = r.headers.get("content-length") || "", s = parseInt(t, 10) || D;
167
+ function n(i, a) {
108
168
  e(
109
169
  new CustomEvent("progress", {
110
170
  detail: {
111
- loaded: r,
171
+ loaded: i,
112
172
  total: a
113
173
  }
114
174
  })
@@ -116,62 +176,62 @@ function D(i, e) {
116
176
  }
117
177
  return new Response(
118
178
  new ReadableStream({
119
- async start(r) {
120
- if (!i.body) {
121
- r.close();
179
+ async start(i) {
180
+ if (!r.body) {
181
+ i.close();
122
182
  return;
123
183
  }
124
- const a = i.body.getReader();
184
+ const a = r.body.getReader();
125
185
  let o = 0;
126
186
  for (; ; )
127
187
  try {
128
188
  const { done: h, value: c } = await a.read();
129
189
  if (c && (o += c.byteLength), h) {
130
- n(o, o), r.close();
190
+ n(o, o), i.close();
131
191
  break;
132
192
  } else
133
- n(o, s), r.enqueue(c);
193
+ n(o, s), i.enqueue(c);
134
194
  } catch (h) {
135
- console.error({ e: h }), r.error(h);
195
+ console.error({ e: h }), i.error(h);
136
196
  break;
137
197
  }
138
198
  }
139
199
  }),
140
200
  {
141
- status: i.status,
142
- statusText: i.statusText,
143
- headers: i.headers
201
+ status: r.status,
202
+ statusText: r.statusText,
203
+ headers: r.headers
144
204
  }
145
205
  );
146
206
  }
147
- var u, v, E, I;
148
- class W extends EventTarget {
207
+ var f, m, _, R;
208
+ class N extends EventTarget {
149
209
  constructor() {
150
210
  super(...arguments);
151
- d(this, E);
152
- d(this, u, void 0);
153
- d(this, v, void 0);
154
- _(this, u, {}), _(this, v, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
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 = "";
155
215
  }
156
216
  partialObserver(t, s = "") {
157
- const n = ++P(this, v)._;
158
- return l(this, u)[n] = 0, (r) => {
159
- const { loaded: a, total: o } = (r == null ? void 0 : r.detail) || {};
160
- l(this, u)[n] = a / o * t, g(this, E, I).call(this, this.totalProgress, "REAL_TIME", 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);
161
221
  };
162
222
  }
163
223
  slowlyIncrementBy(t) {
164
- const s = ++P(this, v)._;
165
- l(this, u)[s] = t, g(this, E, I).call(this, this.totalProgress, "SLOWLY_INCREMENT");
224
+ const s = ++P(this, m)._;
225
+ l(this, f)[s] = t, u(this, _, R).call(this, this.totalProgress, "SLOWLY_INCREMENT");
166
226
  }
167
227
  get totalProgress() {
168
- return Object.values(l(this, u)).reduce(
228
+ return Object.values(l(this, f)).reduce(
169
229
  (t, s) => t + s,
170
230
  0
171
231
  );
172
232
  }
173
233
  }
174
- u = new WeakMap(), v = new WeakMap(), E = new WeakSet(), I = function(t, s, n) {
234
+ f = new WeakMap(), m = new WeakMap(), _ = new WeakSet(), R = function(t, s, n) {
175
235
  this.dispatchEvent(
176
236
  new CustomEvent("progress", {
177
237
  detail: {
@@ -183,7 +243,7 @@ u = new WeakMap(), v = new WeakMap(), E = new WeakSet(), I = function(t, s, n) {
183
243
  );
184
244
  };
185
245
  const T = 1e-5;
186
- class x extends EventTarget {
246
+ class I extends EventTarget {
187
247
  constructor({
188
248
  weight: e = 1,
189
249
  caption: t = "",
@@ -232,7 +292,7 @@ class x extends EventTarget {
232
292
  `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
233
293
  );
234
294
  this._selfWeight -= e;
235
- const s = new x({
295
+ const s = new I({
236
296
  caption: t,
237
297
  weight: e,
238
298
  fillTime: this._fillTime
@@ -350,8 +410,8 @@ class x extends EventTarget {
350
410
  }
351
411
  }
352
412
  export {
353
- A as EmscriptenDownloadMonitor,
354
- W as ProgressObserver,
355
- x as ProgressTracker,
356
- D as cloneResponseMonitorProgress
413
+ W as EmscriptenDownloadMonitor,
414
+ N as ProgressObserver,
415
+ I as ProgressTracker,
416
+ O as cloneResponseMonitorProgress
357
417
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/progress",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "PHP.wasm – loading progress monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,10 +29,12 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "630288218e307d9a5e93d92b428ed30ae6a5fa2f",
32
+ "gitHead": "033b9df217c3b497ebaf0c6ac9a34c7004b55fdb",
33
33
  "engines": {
34
- "node": ">=16.15.1",
34
+ "node": ">=18.18.2",
35
35
  "npm": ">=8.11.0"
36
36
  },
37
- "dependencies": {}
37
+ "dependencies": {
38
+ "@php-wasm/node-polyfills": "0.5.4"
39
+ }
38
40
  }