forked from Simnation/Main
9040 lines
349 KiB
JavaScript
9040 lines
349 KiB
JavaScript
var __create = Object.create;
|
||
var __defProp = Object.defineProperty;
|
||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||
var __getProtoOf = Object.getPrototypeOf;
|
||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||
var __esm = (fn, res) => function __init() {
|
||
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
||
};
|
||
var __commonJS = (cb, mod) => function __require() {
|
||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||
};
|
||
var __export = (target, all) => {
|
||
for (var name in all)
|
||
__defProp(target, name, { get: all[name], enumerable: true });
|
||
};
|
||
var __copyProps = (to, from, except, desc) => {
|
||
if (from && typeof from === "object" || typeof from === "function") {
|
||
for (let key of __getOwnPropNames(from))
|
||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||
}
|
||
return to;
|
||
};
|
||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||
// If the importer is in node compatibility mode or this is not an ESM
|
||
// file that has been converted to a CommonJS file using a Babel-
|
||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||
mod
|
||
));
|
||
|
||
// ../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/unicode.js
|
||
var require_unicode = __commonJS({
|
||
"../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/unicode.js"(exports2, module2) {
|
||
module2.exports.Space_Separator = /[\u1680\u2000-\u200A\u202F\u205F\u3000]/;
|
||
module2.exports.ID_Start = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/;
|
||
module2.exports.ID_Continue = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/;
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/util.js
|
||
var require_util = __commonJS({
|
||
"../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/util.js"(exports2, module2) {
|
||
var unicode = require_unicode();
|
||
module2.exports = {
|
||
isSpaceSeparator(c) {
|
||
return typeof c === "string" && unicode.Space_Separator.test(c);
|
||
},
|
||
isIdStartChar(c) {
|
||
return typeof c === "string" && (c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "$" || c === "_" || unicode.ID_Start.test(c));
|
||
},
|
||
isIdContinueChar(c) {
|
||
return typeof c === "string" && (c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c >= "0" && c <= "9" || c === "$" || c === "_" || c === "\u200C" || c === "\u200D" || unicode.ID_Continue.test(c));
|
||
},
|
||
isDigit(c) {
|
||
return typeof c === "string" && /[0-9]/.test(c);
|
||
},
|
||
isHexDigit(c) {
|
||
return typeof c === "string" && /[0-9A-Fa-f]/.test(c);
|
||
}
|
||
};
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/parse.js
|
||
var require_parse = __commonJS({
|
||
"../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/parse.js"(exports2, module2) {
|
||
var util = require_util();
|
||
var source2;
|
||
var parseState;
|
||
var stack;
|
||
var pos;
|
||
var line;
|
||
var column;
|
||
var token;
|
||
var key;
|
||
var root;
|
||
module2.exports = function parse(text, reviver) {
|
||
source2 = String(text);
|
||
parseState = "start";
|
||
stack = [];
|
||
pos = 0;
|
||
line = 1;
|
||
column = 0;
|
||
token = void 0;
|
||
key = void 0;
|
||
root = void 0;
|
||
do {
|
||
token = lex();
|
||
parseStates[parseState]();
|
||
} while (token.type !== "eof");
|
||
if (typeof reviver === "function") {
|
||
return internalize({ "": root }, "", reviver);
|
||
}
|
||
return root;
|
||
};
|
||
function internalize(holder, name, reviver) {
|
||
const value = holder[name];
|
||
if (value != null && typeof value === "object") {
|
||
if (Array.isArray(value)) {
|
||
for (let i2 = 0; i2 < value.length; i2++) {
|
||
const key2 = String(i2);
|
||
const replacement = internalize(value, key2, reviver);
|
||
if (replacement === void 0) {
|
||
delete value[key2];
|
||
} else {
|
||
Object.defineProperty(value, key2, {
|
||
value: replacement,
|
||
writable: true,
|
||
enumerable: true,
|
||
configurable: true
|
||
});
|
||
}
|
||
}
|
||
} else {
|
||
for (const key2 in value) {
|
||
const replacement = internalize(value, key2, reviver);
|
||
if (replacement === void 0) {
|
||
delete value[key2];
|
||
} else {
|
||
Object.defineProperty(value, key2, {
|
||
value: replacement,
|
||
writable: true,
|
||
enumerable: true,
|
||
configurable: true
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return reviver.call(holder, name, value);
|
||
}
|
||
var lexState;
|
||
var buffer;
|
||
var doubleQuote;
|
||
var sign;
|
||
var c;
|
||
function lex() {
|
||
lexState = "default";
|
||
buffer = "";
|
||
doubleQuote = false;
|
||
sign = 1;
|
||
for (; ; ) {
|
||
c = peek();
|
||
const token2 = lexStates[lexState]();
|
||
if (token2) {
|
||
return token2;
|
||
}
|
||
}
|
||
}
|
||
function peek() {
|
||
if (source2[pos]) {
|
||
return String.fromCodePoint(source2.codePointAt(pos));
|
||
}
|
||
}
|
||
function read() {
|
||
const c2 = peek();
|
||
if (c2 === "\n") {
|
||
line++;
|
||
column = 0;
|
||
} else if (c2) {
|
||
column += c2.length;
|
||
} else {
|
||
column++;
|
||
}
|
||
if (c2) {
|
||
pos += c2.length;
|
||
}
|
||
return c2;
|
||
}
|
||
var lexStates = {
|
||
default() {
|
||
switch (c) {
|
||
case " ":
|
||
case "\v":
|
||
case "\f":
|
||
case " ":
|
||
case "\xA0":
|
||
case "\uFEFF":
|
||
case "\n":
|
||
case "\r":
|
||
case "\u2028":
|
||
case "\u2029":
|
||
read();
|
||
return;
|
||
case "/":
|
||
read();
|
||
lexState = "comment";
|
||
return;
|
||
case void 0:
|
||
read();
|
||
return newToken("eof");
|
||
}
|
||
if (util.isSpaceSeparator(c)) {
|
||
read();
|
||
return;
|
||
}
|
||
return lexStates[parseState]();
|
||
},
|
||
comment() {
|
||
switch (c) {
|
||
case "*":
|
||
read();
|
||
lexState = "multiLineComment";
|
||
return;
|
||
case "/":
|
||
read();
|
||
lexState = "singleLineComment";
|
||
return;
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
multiLineComment() {
|
||
switch (c) {
|
||
case "*":
|
||
read();
|
||
lexState = "multiLineCommentAsterisk";
|
||
return;
|
||
case void 0:
|
||
throw invalidChar(read());
|
||
}
|
||
read();
|
||
},
|
||
multiLineCommentAsterisk() {
|
||
switch (c) {
|
||
case "*":
|
||
read();
|
||
return;
|
||
case "/":
|
||
read();
|
||
lexState = "default";
|
||
return;
|
||
case void 0:
|
||
throw invalidChar(read());
|
||
}
|
||
read();
|
||
lexState = "multiLineComment";
|
||
},
|
||
singleLineComment() {
|
||
switch (c) {
|
||
case "\n":
|
||
case "\r":
|
||
case "\u2028":
|
||
case "\u2029":
|
||
read();
|
||
lexState = "default";
|
||
return;
|
||
case void 0:
|
||
read();
|
||
return newToken("eof");
|
||
}
|
||
read();
|
||
},
|
||
value() {
|
||
switch (c) {
|
||
case "{":
|
||
case "[":
|
||
return newToken("punctuator", read());
|
||
case "n":
|
||
read();
|
||
literal("ull");
|
||
return newToken("null", null);
|
||
case "t":
|
||
read();
|
||
literal("rue");
|
||
return newToken("boolean", true);
|
||
case "f":
|
||
read();
|
||
literal("alse");
|
||
return newToken("boolean", false);
|
||
case "-":
|
||
case "+":
|
||
if (read() === "-") {
|
||
sign = -1;
|
||
}
|
||
lexState = "sign";
|
||
return;
|
||
case ".":
|
||
buffer = read();
|
||
lexState = "decimalPointLeading";
|
||
return;
|
||
case "0":
|
||
buffer = read();
|
||
lexState = "zero";
|
||
return;
|
||
case "1":
|
||
case "2":
|
||
case "3":
|
||
case "4":
|
||
case "5":
|
||
case "6":
|
||
case "7":
|
||
case "8":
|
||
case "9":
|
||
buffer = read();
|
||
lexState = "decimalInteger";
|
||
return;
|
||
case "I":
|
||
read();
|
||
literal("nfinity");
|
||
return newToken("numeric", Infinity);
|
||
case "N":
|
||
read();
|
||
literal("aN");
|
||
return newToken("numeric", NaN);
|
||
case '"':
|
||
case "'":
|
||
doubleQuote = read() === '"';
|
||
buffer = "";
|
||
lexState = "string";
|
||
return;
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
identifierNameStartEscape() {
|
||
if (c !== "u") {
|
||
throw invalidChar(read());
|
||
}
|
||
read();
|
||
const u = unicodeEscape();
|
||
switch (u) {
|
||
case "$":
|
||
case "_":
|
||
break;
|
||
default:
|
||
if (!util.isIdStartChar(u)) {
|
||
throw invalidIdentifier();
|
||
}
|
||
break;
|
||
}
|
||
buffer += u;
|
||
lexState = "identifierName";
|
||
},
|
||
identifierName() {
|
||
switch (c) {
|
||
case "$":
|
||
case "_":
|
||
case "\u200C":
|
||
case "\u200D":
|
||
buffer += read();
|
||
return;
|
||
case "\\":
|
||
read();
|
||
lexState = "identifierNameEscape";
|
||
return;
|
||
}
|
||
if (util.isIdContinueChar(c)) {
|
||
buffer += read();
|
||
return;
|
||
}
|
||
return newToken("identifier", buffer);
|
||
},
|
||
identifierNameEscape() {
|
||
if (c !== "u") {
|
||
throw invalidChar(read());
|
||
}
|
||
read();
|
||
const u = unicodeEscape();
|
||
switch (u) {
|
||
case "$":
|
||
case "_":
|
||
case "\u200C":
|
||
case "\u200D":
|
||
break;
|
||
default:
|
||
if (!util.isIdContinueChar(u)) {
|
||
throw invalidIdentifier();
|
||
}
|
||
break;
|
||
}
|
||
buffer += u;
|
||
lexState = "identifierName";
|
||
},
|
||
sign() {
|
||
switch (c) {
|
||
case ".":
|
||
buffer = read();
|
||
lexState = "decimalPointLeading";
|
||
return;
|
||
case "0":
|
||
buffer = read();
|
||
lexState = "zero";
|
||
return;
|
||
case "1":
|
||
case "2":
|
||
case "3":
|
||
case "4":
|
||
case "5":
|
||
case "6":
|
||
case "7":
|
||
case "8":
|
||
case "9":
|
||
buffer = read();
|
||
lexState = "decimalInteger";
|
||
return;
|
||
case "I":
|
||
read();
|
||
literal("nfinity");
|
||
return newToken("numeric", sign * Infinity);
|
||
case "N":
|
||
read();
|
||
literal("aN");
|
||
return newToken("numeric", NaN);
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
zero() {
|
||
switch (c) {
|
||
case ".":
|
||
buffer += read();
|
||
lexState = "decimalPoint";
|
||
return;
|
||
case "e":
|
||
case "E":
|
||
buffer += read();
|
||
lexState = "decimalExponent";
|
||
return;
|
||
case "x":
|
||
case "X":
|
||
buffer += read();
|
||
lexState = "hexadecimal";
|
||
return;
|
||
}
|
||
return newToken("numeric", sign * 0);
|
||
},
|
||
decimalInteger() {
|
||
switch (c) {
|
||
case ".":
|
||
buffer += read();
|
||
lexState = "decimalPoint";
|
||
return;
|
||
case "e":
|
||
case "E":
|
||
buffer += read();
|
||
lexState = "decimalExponent";
|
||
return;
|
||
}
|
||
if (util.isDigit(c)) {
|
||
buffer += read();
|
||
return;
|
||
}
|
||
return newToken("numeric", sign * Number(buffer));
|
||
},
|
||
decimalPointLeading() {
|
||
if (util.isDigit(c)) {
|
||
buffer += read();
|
||
lexState = "decimalFraction";
|
||
return;
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
decimalPoint() {
|
||
switch (c) {
|
||
case "e":
|
||
case "E":
|
||
buffer += read();
|
||
lexState = "decimalExponent";
|
||
return;
|
||
}
|
||
if (util.isDigit(c)) {
|
||
buffer += read();
|
||
lexState = "decimalFraction";
|
||
return;
|
||
}
|
||
return newToken("numeric", sign * Number(buffer));
|
||
},
|
||
decimalFraction() {
|
||
switch (c) {
|
||
case "e":
|
||
case "E":
|
||
buffer += read();
|
||
lexState = "decimalExponent";
|
||
return;
|
||
}
|
||
if (util.isDigit(c)) {
|
||
buffer += read();
|
||
return;
|
||
}
|
||
return newToken("numeric", sign * Number(buffer));
|
||
},
|
||
decimalExponent() {
|
||
switch (c) {
|
||
case "+":
|
||
case "-":
|
||
buffer += read();
|
||
lexState = "decimalExponentSign";
|
||
return;
|
||
}
|
||
if (util.isDigit(c)) {
|
||
buffer += read();
|
||
lexState = "decimalExponentInteger";
|
||
return;
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
decimalExponentSign() {
|
||
if (util.isDigit(c)) {
|
||
buffer += read();
|
||
lexState = "decimalExponentInteger";
|
||
return;
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
decimalExponentInteger() {
|
||
if (util.isDigit(c)) {
|
||
buffer += read();
|
||
return;
|
||
}
|
||
return newToken("numeric", sign * Number(buffer));
|
||
},
|
||
hexadecimal() {
|
||
if (util.isHexDigit(c)) {
|
||
buffer += read();
|
||
lexState = "hexadecimalInteger";
|
||
return;
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
hexadecimalInteger() {
|
||
if (util.isHexDigit(c)) {
|
||
buffer += read();
|
||
return;
|
||
}
|
||
return newToken("numeric", sign * Number(buffer));
|
||
},
|
||
string() {
|
||
switch (c) {
|
||
case "\\":
|
||
read();
|
||
buffer += escape();
|
||
return;
|
||
case '"':
|
||
if (doubleQuote) {
|
||
read();
|
||
return newToken("string", buffer);
|
||
}
|
||
buffer += read();
|
||
return;
|
||
case "'":
|
||
if (!doubleQuote) {
|
||
read();
|
||
return newToken("string", buffer);
|
||
}
|
||
buffer += read();
|
||
return;
|
||
case "\n":
|
||
case "\r":
|
||
throw invalidChar(read());
|
||
case "\u2028":
|
||
case "\u2029":
|
||
separatorChar(c);
|
||
break;
|
||
case void 0:
|
||
throw invalidChar(read());
|
||
}
|
||
buffer += read();
|
||
},
|
||
start() {
|
||
switch (c) {
|
||
case "{":
|
||
case "[":
|
||
return newToken("punctuator", read());
|
||
}
|
||
lexState = "value";
|
||
},
|
||
beforePropertyName() {
|
||
switch (c) {
|
||
case "$":
|
||
case "_":
|
||
buffer = read();
|
||
lexState = "identifierName";
|
||
return;
|
||
case "\\":
|
||
read();
|
||
lexState = "identifierNameStartEscape";
|
||
return;
|
||
case "}":
|
||
return newToken("punctuator", read());
|
||
case '"':
|
||
case "'":
|
||
doubleQuote = read() === '"';
|
||
lexState = "string";
|
||
return;
|
||
}
|
||
if (util.isIdStartChar(c)) {
|
||
buffer += read();
|
||
lexState = "identifierName";
|
||
return;
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
afterPropertyName() {
|
||
if (c === ":") {
|
||
return newToken("punctuator", read());
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
beforePropertyValue() {
|
||
lexState = "value";
|
||
},
|
||
afterPropertyValue() {
|
||
switch (c) {
|
||
case ",":
|
||
case "}":
|
||
return newToken("punctuator", read());
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
beforeArrayValue() {
|
||
if (c === "]") {
|
||
return newToken("punctuator", read());
|
||
}
|
||
lexState = "value";
|
||
},
|
||
afterArrayValue() {
|
||
switch (c) {
|
||
case ",":
|
||
case "]":
|
||
return newToken("punctuator", read());
|
||
}
|
||
throw invalidChar(read());
|
||
},
|
||
end() {
|
||
throw invalidChar(read());
|
||
}
|
||
};
|
||
function newToken(type, value) {
|
||
return {
|
||
type,
|
||
value,
|
||
line,
|
||
column
|
||
};
|
||
}
|
||
function literal(s2) {
|
||
for (const c2 of s2) {
|
||
const p = peek();
|
||
if (p !== c2) {
|
||
throw invalidChar(read());
|
||
}
|
||
read();
|
||
}
|
||
}
|
||
function escape() {
|
||
const c2 = peek();
|
||
switch (c2) {
|
||
case "b":
|
||
read();
|
||
return "\b";
|
||
case "f":
|
||
read();
|
||
return "\f";
|
||
case "n":
|
||
read();
|
||
return "\n";
|
||
case "r":
|
||
read();
|
||
return "\r";
|
||
case "t":
|
||
read();
|
||
return " ";
|
||
case "v":
|
||
read();
|
||
return "\v";
|
||
case "0":
|
||
read();
|
||
if (util.isDigit(peek())) {
|
||
throw invalidChar(read());
|
||
}
|
||
return "\0";
|
||
case "x":
|
||
read();
|
||
return hexEscape();
|
||
case "u":
|
||
read();
|
||
return unicodeEscape();
|
||
case "\n":
|
||
case "\u2028":
|
||
case "\u2029":
|
||
read();
|
||
return "";
|
||
case "\r":
|
||
read();
|
||
if (peek() === "\n") {
|
||
read();
|
||
}
|
||
return "";
|
||
case "1":
|
||
case "2":
|
||
case "3":
|
||
case "4":
|
||
case "5":
|
||
case "6":
|
||
case "7":
|
||
case "8":
|
||
case "9":
|
||
throw invalidChar(read());
|
||
case void 0:
|
||
throw invalidChar(read());
|
||
}
|
||
return read();
|
||
}
|
||
function hexEscape() {
|
||
let buffer2 = "";
|
||
let c2 = peek();
|
||
if (!util.isHexDigit(c2)) {
|
||
throw invalidChar(read());
|
||
}
|
||
buffer2 += read();
|
||
c2 = peek();
|
||
if (!util.isHexDigit(c2)) {
|
||
throw invalidChar(read());
|
||
}
|
||
buffer2 += read();
|
||
return String.fromCodePoint(parseInt(buffer2, 16));
|
||
}
|
||
function unicodeEscape() {
|
||
let buffer2 = "";
|
||
let count = 4;
|
||
while (count-- > 0) {
|
||
const c2 = peek();
|
||
if (!util.isHexDigit(c2)) {
|
||
throw invalidChar(read());
|
||
}
|
||
buffer2 += read();
|
||
}
|
||
return String.fromCodePoint(parseInt(buffer2, 16));
|
||
}
|
||
var parseStates = {
|
||
start() {
|
||
if (token.type === "eof") {
|
||
throw invalidEOF();
|
||
}
|
||
push();
|
||
},
|
||
beforePropertyName() {
|
||
switch (token.type) {
|
||
case "identifier":
|
||
case "string":
|
||
key = token.value;
|
||
parseState = "afterPropertyName";
|
||
return;
|
||
case "punctuator":
|
||
pop();
|
||
return;
|
||
case "eof":
|
||
throw invalidEOF();
|
||
}
|
||
},
|
||
afterPropertyName() {
|
||
if (token.type === "eof") {
|
||
throw invalidEOF();
|
||
}
|
||
parseState = "beforePropertyValue";
|
||
},
|
||
beforePropertyValue() {
|
||
if (token.type === "eof") {
|
||
throw invalidEOF();
|
||
}
|
||
push();
|
||
},
|
||
beforeArrayValue() {
|
||
if (token.type === "eof") {
|
||
throw invalidEOF();
|
||
}
|
||
if (token.type === "punctuator" && token.value === "]") {
|
||
pop();
|
||
return;
|
||
}
|
||
push();
|
||
},
|
||
afterPropertyValue() {
|
||
if (token.type === "eof") {
|
||
throw invalidEOF();
|
||
}
|
||
switch (token.value) {
|
||
case ",":
|
||
parseState = "beforePropertyName";
|
||
return;
|
||
case "}":
|
||
pop();
|
||
}
|
||
},
|
||
afterArrayValue() {
|
||
if (token.type === "eof") {
|
||
throw invalidEOF();
|
||
}
|
||
switch (token.value) {
|
||
case ",":
|
||
parseState = "beforeArrayValue";
|
||
return;
|
||
case "]":
|
||
pop();
|
||
}
|
||
},
|
||
end() {
|
||
}
|
||
};
|
||
function push() {
|
||
let value;
|
||
switch (token.type) {
|
||
case "punctuator":
|
||
switch (token.value) {
|
||
case "{":
|
||
value = {};
|
||
break;
|
||
case "[":
|
||
value = [];
|
||
break;
|
||
}
|
||
break;
|
||
case "null":
|
||
case "boolean":
|
||
case "numeric":
|
||
case "string":
|
||
value = token.value;
|
||
break;
|
||
}
|
||
if (root === void 0) {
|
||
root = value;
|
||
} else {
|
||
const parent = stack[stack.length - 1];
|
||
if (Array.isArray(parent)) {
|
||
parent.push(value);
|
||
} else {
|
||
Object.defineProperty(parent, key, {
|
||
value,
|
||
writable: true,
|
||
enumerable: true,
|
||
configurable: true
|
||
});
|
||
}
|
||
}
|
||
if (value !== null && typeof value === "object") {
|
||
stack.push(value);
|
||
if (Array.isArray(value)) {
|
||
parseState = "beforeArrayValue";
|
||
} else {
|
||
parseState = "beforePropertyName";
|
||
}
|
||
} else {
|
||
const current = stack[stack.length - 1];
|
||
if (current == null) {
|
||
parseState = "end";
|
||
} else if (Array.isArray(current)) {
|
||
parseState = "afterArrayValue";
|
||
} else {
|
||
parseState = "afterPropertyValue";
|
||
}
|
||
}
|
||
}
|
||
function pop() {
|
||
stack.pop();
|
||
const current = stack[stack.length - 1];
|
||
if (current == null) {
|
||
parseState = "end";
|
||
} else if (Array.isArray(current)) {
|
||
parseState = "afterArrayValue";
|
||
} else {
|
||
parseState = "afterPropertyValue";
|
||
}
|
||
}
|
||
function invalidChar(c2) {
|
||
if (c2 === void 0) {
|
||
return syntaxError(`JSON5: invalid end of input at ${line}:${column}`);
|
||
}
|
||
return syntaxError(`JSON5: invalid character '${formatChar(c2)}' at ${line}:${column}`);
|
||
}
|
||
function invalidEOF() {
|
||
return syntaxError(`JSON5: invalid end of input at ${line}:${column}`);
|
||
}
|
||
function invalidIdentifier() {
|
||
column -= 5;
|
||
return syntaxError(`JSON5: invalid identifier character at ${line}:${column}`);
|
||
}
|
||
function separatorChar(c2) {
|
||
console.warn(`JSON5: '${formatChar(c2)}' in strings is not valid ECMAScript; consider escaping`);
|
||
}
|
||
function formatChar(c2) {
|
||
const replacements = {
|
||
"'": "\\'",
|
||
'"': '\\"',
|
||
"\\": "\\\\",
|
||
"\b": "\\b",
|
||
"\f": "\\f",
|
||
"\n": "\\n",
|
||
"\r": "\\r",
|
||
" ": "\\t",
|
||
"\v": "\\v",
|
||
"\0": "\\0",
|
||
"\u2028": "\\u2028",
|
||
"\u2029": "\\u2029"
|
||
};
|
||
if (replacements[c2]) {
|
||
return replacements[c2];
|
||
}
|
||
if (c2 < " ") {
|
||
const hexString = c2.charCodeAt(0).toString(16);
|
||
return "\\x" + ("00" + hexString).substring(hexString.length);
|
||
}
|
||
return c2;
|
||
}
|
||
function syntaxError(message) {
|
||
const err = new SyntaxError(message);
|
||
err.lineNumber = line;
|
||
err.columnNumber = column;
|
||
return err;
|
||
}
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/stringify.js
|
||
var require_stringify = __commonJS({
|
||
"../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/stringify.js"(exports2, module2) {
|
||
var util = require_util();
|
||
module2.exports = function stringify(value, replacer, space) {
|
||
const stack = [];
|
||
let indent = "";
|
||
let propertyList;
|
||
let replacerFunc;
|
||
let gap = "";
|
||
let quote;
|
||
if (replacer != null && typeof replacer === "object" && !Array.isArray(replacer)) {
|
||
space = replacer.space;
|
||
quote = replacer.quote;
|
||
replacer = replacer.replacer;
|
||
}
|
||
if (typeof replacer === "function") {
|
||
replacerFunc = replacer;
|
||
} else if (Array.isArray(replacer)) {
|
||
propertyList = [];
|
||
for (const v of replacer) {
|
||
let item;
|
||
if (typeof v === "string") {
|
||
item = v;
|
||
} else if (typeof v === "number" || v instanceof String || v instanceof Number) {
|
||
item = String(v);
|
||
}
|
||
if (item !== void 0 && propertyList.indexOf(item) < 0) {
|
||
propertyList.push(item);
|
||
}
|
||
}
|
||
}
|
||
if (space instanceof Number) {
|
||
space = Number(space);
|
||
} else if (space instanceof String) {
|
||
space = String(space);
|
||
}
|
||
if (typeof space === "number") {
|
||
if (space > 0) {
|
||
space = Math.min(10, Math.floor(space));
|
||
gap = " ".substr(0, space);
|
||
}
|
||
} else if (typeof space === "string") {
|
||
gap = space.substr(0, 10);
|
||
}
|
||
return serializeProperty("", { "": value });
|
||
function serializeProperty(key, holder) {
|
||
let value2 = holder[key];
|
||
if (value2 != null) {
|
||
if (typeof value2.toJSON5 === "function") {
|
||
value2 = value2.toJSON5(key);
|
||
} else if (typeof value2.toJSON === "function") {
|
||
value2 = value2.toJSON(key);
|
||
}
|
||
}
|
||
if (replacerFunc) {
|
||
value2 = replacerFunc.call(holder, key, value2);
|
||
}
|
||
if (value2 instanceof Number) {
|
||
value2 = Number(value2);
|
||
} else if (value2 instanceof String) {
|
||
value2 = String(value2);
|
||
} else if (value2 instanceof Boolean) {
|
||
value2 = value2.valueOf();
|
||
}
|
||
switch (value2) {
|
||
case null:
|
||
return "null";
|
||
case true:
|
||
return "true";
|
||
case false:
|
||
return "false";
|
||
}
|
||
if (typeof value2 === "string") {
|
||
return quoteString(value2, false);
|
||
}
|
||
if (typeof value2 === "number") {
|
||
return String(value2);
|
||
}
|
||
if (typeof value2 === "object") {
|
||
return Array.isArray(value2) ? serializeArray(value2) : serializeObject(value2);
|
||
}
|
||
return void 0;
|
||
}
|
||
function quoteString(value2) {
|
||
const quotes = {
|
||
"'": 0.1,
|
||
'"': 0.2
|
||
};
|
||
const replacements = {
|
||
"'": "\\'",
|
||
'"': '\\"',
|
||
"\\": "\\\\",
|
||
"\b": "\\b",
|
||
"\f": "\\f",
|
||
"\n": "\\n",
|
||
"\r": "\\r",
|
||
" ": "\\t",
|
||
"\v": "\\v",
|
||
"\0": "\\0",
|
||
"\u2028": "\\u2028",
|
||
"\u2029": "\\u2029"
|
||
};
|
||
let product = "";
|
||
for (let i2 = 0; i2 < value2.length; i2++) {
|
||
const c = value2[i2];
|
||
switch (c) {
|
||
case "'":
|
||
case '"':
|
||
quotes[c]++;
|
||
product += c;
|
||
continue;
|
||
case "\0":
|
||
if (util.isDigit(value2[i2 + 1])) {
|
||
product += "\\x00";
|
||
continue;
|
||
}
|
||
}
|
||
if (replacements[c]) {
|
||
product += replacements[c];
|
||
continue;
|
||
}
|
||
if (c < " ") {
|
||
let hexString = c.charCodeAt(0).toString(16);
|
||
product += "\\x" + ("00" + hexString).substring(hexString.length);
|
||
continue;
|
||
}
|
||
product += c;
|
||
}
|
||
const quoteChar = quote || Object.keys(quotes).reduce((a, b) => quotes[a] < quotes[b] ? a : b);
|
||
product = product.replace(new RegExp(quoteChar, "g"), replacements[quoteChar]);
|
||
return quoteChar + product + quoteChar;
|
||
}
|
||
function serializeObject(value2) {
|
||
if (stack.indexOf(value2) >= 0) {
|
||
throw TypeError("Converting circular structure to JSON5");
|
||
}
|
||
stack.push(value2);
|
||
let stepback = indent;
|
||
indent = indent + gap;
|
||
let keys = propertyList || Object.keys(value2);
|
||
let partial = [];
|
||
for (const key of keys) {
|
||
const propertyString = serializeProperty(key, value2);
|
||
if (propertyString !== void 0) {
|
||
let member = serializeKey(key) + ":";
|
||
if (gap !== "") {
|
||
member += " ";
|
||
}
|
||
member += propertyString;
|
||
partial.push(member);
|
||
}
|
||
}
|
||
let final;
|
||
if (partial.length === 0) {
|
||
final = "{}";
|
||
} else {
|
||
let properties;
|
||
if (gap === "") {
|
||
properties = partial.join(",");
|
||
final = "{" + properties + "}";
|
||
} else {
|
||
let separator = ",\n" + indent;
|
||
properties = partial.join(separator);
|
||
final = "{\n" + indent + properties + ",\n" + stepback + "}";
|
||
}
|
||
}
|
||
stack.pop();
|
||
indent = stepback;
|
||
return final;
|
||
}
|
||
function serializeKey(key) {
|
||
if (key.length === 0) {
|
||
return quoteString(key, true);
|
||
}
|
||
const firstChar = String.fromCodePoint(key.codePointAt(0));
|
||
if (!util.isIdStartChar(firstChar)) {
|
||
return quoteString(key, true);
|
||
}
|
||
for (let i2 = firstChar.length; i2 < key.length; i2++) {
|
||
if (!util.isIdContinueChar(String.fromCodePoint(key.codePointAt(i2)))) {
|
||
return quoteString(key, true);
|
||
}
|
||
}
|
||
return key;
|
||
}
|
||
function serializeArray(value2) {
|
||
if (stack.indexOf(value2) >= 0) {
|
||
throw TypeError("Converting circular structure to JSON5");
|
||
}
|
||
stack.push(value2);
|
||
let stepback = indent;
|
||
indent = indent + gap;
|
||
let partial = [];
|
||
for (let i2 = 0; i2 < value2.length; i2++) {
|
||
const propertyString = serializeProperty(String(i2), value2);
|
||
partial.push(propertyString !== void 0 ? propertyString : "null");
|
||
}
|
||
let final;
|
||
if (partial.length === 0) {
|
||
final = "[]";
|
||
} else {
|
||
if (gap === "") {
|
||
let properties = partial.join(",");
|
||
final = "[" + properties + "]";
|
||
} else {
|
||
let separator = ",\n" + indent;
|
||
let properties = partial.join(separator);
|
||
final = "[\n" + indent + properties + ",\n" + stepback + "]";
|
||
}
|
||
}
|
||
stack.pop();
|
||
indent = stepback;
|
||
return final;
|
||
}
|
||
};
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/index.js
|
||
var require_lib = __commonJS({
|
||
"../../node_modules/.pnpm/json5@2.2.3/node_modules/json5/lib/index.js"(exports2, module2) {
|
||
var parse = require_parse();
|
||
var stringify = require_stringify();
|
||
var JSON52 = {
|
||
parse,
|
||
stringify
|
||
};
|
||
module2.exports = JSON52;
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/boolean@3.2.0/node_modules/boolean/build/lib/boolean.js
|
||
var require_boolean = __commonJS({
|
||
"../../node_modules/.pnpm/boolean@3.2.0/node_modules/boolean/build/lib/boolean.js"(exports2) {
|
||
"use strict";
|
||
Object.defineProperty(exports2, "__esModule", { value: true });
|
||
exports2.boolean = void 0;
|
||
var boolean = function(value) {
|
||
switch (Object.prototype.toString.call(value)) {
|
||
case "[object String]":
|
||
return ["true", "t", "yes", "y", "on", "1"].includes(value.trim().toLowerCase());
|
||
case "[object Number]":
|
||
return value.valueOf() === 1;
|
||
case "[object Boolean]":
|
||
return value.valueOf();
|
||
default:
|
||
return false;
|
||
}
|
||
};
|
||
exports2.boolean = boolean;
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/boolean@3.2.0/node_modules/boolean/build/lib/isBooleanable.js
|
||
var require_isBooleanable = __commonJS({
|
||
"../../node_modules/.pnpm/boolean@3.2.0/node_modules/boolean/build/lib/isBooleanable.js"(exports2) {
|
||
"use strict";
|
||
Object.defineProperty(exports2, "__esModule", { value: true });
|
||
exports2.isBooleanable = void 0;
|
||
var isBooleanable = function(value) {
|
||
switch (Object.prototype.toString.call(value)) {
|
||
case "[object String]":
|
||
return [
|
||
"true",
|
||
"t",
|
||
"yes",
|
||
"y",
|
||
"on",
|
||
"1",
|
||
"false",
|
||
"f",
|
||
"no",
|
||
"n",
|
||
"off",
|
||
"0"
|
||
].includes(value.trim().toLowerCase());
|
||
case "[object Number]":
|
||
return [0, 1].includes(value.valueOf());
|
||
case "[object Boolean]":
|
||
return true;
|
||
default:
|
||
return false;
|
||
}
|
||
};
|
||
exports2.isBooleanable = isBooleanable;
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/boolean@3.2.0/node_modules/boolean/build/lib/index.js
|
||
var require_lib2 = __commonJS({
|
||
"../../node_modules/.pnpm/boolean@3.2.0/node_modules/boolean/build/lib/index.js"(exports2) {
|
||
"use strict";
|
||
Object.defineProperty(exports2, "__esModule", { value: true });
|
||
exports2.isBooleanable = exports2.boolean = void 0;
|
||
var boolean_1 = require_boolean();
|
||
Object.defineProperty(exports2, "boolean", { enumerable: true, get: function() {
|
||
return boolean_1.boolean;
|
||
} });
|
||
var isBooleanable_1 = require_isBooleanable();
|
||
Object.defineProperty(exports2, "isBooleanable", { enumerable: true, get: function() {
|
||
return isBooleanable_1.isBooleanable;
|
||
} });
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/fast-printf@1.6.9/node_modules/fast-printf/dist/src/tokenize.js
|
||
var require_tokenize = __commonJS({
|
||
"../../node_modules/.pnpm/fast-printf@1.6.9/node_modules/fast-printf/dist/src/tokenize.js"(exports2) {
|
||
"use strict";
|
||
Object.defineProperty(exports2, "__esModule", { value: true });
|
||
exports2.tokenize = void 0;
|
||
var TokenRule = /(?:%(?<flag>([+0-]|-\+))?(?<width>\d+)?(?<position>\d+\$)?(?<precision>\.\d+)?(?<conversion>[%BCESb-iosux]))|(\\%)/g;
|
||
var tokenize = (subject) => {
|
||
let matchResult;
|
||
const tokens = [];
|
||
let argumentIndex = 0;
|
||
let lastIndex = 0;
|
||
let lastToken = null;
|
||
while ((matchResult = TokenRule.exec(subject)) !== null) {
|
||
if (matchResult.index > lastIndex) {
|
||
lastToken = {
|
||
literal: subject.slice(lastIndex, matchResult.index),
|
||
type: "literal"
|
||
};
|
||
tokens.push(lastToken);
|
||
}
|
||
const match = matchResult[0];
|
||
lastIndex = matchResult.index + match.length;
|
||
if (match === "\\%" || match === "%%") {
|
||
if (lastToken && lastToken.type === "literal") {
|
||
lastToken.literal += "%";
|
||
} else {
|
||
lastToken = {
|
||
literal: "%",
|
||
type: "literal"
|
||
};
|
||
tokens.push(lastToken);
|
||
}
|
||
} else if (matchResult.groups) {
|
||
lastToken = {
|
||
conversion: matchResult.groups.conversion,
|
||
flag: matchResult.groups.flag || null,
|
||
placeholder: match,
|
||
position: matchResult.groups.position ? Number.parseInt(matchResult.groups.position, 10) - 1 : argumentIndex++,
|
||
precision: matchResult.groups.precision ? Number.parseInt(matchResult.groups.precision.slice(1), 10) : null,
|
||
type: "placeholder",
|
||
width: matchResult.groups.width ? Number.parseInt(matchResult.groups.width, 10) : null
|
||
};
|
||
tokens.push(lastToken);
|
||
}
|
||
}
|
||
if (lastIndex <= subject.length - 1) {
|
||
if (lastToken && lastToken.type === "literal") {
|
||
lastToken.literal += subject.slice(lastIndex);
|
||
} else {
|
||
tokens.push({
|
||
literal: subject.slice(lastIndex),
|
||
type: "literal"
|
||
});
|
||
}
|
||
}
|
||
return tokens;
|
||
};
|
||
exports2.tokenize = tokenize;
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/fast-printf@1.6.9/node_modules/fast-printf/dist/src/createPrintf.js
|
||
var require_createPrintf = __commonJS({
|
||
"../../node_modules/.pnpm/fast-printf@1.6.9/node_modules/fast-printf/dist/src/createPrintf.js"(exports2) {
|
||
"use strict";
|
||
Object.defineProperty(exports2, "__esModule", { value: true });
|
||
exports2.createPrintf = void 0;
|
||
var boolean_1 = require_lib2();
|
||
var tokenize_1 = require_tokenize();
|
||
var formatDefaultUnboundExpression = (subject, token) => {
|
||
return token.placeholder;
|
||
};
|
||
var createPrintf = (configuration) => {
|
||
var _a;
|
||
const padValue = (value, width, flag) => {
|
||
if (flag === "-") {
|
||
return value.padEnd(width, " ");
|
||
} else if (flag === "-+") {
|
||
return ((Number(value) >= 0 ? "+" : "") + value).padEnd(width, " ");
|
||
} else if (flag === "+") {
|
||
return ((Number(value) >= 0 ? "+" : "") + value).padStart(width, " ");
|
||
} else if (flag === "0") {
|
||
return value.padStart(width, "0");
|
||
} else {
|
||
return value.padStart(width, " ");
|
||
}
|
||
};
|
||
const formatUnboundExpression = (_a = configuration === null || configuration === void 0 ? void 0 : configuration.formatUnboundExpression) !== null && _a !== void 0 ? _a : formatDefaultUnboundExpression;
|
||
const cache2 = {};
|
||
return (subject, ...boundValues) => {
|
||
let tokens = cache2[subject];
|
||
if (!tokens) {
|
||
tokens = cache2[subject] = tokenize_1.tokenize(subject);
|
||
}
|
||
let result = "";
|
||
for (const token of tokens) {
|
||
if (token.type === "literal") {
|
||
result += token.literal;
|
||
} else {
|
||
let boundValue = boundValues[token.position];
|
||
if (boundValue === void 0) {
|
||
result += formatUnboundExpression(subject, token, boundValues);
|
||
} else if (token.conversion === "b") {
|
||
result += boolean_1.boolean(boundValue) ? "true" : "false";
|
||
} else if (token.conversion === "B") {
|
||
result += boolean_1.boolean(boundValue) ? "TRUE" : "FALSE";
|
||
} else if (token.conversion === "c") {
|
||
result += boundValue;
|
||
} else if (token.conversion === "C") {
|
||
result += String(boundValue).toUpperCase();
|
||
} else if (token.conversion === "i" || token.conversion === "d") {
|
||
boundValue = String(Math.trunc(boundValue));
|
||
if (token.width !== null) {
|
||
boundValue = padValue(boundValue, token.width, token.flag);
|
||
}
|
||
result += boundValue;
|
||
} else if (token.conversion === "e") {
|
||
result += Number(boundValue).toExponential();
|
||
} else if (token.conversion === "E") {
|
||
result += Number(boundValue).toExponential().toUpperCase();
|
||
} else if (token.conversion === "f") {
|
||
if (token.precision !== null) {
|
||
boundValue = Number(boundValue).toFixed(token.precision);
|
||
}
|
||
if (token.width !== null) {
|
||
boundValue = padValue(String(boundValue), token.width, token.flag);
|
||
}
|
||
result += boundValue;
|
||
} else if (token.conversion === "o") {
|
||
result += (Number.parseInt(String(boundValue), 10) >>> 0).toString(8);
|
||
} else if (token.conversion === "s") {
|
||
if (token.width !== null) {
|
||
boundValue = padValue(String(boundValue), token.width, token.flag);
|
||
}
|
||
result += boundValue;
|
||
} else if (token.conversion === "S") {
|
||
if (token.width !== null) {
|
||
boundValue = padValue(String(boundValue), token.width, token.flag);
|
||
}
|
||
result += String(boundValue).toUpperCase();
|
||
} else if (token.conversion === "u") {
|
||
result += Number.parseInt(String(boundValue), 10) >>> 0;
|
||
} else if (token.conversion === "x") {
|
||
boundValue = (Number.parseInt(String(boundValue), 10) >>> 0).toString(16);
|
||
if (token.width !== null) {
|
||
boundValue = padValue(String(boundValue), token.width, token.flag);
|
||
}
|
||
result += boundValue;
|
||
} else {
|
||
throw new Error("Unknown format specifier.");
|
||
}
|
||
}
|
||
}
|
||
return result;
|
||
};
|
||
};
|
||
exports2.createPrintf = createPrintf;
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/fast-printf@1.6.9/node_modules/fast-printf/dist/src/printf.js
|
||
var require_printf = __commonJS({
|
||
"../../node_modules/.pnpm/fast-printf@1.6.9/node_modules/fast-printf/dist/src/printf.js"(exports2) {
|
||
"use strict";
|
||
Object.defineProperty(exports2, "__esModule", { value: true });
|
||
exports2.printf = exports2.createPrintf = void 0;
|
||
var createPrintf_1 = require_createPrintf();
|
||
Object.defineProperty(exports2, "createPrintf", { enumerable: true, get: function() {
|
||
return createPrintf_1.createPrintf;
|
||
} });
|
||
exports2.printf = createPrintf_1.createPrintf();
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/web-streams-polyfill@3.3.3/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js
|
||
var require_ponyfill_es2018 = __commonJS({
|
||
"../../node_modules/.pnpm/web-streams-polyfill@3.3.3/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js"(exports2, module2) {
|
||
(function(global2, factory) {
|
||
typeof exports2 === "object" && typeof module2 !== "undefined" ? factory(exports2) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.WebStreamsPolyfill = {}));
|
||
})(exports2, function(exports3) {
|
||
"use strict";
|
||
function noop2() {
|
||
return void 0;
|
||
}
|
||
function typeIsObject(x2) {
|
||
return typeof x2 === "object" && x2 !== null || typeof x2 === "function";
|
||
}
|
||
const rethrowAssertionErrorRejection = noop2;
|
||
function setFunctionName(fn, name) {
|
||
try {
|
||
Object.defineProperty(fn, "name", {
|
||
value: name,
|
||
configurable: true
|
||
});
|
||
} catch (_a2) {
|
||
}
|
||
}
|
||
const originalPromise = Promise;
|
||
const originalPromiseThen = Promise.prototype.then;
|
||
const originalPromiseReject = Promise.reject.bind(originalPromise);
|
||
function newPromise(executor) {
|
||
return new originalPromise(executor);
|
||
}
|
||
function promiseResolvedWith(value) {
|
||
return newPromise((resolve) => resolve(value));
|
||
}
|
||
function promiseRejectedWith(reason) {
|
||
return originalPromiseReject(reason);
|
||
}
|
||
function PerformPromiseThen(promise, onFulfilled, onRejected) {
|
||
return originalPromiseThen.call(promise, onFulfilled, onRejected);
|
||
}
|
||
function uponPromise(promise, onFulfilled, onRejected) {
|
||
PerformPromiseThen(PerformPromiseThen(promise, onFulfilled, onRejected), void 0, rethrowAssertionErrorRejection);
|
||
}
|
||
function uponFulfillment(promise, onFulfilled) {
|
||
uponPromise(promise, onFulfilled);
|
||
}
|
||
function uponRejection(promise, onRejected) {
|
||
uponPromise(promise, void 0, onRejected);
|
||
}
|
||
function transformPromiseWith(promise, fulfillmentHandler, rejectionHandler) {
|
||
return PerformPromiseThen(promise, fulfillmentHandler, rejectionHandler);
|
||
}
|
||
function setPromiseIsHandledToTrue(promise) {
|
||
PerformPromiseThen(promise, void 0, rethrowAssertionErrorRejection);
|
||
}
|
||
let _queueMicrotask = (callback) => {
|
||
if (typeof queueMicrotask === "function") {
|
||
_queueMicrotask = queueMicrotask;
|
||
} else {
|
||
const resolvedPromise = promiseResolvedWith(void 0);
|
||
_queueMicrotask = (cb) => PerformPromiseThen(resolvedPromise, cb);
|
||
}
|
||
return _queueMicrotask(callback);
|
||
};
|
||
function reflectCall(F2, V, args) {
|
||
if (typeof F2 !== "function") {
|
||
throw new TypeError("Argument is not a function");
|
||
}
|
||
return Function.prototype.apply.call(F2, V, args);
|
||
}
|
||
function promiseCall(F2, V, args) {
|
||
try {
|
||
return promiseResolvedWith(reflectCall(F2, V, args));
|
||
} catch (value) {
|
||
return promiseRejectedWith(value);
|
||
}
|
||
}
|
||
const QUEUE_MAX_ARRAY_SIZE = 16384;
|
||
class SimpleQueue {
|
||
constructor() {
|
||
this._cursor = 0;
|
||
this._size = 0;
|
||
this._front = {
|
||
_elements: [],
|
||
_next: void 0
|
||
};
|
||
this._back = this._front;
|
||
this._cursor = 0;
|
||
this._size = 0;
|
||
}
|
||
get length() {
|
||
return this._size;
|
||
}
|
||
// For exception safety, this method is structured in order:
|
||
// 1. Read state
|
||
// 2. Calculate required state mutations
|
||
// 3. Perform state mutations
|
||
push(element) {
|
||
const oldBack = this._back;
|
||
let newBack = oldBack;
|
||
if (oldBack._elements.length === QUEUE_MAX_ARRAY_SIZE - 1) {
|
||
newBack = {
|
||
_elements: [],
|
||
_next: void 0
|
||
};
|
||
}
|
||
oldBack._elements.push(element);
|
||
if (newBack !== oldBack) {
|
||
this._back = newBack;
|
||
oldBack._next = newBack;
|
||
}
|
||
++this._size;
|
||
}
|
||
// Like push(), shift() follows the read -> calculate -> mutate pattern for
|
||
// exception safety.
|
||
shift() {
|
||
const oldFront = this._front;
|
||
let newFront = oldFront;
|
||
const oldCursor = this._cursor;
|
||
let newCursor = oldCursor + 1;
|
||
const elements = oldFront._elements;
|
||
const element = elements[oldCursor];
|
||
if (newCursor === QUEUE_MAX_ARRAY_SIZE) {
|
||
newFront = oldFront._next;
|
||
newCursor = 0;
|
||
}
|
||
--this._size;
|
||
this._cursor = newCursor;
|
||
if (oldFront !== newFront) {
|
||
this._front = newFront;
|
||
}
|
||
elements[oldCursor] = void 0;
|
||
return element;
|
||
}
|
||
// The tricky thing about forEach() is that it can be called
|
||
// re-entrantly. The queue may be mutated inside the callback. It is easy to
|
||
// see that push() within the callback has no negative effects since the end
|
||
// of the queue is checked for on every iteration. If shift() is called
|
||
// repeatedly within the callback then the next iteration may return an
|
||
// element that has been removed. In this case the callback will be called
|
||
// with undefined values until we either "catch up" with elements that still
|
||
// exist or reach the back of the queue.
|
||
forEach(callback) {
|
||
let i2 = this._cursor;
|
||
let node = this._front;
|
||
let elements = node._elements;
|
||
while (i2 !== elements.length || node._next !== void 0) {
|
||
if (i2 === elements.length) {
|
||
node = node._next;
|
||
elements = node._elements;
|
||
i2 = 0;
|
||
if (elements.length === 0) {
|
||
break;
|
||
}
|
||
}
|
||
callback(elements[i2]);
|
||
++i2;
|
||
}
|
||
}
|
||
// Return the element that would be returned if shift() was called now,
|
||
// without modifying the queue.
|
||
peek() {
|
||
const front = this._front;
|
||
const cursor = this._cursor;
|
||
return front._elements[cursor];
|
||
}
|
||
}
|
||
const AbortSteps = Symbol("[[AbortSteps]]");
|
||
const ErrorSteps = Symbol("[[ErrorSteps]]");
|
||
const CancelSteps = Symbol("[[CancelSteps]]");
|
||
const PullSteps = Symbol("[[PullSteps]]");
|
||
const ReleaseSteps = Symbol("[[ReleaseSteps]]");
|
||
function ReadableStreamReaderGenericInitialize(reader, stream) {
|
||
reader._ownerReadableStream = stream;
|
||
stream._reader = reader;
|
||
if (stream._state === "readable") {
|
||
defaultReaderClosedPromiseInitialize(reader);
|
||
} else if (stream._state === "closed") {
|
||
defaultReaderClosedPromiseInitializeAsResolved(reader);
|
||
} else {
|
||
defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError);
|
||
}
|
||
}
|
||
function ReadableStreamReaderGenericCancel(reader, reason) {
|
||
const stream = reader._ownerReadableStream;
|
||
return ReadableStreamCancel(stream, reason);
|
||
}
|
||
function ReadableStreamReaderGenericRelease(reader) {
|
||
const stream = reader._ownerReadableStream;
|
||
if (stream._state === "readable") {
|
||
defaultReaderClosedPromiseReject(reader, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
||
} else {
|
||
defaultReaderClosedPromiseResetToRejected(reader, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
||
}
|
||
stream._readableStreamController[ReleaseSteps]();
|
||
stream._reader = void 0;
|
||
reader._ownerReadableStream = void 0;
|
||
}
|
||
function readerLockException(name) {
|
||
return new TypeError("Cannot " + name + " a stream using a released reader");
|
||
}
|
||
function defaultReaderClosedPromiseInitialize(reader) {
|
||
reader._closedPromise = newPromise((resolve, reject) => {
|
||
reader._closedPromise_resolve = resolve;
|
||
reader._closedPromise_reject = reject;
|
||
});
|
||
}
|
||
function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) {
|
||
defaultReaderClosedPromiseInitialize(reader);
|
||
defaultReaderClosedPromiseReject(reader, reason);
|
||
}
|
||
function defaultReaderClosedPromiseInitializeAsResolved(reader) {
|
||
defaultReaderClosedPromiseInitialize(reader);
|
||
defaultReaderClosedPromiseResolve(reader);
|
||
}
|
||
function defaultReaderClosedPromiseReject(reader, reason) {
|
||
if (reader._closedPromise_reject === void 0) {
|
||
return;
|
||
}
|
||
setPromiseIsHandledToTrue(reader._closedPromise);
|
||
reader._closedPromise_reject(reason);
|
||
reader._closedPromise_resolve = void 0;
|
||
reader._closedPromise_reject = void 0;
|
||
}
|
||
function defaultReaderClosedPromiseResetToRejected(reader, reason) {
|
||
defaultReaderClosedPromiseInitializeAsRejected(reader, reason);
|
||
}
|
||
function defaultReaderClosedPromiseResolve(reader) {
|
||
if (reader._closedPromise_resolve === void 0) {
|
||
return;
|
||
}
|
||
reader._closedPromise_resolve(void 0);
|
||
reader._closedPromise_resolve = void 0;
|
||
reader._closedPromise_reject = void 0;
|
||
}
|
||
const NumberIsFinite = Number.isFinite || function(x2) {
|
||
return typeof x2 === "number" && isFinite(x2);
|
||
};
|
||
const MathTrunc = Math.trunc || function(v) {
|
||
return v < 0 ? Math.ceil(v) : Math.floor(v);
|
||
};
|
||
function isDictionary(x2) {
|
||
return typeof x2 === "object" || typeof x2 === "function";
|
||
}
|
||
function assertDictionary(obj, context) {
|
||
if (obj !== void 0 && !isDictionary(obj)) {
|
||
throw new TypeError(`${context} is not an object.`);
|
||
}
|
||
}
|
||
function assertFunction(x2, context) {
|
||
if (typeof x2 !== "function") {
|
||
throw new TypeError(`${context} is not a function.`);
|
||
}
|
||
}
|
||
function isObject(x2) {
|
||
return typeof x2 === "object" && x2 !== null || typeof x2 === "function";
|
||
}
|
||
function assertObject(x2, context) {
|
||
if (!isObject(x2)) {
|
||
throw new TypeError(`${context} is not an object.`);
|
||
}
|
||
}
|
||
function assertRequiredArgument(x2, position, context) {
|
||
if (x2 === void 0) {
|
||
throw new TypeError(`Parameter ${position} is required in '${context}'.`);
|
||
}
|
||
}
|
||
function assertRequiredField(x2, field, context) {
|
||
if (x2 === void 0) {
|
||
throw new TypeError(`${field} is required in '${context}'.`);
|
||
}
|
||
}
|
||
function convertUnrestrictedDouble(value) {
|
||
return Number(value);
|
||
}
|
||
function censorNegativeZero(x2) {
|
||
return x2 === 0 ? 0 : x2;
|
||
}
|
||
function integerPart(x2) {
|
||
return censorNegativeZero(MathTrunc(x2));
|
||
}
|
||
function convertUnsignedLongLongWithEnforceRange(value, context) {
|
||
const lowerBound = 0;
|
||
const upperBound = Number.MAX_SAFE_INTEGER;
|
||
let x2 = Number(value);
|
||
x2 = censorNegativeZero(x2);
|
||
if (!NumberIsFinite(x2)) {
|
||
throw new TypeError(`${context} is not a finite number`);
|
||
}
|
||
x2 = integerPart(x2);
|
||
if (x2 < lowerBound || x2 > upperBound) {
|
||
throw new TypeError(`${context} is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`);
|
||
}
|
||
if (!NumberIsFinite(x2) || x2 === 0) {
|
||
return 0;
|
||
}
|
||
return x2;
|
||
}
|
||
function assertReadableStream(x2, context) {
|
||
if (!IsReadableStream(x2)) {
|
||
throw new TypeError(`${context} is not a ReadableStream.`);
|
||
}
|
||
}
|
||
function AcquireReadableStreamDefaultReader(stream) {
|
||
return new ReadableStreamDefaultReader(stream);
|
||
}
|
||
function ReadableStreamAddReadRequest(stream, readRequest) {
|
||
stream._reader._readRequests.push(readRequest);
|
||
}
|
||
function ReadableStreamFulfillReadRequest(stream, chunk, done) {
|
||
const reader = stream._reader;
|
||
const readRequest = reader._readRequests.shift();
|
||
if (done) {
|
||
readRequest._closeSteps();
|
||
} else {
|
||
readRequest._chunkSteps(chunk);
|
||
}
|
||
}
|
||
function ReadableStreamGetNumReadRequests(stream) {
|
||
return stream._reader._readRequests.length;
|
||
}
|
||
function ReadableStreamHasDefaultReader(stream) {
|
||
const reader = stream._reader;
|
||
if (reader === void 0) {
|
||
return false;
|
||
}
|
||
if (!IsReadableStreamDefaultReader(reader)) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
class ReadableStreamDefaultReader {
|
||
constructor(stream) {
|
||
assertRequiredArgument(stream, 1, "ReadableStreamDefaultReader");
|
||
assertReadableStream(stream, "First parameter");
|
||
if (IsReadableStreamLocked(stream)) {
|
||
throw new TypeError("This stream has already been locked for exclusive reading by another reader");
|
||
}
|
||
ReadableStreamReaderGenericInitialize(this, stream);
|
||
this._readRequests = new SimpleQueue();
|
||
}
|
||
/**
|
||
* Returns a promise that will be fulfilled when the stream becomes closed,
|
||
* or rejected if the stream ever errors or the reader's lock is released before the stream finishes closing.
|
||
*/
|
||
get closed() {
|
||
if (!IsReadableStreamDefaultReader(this)) {
|
||
return promiseRejectedWith(defaultReaderBrandCheckException("closed"));
|
||
}
|
||
return this._closedPromise;
|
||
}
|
||
/**
|
||
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
||
*/
|
||
cancel(reason = void 0) {
|
||
if (!IsReadableStreamDefaultReader(this)) {
|
||
return promiseRejectedWith(defaultReaderBrandCheckException("cancel"));
|
||
}
|
||
if (this._ownerReadableStream === void 0) {
|
||
return promiseRejectedWith(readerLockException("cancel"));
|
||
}
|
||
return ReadableStreamReaderGenericCancel(this, reason);
|
||
}
|
||
/**
|
||
* Returns a promise that allows access to the next chunk from the stream's internal queue, if available.
|
||
*
|
||
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
||
*/
|
||
read() {
|
||
if (!IsReadableStreamDefaultReader(this)) {
|
||
return promiseRejectedWith(defaultReaderBrandCheckException("read"));
|
||
}
|
||
if (this._ownerReadableStream === void 0) {
|
||
return promiseRejectedWith(readerLockException("read from"));
|
||
}
|
||
let resolvePromise;
|
||
let rejectPromise;
|
||
const promise = newPromise((resolve, reject) => {
|
||
resolvePromise = resolve;
|
||
rejectPromise = reject;
|
||
});
|
||
const readRequest = {
|
||
_chunkSteps: (chunk) => resolvePromise({ value: chunk, done: false }),
|
||
_closeSteps: () => resolvePromise({ value: void 0, done: true }),
|
||
_errorSteps: (e2) => rejectPromise(e2)
|
||
};
|
||
ReadableStreamDefaultReaderRead(this, readRequest);
|
||
return promise;
|
||
}
|
||
/**
|
||
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
||
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
||
* from now on; otherwise, the reader will appear closed.
|
||
*
|
||
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
||
* the reader's {@link ReadableStreamDefaultReader.read | read()} method has not yet been settled. Attempting to
|
||
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
||
*/
|
||
releaseLock() {
|
||
if (!IsReadableStreamDefaultReader(this)) {
|
||
throw defaultReaderBrandCheckException("releaseLock");
|
||
}
|
||
if (this._ownerReadableStream === void 0) {
|
||
return;
|
||
}
|
||
ReadableStreamDefaultReaderRelease(this);
|
||
}
|
||
}
|
||
Object.defineProperties(ReadableStreamDefaultReader.prototype, {
|
||
cancel: { enumerable: true },
|
||
read: { enumerable: true },
|
||
releaseLock: { enumerable: true },
|
||
closed: { enumerable: true }
|
||
});
|
||
setFunctionName(ReadableStreamDefaultReader.prototype.cancel, "cancel");
|
||
setFunctionName(ReadableStreamDefaultReader.prototype.read, "read");
|
||
setFunctionName(ReadableStreamDefaultReader.prototype.releaseLock, "releaseLock");
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(ReadableStreamDefaultReader.prototype, Symbol.toStringTag, {
|
||
value: "ReadableStreamDefaultReader",
|
||
configurable: true
|
||
});
|
||
}
|
||
function IsReadableStreamDefaultReader(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_readRequests")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof ReadableStreamDefaultReader;
|
||
}
|
||
function ReadableStreamDefaultReaderRead(reader, readRequest) {
|
||
const stream = reader._ownerReadableStream;
|
||
stream._disturbed = true;
|
||
if (stream._state === "closed") {
|
||
readRequest._closeSteps();
|
||
} else if (stream._state === "errored") {
|
||
readRequest._errorSteps(stream._storedError);
|
||
} else {
|
||
stream._readableStreamController[PullSteps](readRequest);
|
||
}
|
||
}
|
||
function ReadableStreamDefaultReaderRelease(reader) {
|
||
ReadableStreamReaderGenericRelease(reader);
|
||
const e2 = new TypeError("Reader was released");
|
||
ReadableStreamDefaultReaderErrorReadRequests(reader, e2);
|
||
}
|
||
function ReadableStreamDefaultReaderErrorReadRequests(reader, e2) {
|
||
const readRequests = reader._readRequests;
|
||
reader._readRequests = new SimpleQueue();
|
||
readRequests.forEach((readRequest) => {
|
||
readRequest._errorSteps(e2);
|
||
});
|
||
}
|
||
function defaultReaderBrandCheckException(name) {
|
||
return new TypeError(`ReadableStreamDefaultReader.prototype.${name} can only be used on a ReadableStreamDefaultReader`);
|
||
}
|
||
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {
|
||
}).prototype);
|
||
class ReadableStreamAsyncIteratorImpl {
|
||
constructor(reader, preventCancel) {
|
||
this._ongoingPromise = void 0;
|
||
this._isFinished = false;
|
||
this._reader = reader;
|
||
this._preventCancel = preventCancel;
|
||
}
|
||
next() {
|
||
const nextSteps = () => this._nextSteps();
|
||
this._ongoingPromise = this._ongoingPromise ? transformPromiseWith(this._ongoingPromise, nextSteps, nextSteps) : nextSteps();
|
||
return this._ongoingPromise;
|
||
}
|
||
return(value) {
|
||
const returnSteps = () => this._returnSteps(value);
|
||
return this._ongoingPromise ? transformPromiseWith(this._ongoingPromise, returnSteps, returnSteps) : returnSteps();
|
||
}
|
||
_nextSteps() {
|
||
if (this._isFinished) {
|
||
return Promise.resolve({ value: void 0, done: true });
|
||
}
|
||
const reader = this._reader;
|
||
let resolvePromise;
|
||
let rejectPromise;
|
||
const promise = newPromise((resolve, reject) => {
|
||
resolvePromise = resolve;
|
||
rejectPromise = reject;
|
||
});
|
||
const readRequest = {
|
||
_chunkSteps: (chunk) => {
|
||
this._ongoingPromise = void 0;
|
||
_queueMicrotask(() => resolvePromise({ value: chunk, done: false }));
|
||
},
|
||
_closeSteps: () => {
|
||
this._ongoingPromise = void 0;
|
||
this._isFinished = true;
|
||
ReadableStreamReaderGenericRelease(reader);
|
||
resolvePromise({ value: void 0, done: true });
|
||
},
|
||
_errorSteps: (reason) => {
|
||
this._ongoingPromise = void 0;
|
||
this._isFinished = true;
|
||
ReadableStreamReaderGenericRelease(reader);
|
||
rejectPromise(reason);
|
||
}
|
||
};
|
||
ReadableStreamDefaultReaderRead(reader, readRequest);
|
||
return promise;
|
||
}
|
||
_returnSteps(value) {
|
||
if (this._isFinished) {
|
||
return Promise.resolve({ value, done: true });
|
||
}
|
||
this._isFinished = true;
|
||
const reader = this._reader;
|
||
if (!this._preventCancel) {
|
||
const result = ReadableStreamReaderGenericCancel(reader, value);
|
||
ReadableStreamReaderGenericRelease(reader);
|
||
return transformPromiseWith(result, () => ({ value, done: true }));
|
||
}
|
||
ReadableStreamReaderGenericRelease(reader);
|
||
return promiseResolvedWith({ value, done: true });
|
||
}
|
||
}
|
||
const ReadableStreamAsyncIteratorPrototype = {
|
||
next() {
|
||
if (!IsReadableStreamAsyncIterator(this)) {
|
||
return promiseRejectedWith(streamAsyncIteratorBrandCheckException("next"));
|
||
}
|
||
return this._asyncIteratorImpl.next();
|
||
},
|
||
return(value) {
|
||
if (!IsReadableStreamAsyncIterator(this)) {
|
||
return promiseRejectedWith(streamAsyncIteratorBrandCheckException("return"));
|
||
}
|
||
return this._asyncIteratorImpl.return(value);
|
||
}
|
||
};
|
||
Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype);
|
||
function AcquireReadableStreamAsyncIterator(stream, preventCancel) {
|
||
const reader = AcquireReadableStreamDefaultReader(stream);
|
||
const impl = new ReadableStreamAsyncIteratorImpl(reader, preventCancel);
|
||
const iterator = Object.create(ReadableStreamAsyncIteratorPrototype);
|
||
iterator._asyncIteratorImpl = impl;
|
||
return iterator;
|
||
}
|
||
function IsReadableStreamAsyncIterator(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_asyncIteratorImpl")) {
|
||
return false;
|
||
}
|
||
try {
|
||
return x2._asyncIteratorImpl instanceof ReadableStreamAsyncIteratorImpl;
|
||
} catch (_a2) {
|
||
return false;
|
||
}
|
||
}
|
||
function streamAsyncIteratorBrandCheckException(name) {
|
||
return new TypeError(`ReadableStreamAsyncIterator.${name} can only be used on a ReadableSteamAsyncIterator`);
|
||
}
|
||
const NumberIsNaN = Number.isNaN || function(x2) {
|
||
return x2 !== x2;
|
||
};
|
||
var _a, _b, _c;
|
||
function CreateArrayFromList(elements) {
|
||
return elements.slice();
|
||
}
|
||
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
||
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
||
}
|
||
let TransferArrayBuffer = (O) => {
|
||
if (typeof O.transfer === "function") {
|
||
TransferArrayBuffer = (buffer) => buffer.transfer();
|
||
} else if (typeof structuredClone === "function") {
|
||
TransferArrayBuffer = (buffer) => structuredClone(buffer, { transfer: [buffer] });
|
||
} else {
|
||
TransferArrayBuffer = (buffer) => buffer;
|
||
}
|
||
return TransferArrayBuffer(O);
|
||
};
|
||
let IsDetachedBuffer = (O) => {
|
||
if (typeof O.detached === "boolean") {
|
||
IsDetachedBuffer = (buffer) => buffer.detached;
|
||
} else {
|
||
IsDetachedBuffer = (buffer) => buffer.byteLength === 0;
|
||
}
|
||
return IsDetachedBuffer(O);
|
||
};
|
||
function ArrayBufferSlice(buffer, begin, end) {
|
||
if (buffer.slice) {
|
||
return buffer.slice(begin, end);
|
||
}
|
||
const length = end - begin;
|
||
const slice = new ArrayBuffer(length);
|
||
CopyDataBlockBytes(slice, 0, buffer, begin, length);
|
||
return slice;
|
||
}
|
||
function GetMethod(receiver, prop) {
|
||
const func = receiver[prop];
|
||
if (func === void 0 || func === null) {
|
||
return void 0;
|
||
}
|
||
if (typeof func !== "function") {
|
||
throw new TypeError(`${String(prop)} is not a function`);
|
||
}
|
||
return func;
|
||
}
|
||
function CreateAsyncFromSyncIterator(syncIteratorRecord) {
|
||
const syncIterable = {
|
||
[Symbol.iterator]: () => syncIteratorRecord.iterator
|
||
};
|
||
const asyncIterator = async function* () {
|
||
return yield* syncIterable;
|
||
}();
|
||
const nextMethod = asyncIterator.next;
|
||
return { iterator: asyncIterator, nextMethod, done: false };
|
||
}
|
||
const SymbolAsyncIterator = (_c = (_a = Symbol.asyncIterator) !== null && _a !== void 0 ? _a : (_b = Symbol.for) === null || _b === void 0 ? void 0 : _b.call(Symbol, "Symbol.asyncIterator")) !== null && _c !== void 0 ? _c : "@@asyncIterator";
|
||
function GetIterator(obj, hint = "sync", method) {
|
||
if (method === void 0) {
|
||
if (hint === "async") {
|
||
method = GetMethod(obj, SymbolAsyncIterator);
|
||
if (method === void 0) {
|
||
const syncMethod = GetMethod(obj, Symbol.iterator);
|
||
const syncIteratorRecord = GetIterator(obj, "sync", syncMethod);
|
||
return CreateAsyncFromSyncIterator(syncIteratorRecord);
|
||
}
|
||
} else {
|
||
method = GetMethod(obj, Symbol.iterator);
|
||
}
|
||
}
|
||
if (method === void 0) {
|
||
throw new TypeError("The object is not iterable");
|
||
}
|
||
const iterator = reflectCall(method, obj, []);
|
||
if (!typeIsObject(iterator)) {
|
||
throw new TypeError("The iterator method must return an object");
|
||
}
|
||
const nextMethod = iterator.next;
|
||
return { iterator, nextMethod, done: false };
|
||
}
|
||
function IteratorNext(iteratorRecord) {
|
||
const result = reflectCall(iteratorRecord.nextMethod, iteratorRecord.iterator, []);
|
||
if (!typeIsObject(result)) {
|
||
throw new TypeError("The iterator.next() method must return an object");
|
||
}
|
||
return result;
|
||
}
|
||
function IteratorComplete(iterResult) {
|
||
return Boolean(iterResult.done);
|
||
}
|
||
function IteratorValue(iterResult) {
|
||
return iterResult.value;
|
||
}
|
||
function IsNonNegativeNumber(v) {
|
||
if (typeof v !== "number") {
|
||
return false;
|
||
}
|
||
if (NumberIsNaN(v)) {
|
||
return false;
|
||
}
|
||
if (v < 0) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
function CloneAsUint8Array(O) {
|
||
const buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
|
||
return new Uint8Array(buffer);
|
||
}
|
||
function DequeueValue(container) {
|
||
const pair = container._queue.shift();
|
||
container._queueTotalSize -= pair.size;
|
||
if (container._queueTotalSize < 0) {
|
||
container._queueTotalSize = 0;
|
||
}
|
||
return pair.value;
|
||
}
|
||
function EnqueueValueWithSize(container, value, size) {
|
||
if (!IsNonNegativeNumber(size) || size === Infinity) {
|
||
throw new RangeError("Size must be a finite, non-NaN, non-negative number.");
|
||
}
|
||
container._queue.push({ value, size });
|
||
container._queueTotalSize += size;
|
||
}
|
||
function PeekQueueValue(container) {
|
||
const pair = container._queue.peek();
|
||
return pair.value;
|
||
}
|
||
function ResetQueue(container) {
|
||
container._queue = new SimpleQueue();
|
||
container._queueTotalSize = 0;
|
||
}
|
||
function isDataViewConstructor(ctor) {
|
||
return ctor === DataView;
|
||
}
|
||
function isDataView(view) {
|
||
return isDataViewConstructor(view.constructor);
|
||
}
|
||
function arrayBufferViewElementSize(ctor) {
|
||
if (isDataViewConstructor(ctor)) {
|
||
return 1;
|
||
}
|
||
return ctor.BYTES_PER_ELEMENT;
|
||
}
|
||
class ReadableStreamBYOBRequest {
|
||
constructor() {
|
||
throw new TypeError("Illegal constructor");
|
||
}
|
||
/**
|
||
* Returns the view for writing in to, or `null` if the BYOB request has already been responded to.
|
||
*/
|
||
get view() {
|
||
if (!IsReadableStreamBYOBRequest(this)) {
|
||
throw byobRequestBrandCheckException("view");
|
||
}
|
||
return this._view;
|
||
}
|
||
respond(bytesWritten) {
|
||
if (!IsReadableStreamBYOBRequest(this)) {
|
||
throw byobRequestBrandCheckException("respond");
|
||
}
|
||
assertRequiredArgument(bytesWritten, 1, "respond");
|
||
bytesWritten = convertUnsignedLongLongWithEnforceRange(bytesWritten, "First parameter");
|
||
if (this._associatedReadableByteStreamController === void 0) {
|
||
throw new TypeError("This BYOB request has been invalidated");
|
||
}
|
||
if (IsDetachedBuffer(this._view.buffer)) {
|
||
throw new TypeError(`The BYOB request's buffer has been detached and so cannot be used as a response`);
|
||
}
|
||
ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
|
||
}
|
||
respondWithNewView(view) {
|
||
if (!IsReadableStreamBYOBRequest(this)) {
|
||
throw byobRequestBrandCheckException("respondWithNewView");
|
||
}
|
||
assertRequiredArgument(view, 1, "respondWithNewView");
|
||
if (!ArrayBuffer.isView(view)) {
|
||
throw new TypeError("You can only respond with array buffer views");
|
||
}
|
||
if (this._associatedReadableByteStreamController === void 0) {
|
||
throw new TypeError("This BYOB request has been invalidated");
|
||
}
|
||
if (IsDetachedBuffer(view.buffer)) {
|
||
throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");
|
||
}
|
||
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
||
}
|
||
}
|
||
Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
|
||
respond: { enumerable: true },
|
||
respondWithNewView: { enumerable: true },
|
||
view: { enumerable: true }
|
||
});
|
||
setFunctionName(ReadableStreamBYOBRequest.prototype.respond, "respond");
|
||
setFunctionName(ReadableStreamBYOBRequest.prototype.respondWithNewView, "respondWithNewView");
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(ReadableStreamBYOBRequest.prototype, Symbol.toStringTag, {
|
||
value: "ReadableStreamBYOBRequest",
|
||
configurable: true
|
||
});
|
||
}
|
||
class ReadableByteStreamController {
|
||
constructor() {
|
||
throw new TypeError("Illegal constructor");
|
||
}
|
||
/**
|
||
* Returns the current BYOB pull request, or `null` if there isn't one.
|
||
*/
|
||
get byobRequest() {
|
||
if (!IsReadableByteStreamController(this)) {
|
||
throw byteStreamControllerBrandCheckException("byobRequest");
|
||
}
|
||
return ReadableByteStreamControllerGetBYOBRequest(this);
|
||
}
|
||
/**
|
||
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
||
* over-full. An underlying byte source ought to use this information to determine when and how to apply backpressure.
|
||
*/
|
||
get desiredSize() {
|
||
if (!IsReadableByteStreamController(this)) {
|
||
throw byteStreamControllerBrandCheckException("desiredSize");
|
||
}
|
||
return ReadableByteStreamControllerGetDesiredSize(this);
|
||
}
|
||
/**
|
||
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
||
* the stream, but once those are read, the stream will become closed.
|
||
*/
|
||
close() {
|
||
if (!IsReadableByteStreamController(this)) {
|
||
throw byteStreamControllerBrandCheckException("close");
|
||
}
|
||
if (this._closeRequested) {
|
||
throw new TypeError("The stream has already been closed; do not close it again!");
|
||
}
|
||
const state = this._controlledReadableByteStream._state;
|
||
if (state !== "readable") {
|
||
throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be closed`);
|
||
}
|
||
ReadableByteStreamControllerClose(this);
|
||
}
|
||
enqueue(chunk) {
|
||
if (!IsReadableByteStreamController(this)) {
|
||
throw byteStreamControllerBrandCheckException("enqueue");
|
||
}
|
||
assertRequiredArgument(chunk, 1, "enqueue");
|
||
if (!ArrayBuffer.isView(chunk)) {
|
||
throw new TypeError("chunk must be an array buffer view");
|
||
}
|
||
if (chunk.byteLength === 0) {
|
||
throw new TypeError("chunk must have non-zero byteLength");
|
||
}
|
||
if (chunk.buffer.byteLength === 0) {
|
||
throw new TypeError(`chunk's buffer must have non-zero byteLength`);
|
||
}
|
||
if (this._closeRequested) {
|
||
throw new TypeError("stream is closed or draining");
|
||
}
|
||
const state = this._controlledReadableByteStream._state;
|
||
if (state !== "readable") {
|
||
throw new TypeError(`The stream (in ${state} state) is not in the readable state and cannot be enqueued to`);
|
||
}
|
||
ReadableByteStreamControllerEnqueue(this, chunk);
|
||
}
|
||
/**
|
||
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
||
*/
|
||
error(e2 = void 0) {
|
||
if (!IsReadableByteStreamController(this)) {
|
||
throw byteStreamControllerBrandCheckException("error");
|
||
}
|
||
ReadableByteStreamControllerError(this, e2);
|
||
}
|
||
/** @internal */
|
||
[CancelSteps](reason) {
|
||
ReadableByteStreamControllerClearPendingPullIntos(this);
|
||
ResetQueue(this);
|
||
const result = this._cancelAlgorithm(reason);
|
||
ReadableByteStreamControllerClearAlgorithms(this);
|
||
return result;
|
||
}
|
||
/** @internal */
|
||
[PullSteps](readRequest) {
|
||
const stream = this._controlledReadableByteStream;
|
||
if (this._queueTotalSize > 0) {
|
||
ReadableByteStreamControllerFillReadRequestFromQueue(this, readRequest);
|
||
return;
|
||
}
|
||
const autoAllocateChunkSize = this._autoAllocateChunkSize;
|
||
if (autoAllocateChunkSize !== void 0) {
|
||
let buffer;
|
||
try {
|
||
buffer = new ArrayBuffer(autoAllocateChunkSize);
|
||
} catch (bufferE) {
|
||
readRequest._errorSteps(bufferE);
|
||
return;
|
||
}
|
||
const pullIntoDescriptor = {
|
||
buffer,
|
||
bufferByteLength: autoAllocateChunkSize,
|
||
byteOffset: 0,
|
||
byteLength: autoAllocateChunkSize,
|
||
bytesFilled: 0,
|
||
minimumFill: 1,
|
||
elementSize: 1,
|
||
viewConstructor: Uint8Array,
|
||
readerType: "default"
|
||
};
|
||
this._pendingPullIntos.push(pullIntoDescriptor);
|
||
}
|
||
ReadableStreamAddReadRequest(stream, readRequest);
|
||
ReadableByteStreamControllerCallPullIfNeeded(this);
|
||
}
|
||
/** @internal */
|
||
[ReleaseSteps]() {
|
||
if (this._pendingPullIntos.length > 0) {
|
||
const firstPullInto = this._pendingPullIntos.peek();
|
||
firstPullInto.readerType = "none";
|
||
this._pendingPullIntos = new SimpleQueue();
|
||
this._pendingPullIntos.push(firstPullInto);
|
||
}
|
||
}
|
||
}
|
||
Object.defineProperties(ReadableByteStreamController.prototype, {
|
||
close: { enumerable: true },
|
||
enqueue: { enumerable: true },
|
||
error: { enumerable: true },
|
||
byobRequest: { enumerable: true },
|
||
desiredSize: { enumerable: true }
|
||
});
|
||
setFunctionName(ReadableByteStreamController.prototype.close, "close");
|
||
setFunctionName(ReadableByteStreamController.prototype.enqueue, "enqueue");
|
||
setFunctionName(ReadableByteStreamController.prototype.error, "error");
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(ReadableByteStreamController.prototype, Symbol.toStringTag, {
|
||
value: "ReadableByteStreamController",
|
||
configurable: true
|
||
});
|
||
}
|
||
function IsReadableByteStreamController(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_controlledReadableByteStream")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof ReadableByteStreamController;
|
||
}
|
||
function IsReadableStreamBYOBRequest(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_associatedReadableByteStreamController")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof ReadableStreamBYOBRequest;
|
||
}
|
||
function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
||
const shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
|
||
if (!shouldPull) {
|
||
return;
|
||
}
|
||
if (controller._pulling) {
|
||
controller._pullAgain = true;
|
||
return;
|
||
}
|
||
controller._pulling = true;
|
||
const pullPromise = controller._pullAlgorithm();
|
||
uponPromise(pullPromise, () => {
|
||
controller._pulling = false;
|
||
if (controller._pullAgain) {
|
||
controller._pullAgain = false;
|
||
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
||
}
|
||
return null;
|
||
}, (e2) => {
|
||
ReadableByteStreamControllerError(controller, e2);
|
||
return null;
|
||
});
|
||
}
|
||
function ReadableByteStreamControllerClearPendingPullIntos(controller) {
|
||
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
||
controller._pendingPullIntos = new SimpleQueue();
|
||
}
|
||
function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {
|
||
let done = false;
|
||
if (stream._state === "closed") {
|
||
done = true;
|
||
}
|
||
const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
|
||
if (pullIntoDescriptor.readerType === "default") {
|
||
ReadableStreamFulfillReadRequest(stream, filledView, done);
|
||
} else {
|
||
ReadableStreamFulfillReadIntoRequest(stream, filledView, done);
|
||
}
|
||
}
|
||
function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {
|
||
const bytesFilled = pullIntoDescriptor.bytesFilled;
|
||
const elementSize = pullIntoDescriptor.elementSize;
|
||
return new pullIntoDescriptor.viewConstructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);
|
||
}
|
||
function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {
|
||
controller._queue.push({ buffer, byteOffset, byteLength });
|
||
controller._queueTotalSize += byteLength;
|
||
}
|
||
function ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller, buffer, byteOffset, byteLength) {
|
||
let clonedChunk;
|
||
try {
|
||
clonedChunk = ArrayBufferSlice(buffer, byteOffset, byteOffset + byteLength);
|
||
} catch (cloneE) {
|
||
ReadableByteStreamControllerError(controller, cloneE);
|
||
throw cloneE;
|
||
}
|
||
ReadableByteStreamControllerEnqueueChunkToQueue(controller, clonedChunk, 0, byteLength);
|
||
}
|
||
function ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, firstDescriptor) {
|
||
if (firstDescriptor.bytesFilled > 0) {
|
||
ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller, firstDescriptor.buffer, firstDescriptor.byteOffset, firstDescriptor.bytesFilled);
|
||
}
|
||
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
||
}
|
||
function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {
|
||
const maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);
|
||
const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
|
||
let totalBytesToCopyRemaining = maxBytesToCopy;
|
||
let ready = false;
|
||
const remainderBytes = maxBytesFilled % pullIntoDescriptor.elementSize;
|
||
const maxAlignedBytes = maxBytesFilled - remainderBytes;
|
||
if (maxAlignedBytes >= pullIntoDescriptor.minimumFill) {
|
||
totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
|
||
ready = true;
|
||
}
|
||
const queue = controller._queue;
|
||
while (totalBytesToCopyRemaining > 0) {
|
||
const headOfQueue = queue.peek();
|
||
const bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);
|
||
const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
||
CopyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);
|
||
if (headOfQueue.byteLength === bytesToCopy) {
|
||
queue.shift();
|
||
} else {
|
||
headOfQueue.byteOffset += bytesToCopy;
|
||
headOfQueue.byteLength -= bytesToCopy;
|
||
}
|
||
controller._queueTotalSize -= bytesToCopy;
|
||
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);
|
||
totalBytesToCopyRemaining -= bytesToCopy;
|
||
}
|
||
return ready;
|
||
}
|
||
function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
|
||
pullIntoDescriptor.bytesFilled += size;
|
||
}
|
||
function ReadableByteStreamControllerHandleQueueDrain(controller) {
|
||
if (controller._queueTotalSize === 0 && controller._closeRequested) {
|
||
ReadableByteStreamControllerClearAlgorithms(controller);
|
||
ReadableStreamClose(controller._controlledReadableByteStream);
|
||
} else {
|
||
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
||
}
|
||
}
|
||
function ReadableByteStreamControllerInvalidateBYOBRequest(controller) {
|
||
if (controller._byobRequest === null) {
|
||
return;
|
||
}
|
||
controller._byobRequest._associatedReadableByteStreamController = void 0;
|
||
controller._byobRequest._view = null;
|
||
controller._byobRequest = null;
|
||
}
|
||
function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {
|
||
while (controller._pendingPullIntos.length > 0) {
|
||
if (controller._queueTotalSize === 0) {
|
||
return;
|
||
}
|
||
const pullIntoDescriptor = controller._pendingPullIntos.peek();
|
||
if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
|
||
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
||
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
||
}
|
||
}
|
||
}
|
||
function ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller) {
|
||
const reader = controller._controlledReadableByteStream._reader;
|
||
while (reader._readRequests.length > 0) {
|
||
if (controller._queueTotalSize === 0) {
|
||
return;
|
||
}
|
||
const readRequest = reader._readRequests.shift();
|
||
ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest);
|
||
}
|
||
}
|
||
function ReadableByteStreamControllerPullInto(controller, view, min, readIntoRequest) {
|
||
const stream = controller._controlledReadableByteStream;
|
||
const ctor = view.constructor;
|
||
const elementSize = arrayBufferViewElementSize(ctor);
|
||
const { byteOffset, byteLength } = view;
|
||
const minimumFill = min * elementSize;
|
||
let buffer;
|
||
try {
|
||
buffer = TransferArrayBuffer(view.buffer);
|
||
} catch (e2) {
|
||
readIntoRequest._errorSteps(e2);
|
||
return;
|
||
}
|
||
const pullIntoDescriptor = {
|
||
buffer,
|
||
bufferByteLength: buffer.byteLength,
|
||
byteOffset,
|
||
byteLength,
|
||
bytesFilled: 0,
|
||
minimumFill,
|
||
elementSize,
|
||
viewConstructor: ctor,
|
||
readerType: "byob"
|
||
};
|
||
if (controller._pendingPullIntos.length > 0) {
|
||
controller._pendingPullIntos.push(pullIntoDescriptor);
|
||
ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
|
||
return;
|
||
}
|
||
if (stream._state === "closed") {
|
||
const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);
|
||
readIntoRequest._closeSteps(emptyView);
|
||
return;
|
||
}
|
||
if (controller._queueTotalSize > 0) {
|
||
if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
|
||
const filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
|
||
ReadableByteStreamControllerHandleQueueDrain(controller);
|
||
readIntoRequest._chunkSteps(filledView);
|
||
return;
|
||
}
|
||
if (controller._closeRequested) {
|
||
const e2 = new TypeError("Insufficient bytes to fill elements in the given buffer");
|
||
ReadableByteStreamControllerError(controller, e2);
|
||
readIntoRequest._errorSteps(e2);
|
||
return;
|
||
}
|
||
}
|
||
controller._pendingPullIntos.push(pullIntoDescriptor);
|
||
ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
|
||
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
||
}
|
||
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
||
if (firstDescriptor.readerType === "none") {
|
||
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
||
}
|
||
const stream = controller._controlledReadableByteStream;
|
||
if (ReadableStreamHasBYOBReader(stream)) {
|
||
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
||
const pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller);
|
||
ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);
|
||
}
|
||
}
|
||
}
|
||
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
||
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
||
if (pullIntoDescriptor.readerType === "none") {
|
||
ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, pullIntoDescriptor);
|
||
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
||
return;
|
||
}
|
||
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.minimumFill) {
|
||
return;
|
||
}
|
||
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
||
const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
||
if (remainderSize > 0) {
|
||
const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
||
ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller, pullIntoDescriptor.buffer, end - remainderSize, remainderSize);
|
||
}
|
||
pullIntoDescriptor.bytesFilled -= remainderSize;
|
||
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
||
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
||
}
|
||
function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
||
const firstDescriptor = controller._pendingPullIntos.peek();
|
||
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
||
const state = controller._controlledReadableByteStream._state;
|
||
if (state === "closed") {
|
||
ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
|
||
} else {
|
||
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
||
}
|
||
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
||
}
|
||
function ReadableByteStreamControllerShiftPendingPullInto(controller) {
|
||
const descriptor = controller._pendingPullIntos.shift();
|
||
return descriptor;
|
||
}
|
||
function ReadableByteStreamControllerShouldCallPull(controller) {
|
||
const stream = controller._controlledReadableByteStream;
|
||
if (stream._state !== "readable") {
|
||
return false;
|
||
}
|
||
if (controller._closeRequested) {
|
||
return false;
|
||
}
|
||
if (!controller._started) {
|
||
return false;
|
||
}
|
||
if (ReadableStreamHasDefaultReader(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
||
return true;
|
||
}
|
||
if (ReadableStreamHasBYOBReader(stream) && ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
||
return true;
|
||
}
|
||
const desiredSize = ReadableByteStreamControllerGetDesiredSize(controller);
|
||
if (desiredSize > 0) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
function ReadableByteStreamControllerClearAlgorithms(controller) {
|
||
controller._pullAlgorithm = void 0;
|
||
controller._cancelAlgorithm = void 0;
|
||
}
|
||
function ReadableByteStreamControllerClose(controller) {
|
||
const stream = controller._controlledReadableByteStream;
|
||
if (controller._closeRequested || stream._state !== "readable") {
|
||
return;
|
||
}
|
||
if (controller._queueTotalSize > 0) {
|
||
controller._closeRequested = true;
|
||
return;
|
||
}
|
||
if (controller._pendingPullIntos.length > 0) {
|
||
const firstPendingPullInto = controller._pendingPullIntos.peek();
|
||
if (firstPendingPullInto.bytesFilled % firstPendingPullInto.elementSize !== 0) {
|
||
const e2 = new TypeError("Insufficient bytes to fill elements in the given buffer");
|
||
ReadableByteStreamControllerError(controller, e2);
|
||
throw e2;
|
||
}
|
||
}
|
||
ReadableByteStreamControllerClearAlgorithms(controller);
|
||
ReadableStreamClose(stream);
|
||
}
|
||
function ReadableByteStreamControllerEnqueue(controller, chunk) {
|
||
const stream = controller._controlledReadableByteStream;
|
||
if (controller._closeRequested || stream._state !== "readable") {
|
||
return;
|
||
}
|
||
const { buffer, byteOffset, byteLength } = chunk;
|
||
if (IsDetachedBuffer(buffer)) {
|
||
throw new TypeError("chunk's buffer is detached and so cannot be enqueued");
|
||
}
|
||
const transferredBuffer = TransferArrayBuffer(buffer);
|
||
if (controller._pendingPullIntos.length > 0) {
|
||
const firstPendingPullInto = controller._pendingPullIntos.peek();
|
||
if (IsDetachedBuffer(firstPendingPullInto.buffer)) {
|
||
throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");
|
||
}
|
||
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
||
firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
|
||
if (firstPendingPullInto.readerType === "none") {
|
||
ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, firstPendingPullInto);
|
||
}
|
||
}
|
||
if (ReadableStreamHasDefaultReader(stream)) {
|
||
ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller);
|
||
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
||
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
||
} else {
|
||
if (controller._pendingPullIntos.length > 0) {
|
||
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
||
}
|
||
const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
|
||
ReadableStreamFulfillReadRequest(stream, transferredView, false);
|
||
}
|
||
} else if (ReadableStreamHasBYOBReader(stream)) {
|
||
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
||
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
||
} else {
|
||
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
||
}
|
||
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
||
}
|
||
function ReadableByteStreamControllerError(controller, e2) {
|
||
const stream = controller._controlledReadableByteStream;
|
||
if (stream._state !== "readable") {
|
||
return;
|
||
}
|
||
ReadableByteStreamControllerClearPendingPullIntos(controller);
|
||
ResetQueue(controller);
|
||
ReadableByteStreamControllerClearAlgorithms(controller);
|
||
ReadableStreamError(stream, e2);
|
||
}
|
||
function ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest) {
|
||
const entry = controller._queue.shift();
|
||
controller._queueTotalSize -= entry.byteLength;
|
||
ReadableByteStreamControllerHandleQueueDrain(controller);
|
||
const view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
|
||
readRequest._chunkSteps(view);
|
||
}
|
||
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
||
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
||
const firstDescriptor = controller._pendingPullIntos.peek();
|
||
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
||
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
||
SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
|
||
controller._byobRequest = byobRequest;
|
||
}
|
||
return controller._byobRequest;
|
||
}
|
||
function ReadableByteStreamControllerGetDesiredSize(controller) {
|
||
const state = controller._controlledReadableByteStream._state;
|
||
if (state === "errored") {
|
||
return null;
|
||
}
|
||
if (state === "closed") {
|
||
return 0;
|
||
}
|
||
return controller._strategyHWM - controller._queueTotalSize;
|
||
}
|
||
function ReadableByteStreamControllerRespond(controller, bytesWritten) {
|
||
const firstDescriptor = controller._pendingPullIntos.peek();
|
||
const state = controller._controlledReadableByteStream._state;
|
||
if (state === "closed") {
|
||
if (bytesWritten !== 0) {
|
||
throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream");
|
||
}
|
||
} else {
|
||
if (bytesWritten === 0) {
|
||
throw new TypeError("bytesWritten must be greater than 0 when calling respond() on a readable stream");
|
||
}
|
||
if (firstDescriptor.bytesFilled + bytesWritten > firstDescriptor.byteLength) {
|
||
throw new RangeError("bytesWritten out of range");
|
||
}
|
||
}
|
||
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
||
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
||
}
|
||
function ReadableByteStreamControllerRespondWithNewView(controller, view) {
|
||
const firstDescriptor = controller._pendingPullIntos.peek();
|
||
const state = controller._controlledReadableByteStream._state;
|
||
if (state === "closed") {
|
||
if (view.byteLength !== 0) {
|
||
throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
|
||
}
|
||
} else {
|
||
if (view.byteLength === 0) {
|
||
throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");
|
||
}
|
||
}
|
||
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
|
||
throw new RangeError("The region specified by view does not match byobRequest");
|
||
}
|
||
if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
|
||
throw new RangeError("The buffer of view has different capacity than byobRequest");
|
||
}
|
||
if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
|
||
throw new RangeError("The region specified by view is larger than byobRequest");
|
||
}
|
||
const viewByteLength = view.byteLength;
|
||
firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
|
||
ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
|
||
}
|
||
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
||
controller._controlledReadableByteStream = stream;
|
||
controller._pullAgain = false;
|
||
controller._pulling = false;
|
||
controller._byobRequest = null;
|
||
controller._queue = controller._queueTotalSize = void 0;
|
||
ResetQueue(controller);
|
||
controller._closeRequested = false;
|
||
controller._started = false;
|
||
controller._strategyHWM = highWaterMark;
|
||
controller._pullAlgorithm = pullAlgorithm;
|
||
controller._cancelAlgorithm = cancelAlgorithm;
|
||
controller._autoAllocateChunkSize = autoAllocateChunkSize;
|
||
controller._pendingPullIntos = new SimpleQueue();
|
||
stream._readableStreamController = controller;
|
||
const startResult = startAlgorithm();
|
||
uponPromise(promiseResolvedWith(startResult), () => {
|
||
controller._started = true;
|
||
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
||
return null;
|
||
}, (r2) => {
|
||
ReadableByteStreamControllerError(controller, r2);
|
||
return null;
|
||
});
|
||
}
|
||
function SetUpReadableByteStreamControllerFromUnderlyingSource(stream, underlyingByteSource, highWaterMark) {
|
||
const controller = Object.create(ReadableByteStreamController.prototype);
|
||
let startAlgorithm;
|
||
let pullAlgorithm;
|
||
let cancelAlgorithm;
|
||
if (underlyingByteSource.start !== void 0) {
|
||
startAlgorithm = () => underlyingByteSource.start(controller);
|
||
} else {
|
||
startAlgorithm = () => void 0;
|
||
}
|
||
if (underlyingByteSource.pull !== void 0) {
|
||
pullAlgorithm = () => underlyingByteSource.pull(controller);
|
||
} else {
|
||
pullAlgorithm = () => promiseResolvedWith(void 0);
|
||
}
|
||
if (underlyingByteSource.cancel !== void 0) {
|
||
cancelAlgorithm = (reason) => underlyingByteSource.cancel(reason);
|
||
} else {
|
||
cancelAlgorithm = () => promiseResolvedWith(void 0);
|
||
}
|
||
const autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
|
||
if (autoAllocateChunkSize === 0) {
|
||
throw new TypeError("autoAllocateChunkSize must be greater than 0");
|
||
}
|
||
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
||
}
|
||
function SetUpReadableStreamBYOBRequest(request, controller, view) {
|
||
request._associatedReadableByteStreamController = controller;
|
||
request._view = view;
|
||
}
|
||
function byobRequestBrandCheckException(name) {
|
||
return new TypeError(`ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`);
|
||
}
|
||
function byteStreamControllerBrandCheckException(name) {
|
||
return new TypeError(`ReadableByteStreamController.prototype.${name} can only be used on a ReadableByteStreamController`);
|
||
}
|
||
function convertReaderOptions(options, context) {
|
||
assertDictionary(options, context);
|
||
const mode = options === null || options === void 0 ? void 0 : options.mode;
|
||
return {
|
||
mode: mode === void 0 ? void 0 : convertReadableStreamReaderMode(mode, `${context} has member 'mode' that`)
|
||
};
|
||
}
|
||
function convertReadableStreamReaderMode(mode, context) {
|
||
mode = `${mode}`;
|
||
if (mode !== "byob") {
|
||
throw new TypeError(`${context} '${mode}' is not a valid enumeration value for ReadableStreamReaderMode`);
|
||
}
|
||
return mode;
|
||
}
|
||
function convertByobReadOptions(options, context) {
|
||
var _a2;
|
||
assertDictionary(options, context);
|
||
const min = (_a2 = options === null || options === void 0 ? void 0 : options.min) !== null && _a2 !== void 0 ? _a2 : 1;
|
||
return {
|
||
min: convertUnsignedLongLongWithEnforceRange(min, `${context} has member 'min' that`)
|
||
};
|
||
}
|
||
function AcquireReadableStreamBYOBReader(stream) {
|
||
return new ReadableStreamBYOBReader(stream);
|
||
}
|
||
function ReadableStreamAddReadIntoRequest(stream, readIntoRequest) {
|
||
stream._reader._readIntoRequests.push(readIntoRequest);
|
||
}
|
||
function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) {
|
||
const reader = stream._reader;
|
||
const readIntoRequest = reader._readIntoRequests.shift();
|
||
if (done) {
|
||
readIntoRequest._closeSteps(chunk);
|
||
} else {
|
||
readIntoRequest._chunkSteps(chunk);
|
||
}
|
||
}
|
||
function ReadableStreamGetNumReadIntoRequests(stream) {
|
||
return stream._reader._readIntoRequests.length;
|
||
}
|
||
function ReadableStreamHasBYOBReader(stream) {
|
||
const reader = stream._reader;
|
||
if (reader === void 0) {
|
||
return false;
|
||
}
|
||
if (!IsReadableStreamBYOBReader(reader)) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
class ReadableStreamBYOBReader {
|
||
constructor(stream) {
|
||
assertRequiredArgument(stream, 1, "ReadableStreamBYOBReader");
|
||
assertReadableStream(stream, "First parameter");
|
||
if (IsReadableStreamLocked(stream)) {
|
||
throw new TypeError("This stream has already been locked for exclusive reading by another reader");
|
||
}
|
||
if (!IsReadableByteStreamController(stream._readableStreamController)) {
|
||
throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");
|
||
}
|
||
ReadableStreamReaderGenericInitialize(this, stream);
|
||
this._readIntoRequests = new SimpleQueue();
|
||
}
|
||
/**
|
||
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
||
* the reader's lock is released before the stream finishes closing.
|
||
*/
|
||
get closed() {
|
||
if (!IsReadableStreamBYOBReader(this)) {
|
||
return promiseRejectedWith(byobReaderBrandCheckException("closed"));
|
||
}
|
||
return this._closedPromise;
|
||
}
|
||
/**
|
||
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
||
*/
|
||
cancel(reason = void 0) {
|
||
if (!IsReadableStreamBYOBReader(this)) {
|
||
return promiseRejectedWith(byobReaderBrandCheckException("cancel"));
|
||
}
|
||
if (this._ownerReadableStream === void 0) {
|
||
return promiseRejectedWith(readerLockException("cancel"));
|
||
}
|
||
return ReadableStreamReaderGenericCancel(this, reason);
|
||
}
|
||
read(view, rawOptions = {}) {
|
||
if (!IsReadableStreamBYOBReader(this)) {
|
||
return promiseRejectedWith(byobReaderBrandCheckException("read"));
|
||
}
|
||
if (!ArrayBuffer.isView(view)) {
|
||
return promiseRejectedWith(new TypeError("view must be an array buffer view"));
|
||
}
|
||
if (view.byteLength === 0) {
|
||
return promiseRejectedWith(new TypeError("view must have non-zero byteLength"));
|
||
}
|
||
if (view.buffer.byteLength === 0) {
|
||
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
||
}
|
||
if (IsDetachedBuffer(view.buffer)) {
|
||
return promiseRejectedWith(new TypeError("view's buffer has been detached"));
|
||
}
|
||
let options;
|
||
try {
|
||
options = convertByobReadOptions(rawOptions, "options");
|
||
} catch (e2) {
|
||
return promiseRejectedWith(e2);
|
||
}
|
||
const min = options.min;
|
||
if (min === 0) {
|
||
return promiseRejectedWith(new TypeError("options.min must be greater than 0"));
|
||
}
|
||
if (!isDataView(view)) {
|
||
if (min > view.length) {
|
||
return promiseRejectedWith(new RangeError("options.min must be less than or equal to view's length"));
|
||
}
|
||
} else if (min > view.byteLength) {
|
||
return promiseRejectedWith(new RangeError("options.min must be less than or equal to view's byteLength"));
|
||
}
|
||
if (this._ownerReadableStream === void 0) {
|
||
return promiseRejectedWith(readerLockException("read from"));
|
||
}
|
||
let resolvePromise;
|
||
let rejectPromise;
|
||
const promise = newPromise((resolve, reject) => {
|
||
resolvePromise = resolve;
|
||
rejectPromise = reject;
|
||
});
|
||
const readIntoRequest = {
|
||
_chunkSteps: (chunk) => resolvePromise({ value: chunk, done: false }),
|
||
_closeSteps: (chunk) => resolvePromise({ value: chunk, done: true }),
|
||
_errorSteps: (e2) => rejectPromise(e2)
|
||
};
|
||
ReadableStreamBYOBReaderRead(this, view, min, readIntoRequest);
|
||
return promise;
|
||
}
|
||
/**
|
||
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
||
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
||
* from now on; otherwise, the reader will appear closed.
|
||
*
|
||
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
||
* the reader's {@link ReadableStreamBYOBReader.read | read()} method has not yet been settled. Attempting to
|
||
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
||
*/
|
||
releaseLock() {
|
||
if (!IsReadableStreamBYOBReader(this)) {
|
||
throw byobReaderBrandCheckException("releaseLock");
|
||
}
|
||
if (this._ownerReadableStream === void 0) {
|
||
return;
|
||
}
|
||
ReadableStreamBYOBReaderRelease(this);
|
||
}
|
||
}
|
||
Object.defineProperties(ReadableStreamBYOBReader.prototype, {
|
||
cancel: { enumerable: true },
|
||
read: { enumerable: true },
|
||
releaseLock: { enumerable: true },
|
||
closed: { enumerable: true }
|
||
});
|
||
setFunctionName(ReadableStreamBYOBReader.prototype.cancel, "cancel");
|
||
setFunctionName(ReadableStreamBYOBReader.prototype.read, "read");
|
||
setFunctionName(ReadableStreamBYOBReader.prototype.releaseLock, "releaseLock");
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(ReadableStreamBYOBReader.prototype, Symbol.toStringTag, {
|
||
value: "ReadableStreamBYOBReader",
|
||
configurable: true
|
||
});
|
||
}
|
||
function IsReadableStreamBYOBReader(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_readIntoRequests")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof ReadableStreamBYOBReader;
|
||
}
|
||
function ReadableStreamBYOBReaderRead(reader, view, min, readIntoRequest) {
|
||
const stream = reader._ownerReadableStream;
|
||
stream._disturbed = true;
|
||
if (stream._state === "errored") {
|
||
readIntoRequest._errorSteps(stream._storedError);
|
||
} else {
|
||
ReadableByteStreamControllerPullInto(stream._readableStreamController, view, min, readIntoRequest);
|
||
}
|
||
}
|
||
function ReadableStreamBYOBReaderRelease(reader) {
|
||
ReadableStreamReaderGenericRelease(reader);
|
||
const e2 = new TypeError("Reader was released");
|
||
ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e2);
|
||
}
|
||
function ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e2) {
|
||
const readIntoRequests = reader._readIntoRequests;
|
||
reader._readIntoRequests = new SimpleQueue();
|
||
readIntoRequests.forEach((readIntoRequest) => {
|
||
readIntoRequest._errorSteps(e2);
|
||
});
|
||
}
|
||
function byobReaderBrandCheckException(name) {
|
||
return new TypeError(`ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`);
|
||
}
|
||
function ExtractHighWaterMark(strategy, defaultHWM) {
|
||
const { highWaterMark } = strategy;
|
||
if (highWaterMark === void 0) {
|
||
return defaultHWM;
|
||
}
|
||
if (NumberIsNaN(highWaterMark) || highWaterMark < 0) {
|
||
throw new RangeError("Invalid highWaterMark");
|
||
}
|
||
return highWaterMark;
|
||
}
|
||
function ExtractSizeAlgorithm(strategy) {
|
||
const { size } = strategy;
|
||
if (!size) {
|
||
return () => 1;
|
||
}
|
||
return size;
|
||
}
|
||
function convertQueuingStrategy(init, context) {
|
||
assertDictionary(init, context);
|
||
const highWaterMark = init === null || init === void 0 ? void 0 : init.highWaterMark;
|
||
const size = init === null || init === void 0 ? void 0 : init.size;
|
||
return {
|
||
highWaterMark: highWaterMark === void 0 ? void 0 : convertUnrestrictedDouble(highWaterMark),
|
||
size: size === void 0 ? void 0 : convertQueuingStrategySize(size, `${context} has member 'size' that`)
|
||
};
|
||
}
|
||
function convertQueuingStrategySize(fn, context) {
|
||
assertFunction(fn, context);
|
||
return (chunk) => convertUnrestrictedDouble(fn(chunk));
|
||
}
|
||
function convertUnderlyingSink(original, context) {
|
||
assertDictionary(original, context);
|
||
const abort = original === null || original === void 0 ? void 0 : original.abort;
|
||
const close = original === null || original === void 0 ? void 0 : original.close;
|
||
const start = original === null || original === void 0 ? void 0 : original.start;
|
||
const type = original === null || original === void 0 ? void 0 : original.type;
|
||
const write = original === null || original === void 0 ? void 0 : original.write;
|
||
return {
|
||
abort: abort === void 0 ? void 0 : convertUnderlyingSinkAbortCallback(abort, original, `${context} has member 'abort' that`),
|
||
close: close === void 0 ? void 0 : convertUnderlyingSinkCloseCallback(close, original, `${context} has member 'close' that`),
|
||
start: start === void 0 ? void 0 : convertUnderlyingSinkStartCallback(start, original, `${context} has member 'start' that`),
|
||
write: write === void 0 ? void 0 : convertUnderlyingSinkWriteCallback(write, original, `${context} has member 'write' that`),
|
||
type
|
||
};
|
||
}
|
||
function convertUnderlyingSinkAbortCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (reason) => promiseCall(fn, original, [reason]);
|
||
}
|
||
function convertUnderlyingSinkCloseCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return () => promiseCall(fn, original, []);
|
||
}
|
||
function convertUnderlyingSinkStartCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (controller) => reflectCall(fn, original, [controller]);
|
||
}
|
||
function convertUnderlyingSinkWriteCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (chunk, controller) => promiseCall(fn, original, [chunk, controller]);
|
||
}
|
||
function assertWritableStream(x2, context) {
|
||
if (!IsWritableStream(x2)) {
|
||
throw new TypeError(`${context} is not a WritableStream.`);
|
||
}
|
||
}
|
||
function isAbortSignal2(value) {
|
||
if (typeof value !== "object" || value === null) {
|
||
return false;
|
||
}
|
||
try {
|
||
return typeof value.aborted === "boolean";
|
||
} catch (_a2) {
|
||
return false;
|
||
}
|
||
}
|
||
const supportsAbortController = typeof AbortController === "function";
|
||
function createAbortController() {
|
||
if (supportsAbortController) {
|
||
return new AbortController();
|
||
}
|
||
return void 0;
|
||
}
|
||
class WritableStream {
|
||
constructor(rawUnderlyingSink = {}, rawStrategy = {}) {
|
||
if (rawUnderlyingSink === void 0) {
|
||
rawUnderlyingSink = null;
|
||
} else {
|
||
assertObject(rawUnderlyingSink, "First parameter");
|
||
}
|
||
const strategy = convertQueuingStrategy(rawStrategy, "Second parameter");
|
||
const underlyingSink = convertUnderlyingSink(rawUnderlyingSink, "First parameter");
|
||
InitializeWritableStream(this);
|
||
const type = underlyingSink.type;
|
||
if (type !== void 0) {
|
||
throw new RangeError("Invalid type is specified");
|
||
}
|
||
const sizeAlgorithm = ExtractSizeAlgorithm(strategy);
|
||
const highWaterMark = ExtractHighWaterMark(strategy, 1);
|
||
SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, highWaterMark, sizeAlgorithm);
|
||
}
|
||
/**
|
||
* Returns whether or not the writable stream is locked to a writer.
|
||
*/
|
||
get locked() {
|
||
if (!IsWritableStream(this)) {
|
||
throw streamBrandCheckException$2("locked");
|
||
}
|
||
return IsWritableStreamLocked(this);
|
||
}
|
||
/**
|
||
* Aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be
|
||
* immediately moved to an errored state, with any queued-up writes discarded. This will also execute any abort
|
||
* mechanism of the underlying sink.
|
||
*
|
||
* The returned promise will fulfill if the stream shuts down successfully, or reject if the underlying sink signaled
|
||
* that there was an error doing so. Additionally, it will reject with a `TypeError` (without attempting to cancel
|
||
* the stream) if the stream is currently locked.
|
||
*/
|
||
abort(reason = void 0) {
|
||
if (!IsWritableStream(this)) {
|
||
return promiseRejectedWith(streamBrandCheckException$2("abort"));
|
||
}
|
||
if (IsWritableStreamLocked(this)) {
|
||
return promiseRejectedWith(new TypeError("Cannot abort a stream that already has a writer"));
|
||
}
|
||
return WritableStreamAbort(this, reason);
|
||
}
|
||
/**
|
||
* Closes the stream. The underlying sink will finish processing any previously-written chunks, before invoking its
|
||
* close behavior. During this time any further attempts to write will fail (without erroring the stream).
|
||
*
|
||
* The method returns a promise that will fulfill if all remaining chunks are successfully written and the stream
|
||
* successfully closes, or rejects if an error is encountered during this process. Additionally, it will reject with
|
||
* a `TypeError` (without attempting to cancel the stream) if the stream is currently locked.
|
||
*/
|
||
close() {
|
||
if (!IsWritableStream(this)) {
|
||
return promiseRejectedWith(streamBrandCheckException$2("close"));
|
||
}
|
||
if (IsWritableStreamLocked(this)) {
|
||
return promiseRejectedWith(new TypeError("Cannot close a stream that already has a writer"));
|
||
}
|
||
if (WritableStreamCloseQueuedOrInFlight(this)) {
|
||
return promiseRejectedWith(new TypeError("Cannot close an already-closing stream"));
|
||
}
|
||
return WritableStreamClose(this);
|
||
}
|
||
/**
|
||
* Creates a {@link WritableStreamDefaultWriter | writer} and locks the stream to the new writer. While the stream
|
||
* is locked, no other writer can be acquired until this one is released.
|
||
*
|
||
* This functionality is especially useful for creating abstractions that desire the ability to write to a stream
|
||
* without interruption or interleaving. By getting a writer for the stream, you can ensure nobody else can write at
|
||
* the same time, which would cause the resulting written data to be unpredictable and probably useless.
|
||
*/
|
||
getWriter() {
|
||
if (!IsWritableStream(this)) {
|
||
throw streamBrandCheckException$2("getWriter");
|
||
}
|
||
return AcquireWritableStreamDefaultWriter(this);
|
||
}
|
||
}
|
||
Object.defineProperties(WritableStream.prototype, {
|
||
abort: { enumerable: true },
|
||
close: { enumerable: true },
|
||
getWriter: { enumerable: true },
|
||
locked: { enumerable: true }
|
||
});
|
||
setFunctionName(WritableStream.prototype.abort, "abort");
|
||
setFunctionName(WritableStream.prototype.close, "close");
|
||
setFunctionName(WritableStream.prototype.getWriter, "getWriter");
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(WritableStream.prototype, Symbol.toStringTag, {
|
||
value: "WritableStream",
|
||
configurable: true
|
||
});
|
||
}
|
||
function AcquireWritableStreamDefaultWriter(stream) {
|
||
return new WritableStreamDefaultWriter(stream);
|
||
}
|
||
function CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark = 1, sizeAlgorithm = () => 1) {
|
||
const stream = Object.create(WritableStream.prototype);
|
||
InitializeWritableStream(stream);
|
||
const controller = Object.create(WritableStreamDefaultController.prototype);
|
||
SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
|
||
return stream;
|
||
}
|
||
function InitializeWritableStream(stream) {
|
||
stream._state = "writable";
|
||
stream._storedError = void 0;
|
||
stream._writer = void 0;
|
||
stream._writableStreamController = void 0;
|
||
stream._writeRequests = new SimpleQueue();
|
||
stream._inFlightWriteRequest = void 0;
|
||
stream._closeRequest = void 0;
|
||
stream._inFlightCloseRequest = void 0;
|
||
stream._pendingAbortRequest = void 0;
|
||
stream._backpressure = false;
|
||
}
|
||
function IsWritableStream(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_writableStreamController")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof WritableStream;
|
||
}
|
||
function IsWritableStreamLocked(stream) {
|
||
if (stream._writer === void 0) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
function WritableStreamAbort(stream, reason) {
|
||
var _a2;
|
||
if (stream._state === "closed" || stream._state === "errored") {
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
stream._writableStreamController._abortReason = reason;
|
||
(_a2 = stream._writableStreamController._abortController) === null || _a2 === void 0 ? void 0 : _a2.abort(reason);
|
||
const state = stream._state;
|
||
if (state === "closed" || state === "errored") {
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
if (stream._pendingAbortRequest !== void 0) {
|
||
return stream._pendingAbortRequest._promise;
|
||
}
|
||
let wasAlreadyErroring = false;
|
||
if (state === "erroring") {
|
||
wasAlreadyErroring = true;
|
||
reason = void 0;
|
||
}
|
||
const promise = newPromise((resolve, reject) => {
|
||
stream._pendingAbortRequest = {
|
||
_promise: void 0,
|
||
_resolve: resolve,
|
||
_reject: reject,
|
||
_reason: reason,
|
||
_wasAlreadyErroring: wasAlreadyErroring
|
||
};
|
||
});
|
||
stream._pendingAbortRequest._promise = promise;
|
||
if (!wasAlreadyErroring) {
|
||
WritableStreamStartErroring(stream, reason);
|
||
}
|
||
return promise;
|
||
}
|
||
function WritableStreamClose(stream) {
|
||
const state = stream._state;
|
||
if (state === "closed" || state === "errored") {
|
||
return promiseRejectedWith(new TypeError(`The stream (in ${state} state) is not in the writable state and cannot be closed`));
|
||
}
|
||
const promise = newPromise((resolve, reject) => {
|
||
const closeRequest = {
|
||
_resolve: resolve,
|
||
_reject: reject
|
||
};
|
||
stream._closeRequest = closeRequest;
|
||
});
|
||
const writer = stream._writer;
|
||
if (writer !== void 0 && stream._backpressure && state === "writable") {
|
||
defaultWriterReadyPromiseResolve(writer);
|
||
}
|
||
WritableStreamDefaultControllerClose(stream._writableStreamController);
|
||
return promise;
|
||
}
|
||
function WritableStreamAddWriteRequest(stream) {
|
||
const promise = newPromise((resolve, reject) => {
|
||
const writeRequest = {
|
||
_resolve: resolve,
|
||
_reject: reject
|
||
};
|
||
stream._writeRequests.push(writeRequest);
|
||
});
|
||
return promise;
|
||
}
|
||
function WritableStreamDealWithRejection(stream, error) {
|
||
const state = stream._state;
|
||
if (state === "writable") {
|
||
WritableStreamStartErroring(stream, error);
|
||
return;
|
||
}
|
||
WritableStreamFinishErroring(stream);
|
||
}
|
||
function WritableStreamStartErroring(stream, reason) {
|
||
const controller = stream._writableStreamController;
|
||
stream._state = "erroring";
|
||
stream._storedError = reason;
|
||
const writer = stream._writer;
|
||
if (writer !== void 0) {
|
||
WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);
|
||
}
|
||
if (!WritableStreamHasOperationMarkedInFlight(stream) && controller._started) {
|
||
WritableStreamFinishErroring(stream);
|
||
}
|
||
}
|
||
function WritableStreamFinishErroring(stream) {
|
||
stream._state = "errored";
|
||
stream._writableStreamController[ErrorSteps]();
|
||
const storedError = stream._storedError;
|
||
stream._writeRequests.forEach((writeRequest) => {
|
||
writeRequest._reject(storedError);
|
||
});
|
||
stream._writeRequests = new SimpleQueue();
|
||
if (stream._pendingAbortRequest === void 0) {
|
||
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
||
return;
|
||
}
|
||
const abortRequest = stream._pendingAbortRequest;
|
||
stream._pendingAbortRequest = void 0;
|
||
if (abortRequest._wasAlreadyErroring) {
|
||
abortRequest._reject(storedError);
|
||
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
||
return;
|
||
}
|
||
const promise = stream._writableStreamController[AbortSteps](abortRequest._reason);
|
||
uponPromise(promise, () => {
|
||
abortRequest._resolve();
|
||
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
||
return null;
|
||
}, (reason) => {
|
||
abortRequest._reject(reason);
|
||
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
||
return null;
|
||
});
|
||
}
|
||
function WritableStreamFinishInFlightWrite(stream) {
|
||
stream._inFlightWriteRequest._resolve(void 0);
|
||
stream._inFlightWriteRequest = void 0;
|
||
}
|
||
function WritableStreamFinishInFlightWriteWithError(stream, error) {
|
||
stream._inFlightWriteRequest._reject(error);
|
||
stream._inFlightWriteRequest = void 0;
|
||
WritableStreamDealWithRejection(stream, error);
|
||
}
|
||
function WritableStreamFinishInFlightClose(stream) {
|
||
stream._inFlightCloseRequest._resolve(void 0);
|
||
stream._inFlightCloseRequest = void 0;
|
||
const state = stream._state;
|
||
if (state === "erroring") {
|
||
stream._storedError = void 0;
|
||
if (stream._pendingAbortRequest !== void 0) {
|
||
stream._pendingAbortRequest._resolve();
|
||
stream._pendingAbortRequest = void 0;
|
||
}
|
||
}
|
||
stream._state = "closed";
|
||
const writer = stream._writer;
|
||
if (writer !== void 0) {
|
||
defaultWriterClosedPromiseResolve(writer);
|
||
}
|
||
}
|
||
function WritableStreamFinishInFlightCloseWithError(stream, error) {
|
||
stream._inFlightCloseRequest._reject(error);
|
||
stream._inFlightCloseRequest = void 0;
|
||
if (stream._pendingAbortRequest !== void 0) {
|
||
stream._pendingAbortRequest._reject(error);
|
||
stream._pendingAbortRequest = void 0;
|
||
}
|
||
WritableStreamDealWithRejection(stream, error);
|
||
}
|
||
function WritableStreamCloseQueuedOrInFlight(stream) {
|
||
if (stream._closeRequest === void 0 && stream._inFlightCloseRequest === void 0) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
function WritableStreamHasOperationMarkedInFlight(stream) {
|
||
if (stream._inFlightWriteRequest === void 0 && stream._inFlightCloseRequest === void 0) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
function WritableStreamMarkCloseRequestInFlight(stream) {
|
||
stream._inFlightCloseRequest = stream._closeRequest;
|
||
stream._closeRequest = void 0;
|
||
}
|
||
function WritableStreamMarkFirstWriteRequestInFlight(stream) {
|
||
stream._inFlightWriteRequest = stream._writeRequests.shift();
|
||
}
|
||
function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {
|
||
if (stream._closeRequest !== void 0) {
|
||
stream._closeRequest._reject(stream._storedError);
|
||
stream._closeRequest = void 0;
|
||
}
|
||
const writer = stream._writer;
|
||
if (writer !== void 0) {
|
||
defaultWriterClosedPromiseReject(writer, stream._storedError);
|
||
}
|
||
}
|
||
function WritableStreamUpdateBackpressure(stream, backpressure) {
|
||
const writer = stream._writer;
|
||
if (writer !== void 0 && backpressure !== stream._backpressure) {
|
||
if (backpressure) {
|
||
defaultWriterReadyPromiseReset(writer);
|
||
} else {
|
||
defaultWriterReadyPromiseResolve(writer);
|
||
}
|
||
}
|
||
stream._backpressure = backpressure;
|
||
}
|
||
class WritableStreamDefaultWriter {
|
||
constructor(stream) {
|
||
assertRequiredArgument(stream, 1, "WritableStreamDefaultWriter");
|
||
assertWritableStream(stream, "First parameter");
|
||
if (IsWritableStreamLocked(stream)) {
|
||
throw new TypeError("This stream has already been locked for exclusive writing by another writer");
|
||
}
|
||
this._ownerWritableStream = stream;
|
||
stream._writer = this;
|
||
const state = stream._state;
|
||
if (state === "writable") {
|
||
if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._backpressure) {
|
||
defaultWriterReadyPromiseInitialize(this);
|
||
} else {
|
||
defaultWriterReadyPromiseInitializeAsResolved(this);
|
||
}
|
||
defaultWriterClosedPromiseInitialize(this);
|
||
} else if (state === "erroring") {
|
||
defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError);
|
||
defaultWriterClosedPromiseInitialize(this);
|
||
} else if (state === "closed") {
|
||
defaultWriterReadyPromiseInitializeAsResolved(this);
|
||
defaultWriterClosedPromiseInitializeAsResolved(this);
|
||
} else {
|
||
const storedError = stream._storedError;
|
||
defaultWriterReadyPromiseInitializeAsRejected(this, storedError);
|
||
defaultWriterClosedPromiseInitializeAsRejected(this, storedError);
|
||
}
|
||
}
|
||
/**
|
||
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
||
* the writer’s lock is released before the stream finishes closing.
|
||
*/
|
||
get closed() {
|
||
if (!IsWritableStreamDefaultWriter(this)) {
|
||
return promiseRejectedWith(defaultWriterBrandCheckException("closed"));
|
||
}
|
||
return this._closedPromise;
|
||
}
|
||
/**
|
||
* Returns the desired size to fill the stream’s internal queue. It can be negative, if the queue is over-full.
|
||
* A producer can use this information to determine the right amount of data to write.
|
||
*
|
||
* It will be `null` if the stream cannot be successfully written to (due to either being errored, or having an abort
|
||
* queued up). It will return zero if the stream is closed. And the getter will throw an exception if invoked when
|
||
* the writer’s lock is released.
|
||
*/
|
||
get desiredSize() {
|
||
if (!IsWritableStreamDefaultWriter(this)) {
|
||
throw defaultWriterBrandCheckException("desiredSize");
|
||
}
|
||
if (this._ownerWritableStream === void 0) {
|
||
throw defaultWriterLockException("desiredSize");
|
||
}
|
||
return WritableStreamDefaultWriterGetDesiredSize(this);
|
||
}
|
||
/**
|
||
* Returns a promise that will be fulfilled when the desired size to fill the stream’s internal queue transitions
|
||
* from non-positive to positive, signaling that it is no longer applying backpressure. Once the desired size dips
|
||
* back to zero or below, the getter will return a new promise that stays pending until the next transition.
|
||
*
|
||
* If the stream becomes errored or aborted, or the writer’s lock is released, the returned promise will become
|
||
* rejected.
|
||
*/
|
||
get ready() {
|
||
if (!IsWritableStreamDefaultWriter(this)) {
|
||
return promiseRejectedWith(defaultWriterBrandCheckException("ready"));
|
||
}
|
||
return this._readyPromise;
|
||
}
|
||
/**
|
||
* If the reader is active, behaves the same as {@link WritableStream.abort | stream.abort(reason)}.
|
||
*/
|
||
abort(reason = void 0) {
|
||
if (!IsWritableStreamDefaultWriter(this)) {
|
||
return promiseRejectedWith(defaultWriterBrandCheckException("abort"));
|
||
}
|
||
if (this._ownerWritableStream === void 0) {
|
||
return promiseRejectedWith(defaultWriterLockException("abort"));
|
||
}
|
||
return WritableStreamDefaultWriterAbort(this, reason);
|
||
}
|
||
/**
|
||
* If the reader is active, behaves the same as {@link WritableStream.close | stream.close()}.
|
||
*/
|
||
close() {
|
||
if (!IsWritableStreamDefaultWriter(this)) {
|
||
return promiseRejectedWith(defaultWriterBrandCheckException("close"));
|
||
}
|
||
const stream = this._ownerWritableStream;
|
||
if (stream === void 0) {
|
||
return promiseRejectedWith(defaultWriterLockException("close"));
|
||
}
|
||
if (WritableStreamCloseQueuedOrInFlight(stream)) {
|
||
return promiseRejectedWith(new TypeError("Cannot close an already-closing stream"));
|
||
}
|
||
return WritableStreamDefaultWriterClose(this);
|
||
}
|
||
/**
|
||
* Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active.
|
||
* If the associated stream is errored when the lock is released, the writer will appear errored in the same way from
|
||
* now on; otherwise, the writer will appear closed.
|
||
*
|
||
* Note that the lock can still be released even if some ongoing writes have not yet finished (i.e. even if the
|
||
* promises returned from previous calls to {@link WritableStreamDefaultWriter.write | write()} have not yet settled).
|
||
* It’s not necessary to hold the lock on the writer for the duration of the write; the lock instead simply prevents
|
||
* other producers from writing in an interleaved manner.
|
||
*/
|
||
releaseLock() {
|
||
if (!IsWritableStreamDefaultWriter(this)) {
|
||
throw defaultWriterBrandCheckException("releaseLock");
|
||
}
|
||
const stream = this._ownerWritableStream;
|
||
if (stream === void 0) {
|
||
return;
|
||
}
|
||
WritableStreamDefaultWriterRelease(this);
|
||
}
|
||
write(chunk = void 0) {
|
||
if (!IsWritableStreamDefaultWriter(this)) {
|
||
return promiseRejectedWith(defaultWriterBrandCheckException("write"));
|
||
}
|
||
if (this._ownerWritableStream === void 0) {
|
||
return promiseRejectedWith(defaultWriterLockException("write to"));
|
||
}
|
||
return WritableStreamDefaultWriterWrite(this, chunk);
|
||
}
|
||
}
|
||
Object.defineProperties(WritableStreamDefaultWriter.prototype, {
|
||
abort: { enumerable: true },
|
||
close: { enumerable: true },
|
||
releaseLock: { enumerable: true },
|
||
write: { enumerable: true },
|
||
closed: { enumerable: true },
|
||
desiredSize: { enumerable: true },
|
||
ready: { enumerable: true }
|
||
});
|
||
setFunctionName(WritableStreamDefaultWriter.prototype.abort, "abort");
|
||
setFunctionName(WritableStreamDefaultWriter.prototype.close, "close");
|
||
setFunctionName(WritableStreamDefaultWriter.prototype.releaseLock, "releaseLock");
|
||
setFunctionName(WritableStreamDefaultWriter.prototype.write, "write");
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(WritableStreamDefaultWriter.prototype, Symbol.toStringTag, {
|
||
value: "WritableStreamDefaultWriter",
|
||
configurable: true
|
||
});
|
||
}
|
||
function IsWritableStreamDefaultWriter(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_ownerWritableStream")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof WritableStreamDefaultWriter;
|
||
}
|
||
function WritableStreamDefaultWriterAbort(writer, reason) {
|
||
const stream = writer._ownerWritableStream;
|
||
return WritableStreamAbort(stream, reason);
|
||
}
|
||
function WritableStreamDefaultWriterClose(writer) {
|
||
const stream = writer._ownerWritableStream;
|
||
return WritableStreamClose(stream);
|
||
}
|
||
function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {
|
||
const stream = writer._ownerWritableStream;
|
||
const state = stream._state;
|
||
if (WritableStreamCloseQueuedOrInFlight(stream) || state === "closed") {
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
if (state === "errored") {
|
||
return promiseRejectedWith(stream._storedError);
|
||
}
|
||
return WritableStreamDefaultWriterClose(writer);
|
||
}
|
||
function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {
|
||
if (writer._closedPromiseState === "pending") {
|
||
defaultWriterClosedPromiseReject(writer, error);
|
||
} else {
|
||
defaultWriterClosedPromiseResetToRejected(writer, error);
|
||
}
|
||
}
|
||
function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {
|
||
if (writer._readyPromiseState === "pending") {
|
||
defaultWriterReadyPromiseReject(writer, error);
|
||
} else {
|
||
defaultWriterReadyPromiseResetToRejected(writer, error);
|
||
}
|
||
}
|
||
function WritableStreamDefaultWriterGetDesiredSize(writer) {
|
||
const stream = writer._ownerWritableStream;
|
||
const state = stream._state;
|
||
if (state === "errored" || state === "erroring") {
|
||
return null;
|
||
}
|
||
if (state === "closed") {
|
||
return 0;
|
||
}
|
||
return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController);
|
||
}
|
||
function WritableStreamDefaultWriterRelease(writer) {
|
||
const stream = writer._ownerWritableStream;
|
||
const releasedError = new TypeError(`Writer was released and can no longer be used to monitor the stream's closedness`);
|
||
WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);
|
||
WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);
|
||
stream._writer = void 0;
|
||
writer._ownerWritableStream = void 0;
|
||
}
|
||
function WritableStreamDefaultWriterWrite(writer, chunk) {
|
||
const stream = writer._ownerWritableStream;
|
||
const controller = stream._writableStreamController;
|
||
const chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk);
|
||
if (stream !== writer._ownerWritableStream) {
|
||
return promiseRejectedWith(defaultWriterLockException("write to"));
|
||
}
|
||
const state = stream._state;
|
||
if (state === "errored") {
|
||
return promiseRejectedWith(stream._storedError);
|
||
}
|
||
if (WritableStreamCloseQueuedOrInFlight(stream) || state === "closed") {
|
||
return promiseRejectedWith(new TypeError("The stream is closing or closed and cannot be written to"));
|
||
}
|
||
if (state === "erroring") {
|
||
return promiseRejectedWith(stream._storedError);
|
||
}
|
||
const promise = WritableStreamAddWriteRequest(stream);
|
||
WritableStreamDefaultControllerWrite(controller, chunk, chunkSize);
|
||
return promise;
|
||
}
|
||
const closeSentinel = {};
|
||
class WritableStreamDefaultController {
|
||
constructor() {
|
||
throw new TypeError("Illegal constructor");
|
||
}
|
||
/**
|
||
* The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
|
||
*
|
||
* @deprecated
|
||
* This property has been removed from the specification, see https://github.com/whatwg/streams/pull/1177.
|
||
* Use {@link WritableStreamDefaultController.signal}'s `reason` instead.
|
||
*/
|
||
get abortReason() {
|
||
if (!IsWritableStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException$2("abortReason");
|
||
}
|
||
return this._abortReason;
|
||
}
|
||
/**
|
||
* An `AbortSignal` that can be used to abort the pending write or close operation when the stream is aborted.
|
||
*/
|
||
get signal() {
|
||
if (!IsWritableStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException$2("signal");
|
||
}
|
||
if (this._abortController === void 0) {
|
||
throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");
|
||
}
|
||
return this._abortController.signal;
|
||
}
|
||
/**
|
||
* Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
|
||
*
|
||
* This method is rarely used, since usually it suffices to return a rejected promise from one of the underlying
|
||
* sink's methods. However, it can be useful for suddenly shutting down a stream in response to an event outside the
|
||
* normal lifecycle of interactions with the underlying sink.
|
||
*/
|
||
error(e2 = void 0) {
|
||
if (!IsWritableStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException$2("error");
|
||
}
|
||
const state = this._controlledWritableStream._state;
|
||
if (state !== "writable") {
|
||
return;
|
||
}
|
||
WritableStreamDefaultControllerError(this, e2);
|
||
}
|
||
/** @internal */
|
||
[AbortSteps](reason) {
|
||
const result = this._abortAlgorithm(reason);
|
||
WritableStreamDefaultControllerClearAlgorithms(this);
|
||
return result;
|
||
}
|
||
/** @internal */
|
||
[ErrorSteps]() {
|
||
ResetQueue(this);
|
||
}
|
||
}
|
||
Object.defineProperties(WritableStreamDefaultController.prototype, {
|
||
abortReason: { enumerable: true },
|
||
signal: { enumerable: true },
|
||
error: { enumerable: true }
|
||
});
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(WritableStreamDefaultController.prototype, Symbol.toStringTag, {
|
||
value: "WritableStreamDefaultController",
|
||
configurable: true
|
||
});
|
||
}
|
||
function IsWritableStreamDefaultController(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_controlledWritableStream")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof WritableStreamDefaultController;
|
||
}
|
||
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
||
controller._controlledWritableStream = stream;
|
||
stream._writableStreamController = controller;
|
||
controller._queue = void 0;
|
||
controller._queueTotalSize = void 0;
|
||
ResetQueue(controller);
|
||
controller._abortReason = void 0;
|
||
controller._abortController = createAbortController();
|
||
controller._started = false;
|
||
controller._strategySizeAlgorithm = sizeAlgorithm;
|
||
controller._strategyHWM = highWaterMark;
|
||
controller._writeAlgorithm = writeAlgorithm;
|
||
controller._closeAlgorithm = closeAlgorithm;
|
||
controller._abortAlgorithm = abortAlgorithm;
|
||
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
||
WritableStreamUpdateBackpressure(stream, backpressure);
|
||
const startResult = startAlgorithm();
|
||
const startPromise = promiseResolvedWith(startResult);
|
||
uponPromise(startPromise, () => {
|
||
controller._started = true;
|
||
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
||
return null;
|
||
}, (r2) => {
|
||
controller._started = true;
|
||
WritableStreamDealWithRejection(stream, r2);
|
||
return null;
|
||
});
|
||
}
|
||
function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, highWaterMark, sizeAlgorithm) {
|
||
const controller = Object.create(WritableStreamDefaultController.prototype);
|
||
let startAlgorithm;
|
||
let writeAlgorithm;
|
||
let closeAlgorithm;
|
||
let abortAlgorithm;
|
||
if (underlyingSink.start !== void 0) {
|
||
startAlgorithm = () => underlyingSink.start(controller);
|
||
} else {
|
||
startAlgorithm = () => void 0;
|
||
}
|
||
if (underlyingSink.write !== void 0) {
|
||
writeAlgorithm = (chunk) => underlyingSink.write(chunk, controller);
|
||
} else {
|
||
writeAlgorithm = () => promiseResolvedWith(void 0);
|
||
}
|
||
if (underlyingSink.close !== void 0) {
|
||
closeAlgorithm = () => underlyingSink.close();
|
||
} else {
|
||
closeAlgorithm = () => promiseResolvedWith(void 0);
|
||
}
|
||
if (underlyingSink.abort !== void 0) {
|
||
abortAlgorithm = (reason) => underlyingSink.abort(reason);
|
||
} else {
|
||
abortAlgorithm = () => promiseResolvedWith(void 0);
|
||
}
|
||
SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
|
||
}
|
||
function WritableStreamDefaultControllerClearAlgorithms(controller) {
|
||
controller._writeAlgorithm = void 0;
|
||
controller._closeAlgorithm = void 0;
|
||
controller._abortAlgorithm = void 0;
|
||
controller._strategySizeAlgorithm = void 0;
|
||
}
|
||
function WritableStreamDefaultControllerClose(controller) {
|
||
EnqueueValueWithSize(controller, closeSentinel, 0);
|
||
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
||
}
|
||
function WritableStreamDefaultControllerGetChunkSize(controller, chunk) {
|
||
try {
|
||
return controller._strategySizeAlgorithm(chunk);
|
||
} catch (chunkSizeE) {
|
||
WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
|
||
return 1;
|
||
}
|
||
}
|
||
function WritableStreamDefaultControllerGetDesiredSize(controller) {
|
||
return controller._strategyHWM - controller._queueTotalSize;
|
||
}
|
||
function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
|
||
try {
|
||
EnqueueValueWithSize(controller, chunk, chunkSize);
|
||
} catch (enqueueE) {
|
||
WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
|
||
return;
|
||
}
|
||
const stream = controller._controlledWritableStream;
|
||
if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._state === "writable") {
|
||
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
||
WritableStreamUpdateBackpressure(stream, backpressure);
|
||
}
|
||
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
||
}
|
||
function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {
|
||
const stream = controller._controlledWritableStream;
|
||
if (!controller._started) {
|
||
return;
|
||
}
|
||
if (stream._inFlightWriteRequest !== void 0) {
|
||
return;
|
||
}
|
||
const state = stream._state;
|
||
if (state === "erroring") {
|
||
WritableStreamFinishErroring(stream);
|
||
return;
|
||
}
|
||
if (controller._queue.length === 0) {
|
||
return;
|
||
}
|
||
const value = PeekQueueValue(controller);
|
||
if (value === closeSentinel) {
|
||
WritableStreamDefaultControllerProcessClose(controller);
|
||
} else {
|
||
WritableStreamDefaultControllerProcessWrite(controller, value);
|
||
}
|
||
}
|
||
function WritableStreamDefaultControllerErrorIfNeeded(controller, error) {
|
||
if (controller._controlledWritableStream._state === "writable") {
|
||
WritableStreamDefaultControllerError(controller, error);
|
||
}
|
||
}
|
||
function WritableStreamDefaultControllerProcessClose(controller) {
|
||
const stream = controller._controlledWritableStream;
|
||
WritableStreamMarkCloseRequestInFlight(stream);
|
||
DequeueValue(controller);
|
||
const sinkClosePromise = controller._closeAlgorithm();
|
||
WritableStreamDefaultControllerClearAlgorithms(controller);
|
||
uponPromise(sinkClosePromise, () => {
|
||
WritableStreamFinishInFlightClose(stream);
|
||
return null;
|
||
}, (reason) => {
|
||
WritableStreamFinishInFlightCloseWithError(stream, reason);
|
||
return null;
|
||
});
|
||
}
|
||
function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
|
||
const stream = controller._controlledWritableStream;
|
||
WritableStreamMarkFirstWriteRequestInFlight(stream);
|
||
const sinkWritePromise = controller._writeAlgorithm(chunk);
|
||
uponPromise(sinkWritePromise, () => {
|
||
WritableStreamFinishInFlightWrite(stream);
|
||
const state = stream._state;
|
||
DequeueValue(controller);
|
||
if (!WritableStreamCloseQueuedOrInFlight(stream) && state === "writable") {
|
||
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
||
WritableStreamUpdateBackpressure(stream, backpressure);
|
||
}
|
||
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
||
return null;
|
||
}, (reason) => {
|
||
if (stream._state === "writable") {
|
||
WritableStreamDefaultControllerClearAlgorithms(controller);
|
||
}
|
||
WritableStreamFinishInFlightWriteWithError(stream, reason);
|
||
return null;
|
||
});
|
||
}
|
||
function WritableStreamDefaultControllerGetBackpressure(controller) {
|
||
const desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);
|
||
return desiredSize <= 0;
|
||
}
|
||
function WritableStreamDefaultControllerError(controller, error) {
|
||
const stream = controller._controlledWritableStream;
|
||
WritableStreamDefaultControllerClearAlgorithms(controller);
|
||
WritableStreamStartErroring(stream, error);
|
||
}
|
||
function streamBrandCheckException$2(name) {
|
||
return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);
|
||
}
|
||
function defaultControllerBrandCheckException$2(name) {
|
||
return new TypeError(`WritableStreamDefaultController.prototype.${name} can only be used on a WritableStreamDefaultController`);
|
||
}
|
||
function defaultWriterBrandCheckException(name) {
|
||
return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);
|
||
}
|
||
function defaultWriterLockException(name) {
|
||
return new TypeError("Cannot " + name + " a stream using a released writer");
|
||
}
|
||
function defaultWriterClosedPromiseInitialize(writer) {
|
||
writer._closedPromise = newPromise((resolve, reject) => {
|
||
writer._closedPromise_resolve = resolve;
|
||
writer._closedPromise_reject = reject;
|
||
writer._closedPromiseState = "pending";
|
||
});
|
||
}
|
||
function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) {
|
||
defaultWriterClosedPromiseInitialize(writer);
|
||
defaultWriterClosedPromiseReject(writer, reason);
|
||
}
|
||
function defaultWriterClosedPromiseInitializeAsResolved(writer) {
|
||
defaultWriterClosedPromiseInitialize(writer);
|
||
defaultWriterClosedPromiseResolve(writer);
|
||
}
|
||
function defaultWriterClosedPromiseReject(writer, reason) {
|
||
if (writer._closedPromise_reject === void 0) {
|
||
return;
|
||
}
|
||
setPromiseIsHandledToTrue(writer._closedPromise);
|
||
writer._closedPromise_reject(reason);
|
||
writer._closedPromise_resolve = void 0;
|
||
writer._closedPromise_reject = void 0;
|
||
writer._closedPromiseState = "rejected";
|
||
}
|
||
function defaultWriterClosedPromiseResetToRejected(writer, reason) {
|
||
defaultWriterClosedPromiseInitializeAsRejected(writer, reason);
|
||
}
|
||
function defaultWriterClosedPromiseResolve(writer) {
|
||
if (writer._closedPromise_resolve === void 0) {
|
||
return;
|
||
}
|
||
writer._closedPromise_resolve(void 0);
|
||
writer._closedPromise_resolve = void 0;
|
||
writer._closedPromise_reject = void 0;
|
||
writer._closedPromiseState = "resolved";
|
||
}
|
||
function defaultWriterReadyPromiseInitialize(writer) {
|
||
writer._readyPromise = newPromise((resolve, reject) => {
|
||
writer._readyPromise_resolve = resolve;
|
||
writer._readyPromise_reject = reject;
|
||
});
|
||
writer._readyPromiseState = "pending";
|
||
}
|
||
function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) {
|
||
defaultWriterReadyPromiseInitialize(writer);
|
||
defaultWriterReadyPromiseReject(writer, reason);
|
||
}
|
||
function defaultWriterReadyPromiseInitializeAsResolved(writer) {
|
||
defaultWriterReadyPromiseInitialize(writer);
|
||
defaultWriterReadyPromiseResolve(writer);
|
||
}
|
||
function defaultWriterReadyPromiseReject(writer, reason) {
|
||
if (writer._readyPromise_reject === void 0) {
|
||
return;
|
||
}
|
||
setPromiseIsHandledToTrue(writer._readyPromise);
|
||
writer._readyPromise_reject(reason);
|
||
writer._readyPromise_resolve = void 0;
|
||
writer._readyPromise_reject = void 0;
|
||
writer._readyPromiseState = "rejected";
|
||
}
|
||
function defaultWriterReadyPromiseReset(writer) {
|
||
defaultWriterReadyPromiseInitialize(writer);
|
||
}
|
||
function defaultWriterReadyPromiseResetToRejected(writer, reason) {
|
||
defaultWriterReadyPromiseInitializeAsRejected(writer, reason);
|
||
}
|
||
function defaultWriterReadyPromiseResolve(writer) {
|
||
if (writer._readyPromise_resolve === void 0) {
|
||
return;
|
||
}
|
||
writer._readyPromise_resolve(void 0);
|
||
writer._readyPromise_resolve = void 0;
|
||
writer._readyPromise_reject = void 0;
|
||
writer._readyPromiseState = "fulfilled";
|
||
}
|
||
function getGlobals() {
|
||
if (typeof globalThis !== "undefined") {
|
||
return globalThis;
|
||
} else if (typeof self !== "undefined") {
|
||
return self;
|
||
} else if (typeof global !== "undefined") {
|
||
return global;
|
||
}
|
||
return void 0;
|
||
}
|
||
const globals = getGlobals();
|
||
function isDOMExceptionConstructor(ctor) {
|
||
if (!(typeof ctor === "function" || typeof ctor === "object")) {
|
||
return false;
|
||
}
|
||
if (ctor.name !== "DOMException") {
|
||
return false;
|
||
}
|
||
try {
|
||
new ctor();
|
||
return true;
|
||
} catch (_a2) {
|
||
return false;
|
||
}
|
||
}
|
||
function getFromGlobal() {
|
||
const ctor = globals === null || globals === void 0 ? void 0 : globals.DOMException;
|
||
return isDOMExceptionConstructor(ctor) ? ctor : void 0;
|
||
}
|
||
function createPolyfill() {
|
||
const ctor = function DOMException3(message, name) {
|
||
this.message = message || "";
|
||
this.name = name || "Error";
|
||
if (Error.captureStackTrace) {
|
||
Error.captureStackTrace(this, this.constructor);
|
||
}
|
||
};
|
||
setFunctionName(ctor, "DOMException");
|
||
ctor.prototype = Object.create(Error.prototype);
|
||
Object.defineProperty(ctor.prototype, "constructor", { value: ctor, writable: true, configurable: true });
|
||
return ctor;
|
||
}
|
||
const DOMException2 = getFromGlobal() || createPolyfill();
|
||
function ReadableStreamPipeTo(source2, dest, preventClose, preventAbort, preventCancel, signal) {
|
||
const reader = AcquireReadableStreamDefaultReader(source2);
|
||
const writer = AcquireWritableStreamDefaultWriter(dest);
|
||
source2._disturbed = true;
|
||
let shuttingDown = false;
|
||
let currentWrite = promiseResolvedWith(void 0);
|
||
return newPromise((resolve, reject) => {
|
||
let abortAlgorithm;
|
||
if (signal !== void 0) {
|
||
abortAlgorithm = () => {
|
||
const error = signal.reason !== void 0 ? signal.reason : new DOMException2("Aborted", "AbortError");
|
||
const actions = [];
|
||
if (!preventAbort) {
|
||
actions.push(() => {
|
||
if (dest._state === "writable") {
|
||
return WritableStreamAbort(dest, error);
|
||
}
|
||
return promiseResolvedWith(void 0);
|
||
});
|
||
}
|
||
if (!preventCancel) {
|
||
actions.push(() => {
|
||
if (source2._state === "readable") {
|
||
return ReadableStreamCancel(source2, error);
|
||
}
|
||
return promiseResolvedWith(void 0);
|
||
});
|
||
}
|
||
shutdownWithAction(() => Promise.all(actions.map((action) => action())), true, error);
|
||
};
|
||
if (signal.aborted) {
|
||
abortAlgorithm();
|
||
return;
|
||
}
|
||
signal.addEventListener("abort", abortAlgorithm);
|
||
}
|
||
function pipeLoop() {
|
||
return newPromise((resolveLoop, rejectLoop) => {
|
||
function next(done) {
|
||
if (done) {
|
||
resolveLoop();
|
||
} else {
|
||
PerformPromiseThen(pipeStep(), next, rejectLoop);
|
||
}
|
||
}
|
||
next(false);
|
||
});
|
||
}
|
||
function pipeStep() {
|
||
if (shuttingDown) {
|
||
return promiseResolvedWith(true);
|
||
}
|
||
return PerformPromiseThen(writer._readyPromise, () => {
|
||
return newPromise((resolveRead, rejectRead) => {
|
||
ReadableStreamDefaultReaderRead(reader, {
|
||
_chunkSteps: (chunk) => {
|
||
currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), void 0, noop2);
|
||
resolveRead(false);
|
||
},
|
||
_closeSteps: () => resolveRead(true),
|
||
_errorSteps: rejectRead
|
||
});
|
||
});
|
||
});
|
||
}
|
||
isOrBecomesErrored(source2, reader._closedPromise, (storedError) => {
|
||
if (!preventAbort) {
|
||
shutdownWithAction(() => WritableStreamAbort(dest, storedError), true, storedError);
|
||
} else {
|
||
shutdown(true, storedError);
|
||
}
|
||
return null;
|
||
});
|
||
isOrBecomesErrored(dest, writer._closedPromise, (storedError) => {
|
||
if (!preventCancel) {
|
||
shutdownWithAction(() => ReadableStreamCancel(source2, storedError), true, storedError);
|
||
} else {
|
||
shutdown(true, storedError);
|
||
}
|
||
return null;
|
||
});
|
||
isOrBecomesClosed(source2, reader._closedPromise, () => {
|
||
if (!preventClose) {
|
||
shutdownWithAction(() => WritableStreamDefaultWriterCloseWithErrorPropagation(writer));
|
||
} else {
|
||
shutdown();
|
||
}
|
||
return null;
|
||
});
|
||
if (WritableStreamCloseQueuedOrInFlight(dest) || dest._state === "closed") {
|
||
const destClosed = new TypeError("the destination writable stream closed before all data could be piped to it");
|
||
if (!preventCancel) {
|
||
shutdownWithAction(() => ReadableStreamCancel(source2, destClosed), true, destClosed);
|
||
} else {
|
||
shutdown(true, destClosed);
|
||
}
|
||
}
|
||
setPromiseIsHandledToTrue(pipeLoop());
|
||
function waitForWritesToFinish() {
|
||
const oldCurrentWrite = currentWrite;
|
||
return PerformPromiseThen(currentWrite, () => oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : void 0);
|
||
}
|
||
function isOrBecomesErrored(stream, promise, action) {
|
||
if (stream._state === "errored") {
|
||
action(stream._storedError);
|
||
} else {
|
||
uponRejection(promise, action);
|
||
}
|
||
}
|
||
function isOrBecomesClosed(stream, promise, action) {
|
||
if (stream._state === "closed") {
|
||
action();
|
||
} else {
|
||
uponFulfillment(promise, action);
|
||
}
|
||
}
|
||
function shutdownWithAction(action, originalIsError, originalError) {
|
||
if (shuttingDown) {
|
||
return;
|
||
}
|
||
shuttingDown = true;
|
||
if (dest._state === "writable" && !WritableStreamCloseQueuedOrInFlight(dest)) {
|
||
uponFulfillment(waitForWritesToFinish(), doTheRest);
|
||
} else {
|
||
doTheRest();
|
||
}
|
||
function doTheRest() {
|
||
uponPromise(action(), () => finalize(originalIsError, originalError), (newError) => finalize(true, newError));
|
||
return null;
|
||
}
|
||
}
|
||
function shutdown(isError, error) {
|
||
if (shuttingDown) {
|
||
return;
|
||
}
|
||
shuttingDown = true;
|
||
if (dest._state === "writable" && !WritableStreamCloseQueuedOrInFlight(dest)) {
|
||
uponFulfillment(waitForWritesToFinish(), () => finalize(isError, error));
|
||
} else {
|
||
finalize(isError, error);
|
||
}
|
||
}
|
||
function finalize(isError, error) {
|
||
WritableStreamDefaultWriterRelease(writer);
|
||
ReadableStreamReaderGenericRelease(reader);
|
||
if (signal !== void 0) {
|
||
signal.removeEventListener("abort", abortAlgorithm);
|
||
}
|
||
if (isError) {
|
||
reject(error);
|
||
} else {
|
||
resolve(void 0);
|
||
}
|
||
return null;
|
||
}
|
||
});
|
||
}
|
||
class ReadableStreamDefaultController {
|
||
constructor() {
|
||
throw new TypeError("Illegal constructor");
|
||
}
|
||
/**
|
||
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
||
* over-full. An underlying source ought to use this information to determine when and how to apply backpressure.
|
||
*/
|
||
get desiredSize() {
|
||
if (!IsReadableStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException$1("desiredSize");
|
||
}
|
||
return ReadableStreamDefaultControllerGetDesiredSize(this);
|
||
}
|
||
/**
|
||
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
||
* the stream, but once those are read, the stream will become closed.
|
||
*/
|
||
close() {
|
||
if (!IsReadableStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException$1("close");
|
||
}
|
||
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
||
throw new TypeError("The stream is not in a state that permits close");
|
||
}
|
||
ReadableStreamDefaultControllerClose(this);
|
||
}
|
||
enqueue(chunk = void 0) {
|
||
if (!IsReadableStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException$1("enqueue");
|
||
}
|
||
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
||
throw new TypeError("The stream is not in a state that permits enqueue");
|
||
}
|
||
return ReadableStreamDefaultControllerEnqueue(this, chunk);
|
||
}
|
||
/**
|
||
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
||
*/
|
||
error(e2 = void 0) {
|
||
if (!IsReadableStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException$1("error");
|
||
}
|
||
ReadableStreamDefaultControllerError(this, e2);
|
||
}
|
||
/** @internal */
|
||
[CancelSteps](reason) {
|
||
ResetQueue(this);
|
||
const result = this._cancelAlgorithm(reason);
|
||
ReadableStreamDefaultControllerClearAlgorithms(this);
|
||
return result;
|
||
}
|
||
/** @internal */
|
||
[PullSteps](readRequest) {
|
||
const stream = this._controlledReadableStream;
|
||
if (this._queue.length > 0) {
|
||
const chunk = DequeueValue(this);
|
||
if (this._closeRequested && this._queue.length === 0) {
|
||
ReadableStreamDefaultControllerClearAlgorithms(this);
|
||
ReadableStreamClose(stream);
|
||
} else {
|
||
ReadableStreamDefaultControllerCallPullIfNeeded(this);
|
||
}
|
||
readRequest._chunkSteps(chunk);
|
||
} else {
|
||
ReadableStreamAddReadRequest(stream, readRequest);
|
||
ReadableStreamDefaultControllerCallPullIfNeeded(this);
|
||
}
|
||
}
|
||
/** @internal */
|
||
[ReleaseSteps]() {
|
||
}
|
||
}
|
||
Object.defineProperties(ReadableStreamDefaultController.prototype, {
|
||
close: { enumerable: true },
|
||
enqueue: { enumerable: true },
|
||
error: { enumerable: true },
|
||
desiredSize: { enumerable: true }
|
||
});
|
||
setFunctionName(ReadableStreamDefaultController.prototype.close, "close");
|
||
setFunctionName(ReadableStreamDefaultController.prototype.enqueue, "enqueue");
|
||
setFunctionName(ReadableStreamDefaultController.prototype.error, "error");
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(ReadableStreamDefaultController.prototype, Symbol.toStringTag, {
|
||
value: "ReadableStreamDefaultController",
|
||
configurable: true
|
||
});
|
||
}
|
||
function IsReadableStreamDefaultController(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_controlledReadableStream")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof ReadableStreamDefaultController;
|
||
}
|
||
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
||
const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
||
if (!shouldPull) {
|
||
return;
|
||
}
|
||
if (controller._pulling) {
|
||
controller._pullAgain = true;
|
||
return;
|
||
}
|
||
controller._pulling = true;
|
||
const pullPromise = controller._pullAlgorithm();
|
||
uponPromise(pullPromise, () => {
|
||
controller._pulling = false;
|
||
if (controller._pullAgain) {
|
||
controller._pullAgain = false;
|
||
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
||
}
|
||
return null;
|
||
}, (e2) => {
|
||
ReadableStreamDefaultControllerError(controller, e2);
|
||
return null;
|
||
});
|
||
}
|
||
function ReadableStreamDefaultControllerShouldCallPull(controller) {
|
||
const stream = controller._controlledReadableStream;
|
||
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
||
return false;
|
||
}
|
||
if (!controller._started) {
|
||
return false;
|
||
}
|
||
if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
||
return true;
|
||
}
|
||
const desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
|
||
if (desiredSize > 0) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
function ReadableStreamDefaultControllerClearAlgorithms(controller) {
|
||
controller._pullAlgorithm = void 0;
|
||
controller._cancelAlgorithm = void 0;
|
||
controller._strategySizeAlgorithm = void 0;
|
||
}
|
||
function ReadableStreamDefaultControllerClose(controller) {
|
||
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
||
return;
|
||
}
|
||
const stream = controller._controlledReadableStream;
|
||
controller._closeRequested = true;
|
||
if (controller._queue.length === 0) {
|
||
ReadableStreamDefaultControllerClearAlgorithms(controller);
|
||
ReadableStreamClose(stream);
|
||
}
|
||
}
|
||
function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
|
||
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
||
return;
|
||
}
|
||
const stream = controller._controlledReadableStream;
|
||
if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
||
ReadableStreamFulfillReadRequest(stream, chunk, false);
|
||
} else {
|
||
let chunkSize;
|
||
try {
|
||
chunkSize = controller._strategySizeAlgorithm(chunk);
|
||
} catch (chunkSizeE) {
|
||
ReadableStreamDefaultControllerError(controller, chunkSizeE);
|
||
throw chunkSizeE;
|
||
}
|
||
try {
|
||
EnqueueValueWithSize(controller, chunk, chunkSize);
|
||
} catch (enqueueE) {
|
||
ReadableStreamDefaultControllerError(controller, enqueueE);
|
||
throw enqueueE;
|
||
}
|
||
}
|
||
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
||
}
|
||
function ReadableStreamDefaultControllerError(controller, e2) {
|
||
const stream = controller._controlledReadableStream;
|
||
if (stream._state !== "readable") {
|
||
return;
|
||
}
|
||
ResetQueue(controller);
|
||
ReadableStreamDefaultControllerClearAlgorithms(controller);
|
||
ReadableStreamError(stream, e2);
|
||
}
|
||
function ReadableStreamDefaultControllerGetDesiredSize(controller) {
|
||
const state = controller._controlledReadableStream._state;
|
||
if (state === "errored") {
|
||
return null;
|
||
}
|
||
if (state === "closed") {
|
||
return 0;
|
||
}
|
||
return controller._strategyHWM - controller._queueTotalSize;
|
||
}
|
||
function ReadableStreamDefaultControllerHasBackpressure(controller) {
|
||
if (ReadableStreamDefaultControllerShouldCallPull(controller)) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) {
|
||
const state = controller._controlledReadableStream._state;
|
||
if (!controller._closeRequested && state === "readable") {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
function SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {
|
||
controller._controlledReadableStream = stream;
|
||
controller._queue = void 0;
|
||
controller._queueTotalSize = void 0;
|
||
ResetQueue(controller);
|
||
controller._started = false;
|
||
controller._closeRequested = false;
|
||
controller._pullAgain = false;
|
||
controller._pulling = false;
|
||
controller._strategySizeAlgorithm = sizeAlgorithm;
|
||
controller._strategyHWM = highWaterMark;
|
||
controller._pullAlgorithm = pullAlgorithm;
|
||
controller._cancelAlgorithm = cancelAlgorithm;
|
||
stream._readableStreamController = controller;
|
||
const startResult = startAlgorithm();
|
||
uponPromise(promiseResolvedWith(startResult), () => {
|
||
controller._started = true;
|
||
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
||
return null;
|
||
}, (r2) => {
|
||
ReadableStreamDefaultControllerError(controller, r2);
|
||
return null;
|
||
});
|
||
}
|
||
function SetUpReadableStreamDefaultControllerFromUnderlyingSource(stream, underlyingSource, highWaterMark, sizeAlgorithm) {
|
||
const controller = Object.create(ReadableStreamDefaultController.prototype);
|
||
let startAlgorithm;
|
||
let pullAlgorithm;
|
||
let cancelAlgorithm;
|
||
if (underlyingSource.start !== void 0) {
|
||
startAlgorithm = () => underlyingSource.start(controller);
|
||
} else {
|
||
startAlgorithm = () => void 0;
|
||
}
|
||
if (underlyingSource.pull !== void 0) {
|
||
pullAlgorithm = () => underlyingSource.pull(controller);
|
||
} else {
|
||
pullAlgorithm = () => promiseResolvedWith(void 0);
|
||
}
|
||
if (underlyingSource.cancel !== void 0) {
|
||
cancelAlgorithm = (reason) => underlyingSource.cancel(reason);
|
||
} else {
|
||
cancelAlgorithm = () => promiseResolvedWith(void 0);
|
||
}
|
||
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
||
}
|
||
function defaultControllerBrandCheckException$1(name) {
|
||
return new TypeError(`ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`);
|
||
}
|
||
function ReadableStreamTee(stream, cloneForBranch2) {
|
||
if (IsReadableByteStreamController(stream._readableStreamController)) {
|
||
return ReadableByteStreamTee(stream);
|
||
}
|
||
return ReadableStreamDefaultTee(stream);
|
||
}
|
||
function ReadableStreamDefaultTee(stream, cloneForBranch2) {
|
||
const reader = AcquireReadableStreamDefaultReader(stream);
|
||
let reading = false;
|
||
let readAgain = false;
|
||
let canceled1 = false;
|
||
let canceled2 = false;
|
||
let reason1;
|
||
let reason2;
|
||
let branch1;
|
||
let branch2;
|
||
let resolveCancelPromise;
|
||
const cancelPromise = newPromise((resolve) => {
|
||
resolveCancelPromise = resolve;
|
||
});
|
||
function pullAlgorithm() {
|
||
if (reading) {
|
||
readAgain = true;
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
reading = true;
|
||
const readRequest = {
|
||
_chunkSteps: (chunk) => {
|
||
_queueMicrotask(() => {
|
||
readAgain = false;
|
||
const chunk1 = chunk;
|
||
const chunk2 = chunk;
|
||
if (!canceled1) {
|
||
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
|
||
}
|
||
if (!canceled2) {
|
||
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
|
||
}
|
||
reading = false;
|
||
if (readAgain) {
|
||
pullAlgorithm();
|
||
}
|
||
});
|
||
},
|
||
_closeSteps: () => {
|
||
reading = false;
|
||
if (!canceled1) {
|
||
ReadableStreamDefaultControllerClose(branch1._readableStreamController);
|
||
}
|
||
if (!canceled2) {
|
||
ReadableStreamDefaultControllerClose(branch2._readableStreamController);
|
||
}
|
||
if (!canceled1 || !canceled2) {
|
||
resolveCancelPromise(void 0);
|
||
}
|
||
},
|
||
_errorSteps: () => {
|
||
reading = false;
|
||
}
|
||
};
|
||
ReadableStreamDefaultReaderRead(reader, readRequest);
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
function cancel1Algorithm(reason) {
|
||
canceled1 = true;
|
||
reason1 = reason;
|
||
if (canceled2) {
|
||
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
||
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
||
resolveCancelPromise(cancelResult);
|
||
}
|
||
return cancelPromise;
|
||
}
|
||
function cancel2Algorithm(reason) {
|
||
canceled2 = true;
|
||
reason2 = reason;
|
||
if (canceled1) {
|
||
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
||
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
||
resolveCancelPromise(cancelResult);
|
||
}
|
||
return cancelPromise;
|
||
}
|
||
function startAlgorithm() {
|
||
}
|
||
branch1 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel1Algorithm);
|
||
branch2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel2Algorithm);
|
||
uponRejection(reader._closedPromise, (r2) => {
|
||
ReadableStreamDefaultControllerError(branch1._readableStreamController, r2);
|
||
ReadableStreamDefaultControllerError(branch2._readableStreamController, r2);
|
||
if (!canceled1 || !canceled2) {
|
||
resolveCancelPromise(void 0);
|
||
}
|
||
return null;
|
||
});
|
||
return [branch1, branch2];
|
||
}
|
||
function ReadableByteStreamTee(stream) {
|
||
let reader = AcquireReadableStreamDefaultReader(stream);
|
||
let reading = false;
|
||
let readAgainForBranch1 = false;
|
||
let readAgainForBranch2 = false;
|
||
let canceled1 = false;
|
||
let canceled2 = false;
|
||
let reason1;
|
||
let reason2;
|
||
let branch1;
|
||
let branch2;
|
||
let resolveCancelPromise;
|
||
const cancelPromise = newPromise((resolve) => {
|
||
resolveCancelPromise = resolve;
|
||
});
|
||
function forwardReaderError(thisReader) {
|
||
uponRejection(thisReader._closedPromise, (r2) => {
|
||
if (thisReader !== reader) {
|
||
return null;
|
||
}
|
||
ReadableByteStreamControllerError(branch1._readableStreamController, r2);
|
||
ReadableByteStreamControllerError(branch2._readableStreamController, r2);
|
||
if (!canceled1 || !canceled2) {
|
||
resolveCancelPromise(void 0);
|
||
}
|
||
return null;
|
||
});
|
||
}
|
||
function pullWithDefaultReader() {
|
||
if (IsReadableStreamBYOBReader(reader)) {
|
||
ReadableStreamReaderGenericRelease(reader);
|
||
reader = AcquireReadableStreamDefaultReader(stream);
|
||
forwardReaderError(reader);
|
||
}
|
||
const readRequest = {
|
||
_chunkSteps: (chunk) => {
|
||
_queueMicrotask(() => {
|
||
readAgainForBranch1 = false;
|
||
readAgainForBranch2 = false;
|
||
const chunk1 = chunk;
|
||
let chunk2 = chunk;
|
||
if (!canceled1 && !canceled2) {
|
||
try {
|
||
chunk2 = CloneAsUint8Array(chunk);
|
||
} catch (cloneE) {
|
||
ReadableByteStreamControllerError(branch1._readableStreamController, cloneE);
|
||
ReadableByteStreamControllerError(branch2._readableStreamController, cloneE);
|
||
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
||
return;
|
||
}
|
||
}
|
||
if (!canceled1) {
|
||
ReadableByteStreamControllerEnqueue(branch1._readableStreamController, chunk1);
|
||
}
|
||
if (!canceled2) {
|
||
ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
|
||
}
|
||
reading = false;
|
||
if (readAgainForBranch1) {
|
||
pull1Algorithm();
|
||
} else if (readAgainForBranch2) {
|
||
pull2Algorithm();
|
||
}
|
||
});
|
||
},
|
||
_closeSteps: () => {
|
||
reading = false;
|
||
if (!canceled1) {
|
||
ReadableByteStreamControllerClose(branch1._readableStreamController);
|
||
}
|
||
if (!canceled2) {
|
||
ReadableByteStreamControllerClose(branch2._readableStreamController);
|
||
}
|
||
if (branch1._readableStreamController._pendingPullIntos.length > 0) {
|
||
ReadableByteStreamControllerRespond(branch1._readableStreamController, 0);
|
||
}
|
||
if (branch2._readableStreamController._pendingPullIntos.length > 0) {
|
||
ReadableByteStreamControllerRespond(branch2._readableStreamController, 0);
|
||
}
|
||
if (!canceled1 || !canceled2) {
|
||
resolveCancelPromise(void 0);
|
||
}
|
||
},
|
||
_errorSteps: () => {
|
||
reading = false;
|
||
}
|
||
};
|
||
ReadableStreamDefaultReaderRead(reader, readRequest);
|
||
}
|
||
function pullWithBYOBReader(view, forBranch2) {
|
||
if (IsReadableStreamDefaultReader(reader)) {
|
||
ReadableStreamReaderGenericRelease(reader);
|
||
reader = AcquireReadableStreamBYOBReader(stream);
|
||
forwardReaderError(reader);
|
||
}
|
||
const byobBranch = forBranch2 ? branch2 : branch1;
|
||
const otherBranch = forBranch2 ? branch1 : branch2;
|
||
const readIntoRequest = {
|
||
_chunkSteps: (chunk) => {
|
||
_queueMicrotask(() => {
|
||
readAgainForBranch1 = false;
|
||
readAgainForBranch2 = false;
|
||
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
||
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
||
if (!otherCanceled) {
|
||
let clonedChunk;
|
||
try {
|
||
clonedChunk = CloneAsUint8Array(chunk);
|
||
} catch (cloneE) {
|
||
ReadableByteStreamControllerError(byobBranch._readableStreamController, cloneE);
|
||
ReadableByteStreamControllerError(otherBranch._readableStreamController, cloneE);
|
||
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
||
return;
|
||
}
|
||
if (!byobCanceled) {
|
||
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
||
}
|
||
ReadableByteStreamControllerEnqueue(otherBranch._readableStreamController, clonedChunk);
|
||
} else if (!byobCanceled) {
|
||
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
||
}
|
||
reading = false;
|
||
if (readAgainForBranch1) {
|
||
pull1Algorithm();
|
||
} else if (readAgainForBranch2) {
|
||
pull2Algorithm();
|
||
}
|
||
});
|
||
},
|
||
_closeSteps: (chunk) => {
|
||
reading = false;
|
||
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
||
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
||
if (!byobCanceled) {
|
||
ReadableByteStreamControllerClose(byobBranch._readableStreamController);
|
||
}
|
||
if (!otherCanceled) {
|
||
ReadableByteStreamControllerClose(otherBranch._readableStreamController);
|
||
}
|
||
if (chunk !== void 0) {
|
||
if (!byobCanceled) {
|
||
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
||
}
|
||
if (!otherCanceled && otherBranch._readableStreamController._pendingPullIntos.length > 0) {
|
||
ReadableByteStreamControllerRespond(otherBranch._readableStreamController, 0);
|
||
}
|
||
}
|
||
if (!byobCanceled || !otherCanceled) {
|
||
resolveCancelPromise(void 0);
|
||
}
|
||
},
|
||
_errorSteps: () => {
|
||
reading = false;
|
||
}
|
||
};
|
||
ReadableStreamBYOBReaderRead(reader, view, 1, readIntoRequest);
|
||
}
|
||
function pull1Algorithm() {
|
||
if (reading) {
|
||
readAgainForBranch1 = true;
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
reading = true;
|
||
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch1._readableStreamController);
|
||
if (byobRequest === null) {
|
||
pullWithDefaultReader();
|
||
} else {
|
||
pullWithBYOBReader(byobRequest._view, false);
|
||
}
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
function pull2Algorithm() {
|
||
if (reading) {
|
||
readAgainForBranch2 = true;
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
reading = true;
|
||
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch2._readableStreamController);
|
||
if (byobRequest === null) {
|
||
pullWithDefaultReader();
|
||
} else {
|
||
pullWithBYOBReader(byobRequest._view, true);
|
||
}
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
function cancel1Algorithm(reason) {
|
||
canceled1 = true;
|
||
reason1 = reason;
|
||
if (canceled2) {
|
||
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
||
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
||
resolveCancelPromise(cancelResult);
|
||
}
|
||
return cancelPromise;
|
||
}
|
||
function cancel2Algorithm(reason) {
|
||
canceled2 = true;
|
||
reason2 = reason;
|
||
if (canceled1) {
|
||
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
||
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
||
resolveCancelPromise(cancelResult);
|
||
}
|
||
return cancelPromise;
|
||
}
|
||
function startAlgorithm() {
|
||
return;
|
||
}
|
||
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
||
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
||
forwardReaderError(reader);
|
||
return [branch1, branch2];
|
||
}
|
||
function isReadableStreamLike(stream) {
|
||
return typeIsObject(stream) && typeof stream.getReader !== "undefined";
|
||
}
|
||
function ReadableStreamFrom(source2) {
|
||
if (isReadableStreamLike(source2)) {
|
||
return ReadableStreamFromDefaultReader(source2.getReader());
|
||
}
|
||
return ReadableStreamFromIterable(source2);
|
||
}
|
||
function ReadableStreamFromIterable(asyncIterable) {
|
||
let stream;
|
||
const iteratorRecord = GetIterator(asyncIterable, "async");
|
||
const startAlgorithm = noop2;
|
||
function pullAlgorithm() {
|
||
let nextResult;
|
||
try {
|
||
nextResult = IteratorNext(iteratorRecord);
|
||
} catch (e2) {
|
||
return promiseRejectedWith(e2);
|
||
}
|
||
const nextPromise = promiseResolvedWith(nextResult);
|
||
return transformPromiseWith(nextPromise, (iterResult) => {
|
||
if (!typeIsObject(iterResult)) {
|
||
throw new TypeError("The promise returned by the iterator.next() method must fulfill with an object");
|
||
}
|
||
const done = IteratorComplete(iterResult);
|
||
if (done) {
|
||
ReadableStreamDefaultControllerClose(stream._readableStreamController);
|
||
} else {
|
||
const value = IteratorValue(iterResult);
|
||
ReadableStreamDefaultControllerEnqueue(stream._readableStreamController, value);
|
||
}
|
||
});
|
||
}
|
||
function cancelAlgorithm(reason) {
|
||
const iterator = iteratorRecord.iterator;
|
||
let returnMethod;
|
||
try {
|
||
returnMethod = GetMethod(iterator, "return");
|
||
} catch (e2) {
|
||
return promiseRejectedWith(e2);
|
||
}
|
||
if (returnMethod === void 0) {
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
let returnResult;
|
||
try {
|
||
returnResult = reflectCall(returnMethod, iterator, [reason]);
|
||
} catch (e2) {
|
||
return promiseRejectedWith(e2);
|
||
}
|
||
const returnPromise = promiseResolvedWith(returnResult);
|
||
return transformPromiseWith(returnPromise, (iterResult) => {
|
||
if (!typeIsObject(iterResult)) {
|
||
throw new TypeError("The promise returned by the iterator.return() method must fulfill with an object");
|
||
}
|
||
return void 0;
|
||
});
|
||
}
|
||
stream = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);
|
||
return stream;
|
||
}
|
||
function ReadableStreamFromDefaultReader(reader) {
|
||
let stream;
|
||
const startAlgorithm = noop2;
|
||
function pullAlgorithm() {
|
||
let readPromise;
|
||
try {
|
||
readPromise = reader.read();
|
||
} catch (e2) {
|
||
return promiseRejectedWith(e2);
|
||
}
|
||
return transformPromiseWith(readPromise, (readResult) => {
|
||
if (!typeIsObject(readResult)) {
|
||
throw new TypeError("The promise returned by the reader.read() method must fulfill with an object");
|
||
}
|
||
if (readResult.done) {
|
||
ReadableStreamDefaultControllerClose(stream._readableStreamController);
|
||
} else {
|
||
const value = readResult.value;
|
||
ReadableStreamDefaultControllerEnqueue(stream._readableStreamController, value);
|
||
}
|
||
});
|
||
}
|
||
function cancelAlgorithm(reason) {
|
||
try {
|
||
return promiseResolvedWith(reader.cancel(reason));
|
||
} catch (e2) {
|
||
return promiseRejectedWith(e2);
|
||
}
|
||
}
|
||
stream = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);
|
||
return stream;
|
||
}
|
||
function convertUnderlyingDefaultOrByteSource(source2, context) {
|
||
assertDictionary(source2, context);
|
||
const original = source2;
|
||
const autoAllocateChunkSize = original === null || original === void 0 ? void 0 : original.autoAllocateChunkSize;
|
||
const cancel = original === null || original === void 0 ? void 0 : original.cancel;
|
||
const pull = original === null || original === void 0 ? void 0 : original.pull;
|
||
const start = original === null || original === void 0 ? void 0 : original.start;
|
||
const type = original === null || original === void 0 ? void 0 : original.type;
|
||
return {
|
||
autoAllocateChunkSize: autoAllocateChunkSize === void 0 ? void 0 : convertUnsignedLongLongWithEnforceRange(autoAllocateChunkSize, `${context} has member 'autoAllocateChunkSize' that`),
|
||
cancel: cancel === void 0 ? void 0 : convertUnderlyingSourceCancelCallback(cancel, original, `${context} has member 'cancel' that`),
|
||
pull: pull === void 0 ? void 0 : convertUnderlyingSourcePullCallback(pull, original, `${context} has member 'pull' that`),
|
||
start: start === void 0 ? void 0 : convertUnderlyingSourceStartCallback(start, original, `${context} has member 'start' that`),
|
||
type: type === void 0 ? void 0 : convertReadableStreamType(type, `${context} has member 'type' that`)
|
||
};
|
||
}
|
||
function convertUnderlyingSourceCancelCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (reason) => promiseCall(fn, original, [reason]);
|
||
}
|
||
function convertUnderlyingSourcePullCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (controller) => promiseCall(fn, original, [controller]);
|
||
}
|
||
function convertUnderlyingSourceStartCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (controller) => reflectCall(fn, original, [controller]);
|
||
}
|
||
function convertReadableStreamType(type, context) {
|
||
type = `${type}`;
|
||
if (type !== "bytes") {
|
||
throw new TypeError(`${context} '${type}' is not a valid enumeration value for ReadableStreamType`);
|
||
}
|
||
return type;
|
||
}
|
||
function convertIteratorOptions(options, context) {
|
||
assertDictionary(options, context);
|
||
const preventCancel = options === null || options === void 0 ? void 0 : options.preventCancel;
|
||
return { preventCancel: Boolean(preventCancel) };
|
||
}
|
||
function convertPipeOptions(options, context) {
|
||
assertDictionary(options, context);
|
||
const preventAbort = options === null || options === void 0 ? void 0 : options.preventAbort;
|
||
const preventCancel = options === null || options === void 0 ? void 0 : options.preventCancel;
|
||
const preventClose = options === null || options === void 0 ? void 0 : options.preventClose;
|
||
const signal = options === null || options === void 0 ? void 0 : options.signal;
|
||
if (signal !== void 0) {
|
||
assertAbortSignal(signal, `${context} has member 'signal' that`);
|
||
}
|
||
return {
|
||
preventAbort: Boolean(preventAbort),
|
||
preventCancel: Boolean(preventCancel),
|
||
preventClose: Boolean(preventClose),
|
||
signal
|
||
};
|
||
}
|
||
function assertAbortSignal(signal, context) {
|
||
if (!isAbortSignal2(signal)) {
|
||
throw new TypeError(`${context} is not an AbortSignal.`);
|
||
}
|
||
}
|
||
function convertReadableWritablePair(pair, context) {
|
||
assertDictionary(pair, context);
|
||
const readable = pair === null || pair === void 0 ? void 0 : pair.readable;
|
||
assertRequiredField(readable, "readable", "ReadableWritablePair");
|
||
assertReadableStream(readable, `${context} has member 'readable' that`);
|
||
const writable = pair === null || pair === void 0 ? void 0 : pair.writable;
|
||
assertRequiredField(writable, "writable", "ReadableWritablePair");
|
||
assertWritableStream(writable, `${context} has member 'writable' that`);
|
||
return { readable, writable };
|
||
}
|
||
class ReadableStream2 {
|
||
constructor(rawUnderlyingSource = {}, rawStrategy = {}) {
|
||
if (rawUnderlyingSource === void 0) {
|
||
rawUnderlyingSource = null;
|
||
} else {
|
||
assertObject(rawUnderlyingSource, "First parameter");
|
||
}
|
||
const strategy = convertQueuingStrategy(rawStrategy, "Second parameter");
|
||
const underlyingSource = convertUnderlyingDefaultOrByteSource(rawUnderlyingSource, "First parameter");
|
||
InitializeReadableStream(this);
|
||
if (underlyingSource.type === "bytes") {
|
||
if (strategy.size !== void 0) {
|
||
throw new RangeError("The strategy for a byte stream cannot have a size function");
|
||
}
|
||
const highWaterMark = ExtractHighWaterMark(strategy, 0);
|
||
SetUpReadableByteStreamControllerFromUnderlyingSource(this, underlyingSource, highWaterMark);
|
||
} else {
|
||
const sizeAlgorithm = ExtractSizeAlgorithm(strategy);
|
||
const highWaterMark = ExtractHighWaterMark(strategy, 1);
|
||
SetUpReadableStreamDefaultControllerFromUnderlyingSource(this, underlyingSource, highWaterMark, sizeAlgorithm);
|
||
}
|
||
}
|
||
/**
|
||
* Whether or not the readable stream is locked to a {@link ReadableStreamDefaultReader | reader}.
|
||
*/
|
||
get locked() {
|
||
if (!IsReadableStream(this)) {
|
||
throw streamBrandCheckException$1("locked");
|
||
}
|
||
return IsReadableStreamLocked(this);
|
||
}
|
||
/**
|
||
* Cancels the stream, signaling a loss of interest in the stream by a consumer.
|
||
*
|
||
* The supplied `reason` argument will be given to the underlying source's {@link UnderlyingSource.cancel | cancel()}
|
||
* method, which might or might not use it.
|
||
*/
|
||
cancel(reason = void 0) {
|
||
if (!IsReadableStream(this)) {
|
||
return promiseRejectedWith(streamBrandCheckException$1("cancel"));
|
||
}
|
||
if (IsReadableStreamLocked(this)) {
|
||
return promiseRejectedWith(new TypeError("Cannot cancel a stream that already has a reader"));
|
||
}
|
||
return ReadableStreamCancel(this, reason);
|
||
}
|
||
getReader(rawOptions = void 0) {
|
||
if (!IsReadableStream(this)) {
|
||
throw streamBrandCheckException$1("getReader");
|
||
}
|
||
const options = convertReaderOptions(rawOptions, "First parameter");
|
||
if (options.mode === void 0) {
|
||
return AcquireReadableStreamDefaultReader(this);
|
||
}
|
||
return AcquireReadableStreamBYOBReader(this);
|
||
}
|
||
pipeThrough(rawTransform, rawOptions = {}) {
|
||
if (!IsReadableStream(this)) {
|
||
throw streamBrandCheckException$1("pipeThrough");
|
||
}
|
||
assertRequiredArgument(rawTransform, 1, "pipeThrough");
|
||
const transform = convertReadableWritablePair(rawTransform, "First parameter");
|
||
const options = convertPipeOptions(rawOptions, "Second parameter");
|
||
if (IsReadableStreamLocked(this)) {
|
||
throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");
|
||
}
|
||
if (IsWritableStreamLocked(transform.writable)) {
|
||
throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");
|
||
}
|
||
const promise = ReadableStreamPipeTo(this, transform.writable, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
||
setPromiseIsHandledToTrue(promise);
|
||
return transform.readable;
|
||
}
|
||
pipeTo(destination, rawOptions = {}) {
|
||
if (!IsReadableStream(this)) {
|
||
return promiseRejectedWith(streamBrandCheckException$1("pipeTo"));
|
||
}
|
||
if (destination === void 0) {
|
||
return promiseRejectedWith(`Parameter 1 is required in 'pipeTo'.`);
|
||
}
|
||
if (!IsWritableStream(destination)) {
|
||
return promiseRejectedWith(new TypeError(`ReadableStream.prototype.pipeTo's first argument must be a WritableStream`));
|
||
}
|
||
let options;
|
||
try {
|
||
options = convertPipeOptions(rawOptions, "Second parameter");
|
||
} catch (e2) {
|
||
return promiseRejectedWith(e2);
|
||
}
|
||
if (IsReadableStreamLocked(this)) {
|
||
return promiseRejectedWith(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream"));
|
||
}
|
||
if (IsWritableStreamLocked(destination)) {
|
||
return promiseRejectedWith(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream"));
|
||
}
|
||
return ReadableStreamPipeTo(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
||
}
|
||
/**
|
||
* Tees this readable stream, returning a two-element array containing the two resulting branches as
|
||
* new {@link ReadableStream} instances.
|
||
*
|
||
* Teeing a stream will lock it, preventing any other consumer from acquiring a reader.
|
||
* To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be
|
||
* propagated to the stream's underlying source.
|
||
*
|
||
* Note that the chunks seen in each branch will be the same object. If the chunks are not immutable,
|
||
* this could allow interference between the two branches.
|
||
*/
|
||
tee() {
|
||
if (!IsReadableStream(this)) {
|
||
throw streamBrandCheckException$1("tee");
|
||
}
|
||
const branches = ReadableStreamTee(this);
|
||
return CreateArrayFromList(branches);
|
||
}
|
||
values(rawOptions = void 0) {
|
||
if (!IsReadableStream(this)) {
|
||
throw streamBrandCheckException$1("values");
|
||
}
|
||
const options = convertIteratorOptions(rawOptions, "First parameter");
|
||
return AcquireReadableStreamAsyncIterator(this, options.preventCancel);
|
||
}
|
||
[SymbolAsyncIterator](options) {
|
||
return this.values(options);
|
||
}
|
||
/**
|
||
* Creates a new ReadableStream wrapping the provided iterable or async iterable.
|
||
*
|
||
* This can be used to adapt various kinds of objects into a readable stream,
|
||
* such as an array, an async generator, or a Node.js readable stream.
|
||
*/
|
||
static from(asyncIterable) {
|
||
return ReadableStreamFrom(asyncIterable);
|
||
}
|
||
}
|
||
Object.defineProperties(ReadableStream2, {
|
||
from: { enumerable: true }
|
||
});
|
||
Object.defineProperties(ReadableStream2.prototype, {
|
||
cancel: { enumerable: true },
|
||
getReader: { enumerable: true },
|
||
pipeThrough: { enumerable: true },
|
||
pipeTo: { enumerable: true },
|
||
tee: { enumerable: true },
|
||
values: { enumerable: true },
|
||
locked: { enumerable: true }
|
||
});
|
||
setFunctionName(ReadableStream2.from, "from");
|
||
setFunctionName(ReadableStream2.prototype.cancel, "cancel");
|
||
setFunctionName(ReadableStream2.prototype.getReader, "getReader");
|
||
setFunctionName(ReadableStream2.prototype.pipeThrough, "pipeThrough");
|
||
setFunctionName(ReadableStream2.prototype.pipeTo, "pipeTo");
|
||
setFunctionName(ReadableStream2.prototype.tee, "tee");
|
||
setFunctionName(ReadableStream2.prototype.values, "values");
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(ReadableStream2.prototype, Symbol.toStringTag, {
|
||
value: "ReadableStream",
|
||
configurable: true
|
||
});
|
||
}
|
||
Object.defineProperty(ReadableStream2.prototype, SymbolAsyncIterator, {
|
||
value: ReadableStream2.prototype.values,
|
||
writable: true,
|
||
configurable: true
|
||
});
|
||
function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark = 1, sizeAlgorithm = () => 1) {
|
||
const stream = Object.create(ReadableStream2.prototype);
|
||
InitializeReadableStream(stream);
|
||
const controller = Object.create(ReadableStreamDefaultController.prototype);
|
||
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
||
return stream;
|
||
}
|
||
function CreateReadableByteStream(startAlgorithm, pullAlgorithm, cancelAlgorithm) {
|
||
const stream = Object.create(ReadableStream2.prototype);
|
||
InitializeReadableStream(stream);
|
||
const controller = Object.create(ReadableByteStreamController.prototype);
|
||
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, void 0);
|
||
return stream;
|
||
}
|
||
function InitializeReadableStream(stream) {
|
||
stream._state = "readable";
|
||
stream._reader = void 0;
|
||
stream._storedError = void 0;
|
||
stream._disturbed = false;
|
||
}
|
||
function IsReadableStream(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_readableStreamController")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof ReadableStream2;
|
||
}
|
||
function IsReadableStreamLocked(stream) {
|
||
if (stream._reader === void 0) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
function ReadableStreamCancel(stream, reason) {
|
||
stream._disturbed = true;
|
||
if (stream._state === "closed") {
|
||
return promiseResolvedWith(void 0);
|
||
}
|
||
if (stream._state === "errored") {
|
||
return promiseRejectedWith(stream._storedError);
|
||
}
|
||
ReadableStreamClose(stream);
|
||
const reader = stream._reader;
|
||
if (reader !== void 0 && IsReadableStreamBYOBReader(reader)) {
|
||
const readIntoRequests = reader._readIntoRequests;
|
||
reader._readIntoRequests = new SimpleQueue();
|
||
readIntoRequests.forEach((readIntoRequest) => {
|
||
readIntoRequest._closeSteps(void 0);
|
||
});
|
||
}
|
||
const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
||
return transformPromiseWith(sourceCancelPromise, noop2);
|
||
}
|
||
function ReadableStreamClose(stream) {
|
||
stream._state = "closed";
|
||
const reader = stream._reader;
|
||
if (reader === void 0) {
|
||
return;
|
||
}
|
||
defaultReaderClosedPromiseResolve(reader);
|
||
if (IsReadableStreamDefaultReader(reader)) {
|
||
const readRequests = reader._readRequests;
|
||
reader._readRequests = new SimpleQueue();
|
||
readRequests.forEach((readRequest) => {
|
||
readRequest._closeSteps();
|
||
});
|
||
}
|
||
}
|
||
function ReadableStreamError(stream, e2) {
|
||
stream._state = "errored";
|
||
stream._storedError = e2;
|
||
const reader = stream._reader;
|
||
if (reader === void 0) {
|
||
return;
|
||
}
|
||
defaultReaderClosedPromiseReject(reader, e2);
|
||
if (IsReadableStreamDefaultReader(reader)) {
|
||
ReadableStreamDefaultReaderErrorReadRequests(reader, e2);
|
||
} else {
|
||
ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e2);
|
||
}
|
||
}
|
||
function streamBrandCheckException$1(name) {
|
||
return new TypeError(`ReadableStream.prototype.${name} can only be used on a ReadableStream`);
|
||
}
|
||
function convertQueuingStrategyInit(init, context) {
|
||
assertDictionary(init, context);
|
||
const highWaterMark = init === null || init === void 0 ? void 0 : init.highWaterMark;
|
||
assertRequiredField(highWaterMark, "highWaterMark", "QueuingStrategyInit");
|
||
return {
|
||
highWaterMark: convertUnrestrictedDouble(highWaterMark)
|
||
};
|
||
}
|
||
const byteLengthSizeFunction = (chunk) => {
|
||
return chunk.byteLength;
|
||
};
|
||
setFunctionName(byteLengthSizeFunction, "size");
|
||
class ByteLengthQueuingStrategy {
|
||
constructor(options) {
|
||
assertRequiredArgument(options, 1, "ByteLengthQueuingStrategy");
|
||
options = convertQueuingStrategyInit(options, "First parameter");
|
||
this._byteLengthQueuingStrategyHighWaterMark = options.highWaterMark;
|
||
}
|
||
/**
|
||
* Returns the high water mark provided to the constructor.
|
||
*/
|
||
get highWaterMark() {
|
||
if (!IsByteLengthQueuingStrategy(this)) {
|
||
throw byteLengthBrandCheckException("highWaterMark");
|
||
}
|
||
return this._byteLengthQueuingStrategyHighWaterMark;
|
||
}
|
||
/**
|
||
* Measures the size of `chunk` by returning the value of its `byteLength` property.
|
||
*/
|
||
get size() {
|
||
if (!IsByteLengthQueuingStrategy(this)) {
|
||
throw byteLengthBrandCheckException("size");
|
||
}
|
||
return byteLengthSizeFunction;
|
||
}
|
||
}
|
||
Object.defineProperties(ByteLengthQueuingStrategy.prototype, {
|
||
highWaterMark: { enumerable: true },
|
||
size: { enumerable: true }
|
||
});
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(ByteLengthQueuingStrategy.prototype, Symbol.toStringTag, {
|
||
value: "ByteLengthQueuingStrategy",
|
||
configurable: true
|
||
});
|
||
}
|
||
function byteLengthBrandCheckException(name) {
|
||
return new TypeError(`ByteLengthQueuingStrategy.prototype.${name} can only be used on a ByteLengthQueuingStrategy`);
|
||
}
|
||
function IsByteLengthQueuingStrategy(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_byteLengthQueuingStrategyHighWaterMark")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof ByteLengthQueuingStrategy;
|
||
}
|
||
const countSizeFunction = () => {
|
||
return 1;
|
||
};
|
||
setFunctionName(countSizeFunction, "size");
|
||
class CountQueuingStrategy {
|
||
constructor(options) {
|
||
assertRequiredArgument(options, 1, "CountQueuingStrategy");
|
||
options = convertQueuingStrategyInit(options, "First parameter");
|
||
this._countQueuingStrategyHighWaterMark = options.highWaterMark;
|
||
}
|
||
/**
|
||
* Returns the high water mark provided to the constructor.
|
||
*/
|
||
get highWaterMark() {
|
||
if (!IsCountQueuingStrategy(this)) {
|
||
throw countBrandCheckException("highWaterMark");
|
||
}
|
||
return this._countQueuingStrategyHighWaterMark;
|
||
}
|
||
/**
|
||
* Measures the size of `chunk` by always returning 1.
|
||
* This ensures that the total queue size is a count of the number of chunks in the queue.
|
||
*/
|
||
get size() {
|
||
if (!IsCountQueuingStrategy(this)) {
|
||
throw countBrandCheckException("size");
|
||
}
|
||
return countSizeFunction;
|
||
}
|
||
}
|
||
Object.defineProperties(CountQueuingStrategy.prototype, {
|
||
highWaterMark: { enumerable: true },
|
||
size: { enumerable: true }
|
||
});
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(CountQueuingStrategy.prototype, Symbol.toStringTag, {
|
||
value: "CountQueuingStrategy",
|
||
configurable: true
|
||
});
|
||
}
|
||
function countBrandCheckException(name) {
|
||
return new TypeError(`CountQueuingStrategy.prototype.${name} can only be used on a CountQueuingStrategy`);
|
||
}
|
||
function IsCountQueuingStrategy(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_countQueuingStrategyHighWaterMark")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof CountQueuingStrategy;
|
||
}
|
||
function convertTransformer(original, context) {
|
||
assertDictionary(original, context);
|
||
const cancel = original === null || original === void 0 ? void 0 : original.cancel;
|
||
const flush = original === null || original === void 0 ? void 0 : original.flush;
|
||
const readableType = original === null || original === void 0 ? void 0 : original.readableType;
|
||
const start = original === null || original === void 0 ? void 0 : original.start;
|
||
const transform = original === null || original === void 0 ? void 0 : original.transform;
|
||
const writableType = original === null || original === void 0 ? void 0 : original.writableType;
|
||
return {
|
||
cancel: cancel === void 0 ? void 0 : convertTransformerCancelCallback(cancel, original, `${context} has member 'cancel' that`),
|
||
flush: flush === void 0 ? void 0 : convertTransformerFlushCallback(flush, original, `${context} has member 'flush' that`),
|
||
readableType,
|
||
start: start === void 0 ? void 0 : convertTransformerStartCallback(start, original, `${context} has member 'start' that`),
|
||
transform: transform === void 0 ? void 0 : convertTransformerTransformCallback(transform, original, `${context} has member 'transform' that`),
|
||
writableType
|
||
};
|
||
}
|
||
function convertTransformerFlushCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (controller) => promiseCall(fn, original, [controller]);
|
||
}
|
||
function convertTransformerStartCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (controller) => reflectCall(fn, original, [controller]);
|
||
}
|
||
function convertTransformerTransformCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (chunk, controller) => promiseCall(fn, original, [chunk, controller]);
|
||
}
|
||
function convertTransformerCancelCallback(fn, original, context) {
|
||
assertFunction(fn, context);
|
||
return (reason) => promiseCall(fn, original, [reason]);
|
||
}
|
||
class TransformStream {
|
||
constructor(rawTransformer = {}, rawWritableStrategy = {}, rawReadableStrategy = {}) {
|
||
if (rawTransformer === void 0) {
|
||
rawTransformer = null;
|
||
}
|
||
const writableStrategy = convertQueuingStrategy(rawWritableStrategy, "Second parameter");
|
||
const readableStrategy = convertQueuingStrategy(rawReadableStrategy, "Third parameter");
|
||
const transformer = convertTransformer(rawTransformer, "First parameter");
|
||
if (transformer.readableType !== void 0) {
|
||
throw new RangeError("Invalid readableType specified");
|
||
}
|
||
if (transformer.writableType !== void 0) {
|
||
throw new RangeError("Invalid writableType specified");
|
||
}
|
||
const readableHighWaterMark = ExtractHighWaterMark(readableStrategy, 0);
|
||
const readableSizeAlgorithm = ExtractSizeAlgorithm(readableStrategy);
|
||
const writableHighWaterMark = ExtractHighWaterMark(writableStrategy, 1);
|
||
const writableSizeAlgorithm = ExtractSizeAlgorithm(writableStrategy);
|
||
let startPromise_resolve;
|
||
const startPromise = newPromise((resolve) => {
|
||
startPromise_resolve = resolve;
|
||
});
|
||
InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
|
||
SetUpTransformStreamDefaultControllerFromTransformer(this, transformer);
|
||
if (transformer.start !== void 0) {
|
||
startPromise_resolve(transformer.start(this._transformStreamController));
|
||
} else {
|
||
startPromise_resolve(void 0);
|
||
}
|
||
}
|
||
/**
|
||
* The readable side of the transform stream.
|
||
*/
|
||
get readable() {
|
||
if (!IsTransformStream(this)) {
|
||
throw streamBrandCheckException("readable");
|
||
}
|
||
return this._readable;
|
||
}
|
||
/**
|
||
* The writable side of the transform stream.
|
||
*/
|
||
get writable() {
|
||
if (!IsTransformStream(this)) {
|
||
throw streamBrandCheckException("writable");
|
||
}
|
||
return this._writable;
|
||
}
|
||
}
|
||
Object.defineProperties(TransformStream.prototype, {
|
||
readable: { enumerable: true },
|
||
writable: { enumerable: true }
|
||
});
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(TransformStream.prototype, Symbol.toStringTag, {
|
||
value: "TransformStream",
|
||
configurable: true
|
||
});
|
||
}
|
||
function InitializeTransformStream(stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm) {
|
||
function startAlgorithm() {
|
||
return startPromise;
|
||
}
|
||
function writeAlgorithm(chunk) {
|
||
return TransformStreamDefaultSinkWriteAlgorithm(stream, chunk);
|
||
}
|
||
function abortAlgorithm(reason) {
|
||
return TransformStreamDefaultSinkAbortAlgorithm(stream, reason);
|
||
}
|
||
function closeAlgorithm() {
|
||
return TransformStreamDefaultSinkCloseAlgorithm(stream);
|
||
}
|
||
stream._writable = CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, writableHighWaterMark, writableSizeAlgorithm);
|
||
function pullAlgorithm() {
|
||
return TransformStreamDefaultSourcePullAlgorithm(stream);
|
||
}
|
||
function cancelAlgorithm(reason) {
|
||
return TransformStreamDefaultSourceCancelAlgorithm(stream, reason);
|
||
}
|
||
stream._readable = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
|
||
stream._backpressure = void 0;
|
||
stream._backpressureChangePromise = void 0;
|
||
stream._backpressureChangePromise_resolve = void 0;
|
||
TransformStreamSetBackpressure(stream, true);
|
||
stream._transformStreamController = void 0;
|
||
}
|
||
function IsTransformStream(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_transformStreamController")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof TransformStream;
|
||
}
|
||
function TransformStreamError(stream, e2) {
|
||
ReadableStreamDefaultControllerError(stream._readable._readableStreamController, e2);
|
||
TransformStreamErrorWritableAndUnblockWrite(stream, e2);
|
||
}
|
||
function TransformStreamErrorWritableAndUnblockWrite(stream, e2) {
|
||
TransformStreamDefaultControllerClearAlgorithms(stream._transformStreamController);
|
||
WritableStreamDefaultControllerErrorIfNeeded(stream._writable._writableStreamController, e2);
|
||
TransformStreamUnblockWrite(stream);
|
||
}
|
||
function TransformStreamUnblockWrite(stream) {
|
||
if (stream._backpressure) {
|
||
TransformStreamSetBackpressure(stream, false);
|
||
}
|
||
}
|
||
function TransformStreamSetBackpressure(stream, backpressure) {
|
||
if (stream._backpressureChangePromise !== void 0) {
|
||
stream._backpressureChangePromise_resolve();
|
||
}
|
||
stream._backpressureChangePromise = newPromise((resolve) => {
|
||
stream._backpressureChangePromise_resolve = resolve;
|
||
});
|
||
stream._backpressure = backpressure;
|
||
}
|
||
class TransformStreamDefaultController {
|
||
constructor() {
|
||
throw new TypeError("Illegal constructor");
|
||
}
|
||
/**
|
||
* Returns the desired size to fill the readable side’s internal queue. It can be negative, if the queue is over-full.
|
||
*/
|
||
get desiredSize() {
|
||
if (!IsTransformStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException("desiredSize");
|
||
}
|
||
const readableController = this._controlledTransformStream._readable._readableStreamController;
|
||
return ReadableStreamDefaultControllerGetDesiredSize(readableController);
|
||
}
|
||
enqueue(chunk = void 0) {
|
||
if (!IsTransformStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException("enqueue");
|
||
}
|
||
TransformStreamDefaultControllerEnqueue(this, chunk);
|
||
}
|
||
/**
|
||
* Errors both the readable side and the writable side of the controlled transform stream, making all future
|
||
* interactions with it fail with the given error `e`. Any chunks queued for transformation will be discarded.
|
||
*/
|
||
error(reason = void 0) {
|
||
if (!IsTransformStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException("error");
|
||
}
|
||
TransformStreamDefaultControllerError(this, reason);
|
||
}
|
||
/**
|
||
* Closes the readable side and errors the writable side of the controlled transform stream. This is useful when the
|
||
* transformer only needs to consume a portion of the chunks written to the writable side.
|
||
*/
|
||
terminate() {
|
||
if (!IsTransformStreamDefaultController(this)) {
|
||
throw defaultControllerBrandCheckException("terminate");
|
||
}
|
||
TransformStreamDefaultControllerTerminate(this);
|
||
}
|
||
}
|
||
Object.defineProperties(TransformStreamDefaultController.prototype, {
|
||
enqueue: { enumerable: true },
|
||
error: { enumerable: true },
|
||
terminate: { enumerable: true },
|
||
desiredSize: { enumerable: true }
|
||
});
|
||
setFunctionName(TransformStreamDefaultController.prototype.enqueue, "enqueue");
|
||
setFunctionName(TransformStreamDefaultController.prototype.error, "error");
|
||
setFunctionName(TransformStreamDefaultController.prototype.terminate, "terminate");
|
||
if (typeof Symbol.toStringTag === "symbol") {
|
||
Object.defineProperty(TransformStreamDefaultController.prototype, Symbol.toStringTag, {
|
||
value: "TransformStreamDefaultController",
|
||
configurable: true
|
||
});
|
||
}
|
||
function IsTransformStreamDefaultController(x2) {
|
||
if (!typeIsObject(x2)) {
|
||
return false;
|
||
}
|
||
if (!Object.prototype.hasOwnProperty.call(x2, "_controlledTransformStream")) {
|
||
return false;
|
||
}
|
||
return x2 instanceof TransformStreamDefaultController;
|
||
}
|
||
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm, cancelAlgorithm) {
|
||
controller._controlledTransformStream = stream;
|
||
stream._transformStreamController = controller;
|
||
controller._transformAlgorithm = transformAlgorithm;
|
||
controller._flushAlgorithm = flushAlgorithm;
|
||
controller._cancelAlgorithm = cancelAlgorithm;
|
||
controller._finishPromise = void 0;
|
||
controller._finishPromise_resolve = void 0;
|
||
controller._finishPromise_reject = void 0;
|
||
}
|
||
function SetUpTransformStreamDefaultControllerFromTransformer(stream, transformer) {
|
||
const controller = Object.create(TransformStreamDefaultController.prototype);
|
||
let transformAlgorithm;
|
||
let flushAlgorithm;
|
||
let cancelAlgorithm;
|
||
if (transformer.transform !== void 0) {
|
||
transformAlgorithm = (chunk) => transformer.transform(chunk, controller);
|
||
} else {
|
||
transformAlgorithm = (chunk) => {
|
||
try {
|
||
TransformStreamDefaultControllerEnqueue(controller, chunk);
|
||
return promiseResolvedWith(void 0);
|
||
} catch (transformResultE) {
|
||
return promiseRejectedWith(transformResultE);
|
||
}
|
||
};
|
||
}
|
||
if (transformer.flush !== void 0) {
|
||
flushAlgorithm = () => transformer.flush(controller);
|
||
} else {
|
||
flushAlgorithm = () => promiseResolvedWith(void 0);
|
||
}
|
||
if (transformer.cancel !== void 0) {
|
||
cancelAlgorithm = (reason) => transformer.cancel(reason);
|
||
} else {
|
||
cancelAlgorithm = () => promiseResolvedWith(void 0);
|
||
}
|
||
SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm, cancelAlgorithm);
|
||
}
|
||
function TransformStreamDefaultControllerClearAlgorithms(controller) {
|
||
controller._transformAlgorithm = void 0;
|
||
controller._flushAlgorithm = void 0;
|
||
controller._cancelAlgorithm = void 0;
|
||
}
|
||
function TransformStreamDefaultControllerEnqueue(controller, chunk) {
|
||
const stream = controller._controlledTransformStream;
|
||
const readableController = stream._readable._readableStreamController;
|
||
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(readableController)) {
|
||
throw new TypeError("Readable side is not in a state that permits enqueue");
|
||
}
|
||
try {
|
||
ReadableStreamDefaultControllerEnqueue(readableController, chunk);
|
||
} catch (e2) {
|
||
TransformStreamErrorWritableAndUnblockWrite(stream, e2);
|
||
throw stream._readable._storedError;
|
||
}
|
||
const backpressure = ReadableStreamDefaultControllerHasBackpressure(readableController);
|
||
if (backpressure !== stream._backpressure) {
|
||
TransformStreamSetBackpressure(stream, true);
|
||
}
|
||
}
|
||
function TransformStreamDefaultControllerError(controller, e2) {
|
||
TransformStreamError(controller._controlledTransformStream, e2);
|
||
}
|
||
function TransformStreamDefaultControllerPerformTransform(controller, chunk) {
|
||
const transformPromise = controller._transformAlgorithm(chunk);
|
||
return transformPromiseWith(transformPromise, void 0, (r2) => {
|
||
TransformStreamError(controller._controlledTransformStream, r2);
|
||
throw r2;
|
||
});
|
||
}
|
||
function TransformStreamDefaultControllerTerminate(controller) {
|
||
const stream = controller._controlledTransformStream;
|
||
const readableController = stream._readable._readableStreamController;
|
||
ReadableStreamDefaultControllerClose(readableController);
|
||
const error = new TypeError("TransformStream terminated");
|
||
TransformStreamErrorWritableAndUnblockWrite(stream, error);
|
||
}
|
||
function TransformStreamDefaultSinkWriteAlgorithm(stream, chunk) {
|
||
const controller = stream._transformStreamController;
|
||
if (stream._backpressure) {
|
||
const backpressureChangePromise = stream._backpressureChangePromise;
|
||
return transformPromiseWith(backpressureChangePromise, () => {
|
||
const writable = stream._writable;
|
||
const state = writable._state;
|
||
if (state === "erroring") {
|
||
throw writable._storedError;
|
||
}
|
||
return TransformStreamDefaultControllerPerformTransform(controller, chunk);
|
||
});
|
||
}
|
||
return TransformStreamDefaultControllerPerformTransform(controller, chunk);
|
||
}
|
||
function TransformStreamDefaultSinkAbortAlgorithm(stream, reason) {
|
||
const controller = stream._transformStreamController;
|
||
if (controller._finishPromise !== void 0) {
|
||
return controller._finishPromise;
|
||
}
|
||
const readable = stream._readable;
|
||
controller._finishPromise = newPromise((resolve, reject) => {
|
||
controller._finishPromise_resolve = resolve;
|
||
controller._finishPromise_reject = reject;
|
||
});
|
||
const cancelPromise = controller._cancelAlgorithm(reason);
|
||
TransformStreamDefaultControllerClearAlgorithms(controller);
|
||
uponPromise(cancelPromise, () => {
|
||
if (readable._state === "errored") {
|
||
defaultControllerFinishPromiseReject(controller, readable._storedError);
|
||
} else {
|
||
ReadableStreamDefaultControllerError(readable._readableStreamController, reason);
|
||
defaultControllerFinishPromiseResolve(controller);
|
||
}
|
||
return null;
|
||
}, (r2) => {
|
||
ReadableStreamDefaultControllerError(readable._readableStreamController, r2);
|
||
defaultControllerFinishPromiseReject(controller, r2);
|
||
return null;
|
||
});
|
||
return controller._finishPromise;
|
||
}
|
||
function TransformStreamDefaultSinkCloseAlgorithm(stream) {
|
||
const controller = stream._transformStreamController;
|
||
if (controller._finishPromise !== void 0) {
|
||
return controller._finishPromise;
|
||
}
|
||
const readable = stream._readable;
|
||
controller._finishPromise = newPromise((resolve, reject) => {
|
||
controller._finishPromise_resolve = resolve;
|
||
controller._finishPromise_reject = reject;
|
||
});
|
||
const flushPromise = controller._flushAlgorithm();
|
||
TransformStreamDefaultControllerClearAlgorithms(controller);
|
||
uponPromise(flushPromise, () => {
|
||
if (readable._state === "errored") {
|
||
defaultControllerFinishPromiseReject(controller, readable._storedError);
|
||
} else {
|
||
ReadableStreamDefaultControllerClose(readable._readableStreamController);
|
||
defaultControllerFinishPromiseResolve(controller);
|
||
}
|
||
return null;
|
||
}, (r2) => {
|
||
ReadableStreamDefaultControllerError(readable._readableStreamController, r2);
|
||
defaultControllerFinishPromiseReject(controller, r2);
|
||
return null;
|
||
});
|
||
return controller._finishPromise;
|
||
}
|
||
function TransformStreamDefaultSourcePullAlgorithm(stream) {
|
||
TransformStreamSetBackpressure(stream, false);
|
||
return stream._backpressureChangePromise;
|
||
}
|
||
function TransformStreamDefaultSourceCancelAlgorithm(stream, reason) {
|
||
const controller = stream._transformStreamController;
|
||
if (controller._finishPromise !== void 0) {
|
||
return controller._finishPromise;
|
||
}
|
||
const writable = stream._writable;
|
||
controller._finishPromise = newPromise((resolve, reject) => {
|
||
controller._finishPromise_resolve = resolve;
|
||
controller._finishPromise_reject = reject;
|
||
});
|
||
const cancelPromise = controller._cancelAlgorithm(reason);
|
||
TransformStreamDefaultControllerClearAlgorithms(controller);
|
||
uponPromise(cancelPromise, () => {
|
||
if (writable._state === "errored") {
|
||
defaultControllerFinishPromiseReject(controller, writable._storedError);
|
||
} else {
|
||
WritableStreamDefaultControllerErrorIfNeeded(writable._writableStreamController, reason);
|
||
TransformStreamUnblockWrite(stream);
|
||
defaultControllerFinishPromiseResolve(controller);
|
||
}
|
||
return null;
|
||
}, (r2) => {
|
||
WritableStreamDefaultControllerErrorIfNeeded(writable._writableStreamController, r2);
|
||
TransformStreamUnblockWrite(stream);
|
||
defaultControllerFinishPromiseReject(controller, r2);
|
||
return null;
|
||
});
|
||
return controller._finishPromise;
|
||
}
|
||
function defaultControllerBrandCheckException(name) {
|
||
return new TypeError(`TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`);
|
||
}
|
||
function defaultControllerFinishPromiseResolve(controller) {
|
||
if (controller._finishPromise_resolve === void 0) {
|
||
return;
|
||
}
|
||
controller._finishPromise_resolve();
|
||
controller._finishPromise_resolve = void 0;
|
||
controller._finishPromise_reject = void 0;
|
||
}
|
||
function defaultControllerFinishPromiseReject(controller, reason) {
|
||
if (controller._finishPromise_reject === void 0) {
|
||
return;
|
||
}
|
||
setPromiseIsHandledToTrue(controller._finishPromise);
|
||
controller._finishPromise_reject(reason);
|
||
controller._finishPromise_resolve = void 0;
|
||
controller._finishPromise_reject = void 0;
|
||
}
|
||
function streamBrandCheckException(name) {
|
||
return new TypeError(`TransformStream.prototype.${name} can only be used on a TransformStream`);
|
||
}
|
||
exports3.ByteLengthQueuingStrategy = ByteLengthQueuingStrategy;
|
||
exports3.CountQueuingStrategy = CountQueuingStrategy;
|
||
exports3.ReadableByteStreamController = ReadableByteStreamController;
|
||
exports3.ReadableStream = ReadableStream2;
|
||
exports3.ReadableStreamBYOBReader = ReadableStreamBYOBReader;
|
||
exports3.ReadableStreamBYOBRequest = ReadableStreamBYOBRequest;
|
||
exports3.ReadableStreamDefaultController = ReadableStreamDefaultController;
|
||
exports3.ReadableStreamDefaultReader = ReadableStreamDefaultReader;
|
||
exports3.TransformStream = TransformStream;
|
||
exports3.TransformStreamDefaultController = TransformStreamDefaultController;
|
||
exports3.WritableStream = WritableStream;
|
||
exports3.WritableStreamDefaultController = WritableStreamDefaultController;
|
||
exports3.WritableStreamDefaultWriter = WritableStreamDefaultWriter;
|
||
});
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/streams.cjs
|
||
var require_streams = __commonJS({
|
||
"../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/streams.cjs"() {
|
||
var POOL_SIZE2 = 65536;
|
||
if (!globalThis.ReadableStream) {
|
||
try {
|
||
const process2 = require("node:process");
|
||
const { emitWarning } = process2;
|
||
try {
|
||
process2.emitWarning = () => {
|
||
};
|
||
Object.assign(globalThis, require("node:stream/web"));
|
||
process2.emitWarning = emitWarning;
|
||
} catch (error) {
|
||
process2.emitWarning = emitWarning;
|
||
throw error;
|
||
}
|
||
} catch (error) {
|
||
Object.assign(globalThis, require_ponyfill_es2018());
|
||
}
|
||
}
|
||
try {
|
||
const { Blob: Blob3 } = require("buffer");
|
||
if (Blob3 && !Blob3.prototype.stream) {
|
||
Blob3.prototype.stream = function name(params) {
|
||
let position = 0;
|
||
const blob = this;
|
||
return new ReadableStream({
|
||
type: "bytes",
|
||
async pull(ctrl) {
|
||
const chunk = blob.slice(position, Math.min(blob.size, position + POOL_SIZE2));
|
||
const buffer = await chunk.arrayBuffer();
|
||
position += buffer.byteLength;
|
||
ctrl.enqueue(new Uint8Array(buffer));
|
||
if (position === blob.size) {
|
||
ctrl.close();
|
||
}
|
||
}
|
||
});
|
||
};
|
||
}
|
||
} catch (error) {
|
||
}
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/index.js
|
||
async function* toIterator(parts, clone2 = true) {
|
||
for (const part of parts) {
|
||
if ("stream" in part) {
|
||
yield* (
|
||
/** @type {AsyncIterableIterator<Uint8Array>} */
|
||
part.stream()
|
||
);
|
||
} else if (ArrayBuffer.isView(part)) {
|
||
if (clone2) {
|
||
let position = part.byteOffset;
|
||
const end = part.byteOffset + part.byteLength;
|
||
while (position !== end) {
|
||
const size = Math.min(end - position, POOL_SIZE);
|
||
const chunk = part.buffer.slice(position, position + size);
|
||
position += chunk.byteLength;
|
||
yield new Uint8Array(chunk);
|
||
}
|
||
} else {
|
||
yield part;
|
||
}
|
||
} else {
|
||
let position = 0, b = (
|
||
/** @type {Blob} */
|
||
part
|
||
);
|
||
while (position !== b.size) {
|
||
const chunk = b.slice(position, Math.min(b.size, position + POOL_SIZE));
|
||
const buffer = await chunk.arrayBuffer();
|
||
position += buffer.byteLength;
|
||
yield new Uint8Array(buffer);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
var import_streams, POOL_SIZE, _Blob, Blob2, fetch_blob_default;
|
||
var init_fetch_blob = __esm({
|
||
"../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/index.js"() {
|
||
import_streams = __toESM(require_streams(), 1);
|
||
POOL_SIZE = 65536;
|
||
_Blob = class Blob {
|
||
/** @type {Array.<(Blob|Uint8Array)>} */
|
||
#parts = [];
|
||
#type = "";
|
||
#size = 0;
|
||
#endings = "transparent";
|
||
/**
|
||
* The Blob() constructor returns a new Blob object. The content
|
||
* of the blob consists of the concatenation of the values given
|
||
* in the parameter array.
|
||
*
|
||
* @param {*} blobParts
|
||
* @param {{ type?: string, endings?: string }} [options]
|
||
*/
|
||
constructor(blobParts = [], options = {}) {
|
||
if (typeof blobParts !== "object" || blobParts === null) {
|
||
throw new TypeError("Failed to construct 'Blob': The provided value cannot be converted to a sequence.");
|
||
}
|
||
if (typeof blobParts[Symbol.iterator] !== "function") {
|
||
throw new TypeError("Failed to construct 'Blob': The object must have a callable @@iterator property.");
|
||
}
|
||
if (typeof options !== "object" && typeof options !== "function") {
|
||
throw new TypeError("Failed to construct 'Blob': parameter 2 cannot convert to dictionary.");
|
||
}
|
||
if (options === null) options = {};
|
||
const encoder = new TextEncoder();
|
||
for (const element of blobParts) {
|
||
let part;
|
||
if (ArrayBuffer.isView(element)) {
|
||
part = new Uint8Array(element.buffer.slice(element.byteOffset, element.byteOffset + element.byteLength));
|
||
} else if (element instanceof ArrayBuffer) {
|
||
part = new Uint8Array(element.slice(0));
|
||
} else if (element instanceof Blob) {
|
||
part = element;
|
||
} else {
|
||
part = encoder.encode(`${element}`);
|
||
}
|
||
this.#size += ArrayBuffer.isView(part) ? part.byteLength : part.size;
|
||
this.#parts.push(part);
|
||
}
|
||
this.#endings = `${options.endings === void 0 ? "transparent" : options.endings}`;
|
||
const type = options.type === void 0 ? "" : String(options.type);
|
||
this.#type = /^[\x20-\x7E]*$/.test(type) ? type : "";
|
||
}
|
||
/**
|
||
* The Blob interface's size property returns the
|
||
* size of the Blob in bytes.
|
||
*/
|
||
get size() {
|
||
return this.#size;
|
||
}
|
||
/**
|
||
* The type property of a Blob object returns the MIME type of the file.
|
||
*/
|
||
get type() {
|
||
return this.#type;
|
||
}
|
||
/**
|
||
* The text() method in the Blob interface returns a Promise
|
||
* that resolves with a string containing the contents of
|
||
* the blob, interpreted as UTF-8.
|
||
*
|
||
* @return {Promise<string>}
|
||
*/
|
||
async text() {
|
||
const decoder = new TextDecoder();
|
||
let str = "";
|
||
for await (const part of toIterator(this.#parts, false)) {
|
||
str += decoder.decode(part, { stream: true });
|
||
}
|
||
str += decoder.decode();
|
||
return str;
|
||
}
|
||
/**
|
||
* The arrayBuffer() method in the Blob interface returns a
|
||
* Promise that resolves with the contents of the blob as
|
||
* binary data contained in an ArrayBuffer.
|
||
*
|
||
* @return {Promise<ArrayBuffer>}
|
||
*/
|
||
async arrayBuffer() {
|
||
const data = new Uint8Array(this.size);
|
||
let offset = 0;
|
||
for await (const chunk of toIterator(this.#parts, false)) {
|
||
data.set(chunk, offset);
|
||
offset += chunk.length;
|
||
}
|
||
return data.buffer;
|
||
}
|
||
stream() {
|
||
const it = toIterator(this.#parts, true);
|
||
return new globalThis.ReadableStream({
|
||
// @ts-ignore
|
||
type: "bytes",
|
||
async pull(ctrl) {
|
||
const chunk = await it.next();
|
||
chunk.done ? ctrl.close() : ctrl.enqueue(chunk.value);
|
||
},
|
||
async cancel() {
|
||
await it.return();
|
||
}
|
||
});
|
||
}
|
||
/**
|
||
* The Blob interface's slice() method creates and returns a
|
||
* new Blob object which contains data from a subset of the
|
||
* blob on which it's called.
|
||
*
|
||
* @param {number} [start]
|
||
* @param {number} [end]
|
||
* @param {string} [type]
|
||
*/
|
||
slice(start = 0, end = this.size, type = "") {
|
||
const { size } = this;
|
||
let relativeStart = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);
|
||
let relativeEnd = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);
|
||
const span = Math.max(relativeEnd - relativeStart, 0);
|
||
const parts = this.#parts;
|
||
const blobParts = [];
|
||
let added = 0;
|
||
for (const part of parts) {
|
||
if (added >= span) {
|
||
break;
|
||
}
|
||
const size2 = ArrayBuffer.isView(part) ? part.byteLength : part.size;
|
||
if (relativeStart && size2 <= relativeStart) {
|
||
relativeStart -= size2;
|
||
relativeEnd -= size2;
|
||
} else {
|
||
let chunk;
|
||
if (ArrayBuffer.isView(part)) {
|
||
chunk = part.subarray(relativeStart, Math.min(size2, relativeEnd));
|
||
added += chunk.byteLength;
|
||
} else {
|
||
chunk = part.slice(relativeStart, Math.min(size2, relativeEnd));
|
||
added += chunk.size;
|
||
}
|
||
relativeEnd -= size2;
|
||
blobParts.push(chunk);
|
||
relativeStart = 0;
|
||
}
|
||
}
|
||
const blob = new Blob([], { type: String(type).toLowerCase() });
|
||
blob.#size = span;
|
||
blob.#parts = blobParts;
|
||
return blob;
|
||
}
|
||
get [Symbol.toStringTag]() {
|
||
return "Blob";
|
||
}
|
||
static [Symbol.hasInstance](object) {
|
||
return object && typeof object === "object" && typeof object.constructor === "function" && (typeof object.stream === "function" || typeof object.arrayBuffer === "function") && /^(Blob|File)$/.test(object[Symbol.toStringTag]);
|
||
}
|
||
};
|
||
Object.defineProperties(_Blob.prototype, {
|
||
size: { enumerable: true },
|
||
type: { enumerable: true },
|
||
slice: { enumerable: true }
|
||
});
|
||
Blob2 = _Blob;
|
||
fetch_blob_default = Blob2;
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/file.js
|
||
var _File, File2, file_default;
|
||
var init_file = __esm({
|
||
"../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/file.js"() {
|
||
init_fetch_blob();
|
||
_File = class File extends fetch_blob_default {
|
||
#lastModified = 0;
|
||
#name = "";
|
||
/**
|
||
* @param {*[]} fileBits
|
||
* @param {string} fileName
|
||
* @param {{lastModified?: number, type?: string}} options
|
||
*/
|
||
// @ts-ignore
|
||
constructor(fileBits, fileName, options = {}) {
|
||
if (arguments.length < 2) {
|
||
throw new TypeError(`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`);
|
||
}
|
||
super(fileBits, options);
|
||
if (options === null) options = {};
|
||
const lastModified = options.lastModified === void 0 ? Date.now() : Number(options.lastModified);
|
||
if (!Number.isNaN(lastModified)) {
|
||
this.#lastModified = lastModified;
|
||
}
|
||
this.#name = String(fileName);
|
||
}
|
||
get name() {
|
||
return this.#name;
|
||
}
|
||
get lastModified() {
|
||
return this.#lastModified;
|
||
}
|
||
get [Symbol.toStringTag]() {
|
||
return "File";
|
||
}
|
||
static [Symbol.hasInstance](object) {
|
||
return !!object && object instanceof fetch_blob_default && /^(File)$/.test(object[Symbol.toStringTag]);
|
||
}
|
||
};
|
||
File2 = _File;
|
||
file_default = File2;
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/formdata-polyfill@4.0.10/node_modules/formdata-polyfill/esm.min.js
|
||
function formDataToBlob(F2, B = fetch_blob_default) {
|
||
var b = `${r()}${r()}`.replace(/\./g, "").slice(-28).padStart(32, "-"), c = [], p = `--${b}\r
|
||
Content-Disposition: form-data; name="`;
|
||
F2.forEach((v, n) => typeof v == "string" ? c.push(p + e(n) + `"\r
|
||
\r
|
||
${v.replace(/\r(?!\n)|(?<!\r)\n/g, "\r\n")}\r
|
||
`) : c.push(p + e(n) + `"; filename="${e(v.name, 1)}"\r
|
||
Content-Type: ${v.type || "application/octet-stream"}\r
|
||
\r
|
||
`, v, "\r\n"));
|
||
c.push(`--${b}--`);
|
||
return new B(c, { type: "multipart/form-data; boundary=" + b });
|
||
}
|
||
var t, i, h, r, m, f, e, x, FormData;
|
||
var init_esm_min = __esm({
|
||
"../../node_modules/.pnpm/formdata-polyfill@4.0.10/node_modules/formdata-polyfill/esm.min.js"() {
|
||
init_fetch_blob();
|
||
init_file();
|
||
({ toStringTag: t, iterator: i, hasInstance: h } = Symbol);
|
||
r = Math.random;
|
||
m = "append,set,get,getAll,delete,keys,values,entries,forEach,constructor".split(",");
|
||
f = (a, b, c) => (a += "", /^(Blob|File)$/.test(b && b[t]) ? [(c = c !== void 0 ? c + "" : b[t] == "File" ? b.name : "blob", a), b.name !== c || b[t] == "blob" ? new file_default([b], c, b) : b] : [a, b + ""]);
|
||
e = (c, f3) => (f3 ? c : c.replace(/\r?\n|\r/g, "\r\n")).replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
|
||
x = (n, a, e2) => {
|
||
if (a.length < e2) {
|
||
throw new TypeError(`Failed to execute '${n}' on 'FormData': ${e2} arguments required, but only ${a.length} present.`);
|
||
}
|
||
};
|
||
FormData = class FormData2 {
|
||
#d = [];
|
||
constructor(...a) {
|
||
if (a.length) throw new TypeError(`Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.`);
|
||
}
|
||
get [t]() {
|
||
return "FormData";
|
||
}
|
||
[i]() {
|
||
return this.entries();
|
||
}
|
||
static [h](o) {
|
||
return o && typeof o === "object" && o[t] === "FormData" && !m.some((m2) => typeof o[m2] != "function");
|
||
}
|
||
append(...a) {
|
||
x("append", arguments, 2);
|
||
this.#d.push(f(...a));
|
||
}
|
||
delete(a) {
|
||
x("delete", arguments, 1);
|
||
a += "";
|
||
this.#d = this.#d.filter(([b]) => b !== a);
|
||
}
|
||
get(a) {
|
||
x("get", arguments, 1);
|
||
a += "";
|
||
for (var b = this.#d, l = b.length, c = 0; c < l; c++) if (b[c][0] === a) return b[c][1];
|
||
return null;
|
||
}
|
||
getAll(a, b) {
|
||
x("getAll", arguments, 1);
|
||
b = [];
|
||
a += "";
|
||
this.#d.forEach((c) => c[0] === a && b.push(c[1]));
|
||
return b;
|
||
}
|
||
has(a) {
|
||
x("has", arguments, 1);
|
||
a += "";
|
||
return this.#d.some((b) => b[0] === a);
|
||
}
|
||
forEach(a, b) {
|
||
x("forEach", arguments, 1);
|
||
for (var [c, d] of this) a.call(b, d, c, this);
|
||
}
|
||
set(...a) {
|
||
x("set", arguments, 2);
|
||
var b = [], c = true;
|
||
a = f(...a);
|
||
this.#d.forEach((d) => {
|
||
d[0] === a[0] ? c && (c = !b.push(a)) : b.push(d);
|
||
});
|
||
c && b.push(a);
|
||
this.#d = b;
|
||
}
|
||
*entries() {
|
||
yield* this.#d;
|
||
}
|
||
*keys() {
|
||
for (var [a] of this) yield a;
|
||
}
|
||
*values() {
|
||
for (var [, a] of this) yield a;
|
||
}
|
||
};
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/node-domexception@1.0.0/node_modules/node-domexception/index.js
|
||
var require_node_domexception = __commonJS({
|
||
"../../node_modules/.pnpm/node-domexception@1.0.0/node_modules/node-domexception/index.js"(exports2, module2) {
|
||
if (!globalThis.DOMException) {
|
||
try {
|
||
const { MessageChannel } = require("worker_threads"), port = new MessageChannel().port1, ab = new ArrayBuffer();
|
||
port.postMessage(ab, [ab, ab]);
|
||
} catch (err) {
|
||
err.constructor.name === "DOMException" && (globalThis.DOMException = err.constructor);
|
||
}
|
||
}
|
||
module2.exports = globalThis.DOMException;
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/from.js
|
||
var import_node_fs, import_node_domexception, stat;
|
||
var init_from = __esm({
|
||
"../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/from.js"() {
|
||
import_node_fs = require("node:fs");
|
||
import_node_domexception = __toESM(require_node_domexception(), 1);
|
||
init_file();
|
||
init_fetch_blob();
|
||
({ stat } = import_node_fs.promises);
|
||
}
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/multipart-parser.js
|
||
var multipart_parser_exports = {};
|
||
__export(multipart_parser_exports, {
|
||
toFormData: () => toFormData
|
||
});
|
||
function _fileName(headerValue) {
|
||
const m2 = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
|
||
if (!m2) {
|
||
return;
|
||
}
|
||
const match = m2[2] || m2[3] || "";
|
||
let filename = match.slice(match.lastIndexOf("\\") + 1);
|
||
filename = filename.replace(/%22/g, '"');
|
||
filename = filename.replace(/&#(\d{4});/g, (m3, code) => {
|
||
return String.fromCharCode(code);
|
||
});
|
||
return filename;
|
||
}
|
||
async function toFormData(Body2, ct) {
|
||
if (!/multipart/i.test(ct)) {
|
||
throw new TypeError("Failed to fetch");
|
||
}
|
||
const m2 = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
||
if (!m2) {
|
||
throw new TypeError("no or bad content-type header, no multipart boundary");
|
||
}
|
||
const parser = new MultipartParser(m2[1] || m2[2]);
|
||
let headerField;
|
||
let headerValue;
|
||
let entryValue;
|
||
let entryName;
|
||
let contentType;
|
||
let filename;
|
||
const entryChunks = [];
|
||
const formData = new FormData();
|
||
const onPartData = (ui8a) => {
|
||
entryValue += decoder.decode(ui8a, { stream: true });
|
||
};
|
||
const appendToFile = (ui8a) => {
|
||
entryChunks.push(ui8a);
|
||
};
|
||
const appendFileToFormData = () => {
|
||
const file = new file_default(entryChunks, filename, { type: contentType });
|
||
formData.append(entryName, file);
|
||
};
|
||
const appendEntryToFormData = () => {
|
||
formData.append(entryName, entryValue);
|
||
};
|
||
const decoder = new TextDecoder("utf-8");
|
||
decoder.decode();
|
||
parser.onPartBegin = function() {
|
||
parser.onPartData = onPartData;
|
||
parser.onPartEnd = appendEntryToFormData;
|
||
headerField = "";
|
||
headerValue = "";
|
||
entryValue = "";
|
||
entryName = "";
|
||
contentType = "";
|
||
filename = null;
|
||
entryChunks.length = 0;
|
||
};
|
||
parser.onHeaderField = function(ui8a) {
|
||
headerField += decoder.decode(ui8a, { stream: true });
|
||
};
|
||
parser.onHeaderValue = function(ui8a) {
|
||
headerValue += decoder.decode(ui8a, { stream: true });
|
||
};
|
||
parser.onHeaderEnd = function() {
|
||
headerValue += decoder.decode();
|
||
headerField = headerField.toLowerCase();
|
||
if (headerField === "content-disposition") {
|
||
const m3 = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
|
||
if (m3) {
|
||
entryName = m3[2] || m3[3] || "";
|
||
}
|
||
filename = _fileName(headerValue);
|
||
if (filename) {
|
||
parser.onPartData = appendToFile;
|
||
parser.onPartEnd = appendFileToFormData;
|
||
}
|
||
} else if (headerField === "content-type") {
|
||
contentType = headerValue;
|
||
}
|
||
headerValue = "";
|
||
headerField = "";
|
||
};
|
||
for await (const chunk of Body2) {
|
||
parser.write(chunk);
|
||
}
|
||
parser.end();
|
||
return formData;
|
||
}
|
||
var s, S, f2, F, LF, CR, SPACE, HYPHEN, COLON, A, Z, lower, noop, MultipartParser;
|
||
var init_multipart_parser = __esm({
|
||
"../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/multipart-parser.js"() {
|
||
init_from();
|
||
init_esm_min();
|
||
s = 0;
|
||
S = {
|
||
START_BOUNDARY: s++,
|
||
HEADER_FIELD_START: s++,
|
||
HEADER_FIELD: s++,
|
||
HEADER_VALUE_START: s++,
|
||
HEADER_VALUE: s++,
|
||
HEADER_VALUE_ALMOST_DONE: s++,
|
||
HEADERS_ALMOST_DONE: s++,
|
||
PART_DATA_START: s++,
|
||
PART_DATA: s++,
|
||
END: s++
|
||
};
|
||
f2 = 1;
|
||
F = {
|
||
PART_BOUNDARY: f2,
|
||
LAST_BOUNDARY: f2 *= 2
|
||
};
|
||
LF = 10;
|
||
CR = 13;
|
||
SPACE = 32;
|
||
HYPHEN = 45;
|
||
COLON = 58;
|
||
A = 97;
|
||
Z = 122;
|
||
lower = (c) => c | 32;
|
||
noop = () => {
|
||
};
|
||
MultipartParser = class {
|
||
/**
|
||
* @param {string} boundary
|
||
*/
|
||
constructor(boundary) {
|
||
this.index = 0;
|
||
this.flags = 0;
|
||
this.onHeaderEnd = noop;
|
||
this.onHeaderField = noop;
|
||
this.onHeadersEnd = noop;
|
||
this.onHeaderValue = noop;
|
||
this.onPartBegin = noop;
|
||
this.onPartData = noop;
|
||
this.onPartEnd = noop;
|
||
this.boundaryChars = {};
|
||
boundary = "\r\n--" + boundary;
|
||
const ui8a = new Uint8Array(boundary.length);
|
||
for (let i2 = 0; i2 < boundary.length; i2++) {
|
||
ui8a[i2] = boundary.charCodeAt(i2);
|
||
this.boundaryChars[ui8a[i2]] = true;
|
||
}
|
||
this.boundary = ui8a;
|
||
this.lookbehind = new Uint8Array(this.boundary.length + 8);
|
||
this.state = S.START_BOUNDARY;
|
||
}
|
||
/**
|
||
* @param {Uint8Array} data
|
||
*/
|
||
write(data) {
|
||
let i2 = 0;
|
||
const length_ = data.length;
|
||
let previousIndex = this.index;
|
||
let { lookbehind, boundary, boundaryChars, index, state, flags } = this;
|
||
const boundaryLength = this.boundary.length;
|
||
const boundaryEnd = boundaryLength - 1;
|
||
const bufferLength = data.length;
|
||
let c;
|
||
let cl;
|
||
const mark = (name) => {
|
||
this[name + "Mark"] = i2;
|
||
};
|
||
const clear = (name) => {
|
||
delete this[name + "Mark"];
|
||
};
|
||
const callback = (callbackSymbol, start, end, ui8a) => {
|
||
if (start === void 0 || start !== end) {
|
||
this[callbackSymbol](ui8a && ui8a.subarray(start, end));
|
||
}
|
||
};
|
||
const dataCallback = (name, clear2) => {
|
||
const markSymbol = name + "Mark";
|
||
if (!(markSymbol in this)) {
|
||
return;
|
||
}
|
||
if (clear2) {
|
||
callback(name, this[markSymbol], i2, data);
|
||
delete this[markSymbol];
|
||
} else {
|
||
callback(name, this[markSymbol], data.length, data);
|
||
this[markSymbol] = 0;
|
||
}
|
||
};
|
||
for (i2 = 0; i2 < length_; i2++) {
|
||
c = data[i2];
|
||
switch (state) {
|
||
case S.START_BOUNDARY:
|
||
if (index === boundary.length - 2) {
|
||
if (c === HYPHEN) {
|
||
flags |= F.LAST_BOUNDARY;
|
||
} else if (c !== CR) {
|
||
return;
|
||
}
|
||
index++;
|
||
break;
|
||
} else if (index - 1 === boundary.length - 2) {
|
||
if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
|
||
state = S.END;
|
||
flags = 0;
|
||
} else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
|
||
index = 0;
|
||
callback("onPartBegin");
|
||
state = S.HEADER_FIELD_START;
|
||
} else {
|
||
return;
|
||
}
|
||
break;
|
||
}
|
||
if (c !== boundary[index + 2]) {
|
||
index = -2;
|
||
}
|
||
if (c === boundary[index + 2]) {
|
||
index++;
|
||
}
|
||
break;
|
||
case S.HEADER_FIELD_START:
|
||
state = S.HEADER_FIELD;
|
||
mark("onHeaderField");
|
||
index = 0;
|
||
// falls through
|
||
case S.HEADER_FIELD:
|
||
if (c === CR) {
|
||
clear("onHeaderField");
|
||
state = S.HEADERS_ALMOST_DONE;
|
||
break;
|
||
}
|
||
index++;
|
||
if (c === HYPHEN) {
|
||
break;
|
||
}
|
||
if (c === COLON) {
|
||
if (index === 1) {
|
||
return;
|
||
}
|
||
dataCallback("onHeaderField", true);
|
||
state = S.HEADER_VALUE_START;
|
||
break;
|
||
}
|
||
cl = lower(c);
|
||
if (cl < A || cl > Z) {
|
||
return;
|
||
}
|
||
break;
|
||
case S.HEADER_VALUE_START:
|
||
if (c === SPACE) {
|
||
break;
|
||
}
|
||
mark("onHeaderValue");
|
||
state = S.HEADER_VALUE;
|
||
// falls through
|
||
case S.HEADER_VALUE:
|
||
if (c === CR) {
|
||
dataCallback("onHeaderValue", true);
|
||
callback("onHeaderEnd");
|
||
state = S.HEADER_VALUE_ALMOST_DONE;
|
||
}
|
||
break;
|
||
case S.HEADER_VALUE_ALMOST_DONE:
|
||
if (c !== LF) {
|
||
return;
|
||
}
|
||
state = S.HEADER_FIELD_START;
|
||
break;
|
||
case S.HEADERS_ALMOST_DONE:
|
||
if (c !== LF) {
|
||
return;
|
||
}
|
||
callback("onHeadersEnd");
|
||
state = S.PART_DATA_START;
|
||
break;
|
||
case S.PART_DATA_START:
|
||
state = S.PART_DATA;
|
||
mark("onPartData");
|
||
// falls through
|
||
case S.PART_DATA:
|
||
previousIndex = index;
|
||
if (index === 0) {
|
||
i2 += boundaryEnd;
|
||
while (i2 < bufferLength && !(data[i2] in boundaryChars)) {
|
||
i2 += boundaryLength;
|
||
}
|
||
i2 -= boundaryEnd;
|
||
c = data[i2];
|
||
}
|
||
if (index < boundary.length) {
|
||
if (boundary[index] === c) {
|
||
if (index === 0) {
|
||
dataCallback("onPartData", true);
|
||
}
|
||
index++;
|
||
} else {
|
||
index = 0;
|
||
}
|
||
} else if (index === boundary.length) {
|
||
index++;
|
||
if (c === CR) {
|
||
flags |= F.PART_BOUNDARY;
|
||
} else if (c === HYPHEN) {
|
||
flags |= F.LAST_BOUNDARY;
|
||
} else {
|
||
index = 0;
|
||
}
|
||
} else if (index - 1 === boundary.length) {
|
||
if (flags & F.PART_BOUNDARY) {
|
||
index = 0;
|
||
if (c === LF) {
|
||
flags &= ~F.PART_BOUNDARY;
|
||
callback("onPartEnd");
|
||
callback("onPartBegin");
|
||
state = S.HEADER_FIELD_START;
|
||
break;
|
||
}
|
||
} else if (flags & F.LAST_BOUNDARY) {
|
||
if (c === HYPHEN) {
|
||
callback("onPartEnd");
|
||
state = S.END;
|
||
flags = 0;
|
||
} else {
|
||
index = 0;
|
||
}
|
||
} else {
|
||
index = 0;
|
||
}
|
||
}
|
||
if (index > 0) {
|
||
lookbehind[index - 1] = c;
|
||
} else if (previousIndex > 0) {
|
||
const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
|
||
callback("onPartData", 0, previousIndex, _lookbehind);
|
||
previousIndex = 0;
|
||
mark("onPartData");
|
||
i2--;
|
||
}
|
||
break;
|
||
case S.END:
|
||
break;
|
||
default:
|
||
throw new Error(`Unexpected state entered: ${state}`);
|
||
}
|
||
}
|
||
dataCallback("onHeaderField");
|
||
dataCallback("onHeaderValue");
|
||
dataCallback("onPartData");
|
||
this.index = index;
|
||
this.state = state;
|
||
this.flags = flags;
|
||
}
|
||
end() {
|
||
if (this.state === S.HEADER_FIELD_START && this.index === 0 || this.state === S.PART_DATA && this.index === this.boundary.length) {
|
||
this.onPartEnd();
|
||
} else if (this.state !== S.END) {
|
||
throw new Error("MultipartParser.end(): stream ended unexpectedly");
|
||
}
|
||
}
|
||
};
|
||
}
|
||
});
|
||
|
||
// ../../packages/common/src/bridge.ts
|
||
function saltyChatExport(method, cb) {
|
||
on(`__cfx_export_saltychat_${method}`, (setCb) => {
|
||
setCb(cb);
|
||
});
|
||
}
|
||
|
||
// ../../packages/common/src/config.ts
|
||
var import_json5 = __toESM(require_lib());
|
||
function mergeAndValidate(defaultObj, parsedObj, path = []) {
|
||
const result = { ...defaultObj };
|
||
for (const key in defaultObj) {
|
||
if (Object.prototype.hasOwnProperty.call(defaultObj, key) === false) {
|
||
continue;
|
||
}
|
||
const currentPath = [...path, key].join(".");
|
||
if (!(key in parsedObj)) {
|
||
console.warn(
|
||
`[YaCA] Missing config value for key '${currentPath}' setting to default value: ${defaultObj[key]}
|
||
Missing config values can cause unexpected behavior of the script.`
|
||
);
|
||
} else if (typeof defaultObj[key] === "object" && defaultObj[key] !== null && !Array.isArray(defaultObj[key]) && typeof parsedObj[key] === "object" && parsedObj[key] !== null && !Array.isArray(parsedObj[key])) {
|
||
result[key] = mergeAndValidate(defaultObj[key], parsedObj[key], [...path, key]);
|
||
} else {
|
||
result[key] = parsedObj[key];
|
||
}
|
||
}
|
||
for (const key of Object.keys(parsedObj)) {
|
||
const currentPath = [...path, key].join(".");
|
||
if (!(key in defaultObj)) {
|
||
console.warn(`[YaCA] Unknown config key '${currentPath}' found in config file. This key will be ignored and can be removed.`);
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
function loadConfig(filePath, defaultValues) {
|
||
const fileData = LoadResourceFile(GetCurrentResourceName(), filePath);
|
||
if (!fileData) {
|
||
return defaultValues;
|
||
}
|
||
const parsedData = import_json5.default.parse(fileData);
|
||
return mergeAndValidate(defaultValues, parsedData);
|
||
}
|
||
|
||
// ../../packages/common/src/constants.ts
|
||
var MEGAPHONE_STATE_NAME = "yacaMegaphone";
|
||
var PHONE_SPEAKER_STATE_NAME = "yacaPhoneSpeaker";
|
||
var VOICE_RANGE_STATE_NAME = "yacaVoiceRange";
|
||
var GLOBAL_ERROR_LEVEL_STATE_NAME = "yacaGlobalErrorLevel";
|
||
|
||
// ../../packages/common/src/errorlevel.ts
|
||
var setGlobalErrorLevel = (errorLevel) => {
|
||
GlobalState.set(GLOBAL_ERROR_LEVEL_STATE_NAME, clamp(errorLevel, 0, 1), true);
|
||
};
|
||
var getGlobalErrorLevel = () => {
|
||
return GlobalState[GLOBAL_ERROR_LEVEL_STATE_NAME] ?? 0;
|
||
};
|
||
|
||
// ../../packages/common/src/locale.ts
|
||
var import_fast_printf = __toESM(require_printf());
|
||
var resourceName = GetCurrentResourceName();
|
||
var dict = {};
|
||
function flattenDict(source2, target, prefix) {
|
||
for (const [key, value] of Object.entries(source2)) {
|
||
const fullKey = prefix ? `${prefix}.${key}` : key;
|
||
if (typeof value === "object") flattenDict(value, target, fullKey);
|
||
else target[fullKey] = String(value);
|
||
}
|
||
return target;
|
||
}
|
||
var locale = (str, ...args) => {
|
||
const localeStr = dict[str];
|
||
if (localeStr) {
|
||
if (args.length > 0) {
|
||
return (0, import_fast_printf.printf)(localeStr, ...args);
|
||
}
|
||
return localeStr;
|
||
}
|
||
return str;
|
||
};
|
||
var initLocale = (configLocale) => {
|
||
const lang = configLocale || "en";
|
||
let locales = JSON.parse(LoadResourceFile(resourceName, `locales/${lang}.json`));
|
||
if (!locales) {
|
||
console.warn(`could not load 'locales/${lang}.json'`);
|
||
if (lang !== "en") {
|
||
locales = JSON.parse(LoadResourceFile(resourceName, "locales/en.json"));
|
||
if (!locales) {
|
||
console.warn("could not load 'locales/en.json'");
|
||
}
|
||
}
|
||
if (!locales) return;
|
||
}
|
||
const flattened = flattenDict(locales, {});
|
||
for (const [k, v] of Object.entries(flattened)) {
|
||
const regExp = new RegExp(/\$\{([^}]+)}/g);
|
||
const matches = v.match(regExp);
|
||
if (matches) {
|
||
for (const match of matches) {
|
||
if (!match) break;
|
||
const variable = match.substring(2, match.length - 1);
|
||
const locale2 = flattened[variable];
|
||
if (locale2) {
|
||
flattened[k] = v.replace(match, locale2);
|
||
}
|
||
}
|
||
}
|
||
dict[k] = v;
|
||
}
|
||
};
|
||
|
||
// ../../packages/common/src/index.ts
|
||
function clamp(value, min = 0, max = 1) {
|
||
return Math.max(min, Math.min(max, value));
|
||
}
|
||
|
||
// ../../packages/types/src/config.ts
|
||
var defaultSharedConfig = {
|
||
versionCheck: true,
|
||
autoConnectOnJoin: true,
|
||
buildType: 0 /* RELEASE */,
|
||
locale: "en",
|
||
unmuteDelay: 400,
|
||
maxPhoneSpeakerRange: 5,
|
||
phoneHearPlayersNearby: false,
|
||
notifications: {
|
||
oxLib: false,
|
||
okoknotify: false,
|
||
gta: true,
|
||
redm: false,
|
||
own: false
|
||
},
|
||
keyBinds: {
|
||
increaseVoiceRange: "ADD",
|
||
decreaseVoiceRange: "SUBTRACT",
|
||
primaryRadioTransmit: "N",
|
||
secondaryRadioTransmit: "CAPITAL",
|
||
megaphone: "B",
|
||
voiceRangeWithMouseWheel: "LCONTROL"
|
||
},
|
||
radioSettings: {
|
||
animation: {
|
||
dictionary: "random@arrests",
|
||
name: "generic_radio_chatter",
|
||
flag: 49
|
||
},
|
||
propWhileTalking: {
|
||
prop: false,
|
||
boneId: 28422,
|
||
position: [0, 0, 0],
|
||
rotation: [0, 0, 0]
|
||
},
|
||
channelCount: 9,
|
||
mode: "None",
|
||
maxDistance: 1e3
|
||
},
|
||
voiceRange: {
|
||
defaultIndex: 1,
|
||
ranges: [1, 3, 8, 15, 20, 25, 30, 40],
|
||
sendNotification: true,
|
||
markerColor: {
|
||
enabled: true,
|
||
r: 0,
|
||
g: 255,
|
||
b: 0,
|
||
a: 50,
|
||
duration: 1e3,
|
||
type: 1,
|
||
rotate: true
|
||
}
|
||
},
|
||
megaphone: {
|
||
range: 30,
|
||
automaticVehicleDetection: true,
|
||
allowedVehicleClasses: [18, 19],
|
||
allowedVehicleModels: ["polmav"]
|
||
},
|
||
saltyChatBridge: false,
|
||
mufflingSettings: {
|
||
mufflingRange: -1,
|
||
vehicleMuffling: {
|
||
enabled: true,
|
||
vehicleWhitelist: [
|
||
"gauntlet6",
|
||
"draugur",
|
||
"bodhi2",
|
||
"vagrant",
|
||
"outlaw",
|
||
"trophytruck",
|
||
"ratel",
|
||
"drifttampa",
|
||
"sm722",
|
||
"tornado4",
|
||
"swinger",
|
||
"locust",
|
||
"hotring"
|
||
]
|
||
},
|
||
intensities: {
|
||
differentRoom: 10,
|
||
bothCarsClosed: 10,
|
||
oneCarClosed: 6,
|
||
megaPhoneInCar: 6
|
||
}
|
||
},
|
||
radioAntiSpamCooldown: false,
|
||
useLocalLipSync: false
|
||
};
|
||
var defaultServerConfig = {
|
||
uniqueServerId: "",
|
||
ingameChannelId: 3,
|
||
ingameChannelPassword: "",
|
||
defaultChannelId: 1,
|
||
useWhisper: false,
|
||
excludeChannels: [],
|
||
userNamePattern: "[{serverid}] {guid}"
|
||
};
|
||
var defaultTowerConfig = {
|
||
towerPositions: [
|
||
[2572, 5397, 56],
|
||
[2663, 4972, 56],
|
||
[2892, 3911, 56],
|
||
[2720, 3304, 64],
|
||
[2388, 2949, 64],
|
||
[1830, 2368, 64],
|
||
[1650, 1316, 102],
|
||
[1363, 680, 102],
|
||
[918, 230, 92],
|
||
[567, 303, 58],
|
||
[-47, -666, 74],
|
||
[-585, -902, 53],
|
||
[2572, 5397, 56],
|
||
[2338, 5940, 77],
|
||
[1916, 6244, 65],
|
||
[1591, 6371, 42],
|
||
[953, 6504, 42],
|
||
[76, 6606, 42],
|
||
[408, 6587, 42],
|
||
[-338, -579, 48],
|
||
[-293, -632, 47],
|
||
[-269, -962, 143],
|
||
[98, -870, 136],
|
||
[-214, -744, 219],
|
||
[-166, -590, 199],
|
||
[124, -654, 261],
|
||
[149, -769, 261],
|
||
[580, 89, 117],
|
||
[423, 15, 151],
|
||
[424, 18, 151],
|
||
[551, -28, 93],
|
||
[305, -284, 68],
|
||
[299, -313, 68],
|
||
[1240, -1090, 44],
|
||
[-418, -2804, 14],
|
||
[802, -2996, 27],
|
||
[253, -3145, 39],
|
||
[207, -3145, 39],
|
||
[207, -3307, 39],
|
||
[247, -3307, 39],
|
||
[484, -2178, 40],
|
||
[548, -2219, 67],
|
||
[-701, 58, 68],
|
||
[-696, 208, 139],
|
||
[-769, 255, 134],
|
||
[-150, -150, 96],
|
||
[-202, -327, 65],
|
||
[-1913, -3031, 22],
|
||
[-1918, -3028, 22],
|
||
[-1039, -2385, 27],
|
||
[-1042, -2390, 27],
|
||
[-1583, -3216, 28],
|
||
[-1590, -3212, 28],
|
||
[-1308, -2626, 36],
|
||
[-1311, -2624, 36],
|
||
[-984, -2778, 48],
|
||
[-991, -2774, 48],
|
||
[-556, -119, 50],
|
||
[-619, -106, 51],
|
||
[-1167, -575, 40],
|
||
[-1152, -443, 42],
|
||
[-1156, -498, 49],
|
||
[-1290, -445, 106],
|
||
[-928, -383, 135],
|
||
[-902, -443, 170],
|
||
[-770, -786, 83],
|
||
[-824, -719, 120],
|
||
[-598, -917, 35],
|
||
[-678, -717, 54],
|
||
[-669, -804, 31],
|
||
[-1463, -526, 83],
|
||
[-1525, -596, 66],
|
||
[-1375, -465, 83],
|
||
[-1711, 478, 127],
|
||
[-2311, 335, 187],
|
||
[-2214, 342, 198],
|
||
[-2234, 187, 193],
|
||
[202, 1204, 230],
|
||
[217, 1140, 230],
|
||
[668, 590, 136],
|
||
[722, 562, 134],
|
||
[838, 510, 138],
|
||
[773, 575, 138],
|
||
[735, 231, 145],
|
||
[450, 5566, 795],
|
||
[-449, 6019, 35],
|
||
[-142, 6286, 39],
|
||
[-368, 6105, 38],
|
||
[2792, 5996, 355],
|
||
[2796, 5992, 354],
|
||
[3460, 3653, 51],
|
||
[3459, 3659, 51],
|
||
[3615, 3642, 51],
|
||
[3614, 3636, 51],
|
||
[-2180, 3252, 54],
|
||
[-2124, 3219, 54],
|
||
[-2050, 3178, 54],
|
||
[1858, 3694, 37],
|
||
[1695, 3614, 37],
|
||
[1692, 2532, 60],
|
||
[1692, 2647, 60],
|
||
[1824, 2574, 60],
|
||
[1407, 2117, 104]
|
||
]
|
||
};
|
||
|
||
// src/utils/cache.ts
|
||
var cache = {
|
||
resource: GetCurrentResourceName()
|
||
};
|
||
|
||
// src/utils/events.ts
|
||
var triggerClientEvent = (eventName, targetIds, ...args) => {
|
||
if (!Array.isArray(targetIds)) {
|
||
targetIds = [targetIds];
|
||
}
|
||
if (targetIds.length < 1) {
|
||
return;
|
||
}
|
||
const dataSerialized = msgpack_pack(args);
|
||
for (const targetId of targetIds) {
|
||
TriggerClientEventInternal(eventName, targetId.toString(), dataSerialized, dataSerialized.length);
|
||
}
|
||
};
|
||
|
||
// src/utils/generator.ts
|
||
var import_node_crypto = require("node:crypto");
|
||
function generateRandomName(src, nameSet, namePattern) {
|
||
let name;
|
||
const playerName = GetPlayerName(src.toString());
|
||
for (let i2 = 0; i2 < 10; i2++) {
|
||
let generatedName = namePattern;
|
||
generatedName = generatedName.replace("{serverid}", src.toString());
|
||
generatedName = generatedName.replace("{playername}", playerName);
|
||
generatedName = generatedName.replace("{guid}", (0, import_node_crypto.randomUUID)().replace(/-/g, ""));
|
||
generatedName = generatedName.slice(0, 30);
|
||
if (!nameSet.has(generatedName)) {
|
||
name = generatedName;
|
||
nameSet.add(generatedName);
|
||
break;
|
||
}
|
||
}
|
||
if (!name) {
|
||
console.error(`YaCA: Couldn't generate a random name for player ${playerName} (ID: ${src}).`);
|
||
}
|
||
return name;
|
||
}
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/index.js
|
||
var import_node_http2 = __toESM(require("node:http"), 1);
|
||
var import_node_https = __toESM(require("node:https"), 1);
|
||
var import_node_zlib = __toESM(require("node:zlib"), 1);
|
||
var import_node_stream2 = __toESM(require("node:stream"), 1);
|
||
var import_node_buffer2 = require("node:buffer");
|
||
|
||
// ../../node_modules/.pnpm/data-uri-to-buffer@4.0.1/node_modules/data-uri-to-buffer/dist/index.js
|
||
function dataUriToBuffer(uri) {
|
||
if (!/^data:/i.test(uri)) {
|
||
throw new TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');
|
||
}
|
||
uri = uri.replace(/\r?\n/g, "");
|
||
const firstComma = uri.indexOf(",");
|
||
if (firstComma === -1 || firstComma <= 4) {
|
||
throw new TypeError("malformed data: URI");
|
||
}
|
||
const meta = uri.substring(5, firstComma).split(";");
|
||
let charset = "";
|
||
let base64 = false;
|
||
const type = meta[0] || "text/plain";
|
||
let typeFull = type;
|
||
for (let i2 = 1; i2 < meta.length; i2++) {
|
||
if (meta[i2] === "base64") {
|
||
base64 = true;
|
||
} else if (meta[i2]) {
|
||
typeFull += `;${meta[i2]}`;
|
||
if (meta[i2].indexOf("charset=") === 0) {
|
||
charset = meta[i2].substring(8);
|
||
}
|
||
}
|
||
}
|
||
if (!meta[0] && !charset.length) {
|
||
typeFull += ";charset=US-ASCII";
|
||
charset = "US-ASCII";
|
||
}
|
||
const encoding = base64 ? "base64" : "ascii";
|
||
const data = unescape(uri.substring(firstComma + 1));
|
||
const buffer = Buffer.from(data, encoding);
|
||
buffer.type = type;
|
||
buffer.typeFull = typeFull;
|
||
buffer.charset = charset;
|
||
return buffer;
|
||
}
|
||
var dist_default = dataUriToBuffer;
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/body.js
|
||
var import_node_stream = __toESM(require("node:stream"), 1);
|
||
var import_node_util = require("node:util");
|
||
var import_node_buffer = require("node:buffer");
|
||
init_fetch_blob();
|
||
init_esm_min();
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/errors/base.js
|
||
var FetchBaseError = class extends Error {
|
||
constructor(message, type) {
|
||
super(message);
|
||
Error.captureStackTrace(this, this.constructor);
|
||
this.type = type;
|
||
}
|
||
get name() {
|
||
return this.constructor.name;
|
||
}
|
||
get [Symbol.toStringTag]() {
|
||
return this.constructor.name;
|
||
}
|
||
};
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/errors/fetch-error.js
|
||
var FetchError = class extends FetchBaseError {
|
||
/**
|
||
* @param {string} message - Error message for human
|
||
* @param {string} [type] - Error type for machine
|
||
* @param {SystemError} [systemError] - For Node.js system error
|
||
*/
|
||
constructor(message, type, systemError) {
|
||
super(message, type);
|
||
if (systemError) {
|
||
this.code = this.errno = systemError.code;
|
||
this.erroredSysCall = systemError.syscall;
|
||
}
|
||
}
|
||
};
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/is.js
|
||
var NAME = Symbol.toStringTag;
|
||
var isURLSearchParameters = (object) => {
|
||
return typeof object === "object" && typeof object.append === "function" && typeof object.delete === "function" && typeof object.get === "function" && typeof object.getAll === "function" && typeof object.has === "function" && typeof object.set === "function" && typeof object.sort === "function" && object[NAME] === "URLSearchParams";
|
||
};
|
||
var isBlob = (object) => {
|
||
return object && typeof object === "object" && typeof object.arrayBuffer === "function" && typeof object.type === "string" && typeof object.stream === "function" && typeof object.constructor === "function" && /^(Blob|File)$/.test(object[NAME]);
|
||
};
|
||
var isAbortSignal = (object) => {
|
||
return typeof object === "object" && (object[NAME] === "AbortSignal" || object[NAME] === "EventTarget");
|
||
};
|
||
var isDomainOrSubdomain = (destination, original) => {
|
||
const orig = new URL(original).hostname;
|
||
const dest = new URL(destination).hostname;
|
||
return orig === dest || orig.endsWith(`.${dest}`);
|
||
};
|
||
var isSameProtocol = (destination, original) => {
|
||
const orig = new URL(original).protocol;
|
||
const dest = new URL(destination).protocol;
|
||
return orig === dest;
|
||
};
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/body.js
|
||
var pipeline = (0, import_node_util.promisify)(import_node_stream.default.pipeline);
|
||
var INTERNALS = Symbol("Body internals");
|
||
var Body = class {
|
||
constructor(body, {
|
||
size = 0
|
||
} = {}) {
|
||
let boundary = null;
|
||
if (body === null) {
|
||
body = null;
|
||
} else if (isURLSearchParameters(body)) {
|
||
body = import_node_buffer.Buffer.from(body.toString());
|
||
} else if (isBlob(body)) {
|
||
} else if (import_node_buffer.Buffer.isBuffer(body)) {
|
||
} else if (import_node_util.types.isAnyArrayBuffer(body)) {
|
||
body = import_node_buffer.Buffer.from(body);
|
||
} else if (ArrayBuffer.isView(body)) {
|
||
body = import_node_buffer.Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
||
} else if (body instanceof import_node_stream.default) {
|
||
} else if (body instanceof FormData) {
|
||
body = formDataToBlob(body);
|
||
boundary = body.type.split("=")[1];
|
||
} else {
|
||
body = import_node_buffer.Buffer.from(String(body));
|
||
}
|
||
let stream = body;
|
||
if (import_node_buffer.Buffer.isBuffer(body)) {
|
||
stream = import_node_stream.default.Readable.from(body);
|
||
} else if (isBlob(body)) {
|
||
stream = import_node_stream.default.Readable.from(body.stream());
|
||
}
|
||
this[INTERNALS] = {
|
||
body,
|
||
stream,
|
||
boundary,
|
||
disturbed: false,
|
||
error: null
|
||
};
|
||
this.size = size;
|
||
if (body instanceof import_node_stream.default) {
|
||
body.on("error", (error_) => {
|
||
const error = error_ instanceof FetchBaseError ? error_ : new FetchError(`Invalid response body while trying to fetch ${this.url}: ${error_.message}`, "system", error_);
|
||
this[INTERNALS].error = error;
|
||
});
|
||
}
|
||
}
|
||
get body() {
|
||
return this[INTERNALS].stream;
|
||
}
|
||
get bodyUsed() {
|
||
return this[INTERNALS].disturbed;
|
||
}
|
||
/**
|
||
* Decode response as ArrayBuffer
|
||
*
|
||
* @return Promise
|
||
*/
|
||
async arrayBuffer() {
|
||
const { buffer, byteOffset, byteLength } = await consumeBody(this);
|
||
return buffer.slice(byteOffset, byteOffset + byteLength);
|
||
}
|
||
async formData() {
|
||
const ct = this.headers.get("content-type");
|
||
if (ct.startsWith("application/x-www-form-urlencoded")) {
|
||
const formData = new FormData();
|
||
const parameters = new URLSearchParams(await this.text());
|
||
for (const [name, value] of parameters) {
|
||
formData.append(name, value);
|
||
}
|
||
return formData;
|
||
}
|
||
const { toFormData: toFormData2 } = await Promise.resolve().then(() => (init_multipart_parser(), multipart_parser_exports));
|
||
return toFormData2(this.body, ct);
|
||
}
|
||
/**
|
||
* Return raw response as Blob
|
||
*
|
||
* @return Promise
|
||
*/
|
||
async blob() {
|
||
const ct = this.headers && this.headers.get("content-type") || this[INTERNALS].body && this[INTERNALS].body.type || "";
|
||
const buf = await this.arrayBuffer();
|
||
return new fetch_blob_default([buf], {
|
||
type: ct
|
||
});
|
||
}
|
||
/**
|
||
* Decode response as json
|
||
*
|
||
* @return Promise
|
||
*/
|
||
async json() {
|
||
const text = await this.text();
|
||
return JSON.parse(text);
|
||
}
|
||
/**
|
||
* Decode response as text
|
||
*
|
||
* @return Promise
|
||
*/
|
||
async text() {
|
||
const buffer = await consumeBody(this);
|
||
return new TextDecoder().decode(buffer);
|
||
}
|
||
/**
|
||
* Decode response as buffer (non-spec api)
|
||
*
|
||
* @return Promise
|
||
*/
|
||
buffer() {
|
||
return consumeBody(this);
|
||
}
|
||
};
|
||
Body.prototype.buffer = (0, import_node_util.deprecate)(Body.prototype.buffer, "Please use 'response.arrayBuffer()' instead of 'response.buffer()'", "node-fetch#buffer");
|
||
Object.defineProperties(Body.prototype, {
|
||
body: { enumerable: true },
|
||
bodyUsed: { enumerable: true },
|
||
arrayBuffer: { enumerable: true },
|
||
blob: { enumerable: true },
|
||
json: { enumerable: true },
|
||
text: { enumerable: true },
|
||
data: { get: (0, import_node_util.deprecate)(
|
||
() => {
|
||
},
|
||
"data doesn't exist, use json(), text(), arrayBuffer(), or body instead",
|
||
"https://github.com/node-fetch/node-fetch/issues/1000 (response)"
|
||
) }
|
||
});
|
||
async function consumeBody(data) {
|
||
if (data[INTERNALS].disturbed) {
|
||
throw new TypeError(`body used already for: ${data.url}`);
|
||
}
|
||
data[INTERNALS].disturbed = true;
|
||
if (data[INTERNALS].error) {
|
||
throw data[INTERNALS].error;
|
||
}
|
||
const { body } = data;
|
||
if (body === null) {
|
||
return import_node_buffer.Buffer.alloc(0);
|
||
}
|
||
if (!(body instanceof import_node_stream.default)) {
|
||
return import_node_buffer.Buffer.alloc(0);
|
||
}
|
||
const accum = [];
|
||
let accumBytes = 0;
|
||
try {
|
||
for await (const chunk of body) {
|
||
if (data.size > 0 && accumBytes + chunk.length > data.size) {
|
||
const error = new FetchError(`content size at ${data.url} over limit: ${data.size}`, "max-size");
|
||
body.destroy(error);
|
||
throw error;
|
||
}
|
||
accumBytes += chunk.length;
|
||
accum.push(chunk);
|
||
}
|
||
} catch (error) {
|
||
const error_ = error instanceof FetchBaseError ? error : new FetchError(`Invalid response body while trying to fetch ${data.url}: ${error.message}`, "system", error);
|
||
throw error_;
|
||
}
|
||
if (body.readableEnded === true || body._readableState.ended === true) {
|
||
try {
|
||
if (accum.every((c) => typeof c === "string")) {
|
||
return import_node_buffer.Buffer.from(accum.join(""));
|
||
}
|
||
return import_node_buffer.Buffer.concat(accum, accumBytes);
|
||
} catch (error) {
|
||
throw new FetchError(`Could not create Buffer from response body for ${data.url}: ${error.message}`, "system", error);
|
||
}
|
||
} else {
|
||
throw new FetchError(`Premature close of server response while trying to fetch ${data.url}`);
|
||
}
|
||
}
|
||
var clone = (instance, highWaterMark) => {
|
||
let p1;
|
||
let p2;
|
||
let { body } = instance[INTERNALS];
|
||
if (instance.bodyUsed) {
|
||
throw new Error("cannot clone body after it is used");
|
||
}
|
||
if (body instanceof import_node_stream.default && typeof body.getBoundary !== "function") {
|
||
p1 = new import_node_stream.PassThrough({ highWaterMark });
|
||
p2 = new import_node_stream.PassThrough({ highWaterMark });
|
||
body.pipe(p1);
|
||
body.pipe(p2);
|
||
instance[INTERNALS].stream = p1;
|
||
body = p2;
|
||
}
|
||
return body;
|
||
};
|
||
var getNonSpecFormDataBoundary = (0, import_node_util.deprecate)(
|
||
(body) => body.getBoundary(),
|
||
"form-data doesn't follow the spec and requires special treatment. Use alternative package",
|
||
"https://github.com/node-fetch/node-fetch/issues/1167"
|
||
);
|
||
var extractContentType = (body, request) => {
|
||
if (body === null) {
|
||
return null;
|
||
}
|
||
if (typeof body === "string") {
|
||
return "text/plain;charset=UTF-8";
|
||
}
|
||
if (isURLSearchParameters(body)) {
|
||
return "application/x-www-form-urlencoded;charset=UTF-8";
|
||
}
|
||
if (isBlob(body)) {
|
||
return body.type || null;
|
||
}
|
||
if (import_node_buffer.Buffer.isBuffer(body) || import_node_util.types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
|
||
return null;
|
||
}
|
||
if (body instanceof FormData) {
|
||
return `multipart/form-data; boundary=${request[INTERNALS].boundary}`;
|
||
}
|
||
if (body && typeof body.getBoundary === "function") {
|
||
return `multipart/form-data;boundary=${getNonSpecFormDataBoundary(body)}`;
|
||
}
|
||
if (body instanceof import_node_stream.default) {
|
||
return null;
|
||
}
|
||
return "text/plain;charset=UTF-8";
|
||
};
|
||
var getTotalBytes = (request) => {
|
||
const { body } = request[INTERNALS];
|
||
if (body === null) {
|
||
return 0;
|
||
}
|
||
if (isBlob(body)) {
|
||
return body.size;
|
||
}
|
||
if (import_node_buffer.Buffer.isBuffer(body)) {
|
||
return body.length;
|
||
}
|
||
if (body && typeof body.getLengthSync === "function") {
|
||
return body.hasKnownLength && body.hasKnownLength() ? body.getLengthSync() : null;
|
||
}
|
||
return null;
|
||
};
|
||
var writeToStream = async (dest, { body }) => {
|
||
if (body === null) {
|
||
dest.end();
|
||
} else {
|
||
await pipeline(body, dest);
|
||
}
|
||
};
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/headers.js
|
||
var import_node_util2 = require("node:util");
|
||
var import_node_http = __toESM(require("node:http"), 1);
|
||
var validateHeaderName = typeof import_node_http.default.validateHeaderName === "function" ? import_node_http.default.validateHeaderName : (name) => {
|
||
if (!/^[\^`\-\w!#$%&'*+.|~]+$/.test(name)) {
|
||
const error = new TypeError(`Header name must be a valid HTTP token [${name}]`);
|
||
Object.defineProperty(error, "code", { value: "ERR_INVALID_HTTP_TOKEN" });
|
||
throw error;
|
||
}
|
||
};
|
||
var validateHeaderValue = typeof import_node_http.default.validateHeaderValue === "function" ? import_node_http.default.validateHeaderValue : (name, value) => {
|
||
if (/[^\t\u0020-\u007E\u0080-\u00FF]/.test(value)) {
|
||
const error = new TypeError(`Invalid character in header content ["${name}"]`);
|
||
Object.defineProperty(error, "code", { value: "ERR_INVALID_CHAR" });
|
||
throw error;
|
||
}
|
||
};
|
||
var Headers = class _Headers extends URLSearchParams {
|
||
/**
|
||
* Headers class
|
||
*
|
||
* @constructor
|
||
* @param {HeadersInit} [init] - Response headers
|
||
*/
|
||
constructor(init) {
|
||
let result = [];
|
||
if (init instanceof _Headers) {
|
||
const raw = init.raw();
|
||
for (const [name, values] of Object.entries(raw)) {
|
||
result.push(...values.map((value) => [name, value]));
|
||
}
|
||
} else if (init == null) {
|
||
} else if (typeof init === "object" && !import_node_util2.types.isBoxedPrimitive(init)) {
|
||
const method = init[Symbol.iterator];
|
||
if (method == null) {
|
||
result.push(...Object.entries(init));
|
||
} else {
|
||
if (typeof method !== "function") {
|
||
throw new TypeError("Header pairs must be iterable");
|
||
}
|
||
result = [...init].map((pair) => {
|
||
if (typeof pair !== "object" || import_node_util2.types.isBoxedPrimitive(pair)) {
|
||
throw new TypeError("Each header pair must be an iterable object");
|
||
}
|
||
return [...pair];
|
||
}).map((pair) => {
|
||
if (pair.length !== 2) {
|
||
throw new TypeError("Each header pair must be a name/value tuple");
|
||
}
|
||
return [...pair];
|
||
});
|
||
}
|
||
} else {
|
||
throw new TypeError("Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)");
|
||
}
|
||
result = result.length > 0 ? result.map(([name, value]) => {
|
||
validateHeaderName(name);
|
||
validateHeaderValue(name, String(value));
|
||
return [String(name).toLowerCase(), String(value)];
|
||
}) : void 0;
|
||
super(result);
|
||
return new Proxy(this, {
|
||
get(target, p, receiver) {
|
||
switch (p) {
|
||
case "append":
|
||
case "set":
|
||
return (name, value) => {
|
||
validateHeaderName(name);
|
||
validateHeaderValue(name, String(value));
|
||
return URLSearchParams.prototype[p].call(
|
||
target,
|
||
String(name).toLowerCase(),
|
||
String(value)
|
||
);
|
||
};
|
||
case "delete":
|
||
case "has":
|
||
case "getAll":
|
||
return (name) => {
|
||
validateHeaderName(name);
|
||
return URLSearchParams.prototype[p].call(
|
||
target,
|
||
String(name).toLowerCase()
|
||
);
|
||
};
|
||
case "keys":
|
||
return () => {
|
||
target.sort();
|
||
return new Set(URLSearchParams.prototype.keys.call(target)).keys();
|
||
};
|
||
default:
|
||
return Reflect.get(target, p, receiver);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
get [Symbol.toStringTag]() {
|
||
return this.constructor.name;
|
||
}
|
||
toString() {
|
||
return Object.prototype.toString.call(this);
|
||
}
|
||
get(name) {
|
||
const values = this.getAll(name);
|
||
if (values.length === 0) {
|
||
return null;
|
||
}
|
||
let value = values.join(", ");
|
||
if (/^content-encoding$/i.test(name)) {
|
||
value = value.toLowerCase();
|
||
}
|
||
return value;
|
||
}
|
||
forEach(callback, thisArg = void 0) {
|
||
for (const name of this.keys()) {
|
||
Reflect.apply(callback, thisArg, [this.get(name), name, this]);
|
||
}
|
||
}
|
||
*values() {
|
||
for (const name of this.keys()) {
|
||
yield this.get(name);
|
||
}
|
||
}
|
||
/**
|
||
* @type {() => IterableIterator<[string, string]>}
|
||
*/
|
||
*entries() {
|
||
for (const name of this.keys()) {
|
||
yield [name, this.get(name)];
|
||
}
|
||
}
|
||
[Symbol.iterator]() {
|
||
return this.entries();
|
||
}
|
||
/**
|
||
* Node-fetch non-spec method
|
||
* returning all headers and their values as array
|
||
* @returns {Record<string, string[]>}
|
||
*/
|
||
raw() {
|
||
return [...this.keys()].reduce((result, key) => {
|
||
result[key] = this.getAll(key);
|
||
return result;
|
||
}, {});
|
||
}
|
||
/**
|
||
* For better console.log(headers) and also to convert Headers into Node.js Request compatible format
|
||
*/
|
||
[Symbol.for("nodejs.util.inspect.custom")]() {
|
||
return [...this.keys()].reduce((result, key) => {
|
||
const values = this.getAll(key);
|
||
if (key === "host") {
|
||
result[key] = values[0];
|
||
} else {
|
||
result[key] = values.length > 1 ? values : values[0];
|
||
}
|
||
return result;
|
||
}, {});
|
||
}
|
||
};
|
||
Object.defineProperties(
|
||
Headers.prototype,
|
||
["get", "entries", "forEach", "values"].reduce((result, property) => {
|
||
result[property] = { enumerable: true };
|
||
return result;
|
||
}, {})
|
||
);
|
||
function fromRawHeaders(headers = []) {
|
||
return new Headers(
|
||
headers.reduce((result, value, index, array) => {
|
||
if (index % 2 === 0) {
|
||
result.push(array.slice(index, index + 2));
|
||
}
|
||
return result;
|
||
}, []).filter(([name, value]) => {
|
||
try {
|
||
validateHeaderName(name);
|
||
validateHeaderValue(name, String(value));
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
})
|
||
);
|
||
}
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/is-redirect.js
|
||
var redirectStatus = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
||
var isRedirect = (code) => {
|
||
return redirectStatus.has(code);
|
||
};
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/response.js
|
||
var INTERNALS2 = Symbol("Response internals");
|
||
var Response = class _Response extends Body {
|
||
constructor(body = null, options = {}) {
|
||
super(body, options);
|
||
const status = options.status != null ? options.status : 200;
|
||
const headers = new Headers(options.headers);
|
||
if (body !== null && !headers.has("Content-Type")) {
|
||
const contentType = extractContentType(body, this);
|
||
if (contentType) {
|
||
headers.append("Content-Type", contentType);
|
||
}
|
||
}
|
||
this[INTERNALS2] = {
|
||
type: "default",
|
||
url: options.url,
|
||
status,
|
||
statusText: options.statusText || "",
|
||
headers,
|
||
counter: options.counter,
|
||
highWaterMark: options.highWaterMark
|
||
};
|
||
}
|
||
get type() {
|
||
return this[INTERNALS2].type;
|
||
}
|
||
get url() {
|
||
return this[INTERNALS2].url || "";
|
||
}
|
||
get status() {
|
||
return this[INTERNALS2].status;
|
||
}
|
||
/**
|
||
* Convenience property representing if the request ended normally
|
||
*/
|
||
get ok() {
|
||
return this[INTERNALS2].status >= 200 && this[INTERNALS2].status < 300;
|
||
}
|
||
get redirected() {
|
||
return this[INTERNALS2].counter > 0;
|
||
}
|
||
get statusText() {
|
||
return this[INTERNALS2].statusText;
|
||
}
|
||
get headers() {
|
||
return this[INTERNALS2].headers;
|
||
}
|
||
get highWaterMark() {
|
||
return this[INTERNALS2].highWaterMark;
|
||
}
|
||
/**
|
||
* Clone this response
|
||
*
|
||
* @return Response
|
||
*/
|
||
clone() {
|
||
return new _Response(clone(this, this.highWaterMark), {
|
||
type: this.type,
|
||
url: this.url,
|
||
status: this.status,
|
||
statusText: this.statusText,
|
||
headers: this.headers,
|
||
ok: this.ok,
|
||
redirected: this.redirected,
|
||
size: this.size,
|
||
highWaterMark: this.highWaterMark
|
||
});
|
||
}
|
||
/**
|
||
* @param {string} url The URL that the new response is to originate from.
|
||
* @param {number} status An optional status code for the response (e.g., 302.)
|
||
* @returns {Response} A Response object.
|
||
*/
|
||
static redirect(url, status = 302) {
|
||
if (!isRedirect(status)) {
|
||
throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');
|
||
}
|
||
return new _Response(null, {
|
||
headers: {
|
||
location: new URL(url).toString()
|
||
},
|
||
status
|
||
});
|
||
}
|
||
static error() {
|
||
const response = new _Response(null, { status: 0, statusText: "" });
|
||
response[INTERNALS2].type = "error";
|
||
return response;
|
||
}
|
||
static json(data = void 0, init = {}) {
|
||
const body = JSON.stringify(data);
|
||
if (body === void 0) {
|
||
throw new TypeError("data is not JSON serializable");
|
||
}
|
||
const headers = new Headers(init && init.headers);
|
||
if (!headers.has("content-type")) {
|
||
headers.set("content-type", "application/json");
|
||
}
|
||
return new _Response(body, {
|
||
...init,
|
||
headers
|
||
});
|
||
}
|
||
get [Symbol.toStringTag]() {
|
||
return "Response";
|
||
}
|
||
};
|
||
Object.defineProperties(Response.prototype, {
|
||
type: { enumerable: true },
|
||
url: { enumerable: true },
|
||
status: { enumerable: true },
|
||
ok: { enumerable: true },
|
||
redirected: { enumerable: true },
|
||
statusText: { enumerable: true },
|
||
headers: { enumerable: true },
|
||
clone: { enumerable: true }
|
||
});
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/request.js
|
||
var import_node_url = require("node:url");
|
||
var import_node_util3 = require("node:util");
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/get-search.js
|
||
var getSearch = (parsedURL) => {
|
||
if (parsedURL.search) {
|
||
return parsedURL.search;
|
||
}
|
||
const lastOffset = parsedURL.href.length - 1;
|
||
const hash = parsedURL.hash || (parsedURL.href[lastOffset] === "#" ? "#" : "");
|
||
return parsedURL.href[lastOffset - hash.length] === "?" ? "?" : "";
|
||
};
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/referrer.js
|
||
var import_node_net = require("node:net");
|
||
function stripURLForUseAsAReferrer(url, originOnly = false) {
|
||
if (url == null) {
|
||
return "no-referrer";
|
||
}
|
||
url = new URL(url);
|
||
if (/^(about|blob|data):$/.test(url.protocol)) {
|
||
return "no-referrer";
|
||
}
|
||
url.username = "";
|
||
url.password = "";
|
||
url.hash = "";
|
||
if (originOnly) {
|
||
url.pathname = "";
|
||
url.search = "";
|
||
}
|
||
return url;
|
||
}
|
||
var ReferrerPolicy = /* @__PURE__ */ new Set([
|
||
"",
|
||
"no-referrer",
|
||
"no-referrer-when-downgrade",
|
||
"same-origin",
|
||
"origin",
|
||
"strict-origin",
|
||
"origin-when-cross-origin",
|
||
"strict-origin-when-cross-origin",
|
||
"unsafe-url"
|
||
]);
|
||
var DEFAULT_REFERRER_POLICY = "strict-origin-when-cross-origin";
|
||
function validateReferrerPolicy(referrerPolicy) {
|
||
if (!ReferrerPolicy.has(referrerPolicy)) {
|
||
throw new TypeError(`Invalid referrerPolicy: ${referrerPolicy}`);
|
||
}
|
||
return referrerPolicy;
|
||
}
|
||
function isOriginPotentiallyTrustworthy(url) {
|
||
if (/^(http|ws)s:$/.test(url.protocol)) {
|
||
return true;
|
||
}
|
||
const hostIp = url.host.replace(/(^\[)|(]$)/g, "");
|
||
const hostIPVersion = (0, import_node_net.isIP)(hostIp);
|
||
if (hostIPVersion === 4 && /^127\./.test(hostIp)) {
|
||
return true;
|
||
}
|
||
if (hostIPVersion === 6 && /^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(hostIp)) {
|
||
return true;
|
||
}
|
||
if (url.host === "localhost" || url.host.endsWith(".localhost")) {
|
||
return false;
|
||
}
|
||
if (url.protocol === "file:") {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
function isUrlPotentiallyTrustworthy(url) {
|
||
if (/^about:(blank|srcdoc)$/.test(url)) {
|
||
return true;
|
||
}
|
||
if (url.protocol === "data:") {
|
||
return true;
|
||
}
|
||
if (/^(blob|filesystem):$/.test(url.protocol)) {
|
||
return true;
|
||
}
|
||
return isOriginPotentiallyTrustworthy(url);
|
||
}
|
||
function determineRequestsReferrer(request, { referrerURLCallback, referrerOriginCallback } = {}) {
|
||
if (request.referrer === "no-referrer" || request.referrerPolicy === "") {
|
||
return null;
|
||
}
|
||
const policy = request.referrerPolicy;
|
||
if (request.referrer === "about:client") {
|
||
return "no-referrer";
|
||
}
|
||
const referrerSource = request.referrer;
|
||
let referrerURL = stripURLForUseAsAReferrer(referrerSource);
|
||
let referrerOrigin = stripURLForUseAsAReferrer(referrerSource, true);
|
||
if (referrerURL.toString().length > 4096) {
|
||
referrerURL = referrerOrigin;
|
||
}
|
||
if (referrerURLCallback) {
|
||
referrerURL = referrerURLCallback(referrerURL);
|
||
}
|
||
if (referrerOriginCallback) {
|
||
referrerOrigin = referrerOriginCallback(referrerOrigin);
|
||
}
|
||
const currentURL = new URL(request.url);
|
||
switch (policy) {
|
||
case "no-referrer":
|
||
return "no-referrer";
|
||
case "origin":
|
||
return referrerOrigin;
|
||
case "unsafe-url":
|
||
return referrerURL;
|
||
case "strict-origin":
|
||
if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
|
||
return "no-referrer";
|
||
}
|
||
return referrerOrigin.toString();
|
||
case "strict-origin-when-cross-origin":
|
||
if (referrerURL.origin === currentURL.origin) {
|
||
return referrerURL;
|
||
}
|
||
if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
|
||
return "no-referrer";
|
||
}
|
||
return referrerOrigin;
|
||
case "same-origin":
|
||
if (referrerURL.origin === currentURL.origin) {
|
||
return referrerURL;
|
||
}
|
||
return "no-referrer";
|
||
case "origin-when-cross-origin":
|
||
if (referrerURL.origin === currentURL.origin) {
|
||
return referrerURL;
|
||
}
|
||
return referrerOrigin;
|
||
case "no-referrer-when-downgrade":
|
||
if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
|
||
return "no-referrer";
|
||
}
|
||
return referrerURL;
|
||
default:
|
||
throw new TypeError(`Invalid referrerPolicy: ${policy}`);
|
||
}
|
||
}
|
||
function parseReferrerPolicyFromHeader(headers) {
|
||
const policyTokens = (headers.get("referrer-policy") || "").split(/[,\s]+/);
|
||
let policy = "";
|
||
for (const token of policyTokens) {
|
||
if (token && ReferrerPolicy.has(token)) {
|
||
policy = token;
|
||
}
|
||
}
|
||
return policy;
|
||
}
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/request.js
|
||
var INTERNALS3 = Symbol("Request internals");
|
||
var isRequest = (object) => {
|
||
return typeof object === "object" && typeof object[INTERNALS3] === "object";
|
||
};
|
||
var doBadDataWarn = (0, import_node_util3.deprecate)(
|
||
() => {
|
||
},
|
||
".data is not a valid RequestInit property, use .body instead",
|
||
"https://github.com/node-fetch/node-fetch/issues/1000 (request)"
|
||
);
|
||
var Request = class _Request extends Body {
|
||
constructor(input, init = {}) {
|
||
let parsedURL;
|
||
if (isRequest(input)) {
|
||
parsedURL = new URL(input.url);
|
||
} else {
|
||
parsedURL = new URL(input);
|
||
input = {};
|
||
}
|
||
if (parsedURL.username !== "" || parsedURL.password !== "") {
|
||
throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
|
||
}
|
||
let method = init.method || input.method || "GET";
|
||
if (/^(delete|get|head|options|post|put)$/i.test(method)) {
|
||
method = method.toUpperCase();
|
||
}
|
||
if (!isRequest(init) && "data" in init) {
|
||
doBadDataWarn();
|
||
}
|
||
if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
|
||
throw new TypeError("Request with GET/HEAD method cannot have body");
|
||
}
|
||
const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
|
||
super(inputBody, {
|
||
size: init.size || input.size || 0
|
||
});
|
||
const headers = new Headers(init.headers || input.headers || {});
|
||
if (inputBody !== null && !headers.has("Content-Type")) {
|
||
const contentType = extractContentType(inputBody, this);
|
||
if (contentType) {
|
||
headers.set("Content-Type", contentType);
|
||
}
|
||
}
|
||
let signal = isRequest(input) ? input.signal : null;
|
||
if ("signal" in init) {
|
||
signal = init.signal;
|
||
}
|
||
if (signal != null && !isAbortSignal(signal)) {
|
||
throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
|
||
}
|
||
let referrer = init.referrer == null ? input.referrer : init.referrer;
|
||
if (referrer === "") {
|
||
referrer = "no-referrer";
|
||
} else if (referrer) {
|
||
const parsedReferrer = new URL(referrer);
|
||
referrer = /^about:(\/\/)?client$/.test(parsedReferrer) ? "client" : parsedReferrer;
|
||
} else {
|
||
referrer = void 0;
|
||
}
|
||
this[INTERNALS3] = {
|
||
method,
|
||
redirect: init.redirect || input.redirect || "follow",
|
||
headers,
|
||
parsedURL,
|
||
signal,
|
||
referrer
|
||
};
|
||
this.follow = init.follow === void 0 ? input.follow === void 0 ? 20 : input.follow : init.follow;
|
||
this.compress = init.compress === void 0 ? input.compress === void 0 ? true : input.compress : init.compress;
|
||
this.counter = init.counter || input.counter || 0;
|
||
this.agent = init.agent || input.agent;
|
||
this.highWaterMark = init.highWaterMark || input.highWaterMark || 16384;
|
||
this.insecureHTTPParser = init.insecureHTTPParser || input.insecureHTTPParser || false;
|
||
this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || "";
|
||
}
|
||
/** @returns {string} */
|
||
get method() {
|
||
return this[INTERNALS3].method;
|
||
}
|
||
/** @returns {string} */
|
||
get url() {
|
||
return (0, import_node_url.format)(this[INTERNALS3].parsedURL);
|
||
}
|
||
/** @returns {Headers} */
|
||
get headers() {
|
||
return this[INTERNALS3].headers;
|
||
}
|
||
get redirect() {
|
||
return this[INTERNALS3].redirect;
|
||
}
|
||
/** @returns {AbortSignal} */
|
||
get signal() {
|
||
return this[INTERNALS3].signal;
|
||
}
|
||
// https://fetch.spec.whatwg.org/#dom-request-referrer
|
||
get referrer() {
|
||
if (this[INTERNALS3].referrer === "no-referrer") {
|
||
return "";
|
||
}
|
||
if (this[INTERNALS3].referrer === "client") {
|
||
return "about:client";
|
||
}
|
||
if (this[INTERNALS3].referrer) {
|
||
return this[INTERNALS3].referrer.toString();
|
||
}
|
||
return void 0;
|
||
}
|
||
get referrerPolicy() {
|
||
return this[INTERNALS3].referrerPolicy;
|
||
}
|
||
set referrerPolicy(referrerPolicy) {
|
||
this[INTERNALS3].referrerPolicy = validateReferrerPolicy(referrerPolicy);
|
||
}
|
||
/**
|
||
* Clone this request
|
||
*
|
||
* @return Request
|
||
*/
|
||
clone() {
|
||
return new _Request(this);
|
||
}
|
||
get [Symbol.toStringTag]() {
|
||
return "Request";
|
||
}
|
||
};
|
||
Object.defineProperties(Request.prototype, {
|
||
method: { enumerable: true },
|
||
url: { enumerable: true },
|
||
headers: { enumerable: true },
|
||
redirect: { enumerable: true },
|
||
clone: { enumerable: true },
|
||
signal: { enumerable: true },
|
||
referrer: { enumerable: true },
|
||
referrerPolicy: { enumerable: true }
|
||
});
|
||
var getNodeRequestOptions = (request) => {
|
||
const { parsedURL } = request[INTERNALS3];
|
||
const headers = new Headers(request[INTERNALS3].headers);
|
||
if (!headers.has("Accept")) {
|
||
headers.set("Accept", "*/*");
|
||
}
|
||
let contentLengthValue = null;
|
||
if (request.body === null && /^(post|put)$/i.test(request.method)) {
|
||
contentLengthValue = "0";
|
||
}
|
||
if (request.body !== null) {
|
||
const totalBytes = getTotalBytes(request);
|
||
if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) {
|
||
contentLengthValue = String(totalBytes);
|
||
}
|
||
}
|
||
if (contentLengthValue) {
|
||
headers.set("Content-Length", contentLengthValue);
|
||
}
|
||
if (request.referrerPolicy === "") {
|
||
request.referrerPolicy = DEFAULT_REFERRER_POLICY;
|
||
}
|
||
if (request.referrer && request.referrer !== "no-referrer") {
|
||
request[INTERNALS3].referrer = determineRequestsReferrer(request);
|
||
} else {
|
||
request[INTERNALS3].referrer = "no-referrer";
|
||
}
|
||
if (request[INTERNALS3].referrer instanceof URL) {
|
||
headers.set("Referer", request.referrer);
|
||
}
|
||
if (!headers.has("User-Agent")) {
|
||
headers.set("User-Agent", "node-fetch");
|
||
}
|
||
if (request.compress && !headers.has("Accept-Encoding")) {
|
||
headers.set("Accept-Encoding", "gzip, deflate, br");
|
||
}
|
||
let { agent } = request;
|
||
if (typeof agent === "function") {
|
||
agent = agent(parsedURL);
|
||
}
|
||
const search = getSearch(parsedURL);
|
||
const options = {
|
||
// Overwrite search to retain trailing ? (issue #776)
|
||
path: parsedURL.pathname + search,
|
||
// The following options are not expressed in the URL
|
||
method: request.method,
|
||
headers: headers[Symbol.for("nodejs.util.inspect.custom")](),
|
||
insecureHTTPParser: request.insecureHTTPParser,
|
||
agent
|
||
};
|
||
return {
|
||
/** @type {URL} */
|
||
parsedURL,
|
||
options
|
||
};
|
||
};
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/errors/abort-error.js
|
||
var AbortError = class extends FetchBaseError {
|
||
constructor(message, type = "aborted") {
|
||
super(message, type);
|
||
}
|
||
};
|
||
|
||
// ../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/index.js
|
||
init_esm_min();
|
||
init_from();
|
||
var supportedSchemas = /* @__PURE__ */ new Set(["data:", "http:", "https:"]);
|
||
async function fetch(url, options_) {
|
||
return new Promise((resolve, reject) => {
|
||
const request = new Request(url, options_);
|
||
const { parsedURL, options } = getNodeRequestOptions(request);
|
||
if (!supportedSchemas.has(parsedURL.protocol)) {
|
||
throw new TypeError(`node-fetch cannot load ${url}. URL scheme "${parsedURL.protocol.replace(/:$/, "")}" is not supported.`);
|
||
}
|
||
if (parsedURL.protocol === "data:") {
|
||
const data = dist_default(request.url);
|
||
const response2 = new Response(data, { headers: { "Content-Type": data.typeFull } });
|
||
resolve(response2);
|
||
return;
|
||
}
|
||
const send = (parsedURL.protocol === "https:" ? import_node_https.default : import_node_http2.default).request;
|
||
const { signal } = request;
|
||
let response = null;
|
||
const abort = () => {
|
||
const error = new AbortError("The operation was aborted.");
|
||
reject(error);
|
||
if (request.body && request.body instanceof import_node_stream2.default.Readable) {
|
||
request.body.destroy(error);
|
||
}
|
||
if (!response || !response.body) {
|
||
return;
|
||
}
|
||
response.body.emit("error", error);
|
||
};
|
||
if (signal && signal.aborted) {
|
||
abort();
|
||
return;
|
||
}
|
||
const abortAndFinalize = () => {
|
||
abort();
|
||
finalize();
|
||
};
|
||
const request_ = send(parsedURL.toString(), options);
|
||
if (signal) {
|
||
signal.addEventListener("abort", abortAndFinalize);
|
||
}
|
||
const finalize = () => {
|
||
request_.abort();
|
||
if (signal) {
|
||
signal.removeEventListener("abort", abortAndFinalize);
|
||
}
|
||
};
|
||
request_.on("error", (error) => {
|
||
reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
|
||
finalize();
|
||
});
|
||
fixResponseChunkedTransferBadEnding(request_, (error) => {
|
||
if (response && response.body) {
|
||
response.body.destroy(error);
|
||
}
|
||
});
|
||
if (process.version < "v14") {
|
||
request_.on("socket", (s2) => {
|
||
let endedWithEventsCount;
|
||
s2.prependListener("end", () => {
|
||
endedWithEventsCount = s2._eventsCount;
|
||
});
|
||
s2.prependListener("close", (hadError) => {
|
||
if (response && endedWithEventsCount < s2._eventsCount && !hadError) {
|
||
const error = new Error("Premature close");
|
||
error.code = "ERR_STREAM_PREMATURE_CLOSE";
|
||
response.body.emit("error", error);
|
||
}
|
||
});
|
||
});
|
||
}
|
||
request_.on("response", (response_) => {
|
||
request_.setTimeout(0);
|
||
const headers = fromRawHeaders(response_.rawHeaders);
|
||
if (isRedirect(response_.statusCode)) {
|
||
const location = headers.get("Location");
|
||
let locationURL = null;
|
||
try {
|
||
locationURL = location === null ? null : new URL(location, request.url);
|
||
} catch {
|
||
if (request.redirect !== "manual") {
|
||
reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
|
||
finalize();
|
||
return;
|
||
}
|
||
}
|
||
switch (request.redirect) {
|
||
case "error":
|
||
reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
|
||
finalize();
|
||
return;
|
||
case "manual":
|
||
break;
|
||
case "follow": {
|
||
if (locationURL === null) {
|
||
break;
|
||
}
|
||
if (request.counter >= request.follow) {
|
||
reject(new FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
|
||
finalize();
|
||
return;
|
||
}
|
||
const requestOptions = {
|
||
headers: new Headers(request.headers),
|
||
follow: request.follow,
|
||
counter: request.counter + 1,
|
||
agent: request.agent,
|
||
compress: request.compress,
|
||
method: request.method,
|
||
body: clone(request),
|
||
signal: request.signal,
|
||
size: request.size,
|
||
referrer: request.referrer,
|
||
referrerPolicy: request.referrerPolicy
|
||
};
|
||
if (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) {
|
||
for (const name of ["authorization", "www-authenticate", "cookie", "cookie2"]) {
|
||
requestOptions.headers.delete(name);
|
||
}
|
||
}
|
||
if (response_.statusCode !== 303 && request.body && options_.body instanceof import_node_stream2.default.Readable) {
|
||
reject(new FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
|
||
finalize();
|
||
return;
|
||
}
|
||
if (response_.statusCode === 303 || (response_.statusCode === 301 || response_.statusCode === 302) && request.method === "POST") {
|
||
requestOptions.method = "GET";
|
||
requestOptions.body = void 0;
|
||
requestOptions.headers.delete("content-length");
|
||
}
|
||
const responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);
|
||
if (responseReferrerPolicy) {
|
||
requestOptions.referrerPolicy = responseReferrerPolicy;
|
||
}
|
||
resolve(fetch(new Request(locationURL, requestOptions)));
|
||
finalize();
|
||
return;
|
||
}
|
||
default:
|
||
return reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
|
||
}
|
||
}
|
||
if (signal) {
|
||
response_.once("end", () => {
|
||
signal.removeEventListener("abort", abortAndFinalize);
|
||
});
|
||
}
|
||
let body = (0, import_node_stream2.pipeline)(response_, new import_node_stream2.PassThrough(), (error) => {
|
||
if (error) {
|
||
reject(error);
|
||
}
|
||
});
|
||
if (process.version < "v12.10") {
|
||
response_.on("aborted", abortAndFinalize);
|
||
}
|
||
const responseOptions = {
|
||
url: request.url,
|
||
status: response_.statusCode,
|
||
statusText: response_.statusMessage,
|
||
headers,
|
||
size: request.size,
|
||
counter: request.counter,
|
||
highWaterMark: request.highWaterMark
|
||
};
|
||
const codings = headers.get("Content-Encoding");
|
||
if (!request.compress || request.method === "HEAD" || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {
|
||
response = new Response(body, responseOptions);
|
||
resolve(response);
|
||
return;
|
||
}
|
||
const zlibOptions = {
|
||
flush: import_node_zlib.default.Z_SYNC_FLUSH,
|
||
finishFlush: import_node_zlib.default.Z_SYNC_FLUSH
|
||
};
|
||
if (codings === "gzip" || codings === "x-gzip") {
|
||
body = (0, import_node_stream2.pipeline)(body, import_node_zlib.default.createGunzip(zlibOptions), (error) => {
|
||
if (error) {
|
||
reject(error);
|
||
}
|
||
});
|
||
response = new Response(body, responseOptions);
|
||
resolve(response);
|
||
return;
|
||
}
|
||
if (codings === "deflate" || codings === "x-deflate") {
|
||
const raw = (0, import_node_stream2.pipeline)(response_, new import_node_stream2.PassThrough(), (error) => {
|
||
if (error) {
|
||
reject(error);
|
||
}
|
||
});
|
||
raw.once("data", (chunk) => {
|
||
if ((chunk[0] & 15) === 8) {
|
||
body = (0, import_node_stream2.pipeline)(body, import_node_zlib.default.createInflate(), (error) => {
|
||
if (error) {
|
||
reject(error);
|
||
}
|
||
});
|
||
} else {
|
||
body = (0, import_node_stream2.pipeline)(body, import_node_zlib.default.createInflateRaw(), (error) => {
|
||
if (error) {
|
||
reject(error);
|
||
}
|
||
});
|
||
}
|
||
response = new Response(body, responseOptions);
|
||
resolve(response);
|
||
});
|
||
raw.once("end", () => {
|
||
if (!response) {
|
||
response = new Response(body, responseOptions);
|
||
resolve(response);
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
if (codings === "br") {
|
||
body = (0, import_node_stream2.pipeline)(body, import_node_zlib.default.createBrotliDecompress(), (error) => {
|
||
if (error) {
|
||
reject(error);
|
||
}
|
||
});
|
||
response = new Response(body, responseOptions);
|
||
resolve(response);
|
||
return;
|
||
}
|
||
response = new Response(body, responseOptions);
|
||
resolve(response);
|
||
});
|
||
writeToStream(request_, request).catch(reject);
|
||
});
|
||
}
|
||
function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
||
const LAST_CHUNK = import_node_buffer2.Buffer.from("0\r\n\r\n");
|
||
let isChunkedTransfer = false;
|
||
let properLastChunkReceived = false;
|
||
let previousChunk;
|
||
request.on("response", (response) => {
|
||
const { headers } = response;
|
||
isChunkedTransfer = headers["transfer-encoding"] === "chunked" && !headers["content-length"];
|
||
});
|
||
request.on("socket", (socket) => {
|
||
const onSocketClose = () => {
|
||
if (isChunkedTransfer && !properLastChunkReceived) {
|
||
const error = new Error("Premature close");
|
||
error.code = "ERR_STREAM_PREMATURE_CLOSE";
|
||
errorCallback(error);
|
||
}
|
||
};
|
||
const onData = (buf) => {
|
||
properLastChunkReceived = import_node_buffer2.Buffer.compare(buf.slice(-5), LAST_CHUNK) === 0;
|
||
if (!properLastChunkReceived && previousChunk) {
|
||
properLastChunkReceived = import_node_buffer2.Buffer.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 && import_node_buffer2.Buffer.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0;
|
||
}
|
||
previousChunk = buf;
|
||
};
|
||
socket.prependListener("close", onSocketClose);
|
||
socket.on("data", onData);
|
||
request.on("close", () => {
|
||
socket.removeListener("close", onSocketClose);
|
||
socket.removeListener("data", onData);
|
||
});
|
||
});
|
||
}
|
||
|
||
// src/utils/versioncheck.ts
|
||
var checkVersion = async () => {
|
||
const currentVersion = GetResourceMetadata(cache.resource, "version", 0);
|
||
if (!currentVersion) {
|
||
console.error("[YaCA] Version check failed, no version found in resource manifest.");
|
||
return;
|
||
}
|
||
const parsedVersion = currentVersion.match(/\d+\.\d+\.\d+/g);
|
||
if (!parsedVersion) {
|
||
console.error("[YaCA] Version check failed, version in resource manifest is not in the correct format.");
|
||
return;
|
||
}
|
||
const response = await fetch("https://api.github.com/repos/yaca-systems/fivem-yaca-typescript/releases/latest");
|
||
if (response.status !== 200) {
|
||
console.error("[YaCA] Version check failed, unable to fetch latest release.");
|
||
return;
|
||
}
|
||
const data = await response.json();
|
||
const latestVersion = data.tag_name;
|
||
if (!latestVersion && latestVersion === currentVersion) {
|
||
console.log("[YaCA] You are running the latest version of YaCA.");
|
||
return;
|
||
}
|
||
const parsedLatestVersion = latestVersion.match(/\d+\.\d+\.\d+/g);
|
||
if (!parsedLatestVersion) {
|
||
console.error("[YaCA] Version check failed, latest release is not in the correct format.");
|
||
return;
|
||
}
|
||
for (let i2 = 0; i2 < parsedVersion.length; i2++) {
|
||
const current = Number.parseInt(parsedVersion[i2]);
|
||
const latest = Number.parseInt(parsedLatestVersion[i2]);
|
||
if (current !== latest) {
|
||
if (current < latest) {
|
||
console.error(
|
||
`[YaCA] You are running an outdated version of YaCA. (current: ${currentVersion}, latest: ${latestVersion}) \r
|
||
${data.html_url}`
|
||
);
|
||
} else {
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|
||
// src/bridge/saltychat.ts
|
||
var YaCAServerSaltyChatBridge = class {
|
||
/**
|
||
* Creates an instance of the SaltyChat bridge.
|
||
*
|
||
* @param {YaCAServerModule} serverModule - The server module.
|
||
*/
|
||
constructor(serverModule) {
|
||
this.callMap = /* @__PURE__ */ new Map();
|
||
this.serverModule = serverModule;
|
||
this.registerSaltyChatEvents();
|
||
console.log("[YaCA] SaltyChat bridge loaded");
|
||
on("onResourceStop", (resourceName2) => {
|
||
if (cache.resource !== resourceName2) {
|
||
return;
|
||
}
|
||
emit("onServerResourceStop", "saltychat");
|
||
});
|
||
}
|
||
/**
|
||
* Register SaltyChat events.
|
||
*/
|
||
registerSaltyChatEvents() {
|
||
saltyChatExport("GetPlayerAlive", (netId) => {
|
||
this.serverModule.getPlayerAliveStatus(netId);
|
||
});
|
||
saltyChatExport("SetPlayerAlive", (netId, isAlive) => {
|
||
this.serverModule.changePlayerAliveStatus(netId, isAlive);
|
||
});
|
||
saltyChatExport("GetPlayerVoiceRange", (netId) => {
|
||
this.serverModule.getPlayerVoiceRange(netId);
|
||
});
|
||
saltyChatExport("SetPlayerVoiceRange", (netId, voiceRange) => {
|
||
this.serverModule.changeVoiceRange(netId, voiceRange);
|
||
});
|
||
saltyChatExport("AddPlayerToCall", (callIdentifier, playerHandle) => this.addPlayerToCall(callIdentifier, playerHandle));
|
||
saltyChatExport("AddPlayersToCall", (callIdentifier, playerHandles) => this.addPlayerToCall(callIdentifier, playerHandles));
|
||
saltyChatExport("RemovePlayerFromCall", (callIdentifier, playerHandle) => this.removePlayerFromCall(callIdentifier, playerHandle));
|
||
saltyChatExport("RemovePlayersFromCall", (callIdentifier, playerHandles) => this.removePlayerFromCall(callIdentifier, playerHandles));
|
||
saltyChatExport("SetPhoneSpeaker", (playerHandle, toggle) => {
|
||
this.serverModule.phoneModule.enablePhoneSpeaker(playerHandle, toggle);
|
||
});
|
||
saltyChatExport("SetPlayerRadioSpeaker", () => {
|
||
console.warn("SetPlayerRadioSpeaker is not implemented in YaCA");
|
||
});
|
||
saltyChatExport("GetPlayersInRadioChannel", (radioChannelName) => this.serverModule.radioModule.getPlayersInRadioFrequency(radioChannelName));
|
||
saltyChatExport("SetPlayerRadioChannel", (netId, radioChannelName, primary = true) => {
|
||
const channel = primary ? 1 : 2;
|
||
const newRadioChannelName = radioChannelName === "" ? "0" : radioChannelName;
|
||
this.serverModule.radioModule.changeRadioFrequency(netId, channel, newRadioChannelName);
|
||
});
|
||
saltyChatExport("RemovePlayerRadioChannel", (netId, primary) => {
|
||
const channel = primary ? 1 : 2;
|
||
this.serverModule.radioModule.changeRadioFrequency(netId, channel, "0");
|
||
});
|
||
saltyChatExport("SetRadioTowers", () => {
|
||
console.warn("SetRadioTowers is not implemented in YaCA");
|
||
});
|
||
saltyChatExport("EstablishCall", (callerId, targetId) => {
|
||
this.serverModule.phoneModule.callPlayer(callerId, targetId, true);
|
||
});
|
||
saltyChatExport("EndCall", (callerId, targetId) => {
|
||
this.serverModule.phoneModule.callPlayer(callerId, targetId, false);
|
||
});
|
||
}
|
||
/**
|
||
* Add a player to a call.
|
||
*
|
||
* @param callIdentifier - The call identifier.
|
||
* @param playerHandle - The player handles.
|
||
*/
|
||
addPlayerToCall(callIdentifier, playerHandle) {
|
||
if (!Array.isArray(playerHandle)) {
|
||
playerHandle = [playerHandle];
|
||
}
|
||
const currentlyInCall = this.callMap.get(callIdentifier) ?? /* @__PURE__ */ new Set();
|
||
const newInCall = /* @__PURE__ */ new Set();
|
||
for (const player of playerHandle) {
|
||
if (!currentlyInCall.has(player)) {
|
||
currentlyInCall.add(player);
|
||
newInCall.add(player);
|
||
}
|
||
}
|
||
this.callMap.set(callIdentifier, currentlyInCall);
|
||
for (const player of currentlyInCall) {
|
||
for (const otherPlayer of newInCall) {
|
||
if (player !== otherPlayer) {
|
||
this.serverModule.phoneModule.callPlayer(player, otherPlayer, true);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* Remove a player from a call.
|
||
*
|
||
* @param callIdentifier - The call identifier.
|
||
* @param playerHandle - The player handles.
|
||
*/
|
||
removePlayerFromCall(callIdentifier, playerHandle) {
|
||
if (!Array.isArray(playerHandle)) {
|
||
playerHandle = [playerHandle];
|
||
}
|
||
const beforeInCall = this.callMap.get(callIdentifier);
|
||
if (!beforeInCall) {
|
||
return;
|
||
}
|
||
const nowInCall = new Set(beforeInCall);
|
||
const removedFromCall = /* @__PURE__ */ new Set();
|
||
for (const player of playerHandle) {
|
||
if (beforeInCall.has(player)) {
|
||
nowInCall.delete(player);
|
||
removedFromCall.add(player);
|
||
}
|
||
}
|
||
this.callMap.set(callIdentifier, nowInCall);
|
||
for (const player of removedFromCall) {
|
||
for (const otherPlayer of beforeInCall) {
|
||
if (player !== otherPlayer) {
|
||
this.serverModule.phoneModule.callPlayer(player, otherPlayer, false);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|
||
// src/yaca/megaphone.ts
|
||
var YaCAServerMegaphoneModule = class {
|
||
/**
|
||
* Creates an instance of the megaphone module.
|
||
*
|
||
* @param serverModule - The server module.
|
||
*/
|
||
constructor(serverModule) {
|
||
this.serverModule = serverModule;
|
||
this.sharedConfig = serverModule.sharedConfig;
|
||
this.registerEvents();
|
||
}
|
||
/**
|
||
* Register server events.
|
||
*/
|
||
registerEvents() {
|
||
onNet("server:yaca:useMegaphone", (state) => {
|
||
this.playerUseMegaphone(source, state);
|
||
});
|
||
onNet("server:yaca:playerLeftVehicle", () => {
|
||
this.changeMegaphoneState(source, false, true);
|
||
});
|
||
}
|
||
/**
|
||
* Apply the megaphone effect on a specific player via client event.
|
||
*
|
||
* @param {number} src - The source-id of the player to apply the megaphone effect to.
|
||
* @param {boolean} state - The state of the megaphone effect.
|
||
*/
|
||
playerUseMegaphone(src, state) {
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
const playerState = Player(src).state;
|
||
if (!state && !playerState[MEGAPHONE_STATE_NAME] || state && playerState[MEGAPHONE_STATE_NAME]) {
|
||
return;
|
||
}
|
||
this.changeMegaphoneState(src, state);
|
||
emit("yaca:external:changeMegaphoneState", src, state);
|
||
}
|
||
/**
|
||
* Apply the megaphone effect on a specific player.
|
||
*
|
||
* @param {number} src - The source-id of the player to apply the megaphone effect to.
|
||
* @param {boolean} state - The state of the megaphone effect.
|
||
* @param {boolean} [forced=false] - Whether the change is forced. Defaults to false if not provided.
|
||
*/
|
||
changeMegaphoneState(src, state, forced = false) {
|
||
const playerState = Player(src).state;
|
||
if (!state && playerState[MEGAPHONE_STATE_NAME]) {
|
||
playerState.set(MEGAPHONE_STATE_NAME, null, true);
|
||
if (forced) {
|
||
emitNet("client:yaca:setLastMegaphoneState", src, false);
|
||
}
|
||
} else if (state && !playerState[MEGAPHONE_STATE_NAME]) {
|
||
playerState.set(MEGAPHONE_STATE_NAME, this.sharedConfig.megaphone.range, true);
|
||
}
|
||
}
|
||
};
|
||
|
||
// src/yaca/phone.ts
|
||
var YaCAServerPhoneModle = class {
|
||
/**
|
||
* Creates an instance of the phone module.
|
||
*
|
||
* @param {YaCAServerModule} serverModule - The server module.
|
||
*/
|
||
constructor(serverModule) {
|
||
this.serverModule = serverModule;
|
||
this.registerEvents();
|
||
this.registerExports();
|
||
}
|
||
/**
|
||
* Register server events.
|
||
*/
|
||
registerEvents() {
|
||
onNet("server:yaca:phoneSpeakerEmitWhisper", (enableForTargets, disableForTargets) => {
|
||
const player = this.serverModule.players.get(source);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
const targets = /* @__PURE__ */ new Set();
|
||
for (const callTarget of player.voiceSettings.inCallWith) {
|
||
const target = this.serverModule.players.get(callTarget);
|
||
if (!target) {
|
||
continue;
|
||
}
|
||
targets.add(callTarget);
|
||
}
|
||
if (targets.size && (enableForTargets == null ? void 0 : enableForTargets.length)) {
|
||
triggerClientEvent("client:yaca:playersToPhoneSpeakerEmitWhisper", Array.from(targets), enableForTargets, true);
|
||
}
|
||
if (targets.size && (disableForTargets == null ? void 0 : disableForTargets.length)) {
|
||
triggerClientEvent("client:yaca:playersToPhoneSpeakerEmitWhisper", Array.from(targets), disableForTargets, false);
|
||
}
|
||
});
|
||
onNet("server:yaca:phoneEmit", (enableForTargets, disableForTargets) => {
|
||
if (!this.serverModule.sharedConfig.phoneHearPlayersNearby) return;
|
||
const player = this.serverModule.players.get(source);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
const enableReceive = /* @__PURE__ */ new Set();
|
||
const disableReceive = /* @__PURE__ */ new Set();
|
||
if (enableForTargets == null ? void 0 : enableForTargets.length) {
|
||
for (const callTarget of player.voiceSettings.inCallWith) {
|
||
const target = this.serverModule.players.get(callTarget);
|
||
if (!target) continue;
|
||
enableReceive.add(callTarget);
|
||
for (const targetID of enableForTargets) {
|
||
const map = player.voiceSettings.emittedPhoneSpeaker;
|
||
const set = map.get(targetID) ?? /* @__PURE__ */ new Set();
|
||
set.add(callTarget);
|
||
map.set(targetID, set);
|
||
}
|
||
}
|
||
}
|
||
if (disableForTargets == null ? void 0 : disableForTargets.length) {
|
||
for (const targetID of disableForTargets) {
|
||
const emittedFor = player.voiceSettings.emittedPhoneSpeaker.get(targetID);
|
||
if (!emittedFor) continue;
|
||
for (const emittedTarget of emittedFor) {
|
||
const target = this.serverModule.players.get(emittedTarget);
|
||
if (!target) continue;
|
||
disableReceive.add(emittedTarget);
|
||
}
|
||
player.voiceSettings.emittedPhoneSpeaker.delete(targetID);
|
||
}
|
||
}
|
||
if (enableReceive.size && (enableForTargets == null ? void 0 : enableForTargets.length)) {
|
||
const enableForTargetsData = /* @__PURE__ */ new Set();
|
||
for (const enableTarget of enableForTargets) {
|
||
const target = this.serverModule.players.get(enableTarget);
|
||
if (!target || !target.voicePlugin) continue;
|
||
enableForTargetsData.add(target.voicePlugin.clientId);
|
||
}
|
||
triggerClientEvent("client:yaca:phoneHearAround", Array.from(enableReceive), Array.from(enableForTargetsData), true);
|
||
}
|
||
if (disableReceive.size && (disableForTargets == null ? void 0 : disableForTargets.length)) {
|
||
const disableForTargetsData = /* @__PURE__ */ new Set();
|
||
for (const disableTarget of disableForTargets) {
|
||
const target = this.serverModule.players.get(disableTarget);
|
||
if (!target || !target.voicePlugin) continue;
|
||
disableForTargetsData.add(target.voicePlugin.clientId);
|
||
}
|
||
triggerClientEvent("client:yaca:phoneHearAround", Array.from(disableReceive), Array.from(disableForTargetsData), false);
|
||
}
|
||
});
|
||
}
|
||
registerExports() {
|
||
exports("callPlayer", (src, target, state) => this.callPlayer(src, target, state));
|
||
exports("callPlayerOldEffect", (src, target, state) => this.callPlayer(src, target, state, "PHONE_HISTORICAL" /* PHONE_HISTORICAL */));
|
||
exports("muteOnPhone", (src, state) => this.muteOnPhone(src, state));
|
||
exports("enablePhoneSpeaker", (src, state) => this.enablePhoneSpeaker(src, state));
|
||
exports("isPlayerInCall", (src) => {
|
||
const player = this.serverModule.players.get(src);
|
||
if (!player) {
|
||
return [false, []];
|
||
}
|
||
return [player.voiceSettings.inCallWith.size > 0, [...player.voiceSettings.inCallWith]];
|
||
});
|
||
}
|
||
/**
|
||
* Call another player.
|
||
*
|
||
* @param {number} src - The player who is making the call.
|
||
* @param {number} target - The player who is being called.
|
||
* @param {boolean} state - The state of the call.
|
||
* @param {YacaFilterEnum} filter - The filter to use for the call. Defaults to PHONE if not provided.
|
||
*/
|
||
callPlayer(src, target, state, filter = "PHONE" /* PHONE */) {
|
||
const player = this.serverModule.getPlayer(src);
|
||
const targetPlayer = this.serverModule.getPlayer(target);
|
||
if (!player || !targetPlayer) {
|
||
return;
|
||
}
|
||
emitNet("client:yaca:phone", target, src, state, filter);
|
||
emitNet("client:yaca:phone", src, target, state, filter);
|
||
const playerState = Player(src).state;
|
||
const targetState = Player(target).state;
|
||
if (state) {
|
||
player.voiceSettings.inCallWith.add(target);
|
||
targetPlayer.voiceSettings.inCallWith.add(src);
|
||
if (playerState[PHONE_SPEAKER_STATE_NAME]) {
|
||
this.enablePhoneSpeaker(src, true);
|
||
}
|
||
if (targetState[PHONE_SPEAKER_STATE_NAME]) {
|
||
this.enablePhoneSpeaker(target, true);
|
||
}
|
||
} else {
|
||
this.muteOnPhone(src, false, true);
|
||
this.muteOnPhone(target, false, true);
|
||
player.voiceSettings.inCallWith.delete(target);
|
||
targetPlayer.voiceSettings.inCallWith.delete(src);
|
||
if (playerState[PHONE_SPEAKER_STATE_NAME]) {
|
||
this.enablePhoneSpeaker(src, false);
|
||
}
|
||
if (targetState[PHONE_SPEAKER_STATE_NAME]) {
|
||
this.enablePhoneSpeaker(target, false);
|
||
}
|
||
}
|
||
emit("yaca:external:phoneCall", src, target, state, filter);
|
||
}
|
||
/**
|
||
* Mute a player during a phone call.
|
||
*
|
||
* @param {number} src - The source-id of the player to mute.
|
||
* @param {boolean} state - The mute state.
|
||
* @param {boolean} [onCallStop=false] - Whether the call has stopped. Defaults to false if not provided.
|
||
*/
|
||
muteOnPhone(src, state, onCallStop = false) {
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
player.voiceSettings.mutedOnPhone = state;
|
||
emitNet("client:yaca:phoneMute", -1, src, state, onCallStop);
|
||
emit("yaca:external:phoneMute", src, state);
|
||
}
|
||
/**
|
||
* Enable or disable the phone speaker for a player.
|
||
*
|
||
* @param {number} src - The source-id of the player to enable the phone speaker for.
|
||
* @param {boolean} state - The state of the phone speaker.
|
||
*/
|
||
enablePhoneSpeaker(src, state) {
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
const playerState = Player(src).state;
|
||
if (state && player.voiceSettings.inCallWith.size) {
|
||
playerState.set(PHONE_SPEAKER_STATE_NAME, Array.from(player.voiceSettings.inCallWith), true);
|
||
emit("yaca:external:phoneSpeaker", src, true);
|
||
} else {
|
||
playerState.set(PHONE_SPEAKER_STATE_NAME, null, true);
|
||
emit("yaca:external:phoneSpeaker", src, false);
|
||
}
|
||
}
|
||
};
|
||
|
||
// src/yaca/radio.ts
|
||
var YaCAServerRadioModule = class {
|
||
/**
|
||
* Creates an instance of the radio module.
|
||
*
|
||
* @param {YaCAServerModule} serverModule - The server module.
|
||
*/
|
||
constructor(serverModule) {
|
||
this.radioFrequencyMap = /* @__PURE__ */ new Map();
|
||
this.serverModule = serverModule;
|
||
this.sharedConfig = serverModule.sharedConfig;
|
||
this.serverConfig = serverModule.serverConfig;
|
||
this.registerEvents();
|
||
this.registerExports();
|
||
}
|
||
/**
|
||
* Register server events.
|
||
*/
|
||
registerEvents() {
|
||
onNet("server:yaca:enableRadio", (state) => {
|
||
this.enableRadio(source, state);
|
||
});
|
||
onNet("server:yaca:changeRadioFrequency", (channel, frequency) => {
|
||
this.changeRadioFrequency(source, channel, frequency);
|
||
});
|
||
onNet("server:yaca:muteRadioChannel", (channel, state) => {
|
||
this.radioChannelMute(source, channel, state);
|
||
});
|
||
onNet("server:yaca:radioTalking", (state, channel, distanceToTower = -1) => {
|
||
this.radioTalkingState(source, state, channel, distanceToTower);
|
||
});
|
||
}
|
||
/**
|
||
* Register server exports.
|
||
*/
|
||
registerExports() {
|
||
exports("getPlayersInRadioFrequency", (frequency) => this.getPlayersInRadioFrequency(frequency));
|
||
exports("setPlayerRadioChannel", (src, channel, frequency) => this.changeRadioFrequency(src, channel, frequency));
|
||
exports("getPlayerHasLongRange", (src) => this.getPlayerHasLongRange(src));
|
||
exports("setPlayerHasLongRange", (src, state) => this.setPlayerHasLongRange(src, state));
|
||
}
|
||
/**
|
||
* Get all players in a radio frequency.
|
||
*
|
||
* @param frequency - The frequency to get the players for.
|
||
*/
|
||
getPlayersInRadioFrequency(frequency) {
|
||
const allPlayersInChannel = this.radioFrequencyMap.get(frequency);
|
||
const playersArray = [];
|
||
if (!allPlayersInChannel) {
|
||
return playersArray;
|
||
}
|
||
for (const [key] of allPlayersInChannel) {
|
||
const target = this.serverModule.getPlayer(key);
|
||
if (!target) {
|
||
continue;
|
||
}
|
||
playersArray.push(key);
|
||
}
|
||
return playersArray;
|
||
}
|
||
/**
|
||
* Gets if a player has long range radio.
|
||
*
|
||
* @param src - The player to get the long range radio for.
|
||
*/
|
||
getPlayerHasLongRange(src) {
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player) {
|
||
return false;
|
||
}
|
||
return player.radioSettings.hasLong;
|
||
}
|
||
/**
|
||
* Sets if a player has long range radio.
|
||
*
|
||
* @param src - The player to set the long range radio for.
|
||
* @param state - The new state of the long range radio.
|
||
*/
|
||
setPlayerHasLongRange(src, state) {
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
player.radioSettings.hasLong = state;
|
||
}
|
||
/**
|
||
* Enable or disable the radio for a player.
|
||
*
|
||
* @param {number} src - The player to enable or disable the radio for.
|
||
* @param {boolean} state - The new state of the radio.
|
||
*/
|
||
enableRadio(src, state) {
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
player.radioSettings.activated = state;
|
||
emit("yaca:export:enabledRadio", src, state);
|
||
}
|
||
/**
|
||
* Change the radio frequency for a player.
|
||
*
|
||
* @param {number} src - The player to change the radio frequency for.
|
||
* @param {number} channel - The channel to change the frequency of.
|
||
* @param {string} frequency - The new frequency.
|
||
*/
|
||
changeRadioFrequency(src, channel, frequency) {
|
||
var _a;
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
if (!player.radioSettings.activated) {
|
||
emitNet("client:yaca:notification", src, locale("radio_not_activated"), "error" /* ERROR */);
|
||
return;
|
||
}
|
||
if (Number.isNaN(channel) || channel < 1 || channel > this.sharedConfig.radioSettings.channelCount) {
|
||
emitNet("client:yaca:notification", src, locale("radio_channel_invalid"), "error" /* ERROR */);
|
||
return;
|
||
}
|
||
const oldFrequency = player.radioSettings.frequencies[channel];
|
||
if (frequency === "0") {
|
||
this.leaveRadioFrequency(src, channel, oldFrequency);
|
||
return;
|
||
}
|
||
if (oldFrequency !== frequency) {
|
||
this.leaveRadioFrequency(src, channel, oldFrequency);
|
||
}
|
||
if (!this.radioFrequencyMap.has(frequency)) {
|
||
this.radioFrequencyMap.set(frequency, /* @__PURE__ */ new Map());
|
||
}
|
||
(_a = this.radioFrequencyMap.get(frequency)) == null ? void 0 : _a.set(src, { muted: false });
|
||
player.radioSettings.frequencies[channel] = frequency;
|
||
emitNet("client:yaca:setRadioFreq", src, channel, frequency);
|
||
emit("yaca:external:changedRadioFrequency", src, channel, frequency);
|
||
}
|
||
/**
|
||
* Make a player leave a radio frequency.
|
||
*
|
||
* @param {number} src - The player to leave the radio frequency.
|
||
* @param {number} channel - The channel to leave.
|
||
* @param {string} frequency - The frequency to leave.
|
||
*/
|
||
leaveRadioFrequency(src, channel, frequency) {
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
const allPlayersInChannel = this.radioFrequencyMap.get(frequency);
|
||
if (!allPlayersInChannel) {
|
||
return;
|
||
}
|
||
player.radioSettings.frequencies[channel] = "0";
|
||
const playersArray = [];
|
||
const allTargets = [];
|
||
for (const [key] of allPlayersInChannel) {
|
||
const target = this.serverModule.getPlayer(key);
|
||
if (!target) {
|
||
continue;
|
||
}
|
||
playersArray.push(key);
|
||
if (key === src) {
|
||
continue;
|
||
}
|
||
allTargets.push(key);
|
||
}
|
||
if (this.serverConfig.useWhisper) {
|
||
emitNet("client:yaca:radioTalking", src, allTargets, frequency, false, null, true);
|
||
} else if (player.voicePlugin) {
|
||
triggerClientEvent("client:yaca:leaveRadioChannel", playersArray, player.voicePlugin.clientId, frequency);
|
||
}
|
||
allPlayersInChannel.delete(src);
|
||
if (!allPlayersInChannel.size) {
|
||
this.radioFrequencyMap.delete(frequency);
|
||
}
|
||
}
|
||
/**
|
||
* Mute a radio channel for a player.
|
||
*
|
||
* @param {number} src - The player to mute the radio channel for.
|
||
* @param {number} channel - The channel to mute.
|
||
*/
|
||
radioChannelMute(src, channel, state) {
|
||
var _a;
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
const radioFrequency = player.radioSettings.frequencies[channel];
|
||
const foundPlayer = (_a = this.radioFrequencyMap.get(radioFrequency)) == null ? void 0 : _a.get(src);
|
||
if (!foundPlayer) {
|
||
return;
|
||
}
|
||
foundPlayer.muted = typeof state !== "undefined" ? state : !foundPlayer.muted;
|
||
emitNet("client:yaca:setRadioMuteState", src, channel, foundPlayer.muted);
|
||
emit("yaca:external:changedRadioMuteState", src, channel, foundPlayer.muted);
|
||
}
|
||
/**
|
||
* Change the talking state of a player on the radio.
|
||
*
|
||
* @param {number} src - The player to change the talking state for.
|
||
* @param {boolean} state - The new talking state.
|
||
* @param {number} channel - The channel to change the talking state for.
|
||
* @param {number} distanceToTower - The distance to the tower.
|
||
*/
|
||
radioTalkingState(src, state, channel, distanceToTower) {
|
||
const player = this.serverModule.getPlayer(src);
|
||
if (!player || !player.radioSettings.activated) {
|
||
return;
|
||
}
|
||
const radioFrequency = player.radioSettings.frequencies[channel];
|
||
if (!radioFrequency || radioFrequency === "0") {
|
||
return;
|
||
}
|
||
const getPlayers2 = this.radioFrequencyMap.get(radioFrequency);
|
||
if (!getPlayers2) {
|
||
return;
|
||
}
|
||
let targets = [];
|
||
const targetsToSender = [];
|
||
const radioInfos = {};
|
||
for (const [key, values] of getPlayers2) {
|
||
if (values.muted) {
|
||
if (key === src) {
|
||
targets = [];
|
||
break;
|
||
}
|
||
continue;
|
||
}
|
||
if (key === src) {
|
||
continue;
|
||
}
|
||
const target = this.serverModule.getPlayer(key);
|
||
if (!target || !target.radioSettings.activated) {
|
||
continue;
|
||
}
|
||
const shortRange = !player.radioSettings.hasLong && !target.radioSettings.hasLong;
|
||
if (player.radioSettings.hasLong && target.radioSettings.hasLong || shortRange) {
|
||
targets.push(key);
|
||
radioInfos[key] = {
|
||
shortRange
|
||
};
|
||
targetsToSender.push(key);
|
||
}
|
||
}
|
||
triggerClientEvent(
|
||
"client:yaca:radioTalking",
|
||
targets,
|
||
src,
|
||
radioFrequency,
|
||
state,
|
||
radioInfos,
|
||
distanceToTower,
|
||
GetEntityCoords(GetPlayerPed(src.toString()))
|
||
);
|
||
if (this.serverConfig.useWhisper) {
|
||
emitNet("client:yaca:radioTalkingWhisper", src, targetsToSender, radioFrequency, state, GetEntityCoords(GetPlayerPed(src.toString())));
|
||
}
|
||
}
|
||
};
|
||
|
||
// src/yaca/main.ts
|
||
var YaCAServerModule = class {
|
||
/**
|
||
* Creates an instance of the server module.
|
||
*/
|
||
constructor() {
|
||
this.nameSet = /* @__PURE__ */ new Set();
|
||
this.players = /* @__PURE__ */ new Map();
|
||
console.log("~g~ --> YaCA: Server loaded");
|
||
this.serverConfig = loadConfig("config/server.json5", defaultServerConfig);
|
||
this.sharedConfig = loadConfig("config/shared.json5", defaultSharedConfig);
|
||
this.towerConfig = loadConfig("config/tower.json5", defaultTowerConfig);
|
||
initLocale(this.sharedConfig.locale);
|
||
if (this.sharedConfig.voiceRange.ranges[this.sharedConfig.voiceRange.defaultIndex]) {
|
||
this.defaultVoiceRange = this.sharedConfig.voiceRange.ranges[this.sharedConfig.voiceRange.defaultIndex];
|
||
} else {
|
||
this.defaultVoiceRange = 1;
|
||
this.sharedConfig.voiceRange.ranges = [1];
|
||
console.error("[YaCA] Default voice range is not set correctly in the config.");
|
||
}
|
||
this.phoneModule = new YaCAServerPhoneModle(this);
|
||
this.radioModule = new YaCAServerRadioModule(this);
|
||
this.megaphoneModule = new YaCAServerMegaphoneModule(this);
|
||
this.registerExports();
|
||
this.registerEvents();
|
||
if (this.sharedConfig.saltyChatBridge) {
|
||
this.saltChatBridge = new YaCAServerSaltyChatBridge(this);
|
||
}
|
||
if (this.sharedConfig.versionCheck) {
|
||
checkVersion().then();
|
||
}
|
||
GlobalState.set(GLOBAL_ERROR_LEVEL_STATE_NAME, 0, true);
|
||
}
|
||
/**
|
||
* Get the player data for a specific player.
|
||
*/
|
||
getPlayer(playerId) {
|
||
return this.players.get(playerId);
|
||
}
|
||
/**
|
||
* Initialize the player on first connect.
|
||
*
|
||
* @param {number} src - The source-id of the player to initialize.
|
||
*/
|
||
connectToVoice(src) {
|
||
const name = generateRandomName(src, this.nameSet, this.serverConfig.userNamePattern);
|
||
if (!name) {
|
||
DropPlayer(src.toString(), "[YaCA] Failed to generate a random name.");
|
||
return;
|
||
}
|
||
const playerState = Player(src).state;
|
||
playerState.set(VOICE_RANGE_STATE_NAME, this.defaultVoiceRange, true);
|
||
this.players.set(src, {
|
||
voiceSettings: {
|
||
voiceFirstConnect: false,
|
||
forceMuted: false,
|
||
ingameName: name,
|
||
mutedOnPhone: false,
|
||
inCallWith: /* @__PURE__ */ new Set(),
|
||
emittedPhoneSpeaker: /* @__PURE__ */ new Map()
|
||
},
|
||
radioSettings: {
|
||
activated: false,
|
||
hasLong: true,
|
||
frequencies: {}
|
||
}
|
||
});
|
||
this.connect(src);
|
||
}
|
||
/**
|
||
* Register all exports for the YaCA module.
|
||
*/
|
||
registerExports() {
|
||
exports("connectToVoice", (src) => this.connectToVoice(src));
|
||
exports("getPlayerAliveStatus", (playerId) => this.getPlayerAliveStatus(playerId));
|
||
exports("setPlayerAliveStatus", (playerId, state) => this.changePlayerAliveStatus(playerId, state));
|
||
exports("getPlayerVoiceRange", (playerId) => this.getPlayerVoiceRange(playerId));
|
||
exports("setPlayerVoiceRange", (playerId, range) => this.changeVoiceRange(playerId, range));
|
||
exports("setGlobalErrorLevel", (errorLevel) => setGlobalErrorLevel(errorLevel));
|
||
exports("getGlobalErrorLevel", () => getGlobalErrorLevel());
|
||
}
|
||
/**
|
||
* Register all events for the YaCA module.
|
||
*/
|
||
registerEvents() {
|
||
on("playerDropped", (_reason) => {
|
||
this.handlePlayerDisconnect(source);
|
||
});
|
||
onNet("server:yaca:nuiReady", () => {
|
||
if (!this.sharedConfig.autoConnectOnJoin) return;
|
||
this.connectToVoice(source);
|
||
});
|
||
onNet("server:yaca:addPlayer", (clientId) => {
|
||
this.addNewPlayer(source, clientId);
|
||
});
|
||
onNet("server:yaca:wsReady", () => {
|
||
this.playerReconnect(source);
|
||
});
|
||
onNet("txsv:req:spectate:end", () => {
|
||
emitNet("client:yaca:txadmin:stopspectate", source);
|
||
});
|
||
}
|
||
/**
|
||
* Handle various cases if player disconnects.
|
||
*
|
||
* @param {number} src - The source-id of the player who disconnected.
|
||
*/
|
||
handlePlayerDisconnect(src) {
|
||
var _a;
|
||
const player = this.players.get(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
this.nameSet.delete((_a = player.voiceSettings) == null ? void 0 : _a.ingameName);
|
||
const allFrequencies = this.radioModule.radioFrequencyMap;
|
||
for (const [key, value] of allFrequencies) {
|
||
value.delete(src);
|
||
if (!value.size) {
|
||
this.radioModule.radioFrequencyMap.delete(key);
|
||
}
|
||
}
|
||
for (const [targetId, emitterTargets] of player.voiceSettings.emittedPhoneSpeaker) {
|
||
const target = this.players.get(targetId);
|
||
if (!target || !target.voicePlugin) {
|
||
continue;
|
||
}
|
||
triggerClientEvent("client:yaca:phoneHearAround", Array.from(emitterTargets), [target.voicePlugin.clientId], false);
|
||
}
|
||
emitNet("client:yaca:disconnect", -1, src);
|
||
}
|
||
/**
|
||
* Syncs player alive status and mute him if he is dead or whatever.
|
||
*
|
||
* @param {number} src - The source-id of the player to sync.
|
||
* @param {boolean} alive - The new alive status.
|
||
*/
|
||
changePlayerAliveStatus(src, alive) {
|
||
const player = this.players.get(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
player.voiceSettings.forceMuted = !alive;
|
||
emitNet("client:yaca:muteTarget", -1, src, !alive);
|
||
if (player.voicePlugin) {
|
||
player.voicePlugin.forceMuted = !alive;
|
||
}
|
||
}
|
||
/**
|
||
* Get the alive status of a player.
|
||
*
|
||
* @param playerId - The ID of the player to get the alive status for.
|
||
*/
|
||
getPlayerAliveStatus(playerId) {
|
||
var _a;
|
||
return ((_a = this.players.get(playerId)) == null ? void 0 : _a.voiceSettings.forceMuted) ?? false;
|
||
}
|
||
/**
|
||
* Used if a player reconnects to the server.
|
||
*
|
||
* @param {number} src - The source-id of the player to reconnect.
|
||
*/
|
||
playerReconnect(src) {
|
||
const player = this.players.get(src);
|
||
if (!player) {
|
||
return;
|
||
}
|
||
if (!player.voiceSettings.voiceFirstConnect) {
|
||
return;
|
||
}
|
||
this.connect(src);
|
||
}
|
||
/**
|
||
* Change the voice range of a player.
|
||
*
|
||
* @param {number} src - The source-id of the player to change the voice range for.
|
||
* @param {number} range - The new voice range. Defaults to the default voice range if not provided.
|
||
*/
|
||
changeVoiceRange(src, range) {
|
||
const playerState = Player(src).state;
|
||
playerState.set(VOICE_RANGE_STATE_NAME, range ?? this.defaultVoiceRange, true);
|
||
emitNet("client:yaca:changeVoiceRange", src, range);
|
||
}
|
||
/**
|
||
* Get the voice range of a player.
|
||
*
|
||
* @param playerId - The ID of the player to get the voice range for.
|
||
*/
|
||
getPlayerVoiceRange(playerId) {
|
||
const playerState = Player(playerId).state;
|
||
return playerState[VOICE_RANGE_STATE_NAME] ?? this.defaultVoiceRange;
|
||
}
|
||
/**
|
||
* Sends initial data needed to connect to teamspeak plugin.
|
||
*
|
||
* @param {number} src - The source-id of the player to connect
|
||
*/
|
||
connect(src) {
|
||
const player = this.players.get(src);
|
||
if (!player) {
|
||
console.error(`YaCA: Missing player data for ${src}.`);
|
||
return;
|
||
}
|
||
player.voiceSettings.voiceFirstConnect = true;
|
||
const initObject = {
|
||
suid: this.serverConfig.uniqueServerId,
|
||
chid: this.serverConfig.ingameChannelId,
|
||
deChid: this.serverConfig.defaultChannelId,
|
||
channelPassword: this.serverConfig.ingameChannelPassword,
|
||
ingameName: player.voiceSettings.ingameName,
|
||
useWhisper: this.serverConfig.useWhisper,
|
||
excludeChannels: this.serverConfig.excludeChannels
|
||
};
|
||
emitNet("client:yaca:init", src, initObject);
|
||
}
|
||
/**
|
||
* Add new player to all other players on connect or reconnect, so they know about some variables.
|
||
*
|
||
* @param src - The source-id of the player to add.
|
||
* @param {number} clientId - The client ID of the player.
|
||
*/
|
||
addNewPlayer(src, clientId) {
|
||
const player = this.players.get(src);
|
||
if (!player || !clientId) {
|
||
return;
|
||
}
|
||
player.voicePlugin = {
|
||
playerId: src,
|
||
clientId,
|
||
forceMuted: player.voiceSettings.forceMuted,
|
||
mutedOnPhone: player.voiceSettings.mutedOnPhone
|
||
};
|
||
emitNet("client:yaca:addPlayers", -1, player.voicePlugin);
|
||
const allPlayersData = [];
|
||
for (const playerSource of getPlayers()) {
|
||
const intPlayerSource = Number.parseInt(playerSource);
|
||
const playerServer = this.players.get(intPlayerSource);
|
||
if (!playerServer) {
|
||
continue;
|
||
}
|
||
if (!playerServer.voicePlugin || intPlayerSource === src) {
|
||
continue;
|
||
}
|
||
allPlayersData.push(playerServer.voicePlugin);
|
||
}
|
||
emitNet("client:yaca:addPlayers", src, allPlayersData);
|
||
}
|
||
};
|
||
|
||
// src/index.ts
|
||
new YaCAServerModule();
|
||
/*! Bundled license information:
|
||
|
||
web-streams-polyfill/dist/ponyfill.es2018.js:
|
||
(**
|
||
* @license
|
||
* web-streams-polyfill v3.3.3
|
||
* Copyright 2024 Mattias Buelens, Diwank Singh Tomer and other contributors.
|
||
* This code is released under the MIT license.
|
||
* SPDX-License-Identifier: MIT
|
||
*)
|
||
|
||
fetch-blob/index.js:
|
||
(*! fetch-blob. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> *)
|
||
|
||
formdata-polyfill/esm.min.js:
|
||
(*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> *)
|
||
|
||
node-domexception/index.js:
|
||
(*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> *)
|
||
*/
|