UNPKG

rsbuild-plugin-react-router

Version:
1,138 lines (1,137 loc) 546 kB
let globalStore, o, origin, bigint1e6, characters, charactersLength, O, quoteValue, whitespace, options, boundaries, description, options1, f; import { existsSync, mkdirSync, readFileSync, realpathSync, watch, writeFileSync } from "node:fs"; import fs_extra from "fs-extra"; import { rspack } from "@rsbuild/core"; import { createJiti } from "jiti"; import { dirname, isAbsolute, join as external_pathe_join, relative, resolve as external_pathe_resolve } from "pathe"; import { availableParallelism, cpus } from "node:os"; import { createRequestHandler as external_react_router_createRequestHandler, matchRoutes } from "react-router"; import { access, mkdir, readdir, writeFile } from "node:fs/promises"; import { pathToFileURL, fileURLToPath as __rspack_fileURLToPath } from "node:url"; import { createHash } from "node:crypto"; import jsesc from "jsesc"; import { Worker } from "node:worker_threads"; import { createRequire } from "node:module"; import { dirname as external_node_path_dirname, isAbsolute as external_node_path_isAbsolute, relative as external_node_path_relative, resolve as external_node_path_resolve, sep as external_node_path_sep, dirname as __rspack_dirname } from "node:path"; import { createRouteId, HMR_PATCHABLE_ROUTE_FLAGS, SERVER_EXPORTS, combineURLs, JS_EXTENSIONS, executeRouteTransformTask, setBoundedCacheEntry, PLUGIN_NAME, generateWithProps, getRouteModuleAnalysis, createEmptyRouteChunkByExportName, findEntryFile, routeChunkExportNames, validateRouteChunks, CLIENT_EXPORTS, buildManifestChunkValidity, BUILD_CLIENT_ROUTE_QUERY_STRING, getRouteChunkEntryName, getRouteChunkModuleId, normalizeAssetPrefix, detectRouteChunksIfEnabled, createBundlerRouteExportResolver } from "./451.js"; let getAvailableCpuCount = ()=>'function' == typeof availableParallelism ? availableParallelism() : cpus().length, getDefaultConcurrency = (cpuCount = getAvailableCpuCount())=>Math.max(0, Math.floor(cpuCount) - 2), getCappedPluginConcurrency = (cap = 16)=>Math.max(1, Math.min(cap, getDefaultConcurrency() || 1)), createReactRouterHydrationModuleTest = (entryClientPath)=>{ let eagerPatterns = [ 'virtual/react-router/browser-manifest', ...entryClientPath ? [ entryClientPath.replace(/\\/g, '/'), BUILD_CLIENT_ROUTE_QUERY_STRING, '?react-router-route' ] : [] ]; return (module)=>[ module.request, module.userRequest, module.rawRequest, module.resource, module.identifier?.(), module.nameForCondition?.() ].filter((value)=>!!value).some((value)=>{ let normalizedValue = value.replace(/\\/g, '/'); return eagerPatterns.some((pattern)=>normalizedValue.includes(pattern)); }); }, Function_dual = function(arity, body) { if ("function" == typeof arity) return function() { return arity(arguments) ? body.apply(this, arguments) : (self)=>body(self, ...arguments); }; switch(arity){ case 0: case 1: throw RangeError(`Invalid arity ${arity}`); case 2: return function(a, b) { return arguments.length >= 2 ? body(a, b) : function(self) { return body(self, a); }; }; case 3: return function(a, b, c) { return arguments.length >= 3 ? body(a, b, c) : function(self) { return body(self, a, b); }; }; case 4: return function(a, b, c, d) { return arguments.length >= 4 ? body(a, b, c, d) : function(self) { return body(self, a, b, c); }; }; case 5: return function(a, b, c, d, e) { return arguments.length >= 5 ? body(a, b, c, d, e) : function(self) { return body(self, a, b, c, d); }; }; default: return function() { if (arguments.length >= arity) return body.apply(this, arguments); let args = arguments; return function(self) { return body(self, ...args); }; }; } }, Function_identity = (a)=>a, constant = (value)=>()=>value, Function_constTrue = constant(!0), Function_constFalse = constant(!1), Function_constUndefined = constant(void 0); function Function_pipe(a, ab, bc, cd, de, ef, fg, gh, hi) { switch(arguments.length){ case 1: return a; case 2: return ab(a); case 3: return bc(ab(a)); case 4: return cd(bc(ab(a))); case 5: return de(cd(bc(ab(a)))); case 6: return ef(de(cd(bc(ab(a))))); case 7: return fg(ef(de(cd(bc(ab(a)))))); case 8: return gh(fg(ef(de(cd(bc(ab(a))))))); case 9: return hi(gh(fg(ef(de(cd(bc(ab(a)))))))); default: { let ret = arguments[0]; for(let i = 1; i < arguments.length; i++)ret = arguments[i](ret); return ret; } } } let globalStoreId = "effect/GlobalValue", GlobalValue_globalValue = (id, compute)=>(globalStore || (globalThis[globalStoreId] ??= new Map(), globalStore = globalThis[globalStoreId]), globalStore.has(id) || globalStore.set(id, compute()), globalStore.get(id)), isNumber = (input)=>"number" == typeof input, Predicate_isObject = (input)=>"object" == typeof input && null !== input || "function" == typeof input, Predicate_hasProperty = Function_dual(2, (self, property)=>Predicate_isObject(self) && property in self), Predicate_isTagged = Function_dual(2, (self, tag)=>Predicate_hasProperty(self, "_tag") && self._tag === tag), Predicate_isIterable = (input)=>"string" == typeof input || Predicate_hasProperty(input, Symbol.iterator), getBugErrorMessage = (message)=>`BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`; class SingleShotGen { self; called = !1; constructor(self){ this.self = self; } next(a) { return this.called ? { value: a, done: !0 } : (this.called = !0, { value: this.self, done: !1 }); } return(a) { return { value: a, done: !0 }; } throw(e) { throw e; } [Symbol.iterator]() { return new SingleShotGen(this.self); } } class PCGRandom { _state; constructor(seedHi, seedLo, incHi, incLo){ if (null == seedLo && null == seedHi) seedLo = 0xffffffff * Math.random() >>> 0, seedHi = 0; else null == seedLo && (seedLo = seedHi, seedHi = 0); if (null == incLo && null == incHi) incLo = this._state ? this._state[3] : 0xf767814f, incHi = this._state ? this._state[2] : 0x14057b7e; else null == incLo && (incLo = incHi, incHi = 0); return this._state = new Int32Array([ 0, 0, incHi >>> 0, (1 | (incLo || 0)) >>> 0 ]), this._next(), add64(this._state, this._state[0], this._state[1], seedHi >>> 0, seedLo >>> 0), this._next(), this; } getState() { return [ this._state[0], this._state[1], this._state[2], this._state[3] ]; } setState(state) { this._state[0] = state[0], this._state[1] = state[1], this._state[2] = state[2], this._state[3] = 1 | state[3]; } integer(max) { return Math.round(this.number() * Number.MAX_SAFE_INTEGER) % max; } number() { return (134217728.0 * ((0x03ffffff & this._next()) * 1.0) + (0x07ffffff & this._next()) * 1.0) / 9007199254740992.0; } _next() { var out, aHi, aLo; let c1, c0, lo, hi, oldHi = this._state[0] >>> 0, oldLo = this._state[1] >>> 0; out = this._state, aHi = oldHi, c1 = ((aLo = oldLo) >>> 16) * 32557 >>> 0, c0 = (0xffff & aLo) * 19605 >>> 0, lo = (0xffff & aLo) * 32557 >>> 0, hi = (aLo >>> 16) * 19605 + ((c0 >>> 16) + (c1 >>> 16)) >>> 0, (lo = lo + (c0 = c0 << 16 >>> 0) >>> 0) >>> 0 < c0 >>> 0 && (hi = hi + 1 >>> 0), (lo = lo + (c1 = c1 << 16 >>> 0) >>> 0) >>> 0 < c1 >>> 0 && (hi = hi + 1 >>> 0), hi = (hi = hi + Math.imul(aLo, 1481765933) >>> 0) + Math.imul(aHi, 1284865837) >>> 0, out[0] = hi, out[1] = lo, add64(this._state, this._state[0], this._state[1], this._state[2], this._state[3]); let xsHi = oldHi >>> 18, xsLo = (oldLo >>> 18 | oldHi << 14) >>> 0; xsHi = (xsHi ^ oldHi) >>> 0; let xorshifted = ((xsLo = (xsLo ^ oldLo) >>> 0) >>> 27 | xsHi << 5) >>> 0, rot = oldHi >>> 27; return (xorshifted >>> rot | xorshifted << ((-rot >>> 0 & 31) >>> 0)) >>> 0; } } function add64(out, aHi, aLo, bHi, bLo) { let hi = aHi + bHi >>> 0, lo = aLo + bLo >>> 0; lo >>> 0 < aLo >>> 0 && (hi = hi + 1 | 0), out[0] = hi, out[1] = lo; } let YieldWrapTypeId = Symbol.for("effect/Utils/YieldWrap"); class YieldWrap { #value; constructor(value){ this.#value = value; } [YieldWrapTypeId]() { return this.#value; } } let structuralRegionState = GlobalValue_globalValue("effect/Utils/isStructuralRegion", ()=>({ enabled: !1, tester: void 0 })), standard_effect_internal_function = (body)=>body(), internalCall = standard_effect_internal_function(()=>Error().stack)?.includes("effect_internal_function") === !0 ? standard_effect_internal_function : (body)=>body(), randomHashCache = GlobalValue_globalValue(Symbol.for("effect/Hash/randomHashCache"), ()=>new WeakMap()), Hash_symbol = Symbol.for("effect/Hash"), Hash_hash = (self)=>{ if (!0 === structuralRegionState.enabled) return 0; switch(typeof self){ case "number": return number(self); case "bigint": return Hash_string(self.toString(10)); case "boolean": case "symbol": return Hash_string(String(self)); case "string": return Hash_string(self); case "undefined": return Hash_string("undefined"); case "function": case "object": if (null === self) return Hash_string("null"); if (self instanceof Date) { if (Number.isNaN(self.getTime())) return Hash_string("Invalid Date"); return Hash_hash(self.toISOString()); } if (self instanceof URL) return Hash_hash(self.href); else if (isHash(self)) return self[Hash_symbol](); else return Hash_random(self); default: throw Error(`BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`); } }, Hash_random = (self)=>(randomHashCache.has(self) || randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER))), randomHashCache.get(self)), Hash_combine = (b)=>(self)=>53 * self ^ b, optimize = (n)=>0xbfffffff & n | n >>> 1 & 0x40000000, isHash = (u)=>Predicate_hasProperty(u, Hash_symbol), number = (n)=>{ if (n != n || n === 1 / 0) return 0; let h = 0 | n; for(h !== n && (h ^= 0xffffffff * n); n > 0xffffffff;)h ^= n /= 0xffffffff; return optimize(h); }, Hash_string = (str)=>{ let h = 5381, i = str.length; for(; i;)h = 33 * h ^ str.charCodeAt(--i); return optimize(h); }, structure = (o)=>((o, keys)=>{ let h = 12289; for(let i = 0; i < keys.length; i++)h ^= Function_pipe(Hash_string(keys[i]), Hash_combine(Hash_hash(o[keys[i]]))); return optimize(h); })(o, Object.keys(o)), Hash_array = (arr)=>{ let h = 6151; for(let i = 0; i < arr.length; i++)h = Function_pipe(h, Hash_combine(Hash_hash(arr[i]))); return optimize(h); }, Hash_cached = function() { if (1 == arguments.length) { let self = arguments[0]; return function(hash) { return Object.defineProperty(self, Hash_symbol, { value: ()=>hash, enumerable: !1 }), hash; }; } let self = arguments[0], hash = arguments[1]; return Object.defineProperty(self, Hash_symbol, { value: ()=>hash, enumerable: !1 }), hash; }, Equal_symbol = Symbol.for("effect/Equal"); function equals() { return 1 == arguments.length ? (self)=>compareBoth(self, arguments[0]) : compareBoth(arguments[0], arguments[1]); } function compareBoth(self, that) { if (self === that) return !0; let selfType = typeof self; if (selfType !== typeof that) return !1; if ("object" === selfType || "function" === selfType) { if (null !== self && null !== that) { if (isEqual(self) && isEqual(that)) if (Hash_hash(self) === Hash_hash(that) && self[Equal_symbol](that)) return !0; else return !!structuralRegionState.enabled && !!structuralRegionState.tester && structuralRegionState.tester(self, that); else if (self instanceof Date && that instanceof Date) { let t1 = self.getTime(), t2 = that.getTime(); return t1 === t2 || Number.isNaN(t1) && Number.isNaN(t2); } else if (self instanceof URL && that instanceof URL) return self.href === that.href; } if (structuralRegionState.enabled) { if (null === self || null === that) return !1; if (Array.isArray(self) && Array.isArray(that)) return self.length === that.length && self.every((v1, i)=>compareBoth(v1, that[i])); if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(that) === Object.prototype) { let keysSelf = Object.keys(self), keysThat = Object.keys(that); if (keysSelf.length === keysThat.length) { for (let key of keysSelf)if (!(key in that && compareBoth(self[key], that[key]))) return !!structuralRegionState.tester && structuralRegionState.tester(self, that); return !0; } } return !!structuralRegionState.tester && structuralRegionState.tester(self, that); } } return !!structuralRegionState.enabled && !!structuralRegionState.tester && structuralRegionState.tester(self, that); } let isEqual = (u)=>Predicate_hasProperty(u, Equal_symbol), Inspectable_NodeInspectSymbol = Symbol.for("nodejs.util.inspect.custom"), toJSON = (x)=>{ try { let input; if (Predicate_hasProperty(x, "toJSON") && (input = x.toJSON, "function" == typeof input) && 0 === x.toJSON.length) return x.toJSON(); if (Array.isArray(x)) return x.map(toJSON); } catch { return {}; } return redact(x); }, toStringUnknown = (u, whitespace = 2)=>{ if ("string" == typeof u) return u; try { return "object" == typeof u ? stringifyCircular(u, whitespace) : String(u); } catch { return String(u); } }, stringifyCircular = (obj, whitespace)=>{ let cache = [], retVal = JSON.stringify(obj, (_key, value)=>"object" == typeof value && null !== value ? cache.includes(value) ? void 0 : cache.push(value) && (void 0 !== redactableState.fiberRefs && isRedactable(value) ? value[symbolRedactable](redactableState.fiberRefs) : value) : value, whitespace); return cache = void 0, retVal; }, symbolRedactable = Symbol.for("effect/Inspectable/Redactable"), isRedactable = (u)=>"object" == typeof u && null !== u && symbolRedactable in u, redactableState = GlobalValue_globalValue("effect/Inspectable/redactableState", ()=>({ fiberRefs: void 0 })), redact = (u)=>isRedactable(u) && void 0 !== redactableState.fiberRefs ? u[symbolRedactable](redactableState.fiberRefs) : u, Pipeable_pipeArguments = (self, args)=>{ switch(args.length){ case 0: return self; case 1: return args[0](self); case 2: return args[1](args[0](self)); case 3: return args[2](args[1](args[0](self))); case 4: return args[3](args[2](args[1](args[0](self)))); case 5: return args[4](args[3](args[2](args[1](args[0](self))))); case 6: return args[5](args[4](args[3](args[2](args[1](args[0](self)))))); case 7: return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))); case 8: return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))); case 9: return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))))); default: { let ret = self; for(let i = 0, len = args.length; i < len; i++)ret = args[i](ret); return ret; } } }, getCurrentVersion = ()=>"3.21.4", EffectTypeId = Symbol.for("effect/Effect"), StreamTypeId = Symbol.for("effect/Stream"), SinkTypeId = Symbol.for("effect/Sink"), ChannelTypeId = Symbol.for("effect/Channel"), effectVariance = { _R: (_)=>_, _E: (_)=>_, _A: (_)=>_, _V: getCurrentVersion() }, EffectPrototype = { [EffectTypeId]: effectVariance, [StreamTypeId]: effectVariance, [SinkTypeId]: { _A: (_)=>_, _In: (_)=>_, _L: (_)=>_, _E: (_)=>_, _R: (_)=>_ }, [ChannelTypeId]: { _Env: (_)=>_, _InErr: (_)=>_, _InElem: (_)=>_, _InDone: (_)=>_, _OutErr: (_)=>_, _OutElem: (_)=>_, _OutDone: (_)=>_ }, [Equal_symbol] (that) { return this === that; }, [Hash_symbol] () { return Hash_cached(this, Hash_random(this)); }, [Symbol.iterator] () { return new SingleShotGen(new YieldWrap(this)); }, pipe () { return Pipeable_pipeArguments(this, arguments); } }, effectable_StructuralPrototype = { [Hash_symbol] () { return Hash_cached(this, structure(this)); }, [Equal_symbol] (that) { let selfKeys = Object.keys(this), thatKeys = Object.keys(that); if (selfKeys.length !== thatKeys.length) return !1; for (let key of selfKeys)if (!(key in that && equals(this[key], that[key]))) return !1; return !0; } }, CommitPrototype = { ...EffectPrototype, _op: "Commit" }, StructuralCommitPrototype = { ...CommitPrototype, ...effectable_StructuralPrototype }, effectable_Base = function() { function Base() {} return Base.prototype = CommitPrototype, Base; }(), TypeId = Symbol.for("effect/Option"), CommonProto = { ...EffectPrototype, [TypeId]: { _A: (_)=>_ }, [Inspectable_NodeInspectSymbol] () { return this.toJSON(); }, toString () { return JSON.stringify(this.toJSON(), null, 2); } }, SomeProto = Object.assign(Object.create(CommonProto), { _tag: "Some", _op: "Some", [Equal_symbol] (that) { return isOption(that) && isSome(that) && equals(this.value, that.value); }, [Hash_symbol] () { return Hash_cached(this, Hash_combine(Hash_hash(this._tag))(Hash_hash(this.value))); }, toJSON () { return { _id: "Option", _tag: this._tag, value: toJSON(this.value) }; } }), NoneHash = Hash_hash("None"), NoneProto = Object.assign(Object.create(CommonProto), { _tag: "None", _op: "None", [Equal_symbol]: (that)=>isOption(that) && isNone(that), [Hash_symbol]: ()=>NoneHash, toJSON () { return { _id: "Option", _tag: this._tag }; } }), isOption = (input)=>Predicate_hasProperty(input, TypeId), isNone = (fa)=>"None" === fa._tag, isSome = (fa)=>"Some" === fa._tag, option_none = Object.create(NoneProto), option_some = (value)=>{ let a = Object.create(SomeProto); return a.value = value, a; }, either_TypeId = Symbol.for("effect/Either"), either_CommonProto = { ...EffectPrototype, [either_TypeId]: { _R: (_)=>_ }, [Inspectable_NodeInspectSymbol] () { return this.toJSON(); }, toString () { return JSON.stringify(this.toJSON(), null, 2); } }, RightProto = Object.assign(Object.create(either_CommonProto), { _tag: "Right", _op: "Right", [Equal_symbol] (that) { return isEither(that) && isRight(that) && equals(this.right, that.right); }, [Hash_symbol] () { return Hash_combine(Hash_hash(this._tag))(Hash_hash(this.right)); }, toJSON () { return { _id: "Either", _tag: this._tag, right: toJSON(this.right) }; } }), LeftProto = Object.assign(Object.create(either_CommonProto), { _tag: "Left", _op: "Left", [Equal_symbol] (that) { return isEither(that) && isLeft(that) && equals(this.left, that.left); }, [Hash_symbol] () { return Hash_combine(Hash_hash(this._tag))(Hash_hash(this.left)); }, toJSON () { return { _id: "Either", _tag: this._tag, left: toJSON(this.left) }; } }), isEither = (input)=>Predicate_hasProperty(input, either_TypeId), isLeft = (ma)=>"Left" === ma._tag, isRight = (ma)=>"Right" === ma._tag, either_left = (left)=>{ let a = Object.create(LeftProto); return a.left = left, a; }, either_right = (right)=>{ let a = Object.create(RightProto); return a.right = right, a; }, merge = Function_dual(2, (self, { onLeft, onRight })=>isLeft(self) ? onLeft(self.left) : onRight(self.right))({ onLeft: Function_identity, onRight: Function_identity }), make = (isEquivalent)=>(self, that)=>self === that || isEquivalent(self, that), Equivalence_mapInput = Function_dual(2, (self, f)=>make((x, y)=>self(f(x), f(y)))), isNonEmptyArray = (self)=>self.length > 0, Option_none = ()=>option_none, Option_match = Function_dual(2, (self, { onNone, onSome })=>isNone(self) ? onNone() : onSome(self.value)), Option_getOrElse = Function_dual(2, (self, onNone)=>isNone(self) ? onNone() : self.value), orElseSome = Function_dual(2, (self, onNone)=>isNone(self) ? option_some(onNone()) : self), Option_fromNullable = (nullableValue)=>null == nullableValue ? Option_none() : option_some(nullableValue), Option_getOrUndefined = Option_getOrElse(Function_constUndefined), Option_getOrThrow = Function_dual(2, (self, onNone)=>{ if (isSome(self)) return self.value; throw onNone(); })(()=>Error("getOrThrow called on a None")), Option_map = Function_dual(2, (self, f)=>isNone(self) ? Option_none() : option_some(f(self.value))), Option_flatMap = Function_dual(2, (self, f)=>isNone(self) ? Option_none() : f(self.value)), contains = Function_dual(2, (self, a)=>!isNone(self) && equals(self.value, a)), mergeWith = (f)=>(o1, o2)=>isNone(o1) ? o2 : isNone(o2) ? o1 : option_some(f(o1.value, o2.value)), Order_make = (compare)=>(self, that)=>self === that ? 0 : compare(self, that), Order_number = Order_make((self, that)=>self < that ? -1 : 1), Order_mapInput = Function_dual(2, (self, f)=>Order_make((b1, b2)=>self(f(b1), f(b2)))), Tuple_make = (...elements)=>elements, Array_makeBy = Function_dual(2, (n, f)=>{ let max = Math.max(1, Math.floor(n)), out = Array(max); for(let i = 0; i < max; i++)out[i] = f(i); return out; }), Array_fromIterable = (collection)=>Array.isArray(collection) ? collection : Array.from(collection), ensure = (self)=>Array.isArray(self) ? self : [ self ], Array_prepend = Function_dual(2, (self, head)=>[ head, ...self ]), Array_append = Function_dual(2, (self, last)=>[ ...self, last ]), Array_appendAll = Function_dual(2, (self, that)=>Array_fromIterable(self).concat(Array_fromIterable(that))), isOutOfBounds = (i, as)=>i < 0 || i >= as.length, Array_get = Function_dual(2, (self, index)=>{ let i = Math.floor(index); return isOutOfBounds(i, self) ? Option_none() : option_some(self[i]); }), unsafeGet = Function_dual(2, (self, index)=>{ let i = Math.floor(index); if (isOutOfBounds(i, self)) throw Error(`Index ${i} out of bounds`); return self[i]; }), Array_head = Array_get(0), headNonEmpty = unsafeGet(0), lastNonEmpty = (self)=>self[self.length - 1], tailNonEmpty = (self)=>self.slice(1), Array_span = Function_dual(2, (self, predicate)=>splitAt(self, ((self, predicate)=>{ let i = 0; for (let a of self){ if (!predicate(a, i)) break; i++; } return i; })(self, predicate))), Array_drop = Function_dual(2, (self, n)=>{ let input = Array_fromIterable(self); return input.slice(Math.floor(Math.min(Math.max(0, n), input.length)), input.length); }), Array_reverse = (self)=>Array.from(self).reverse(), sort = Function_dual(2, (self, O)=>{ let out = Array.from(self); return out.sort(O), out; }), Array_zip = Function_dual(2, (self, that)=>Array_zipWith(self, that, Tuple_make)), Array_zipWith = Function_dual(3, (self, that, f)=>{ let as = Array_fromIterable(self), bs = Array_fromIterable(that); if (isNonEmptyArray(as) && isNonEmptyArray(bs)) { let out = [ f(headNonEmpty(as), headNonEmpty(bs)) ], len = Math.min(as.length, bs.length); for(let i = 1; i < len; i++)out[i] = f(as[i], bs[i]); return out; } return []; }), splitAt = Function_dual(2, (self, n)=>{ let input = Array.from(self), _n = Math.floor(n); return isNonEmptyArray(input) ? _n >= 1 ? splitNonEmptyAt(input, _n) : [ [], input ] : [ input, [] ]; }), splitNonEmptyAt = Function_dual(2, (self, n)=>{ let _n = Math.max(1, Math.floor(n)); return _n >= self.length ? [ copy(self), [] ] : [ Array_prepend(self.slice(1, _n), headNonEmpty(self)), self.slice(_n) ]; }), copy = (self)=>self.slice(), unionWith = Function_dual(3, (self, that, isEquivalent)=>{ let a = Array_fromIterable(self), b = Array_fromIterable(that); return isNonEmptyArray(a) ? isNonEmptyArray(b) ? dedupeWith(isEquivalent)(Array_appendAll(a, b)) : a : b; }), Array_union = Function_dual(2, (self, that)=>unionWith(self, that, equals)), Array_empty = ()=>[], Array_of = (a)=>[ a ], Array_map = Function_dual(2, (self, f)=>self.map(f)), Array_flatten = Function_dual(2, (self, f)=>{ if (0 === self.length) return []; let out = []; for(let i = 0; i < self.length; i++){ let inner = f(self[i], i); for(let j = 0; j < inner.length; j++)out.push(inner[j]); } return out; })(Function_identity), Array_filterMap = Function_dual(2, (self, f)=>{ let as = Array_fromIterable(self), out = []; for(let i = 0; i < as.length; i++){ let o = f(as[i], i); isSome(o) && out.push(o.value); } return out; }), Array_partitionMap = Function_dual(2, (self, f)=>{ let left = [], right = [], as = Array_fromIterable(self); for(let i = 0; i < as.length; i++){ let e = f(as[i], i); isLeft(e) ? left.push(e.left) : right.push(e.right); } return [ left, right ]; }), Array_reduce = Function_dual(3, (self, b, f)=>Array_fromIterable(self).reduce((b, a, i)=>f(b, a, i), b)), reduceRight = Function_dual(3, (self, b, f)=>Array_fromIterable(self).reduceRight((b, a, i)=>f(b, a, i), b)), Array_unfold = (b, f)=>{ let o, out = [], next = b; for(; isSome(o = f(next));){ let [a, b] = o.value; out.push(a), next = b; } return out; }, Array_getEquivalence = (item)=>make((self, that)=>{ if (self.length !== that.length) return !1; for(let i = 0; i < self.length; i++)if (!item(self[i], that[i])) return !1; return !0; }), dedupeWith = Function_dual(2, (self, isEquivalent)=>{ let input = Array_fromIterable(self); if (isNonEmptyArray(input)) { let out = [ headNonEmpty(input) ]; for (let r of tailNonEmpty(input))out.every((a)=>!isEquivalent(r, a)) && out.push(r); return out; } return []; }), Array_dedupe = (self)=>dedupeWith(self, equals), join = Function_dual(2, (self, sep)=>Array_fromIterable(self).join(sep)), Chunk_TypeId = Symbol.for("effect/Chunk"), emptyArray = [], Chunk_equivalence = make((self, that)=>self.length === that.length && toReadonlyArray(self).every((value, i)=>equals(value, Chunk_unsafeGet(that, i)))), ChunkProto = { [Chunk_TypeId]: { _A: (_)=>_ }, toString () { return JSON.stringify(this.toJSON(), null, 2); }, toJSON () { return { _id: "Chunk", values: toReadonlyArray(this).map(toJSON) }; }, [Inspectable_NodeInspectSymbol] () { return this.toJSON(); }, [Equal_symbol] (that) { return isChunk(that) && Chunk_equivalence(this, that); }, [Hash_symbol] () { return Hash_cached(this, Hash_array(toReadonlyArray(this))); }, [Symbol.iterator] () { switch(this.backing._tag){ case "IArray": return this.backing.array[Symbol.iterator](); case "IEmpty": return emptyArray[Symbol.iterator](); default: return toReadonlyArray(this)[Symbol.iterator](); } }, pipe () { return Pipeable_pipeArguments(this, arguments); } }, makeChunk = (backing)=>{ let chunk = Object.create(ChunkProto); switch(chunk.backing = backing, backing._tag){ case "IEmpty": chunk.length = 0, chunk.depth = 0, chunk.left = chunk, chunk.right = chunk; break; case "IConcat": chunk.length = backing.left.length + backing.right.length, chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth), chunk.left = backing.left, chunk.right = backing.right; break; case "IArray": chunk.length = backing.array.length, chunk.depth = 0, chunk.left = _empty, chunk.right = _empty; break; case "ISingleton": chunk.length = 1, chunk.depth = 0, chunk.left = _empty, chunk.right = _empty; break; case "ISlice": chunk.length = backing.length, chunk.depth = backing.chunk.depth + 1, chunk.left = _empty, chunk.right = _empty; } return chunk; }, isChunk = (u)=>Predicate_hasProperty(u, Chunk_TypeId), _empty = makeChunk({ _tag: "IEmpty" }), Chunk_empty = ()=>_empty, Chunk_make = (...as)=>unsafeFromNonEmptyArray(as), Chunk_of = (a)=>makeChunk({ _tag: "ISingleton", a }), Chunk_fromIterable = (self)=>isChunk(self) ? self : unsafeFromArray(Array_fromIterable(self)), copyToArray = (self, array, initial)=>{ switch(self.backing._tag){ case "IArray": !function(src, dest, destPos, len) { for(let i = 0; i < Math.min(src.length, 0 + len); i++)dest[destPos + i - 0] = src[i]; }(self.backing.array, array, initial, self.length); break; case "IConcat": copyToArray(self.left, array, initial), copyToArray(self.right, array, initial + self.left.length); break; case "ISingleton": array[initial] = self.backing.a; break; case "ISlice": { let i = 0, j = initial; for(; i < self.length;)array[j] = Chunk_unsafeGet(self, i), i += 1, j += 1; } } }, toReadonlyArray = (self)=>{ switch(self.backing._tag){ case "IEmpty": return emptyArray; case "IArray": return self.backing.array; default: { let arr = Array(self.length); return copyToArray(self, arr, 0), self.backing = { _tag: "IArray", array: arr }, self.left = _empty, self.right = _empty, self.depth = 0, arr; } } }, Chunk_reverse = (self)=>{ switch(self.backing._tag){ case "IEmpty": case "ISingleton": return self; case "IArray": return makeChunk({ _tag: "IArray", array: Array_reverse(self.backing.array) }); case "IConcat": return makeChunk({ _tag: "IConcat", left: Chunk_reverse(self.backing.right), right: Chunk_reverse(self.backing.left) }); case "ISlice": return unsafeFromArray(Array_reverse(toReadonlyArray(self))); } }, Chunk_get = Function_dual(2, (self, index)=>index < 0 || index >= self.length ? Option_none() : option_some(Chunk_unsafeGet(self, index))), unsafeFromArray = (self)=>0 === self.length ? Chunk_empty() : 1 === self.length ? Chunk_of(self[0]) : makeChunk({ _tag: "IArray", array: self }), unsafeFromNonEmptyArray = (self)=>unsafeFromArray(self), Chunk_unsafeGet = Function_dual(2, (self, index)=>{ switch(self.backing._tag){ case "IEmpty": throw Error("Index out of bounds"); case "ISingleton": if (0 !== index) throw Error("Index out of bounds"); return self.backing.a; case "IArray": if (index >= self.length || index < 0) throw Error("Index out of bounds"); return self.backing.array[index]; case "IConcat": return index < self.left.length ? Chunk_unsafeGet(self.left, index) : Chunk_unsafeGet(self.right, index - self.left.length); case "ISlice": return Chunk_unsafeGet(self.backing.chunk, index + self.backing.offset); } }), Chunk_append = Function_dual(2, (self, a)=>Chunk_appendAll(self, Chunk_of(a))), Chunk_prepend = Function_dual(2, (self, elem)=>Chunk_appendAll(Chunk_of(elem), self)), Chunk_drop = Function_dual(2, (self, n)=>{ if (n <= 0) return self; if (n >= self.length) return _empty; switch(self.backing._tag){ case "ISlice": return makeChunk({ _tag: "ISlice", chunk: self.backing.chunk, offset: self.backing.offset + n, length: self.backing.length - n }); case "IConcat": if (n > self.left.length) return Chunk_drop(self.right, n - self.left.length); return makeChunk({ _tag: "IConcat", left: Chunk_drop(self.left, n), right: self.right }); default: return makeChunk({ _tag: "ISlice", chunk: self, offset: n, length: self.length - n }); } }), Chunk_appendAll = Function_dual(2, (self, that)=>{ if ("IEmpty" === self.backing._tag) return that; if ("IEmpty" === that.backing._tag) return self; let diff = that.depth - self.depth; if (1 >= Math.abs(diff)) return makeChunk({ _tag: "IConcat", left: self, right: that }); if (diff < -1) if (self.left.depth >= self.right.depth) { let nr = Chunk_appendAll(self.right, that); return makeChunk({ _tag: "IConcat", left: self.left, right: nr }); } else { let nrr = Chunk_appendAll(self.right.right, that); if (nrr.depth === self.depth - 3) { let nr = makeChunk({ _tag: "IConcat", left: self.right.left, right: nrr }); return makeChunk({ _tag: "IConcat", left: self.left, right: nr }); } { let nl = makeChunk({ _tag: "IConcat", left: self.left, right: self.right.left }); return makeChunk({ _tag: "IConcat", left: nl, right: nrr }); } } if (that.right.depth >= that.left.depth) return makeChunk({ _tag: "IConcat", left: Chunk_appendAll(self, that.left), right: that.right }); { let nll = Chunk_appendAll(self, that.left.left); if (nll.depth === that.depth - 3) { let nl = makeChunk({ _tag: "IConcat", left: nll, right: that.left.right }); return makeChunk({ _tag: "IConcat", left: nl, right: that.right }); } { let nr = makeChunk({ _tag: "IConcat", left: that.left.right, right: that.right }); return makeChunk({ _tag: "IConcat", left: nll, right: nr }); } } }), Chunk_isEmpty = (self)=>0 === self.length, isNonEmpty = (self)=>self.length > 0, Chunk_head = Chunk_get(0), Chunk_unsafeHead = (self)=>Chunk_unsafeGet(self, 0), Chunk_tailNonEmpty = (self)=>Chunk_drop(self, 1); function fromBitmap(bitmap, bit) { var x; return x = bitmap & bit - 1, x -= x >> 1 & 0x55555555, x = (x = (0x33333333 & x) + (x >> 2 & 0x33333333)) + (x >> 4) & 0x0f0f0f0f, x += x >> 8, 0x7f & (x += x >> 16); } let stack_make = (value, previous)=>({ value, previous }); function arrayUpdate(mutate, at, v1, arr) { let out = arr; if (!mutate) { let len = arr.length; out = Array(len); for(let i = 0; i < len; ++i)out[i] = arr[i]; } return out[at] = v1, out; } function arraySpliceOut(mutate, at, arr) { let newLen = arr.length - 1, i = 0, g = 0, out = arr; if (mutate) i = g = at; else for(out = Array(newLen); i < at;)out[g++] = arr[i++]; for(++i; i <= newLen;)out[g++] = arr[i++]; return mutate && (out.length = newLen), out; } class EmptyNode { _tag = "EmptyNode"; modify(edit, _shift, f, hash, key, size) { let v1 = f(Option_none()); return isNone(v1) ? new EmptyNode() : (++size.value, new LeafNode(edit, hash, key, v1)); } } function isEmptyNode(a) { return Predicate_isTagged(a, "EmptyNode"); } function canEditNode(node, edit) { return !isEmptyNode(node) && edit === node.edit; } class LeafNode { edit; hash; key; value; _tag = "LeafNode"; constructor(edit, hash, key, value){ this.edit = edit, this.hash = hash, this.key = key, this.value = value; } modify(edit, shift, f, hash, key, size) { if (equals(key, this.key)) { let v1 = f(this.value); return v1 === this.value ? this : isNone(v1) ? (--size.value, new EmptyNode()) : canEditNode(this, edit) ? (this.value = v1, this) : new LeafNode(edit, hash, key, v1); } let v1 = f(Option_none()); return isNone(v1) ? this : (++size.value, mergeLeaves(edit, shift, this.hash, this, hash, new LeafNode(edit, hash, key, v1))); } } class CollisionNode { edit; hash; children; _tag = "CollisionNode"; constructor(edit, hash, children){ this.edit = edit, this.hash = hash, this.children = children; } modify(edit, shift, f, hash, key, size) { if (hash === this.hash) { let canEdit = canEditNode(this, edit), list = this.updateCollisionList(canEdit, edit, this.hash, this.children, f, key, size); return list === this.children ? this : list.length > 1 ? new CollisionNode(edit, this.hash, list) : list[0]; } let v1 = f(Option_none()); return isNone(v1) ? this : (++size.value, mergeLeaves(edit, shift, this.hash, this, hash, new LeafNode(edit, hash, key, v1))); } updateCollisionList(mutate, edit, hash, list, f, key, size) { let len = list.length; for(let i = 0; i < len; ++i){ let child = list[i]; if ("key" in child && equals(key, child.key)) { let value = child.value, newValue = f(value); if (newValue === value) return list; if (isNone(newValue)) return --size.value, arraySpliceOut(mutate, i, list); return arrayUpdate(mutate, i, new LeafNode(edit, hash, key, newValue), list); } } let newValue = f(Option_none()); return isNone(newValue) ? list : (++size.value, arrayUpdate(mutate, len, new LeafNode(edit, hash, key, newValue), list)); } } class IndexedNode { edit; mask; children; _tag = "IndexedNode"; constructor(edit, mask, children){ this.edit = edit, this.mask = mask, this.children = children; } modify(edit, shift, f, hash, key, size) { let newChildren, mask = this.mask, children = this.children, frag = hash >>> shift & 31, bit = 1 << frag, indx = fromBitmap(mask, bit), exists = mask & bit, canEdit = canEditNode(this, edit); if (!exists) { let _newChild = new EmptyNode().modify(edit, shift + 5, f, hash, key, size); return _newChild ? children.length >= 16 ? function(edit, frag, child, bitmap, subNodes) { let arr = [], bit = bitmap, count = 0; for(let i = 0; bit; ++i)1 & bit && (arr[i] = subNodes[count++]), bit >>>= 1; return arr[frag] = child, new ArrayNode(edit, count + 1, arr); }(edit, frag, _newChild, mask, children) : new IndexedNode(edit, mask | bit, function(mutate, at, v1, arr) { let len = arr.length; if (mutate) { let i = len; for(; i >= at;)arr[i--] = arr[i]; return arr[at] = v1, arr; } let i = 0, g = 0, out = Array(len + 1); for(; i < at;)out[g++] = arr[i++]; for(out[at] = v1; i < len;)out[++g] = arr[i++]; return out; }(canEdit, indx, _newChild, children)) : this; } let current = children[indx], child = current.modify(edit, shift + 5, f, hash, key, size); if (current === child) return this; let bitmap = mask; if (isEmptyNode(child)) { var node; if (!(bitmap &= ~bit)) return new EmptyNode(); if (children.length <= 2 && (isEmptyNode(node = children[1 ^ indx]) || "LeafNode" === node._tag || "CollisionNode" === node._tag)) return children[1 ^ indx]; newChildren = arraySpliceOut(canEdit, indx, children); } else newChildren = arrayUpdate(canEdit, indx, child, children); return canEdit ? (this.mask = bitmap, this.children = newChildren, this) : new IndexedNode(edit, bitmap, newChildren); } } class ArrayNode { edit; size; children; _tag = "ArrayNode"; constructor(edit, size, children){ this.edit = edit, this.size = size, this.children = children; } modify(edit, shift, f, hash, key, size) { let newChildren, count = this.size, children = this.children, frag = hash >>> shift & 31, child = children[frag], newChild = (child || new EmptyNode()).modify(edit, shift + 5, f, hash, key, size); if (child === newChild) return this; let canEdit = canEditNode(this, edit); if (isEmptyNode(child) && !isEmptyNode(newChild)) ++count, newChildren = arrayUpdate(canEdit, frag, newChild, children); else if (!isEmptyNode(child) && isEmptyNode(newChild)) { if (--count <= 8) return function(edit, count, removed, elements) { let children = Array(count - 1), g = 0, bitmap = 0; for(let i = 0, len = elements.length; i < len; ++i)if (i !== removed) { let elem = elements[i]; elem && !isEmptyNode(elem) && (children[g++] = elem, bitmap |= 1 << i); } return new IndexedNode(edit, bitmap, children); }(edit, count, frag, children); newChildren = arrayUpdate(canEdit, frag, new EmptyNode(), children); } else newChildren = arrayUpdate(canEdit, frag, newChild, children); return canEdit ? (this.size = count, this.children = newChildren, this) : new ArrayNode(edit, count, newChildren); } } function mergeLeaves(edit, shift, h1, n1, h2, n2) { let stack, currentShift = shift; for(;;){ let res = function(edit, shift, h1, n1, h2, n2) { if (h1 === h2) return new CollisionNode(edit, h1, [ n2, n1 ]); let subH1 = h1 >>> shift & 31, subH2 = h2 >>> shift & 31; return subH1 === subH2 ? (child)=>new IndexedNode(edit, 1 << subH1 | 1 << subH2, [ child ]) : new IndexedNode(edit, 1 << subH1 | 1 << subH2, subH1 < subH2 ? [ n1, n2 ] : [ n2, n1 ]); }(edit, currentShift, h1, n1, h2, n2); if ("function" == typeof res) stack = stack_make(res, stack), currentShift += 5; else { let final = res; for(; null != stack;)final = stack.value(final), stack = stack.previous; return final; } } } let HashMapSymbolKey = "effect/HashMap", HashMapTypeId = Symbol.for(HashMapSymbolKey), HashMapProto = { [HashMapTypeId]: HashMapTypeId, [Symbol.iterator] () { return new HashMapIterator(this, (k, v1)=>[ k, v1 ]); }, [Hash_symbol] () { let hash = Hash_hash(HashMapSymbolKey); for (let item of this)hash ^= Function_pipe(Hash_hash(item[0]), Hash_combine(Hash_hash(item[1]))); return Hash_cached(this, hash); }, [Equal_symbol] (that) { if (isHashMap(that)) { if (that._size !== this._size) return !1; for (let item of this){ let elem = Function_pipe(that, getHash(item[0], Hash_hash(item[0]))); if (isNone(elem) || !equals(item[1], elem.value)) return !1; } return !0; } return !1; }, toString () { return JSON.stringify(this.toJSON(), null, 2); }, toJSON () { return { _id: "HashMap", values: Array.from(this).map(toJSON) }; }, [Inspectable_NodeInspectSymbol] () { return this.toJSON(); }, pipe () { return Pipeable_pipeArguments(this, arguments); } }, makeImpl = (editable, edit, root, size)=>{ let map = Object.create(HashMapProto); return map._editable = editable, map._edit = edit, map._root = root, map._size = size, map; }; class HashMapIterator { map; f; v; constructor(map, f){ this.map = map, this.f = f, this.v = visitLazy(this.map._root, this.f, void 0); } next() { if (isNone(this.v)) return { done: !0, value: void 0 }; let v0 = this.v.value; return this.v = applyCont(v0.cont), { done: !1, value: v0.value }; } [Symbol.iterator]() { return new HashMapIterator(this.map, this.f); } } let applyCont = (cont)=>cont ? visitLazyChildren(cont[0], cont[1], cont[2], cont[3], cont[4]) : Option_none(), visitLazy = (node, f, cont)=>{ switch(node._tag){ case "LeafNode": if (isSome(node.value)) return option_some({ value: f(node.key, node.value.value), cont }); return applyCont(cont); case "CollisionNode": case "ArrayNode": case "IndexedNode": { let children = node.children; return visitLazyChildren(children.length, children, 0, f, cont); } default: return applyCont(cont); } }, visitLazyChildren = (len, children, i, f, cont)=>{ for(; i < len;){ let child = children[i++]; if (child && !isEmptyNode(child)) return visitLazy(child, f, [ len, children, i, f, cont ]); } return applyCont(cont); }, hashMap_empty = makeImpl(!1, 0, new EmptyNode(), 0), isHashMap = (u)=>Predicate_hasProperty(u, HashMapTypeId), hashMap_get = Function_dual(2, (self, key)=>getHash(self, key, Hash_hash(key))), getHash = Function_dual(3, (self, key, hash)=>{ let node = self._root, shift = 0; for(;;)switch(node._tag){ case "LeafNode": return equals(key, node.key) ? node.value : Option_none(); case "CollisionNode": if (hash === node.hash) { let children = node.children; for(let i = 0, len = children.length; i < len; ++i){ let child = children[i]; if ("key" in child && equals(key, child.key)) return child.value; } } return Option_none(); case "IndexedNode": { let bit = 1 << (hash >>> shift & 31); if (node.mask & bit) { node = node.children[fromBitmap(node.mask, bit)], shift += 5; break; } return Option_none(); } case "ArrayNode": if (node = node.children[hash >>> shift & 31]) { shift += 5; break; } return Option_none(); default: return Option_none(); } }), hashMap_has = Function_dual(2, (self, key)=>isSome(getHash(self, key, Hash_hash(key)))), hashMap_set = Function_dual(3, (self, key, value)=>modifyAt(self, key, ()=>option_some(value))), setTree = Function_dual(3, (self, newRoot, newSize)=>self._editable ? (self._root = newRoot, self._size = newSize, self) : newRoot === self._root ? self : makeImpl(self._editable, self._edit, newRoot, newSize)), hashMap_keys = (self)=>new HashMapIterator(self, (key)=>key), beginMutation = (self)=>makeImpl(!0, self._edit + 1, self._root, self._size), endMutation = (self)=>(self._editable = !1, self), modifyAt = ((self, f)=>{