@stardazed/streams-polyfill
Advanced tools
Comparing version 1.0.4 to 1.0.5
# @stardazed/streams-polyfill changelog | ||
## 1.0.5 | ||
_2018-09-17_ | ||
* Add TextEncoderStream and TextDecoderStream polyfills | ||
## 1.0.4 | ||
@@ -4,0 +8,0 @@ _2018-09-10_ |
/** | ||
* @stardazed/streams-polyfill - drop-in polyfill for Web Streams with fetch integration | ||
* @stardazed/streams-polyfill - drop-in polyfill for Web Streams with fetch and encoding integration | ||
* Part of Stardazed | ||
* (c) 2018 by Arthur Langereis - @zenmumbler | ||
* https://github.com/stardazed/sd-streams-fetch-adapter | ||
* https://github.com/stardazed/sd-streams | ||
*/ | ||
!function(){"use strict";const state_=Symbol("state_"),storedError_=Symbol("storedError_");function isInteger(e){if(!isFinite(e))return!1;const r=Math.abs(e);return Math.floor(r)===r}function isFiniteNonNegativeNumber(e){return!("number"!=typeof e||!isFinite(e))&&e>=0}function invokeOrNoop(e,r,t){const a=e[r];if(void 0!==a)return Function.prototype.apply.call(a,e,t)}function cloneArrayBuffer(e,r,t,a){return e.slice(r,r+t)}function transferArrayBuffer(e){return e.slice(0)}function copyDataBlockBytes(e,r,t,a,o){new Uint8Array(e,r,o).set(new Uint8Array(t,a,o))}function promiseCall(e,r,t){try{const a=Function.prototype.apply.call(e,r,t);return Promise.resolve(a)}catch(e){return Promise.reject(e)}}function createAlgorithmFromUnderlyingMethod(e,r,t){const a=e[r];if(void 0===a)return()=>Promise.resolve(void 0);if("function"!=typeof a)throw new TypeError(`Field "${r}" is not a function.`);return function(...r){return promiseCall(a,e,r.concat(t))}}function validateAndNormalizeHighWaterMark(e){const r=Number(e);if(isNaN(r)||r<0)throw new RangeError("highWaterMark must be a valid, non-negative integer.");return r}function makeSizeAlgorithmFromSizeFunction(e){if("function"!=typeof e&&void 0!==e)throw new TypeError("size function must be undefined or a function");return function(r){return"function"==typeof e?e(r):1}}var ControlledPromiseState;function createControlledPromise(){const e={state:ControlledPromiseState.Pending};return e.promise=new Promise(function(r,t){e.resolve=function(t){e.state=ControlledPromiseState.Resolved,r(t)},e.reject=function(r){e.state=ControlledPromiseState.Rejected,t(r)}}),e}!function(e){e[e.Pending=0]="Pending",e[e.Resolved=1]="Resolved",e[e.Rejected=2]="Rejected"}(ControlledPromiseState||(ControlledPromiseState={}));const CHUNK_SIZE=16384;class QueueImpl{constructor(){this.chunks_=[[]],this.readChunk_=this.writeChunk_=this.chunks_[0],this.length_=0}push(e){this.writeChunk_.push(e),this.length_+=1,this.writeChunk_.length===CHUNK_SIZE&&(this.writeChunk_=[],this.chunks_.push(this.writeChunk_))}front(){if(0!==this.length_)return this.readChunk_[0]}shift(){if(0===this.length_)return;const e=this.readChunk_.shift();return this.length_-=1,0===this.readChunk_.length&&this.readChunk_!==this.writeChunk_&&(this.chunks_.shift(),this.readChunk_=this.chunks_[0]),e}get length(){return this.length_}}const queue_=Symbol("queue_"),queueTotalSize_=Symbol("queueTotalSize_");function dequeueValue(e){const r=e[queue_].shift(),t=e[queueTotalSize_]-r.size;return e[queueTotalSize_]=Math.max(0,t),r.value}function enqueueValueWithSize(e,r,t){if(!isFiniteNonNegativeNumber(t))throw new RangeError("Chunk size must be a non-negative, finite numbers");e[queue_].push({value:r,size:t}),e[queueTotalSize_]+=t}function peekQueueValue(e){return e[queue_].front().value}function resetQueue(e){e[queue_]=new QueueImpl,e[queueTotalSize_]=0}const controlledReadableStream_=Symbol("controlledReadableStream_"),pullAlgorithm_=Symbol("pullAlgorithm_"),cancelAlgorithm_=Symbol("cancelAlgorithm_"),strategySizeAlgorithm_=Symbol("strategySizeAlgorithm_"),strategyHWM_=Symbol("strategyHWM_"),started_=Symbol("started_"),closeRequested_=Symbol("closeRequested_"),pullAgain_=Symbol("pullAgain_"),pulling_=Symbol("pulling_"),cancelSteps_=Symbol("cancelSteps_"),pullSteps_=Symbol("pullSteps_"),autoAllocateChunkSize_=Symbol("autoAllocateChunkSize_"),byobRequest_=Symbol("byobRequest_"),controlledReadableByteStream_=Symbol("controlledReadableByteStream_"),pendingPullIntos_=Symbol("pendingPullIntos_"),closedPromise_=Symbol("closedPromise_"),ownerReadableStream_=Symbol("ownerReadableStream_"),readRequests_=Symbol("readRequests_"),readIntoRequests_=Symbol("readIntoRequests_"),associatedReadableByteStreamController_=Symbol("associatedReadableByteStreamController_"),view_=Symbol("view_"),reader_=Symbol("reader_"),readableStreamController_=Symbol("readableStreamController_");function initializeReadableStream(e){e[state_]="readable",e[reader_]=void 0,e[storedError_]=void 0,e[readableStreamController_]=void 0}function isReadableStream(e){return null!=e&&"object"==typeof e&&readableStreamController_ in e}function isReadableStreamLocked(e){return void 0!==e[reader_]}function readableStreamGetNumReadIntoRequests(e){const r=e[reader_];return void 0===r?0:r[readIntoRequests_].length}function readableStreamGetNumReadRequests(e){const r=e[reader_];return void 0===r?0:r[readRequests_].length}function readableStreamCreateReadResult(e,r,t){const a=t?Object.prototype:null,o=Object.create(a);return o.value=e,o.done=r,o}function readableStreamAddReadIntoRequest(e,r){const t=e[reader_],a=createControlledPromise();return a.forAuthorCode=r,t[readIntoRequests_].push(a),a.promise}function readableStreamAddReadRequest(e,r){const t=e[reader_],a=createControlledPromise();return a.forAuthorCode=r,t[readRequests_].push(a),a.promise}function readableStreamHasBYOBReader(e){return isReadableStreamBYOBReader(e[reader_])}function readableStreamHasDefaultReader(e){return isReadableStreamDefaultReader(e[reader_])}function readableStreamCancel(e,r){if("closed"===e[state_])return Promise.resolve(void 0);if("errored"===e[state_])return Promise.reject(e[storedError_]);return readableStreamClose(e),e[readableStreamController_][cancelSteps_](r).then(e=>void 0)}function readableStreamClose(e){e[state_]="closed";const r=e[reader_];if(void 0!==r){if(isReadableStreamDefaultReader(r)){for(const e of r[readRequests_])e.resolve(readableStreamCreateReadResult(void 0,!0,e.forAuthorCode));r[readRequests_]=[]}r[closedPromise_].resolve(),r[closedPromise_].promise.catch(()=>{})}}function readableStreamError(e,r){if("readable"!==e[state_])throw new RangeError("Stream is in an invalid state");e[state_]="errored",e[storedError_]=r;const t=e[reader_];if(void 0!==t){if(isReadableStreamDefaultReader(t)){for(const e of t[readRequests_])e.reject(r);t[readRequests_]=[]}else{const e=t[readIntoRequests_];for(const t of e)t.reject(r);t[readIntoRequests_]=[]}t[closedPromise_].reject(r)}}function isReadableStreamDefaultReader(e){return null!=e&&"object"==typeof e&&readRequests_ in e}function isReadableStreamBYOBReader(e){return null!=e&&"object"==typeof e&&readIntoRequests_ in e}function readableStreamReaderGenericInitialize(e,r){e[ownerReadableStream_]=r,r[reader_]=e;const t=r[state_];e[closedPromise_]=createControlledPromise(),"readable"===t||("closed"===t?e[closedPromise_].resolve(void 0):(e[closedPromise_].reject(r[storedError_]),e[closedPromise_].promise.catch(()=>{})))}function readableStreamReaderGenericRelease(e){const r=e[ownerReadableStream_];if(void 0===r)throw new TypeError("Reader is in an inconsistent state");"readable"===r[state_]||(e[closedPromise_]=createControlledPromise()),e[closedPromise_].reject(new TypeError),e[closedPromise_].promise.catch(()=>{}),r[reader_]=void 0,e[ownerReadableStream_]=void 0}function readableStreamBYOBReaderRead(e,r,t=!1){const a=e[ownerReadableStream_];return"errored"===a[state_]?Promise.reject(a[storedError_]):readableByteStreamControllerPullInto(a[readableStreamController_],r,t)}function readableStreamDefaultReaderRead(e,r=!1){const t=e[ownerReadableStream_];return"closed"===t[state_]?Promise.resolve(readableStreamCreateReadResult(void 0,!0,r)):"errored"===t[state_]?Promise.reject(t[storedError_]):t[readableStreamController_][pullSteps_](r)}function readableStreamFulfillReadIntoRequest(e,r,t){const a=e[reader_][readIntoRequests_].shift();a.resolve(readableStreamCreateReadResult(r,t,a.forAuthorCode))}function readableStreamFulfillReadRequest(e,r,t){const a=e[reader_][readRequests_].shift();a.resolve(readableStreamCreateReadResult(r,t,a.forAuthorCode))}function setUpReadableStreamDefaultController(e,r,t,a,o,l,n){r[controlledReadableStream_]=e,resetQueue(r),r[started_]=!1,r[closeRequested_]=!1,r[pullAgain_]=!1,r[pulling_]=!1,r[strategySizeAlgorithm_]=n,r[strategyHWM_]=l,r[pullAlgorithm_]=a,r[cancelAlgorithm_]=o,e[readableStreamController_]=r;const i=t();Promise.resolve(i).then(e=>{r[started_]=!0,readableStreamDefaultControllerCallPullIfNeeded(r)},e=>{readableStreamDefaultControllerError(r,e)})}function isReadableStreamDefaultController(e){return null!=e&&"object"==typeof e&&controlledReadableStream_ in e}function readableStreamDefaultControllerHasBackpressure(e){return!readableStreamDefaultControllerShouldCallPull(e)}function readableStreamDefaultControllerCanCloseOrEnqueue(e){const r=e[controlledReadableStream_][state_];return!1===e[closeRequested_]&&"readable"===r}function readableStreamDefaultControllerGetDesiredSize(e){const r=e[controlledReadableStream_][state_];return"errored"===r?null:"closed"===r?0:e[strategyHWM_]-e[queueTotalSize_]}function readableStreamDefaultControllerClose(e){e[closeRequested_]=!0;const r=e[controlledReadableStream_];0===e[queue_].length&&(readableStreamDefaultControllerClearAlgorithms(e),readableStreamClose(r))}function readableStreamDefaultControllerEnqueue(e,r){const t=e[controlledReadableStream_];if(isReadableStreamLocked(t)&&readableStreamGetNumReadRequests(t)>0)readableStreamFulfillReadRequest(t,r,!1);else{let t;try{t=e[strategySizeAlgorithm_](r)}catch(r){throw readableStreamDefaultControllerError(e,r),r}try{enqueueValueWithSize(e,r,t)}catch(r){throw readableStreamDefaultControllerError(e,r),r}}readableStreamDefaultControllerCallPullIfNeeded(e)}function readableStreamDefaultControllerError(e,r){const t=e[controlledReadableStream_];"readable"===t[state_]&&(resetQueue(e),readableStreamDefaultControllerClearAlgorithms(e),readableStreamError(t,r))}function readableStreamDefaultControllerCallPullIfNeeded(e){if(readableStreamDefaultControllerShouldCallPull(e))if(e[pulling_])e[pullAgain_]=!0;else{if(e[pullAgain_])throw new RangeError("Stream controller is in an invalid state.");e[pulling_]=!0,e[pullAlgorithm_](e).then(r=>{e[pulling_]=!1,e[pullAgain_]&&(e[pullAgain_]=!1,readableStreamDefaultControllerCallPullIfNeeded(e))},r=>{readableStreamDefaultControllerError(e,r)})}}function readableStreamDefaultControllerShouldCallPull(e){const r=e[controlledReadableStream_];if(!readableStreamDefaultControllerCanCloseOrEnqueue(e))return!1;if(!1===e[started_])return!1;if(isReadableStreamLocked(r)&&readableStreamGetNumReadRequests(r)>0)return!0;const t=readableStreamDefaultControllerGetDesiredSize(e);if(null===t)throw new RangeError("Stream is in an invalid state.");return t>0}function readableStreamDefaultControllerClearAlgorithms(e){e[pullAlgorithm_]=void 0,e[cancelAlgorithm_]=void 0,e[strategySizeAlgorithm_]=void 0}function setUpReadableByteStreamController(e,r,t,a,o,l,n){if(void 0!==e[readableStreamController_])throw new TypeError("Cannot reuse streams");if(void 0!==n&&(!isInteger(n)||n<=0))throw new RangeError("autoAllocateChunkSize must be a positive, finite integer");r[controlledReadableByteStream_]=e,r[pullAgain_]=!1,r[pulling_]=!1,readableByteStreamControllerClearPendingPullIntos(r),resetQueue(r),r[closeRequested_]=!1,r[started_]=!1,r[strategyHWM_]=validateAndNormalizeHighWaterMark(l),r[pullAlgorithm_]=a,r[cancelAlgorithm_]=o,r[autoAllocateChunkSize_]=n,r[pendingPullIntos_]=[],e[readableStreamController_]=r;const i=t();Promise.resolve(i).then(e=>{r[started_]=!0,readableByteStreamControllerCallPullIfNeeded(r)},e=>{readableByteStreamControllerError(r,e)})}function isReadableStreamBYOBRequest(e){return null!=e&&"object"==typeof e&&associatedReadableByteStreamController_ in e}function isReadableByteStreamController(e){return null!=e&&"object"==typeof e&&controlledReadableByteStream_ in e}function readableByteStreamControllerCallPullIfNeeded(e){readableByteStreamControllerShouldCallPull(e)&&(e[pulling_]?e[pullAgain_]=!0:(e[pulling_]=!0,e[pullAlgorithm_](e).then(r=>{e[pulling_]=!1,e[pullAgain_]&&(e[pullAgain_]=!1,readableByteStreamControllerCallPullIfNeeded(e))},r=>{readableByteStreamControllerError(e,r)})))}function readableByteStreamControllerClearAlgorithms(e){e[pullAlgorithm_]=void 0,e[cancelAlgorithm_]=void 0}function readableByteStreamControllerClearPendingPullIntos(e){readableByteStreamControllerInvalidateBYOBRequest(e),e[pendingPullIntos_]=[]}function readableByteStreamControllerClose(e){const r=e[controlledReadableByteStream_];if(e[queueTotalSize_]>0)e[closeRequested_]=!0;else{if(e[pendingPullIntos_].length>0){if(e[pendingPullIntos_][0].bytesFilled>0){const r=new TypeError;throw readableByteStreamControllerError(e,r),r}}readableByteStreamControllerClearAlgorithms(e),readableStreamClose(r)}}function readableByteStreamControllerCommitPullIntoDescriptor(e,r){let t=!1;"closed"===e[state_]&&(t=!0);const a=readableByteStreamControllerConvertPullIntoDescriptor(r);"default"===r.readerType?readableStreamFulfillReadRequest(e,a,t):readableStreamFulfillReadIntoRequest(e,a,t)}function readableByteStreamControllerConvertPullIntoDescriptor(e){const{bytesFilled:r,elementSize:t}=e;return new e.ctor(e.buffer,e.byteOffset,r/t)}function readableByteStreamControllerEnqueue(e,r){const t=e[controlledReadableByteStream_],{buffer:a,byteOffset:o,byteLength:l}=r,n=transferArrayBuffer(a);if(readableStreamHasDefaultReader(t))if(0===readableStreamGetNumReadRequests(t))readableByteStreamControllerEnqueueChunkToQueue(e,n,o,l);else{readableStreamFulfillReadRequest(t,new Uint8Array(n,o,l),!1)}else readableStreamHasBYOBReader(t)?(readableByteStreamControllerEnqueueChunkToQueue(e,n,o,l),readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(e)):readableByteStreamControllerEnqueueChunkToQueue(e,n,o,l);readableByteStreamControllerCallPullIfNeeded(e)}function readableByteStreamControllerEnqueueChunkToQueue(e,r,t,a){e[queue_].push({buffer:r,byteOffset:t,byteLength:a}),e[queueTotalSize_]+=a}function readableByteStreamControllerError(e,r){const t=e[controlledReadableByteStream_];"readable"===t[state_]&&(readableByteStreamControllerClearPendingPullIntos(e),resetQueue(e),readableByteStreamControllerClearAlgorithms(e),readableStreamError(t,r))}function readableByteStreamControllerFillHeadPullIntoDescriptor(e,r,t){readableByteStreamControllerInvalidateBYOBRequest(e),t.bytesFilled+=r}function readableByteStreamControllerFillPullIntoDescriptorFromQueue(e,r){const t=r.elementSize,a=r.bytesFilled-r.bytesFilled%t,o=Math.min(e[queueTotalSize_],r.byteLength-r.bytesFilled),l=r.bytesFilled+o,n=l-l%t;let i=o,s=!1;n>a&&(i=n-r.bytesFilled,s=!0);const u=e[queue_];for(;i>0;){const t=u.front(),a=Math.min(i,t.byteLength),o=r.byteOffset+r.bytesFilled;copyDataBlockBytes(r.buffer,o,t.buffer,t.byteOffset,a),t.byteLength===a?u.shift():(t.byteOffset+=a,t.byteLength-=a),e[queueTotalSize_]-=a,readableByteStreamControllerFillHeadPullIntoDescriptor(e,a,r),i-=a}return s}function readableByteStreamControllerGetDesiredSize(e){const r=e[controlledReadableByteStream_][state_];return"errored"===r?null:"closed"===r?0:e[strategyHWM_]-e[queueTotalSize_]}function readableByteStreamControllerHandleQueueDrain(e){0===e[queueTotalSize_]&&e[closeRequested_]?(readableByteStreamControllerClearAlgorithms(e),readableStreamClose(e[controlledReadableByteStream_])):readableByteStreamControllerCallPullIfNeeded(e)}function readableByteStreamControllerInvalidateBYOBRequest(e){const r=e[byobRequest_];void 0!==r&&(r[associatedReadableByteStreamController_]=void 0,r[view_]=void 0,e[byobRequest_]=void 0)}function readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(e){const r=e[pendingPullIntos_];for(;r.length>0;){if(0===e[queueTotalSize_])return;const t=r[0];readableByteStreamControllerFillPullIntoDescriptorFromQueue(e,t)&&(readableByteStreamControllerShiftPendingPullInto(e),readableByteStreamControllerCommitPullIntoDescriptor(e[controlledReadableByteStream_],t))}}function readableByteStreamControllerPullInto(e,r,t){const a=e[controlledReadableByteStream_],o=r.BYTES_PER_ELEMENT||1,l=r.constructor,n=r.byteOffset,i=r.byteLength,s={buffer:transferArrayBuffer(r.buffer),byteOffset:n,byteLength:i,bytesFilled:0,elementSize:o,ctor:l,readerType:"byob"};if(e[pendingPullIntos_].length>0)return e[pendingPullIntos_].push(s),readableStreamAddReadIntoRequest(a,t);if("closed"===a[state_]){const e=new l(s.buffer,s.byteOffset,0);return Promise.resolve(readableStreamCreateReadResult(e,!0,t))}if(e[queueTotalSize_]>0){if(readableByteStreamControllerFillPullIntoDescriptorFromQueue(e,s)){const r=readableByteStreamControllerConvertPullIntoDescriptor(s);return readableByteStreamControllerHandleQueueDrain(e),Promise.resolve(readableStreamCreateReadResult(r,!1,t))}if(e[closeRequested_]){const r=new TypeError;return readableByteStreamControllerError(e,r),Promise.reject(r)}}e[pendingPullIntos_].push(s);const u=readableStreamAddReadIntoRequest(a,t);return readableByteStreamControllerCallPullIfNeeded(e),u}function readableByteStreamControllerRespond(e,r){if(!isFiniteNonNegativeNumber(r=Number(r)))throw new RangeError("bytesWritten must be a finite, non-negative number");readableByteStreamControllerRespondInternal(e,r)}function readableByteStreamControllerRespondInClosedState(e,r){r.buffer=transferArrayBuffer(r.buffer);const t=e[controlledReadableByteStream_];if(readableStreamHasBYOBReader(t))for(;readableStreamGetNumReadIntoRequests(t)>0;){readableByteStreamControllerCommitPullIntoDescriptor(t,readableByteStreamControllerShiftPendingPullInto(e))}}function readableByteStreamControllerRespondInReadableState(e,r,t){if(t.bytesFilled+r>t.byteLength)throw new RangeError;if(readableByteStreamControllerFillHeadPullIntoDescriptor(e,r,t),t.bytesFilled<t.elementSize)return;readableByteStreamControllerShiftPendingPullInto(e);const a=t.bytesFilled%t.elementSize;if(a>0){const r=t.byteOffset+t.bytesFilled,o=cloneArrayBuffer(t.buffer,r-a,a,ArrayBuffer);readableByteStreamControllerEnqueueChunkToQueue(e,o,0,o.byteLength)}t.buffer=transferArrayBuffer(t.buffer),t.bytesFilled=t.bytesFilled-a,readableByteStreamControllerCommitPullIntoDescriptor(e[controlledReadableByteStream_],t),readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(e)}function readableByteStreamControllerRespondInternal(e,r){const t=e[pendingPullIntos_][0];if("closed"===e[controlledReadableByteStream_][state_]){if(0!==r)throw new TypeError;readableByteStreamControllerRespondInClosedState(e,t)}else readableByteStreamControllerRespondInReadableState(e,r,t);readableByteStreamControllerCallPullIfNeeded(e)}function readableByteStreamControllerRespondWithNewView(e,r){const t=e[pendingPullIntos_][0];if(t.byteOffset+t.bytesFilled!==r.byteOffset)throw new RangeError;if(t.byteLength!==r.byteLength)throw new RangeError;t.buffer=r.buffer,readableByteStreamControllerRespondInternal(e,r.byteLength)}function readableByteStreamControllerShiftPendingPullInto(e){const r=e[pendingPullIntos_].shift();return readableByteStreamControllerInvalidateBYOBRequest(e),r}function readableByteStreamControllerShouldCallPull(e){const r=e[controlledReadableByteStream_];return"readable"===r[state_]&&(!e[closeRequested_]&&(!!e[started_]&&(!!(readableStreamHasDefaultReader(r)&&readableStreamGetNumReadRequests(r)>0)||(!!(readableStreamHasBYOBReader(r)&&readableStreamGetNumReadIntoRequests(r)>0)||readableByteStreamControllerGetDesiredSize(e)>0))))}function setUpReadableStreamBYOBRequest(e,r,t){if(!isReadableByteStreamController(r))throw new TypeError;if(!ArrayBuffer.isView(t))throw new TypeError;e[associatedReadableByteStreamController_]=r,e[view_]=t}const backpressure_=Symbol("backpressure_"),closeRequest_=Symbol("closeRequest_"),inFlightWriteRequest_=Symbol("inFlightWriteRequest_"),inFlightCloseRequest_=Symbol("inFlightCloseRequest_"),pendingAbortRequest_=Symbol("pendingAbortRequest_"),writableStreamController_=Symbol("writableStreamController_"),writer_=Symbol("writer_"),writeRequests_=Symbol("writeRequests_"),abortAlgorithm_=Symbol("abortAlgorithm_"),closeAlgorithm_=Symbol("closeAlgorithm_"),controlledWritableStream_=Symbol("controlledWritableStream_"),started_$1=Symbol("started_"),strategyHWM_$1=Symbol("strategyHWM_"),strategySizeAlgorithm_$1=Symbol("strategySizeAlgorithm_"),writeAlgorithm_=Symbol("writeAlgorithm_"),ownerWritableStream_=Symbol("ownerWritableStream_"),closedPromise_$1=Symbol("closedPromise_"),readyPromise_=Symbol("readyPromise_"),errorSteps_=Symbol("errorSteps_"),abortSteps_=Symbol("abortSteps_");function initializeWritableStream(e){e[state_]="writable",e[storedError_]=void 0,e[writer_]=void 0,e[writableStreamController_]=void 0,e[inFlightWriteRequest_]=void 0,e[closeRequest_]=void 0,e[inFlightCloseRequest_]=void 0,e[pendingAbortRequest_]=void 0,e[writeRequests_]=[],e[backpressure_]=!1}function isWritableStream(e){return null!=e&&"object"==typeof e&&writableStreamController_ in e}function isWritableStreamLocked(e){return void 0!==e[writer_]}function writableStreamAbort(e,r){const t=e[state_];if("closed"===t||"errored"===t)return Promise.resolve(void 0);let a=e[pendingAbortRequest_];if(void 0!==a)return a.promise;let o=!1;"erroring"===t&&(o=!0,r=void 0),a={reason:r,wasAlreadyErroring:o};const l=new Promise((e,r)=>{a.resolve=e,a.reject=r});return a.promise=l,e[pendingAbortRequest_]=a,o||writableStreamStartErroring(e,r),l}function writableStreamAddWriteRequest(e){const r=createControlledPromise();return e[writeRequests_].push(r),r.promise}function writableStreamDealWithRejection(e,r){"writable"!==e[state_]?writableStreamFinishErroring(e):writableStreamStartErroring(e,r)}function writableStreamStartErroring(e,r){const t=e[writableStreamController_];e[state_]="erroring",e[storedError_]=r;const a=e[writer_];void 0!==a&&writableStreamDefaultWriterEnsureReadyPromiseRejected(a,r),!writableStreamHasOperationMarkedInFlight(e)&&t[started_$1]&&writableStreamFinishErroring(e)}function writableStreamFinishErroring(e){e[state_]="errored";const r=e[writableStreamController_];r[errorSteps_]();const t=e[storedError_];for(const o of e[writeRequests_])o.reject(t);e[writeRequests_]=[];const a=e[pendingAbortRequest_];if(void 0!==a)return e[pendingAbortRequest_]=void 0,a.wasAlreadyErroring?(a.reject(t),void writableStreamRejectCloseAndClosedPromiseIfNeeded(e)):void r[abortSteps_](a.reason).then(r=>{a.resolve(),writableStreamRejectCloseAndClosedPromiseIfNeeded(e)},r=>{a.reject(r),writableStreamRejectCloseAndClosedPromiseIfNeeded(e)});writableStreamRejectCloseAndClosedPromiseIfNeeded(e)}function writableStreamFinishInFlightWrite(e){e[inFlightWriteRequest_].resolve(void 0),e[inFlightWriteRequest_]=void 0}function writableStreamFinishInFlightWriteWithError(e,r){e[inFlightWriteRequest_].reject(r),e[inFlightWriteRequest_]=void 0,writableStreamDealWithRejection(e,r)}function writableStreamFinishInFlightClose(e){e[inFlightCloseRequest_].resolve(void 0),e[inFlightCloseRequest_]=void 0,"erroring"===e[state_]&&(e[storedError_]=void 0,void 0!==e[pendingAbortRequest_]&&(e[pendingAbortRequest_].resolve(),e[pendingAbortRequest_]=void 0)),e[state_]="closed";const r=e[writer_];void 0!==r&&r[closedPromise_$1].resolve(void 0)}function writableStreamFinishInFlightCloseWithError(e,r){e[inFlightCloseRequest_].reject(r),e[inFlightCloseRequest_]=void 0,void 0!==e[pendingAbortRequest_]&&(e[pendingAbortRequest_].reject(r),e[pendingAbortRequest_]=void 0),writableStreamDealWithRejection(e,r)}function writableStreamCloseQueuedOrInFlight(e){return void 0!==e[closeRequest_]||void 0!==e[inFlightCloseRequest_]}function writableStreamHasOperationMarkedInFlight(e){return void 0!==e[inFlightWriteRequest_]||void 0!==e[inFlightCloseRequest_]}function writableStreamMarkCloseRequestInFlight(e){e[inFlightCloseRequest_]=e[closeRequest_],e[closeRequest_]=void 0}function writableStreamMarkFirstWriteRequestInFlight(e){const r=e[writeRequests_].shift();e[inFlightWriteRequest_]=r}function writableStreamRejectCloseAndClosedPromiseIfNeeded(e){const r=e[closeRequest_];void 0!==r&&(r.reject(e[storedError_]),e[closeRequest_]=void 0);const t=e[writer_];void 0!==t&&(t[closedPromise_$1].reject(e[storedError_]),t[closedPromise_$1].promise.catch(()=>{}))}function writableStreamUpdateBackpressure(e,r){const t=e[writer_];void 0!==t&&r!==e[backpressure_]&&(r?t[readyPromise_]=createControlledPromise():t[readyPromise_].resolve(void 0)),e[backpressure_]=r}function isWritableStreamDefaultWriter(e){return null!=e&&"object"==typeof e&&ownerWritableStream_ in e}function writableStreamDefaultWriterAbort(e,r){return writableStreamAbort(e[ownerWritableStream_],r)}function writableStreamDefaultWriterClose(e){const r=e[ownerWritableStream_],t=r[state_];if("closed"===t||"errored"===t)return Promise.reject(new TypeError("Writer stream is already closed or errored"));const a=createControlledPromise();return r[closeRequest_]=a,r[backpressure_]&&"writable"===t&&e[readyPromise_].resolve(void 0),writableStreamDefaultControllerClose(r[writableStreamController_]),a.promise}function writableStreamDefaultWriterCloseWithErrorPropagation(e){const r=e[ownerWritableStream_],t=r[state_];return writableStreamCloseQueuedOrInFlight(r)||"closed"===t?Promise.resolve(void 0):"errored"===t?Promise.reject(r[storedError_]):writableStreamDefaultWriterClose(e)}function writableStreamDefaultWriterEnsureClosedPromiseRejected(e,r){const t=e[closedPromise_$1];t.state===ControlledPromiseState.Pending?t.reject(r):(e[closedPromise_$1]=createControlledPromise(),e[closedPromise_$1].reject(r)),e[closedPromise_$1].promise.catch(()=>{})}function writableStreamDefaultWriterEnsureReadyPromiseRejected(e,r){const t=e[readyPromise_];t.state===ControlledPromiseState.Pending?t.reject(r):(e[readyPromise_]=createControlledPromise(),e[readyPromise_].reject(r)),e[readyPromise_].promise.catch(()=>{})}function writableStreamDefaultWriterGetDesiredSize(e){const r=e[ownerWritableStream_],t=r[state_];return"errored"===t||"erroring"===t?null:"closed"===t?0:writableStreamDefaultControllerGetDesiredSize(r[writableStreamController_])}function writableStreamDefaultWriterRelease(e){const r=e[ownerWritableStream_],t=new TypeError;writableStreamDefaultWriterEnsureReadyPromiseRejected(e,t),writableStreamDefaultWriterEnsureClosedPromiseRejected(e,t),r[writer_]=void 0,e[ownerWritableStream_]=void 0}function writableStreamDefaultWriterWrite(e,r){const t=e[ownerWritableStream_],a=t[writableStreamController_],o=writableStreamDefaultControllerGetChunkSize(a,r);if(e[ownerWritableStream_]!==t)return Promise.reject(new TypeError);const l=t[state_];if("errored"===l)return Promise.reject(t[storedError_]);if(writableStreamCloseQueuedOrInFlight(t)||"closed"===l)return Promise.reject(new TypeError("Cannot write to a closing or closed stream"));if("erroring"===l)return Promise.reject(t[storedError_]);const n=writableStreamAddWriteRequest(t);return writableStreamDefaultControllerWrite(a,r,o),n}function setUpWritableStreamDefaultController(e,r,t,a,o,l,n,i){if(!isWritableStream(e))throw new TypeError;if(void 0!==e[writableStreamController_])throw new TypeError;r[controlledWritableStream_]=e,e[writableStreamController_]=r,resetQueue(r),r[started_$1]=!1,r[strategySizeAlgorithm_$1]=i,r[strategyHWM_$1]=n,r[writeAlgorithm_]=a,r[closeAlgorithm_]=o,r[abortAlgorithm_]=l;const s=writableStreamDefaultControllerGetBackpressure(r);writableStreamUpdateBackpressure(e,s);const u=t();Promise.resolve(u).then(e=>{r[started_$1]=!0,writableStreamDefaultControllerAdvanceQueueIfNeeded(r)},t=>{r[started_$1]=!0,writableStreamDealWithRejection(e,t)})}function isWritableStreamDefaultController(e){return null!=e&&"object"==typeof e&&controlledWritableStream_ in e}function writableStreamDefaultControllerClearAlgorithms(e){e[writeAlgorithm_]=void 0,e[closeAlgorithm_]=void 0,e[abortAlgorithm_]=void 0,e[strategySizeAlgorithm_$1]=void 0}function writableStreamDefaultControllerClose(e){enqueueValueWithSize(e,"close",0),writableStreamDefaultControllerAdvanceQueueIfNeeded(e)}function writableStreamDefaultControllerGetChunkSize(e,r){let t;try{t=e[strategySizeAlgorithm_$1](r)}catch(r){writableStreamDefaultControllerErrorIfNeeded(e,r),t=1}return t}function writableStreamDefaultControllerGetDesiredSize(e){return e[strategyHWM_$1]-e[queueTotalSize_]}function writableStreamDefaultControllerWrite(e,r,t){try{enqueueValueWithSize(e,{chunk:r},t)}catch(r){return void writableStreamDefaultControllerErrorIfNeeded(e,r)}const a=e[controlledWritableStream_];if(!writableStreamCloseQueuedOrInFlight(a)&&"writable"===a[state_]){writableStreamUpdateBackpressure(a,writableStreamDefaultControllerGetBackpressure(e))}writableStreamDefaultControllerAdvanceQueueIfNeeded(e)}function writableStreamDefaultControllerAdvanceQueueIfNeeded(e){if(!e[started_$1])return;const r=e[controlledWritableStream_];if(void 0!==r[inFlightWriteRequest_])return;const t=r[state_];if("closed"===t||"errored"===t)return;if("erroring"===t)return void writableStreamFinishErroring(r);if(0===e[queue_].length)return;const a=peekQueueValue(e);"close"===a?writableStreamDefaultControllerProcessClose(e):writableStreamDefaultControllerProcessWrite(e,a.chunk)}function writableStreamDefaultControllerErrorIfNeeded(e,r){"writable"===e[controlledWritableStream_][state_]&&writableStreamDefaultControllerError(e,r)}function writableStreamDefaultControllerProcessClose(e){const r=e[controlledWritableStream_];writableStreamMarkCloseRequestInFlight(r),dequeueValue(e);const t=e[closeAlgorithm_]();writableStreamDefaultControllerClearAlgorithms(e),t.then(e=>{writableStreamFinishInFlightClose(r)},e=>{writableStreamFinishInFlightCloseWithError(r,e)})}function writableStreamDefaultControllerProcessWrite(e,r){const t=e[controlledWritableStream_];writableStreamMarkFirstWriteRequestInFlight(t),e[writeAlgorithm_](r).then(r=>{writableStreamFinishInFlightWrite(t);const a=t[state_];if(dequeueValue(e),!writableStreamCloseQueuedOrInFlight(t)&&"writable"===a){const r=writableStreamDefaultControllerGetBackpressure(e);writableStreamUpdateBackpressure(t,r)}writableStreamDefaultControllerAdvanceQueueIfNeeded(e)},r=>{"writable"===t[state_]&&writableStreamDefaultControllerClearAlgorithms(e),writableStreamFinishInFlightWriteWithError(t,r)})}function writableStreamDefaultControllerGetBackpressure(e){return writableStreamDefaultControllerGetDesiredSize(e)<=0}function writableStreamDefaultControllerError(e,r){const t=e[controlledWritableStream_];writableStreamDefaultControllerClearAlgorithms(e),writableStreamStartErroring(t,r)}class ReadableStreamDefaultReader{constructor(e){if(!isReadableStream(e))throw new TypeError;if(isReadableStreamLocked(e))throw new TypeError("The stream is locked.");readableStreamReaderGenericInitialize(this,e),this[readRequests_]=[]}get closed(){return isReadableStreamDefaultReader(this)?this[closedPromise_].promise:Promise.reject(new TypeError)}cancel(e){if(!isReadableStreamDefaultReader(this))return Promise.reject(new TypeError);const r=this[ownerReadableStream_];return void 0===r?Promise.reject(new TypeError("Reader is not associated with a stream")):readableStreamCancel(r,e)}read(){return isReadableStreamDefaultReader(this)?void 0===this[ownerReadableStream_]?Promise.reject(new TypeError("Reader is not associated with a stream")):readableStreamDefaultReaderRead(this,!0):Promise.reject(new TypeError)}releaseLock(){if(!isReadableStreamDefaultReader(this))throw new TypeError;if(void 0!==this[ownerReadableStream_]){if(0!==this[readRequests_].length)throw new TypeError("Cannot release a stream with pending read requests");readableStreamReaderGenericRelease(this)}}}class WritableStreamDefaultWriter{constructor(e){if(!isWritableStream(e))throw new TypeError;if(isWritableStreamLocked(e))throw new TypeError("Stream is already locked");this[ownerWritableStream_]=e,e[writer_]=this;const r=createControlledPromise(),t=createControlledPromise();this[readyPromise_]=r,this[closedPromise_$1]=t;const a=e[state_];if("writable"===a)!writableStreamCloseQueuedOrInFlight(e)&&e[backpressure_]||r.resolve(void 0);else if("erroring"===a)r.reject(e[storedError_]),r.promise.catch(()=>{});else if("closed"===a)r.resolve(void 0),t.resolve(void 0);else{const a=e[storedError_];r.reject(a),r.promise.catch(()=>{}),t.reject(a),t.promise.catch(()=>{})}}abort(e){return isWritableStreamDefaultWriter(this)?void 0===this[ownerWritableStream_]?Promise.reject(new TypeError("Writer is not connected to a stream")):writableStreamDefaultWriterAbort(this,e):Promise.reject(new TypeError)}close(){if(!isWritableStreamDefaultWriter(this))return Promise.reject(new TypeError);const e=this[ownerWritableStream_];return void 0===e?Promise.reject(new TypeError("Writer is not connected to a stream")):writableStreamCloseQueuedOrInFlight(e)?Promise.reject(new TypeError):writableStreamDefaultWriterClose(this)}releaseLock(){void 0!==this[ownerWritableStream_]&&writableStreamDefaultWriterRelease(this)}write(e){return isWritableStreamDefaultWriter(this)?void 0===this[ownerWritableStream_]?Promise.reject(new TypeError("Writer is not connected to a stream")):writableStreamDefaultWriterWrite(this,e):Promise.reject(new TypeError)}get closed(){return isWritableStreamDefaultWriter(this)?this[closedPromise_$1].promise:Promise.reject(new TypeError)}get desiredSize(){if(!isWritableStreamDefaultWriter(this))throw new TypeError;if(void 0===this[ownerWritableStream_])throw new TypeError("Writer is not connected to stream");return writableStreamDefaultWriterGetDesiredSize(this)}get ready(){return isWritableStreamDefaultWriter(this)?this[readyPromise_].promise:Promise.reject(new TypeError)}}function pipeTo(e,r,t){const a=!!t.preventClose,o=!!t.preventAbort,l=!!t.preventCancel;let n=!1,i=Promise.resolve();const s=createControlledPromise(),u=new ReadableStreamDefaultReader(e),d=new WritableStreamDefaultWriter(r);function m(e,r,t){"errored"===e[state_]?t(e[storedError_]):r.catch(t)}if(m(e,u[closedPromise_].promise,e=>{b(o?void 0:()=>writableStreamAbort(r,e),{actualError:e})}),m(r,d[closedPromise_$1].promise,r=>{b(l?void 0:()=>readableStreamCancel(e,r),{actualError:r})}),function(e,r,t){"closed"===e[state_]?t():r.then(t)}(e,u[closedPromise_].promise,()=>{a?b():b(()=>writableStreamDefaultWriterCloseWithErrorPropagation(d))}),writableStreamCloseQueuedOrInFlight(r)||"closed"===r[state_]){const r=new TypeError;b(l?void 0:()=>readableStreamCancel(e,r),{actualError:r})}function c(){return"writable"!==r[state_]||writableStreamCloseQueuedOrInFlight(r)?void 0:function e(){const r=i;return i.then(()=>r===i?void 0:e())}()}function b(e,r){if(n)return;function t(){e().then(e=>f(r),e=>f({actualError:e}))}n=!0,void 0===e&&(e=(()=>Promise.resolve()));const a=c();a?a.then(t):t()}function f(e){writableStreamDefaultWriterRelease(d),readableStreamReaderGenericRelease(u),e?s.reject(e.actualError):s.resolve(void 0)}return function e(){n||d[readyPromise_].promise.then(()=>{readableStreamDefaultReaderRead(u).then(({value:r,done:t})=>{t||(i=writableStreamDefaultWriterWrite(d,r).catch(()=>{}),e())},e=>{i=Promise.resolve()})})}(),s.promise}class ReadableStreamDefaultController{constructor(){throw new TypeError}get desiredSize(){return readableStreamDefaultControllerGetDesiredSize(this)}close(){if(!isReadableStreamDefaultController(this))throw new TypeError;if(!readableStreamDefaultControllerCanCloseOrEnqueue(this))throw new TypeError("Cannot close, the stream is already closing or not readable");readableStreamDefaultControllerClose(this)}enqueue(e){if(!isReadableStreamDefaultController(this))throw new TypeError;if(!readableStreamDefaultControllerCanCloseOrEnqueue(this))throw new TypeError("Cannot enqueue, the stream is closing or not readable");readableStreamDefaultControllerEnqueue(this,e)}error(e){if(!isReadableStreamDefaultController(this))throw new TypeError;readableStreamDefaultControllerError(this,e)}[cancelSteps_](e){resetQueue(this);const r=this[cancelAlgorithm_](e);return readableStreamDefaultControllerClearAlgorithms(this),r}[pullSteps_](e){const r=this[controlledReadableStream_];if(this[queue_].length>0){const t=dequeueValue(this);return this[closeRequested_]&&0===this[queue_].length?(readableStreamDefaultControllerClearAlgorithms(this),readableStreamClose(r)):readableStreamDefaultControllerCallPullIfNeeded(this),Promise.resolve(readableStreamCreateReadResult(t,!1,e))}const t=readableStreamAddReadRequest(r,e);return readableStreamDefaultControllerCallPullIfNeeded(this),t}}function setUpReadableStreamDefaultControllerFromUnderlyingSource(e,r,t,a){const o=Object.create(ReadableStreamDefaultController.prototype),l=createAlgorithmFromUnderlyingMethod(r,"pull",[o]),n=createAlgorithmFromUnderlyingMethod(r,"cancel",[]);setUpReadableStreamDefaultController(e,o,()=>invokeOrNoop(r,"start",[o]),l,n,t,a)}class ReadableStreamBYOBRequest{constructor(){throw new TypeError}get view(){if(!isReadableStreamBYOBRequest(this))throw new TypeError;return this[view_]}respond(e){if(!isReadableStreamBYOBRequest(this))throw new TypeError;if(void 0===this[associatedReadableByteStreamController_])throw new TypeError;return readableByteStreamControllerRespond(this[associatedReadableByteStreamController_],e)}respondWithNewView(e){if(!isReadableStreamBYOBRequest(this))throw new TypeError;if(void 0===this[associatedReadableByteStreamController_])throw new TypeError;if(!ArrayBuffer.isView(e))throw new TypeError("view parameter must be a TypedArray");return readableByteStreamControllerRespondWithNewView(this[associatedReadableByteStreamController_],e)}}class ReadableByteStreamController{constructor(){throw new TypeError}get byobRequest(){if(!isReadableByteStreamController(this))throw new TypeError;if(void 0===this[byobRequest_]&&this[pendingPullIntos_].length>0){const e=this[pendingPullIntos_][0],r=new Uint8Array(e.buffer,e.byteOffset+e.bytesFilled,e.byteLength-e.bytesFilled),t=Object.create(ReadableStreamBYOBRequest.prototype);setUpReadableStreamBYOBRequest(t,this,r),this[byobRequest_]=t}return this[byobRequest_]}get desiredSize(){if(!isReadableByteStreamController(this))throw new TypeError;return readableByteStreamControllerGetDesiredSize(this)}close(){if(!isReadableByteStreamController(this))throw new TypeError;if(this[closeRequested_])throw new TypeError("Stream is already closing");if("readable"!==this[controlledReadableByteStream_][state_])throw new TypeError("Stream is closed or errored");readableByteStreamControllerClose(this)}enqueue(e){if(!isReadableByteStreamController(this))throw new TypeError;if(this[closeRequested_])throw new TypeError("Stream is already closing");if("readable"!==this[controlledReadableByteStream_][state_])throw new TypeError("Stream is closed or errored");if(!ArrayBuffer.isView(e))throw new TypeError("chunk must be a valid ArrayBufferView");return readableByteStreamControllerEnqueue(this,e)}error(e){if(!isReadableByteStreamController(this))throw new TypeError;readableByteStreamControllerError(this,e)}[cancelSteps_](e){if(this[pendingPullIntos_].length>0){this[pendingPullIntos_][0].bytesFilled=0}resetQueue(this);const r=this[cancelAlgorithm_](e);return readableByteStreamControllerClearAlgorithms(this),r}[pullSteps_](e){const r=this[controlledReadableByteStream_];if(this[queueTotalSize_]>0){const r=this[queue_].shift();this[queueTotalSize_]-=r.byteLength,readableByteStreamControllerHandleQueueDrain(this);const t=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);return Promise.resolve(readableStreamCreateReadResult(t,!1,e))}const t=this[autoAllocateChunkSize_];if(void 0!==t){let e;try{e=new ArrayBuffer(t)}catch(e){return Promise.reject(e)}const r={buffer:e,byteOffset:0,byteLength:t,bytesFilled:0,elementSize:1,ctor:Uint8Array,readerType:"default"};this[pendingPullIntos_].push(r)}const a=readableStreamAddReadRequest(r,e);return readableByteStreamControllerCallPullIfNeeded(this),a}}function setUpReadableByteStreamControllerFromUnderlyingSource(e,r,t){const a=Object.create(ReadableByteStreamController.prototype),o=createAlgorithmFromUnderlyingMethod(r,"pull",[a]),l=createAlgorithmFromUnderlyingMethod(r,"cancel",[]);let n=r.autoAllocateChunkSize;if(void 0!==n&&(!isInteger(n=Number(n))||n<=0))throw new RangeError("autoAllocateChunkSize must be a positive, finite integer");setUpReadableByteStreamController(e,a,()=>invokeOrNoop(r,"start",[a]),o,l,t,n)}class ReadableStreamBYOBReader{constructor(e){if(!isReadableStream(e))throw new TypeError;if(!isReadableByteStreamController(e[readableStreamController_]))throw new TypeError;if(isReadableStreamLocked(e))throw new TypeError("The stream is locked.");readableStreamReaderGenericInitialize(this,e),this[readIntoRequests_]=[]}get closed(){return isReadableStreamBYOBReader(this)?this[closedPromise_].promise:Promise.reject(new TypeError)}cancel(e){if(!isReadableStreamBYOBReader(this))return Promise.reject(new TypeError);const r=this[ownerReadableStream_];return void 0===r?Promise.reject(new TypeError("Reader is not associated with a stream")):readableStreamCancel(r,e)}read(e){return isReadableStreamBYOBReader(this)?void 0===this[ownerReadableStream_]?Promise.reject(new TypeError("Reader is not associated with a stream")):ArrayBuffer.isView(e)?0===e.byteLength?Promise.reject(new TypeError("supplied buffer view must be > 0 bytes")):readableStreamBYOBReaderRead(this,e,!0):Promise.reject(new TypeError("view argument must be a valid ArrayBufferView")):Promise.reject(new TypeError)}releaseLock(){if(!isReadableStreamBYOBReader(this))throw new TypeError;if(void 0===this[ownerReadableStream_])throw new TypeError("Reader is not associated with a stream");if(this[readIntoRequests_].length>0)throw new TypeError;readableStreamReaderGenericRelease(this)}}class ReadableStream{constructor(e={},r={}){initializeReadableStream(this);const t=r.size,a=r.highWaterMark,o=e.type;if(void 0===o){const r=makeSizeAlgorithmFromSizeFunction(t);setUpReadableStreamDefaultControllerFromUnderlyingSource(this,e,validateAndNormalizeHighWaterMark(void 0===a?1:a),r)}else{if("bytes"!==String(o))throw new RangeError("The underlying source's `type` field must be undefined or 'bytes'");if(void 0!==t)throw new RangeError("bytes streams cannot have a strategy with a `size` field");setUpReadableByteStreamControllerFromUnderlyingSource(this,e,validateAndNormalizeHighWaterMark(void 0===a?0:a))}}get locked(){return isReadableStreamLocked(this)}getReader(e={}){if(!isReadableStream(this))throw new TypeError;const{mode:r}=e;if(void 0===r)return new ReadableStreamDefaultReader(this);if("byob"===String(r))return new ReadableStreamBYOBReader(this);throw RangeError("mode option must be undefined or `byob`")}cancel(e){return isReadableStream(this)?isReadableStreamLocked(this)?Promise.reject(new TypeError("Cannot cancel a locked stream")):readableStreamCancel(this,e):Promise.reject(new TypeError)}tee(){if(!isReadableStream(this))throw new TypeError;const e=new ReadableStreamDefaultReader(this);let r,t,a,o,l,n=!1,i=!1,s=!1;const u=new Promise(e=>l=e),d=()=>readableStreamDefaultReaderRead(e).then(({value:e,done:r})=>{if(r&&!n&&(i||readableStreamDefaultControllerClose(a[readableStreamController_]),s||readableStreamDefaultControllerClose(o[readableStreamController_]),n=!0),n)return;const t=e,l=e;i||readableStreamDefaultControllerEnqueue(a[readableStreamController_],t),s||readableStreamDefaultControllerEnqueue(o[readableStreamController_],l)}),m=()=>void 0;return a=createReadableStream(m,d,e=>{if(i=!0,r=e,s){const e=readableStreamCancel(this,[r,t]);l(e)}return u}),o=createReadableStream(m,d,e=>{if(s=!0,t=e,i){const e=readableStreamCancel(this,[r,t]);l(e)}return u}),e[closedPromise_].promise.catch(e=>{n||(readableStreamDefaultControllerError(a[readableStreamController_],e),readableStreamDefaultControllerError(o[readableStreamController_],e),n=!0)}),[a,o]}pipeThrough(e,r){const{readable:t,writable:a}=e;if(void 0===t||void 0===a)throw new TypeError("Both a readable and writable stream must be provided");const o=this.pipeTo(a,r);try{Promise.prototype.then.call(o,void 0,()=>{})}catch(e){}return t}pipeTo(e,r={}){return isReadableStream(this)&&isWritableStream(e)?isReadableStreamLocked(this)?Promise.reject(new TypeError("Cannot pipe from a locked stream")):isWritableStreamLocked(e)?Promise.reject(new TypeError("Cannot pipe to a locked stream")):pipeTo(this,e,r):Promise.reject(new TypeError)}}function createReadableStream(e,r,t,a,o){void 0===a&&(a=1),void 0===o&&(o=(()=>1));const l=Object.create(ReadableStream.prototype);return initializeReadableStream(l),setUpReadableStreamDefaultController(l,Object.create(ReadableStreamDefaultController.prototype),e,r,t,a,o),l}class WritableStreamDefaultController{constructor(){throw new TypeError}error(e){if(!isWritableStreamDefaultController(this))throw new TypeError;"writable"===this[controlledWritableStream_][state_]&&writableStreamDefaultControllerError(this,e)}[abortSteps_](e){const r=this[abortAlgorithm_](e);return writableStreamDefaultControllerClearAlgorithms(this),r}[errorSteps_](){resetQueue(this)}}function setUpWritableStreamDefaultControllerFromUnderlyingSink(e,r,t,a){const o=Object.create(WritableStreamDefaultController.prototype),l=createAlgorithmFromUnderlyingMethod(r,"write",[o]),n=createAlgorithmFromUnderlyingMethod(r,"close",[]),i=createAlgorithmFromUnderlyingMethod(r,"abort",[]);setUpWritableStreamDefaultController(e,o,function(){return invokeOrNoop(r,"start",[o])},l,n,i,t,a)}class WritableStream{constructor(e={},r={}){initializeWritableStream(this);const t=r.size,a=r.highWaterMark;if(void 0!==e.type)throw new RangeError("The type of an underlying sink must be undefined");const o=makeSizeAlgorithmFromSizeFunction(t);setUpWritableStreamDefaultControllerFromUnderlyingSink(this,e,validateAndNormalizeHighWaterMark(void 0===a?1:a),o)}get locked(){if(!isWritableStream(this))throw new TypeError;return isWritableStreamLocked(this)}abort(e){return isWritableStream(this)?isWritableStreamLocked(this)?Promise.reject(new TypeError("Cannot abort a locked stream")):writableStreamAbort(this,e):Promise.reject(new TypeError)}getWriter(){if(!isWritableStream(this))throw new TypeError;return new WritableStreamDefaultWriter(this)}}function createWritableStream(e,r,t,a,o,l){void 0===o&&(o=1),void 0===l&&(l=(()=>1));const n=Object.create(WritableStream.prototype);return initializeWritableStream(n),setUpWritableStreamDefaultController(n,Object.create(WritableStreamDefaultController.prototype),e,r,t,a,o,l),n}const backpressure_$1=Symbol("backpressure_"),backpressureChangePromise_=Symbol("backpressureChangePromise_"),readable_=Symbol("readable_"),transformStreamController_=Symbol("transformStreamController_"),writable_=Symbol("writable_"),controlledTransformStream_=Symbol("controlledTransformStream_"),flushAlgorithm_=Symbol("flushAlgorithm_"),transformAlgorithm_=Symbol("transformAlgorithm_");function isTransformStream(e){return null!=e&&"object"==typeof e&&transformStreamController_ in e}function initializeTransformStream(e,r,t,a,o,l){const n=function(){return r};e[writable_]=createWritableStream(n,function(r){return transformStreamDefaultSinkWriteAlgorithm(e,r)},function(){return transformStreamDefaultSinkCloseAlgorithm(e)},function(r){return transformStreamDefaultSinkAbortAlgorithm(e,r)},t,a);e[readable_]=createReadableStream(n,function(){return transformStreamDefaultSourcePullAlgorithm(e)},function(r){return transformStreamErrorWritableAndUnblockWrite(e,r),Promise.resolve(void 0)},o,l),e[backpressure_$1]=void 0,e[backpressureChangePromise_]=void 0,transformStreamSetBackpressure(e,!0),e[transformStreamController_]=void 0}function transformStreamError(e,r){readableStreamDefaultControllerError(e[readable_][readableStreamController_],r),transformStreamErrorWritableAndUnblockWrite(e,r)}function transformStreamErrorWritableAndUnblockWrite(e,r){transformStreamDefaultControllerClearAlgorithms(e[transformStreamController_]),writableStreamDefaultControllerErrorIfNeeded(e[writable_][writableStreamController_],r),e[backpressure_$1]&&transformStreamSetBackpressure(e,!1)}function transformStreamSetBackpressure(e,r){void 0!==e[backpressure_$1]&&e[backpressureChangePromise_].resolve(void 0),e[backpressureChangePromise_]=createControlledPromise(),e[backpressure_$1]=r}function isTransformStreamDefaultController(e){return null!=e&&"object"==typeof e&&controlledTransformStream_ in e}function setUpTransformStreamDefaultController(e,r,t,a){r[controlledTransformStream_]=e,e[transformStreamController_]=r,r[transformAlgorithm_]=t,r[flushAlgorithm_]=a}function transformStreamDefaultControllerClearAlgorithms(e){e[transformAlgorithm_]=void 0,e[flushAlgorithm_]=void 0}function transformStreamDefaultControllerEnqueue(e,r){const t=e[controlledTransformStream_],a=t[readable_][readableStreamController_];if(!readableStreamDefaultControllerCanCloseOrEnqueue(a))throw new TypeError;try{readableStreamDefaultControllerEnqueue(a,r)}catch(e){throw transformStreamErrorWritableAndUnblockWrite(t,e),t[readable_][storedError_]}readableStreamDefaultControllerHasBackpressure(a)!==t[backpressure_$1]&&transformStreamSetBackpressure(t,!0)}function transformStreamDefaultControllerError(e,r){transformStreamError(e[controlledTransformStream_],r)}function transformStreamDefaultControllerPerformTransform(e,r){return e[transformAlgorithm_](r).catch(r=>{throw transformStreamError(e[controlledTransformStream_],r),r})}function transformStreamDefaultControllerTerminate(e){const r=e[controlledTransformStream_],t=r[readable_][readableStreamController_];readableStreamDefaultControllerCanCloseOrEnqueue(t)&&readableStreamDefaultControllerClose(t),transformStreamErrorWritableAndUnblockWrite(r,new TypeError("The transform stream has been terminated"))}function transformStreamDefaultSinkWriteAlgorithm(e,r){const t=e[transformStreamController_];if(e[backpressure_$1]){return e[backpressureChangePromise_].promise.then(a=>{const o=e[writable_];if("erroring"===o[state_])throw o[storedError_];return transformStreamDefaultControllerPerformTransform(t,r)})}return transformStreamDefaultControllerPerformTransform(t,r)}function transformStreamDefaultSinkAbortAlgorithm(e,r){return transformStreamError(e,r),Promise.resolve(void 0)}function transformStreamDefaultSinkCloseAlgorithm(e){const r=e[readable_],t=e[transformStreamController_],a=t[flushAlgorithm_]();return transformStreamDefaultControllerClearAlgorithms(t),a.then(e=>{if("errored"===r[state_])throw r[storedError_];const t=r[readableStreamController_];readableStreamDefaultControllerCanCloseOrEnqueue(t)&&readableStreamDefaultControllerClose(t)},t=>{throw transformStreamError(e,t),r[storedError_]})}function transformStreamDefaultSourcePullAlgorithm(e){return transformStreamSetBackpressure(e,!1),e[backpressureChangePromise_].promise}class TransformStreamDefaultController{constructor(){throw new TypeError}get desiredSize(){if(!isTransformStreamDefaultController(this))throw new TypeError;return readableStreamDefaultControllerGetDesiredSize(this[controlledTransformStream_][readable_][readableStreamController_])}enqueue(e){if(!isTransformStreamDefaultController(this))throw new TypeError;transformStreamDefaultControllerEnqueue(this,e)}error(e){if(!isTransformStreamDefaultController(this))throw new TypeError;transformStreamDefaultControllerError(this,e)}terminate(){if(!isTransformStreamDefaultController(this))throw new TypeError;transformStreamDefaultControllerTerminate(this)}}class TransformStream{constructor(e={},r={},t={}){const a=r.size,o=r.highWaterMark,l=t.size,n=t.highWaterMark;if(void 0!==e.writableType)throw new RangeError("The transformer's `writableType` field must be undefined");const i=makeSizeAlgorithmFromSizeFunction(a),s=validateAndNormalizeHighWaterMark(void 0===o?1:o);if(void 0!==e.readableType)throw new RangeError("The transformer's `readableType` field must be undefined");const u=makeSizeAlgorithmFromSizeFunction(l),d=validateAndNormalizeHighWaterMark(void 0===n?0:n),m=createControlledPromise();initializeTransformStream(this,m.promise,s,i,d,u),setUpTransformStreamDefaultControllerFromTransformer(this,e);const c=invokeOrNoop(e,"start",[this[transformStreamController_]]);m.resolve(c)}get readable(){if(!isTransformStream(this))throw new TypeError;return this[readable_]}get writable(){if(!isTransformStream(this))throw new TypeError;return this[writable_]}}function setUpTransformStreamDefaultControllerFromTransformer(e,r){const t=Object.create(TransformStreamDefaultController.prototype);let a;const o=r.transform;if(void 0!==o){if("function"!=typeof o)throw new TypeError("`transform` field of the transformer must be a function");a=(e=>promiseCall(o,r,[e,t]))}else a=function(e){try{transformStreamDefaultControllerEnqueue(t,e)}catch(e){return Promise.reject(e)}return Promise.resolve(void 0)};const l=createAlgorithmFromUnderlyingMethod(r,"flush",[t]);setUpTransformStreamDefaultController(e,t,a,l)}class ByteLengthQueuingStrategy{constructor(e){this.highWaterMark=e.highWaterMark}size(e){return e.byteLength}}class CountQueuingStrategy{constructor(e){this.highWaterMark=e.highWaterMark}size(){return 1}}function wrapReadableStream(e,r){let t;return new r({start(r){(t=e.getReader()).closed.catch(e=>{r.error(e)})},pull:e=>t.read().then(({value:r,done:t})=>{t?e.close():e.enqueue(r)},r=>{e.error(r)}),cancel(e){t.cancel(e)}})}function getMIMETypeFromHeadersInit(e){if(void 0===e)return"";if(e instanceof Headers)return e.get("Content-Type")||"";if(Array.isArray(e)){const r=e.find(e=>Array.isArray(e)&&2===e.length&&"Content-Type"===e[0]);return r?r[1]:""}return e["Content-Type"]||""}function resolveRequestInitStream(e,r,t){if(void 0===e)return Promise.resolve(e);const a=e.body;let o;if(a&&"object"==typeof a&&(r&&a instanceof r?o=a:a instanceof t&&(o=a)),!o)return Promise.resolve(e);const l=getMIMETypeFromHeadersInit(e.headers);return readAllBytesFromStream(o.getReader(),l).then(r=>(e.body=r,e))}function createAdaptedFetch(e,r,t){return function(a,o){return resolveRequestInitStream(o,r,t).then(r=>e.call(void 0,a,r).then(e=>{if("body"in e){const r=e;let a;e=new Proxy(r,{get(e,o,l){if("body"===o)return void 0===a&&(a=wrapReadableStream(r.body,t)),a;{const r=e[o];return"function"==typeof r?function(...t){return r.apply(e,t)}:r}}})}else e.body=new t({pull:r=>e.arrayBuffer().then(e=>{r.enqueue(new Uint8Array(e)),r.close()},e=>{r.error(e)})});return e}))}}function readAllBytesFromStream(e,r){return new Promise((t,a)=>{const o=[];!function l(){e.read().then(({value:e,done:n})=>{n?function(){0===o.length&&o.push(new Uint8Array(0));const e=new Blob(o,{type:r});t(e)}():e instanceof Uint8Array?(o.push(e),l()):a(new TypeError("A ReadableStream body must only yield Uint8Array values"))},e=>{a(e)})}()})}function createResponseProxyWithStreamBody(e,r,t){const a=new e("fake",t),o=getMIMETypeFromHeadersInit(a.headers);let l,n=!1;function i(){return void 0===l&&(l=new Promise((a,l)=>{if(n=!0,r.locked)return l(new TypeError("The ReadableStream is locked"));readAllBytesFromStream(r.getReader(),o).then(r=>{a(new e(r,t))}).catch(e=>{l(e)})})),l}return new class{get type(){return a.type}get url(){return a.url}get redirected(){return a.redirected}get status(){return a.status}get ok(){return a.ok}get statusText(){return a.statusText}get headers(){return a.headers}clone(){const[a,o]=r.tee();return r=a,createResponseProxyWithStreamBody(e,o,t)}get body(){return r}get bodyUsed(){return n}arrayBuffer(){return i().then(e=>e.arrayBuffer())}blob(){return i().then(e=>e.blob())}formData(){return i().then(e=>e.formData())}json(){return i().then(e=>e.json())}text(){return i().then(e=>e.text())}}}function createAdaptedResponse(e,r,t){const a=function(a,o){if(a instanceof t){if(void 0===r||!("body"in e))return createResponseProxyWithStreamBody(e,a,o);a=wrapReadableStream(a,r)}return new e(a,o)};return a.prototype=e.prototype,a}function getGlobal(){let e;if(void 0===e){try{e=window}catch(e){}if(void 0===e)try{e=global}catch(e){}}return e}function getGlobalValue(e){const r=getGlobal();let t;return void 0!==r&&(t=r[e]),t}function getGlobalOrContextualValue(name){const global=getGlobal();let value;if(void 0!==global&&(value=global[name]),void 0===value)try{value=eval(name)}catch(e){}return value}function hasCompleteStreamsImplementation(){const e=getGlobalValue("ReadableStream"),r=getGlobalValue("WritableStream"),t=getGlobalValue("TransformStream"),a=getGlobalValue("ByteLengthQueuingStrategy"),o=getGlobalValue("CountQueuingStrategy"),l=e=>"function"==typeof e;if(!(l(e)&&l(r)&&l(t)&&l(a)&&l(o)))return!1;try{const r=new e({type:"bytes"}).getReader({mode:"byob"});if(null==r||"object"!=typeof r)return!1}catch(e){return!1}return!0}function installStardazedStreams(){const e=getGlobal();if(!e)return;if(hasCompleteStreamsImplementation())return;const r=getGlobalOrContextualValue("fetch"),t=getGlobalOrContextualValue("Response"),a=getGlobalValue("ReadableStream");if(r&&t){const o=createAdaptedFetch(r,a,ReadableStream),l=createAdaptedResponse(t,a,ReadableStream);e.fetch=o,e.Response=l}e.ReadableStream=ReadableStream,e.WritableStream=WritableStream,e.TransformStream=TransformStream,e.ByteLengthQueuingStrategy=ByteLengthQueuingStrategy,e.CountQueuingStrategy=CountQueuingStrategy}installStardazedStreams()}(); | ||
!function(){"use strict";const state_=Symbol("state_"),storedError_=Symbol("storedError_");function isInteger(e){if(!isFinite(e))return!1;const r=Math.abs(e);return Math.floor(r)===r}function isFiniteNonNegativeNumber(e){return!("number"!=typeof e||!isFinite(e))&&e>=0}function invokeOrNoop(e,r,t){const a=e[r];if(void 0!==a)return Function.prototype.apply.call(a,e,t)}function cloneArrayBuffer(e,r,t,a){return e.slice(r,r+t)}function transferArrayBuffer(e){return e.slice(0)}function copyDataBlockBytes(e,r,t,a,o){new Uint8Array(e,r,o).set(new Uint8Array(t,a,o))}function promiseCall(e,r,t){try{const a=Function.prototype.apply.call(e,r,t);return Promise.resolve(a)}catch(e){return Promise.reject(e)}}function createAlgorithmFromUnderlyingMethod(e,r,t){const a=e[r];if(void 0===a)return()=>Promise.resolve(void 0);if("function"!=typeof a)throw new TypeError(`Field "${r}" is not a function.`);return function(...r){return promiseCall(a,e,r.concat(t))}}function validateAndNormalizeHighWaterMark(e){const r=Number(e);if(isNaN(r)||r<0)throw new RangeError("highWaterMark must be a valid, non-negative integer.");return r}function makeSizeAlgorithmFromSizeFunction(e){if("function"!=typeof e&&void 0!==e)throw new TypeError("size function must be undefined or a function");return function(r){return"function"==typeof e?e(r):1}}var ControlledPromiseState;function createControlledPromise(){const e={state:ControlledPromiseState.Pending};return e.promise=new Promise(function(r,t){e.resolve=function(t){e.state=ControlledPromiseState.Resolved,r(t)},e.reject=function(r){e.state=ControlledPromiseState.Rejected,t(r)}}),e}!function(e){e[e.Pending=0]="Pending",e[e.Resolved=1]="Resolved",e[e.Rejected=2]="Rejected"}(ControlledPromiseState||(ControlledPromiseState={}));const CHUNK_SIZE=16384;class QueueImpl{constructor(){this.chunks_=[[]],this.readChunk_=this.writeChunk_=this.chunks_[0],this.length_=0}push(e){this.writeChunk_.push(e),this.length_+=1,this.writeChunk_.length===CHUNK_SIZE&&(this.writeChunk_=[],this.chunks_.push(this.writeChunk_))}front(){if(0!==this.length_)return this.readChunk_[0]}shift(){if(0===this.length_)return;const e=this.readChunk_.shift();return this.length_-=1,0===this.readChunk_.length&&this.readChunk_!==this.writeChunk_&&(this.chunks_.shift(),this.readChunk_=this.chunks_[0]),e}get length(){return this.length_}}const queue_=Symbol("queue_"),queueTotalSize_=Symbol("queueTotalSize_");function dequeueValue(e){const r=e[queue_].shift(),t=e[queueTotalSize_]-r.size;return e[queueTotalSize_]=Math.max(0,t),r.value}function enqueueValueWithSize(e,r,t){if(!isFiniteNonNegativeNumber(t))throw new RangeError("Chunk size must be a non-negative, finite numbers");e[queue_].push({value:r,size:t}),e[queueTotalSize_]+=t}function peekQueueValue(e){return e[queue_].front().value}function resetQueue(e){e[queue_]=new QueueImpl,e[queueTotalSize_]=0}const controlledReadableStream_=Symbol("controlledReadableStream_"),pullAlgorithm_=Symbol("pullAlgorithm_"),cancelAlgorithm_=Symbol("cancelAlgorithm_"),strategySizeAlgorithm_=Symbol("strategySizeAlgorithm_"),strategyHWM_=Symbol("strategyHWM_"),started_=Symbol("started_"),closeRequested_=Symbol("closeRequested_"),pullAgain_=Symbol("pullAgain_"),pulling_=Symbol("pulling_"),cancelSteps_=Symbol("cancelSteps_"),pullSteps_=Symbol("pullSteps_"),autoAllocateChunkSize_=Symbol("autoAllocateChunkSize_"),byobRequest_=Symbol("byobRequest_"),controlledReadableByteStream_=Symbol("controlledReadableByteStream_"),pendingPullIntos_=Symbol("pendingPullIntos_"),closedPromise_=Symbol("closedPromise_"),ownerReadableStream_=Symbol("ownerReadableStream_"),readRequests_=Symbol("readRequests_"),readIntoRequests_=Symbol("readIntoRequests_"),associatedReadableByteStreamController_=Symbol("associatedReadableByteStreamController_"),view_=Symbol("view_"),reader_=Symbol("reader_"),readableStreamController_=Symbol("readableStreamController_");function initializeReadableStream(e){e[state_]="readable",e[reader_]=void 0,e[storedError_]=void 0,e[readableStreamController_]=void 0}function isReadableStream(e){return null!=e&&"object"==typeof e&&readableStreamController_ in e}function isReadableStreamLocked(e){return void 0!==e[reader_]}function readableStreamGetNumReadIntoRequests(e){const r=e[reader_];return void 0===r?0:r[readIntoRequests_].length}function readableStreamGetNumReadRequests(e){const r=e[reader_];return void 0===r?0:r[readRequests_].length}function readableStreamCreateReadResult(e,r,t){const a=t?Object.prototype:null,o=Object.create(a);return o.value=e,o.done=r,o}function readableStreamAddReadIntoRequest(e,r){const t=e[reader_],a=createControlledPromise();return a.forAuthorCode=r,t[readIntoRequests_].push(a),a.promise}function readableStreamAddReadRequest(e,r){const t=e[reader_],a=createControlledPromise();return a.forAuthorCode=r,t[readRequests_].push(a),a.promise}function readableStreamHasBYOBReader(e){return isReadableStreamBYOBReader(e[reader_])}function readableStreamHasDefaultReader(e){return isReadableStreamDefaultReader(e[reader_])}function readableStreamCancel(e,r){if("closed"===e[state_])return Promise.resolve(void 0);if("errored"===e[state_])return Promise.reject(e[storedError_]);return readableStreamClose(e),e[readableStreamController_][cancelSteps_](r).then(e=>void 0)}function readableStreamClose(e){e[state_]="closed";const r=e[reader_];if(void 0!==r){if(isReadableStreamDefaultReader(r)){for(const e of r[readRequests_])e.resolve(readableStreamCreateReadResult(void 0,!0,e.forAuthorCode));r[readRequests_]=[]}r[closedPromise_].resolve(),r[closedPromise_].promise.catch(()=>{})}}function readableStreamError(e,r){if("readable"!==e[state_])throw new RangeError("Stream is in an invalid state");e[state_]="errored",e[storedError_]=r;const t=e[reader_];if(void 0!==t){if(isReadableStreamDefaultReader(t)){for(const e of t[readRequests_])e.reject(r);t[readRequests_]=[]}else{const e=t[readIntoRequests_];for(const t of e)t.reject(r);t[readIntoRequests_]=[]}t[closedPromise_].reject(r)}}function isReadableStreamDefaultReader(e){return null!=e&&"object"==typeof e&&readRequests_ in e}function isReadableStreamBYOBReader(e){return null!=e&&"object"==typeof e&&readIntoRequests_ in e}function readableStreamReaderGenericInitialize(e,r){e[ownerReadableStream_]=r,r[reader_]=e;const t=r[state_];e[closedPromise_]=createControlledPromise(),"readable"===t||("closed"===t?e[closedPromise_].resolve(void 0):(e[closedPromise_].reject(r[storedError_]),e[closedPromise_].promise.catch(()=>{})))}function readableStreamReaderGenericRelease(e){const r=e[ownerReadableStream_];if(void 0===r)throw new TypeError("Reader is in an inconsistent state");"readable"===r[state_]||(e[closedPromise_]=createControlledPromise()),e[closedPromise_].reject(new TypeError),e[closedPromise_].promise.catch(()=>{}),r[reader_]=void 0,e[ownerReadableStream_]=void 0}function readableStreamBYOBReaderRead(e,r,t=!1){const a=e[ownerReadableStream_];return"errored"===a[state_]?Promise.reject(a[storedError_]):readableByteStreamControllerPullInto(a[readableStreamController_],r,t)}function readableStreamDefaultReaderRead(e,r=!1){const t=e[ownerReadableStream_];return"closed"===t[state_]?Promise.resolve(readableStreamCreateReadResult(void 0,!0,r)):"errored"===t[state_]?Promise.reject(t[storedError_]):t[readableStreamController_][pullSteps_](r)}function readableStreamFulfillReadIntoRequest(e,r,t){const a=e[reader_][readIntoRequests_].shift();a.resolve(readableStreamCreateReadResult(r,t,a.forAuthorCode))}function readableStreamFulfillReadRequest(e,r,t){const a=e[reader_][readRequests_].shift();a.resolve(readableStreamCreateReadResult(r,t,a.forAuthorCode))}function setUpReadableStreamDefaultController(e,r,t,a,o,l,n){r[controlledReadableStream_]=e,resetQueue(r),r[started_]=!1,r[closeRequested_]=!1,r[pullAgain_]=!1,r[pulling_]=!1,r[strategySizeAlgorithm_]=n,r[strategyHWM_]=l,r[pullAlgorithm_]=a,r[cancelAlgorithm_]=o,e[readableStreamController_]=r;const i=t();Promise.resolve(i).then(e=>{r[started_]=!0,readableStreamDefaultControllerCallPullIfNeeded(r)},e=>{readableStreamDefaultControllerError(r,e)})}function isReadableStreamDefaultController(e){return null!=e&&"object"==typeof e&&controlledReadableStream_ in e}function readableStreamDefaultControllerHasBackpressure(e){return!readableStreamDefaultControllerShouldCallPull(e)}function readableStreamDefaultControllerCanCloseOrEnqueue(e){const r=e[controlledReadableStream_][state_];return!1===e[closeRequested_]&&"readable"===r}function readableStreamDefaultControllerGetDesiredSize(e){const r=e[controlledReadableStream_][state_];return"errored"===r?null:"closed"===r?0:e[strategyHWM_]-e[queueTotalSize_]}function readableStreamDefaultControllerClose(e){e[closeRequested_]=!0;const r=e[controlledReadableStream_];0===e[queue_].length&&(readableStreamDefaultControllerClearAlgorithms(e),readableStreamClose(r))}function readableStreamDefaultControllerEnqueue(e,r){const t=e[controlledReadableStream_];if(isReadableStreamLocked(t)&&readableStreamGetNumReadRequests(t)>0)readableStreamFulfillReadRequest(t,r,!1);else{let t;try{t=e[strategySizeAlgorithm_](r)}catch(r){throw readableStreamDefaultControllerError(e,r),r}try{enqueueValueWithSize(e,r,t)}catch(r){throw readableStreamDefaultControllerError(e,r),r}}readableStreamDefaultControllerCallPullIfNeeded(e)}function readableStreamDefaultControllerError(e,r){const t=e[controlledReadableStream_];"readable"===t[state_]&&(resetQueue(e),readableStreamDefaultControllerClearAlgorithms(e),readableStreamError(t,r))}function readableStreamDefaultControllerCallPullIfNeeded(e){if(readableStreamDefaultControllerShouldCallPull(e))if(e[pulling_])e[pullAgain_]=!0;else{if(e[pullAgain_])throw new RangeError("Stream controller is in an invalid state.");e[pulling_]=!0,e[pullAlgorithm_](e).then(r=>{e[pulling_]=!1,e[pullAgain_]&&(e[pullAgain_]=!1,readableStreamDefaultControllerCallPullIfNeeded(e))},r=>{readableStreamDefaultControllerError(e,r)})}}function readableStreamDefaultControllerShouldCallPull(e){const r=e[controlledReadableStream_];if(!readableStreamDefaultControllerCanCloseOrEnqueue(e))return!1;if(!1===e[started_])return!1;if(isReadableStreamLocked(r)&&readableStreamGetNumReadRequests(r)>0)return!0;const t=readableStreamDefaultControllerGetDesiredSize(e);if(null===t)throw new RangeError("Stream is in an invalid state.");return t>0}function readableStreamDefaultControllerClearAlgorithms(e){e[pullAlgorithm_]=void 0,e[cancelAlgorithm_]=void 0,e[strategySizeAlgorithm_]=void 0}function setUpReadableByteStreamController(e,r,t,a,o,l,n){if(void 0!==e[readableStreamController_])throw new TypeError("Cannot reuse streams");if(void 0!==n&&(!isInteger(n)||n<=0))throw new RangeError("autoAllocateChunkSize must be a positive, finite integer");r[controlledReadableByteStream_]=e,r[pullAgain_]=!1,r[pulling_]=!1,readableByteStreamControllerClearPendingPullIntos(r),resetQueue(r),r[closeRequested_]=!1,r[started_]=!1,r[strategyHWM_]=validateAndNormalizeHighWaterMark(l),r[pullAlgorithm_]=a,r[cancelAlgorithm_]=o,r[autoAllocateChunkSize_]=n,r[pendingPullIntos_]=[],e[readableStreamController_]=r;const i=t();Promise.resolve(i).then(e=>{r[started_]=!0,readableByteStreamControllerCallPullIfNeeded(r)},e=>{readableByteStreamControllerError(r,e)})}function isReadableStreamBYOBRequest(e){return null!=e&&"object"==typeof e&&associatedReadableByteStreamController_ in e}function isReadableByteStreamController(e){return null!=e&&"object"==typeof e&&controlledReadableByteStream_ in e}function readableByteStreamControllerCallPullIfNeeded(e){readableByteStreamControllerShouldCallPull(e)&&(e[pulling_]?e[pullAgain_]=!0:(e[pulling_]=!0,e[pullAlgorithm_](e).then(r=>{e[pulling_]=!1,e[pullAgain_]&&(e[pullAgain_]=!1,readableByteStreamControllerCallPullIfNeeded(e))},r=>{readableByteStreamControllerError(e,r)})))}function readableByteStreamControllerClearAlgorithms(e){e[pullAlgorithm_]=void 0,e[cancelAlgorithm_]=void 0}function readableByteStreamControllerClearPendingPullIntos(e){readableByteStreamControllerInvalidateBYOBRequest(e),e[pendingPullIntos_]=[]}function readableByteStreamControllerClose(e){const r=e[controlledReadableByteStream_];if(e[queueTotalSize_]>0)e[closeRequested_]=!0;else{if(e[pendingPullIntos_].length>0){if(e[pendingPullIntos_][0].bytesFilled>0){const r=new TypeError;throw readableByteStreamControllerError(e,r),r}}readableByteStreamControllerClearAlgorithms(e),readableStreamClose(r)}}function readableByteStreamControllerCommitPullIntoDescriptor(e,r){let t=!1;"closed"===e[state_]&&(t=!0);const a=readableByteStreamControllerConvertPullIntoDescriptor(r);"default"===r.readerType?readableStreamFulfillReadRequest(e,a,t):readableStreamFulfillReadIntoRequest(e,a,t)}function readableByteStreamControllerConvertPullIntoDescriptor(e){const{bytesFilled:r,elementSize:t}=e;return new e.ctor(e.buffer,e.byteOffset,r/t)}function readableByteStreamControllerEnqueue(e,r){const t=e[controlledReadableByteStream_],{buffer:a,byteOffset:o,byteLength:l}=r,n=transferArrayBuffer(a);if(readableStreamHasDefaultReader(t))if(0===readableStreamGetNumReadRequests(t))readableByteStreamControllerEnqueueChunkToQueue(e,n,o,l);else{readableStreamFulfillReadRequest(t,new Uint8Array(n,o,l),!1)}else readableStreamHasBYOBReader(t)?(readableByteStreamControllerEnqueueChunkToQueue(e,n,o,l),readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(e)):readableByteStreamControllerEnqueueChunkToQueue(e,n,o,l);readableByteStreamControllerCallPullIfNeeded(e)}function readableByteStreamControllerEnqueueChunkToQueue(e,r,t,a){e[queue_].push({buffer:r,byteOffset:t,byteLength:a}),e[queueTotalSize_]+=a}function readableByteStreamControllerError(e,r){const t=e[controlledReadableByteStream_];"readable"===t[state_]&&(readableByteStreamControllerClearPendingPullIntos(e),resetQueue(e),readableByteStreamControllerClearAlgorithms(e),readableStreamError(t,r))}function readableByteStreamControllerFillHeadPullIntoDescriptor(e,r,t){readableByteStreamControllerInvalidateBYOBRequest(e),t.bytesFilled+=r}function readableByteStreamControllerFillPullIntoDescriptorFromQueue(e,r){const t=r.elementSize,a=r.bytesFilled-r.bytesFilled%t,o=Math.min(e[queueTotalSize_],r.byteLength-r.bytesFilled),l=r.bytesFilled+o,n=l-l%t;let i=o,s=!1;n>a&&(i=n-r.bytesFilled,s=!0);const u=e[queue_];for(;i>0;){const t=u.front(),a=Math.min(i,t.byteLength),o=r.byteOffset+r.bytesFilled;copyDataBlockBytes(r.buffer,o,t.buffer,t.byteOffset,a),t.byteLength===a?u.shift():(t.byteOffset+=a,t.byteLength-=a),e[queueTotalSize_]-=a,readableByteStreamControllerFillHeadPullIntoDescriptor(e,a,r),i-=a}return s}function readableByteStreamControllerGetDesiredSize(e){const r=e[controlledReadableByteStream_][state_];return"errored"===r?null:"closed"===r?0:e[strategyHWM_]-e[queueTotalSize_]}function readableByteStreamControllerHandleQueueDrain(e){0===e[queueTotalSize_]&&e[closeRequested_]?(readableByteStreamControllerClearAlgorithms(e),readableStreamClose(e[controlledReadableByteStream_])):readableByteStreamControllerCallPullIfNeeded(e)}function readableByteStreamControllerInvalidateBYOBRequest(e){const r=e[byobRequest_];void 0!==r&&(r[associatedReadableByteStreamController_]=void 0,r[view_]=void 0,e[byobRequest_]=void 0)}function readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(e){const r=e[pendingPullIntos_];for(;r.length>0;){if(0===e[queueTotalSize_])return;const t=r[0];readableByteStreamControllerFillPullIntoDescriptorFromQueue(e,t)&&(readableByteStreamControllerShiftPendingPullInto(e),readableByteStreamControllerCommitPullIntoDescriptor(e[controlledReadableByteStream_],t))}}function readableByteStreamControllerPullInto(e,r,t){const a=e[controlledReadableByteStream_],o=r.BYTES_PER_ELEMENT||1,l=r.constructor,n=r.byteOffset,i=r.byteLength,s={buffer:transferArrayBuffer(r.buffer),byteOffset:n,byteLength:i,bytesFilled:0,elementSize:o,ctor:l,readerType:"byob"};if(e[pendingPullIntos_].length>0)return e[pendingPullIntos_].push(s),readableStreamAddReadIntoRequest(a,t);if("closed"===a[state_]){const e=new l(s.buffer,s.byteOffset,0);return Promise.resolve(readableStreamCreateReadResult(e,!0,t))}if(e[queueTotalSize_]>0){if(readableByteStreamControllerFillPullIntoDescriptorFromQueue(e,s)){const r=readableByteStreamControllerConvertPullIntoDescriptor(s);return readableByteStreamControllerHandleQueueDrain(e),Promise.resolve(readableStreamCreateReadResult(r,!1,t))}if(e[closeRequested_]){const r=new TypeError;return readableByteStreamControllerError(e,r),Promise.reject(r)}}e[pendingPullIntos_].push(s);const u=readableStreamAddReadIntoRequest(a,t);return readableByteStreamControllerCallPullIfNeeded(e),u}function readableByteStreamControllerRespond(e,r){if(!isFiniteNonNegativeNumber(r=Number(r)))throw new RangeError("bytesWritten must be a finite, non-negative number");readableByteStreamControllerRespondInternal(e,r)}function readableByteStreamControllerRespondInClosedState(e,r){r.buffer=transferArrayBuffer(r.buffer);const t=e[controlledReadableByteStream_];if(readableStreamHasBYOBReader(t))for(;readableStreamGetNumReadIntoRequests(t)>0;){readableByteStreamControllerCommitPullIntoDescriptor(t,readableByteStreamControllerShiftPendingPullInto(e))}}function readableByteStreamControllerRespondInReadableState(e,r,t){if(t.bytesFilled+r>t.byteLength)throw new RangeError;if(readableByteStreamControllerFillHeadPullIntoDescriptor(e,r,t),t.bytesFilled<t.elementSize)return;readableByteStreamControllerShiftPendingPullInto(e);const a=t.bytesFilled%t.elementSize;if(a>0){const r=t.byteOffset+t.bytesFilled,o=cloneArrayBuffer(t.buffer,r-a,a,ArrayBuffer);readableByteStreamControllerEnqueueChunkToQueue(e,o,0,o.byteLength)}t.buffer=transferArrayBuffer(t.buffer),t.bytesFilled=t.bytesFilled-a,readableByteStreamControllerCommitPullIntoDescriptor(e[controlledReadableByteStream_],t),readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(e)}function readableByteStreamControllerRespondInternal(e,r){const t=e[pendingPullIntos_][0];if("closed"===e[controlledReadableByteStream_][state_]){if(0!==r)throw new TypeError;readableByteStreamControllerRespondInClosedState(e,t)}else readableByteStreamControllerRespondInReadableState(e,r,t);readableByteStreamControllerCallPullIfNeeded(e)}function readableByteStreamControllerRespondWithNewView(e,r){const t=e[pendingPullIntos_][0];if(t.byteOffset+t.bytesFilled!==r.byteOffset)throw new RangeError;if(t.byteLength!==r.byteLength)throw new RangeError;t.buffer=r.buffer,readableByteStreamControllerRespondInternal(e,r.byteLength)}function readableByteStreamControllerShiftPendingPullInto(e){const r=e[pendingPullIntos_].shift();return readableByteStreamControllerInvalidateBYOBRequest(e),r}function readableByteStreamControllerShouldCallPull(e){const r=e[controlledReadableByteStream_];return"readable"===r[state_]&&(!e[closeRequested_]&&(!!e[started_]&&(!!(readableStreamHasDefaultReader(r)&&readableStreamGetNumReadRequests(r)>0)||(!!(readableStreamHasBYOBReader(r)&&readableStreamGetNumReadIntoRequests(r)>0)||readableByteStreamControllerGetDesiredSize(e)>0))))}function setUpReadableStreamBYOBRequest(e,r,t){if(!isReadableByteStreamController(r))throw new TypeError;if(!ArrayBuffer.isView(t))throw new TypeError;e[associatedReadableByteStreamController_]=r,e[view_]=t}const backpressure_=Symbol("backpressure_"),closeRequest_=Symbol("closeRequest_"),inFlightWriteRequest_=Symbol("inFlightWriteRequest_"),inFlightCloseRequest_=Symbol("inFlightCloseRequest_"),pendingAbortRequest_=Symbol("pendingAbortRequest_"),writableStreamController_=Symbol("writableStreamController_"),writer_=Symbol("writer_"),writeRequests_=Symbol("writeRequests_"),abortAlgorithm_=Symbol("abortAlgorithm_"),closeAlgorithm_=Symbol("closeAlgorithm_"),controlledWritableStream_=Symbol("controlledWritableStream_"),started_$1=Symbol("started_"),strategyHWM_$1=Symbol("strategyHWM_"),strategySizeAlgorithm_$1=Symbol("strategySizeAlgorithm_"),writeAlgorithm_=Symbol("writeAlgorithm_"),ownerWritableStream_=Symbol("ownerWritableStream_"),closedPromise_$1=Symbol("closedPromise_"),readyPromise_=Symbol("readyPromise_"),errorSteps_=Symbol("errorSteps_"),abortSteps_=Symbol("abortSteps_");function initializeWritableStream(e){e[state_]="writable",e[storedError_]=void 0,e[writer_]=void 0,e[writableStreamController_]=void 0,e[inFlightWriteRequest_]=void 0,e[closeRequest_]=void 0,e[inFlightCloseRequest_]=void 0,e[pendingAbortRequest_]=void 0,e[writeRequests_]=[],e[backpressure_]=!1}function isWritableStream(e){return null!=e&&"object"==typeof e&&writableStreamController_ in e}function isWritableStreamLocked(e){return void 0!==e[writer_]}function writableStreamAbort(e,r){const t=e[state_];if("closed"===t||"errored"===t)return Promise.resolve(void 0);let a=e[pendingAbortRequest_];if(void 0!==a)return a.promise;let o=!1;"erroring"===t&&(o=!0,r=void 0),a={reason:r,wasAlreadyErroring:o};const l=new Promise((e,r)=>{a.resolve=e,a.reject=r});return a.promise=l,e[pendingAbortRequest_]=a,o||writableStreamStartErroring(e,r),l}function writableStreamAddWriteRequest(e){const r=createControlledPromise();return e[writeRequests_].push(r),r.promise}function writableStreamDealWithRejection(e,r){"writable"!==e[state_]?writableStreamFinishErroring(e):writableStreamStartErroring(e,r)}function writableStreamStartErroring(e,r){const t=e[writableStreamController_];e[state_]="erroring",e[storedError_]=r;const a=e[writer_];void 0!==a&&writableStreamDefaultWriterEnsureReadyPromiseRejected(a,r),!writableStreamHasOperationMarkedInFlight(e)&&t[started_$1]&&writableStreamFinishErroring(e)}function writableStreamFinishErroring(e){e[state_]="errored";const r=e[writableStreamController_];r[errorSteps_]();const t=e[storedError_];for(const o of e[writeRequests_])o.reject(t);e[writeRequests_]=[];const a=e[pendingAbortRequest_];if(void 0!==a)return e[pendingAbortRequest_]=void 0,a.wasAlreadyErroring?(a.reject(t),void writableStreamRejectCloseAndClosedPromiseIfNeeded(e)):void r[abortSteps_](a.reason).then(r=>{a.resolve(),writableStreamRejectCloseAndClosedPromiseIfNeeded(e)},r=>{a.reject(r),writableStreamRejectCloseAndClosedPromiseIfNeeded(e)});writableStreamRejectCloseAndClosedPromiseIfNeeded(e)}function writableStreamFinishInFlightWrite(e){e[inFlightWriteRequest_].resolve(void 0),e[inFlightWriteRequest_]=void 0}function writableStreamFinishInFlightWriteWithError(e,r){e[inFlightWriteRequest_].reject(r),e[inFlightWriteRequest_]=void 0,writableStreamDealWithRejection(e,r)}function writableStreamFinishInFlightClose(e){e[inFlightCloseRequest_].resolve(void 0),e[inFlightCloseRequest_]=void 0,"erroring"===e[state_]&&(e[storedError_]=void 0,void 0!==e[pendingAbortRequest_]&&(e[pendingAbortRequest_].resolve(),e[pendingAbortRequest_]=void 0)),e[state_]="closed";const r=e[writer_];void 0!==r&&r[closedPromise_$1].resolve(void 0)}function writableStreamFinishInFlightCloseWithError(e,r){e[inFlightCloseRequest_].reject(r),e[inFlightCloseRequest_]=void 0,void 0!==e[pendingAbortRequest_]&&(e[pendingAbortRequest_].reject(r),e[pendingAbortRequest_]=void 0),writableStreamDealWithRejection(e,r)}function writableStreamCloseQueuedOrInFlight(e){return void 0!==e[closeRequest_]||void 0!==e[inFlightCloseRequest_]}function writableStreamHasOperationMarkedInFlight(e){return void 0!==e[inFlightWriteRequest_]||void 0!==e[inFlightCloseRequest_]}function writableStreamMarkCloseRequestInFlight(e){e[inFlightCloseRequest_]=e[closeRequest_],e[closeRequest_]=void 0}function writableStreamMarkFirstWriteRequestInFlight(e){const r=e[writeRequests_].shift();e[inFlightWriteRequest_]=r}function writableStreamRejectCloseAndClosedPromiseIfNeeded(e){const r=e[closeRequest_];void 0!==r&&(r.reject(e[storedError_]),e[closeRequest_]=void 0);const t=e[writer_];void 0!==t&&(t[closedPromise_$1].reject(e[storedError_]),t[closedPromise_$1].promise.catch(()=>{}))}function writableStreamUpdateBackpressure(e,r){const t=e[writer_];void 0!==t&&r!==e[backpressure_]&&(r?t[readyPromise_]=createControlledPromise():t[readyPromise_].resolve(void 0)),e[backpressure_]=r}function isWritableStreamDefaultWriter(e){return null!=e&&"object"==typeof e&&ownerWritableStream_ in e}function writableStreamDefaultWriterAbort(e,r){return writableStreamAbort(e[ownerWritableStream_],r)}function writableStreamDefaultWriterClose(e){const r=e[ownerWritableStream_],t=r[state_];if("closed"===t||"errored"===t)return Promise.reject(new TypeError("Writer stream is already closed or errored"));const a=createControlledPromise();return r[closeRequest_]=a,r[backpressure_]&&"writable"===t&&e[readyPromise_].resolve(void 0),writableStreamDefaultControllerClose(r[writableStreamController_]),a.promise}function writableStreamDefaultWriterCloseWithErrorPropagation(e){const r=e[ownerWritableStream_],t=r[state_];return writableStreamCloseQueuedOrInFlight(r)||"closed"===t?Promise.resolve(void 0):"errored"===t?Promise.reject(r[storedError_]):writableStreamDefaultWriterClose(e)}function writableStreamDefaultWriterEnsureClosedPromiseRejected(e,r){const t=e[closedPromise_$1];t.state===ControlledPromiseState.Pending?t.reject(r):(e[closedPromise_$1]=createControlledPromise(),e[closedPromise_$1].reject(r)),e[closedPromise_$1].promise.catch(()=>{})}function writableStreamDefaultWriterEnsureReadyPromiseRejected(e,r){const t=e[readyPromise_];t.state===ControlledPromiseState.Pending?t.reject(r):(e[readyPromise_]=createControlledPromise(),e[readyPromise_].reject(r)),e[readyPromise_].promise.catch(()=>{})}function writableStreamDefaultWriterGetDesiredSize(e){const r=e[ownerWritableStream_],t=r[state_];return"errored"===t||"erroring"===t?null:"closed"===t?0:writableStreamDefaultControllerGetDesiredSize(r[writableStreamController_])}function writableStreamDefaultWriterRelease(e){const r=e[ownerWritableStream_],t=new TypeError;writableStreamDefaultWriterEnsureReadyPromiseRejected(e,t),writableStreamDefaultWriterEnsureClosedPromiseRejected(e,t),r[writer_]=void 0,e[ownerWritableStream_]=void 0}function writableStreamDefaultWriterWrite(e,r){const t=e[ownerWritableStream_],a=t[writableStreamController_],o=writableStreamDefaultControllerGetChunkSize(a,r);if(e[ownerWritableStream_]!==t)return Promise.reject(new TypeError);const l=t[state_];if("errored"===l)return Promise.reject(t[storedError_]);if(writableStreamCloseQueuedOrInFlight(t)||"closed"===l)return Promise.reject(new TypeError("Cannot write to a closing or closed stream"));if("erroring"===l)return Promise.reject(t[storedError_]);const n=writableStreamAddWriteRequest(t);return writableStreamDefaultControllerWrite(a,r,o),n}function setUpWritableStreamDefaultController(e,r,t,a,o,l,n,i){if(!isWritableStream(e))throw new TypeError;if(void 0!==e[writableStreamController_])throw new TypeError;r[controlledWritableStream_]=e,e[writableStreamController_]=r,resetQueue(r),r[started_$1]=!1,r[strategySizeAlgorithm_$1]=i,r[strategyHWM_$1]=n,r[writeAlgorithm_]=a,r[closeAlgorithm_]=o,r[abortAlgorithm_]=l;const s=writableStreamDefaultControllerGetBackpressure(r);writableStreamUpdateBackpressure(e,s);const u=t();Promise.resolve(u).then(e=>{r[started_$1]=!0,writableStreamDefaultControllerAdvanceQueueIfNeeded(r)},t=>{r[started_$1]=!0,writableStreamDealWithRejection(e,t)})}function isWritableStreamDefaultController(e){return null!=e&&"object"==typeof e&&controlledWritableStream_ in e}function writableStreamDefaultControllerClearAlgorithms(e){e[writeAlgorithm_]=void 0,e[closeAlgorithm_]=void 0,e[abortAlgorithm_]=void 0,e[strategySizeAlgorithm_$1]=void 0}function writableStreamDefaultControllerClose(e){enqueueValueWithSize(e,"close",0),writableStreamDefaultControllerAdvanceQueueIfNeeded(e)}function writableStreamDefaultControllerGetChunkSize(e,r){let t;try{t=e[strategySizeAlgorithm_$1](r)}catch(r){writableStreamDefaultControllerErrorIfNeeded(e,r),t=1}return t}function writableStreamDefaultControllerGetDesiredSize(e){return e[strategyHWM_$1]-e[queueTotalSize_]}function writableStreamDefaultControllerWrite(e,r,t){try{enqueueValueWithSize(e,{chunk:r},t)}catch(r){return void writableStreamDefaultControllerErrorIfNeeded(e,r)}const a=e[controlledWritableStream_];if(!writableStreamCloseQueuedOrInFlight(a)&&"writable"===a[state_]){writableStreamUpdateBackpressure(a,writableStreamDefaultControllerGetBackpressure(e))}writableStreamDefaultControllerAdvanceQueueIfNeeded(e)}function writableStreamDefaultControllerAdvanceQueueIfNeeded(e){if(!e[started_$1])return;const r=e[controlledWritableStream_];if(void 0!==r[inFlightWriteRequest_])return;const t=r[state_];if("closed"===t||"errored"===t)return;if("erroring"===t)return void writableStreamFinishErroring(r);if(0===e[queue_].length)return;const a=peekQueueValue(e);"close"===a?writableStreamDefaultControllerProcessClose(e):writableStreamDefaultControllerProcessWrite(e,a.chunk)}function writableStreamDefaultControllerErrorIfNeeded(e,r){"writable"===e[controlledWritableStream_][state_]&&writableStreamDefaultControllerError(e,r)}function writableStreamDefaultControllerProcessClose(e){const r=e[controlledWritableStream_];writableStreamMarkCloseRequestInFlight(r),dequeueValue(e);const t=e[closeAlgorithm_]();writableStreamDefaultControllerClearAlgorithms(e),t.then(e=>{writableStreamFinishInFlightClose(r)},e=>{writableStreamFinishInFlightCloseWithError(r,e)})}function writableStreamDefaultControllerProcessWrite(e,r){const t=e[controlledWritableStream_];writableStreamMarkFirstWriteRequestInFlight(t),e[writeAlgorithm_](r).then(r=>{writableStreamFinishInFlightWrite(t);const a=t[state_];if(dequeueValue(e),!writableStreamCloseQueuedOrInFlight(t)&&"writable"===a){const r=writableStreamDefaultControllerGetBackpressure(e);writableStreamUpdateBackpressure(t,r)}writableStreamDefaultControllerAdvanceQueueIfNeeded(e)},r=>{"writable"===t[state_]&&writableStreamDefaultControllerClearAlgorithms(e),writableStreamFinishInFlightWriteWithError(t,r)})}function writableStreamDefaultControllerGetBackpressure(e){return writableStreamDefaultControllerGetDesiredSize(e)<=0}function writableStreamDefaultControllerError(e,r){const t=e[controlledWritableStream_];writableStreamDefaultControllerClearAlgorithms(e),writableStreamStartErroring(t,r)}class ReadableStreamDefaultReader{constructor(e){if(!isReadableStream(e))throw new TypeError;if(isReadableStreamLocked(e))throw new TypeError("The stream is locked.");readableStreamReaderGenericInitialize(this,e),this[readRequests_]=[]}get closed(){return isReadableStreamDefaultReader(this)?this[closedPromise_].promise:Promise.reject(new TypeError)}cancel(e){if(!isReadableStreamDefaultReader(this))return Promise.reject(new TypeError);const r=this[ownerReadableStream_];return void 0===r?Promise.reject(new TypeError("Reader is not associated with a stream")):readableStreamCancel(r,e)}read(){return isReadableStreamDefaultReader(this)?void 0===this[ownerReadableStream_]?Promise.reject(new TypeError("Reader is not associated with a stream")):readableStreamDefaultReaderRead(this,!0):Promise.reject(new TypeError)}releaseLock(){if(!isReadableStreamDefaultReader(this))throw new TypeError;if(void 0!==this[ownerReadableStream_]){if(0!==this[readRequests_].length)throw new TypeError("Cannot release a stream with pending read requests");readableStreamReaderGenericRelease(this)}}}class WritableStreamDefaultWriter{constructor(e){if(!isWritableStream(e))throw new TypeError;if(isWritableStreamLocked(e))throw new TypeError("Stream is already locked");this[ownerWritableStream_]=e,e[writer_]=this;const r=createControlledPromise(),t=createControlledPromise();this[readyPromise_]=r,this[closedPromise_$1]=t;const a=e[state_];if("writable"===a)!writableStreamCloseQueuedOrInFlight(e)&&e[backpressure_]||r.resolve(void 0);else if("erroring"===a)r.reject(e[storedError_]),r.promise.catch(()=>{});else if("closed"===a)r.resolve(void 0),t.resolve(void 0);else{const a=e[storedError_];r.reject(a),r.promise.catch(()=>{}),t.reject(a),t.promise.catch(()=>{})}}abort(e){return isWritableStreamDefaultWriter(this)?void 0===this[ownerWritableStream_]?Promise.reject(new TypeError("Writer is not connected to a stream")):writableStreamDefaultWriterAbort(this,e):Promise.reject(new TypeError)}close(){if(!isWritableStreamDefaultWriter(this))return Promise.reject(new TypeError);const e=this[ownerWritableStream_];return void 0===e?Promise.reject(new TypeError("Writer is not connected to a stream")):writableStreamCloseQueuedOrInFlight(e)?Promise.reject(new TypeError):writableStreamDefaultWriterClose(this)}releaseLock(){void 0!==this[ownerWritableStream_]&&writableStreamDefaultWriterRelease(this)}write(e){return isWritableStreamDefaultWriter(this)?void 0===this[ownerWritableStream_]?Promise.reject(new TypeError("Writer is not connected to a stream")):writableStreamDefaultWriterWrite(this,e):Promise.reject(new TypeError)}get closed(){return isWritableStreamDefaultWriter(this)?this[closedPromise_$1].promise:Promise.reject(new TypeError)}get desiredSize(){if(!isWritableStreamDefaultWriter(this))throw new TypeError;if(void 0===this[ownerWritableStream_])throw new TypeError("Writer is not connected to stream");return writableStreamDefaultWriterGetDesiredSize(this)}get ready(){return isWritableStreamDefaultWriter(this)?this[readyPromise_].promise:Promise.reject(new TypeError)}}function pipeTo(e,r,t){const a=!!t.preventClose,o=!!t.preventAbort,l=!!t.preventCancel;let n=!1,i=Promise.resolve();const s=createControlledPromise(),u=new ReadableStreamDefaultReader(e),d=new WritableStreamDefaultWriter(r);function m(e,r,t){"errored"===e[state_]?t(e[storedError_]):r.catch(t)}if(m(e,u[closedPromise_].promise,e=>{b(o?void 0:()=>writableStreamAbort(r,e),{actualError:e})}),m(r,d[closedPromise_$1].promise,r=>{b(l?void 0:()=>readableStreamCancel(e,r),{actualError:r})}),function(e,r,t){"closed"===e[state_]?t():r.then(t)}(e,u[closedPromise_].promise,()=>{a?b():b(()=>writableStreamDefaultWriterCloseWithErrorPropagation(d))}),writableStreamCloseQueuedOrInFlight(r)||"closed"===r[state_]){const r=new TypeError;b(l?void 0:()=>readableStreamCancel(e,r),{actualError:r})}function c(){return"writable"!==r[state_]||writableStreamCloseQueuedOrInFlight(r)?void 0:function e(){const r=i;return i.then(()=>r===i?void 0:e())}()}function b(e,r){if(n)return;function t(){e().then(e=>f(r),e=>f({actualError:e}))}n=!0,void 0===e&&(e=(()=>Promise.resolve()));const a=c();a?a.then(t):t()}function f(e){writableStreamDefaultWriterRelease(d),readableStreamReaderGenericRelease(u),e?s.reject(e.actualError):s.resolve(void 0)}return function e(){n||d[readyPromise_].promise.then(()=>{readableStreamDefaultReaderRead(u).then(({value:r,done:t})=>{t||(i=writableStreamDefaultWriterWrite(d,r).catch(()=>{}),e())},e=>{i=Promise.resolve()})})}(),s.promise}class ReadableStreamDefaultController{constructor(){throw new TypeError}get desiredSize(){return readableStreamDefaultControllerGetDesiredSize(this)}close(){if(!isReadableStreamDefaultController(this))throw new TypeError;if(!readableStreamDefaultControllerCanCloseOrEnqueue(this))throw new TypeError("Cannot close, the stream is already closing or not readable");readableStreamDefaultControllerClose(this)}enqueue(e){if(!isReadableStreamDefaultController(this))throw new TypeError;if(!readableStreamDefaultControllerCanCloseOrEnqueue(this))throw new TypeError("Cannot enqueue, the stream is closing or not readable");readableStreamDefaultControllerEnqueue(this,e)}error(e){if(!isReadableStreamDefaultController(this))throw new TypeError;readableStreamDefaultControllerError(this,e)}[cancelSteps_](e){resetQueue(this);const r=this[cancelAlgorithm_](e);return readableStreamDefaultControllerClearAlgorithms(this),r}[pullSteps_](e){const r=this[controlledReadableStream_];if(this[queue_].length>0){const t=dequeueValue(this);return this[closeRequested_]&&0===this[queue_].length?(readableStreamDefaultControllerClearAlgorithms(this),readableStreamClose(r)):readableStreamDefaultControllerCallPullIfNeeded(this),Promise.resolve(readableStreamCreateReadResult(t,!1,e))}const t=readableStreamAddReadRequest(r,e);return readableStreamDefaultControllerCallPullIfNeeded(this),t}}function setUpReadableStreamDefaultControllerFromUnderlyingSource(e,r,t,a){const o=Object.create(ReadableStreamDefaultController.prototype),l=createAlgorithmFromUnderlyingMethod(r,"pull",[o]),n=createAlgorithmFromUnderlyingMethod(r,"cancel",[]);setUpReadableStreamDefaultController(e,o,()=>invokeOrNoop(r,"start",[o]),l,n,t,a)}class ReadableStreamBYOBRequest{constructor(){throw new TypeError}get view(){if(!isReadableStreamBYOBRequest(this))throw new TypeError;return this[view_]}respond(e){if(!isReadableStreamBYOBRequest(this))throw new TypeError;if(void 0===this[associatedReadableByteStreamController_])throw new TypeError;return readableByteStreamControllerRespond(this[associatedReadableByteStreamController_],e)}respondWithNewView(e){if(!isReadableStreamBYOBRequest(this))throw new TypeError;if(void 0===this[associatedReadableByteStreamController_])throw new TypeError;if(!ArrayBuffer.isView(e))throw new TypeError("view parameter must be a TypedArray");return readableByteStreamControllerRespondWithNewView(this[associatedReadableByteStreamController_],e)}}class ReadableByteStreamController{constructor(){throw new TypeError}get byobRequest(){if(!isReadableByteStreamController(this))throw new TypeError;if(void 0===this[byobRequest_]&&this[pendingPullIntos_].length>0){const e=this[pendingPullIntos_][0],r=new Uint8Array(e.buffer,e.byteOffset+e.bytesFilled,e.byteLength-e.bytesFilled),t=Object.create(ReadableStreamBYOBRequest.prototype);setUpReadableStreamBYOBRequest(t,this,r),this[byobRequest_]=t}return this[byobRequest_]}get desiredSize(){if(!isReadableByteStreamController(this))throw new TypeError;return readableByteStreamControllerGetDesiredSize(this)}close(){if(!isReadableByteStreamController(this))throw new TypeError;if(this[closeRequested_])throw new TypeError("Stream is already closing");if("readable"!==this[controlledReadableByteStream_][state_])throw new TypeError("Stream is closed or errored");readableByteStreamControllerClose(this)}enqueue(e){if(!isReadableByteStreamController(this))throw new TypeError;if(this[closeRequested_])throw new TypeError("Stream is already closing");if("readable"!==this[controlledReadableByteStream_][state_])throw new TypeError("Stream is closed or errored");if(!ArrayBuffer.isView(e))throw new TypeError("chunk must be a valid ArrayBufferView");return readableByteStreamControllerEnqueue(this,e)}error(e){if(!isReadableByteStreamController(this))throw new TypeError;readableByteStreamControllerError(this,e)}[cancelSteps_](e){if(this[pendingPullIntos_].length>0){this[pendingPullIntos_][0].bytesFilled=0}resetQueue(this);const r=this[cancelAlgorithm_](e);return readableByteStreamControllerClearAlgorithms(this),r}[pullSteps_](e){const r=this[controlledReadableByteStream_];if(this[queueTotalSize_]>0){const r=this[queue_].shift();this[queueTotalSize_]-=r.byteLength,readableByteStreamControllerHandleQueueDrain(this);const t=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);return Promise.resolve(readableStreamCreateReadResult(t,!1,e))}const t=this[autoAllocateChunkSize_];if(void 0!==t){let e;try{e=new ArrayBuffer(t)}catch(e){return Promise.reject(e)}const r={buffer:e,byteOffset:0,byteLength:t,bytesFilled:0,elementSize:1,ctor:Uint8Array,readerType:"default"};this[pendingPullIntos_].push(r)}const a=readableStreamAddReadRequest(r,e);return readableByteStreamControllerCallPullIfNeeded(this),a}}function setUpReadableByteStreamControllerFromUnderlyingSource(e,r,t){const a=Object.create(ReadableByteStreamController.prototype),o=createAlgorithmFromUnderlyingMethod(r,"pull",[a]),l=createAlgorithmFromUnderlyingMethod(r,"cancel",[]);let n=r.autoAllocateChunkSize;if(void 0!==n&&(!isInteger(n=Number(n))||n<=0))throw new RangeError("autoAllocateChunkSize must be a positive, finite integer");setUpReadableByteStreamController(e,a,()=>invokeOrNoop(r,"start",[a]),o,l,t,n)}class ReadableStreamBYOBReader{constructor(e){if(!isReadableStream(e))throw new TypeError;if(!isReadableByteStreamController(e[readableStreamController_]))throw new TypeError;if(isReadableStreamLocked(e))throw new TypeError("The stream is locked.");readableStreamReaderGenericInitialize(this,e),this[readIntoRequests_]=[]}get closed(){return isReadableStreamBYOBReader(this)?this[closedPromise_].promise:Promise.reject(new TypeError)}cancel(e){if(!isReadableStreamBYOBReader(this))return Promise.reject(new TypeError);const r=this[ownerReadableStream_];return void 0===r?Promise.reject(new TypeError("Reader is not associated with a stream")):readableStreamCancel(r,e)}read(e){return isReadableStreamBYOBReader(this)?void 0===this[ownerReadableStream_]?Promise.reject(new TypeError("Reader is not associated with a stream")):ArrayBuffer.isView(e)?0===e.byteLength?Promise.reject(new TypeError("supplied buffer view must be > 0 bytes")):readableStreamBYOBReaderRead(this,e,!0):Promise.reject(new TypeError("view argument must be a valid ArrayBufferView")):Promise.reject(new TypeError)}releaseLock(){if(!isReadableStreamBYOBReader(this))throw new TypeError;if(void 0===this[ownerReadableStream_])throw new TypeError("Reader is not associated with a stream");if(this[readIntoRequests_].length>0)throw new TypeError;readableStreamReaderGenericRelease(this)}}class ReadableStream{constructor(e={},r={}){initializeReadableStream(this);const t=r.size,a=r.highWaterMark,o=e.type;if(void 0===o){const r=makeSizeAlgorithmFromSizeFunction(t);setUpReadableStreamDefaultControllerFromUnderlyingSource(this,e,validateAndNormalizeHighWaterMark(void 0===a?1:a),r)}else{if("bytes"!==String(o))throw new RangeError("The underlying source's `type` field must be undefined or 'bytes'");if(void 0!==t)throw new RangeError("bytes streams cannot have a strategy with a `size` field");setUpReadableByteStreamControllerFromUnderlyingSource(this,e,validateAndNormalizeHighWaterMark(void 0===a?0:a))}}get locked(){return isReadableStreamLocked(this)}getReader(e={}){if(!isReadableStream(this))throw new TypeError;const{mode:r}=e;if(void 0===r)return new ReadableStreamDefaultReader(this);if("byob"===String(r))return new ReadableStreamBYOBReader(this);throw RangeError("mode option must be undefined or `byob`")}cancel(e){return isReadableStream(this)?isReadableStreamLocked(this)?Promise.reject(new TypeError("Cannot cancel a locked stream")):readableStreamCancel(this,e):Promise.reject(new TypeError)}tee(){if(!isReadableStream(this))throw new TypeError;const e=new ReadableStreamDefaultReader(this);let r,t,a,o,l,n=!1,i=!1,s=!1;const u=new Promise(e=>l=e),d=()=>readableStreamDefaultReaderRead(e).then(({value:e,done:r})=>{if(r&&!n&&(i||readableStreamDefaultControllerClose(a[readableStreamController_]),s||readableStreamDefaultControllerClose(o[readableStreamController_]),n=!0),n)return;const t=e,l=e;i||readableStreamDefaultControllerEnqueue(a[readableStreamController_],t),s||readableStreamDefaultControllerEnqueue(o[readableStreamController_],l)}),m=()=>void 0;return a=createReadableStream(m,d,e=>{if(i=!0,r=e,s){const e=readableStreamCancel(this,[r,t]);l(e)}return u}),o=createReadableStream(m,d,e=>{if(s=!0,t=e,i){const e=readableStreamCancel(this,[r,t]);l(e)}return u}),e[closedPromise_].promise.catch(e=>{n||(readableStreamDefaultControllerError(a[readableStreamController_],e),readableStreamDefaultControllerError(o[readableStreamController_],e),n=!0)}),[a,o]}pipeThrough(e,r){const{readable:t,writable:a}=e;if(void 0===t||void 0===a)throw new TypeError("Both a readable and writable stream must be provided");const o=this.pipeTo(a,r);try{Promise.prototype.then.call(o,void 0,()=>{})}catch(e){}return t}pipeTo(e,r={}){return isReadableStream(this)&&isWritableStream(e)?isReadableStreamLocked(this)?Promise.reject(new TypeError("Cannot pipe from a locked stream")):isWritableStreamLocked(e)?Promise.reject(new TypeError("Cannot pipe to a locked stream")):pipeTo(this,e,r):Promise.reject(new TypeError)}}function createReadableStream(e,r,t,a,o){void 0===a&&(a=1),void 0===o&&(o=(()=>1));const l=Object.create(ReadableStream.prototype);return initializeReadableStream(l),setUpReadableStreamDefaultController(l,Object.create(ReadableStreamDefaultController.prototype),e,r,t,a,o),l}class WritableStreamDefaultController{constructor(){throw new TypeError}error(e){if(!isWritableStreamDefaultController(this))throw new TypeError;"writable"===this[controlledWritableStream_][state_]&&writableStreamDefaultControllerError(this,e)}[abortSteps_](e){const r=this[abortAlgorithm_](e);return writableStreamDefaultControllerClearAlgorithms(this),r}[errorSteps_](){resetQueue(this)}}function setUpWritableStreamDefaultControllerFromUnderlyingSink(e,r,t,a){const o=Object.create(WritableStreamDefaultController.prototype),l=createAlgorithmFromUnderlyingMethod(r,"write",[o]),n=createAlgorithmFromUnderlyingMethod(r,"close",[]),i=createAlgorithmFromUnderlyingMethod(r,"abort",[]);setUpWritableStreamDefaultController(e,o,function(){return invokeOrNoop(r,"start",[o])},l,n,i,t,a)}class WritableStream{constructor(e={},r={}){initializeWritableStream(this);const t=r.size,a=r.highWaterMark;if(void 0!==e.type)throw new RangeError("The type of an underlying sink must be undefined");const o=makeSizeAlgorithmFromSizeFunction(t);setUpWritableStreamDefaultControllerFromUnderlyingSink(this,e,validateAndNormalizeHighWaterMark(void 0===a?1:a),o)}get locked(){if(!isWritableStream(this))throw new TypeError;return isWritableStreamLocked(this)}abort(e){return isWritableStream(this)?isWritableStreamLocked(this)?Promise.reject(new TypeError("Cannot abort a locked stream")):writableStreamAbort(this,e):Promise.reject(new TypeError)}getWriter(){if(!isWritableStream(this))throw new TypeError;return new WritableStreamDefaultWriter(this)}}function createWritableStream(e,r,t,a,o,l){void 0===o&&(o=1),void 0===l&&(l=(()=>1));const n=Object.create(WritableStream.prototype);return initializeWritableStream(n),setUpWritableStreamDefaultController(n,Object.create(WritableStreamDefaultController.prototype),e,r,t,a,o,l),n}const backpressure_$1=Symbol("backpressure_"),backpressureChangePromise_=Symbol("backpressureChangePromise_"),readable_=Symbol("readable_"),transformStreamController_=Symbol("transformStreamController_"),writable_=Symbol("writable_"),controlledTransformStream_=Symbol("controlledTransformStream_"),flushAlgorithm_=Symbol("flushAlgorithm_"),transformAlgorithm_=Symbol("transformAlgorithm_");function isTransformStream(e){return null!=e&&"object"==typeof e&&transformStreamController_ in e}function initializeTransformStream(e,r,t,a,o,l){const n=function(){return r};e[writable_]=createWritableStream(n,function(r){return transformStreamDefaultSinkWriteAlgorithm(e,r)},function(){return transformStreamDefaultSinkCloseAlgorithm(e)},function(r){return transformStreamDefaultSinkAbortAlgorithm(e,r)},t,a);e[readable_]=createReadableStream(n,function(){return transformStreamDefaultSourcePullAlgorithm(e)},function(r){return transformStreamErrorWritableAndUnblockWrite(e,r),Promise.resolve(void 0)},o,l),e[backpressure_$1]=void 0,e[backpressureChangePromise_]=void 0,transformStreamSetBackpressure(e,!0),e[transformStreamController_]=void 0}function transformStreamError(e,r){readableStreamDefaultControllerError(e[readable_][readableStreamController_],r),transformStreamErrorWritableAndUnblockWrite(e,r)}function transformStreamErrorWritableAndUnblockWrite(e,r){transformStreamDefaultControllerClearAlgorithms(e[transformStreamController_]),writableStreamDefaultControllerErrorIfNeeded(e[writable_][writableStreamController_],r),e[backpressure_$1]&&transformStreamSetBackpressure(e,!1)}function transformStreamSetBackpressure(e,r){void 0!==e[backpressure_$1]&&e[backpressureChangePromise_].resolve(void 0),e[backpressureChangePromise_]=createControlledPromise(),e[backpressure_$1]=r}function isTransformStreamDefaultController(e){return null!=e&&"object"==typeof e&&controlledTransformStream_ in e}function setUpTransformStreamDefaultController(e,r,t,a){r[controlledTransformStream_]=e,e[transformStreamController_]=r,r[transformAlgorithm_]=t,r[flushAlgorithm_]=a}function transformStreamDefaultControllerClearAlgorithms(e){e[transformAlgorithm_]=void 0,e[flushAlgorithm_]=void 0}function transformStreamDefaultControllerEnqueue(e,r){const t=e[controlledTransformStream_],a=t[readable_][readableStreamController_];if(!readableStreamDefaultControllerCanCloseOrEnqueue(a))throw new TypeError;try{readableStreamDefaultControllerEnqueue(a,r)}catch(e){throw transformStreamErrorWritableAndUnblockWrite(t,e),t[readable_][storedError_]}readableStreamDefaultControllerHasBackpressure(a)!==t[backpressure_$1]&&transformStreamSetBackpressure(t,!0)}function transformStreamDefaultControllerError(e,r){transformStreamError(e[controlledTransformStream_],r)}function transformStreamDefaultControllerPerformTransform(e,r){return e[transformAlgorithm_](r).catch(r=>{throw transformStreamError(e[controlledTransformStream_],r),r})}function transformStreamDefaultControllerTerminate(e){const r=e[controlledTransformStream_],t=r[readable_][readableStreamController_];readableStreamDefaultControllerCanCloseOrEnqueue(t)&&readableStreamDefaultControllerClose(t),transformStreamErrorWritableAndUnblockWrite(r,new TypeError("The transform stream has been terminated"))}function transformStreamDefaultSinkWriteAlgorithm(e,r){const t=e[transformStreamController_];if(e[backpressure_$1]){return e[backpressureChangePromise_].promise.then(a=>{const o=e[writable_];if("erroring"===o[state_])throw o[storedError_];return transformStreamDefaultControllerPerformTransform(t,r)})}return transformStreamDefaultControllerPerformTransform(t,r)}function transformStreamDefaultSinkAbortAlgorithm(e,r){return transformStreamError(e,r),Promise.resolve(void 0)}function transformStreamDefaultSinkCloseAlgorithm(e){const r=e[readable_],t=e[transformStreamController_],a=t[flushAlgorithm_]();return transformStreamDefaultControllerClearAlgorithms(t),a.then(e=>{if("errored"===r[state_])throw r[storedError_];const t=r[readableStreamController_];readableStreamDefaultControllerCanCloseOrEnqueue(t)&&readableStreamDefaultControllerClose(t)},t=>{throw transformStreamError(e,t),r[storedError_]})}function transformStreamDefaultSourcePullAlgorithm(e){return transformStreamSetBackpressure(e,!1),e[backpressureChangePromise_].promise}class TransformStreamDefaultController{constructor(){throw new TypeError}get desiredSize(){if(!isTransformStreamDefaultController(this))throw new TypeError;return readableStreamDefaultControllerGetDesiredSize(this[controlledTransformStream_][readable_][readableStreamController_])}enqueue(e){if(!isTransformStreamDefaultController(this))throw new TypeError;transformStreamDefaultControllerEnqueue(this,e)}error(e){if(!isTransformStreamDefaultController(this))throw new TypeError;transformStreamDefaultControllerError(this,e)}terminate(){if(!isTransformStreamDefaultController(this))throw new TypeError;transformStreamDefaultControllerTerminate(this)}}class TransformStream$1{constructor(e={},r={},t={}){const a=r.size,o=r.highWaterMark,l=t.size,n=t.highWaterMark;if(void 0!==e.writableType)throw new RangeError("The transformer's `writableType` field must be undefined");const i=makeSizeAlgorithmFromSizeFunction(a),s=validateAndNormalizeHighWaterMark(void 0===o?1:o);if(void 0!==e.readableType)throw new RangeError("The transformer's `readableType` field must be undefined");const u=makeSizeAlgorithmFromSizeFunction(l),d=validateAndNormalizeHighWaterMark(void 0===n?0:n),m=createControlledPromise();initializeTransformStream(this,m.promise,s,i,d,u),setUpTransformStreamDefaultControllerFromTransformer(this,e);const c=invokeOrNoop(e,"start",[this[transformStreamController_]]);m.resolve(c)}get readable(){if(!isTransformStream(this))throw new TypeError;return this[readable_]}get writable(){if(!isTransformStream(this))throw new TypeError;return this[writable_]}}function setUpTransformStreamDefaultControllerFromTransformer(e,r){const t=Object.create(TransformStreamDefaultController.prototype);let a;const o=r.transform;if(void 0!==o){if("function"!=typeof o)throw new TypeError("`transform` field of the transformer must be a function");a=(e=>promiseCall(o,r,[e,t]))}else a=function(e){try{transformStreamDefaultControllerEnqueue(t,e)}catch(e){return Promise.reject(e)}return Promise.resolve(void 0)};const l=createAlgorithmFromUnderlyingMethod(r,"flush",[t]);setUpTransformStreamDefaultController(e,t,a,l)}class ByteLengthQueuingStrategy{constructor(e){this.highWaterMark=e.highWaterMark}size(e){return e.byteLength}}class CountQueuingStrategy{constructor(e){this.highWaterMark=e.highWaterMark}size(){return 1}}function wrapReadableStream(e,r){let t;return new r({start(r){(t=e.getReader()).closed.catch(e=>{r.error(e)})},pull:e=>t.read().then(({value:r,done:t})=>{t?e.close():e.enqueue(r)},r=>{e.error(r)}),cancel(e){t.cancel(e)}})}function getMIMETypeFromHeadersInit(e){if(void 0===e)return"";if(e instanceof Headers)return e.get("Content-Type")||"";if(Array.isArray(e)){const r=e.find(e=>Array.isArray(e)&&2===e.length&&"Content-Type"===e[0]);return r?r[1]:""}return e["Content-Type"]||""}function resolveRequestInitStream(e,r,t){if(void 0===e)return Promise.resolve(e);const a=e.body;let o;if(a&&"object"==typeof a&&(r&&a instanceof r?o=a:a instanceof t&&(o=a)),!o)return Promise.resolve(e);const l=getMIMETypeFromHeadersInit(e.headers);return readAllBytesFromStream(o.getReader(),l).then(r=>(e.body=r,e))}function createAdaptedFetch(e,r,t){return function(a,o){return resolveRequestInitStream(o,r,t).then(r=>e.call(void 0,a,r).then(e=>{if("body"in e){const r=e;let a;e=new Proxy(r,{get(e,o,l){if("body"===o)return void 0===a&&(a=wrapReadableStream(r.body,t)),a;{const r=e[o];return"function"==typeof r?function(...t){return r.apply(e,t)}:r}}})}else e.body=new t({pull:r=>e.arrayBuffer().then(e=>{r.enqueue(new Uint8Array(e)),r.close()},e=>{r.error(e)})});return e}))}}function readAllBytesFromStream(e,r){return new Promise((t,a)=>{const o=[];!function l(){e.read().then(({value:e,done:n})=>{n?function(){0===o.length&&o.push(new Uint8Array(0));const e=new Blob(o,{type:r});t(e)}():e instanceof Uint8Array?(o.push(e),l()):a(new TypeError("A ReadableStream body must only yield Uint8Array values"))},e=>{a(e)})}()})}function createResponseProxyWithStreamBody(e,r,t){const a=new e("fake",t),o=getMIMETypeFromHeadersInit(a.headers);let l,n=!1;function i(){return void 0===l&&(l=new Promise((a,l)=>{if(n=!0,r.locked)return l(new TypeError("The ReadableStream is locked"));readAllBytesFromStream(r.getReader(),o).then(r=>{a(new e(r,t))}).catch(e=>{l(e)})})),l}return new class{get type(){return a.type}get url(){return a.url}get redirected(){return a.redirected}get status(){return a.status}get ok(){return a.ok}get statusText(){return a.statusText}get headers(){return a.headers}clone(){const[a,o]=r.tee();return r=a,createResponseProxyWithStreamBody(e,o,t)}get body(){return r}get bodyUsed(){return n}arrayBuffer(){return i().then(e=>e.arrayBuffer())}blob(){return i().then(e=>e.blob())}formData(){return i().then(e=>e.formData())}json(){return i().then(e=>e.json())}text(){return i().then(e=>e.text())}}}function createAdaptedResponse(e,r,t){const a=function(a,o){if(a instanceof t){if(void 0===r||!("body"in e))return createResponseProxyWithStreamBody(e,a,o);a=wrapReadableStream(a,r)}return new e(a,o)};return a.prototype=e.prototype,a}const decDecoder=Symbol("decDecoder"),decTransform=Symbol("decTransform");class TextDecodeTransformer{constructor(e){this.decoder_=e}transform(e,r){if(!(e instanceof ArrayBuffer||ArrayBuffer.isView(e)))throw new TypeError("Input data must be a BufferSource");const t=this.decoder_.decode(e,{stream:!0});0!==t.length&&r.enqueue(t)}flush(e){const r=this.decoder_.decode();0!==r.length&&e.enqueue(r)}}class TextDecoderStream{constructor(e,r){this[decDecoder]=new TextDecoder(e,r),this[decTransform]=new TransformStream(new TextDecodeTransformer(this[decDecoder]))}get encoding(){return this[decDecoder].encoding}get fatal(){return this[decDecoder].fatal}get ignoreBOM(){return this[decDecoder].ignoreBOM}get readable(){return this[decTransform].readable}get writable(){return this[decTransform].writable}}const encEncoder=Symbol("encEncoder"),encTransform=Symbol("encTransform");class TextEncodeTransformer{constructor(e){this.encoder_=e,this.partial_=void 0}transform(e,r){let t=String(e);void 0!==this.partial_&&(t=this.partial_+t,this.partial_=void 0);const a=t.length-1,o=t.charCodeAt(a);o>=55296&&o<56320&&(this.partial_=String.fromCharCode(o),t=t.substring(0,a));const l=this.encoder_.encode(t);0!==l.length&&r.enqueue(l)}flush(e){this.partial_&&(e.enqueue(this.encoder_.encode(this.partial_)),this.partial_=void 0)}}class TextEncoderStream{constructor(){this[encEncoder]=new TextEncoder,this[encTransform]=new TransformStream(new TextEncodeTransformer(this[encEncoder]))}get encoding(){return this[encEncoder].encoding}get readable(){return this[encTransform].readable}get writable(){return this[encTransform].writable}}function getGlobal(){let e;if(void 0===e){try{e=window}catch(e){}if(void 0===e)try{e=global}catch(e){}}return e}function getGlobalValue(e){const r=getGlobal();let t;return void 0!==r&&(t=r[e]),t}function getGlobalOrContextualValue(name){const global=getGlobal();let value;if(void 0!==global&&(value=global[name]),void 0===value)try{value=eval(name)}catch(e){}return value}function hasCompleteStreamsImplementation(){const e=getGlobalValue("ReadableStream"),r=getGlobalValue("WritableStream"),t=getGlobalValue("TransformStream"),a=getGlobalValue("ByteLengthQueuingStrategy"),o=getGlobalValue("CountQueuingStrategy"),l=e=>"function"==typeof e;if(!(l(e)&&l(r)&&l(t)&&l(a)&&l(o)))return!1;try{const r=new e({type:"bytes"}).getReader({mode:"byob"});if(null==r||"object"!=typeof r)return!1}catch(e){return!1}return!0}function installStardazedStreams(){const e=getGlobal();if(!e)return;if(hasCompleteStreamsImplementation())return;const r=getGlobalOrContextualValue("fetch"),t=getGlobalOrContextualValue("Response"),a=getGlobalValue("ReadableStream");if(r&&t){const o=createAdaptedFetch(r,a,ReadableStream),l=createAdaptedResponse(t,a,ReadableStream);e.fetch=o,e.Response=l}e.ReadableStream=ReadableStream,e.WritableStream=WritableStream,e.TransformStream=TransformStream$1,e.ByteLengthQueuingStrategy=ByteLengthQueuingStrategy,e.CountQueuingStrategy=CountQueuingStrategy}function installEncodingStreams(){const e=getGlobal();e&&("function"!=typeof getGlobalValue("TextDecoderStream")&&(e.TextDecoderStream=TextDecoderStream),"function"!=typeof getGlobalValue("TextEncoderStream")&&(e.TextEncoderStream=TextEncoderStream))}installStardazedStreams(),installEncodingStreams()}(); |
{ | ||
"name": "@stardazed/streams-polyfill", | ||
"description": "Drop-in polyfill for Web Streams with fetch integration", | ||
"version": "1.0.4", | ||
"description": "Drop-in polyfill for Web Streams with fetch and encoding integration", | ||
"version": "1.0.5", | ||
"author": { | ||
@@ -11,3 +11,3 @@ "name": "Arthur Langereis" | ||
"type": "git", | ||
"url": "https://github.com/stardazed/sd-streams-polyfill.git" | ||
"url": "https://github.com/stardazed/sd-streams.git" | ||
}, | ||
@@ -19,5 +19,10 @@ "main": "dist/sd-streams-polyfill.min.js", | ||
}, | ||
"files": [ | ||
"dist/*.d.ts", | ||
"dist/*.js" | ||
], | ||
"devDependencies": { | ||
"@stardazed/streams": "^1.0.2", | ||
"@stardazed/streams-fetch-adapter": "^1.0.1", | ||
"@stardazed/streams-text-encoding": "^1.0.1", | ||
"rollup": "^0.65.2", | ||
@@ -27,4 +32,4 @@ "rollup-plugin-node-resolve": "^3.3.0", | ||
"rollup-plugin-typescript": "^0.8.1", | ||
"typescript": "^2.9.2" | ||
"typescript": "^3.0.3" | ||
} | ||
} |
@@ -5,7 +5,10 @@ @stardazed/streams-polyfill | ||
for use in browsers, including patching the built-in `fetch` and `Response` types | ||
to support the `body` field for both downloading and uploading. | ||
to support the `body` field for both downloading and uploading. It also provides the | ||
`TextEncoderStream` and `TextDecoderStream` from the [Encoding Standard](https://encoding.spec.whatwg.org/) | ||
where necessary. | ||
This uses the fully compliant [Stardazed streams](https://www.npmjs.com/package/@stardazed/streams) | ||
implementation and the [streams fetch adapter](https://www.npmjs.com/package/@stardazed/streams-fetch-adapter) | ||
to connect the implementation to the current environment. | ||
and [text encoding streams](https://www.npmjs.com/package/@stardazed/streams-text-encoding) | ||
implementations, and the [streams fetch adapter](https://www.npmjs.com/package/@stardazed/streams-fetch-adapter) | ||
to connect the implementations to the current environment. | ||
@@ -29,4 +32,8 @@ 💡 **NB:** if you have your own `ReadableStream` replacement — including mocks or modifications | ||
The text encoding streams require a compliant `TextEncoder` and `TextDecoder` to be present | ||
either natively or through a polyfill. Browser support: Safari 10.1+, (iOS 10.3+), | ||
Firefox 19+, Chrome 38+. Edge currently does NOT support these interfaces. | ||
### Node | ||
Node (as of July 2018) has no built-in fetch or web streams support. I did not do extensive | ||
Node (as of September 2018) has no built-in fetch or web streams support. I did not do extensive | ||
tests but this polyfill, when `require()`d, will install all streams types in Node's | ||
@@ -33,0 +40,0 @@ `global` object and they then work as expected. Like with browsers, cooperation with any |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
65240
229
97
8