{"version":3,"file":"scramjet.shared.js","sources":["webpack://@mercuryworkshop/scramjet/./rewriter/wasm/out/wasm.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/parse-domain@8.2.2/node_modules/parse-domain/build/parse-domain.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/decode_codepoint.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/decode.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/htmlparser2@9.1.0/node_modules/htmlparser2/lib/esm/Tokenizer.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/domelementtype@2.3.0/node_modules/domelementtype/lib/esm/index.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/index.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/domutils@3.1.0/node_modules/domutils/lib/esm/helpers.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/parse-domain@8.2.2/node_modules/parse-domain/build/sanitize.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/set-cookie-parser@2.7.1/node_modules/set-cookie-parser/lib/set-cookie.js","webpack://@mercuryworkshop/scramjet/./src/scramjet.ts","webpack://@mercuryworkshop/scramjet/./rewriter/wasm/out/snippets/wasm-4b0f351a8e6eeb46/inline0.js","webpack://@mercuryworkshop/scramjet/./src/shared/rewriters/js.ts","webpack://@mercuryworkshop/scramjet/./src/shared/rewriters/url.ts","webpack://@mercuryworkshop/scramjet/./src/shared/rewriters/css.ts","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/generated/decode-data-html.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/generated/decode-data-xml.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/htmlparser2@9.1.0/node_modules/htmlparser2/lib/esm/Parser.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/domhandler@5.0.3/node_modules/domhandler/lib/esm/node.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/domhandler@5.0.3/node_modules/domhandler/lib/esm/index.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/escape.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/entities@4.5.0/node_modules/entities/lib/esm/encode.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/dom-serializer@2.0.0/node_modules/dom-serializer/lib/esm/foreignNames.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/dom-serializer@2.0.0/node_modules/dom-serializer/lib/esm/index.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/domutils@3.1.0/node_modules/domutils/lib/esm/stringify.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/domutils@3.1.0/node_modules/domutils/lib/esm/legacy.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/domutils@3.1.0/node_modules/domutils/lib/esm/feeds.js","webpack://@mercuryworkshop/scramjet/./src/shared/rewriters/html.ts","webpack://@mercuryworkshop/scramjet/./src/shared/rewriters/headers.ts","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/@mercuryworkshop+bare-mux@2.1.7/node_modules/@mercuryworkshop/bare-mux/dist/index.mjs","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/parse-domain@8.2.2/node_modules/parse-domain/build/trie/look-up.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/parse-domain@8.2.2/node_modules/parse-domain/build/trie/characters.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/ip-regex@5.0.0/node_modules/ip-regex/index.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/is-regexp@3.1.0/node_modules/is-regexp/index.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/clone-regexp@3.0.0/node_modules/clone-regexp/index.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/super-regex@0.2.0/node_modules/super-regex/index.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/function-timeout@0.1.1/node_modules/function-timeout/browser.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/is-ip@5.0.1/node_modules/is-ip/index.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/parse-domain@8.2.2/node_modules/parse-domain/build/trie/nodes.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/parse-domain@8.2.2/node_modules/parse-domain/build/trie/parse-trie.js","webpack://@mercuryworkshop/scramjet/./src/shared/index.ts","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/parse-domain@8.2.2/node_modules/parse-domain/serialized-tries/icann.js","webpack://@mercuryworkshop/scramjet/./node_modules/.pnpm/parse-domain@8.2.2/node_modules/parse-domain/serialized-tries/private.js","webpack://@mercuryworkshop/scramjet/./src/shared/headers.ts","webpack://@mercuryworkshop/scramjet/./src/shared/rewriters/worker.ts","webpack://@mercuryworkshop/scramjet/./src/shared/cookie.ts"],"sourcesContent":["import { scramtag } from './snippets/wasm-4b0f351a8e6eeb46/inline0.js';\n\nlet wasm;\n\nfunction addToExternrefTable0(obj) {\n const idx = wasm.__externref_table_alloc();\n wasm.__wbindgen_export_2.set(idx, obj);\n return idx;\n}\n\nfunction handleError(f, args) {\n try {\n return f.apply(this, args);\n } catch (e) {\n const idx = addToExternrefTable0(e);\n wasm.__wbindgen_exn_store(idx);\n }\n}\n\nconst cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );\n\nif (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };\n\nlet cachedUint8ArrayMemory0 = null;\n\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm.memory.buffer) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return cachedTextDecoder.decode(getUint8ArrayMemory0().slice(ptr, ptr + len));\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nconst cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );\n\nconst encodeString = function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n};\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = encodeString(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nlet cachedDataViewMemory0 = null;\n\nfunction getDataViewMemory0() {\n if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer !== wasm.memory.buffer) {\n cachedDataViewMemory0 = new DataView(wasm.memory.buffer);\n }\n return cachedDataViewMemory0;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nfunction getArrayU8FromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);\n}\n\nfunction takeFromExternrefTable0(idx) {\n const value = wasm.__wbindgen_export_2.get(idx);\n wasm.__externref_table_dealloc(idx);\n return value;\n}\n/**\n * @param {string} js\n * @param {string} url\n * @param {string} script_url\n * @param {object} scramjet\n * @returns {RewriterOutput}\n */\nexport function rewrite_js(js, url, script_url, scramjet) {\n const ptr0 = passStringToWasm0(js, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(script_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len2 = WASM_VECTOR_LEN;\n const ret = wasm.rewrite_js(ptr0, len0, ptr1, len1, ptr2, len2, scramjet);\n if (ret[2]) {\n throw takeFromExternrefTable0(ret[1]);\n }\n return takeFromExternrefTable0(ret[0]);\n}\n\nfunction passArray8ToWasm0(arg, malloc) {\n const ptr = malloc(arg.length * 1, 1) >>> 0;\n getUint8ArrayMemory0().set(arg, ptr / 1);\n WASM_VECTOR_LEN = arg.length;\n return ptr;\n}\n/**\n * @param {Uint8Array} js\n * @param {string} url\n * @param {string} script_url\n * @param {object} scramjet\n * @returns {RewriterOutput}\n */\nexport function rewrite_js_from_arraybuffer(js, url, script_url, scramjet) {\n const ptr0 = passArray8ToWasm0(js, wasm.__wbindgen_malloc);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(script_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len2 = WASM_VECTOR_LEN;\n const ret = wasm.rewrite_js_from_arraybuffer(ptr0, len0, ptr1, len1, ptr2, len2, scramjet);\n if (ret[2]) {\n throw takeFromExternrefTable0(ret[1]);\n }\n return takeFromExternrefTable0(ret[0]);\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n\n } catch (e) {\n if (module.headers.get('Content-Type') != 'application/wasm') {\n console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\", e);\n\n } else {\n throw e;\n }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n\n } else {\n return instance;\n }\n }\n}\n\nfunction __wbg_get_imports() {\n const imports = {};\n imports.wbg = {};\n imports.wbg.__wbg_call_3b770f0d6eb4720e = function() { return handleError(function (arg0, arg1, arg2, arg3) {\n const ret = arg0.call(arg1, arg2, arg3);\n return ret;\n }, arguments) };\n imports.wbg.__wbg_call_500db948e69c7330 = function() { return handleError(function (arg0, arg1, arg2) {\n const ret = arg0.call(arg1, arg2);\n return ret;\n }, arguments) };\n imports.wbg.__wbg_call_b0d8e36992d9900d = function() { return handleError(function (arg0, arg1) {\n const ret = arg0.call(arg1);\n return ret;\n }, arguments) };\n imports.wbg.__wbg_get_bbccf8970793c087 = function() { return handleError(function (arg0, arg1) {\n const ret = Reflect.get(arg0, arg1);\n return ret;\n }, arguments) };\n imports.wbg.__wbg_new_17f755666e48d1d8 = function() { return handleError(function (arg0, arg1) {\n const ret = new URL(getStringFromWasm0(arg0, arg1));\n return ret;\n }, arguments) };\n imports.wbg.__wbg_new_254fa9eac11932ae = function() {\n const ret = new Array();\n return ret;\n };\n imports.wbg.__wbg_new_688846f374351c92 = function() {\n const ret = new Object();\n return ret;\n };\n imports.wbg.__wbg_newnoargs_fd9e4bf8be2bc16d = function(arg0, arg1) {\n const ret = new Function(getStringFromWasm0(arg0, arg1));\n return ret;\n };\n imports.wbg.__wbg_newwithbase_aa2c471fe3eacc2b = function() { return handleError(function (arg0, arg1, arg2, arg3) {\n const ret = new URL(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));\n return ret;\n }, arguments) };\n imports.wbg.__wbg_now_62a101fe35b60230 = function(arg0) {\n const ret = arg0.now();\n return ret;\n };\n imports.wbg.__wbg_scramtag_bd98edaa0eaec45e = function(arg0) {\n const ret = scramtag();\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);\n getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);\n };\n imports.wbg.__wbg_set_4e647025551483bd = function() { return handleError(function (arg0, arg1, arg2) {\n const ret = Reflect.set(arg0, arg1, arg2);\n return ret;\n }, arguments) };\n imports.wbg.__wbg_static_accessor_GLOBAL_0be7472e492ad3e3 = function() {\n const ret = typeof global === 'undefined' ? null : global;\n return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);\n };\n imports.wbg.__wbg_static_accessor_GLOBAL_THIS_1a6eb482d12c9bfb = function() {\n const ret = typeof globalThis === 'undefined' ? null : globalThis;\n return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);\n };\n imports.wbg.__wbg_static_accessor_SELF_1dc398a895c82351 = function() {\n const ret = typeof self === 'undefined' ? null : self;\n return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);\n };\n imports.wbg.__wbg_static_accessor_WINDOW_ae1c80c7eea8d64a = function() {\n const ret = typeof window === 'undefined' ? null : window;\n return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);\n };\n imports.wbg.__wbg_toString_a491ccf7be1ca5c9 = function(arg0) {\n const ret = arg0.toString();\n return ret;\n };\n imports.wbg.__wbg_toString_cbcf95f260c441ae = function(arg0) {\n const ret = arg0.toString();\n return ret;\n };\n imports.wbg.__wbindgen_boolean_get = function(arg0) {\n const v = arg0;\n const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;\n return ret;\n };\n imports.wbg.__wbindgen_error_new = function(arg0, arg1) {\n const ret = new Error(getStringFromWasm0(arg0, arg1));\n return ret;\n };\n imports.wbg.__wbindgen_init_externref_table = function() {\n const table = wasm.__wbindgen_export_2;\n const offset = table.grow(4);\n table.set(0, undefined);\n table.set(offset + 0, undefined);\n table.set(offset + 1, null);\n table.set(offset + 2, true);\n table.set(offset + 3, false);\n ;\n };\n imports.wbg.__wbindgen_is_function = function(arg0) {\n const ret = typeof(arg0) === 'function';\n return ret;\n };\n imports.wbg.__wbindgen_is_undefined = function(arg0) {\n const ret = arg0 === undefined;\n return ret;\n };\n imports.wbg.__wbindgen_number_new = function(arg0) {\n const ret = arg0;\n return ret;\n };\n imports.wbg.__wbindgen_string_get = function(arg0, arg1) {\n const obj = arg1;\n const ret = typeof(obj) === 'string' ? obj : undefined;\n var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n var len1 = WASM_VECTOR_LEN;\n getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);\n getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);\n };\n imports.wbg.__wbindgen_string_new = function(arg0, arg1) {\n const ret = getStringFromWasm0(arg0, arg1);\n return ret;\n };\n imports.wbg.__wbindgen_throw = function(arg0, arg1) {\n throw new Error(getStringFromWasm0(arg0, arg1));\n };\n imports.wbg.__wbindgen_uint8_array_new = function(arg0, arg1) {\n var v0 = getArrayU8FromWasm0(arg0, arg1).slice();\n wasm.__wbindgen_free(arg0, arg1 * 1, 1);\n const ret = v0;\n return ret;\n };\n\n return imports;\n}\n\nfunction __wbg_init_memory(imports, memory) {\n imports.wbg.memory = memory || new WebAssembly.Memory({initial:18,maximum:16384,shared:true});\n}\n\nfunction __wbg_finalize_init(instance, module, thread_stack_size) {\n wasm = instance.exports;\n __wbg_init.__wbindgen_wasm_module = module;\n cachedDataViewMemory0 = null;\n cachedUint8ArrayMemory0 = null;\n\n if (typeof thread_stack_size !== 'undefined' && (typeof thread_stack_size !== 'number' || thread_stack_size === 0 || thread_stack_size % 65536 !== 0)) { throw 'invalid stack size' }\n wasm.__wbindgen_start(thread_stack_size);\n return wasm;\n}\n\nfunction initSync(module, memory) {\n if (wasm !== undefined) return wasm;\n\n let thread_stack_size\n if (typeof module !== 'undefined') {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module, memory, thread_stack_size} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n\n __wbg_init_memory(imports, memory);\n\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n\n const instance = new WebAssembly.Instance(module, imports);\n\n return __wbg_finalize_init(instance, module, thread_stack_size);\n}\n\nasync function __wbg_init(module_or_path, memory) {\n if (wasm !== undefined) return wasm;\n\n let thread_stack_size\n if (typeof module_or_path !== 'undefined') {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path, memory, thread_stack_size} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (typeof module_or_path === 'undefined') {\n module_or_path = new URL('wasm_bg.wasm', \"\");\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n __wbg_init_memory(imports, memory);\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module, thread_stack_size);\n}\n\nexport { initSync };\nexport default __wbg_init;\n","import { icannTrie, privateTrie } from \"./serialized-tries.js\";\nimport { lookUpTldsInTrie } from \"./trie/look-up.js\";\nimport { sanitize, SanitizationResultType, } from \"./sanitize.js\";\nimport { parseTrie } from \"./trie/parse-trie.js\";\nexport const RESERVED_TOP_LEVEL_DOMAINS = [\n \"localhost\",\n \"local\",\n \"example\",\n \"invalid\",\n \"test\",\n];\nexport var ParseResultType;\n(function (ParseResultType) {\n /**\n * This parse result is returned in case the given hostname does not adhere to [RFC 1034](https://tools.ietf.org/html/rfc1034).\n */\n ParseResultType[\"Invalid\"] = \"INVALID\";\n /**\n * This parse result is returned if the given hostname was an IPv4 or IPv6.\n */\n ParseResultType[\"Ip\"] = \"IP\";\n /**\n * This parse result is returned when the given hostname\n * - is the root domain (the empty string `\"\"`)\n * - belongs to the top-level domain `localhost`, `local`, `example`, `invalid` or `test`\n */\n ParseResultType[\"Reserved\"] = \"RESERVED\";\n /**\n * This parse result is returned when the given hostname is valid and does not belong to a reserved top-level domain, but is not listed in the public suffix list.\n */\n ParseResultType[\"NotListed\"] = \"NOT_LISTED\";\n /**\n * This parse result is returned when the given hostname belongs to a top-level domain that is listed in the public suffix list.\n */\n ParseResultType[\"Listed\"] = \"LISTED\";\n})(ParseResultType || (ParseResultType = {}));\nconst getAtIndex = (array, index) => {\n return index >= 0 && index < array.length ? array[index] : undefined;\n};\nconst splitLabelsIntoDomains = (labels, index) => {\n return {\n subDomains: labels.slice(0, Math.max(0, index)),\n domain: getAtIndex(labels, index),\n topLevelDomains: labels.slice(index + 1),\n };\n};\nlet parsedIcannTrie;\nlet parsedPrivateTrie;\n/**\n * Splits the given hostname in topLevelDomains, a domain and subDomains.\n */\nexport const parseDomain = (hostname, options) => {\n const sanitizationResult = sanitize(hostname, options);\n if (sanitizationResult.type === SanitizationResultType.Error) {\n return {\n type: ParseResultType.Invalid,\n hostname,\n errors: sanitizationResult.errors,\n };\n }\n if (sanitizationResult.type === SanitizationResultType.ValidIp) {\n return {\n type: ParseResultType.Ip,\n hostname: sanitizationResult.ip,\n ipVersion: sanitizationResult.ipVersion,\n };\n }\n const { labels, domain } = sanitizationResult;\n if (hostname === \"\" ||\n RESERVED_TOP_LEVEL_DOMAINS.includes(labels[labels.length - 1])) {\n return {\n type: ParseResultType.Reserved,\n hostname: domain,\n labels,\n };\n }\n // Parse the serialized trie lazily\n parsedIcannTrie = parsedIcannTrie !== null && parsedIcannTrie !== void 0 ? parsedIcannTrie : parseTrie(icannTrie);\n parsedPrivateTrie = parsedPrivateTrie !== null && parsedPrivateTrie !== void 0 ? parsedPrivateTrie : parseTrie(privateTrie);\n const icannTlds = lookUpTldsInTrie(labels, parsedIcannTrie);\n const privateTlds = lookUpTldsInTrie(labels, parsedPrivateTrie);\n if (icannTlds.length === 0 && privateTlds.length === 0) {\n return {\n type: ParseResultType.NotListed,\n hostname: domain,\n labels,\n };\n }\n const indexOfPublicSuffixDomain = labels.length - Math.max(privateTlds.length, icannTlds.length) - 1;\n const indexOfIcannDomain = labels.length - icannTlds.length - 1;\n return Object.assign({ type: ParseResultType.Listed, hostname: domain, labels, icann: splitLabelsIntoDomains(labels, indexOfIcannDomain) }, splitLabelsIntoDomains(labels, indexOfPublicSuffixDomain));\n};\n//# sourceMappingURL=parse-domain.js.map","// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134\nvar _a;\nconst decodeMap = new Map([\n [0, 65533],\n // C1 Unicode control character reference replacements\n [128, 8364],\n [130, 8218],\n [131, 402],\n [132, 8222],\n [133, 8230],\n [134, 8224],\n [135, 8225],\n [136, 710],\n [137, 8240],\n [138, 352],\n [139, 8249],\n [140, 338],\n [142, 381],\n [145, 8216],\n [146, 8217],\n [147, 8220],\n [148, 8221],\n [149, 8226],\n [150, 8211],\n [151, 8212],\n [152, 732],\n [153, 8482],\n [154, 353],\n [155, 8250],\n [156, 339],\n [158, 382],\n [159, 376],\n]);\n/**\n * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.\n */\nexport const fromCodePoint = \n// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins\n(_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) {\n let output = \"\";\n if (codePoint > 0xffff) {\n codePoint -= 0x10000;\n output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);\n codePoint = 0xdc00 | (codePoint & 0x3ff);\n }\n output += String.fromCharCode(codePoint);\n return output;\n};\n/**\n * Replace the given code point with a replacement character if it is a\n * surrogate or is outside the valid range. Otherwise return the code\n * point unchanged.\n */\nexport function replaceCodePoint(codePoint) {\n var _a;\n if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {\n return 0xfffd;\n }\n return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;\n}\n/**\n * Replace the code point if relevant, then convert it to a string.\n *\n * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead.\n * @param codePoint The code point to decode.\n * @returns The decoded code point.\n */\nexport default function decodeCodePoint(codePoint) {\n return fromCodePoint(replaceCodePoint(codePoint));\n}\n//# sourceMappingURL=decode_codepoint.js.map","import htmlDecodeTree from \"./generated/decode-data-html.js\";\nimport xmlDecodeTree from \"./generated/decode-data-xml.js\";\nimport decodeCodePoint, { replaceCodePoint, fromCodePoint, } from \"./decode_codepoint.js\";\n// Re-export for use by eg. htmlparser2\nexport { htmlDecodeTree, xmlDecodeTree, decodeCodePoint };\nexport { replaceCodePoint, fromCodePoint } from \"./decode_codepoint.js\";\nvar CharCodes;\n(function (CharCodes) {\n CharCodes[CharCodes[\"NUM\"] = 35] = \"NUM\";\n CharCodes[CharCodes[\"SEMI\"] = 59] = \"SEMI\";\n CharCodes[CharCodes[\"EQUALS\"] = 61] = \"EQUALS\";\n CharCodes[CharCodes[\"ZERO\"] = 48] = \"ZERO\";\n CharCodes[CharCodes[\"NINE\"] = 57] = \"NINE\";\n CharCodes[CharCodes[\"LOWER_A\"] = 97] = \"LOWER_A\";\n CharCodes[CharCodes[\"LOWER_F\"] = 102] = \"LOWER_F\";\n CharCodes[CharCodes[\"LOWER_X\"] = 120] = \"LOWER_X\";\n CharCodes[CharCodes[\"LOWER_Z\"] = 122] = \"LOWER_Z\";\n CharCodes[CharCodes[\"UPPER_A\"] = 65] = \"UPPER_A\";\n CharCodes[CharCodes[\"UPPER_F\"] = 70] = \"UPPER_F\";\n CharCodes[CharCodes[\"UPPER_Z\"] = 90] = \"UPPER_Z\";\n})(CharCodes || (CharCodes = {}));\n/** Bit that needs to be set to convert an upper case ASCII character to lower case */\nconst TO_LOWER_BIT = 0b100000;\nexport var BinTrieFlags;\n(function (BinTrieFlags) {\n BinTrieFlags[BinTrieFlags[\"VALUE_LENGTH\"] = 49152] = \"VALUE_LENGTH\";\n BinTrieFlags[BinTrieFlags[\"BRANCH_LENGTH\"] = 16256] = \"BRANCH_LENGTH\";\n BinTrieFlags[BinTrieFlags[\"JUMP_TABLE\"] = 127] = \"JUMP_TABLE\";\n})(BinTrieFlags || (BinTrieFlags = {}));\nfunction isNumber(code) {\n return code >= CharCodes.ZERO && code <= CharCodes.NINE;\n}\nfunction isHexadecimalCharacter(code) {\n return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) ||\n (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F));\n}\nfunction isAsciiAlphaNumeric(code) {\n return ((code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) ||\n (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) ||\n isNumber(code));\n}\n/**\n * Checks if the given character is a valid end character for an entity in an attribute.\n *\n * Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error.\n * See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state\n */\nfunction isEntityInAttributeInvalidEnd(code) {\n return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code);\n}\nvar EntityDecoderState;\n(function (EntityDecoderState) {\n EntityDecoderState[EntityDecoderState[\"EntityStart\"] = 0] = \"EntityStart\";\n EntityDecoderState[EntityDecoderState[\"NumericStart\"] = 1] = \"NumericStart\";\n EntityDecoderState[EntityDecoderState[\"NumericDecimal\"] = 2] = \"NumericDecimal\";\n EntityDecoderState[EntityDecoderState[\"NumericHex\"] = 3] = \"NumericHex\";\n EntityDecoderState[EntityDecoderState[\"NamedEntity\"] = 4] = \"NamedEntity\";\n})(EntityDecoderState || (EntityDecoderState = {}));\nexport var DecodingMode;\n(function (DecodingMode) {\n /** Entities in text nodes that can end with any character. */\n DecodingMode[DecodingMode[\"Legacy\"] = 0] = \"Legacy\";\n /** Only allow entities terminated with a semicolon. */\n DecodingMode[DecodingMode[\"Strict\"] = 1] = \"Strict\";\n /** Entities in attributes have limitations on ending characters. */\n DecodingMode[DecodingMode[\"Attribute\"] = 2] = \"Attribute\";\n})(DecodingMode || (DecodingMode = {}));\n/**\n * Token decoder with support of writing partial entities.\n */\nexport class EntityDecoder {\n constructor(\n /** The tree used to decode entities. */\n decodeTree, \n /**\n * The function that is called when a codepoint is decoded.\n *\n * For multi-byte named entities, this will be called multiple times,\n * with the second codepoint, and the same `consumed` value.\n *\n * @param codepoint The decoded codepoint.\n * @param consumed The number of bytes consumed by the decoder.\n */\n emitCodePoint, \n /** An object that is used to produce errors. */\n errors) {\n this.decodeTree = decodeTree;\n this.emitCodePoint = emitCodePoint;\n this.errors = errors;\n /** The current state of the decoder. */\n this.state = EntityDecoderState.EntityStart;\n /** Characters that were consumed while parsing an entity. */\n this.consumed = 1;\n /**\n * The result of the entity.\n *\n * Either the result index of a numeric entity, or the codepoint of a\n * numeric entity.\n */\n this.result = 0;\n /** The current index in the decode tree. */\n this.treeIndex = 0;\n /** The number of characters that were consumed in excess. */\n this.excess = 1;\n /** The mode in which the decoder is operating. */\n this.decodeMode = DecodingMode.Strict;\n }\n /** Resets the instance to make it reusable. */\n startEntity(decodeMode) {\n this.decodeMode = decodeMode;\n this.state = EntityDecoderState.EntityStart;\n this.result = 0;\n this.treeIndex = 0;\n this.excess = 1;\n this.consumed = 1;\n }\n /**\n * Write an entity to the decoder. This can be called multiple times with partial entities.\n * If the entity is incomplete, the decoder will return -1.\n *\n * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the\n * entity is incomplete, and resume when the next string is written.\n *\n * @param string The string containing the entity (or a continuation of the entity).\n * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.\n * @returns The number of characters that were consumed, or -1 if the entity is incomplete.\n */\n write(str, offset) {\n switch (this.state) {\n case EntityDecoderState.EntityStart: {\n if (str.charCodeAt(offset) === CharCodes.NUM) {\n this.state = EntityDecoderState.NumericStart;\n this.consumed += 1;\n return this.stateNumericStart(str, offset + 1);\n }\n this.state = EntityDecoderState.NamedEntity;\n return this.stateNamedEntity(str, offset);\n }\n case EntityDecoderState.NumericStart: {\n return this.stateNumericStart(str, offset);\n }\n case EntityDecoderState.NumericDecimal: {\n return this.stateNumericDecimal(str, offset);\n }\n case EntityDecoderState.NumericHex: {\n return this.stateNumericHex(str, offset);\n }\n case EntityDecoderState.NamedEntity: {\n return this.stateNamedEntity(str, offset);\n }\n }\n }\n /**\n * Switches between the numeric decimal and hexadecimal states.\n *\n * Equivalent to the `Numeric character reference state` in the HTML spec.\n *\n * @param str The string containing the entity (or a continuation of the entity).\n * @param offset The current offset.\n * @returns The number of characters that were consumed, or -1 if the entity is incomplete.\n */\n stateNumericStart(str, offset) {\n if (offset >= str.length) {\n return -1;\n }\n if ((str.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {\n this.state = EntityDecoderState.NumericHex;\n this.consumed += 1;\n return this.stateNumericHex(str, offset + 1);\n }\n this.state = EntityDecoderState.NumericDecimal;\n return this.stateNumericDecimal(str, offset);\n }\n addToNumericResult(str, start, end, base) {\n if (start !== end) {\n const digitCount = end - start;\n this.result =\n this.result * Math.pow(base, digitCount) +\n parseInt(str.substr(start, digitCount), base);\n this.consumed += digitCount;\n }\n }\n /**\n * Parses a hexadecimal numeric entity.\n *\n * Equivalent to the `Hexademical character reference state` in the HTML spec.\n *\n * @param str The string containing the entity (or a continuation of the entity).\n * @param offset The current offset.\n * @returns The number of characters that were consumed, or -1 if the entity is incomplete.\n */\n stateNumericHex(str, offset) {\n const startIdx = offset;\n while (offset < str.length) {\n const char = str.charCodeAt(offset);\n if (isNumber(char) || isHexadecimalCharacter(char)) {\n offset += 1;\n }\n else {\n this.addToNumericResult(str, startIdx, offset, 16);\n return this.emitNumericEntity(char, 3);\n }\n }\n this.addToNumericResult(str, startIdx, offset, 16);\n return -1;\n }\n /**\n * Parses a decimal numeric entity.\n *\n * Equivalent to the `Decimal character reference state` in the HTML spec.\n *\n * @param str The string containing the entity (or a continuation of the entity).\n * @param offset The current offset.\n * @returns The number of characters that were consumed, or -1 if the entity is incomplete.\n */\n stateNumericDecimal(str, offset) {\n const startIdx = offset;\n while (offset < str.length) {\n const char = str.charCodeAt(offset);\n if (isNumber(char)) {\n offset += 1;\n }\n else {\n this.addToNumericResult(str, startIdx, offset, 10);\n return this.emitNumericEntity(char, 2);\n }\n }\n this.addToNumericResult(str, startIdx, offset, 10);\n return -1;\n }\n /**\n * Validate and emit a numeric entity.\n *\n * Implements the logic from the `Hexademical character reference start\n * state` and `Numeric character reference end state` in the HTML spec.\n *\n * @param lastCp The last code point of the entity. Used to see if the\n * entity was terminated with a semicolon.\n * @param expectedLength The minimum number of characters that should be\n * consumed. Used to validate that at least one digit\n * was consumed.\n * @returns The number of characters that were consumed.\n */\n emitNumericEntity(lastCp, expectedLength) {\n var _a;\n // Ensure we consumed at least one digit.\n if (this.consumed <= expectedLength) {\n (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);\n return 0;\n }\n // Figure out if this is a legit end of the entity\n if (lastCp === CharCodes.SEMI) {\n this.consumed += 1;\n }\n else if (this.decodeMode === DecodingMode.Strict) {\n return 0;\n }\n this.emitCodePoint(replaceCodePoint(this.result), this.consumed);\n if (this.errors) {\n if (lastCp !== CharCodes.SEMI) {\n this.errors.missingSemicolonAfterCharacterReference();\n }\n this.errors.validateNumericCharacterReference(this.result);\n }\n return this.consumed;\n }\n /**\n * Parses a named entity.\n *\n * Equivalent to the `Named character reference state` in the HTML spec.\n *\n * @param str The string containing the entity (or a continuation of the entity).\n * @param offset The current offset.\n * @returns The number of characters that were consumed, or -1 if the entity is incomplete.\n */\n stateNamedEntity(str, offset) {\n const { decodeTree } = this;\n let current = decodeTree[this.treeIndex];\n // The mask is the number of bytes of the value, including the current byte.\n let valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;\n for (; offset < str.length; offset++, this.excess++) {\n const char = str.charCodeAt(offset);\n this.treeIndex = determineBranch(decodeTree, current, this.treeIndex + Math.max(1, valueLength), char);\n if (this.treeIndex < 0) {\n return this.result === 0 ||\n // If we are parsing an attribute\n (this.decodeMode === DecodingMode.Attribute &&\n // We shouldn't have consumed any characters after the entity,\n (valueLength === 0 ||\n // And there should be no invalid characters.\n isEntityInAttributeInvalidEnd(char)))\n ? 0\n : this.emitNotTerminatedNamedEntity();\n }\n current = decodeTree[this.treeIndex];\n valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;\n // If the branch is a value, store it and continue\n if (valueLength !== 0) {\n // If the entity is terminated by a semicolon, we are done.\n if (char === CharCodes.SEMI) {\n return this.emitNamedEntityData(this.treeIndex, valueLength, this.consumed + this.excess);\n }\n // If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it.\n if (this.decodeMode !== DecodingMode.Strict) {\n this.result = this.treeIndex;\n this.consumed += this.excess;\n this.excess = 0;\n }\n }\n }\n return -1;\n }\n /**\n * Emit a named entity that was not terminated with a semicolon.\n *\n * @returns The number of characters consumed.\n */\n emitNotTerminatedNamedEntity() {\n var _a;\n const { result, decodeTree } = this;\n const valueLength = (decodeTree[result] & BinTrieFlags.VALUE_LENGTH) >> 14;\n this.emitNamedEntityData(result, valueLength, this.consumed);\n (_a = this.errors) === null || _a === void 0 ? void 0 : _a.missingSemicolonAfterCharacterReference();\n return this.consumed;\n }\n /**\n * Emit a named entity.\n *\n * @param result The index of the entity in the decode tree.\n * @param valueLength The number of bytes in the entity.\n * @param consumed The number of characters consumed.\n *\n * @returns The number of characters consumed.\n */\n emitNamedEntityData(result, valueLength, consumed) {\n const { decodeTree } = this;\n this.emitCodePoint(valueLength === 1\n ? decodeTree[result] & ~BinTrieFlags.VALUE_LENGTH\n : decodeTree[result + 1], consumed);\n if (valueLength === 3) {\n // For multi-byte values, we need to emit the second byte.\n this.emitCodePoint(decodeTree[result + 2], consumed);\n }\n return consumed;\n }\n /**\n * Signal to the parser that the end of the input was reached.\n *\n * Remaining data will be emitted and relevant errors will be produced.\n *\n * @returns The number of characters consumed.\n */\n end() {\n var _a;\n switch (this.state) {\n case EntityDecoderState.NamedEntity: {\n // Emit a named entity if we have one.\n return this.result !== 0 &&\n (this.decodeMode !== DecodingMode.Attribute ||\n this.result === this.treeIndex)\n ? this.emitNotTerminatedNamedEntity()\n : 0;\n }\n // Otherwise, emit a numeric entity if we have one.\n case EntityDecoderState.NumericDecimal: {\n return this.emitNumericEntity(0, 2);\n }\n case EntityDecoderState.NumericHex: {\n return this.emitNumericEntity(0, 3);\n }\n case EntityDecoderState.NumericStart: {\n (_a = this.errors) === null || _a === void 0 ? void 0 : _a.absenceOfDigitsInNumericCharacterReference(this.consumed);\n return 0;\n }\n case EntityDecoderState.EntityStart: {\n // Return 0 if we have no entity.\n return 0;\n }\n }\n }\n}\n/**\n * Creates a function that decodes entities in a string.\n *\n * @param decodeTree The decode tree.\n * @returns A function that decodes entities in a string.\n */\nfunction getDecoder(decodeTree) {\n let ret = \"\";\n const decoder = new EntityDecoder(decodeTree, (str) => (ret += fromCodePoint(str)));\n return function decodeWithTrie(str, decodeMode) {\n let lastIndex = 0;\n let offset = 0;\n while ((offset = str.indexOf(\"&\", offset)) >= 0) {\n ret += str.slice(lastIndex, offset);\n decoder.startEntity(decodeMode);\n const len = decoder.write(str, \n // Skip the \"&\"\n offset + 1);\n if (len < 0) {\n lastIndex = offset + decoder.end();\n break;\n }\n lastIndex = offset + len;\n // If `len` is 0, skip the current `&` and continue.\n offset = len === 0 ? lastIndex + 1 : lastIndex;\n }\n const result = ret + str.slice(lastIndex);\n // Make sure we don't keep a reference to the final string.\n ret = \"\";\n return result;\n };\n}\n/**\n * Determines the branch of the current node that is taken given the current\n * character. This function is used to traverse the trie.\n *\n * @param decodeTree The trie.\n * @param current The current node.\n * @param nodeIdx The index right after the current node and its value.\n * @param char The current character.\n * @returns The index of the next node, or -1 if no branch is taken.\n */\nexport function determineBranch(decodeTree, current, nodeIdx, char) {\n const branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;\n const jumpOffset = current & BinTrieFlags.JUMP_TABLE;\n // Case 1: Single branch encoded in jump offset\n if (branchCount === 0) {\n return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1;\n }\n // Case 2: Multiple branches encoded in jump table\n if (jumpOffset) {\n const value = char - jumpOffset;\n return value < 0 || value >= branchCount\n ? -1\n : decodeTree[nodeIdx + value] - 1;\n }\n // Case 3: Multiple branches encoded in dictionary\n // Binary search for the character.\n let lo = nodeIdx;\n let hi = lo + branchCount - 1;\n while (lo <= hi) {\n const mid = (lo + hi) >>> 1;\n const midVal = decodeTree[mid];\n if (midVal < char) {\n lo = mid + 1;\n }\n else if (midVal > char) {\n hi = mid - 1;\n }\n else {\n return decodeTree[mid + branchCount];\n }\n }\n return -1;\n}\nconst htmlDecoder = getDecoder(htmlDecodeTree);\nconst xmlDecoder = getDecoder(xmlDecodeTree);\n/**\n * Decodes an HTML string.\n *\n * @param str The string to decode.\n * @param mode The decoding mode.\n * @returns The decoded string.\n */\nexport function decodeHTML(str, mode = DecodingMode.Legacy) {\n return htmlDecoder(str, mode);\n}\n/**\n * Decodes an HTML string in an attribute.\n *\n * @param str The string to decode.\n * @returns The decoded string.\n */\nexport function decodeHTMLAttribute(str) {\n return htmlDecoder(str, DecodingMode.Attribute);\n}\n/**\n * Decodes an HTML string, requiring all entities to be terminated by a semicolon.\n *\n * @param str The string to decode.\n * @returns The decoded string.\n */\nexport function decodeHTMLStrict(str) {\n return htmlDecoder(str, DecodingMode.Strict);\n}\n/**\n * Decodes an XML string, requiring all entities to be terminated by a semicolon.\n *\n * @param str The string to decode.\n * @returns The decoded string.\n */\nexport function decodeXML(str) {\n return xmlDecoder(str, DecodingMode.Strict);\n}\n//# sourceMappingURL=decode.js.map","import { EntityDecoder, DecodingMode, htmlDecodeTree, xmlDecodeTree, } from \"entities/lib/decode.js\";\nvar CharCodes;\n(function (CharCodes) {\n CharCodes[CharCodes[\"Tab\"] = 9] = \"Tab\";\n CharCodes[CharCodes[\"NewLine\"] = 10] = \"NewLine\";\n CharCodes[CharCodes[\"FormFeed\"] = 12] = \"FormFeed\";\n CharCodes[CharCodes[\"CarriageReturn\"] = 13] = \"CarriageReturn\";\n CharCodes[CharCodes[\"Space\"] = 32] = \"Space\";\n CharCodes[CharCodes[\"ExclamationMark\"] = 33] = \"ExclamationMark\";\n CharCodes[CharCodes[\"Number\"] = 35] = \"Number\";\n CharCodes[CharCodes[\"Amp\"] = 38] = \"Amp\";\n CharCodes[CharCodes[\"SingleQuote\"] = 39] = \"SingleQuote\";\n CharCodes[CharCodes[\"DoubleQuote\"] = 34] = \"DoubleQuote\";\n CharCodes[CharCodes[\"Dash\"] = 45] = \"Dash\";\n CharCodes[CharCodes[\"Slash\"] = 47] = \"Slash\";\n CharCodes[CharCodes[\"Zero\"] = 48] = \"Zero\";\n CharCodes[CharCodes[\"Nine\"] = 57] = \"Nine\";\n CharCodes[CharCodes[\"Semi\"] = 59] = \"Semi\";\n CharCodes[CharCodes[\"Lt\"] = 60] = \"Lt\";\n CharCodes[CharCodes[\"Eq\"] = 61] = \"Eq\";\n CharCodes[CharCodes[\"Gt\"] = 62] = \"Gt\";\n CharCodes[CharCodes[\"Questionmark\"] = 63] = \"Questionmark\";\n CharCodes[CharCodes[\"UpperA\"] = 65] = \"UpperA\";\n CharCodes[CharCodes[\"LowerA\"] = 97] = \"LowerA\";\n CharCodes[CharCodes[\"UpperF\"] = 70] = \"UpperF\";\n CharCodes[CharCodes[\"LowerF\"] = 102] = \"LowerF\";\n CharCodes[CharCodes[\"UpperZ\"] = 90] = \"UpperZ\";\n CharCodes[CharCodes[\"LowerZ\"] = 122] = \"LowerZ\";\n CharCodes[CharCodes[\"LowerX\"] = 120] = \"LowerX\";\n CharCodes[CharCodes[\"OpeningSquareBracket\"] = 91] = \"OpeningSquareBracket\";\n})(CharCodes || (CharCodes = {}));\n/** All the states the tokenizer can be in. */\nvar State;\n(function (State) {\n State[State[\"Text\"] = 1] = \"Text\";\n State[State[\"BeforeTagName\"] = 2] = \"BeforeTagName\";\n State[State[\"InTagName\"] = 3] = \"InTagName\";\n State[State[\"InSelfClosingTag\"] = 4] = \"InSelfClosingTag\";\n State[State[\"BeforeClosingTagName\"] = 5] = \"BeforeClosingTagName\";\n State[State[\"InClosingTagName\"] = 6] = \"InClosingTagName\";\n State[State[\"AfterClosingTagName\"] = 7] = \"AfterClosingTagName\";\n // Attributes\n State[State[\"BeforeAttributeName\"] = 8] = \"BeforeAttributeName\";\n State[State[\"InAttributeName\"] = 9] = \"InAttributeName\";\n State[State[\"AfterAttributeName\"] = 10] = \"AfterAttributeName\";\n State[State[\"BeforeAttributeValue\"] = 11] = \"BeforeAttributeValue\";\n State[State[\"InAttributeValueDq\"] = 12] = \"InAttributeValueDq\";\n State[State[\"InAttributeValueSq\"] = 13] = \"InAttributeValueSq\";\n State[State[\"InAttributeValueNq\"] = 14] = \"InAttributeValueNq\";\n // Declarations\n State[State[\"BeforeDeclaration\"] = 15] = \"BeforeDeclaration\";\n State[State[\"InDeclaration\"] = 16] = \"InDeclaration\";\n // Processing instructions\n State[State[\"InProcessingInstruction\"] = 17] = \"InProcessingInstruction\";\n // Comments & CDATA\n State[State[\"BeforeComment\"] = 18] = \"BeforeComment\";\n State[State[\"CDATASequence\"] = 19] = \"CDATASequence\";\n State[State[\"InSpecialComment\"] = 20] = \"InSpecialComment\";\n State[State[\"InCommentLike\"] = 21] = \"InCommentLike\";\n // Special tags\n State[State[\"BeforeSpecialS\"] = 22] = \"BeforeSpecialS\";\n State[State[\"BeforeSpecialT\"] = 23] = \"BeforeSpecialT\";\n State[State[\"SpecialStartSequence\"] = 24] = \"SpecialStartSequence\";\n State[State[\"InSpecialTag\"] = 25] = \"InSpecialTag\";\n State[State[\"InEntity\"] = 26] = \"InEntity\";\n})(State || (State = {}));\nfunction isWhitespace(c) {\n return (c === CharCodes.Space ||\n c === CharCodes.NewLine ||\n c === CharCodes.Tab ||\n c === CharCodes.FormFeed ||\n c === CharCodes.CarriageReturn);\n}\nfunction isEndOfTagSection(c) {\n return c === CharCodes.Slash || c === CharCodes.Gt || isWhitespace(c);\n}\nfunction isASCIIAlpha(c) {\n return ((c >= CharCodes.LowerA && c <= CharCodes.LowerZ) ||\n (c >= CharCodes.UpperA && c <= CharCodes.UpperZ));\n}\nexport var QuoteType;\n(function (QuoteType) {\n QuoteType[QuoteType[\"NoValue\"] = 0] = \"NoValue\";\n QuoteType[QuoteType[\"Unquoted\"] = 1] = \"Unquoted\";\n QuoteType[QuoteType[\"Single\"] = 2] = \"Single\";\n QuoteType[QuoteType[\"Double\"] = 3] = \"Double\";\n})(QuoteType || (QuoteType = {}));\n/**\n * Sequences used to match longer strings.\n *\n * We don't have `Script`, `Style`, or `Title` here. Instead, we re-use the *End\n * sequences with an increased offset.\n */\nconst Sequences = {\n Cdata: new Uint8Array([0x43, 0x44, 0x41, 0x54, 0x41, 0x5b]), // CDATA[\n CdataEnd: new Uint8Array([0x5d, 0x5d, 0x3e]), // ]]>\n CommentEnd: new Uint8Array([0x2d, 0x2d, 0x3e]), // `-->`\n ScriptEnd: new Uint8Array([0x3c, 0x2f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74]), // ` this.emitCodePoint(cp, consumed));\n }\n reset() {\n this.state = State.Text;\n this.buffer = \"\";\n this.sectionStart = 0;\n this.index = 0;\n this.baseState = State.Text;\n this.currentSequence = undefined;\n this.running = true;\n this.offset = 0;\n }\n write(chunk) {\n this.offset += this.buffer.length;\n this.buffer = chunk;\n this.parse();\n }\n end() {\n if (this.running)\n this.finish();\n }\n pause() {\n this.running = false;\n }\n resume() {\n this.running = true;\n if (this.index < this.buffer.length + this.offset) {\n this.parse();\n }\n }\n stateText(c) {\n if (c === CharCodes.Lt ||\n (!this.decodeEntities && this.fastForwardTo(CharCodes.Lt))) {\n if (this.index > this.sectionStart) {\n this.cbs.ontext(this.sectionStart, this.index);\n }\n this.state = State.BeforeTagName;\n this.sectionStart = this.index;\n }\n else if (this.decodeEntities && c === CharCodes.Amp) {\n this.startEntity();\n }\n }\n stateSpecialStartSequence(c) {\n const isEnd = this.sequenceIndex === this.currentSequence.length;\n const isMatch = isEnd\n ? // If we are at the end of the sequence, make sure the tag name has ended\n isEndOfTagSection(c)\n : // Otherwise, do a case-insensitive comparison\n (c | 0x20) === this.currentSequence[this.sequenceIndex];\n if (!isMatch) {\n this.isSpecial = false;\n }\n else if (!isEnd) {\n this.sequenceIndex++;\n return;\n }\n this.sequenceIndex = 0;\n this.state = State.InTagName;\n this.stateInTagName(c);\n }\n /** Look for an end tag. For