@php-wasm/progress 0.6.0 → 0.6.1

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.
@@ -0,0 +1,4 @@
1
+ const e = {};
2
+ export {
3
+ e as default
4
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={};exports.default=e;
package/index.cjs CHANGED
@@ -1 +1 @@
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)),h=(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)},_=(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){_(s,e,n,t)},get _(){return a(s,e,r)}}),g=(s,e,t)=>(w(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});if(typeof File>"u"){class s extends Blob{constructor(t,r,n){super(t);let i;n!=null&&n.lastModified&&(i=new Date),(!i||isNaN(i.getFullYear()))&&(i=new Date),this.lastModifiedDate=i,this.lastModified=i.getMilliseconds(),this.name=r||""}}global.File=s}function I(s){return new Promise(function(e,t){s.onload=s.onerror=function(r){s.onload=s.onerror=null,r.type==="load"?e(s.result):t(new Error("Failed to read the blob/file"))}})}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const e=new FileReader;return e.readAsArrayBuffer(this),I(e)});typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const e=new FileReader;return e.readAsText(this),I(e)});function x(){const s=new Uint8Array([1,2,3,4]),t=new File([s],"test").stream();try{return t.getReader({mode:"byob"}),!0}catch{return!1}}(typeof Blob.prototype.stream>"u"||!x())&&(Blob.prototype.stream=function(){let s=0;const e=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(t){const r=t.byobRequest.view,i=await e.slice(s,s+r.byteLength).arrayBuffer(),l=new Uint8Array(i);new Uint8Array(r.buffer).set(l);const o=l.byteLength;t.byobRequest.respond(o),s+=o,s>=e.size&&t.close()}})});if(typeof CustomEvent>"u"){class s extends Event{constructor(t,r={}){super(t,r),this.detail=r.detail}initCustomEvent(){}}globalThis.CustomEvent=s}const A=5*1024*1024;var u,d,v,S,b,L;class F extends EventTarget{constructor(){super();h(this,v);h(this,b);h(this,u,{});h(this,d,{});g(this,v,S).call(this)}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,u)||(a(this,u)[o]=n),o in a(this,d)||(a(this,d)[o]=0)}}async monitorFetch(t){const r=await t;return T(r,i=>{g(this,b,L).call(this,r.url,i.detail.loaded,i.detail.total)})}}u=new WeakMap,d=new WeakMap,v=new WeakSet,S=function(){const t=WebAssembly.instantiateStreaming;WebAssembly.instantiateStreaming=async(r,...n)=>{const i=await r,l=i.url.substring(new URL(i.url).origin.length+1),o=T(i,({detail:{loaded:c,total:y}})=>g(this,b,L).call(this,l,c,y));return t(o,...n)}},b=new WeakSet,L=function(t,r,n){const i=new URL(t,"http://example.com").pathname.split("/").pop();n||(n=a(this,u)[i]),i in a(this,d)||console.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,d)[i]=r,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:B(a(this,d)),total:B(a(this,u))}}))};function B(s){return Object.values(s).reduce((e,t)=>e+t,0)}function T(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:y}=await l.read();if(y&&(o+=y.byteLength),c){n(o,o),i.close();break}else n(o,r),i.enqueue(y)}catch(c){console.error({e:c}),i.error(c);break}}}),{status:s.status,statusText:s.statusText,headers:s.headers})}var f,p,m,R;class M extends EventTarget{constructor(){super(...arguments);h(this,m);h(this,f,void 0);h(this,p,void 0);_(this,f,{}),_(this,p,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(t,r=""){const n=++E(this,p)._;return a(this,f)[n]=0,i=>{const{loaded:l,total:o}=(i==null?void 0:i.detail)||{};a(this,f)[n]=l/o*t,g(this,m,R).call(this,this.totalProgress,"REAL_TIME",r)}}slowlyIncrementBy(t){const r=++E(this,p)._;a(this,f)[r]=t,g(this,m,R).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(a(this,f)).reduce((t,r)=>t+r,0)}}f=new WeakMap,p=new WeakMap,m=new WeakSet,R=function(t,r,n){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:t,mode:r,caption:n}}))};const P=1e-5;class C 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<-P)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 C({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+P>=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+P>=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=F;exports.ProgressObserver=M;exports.ProgressTracker=C;exports.cloneResponseMonitorProgress=T;
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)),h=(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)},_=(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){_(s,e,n,t)},get _(){return a(s,e,r)}}),g=(s,e,t)=>(w(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});if(typeof File>"u"){class s extends Blob{constructor(t,r,n){super(t);let i;n!=null&&n.lastModified&&(i=new Date),(!i||isNaN(i.getFullYear()))&&(i=new Date),this.lastModifiedDate=i,this.lastModified=i.getMilliseconds(),this.name=r||""}}global.File=s}function I(s){return new Promise(function(e,t){s.onload=s.onerror=function(r){s.onload=s.onerror=null,r.type==="load"?e(s.result):t(new Error("Failed to read the blob/file"))}})}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const e=new FileReader;return e.readAsArrayBuffer(this),I(e)});typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const e=new FileReader;return e.readAsText(this),I(e)});function x(){const s=new Uint8Array([1,2,3,4]),t=new File([s],"test").stream();try{return t.getReader({mode:"byob"}),!0}catch{return!1}}(typeof Blob.prototype.stream>"u"||!x())&&(Blob.prototype.stream=function(){let s=0;const e=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(t){const r=t.byobRequest.view,i=await e.slice(s,s+r.byteLength).arrayBuffer(),l=new Uint8Array(i);new Uint8Array(r.buffer).set(l);const o=l.byteLength;t.byobRequest.respond(o),s+=o,s>=e.size&&t.close()}})});if(typeof CustomEvent>"u"){class s extends Event{constructor(t,r={}){super(t,r),this.detail=r.detail}initCustomEvent(){}}globalThis.CustomEvent=s}typeof crypto>"u"&&Promise.resolve().then(()=>require("./__vite-browser-external-b3701507.cjs")).then(s=>{global.crypto=s});const A=5*1024*1024;var u,d,v,S,b,L;class F extends EventTarget{constructor(){super();h(this,v);h(this,b);h(this,u,{});h(this,d,{});g(this,v,S).call(this)}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,u)||(a(this,u)[o]=n),o in a(this,d)||(a(this,d)[o]=0)}}async monitorFetch(t){const r=await t;return T(r,i=>{g(this,b,L).call(this,r.url,i.detail.loaded,i.detail.total)})}}u=new WeakMap,d=new WeakMap,v=new WeakSet,S=function(){const t=WebAssembly.instantiateStreaming;WebAssembly.instantiateStreaming=async(r,...n)=>{const i=await r,l=i.url.substring(new URL(i.url).origin.length+1),o=T(i,({detail:{loaded:c,total:y}})=>g(this,b,L).call(this,l,c,y));return t(o,...n)}},b=new WeakSet,L=function(t,r,n){const i=new URL(t,"http://example.com").pathname.split("/").pop();n||(n=a(this,u)[i]),i in a(this,d)||console.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,d)[i]=r,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:B(a(this,d)),total:B(a(this,u))}}))};function B(s){return Object.values(s).reduce((e,t)=>e+t,0)}function T(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:y}=await l.read();if(y&&(o+=y.byteLength),c){n(o,o),i.close();break}else n(o,r),i.enqueue(y)}catch(c){console.error({e:c}),i.error(c);break}}}),{status:s.status,statusText:s.statusText,headers:s.headers})}var f,p,m,R;class M extends EventTarget{constructor(){super(...arguments);h(this,m);h(this,f,void 0);h(this,p,void 0);_(this,f,{}),_(this,p,0),this.progress=0,this.mode="REAL_TIME",this.caption=""}partialObserver(t,r=""){const n=++E(this,p)._;return a(this,f)[n]=0,i=>{const{loaded:l,total:o}=(i==null?void 0:i.detail)||{};a(this,f)[n]=l/o*t,g(this,m,R).call(this,this.totalProgress,"REAL_TIME",r)}}slowlyIncrementBy(t){const r=++E(this,p)._;a(this,f)[r]=t,g(this,m,R).call(this,this.totalProgress,"SLOWLY_INCREMENT")}get totalProgress(){return Object.values(a(this,f)).reduce((t,r)=>t+r,0)}}f=new WeakMap,p=new WeakMap,m=new WeakSet,R=function(t,r,n){this.dispatchEvent(new CustomEvent("progress",{detail:{progress:t,mode:r,caption:n}}))};const P=1e-5;class C 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<-P)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 C({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+P>=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+P>=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=F;exports.ProgressObserver=M;exports.ProgressTracker=C;exports.cloneResponseMonitorProgress=T;
package/index.js CHANGED
@@ -74,6 +74,9 @@ if (typeof CustomEvent > "u") {
74
74
  }
75
75
  globalThis.CustomEvent = s;
76
76
  }
77
+ typeof crypto > "u" && import("./__vite-browser-external-2447137e.js").then((s) => {
78
+ global.crypto = s;
79
+ });
77
80
  const F = 5 * 1024 * 1024;
78
81
  var u, d, v, I, b, P;
79
82
  class k extends EventTarget {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/progress",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "PHP.wasm – loading progress monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,12 +29,12 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "3f137306ec8e3b10ec0674a1fe69ee43349edb4a",
32
+ "gitHead": "171b22b853786b8912d9624ea064eaa1e985e96b",
33
33
  "engines": {
34
34
  "node": ">=18.18.2",
35
35
  "npm": ">=8.11.0"
36
36
  },
37
37
  "dependencies": {
38
- "@php-wasm/node-polyfills": "0.6.0"
38
+ "@php-wasm/node-polyfills": "0.6.1"
39
39
  }
40
40
  }