@php-wasm/progress
Advanced tools
Comparing version 0.6.16 to 0.7.0
131
index.js
@@ -1,13 +0,13 @@ | ||
var E = (r, t, e) => { | ||
var v = (r, t, e) => { | ||
if (!t.has(r)) | ||
throw TypeError("Cannot " + e); | ||
}; | ||
var a = (r, t, e) => (E(r, t, "read from private field"), e ? e.call(r) : t.get(r)), f = (r, t, e) => { | ||
var a = (r, t, e) => (v(r, t, "read from private field"), e ? e.call(r) : t.get(r)), u = (r, t, e) => { | ||
if (t.has(r)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
t instanceof WeakSet ? t.add(r) : t.set(r, e); | ||
}, _ = (r, t, e, s) => (E(r, t, "write to private field"), s ? s.call(r, e) : t.set(r, e), e); | ||
var w = (r, t, e, s) => ({ | ||
}, b = (r, t, e, s) => (v(r, t, "write to private field"), s ? s.call(r, e) : t.set(r, e), e); | ||
var E = (r, t, e, s) => ({ | ||
set _(n) { | ||
_(r, t, n, e); | ||
b(r, t, n, e); | ||
}, | ||
@@ -17,4 +17,4 @@ get _() { | ||
} | ||
}), p = (r, t, e) => (E(r, t, "access private method"), e); | ||
const C = function() { | ||
}), _ = (r, t, e) => (v(r, t, "access private method"), e); | ||
const R = function() { | ||
var r; | ||
@@ -27,3 +27,3 @@ return typeof process < "u" && ((r = process.release) == null ? void 0 : r.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : ( | ||
}(); | ||
if (C === "NODE") { | ||
if (R === "NODE") { | ||
let r = function(e) { | ||
@@ -71,6 +71,6 @@ return new Promise(function(s, n) { | ||
e + i.byteLength | ||
).arrayBuffer(), h = new Uint8Array(o); | ||
new Uint8Array(i.buffer).set(h); | ||
const d = h.byteLength; | ||
n.byobRequest.respond(d), e += d, e >= s.size && n.close(); | ||
).arrayBuffer(), f = new Uint8Array(o); | ||
new Uint8Array(i.buffer).set(f); | ||
const p = f.byteLength; | ||
n.byobRequest.respond(p), e += p, e >= s.size && n.close(); | ||
} | ||
@@ -80,3 +80,3 @@ }); | ||
} | ||
if (C === "NODE" && typeof CustomEvent > "u") { | ||
if (R === "NODE" && typeof CustomEvent > "u") { | ||
class r extends Event { | ||
@@ -91,13 +91,8 @@ constructor(e, s = {}) { | ||
} | ||
const x = 5 * 1024 * 1024; | ||
var g, u, v, I, b, P; | ||
class A extends EventTarget { | ||
const C = 5 * 1024 * 1024; | ||
var c, h, m, T; | ||
class x extends EventTarget { | ||
constructor() { | ||
super(); | ||
super(...arguments); | ||
/** | ||
* Replaces the default WebAssembly.instantiateStreaming with a version | ||
* that monitors the download #progress. | ||
*/ | ||
f(this, v); | ||
/** | ||
* Notifies about the download #progress of a file. | ||
@@ -109,6 +104,5 @@ * | ||
*/ | ||
f(this, b); | ||
f(this, g, {}); | ||
f(this, u, {}); | ||
p(this, v, I).call(this); | ||
u(this, m); | ||
u(this, c, {}); | ||
u(this, h, {}); | ||
} | ||
@@ -118,3 +112,3 @@ expectAssets(e) { | ||
const i = "http://example.com/", o = new URL(s, i).pathname.split("/").pop(); | ||
o in a(this, g) || (a(this, g)[o] = n), o in a(this, u) || (a(this, u)[o] = 0); | ||
o in a(this, c) || (a(this, c)[o] = n), o in a(this, h) || (a(this, h)[o] = 0); | ||
} | ||
@@ -124,27 +118,16 @@ } | ||
const s = await e; | ||
return B(s, (i) => { | ||
p(this, b, P).call(this, s.url, i.detail.loaded, i.detail.total); | ||
return I(s, (i) => { | ||
_(this, m, T).call(this, s.url, i.detail.loaded, i.detail.total); | ||
}); | ||
} | ||
} | ||
g = new WeakMap(), u = new WeakMap(), v = new WeakSet(), I = function() { | ||
const e = WebAssembly.instantiateStreaming; | ||
WebAssembly.instantiateStreaming = async (s, ...n) => { | ||
const i = await s, l = i.url.substring( | ||
new URL(i.url).origin.length + 1 | ||
), o = B( | ||
i, | ||
({ detail: { loaded: h, total: d } }) => p(this, b, P).call(this, l, h, d) | ||
); | ||
return e(o, ...n); | ||
}; | ||
}, b = new WeakSet(), P = function(e, s, n) { | ||
c = new WeakMap(), h = new WeakMap(), m = new WeakSet(), T = function(e, s, n) { | ||
const i = new URL(e, "http://example.com").pathname.split("/").pop(); | ||
n || (n = a(this, g)[i]), i in a(this, u) || console.warn( | ||
n || (n = a(this, c)[i]), i in a(this, h) || 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, u)[i] = s, this.dispatchEvent( | ||
), a(this, h)[i] = s, this.dispatchEvent( | ||
new CustomEvent("progress", { | ||
detail: { | ||
loaded: T(a(this, u)), | ||
total: T(a(this, g)) | ||
loaded: P(a(this, h)), | ||
total: P(a(this, c)) | ||
} | ||
@@ -154,7 +137,7 @@ }) | ||
}; | ||
function T(r) { | ||
function P(r) { | ||
return Object.values(r).reduce((t, e) => t + e, 0); | ||
} | ||
function B(r, t) { | ||
const e = r.headers.get("content-length") || "", s = parseInt(e, 10) || x; | ||
function I(r, t) { | ||
const e = r.headers.get("content-length") || "", s = parseInt(e, 10) || C; | ||
function n(i, l) { | ||
@@ -181,10 +164,10 @@ t( | ||
try { | ||
const { done: h, value: d } = await l.read(); | ||
if (d && (o += d.byteLength), h) { | ||
const { done: f, value: p } = await l.read(); | ||
if (p && (o += p.byteLength), f) { | ||
n(o, o), i.close(); | ||
break; | ||
} else | ||
n(o, s), i.enqueue(d); | ||
} catch (h) { | ||
console.error({ e: h }), i.error(h); | ||
n(o, s), i.enqueue(p); | ||
} catch (f) { | ||
console.error({ e: f }), i.error(f); | ||
break; | ||
@@ -201,24 +184,24 @@ } | ||
} | ||
var c, y, m, R; | ||
var d, g, y, L; | ||
class F extends EventTarget { | ||
constructor() { | ||
super(...arguments); | ||
f(this, m); | ||
f(this, c, void 0); | ||
f(this, y, void 0); | ||
_(this, c, {}), _(this, y, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = ""; | ||
u(this, y); | ||
u(this, d, void 0); | ||
u(this, g, void 0); | ||
b(this, d, {}), b(this, g, 0), this.progress = 0, this.mode = "REAL_TIME", this.caption = ""; | ||
} | ||
partialObserver(e, s = "") { | ||
const n = ++w(this, y)._; | ||
return a(this, c)[n] = 0, (i) => { | ||
const n = ++E(this, g)._; | ||
return a(this, d)[n] = 0, (i) => { | ||
const { loaded: l, total: o } = (i == null ? void 0 : i.detail) || {}; | ||
a(this, c)[n] = l / o * e, p(this, m, R).call(this, this.totalProgress, "REAL_TIME", s); | ||
a(this, d)[n] = l / o * e, _(this, y, L).call(this, this.totalProgress, "REAL_TIME", s); | ||
}; | ||
} | ||
slowlyIncrementBy(e) { | ||
const s = ++w(this, y)._; | ||
a(this, c)[s] = e, p(this, m, R).call(this, this.totalProgress, "SLOWLY_INCREMENT"); | ||
const s = ++E(this, g)._; | ||
a(this, d)[s] = e, _(this, y, L).call(this, this.totalProgress, "SLOWLY_INCREMENT"); | ||
} | ||
get totalProgress() { | ||
return Object.values(a(this, c)).reduce( | ||
return Object.values(a(this, d)).reduce( | ||
(e, s) => e + s, | ||
@@ -229,3 +212,3 @@ 0 | ||
} | ||
c = new WeakMap(), y = new WeakMap(), m = new WeakSet(), R = function(e, s, n) { | ||
d = new WeakMap(), g = new WeakMap(), y = new WeakSet(), L = function(e, s, n) { | ||
this.dispatchEvent( | ||
@@ -241,4 +224,4 @@ new CustomEvent("progress", { | ||
}; | ||
const L = 1e-5; | ||
class O extends EventTarget { | ||
const w = 1e-5; | ||
class B extends EventTarget { | ||
constructor({ | ||
@@ -287,3 +270,3 @@ weight: t = 1, | ||
stage(t, e = "") { | ||
if (t || (t = this._selfWeight), this._selfWeight - t < -L) | ||
if (t || (t = this._selfWeight), this._selfWeight - t < -w) | ||
throw new Error( | ||
@@ -293,3 +276,3 @@ `Cannot add a stage with weight ${t} as the total weight of registered stages would exceed 1.` | ||
this._selfWeight -= t; | ||
const s = new O({ | ||
const s = new B({ | ||
caption: e, | ||
@@ -331,3 +314,3 @@ weight: t, | ||
set(t) { | ||
this._selfProgress = Math.min(t, 100), this.notifyProgress(), this._selfProgress + L >= 100 && this.finish(); | ||
this._selfProgress = Math.min(t, 100), this.notifyProgress(), this._selfProgress + w >= 100 && this.finish(); | ||
} | ||
@@ -350,3 +333,3 @@ finish() { | ||
get done() { | ||
return this.progress + L >= 100; | ||
return this.progress + w >= 100; | ||
} | ||
@@ -414,6 +397,6 @@ get progress() { | ||
export { | ||
A as EmscriptenDownloadMonitor, | ||
x as EmscriptenDownloadMonitor, | ||
F as ProgressObserver, | ||
O as ProgressTracker, | ||
B as cloneResponseMonitorProgress | ||
B as ProgressTracker, | ||
I as cloneResponseMonitorProgress | ||
}; |
@@ -20,3 +20,2 @@ /** | ||
#private; | ||
constructor(); | ||
expectAssets(assets: Record<string, number>): void; | ||
@@ -23,0 +22,0 @@ monitorFetch(fetchPromise: Promise<Response>): Promise<Response>; |
{ | ||
"name": "@php-wasm/progress", | ||
"version": "0.6.16", | ||
"version": "0.7.0", | ||
"description": "PHP.wasm – loading progress monitoring", | ||
@@ -32,3 +32,3 @@ "repository": { | ||
"types": "index.d.ts", | ||
"gitHead": "1981567e7eacecbc4a18c870267c20bf489afd8f", | ||
"gitHead": "c5eba3d709f2821c4303521e8c81b962e3bcca23", | ||
"engines": { | ||
@@ -39,4 +39,4 @@ "node": ">=18.18.0", | ||
"dependencies": { | ||
"@php-wasm/node-polyfills": "0.6.16" | ||
"@php-wasm/node-polyfills": "0.7.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
28586
656
+ Added@php-wasm/node-polyfills@0.7.0(transitive)
- Removed@php-wasm/node-polyfills@0.6.16(transitive)