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EAAA,IAAI,kBAAkB,GAAK,EAAA;AAC1B,IAAM,MAAA,MAAA,GAAS,IAAK,MAAA,CAAO,WAA+B,EAAA;AAE1D,IAAW,KAAA,MAAA,KAAA,IAAS,MAAO,CAAA,MAAA,EAAU,EAAA;AACpC,MAAO,MAAA,CAAA,GAAA,CAAI,SAAU,CAAA,KAAK,CAAC,CAAA;AAAA;AAG5B,IAAO,OAAA,MAAA;AAAA;AAGR,EAAI,IAAA,OAAO,WAAW,QAAU,EAAA;AAC/B,IAAM,MAAA,MAAA,GAAS,IAAM,MAAA,CAAuD,WAAkC,EAAA;AAK9G,IAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,MAAM,CAAG,EAAA;AAClD,MAAO,MAAA,CAAA,cAAA,CAAe,QAAQ,GAAK,EAAA;AAAA,QAClC,YAAc,EAAA,IAAA;AAAA,QACd,UAAY,EAAA,IAAA;AAAA,QACZ,KAAA,EAAO,UAAU,KAAK,CAAA;AAAA,QACtB,QAAU,EAAA;AAAA,OACV,CAAA;AAAA;AAGF,IAAO,OAAA,MAAA;AAAA;AAGR,EAAO,OAAA,MAAA;AACR;AAnEgB,MAAA,CAAA,SAAA,EAAA,WAAA,CAAA","file":"deepClone.cjs","sourcesContent":["import { isPrimitive } from './isPrimitive';\nimport type { Constructor } from './types';\n\n/**\n * A constant reference to the prototype of a `TypedArray` to avoid recomputing the expensive\n * `Object.getPrototypeOf` call.\n *\n * We can safely reference `NodeJS.TypedArray` while preserving browser compatibility,\n * because this is TypeScript-only code and this constant is also not included\n * in the `.d.ts` file as it is not exported.\n */\nconst TypedArrayPrototype = Object.getPrototypeOf(Uint8Array) as Constructor<NodeJS.TypedArray>;\n\n/**\n * Deep clone an object\n * @param source The object to clone\n */\nexport function deepClone<T>(source: T): T {\n\t// Check if it's a primitive (string, number, boolean, bigint)\n\tif (source === null || isPrimitive(source)) {\n\t\treturn source;\n\t}\n\n\tif (source instanceof Date) {\n\t\tconst output = new (source.constructor as DateConstructor)(source);\n\n\t\treturn output as unknown as T;\n\t}\n\n\tif (source instanceof TypedArrayPrototype) {\n\t\tconst output = (source.constructor as Uint8ArrayConstructor).from(source as Uint8Array);\n\n\t\treturn output as unknown as T;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tconst output = new (source.constructor as ArrayConstructor)(source.length) as unknown as T & T extends (infer S)[] ? S[] : never;\n\n\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\toutput[i] = deepClone(source[i]);\n\t\t}\n\n\t\treturn output as unknown as T;\n\t}\n\n\tif (source instanceof Map) {\n\t\tconst output = new (source.constructor as MapConstructor)() as unknown as T & T extends Map<infer K, infer V> ? Map<K, V> : never;\n\n\t\tfor (const [key, value] of source.entries()) {\n\t\t\toutput.set(key, deepClone(value));\n\t\t}\n\n\t\treturn output as unknown as T;\n\t}\n\n\tif (source instanceof Set) {\n\t\tconst output = new (source.constructor as SetConstructor)() as unknown as T & T extends Set<infer K> ? Set<K> : never;\n\n\t\tfor (const value of source.values()) {\n\t\t\toutput.add(deepClone(value));\n\t\t}\n\n\t\treturn output as unknown as T;\n\t}\n\n\tif (typeof source === 'object') {\n\t\tconst output = new ((source as T & (object | Record<PropertyKey, unknown>)).constructor as ObjectConstructor)() as unknown as Record<\n\t\t\tPropertyKey,\n\t\t\tunknown\n\t\t>;\n\n\t\tfor (const [key, value] of Object.entries(source)) {\n\t\t\tObject.defineProperty(output, key, {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tvalue: deepClone(value),\n\t\t\t\twritable: true\n\t\t\t});\n\t\t}\n\n\t\treturn output as unknown as T;\n\t}\n\n\treturn source;\n}\n"]}