@mattiasbuelens/web-streams-polyfill
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -12,2 +12,6 @@ # Changelog | ||
## v0.3.1 (2019-02-25) | ||
* 🐛 Fix ES5 build target ([#9](https://github.com/MattiasBuelens/web-streams-polyfill/pull/9)) | ||
## v0.3.0 (2019-02-21) | ||
@@ -14,0 +18,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).WebStreamsPolyfill={})}(this,function(e){"use strict";const t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol:e=>`Symbol(${e})`;const r="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0,o=Number.isNaN||function(e){return e!=e};function n(e){return"object"==typeof e&&null!==e||"function"==typeof e}function i(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function a(e){return e.slice()}function s(e,t,r,o,n){new Uint8Array(e).set(new Uint8Array(r,o,n),t)}function l(e){return!1!==function(e){if("number"!=typeof e)return!1;if(o(e))return!1;if(e<0)return!1;return!0}(e)&&e!==1/0}function c(e,t,r){if("function"!=typeof e)throw new TypeError("Argument is not a function");return Function.prototype.apply.call(e,t,r)}function u(e,t,r,o){const n=e[t];if(void 0!==n){if("function"!=typeof n)throw new TypeError(`${n} is not a method`);switch(r){case 0:return()=>f(n,e,o);case 1:return t=>{const r=[t].concat(o);return f(n,e,r)}}}return()=>Promise.resolve()}function d(e,t,r){const o=e[t];if(void 0!==o)return c(o,e,r)}function f(e,t,r){try{return Promise.resolve(c(e,t,r))}catch(e){return Promise.reject(e)}}function _(e){return e}function h(e){if(e=Number(e),o(e)||e<0)throw new RangeError("highWaterMark property of a queuing strategy must be non-negative and non-NaN");return e}function b(e){if(void 0===e)return()=>1;if("function"!=typeof e)throw new TypeError("size property of a queuing strategy must be a function");return t=>e(t)}function m(e,t,r){return Promise.prototype.then.call(e,t,r)}function y(e,t,r){let o,n;const i=new Promise((e,t)=>{o=e,n=t});void 0===r&&(r=(e=>{throw e}));return function(e,t,r){let o=!1;const n=e=>{!1===o&&(o=!0,r(e))};let i=0,a=0;const s=e.length,l=new Array(s);for(const r of e){const e=i;m(r,r=>{l[e]=r,++a===s&&t(l)},n),++i}}(e,e=>{try{const r=t(e);o(r)}catch(e){n(e)}},e=>{try{const t=r(e);o(t)}catch(e){n(e)}}),i}function p(e){}function w(e){e&&e instanceof p.AssertionError&&setTimeout(()=>{throw e},0)}function g(e){const t=e._queue.shift();return e._queueTotalSize-=t.size,e._queueTotalSize<0&&(e._queueTotalSize=0),t.value}function S(e,t,r){if(!l(r=Number(r)))throw new RangeError("Size must be a finite, non-NaN, non-negative number.");e._queue.push({value:t,size:r}),e._queueTotalSize+=r}function v(e){e._queue=[],e._queueTotalSize=0}p.AssertionError=function(){};const R=t("[[AbortSteps]]"),P=t("[[ErrorSteps]]");class WritableStream{constructor(e={},t={}){q(this);const r=t.size;let o=t.highWaterMark;if(void 0!==e.type)throw new RangeError("Invalid type is specified");const n=b(r);void 0===o&&(o=1),function(e,t,r,o){const n=Object.create(WritableStreamDefaultController.prototype);const i=u(t,"write",1,[n]),a=u(t,"close",0,[]),s=u(t,"abort",1,[]);$(e,n,function(){return d(t,"start",[n])},i,a,s,r,o)}(this,e,o=h(o),n)}get locked(){if(!1===E(this))throw G("locked");return C(this)}abort(e){return!1===E(this)?Promise.reject(G("abort")):!0===C(this)?Promise.reject(new TypeError("Cannot abort a stream that already has a writer")):j(this,e)}getWriter(){if(!1===E(this))throw G("getWriter");return T(this)}}function T(e){return new WritableStreamDefaultWriter(e)}function q(e){e._state="writable",e._storedError=void 0,e._writer=void 0,e._writableStreamController=void 0,e._writeRequests=[],e._inFlightWriteRequest=void 0,e._closeRequest=void 0,e._inFlightCloseRequest=void 0,e._pendingAbortRequest=void 0,e._backpressure=!1}function E(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_writableStreamController")}function C(e){return void 0!==e._writer}function j(e,t){const r=e._state;if("closed"===r||"errored"===r)return Promise.resolve(void 0);if(void 0!==e._pendingAbortRequest)return e._pendingAbortRequest._promise;let o=!1;"erroring"===r&&(o=!0,t=void 0);const n=new Promise((r,n)=>{e._pendingAbortRequest={_promise:void 0,_resolve:r,_reject:n,_reason:t,_wasAlreadyErroring:o}});return e._pendingAbortRequest._promise=n,!1===o&&W(e,t),n}function A(e,t){"writable"!==e._state?B(e):W(e,t)}function W(e,t){const r=e._writableStreamController;e._state="erroring",e._storedError=t;const o=e._writer;void 0!==o&&D(o,t),!1===function(e){if(void 0===e._inFlightWriteRequest&&void 0===e._inFlightCloseRequest)return!1;return!0}(e)&&!0===r._started&&B(e)}function B(e){e._state="errored",e._writableStreamController[P]();const t=e._storedError;for(const r of e._writeRequests)r._reject(t);if(e._writeRequests=[],void 0===e._pendingAbortRequest)return void z(e);const r=e._pendingAbortRequest;if(e._pendingAbortRequest=void 0,!0===r._wasAlreadyErroring)return r._reject(t),void z(e);e._writableStreamController[R](r._reason).then(()=>{r._resolve(),z(e)},t=>{r._reject(t),z(e)})}function O(e){return void 0!==e._closeRequest||void 0!==e._inFlightCloseRequest}function z(e){void 0!==e._closeRequest&&(e._closeRequest._reject(e._storedError),e._closeRequest=void 0);const t=e._writer;void 0!==t&&ee(t,e._storedError)}function k(e,t){const r=e._writer;void 0!==r&&t!==e._backpressure&&(!0===t?function(e){re(e)}(r):ae(r)),e._backpressure=t}class WritableStreamDefaultWriter{constructor(e){if(!1===E(e))throw new TypeError("WritableStreamDefaultWriter can only be constructed with a WritableStream instance");if(!0===C(e))throw new TypeError("This stream has already been locked for exclusive writing by another writer");this._ownerWritableStream=e,e._writer=this;const t=e._state;if("writable"===t)!1===O(e)&&!0===e._backpressure?re(this):ne(this),X(this);else if("erroring"===t)oe(this,e._storedError),X(this);else if("closed"===t)ne(this),function(e){X(e),te(e)}(this);else{const t=e._storedError;oe(this,t),Z(this,t)}}get closed(){return!1===F(this)?Promise.reject(J("closed")):this._closedPromise}get desiredSize(){if(!1===F(this))throw J("desiredSize");if(void 0===this._ownerWritableStream)throw K("desiredSize");return function(e){const t=e._ownerWritableStream,r=t._state;if("errored"===r||"erroring"===r)return null;if("closed"===r)return 0;return Q(t._writableStreamController)}(this)}get ready(){return!1===F(this)?Promise.reject(J("ready")):this._readyPromise}abort(e){return!1===F(this)?Promise.reject(J("abort")):void 0===this._ownerWritableStream?Promise.reject(K("abort")):function(e,t){return j(e._ownerWritableStream,t)}(this,e)}close(){if(!1===F(this))return Promise.reject(J("close"));const e=this._ownerWritableStream;return void 0===e?Promise.reject(K("close")):!0===O(e)?Promise.reject(new TypeError("cannot close an already-closing stream")):L(this)}releaseLock(){if(!1===F(this))throw J("releaseLock");void 0!==this._ownerWritableStream&&M(this)}write(e){return!1===F(this)?Promise.reject(J("write")):void 0===this._ownerWritableStream?Promise.reject(K("write to")):Y(this,e)}}function F(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_ownerWritableStream")}function L(e){const t=e._ownerWritableStream,r=t._state;if("closed"===r||"errored"===r)return Promise.reject(new TypeError(`The stream (in ${r} state) is not in the writable state and cannot be closed`));const o=new Promise((e,r)=>{const o={_resolve:e,_reject:r};t._closeRequest=o});return!0===t._backpressure&&"writable"===r&&ae(e),function(e){S(e,"close",0),x(e)}(t._writableStreamController),o}function I(e,t){"pending"===e._closedPromiseState?ee(e,t):function(e,t){Z(e,t)}(e,t)}function D(e,t){"pending"===e._readyPromiseState?ie(e,t):function(e,t){oe(e,t)}(e,t)}function M(e){const t=e._ownerWritableStream,r=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");D(e,r),I(e,r),t._writer=void 0,e._ownerWritableStream=void 0}function Y(e,t){const r=e._ownerWritableStream,o=r._writableStreamController,n=function(e,t){try{return e._strategySizeAlgorithm(t)}catch(t){return H(e,t),1}}(o,t);if(r!==e._ownerWritableStream)return Promise.reject(K("write to"));const i=r._state;if("errored"===i)return Promise.reject(r._storedError);if(!0===O(r)||"closed"===i)return Promise.reject(new TypeError("The stream is closing or closed and cannot be written to"));if("erroring"===i)return Promise.reject(r._storedError);const a=function(e){return new Promise((t,r)=>{const o={_resolve:t,_reject:r};e._writeRequests.push(o)})}(r);return function(e,t,r){const o={chunk:t};try{S(e,o,r)}catch(t){return void H(e,t)}const n=e._controlledWritableStream;if(!1===O(n)&&"writable"===n._state){const t=U(e);k(n,t)}x(e)}(o,t,n),a}class WritableStreamDefaultController{constructor(){throw new TypeError("WritableStreamDefaultController cannot be constructed explicitly")}error(e){if(!1===function(e){if(!n(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_controlledWritableStream"))return!1;return!0}(this))throw new TypeError("WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController");"writable"===this._controlledWritableStream._state&&V(this,e)}[R](e){const t=this._abortAlgorithm(e);return N(this),t}[P](){v(this)}}function $(e,t,r,o,n,i,a,s){t._controlledWritableStream=e,e._writableStreamController=t,t._queue=void 0,t._queueTotalSize=void 0,v(t),t._started=!1,t._strategySizeAlgorithm=s,t._strategyHWM=a,t._writeAlgorithm=o,t._closeAlgorithm=n,t._abortAlgorithm=i;const l=U(t);k(e,l);const c=r();Promise.resolve(c).then(()=>{t._started=!0,x(t)},r=>{t._started=!0,A(e,r)}).catch(w)}function N(e){e._writeAlgorithm=void 0,e._closeAlgorithm=void 0,e._abortAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function Q(e){return e._strategyHWM-e._queueTotalSize}function x(e){const t=e._controlledWritableStream;if(!1===e._started)return;if(void 0!==t._inFlightWriteRequest)return;const r=t._state;if("closed"===r||"errored"===r)return;if("erroring"===r)return void B(t);if(0===e._queue.length)return;const o=function(e){return e._queue[0].value}(e);"close"===o?function(e){const t=e._controlledWritableStream;(function(e){e._inFlightCloseRequest=e._closeRequest,e._closeRequest=void 0})(t),g(e);const r=e._closeAlgorithm();N(e),r.then(()=>{!function(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 t=e._writer;void 0!==t&&te(t)}(t)},e=>{!function(e,t){e._inFlightCloseRequest._reject(t),e._inFlightCloseRequest=void 0,void 0!==e._pendingAbortRequest&&(e._pendingAbortRequest._reject(t),e._pendingAbortRequest=void 0),A(e,t)}(t,e)}).catch(w)}(e):function(e,t){const r=e._controlledWritableStream;(function(e){e._inFlightWriteRequest=e._writeRequests.shift()})(r),e._writeAlgorithm(t).then(()=>{!function(e){e._inFlightWriteRequest._resolve(void 0),e._inFlightWriteRequest=void 0}(r);const t=r._state;if(g(e),!1===O(r)&&"writable"===t){const t=U(e);k(r,t)}x(e)},t=>{"writable"===r._state&&N(e),function(e,t){e._inFlightWriteRequest._reject(t),e._inFlightWriteRequest=void 0,A(e,t)}(r,t)}).catch(w)}(e,o.chunk)}function H(e,t){"writable"===e._controlledWritableStream._state&&V(e,t)}function U(e){return Q(e)<=0}function V(e,t){const r=e._controlledWritableStream;N(e),W(r,t)}function G(e){return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`)}function J(e){return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`)}function K(e){return new TypeError("Cannot "+e+" a stream using a released writer")}function X(e){e._closedPromise=new Promise((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r,e._closedPromiseState="pending"})}function Z(e,t){X(e),ee(e,t)}function ee(e,t){e._closedPromise.catch(()=>{}),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="rejected"}function te(e){e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="resolved"}function re(e){e._readyPromise=new Promise((t,r)=>{e._readyPromise_resolve=t,e._readyPromise_reject=r}),e._readyPromiseState="pending"}function oe(e,t){re(e),ie(e,t)}function ne(e){re(e),ae(e)}function ie(e,t){e._readyPromise.catch(()=>{}),e._readyPromise_reject(t),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="rejected"}function ae(e){e._readyPromise_resolve(void 0),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="fulfilled"}const se=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},le=t("[[CancelSteps]]"),ce=t("[[PullSteps]]");class ReadableStream{constructor(e={},t={}){fe(this);const r=t.size;let o=t.highWaterMark;const n=e.type;if("bytes"===String(n)){if(void 0!==r)throw new RangeError("The strategy for a byte stream cannot have a size function");void 0===o&&(o=0),function(e,t,r){const o=Object.create(ReadableByteStreamController.prototype);const n=u(t,"pull",0,[o]),i=u(t,"cancel",1,[]);let a=t.autoAllocateChunkSize;if(void 0!==a&&(a=Number(a),!1===se(a)||a<=0))throw new RangeError("autoAllocateChunkSize must be a positive integer");!function(e,t,r,o,n,i,a){t._controlledReadableByteStream=e,t._pullAgain=!1,t._pulling=!1,He(t),t._queue=t._queueTotalSize=void 0,v(t),t._closeRequested=!1,t._started=!1,t._strategyHWM=h(i),t._pullAlgorithm=o,t._cancelAlgorithm=n,t._autoAllocateChunkSize=a,t._pendingPullIntos=[],e._readableStreamController=t;const s=r();Promise.resolve(s).then(()=>{t._started=!0,xe(t)},e=>{nt(t,e)}).catch(w)}(e,o,function(){return d(t,"start",[o])},n,i,r,a)}(this,e,o=h(o))}else{if(void 0!==n)throw new RangeError("Invalid type is specified");{const t=b(r);void 0===o&&(o=1),function(e,t,r,o){const n=Object.create(ReadableStreamDefaultController.prototype);const i=u(t,"pull",0,[n]),a=u(t,"cancel",1,[]);$e(e,n,function(){return d(t,"start",[n])},i,a,r,o)}(this,e,o=h(o),t)}}}get locked(){if(!1===_e(this))throw st("locked");return he(this)}cancel(e){return!1===_e(this)?Promise.reject(st("cancel")):!0===he(this)?Promise.reject(new TypeError("Cannot cancel a stream that already has a reader")):pe(this,e)}getReader({mode:e}={}){if(!1===_e(this))throw st("getReader");if(void 0===e)return ue(this);if("byob"===(e=String(e)))return function(e){return new ReadableStreamBYOBReader(e)}(this);throw new RangeError("Invalid mode is specified")}pipeThrough({writable:e,readable:t},{preventClose:r,preventAbort:o,preventCancel:n,signal:i}={}){if(!1===_e(this))throw st("pipeThrough");if(!1===E(e))throw new TypeError("writable argument to pipeThrough must be a WritableStream");if(!1===_e(t))throw new TypeError("readable argument to pipeThrough must be a ReadableStream");if(r=Boolean(r),o=Boolean(o),n=Boolean(n),void 0!==i&&!at(i))throw new TypeError("ReadableStream.prototype.pipeThrough's signal option must be an AbortSignal");if(!0===he(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(!0===C(e))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return be(this,e,r,o,n,i).catch(()=>{}),t}pipeTo(e,{preventClose:t,preventAbort:r,preventCancel:o,signal:n}={}){return!1===_e(this)?Promise.reject(st("pipeTo")):!1===E(e)?Promise.reject(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream")):(t=Boolean(t),r=Boolean(r),o=Boolean(o),void 0===n||at(n)?!0===he(this)?Promise.reject(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):!0===C(e)?Promise.reject(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):be(this,e,t,r,o,n):Promise.reject(new TypeError("ReadableStream.prototype.pipeTo's signal option must be an AbortSignal")))}tee(){if(!1===_e(this))throw st("tee");const e=function(e,t){const r=ue(e);let o,n,i,s,l,c=!1,u=!1,d=!1;const f=new Promise(e=>{l=e});function _(){return Be(r).then(e=>{const t=e.value,r=e.done;if(!0===r&&!1===c&&(!1===u&&Le(i._readableStreamController),!1===d&&Le(s._readableStreamController),c=!0),!0===c)return;const o=t,n=t;!1===u&&Ie(i._readableStreamController,o),!1===d&&Ie(s._readableStreamController,n)})}function h(){}return i=de(h,_,function(t){if(u=!0,o=t,!0===d){const t=a([o,n]),r=pe(e,t);l(r)}return f}),s=de(h,_,function(t){if(d=!0,n=t,!0===u){const t=a([o,n]),r=pe(e,t);l(r)}return f}),r._closedPromise.catch(e=>{!0!==c&&(De(i._readableStreamController,e),De(s._readableStreamController,e),c=!0)}),[i,s]}(this);return a(e)}}function ue(e){return new ReadableStreamDefaultReader(e)}function de(e,t,r,o=1,n=(()=>1)){const i=Object.create(ReadableStream.prototype);return fe(i),$e(i,Object.create(ReadableStreamDefaultController.prototype),e,t,r,o,n),i}function fe(e){e._state="readable",e._reader=void 0,e._storedError=void 0,e._disturbed=!1}function _e(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readableStreamController")}function he(e){return void 0!==e._reader}function be(e,t,r,o,n,i){const a=ue(e),s=T(t);let l=!1,c=Promise.resolve();return new Promise((u,d)=>{let f;if(void 0!==i){if(f=(()=>{const r=new DOMException("Aborted","AbortError"),i=[];!1===o&&i.push(()=>"writable"===t._state?j(t,r):Promise.resolve()),!1===n&&i.push(()=>"readable"===e._state?pe(e,r):Promise.resolve()),b(()=>y(i.map(e=>e()),e=>e),!0,r)}),!0===i.aborted)return void f();i.addEventListener("abort",f)}if(h(e,a._closedPromise,e=>{!1===o?b(()=>j(t,e),!0,e):m(!0,e)}),h(t,s._closedPromise,t=>{!1===n?b(()=>pe(e,t),!0,t):m(!0,t)}),function(e,t,r){"closed"===e._state?r():t.then(r).catch(w)}(e,a._closedPromise,()=>{!1===r?b(()=>(function(e){const t=e._ownerWritableStream,r=t._state;return!0===O(t)||"closed"===r?Promise.resolve():"errored"===r?Promise.reject(t._storedError):L(e)})(s)):m()}),!0===O(t)||"closed"===t._state){const t=new TypeError("the destination writable stream closed before all data could be piped to it");!1===n?b(()=>pe(e,t),!0,t):m(!0,t)}function _(){const e=c;return c.then(()=>e!==c?_():void 0)}function h(e,t,r){"errored"===e._state?r(e._storedError):t.catch(r).catch(w)}function b(e,r,o){function n(){e().then(()=>p(r,o),e=>p(!0,e)).catch(w)}!0!==l&&(l=!0,"writable"===t._state&&!1===O(t)?_().then(n):n())}function m(e,r){!0!==l&&(l=!0,"writable"===t._state&&!1===O(t)?_().then(()=>p(e,r)).catch(w):p(e,r))}function p(e,t){M(s),We(a),void 0!==i&&i.removeEventListener("abort",f),e?d(t):u(void 0)}new Promise((e,t)=>{!function r(o){o?e():(!0===l?Promise.resolve(!0):s._readyPromise.then(()=>Be(a).then(({value:e,done:t})=>!0===t||(c=Y(s,e).catch(()=>{}),!1)))).then(r,t)}(!1)}).catch(e=>{c=Promise.resolve(),w(e)})})}function me(e,t){return new Promise((r,o)=>{const n={_resolve:r,_reject:o,_forAuthorCode:t};e._reader._readIntoRequests.push(n)})}function ye(e,t){return new Promise((r,o)=>{const n={_resolve:r,_reject:o,_forAuthorCode:t};e._reader._readRequests.push(n)})}function pe(e,t){if(e._disturbed=!0,"closed"===e._state)return Promise.resolve(void 0);if("errored"===e._state)return Promise.reject(e._storedError);return we(e),e._readableStreamController[le](t).then(()=>void 0)}function we(e){e._state="closed";const t=e._reader;if(void 0!==t){if(Ce(t)){for(const{_resolve:e,_forAuthorCode:r}of t._readRequests)e(ge(void 0,!0,r));t._readRequests=[]}_t(t)}}function ge(e,t,r){let o=null;!0===r&&(o=Object.prototype);const n=Object.create(o);return Object.defineProperty(n,"value",{value:e,enumerable:!0,writable:!0,configurable:!0}),Object.defineProperty(n,"done",{value:t,enumerable:!0,writable:!0,configurable:!0}),n}function Se(e,t){e._state="errored",e._storedError=t;const r=e._reader;if(void 0!==r){if(Ce(r)){for(const e of r._readRequests)e._reject(t);r._readRequests=[]}else{for(const e of r._readIntoRequests)e._reject(t);r._readIntoRequests=[]}ft(r,t)}}function ve(e,t,r){const o=e._reader._readRequests.shift();o._resolve(ge(t,r,o._forAuthorCode))}function Re(e){return e._reader._readIntoRequests.length}function Pe(e){return e._reader._readRequests.length}function Te(e){const t=e._reader;return void 0!==t&&!!Ee(t)}function qe(e){const t=e._reader;return void 0!==t&&!!Ce(t)}class ReadableStreamDefaultReader{constructor(e){if(!1===_e(e))throw new TypeError("ReadableStreamDefaultReader can only be constructed with a ReadableStream instance");if(!0===he(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");je(this,e),this._readRequests=[]}get closed(){return Ce(this)?this._closedPromise:Promise.reject(ct("closed"))}cancel(e){return Ce(this)?void 0===this._ownerReadableStream?Promise.reject(lt("cancel")):Ae(this,e):Promise.reject(ct("cancel"))}read(){return Ce(this)?void 0===this._ownerReadableStream?Promise.reject(lt("read from")):Be(this,!0):Promise.reject(ct("read"))}releaseLock(){if(!Ce(this))throw ct("releaseLock");if(void 0!==this._ownerReadableStream){if(this._readRequests.length>0)throw new TypeError("Tried to release a reader lock when that reader has pending read() calls un-settled");We(this)}}}class ReadableStreamBYOBReader{constructor(e){if(!_e(e))throw new TypeError("ReadableStreamBYOBReader can only be constructed with a ReadableStream instance given a byte source");if(!1===Ne(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");if(he(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");je(this,e),this._readIntoRequests=[]}get closed(){return Ee(this)?this._closedPromise:Promise.reject(ht("closed"))}cancel(e){return Ee(this)?void 0===this._ownerReadableStream?Promise.reject(lt("cancel")):Ae(this,e):Promise.reject(ht("cancel"))}read(e){return Ee(this)?void 0===this._ownerReadableStream?Promise.reject(lt("read from")):ArrayBuffer.isView(e)?(e.buffer,0===e.byteLength?Promise.reject(new TypeError("view must have non-zero byteLength")):function(e,t,r=!1){const o=e._ownerReadableStream;if(o._disturbed=!0,"errored"===o._state)return Promise.reject(o._storedError);return function(e,t,r){const o=e._controlledReadableByteStream;let n=1;t.constructor!==DataView&&(n=t.constructor.BYTES_PER_ELEMENT);const i=t.constructor,a={buffer:_(t.buffer),byteOffset:t.byteOffset,byteLength:t.byteLength,bytesFilled:0,elementSize:n,ctor:i,readerType:"byob"};if(e._pendingPullIntos.length>0)return e._pendingPullIntos.push(a),me(o,r);if("closed"===o._state){const e=new i(a.buffer,a.byteOffset,0);return Promise.resolve(ge(e,!0,r))}if(e._queueTotalSize>0){if(!0===Je(e,a)){const t=Ve(a);return Xe(e),Promise.resolve(ge(t,!1,r))}if(!0===e._closeRequested){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");return nt(e,t),Promise.reject(t)}}e._pendingPullIntos.push(a);const s=me(o,r);return xe(e),s}(o._readableStreamController,t,r)}(this,e,!0)):Promise.reject(new TypeError("view must be an array buffer view")):Promise.reject(ht("read"))}releaseLock(){if(!Ee(this))throw ht("releaseLock");if(void 0!==this._ownerReadableStream){if(this._readIntoRequests.length>0)throw new TypeError("Tried to release a reader lock when that reader has pending read() calls un-settled");We(this)}}}function Ee(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readIntoRequests")}function Ce(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readRequests")}function je(e,t){e._ownerReadableStream=t,t._reader=e,"readable"===t._state?ut(e):"closed"===t._state?function(e){ut(e),_t(e)}(e):dt(e,t._storedError)}function Ae(e,t){return pe(e._ownerReadableStream,t)}function We(e){"readable"===e._ownerReadableStream._state?ft(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e,t){dt(e,t)}(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")),e._ownerReadableStream._reader=void 0,e._ownerReadableStream=void 0}function Be(e,t=!1){const r=e._ownerReadableStream;return r._disturbed=!0,"closed"===r._state?Promise.resolve(ge(void 0,!0,t)):"errored"===r._state?Promise.reject(r._storedError):r._readableStreamController[ce](t)}class ReadableStreamDefaultController{constructor(){throw new TypeError}get desiredSize(){if(!1===Oe(this))throw bt("desiredSize");return Me(this)}close(){if(!1===Oe(this))throw bt("close");if(!1===Ye(this))throw new TypeError("The stream is not in a state that permits close");Le(this)}enqueue(e){if(!1===Oe(this))throw bt("enqueue");if(!1===Ye(this))throw new TypeError("The stream is not in a state that permits enqueue");return Ie(this,e)}error(e){if(!1===Oe(this))throw bt("error");De(this,e)}[le](e){v(this);const t=this._cancelAlgorithm(e);return Fe(this),t}[ce](e){const t=this._controlledReadableStream;if(this._queue.length>0){const r=g(this);return!0===this._closeRequested&&0===this._queue.length?(Fe(this),we(t)):ze(this),Promise.resolve(ge(r,!1,e))}const r=ye(t,e);return ze(this),r}}function Oe(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableStream")}function ze(e){!1!==ke(e)&&(!0!==e._pulling?(e._pulling=!0,e._pullAlgorithm().then(()=>{if(e._pulling=!1,!0===e._pullAgain)return e._pullAgain=!1,ze(e)},t=>{De(e,t)}).catch(w)):e._pullAgain=!0)}function ke(e){const t=e._controlledReadableStream;return!1!==Ye(e)&&(!1!==e._started&&(!0===he(t)&&Pe(t)>0||Me(e)>0))}function Fe(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function Le(e){const t=e._controlledReadableStream;e._closeRequested=!0,0===e._queue.length&&(Fe(e),we(t))}function Ie(e,t){const r=e._controlledReadableStream;if(!0===he(r)&&Pe(r)>0)ve(r,t,!1);else{let r;try{r=e._strategySizeAlgorithm(t)}catch(t){throw De(e,t),t}try{S(e,t,r)}catch(t){throw De(e,t),t}}ze(e)}function De(e,t){const r=e._controlledReadableStream;"readable"===r._state&&(v(e),Fe(e),Se(r,t))}function Me(e){const t=e._controlledReadableStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Ye(e){const t=e._controlledReadableStream._state;return!1===e._closeRequested&&"readable"===t}function $e(e,t,r,o,n,i,a){t._controlledReadableStream=e,t._queue=void 0,t._queueTotalSize=void 0,v(t),t._started=!1,t._closeRequested=!1,t._pullAgain=!1,t._pulling=!1,t._strategySizeAlgorithm=a,t._strategyHWM=i,t._pullAlgorithm=o,t._cancelAlgorithm=n,e._readableStreamController=t;const s=r();Promise.resolve(s).then(()=>{t._started=!0,ze(t)},e=>{De(t,e)}).catch(w)}class ReadableStreamBYOBRequest{constructor(){throw new TypeError("ReadableStreamBYOBRequest cannot be used directly")}get view(){if(!1===Qe(this))throw mt("view");return this._view}respond(e){if(!1===Qe(this))throw mt("respond");if(void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");this._view.buffer,function(e,t){if(!1===l(t=Number(t)))throw new RangeError("bytesWritten must be a finite");tt(e,t)}(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!1===Qe(this))throw mt("respond");if(void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(!ArrayBuffer.isView(e))throw new TypeError("You can only respond with array buffer views");e.buffer,function(e,t){const r=e._pendingPullIntos[0];if(r.byteOffset+r.bytesFilled!==t.byteOffset)throw new RangeError("The region specified by view does not match byobRequest");if(r.byteLength!==t.byteLength)throw new RangeError("The buffer of view has different capacity than byobRequest");r.buffer=t.buffer,tt(e,t.byteLength)}(this._associatedReadableByteStreamController,e)}}class ReadableByteStreamController{constructor(){throw new TypeError("ReadableByteStreamController constructor cannot be used directly")}get byobRequest(){if(!1===Ne(this))throw yt("byobRequest");if(void 0===this._byobRequest&&this._pendingPullIntos.length>0){const e=this._pendingPullIntos[0],t=new Uint8Array(e.buffer,e.byteOffset+e.bytesFilled,e.byteLength-e.bytesFilled),r=Object.create(ReadableStreamBYOBRequest.prototype);!function(e,t,r){e._associatedReadableByteStreamController=t,e._view=r}(r,this,t),this._byobRequest=r}return this._byobRequest}get desiredSize(){if(!1===Ne(this))throw yt("desiredSize");return it(this)}close(){if(!1===Ne(this))throw yt("close");if(!0===this._closeRequested)throw new TypeError("The stream has already been closed; do not close it again!");const e=this._controlledReadableByteStream._state;if("readable"!==e)throw new TypeError(`The stream (in ${e} state) is not in the readable state and cannot be closed`);!function(e){const t=e._controlledReadableByteStream;if(e._queueTotalSize>0)return void(e._closeRequested=!0);if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos[0];if(t.bytesFilled>0){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");throw nt(e,t),t}}ot(e),we(t)}(this)}enqueue(e){if(!1===Ne(this))throw yt("enqueue");if(!0===this._closeRequested)throw new TypeError("stream is closed or draining");const t=this._controlledReadableByteStream._state;if("readable"!==t)throw new TypeError(`The stream (in ${t} state) is not in the readable state and cannot be enqueued to`);if(!ArrayBuffer.isView(e))throw new TypeError("You can only enqueue array buffer views when using a ReadableByteStreamController");e.buffer,function(e,t){const r=e._controlledReadableByteStream,o=t.buffer,n=t.byteOffset,i=t.byteLength,a=_(o);if(!0===qe(r))if(0===Pe(r))Ge(e,a,n,i);else{const e=new Uint8Array(a,n,i);ve(r,e,!1)}else!0===Te(r)?(Ge(e,a,n,i),et(e)):Ge(e,a,n,i);xe(e)}(this,e)}error(e){if(!1===Ne(this))throw yt("error");nt(this,e)}[le](e){if(this._pendingPullIntos.length>0){this._pendingPullIntos[0].bytesFilled=0}v(this);const t=this._cancelAlgorithm(e);return ot(this),t}[ce](e){const t=this._controlledReadableByteStream;if(this._queueTotalSize>0){const t=this._queue.shift();let r;this._queueTotalSize-=t.byteLength,Xe(this);try{r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}catch(e){return Promise.reject(e)}return Promise.resolve(ge(r,!1,e))}const r=this._autoAllocateChunkSize;if(void 0!==r){let e;try{e=new ArrayBuffer(r)}catch(e){return Promise.reject(e)}const t={buffer:e,byteOffset:0,byteLength:r,bytesFilled:0,elementSize:1,ctor:Uint8Array,readerType:"default"};this._pendingPullIntos.push(t)}const o=ye(t,e);return xe(this),o}}function Ne(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableByteStream")}function Qe(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_associatedReadableByteStreamController")}function xe(e){!1!==function(e){const t=e._controlledReadableByteStream;if("readable"!==t._state)return!1;if(!0===e._closeRequested)return!1;if(!1===e._started)return!1;if(!0===qe(t)&&Pe(t)>0)return!0;if(!0===Te(t)&&Re(t)>0)return!0;if(it(e)>0)return!0;return!1}(e)&&(!0!==e._pulling?(e._pulling=!0,e._pullAlgorithm().then(()=>{e._pulling=!1,!0===e._pullAgain&&(e._pullAgain=!1,xe(e))},t=>{nt(e,t)}).catch(w)):e._pullAgain=!0)}function He(e){Ze(e),e._pendingPullIntos=[]}function Ue(e,t){let r=!1;"closed"===e._state&&(r=!0);const o=Ve(t);"default"===t.readerType?ve(e,o,r):function(e,t,r){const o=e._reader._readIntoRequests.shift();o._resolve(ge(t,r,o._forAuthorCode))}(e,o,r)}function Ve(e){const t=e.bytesFilled,r=e.elementSize;return new e.ctor(e.buffer,e.byteOffset,t/r)}function Ge(e,t,r,o){e._queue.push({buffer:t,byteOffset:r,byteLength:o}),e._queueTotalSize+=o}function Je(e,t){const r=t.elementSize,o=t.bytesFilled-t.bytesFilled%r,n=Math.min(e._queueTotalSize,t.byteLength-t.bytesFilled),i=t.bytesFilled+n,a=i-i%r;let l=n,c=!1;a>o&&(l=a-t.bytesFilled,c=!0);const u=e._queue;for(;l>0;){const r=u[0],o=Math.min(l,r.byteLength),n=t.byteOffset+t.bytesFilled;s(t.buffer,n,r.buffer,r.byteOffset,o),r.byteLength===o?u.shift():(r.byteOffset+=o,r.byteLength-=o),e._queueTotalSize-=o,Ke(e,o,t),l-=o}return c}function Ke(e,t,r){Ze(e),r.bytesFilled+=t}function Xe(e){0===e._queueTotalSize&&!0===e._closeRequested?(ot(e),we(e._controlledReadableByteStream)):xe(e)}function Ze(e){void 0!==e._byobRequest&&(e._byobRequest._associatedReadableByteStreamController=void 0,e._byobRequest._view=void 0,e._byobRequest=void 0)}function et(e){for(;e._pendingPullIntos.length>0;){if(0===e._queueTotalSize)return;const t=e._pendingPullIntos[0];!0===Je(e,t)&&(rt(e),Ue(e._controlledReadableByteStream,t))}}function tt(e,t){const r=e._pendingPullIntos[0];if("closed"===e._controlledReadableByteStream._state){if(0!==t)throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream");!function(e,t){t.buffer=_(t.buffer);const r=e._controlledReadableByteStream;if(!0===Te(r))for(;Re(r)>0;)Ue(r,rt(e))}(e,r)}else!function(e,t,r){if(r.bytesFilled+t>r.byteLength)throw new RangeError("bytesWritten out of range");if(Ke(e,t,r),r.bytesFilled<r.elementSize)return;rt(e);const o=r.bytesFilled%r.elementSize;if(o>0){const t=r.byteOffset+r.bytesFilled,n=r.buffer.slice(t-o,t);Ge(e,n,0,n.byteLength)}r.buffer=_(r.buffer),r.bytesFilled-=o,Ue(e._controlledReadableByteStream,r),et(e)}(e,t,r);xe(e)}function rt(e){const t=e._pendingPullIntos.shift();return Ze(e),t}function ot(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0}function nt(e,t){const r=e._controlledReadableByteStream;"readable"===r._state&&(He(e),v(e),ot(e),Se(r,t))}function it(e){const t=e._controlledReadableByteStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function at(e){if("object"!=typeof e||null===e)return!1;const t=Object.getOwnPropertyDescriptor(AbortSignal.prototype,"aborted").get;try{return t.call(e),!0}catch(e){return!1}}function st(e){return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`)}function lt(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function ct(e){return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`)}function ut(e){e._closedPromise=new Promise((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r})}function dt(e,t){ut(e),ft(e,t)}function ft(e,t){e._closedPromise.catch(()=>{}),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0}function _t(e){e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0}function ht(e){return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`)}function bt(e){return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`)}function mt(e){return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`)}function yt(e){return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`)}class ByteLengthQueuingStrategy{constructor({highWaterMark:e}){i(this,"highWaterMark",e)}size(e){return e.byteLength}}class CountQueuingStrategy{constructor({highWaterMark:e}){i(this,"highWaterMark",e)}size(){return 1}}class TransformStream{constructor(e={},t={},r={}){const o=t.size;let n=t.highWaterMark;const i=r.size;let a=r.highWaterMark;if(void 0!==e.writableType)throw new RangeError("Invalid writable type specified");const s=b(o);if(void 0===n&&(n=1),n=h(n),void 0!==e.readableType)throw new RangeError("Invalid readable type specified");const l=b(i);let c;void 0===a&&(a=0),a=h(a),function(e,t,r,o,n,i){function a(){return t}e._writable=function(e,t,r,o,n=1,i=(()=>1)){const a=Object.create(WritableStream.prototype);return q(a),$(a,Object.create(WritableStreamDefaultController.prototype),e,t,r,o,n,i),a}(a,function(t){return function(e,t){const r=e._transformStreamController;if(!0===e._backpressure){const o=e._backpressureChangePromise;return o.then(()=>{const o=e._writable,n=o._state;if("erroring"===n)throw o._storedError;return Tt(r,t)})}return Tt(r,t)}(e,t)},function(){return function(e){const t=e._readable,r=e._transformStreamController,o=r._flushAlgorithm();return Rt(r),o.then(()=>{if("errored"===t._state)throw t._storedError;const e=t._readableStreamController;!0===Ye(e)&&Le(e)}).catch(r=>{throw wt(e,r),t._storedError})}(e)},function(t){return function(e,t){return wt(e,t),Promise.resolve()}(e,t)},r,o),e._readable=de(a,function(){return function(e){return St(e,!1),e._backpressureChangePromise}(e)},function(t){return gt(e,t),Promise.resolve()},n,i),e._backpressure=void 0,e._backpressureChangePromise=void 0,e._backpressureChangePromise_resolve=void 0,St(e,!0),e._transformStreamController=void 0}(this,new Promise(e=>{c=e}),n,s,a,l),function(e,t){const r=Object.create(TransformStreamDefaultController.prototype);let o=e=>{try{return Pt(r,e),Promise.resolve()}catch(e){return Promise.reject(e)}};const n=t.transform;if(void 0!==n){if("function"!=typeof n)throw new TypeError("transform is not a method");o=(e=>f(n,t,[e,r]))}const i=u(t,"flush",0,[r]);!function(e,t,r,o){t._controlledTransformStream=e,e._transformStreamController=t,t._transformAlgorithm=r,t._flushAlgorithm=o}(e,r,o,i)}(this,e);const _=d(e,"start",[this._transformStreamController]);c(_)}get readable(){if(!1===pt(this))throw Et("readable");return this._readable}get writable(){if(!1===pt(this))throw Et("writable");return this._writable}}function pt(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_transformStreamController")}function wt(e,t){De(e._readable._readableStreamController,t),gt(e,t)}function gt(e,t){Rt(e._transformStreamController),H(e._writable._writableStreamController,t),!0===e._backpressure&&St(e,!1)}function St(e,t){void 0!==e._backpressureChangePromise&&e._backpressureChangePromise_resolve(),e._backpressureChangePromise=new Promise(t=>{e._backpressureChangePromise_resolve=t}),e._backpressure=t}class TransformStreamDefaultController{constructor(){throw new TypeError("TransformStreamDefaultController instances cannot be created directly")}get desiredSize(){if(!1===vt(this))throw qt("desiredSize");return Me(this._controlledTransformStream._readable._readableStreamController)}enqueue(e){if(!1===vt(this))throw qt("enqueue");Pt(this,e)}error(e){if(!1===vt(this))throw qt("error");!function(e,t){wt(e._controlledTransformStream,t)}(this,e)}terminate(){if(!1===vt(this))throw qt("terminate");!function(e){const t=e._controlledTransformStream,r=t._readable._readableStreamController;!0===Ye(r)&&Le(r);const o=new TypeError("TransformStream terminated");gt(t,o)}(this)}}function vt(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledTransformStream")}function Rt(e){e._transformAlgorithm=void 0,e._flushAlgorithm=void 0}function Pt(e,t){const r=e._controlledTransformStream,o=r._readable._readableStreamController;if(!1===Ye(o))throw new TypeError("Readable side is not in a state that permits enqueue");try{Ie(o,t)}catch(e){throw gt(r,e),r._readable._storedError}(function(e){return!0!==ke(e)})(o)!==r._backpressure&&St(r,!0)}function Tt(e,t){return e._transformAlgorithm(t).catch(t=>{throw wt(e._controlledTransformStream,t),t})}function qt(e){return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`)}function Et(e){return new TypeError(`TransformStream.prototype.${e} can only be used on a TransformStream`)}const Ct={ReadableStream:ReadableStream,WritableStream:WritableStream,ByteLengthQueuingStrategy:ByteLengthQueuingStrategy,CountQueuingStrategy:CountQueuingStrategy,TransformStream:TransformStream};void 0!==r&&Object.assign(r,Ct),e.ReadableStream=ReadableStream,e.WritableStream=WritableStream,e.ByteLengthQueuingStrategy=ByteLengthQueuingStrategy,e.CountQueuingStrategy=CountQueuingStrategy,e.TransformStream=TransformStream,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).WebStreamsPolyfill={})}(this,function(e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol:function(e){return"Symbol("+e+")"};var t="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0,o=Number.isNaN||function(e){return e!=e};function n(e){return"object"==typeof e&&null!==e||"function"==typeof e}function i(e,r,t){Object.defineProperty(e,r,{value:t,writable:!0,enumerable:!0,configurable:!0})}function a(e){return e.slice()}function s(e,r,t,o,n){new Uint8Array(e).set(new Uint8Array(t,o,n),r)}function u(e){return!1!==function(e){if("number"!=typeof e)return!1;if(o(e))return!1;if(e<0)return!1;return!0}(e)&&e!==1/0}function l(e,r,t){if("function"!=typeof e)throw new TypeError("Argument is not a function");return Function.prototype.apply.call(e,r,t)}function c(e,r,t,o){var n=e[r];if(void 0!==n){if("function"!=typeof n)throw new TypeError(n+" is not a method");switch(t){case 0:return function(){return d(n,e,o)};case 1:return function(r){var t=[r].concat(o);return d(n,e,t)}}}return function(){return Promise.resolve()}}function f(e,r,t){var o=e[r];if(void 0!==o)return l(o,e,t)}function d(e,r,t){try{return Promise.resolve(l(e,r,t))}catch(e){return Promise.reject(e)}}function _(e){return e}function h(e){if(e=Number(e),o(e)||e<0)throw new RangeError("highWaterMark property of a queuing strategy must be non-negative and non-NaN");return e}function b(e){if(void 0===e)return function(){return 1};if("function"!=typeof e)throw new TypeError("size property of a queuing strategy must be a function");return function(r){return e(r)}}function p(e,r,t){for(var o=!1,n=function(e){!1===o&&(o=!0,t(e))},i=0,a=0,s=e.length,u=new Array(s),l=function(e){var t=i;!function(e,r,t){Promise.prototype.then.call(e,r,t)}(e,function(e){u[t]=e,++a===s&&r(u)},n),++i},c=0,f=e;c<f.length;c++){l(f[c])}}function m(e){}function y(e){e&&e instanceof m.AssertionError&&setTimeout(function(){throw e},0)}function v(e){var r=e._queue.shift();return e._queueTotalSize-=r.size,e._queueTotalSize<0&&(e._queueTotalSize=0),r.value}function w(e,r,t){if(!u(t=Number(t)))throw new RangeError("Size must be a finite, non-NaN, non-negative number.");e._queue.push({value:r,size:t}),e._queueTotalSize+=t}function g(e){e._queue=[],e._queueTotalSize=0}m.AssertionError=function(){};var S=r("[[AbortSteps]]"),R=r("[[ErrorSteps]]"),P=function(){function e(e,r){void 0===e&&(e={}),void 0===r&&(r={}),q(this);var t=r.size,o=r.highWaterMark;if(void 0!==e.type)throw new RangeError("Invalid type is specified");var n=b(t);void 0===o&&(o=1),function(e,r,t,o){var n=Object.create(x.prototype);var i=c(r,"write",1,[n]),a=c(r,"close",0,[]),s=c(r,"abort",1,[]);H(e,n,function(){return f(r,"start",[n])},i,a,s,t,o)}(this,e,o=h(o),n)}return Object.defineProperty(e.prototype,"locked",{get:function(){if(!1===j(this))throw X("locked");return E(this)},enumerable:!0,configurable:!0}),e.prototype.abort=function(e){return!1===j(this)?Promise.reject(X("abort")):!0===E(this)?Promise.reject(new TypeError("Cannot abort a stream that already has a writer")):C(this,e)},e.prototype.getWriter=function(){if(!1===j(this))throw X("getWriter");return T(this)},e}();function T(e){return new F(e)}function q(e){e._state="writable",e._storedError=void 0,e._writer=void 0,e._writableStreamController=void 0,e._writeRequests=[],e._inFlightWriteRequest=void 0,e._closeRequest=void 0,e._inFlightCloseRequest=void 0,e._pendingAbortRequest=void 0,e._backpressure=!1}function j(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_writableStreamController")}function E(e){return void 0!==e._writer}function C(e,r){var t=e._state;if("closed"===t||"errored"===t)return Promise.resolve(void 0);if(void 0!==e._pendingAbortRequest)return e._pendingAbortRequest._promise;var o=!1;"erroring"===t&&(o=!0,r=void 0);var n=new Promise(function(t,n){e._pendingAbortRequest={_promise:void 0,_resolve:t,_reject:n,_reason:r,_wasAlreadyErroring:o}});return e._pendingAbortRequest._promise=n,!1===o&&O(e,r),n}function A(e,r){"writable"!==e._state?W(e):O(e,r)}function O(e,r){var t=e._writableStreamController;e._state="erroring",e._storedError=r;var o=e._writer;void 0!==o&&D(o,r),!1===function(e){if(void 0===e._inFlightWriteRequest&&void 0===e._inFlightCloseRequest)return!1;return!0}(e)&&!0===t._started&&W(e)}function W(e){e._state="errored",e._writableStreamController[R]();for(var r=e._storedError,t=0,o=e._writeRequests;t<o.length;t++){o[t]._reject(r)}if(e._writeRequests=[],void 0!==e._pendingAbortRequest){var n=e._pendingAbortRequest;if(e._pendingAbortRequest=void 0,!0===n._wasAlreadyErroring)return n._reject(r),void z(e);e._writableStreamController[S](n._reason).then(function(){n._resolve(),z(e)},function(r){n._reject(r),z(e)})}else z(e)}function B(e){return void 0!==e._closeRequest||void 0!==e._inFlightCloseRequest}function z(e){void 0!==e._closeRequest&&(e._closeRequest._reject(e._storedError),e._closeRequest=void 0);var r=e._writer;void 0!==r&&te(r,e._storedError)}function k(e,r){var t=e._writer;void 0!==t&&r!==e._backpressure&&(!0===r?function(e){ne(e)}(t):ue(t)),e._backpressure=r}var F=function(){function e(e){if(!1===j(e))throw new TypeError("WritableStreamDefaultWriter can only be constructed with a WritableStream instance");if(!0===E(e))throw new TypeError("This stream has already been locked for exclusive writing by another writer");this._ownerWritableStream=e,e._writer=this;var r=e._state;if("writable"===r)!1===B(e)&&!0===e._backpressure?ne(this):ae(this),ee(this);else if("erroring"===r)ie(this,e._storedError),ee(this);else if("closed"===r)ae(this),function(e){ee(e),oe(e)}(this);else{var t=e._storedError;ie(this,t),re(this,t)}}return Object.defineProperty(e.prototype,"closed",{get:function(){return!1===I(this)?Promise.reject(Z("closed")):this._closedPromise},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"desiredSize",{get:function(){if(!1===I(this))throw Z("desiredSize");if(void 0===this._ownerWritableStream)throw $("desiredSize");return function(e){var r=e._ownerWritableStream,t=r._state;if("errored"===t||"erroring"===t)return null;if("closed"===t)return 0;return V(r._writableStreamController)}(this)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ready",{get:function(){return!1===I(this)?Promise.reject(Z("ready")):this._readyPromise},enumerable:!0,configurable:!0}),e.prototype.abort=function(e){return!1===I(this)?Promise.reject(Z("abort")):void 0===this._ownerWritableStream?Promise.reject($("abort")):function(e,r){return C(e._ownerWritableStream,r)}(this,e)},e.prototype.close=function(){if(!1===I(this))return Promise.reject(Z("close"));var e=this._ownerWritableStream;return void 0===e?Promise.reject($("close")):!0===B(e)?Promise.reject(new TypeError("cannot close an already-closing stream")):L(this)},e.prototype.releaseLock=function(){if(!1===I(this))throw Z("releaseLock");void 0!==this._ownerWritableStream&&N(this)},e.prototype.write=function(e){return!1===I(this)?Promise.reject(Z("write")):void 0===this._ownerWritableStream?Promise.reject($("write to")):Y(this,e)},e}();function I(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_ownerWritableStream")}function L(e){var r=e._ownerWritableStream,t=r._state;if("closed"===t||"errored"===t)return Promise.reject(new TypeError("The stream (in "+t+" state) is not in the writable state and cannot be closed"));var o=new Promise(function(e,t){var o={_resolve:e,_reject:t};r._closeRequest=o});return!0===r._backpressure&&"writable"===t&&ue(e),function(e){w(e,"close",0),Q(e)}(r._writableStreamController),o}function M(e,r){"pending"===e._closedPromiseState?te(e,r):function(e,r){re(e,r)}(e,r)}function D(e,r){"pending"===e._readyPromiseState?se(e,r):function(e,r){ie(e,r)}(e,r)}function N(e){var r=e._ownerWritableStream,t=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");D(e,t),M(e,t),r._writer=void 0,e._ownerWritableStream=void 0}function Y(e,r){var t=e._ownerWritableStream,o=t._writableStreamController,n=function(e,r){try{return e._strategySizeAlgorithm(r)}catch(r){return G(e,r),1}}(o,r);if(t!==e._ownerWritableStream)return Promise.reject($("write to"));var i=t._state;if("errored"===i)return Promise.reject(t._storedError);if(!0===B(t)||"closed"===i)return Promise.reject(new TypeError("The stream is closing or closed and cannot be written to"));if("erroring"===i)return Promise.reject(t._storedError);var a=function(e){return new Promise(function(r,t){var o={_resolve:r,_reject:t};e._writeRequests.push(o)})}(t);return function(e,r,t){var o={chunk:r};try{w(e,o,t)}catch(r){return void G(e,r)}var n=e._controlledWritableStream;if(!1===B(n)&&"writable"===n._state){var i=J(e);k(n,i)}Q(e)}(o,r,n),a}var x=function(){function e(){throw new TypeError("WritableStreamDefaultController cannot be constructed explicitly")}return e.prototype.error=function(e){if(!1===function(e){if(!n(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_controlledWritableStream"))return!1;return!0}(this))throw new TypeError("WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController");"writable"===this._controlledWritableStream._state&&K(this,e)},e.prototype[S]=function(e){var r=this._abortAlgorithm(e);return U(this),r},e.prototype[R]=function(){g(this)},e}();function H(e,r,t,o,n,i,a,s){r._controlledWritableStream=e,e._writableStreamController=r,r._queue=void 0,r._queueTotalSize=void 0,g(r),r._started=!1,r._strategySizeAlgorithm=s,r._strategyHWM=a,r._writeAlgorithm=o,r._closeAlgorithm=n,r._abortAlgorithm=i;var u=J(r);k(e,u);var l=t();Promise.resolve(l).then(function(){r._started=!0,Q(r)},function(t){r._started=!0,A(e,t)}).catch(y)}function U(e){e._writeAlgorithm=void 0,e._closeAlgorithm=void 0,e._abortAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function V(e){return e._strategyHWM-e._queueTotalSize}function Q(e){var r=e._controlledWritableStream;if(!1!==e._started&&void 0===r._inFlightWriteRequest){var t=r._state;if("closed"!==t&&"errored"!==t)if("erroring"!==t){if(0!==e._queue.length){var o=function(e){return e._queue[0].value}(e);"close"===o?function(e){var r=e._controlledWritableStream;(function(e){e._inFlightCloseRequest=e._closeRequest,e._closeRequest=void 0})(r),v(e);var t=e._closeAlgorithm();U(e),t.then(function(){!function(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";var r=e._writer;void 0!==r&&oe(r)}(r)},function(e){!function(e,r){e._inFlightCloseRequest._reject(r),e._inFlightCloseRequest=void 0,void 0!==e._pendingAbortRequest&&(e._pendingAbortRequest._reject(r),e._pendingAbortRequest=void 0),A(e,r)}(r,e)}).catch(y)}(e):function(e,r){var t=e._controlledWritableStream;(function(e){e._inFlightWriteRequest=e._writeRequests.shift()})(t),e._writeAlgorithm(r).then(function(){!function(e){e._inFlightWriteRequest._resolve(void 0),e._inFlightWriteRequest=void 0}(t);var r=t._state;if(v(e),!1===B(t)&&"writable"===r){var o=J(e);k(t,o)}Q(e)},function(r){"writable"===t._state&&U(e),function(e,r){e._inFlightWriteRequest._reject(r),e._inFlightWriteRequest=void 0,A(e,r)}(t,r)}).catch(y)}(e,o.chunk)}}else W(r)}}function G(e,r){"writable"===e._controlledWritableStream._state&&K(e,r)}function J(e){return V(e)<=0}function K(e,r){var t=e._controlledWritableStream;U(e),O(t,r)}function X(e){return new TypeError("WritableStream.prototype."+e+" can only be used on a WritableStream")}function Z(e){return new TypeError("WritableStreamDefaultWriter.prototype."+e+" can only be used on a WritableStreamDefaultWriter")}function $(e){return new TypeError("Cannot "+e+" a stream using a released writer")}function ee(e){e._closedPromise=new Promise(function(r,t){e._closedPromise_resolve=r,e._closedPromise_reject=t,e._closedPromiseState="pending"})}function re(e,r){ee(e),te(e,r)}function te(e,r){e._closedPromise.catch(function(){}),e._closedPromise_reject(r),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="rejected"}function oe(e){e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="resolved"}function ne(e){e._readyPromise=new Promise(function(r,t){e._readyPromise_resolve=r,e._readyPromise_reject=t}),e._readyPromiseState="pending"}function ie(e,r){ne(e),se(e,r)}function ae(e){ne(e),ue(e)}function se(e,r){e._readyPromise.catch(function(){}),e._readyPromise_reject(r),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="rejected"}function ue(e){e._readyPromise_resolve(void 0),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="fulfilled"}var le=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},ce=r("[[CancelSteps]]"),fe=r("[[PullSteps]]"),de=function(){function e(e,r){void 0===e&&(e={}),void 0===r&&(r={}),be(this);var t=r.size,o=r.highWaterMark,n=e.type;if("bytes"===String(n)){if(void 0!==t)throw new RangeError("The strategy for a byte stream cannot have a size function");void 0===o&&(o=0),function(e,r,t){var o=Object.create(Ke.prototype);var n=c(r,"pull",0,[o]),i=c(r,"cancel",1,[]),a=r.autoAllocateChunkSize;if(void 0!==a&&(a=Number(a),!1===le(a)||a<=0))throw new RangeError("autoAllocateChunkSize must be a positive integer");!function(e,r,t,o,n,i,a){r._controlledReadableByteStream=e,r._pullAgain=!1,r._pulling=!1,er(r),r._queue=r._queueTotalSize=void 0,g(r),r._closeRequested=!1,r._started=!1,r._strategyHWM=h(i),r._pullAlgorithm=o,r._cancelAlgorithm=n,r._autoAllocateChunkSize=a,r._pendingPullIntos=[],e._readableStreamController=r;var s=t();Promise.resolve(s).then(function(){r._started=!0,$e(r)},function(e){dr(r,e)}).catch(y)}(e,o,function(){return f(r,"start",[o])},n,i,t,a)}(this,e,o=h(o))}else{if(void 0!==n)throw new RangeError("Invalid type is specified");var i=b(t);void 0===o&&(o=1),function(e,r,t,o){var n=Object.create(Le.prototype);var i=c(r,"pull",0,[n]),a=c(r,"cancel",1,[]);Ge(e,n,function(){return f(r,"start",[n])},i,a,t,o)}(this,e,o=h(o),i)}}return Object.defineProperty(e.prototype,"locked",{get:function(){if(!1===pe(this))throw br("locked");return me(this)},enumerable:!0,configurable:!0}),e.prototype.cancel=function(e){return!1===pe(this)?Promise.reject(br("cancel")):!0===me(this)?Promise.reject(new TypeError("Cannot cancel a stream that already has a reader")):ge(this,e)},e.prototype.getReader=function(e){var r=(void 0===e?{}:e).mode;if(!1===pe(this))throw br("getReader");if(void 0===r)return _e(this);if("byob"===(r=String(r)))return function(e){return new Oe(e)}(this);throw new RangeError("Invalid mode is specified")},e.prototype.pipeThrough=function(e,r){var t=e.writable,o=e.readable,n=void 0===r?{}:r,i=n.preventClose,a=n.preventAbort,s=n.preventCancel,u=n.signal;if(!1===pe(this))throw br("pipeThrough");if(!1===j(t))throw new TypeError("writable argument to pipeThrough must be a WritableStream");if(!1===pe(o))throw new TypeError("readable argument to pipeThrough must be a ReadableStream");if(i=Boolean(i),a=Boolean(a),s=Boolean(s),void 0!==u&&!hr(u))throw new TypeError("ReadableStream.prototype.pipeThrough's signal option must be an AbortSignal");if(!0===me(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(!0===E(t))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return ye(this,t,i,a,s,u).catch(function(){}),o},e.prototype.pipeTo=function(e,r){var t=void 0===r?{}:r,o=t.preventClose,n=t.preventAbort,i=t.preventCancel,a=t.signal;return!1===pe(this)?Promise.reject(br("pipeTo")):!1===j(e)?Promise.reject(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream")):(o=Boolean(o),n=Boolean(n),i=Boolean(i),void 0===a||hr(a)?!0===me(this)?Promise.reject(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):!0===E(e)?Promise.reject(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):ye(this,e,o,n,i,a):Promise.reject(new TypeError("ReadableStream.prototype.pipeTo's signal option must be an AbortSignal")))},e.prototype.tee=function(){if(!1===pe(this))throw br("tee");var e=function(e,r){var t,o,n,i,s,u=_e(e),l=!1,c=!1,f=!1,d=new Promise(function(e){s=e});function _(){return Ie(u).then(function(e){var r=e.value,t=e.done;if(!0===t&&!1===l&&(!1===c&&xe(n._readableStreamController),!1===f&&xe(i._readableStreamController),l=!0),!0!==l){var o=r,a=r;!1===c&&He(n._readableStreamController,o),!1===f&&He(i._readableStreamController,a)}})}function h(){}return n=he(h,_,function(r){if(c=!0,t=r,!0===f){var n=a([t,o]),i=ge(e,n);s(i)}return d}),i=he(h,_,function(r){if(f=!0,o=r,!0===c){var n=a([t,o]),i=ge(e,n);s(i)}return d}),u._closedPromise.catch(function(e){!0!==l&&(Ue(n._readableStreamController,e),Ue(i._readableStreamController,e),l=!0)}),[n,i]}(this);return a(e)},e}();function _e(e){return new Ae(e)}function he(e,r,t,o,n){void 0===o&&(o=1),void 0===n&&(n=function(){return 1});var i=Object.create(de.prototype);return be(i),Ge(i,Object.create(Le.prototype),e,r,t,o,n),i}function be(e){e._state="readable",e._reader=void 0,e._storedError=void 0,e._disturbed=!1}function pe(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readableStreamController")}function me(e){return void 0!==e._reader}function ye(e,r,t,o,n,i){var a=_e(e),s=T(r),u=!1,l=Promise.resolve();return new Promise(function(c,f){var d;if(void 0!==i){if(d=function(){var t=new DOMException("Aborted","AbortError"),i=[];!1===o&&i.push(function(){return"writable"===r._state?C(r,t):Promise.resolve()}),!1===n&&i.push(function(){return"readable"===e._state?ge(e,t):Promise.resolve()}),m(function(){return function(e,r,t){var o,n;void 0===t&&(t=void 0);var i=new Promise(function(e,r){o=e,n=r});return void 0===t&&(t=function(e){throw e}),p(e,function(e){try{var t=r(e);o(t)}catch(e){n(e)}},function(e){try{var r=t(e);o(r)}catch(e){n(e)}}),i}(i.map(function(e){return e()}),function(e){return e})},!0,t)},!0===i.aborted)return void d();i.addEventListener("abort",d)}if(b(e,a._closedPromise,function(e){!1===o?m(function(){return C(r,e)},!0,e):v(!0,e)}),b(r,s._closedPromise,function(r){!1===n?m(function(){return ge(e,r)},!0,r):v(!0,r)}),function(e,r,t){"closed"===e._state?t():r.then(t).catch(y)}(e,a._closedPromise,function(){!1===t?m(function(){return function(e){var r=e._ownerWritableStream,t=r._state;return!0===B(r)||"closed"===t?Promise.resolve():"errored"===t?Promise.reject(r._storedError):L(e)}(s)}):v()}),!0===B(r)||"closed"===r._state){var _=new TypeError("the destination writable stream closed before all data could be piped to it");!1===n?m(function(){return ge(e,_)},!0,_):v(!0,_)}function h(){var e=l;return l.then(function(){return e!==l?h():void 0})}function b(e,r,t){"errored"===e._state?t(e._storedError):r.catch(t).catch(y)}function m(e,t,o){function n(){e().then(function(){return w(t,o)},function(e){return w(!0,e)}).catch(y)}!0!==u&&(u=!0,"writable"===r._state&&!1===B(r)?h().then(n):n())}function v(e,t){!0!==u&&(u=!0,"writable"===r._state&&!1===B(r)?h().then(function(){return w(e,t)}).catch(y):w(e,t))}function w(e,r){N(s),Fe(a),void 0!==i&&i.removeEventListener("abort",d),e?f(r):c(void 0)}new Promise(function(e,r){!function t(o){o?e():(!0===u?Promise.resolve(!0):s._readyPromise.then(function(){return Ie(a).then(function(e){var r=e.value,t=e.done;return!0===t||(l=Y(s,r).catch(function(){}),!1)})})).then(t,r)}(!1)}).catch(function(e){l=Promise.resolve(),y(e)})})}function ve(e,r){return new Promise(function(t,o){var n={_resolve:t,_reject:o,_forAuthorCode:r};e._reader._readIntoRequests.push(n)})}function we(e,r){return new Promise(function(t,o){var n={_resolve:t,_reject:o,_forAuthorCode:r};e._reader._readRequests.push(n)})}function ge(e,r){return e._disturbed=!0,"closed"===e._state?Promise.resolve(void 0):"errored"===e._state?Promise.reject(e._storedError):(Se(e),e._readableStreamController[ce](r).then(function(){}))}function Se(e){e._state="closed";var r=e._reader;if(void 0!==r){if(Be(r)){for(var t=0,o=r._readRequests;t<o.length;t++){var n=o[t];(0,n._resolve)(Re(void 0,!0,n._forAuthorCode))}r._readRequests=[]}gr(r)}}function Re(e,r,t){var o=null;!0===t&&(o=Object.prototype);var n=Object.create(o);return Object.defineProperty(n,"value",{value:e,enumerable:!0,writable:!0,configurable:!0}),Object.defineProperty(n,"done",{value:r,enumerable:!0,writable:!0,configurable:!0}),n}function Pe(e,r){e._state="errored",e._storedError=r;var t=e._reader;if(void 0!==t){if(Be(t)){for(var o=0,n=t._readRequests;o<n.length;o++){n[o]._reject(r)}t._readRequests=[]}else{for(var i=0,a=t._readIntoRequests;i<a.length;i++){a[i]._reject(r)}t._readIntoRequests=[]}wr(t,r)}}function Te(e,r,t){var o=e._reader._readRequests.shift();o._resolve(Re(r,t,o._forAuthorCode))}function qe(e){return e._reader._readIntoRequests.length}function je(e){return e._reader._readRequests.length}function Ee(e){var r=e._reader;return void 0!==r&&!!We(r)}function Ce(e){var r=e._reader;return void 0!==r&&!!Be(r)}var Ae=function(){function e(e){if(!1===pe(e))throw new TypeError("ReadableStreamDefaultReader can only be constructed with a ReadableStream instance");if(!0===me(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");ze(this,e),this._readRequests=[]}return Object.defineProperty(e.prototype,"closed",{get:function(){return Be(this)?this._closedPromise:Promise.reject(mr("closed"))},enumerable:!0,configurable:!0}),e.prototype.cancel=function(e){return Be(this)?void 0===this._ownerReadableStream?Promise.reject(pr("cancel")):ke(this,e):Promise.reject(mr("cancel"))},e.prototype.read=function(){return Be(this)?void 0===this._ownerReadableStream?Promise.reject(pr("read from")):Ie(this,!0):Promise.reject(mr("read"))},e.prototype.releaseLock=function(){if(!Be(this))throw mr("releaseLock");if(void 0!==this._ownerReadableStream){if(this._readRequests.length>0)throw new TypeError("Tried to release a reader lock when that reader has pending read() calls un-settled");Fe(this)}},e}(),Oe=function(){function e(e){if(!pe(e))throw new TypeError("ReadableStreamBYOBReader can only be constructed with a ReadableStream instance given a byte source");if(!1===Xe(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");if(me(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");ze(this,e),this._readIntoRequests=[]}return Object.defineProperty(e.prototype,"closed",{get:function(){return We(this)?this._closedPromise:Promise.reject(Sr("closed"))},enumerable:!0,configurable:!0}),e.prototype.cancel=function(e){return We(this)?void 0===this._ownerReadableStream?Promise.reject(pr("cancel")):ke(this,e):Promise.reject(Sr("cancel"))},e.prototype.read=function(e){return We(this)?void 0===this._ownerReadableStream?Promise.reject(pr("read from")):ArrayBuffer.isView(e)?(e.buffer,0===e.byteLength?Promise.reject(new TypeError("view must have non-zero byteLength")):function(e,r,t){void 0===t&&(t=!1);var o=e._ownerReadableStream;if(o._disturbed=!0,"errored"===o._state)return Promise.reject(o._storedError);return function(e,r,t){var o=e._controlledReadableByteStream,n=1;r.constructor!==DataView&&(n=r.constructor.BYTES_PER_ELEMENT);var i=r.constructor,a={buffer:_(r.buffer),byteOffset:r.byteOffset,byteLength:r.byteLength,bytesFilled:0,elementSize:n,ctor:i,readerType:"byob"};if(e._pendingPullIntos.length>0)return e._pendingPullIntos.push(a),ve(o,t);if("closed"===o._state){var s=new i(a.buffer,a.byteOffset,0);return Promise.resolve(Re(s,!0,t))}if(e._queueTotalSize>0){if(!0===nr(e,a)){var u=tr(a);return ar(e),Promise.resolve(Re(u,!1,t))}if(!0===e._closeRequested){var l=new TypeError("Insufficient bytes to fill elements in the given buffer");return dr(e,l),Promise.reject(l)}}e._pendingPullIntos.push(a);var c=ve(o,t);return $e(e),c}(o._readableStreamController,r,t)}(this,e,!0)):Promise.reject(new TypeError("view must be an array buffer view")):Promise.reject(Sr("read"))},e.prototype.releaseLock=function(){if(!We(this))throw Sr("releaseLock");if(void 0!==this._ownerReadableStream){if(this._readIntoRequests.length>0)throw new TypeError("Tried to release a reader lock when that reader has pending read() calls un-settled");Fe(this)}},e}();function We(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readIntoRequests")}function Be(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readRequests")}function ze(e,r){e._ownerReadableStream=r,r._reader=e,"readable"===r._state?yr(e):"closed"===r._state?function(e){yr(e),gr(e)}(e):vr(e,r._storedError)}function ke(e,r){return ge(e._ownerReadableStream,r)}function Fe(e){"readable"===e._ownerReadableStream._state?wr(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e,r){vr(e,r)}(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")),e._ownerReadableStream._reader=void 0,e._ownerReadableStream=void 0}function Ie(e,r){void 0===r&&(r=!1);var t=e._ownerReadableStream;return t._disturbed=!0,"closed"===t._state?Promise.resolve(Re(void 0,!0,r)):"errored"===t._state?Promise.reject(t._storedError):t._readableStreamController[fe](r)}var Le=function(){function e(){throw new TypeError}return Object.defineProperty(e.prototype,"desiredSize",{get:function(){if(!1===Me(this))throw Rr("desiredSize");return Ve(this)},enumerable:!0,configurable:!0}),e.prototype.close=function(){if(!1===Me(this))throw Rr("close");if(!1===Qe(this))throw new TypeError("The stream is not in a state that permits close");xe(this)},e.prototype.enqueue=function(e){if(!1===Me(this))throw Rr("enqueue");if(!1===Qe(this))throw new TypeError("The stream is not in a state that permits enqueue");return He(this,e)},e.prototype.error=function(e){if(!1===Me(this))throw Rr("error");Ue(this,e)},e.prototype[ce]=function(e){g(this);var r=this._cancelAlgorithm(e);return Ye(this),r},e.prototype[fe]=function(e){var r=this._controlledReadableStream;if(this._queue.length>0){var t=v(this);return!0===this._closeRequested&&0===this._queue.length?(Ye(this),Se(r)):De(this),Promise.resolve(Re(t,!1,e))}var o=we(r,e);return De(this),o},e}();function Me(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableStream")}function De(e){!1!==Ne(e)&&(!0!==e._pulling?(e._pulling=!0,e._pullAlgorithm().then(function(){if(e._pulling=!1,!0===e._pullAgain)return e._pullAgain=!1,De(e)},function(r){Ue(e,r)}).catch(y)):e._pullAgain=!0)}function Ne(e){var r=e._controlledReadableStream;return!1!==Qe(e)&&(!1!==e._started&&(!0===me(r)&&je(r)>0||Ve(e)>0))}function Ye(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function xe(e){var r=e._controlledReadableStream;e._closeRequested=!0,0===e._queue.length&&(Ye(e),Se(r))}function He(e,r){var t=e._controlledReadableStream;if(!0===me(t)&&je(t)>0)Te(t,r,!1);else{var o=void 0;try{o=e._strategySizeAlgorithm(r)}catch(r){throw Ue(e,r),r}try{w(e,r,o)}catch(r){throw Ue(e,r),r}}De(e)}function Ue(e,r){var t=e._controlledReadableStream;"readable"===t._state&&(g(e),Ye(e),Pe(t,r))}function Ve(e){var r=e._controlledReadableStream._state;return"errored"===r?null:"closed"===r?0:e._strategyHWM-e._queueTotalSize}function Qe(e){var r=e._controlledReadableStream._state;return!1===e._closeRequested&&"readable"===r}function Ge(e,r,t,o,n,i,a){r._controlledReadableStream=e,r._queue=void 0,r._queueTotalSize=void 0,g(r),r._started=!1,r._closeRequested=!1,r._pullAgain=!1,r._pulling=!1,r._strategySizeAlgorithm=a,r._strategyHWM=i,r._pullAlgorithm=o,r._cancelAlgorithm=n,e._readableStreamController=r;var s=t();Promise.resolve(s).then(function(){r._started=!0,De(r)},function(e){Ue(r,e)}).catch(y)}var Je=function(){function e(){throw new TypeError("ReadableStreamBYOBRequest cannot be used directly")}return Object.defineProperty(e.prototype,"view",{get:function(){if(!1===Ze(this))throw Pr("view");return this._view},enumerable:!0,configurable:!0}),e.prototype.respond=function(e){if(!1===Ze(this))throw Pr("respond");if(void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");this._view.buffer,function(e,r){if(!1===u(r=Number(r)))throw new RangeError("bytesWritten must be a finite");lr(e,r)}(this._associatedReadableByteStreamController,e)},e.prototype.respondWithNewView=function(e){if(!1===Ze(this))throw Pr("respond");if(void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(!ArrayBuffer.isView(e))throw new TypeError("You can only respond with array buffer views");e.buffer,function(e,r){var t=e._pendingPullIntos[0];if(t.byteOffset+t.bytesFilled!==r.byteOffset)throw new RangeError("The region specified by view does not match byobRequest");if(t.byteLength!==r.byteLength)throw new RangeError("The buffer of view has different capacity than byobRequest");t.buffer=r.buffer,lr(e,r.byteLength)}(this._associatedReadableByteStreamController,e)},e}(),Ke=function(){function e(){throw new TypeError("ReadableByteStreamController constructor cannot be used directly")}return Object.defineProperty(e.prototype,"byobRequest",{get:function(){if(!1===Xe(this))throw Tr("byobRequest");if(void 0===this._byobRequest&&this._pendingPullIntos.length>0){var e=this._pendingPullIntos[0],r=new Uint8Array(e.buffer,e.byteOffset+e.bytesFilled,e.byteLength-e.bytesFilled),t=Object.create(Je.prototype);!function(e,r,t){e._associatedReadableByteStreamController=r,e._view=t}(t,this,r),this._byobRequest=t}return this._byobRequest},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"desiredSize",{get:function(){if(!1===Xe(this))throw Tr("desiredSize");return _r(this)},enumerable:!0,configurable:!0}),e.prototype.close=function(){if(!1===Xe(this))throw Tr("close");if(!0===this._closeRequested)throw new TypeError("The stream has already been closed; do not close it again!");var e=this._controlledReadableByteStream._state;if("readable"!==e)throw new TypeError("The stream (in "+e+" state) is not in the readable state and cannot be closed");!function(e){var r=e._controlledReadableByteStream;if(e._queueTotalSize>0)return void(e._closeRequested=!0);if(e._pendingPullIntos.length>0){var t=e._pendingPullIntos[0];if(t.bytesFilled>0){var o=new TypeError("Insufficient bytes to fill elements in the given buffer");throw dr(e,o),o}}fr(e),Se(r)}(this)},e.prototype.enqueue=function(e){if(!1===Xe(this))throw Tr("enqueue");if(!0===this._closeRequested)throw new TypeError("stream is closed or draining");var r=this._controlledReadableByteStream._state;if("readable"!==r)throw new TypeError("The stream (in "+r+" state) is not in the readable state and cannot be enqueued to");if(!ArrayBuffer.isView(e))throw new TypeError("You can only enqueue array buffer views when using a ReadableByteStreamController");e.buffer,function(e,r){var t=e._controlledReadableByteStream,o=r.buffer,n=r.byteOffset,i=r.byteLength,a=_(o);if(!0===Ce(t))if(0===je(t))or(e,a,n,i);else{var s=new Uint8Array(a,n,i);Te(t,s,!1)}else!0===Ee(t)?(or(e,a,n,i),ur(e)):or(e,a,n,i);$e(e)}(this,e)},e.prototype.error=function(e){if(!1===Xe(this))throw Tr("error");dr(this,e)},e.prototype[ce]=function(e){this._pendingPullIntos.length>0&&(this._pendingPullIntos[0].bytesFilled=0);g(this);var r=this._cancelAlgorithm(e);return fr(this),r},e.prototype[fe]=function(e){var r=this._controlledReadableByteStream;if(this._queueTotalSize>0){var t=this._queue.shift();this._queueTotalSize-=t.byteLength,ar(this);var o=void 0;try{o=new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}catch(e){return Promise.reject(e)}return Promise.resolve(Re(o,!1,e))}var n=this._autoAllocateChunkSize;if(void 0!==n){var i=void 0;try{i=new ArrayBuffer(n)}catch(e){return Promise.reject(e)}var a={buffer:i,byteOffset:0,byteLength:n,bytesFilled:0,elementSize:1,ctor:Uint8Array,readerType:"default"};this._pendingPullIntos.push(a)}var s=we(r,e);return $e(this),s},e}();function Xe(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableByteStream")}function Ze(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_associatedReadableByteStreamController")}function $e(e){!1!==function(e){var r=e._controlledReadableByteStream;if("readable"!==r._state)return!1;if(!0===e._closeRequested)return!1;if(!1===e._started)return!1;if(!0===Ce(r)&&je(r)>0)return!0;if(!0===Ee(r)&&qe(r)>0)return!0;if(_r(e)>0)return!0;return!1}(e)&&(!0!==e._pulling?(e._pulling=!0,e._pullAlgorithm().then(function(){e._pulling=!1,!0===e._pullAgain&&(e._pullAgain=!1,$e(e))},function(r){dr(e,r)}).catch(y)):e._pullAgain=!0)}function er(e){sr(e),e._pendingPullIntos=[]}function rr(e,r){var t=!1;"closed"===e._state&&(t=!0);var o=tr(r);"default"===r.readerType?Te(e,o,t):function(e,r,t){var o=e._reader._readIntoRequests.shift();o._resolve(Re(r,t,o._forAuthorCode))}(e,o,t)}function tr(e){var r=e.bytesFilled,t=e.elementSize;return new e.ctor(e.buffer,e.byteOffset,r/t)}function or(e,r,t,o){e._queue.push({buffer:r,byteOffset:t,byteLength:o}),e._queueTotalSize+=o}function nr(e,r){var t=r.elementSize,o=r.bytesFilled-r.bytesFilled%t,n=Math.min(e._queueTotalSize,r.byteLength-r.bytesFilled),i=r.bytesFilled+n,a=i-i%t,u=n,l=!1;a>o&&(u=a-r.bytesFilled,l=!0);for(var c=e._queue;u>0;){var f=c[0],d=Math.min(u,f.byteLength),_=r.byteOffset+r.bytesFilled;s(r.buffer,_,f.buffer,f.byteOffset,d),f.byteLength===d?c.shift():(f.byteOffset+=d,f.byteLength-=d),e._queueTotalSize-=d,ir(e,d,r),u-=d}return l}function ir(e,r,t){sr(e),t.bytesFilled+=r}function ar(e){0===e._queueTotalSize&&!0===e._closeRequested?(fr(e),Se(e._controlledReadableByteStream)):$e(e)}function sr(e){void 0!==e._byobRequest&&(e._byobRequest._associatedReadableByteStreamController=void 0,e._byobRequest._view=void 0,e._byobRequest=void 0)}function ur(e){for(;e._pendingPullIntos.length>0;){if(0===e._queueTotalSize)return;var r=e._pendingPullIntos[0];!0===nr(e,r)&&(cr(e),rr(e._controlledReadableByteStream,r))}}function lr(e,r){var t=e._pendingPullIntos[0];if("closed"===e._controlledReadableByteStream._state){if(0!==r)throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream");!function(e,r){r.buffer=_(r.buffer);var t=e._controlledReadableByteStream;if(!0===Ee(t))for(;qe(t)>0;)rr(t,cr(e))}(e,t)}else!function(e,r,t){if(t.bytesFilled+r>t.byteLength)throw new RangeError("bytesWritten out of range");if(ir(e,r,t),!(t.bytesFilled<t.elementSize)){cr(e);var o=t.bytesFilled%t.elementSize;if(o>0){var n=t.byteOffset+t.bytesFilled,i=t.buffer.slice(n-o,n);or(e,i,0,i.byteLength)}t.buffer=_(t.buffer),t.bytesFilled-=o,rr(e._controlledReadableByteStream,t),ur(e)}}(e,r,t);$e(e)}function cr(e){var r=e._pendingPullIntos.shift();return sr(e),r}function fr(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0}function dr(e,r){var t=e._controlledReadableByteStream;"readable"===t._state&&(er(e),g(e),fr(e),Pe(t,r))}function _r(e){var r=e._controlledReadableByteStream._state;return"errored"===r?null:"closed"===r?0:e._strategyHWM-e._queueTotalSize}function hr(e){if("object"!=typeof e||null===e)return!1;var r=Object.getOwnPropertyDescriptor(AbortSignal.prototype,"aborted").get;try{return r.call(e),!0}catch(e){return!1}}function br(e){return new TypeError("ReadableStream.prototype."+e+" can only be used on a ReadableStream")}function pr(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function mr(e){return new TypeError("ReadableStreamDefaultReader.prototype."+e+" can only be used on a ReadableStreamDefaultReader")}function yr(e){e._closedPromise=new Promise(function(r,t){e._closedPromise_resolve=r,e._closedPromise_reject=t})}function vr(e,r){yr(e),wr(e,r)}function wr(e,r){e._closedPromise.catch(function(){}),e._closedPromise_reject(r),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0}function gr(e){e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0}function Sr(e){return new TypeError("ReadableStreamBYOBReader.prototype."+e+" can only be used on a ReadableStreamBYOBReader")}function Rr(e){return new TypeError("ReadableStreamDefaultController.prototype."+e+" can only be used on a ReadableStreamDefaultController")}function Pr(e){return new TypeError("ReadableStreamBYOBRequest.prototype."+e+" can only be used on a ReadableStreamBYOBRequest")}function Tr(e){return new TypeError("ReadableByteStreamController.prototype."+e+" can only be used on a ReadableByteStreamController")}var qr=function(){function e(e){i(this,"highWaterMark",e.highWaterMark)}return e.prototype.size=function(e){return e.byteLength},e}(),jr=function(){function e(e){i(this,"highWaterMark",e.highWaterMark)}return e.prototype.size=function(){return 1},e}(),Er=function(){function e(e,r,t){void 0===e&&(e={}),void 0===r&&(r={}),void 0===t&&(t={});var o=r.size,n=r.highWaterMark,i=t.size,a=t.highWaterMark;if(void 0!==e.writableType)throw new RangeError("Invalid writable type specified");var s=b(o);if(void 0===n&&(n=1),n=h(n),void 0!==e.readableType)throw new RangeError("Invalid readable type specified");var u,l=b(i);void 0===a&&(a=0),a=h(a),function(e,r,t,o,n,i){function a(){return r}e._writable=function(e,r,t,o,n,i){void 0===n&&(n=1),void 0===i&&(i=function(){return 1});var a=Object.create(P.prototype);return q(a),H(a,Object.create(x.prototype),e,r,t,o,n,i),a}(a,function(r){return function(e,r){var t=e._transformStreamController;if(!0===e._backpressure){var o=e._backpressureChangePromise;return o.then(function(){var o=e._writable,n=o._state;if("erroring"===n)throw o._storedError;return Ir(t,r)})}return Ir(t,r)}(e,r)},function(){return function(e){var r=e._readable,t=e._transformStreamController,o=t._flushAlgorithm();return kr(t),o.then(function(){if("errored"===r._state)throw r._storedError;var e=r._readableStreamController;!0===Qe(e)&&xe(e)}).catch(function(t){throw Ar(e,t),r._storedError})}(e)},function(r){return function(e,r){return Ar(e,r),Promise.resolve()}(e,r)},t,o),e._readable=he(a,function(){return function(e){return Wr(e,!1),e._backpressureChangePromise}(e)},function(r){return Or(e,r),Promise.resolve()},n,i),e._backpressure=void 0,e._backpressureChangePromise=void 0,e._backpressureChangePromise_resolve=void 0,Wr(e,!0),e._transformStreamController=void 0}(this,new Promise(function(e){u=e}),n,s,a,l),function(e,r){var t=Object.create(Br.prototype),o=function(e){try{return Fr(t,e),Promise.resolve()}catch(e){return Promise.reject(e)}},n=r.transform;if(void 0!==n){if("function"!=typeof n)throw new TypeError("transform is not a method");o=function(e){return d(n,r,[e,t])}}var i=c(r,"flush",0,[t]);!function(e,r,t,o){r._controlledTransformStream=e,e._transformStreamController=r,r._transformAlgorithm=t,r._flushAlgorithm=o}(e,t,o,i)}(this,e);var _=f(e,"start",[this._transformStreamController]);u(_)}return Object.defineProperty(e.prototype,"readable",{get:function(){if(!1===Cr(this))throw Mr("readable");return this._readable},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"writable",{get:function(){if(!1===Cr(this))throw Mr("writable");return this._writable},enumerable:!0,configurable:!0}),e}();function Cr(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_transformStreamController")}function Ar(e,r){Ue(e._readable._readableStreamController,r),Or(e,r)}function Or(e,r){kr(e._transformStreamController),G(e._writable._writableStreamController,r),!0===e._backpressure&&Wr(e,!1)}function Wr(e,r){void 0!==e._backpressureChangePromise&&e._backpressureChangePromise_resolve(),e._backpressureChangePromise=new Promise(function(r){e._backpressureChangePromise_resolve=r}),e._backpressure=r}var Br=function(){function e(){throw new TypeError("TransformStreamDefaultController instances cannot be created directly")}return Object.defineProperty(e.prototype,"desiredSize",{get:function(){if(!1===zr(this))throw Lr("desiredSize");return Ve(this._controlledTransformStream._readable._readableStreamController)},enumerable:!0,configurable:!0}),e.prototype.enqueue=function(e){if(!1===zr(this))throw Lr("enqueue");Fr(this,e)},e.prototype.error=function(e){if(!1===zr(this))throw Lr("error");!function(e,r){Ar(e._controlledTransformStream,r)}(this,e)},e.prototype.terminate=function(){if(!1===zr(this))throw Lr("terminate");!function(e){var r=e._controlledTransformStream,t=r._readable._readableStreamController;!0===Qe(t)&&xe(t);var o=new TypeError("TransformStream terminated");Or(r,o)}(this)},e}();function zr(e){return!!n(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledTransformStream")}function kr(e){e._transformAlgorithm=void 0,e._flushAlgorithm=void 0}function Fr(e,r){var t=e._controlledTransformStream,o=t._readable._readableStreamController;if(!1===Qe(o))throw new TypeError("Readable side is not in a state that permits enqueue");try{He(o,r)}catch(e){throw Or(t,e),t._readable._storedError}(function(e){return!0!==Ne(e)})(o)!==t._backpressure&&Wr(t,!0)}function Ir(e,r){return e._transformAlgorithm(r).catch(function(r){throw Ar(e._controlledTransformStream,r),r})}function Lr(e){return new TypeError("TransformStreamDefaultController.prototype."+e+" can only be used on a TransformStreamDefaultController")}function Mr(e){return new TypeError("TransformStream.prototype."+e+" can only be used on a TransformStream")}var Dr={ReadableStream:de,WritableStream:P,ByteLengthQueuingStrategy:qr,CountQueuingStrategy:jr,TransformStream:Er};void 0!==t&&Object.assign(t,Dr),e.ReadableStream=de,e.WritableStream=P,e.ByteLengthQueuingStrategy=qr,e.CountQueuingStrategy=jr,e.TransformStream=Er,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=polyfill.min.js.map |
/** | ||
* Type definitions for @mattiasbuelens/web-streams-polyfill v0.3.0 | ||
* Type definitions for @mattiasbuelens/web-streams-polyfill v0.3.1 | ||
*/ | ||
@@ -4,0 +4,0 @@ // FILE GENERATED BY `rollup-plugin-dts@0.12.0` |
{ | ||
"name": "@mattiasbuelens/web-streams-polyfill", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Web Streams, based on the WHATWG spec reference implementation", | ||
@@ -5,0 +5,0 @@ "main": "dist/polyfill", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
22962
1872162
28