@php-wasm/progress 0.3.1 → 0.4.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.
Files changed (3) hide show
  1. package/index.cjs +1 -1
  2. package/index.js +148 -123
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=5*1024*1024;class p extends EventTarget{#e={};#t={};constructor(e=[]){super(),this.setModules(e),this.#s()}getEmscriptenOptions(){return{dataFileDownloads:this.#i()}}setModules(e){this.#e=e.reduce((t,s)=>{if(s.dependenciesTotalSize>0){const r="http://example.com/",n=new URL(s.dependencyFilename,r).pathname.split("/").pop();t[n]=Math.max(n in t?t[n]:0,s.dependenciesTotalSize)}return t},{}),this.#t=Object.fromEntries(Object.entries(this.#e).map(([t])=>[t,0]))}#s(){const e=WebAssembly.instantiateStreaming;WebAssembly.instantiateStreaming=async(t,...s)=>{const r=await t,i=r.url.substring(new URL(r.url).origin.length+1),n=u(r,({detail:{loaded:a,total:l}})=>this.#r(i,a,l));return e(n,...s)}}#i(){const e=this,t={};return new Proxy(t,{set(s,r,i){return e.#r(r,i.loaded,i.total),s[r]=new Proxy(JSON.parse(JSON.stringify(i)),{set(n,a,l){return n[a]=l,e.#r(r,n.loaded,n.total),!0}}),!0}})}#r(e,t,s){const r=new URL(e,"http://example.com").pathname.split("/").pop();s||(s=this.#e[r]),r in this.#t||console.warn(`Registered a download #progress of an unregistered file "${r}". This may cause a sudden **decrease** in the #progress percentage as the total number of bytes increases during the download.`),this.#t[r]=t,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:c(this.#t),total:c(this.#e)}}))}}function c(o){return Object.values(o).reduce((e,t)=>e+t,0)}function u(o,e){const t=o.headers.get("content-length")||"",s=parseInt(t,10)||f;function r(i,n){e(new CustomEvent("progress",{detail:{loaded:i,total:n}}))}return new Response(new ReadableStream({async start(i){if(!o.body){i.close();return}const n=o.body.getReader();let a=0;for(;;)try{const{done:l,value:h}=await n.read();if(h&&(a+=h.byteLength),l){r(a,a),i.close();break}else r(a,s),i.enqueue(h)}catch(l){console.error({e:l}),i.error(l);break}}}),{status:o.status,statusText:o.statusText,headers:o.headers})}class _ extends EventTarget{constructor(){super(...arguments),this.#e={},this.#t=0,this.progress=0,this.mode="REAL_TIME",this.caption=""}#e;#t;partialObserver(e,t=""){const s=++this.#t;return this.#e[s]=0,r=>{const{loaded:i,total:n}=r?.detail||{};this.#e[s]=i/n*e,this.#s(this.totalProgress,"REAL_TIME",t)}}slowlyIncrementBy(e){const t=++this.#t;this.#e[t]=e,this.#s(this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(this.#e).reduce((e,t)=>e+t,0)}#s(e,t,s){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:e,mode:t,caption:s}}))}}const d=1e-5;class g extends EventTarget{constructor({weight:e=1,caption:t="",fillTime:s=4}={}){super(),this._selfWeight=1,this._selfDone=!1,this._selfProgress=0,this._selfCaption="",this._isFilling=!1,this._subTrackers=[],this._weight=e,this._selfCaption=t,this._fillTime=s}stage(e,t=""){if(e||(e=this._selfWeight),this._selfWeight-e<-d)throw new Error(`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`);this._selfWeight-=e;const s=new g({caption:t,weight:e,fillTime:this._fillTime});return this._subTrackers.push(s),s.addEventListener("progress",()=>this.notifyProgress()),s.addEventListener("done",()=>{this.done&&this.notifyDone()}),s}fillSlowly({stopBeforeFinishing:e=!0}={}){if(this._isFilling)return;this._isFilling=!0;const t=100,s=this._fillTime/t;this._fillInterval=setInterval(()=>{this.set(this._selfProgress+1),e&&this._selfProgress>=99&&clearInterval(this._fillInterval)},s)}set(e){this._selfProgress=Math.min(e,100),this.notifyProgress(),this._selfProgress+d>=100&&this.finish()}finish(){this._fillInterval&&clearInterval(this._fillInterval),this._selfDone=!0,this._selfProgress=100,this._isFilling=!1,this._fillInterval=void 0,this.notifyProgress(),this.notifyDone()}get caption(){for(let e=this._subTrackers.length-1;e>=0;e--)if(!this._subTrackers[e].done){const t=this._subTrackers[e].caption;if(t)return t}return this._selfCaption}setCaption(e){this._selfCaption=e,this.notifyProgress()}get done(){return this.progress+d>=100}get progress(){if(this._selfDone)return 100;const e=this._subTrackers.reduce((t,s)=>t+s.progress*s.weight,this._selfProgress*this._selfWeight);return Math.round(e*1e4)/1e4}get weight(){return this._weight}get observer(){return this._progressObserver||(this._progressObserver=e=>{this.set(e)}),this._progressObserver}get loadingListener(){return this._loadingListener||(this._loadingListener=e=>{this.set(e.detail.loaded/e.detail.total*100)}),this._loadingListener}pipe(e){e.setProgress({progress:this.progress,caption:this.caption}),this.addEventListener("progress",t=>{e.setProgress({progress:t.detail.progress,caption:t.detail.caption})}),this.addEventListener("done",()=>{e.setLoaded()})}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}notifyProgress(){const e=this;this.dispatchEvent(new CustomEvent("progress",{detail:{get progress(){return e.progress},get caption(){return e.caption}}}))}notifyDone(){this.dispatchEvent(new CustomEvent("done"))}}exports.EmscriptenDownloadMonitor=p;exports.ProgressObserver=_;exports.ProgressTracker=g;exports.cloneResponseMonitorProgress=u;
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;
package/index.js CHANGED
@@ -1,93 +1,115 @@
1
- class f extends EventTarget {
2
- #e = {};
3
- #t = {};
4
- constructor(e = []) {
5
- super(), this.setModules(e), this.#s();
1
+ var L = (i, e, t) => {
2
+ if (!e.has(i))
3
+ throw TypeError("Cannot " + t);
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))
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) => ({
11
+ set _(n) {
12
+ _(i, e, n, t);
13
+ },
14
+ get _() {
15
+ return l(i, e, s);
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 {
20
+ constructor(t = []) {
21
+ super();
22
+ /**
23
+ * Replaces the default WebAssembly.instantiateStreaming with a version
24
+ * that monitors the download #progress.
25
+ */
26
+ d(this, y);
27
+ /**
28
+ * Creates a `dataFileDownloads` Proxy object that can be passed
29
+ * to `startPHP` to monitor the download #progress of the data
30
+ * dependencies.
31
+ */
32
+ d(this, w);
33
+ /**
34
+ * Notifies about the download #progress of a file.
35
+ *
36
+ * @param file The file name.
37
+ * @param loaded The number of bytes of that file loaded so far.
38
+ * @param fileSize The total number of bytes in the loaded file.
39
+ */
40
+ d(this, m);
41
+ d(this, f, {});
42
+ d(this, p, {});
43
+ this.setModules(t), g(this, y, O).call(this);
6
44
  }
7
45
  getEmscriptenOptions() {
8
46
  return {
9
- dataFileDownloads: this.#r()
47
+ dataFileDownloads: g(this, w, R).call(this)
10
48
  };
11
49
  }
12
- setModules(e) {
13
- this.#e = e.reduce((t, s) => {
14
- if (s.dependenciesTotalSize > 0) {
15
- const i = "http://example.com/", n = new URL(s.dependencyFilename, i).pathname.split("/").pop();
16
- t[n] = Math.max(
17
- n in t ? t[n] : 0,
18
- s.dependenciesTotalSize
50
+ setModules(t) {
51
+ _(this, f, t.reduce((s, n) => {
52
+ if (n.dependenciesTotalSize > 0) {
53
+ const r = "http://example.com/", o = new URL(n.dependencyFilename, r).pathname.split("/").pop();
54
+ s[o] = Math.max(
55
+ o in s ? s[o] : 0,
56
+ n.dependenciesTotalSize
19
57
  );
20
58
  }
21
- return t;
22
- }, {}), this.#t = Object.fromEntries(
23
- Object.entries(this.#e).map(([t]) => [t, 0])
24
- );
25
- }
26
- /**
27
- * Replaces the default WebAssembly.instantiateStreaming with a version
28
- * that monitors the download #progress.
29
- */
30
- #s() {
31
- const e = WebAssembly.instantiateStreaming;
32
- WebAssembly.instantiateStreaming = async (t, ...s) => {
33
- const i = await t, r = i.url.substring(
34
- new URL(i.url).origin.length + 1
35
- ), n = c(
36
- i,
37
- ({ detail: { loaded: a, total: l } }) => this.#i(r, a, l)
38
- );
39
- return e(n, ...s);
40
- };
41
- }
42
- /**
43
- * Creates a `dataFileDownloads` Proxy object that can be passed
44
- * to `startPHP` to monitor the download #progress of the data
45
- * dependencies.
46
- */
47
- #r() {
48
- const e = this, t = {};
49
- return new Proxy(t, {
50
- set(s, i, r) {
51
- return e.#i(i, r.loaded, r.total), s[i] = new Proxy(JSON.parse(JSON.stringify(r)), {
52
- set(n, a, l) {
53
- return n[a] = l, e.#i(i, n.loaded, n.total), !0;
54
- }
55
- }), !0;
56
- }
57
- });
58
- }
59
- /**
60
- * Notifies about the download #progress of a file.
61
- *
62
- * @param file The file name.
63
- * @param loaded The number of bytes of that file loaded so far.
64
- * @param fileSize The total number of bytes in the loaded file.
65
- */
66
- #i(e, t, s) {
67
- const i = new URL(e, "http://example.com").pathname.split("/").pop();
68
- s || (s = this.#e[i]), i in this.#t || console.warn(
69
- `Registered a download #progress of an unregistered file "${i}". This may cause a sudden **decrease** in the #progress percentage as the total number of bytes increases during the download.`
70
- ), this.#t[i] = t, this.dispatchEvent(
71
- new CustomEvent("progress", {
72
- detail: {
73
- loaded: g(this.#t),
74
- total: g(this.#e)
75
- }
76
- })
77
- );
59
+ return s;
60
+ }, {})), _(this, p, Object.fromEntries(
61
+ Object.entries(l(this, f)).map(([s]) => [s, 0])
62
+ ));
78
63
  }
79
64
  }
80
- function g(o) {
81
- return Object.values(o).reduce((e, t) => e + t, 0);
65
+ f = new WeakMap(), p = new WeakMap(), y = new WeakSet(), O = function() {
66
+ const t = WebAssembly.instantiateStreaming;
67
+ 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)
73
+ );
74
+ return t(o, ...n);
75
+ };
76
+ }, w = new WeakSet(), R = function() {
77
+ const t = this, s = {};
78
+ return new Proxy(s, {
79
+ set(n, r, a) {
80
+ 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;
85
+ }
86
+ }), !0;
87
+ }
88
+ });
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(
94
+ new CustomEvent("progress", {
95
+ detail: {
96
+ loaded: C(l(this, p)),
97
+ total: C(l(this, f))
98
+ }
99
+ })
100
+ );
101
+ };
102
+ function C(i) {
103
+ return Object.values(i).reduce((e, t) => e + t, 0);
82
104
  }
83
- function c(o, e) {
84
- const t = o.headers.get("content-length") || "", s = parseInt(t, 10) || 5242880;
85
- function i(r, n) {
105
+ function D(i, e) {
106
+ const t = i.headers.get("content-length") || "", s = parseInt(t, 10) || 5242880;
107
+ function n(r, a) {
86
108
  e(
87
109
  new CustomEvent("progress", {
88
110
  detail: {
89
111
  loaded: r,
90
- total: n
112
+ total: a
91
113
  }
92
114
  })
93
115
  );
@@ -95,70 +117,73 @@ function c(o, e) {
95
117
  return new Response(
96
118
  new ReadableStream({
97
119
  async start(r) {
98
- if (!o.body) {
120
+ if (!i.body) {
99
121
  r.close();
100
122
  return;
101
123
  }
102
- const n = o.body.getReader();
103
- let a = 0;
124
+ const a = i.body.getReader();
125
+ let o = 0;
104
126
  for (; ; )
105
127
  try {
106
- const { done: l, value: h } = await n.read();
107
- if (h && (a += h.byteLength), l) {
108
- i(a, a), r.close();
128
+ const { done: h, value: c } = await a.read();
129
+ if (c && (o += c.byteLength), h) {
130
+ n(o, o), r.close();
109
131
  break;
110
132
  } else
111
- i(a, s), r.enqueue(h);
112
- } catch (l) {
113
- console.error({ e: l }), r.error(l);
133
+ n(o, s), r.enqueue(c);
134
+ } catch (h) {
135
+ console.error({ e: h }), r.error(h);
114
136
  break;
115
137
  }
116
138
  }
117
139
  }),
118
140
  {
119
- status: o.status,
120
- statusText: o.statusText,
121
- headers: o.headers
141
+ status: i.status,
142
+ statusText: i.statusText,
143
+ headers: i.headers
122
144
  }
123
145
  );
124
146
  }
125
- class p extends EventTarget {
147
+ var u, v, E, I;
148
+ class W extends EventTarget {
126
149
  constructor() {
127
- super(...arguments), this.#e = {}, this.#t = 0, this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
150
+ 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 = "";
128
155
  }
129
- #e;
130
- #t;
131
- partialObserver(e, t = "") {
132
- const s = ++this.#t;
133
- return this.#e[s] = 0, (i) => {
134
- const { loaded: r, total: n } = i?.detail || {};
135
- this.#e[s] = r / n * e, this.#s(this.totalProgress, "REAL_TIME", t);
156
+ 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);
136
161
  };
137
162
  }
138
- slowlyIncrementBy(e) {
139
- const t = ++this.#t;
140
- this.#e[t] = e, this.#s(this.totalProgress, "SLOWLY_INCREMENT");
163
+ slowlyIncrementBy(t) {
164
+ const s = ++P(this, v)._;
165
+ l(this, u)[s] = t, g(this, E, I).call(this, this.totalProgress, "SLOWLY_INCREMENT");
141
166
  }
142
167
  get totalProgress() {
143
- return Object.values(this.#e).reduce(
144
- (e, t) => e + t,
168
+ return Object.values(l(this, u)).reduce(
169
+ (t, s) => t + s,
145
170
  0
146
171
  );
147
172
  }
148
- #s(e, t, s) {
149
- this.dispatchEvent(
150
- new CustomEvent("progress", {
151
- detail: {
152
- progress: e,
153
- mode: t,
154
- caption: s
155
- }
156
- })
157
- );
158
- }
159
173
  }
160
- const d = 1e-5;
161
- class u extends EventTarget {
174
+ u = new WeakMap(), v = new WeakMap(), E = new WeakSet(), I = function(t, s, n) {
175
+ this.dispatchEvent(
176
+ new CustomEvent("progress", {
177
+ detail: {
178
+ progress: t,
179
+ mode: s,
180
+ caption: n
181
+ }
182
+ })
183
+ );
184
+ };
185
+ const T = 1e-5;
186
+ class x extends EventTarget {
162
187
  constructor({
163
188
  weight: e = 1,
164
189
  caption: t = "",
@@ -202,12 +227,12 @@ class u extends EventTarget {
202
227
  * ```
203
228
  */
204
229
  stage(e, t = "") {
205
- if (e || (e = this._selfWeight), this._selfWeight - e < -d)
230
+ if (e || (e = this._selfWeight), this._selfWeight - e < -T)
206
231
  throw new Error(
207
232
  `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
208
233
  );
209
234
  this._selfWeight -= e;
210
- const s = new u({
235
+ const s = new x({
211
236
  caption: t,
212
237
  weight: e,
213
238
  fillTime: this._fillTime
@@ -244,7 +269,7 @@ class u extends EventTarget {
244
269
  }, s);
245
270
  }
246
271
  set(e) {
247
- this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + d >= 100 && this.finish();
272
+ this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + T >= 100 && this.finish();
248
273
  }
249
274
  finish() {
250
275
  this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
@@ -262,7 +287,7 @@ class u extends EventTarget {
262
287
  this._selfCaption = e, this.notifyProgress();
263
288
  }
264
289
  get done() {
265
- return this.progress + d >= 100;
290
+ return this.progress + T >= 100;
266
291
  }
267
292
  get progress() {
268
293
  if (this._selfDone)
@@ -325,8 +350,8 @@ class u extends EventTarget {
325
350
  }
326
351
  }
327
352
  export {
328
- f as EmscriptenDownloadMonitor,
329
- p as ProgressObserver,
330
- u as ProgressTracker,
331
- c as cloneResponseMonitorProgress
353
+ A as EmscriptenDownloadMonitor,
354
+ W as ProgressObserver,
355
+ x as ProgressTracker,
356
+ D as cloneResponseMonitorProgress
332
357
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/progress",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "PHP.wasm – loading progress monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,7 +29,7 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "73b285f8b496c7442474fd7325b3f6b1287cbf95",
32
+ "gitHead": "0851e71512709843af0539f747caded8ea904fe6",
33
33
  "engines": {
34
34
  "node": ">=16.15.1",
35
35
  "npm": ">=8.11.0"