@php-wasm/progress 0.7.20 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.cjs +3 -3
  2. package/index.js +56 -47
  3. package/package.json +4 -4
package/index.cjs CHANGED
@@ -1,4 +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 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.
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
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 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;
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;
package/index.js CHANGED
@@ -1,21 +1,21 @@
1
- var w = (s, e, t) => {
1
+ var E = (s, e, t) => {
2
2
  if (!e.has(s))
3
3
  throw TypeError("Cannot " + t);
4
4
  };
5
- var a = (s, e, t) => (w(s, e, "read from private field"), t ? t.call(s) : e.get(s)), u = (s, e, t) => {
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
6
  if (e.has(s))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
8
  e instanceof WeakSet ? e.add(s) : e.set(s, t);
9
- }, y = (s, e, t, r) => (w(s, e, "write to private field"), r ? r.call(s, t) : e.set(s, t), t);
10
- var E = (s, e, t, r) => ({
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
11
  set _(n) {
12
12
  y(s, e, n, t);
13
13
  },
14
14
  get _() {
15
15
  return a(s, e, r);
16
16
  }
17
- }), b = (s, e, t) => (w(s, e, "access private method"), t);
18
- const D = function() {
17
+ }), v = (s, e, t) => (E(s, e, "access private method"), t);
18
+ const R = 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 D = function() {
23
23
  self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
24
24
  );
25
25
  }();
26
- if (D === "NODE") {
26
+ if (R === "NODE") {
27
27
  let s = function(t) {
28
28
  return new Promise(function(r, n) {
29
29
  t.onload = t.onerror = function(i) {
@@ -74,7 +74,7 @@ if (D === "NODE") {
74
74
  });
75
75
  });
76
76
  }
77
- if (D === "NODE" && typeof CustomEvent > "u") {
77
+ if (R === "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,7 +84,16 @@ if (D === "NODE" && typeof CustomEvent > "u") {
84
84
  }
85
85
  globalThis.CustomEvent = s;
86
86
  }
87
- const M = (s, ...e) => {
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) => {
88
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) {
89
98
  case "Debug":
90
99
  console.debug(s.message, ...e);
@@ -104,22 +113,22 @@ const M = (s, ...e) => {
104
113
  default:
105
114
  console.log(s.message, ...e);
106
115
  }
107
- }, O = (s) => s instanceof Error ? [s.message, s.stack].join(`
108
- `) : JSON.stringify(s, null, 2), R = [], x = (s) => {
109
- R.push(s);
116
+ }, S = (s) => s instanceof Error ? [s.message, s.stack].join(`
117
+ `) : JSON.stringify(s, null, 2), k = [], C = (s) => {
118
+ k.push(s);
110
119
  }, L = (s) => {
111
120
  if (s.raw === !0)
112
- x(s.message);
121
+ C(s.message);
113
122
  else {
114
- const e = N(
115
- typeof s.message == "object" ? O(s.message) : s.message,
123
+ const e = W(
124
+ typeof s.message == "object" ? S(s.message) : s.message,
116
125
  s.severity ?? "Info",
117
126
  s.prefix ?? "JavaScript"
118
127
  );
119
- x(e);
128
+ C(e);
120
129
  }
121
130
  };
122
- class F extends EventTarget {
131
+ class N extends EventTarget {
123
132
  // constructor
124
133
  constructor(e = []) {
125
134
  super(), this.handlers = e, this.fatalErrorEvent = "playground-fatal-error";
@@ -129,7 +138,7 @@ class F extends EventTarget {
129
138
  * @returns string[]
130
139
  */
131
140
  getLogs() {
132
- return this.handlers.includes(L) ? [...R] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
141
+ return this.handlers.includes(L) ? [...k] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
133
142
  If you're using a custom logger instance, make sure to register logToMemory handler.
134
143
  `), []);
135
144
  }
@@ -231,14 +240,14 @@ class F extends EventTarget {
231
240
  );
232
241
  }
233
242
  }
234
- const S = () => {
243
+ const A = () => {
235
244
  try {
236
245
  if (process.env.NODE_ENV === "test")
237
- return [L];
246
+ return [L, I];
238
247
  } catch {
239
248
  }
240
- return [L, M];
241
- }, k = new F(S()), T = (s) => s.replace(/\t/g, ""), N = (s, e, t) => {
249
+ return [L, F, I];
250
+ }, x = new N(A()), T = (s) => s.replace(/\t/g, ""), W = (s, e, t) => {
242
251
  const r = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
243
252
  year: "numeric",
244
253
  month: "short",
@@ -253,9 +262,9 @@ const S = () => {
253
262
  timeZoneName: "short"
254
263
  }).format(r), l = n + " " + i;
255
264
  return s = T(s), `[${l}] ${t} ${e}: ${s}`;
256
- }, A = 5 * 1024 * 1024;
257
- var f, h, v, C;
258
- class U extends EventTarget {
265
+ }, J = 5 * 1024 * 1024;
266
+ var f, h, b, B;
267
+ class G extends EventTarget {
259
268
  constructor() {
260
269
  super(...arguments);
261
270
  /**
@@ -265,7 +274,7 @@ class U extends EventTarget {
265
274
  * @param loaded The number of bytes of that file loaded so far.
266
275
  * @param fileSize The total number of bytes in the loaded file.
267
276
  */
268
- u(this, v);
277
+ u(this, b);
269
278
  u(this, f, {});
270
279
  u(this, h, {});
271
280
  }
@@ -277,29 +286,29 @@ class U extends EventTarget {
277
286
  }
278
287
  async monitorFetch(t) {
279
288
  const r = await t;
280
- return W(r, (i) => {
281
- b(this, v, C).call(this, r.url, i.detail.loaded, i.detail.total);
289
+ return U(r, (i) => {
290
+ v(this, b, B).call(this, r.url, i.detail.loaded, i.detail.total);
282
291
  });
283
292
  }
284
293
  }
285
- f = new WeakMap(), h = new WeakMap(), v = new WeakSet(), C = function(t, r, n) {
294
+ f = new WeakMap(), h = new WeakMap(), b = new WeakSet(), B = function(t, r, n) {
286
295
  const i = new URL(t, "http://example.com").pathname.split("/").pop();
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(
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(
288
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.`
289
298
  ), a(this, h)[i] = r, this.dispatchEvent(
290
299
  new CustomEvent("progress", {
291
300
  detail: {
292
- loaded: I(a(this, h)),
293
- total: I(a(this, f))
301
+ loaded: D(a(this, h)),
302
+ total: D(a(this, f))
294
303
  }
295
304
  })
296
305
  );
297
306
  };
298
- function I(s) {
307
+ function D(s) {
299
308
  return Object.values(s).reduce((e, t) => e + t, 0);
300
309
  }
301
- function W(s, e) {
302
- const t = s.headers.get("content-length") || "", r = parseInt(t, 10) || A;
310
+ function U(s, e) {
311
+ const t = s.headers.get("content-length") || "", r = parseInt(t, 10) || J;
303
312
  function n(i, l) {
304
313
  e(
305
314
  new CustomEvent("progress", {
@@ -328,7 +337,7 @@ function W(s, e) {
328
337
  } else
329
338
  n(o, r), i.enqueue(g);
330
339
  } catch (d) {
331
- k.error({ e: d }), i.error(d);
340
+ x.error({ e: d }), i.error(d);
332
341
  break;
333
342
  }
334
343
  }
@@ -341,7 +350,7 @@ function W(s, e) {
341
350
  );
342
351
  }
343
352
  var c, p, m, P;
344
- class $ extends EventTarget {
353
+ class Z extends EventTarget {
345
354
  constructor() {
346
355
  super(...arguments);
347
356
  u(this, m);
@@ -350,15 +359,15 @@ class $ extends EventTarget {
350
359
  y(this, c, {}), y(this, p, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = "";
351
360
  }
352
361
  partialObserver(t, r = "") {
353
- const n = ++E(this, p)._;
362
+ const n = ++w(this, p)._;
354
363
  return a(this, c)[n] = 0, (i) => {
355
364
  const { loaded: l, total: o } = (i == null ? void 0 : i.detail) || {};
356
- a(this, c)[n] = l / o * t, b(this, m, P).call(this, this.totalProgress, "REAL_TIME", r);
365
+ a(this, c)[n] = l / o * t, v(this, m, P).call(this, this.totalProgress, "REAL_TIME", r);
357
366
  };
358
367
  }
359
368
  slowlyIncrementBy(t) {
360
- const r = ++E(this, p)._;
361
- a(this, c)[r] = t, b(this, m, P).call(this, this.totalProgress, "SLOWLY_INCREMENT");
369
+ const r = ++w(this, p)._;
370
+ a(this, c)[r] = t, v(this, m, P).call(this, this.totalProgress, "SLOWLY_INCREMENT");
362
371
  }
363
372
  get totalProgress() {
364
373
  return Object.values(a(this, c)).reduce(
@@ -379,7 +388,7 @@ c = new WeakMap(), p = new WeakMap(), m = new WeakSet(), P = function(t, r, n) {
379
388
  );
380
389
  };
381
390
  const _ = 1e-5;
382
- class B extends EventTarget {
391
+ class M extends EventTarget {
383
392
  constructor({
384
393
  weight: e = 1,
385
394
  caption: t = "",
@@ -428,7 +437,7 @@ class B extends EventTarget {
428
437
  `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
429
438
  );
430
439
  this._selfWeight -= e;
431
- const r = new B({
440
+ const r = new M({
432
441
  caption: t,
433
442
  weight: e,
434
443
  fillTime: this._fillTime
@@ -546,8 +555,8 @@ class B extends EventTarget {
546
555
  }
547
556
  }
548
557
  export {
549
- U as EmscriptenDownloadMonitor,
550
- $ as ProgressObserver,
551
- B as ProgressTracker,
552
- W as cloneResponseMonitorProgress
558
+ G as EmscriptenDownloadMonitor,
559
+ Z as ProgressObserver,
560
+ M as ProgressTracker,
561
+ U as cloneResponseMonitorProgress
553
562
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/progress",
3
- "version": "0.7.20",
3
+ "version": "0.9.4",
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": "5915ef756c88da8dcb665f9f0e49ddc0c0b10d50",
32
+ "gitHead": "702bb9bed9c153ea23651059592aea19c1ba9be4",
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.20",
39
- "@php-wasm/logger": "0.7.20"
38
+ "@php-wasm/node-polyfills": "0.9.4",
39
+ "@php-wasm/logger": "0.9.4"
40
40
  }
41
41
  }