@sheetxl/io
Version:
IO - Import/Export Libraries for SheetXL.
1,697 lines • 67.4 kB
JavaScript
/**
* @license @sheetxl/io - IO - Import/Export Libraries for SheetXL. - v0.7.27
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/
function Pe() {
}
function R(e) {
return typeof e == "object" && e !== null || typeof e == "function";
}
const rr = Pe;
function p(e, t) {
try {
Object.defineProperty(e, "name", { value: t, configurable: !0 });
} catch {
}
}
const St = Promise, to = Promise.resolve.bind(St), ro = Promise.prototype.then, oo = Promise.reject.bind(St), no = to;
function P(e) {
return new St(e);
}
function y(e) {
return P((t) => t(e));
}
function c(e) {
return oo(e);
}
function B(e, t, r) {
return ro.call(e, t, r);
}
function W(e, t, r) {
B(B(e, t, r), void 0, rr);
}
function nt(e, t) {
W(e, t);
}
function bt(e, t) {
W(e, void 0, t);
}
function ne(e, t, r) {
return B(e, t, r);
}
function Ae(e) {
B(e, void 0, rr);
}
let ie = (e) => {
if (typeof queueMicrotask == "function") ie = queueMicrotask;
else {
const t = y(void 0);
ie = (r) => B(t, r);
}
return ie(e);
};
function me(e, t, r) {
if (typeof e != "function") throw new TypeError("Argument is not a function");
return Function.prototype.apply.call(e, t, r);
}
function ge(e, t, r) {
try {
return y(me(e, t, r));
} catch (o) {
return c(o);
}
}
class A {
constructor() {
this._cursor = 0, this._size = 0, this._front = { _elements: [], _next: void 0 }, this._back = this._front, this._cursor = 0, this._size = 0;
}
get length() {
return this._size;
}
push(t) {
const r = this._back;
let o = r;
r._elements.length === 16383 && (o = { _elements: [], _next: void 0 }), r._elements.push(t), o !== r && (this._back = o, r._next = o), ++this._size;
}
shift() {
const t = this._front;
let r = t;
const o = this._cursor;
let a = o + 1;
const i = t._elements, n = i[o];
return a === 16384 && (r = t._next, a = 0), --this._size, this._cursor = a, t !== r && (this._front = r), i[o] = void 0, n;
}
forEach(t) {
let r = this._cursor, o = this._front, a = o._elements;
for (; !(r === a.length && o._next === void 0 || r === a.length && (o = o._next, a = o._elements, r = 0, a.length === 0)); ) t(a[r]), ++r;
}
peek() {
const t = this._front, r = this._cursor;
return t._elements[r];
}
}
const or = Symbol("[[AbortSteps]]"), nr = Symbol("[[ErrorSteps]]"), Rt = Symbol("[[CancelSteps]]"), Tt = Symbol("[[PullSteps]]"), qt = Symbol("[[ReleaseSteps]]");
function ir(e, t) {
e._ownerReadableStream = t, t._reader = e, t._state === "readable" ? ht(e) : t._state === "closed" ? (function(r) {
ht(r), sr(r);
})(e) : ar(e, t._storedError);
}
function Et(e, t) {
return k(e._ownerReadableStream, t);
}
function L(e) {
const t = e._ownerReadableStream;
t._state === "readable" ? Pt(e, new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")) : (function(r) {
ar(r, new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"));
})(e), t._readableStreamController[qt](), t._reader = void 0, e._ownerReadableStream = void 0;
}
function He(e) {
return new TypeError("Cannot " + e + " a stream using a released reader");
}
function ht(e) {
e._closedPromise = P((t, r) => {
e._closedPromise_resolve = t, e._closedPromise_reject = r;
});
}
function ar(e, t) {
ht(e), Pt(e, t);
}
function Pt(e, t) {
e._closedPromise_reject !== void 0 && (Ae(e._closedPromise), e._closedPromise_reject(t), e._closedPromise_resolve = void 0, e._closedPromise_reject = void 0);
}
function sr(e) {
e._closedPromise_resolve !== void 0 && (e._closedPromise_resolve(void 0), e._closedPromise_resolve = void 0, e._closedPromise_reject = void 0);
}
const Mt = Number.isFinite || function(e) {
return typeof e == "number" && isFinite(e);
}, io = Math.trunc || function(e) {
return e < 0 ? Math.ceil(e) : Math.floor(e);
};
function V(e, t) {
if (e !== void 0 && typeof (r = e) != "object" && typeof r != "function") throw new TypeError(`${t} is not an object.`);
var r;
}
function X(e, t) {
if (typeof e != "function") throw new TypeError(`${t} is not a function.`);
}
function lr(e, t) {
if (!/* @__PURE__ */ (function(r) {
return typeof r == "object" && r !== null || typeof r == "function";
})(e)) throw new TypeError(`${t} is not an object.`);
}
function ae(e, t, r) {
if (e === void 0) throw new TypeError(`Parameter ${t} is required in '${r}'.`);
}
function Nt(e, t, r) {
if (e === void 0) throw new TypeError(`${t} is required in '${r}'.`);
}
function ur(e) {
return Number(e);
}
function Yt(e) {
return e === 0 ? 0 : e;
}
function Ct(e, t) {
const r = Number.MAX_SAFE_INTEGER;
let o = Number(e);
if (o = Yt(o), !Mt(o)) throw new TypeError(`${t} is not a finite number`);
if (o = (function(a) {
return Yt(io(a));
})(o), o < 0 || o > r) throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);
return Mt(o) && o !== 0 ? o : 0;
}
function Ot(e, t) {
if (!D(e)) throw new TypeError(`${t} is not a ReadableStream.`);
}
function ce(e) {
return new ee(e);
}
function cr(e, t) {
e._reader._readRequests.push(t);
}
function At(e, t, r) {
const o = e._reader._readRequests.shift();
r ? o._closeSteps() : o._chunkSteps(t);
}
function Ze(e) {
return e._reader._readRequests.length;
}
function dr(e) {
const t = e._reader;
return t !== void 0 && !!U(t);
}
class ee {
constructor(t) {
if (ae(t, 1, "ReadableStreamDefaultReader"), Ot(t, "First parameter"), H(t)) throw new TypeError("This stream has already been locked for exclusive reading by another reader");
ir(this, t), this._readRequests = new A();
}
get closed() {
return U(this) ? this._closedPromise : c(We("closed"));
}
cancel(t = void 0) {
return U(this) ? this._ownerReadableStream === void 0 ? c(He("cancel")) : Et(this, t) : c(We("cancel"));
}
read() {
if (!U(this)) return c(We("read"));
if (this._ownerReadableStream === void 0) return c(He("read from"));
let t, r;
const o = P((a, i) => {
t = a, r = i;
});
return Ce(this, { _chunkSteps: (a) => t({ value: a, done: !1 }), _closeSteps: () => t({ value: void 0, done: !0 }), _errorSteps: (a) => r(a) }), o;
}
releaseLock() {
if (!U(this)) throw We("releaseLock");
this._ownerReadableStream !== void 0 && (function(t) {
L(t), fr(t, new TypeError("Reader was released"));
})(this);
}
}
function U(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_readRequests") && e instanceof ee;
}
function Ce(e, t) {
const r = e._ownerReadableStream;
r._disturbed = !0, r._state === "closed" ? t._closeSteps() : r._state === "errored" ? t._errorSteps(r._storedError) : r._readableStreamController[Tt](t);
}
function fr(e, t) {
const r = e._readRequests;
e._readRequests = new A(), r.forEach((o) => {
o._errorSteps(t);
});
}
function We(e) {
return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`);
}
var it, at, st;
function Se(e) {
return e.slice();
}
function br(e, t, r, o, a) {
new Uint8Array(e).set(new Uint8Array(r, o, a), t);
}
Object.defineProperties(ee.prototype, { cancel: { enumerable: !0 }, read: { enumerable: !0 }, releaseLock: { enumerable: !0 }, closed: { enumerable: !0 } }), p(ee.prototype.cancel, "cancel"), p(ee.prototype.read, "read"), p(ee.prototype.releaseLock, "releaseLock"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(ee.prototype, Symbol.toStringTag, { value: "ReadableStreamDefaultReader", configurable: !0 });
let se = (e) => (se = typeof e.transfer == "function" ? (t) => t.transfer() : typeof structuredClone == "function" ? (t) => structuredClone(t, { transfer: [t] }) : (t) => t, se(e)), le = (e) => (le = typeof e.detached == "boolean" ? (t) => t.detached : (t) => t.byteLength === 0, le(e));
function hr(e, t, r) {
if (e.slice) return e.slice(t, r);
const o = r - t, a = new ArrayBuffer(o);
return br(a, 0, e, t, o), a;
}
function Te(e, t) {
const r = e[t];
if (r != null) {
if (typeof r != "function") throw new TypeError(`${String(t)} is not a function`);
return r;
}
}
function Vt(e) {
try {
const t = e.done, r = e.value;
return B(no(r), (o) => ({ done: t, value: o }));
} catch (t) {
return c(t);
}
}
const je = (st = (it = Symbol.asyncIterator) !== null && it !== void 0 ? it : (at = Symbol.for) === null || at === void 0 ? void 0 : at.call(Symbol, "Symbol.asyncIterator")) !== null && st !== void 0 ? st : "@@asyncIterator";
function _r(e, t = "sync", r) {
if (r === void 0) if (t === "async") {
if ((r = Te(e, je)) === void 0) return (function(a) {
const i = { next() {
let n;
try {
n = pr(a);
} catch (s) {
return c(s);
}
return Vt(n);
}, return(n) {
let s;
try {
const l = Te(a.iterator, "return");
if (l === void 0) return y({ done: !0, value: n });
s = me(l, a.iterator, [n]);
} catch (l) {
return c(l);
}
return R(s) ? Vt(s) : c(new TypeError("The iterator.return() method must return an object"));
} };
return { iterator: i, nextMethod: i.next, done: !1 };
})(_r(e, "sync", Te(e, Symbol.iterator)));
} else r = Te(e, Symbol.iterator);
if (r === void 0) throw new TypeError("The object is not iterable");
const o = me(r, e, []);
if (!R(o)) throw new TypeError("The iterator method must return an object");
return { iterator: o, nextMethod: o.next, done: !1 };
}
function pr(e) {
const t = me(e.nextMethod, e.iterator, []);
if (!R(t)) throw new TypeError("The iterator.next() method must return an object");
return t;
}
class mr {
constructor(t, r) {
this._ongoingPromise = void 0, this._isFinished = !1, this._reader = t, this._preventCancel = r;
}
next() {
const t = () => this._nextSteps();
return this._ongoingPromise = this._ongoingPromise ? ne(this._ongoingPromise, t, t) : t(), this._ongoingPromise;
}
return(t) {
const r = () => this._returnSteps(t);
return this._ongoingPromise = this._ongoingPromise ? ne(this._ongoingPromise, r, r) : r(), this._ongoingPromise;
}
_nextSteps() {
if (this._isFinished) return Promise.resolve({ value: void 0, done: !0 });
const t = this._reader;
let r, o;
const a = P((i, n) => {
r = i, o = n;
});
return Ce(t, { _chunkSteps: (i) => {
this._ongoingPromise = void 0, ie(() => r({ value: i, done: !1 }));
}, _closeSteps: () => {
this._ongoingPromise = void 0, this._isFinished = !0, L(t), r({ value: void 0, done: !0 });
}, _errorSteps: (i) => {
this._ongoingPromise = void 0, this._isFinished = !0, L(t), o(i);
} }), a;
}
_returnSteps(t) {
if (this._isFinished) return Promise.resolve({ value: t, done: !0 });
this._isFinished = !0;
const r = this._reader;
if (!this._preventCancel) {
const o = Et(r, t);
return L(r), ne(o, () => ({ value: t, done: !0 }));
}
return L(r), y({ value: t, done: !0 });
}
}
const yr = { next() {
return Ut(this) ? this._asyncIteratorImpl.next() : c(Ht("next"));
}, return(e) {
return Ut(this) ? this._asyncIteratorImpl.return(e) : c(Ht("return"));
}, [je]() {
return this;
} };
function Ut(e) {
if (!R(e) || !Object.prototype.hasOwnProperty.call(e, "_asyncIteratorImpl")) return !1;
try {
return e._asyncIteratorImpl instanceof mr;
} catch {
return !1;
}
}
function Ht(e) {
return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`);
}
Object.defineProperty(yr, je, { enumerable: !1 });
const vr = Number.isNaN || function(e) {
return e != e;
};
function Gt(e) {
const t = hr(e.buffer, e.byteOffset, e.byteOffset + e.byteLength);
return new Uint8Array(t);
}
function _t(e) {
const t = e._queue.shift();
return e._queueTotalSize -= t.size, e._queueTotalSize < 0 && (e._queueTotalSize = 0), t.value;
}
function jt(e, t, r) {
if (typeof (o = r) != "number" || vr(o) || o < 0 || r === 1 / 0) throw new RangeError("Size must be a finite, non-NaN, non-negative number.");
var o;
e._queue.push({ value: t, size: r }), e._queueTotalSize += r;
}
function J(e) {
e._queue = new A(), e._queueTotalSize = 0;
}
function wr(e) {
return e === DataView;
}
class be {
constructor() {
throw new TypeError("Illegal constructor");
}
get view() {
if (!lt(this)) throw ut("view");
return this._view;
}
respond(t) {
if (!lt(this)) throw ut("respond");
if (ae(t, 1, "respond"), t = Ct(t, "First parameter"), this._associatedReadableByteStreamController === void 0) throw new TypeError("This BYOB request has been invalidated");
if (le(this._view.buffer)) throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");
Ye(this._associatedReadableByteStreamController, t);
}
respondWithNewView(t) {
if (!lt(this)) throw ut("respondWithNewView");
if (ae(t, 1, "respondWithNewView"), !ArrayBuffer.isView(t)) throw new TypeError("You can only respond with array buffer views");
if (this._associatedReadableByteStreamController === void 0) throw new TypeError("This BYOB request has been invalidated");
if (le(t.buffer)) throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");
Ve(this._associatedReadableByteStreamController, t);
}
}
Object.defineProperties(be.prototype, { respond: { enumerable: !0 }, respondWithNewView: { enumerable: !0 }, view: { enumerable: !0 } }), p(be.prototype.respond, "respond"), p(be.prototype.respondWithNewView, "respondWithNewView"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(be.prototype, Symbol.toStringTag, { value: "ReadableStreamBYOBRequest", configurable: !0 });
class N {
constructor() {
throw new TypeError("Illegal constructor");
}
get byobRequest() {
if (!te(this)) throw Re("byobRequest");
return mt(this);
}
get desiredSize() {
if (!te(this)) throw Re("desiredSize");
return jr(this);
}
close() {
if (!te(this)) throw Re("close");
if (this._closeRequested) throw new TypeError("The stream has already been closed; do not close it again!");
const t = this._controlledReadableByteStream._state;
if (t !== "readable") throw new TypeError(`The stream (in ${t} state) is not in the readable state and cannot be closed`);
qe(this);
}
enqueue(t) {
if (!te(this)) throw Re("enqueue");
if (ae(t, 1, "enqueue"), !ArrayBuffer.isView(t)) throw new TypeError("chunk must be an array buffer view");
if (t.byteLength === 0) throw new TypeError("chunk must have non-zero byteLength");
if (t.buffer.byteLength === 0) throw new TypeError("chunk's buffer must have non-zero byteLength");
if (this._closeRequested) throw new TypeError("stream is closed or draining");
const r = this._controlledReadableByteStream._state;
if (r !== "readable") throw new TypeError(`The stream (in ${r} state) is not in the readable state and cannot be enqueued to`);
Ne(this, t);
}
error(t = void 0) {
if (!te(this)) throw Re("error");
O(this, t);
}
[Rt](t) {
gr(this), J(this);
const r = this._cancelAlgorithm(t);
return et(this), r;
}
[Tt](t) {
const r = this._controlledReadableByteStream;
if (this._queueTotalSize > 0) return void Ar(this, t);
const o = this._autoAllocateChunkSize;
if (o !== void 0) {
let a;
try {
a = new ArrayBuffer(o);
} catch (n) {
return void t._errorSteps(n);
}
const i = { buffer: a, bufferByteLength: o, byteOffset: 0, byteLength: o, bytesFilled: 0, minimumFill: 1, elementSize: 1, viewConstructor: Uint8Array, readerType: "default" };
this._pendingPullIntos.push(i);
}
cr(r, t), ue(this);
}
[qt]() {
if (this._pendingPullIntos.length > 0) {
const t = this._pendingPullIntos.peek();
t.readerType = "none", this._pendingPullIntos = new A(), this._pendingPullIntos.push(t);
}
}
}
function te(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_controlledReadableByteStream") && e instanceof N;
}
function lt(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_associatedReadableByteStreamController") && e instanceof be;
}
function ue(e) {
(function(r) {
const o = r._controlledReadableByteStream;
return o._state !== "readable" || r._closeRequested || !r._started ? !1 : dr(o) && Ze(o) > 0 || Wt(o) && Wr(o) > 0 ? !0 : jr(r) > 0;
})(e) && (e._pulling ? e._pullAgain = !0 : (e._pulling = !0, W(e._pullAlgorithm(), () => (e._pulling = !1, e._pullAgain && (e._pullAgain = !1, ue(e)), null), (r) => (O(e, r), null))));
}
function gr(e) {
kt(e), e._pendingPullIntos = new A();
}
function Sr(e, t) {
let r = !1;
e._state === "closed" && (r = !0);
const o = Rr(t);
t.readerType === "default" ? At(e, o, r) : (function(a, i, n) {
const s = a._reader._readIntoRequests.shift();
n ? s._closeSteps(i) : s._chunkSteps(i);
})(e, o, r);
}
function De(e, t) {
for (let r = 0; r < t.length; ++r) Sr(e, t[r]);
}
function Rr(e) {
const t = e.bytesFilled, r = e.elementSize;
return new e.viewConstructor(e.buffer, e.byteOffset, t / r);
}
function Me(e, t, r, o) {
e._queue.push({ buffer: t, byteOffset: r, byteLength: o }), e._queueTotalSize += o;
}
function Tr(e, t, r, o) {
let a;
try {
a = hr(t, r, r + o);
} catch (i) {
throw O(e, i), i;
}
Me(e, a, 0, o);
}
function qr(e, t) {
t.bytesFilled > 0 && Tr(e, t.buffer, t.byteOffset, t.bytesFilled), _e(e);
}
function Er(e, t) {
const r = Math.min(e._queueTotalSize, t.byteLength - t.bytesFilled), o = t.bytesFilled + r;
let a = r, i = !1;
const n = o - o % t.elementSize;
n >= t.minimumFill && (a = n - t.bytesFilled, i = !0);
const s = e._queue;
for (; a > 0; ) {
const l = s.peek(), u = Math.min(a, l.byteLength), f = t.byteOffset + t.bytesFilled;
br(t.buffer, f, l.buffer, l.byteOffset, u), l.byteLength === u ? s.shift() : (l.byteOffset += u, l.byteLength -= u), e._queueTotalSize -= u, Pr(e, u, t), a -= u;
}
return i;
}
function Pr(e, t, r) {
r.bytesFilled += t;
}
function Cr(e) {
e._queueTotalSize === 0 && e._closeRequested ? (et(e), ke(e._controlledReadableByteStream)) : ue(e);
}
function kt(e) {
e._byobRequest !== null && (e._byobRequest._associatedReadableByteStreamController = void 0, e._byobRequest._view = null, e._byobRequest = null);
}
function pt(e) {
const t = [];
for (; e._pendingPullIntos.length > 0 && e._queueTotalSize !== 0; ) {
const r = e._pendingPullIntos.peek();
Er(e, r) && (_e(e), t.push(r));
}
return t;
}
function Or(e, t) {
const r = e._pendingPullIntos.peek();
kt(e), e._controlledReadableByteStream._state === "closed" ? (function(o, a) {
a.readerType === "none" && _e(o);
const i = o._controlledReadableByteStream;
if (Wt(i)) {
const n = [];
for (; n.length < Wr(i); ) n.push(_e(o));
De(i, n);
}
})(e, r) : (function(o, a, i) {
if (Pr(0, a, i), i.readerType === "none") {
qr(o, i);
const l = pt(o);
return void De(o._controlledReadableByteStream, l);
}
if (i.bytesFilled < i.minimumFill) return;
_e(o);
const n = i.bytesFilled % i.elementSize;
if (n > 0) {
const l = i.byteOffset + i.bytesFilled;
Tr(o, i.buffer, l - n, n);
}
i.bytesFilled -= n;
const s = pt(o);
Sr(o._controlledReadableByteStream, i), De(o._controlledReadableByteStream, s);
})(e, t, r), ue(e);
}
function _e(e) {
return e._pendingPullIntos.shift();
}
function et(e) {
e._pullAlgorithm = void 0, e._cancelAlgorithm = void 0;
}
function qe(e) {
const t = e._controlledReadableByteStream;
if (!e._closeRequested && t._state === "readable") if (e._queueTotalSize > 0) e._closeRequested = !0;
else {
if (e._pendingPullIntos.length > 0) {
const r = e._pendingPullIntos.peek();
if (r.bytesFilled % r.elementSize !== 0) {
const o = new TypeError("Insufficient bytes to fill elements in the given buffer");
throw O(e, o), o;
}
}
et(e), ke(t);
}
}
function Ne(e, t) {
const r = e._controlledReadableByteStream;
if (e._closeRequested || r._state !== "readable") return;
const { buffer: o, byteOffset: a, byteLength: i } = t;
if (le(o)) throw new TypeError("chunk's buffer is detached and so cannot be enqueued");
const n = se(o);
if (e._pendingPullIntos.length > 0) {
const s = e._pendingPullIntos.peek();
if (le(s.buffer)) throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");
kt(e), s.buffer = se(s.buffer), s.readerType === "none" && qr(e, s);
}
dr(r) ? ((function(s) {
const l = s._controlledReadableByteStream._reader;
for (; l._readRequests.length > 0; ) {
if (s._queueTotalSize === 0) return;
Ar(s, l._readRequests.shift());
}
})(e), Ze(r) === 0 ? Me(e, n, a, i) : (e._pendingPullIntos.length > 0 && _e(e), At(r, new Uint8Array(n, a, i), !1))) : Wt(r) ? (Me(e, n, a, i), De(r, pt(e))) : Me(e, n, a, i), ue(e);
}
function O(e, t) {
const r = e._controlledReadableByteStream;
r._state === "readable" && (gr(e), J(e), et(e), Zr(r, t));
}
function Ar(e, t) {
const r = e._queue.shift();
e._queueTotalSize -= r.byteLength, Cr(e);
const o = new Uint8Array(r.buffer, r.byteOffset, r.byteLength);
t._chunkSteps(o);
}
function mt(e) {
if (e._byobRequest === null && e._pendingPullIntos.length > 0) {
const t = e._pendingPullIntos.peek(), r = new Uint8Array(t.buffer, t.byteOffset + t.bytesFilled, t.byteLength - t.bytesFilled), o = Object.create(be.prototype);
(function(a, i, n) {
a._associatedReadableByteStreamController = i, a._view = n;
})(o, e, r), e._byobRequest = o;
}
return e._byobRequest;
}
function jr(e) {
const t = e._controlledReadableByteStream._state;
return t === "errored" ? null : t === "closed" ? 0 : e._strategyHWM - e._queueTotalSize;
}
function Ye(e, t) {
const r = e._pendingPullIntos.peek();
if (e._controlledReadableByteStream._state === "closed") {
if (t !== 0) throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream");
} else {
if (t === 0) throw new TypeError("bytesWritten must be greater than 0 when calling respond() on a readable stream");
if (r.bytesFilled + t > r.byteLength) throw new RangeError("bytesWritten out of range");
}
r.buffer = se(r.buffer), Or(e, t);
}
function Ve(e, t) {
const r = e._pendingPullIntos.peek();
if (e._controlledReadableByteStream._state === "closed") {
if (t.byteLength !== 0) throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
} else if (t.byteLength === 0) throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");
if (r.byteOffset + r.bytesFilled !== t.byteOffset) throw new RangeError("The region specified by view does not match byobRequest");
if (r.bufferByteLength !== t.buffer.byteLength) throw new RangeError("The buffer of view has different capacity than byobRequest");
if (r.bytesFilled + t.byteLength > r.byteLength) throw new RangeError("The region specified by view is larger than byobRequest");
const o = t.byteLength;
r.buffer = se(t.buffer), Or(e, o);
}
function kr(e, t, r, o, a, i, n) {
t._controlledReadableByteStream = e, t._pullAgain = !1, t._pulling = !1, t._byobRequest = null, t._queue = t._queueTotalSize = void 0, J(t), t._closeRequested = !1, t._started = !1, t._strategyHWM = i, t._pullAlgorithm = o, t._cancelAlgorithm = a, t._autoAllocateChunkSize = n, t._pendingPullIntos = new A(), e._readableStreamController = t, W(y(r()), () => (t._started = !0, ue(t), null), (s) => (O(t, s), null));
}
function ut(e) {
return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`);
}
function Re(e) {
return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`);
}
function ao(e, t) {
if ((e = `${e}`) != "byob") throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamReaderMode`);
return e;
}
function Xt(e) {
return new re(e);
}
function Jt(e, t) {
e._reader._readIntoRequests.push(t);
}
function Wr(e) {
return e._reader._readIntoRequests.length;
}
function Wt(e) {
const t = e._reader;
return t !== void 0 && !!oe(t);
}
Object.defineProperties(N.prototype, { close: { enumerable: !0 }, enqueue: { enumerable: !0 }, error: { enumerable: !0 }, byobRequest: { enumerable: !0 }, desiredSize: { enumerable: !0 } }), p(N.prototype.close, "close"), p(N.prototype.enqueue, "enqueue"), p(N.prototype.error, "error"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(N.prototype, Symbol.toStringTag, { value: "ReadableByteStreamController", configurable: !0 });
class re {
constructor(t) {
if (ae(t, 1, "ReadableStreamBYOBReader"), Ot(t, "First parameter"), H(t)) throw new TypeError("This stream has already been locked for exclusive reading by another reader");
if (!te(t._readableStreamController)) throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");
ir(this, t), this._readIntoRequests = new A();
}
get closed() {
return oe(this) ? this._closedPromise : c(ze("closed"));
}
cancel(t = void 0) {
return oe(this) ? this._ownerReadableStream === void 0 ? c(He("cancel")) : Et(this, t) : c(ze("cancel"));
}
read(t, r = {}) {
if (!oe(this)) return c(ze("read"));
if (!ArrayBuffer.isView(t)) return c(new TypeError("view must be an array buffer view"));
if (t.byteLength === 0) return c(new TypeError("view must have non-zero byteLength"));
if (t.buffer.byteLength === 0) return c(new TypeError("view's buffer must have non-zero byteLength"));
if (le(t.buffer)) return c(new TypeError("view's buffer has been detached"));
let o;
try {
o = (function(l, u) {
var f;
return V(l, u), { min: Ct((f = l?.min) !== null && f !== void 0 ? f : 1, `${u} has member 'min' that`) };
})(r, "options");
} catch (l) {
return c(l);
}
const a = o.min;
if (a === 0) return c(new TypeError("options.min must be greater than 0"));
if ((function(l) {
return wr(l.constructor);
})(t)) {
if (a > t.byteLength) return c(new RangeError("options.min must be less than or equal to view's byteLength"));
} else if (a > t.length) return c(new RangeError("options.min must be less than or equal to view's length"));
if (this._ownerReadableStream === void 0) return c(He("read from"));
let i, n;
const s = P((l, u) => {
i = l, n = u;
});
return zr(this, t, a, { _chunkSteps: (l) => i({ value: l, done: !1 }), _closeSteps: (l) => i({ value: l, done: !0 }), _errorSteps: (l) => n(l) }), s;
}
releaseLock() {
if (!oe(this)) throw ze("releaseLock");
this._ownerReadableStream !== void 0 && (function(t) {
L(t), Br(t, new TypeError("Reader was released"));
})(this);
}
}
function oe(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_readIntoRequests") && e instanceof re;
}
function zr(e, t, r, o) {
const a = e._ownerReadableStream;
a._disturbed = !0, a._state === "errored" ? o._errorSteps(a._storedError) : (function(i, n, s, l) {
const u = i._controlledReadableByteStream, f = n.constructor, m = (function(g) {
return wr(g) ? 1 : g.BYTES_PER_ELEMENT;
})(f), { byteOffset: h, byteLength: v } = n, q = s * m;
let S;
try {
S = se(n.buffer);
} catch (g) {
return void l._errorSteps(g);
}
const b = { buffer: S, bufferByteLength: S.byteLength, byteOffset: h, byteLength: v, bytesFilled: 0, minimumFill: q, elementSize: m, viewConstructor: f, readerType: "byob" };
if (i._pendingPullIntos.length > 0) return i._pendingPullIntos.push(b), void Jt(u, l);
if (u._state === "closed") {
const g = new f(b.buffer, b.byteOffset, 0);
return void l._closeSteps(g);
}
if (i._queueTotalSize > 0) {
if (Er(i, b)) {
const g = Rr(b);
return Cr(i), void l._chunkSteps(g);
}
if (i._closeRequested) {
const g = new TypeError("Insufficient bytes to fill elements in the given buffer");
return O(i, g), void l._errorSteps(g);
}
}
i._pendingPullIntos.push(b), Jt(u, l), ue(i);
})(a._readableStreamController, t, r, o);
}
function Br(e, t) {
const r = e._readIntoRequests;
e._readIntoRequests = new A(), r.forEach((o) => {
o._errorSteps(t);
});
}
function ze(e) {
return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`);
}
function yt(e, t) {
const { highWaterMark: r } = e;
if (r === void 0) return t;
if (vr(r) || r < 0) throw new RangeError("Invalid highWaterMark");
return r;
}
function Fr(e) {
const { size: t } = e;
return t || (() => 1);
}
function Ir(e, t) {
V(e, t);
const r = e?.highWaterMark, o = e?.size;
return { highWaterMark: r === void 0 ? void 0 : ur(r), size: o === void 0 ? void 0 : so(o, `${t} has member 'size' that`) };
}
function so(e, t) {
return X(e, t), (r) => ur(e(r));
}
function lo(e, t, r) {
return X(e, r), (o) => ge(e, t, [o]);
}
function uo(e, t, r) {
return X(e, r), () => ge(e, t, []);
}
function co(e, t, r) {
return X(e, r), (o) => me(e, t, [o]);
}
function fo(e, t, r) {
return X(e, r), (o, a) => ge(e, t, [o, a]);
}
function Lr(e, t) {
if (!he(e)) throw new TypeError(`${t} is not a WritableStream.`);
}
Object.defineProperties(re.prototype, { cancel: { enumerable: !0 }, read: { enumerable: !0 }, releaseLock: { enumerable: !0 }, closed: { enumerable: !0 } }), p(re.prototype.cancel, "cancel"), p(re.prototype.read, "read"), p(re.prototype.releaseLock, "releaseLock"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(re.prototype, Symbol.toStringTag, { value: "ReadableStreamBYOBReader", configurable: !0 });
class de {
constructor(t = {}, r = {}) {
t === void 0 ? t = null : lr(t, "First parameter");
const o = Ir(r, "Second parameter"), a = (function(n, s) {
V(n, s);
const l = n?.abort, u = n?.close, f = n?.start, m = n?.type, h = n?.write;
return { abort: l === void 0 ? void 0 : lo(l, n, `${s} has member 'abort' that`), close: u === void 0 ? void 0 : uo(u, n, `${s} has member 'close' that`), start: f === void 0 ? void 0 : co(f, n, `${s} has member 'start' that`), write: h === void 0 ? void 0 : fo(h, n, `${s} has member 'write' that`), type: m };
})(t, "First parameter");
if ((function(n) {
n._state = "writable", n._storedError = void 0, n._writer = void 0, n._writableStreamController = void 0, n._writeRequests = new A(), n._inFlightWriteRequest = void 0, n._closeRequest = void 0, n._inFlightCloseRequest = void 0, n._pendingAbortRequest = void 0, n._backpressure = !1;
})(this), a.type !== void 0) throw new RangeError("Invalid type is specified");
const i = Fr(o);
(function(n, s, l, u) {
const f = Object.create(Xe.prototype);
let m, h, v, q;
m = s.start !== void 0 ? () => s.start(f) : () => {
}, h = s.write !== void 0 ? (S) => s.write(S, f) : () => y(void 0), v = s.close !== void 0 ? () => s.close() : () => y(void 0), q = s.abort !== void 0 ? (S) => s.abort(S) : () => y(void 0), (function(S, b, g, T, z, I, d, _) {
b._controlledWritableStream = S, S._writableStreamController = b, b._queue = void 0, b._queueTotalSize = void 0, J(b), b._abortReason = void 0, b._abortController = (function() {
if (typeof AbortController == "function") return new AbortController();
})(), b._started = !1, b._strategySizeAlgorithm = _, b._strategyHWM = d, b._writeAlgorithm = T, b._closeAlgorithm = z, b._abortAlgorithm = I;
const w = It(b);
Ft(S, w), W(y(g()), () => (b._started = !0, tt(b), null), (E) => (b._started = !0, vt(S, E), null));
})(n, f, m, h, v, q, l, u);
})(this, a, yt(o, 1), i);
}
get locked() {
if (!he(this)) throw Fe("locked");
return pe(this);
}
abort(t = void 0) {
return he(this) ? pe(this) ? c(new TypeError("Cannot abort a stream that already has a writer")) : Ge(this, t) : c(Fe("abort"));
}
close() {
return he(this) ? pe(this) ? c(new TypeError("Cannot close a stream that already has a writer")) : F(this) ? c(new TypeError("Cannot close an already-closing stream")) : xr(this) : c(Fe("close"));
}
getWriter() {
if (!he(this)) throw Fe("getWriter");
return $r(this);
}
}
function $r(e) {
return new M(e);
}
function he(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_writableStreamController") && e instanceof de;
}
function pe(e) {
return e._writer !== void 0;
}
function Ge(e, t) {
var r;
if (e._state === "closed" || e._state === "errored") return y(void 0);
e._writableStreamController._abortReason = t, (r = e._writableStreamController._abortController) === null || r === void 0 || r.abort(t);
const o = e._state;
if (o === "closed" || o === "errored") return y(void 0);
if (e._pendingAbortRequest !== void 0) return e._pendingAbortRequest._promise;
let a = !1;
o === "erroring" && (a = !0, t = void 0);
const i = P((n, s) => {
e._pendingAbortRequest = { _promise: void 0, _resolve: n, _reject: s, _reason: t, _wasAlreadyErroring: a };
});
return e._pendingAbortRequest._promise = i, a || zt(e, t), i;
}
function xr(e) {
const t = e._state;
if (t === "closed" || t === "errored") return c(new TypeError(`The stream (in ${t} state) is not in the writable state and cannot be closed`));
const r = P((i, n) => {
const s = { _resolve: i, _reject: n };
e._closeRequest = s;
}), o = e._writer;
var a;
return o !== void 0 && e._backpressure && t === "writable" && $t(o), jt(a = e._writableStreamController, Vr, 0), tt(a), r;
}
function vt(e, t) {
e._state !== "writable" ? Bt(e) : zt(e, t);
}
function zt(e, t) {
const r = e._writableStreamController;
e._state = "erroring", e._storedError = t;
const o = e._writer;
o !== void 0 && Mr(o, t), !(function(a) {
return a._inFlightWriteRequest !== void 0 || a._inFlightCloseRequest !== void 0;
})(e) && r._started && Bt(e);
}
function Bt(e) {
e._state = "errored", e._writableStreamController[nr]();
const t = e._storedError;
if (e._writeRequests.forEach((o) => {
o._reject(t);
}), e._writeRequests = new A(), e._pendingAbortRequest === void 0) return void Be(e);
const r = e._pendingAbortRequest;
if (e._pendingAbortRequest = void 0, r._wasAlreadyErroring) return r._reject(t), void Be(e);
W(e._writableStreamController[or](r._reason), () => (r._resolve(), Be(e), null), (o) => (r._reject(o), Be(e), null));
}
function F(e) {
return e._closeRequest !== void 0 || e._inFlightCloseRequest !== void 0;
}
function Be(e) {
e._closeRequest !== void 0 && (e._closeRequest._reject(e._storedError), e._closeRequest = void 0);
const t = e._writer;
t !== void 0 && Lt(t, e._storedError);
}
function Ft(e, t) {
const r = e._writer;
r !== void 0 && t !== e._backpressure && (t ? (function(o) {
rt(o);
})(r) : $t(r)), e._backpressure = t;
}
Object.defineProperties(de.prototype, { abort: { enumerable: !0 }, close: { enumerable: !0 }, getWriter: { enumerable: !0 }, locked: { enumerable: !0 } }), p(de.prototype.abort, "abort"), p(de.prototype.close, "close"), p(de.prototype.getWriter, "getWriter"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(de.prototype, Symbol.toStringTag, { value: "WritableStream", configurable: !0 });
class M {
constructor(t) {
if (ae(t, 1, "WritableStreamDefaultWriter"), Lr(t, "First parameter"), pe(t)) throw new TypeError("This stream has already been locked for exclusive writing by another writer");
this._ownerWritableStream = t, t._writer = this;
const r = t._state;
if (r === "writable") !F(t) && t._backpressure ? rt(this) : Kt(this), Ue(this);
else if (r === "erroring") gt(this, t._storedError), Ue(this);
else if (r === "closed") Kt(this), Ue(this), Xr(this);
else {
const o = t._storedError;
gt(this, o), Gr(this, o);
}
}
get closed() {
return K(this) ? this._closedPromise : c(Q("closed"));
}
get desiredSize() {
if (!K(this)) throw Q("desiredSize");
if (this._ownerWritableStream === void 0) throw Ee("desiredSize");
return (function(t) {
const r = t._ownerWritableStream, o = r._state;
return o === "errored" || o === "erroring" ? null : o === "closed" ? 0 : Ur(r._writableStreamController);
})(this);
}
get ready() {
return K(this) ? this._readyPromise : c(Q("ready"));
}
abort(t = void 0) {
return K(this) ? this._ownerWritableStream === void 0 ? c(Ee("abort")) : (function(r, o) {
return Ge(r._ownerWritableStream, o);
})(this, t) : c(Q("abort"));
}
close() {
if (!K(this)) return c(Q("close"));
const t = this._ownerWritableStream;
return t === void 0 ? c(Ee("close")) : F(t) ? c(new TypeError("Cannot close an already-closing stream")) : Dr(this);
}
releaseLock() {
if (!K(this)) throw Q("releaseLock");
this._ownerWritableStream !== void 0 && Nr(this);
}
write(t = void 0) {
return K(this) ? this._ownerWritableStream === void 0 ? c(Ee("write to")) : Yr(this, t) : c(Q("write"));
}
}
function K(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_ownerWritableStream") && e instanceof M;
}
function Dr(e) {
return xr(e._ownerWritableStream);
}
function Mr(e, t) {
e._readyPromiseState === "pending" ? Jr(e, t) : (function(r, o) {
gt(r, o);
})(e, t);
}
function Nr(e) {
const t = e._ownerWritableStream, r = new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");
Mr(e, r), (function(o, a) {
o._closedPromiseState === "pending" ? Lt(o, a) : (function(i, n) {
Gr(i, n);
})(o, a);
})(e, r), t._writer = void 0, e._ownerWritableStream = void 0;
}
function Yr(e, t) {
const r = e._ownerWritableStream, o = r._writableStreamController, a = (function(s, l) {
if (s._strategySizeAlgorithm === void 0) return 1;
try {
return s._strategySizeAlgorithm(l);
} catch (u) {
return wt(s, u), 1;
}
})(o, t);
if (r !== e._ownerWritableStream) return c(Ee("write to"));
const i = r._state;
if (i === "errored") return c(r._storedError);
if (F(r) || i === "closed") return c(new TypeError("The stream is closing or closed and cannot be written to"));
if (i === "erroring") return c(r._storedError);
const n = (function(s) {
return P((l, u) => {
const f = { _resolve: l, _reject: u };
s._writeRequests.push(f);
});
})(r);
return (function(s, l, u) {
try {
jt(s, l, u);
} catch (m) {
return void wt(s, m);
}
const f = s._controlledWritableStream;
F(f) || f._state !== "writable" || Ft(f, It(s)), tt(s);
})(o, t, a), n;
}
Object.defineProperties(M.prototype, { abort: { enumerable: !0 }, close: { enumerable: !0 }, releaseLock: { enumerable: !0 }, write: { enumerable: !0 }, closed: { enumerable: !0 }, desiredSize: { enumerable: !0 }, ready: { enumerable: !0 } }), p(M.prototype.abort, "abort"), p(M.prototype.close, "close"), p(M.prototype.releaseLock, "releaseLock"), p(M.prototype.write, "write"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(M.prototype, Symbol.toStringTag, { value: "WritableStreamDefaultWriter", configurable: !0 });
const Vr = {};
class Xe {
constructor() {
throw new TypeError("Illegal constructor");
}
get abortReason() {
if (!ct(this)) throw dt("abortReason");
return this._abortReason;
}
get signal() {
if (!ct(this)) throw dt("signal");
if (this._abortController === void 0) throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");
return this._abortController.signal;
}
error(t = void 0) {
if (!ct(this)) throw dt("error");
this._controlledWritableStream._state === "writable" && Hr(this, t);
}
[or](t) {
const r = this._abortAlgorithm(t);
return Je(this), r;
}
[nr]() {
J(this);
}
}
function ct(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_controlledWritableStream") && e instanceof Xe;
}
function Je(e) {
e._writeAlgorithm = void 0, e._closeAlgorithm = void 0, e._abortAlgorithm = void 0, e._strategySizeAlgorithm = void 0;
}
function Ur(e) {
return e._strategyHWM - e._queueTotalSize;
}
function tt(e) {
const t = e._controlledWritableStream;
if (!e._started || t._inFlightWriteRequest !== void 0) return;
if (t._state === "erroring") return void Bt(t);
if (e._queue.length === 0) return;
const r = e._queue.peek().value;
r === Vr ? (function(o) {
const a = o._controlledWritableStream;
(function(n) {
n._inFlightCloseRequest = n._closeRequest, n._closeRequest = void 0;
})(a), _t(o);
const i = o._closeAlgorithm();
Je(o), W(i, () => ((function(n) {
n._inFlightCloseRequest._resolve(void 0), n._inFlightCloseRequest = void 0, n._state === "erroring" && (n._storedError = void 0, n._pendingAbortRequest !== void 0 && (n._pendingAbortRequest._resolve(), n._pendingAbortRequest = void 0)), n._state = "closed";
const s = n._writer;
s !== void 0 && Xr(s);
})(a), null), (n) => ((function(s, l) {
s._inFlightCloseRequest._reject(l), s._inFlightCloseRequest = void 0, s._pendingAbortRequest !== void 0 && (s._pendingAbortRequest._reject(l), s._pendingAbortRequest = void 0), vt(s, l);
})(a, n), null));
})(e) : (function(o, a) {
const i = o._controlledWritableStream;
(function(n) {
n._inFlightWriteRequest = n._writeRequests.shift();
})(i), W(o._writeAlgorithm(a), () => {
(function(s) {
s._inFlightWriteRequest._resolve(void 0), s._inFlightWriteRequest = void 0;
})(i);
const n = i._state;
if (_t(o), !F(i) && n === "writable") {
const s = It(o);
Ft(i, s);
}
return tt(o), null;
}, (n) => (i._state === "writable" && Je(o), (function(s, l) {
s._inFlightWriteRequest._reject(l), s._inFlightWriteRequest = void 0, vt(s, l);
})(i, n), null));
})(e, r);
}
function wt(e, t) {
e._controlledWritableStream._state === "writable" && Hr(e, t);
}
function It(e) {
return Ur(e) <= 0;
}
function Hr(e, t) {
const r = e._controlledWritableStream;
Je(e), zt(r, t);
}
function Fe(e) {
return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`);
}
function dt(e) {
return new TypeError(`WritableStreamDefaultController.prototype.${e} can only be used on a WritableStreamDefaultController`);
}
function Q(e) {
return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`);
}
function Ee(e) {
return new TypeError("Cannot " + e + " a stream using a released writer");
}
function Ue(e) {
e._closedPromise = P((t, r) => {
e._closedPromise_resolve = t, e._closedPromise_reject = r, e._closedPromiseState = "pending";
});
}
function Gr(e, t) {
Ue(e), Lt(e, t);
}
function Lt(e, t) {
e._closedPromise_reject !== void 0 && (Ae(e._closedPromise), e._closedPromise_reject(t), e._closedPromise_resolve = void 0, e._closedPromise_reject = void 0, e._closedPromiseState = "rejected");
}
function Xr(e) {
e._closedPromise_resolve !== void 0 && (e._closedPromise_resolve(void 0), e._closedPromise_resolve = void 0, e._closedPromise_reject = void 0, e._closedPromiseState = "resolved");
}
function rt(e) {
e._readyPromise = P((t, r) => {
e._readyPromise_resolve = t, e._readyPromise_reject = r;
}), e._readyPromiseState = "pending";
}
function gt(e, t) {
rt(e), Jr(e, t);
}
function Kt(e) {
rt(e), $t(e);
}
function Jr(e, t) {
e._readyPromise_reject !== void 0 && (Ae(e._readyPromise), e._readyPromise_reject(t), e._readyPromise_resolve = void 0, e._readyPromise_reject = void 0, e._readyPromiseState = "rejected");
}
function $t(e) {
e._readyPromise_resolve !== void 0 && (e._readyPromise_resolve(void 0), e._readyPromise_resolve = void 0, e._readyPromise_reject = void 0, e._readyPromiseState = "fulfilled");
}
Object.defineProperties(Xe.prototype, { abortReason: { enumerable: !0 }, signal: { enumerable: !0 }, error: { enumerable: !0 } }), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(Xe.prototype, Symbol.toStringTag, { value: "WritableStreamDefaultController", configurable: !0 });
const Qt = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof global < "u" ? global : void 0, bo = (function() {
const e = Qt?.DOMException;
return (function(t) {
if (typeof t != "function" && typeof t != "object" || t.name !== "DOMException") return !1;
try {
return new t(), !0;
} catch {
return !1;
}
})(e) ? e : void 0;
})() || (function() {
const e = function(t, r) {
this.message = t || "", this.name = r || "Error", Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
};
return p(e, "DOMException"), e.prototype = Object.create(Error.prototype), Object.defineProperty(e.prototype, "constructor", { value: e, writable: !0, configurable: !0 }), e;
})();
function Zt(e, t, r, o, a, i) {
const n = ce(e), s = $r(t);
e._disturbed = !0;
let l = !1, u = y(void 0);
return P((f, m) => {
let h;
if (i !== void 0) {
if (h = () => {
const d = i.reason !== void 0 ? i.reason : new bo("Aborted", "AbortError"), _ = [];
o || _.push(() => t._state === "writable" ? Ge(t, d) : y(void 0)), a || _.push(() => e._state === "readable" ? k(e, d) : y(void 0)), T(() => Promise.all(_.map((w) => w())), !0, d);
}, i.aborted) return void h();
i.addEventListener("abort", h);
}
var v, q, S;
if (g(e, n._closedPromise, (d) => (o ? z(!0, d) : T(() => Ge(t, d), !0, d), null)), g(t, s._closedPromise, (d) => (a ? z(!0, d) : T(() => k(e, d), !0, d), null)), v = e, q = n._closedPromise, S = () => (r ? z() : T(() => (function(d) {
const _ = d._ownerWritableStream, w = _._state;
return F(_) || w === "closed" ? y(void 0) : w === "errored" ? c(_._storedError) : Dr(d);
})(s)), null), v._state === "closed" ? S() : nt(q, S), F(t) || t._state === "closed") {
const d = new TypeError("the destination writable stream closed before all data could be piped to it");
a ? z(!0, d) : T(() => k(e, d), !0, d);
}
function b() {
const d = u;
return B(u, () => d !== u ? b() : void 0);
}
function g(d, _, w) {
d._state === "errored" ? w(d._storedError) : bt(_, w);
}
function T(d, _, w) {
function E() {
return W(d(), () => I(_, w), (j) => I(!0, j)), null;
}
l || (l = !0, t._state !== "writable" || F(t) ? E() : nt(b(), E));
}
function z(d, _) {
l || (l = !0, t._state !== "writable" || F(t) ? I(d, _) : nt(b(), () => I(d, _)));
}
function I(d, _) {
return Nr(s), L(n), i !== void 0 && i.removeEventListener("abort", h), d ? m(_) : f(void 0), null;
}
Ae(P((d, _) => {
(function w(E) {
E ? d() : B(l ? y(!0) : B(s._readyPromise, () => P((j, $) => {
Ce(n, { _chunkSteps: (x) => {
u = B(Yr(s, x), void 0, Pe), j(!1);
}, _closeSteps: () => j(!0), _errorSteps: $ });
})), w, _);
})(!1);
}));
});
}
class Y {
constructor() {
throw new TypeError("Illegal constructor");
}
get desiredSize() {
if (!Ie(this)) throw Le("desiredSize");
return xt(this);
}
close() {
if (!Ie(this)) throw Le("close");
if (!we(this)) throw new TypeError("The stream is not in a state that permits close");
ye(this);
}
enqueue(t = void 0) {
if (!Ie(this)) throw Le("enqueue");
if (!we(this)) throw new TypeError("The stream is not in a state that permits enqueue");
return ve(this, t);
}
error(t = void 0) {
if (!Ie(this)) throw Le("error");
G(this, t);
}
[Rt](t) {
J(this);
const r = this._cancelAlgorithm(t);
return Ke(this), r;
}
[Tt](t) {
const r = this._controlledReadableStream;
if (this._queue.length > 0) {
const o = _t(this);
this._closeRequested && this._queue.length === 0 ? (Ke(this), ke(r)) : Oe(this), t._chunkSteps(o);
} else cr(r, t), Oe(this);
}
[qt]() {
}
}
function Ie(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_controlledReadableStream") && e instanceof Y;
}
function Oe(e) {
Kr(e) && (e._pulling ? e._pullAgain = !0 : (e._pulling = !0, W(e._pullAlgorithm(), () => (e._pulling = !1, e._pullAgain && (e._pullAgain = !1, Oe(e)), null), (t) => (G(e, t), null))));
}
function Kr(e) {
const t = e._controlledReadableStream;
return !!we(e) && !!e._started && (!!(H(t) && Ze(t) > 0) || xt(e) > 0);
}
function Ke(e) {
e._pullAlgorithm = void 0, e._cancelAlgorithm = void 0, e._strategySizeAlgorithm = void 0;
}
function ye(e) {
if (!we(e)) return;
const t = e._controlledReadableStream;
e._closeRequested = !0, e._queue.length === 0 && (Ke(e), ke(t));
}
function ve(e, t) {
if (!we(e)) return;
const r = e._controlledReadableStream;
if (H(r) && Ze(r) > 0) At(r, t, !1);
else {
let o;
try {
o = e._strategySizeAlgorithm(t);
} catch (a) {
throw G(e, a), a;
}
try {
jt(e, t, o);
} catch (a) {
throw G(e, a), a;
}
}
Oe(e);
}
function G(e, t) {
const r = e._controlledReadableStream;
r._state === "readable" && (J(e), Ke(e), Zr(r, t));
}
function xt(e) {
const t = e._controlledReadableStream._state;
return t === "errored" ? null : t === "closed" ? 0 : e._strategyHWM - e._queueTotalSize;
}
function we(e) {
const t = e._controlledReadableStream._state;
return !e._closeRequested && t === "readable";
}
function Qr(e, t, r, o, a, i, n) {
t._controlledReadableStream = e, t._queue = void 0, t._queueTotalSize = void 0, J(t), t._started = !1, t._closeRequested = !1, t._pullAgain = !1, t._pulling = !1, t._strategySizeAlgorithm = n, t._strategyHWM = i, t._pullAlgorithm = o, t._cancelAlgorithm = a, e._readableStreamController = t, W(y(r()), () => (t._started = !0, Oe(t), null), (s) => (G(t, s), null));
}
function Le(e) {
return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`);
}
function ho(e) {
return R(t = e) && t.getReader !== void 0 ? (function(r) {
let o;
return o = Qe(Pe, function() {
let a;
try {
a = r.read();
} catch (i) {
return c(i);
}
return ne(a, (i) => {
if (!R(i)) throw new TypeError("The promise returned by the reader.read() method must fulfill with an object");
if (i.done) ye(o._readableStreamController);
else {
const n = i.value;
ve(o._readableStreamController, n);
}
});
}, function(a) {
try {
return y(r.cancel(a));
} catch (i) {
return c(i);
}
}, 0), o;
})(e.getReader()) : (function(r) {
let o;
const a = _r(r, "async");
return o = Qe(Pe, function() {
let i;
try {
i = pr(a);
} catch (n) {
return c(n);
}
return ne(y(i), (n) => {
if (!R(n)) throw new TypeError("The promise returned by the iterator.next() method must fulfill with an object");
if (n.done) ye(o._readableStreamController);
else {
const s = n.value;
ve(o._readableStreamController, s);
}
});
}, function(i) {
const n = a.iterator;
let s;
try {
s = Te(n, "return");
} catch (l) {
return c(l);
}
return s === void 0 ? y(void 0) : ne(ge(s, n, [i]), (l) => {
if (!R(l)) throw new TypeError("The promise returned by the iterator.return() method must fulfill with an object");
});
}, 0), o;
})(e);
var t;
}
function _o(e, t, r) {
return X(e, r), (o) => ge(e, t, [o]);
}
function po(e, t, r) {
return X(e, r), (o) => ge(e, t, [o]);
}
function mo(e, t, r) {
return X(e, r), (o) => me(e, t, [o]);
}
function yo(e, t) {
if ((e = `${e}`) != "bytes") throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamType`);
return e;
}
function er(e, t) {
V(e, t);
const r = e?.preventAbort, o = e?.preventCancel, a = e?.preventClose, i = e?.signal;
return i !== void 0 && (function(n, s) {
if (!(function(l) {
if (typeof l != "object" || l === null) return !1;
try {
return typeof l.aborted == "boolean";
} catch {
return !1;
}
})(n)) throw new TypeError(`${s} is not an AbortSignal.`);
})(i, `${t} has member 'signal' that`), { preventAbort: !!r, preventCancel: !!o, preventClose: !!a, signal: i };
}
Object.defineProperties(Y.prototype, { close: { enumerable: !0 }, enqueue: { enumerable: !0 }, error: { enumerable: !0 }, desiredSize: { enumerable: !0 } }), p(Y.prototype.close, "close"), p(Y.prototype.enqueue, "enqueue"), p(Y.prototype.error, "error"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(Y.prototype, Symbol.toStringTag, { value: "ReadableStreamDefaultController", configurable: !0 });
class C {
constructor(t = {}, r = {}) {
t === void 0 ? t = null : lr(t, "First parameter");
const o = Ir(r, "Second parameter"), a = (function(i, n) {
V(i, n);
const s = i, l = s?.autoAllocateChunkSize, u = s?.cancel, f = s?.pull, m = s?.start, h = s?.type;
return { autoAllocateChunkSize: l === void 0 ? void 0 : Ct(l, `${n} has member 'autoAllocateChunkSize' that`), cancel: u === void 0 ? void 0 : _o(u, s, `${n} has member 'cancel' that`), pull: f === void 0 ? void 0 : po(f, s, `${n} has member 'pull' that`), start: m === void 0 ? void 0 : mo(m, s, `${n} has member 'start' that`), type: h === void 0 ? void 0 : yo(h, `${n} has member 'type' that`) };
})(t, "First parameter");
if (Dt(this), a.type === "bytes") {
if (o.size !== void 0) throw new RangeError("The strategy for a byte stream cannot have a size function");
(function(i, n, s) {
const l = Object.create(N.prototype);
let u, f, m;
u = n.start !== void 0 ? () => n.start(l) : () => {
}, f = n.pull !== void 0 ? () => n.pull(l) : () => y(void 0), m = n.cancel !== void 0 ? (v) => n.cancel(v) : () => y(void 0);
const h = n.autoAllocateChunkSize;
if (h === 0) throw new TypeError("autoAllocateChunkSize must be greater than 0");
kr(i, l, u, f, m, s, h);
})(this, a, yt(o, 0));
} else {
const i = Fr(o);
(function(n, s, l, u) {
const f = Object.create(Y.prototype);
let m, h, v;
m = s.start !== void 0 ? () => s.start(f) : () => {
}, h = s.pull !== void 0 ? () => s.pull(f) : () => y(void 0), v = s.cancel !== void 0 ? (q) => s.cancel(q) : () => y(void 0), Qr(n, f, m, h, v, l, u);
})(this, a, yt(o, 1), i);
}
}
get locked() {
if (!D(this)) throw Z("locked");
return H(this);
}
cancel(t = void 0) {
return D(this) ? H(this) ? c(new TypeError("Cannot cancel a stream that already has a reader")) : k(this, t) : c(Z("cancel"));
}
getReader(t = void 0) {
if (!D(this)) throw Z("getReader");
return (function(r, o) {
V(r, o);
const a = r?.mode;
return { mode: a === void 0 ? void 0 : ao(a, `${o} has member 'mode' that`) };
})(t, "First parameter").mode === void 0 ? ce(this) : Xt(this);
}
pipeThrough(t, r = {}) {
if (!D(this)) throw Z("pipeThrough");
ae(t, 1, "pipeThrough");
const o = (function(i, n) {
V(i, n);
const s = i?.readable;
Nt(s, "readable", "ReadableWritablePair"), Ot(s, `${n} has member 'readable' that`);
const l = i?.writable;
return Nt(l, "writable", "ReadableWritablePair"), Lr(l, `${n} has member 'writable' that`), { readable: s, writable: l };
})(t, "First parameter"), a = er(r, "Second parameter");
if (H(this)) throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");
if (pe(o.writable)) throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");
return Ae(Zt(this, o.writable, a.preventClose, a.preventAbort, a.preventCancel, a.signal)), o.readable;
}
pipeTo(t, r = {}) {
if (!D(this)) return c(Z("pipeTo"));
if (t === void 0) return c("Parameter 1 is required in 'pipeTo'.");
if (!he(t)) return c(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));
let o;
try {
o = er(r, "Second parameter");
} catch (a) {
return c(a);
}
return H(this) ? c(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")) : pe(t) ? c(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")) : Zt(this, t, o.preventClose, o.preventAbort, o.preventCancel, o.signal);
}
tee() {
if (!D(this)) throw Z("tee");
return Se((function(t) {
return te(t._readableStreamController) ? (function(r) {
let o, a, i, n, s, l = ce(r), u = !1, f = !1, m = !1, h = !1, v = !1;
const q = P((d) => {
s = d;
});
function S(d) {
bt(d._closedPromise, (_) => (d !== l || (O(i._readableStreamController, _), O(n._readableStreamController, _), h && v || s(void 0)), null));
}
function b() {
oe(l) && (L(l), l = ce(r), S(l)), Ce(l, { _chunkSteps: (d) => {
ie(() => {
f = !1, m = !1;
const _ = d;
let w = d;
if (!h && !v) try {
w = Gt(d);
} catch (E) {
return O(i._readableStreamController, E), O(n._readableStreamController, E), void s(k(r, E));
}
h || Ne(i._readableStreamController, _), v || Ne(n._readableStreamController, w), u = !1, f ? T() : m && z();
});
}, _closeSteps: () => {
u = !1, h || qe(i._readableStreamController), v || qe(n._readableStreamController), i._readableStreamController._pendingPullIntos.length > 0 && Ye(i._readableStreamController, 0), n._readableStreamController._pendingPullIntos.length > 0 && Ye(n._readableStreamController, 0), h && v || s(void 0);
}, _errorSteps: () => {
u = !1;
} });
}
function g(d, _) {
U(l) && (L(l), l = Xt(r), S(l));
const w = _ ? n : i, E = _ ? i : n;
zr(l, d, 1, { _chunkSteps: (j) => {
ie(() => {
f = !1, m = !1;
const $ = _ ? v : h;
if (_ ? h : v) $ || Ve(w._readableStreamController, j);
else {
let x;
try {
x = Gt(j);
} catch (ot) {
return O(w._readableStreamController, ot), O(E._readableStreamController, ot), void s(k(r, ot));
}
$ || Ve(w._readableStreamController, j), Ne(E._readableStreamController, x);
}
u = !1, f ? T() : m && z();
});
}, _closeSteps: (j) => {
u = !1;
const $ = _ ? v : h, x = _ ? h : v;
$ || qe(w._readableStreamController), x || qe(E._readableStreamController), j !== void 0 && ($ || Ve(w._readableStreamController, j), !x && E._readableStreamController._pendingPullIntos.length > 0 && Ye(E._readableStreamController, 0)), $ && x || s(void 0);
}, _errorSteps: () => {
u = !1;
} });
}
function T() {
if (u) return f = !0, y(void 0);
u = !0;
const d = mt(i._readableStreamController);
return d === null ? b() : g(d._view, !1), y(void 0);
}
function z() {
if (u) return m = !0, y(void 0);
u = !0;
const d = mt(n._readableStreamController);
return d === null ? b() : g(d._view, !0), y(void 0);
}
function I() {
}
return i = tr(I, T, function(d) {
if (h = !0, o = d, v) {
const _ = Se([o, a]), w = k(r, _);
s(w);
}
return q;
}), n = tr(I, z, function(d) {
if (v = !0, a = d, h) {
const _ = Se([o, a]), w = k(r, _);
s(w);
}
return q;
}), S(l), [i, n];
})(t) : (function(r) {
const o = ce(r);
let a, i, n, s, l, u = !1, f = !1, m = !1, h = !1;
const v = P((b) => {
l = b;
});
function q() {
return u ? (f = !0, y(void 0)) : (u = !0, Ce(o, { _chunkSteps: (b) => {
ie(() => {
f = !1;
const g = b, T = b;
m || ve(n._readableStreamController, g), h || ve(s._readableStreamController, T), u = !1, f && q();
});
}, _closeSteps: () => {
u = !1, m || ye(n._readableStreamController), h || ye(s._readableStreamController), m && h || l(void 0);
}, _errorSteps: () => {
u = !1;
} }), y(void 0));
}
function S() {
}
return n = Qe(S, q, function(b) {
if (m = !0, a = b, h) {
const g = Se([a, i]), T = k(r, g);
l(T);
}
return v;
}), s = Qe(S, q, function(b) {
if (h = !0, i = b, m) {
const g = Se([a, i]), T = k(r, g);
l(T);
}
return v;
}), bt(o._closedPromise, (b) => (G(n._readableStreamController, b), G(s._readableStreamController, b), m && h || l(void 0), null)), [n, s];
})(t);
})(this));
}
values(t = void 0) {
if (!D(this)) throw Z("values");
return (function(r, o) {
const a = ce(r), i = new mr(a, o), n = Object.create(yr);
return n._asyncIteratorImpl = i, n;
})(this, (function(r) {
return V(r, "First parameter"), { preventCancel: !!r?.preventCancel };
})(t).preventCancel);
}
[je](t) {
return this.values(t);
}
static from(t) {
return ho(t);
}
}
function Qe(e, t, r, o = 1, a = () => 1) {
const i = Object.create(C.prototype);
return Dt(i), Qr(i, Object.create(Y.prototype), e, t, r, o, a), i;
}
function tr(e, t, r) {
const o = Object.create(C.prototype);
return Dt(o), kr(o, Object.create(N.prototype), e, t, r, 0, void 0), o;
}
function Dt(e) {
e._state = "readable", e._reader = void 0, e._storedError = void 0, e._disturbed = !1;
}
function D(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_readableStreamController") && e instanceof C;
}
function H(e) {
return e._reader !== void 0;
}
function k(e, t) {
if (e._disturbed = !0, e._state === "closed") return y(void 0);
if (e._state === "errored") return c(e._storedError);
ke(e);
const r = e._reader;
if (r !== void 0 && oe(r)) {
const o = r._readIntoRequests;
r._readIntoRequests = new A(), o.forEach((a) => {
a._closeSteps(void 0);
});
}
return ne(e._readableStreamController[Rt](t), Pe);
}
function ke(e) {
e._state = "closed";
const t = e._reader;
if (t !== void 0 && (sr(t), U(t))) {
const r = t._readRequests;
t._readRequests = new A(), r.forEach((o) => {
o._closeSteps();
});
}
}
function Zr(e, t) {
e._state = "errored", e._storedError = t;
const r = e._reader;
r !== void 0 && (Pt(r, t), U(r) ? fr(r, t) : Br(r, t));
}
function Z(e) {
return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`);
}
Object.defineProperties(C, { from: { enumerable: !0 } }), Object.defineProperties(C.prototype, { cancel: { enumerable: !0 }, getReader: { enumerable: !0 }, pipeThrough: { enumerable: !0 }, pipeTo: { enumerable: !0 }, tee: { enumerable: !0 }, values: { enumerable: !0 }, locked: { enumerable: !0 } }), p(C.from, "from"), p(C.prototype.cancel, "cancel"), p(C.prototype.getReader, "getReader"), p(C.prototype.pipeThrough, "pipeThrough"), p(C.prototype.pipeTo, "pipeTo"), p(C.prototype.tee, "tee"), p(C.prototype.values, "values"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(C.prototype, Symbol.toStringTag, { value: "ReadableStream", configurable: !0 }), Object.defineProperty(C.prototype, je, { value: C.prototype.values, writable: !0, configurable: !0 });
p((e) => e.byteLength, "size");
function ft(e, t) {
(function(r) {
r._transformAlgorithm = void 0, r._flushAlgorithm = void 0, r._cancelAlgorithm = void 0;
})(e._transformStreamController), wt(e._writable._writableStreamController, t), (function(r) {
r._backpressure && eo(r, !1);
})(e);
}
function eo(e, t) {
e._backpressureChangePromise !== void 0 && e._backpressureChangePromise_resolve(), e._backpressureChangePromise = P((r) => {
e._backpressureChangePromise_resolve = r;
}), e._backpressure = t;
}
p(() => 1, "size");
class fe {
constructor() {
throw new TypeError("Illegal constructor");
}
get desiredSize() {
if (!$e(this)) throw xe("desiredSize");
return xt(this._controlledTransformStream._readable._readableStreamController);
}
enqueue(t = void 0) {
if (!$e(this)) throw xe("enqueue");
(function(r, o) {
const a = r._controlledTransformStream, i = a._readable._readableStreamController;
if (!we(i)) throw new TypeError("Readable side is not in a state that permits enqueue");
try {
ve(i, o);
} catch (s) {
throw ft(a, s), a._readable._storedError;
}
(function(s) {
return !Kr(s);
})(i) !== a._backpressure && eo(a, !0);
})(this, t);
}
error(t = void 0) {
if (!$e(this)) throw xe("error");
var r;
r = t, (function(o, a) {
G(o._readable._readableStreamController, a), ft(o, a);
})(this._controlledTransformStream, r);
}
terminate() {
if (!$e(this)) throw xe("terminate");
(function(t) {
const r = t._controlledTransformStream;
ye(r._readable._readableStreamController), ft(r, new TypeError("TransformStream terminated"));
})(this);
}
}
function $e(e) {
return !!R(e) && !!Object.prototype.hasOwnProperty.call(e, "_controlledTransformStream") && e instanceof fe;
}
function xe(e) {
return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`);
}
Object.defineProperties(fe.prototype, { enqueue: { enumerable: !0 }, error: { enumerable: !0 }, terminate: { enumerable: !0 }, desiredSize: { enumerable: !0 } }), p(fe.prototype.enqueue, "enqueue"), p(fe.prototype.error, "error"), p(fe.prototype.terminate, "terminate"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(fe.prototype, Symbol.toStringTag, { value: "TransformStreamDefaultController", configurable: !0 });
export {
N as ReadableByteStreamController,
C as ReadableStream,
re as ReadableStreamBYOBReader,
be as ReadableStreamBYOBRequest,
Y as ReadableStreamDefaultController,
ee as ReadableStreamDefaultReader,
fe as TransformStreamDefaultController,
de as WritableStream,
Xe as WritableStreamDefaultController,
M as WritableStreamDefaultWriter
};