@bquery/bquery 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +501 -427
- package/dist/batch-4LAvfLE7.js +13 -0
- package/dist/batch-4LAvfLE7.js.map +1 -0
- package/dist/component/component.d.ts +69 -0
- package/dist/component/component.d.ts.map +1 -0
- package/dist/component/html.d.ts +35 -0
- package/dist/component/html.d.ts.map +1 -0
- package/dist/component/index.d.ts +3 -126
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/props.d.ts +18 -0
- package/dist/component/props.d.ts.map +1 -0
- package/dist/component/types.d.ts +77 -0
- package/dist/component/types.d.ts.map +1 -0
- package/dist/component.es.mjs +90 -59
- package/dist/component.es.mjs.map +1 -1
- package/dist/core/collection.d.ts +36 -0
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/dom.d.ts +6 -0
- package/dist/core/dom.d.ts.map +1 -0
- package/dist/core/element.d.ts +8 -0
- package/dist/core/element.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/utils/array.d.ts +74 -0
- package/dist/core/utils/array.d.ts.map +1 -0
- package/dist/core/utils/function.d.ts +70 -0
- package/dist/core/utils/function.d.ts.map +1 -0
- package/dist/core/utils/index.d.ts +70 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/misc.d.ts +63 -0
- package/dist/core/utils/misc.d.ts.map +1 -0
- package/dist/core/utils/number.d.ts +65 -0
- package/dist/core/utils/number.d.ts.map +1 -0
- package/dist/core/utils/object.d.ts +133 -0
- package/dist/core/utils/object.d.ts.map +1 -0
- package/dist/core/utils/string.d.ts +80 -0
- package/dist/core/utils/string.d.ts.map +1 -0
- package/dist/core/utils/type-guards.d.ts +79 -0
- package/dist/core/utils/type-guards.d.ts.map +1 -0
- package/dist/core-COenAZjD.js +145 -0
- package/dist/core-COenAZjD.js.map +1 -0
- package/dist/core.es.mjs +411 -448
- package/dist/core.es.mjs.map +1 -1
- package/dist/full.d.ts +2 -2
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +87 -64
- package/dist/full.es.mjs.map +1 -1
- package/dist/full.iife.js +2 -2
- package/dist/full.iife.js.map +1 -1
- package/dist/full.umd.js +2 -2
- package/dist/full.umd.js.map +1 -1
- package/dist/index.es.mjs +138 -68
- package/dist/index.es.mjs.map +1 -1
- package/dist/motion/animate.d.ts +25 -0
- package/dist/motion/animate.d.ts.map +1 -0
- package/dist/motion/easing.d.ts +30 -0
- package/dist/motion/easing.d.ts.map +1 -0
- package/dist/motion/flip.d.ts +55 -0
- package/dist/motion/flip.d.ts.map +1 -0
- package/dist/motion/index.d.ts +11 -138
- package/dist/motion/index.d.ts.map +1 -1
- package/dist/motion/keyframes.d.ts +21 -0
- package/dist/motion/keyframes.d.ts.map +1 -0
- package/dist/motion/reduced-motion.d.ts +12 -0
- package/dist/motion/reduced-motion.d.ts.map +1 -0
- package/dist/motion/scroll.d.ts +15 -0
- package/dist/motion/scroll.d.ts.map +1 -0
- package/dist/motion/spring.d.ts +42 -0
- package/dist/motion/spring.d.ts.map +1 -0
- package/dist/motion/stagger.d.ts +22 -0
- package/dist/motion/stagger.d.ts.map +1 -0
- package/dist/motion/timeline.d.ts +21 -0
- package/dist/motion/timeline.d.ts.map +1 -0
- package/dist/motion/transition.d.ts +22 -0
- package/dist/motion/transition.d.ts.map +1 -0
- package/dist/motion/types.d.ts +182 -0
- package/dist/motion/types.d.ts.map +1 -0
- package/dist/motion.es.mjs +320 -61
- package/dist/motion.es.mjs.map +1 -1
- package/dist/persisted-Dz_ryNuC.js +278 -0
- package/dist/persisted-Dz_ryNuC.js.map +1 -0
- package/dist/reactive/batch.d.ts +13 -0
- package/dist/reactive/batch.d.ts.map +1 -0
- package/dist/reactive/computed.d.ts +50 -0
- package/dist/reactive/computed.d.ts.map +1 -0
- package/dist/reactive/core.d.ts +60 -0
- package/dist/reactive/core.d.ts.map +1 -0
- package/dist/reactive/effect.d.ts +15 -0
- package/dist/reactive/effect.d.ts.map +1 -0
- package/dist/reactive/index.d.ts +2 -2
- package/dist/reactive/index.d.ts.map +1 -1
- package/dist/reactive/internals.d.ts +36 -0
- package/dist/reactive/internals.d.ts.map +1 -0
- package/dist/reactive/linked.d.ts +36 -0
- package/dist/reactive/linked.d.ts.map +1 -0
- package/dist/reactive/persisted.d.ts +14 -0
- package/dist/reactive/persisted.d.ts.map +1 -0
- package/dist/reactive/readonly.d.ts +26 -0
- package/dist/reactive/readonly.d.ts.map +1 -0
- package/dist/reactive/signal.d.ts +13 -312
- package/dist/reactive/signal.d.ts.map +1 -1
- package/dist/reactive/type-guards.d.ts +20 -0
- package/dist/reactive/type-guards.d.ts.map +1 -0
- package/dist/reactive/untrack.d.ts +29 -0
- package/dist/reactive/untrack.d.ts.map +1 -0
- package/dist/reactive/watch.d.ts +42 -0
- package/dist/reactive/watch.d.ts.map +1 -0
- package/dist/reactive.es.mjs +30 -163
- package/dist/reactive.es.mjs.map +1 -1
- package/dist/router/index.d.ts +6 -252
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/links.d.ts +44 -0
- package/dist/router/links.d.ts.map +1 -0
- package/dist/router/match.d.ts +20 -0
- package/dist/router/match.d.ts.map +1 -0
- package/dist/router/navigation.d.ts +45 -0
- package/dist/router/navigation.d.ts.map +1 -0
- package/dist/router/query.d.ts +16 -0
- package/dist/router/query.d.ts.map +1 -0
- package/dist/router/router.d.ts +34 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/state.d.ts +27 -0
- package/dist/router/state.d.ts.map +1 -0
- package/dist/router/types.d.ts +88 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/utils.d.ts +65 -0
- package/dist/router/utils.d.ts.map +1 -0
- package/dist/router.es.mjs +168 -132
- package/dist/router.es.mjs.map +1 -1
- package/dist/sanitize-1FBEPAFH.js +272 -0
- package/dist/sanitize-1FBEPAFH.js.map +1 -0
- package/dist/security/constants.d.ts +42 -0
- package/dist/security/constants.d.ts.map +1 -0
- package/dist/security/csp.d.ts +24 -0
- package/dist/security/csp.d.ts.map +1 -0
- package/dist/security/index.d.ts +4 -2
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/sanitize-core.d.ts +13 -0
- package/dist/security/sanitize-core.d.ts.map +1 -0
- package/dist/security/sanitize.d.ts +5 -57
- package/dist/security/sanitize.d.ts.map +1 -1
- package/dist/security/trusted-types.d.ts +25 -0
- package/dist/security/trusted-types.d.ts.map +1 -0
- package/dist/security/types.d.ts +36 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security.es.mjs +50 -277
- package/dist/security.es.mjs.map +1 -1
- package/dist/store/create-store.d.ts +15 -0
- package/dist/store/create-store.d.ts.map +1 -0
- package/dist/store/define-store.d.ts +28 -0
- package/dist/store/define-store.d.ts.map +1 -0
- package/dist/store/devtools.d.ts +22 -0
- package/dist/store/devtools.d.ts.map +1 -0
- package/dist/store/index.d.ts +10 -286
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/mapping.d.ts +28 -0
- package/dist/store/mapping.d.ts.map +1 -0
- package/dist/store/persisted.d.ts +13 -0
- package/dist/store/persisted.d.ts.map +1 -0
- package/dist/store/plugins.d.ts +13 -0
- package/dist/store/plugins.d.ts.map +1 -0
- package/dist/store/registry.d.ts +28 -0
- package/dist/store/registry.d.ts.map +1 -0
- package/dist/store/types.d.ts +71 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/utils.d.ts +28 -0
- package/dist/store/utils.d.ts.map +1 -0
- package/dist/store/watch.d.ts +23 -0
- package/dist/store/watch.d.ts.map +1 -0
- package/dist/store.es.mjs +22 -224
- package/dist/store.es.mjs.map +1 -1
- package/dist/type-guards-DRma3-Kc.js +16 -0
- package/dist/type-guards-DRma3-Kc.js.map +1 -0
- package/dist/untrack-BuEQKH7_.js +6 -0
- package/dist/untrack-BuEQKH7_.js.map +1 -0
- package/dist/view/directives/bind.d.ts +7 -0
- package/dist/view/directives/bind.d.ts.map +1 -0
- package/dist/view/directives/class.d.ts +8 -0
- package/dist/view/directives/class.d.ts.map +1 -0
- package/dist/view/directives/for.d.ts +23 -0
- package/dist/view/directives/for.d.ts.map +1 -0
- package/dist/view/directives/html.d.ts +7 -0
- package/dist/view/directives/html.d.ts.map +1 -0
- package/dist/view/directives/if.d.ts +7 -0
- package/dist/view/directives/if.d.ts.map +1 -0
- package/dist/view/directives/index.d.ts +12 -0
- package/dist/view/directives/index.d.ts.map +1 -0
- package/dist/view/directives/model.d.ts +7 -0
- package/dist/view/directives/model.d.ts.map +1 -0
- package/dist/view/directives/on.d.ts +7 -0
- package/dist/view/directives/on.d.ts.map +1 -0
- package/dist/view/directives/ref.d.ts +7 -0
- package/dist/view/directives/ref.d.ts.map +1 -0
- package/dist/view/directives/show.d.ts +7 -0
- package/dist/view/directives/show.d.ts.map +1 -0
- package/dist/view/directives/style.d.ts +7 -0
- package/dist/view/directives/style.d.ts.map +1 -0
- package/dist/view/directives/text.d.ts +7 -0
- package/dist/view/directives/text.d.ts.map +1 -0
- package/dist/view/evaluate.d.ts +43 -0
- package/dist/view/evaluate.d.ts.map +1 -0
- package/dist/view/index.d.ts +3 -93
- package/dist/view/index.d.ts.map +1 -1
- package/dist/view/mount.d.ts +69 -0
- package/dist/view/mount.d.ts.map +1 -0
- package/dist/view/process.d.ts +26 -0
- package/dist/view/process.d.ts.map +1 -0
- package/dist/view/types.d.ts +36 -0
- package/dist/view/types.d.ts.map +1 -0
- package/dist/view.es.mjs +368 -267
- package/dist/view.es.mjs.map +1 -1
- package/dist/watch-CXyaBC_9.js +58 -0
- package/dist/watch-CXyaBC_9.js.map +1 -0
- package/package.json +132 -132
- package/src/component/component.ts +289 -0
- package/src/component/html.ts +53 -0
- package/src/component/index.ts +40 -414
- package/src/component/props.ts +116 -0
- package/src/component/types.ts +85 -0
- package/src/core/collection.ts +588 -454
- package/src/core/dom.ts +38 -0
- package/src/core/element.ts +746 -740
- package/src/core/index.ts +43 -0
- package/src/core/utils/array.ts +102 -0
- package/src/core/utils/function.ts +110 -0
- package/src/core/utils/index.ts +83 -0
- package/src/core/utils/misc.ts +82 -0
- package/src/core/utils/number.ts +78 -0
- package/src/core/utils/object.ts +206 -0
- package/src/core/utils/string.ts +112 -0
- package/src/core/utils/type-guards.ts +112 -0
- package/src/full.ts +187 -150
- package/src/index.ts +36 -36
- package/src/motion/animate.ts +113 -0
- package/src/motion/easing.ts +40 -0
- package/src/motion/flip.ts +176 -0
- package/src/motion/index.ts +41 -358
- package/src/motion/keyframes.ts +46 -0
- package/src/motion/reduced-motion.ts +17 -0
- package/src/motion/scroll.ts +57 -0
- package/src/motion/spring.ts +150 -0
- package/src/motion/stagger.ts +43 -0
- package/src/motion/timeline.ts +246 -0
- package/src/motion/transition.ts +51 -0
- package/src/motion/types.ts +198 -0
- package/src/reactive/batch.ts +22 -0
- package/src/reactive/computed.ts +92 -0
- package/src/reactive/core.ts +93 -0
- package/src/reactive/effect.ts +43 -0
- package/src/reactive/index.ts +23 -22
- package/src/reactive/internals.ts +105 -0
- package/src/reactive/linked.ts +56 -0
- package/src/reactive/persisted.ts +74 -0
- package/src/reactive/readonly.ts +35 -0
- package/src/reactive/signal.ts +20 -520
- package/src/reactive/type-guards.ts +22 -0
- package/src/reactive/untrack.ts +31 -0
- package/src/reactive/watch.ts +73 -0
- package/src/router/index.ts +41 -718
- package/src/router/links.ts +130 -0
- package/src/router/match.ts +106 -0
- package/src/router/navigation.ts +71 -0
- package/src/router/query.ts +35 -0
- package/src/router/router.ts +211 -0
- package/src/router/state.ts +46 -0
- package/src/router/types.ts +93 -0
- package/src/router/utils.ts +116 -0
- package/src/security/constants.ts +209 -0
- package/src/security/csp.ts +77 -0
- package/src/security/index.ts +4 -12
- package/src/security/sanitize-core.ts +343 -0
- package/src/security/sanitize.ts +66 -625
- package/src/security/trusted-types.ts +69 -0
- package/src/security/types.ts +40 -0
- package/src/store/create-store.ts +329 -0
- package/src/store/define-store.ts +48 -0
- package/src/store/devtools.ts +45 -0
- package/src/store/index.ts +22 -848
- package/src/store/mapping.ts +73 -0
- package/src/store/persisted.ts +61 -0
- package/src/store/plugins.ts +32 -0
- package/src/store/registry.ts +51 -0
- package/src/store/types.ts +94 -0
- package/src/store/utils.ts +141 -0
- package/src/store/watch.ts +52 -0
- package/src/view/directives/bind.ts +23 -0
- package/src/view/directives/class.ts +70 -0
- package/src/view/directives/for.ts +275 -0
- package/src/view/directives/html.ts +19 -0
- package/src/view/directives/if.ts +30 -0
- package/src/view/directives/index.ts +11 -0
- package/src/view/directives/model.ts +56 -0
- package/src/view/directives/on.ts +41 -0
- package/src/view/directives/ref.ts +41 -0
- package/src/view/directives/show.ts +26 -0
- package/src/view/directives/style.ts +47 -0
- package/src/view/directives/text.ts +15 -0
- package/src/view/evaluate.ts +274 -0
- package/src/view/index.ts +112 -1041
- package/src/view/mount.ts +200 -0
- package/src/view/process.ts +92 -0
- package/src/view/types.ts +44 -0
- package/dist/core/utils.d.ts +0 -313
- package/dist/core/utils.d.ts.map +0 -1
- package/src/core/utils.ts +0 -444
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object-focused utility helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/core/utils/object
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Checks if a value is a plain object (not null, array, or class instance).
|
|
8
|
+
*
|
|
9
|
+
* @param value - The value to check
|
|
10
|
+
* @returns True if the value is a plain object
|
|
11
|
+
*/
|
|
12
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if a key could cause prototype pollution.
|
|
15
|
+
* These keys are dangerous when used in object merging operations.
|
|
16
|
+
*
|
|
17
|
+
* @param key - The key to check
|
|
18
|
+
* @returns True if the key is a prototype pollution vector
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare function isPrototypePollutionKey(key: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a deep clone using structuredClone if available, otherwise fallback to JSON.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The type of value being cloned
|
|
27
|
+
* @param value - The value to clone
|
|
28
|
+
* @returns A deep copy of the value
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* When `structuredClone` is available (modern browsers, Node 17+, Bun), this function
|
|
32
|
+
* provides full deep cloning including circular references, Date, Map, Set, ArrayBuffer, etc.
|
|
33
|
+
*
|
|
34
|
+
* **JSON fallback limitations** (older environments without `structuredClone`):
|
|
35
|
+
* - **Throws** on circular references
|
|
36
|
+
* - **Drops** functions, `undefined`, and Symbol properties
|
|
37
|
+
* - **Transforms** Date → ISO string, Map/Set → empty object, BigInt → throws
|
|
38
|
+
* - **Loses** prototype chains and non-enumerable properties
|
|
39
|
+
*
|
|
40
|
+
* For guaranteed safe cloning of arbitrary data, ensure your environment supports
|
|
41
|
+
* `structuredClone` or pre-validate your data structure.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const original = { nested: { value: 1 } };
|
|
46
|
+
* const copy = clone(original);
|
|
47
|
+
* copy.nested.value = 2;
|
|
48
|
+
* console.log(original.nested.value); // 1
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function clone<T>(value: T): T;
|
|
52
|
+
/**
|
|
53
|
+
* Deep-merges plain objects into a new object.
|
|
54
|
+
* Later sources override earlier ones for primitive values.
|
|
55
|
+
* Objects are recursively merged.
|
|
56
|
+
*
|
|
57
|
+
* @param sources - Objects to merge
|
|
58
|
+
* @returns A new object with all sources merged as an intersection type
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* This function uses overloads to provide accurate intersection types for up to 5 sources.
|
|
62
|
+
* For more than 5 sources, the return type falls back to `Record<string, unknown>`.
|
|
63
|
+
*
|
|
64
|
+
* Note that deep merging creates a shallow intersection at the type level. Nested objects
|
|
65
|
+
* are merged at runtime, but TypeScript sees them as intersected types which may not
|
|
66
|
+
* perfectly represent the merged structure for deeply nested conflicting types.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const result = merge(
|
|
71
|
+
* { a: 1, nested: { x: 1 } },
|
|
72
|
+
* { b: 2, nested: { y: 2 } }
|
|
73
|
+
* );
|
|
74
|
+
* // Result: { a: 1, b: 2, nested: { x: 1, y: 2 } }
|
|
75
|
+
* // Type: { a: number; nested: { x: number } } & { b: number; nested: { y: number } }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @security This method is protected against prototype pollution attacks.
|
|
79
|
+
* Keys like `__proto__`, `constructor`, and `prototype` are ignored.
|
|
80
|
+
*/
|
|
81
|
+
export declare function merge<T1 extends Record<string, unknown>>(source1: T1): T1;
|
|
82
|
+
export declare function merge<T1 extends Record<string, unknown>, T2 extends Record<string, unknown>>(source1: T1, source2: T2): T1 & T2;
|
|
83
|
+
export declare function merge<T1 extends Record<string, unknown>, T2 extends Record<string, unknown>, T3 extends Record<string, unknown>>(source1: T1, source2: T2, source3: T3): T1 & T2 & T3;
|
|
84
|
+
export declare function merge<T1 extends Record<string, unknown>, T2 extends Record<string, unknown>, T3 extends Record<string, unknown>, T4 extends Record<string, unknown>>(source1: T1, source2: T2, source3: T3, source4: T4): T1 & T2 & T3 & T4;
|
|
85
|
+
export declare function merge<T1 extends Record<string, unknown>, T2 extends Record<string, unknown>, T3 extends Record<string, unknown>, T4 extends Record<string, unknown>, T5 extends Record<string, unknown>>(source1: T1, source2: T2, source3: T3, source4: T4, source5: T5): T1 & T2 & T3 & T4 & T5;
|
|
86
|
+
export declare function merge(...sources: Record<string, unknown>[]): Record<string, unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* Picks specified keys from an object.
|
|
89
|
+
*
|
|
90
|
+
* @template T - The object type
|
|
91
|
+
* @template K - The key type
|
|
92
|
+
* @param obj - The source object
|
|
93
|
+
* @param keys - Keys to pick
|
|
94
|
+
* @returns A new object with only the specified keys
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const user = { name: 'John', age: 30, email: 'john@example.com' };
|
|
99
|
+
* pick(user, ['name', 'email']); // { name: 'John', email: 'john@example.com' }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
103
|
+
/**
|
|
104
|
+
* Omits specified keys from an object.
|
|
105
|
+
*
|
|
106
|
+
* @template T - The object type
|
|
107
|
+
* @template K - The key type
|
|
108
|
+
* @param obj - The source object
|
|
109
|
+
* @param keys - Keys to omit
|
|
110
|
+
* @returns A new object without the specified keys
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const user = { name: 'John', age: 30, password: 'secret' };
|
|
115
|
+
* omit(user, ['password']); // { name: 'John', age: 30 }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
119
|
+
/**
|
|
120
|
+
* Checks if an object has a given own property.
|
|
121
|
+
*
|
|
122
|
+
* @template T - The object type
|
|
123
|
+
* @param obj - The object to check
|
|
124
|
+
* @param key - The property key
|
|
125
|
+
* @returns True if the property exists on the object
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* hasOwn({ a: 1 }, 'a'); // true
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function hasOwn<T extends object>(obj: T, key: PropertyKey): key is keyof T;
|
|
133
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../src/core/utils/object.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GA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AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,GAAG,IAAI,MAAM,CAAC,CAEjF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String-focused utility helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/core/utils/string
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Capitalizes the first letter of a string.
|
|
8
|
+
*
|
|
9
|
+
* @param str - The string to capitalize
|
|
10
|
+
* @returns The capitalized string
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* capitalize('hello'); // 'Hello'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function capitalize(str: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a string to kebab-case.
|
|
20
|
+
*
|
|
21
|
+
* @param str - The string to convert
|
|
22
|
+
* @returns The kebab-cased string
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* toKebabCase('myVariableName'); // 'my-variable-name'
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function toKebabCase(str: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Converts a string to camelCase.
|
|
32
|
+
*
|
|
33
|
+
* @param str - The string to convert
|
|
34
|
+
* @returns The camelCased string
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* toCamelCase('my-variable-name'); // 'myVariableName'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function toCamelCase(str: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Truncates a string to a maximum length.
|
|
44
|
+
*
|
|
45
|
+
* @param str - The string to truncate
|
|
46
|
+
* @param maxLength - The maximum length
|
|
47
|
+
* @param suffix - The suffix to append when truncating (default: '…')
|
|
48
|
+
* @returns The truncated string
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* truncate('Hello world', 8); // 'Hello w…'
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function truncate(str: string, maxLength: number, suffix?: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Converts a string to a URL-friendly slug.
|
|
58
|
+
*
|
|
59
|
+
* @param str - The string to slugify
|
|
60
|
+
* @returns The slugified string
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* slugify('Hello, World!'); // 'hello-world'
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function slugify(str: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Escapes a string for safe usage inside a RegExp.
|
|
70
|
+
*
|
|
71
|
+
* @param str - The string to escape
|
|
72
|
+
* @returns The escaped string
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* escapeRegExp('[a-z]+'); // '\\[a-z\\]+'
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function escapeRegExp(str: string): string;
|
|
80
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../src/core/utils/string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI/C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAM,GAAG,MAAM,CAK7E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ3C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/core/utils/type-guards
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Checks if a value is a DOM Element.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The value to check
|
|
10
|
+
* @returns True if the value is an Element
|
|
11
|
+
*/
|
|
12
|
+
export declare function isElement(value: unknown): value is Element;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if a value is a BQueryCollection-like object.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The value to check
|
|
17
|
+
* @returns True if the value has an elements array property
|
|
18
|
+
*/
|
|
19
|
+
export declare function isCollection(value: unknown): value is {
|
|
20
|
+
elements: Element[];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Checks if a value is a function.
|
|
24
|
+
*
|
|
25
|
+
* @param value - The value to check
|
|
26
|
+
* @returns True if the value is a function
|
|
27
|
+
*/
|
|
28
|
+
export declare function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a value is a string.
|
|
31
|
+
*
|
|
32
|
+
* @param value - The value to check
|
|
33
|
+
* @returns True if the value is a string
|
|
34
|
+
*/
|
|
35
|
+
export declare function isString(value: unknown): value is string;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a value is a number (excluding NaN).
|
|
38
|
+
*
|
|
39
|
+
* @param value - The value to check
|
|
40
|
+
* @returns True if the value is a valid number
|
|
41
|
+
*/
|
|
42
|
+
export declare function isNumber(value: unknown): value is number;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a value is a boolean.
|
|
45
|
+
*
|
|
46
|
+
* @param value - The value to check
|
|
47
|
+
* @returns True if the value is a boolean
|
|
48
|
+
*/
|
|
49
|
+
export declare function isBoolean(value: unknown): value is boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if a value is an array.
|
|
52
|
+
*
|
|
53
|
+
* @template T - The type of array elements
|
|
54
|
+
* @param value - The value to check
|
|
55
|
+
* @returns True if the value is an array
|
|
56
|
+
*/
|
|
57
|
+
export declare function isArray<T = unknown>(value: unknown): value is T[];
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a value is a Date instance.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The value to check
|
|
62
|
+
* @returns True if the value is a Date
|
|
63
|
+
*/
|
|
64
|
+
export declare function isDate(value: unknown): value is Date;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a value is a Promise-like object.
|
|
67
|
+
*
|
|
68
|
+
* @param value - The value to check
|
|
69
|
+
* @returns True if the value is a Promise-like object
|
|
70
|
+
*/
|
|
71
|
+
export declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Checks if a value is a non-null object.
|
|
74
|
+
*
|
|
75
|
+
* @param value - The value to check
|
|
76
|
+
* @returns True if the value is an object
|
|
77
|
+
*/
|
|
78
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
79
|
+
//# sourceMappingURL=type-guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../../../src/core/utils/type-guards.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;CAAE,CAE7E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAEnF;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,EAAE,CAEjE;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,CAQ1E;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const r = [];
|
|
2
|
+
let i = 0;
|
|
3
|
+
const n = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new WeakMap(), u = (e, s) => {
|
|
4
|
+
r.push(e);
|
|
5
|
+
try {
|
|
6
|
+
return s();
|
|
7
|
+
} finally {
|
|
8
|
+
r.pop();
|
|
9
|
+
}
|
|
10
|
+
}, o = () => r[r.length - 1], y = (e) => {
|
|
11
|
+
r.push(void 0);
|
|
12
|
+
try {
|
|
13
|
+
return e();
|
|
14
|
+
} finally {
|
|
15
|
+
r.pop();
|
|
16
|
+
}
|
|
17
|
+
}, b = (e) => {
|
|
18
|
+
if (i > 0) {
|
|
19
|
+
n.add(e);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
e();
|
|
23
|
+
}, d = () => {
|
|
24
|
+
for (const e of Array.from(n))
|
|
25
|
+
n.delete(e), e();
|
|
26
|
+
}, v = () => {
|
|
27
|
+
i += 1;
|
|
28
|
+
}, m = () => {
|
|
29
|
+
i -= 1, i === 0 && d();
|
|
30
|
+
}, l = (e, s) => {
|
|
31
|
+
let t = a.get(e);
|
|
32
|
+
t || (t = /* @__PURE__ */ new Set(), a.set(e, t)), t.add(s);
|
|
33
|
+
}, h = (e) => {
|
|
34
|
+
const s = a.get(e);
|
|
35
|
+
if (s) {
|
|
36
|
+
for (const t of s)
|
|
37
|
+
t.unsubscribe(e);
|
|
38
|
+
s.clear();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
class f {
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new computed value.
|
|
44
|
+
* @param compute - Function that computes the value
|
|
45
|
+
*/
|
|
46
|
+
constructor(s) {
|
|
47
|
+
this.compute = s, this.dirty = !0, this.subscribers = /* @__PURE__ */ new Set(), this.markDirty = () => {
|
|
48
|
+
this.dirty = !0;
|
|
49
|
+
const t = Array.from(this.subscribers);
|
|
50
|
+
for (const c of t)
|
|
51
|
+
b(c);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Gets the computed value, recomputing if dependencies changed.
|
|
56
|
+
* During untrack calls, getCurrentObserver returns undefined, preventing dependency tracking.
|
|
57
|
+
*/
|
|
58
|
+
get value() {
|
|
59
|
+
const s = o();
|
|
60
|
+
return s && (this.subscribers.add(s), l(s, this)), this.dirty && (this.dirty = !1, h(this.markDirty), this.cachedValue = u(this.markDirty, this.compute)), this.cachedValue;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reads the current computed value without tracking.
|
|
64
|
+
* Useful when you need the value but don't want to create a dependency.
|
|
65
|
+
*
|
|
66
|
+
* @returns The current cached value (recomputes if dirty)
|
|
67
|
+
*/
|
|
68
|
+
peek() {
|
|
69
|
+
return this.dirty && (this.dirty = !1, h(this.markDirty), this.cachedValue = u(this.markDirty, this.compute)), this.cachedValue;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Removes an observer from this computed's subscriber set.
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
unsubscribe(s) {
|
|
76
|
+
this.subscribers.delete(s);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const g = (e) => new f(e);
|
|
80
|
+
class p {
|
|
81
|
+
/**
|
|
82
|
+
* Creates a new signal with an initial value.
|
|
83
|
+
* @param _value - The initial value
|
|
84
|
+
*/
|
|
85
|
+
constructor(s) {
|
|
86
|
+
this._value = s, this.subscribers = /* @__PURE__ */ new Set();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets the current value and tracks the read if inside an observer.
|
|
90
|
+
* During untrack calls, getCurrentObserver returns undefined, preventing dependency tracking.
|
|
91
|
+
*/
|
|
92
|
+
get value() {
|
|
93
|
+
const s = o();
|
|
94
|
+
return s && (this.subscribers.add(s), l(s, this)), this._value;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Sets a new value and notifies all subscribers if the value changed.
|
|
98
|
+
* Uses Object.is for equality comparison.
|
|
99
|
+
*/
|
|
100
|
+
set value(s) {
|
|
101
|
+
if (Object.is(this._value, s)) return;
|
|
102
|
+
this._value = s;
|
|
103
|
+
const t = Array.from(this.subscribers);
|
|
104
|
+
for (const c of t)
|
|
105
|
+
b(c);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reads the current value without tracking.
|
|
109
|
+
* Useful when you need the value but don't want to create a dependency.
|
|
110
|
+
*
|
|
111
|
+
* @returns The current value
|
|
112
|
+
*/
|
|
113
|
+
peek() {
|
|
114
|
+
return this._value;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Updates the value using a function.
|
|
118
|
+
* Useful for updates based on the current value.
|
|
119
|
+
*
|
|
120
|
+
* @param updater - Function that receives current value and returns new value
|
|
121
|
+
*/
|
|
122
|
+
update(s) {
|
|
123
|
+
this.value = s(this._value);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Removes an observer from this signal's subscriber set.
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
unsubscribe(s) {
|
|
130
|
+
this.subscribers.delete(s);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const k = (e) => new p(e);
|
|
134
|
+
export {
|
|
135
|
+
f as C,
|
|
136
|
+
p as S,
|
|
137
|
+
h as a,
|
|
138
|
+
v as b,
|
|
139
|
+
g as c,
|
|
140
|
+
m as e,
|
|
141
|
+
k as s,
|
|
142
|
+
u as t,
|
|
143
|
+
y as w
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=core-COenAZjD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-COenAZjD.js","sources":["../src/reactive/internals.ts","../src/reactive/computed.ts","../src/reactive/core.ts"],"sourcesContent":["/**\n * Internal reactive plumbing shared across primitives.\n * @internal\n */\n\nexport type Observer = () => void;\nexport type CleanupFn = () => void;\n\n/**\n * Interface for reactive sources (Signals, Computed) that can unsubscribe observers.\n * @internal\n */\nexport interface ReactiveSource {\n unsubscribe(observer: Observer): void;\n}\n\nconst observerStack: Observer[] = [];\nlet batchDepth = 0;\nconst pendingObservers = new Set<Observer>();\n\n// Track dependencies for each observer to enable cleanup\nconst observerDependencies = new WeakMap<Observer, Set<ReactiveSource>>();\n\nexport const track = <T>(observer: Observer, fn: () => T): T => {\n observerStack.push(observer);\n try {\n return fn();\n } finally {\n observerStack.pop();\n }\n};\n\nexport const getCurrentObserver = (): Observer | undefined =>\n observerStack[observerStack.length - 1];\n\n/**\n * Executes a function without exposing the current observer to dependencies.\n * Unlike disabling tracking globally, this still allows nested reactive internals\n * (e.g., computed recomputation) to track their own dependencies.\n * @internal\n */\nexport const withoutCurrentObserver = <T>(fn: () => T): T => {\n // Push undefined to temporarily \"hide\" the current observer\n // This way, Signal.value reads won't link to the previous observer,\n // but nested track() calls (e.g., computed recompute) still work normally.\n observerStack.push(undefined as unknown as Observer);\n try {\n return fn();\n } finally {\n observerStack.pop();\n }\n};\n\nexport const scheduleObserver = (observer: Observer): void => {\n if (batchDepth > 0) {\n pendingObservers.add(observer);\n return;\n }\n observer();\n};\n\nconst flushObservers = (): void => {\n for (const observer of Array.from(pendingObservers)) {\n pendingObservers.delete(observer);\n observer();\n }\n};\n\nexport const beginBatch = (): void => {\n batchDepth += 1;\n};\n\nexport const endBatch = (): void => {\n batchDepth -= 1;\n if (batchDepth === 0) {\n flushObservers();\n }\n};\n\n/**\n * Registers a dependency between an observer and a reactive source.\n * @internal\n */\nexport const registerDependency = (observer: Observer, source: ReactiveSource): void => {\n let deps = observerDependencies.get(observer);\n if (!deps) {\n deps = new Set();\n observerDependencies.set(observer, deps);\n }\n deps.add(source);\n};\n\n/**\n * Clears all dependencies for an observer, unsubscribing from all sources.\n * @internal\n */\nexport const clearDependencies = (observer: Observer): void => {\n const deps = observerDependencies.get(observer);\n if (deps) {\n for (const source of deps) {\n source.unsubscribe(observer);\n }\n deps.clear();\n }\n};\n","/**\n * Computed reactive values.\n */\n\nimport {\n clearDependencies,\n getCurrentObserver,\n registerDependency,\n scheduleObserver,\n track,\n type ReactiveSource,\n} from './internals';\n\n/**\n * A computed value that derives from other reactive sources.\n *\n * Computed values are lazily evaluated and cached. They only\n * recompute when their dependencies change.\n *\n * @template T - The type of the computed value\n */\nexport class Computed<T> implements ReactiveSource {\n private cachedValue!: T;\n private dirty = true;\n private subscribers = new Set<() => void>();\n private readonly markDirty = () => {\n this.dirty = true;\n // Create snapshot to avoid issues with subscribers modifying the set during iteration\n const subscribersSnapshot = Array.from(this.subscribers);\n for (const subscriber of subscribersSnapshot) {\n scheduleObserver(subscriber);\n }\n };\n\n /**\n * Creates a new computed value.\n * @param compute - Function that computes the value\n */\n constructor(private readonly compute: () => T) {}\n\n /**\n * Gets the computed value, recomputing if dependencies changed.\n * During untrack calls, getCurrentObserver returns undefined, preventing dependency tracking.\n */\n get value(): T {\n const current = getCurrentObserver();\n if (current) {\n this.subscribers.add(current);\n registerDependency(current, this);\n }\n if (this.dirty) {\n this.dirty = false;\n // Clear old dependencies before recomputing\n clearDependencies(this.markDirty);\n this.cachedValue = track(this.markDirty, this.compute);\n }\n return this.cachedValue;\n }\n\n /**\n * Reads the current computed value without tracking.\n * Useful when you need the value but don't want to create a dependency.\n *\n * @returns The current cached value (recomputes if dirty)\n */\n peek(): T {\n if (this.dirty) {\n this.dirty = false;\n // Clear old dependencies before recomputing\n clearDependencies(this.markDirty);\n this.cachedValue = track(this.markDirty, this.compute);\n }\n return this.cachedValue;\n }\n\n /**\n * Removes an observer from this computed's subscriber set.\n * @internal\n */\n unsubscribe(observer: () => void): void {\n this.subscribers.delete(observer);\n }\n}\n\n/**\n * Creates a new computed value.\n *\n * @template T - The type of the computed value\n * @param fn - Function that computes the value from reactive sources\n * @returns A new Computed instance\n */\nexport const computed = <T>(fn: () => T): Computed<T> => new Computed(fn);\n","/**\n * Core reactive signals.\n */\n\nimport {\n getCurrentObserver,\n registerDependency,\n scheduleObserver,\n type ReactiveSource,\n} from './internals';\n\n/**\n * A reactive value container that notifies subscribers on change.\n *\n * Signals are the foundational primitive of the reactive system.\n * Reading a signal's value inside an effect or computed automatically\n * establishes a reactive dependency.\n *\n * @template T - The type of the stored value\n */\nexport class Signal<T> implements ReactiveSource {\n private subscribers = new Set<() => void>();\n\n /**\n * Creates a new signal with an initial value.\n * @param _value - The initial value\n */\n constructor(private _value: T) {}\n\n /**\n * Gets the current value and tracks the read if inside an observer.\n * During untrack calls, getCurrentObserver returns undefined, preventing dependency tracking.\n */\n get value(): T {\n const current = getCurrentObserver();\n if (current) {\n this.subscribers.add(current);\n registerDependency(current, this);\n }\n return this._value;\n }\n\n /**\n * Sets a new value and notifies all subscribers if the value changed.\n * Uses Object.is for equality comparison.\n */\n set value(next: T) {\n if (Object.is(this._value, next)) return;\n this._value = next;\n // Create snapshot to avoid issues with subscribers modifying the set during iteration\n const subscribersSnapshot = Array.from(this.subscribers);\n for (const subscriber of subscribersSnapshot) {\n scheduleObserver(subscriber);\n }\n }\n\n /**\n * Reads the current value without tracking.\n * Useful when you need the value but don't want to create a dependency.\n *\n * @returns The current value\n */\n peek(): T {\n return this._value;\n }\n\n /**\n * Updates the value using a function.\n * Useful for updates based on the current value.\n *\n * @param updater - Function that receives current value and returns new value\n */\n update(updater: (current: T) => T): void {\n this.value = updater(this._value);\n }\n\n /**\n * Removes an observer from this signal's subscriber set.\n * @internal\n */\n unsubscribe(observer: () => void): void {\n this.subscribers.delete(observer);\n }\n}\n\n/**\n * Creates a new reactive signal.\n *\n * @template T - The type of the signal value\n * @param value - The initial value\n * @returns A new Signal instance\n */\nexport const signal = <T>(value: T): Signal<T> => new Signal(value);\n"],"names":["observerStack","batchDepth","pendingObservers","observerDependencies","track","observer","fn","getCurrentObserver","withoutCurrentObserver","scheduleObserver","flushObservers","beginBatch","endBatch","registerDependency","source","deps","clearDependencies","Computed","compute","subscribersSnapshot","subscriber","current","computed","Signal","_value","next","updater","signal","value"],"mappings":"AAgBA,MAAMA,IAA4B,CAAA;AAClC,IAAIC,IAAa;AACjB,MAAMC,wBAAuB,IAAA,GAGvBC,wBAA2B,QAAA,GAEpBC,IAAQ,CAAIC,GAAoBC,MAAmB;AAC9D,EAAAN,EAAc,KAAKK,CAAQ;AAC3B,MAAI;AACF,WAAOC,EAAA;AAAA,EACT,UAAA;AACE,IAAAN,EAAc,IAAA;AAAA,EAChB;AACF,GAEaO,IAAqB,MAChCP,EAAcA,EAAc,SAAS,CAAC,GAQ3BQ,IAAyB,CAAIF,MAAmB;AAI3D,EAAAN,EA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