@php-wasm/progress 0.1.28 → 0.1.30

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 +41 -40
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=5*1024*1024;class f 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[e]=t,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:g(this.#t),total:g(this.#e)}}))}}function g(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)||c;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 p 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}}))}}class d extends EventTarget{constructor({weight:e=1,caption:t="",fillTime:s=4}={}){super(),this._selfWeight=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<-Number.EPSILON)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 d({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+Number.EPSILON>=100&&this.finish()}finish(){this._fillInterval&&clearInterval(this._fillInterval),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+Number.EPSILON>=100}get progress(){return this._subTrackers.reduce((e,t)=>e+t.progress*t.weight,this._selfProgress*this._selfWeight)}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){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=p;exports.ProgressTracker=d;exports.cloneResponseMonitorProgress=u;
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[e]=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:d}=await n.read();if(d&&(a+=d.byteLength),l){r(a,a),i.close();break}else r(a,s),i.enqueue(d)}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 h=1e-5;class g extends EventTarget{constructor({weight:e=1,caption:t="",fillTime:s=4}={}){super(),this._selfWeight=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<-h)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+h>=100&&this.finish()}finish(){this._fillInterval&&clearInterval(this._fillInterval),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+h>=100}get progress(){return this._subTrackers.reduce((e,t)=>e+t.progress*t.weight,this._selfProgress*this._selfWeight)+h}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){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;
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- class c extends EventTarget {
1
+ class f extends EventTarget {
2
2
  #e = {};
3
3
  #t = {};
4
4
  constructor(e = []) {
@@ -6,13 +6,13 @@ class c extends EventTarget {
6
6
  }
7
7
  getEmscriptenOptions() {
8
8
  return {
9
- dataFileDownloads: this.#i()
9
+ dataFileDownloads: this.#r()
10
10
  };
11
11
  }
12
12
  setModules(e) {
13
13
  this.#e = e.reduce((t, s) => {
14
14
  if (s.dependenciesTotalSize > 0) {
15
- const r = "http://example.com/", n = new URL(s.dependencyFilename, r).pathname.split("/").pop();
15
+ const i = "http://example.com/", n = new URL(s.dependencyFilename, i).pathname.split("/").pop();
16
16
  t[n] = Math.max(
17
17
  n in t ? t[n] : 0,
18
18
  s.dependenciesTotalSize
@@ -30,11 +30,11 @@ class c extends EventTarget {
30
30
  #s() {
31
31
  const e = WebAssembly.instantiateStreaming;
32
32
  WebAssembly.instantiateStreaming = async (t, ...s) => {
33
- const r = await t, i = r.url.substring(
34
- new URL(r.url).origin.length + 1
33
+ const i = await t, r = i.url.substring(
34
+ new URL(i.url).origin.length + 1
35
35
  ), n = u(
36
- r,
37
- ({ detail: { loaded: a, total: l } }) => this.#r(i, a, l)
36
+ i,
37
+ ({ detail: { loaded: a, total: l } }) => this.#i(r, a, l)
38
38
  );
39
39
  return e(n, ...s);
40
40
  };
@@ -44,13 +44,13 @@ class c extends EventTarget {
44
44
  * to `startPHP` to monitor the download #progress of the data
45
45
  * dependencies.
46
46
  */
47
- #i() {
47
+ #r() {
48
48
  const e = this, t = {};
49
49
  return new Proxy(t, {
50
- set(s, r, i) {
51
- return e.#r(r, i.loaded, i.total), s[r] = new Proxy(JSON.parse(JSON.stringify(i)), {
50
+ set(s, i, r) {
51
+ return e.#i(i, r.loaded, r.total), s[i] = new Proxy(JSON.parse(JSON.stringify(r)), {
52
52
  set(n, a, l) {
53
- return n[a] = l, e.#r(r, n.loaded, n.total), !0;
53
+ return n[a] = l, e.#i(i, n.loaded, n.total), !0;
54
54
  }
55
55
  }), !0;
56
56
  }
@@ -63,30 +63,30 @@ class c extends EventTarget {
63
63
  * @param loaded The number of bytes of that file loaded so far.
64
64
  * @param fileSize The total number of bytes in the loaded file.
65
65
  */
66
- #r(e, t, s) {
67
- const r = new URL(e, "http://example.com").pathname.split("/").pop();
68
- s || (s = this.#e[r]), r in this.#t || console.warn(
69
- `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.`
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
70
  ), this.#t[e] = t, this.dispatchEvent(
71
71
  new CustomEvent("progress", {
72
72
  detail: {
73
- loaded: d(this.#t),
74
- total: d(this.#e)
73
+ loaded: g(this.#t),
74
+ total: g(this.#e)
75
75
  }
76
76
  })
77
77
  );
78
78
  }
79
79
  }
80
- function d(o) {
80
+ function g(o) {
81
81
  return Object.values(o).reduce((e, t) => e + t, 0);
82
82
  }
83
83
  function u(o, e) {
84
84
  const t = o.headers.get("content-length") || "", s = parseInt(t, 10) || 5242880;
85
- function r(i, n) {
85
+ function i(r, n) {
86
86
  e(
87
87
  new CustomEvent("progress", {
88
88
  detail: {
89
- loaded: i,
89
+ loaded: r,
90
90
  total: n
91
91
  }
92
92
  })
@@ -94,23 +94,23 @@ function u(o, e) {
94
94
  }
95
95
  return new Response(
96
96
  new ReadableStream({
97
- async start(i) {
97
+ async start(r) {
98
98
  if (!o.body) {
99
- i.close();
99
+ r.close();
100
100
  return;
101
101
  }
102
102
  const n = o.body.getReader();
103
103
  let a = 0;
104
104
  for (; ; )
105
105
  try {
106
- const { done: l, value: h } = await n.read();
107
- if (h && (a += h.byteLength), l) {
108
- r(a, a), i.close();
106
+ const { done: l, value: d } = await n.read();
107
+ if (d && (a += d.byteLength), l) {
108
+ i(a, a), r.close();
109
109
  break;
110
110
  } else
111
- r(a, s), i.enqueue(h);
111
+ i(a, s), r.enqueue(d);
112
112
  } catch (l) {
113
- console.error({ e: l }), i.error(l);
113
+ console.error({ e: l }), r.error(l);
114
114
  break;
115
115
  }
116
116
  }
@@ -122,7 +122,7 @@ function u(o, e) {
122
122
  }
123
123
  );
124
124
  }
125
- class f extends EventTarget {
125
+ class p extends EventTarget {
126
126
  constructor() {
127
127
  super(...arguments), this.#e = {}, this.#t = 0, this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
128
128
  }
@@ -130,9 +130,9 @@ class f extends EventTarget {
130
130
  #t;
131
131
  partialObserver(e, t = "") {
132
132
  const s = ++this.#t;
133
- return this.#e[s] = 0, (r) => {
134
- const { loaded: i, total: n } = r?.detail || {};
135
- this.#e[s] = i / n * e, this.#s(this.totalProgress, "REAL_TIME", 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);
136
136
  };
137
137
  }
138
138
  slowlyIncrementBy(e) {
@@ -157,7 +157,8 @@ class f extends EventTarget {
157
157
  );
158
158
  }
159
159
  }
160
- class g extends EventTarget {
160
+ const h = 1e-5;
161
+ class c extends EventTarget {
161
162
  constructor({
162
163
  weight: e = 1,
163
164
  caption: t = "",
@@ -201,12 +202,12 @@ class g extends EventTarget {
201
202
  * ```
202
203
  */
203
204
  stage(e, t = "") {
204
- if (e || (e = this._selfWeight), this._selfWeight - e < -Number.EPSILON)
205
+ if (e || (e = this._selfWeight), this._selfWeight - e < -h)
205
206
  throw new Error(
206
207
  `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
207
208
  );
208
209
  this._selfWeight -= e;
209
- const s = new g({
210
+ const s = new c({
210
211
  caption: t,
211
212
  weight: e,
212
213
  fillTime: this._fillTime
@@ -243,7 +244,7 @@ class g extends EventTarget {
243
244
  }, s);
244
245
  }
245
246
  set(e) {
246
- this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + Number.EPSILON >= 100 && this.finish();
247
+ this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + h >= 100 && this.finish();
247
248
  }
248
249
  finish() {
249
250
  this._fillInterval && clearInterval(this._fillInterval), this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
@@ -261,13 +262,13 @@ class g extends EventTarget {
261
262
  this._selfCaption = e, this.notifyProgress();
262
263
  }
263
264
  get done() {
264
- return this.progress + Number.EPSILON >= 100;
265
+ return this.progress + h >= 100;
265
266
  }
266
267
  get progress() {
267
268
  return this._subTrackers.reduce(
268
269
  (e, t) => e + t.progress * t.weight,
269
270
  this._selfProgress * this._selfWeight
270
- );
271
+ ) + h;
271
272
  }
272
273
  get weight() {
273
274
  return this._weight;
@@ -318,8 +319,8 @@ class g extends EventTarget {
318
319
  }
319
320
  }
320
321
  export {
321
- c as EmscriptenDownloadMonitor,
322
- f as ProgressObserver,
323
- g as ProgressTracker,
322
+ f as EmscriptenDownloadMonitor,
323
+ p as ProgressObserver,
324
+ c as ProgressTracker,
324
325
  u as cloneResponseMonitorProgress
325
326
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/progress",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "PHP.wasm – loading progress monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,6 +29,6 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "883860eacc7c37377f772a26919e700749020e4c",
32
+ "gitHead": "df3e9bff1de33d53d026c35a6ba5534aeff21a78",
33
33
  "dependencies": {}
34
34
  }