@php-wasm/progress 0.7.18 → 0.7.20

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 +3 -2
  2. package/index.js +56 -51
  3. package/package.json +4 -4
package/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
- "use strict";var w=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var a=(s,e,t)=>(w(s,e,"read from private field"),t?t.call(s):e.get(s)),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)=>(w(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t);var E=(s,e,t,r)=>({set _(n){y(s,e,n,t)},get _(){return a(s,e,r)}}),b=(s,e,t)=>(w(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=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(I==="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(),c=new Uint8Array(o);new Uint8Array(i.buffer).set(c);const g=c.byteLength;n.byobRequest.respond(g),t+=g,t>=r.size&&n.close()}})})}if(I==="NODE"&&typeof CustomEvent>"u"){class s extends Event{constructor(t,r={}){super(t,r),this.detail=r.detail}initCustomEvent(){}}globalThis.CustomEvent=s}const O=(s,...e)=>{switch(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)}},S=(s,...e)=>[typeof s=="object"?JSON.stringify(s):s,...e.map(t=>JSON.stringify(t))].join(" "),R=[],P=s=>{R.push(s)},x=s=>{if(s.raw===!0)P(s.message);else{const e=F(typeof s.message=="object"?S(s.message):s.message,s.severity??"Info",s.prefix??"JavaScript");P(e)}};class B extends EventTarget{constructor(e=[]){super(),this.handlers=e,this.fatalErrorEvent="playground-fatal-error"}getLogs(){return this.handlers.includes(x)?[...R]:(this.error(`Logs aren't stored because the logToMemory handler isn't registered.
1
+ "use strict";var w=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var a=(s,e,t)=>(w(s,e,"read from private field"),t?t.call(s):e.get(s)),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)=>(w(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t);var E=(s,e,t,r)=>({set _(n){y(s,e,n,t)},get _(){return a(s,e,r)}}),b=(s,e,t)=>(w(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=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(R==="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(R==="NODE"&&typeof CustomEvent>"u"){class s extends Event{constructor(t,r={}){super(t,r),this.detail=r.detail}initCustomEvent(){}}globalThis.CustomEvent=s}const B=(s,...e)=>{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){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)}},S=s=>s instanceof Error?[s.message,s.stack].join(`
2
+ `):JSON.stringify(s,null,2),k=[],I=s=>{k.push(s)},L=s=>{if(s.raw===!0)I(s.message);else{const e=A(typeof s.message=="object"?S(s.message):s.message,s.severity??"Info",s.prefix??"JavaScript");I(e)}};class F extends EventTarget{constructor(e=[]){super(),this.handlers=e,this.fatalErrorEvent="playground-fatal-error"}getLogs(){return this.handlers.includes(L)?[...k]:(this.error(`Logs aren't stored because the logToMemory handler isn't registered.
2
3
  If you're using a custom logger instance, make sure to register logToMemory handler.
3
- `),[])}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 k=new B([x,O]),F=(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);return`[${n+" "+i}] ${t} ${e}: ${s}`},A=5*1024*1024;var f,h,v,C;class N extends EventTarget{constructor(){super(...arguments);u(this,v);u(this,f,{});u(this,h,{})}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,h)||(a(this,h)[o]=0)}}async monitorFetch(t){const r=await t;return D(r,i=>{b(this,v,C).call(this,r.url,i.detail.loaded,i.detail.total)})}}f=new WeakMap,h=new WeakMap,v=new WeakSet,C=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,h)[i]=r):n=a(this,f)[i],i in a(this,h)||k.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,h)[i]=r,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:M(a(this,h)),total:M(a(this,f))}}))};function M(s){return Object.values(s).reduce((e,t)=>e+t,0)}function D(s,e){const t=s.headers.get("content-length")||"",r=parseInt(t,10)||A;function n(i,l){e(new CustomEvent("progress",{detail:{loaded:i,total:l}}))}return new Response(new ReadableStream({async start(i){if(!s.body){i.close();return}const l=s.body.getReader();let o=0;for(;;)try{const{done:c,value:g}=await l.read();if(g&&(o+=g.byteLength),c){n(o,o),i.close();break}else n(o,r),i.enqueue(g)}catch(c){k.error({e:c}),i.error(c);break}}}),{status:s.status,statusText:s.statusText,headers:s.headers})}var d,p,m,T;class W extends EventTarget{constructor(){super(...arguments);u(this,m);u(this,d,void 0);u(this,p,void 0);y(this,d,{}),y(this,p,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(t,r=""){const n=++E(this,p)._;return a(this,d)[n]=0,i=>{const{loaded:l,total:o}=(i==null?void 0:i.detail)||{};a(this,d)[n]=l/o*t,b(this,m,T).call(this,this.totalProgress,"REAL_TIME",r)}}slowlyIncrementBy(t){const r=++E(this,p)._;a(this,d)[r]=t,b(this,m,T).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(a(this,d)).reduce((t,r)=>t+r,0)}}d=new WeakMap,p=new WeakMap,m=new WeakSet,T=function(t,r,n){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:t,mode:r,caption:n}}))};const _=1e-5;class L 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 L({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=N;exports.ProgressObserver=W;exports.ProgressTracker=L;exports.cloneResponseMonitorProgress=D;
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 N=()=>{try{if(process.env.NODE_ENV==="test")return[L]}catch{}return[L,B]},x=new F(N()),T=s=>s.replace(/\t/g,""),A=(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=T(s),`[${l}] ${t} ${e}: ${s}`},W=5*1024*1024;var f,h,v,C;class J extends EventTarget{constructor(){super(...arguments);u(this,v);u(this,f,{});u(this,h,{})}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,h)||(a(this,h)[o]=0)}}async monitorFetch(t){const r=await t;return O(r,i=>{b(this,v,C).call(this,r.url,i.detail.loaded,i.detail.total)})}}f=new WeakMap,h=new WeakMap,v=new WeakSet,C=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,h)[i]=r):n=a(this,f)[i],i in a(this,h)||x.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,h)[i]=r,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:M(a(this,h)),total:M(a(this,f))}}))};function M(s){return Object.values(s).reduce((e,t)=>e+t,0)}function O(s,e){const t=s.headers.get("content-length")||"",r=parseInt(t,10)||W;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){x.error({e:d}),i.error(d);break}}}),{status:s.status,statusText:s.statusText,headers:s.headers})}var c,p,m,P;class U extends EventTarget{constructor(){super(...arguments);u(this,m);u(this,c,void 0);u(this,p,void 0);y(this,c,{}),y(this,p,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(t,r=""){const n=++E(this,p)._;return a(this,c)[n]=0,i=>{const{loaded:l,total:o}=(i==null?void 0:i.detail)||{};a(this,c)[n]=l/o*t,b(this,m,P).call(this,this.totalProgress,"REAL_TIME",r)}}slowlyIncrementBy(t){const r=++E(this,p)._;a(this,c)[r]=t,b(this,m,P).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(a(this,c)).reduce((t,r)=>t+r,0)}}c=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 D 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 D({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=J;exports.ProgressObserver=U;exports.ProgressTracker=D;exports.cloneResponseMonitorProgress=O;
package/index.js CHANGED
@@ -15,7 +15,7 @@ var E = (s, e, t, r) => ({
15
15
  return a(s, e, r);
16
16
  }
17
17
  }), b = (s, e, t) => (w(s, e, "access private method"), t);
18
- const x = function() {
18
+ const D = function() {
19
19
  var s;
20
20
  return typeof process < "u" && ((s = process.release) == null ? void 0 : s.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
21
21
  // @ts-ignore
@@ -23,7 +23,7 @@ const x = function() {
23
23
  self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
24
24
  );
25
25
  }();
26
- if (x === "NODE") {
26
+ if (D === "NODE") {
27
27
  let s = function(t) {
28
28
  return new Promise(function(r, n) {
29
29
  t.onload = t.onerror = function(i) {
@@ -66,15 +66,15 @@ if (x === "NODE") {
66
66
  const i = n.byobRequest.view, o = await r.slice(
67
67
  t,
68
68
  t + i.byteLength
69
- ).arrayBuffer(), c = new Uint8Array(o);
70
- new Uint8Array(i.buffer).set(c);
71
- const g = c.byteLength;
69
+ ).arrayBuffer(), d = new Uint8Array(o);
70
+ new Uint8Array(i.buffer).set(d);
71
+ const g = d.byteLength;
72
72
  n.byobRequest.respond(g), t += g, t >= r.size && n.close();
73
73
  }
74
74
  });
75
75
  });
76
76
  }
77
- if (x === "NODE" && typeof CustomEvent > "u") {
77
+ if (D === "NODE" && typeof CustomEvent > "u") {
78
78
  class s extends Event {
79
79
  constructor(t, r = {}) {
80
80
  super(t, r), this.detail = r.detail;
@@ -84,8 +84,8 @@ if (x === "NODE" && typeof CustomEvent > "u") {
84
84
  }
85
85
  globalThis.CustomEvent = s;
86
86
  }
87
- const B = (s, ...e) => {
88
- switch (s.severity) {
87
+ const M = (s, ...e) => {
88
+ 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) {
89
89
  case "Debug":
90
90
  console.debug(s.message, ...e);
91
91
  break;
@@ -104,24 +104,22 @@ const B = (s, ...e) => {
104
104
  default:
105
105
  console.log(s.message, ...e);
106
106
  }
107
- }, D = (s, ...e) => [
108
- typeof s == "object" ? JSON.stringify(s) : s,
109
- ...e.map((t) => JSON.stringify(t))
110
- ].join(" "), I = [], T = (s) => {
111
- I.push(s);
112
- }, M = (s) => {
107
+ }, O = (s) => s instanceof Error ? [s.message, s.stack].join(`
108
+ `) : JSON.stringify(s, null, 2), R = [], x = (s) => {
109
+ R.push(s);
110
+ }, L = (s) => {
113
111
  if (s.raw === !0)
114
- T(s.message);
112
+ x(s.message);
115
113
  else {
116
- const e = S(
117
- typeof s.message == "object" ? D(s.message) : s.message,
114
+ const e = N(
115
+ typeof s.message == "object" ? O(s.message) : s.message,
118
116
  s.severity ?? "Info",
119
117
  s.prefix ?? "JavaScript"
120
118
  );
121
- T(e);
119
+ x(e);
122
120
  }
123
121
  };
124
- class O extends EventTarget {
122
+ class F extends EventTarget {
125
123
  // constructor
126
124
  constructor(e = []) {
127
125
  super(), this.handlers = e, this.fatalErrorEvent = "playground-fatal-error";
@@ -131,7 +129,7 @@ class O extends EventTarget {
131
129
  * @returns string[]
132
130
  */
133
131
  getLogs() {
134
- return this.handlers.includes(M) ? [...I] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
132
+ return this.handlers.includes(L) ? [...R] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
135
133
  If you're using a custom logger instance, make sure to register logToMemory handler.
136
134
  `), []);
137
135
  }
@@ -233,7 +231,14 @@ class O extends EventTarget {
233
231
  );
234
232
  }
235
233
  }
236
- const R = new O([M, B]), S = (s, e, t) => {
234
+ const S = () => {
235
+ try {
236
+ if (process.env.NODE_ENV === "test")
237
+ return [L];
238
+ } catch {
239
+ }
240
+ return [L, M];
241
+ }, k = new F(S()), T = (s) => s.replace(/\t/g, ""), N = (s, e, t) => {
237
242
  const r = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
238
243
  year: "numeric",
239
244
  month: "short",
@@ -246,11 +251,11 @@ const R = new O([M, B]), S = (s, e, t) => {
246
251
  hour12: !1,
247
252
  timeZone: "UTC",
248
253
  timeZoneName: "short"
249
- }).format(r);
250
- return `[${n + " " + i}] ${t} ${e}: ${s}`;
251
- }, F = 5 * 1024 * 1024;
254
+ }).format(r), l = n + " " + i;
255
+ return s = T(s), `[${l}] ${t} ${e}: ${s}`;
256
+ }, A = 5 * 1024 * 1024;
252
257
  var f, h, v, C;
253
- class W extends EventTarget {
258
+ class U extends EventTarget {
254
259
  constructor() {
255
260
  super(...arguments);
256
261
  /**
@@ -272,29 +277,29 @@ class W extends EventTarget {
272
277
  }
273
278
  async monitorFetch(t) {
274
279
  const r = await t;
275
- return A(r, (i) => {
280
+ return W(r, (i) => {
276
281
  b(this, v, C).call(this, r.url, i.detail.loaded, i.detail.total);
277
282
  });
278
283
  }
279
284
  }
280
285
  f = new WeakMap(), h = new WeakMap(), v = new WeakSet(), C = function(t, r, n) {
281
286
  const i = new URL(t, "http://example.com").pathname.split("/").pop();
282
- 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) || R.warn(
287
+ 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) || k.warn(
283
288
  `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.`
284
289
  ), a(this, h)[i] = r, this.dispatchEvent(
285
290
  new CustomEvent("progress", {
286
291
  detail: {
287
- loaded: P(a(this, h)),
288
- total: P(a(this, f))
292
+ loaded: I(a(this, h)),
293
+ total: I(a(this, f))
289
294
  }
290
295
  })
291
296
  );
292
297
  };
293
- function P(s) {
298
+ function I(s) {
294
299
  return Object.values(s).reduce((e, t) => e + t, 0);
295
300
  }
296
- function A(s, e) {
297
- const t = s.headers.get("content-length") || "", r = parseInt(t, 10) || F;
301
+ function W(s, e) {
302
+ const t = s.headers.get("content-length") || "", r = parseInt(t, 10) || A;
298
303
  function n(i, l) {
299
304
  e(
300
305
  new CustomEvent("progress", {
@@ -316,14 +321,14 @@ function A(s, e) {
316
321
  let o = 0;
317
322
  for (; ; )
318
323
  try {
319
- const { done: c, value: g } = await l.read();
320
- if (g && (o += g.byteLength), c) {
324
+ const { done: d, value: g } = await l.read();
325
+ if (g && (o += g.byteLength), d) {
321
326
  n(o, o), i.close();
322
327
  break;
323
328
  } else
324
329
  n(o, r), i.enqueue(g);
325
- } catch (c) {
326
- R.error({ e: c }), i.error(c);
330
+ } catch (d) {
331
+ k.error({ e: d }), i.error(d);
327
332
  break;
328
333
  }
329
334
  }
@@ -335,34 +340,34 @@ function A(s, e) {
335
340
  }
336
341
  );
337
342
  }
338
- var d, p, m, L;
339
- class J extends EventTarget {
343
+ var c, p, m, P;
344
+ class $ extends EventTarget {
340
345
  constructor() {
341
346
  super(...arguments);
342
347
  u(this, m);
343
- u(this, d, void 0);
348
+ u(this, c, void 0);
344
349
  u(this, p, void 0);
345
- y(this, d, {}), y(this, p, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
350
+ y(this, c, {}), y(this, p, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
346
351
  }
347
352
  partialObserver(t, r = "") {
348
353
  const n = ++E(this, p)._;
349
- return a(this, d)[n] = 0, (i) => {
354
+ return a(this, c)[n] = 0, (i) => {
350
355
  const { loaded: l, total: o } = (i == null ? void 0 : i.detail) || {};
351
- a(this, d)[n] = l / o * t, b(this, m, L).call(this, this.totalProgress, "REAL_TIME", r);
356
+ a(this, c)[n] = l / o * t, b(this, m, P).call(this, this.totalProgress, "REAL_TIME", r);
352
357
  };
353
358
  }
354
359
  slowlyIncrementBy(t) {
355
360
  const r = ++E(this, p)._;
356
- a(this, d)[r] = t, b(this, m, L).call(this, this.totalProgress, "SLOWLY_INCREMENT");
361
+ a(this, c)[r] = t, b(this, m, P).call(this, this.totalProgress, "SLOWLY_INCREMENT");
357
362
  }
358
363
  get totalProgress() {
359
- return Object.values(a(this, d)).reduce(
364
+ return Object.values(a(this, c)).reduce(
360
365
  (t, r) => t + r,
361
366
  0
362
367
  );
363
368
  }
364
369
  }
365
- d = new WeakMap(), p = new WeakMap(), m = new WeakSet(), L = function(t, r, n) {
370
+ c = new WeakMap(), p = new WeakMap(), m = new WeakSet(), P = function(t, r, n) {
366
371
  this.dispatchEvent(
367
372
  new CustomEvent("progress", {
368
373
  detail: {
@@ -374,7 +379,7 @@ d = new WeakMap(), p = new WeakMap(), m = new WeakSet(), L = function(t, r, n) {
374
379
  );
375
380
  };
376
381
  const _ = 1e-5;
377
- class k extends EventTarget {
382
+ class B extends EventTarget {
378
383
  constructor({
379
384
  weight: e = 1,
380
385
  caption: t = "",
@@ -423,7 +428,7 @@ class k extends EventTarget {
423
428
  `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
424
429
  );
425
430
  this._selfWeight -= e;
426
- const r = new k({
431
+ const r = new B({
427
432
  caption: t,
428
433
  weight: e,
429
434
  fillTime: this._fillTime
@@ -541,8 +546,8 @@ class k extends EventTarget {
541
546
  }
542
547
  }
543
548
  export {
544
- W as EmscriptenDownloadMonitor,
545
- J as ProgressObserver,
546
- k as ProgressTracker,
547
- A as cloneResponseMonitorProgress
549
+ U as EmscriptenDownloadMonitor,
550
+ $ as ProgressObserver,
551
+ B as ProgressTracker,
552
+ W as cloneResponseMonitorProgress
548
553
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/progress",
3
- "version": "0.7.18",
3
+ "version": "0.7.20",
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": "44ba621a9ca5e78acd5d6995da44ac460f8adc50",
32
+ "gitHead": "5915ef756c88da8dcb665f9f0e49ddc0c0b10d50",
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.7.18",
39
- "@php-wasm/logger": "0.7.18"
38
+ "@php-wasm/node-polyfills": "0.7.20",
39
+ "@php-wasm/logger": "0.7.20"
40
40
  }
41
41
  }