@php-wasm/progress 0.9.13 → 0.9.15

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 -4
  2. package/index.js +134 -379
  3. package/package.json +4 -4
package/index.cjs CHANGED
@@ -1,4 +1 @@
1
- "use strict";var E=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var a=(s,e,t)=>(E(s,e,"read from private field"),t?t.call(s):e.get(s)),u=(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)},y=(s,e,t,r)=>(E(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t);var w=(s,e,t,r)=>({set _(n){y(s,e,n,t)},get _(){return a(s,e,r)}}),v=(s,e,t)=>(E(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=function(){var s;return typeof process<"u"&&((s=process.release)==null?void 0:s.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(x==="NODE"){let s=function(t){return new Promise(function(r,n){t.onload=t.onerror=function(i){t.onload=t.onerror=null,i.type==="load"?r(t.result):n(new Error("Failed to read the blob/file"))}})},e=function(){const t=new Uint8Array([1,2,3,4]),n=new File([t],"test").stream();try{return n.getReader({mode:"byob"}),!0}catch{return!1}};if(typeof File>"u"){class t extends Blob{constructor(n,i,l){super(n);let o;l!=null&&l.lastModified&&(o=new Date),(!o||isNaN(o.getFullYear()))&&(o=new Date),this.lastModifiedDate=o,this.lastModified=o.getMilliseconds(),this.name=i||""}}global.File=t}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const r=new FileReader;return r.readAsArrayBuffer(this),s(r)}),typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const r=new FileReader;return r.readAsText(this),s(r)}),(typeof Blob.prototype.stream>"u"||!e())&&(Blob.prototype.stream=function(){let t=0;const r=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(n){const i=n.byobRequest.view,o=await r.slice(t,t+i.byteLength).arrayBuffer(),d=new Uint8Array(o);new Uint8Array(i.buffer).set(d);const g=d.byteLength;n.byobRequest.respond(g),t+=g,t>=r.size&&n.close()}})})}if(x==="NODE"&&typeof CustomEvent>"u"){class s extends Event{constructor(t,r={}){super(t,r),this.detail=r.detail}initCustomEvent(){}}globalThis.CustomEvent=s}const S="playground-log",M=(s,...e)=>{D.dispatchEvent(new CustomEvent(S,{detail:{log:s,args:e}}))},F=(s,...e)=>{switch(typeof s.message=="string"?s.message=L(s.message):s.message.message&&typeof s.message.message=="string"&&(s.message.message=L(s.message.message)),s.severity){case"Debug":console.debug(s.message,...e);break;case"Info":console.info(s.message,...e);break;case"Warn":console.warn(s.message,...e);break;case"Error":console.error(s.message,...e);break;case"Fatal":console.error(s.message,...e);break;default:console.log(s.message,...e)}},N=s=>s instanceof Error?[s.message,s.stack].join(`
2
- `):JSON.stringify(s,null,2),C=[],R=s=>{C.push(s)},T=s=>{if(s.raw===!0)R(s.message);else{const e=J(typeof s.message=="object"?N(s.message):s.message,s.severity??"Info",s.prefix??"JavaScript");R(e)}};class A extends EventTarget{constructor(e=[]){super(),this.handlers=e,this.fatalErrorEvent="playground-fatal-error"}getLogs(){return this.handlers.includes(T)?[...C]:(this.error(`Logs aren't stored because the logToMemory handler isn't registered.
3
- If you're using a custom logger instance, make sure to register logToMemory handler.
4
- `),[])}logMessage(e,...t){for(const r of this.handlers)r(e,...t)}log(e,...t){this.logMessage({message:e,severity:void 0,prefix:"JavaScript",raw:!1},...t)}debug(e,...t){this.logMessage({message:e,severity:"Debug",prefix:"JavaScript",raw:!1},...t)}info(e,...t){this.logMessage({message:e,severity:"Info",prefix:"JavaScript",raw:!1},...t)}warn(e,...t){this.logMessage({message:e,severity:"Warn",prefix:"JavaScript",raw:!1},...t)}error(e,...t){this.logMessage({message:e,severity:"Error",prefix:"JavaScript",raw:!1},...t)}}const W=()=>{try{if(process.env.NODE_ENV==="test")return[T,M]}catch{}return[T,F,M]},D=new A(W()),L=s=>s.replace(/\t/g,""),J=(s,e,t)=>{const r=new Date,n=new Intl.DateTimeFormat("en-GB",{year:"numeric",month:"short",day:"2-digit",timeZone:"UTC"}).format(r).replace(/ /g,"-"),i=new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZone:"UTC",timeZoneName:"short"}).format(r),l=n+" "+i;return s=L(s),`[${l}] ${t} ${e}: ${s}`},U=5*1024*1024;var f,c,b,O;class $ extends EventTarget{constructor(){super(...arguments);u(this,b);u(this,f,{});u(this,c,{})}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,f)||(a(this,f)[o]=n),o in a(this,c)||(a(this,c)[o]=0)}}async monitorFetch(t){const r=await t;return B(r,i=>{v(this,b,O).call(this,r.url,i.detail.loaded,i.detail.total)})}}f=new WeakMap,c=new WeakMap,b=new WeakSet,O=function(t,r,n){const i=new URL(t,"http://example.com").pathname.split("/").pop();n?i in a(this,f)||(a(this,f)[i]=n,a(this,c)[i]=r):n=a(this,f)[i],i in a(this,c)||D.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,c)[i]=r,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:k(a(this,c)),total:k(a(this,f))}}))};function k(s){return Object.values(s).reduce((e,t)=>e+t,0)}function B(s,e){const t=s.headers.get("content-length")||"",r=parseInt(t,10)||U;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:d,value:g}=await l.read();if(g&&(o+=g.byteLength),d){n(o,o),i.close();break}else n(o,r),i.enqueue(g)}catch(d){D.error({e:d}),i.error(d);break}}}),{status:s.status,statusText:s.statusText,headers:s.headers})}var h,p,m,P;class G extends EventTarget{constructor(){super(...arguments);u(this,m);u(this,h,void 0);u(this,p,void 0);y(this,h,{}),y(this,p,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(t,r=""){const n=++w(this,p)._;return a(this,h)[n]=0,i=>{const{loaded:l,total:o}=(i==null?void 0:i.detail)||{};a(this,h)[n]=l/o*t,v(this,m,P).call(this,this.totalProgress,"REAL_TIME",r)}}slowlyIncrementBy(t){const r=++w(this,p)._;a(this,h)[r]=t,v(this,m,P).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(a(this,h)).reduce((t,r)=>t+r,0)}}h=new WeakMap,p=new WeakMap,m=new WeakSet,P=function(t,r,n){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:t,mode:r,caption:n}}))};const _=1e-5;class I 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<-_)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 I({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+_>=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+_>=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=$;exports.ProgressObserver=G;exports.ProgressTracker=I;exports.cloneResponseMonitorProgress=B;
1
+ "use strict";var b=(i,e,s)=>{if(!e.has(i))throw TypeError("Cannot "+s)};var n=(i,e,s)=>(b(i,e,"read from private field"),s?s.call(i):e.get(i)),d=(i,e,s)=>{if(e.has(i))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(i):e.set(i,s)},_=(i,e,s,t)=>(b(i,e,"write to private field"),t?t.call(i,s):e.set(i,s),s);var P=(i,e,s,t)=>({set _(o){_(i,e,o,s)},get _(){return n(i,e,t)}}),v=(i,e,s)=>(b(i,e,"access private method"),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@php-wasm/node-polyfills");const I=require("@php-wasm/logger"),R=5*1024*1024;var h,l,m,O;class M extends EventTarget{constructor(){super(...arguments);d(this,m);d(this,h,{});d(this,l,{})}expectAssets(s){for(const[t,o]of Object.entries(s)){const r="http://example.com/",a=new URL(t,r).pathname.split("/").pop();a in n(this,h)||(n(this,h)[a]=o),a in n(this,l)||(n(this,l)[a]=0)}}async monitorFetch(s){const t=await s;return C(t,r=>{v(this,m,O).call(this,t.url,r.detail.loaded,r.detail.total)})}}h=new WeakMap,l=new WeakMap,m=new WeakSet,O=function(s,t,o){const r=new URL(s,"http://example.com").pathname.split("/").pop();o?r in n(this,h)||(n(this,h)[r]=o,n(this,l)[r]=t):o=n(this,h)[r],r in n(this,l)||I.logger.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.`),n(this,l)[r]=t,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:T(n(this,l)),total:T(n(this,h))}}))};function T(i){return Object.values(i).reduce((e,s)=>e+s,0)}function C(i,e){const s=i.headers.get("content-length")||"",t=parseInt(s,10)||R;function o(r,c){e(new CustomEvent("progress",{detail:{loaded:r,total:c}}))}return new Response(new ReadableStream({async start(r){if(!i.body){r.close();return}const c=i.body.getReader();let a=0;for(;;)try{const{done:p,value:E}=await c.read();if(E&&(a+=E.byteLength),p){o(a,a),r.close();break}else o(a,t),r.enqueue(E)}catch(p){I.logger.error({e:p}),r.error(p);break}}}),{status:i.status,statusText:i.statusText,headers:i.headers})}var g,f,u,y;class k extends EventTarget{constructor(){super(...arguments);d(this,u);d(this,g,void 0);d(this,f,void 0);_(this,g,{}),_(this,f,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(s,t=""){const o=++P(this,f)._;return n(this,g)[o]=0,r=>{const{loaded:c,total:a}=(r==null?void 0:r.detail)||{};n(this,g)[o]=c/a*s,v(this,u,y).call(this,this.totalProgress,"REAL_TIME",t)}}slowlyIncrementBy(s){const t=++P(this,f)._;n(this,g)[t]=s,v(this,u,y).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(n(this,g)).reduce((s,t)=>s+t,0)}}g=new WeakMap,f=new WeakMap,u=new WeakSet,y=function(s,t,o){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:s,mode:t,caption:o}}))};const L=1e-5;class w extends EventTarget{constructor({weight:e=1,caption:s="",fillTime:t=4}={}){super(),this._selfWeight=1,this._selfDone=!1,this._selfProgress=0,this._selfCaption="",this._isFilling=!1,this._subTrackers=[],this._weight=e,this._selfCaption=s,this._fillTime=t}stage(e,s=""){if(e||(e=this._selfWeight),this._selfWeight-e<-L)throw new Error(`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`);this._selfWeight-=e;const t=new w({caption:s,weight:e,fillTime:this._fillTime});return this._subTrackers.push(t),t.addEventListener("progress",()=>this.notifyProgress()),t.addEventListener("done",()=>{this.done&&this.notifyDone()}),t}fillSlowly({stopBeforeFinishing:e=!0}={}){if(this._isFilling)return;this._isFilling=!0;const s=100,t=this._fillTime/s;this._fillInterval=setInterval(()=>{this.set(this._selfProgress+1),e&&this._selfProgress>=99&&clearInterval(this._fillInterval)},t)}set(e){this._selfProgress=Math.min(e,100),this.notifyProgress(),this._selfProgress+L>=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 s=this._subTrackers[e].caption;if(s)return s}return this._selfCaption}setCaption(e){this._selfCaption=e,this.notifyProgress()}get done(){return this.progress+L>=100}get progress(){if(this._selfDone)return 100;const e=this._subTrackers.reduce((s,t)=>s+t.progress*t.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",s=>{e.setProgress({progress:s.detail.progress,caption:s.detail.caption})}),this.addEventListener("done",()=>{e.setLoaded()})}addEventListener(e,s){super.addEventListener(e,s)}removeEventListener(e,s){super.removeEventListener(e,s)}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=M;exports.ProgressObserver=k;exports.ProgressTracker=w;exports.cloneResponseMonitorProgress=C;
package/index.js CHANGED
@@ -1,270 +1,25 @@
1
- var E = (s, e, t) => {
2
- if (!e.has(s))
3
- throw TypeError("Cannot " + t);
1
+ var b = (i, t, e) => {
2
+ if (!t.has(i))
3
+ throw TypeError("Cannot " + e);
4
4
  };
5
- var a = (s, e, t) => (E(s, e, "read from private field"), t ? t.call(s) : e.get(s)), u = (s, e, t) => {
6
- if (e.has(s))
5
+ var n = (i, t, e) => (b(i, t, "read from private field"), e ? e.call(i) : t.get(i)), g = (i, t, e) => {
6
+ if (t.has(i))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
- e instanceof WeakSet ? e.add(s) : e.set(s, t);
9
- }, y = (s, e, t, r) => (E(s, e, "write to private field"), r ? r.call(s, t) : e.set(s, t), t);
10
- var w = (s, e, t, r) => ({
11
- set _(n) {
12
- y(s, e, n, t);
8
+ t instanceof WeakSet ? t.add(i) : t.set(i, e);
9
+ }, _ = (i, t, e, s) => (b(i, t, "write to private field"), s ? s.call(i, e) : t.set(i, e), e);
10
+ var L = (i, t, e, s) => ({
11
+ set _(o) {
12
+ _(i, t, o, e);
13
13
  },
14
14
  get _() {
15
- return a(s, e, r);
16
- }
17
- }), v = (s, e, t) => (E(s, e, "access private method"), t);
18
- const R = function() {
19
- var s;
20
- return typeof process < "u" && ((s = process.release) == null ? void 0 : s.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
21
- // @ts-ignore
22
- typeof WorkerGlobalScope < "u" && // @ts-ignore
23
- self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
24
- );
25
- }();
26
- if (R === "NODE") {
27
- let s = function(t) {
28
- return new Promise(function(r, n) {
29
- t.onload = t.onerror = function(i) {
30
- t.onload = t.onerror = null, i.type === "load" ? r(t.result) : n(new Error("Failed to read the blob/file"));
31
- };
32
- });
33
- }, e = function() {
34
- const t = new Uint8Array([1, 2, 3, 4]), n = new File([t], "test").stream();
35
- try {
36
- return n.getReader({ mode: "byob" }), !0;
37
- } catch {
38
- return !1;
39
- }
40
- };
41
- if (typeof File > "u") {
42
- class t extends Blob {
43
- constructor(n, i, l) {
44
- super(n);
45
- let o;
46
- l != null && l.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = i || "";
47
- }
48
- }
49
- global.File = t;
50
- }
51
- typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
52
- const r = new FileReader();
53
- return r.readAsArrayBuffer(this), s(r);
54
- }), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
55
- const r = new FileReader();
56
- return r.readAsText(this), s(r);
57
- }), (typeof Blob.prototype.stream > "u" || !e()) && (Blob.prototype.stream = function() {
58
- let t = 0;
59
- const r = this;
60
- return new ReadableStream({
61
- type: "bytes",
62
- // 0.5 MB seems like a reasonable chunk size, let's adjust
63
- // this if needed.
64
- autoAllocateChunkSize: 512 * 1024,
65
- async pull(n) {
66
- const i = n.byobRequest.view, o = await r.slice(
67
- t,
68
- t + i.byteLength
69
- ).arrayBuffer(), d = new Uint8Array(o);
70
- new Uint8Array(i.buffer).set(d);
71
- const g = d.byteLength;
72
- n.byobRequest.respond(g), t += g, t >= r.size && n.close();
73
- }
74
- });
75
- });
76
- }
77
- if (R === "NODE" && typeof CustomEvent > "u") {
78
- class s extends Event {
79
- constructor(t, r = {}) {
80
- super(t, r), this.detail = r.detail;
81
- }
82
- initCustomEvent() {
83
- }
84
- }
85
- globalThis.CustomEvent = s;
86
- }
87
- const O = "playground-log", I = (s, ...e) => {
88
- x.dispatchEvent(
89
- new CustomEvent(O, {
90
- detail: {
91
- log: s,
92
- args: e
93
- }
94
- })
95
- );
96
- }, F = (s, ...e) => {
97
- switch (typeof s.message == "string" ? s.message = T(s.message) : s.message.message && typeof s.message.message == "string" && (s.message.message = T(s.message.message)), s.severity) {
98
- case "Debug":
99
- console.debug(s.message, ...e);
100
- break;
101
- case "Info":
102
- console.info(s.message, ...e);
103
- break;
104
- case "Warn":
105
- console.warn(s.message, ...e);
106
- break;
107
- case "Error":
108
- console.error(s.message, ...e);
109
- break;
110
- case "Fatal":
111
- console.error(s.message, ...e);
112
- break;
113
- default:
114
- console.log(s.message, ...e);
115
- }
116
- }, S = (s) => s instanceof Error ? [s.message, s.stack].join(`
117
- `) : JSON.stringify(s, null, 2), k = [], C = (s) => {
118
- k.push(s);
119
- }, L = (s) => {
120
- if (s.raw === !0)
121
- C(s.message);
122
- else {
123
- const e = W(
124
- typeof s.message == "object" ? S(s.message) : s.message,
125
- s.severity ?? "Info",
126
- s.prefix ?? "JavaScript"
127
- );
128
- C(e);
129
- }
130
- };
131
- class N extends EventTarget {
132
- // constructor
133
- constructor(e = []) {
134
- super(), this.handlers = e, this.fatalErrorEvent = "playground-fatal-error";
135
- }
136
- /**
137
- * Get all logs.
138
- * @returns string[]
139
- */
140
- getLogs() {
141
- return this.handlers.includes(L) ? [...k] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
142
- If you're using a custom logger instance, make sure to register logToMemory handler.
143
- `), []);
144
- }
145
- /**
146
- * Log message with severity.
147
- *
148
- * @param message any
149
- * @param severity LogSeverity
150
- * @param raw boolean
151
- * @param args any
152
- */
153
- logMessage(e, ...t) {
154
- for (const r of this.handlers)
155
- r(e, ...t);
156
- }
157
- /**
158
- * Log message
159
- *
160
- * @param message any
161
- * @param args any
162
- */
163
- log(e, ...t) {
164
- this.logMessage(
165
- {
166
- message: e,
167
- severity: void 0,
168
- prefix: "JavaScript",
169
- raw: !1
170
- },
171
- ...t
172
- );
173
- }
174
- /**
175
- * Log debug message
176
- *
177
- * @param message any
178
- * @param args any
179
- */
180
- debug(e, ...t) {
181
- this.logMessage(
182
- {
183
- message: e,
184
- severity: "Debug",
185
- prefix: "JavaScript",
186
- raw: !1
187
- },
188
- ...t
189
- );
190
- }
191
- /**
192
- * Log info message
193
- *
194
- * @param message any
195
- * @param args any
196
- */
197
- info(e, ...t) {
198
- this.logMessage(
199
- {
200
- message: e,
201
- severity: "Info",
202
- prefix: "JavaScript",
203
- raw: !1
204
- },
205
- ...t
206
- );
207
- }
208
- /**
209
- * Log warning message
210
- *
211
- * @param message any
212
- * @param args any
213
- */
214
- warn(e, ...t) {
215
- this.logMessage(
216
- {
217
- message: e,
218
- severity: "Warn",
219
- prefix: "JavaScript",
220
- raw: !1
221
- },
222
- ...t
223
- );
224
- }
225
- /**
226
- * Log error message
227
- *
228
- * @param message any
229
- * @param args any
230
- */
231
- error(e, ...t) {
232
- this.logMessage(
233
- {
234
- message: e,
235
- severity: "Error",
236
- prefix: "JavaScript",
237
- raw: !1
238
- },
239
- ...t
240
- );
241
- }
242
- }
243
- const A = () => {
244
- try {
245
- if (process.env.NODE_ENV === "test")
246
- return [L, I];
247
- } catch {
248
- }
249
- return [L, F, I];
250
- }, x = new N(A()), T = (s) => s.replace(/\t/g, ""), W = (s, e, t) => {
251
- const r = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
252
- year: "numeric",
253
- month: "short",
254
- day: "2-digit",
255
- timeZone: "UTC"
256
- }).format(r).replace(/ /g, "-"), i = new Intl.DateTimeFormat("en-GB", {
257
- hour: "2-digit",
258
- minute: "2-digit",
259
- second: "2-digit",
260
- hour12: !1,
261
- timeZone: "UTC",
262
- timeZoneName: "short"
263
- }).format(r), l = n + " " + i;
264
- return s = T(s), `[${l}] ${t} ${e}: ${s}`;
265
- }, J = 5 * 1024 * 1024;
266
- var f, h, b, B;
267
- class G extends EventTarget {
15
+ return n(i, t, s);
16
+ }
17
+ }), v = (i, t, e) => (b(i, t, "access private method"), e);
18
+ import "@php-wasm/node-polyfills";
19
+ import { logger as T } from "@php-wasm/logger";
20
+ const O = 5 * 1024 * 1024;
21
+ var h, l, m, I;
22
+ class D extends EventTarget {
268
23
  constructor() {
269
24
  super(...arguments);
270
25
  /**
@@ -274,127 +29,127 @@ class G extends EventTarget {
274
29
  * @param loaded The number of bytes of that file loaded so far.
275
30
  * @param fileSize The total number of bytes in the loaded file.
276
31
  */
277
- u(this, b);
278
- u(this, f, {});
279
- u(this, h, {});
280
- }
281
- expectAssets(t) {
282
- for (const [r, n] of Object.entries(t)) {
283
- const i = "http://example.com/", o = new URL(r, i).pathname.split("/").pop();
284
- o in a(this, f) || (a(this, f)[o] = n), o in a(this, h) || (a(this, h)[o] = 0);
32
+ g(this, m);
33
+ g(this, h, {});
34
+ g(this, l, {});
35
+ }
36
+ expectAssets(e) {
37
+ for (const [s, o] of Object.entries(e)) {
38
+ const r = "http://example.com/", a = new URL(s, r).pathname.split("/").pop();
39
+ a in n(this, h) || (n(this, h)[a] = o), a in n(this, l) || (n(this, l)[a] = 0);
285
40
  }
286
41
  }
287
- async monitorFetch(t) {
288
- const r = await t;
289
- return U(r, (i) => {
290
- v(this, b, B).call(this, r.url, i.detail.loaded, i.detail.total);
42
+ async monitorFetch(e) {
43
+ const s = await e;
44
+ return R(s, (r) => {
45
+ v(this, m, I).call(this, s.url, r.detail.loaded, r.detail.total);
291
46
  });
292
47
  }
293
48
  }
294
- f = new WeakMap(), h = new WeakMap(), b = new WeakSet(), B = function(t, r, n) {
295
- const i = new URL(t, "http://example.com").pathname.split("/").pop();
296
- n ? i in a(this, f) || (a(this, f)[i] = n, a(this, h)[i] = r) : n = a(this, f)[i], i in a(this, h) || x.warn(
297
- `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.`
298
- ), a(this, h)[i] = r, this.dispatchEvent(
49
+ h = new WeakMap(), l = new WeakMap(), m = new WeakSet(), I = function(e, s, o) {
50
+ const r = new URL(e, "http://example.com").pathname.split("/").pop();
51
+ o ? r in n(this, h) || (n(this, h)[r] = o, n(this, l)[r] = s) : o = n(this, h)[r], r in n(this, l) || T.warn(
52
+ `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.`
53
+ ), n(this, l)[r] = s, this.dispatchEvent(
299
54
  new CustomEvent("progress", {
300
55
  detail: {
301
- loaded: D(a(this, h)),
302
- total: D(a(this, f))
56
+ loaded: y(n(this, l)),
57
+ total: y(n(this, h))
303
58
  }
304
59
  })
305
60
  );
306
61
  };
307
- function D(s) {
308
- return Object.values(s).reduce((e, t) => e + t, 0);
62
+ function y(i) {
63
+ return Object.values(i).reduce((t, e) => t + e, 0);
309
64
  }
310
- function U(s, e) {
311
- const t = s.headers.get("content-length") || "", r = parseInt(t, 10) || J;
312
- function n(i, l) {
313
- e(
65
+ function R(i, t) {
66
+ const e = i.headers.get("content-length") || "", s = parseInt(e, 10) || O;
67
+ function o(r, f) {
68
+ t(
314
69
  new CustomEvent("progress", {
315
70
  detail: {
316
- loaded: i,
317
- total: l
71
+ loaded: r,
72
+ total: f
318
73
  }
319
74
  })
320
75
  );
321
76
  }
322
77
  return new Response(
323
78
  new ReadableStream({
324
- async start(i) {
325
- if (!s.body) {
326
- i.close();
79
+ async start(r) {
80
+ if (!i.body) {
81
+ r.close();
327
82
  return;
328
83
  }
329
- const l = s.body.getReader();
330
- let o = 0;
84
+ const f = i.body.getReader();
85
+ let a = 0;
331
86
  for (; ; )
332
87
  try {
333
- const { done: d, value: g } = await l.read();
334
- if (g && (o += g.byteLength), d) {
335
- n(o, o), i.close();
88
+ const { done: p, value: E } = await f.read();
89
+ if (E && (a += E.byteLength), p) {
90
+ o(a, a), r.close();
336
91
  break;
337
92
  } else
338
- n(o, r), i.enqueue(g);
339
- } catch (d) {
340
- x.error({ e: d }), i.error(d);
93
+ o(a, s), r.enqueue(E);
94
+ } catch (p) {
95
+ T.error({ e: p }), r.error(p);
341
96
  break;
342
97
  }
343
98
  }
344
99
  }),
345
100
  {
346
- status: s.status,
347
- statusText: s.statusText,
348
- headers: s.headers
101
+ status: i.status,
102
+ statusText: i.statusText,
103
+ headers: i.headers
349
104
  }
350
105
  );
351
106
  }
352
- var c, p, m, P;
353
- class Z extends EventTarget {
107
+ var d, c, u, w;
108
+ class F extends EventTarget {
354
109
  constructor() {
355
110
  super(...arguments);
356
- u(this, m);
357
- u(this, c, void 0);
358
- u(this, p, void 0);
359
- y(this, c, {}), y(this, p, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
360
- }
361
- partialObserver(t, r = "") {
362
- const n = ++w(this, p)._;
363
- return a(this, c)[n] = 0, (i) => {
364
- const { loaded: l, total: o } = (i == null ? void 0 : i.detail) || {};
365
- a(this, c)[n] = l / o * t, v(this, m, P).call(this, this.totalProgress, "REAL_TIME", r);
111
+ g(this, u);
112
+ g(this, d, void 0);
113
+ g(this, c, void 0);
114
+ _(this, d, {}), _(this, c, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
115
+ }
116
+ partialObserver(e, s = "") {
117
+ const o = ++L(this, c)._;
118
+ return n(this, d)[o] = 0, (r) => {
119
+ const { loaded: f, total: a } = (r == null ? void 0 : r.detail) || {};
120
+ n(this, d)[o] = f / a * e, v(this, u, w).call(this, this.totalProgress, "REAL_TIME", s);
366
121
  };
367
122
  }
368
- slowlyIncrementBy(t) {
369
- const r = ++w(this, p)._;
370
- a(this, c)[r] = t, v(this, m, P).call(this, this.totalProgress, "SLOWLY_INCREMENT");
123
+ slowlyIncrementBy(e) {
124
+ const s = ++L(this, c)._;
125
+ n(this, d)[s] = e, v(this, u, w).call(this, this.totalProgress, "SLOWLY_INCREMENT");
371
126
  }
372
127
  get totalProgress() {
373
- return Object.values(a(this, c)).reduce(
374
- (t, r) => t + r,
128
+ return Object.values(n(this, d)).reduce(
129
+ (e, s) => e + s,
375
130
  0
376
131
  );
377
132
  }
378
133
  }
379
- c = new WeakMap(), p = new WeakMap(), m = new WeakSet(), P = function(t, r, n) {
134
+ d = new WeakMap(), c = new WeakMap(), u = new WeakSet(), w = function(e, s, o) {
380
135
  this.dispatchEvent(
381
136
  new CustomEvent("progress", {
382
137
  detail: {
383
- progress: t,
384
- mode: r,
385
- caption: n
138
+ progress: e,
139
+ mode: s,
140
+ caption: o
386
141
  }
387
142
  })
388
143
  );
389
144
  };
390
- const _ = 1e-5;
391
- class M extends EventTarget {
145
+ const P = 1e-5;
146
+ class C extends EventTarget {
392
147
  constructor({
393
- weight: e = 1,
394
- caption: t = "",
395
- fillTime: r = 4
148
+ weight: t = 1,
149
+ caption: e = "",
150
+ fillTime: s = 4
396
151
  } = {}) {
397
- 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;
152
+ super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight = t, this._selfCaption = e, this._fillTime = s;
398
153
  }
399
154
  /**
400
155
  * Creates a new sub-tracker with a specific weight.
@@ -431,20 +186,20 @@ class M extends EventTarget {
431
186
  * subTracker1.set(100);
432
187
  * ```
433
188
  */
434
- stage(e, t = "") {
435
- if (e || (e = this._selfWeight), this._selfWeight - e < -_)
189
+ stage(t, e = "") {
190
+ if (t || (t = this._selfWeight), this._selfWeight - t < -P)
436
191
  throw new Error(
437
- `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
192
+ `Cannot add a stage with weight ${t} as the total weight of registered stages would exceed 1.`
438
193
  );
439
- this._selfWeight -= e;
440
- const r = new M({
441
- caption: t,
442
- weight: e,
194
+ this._selfWeight -= t;
195
+ const s = new C({
196
+ caption: e,
197
+ weight: t,
443
198
  fillTime: this._fillTime
444
199
  });
445
- return this._subTrackers.push(r), r.addEventListener("progress", () => this.notifyProgress()), r.addEventListener("done", () => {
200
+ return this._subTrackers.push(s), s.addEventListener("progress", () => this.notifyProgress()), s.addEventListener("done", () => {
446
201
  this.done && this.notifyDone();
447
- }), r;
202
+ }), s;
448
203
  }
449
204
  /**
450
205
  * Fills the progress bar slowly over time, simulating progress.
@@ -464,87 +219,87 @@ class M extends EventTarget {
464
219
  *
465
220
  * @param options Optional options.
466
221
  */
467
- fillSlowly({ stopBeforeFinishing: e = !0 } = {}) {
222
+ fillSlowly({ stopBeforeFinishing: t = !0 } = {}) {
468
223
  if (this._isFilling)
469
224
  return;
470
225
  this._isFilling = !0;
471
- const t = 100, r = this._fillTime / t;
226
+ const e = 100, s = this._fillTime / e;
472
227
  this._fillInterval = setInterval(() => {
473
- this.set(this._selfProgress + 1), e && this._selfProgress >= 99 && clearInterval(this._fillInterval);
474
- }, r);
228
+ this.set(this._selfProgress + 1), t && this._selfProgress >= 99 && clearInterval(this._fillInterval);
229
+ }, s);
475
230
  }
476
- set(e) {
477
- this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + _ >= 100 && this.finish();
231
+ set(t) {
232
+ this._selfProgress = Math.min(t, 100), this.notifyProgress(), this._selfProgress + P >= 100 && this.finish();
478
233
  }
479
234
  finish() {
480
235
  this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
481
236
  }
482
237
  get caption() {
483
- for (let e = this._subTrackers.length - 1; e >= 0; e--)
484
- if (!this._subTrackers[e].done) {
485
- const t = this._subTrackers[e].caption;
486
- if (t)
487
- return t;
238
+ for (let t = this._subTrackers.length - 1; t >= 0; t--)
239
+ if (!this._subTrackers[t].done) {
240
+ const e = this._subTrackers[t].caption;
241
+ if (e)
242
+ return e;
488
243
  }
489
244
  return this._selfCaption;
490
245
  }
491
- setCaption(e) {
492
- this._selfCaption = e, this.notifyProgress();
246
+ setCaption(t) {
247
+ this._selfCaption = t, this.notifyProgress();
493
248
  }
494
249
  get done() {
495
- return this.progress + _ >= 100;
250
+ return this.progress + P >= 100;
496
251
  }
497
252
  get progress() {
498
253
  if (this._selfDone)
499
254
  return 100;
500
- const e = this._subTrackers.reduce(
501
- (t, r) => t + r.progress * r.weight,
255
+ const t = this._subTrackers.reduce(
256
+ (e, s) => e + s.progress * s.weight,
502
257
  this._selfProgress * this._selfWeight
503
258
  );
504
- return Math.round(e * 1e4) / 1e4;
259
+ return Math.round(t * 1e4) / 1e4;
505
260
  }
506
261
  get weight() {
507
262
  return this._weight;
508
263
  }
509
264
  get observer() {
510
- return this._progressObserver || (this._progressObserver = (e) => {
511
- this.set(e);
265
+ return this._progressObserver || (this._progressObserver = (t) => {
266
+ this.set(t);
512
267
  }), this._progressObserver;
513
268
  }
514
269
  get loadingListener() {
515
- return this._loadingListener || (this._loadingListener = (e) => {
516
- this.set(e.detail.loaded / e.detail.total * 100);
270
+ return this._loadingListener || (this._loadingListener = (t) => {
271
+ this.set(t.detail.loaded / t.detail.total * 100);
517
272
  }), this._loadingListener;
518
273
  }
519
- pipe(e) {
520
- e.setProgress({
274
+ pipe(t) {
275
+ t.setProgress({
521
276
  progress: this.progress,
522
277
  caption: this.caption
523
- }), this.addEventListener("progress", (t) => {
524
- e.setProgress({
525
- progress: t.detail.progress,
526
- caption: t.detail.caption
278
+ }), this.addEventListener("progress", (e) => {
279
+ t.setProgress({
280
+ progress: e.detail.progress,
281
+ caption: e.detail.caption
527
282
  });
528
283
  }), this.addEventListener("done", () => {
529
- e.setLoaded();
284
+ t.setLoaded();
530
285
  });
531
286
  }
532
- addEventListener(e, t) {
533
- super.addEventListener(e, t);
287
+ addEventListener(t, e) {
288
+ super.addEventListener(t, e);
534
289
  }
535
- removeEventListener(e, t) {
536
- super.removeEventListener(e, t);
290
+ removeEventListener(t, e) {
291
+ super.removeEventListener(t, e);
537
292
  }
538
293
  notifyProgress() {
539
- const e = this;
294
+ const t = this;
540
295
  this.dispatchEvent(
541
296
  new CustomEvent("progress", {
542
297
  detail: {
543
298
  get progress() {
544
- return e.progress;
299
+ return t.progress;
545
300
  },
546
301
  get caption() {
547
- return e.caption;
302
+ return t.caption;
548
303
  }
549
304
  }
550
305
  })
@@ -555,8 +310,8 @@ class M extends EventTarget {
555
310
  }
556
311
  }
557
312
  export {
558
- G as EmscriptenDownloadMonitor,
559
- Z as ProgressObserver,
560
- M as ProgressTracker,
561
- U as cloneResponseMonitorProgress
313
+ D as EmscriptenDownloadMonitor,
314
+ F as ProgressObserver,
315
+ C as ProgressTracker,
316
+ R as cloneResponseMonitorProgress
562
317
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/progress",
3
- "version": "0.9.13",
3
+ "version": "0.9.15",
4
4
  "description": "PHP.wasm – loading progress monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,13 +29,13 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "17a507b1456864892f6a8d85acccf19cb013ccb1",
32
+ "gitHead": "62c0b6769e8922ec6ec1fdb985a69c4e86d070a2",
33
33
  "engines": {
34
34
  "node": ">=18.18.0",
35
35
  "npm": ">=8.11.0"
36
36
  },
37
37
  "dependencies": {
38
- "@php-wasm/node-polyfills": "0.9.13",
39
- "@php-wasm/logger": "0.9.13"
38
+ "@php-wasm/node-polyfills": "0.9.15",
39
+ "@php-wasm/logger": "0.9.15"
40
40
  }
41
41
  }