PageSourceSearch

https://victor-longcat-video-avatar-1-5.hf.space/assets/clone-dZfS06Ds.js

js victor-longcat-video-avatar-1-5.hf.space collected 2026-10-03 10:22:29 UTC 4,401 bytes, 167 lines download raw bytes

1import { D as DEV, $ as is_array, ah as get_prototype_of, ai as object_prototype } from './index-CDZuCcOm.js';
2
3/* This file is generated by scripts/process-messages/index.js. Do not edit! */
4
5
6var bold = 'font-weight: bold';
7var normal = 'font-weight: normal';
8
9/**
10 * The following properties cannot be cloned with `$state.snapshot` — the return value contains the originals:
11 * 
12 * %properties%
13 * @param {string | undefined | null} [properties]
14 */
15function state_snapshot_uncloneable(properties) {
16	if (DEV) {
17		console.warn(
18			`%c[svelte] state_snapshot_uncloneable\n%c${properties
19				? `The following properties cannot be cloned with \`$state.snapshot\` — the return value contains the originals:
20
21${properties}`
22				: 'Value cannot be cloned with `$state.snapshot` — the original value was returned'}\nhttps://svelte.dev/e/state_snapshot_uncloneable`,
23			bold,
24			normal
25		);
26	} else {
27		console.warn(`https://svelte.dev/e/state_snapshot_uncloneable`);
28	}
29}
30
31/** @import { Snapshot } from './types' */
32
33/**
34 * In dev, we keep track of which properties could not be cloned. In prod
35 * we don't bother, but we keep a dummy array around so that the
36 * signature stays the same
37 * @type {string[]}
38 */
39const empty = [];
40
41/**
42 * @template T
43 * @param {T} value
44 * @param {boolean} [skip_warning]
45 * @param {boolean} [no_tojson]
46 * @returns {Snapshot<T>}
47 */
48function snapshot(value, skip_warning = false, no_tojson = false) {
49	if (DEV && !skip_warning) {
50		/** @type {string[]} */
51		const paths = [];
52
53		const copy = clone(value, new Map(), '', paths, null, no_tojson);
54		if (paths.length === 1 && paths[0] === '') {
55			// value could not be cloned
56			state_snapshot_uncloneable();
57		} else if (paths.length > 0) {
58			// some properties could not be cloned
59			const slice = paths.length > 10 ? paths.slice(0, 7) : paths.slice(0, 10);
60			const excess = paths.length - slice.length;
61
62			let uncloned = slice.map((path) => `- <value>${path}`).join('\n');
63			if (excess > 0) uncloned += `\n- ...and ${excess} more`;
64
65			state_snapshot_uncloneable(uncloned);
66		}
67
68		return copy;
69	}
70
71	return clone(value, new Map(), '', empty, null, no_tojson);
72}
73
74/**
75 * @template T
76 * @param {T} value
77 * @param {Map<T, Snapshot<T>>} cloned
78 * @param {string} path
79 * @param {string[]} paths
80 * @param {null | T} [original] The original value, if `value` was produced from a `toJSON` call
81 * @param {boolean} [no_tojson]
82 * @returns {Snapshot<T>}
83 */
84function clone(value, cloned, path, paths, original = null, no_tojson = false) {
85	if (typeof value === 'object' && value !== null) {
86		var unwrapped = cloned.get(value);
87		if (unwrapped !== undefined) return unwrapped;
88
89		if (value instanceof Map) return /** @type {Snapshot<T>} */ (new Map(value));
90		if (value instanceof Set) return /** @type {Snapshot<T>} */ (new Set(value));
91
92		if (is_array(value)) {
93			var copy = /** @type {Snapshot<any>} */ (Array(value.length));
94			cloned.set(value, copy);
95
96			if (original !== null) {
97				cloned.set(original, copy);
98			}
99
100			for (var i = 0; i < value.length; i += 1) {
101				var element = value[i];
102				if (i in value) {
103					copy[i] = clone(element, cloned, DEV ? `${path}[${i}]` : path, paths, null, no_tojson);
104				}
105			}
106
107			return copy;
108		}
109
110		if (get_prototype_of(value) === object_prototype) {
111			/** @type {Snapshot<any>} */
112			copy = {};
113			cloned.set(value, copy);
114
115			if (original !== null) {
116				cloned.set(original, copy);
117			}
118
119			for (var key in value) {
120				copy[key] = clone(
121					// @ts-expect-error
122					value[key],
123					cloned,
124					DEV ? `${path}.${key}` : path,
125					paths,
126					null,
127					no_tojson
128				);
129			}
130
131			return copy;
132		}
133
134		if (value instanceof Date) {
135			return /** @type {Snapshot<T>} */ (structuredClone(value));
136		}
137
138		if (typeof (/** @type {T & { toJSON?: any } } */ (value).toJSON) === 'function' && !no_tojson) {
139			return clone(
140				/** @type {T & { toJSON(): any } } */ (value).toJSON(),
141				cloned,
142				DEV ? `${path}.toJSON()` : path,
143				paths,
144				// Associate the instance with the toJSON clone
145				value
146			);
147		}
148	}
149
150	if (value instanceof EventTarget) {
151		// can't be cloned
152		return /** @type {Snapshot<T>} */ (value);
153	}
154
155	try {
156		return /** @type {Snapshot<T>} */ (structuredClone(value));
157	} catch (e) {
158		if (DEV) {
159			paths.push(path);
160		}
161
162		return /** @type {Snapshot<T>} */ (value);
163	}
164}
165
166export { snapshot as s };
167//# sourceMappingURL=clone-dZfS06Ds.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.