flexium 0.9.1 → 0.10.4
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 +14 -0
- package/dist/{DrawText-CJikXQjL.d.cts → DrawText-ccZrs3Xs.d.cts} +1 -1
- package/dist/{DrawText-Bvzl40Vi.d.ts → DrawText-ngwNNh8O.d.ts} +1 -1
- package/dist/advanced.d.cts +1 -1
- package/dist/advanced.d.ts +1 -1
- package/dist/advanced.js +1 -1
- package/dist/advanced.js.map +1 -1
- package/dist/advanced.mjs +1 -1
- package/dist/advanced.mjs.map +1 -1
- package/dist/canvas.d.cts +4 -4
- package/dist/canvas.d.ts +4 -4
- package/dist/canvas.js +1 -1
- package/dist/canvas.mjs +1 -1
- package/dist/chunk-3AWR7IKE.js +2 -0
- package/dist/chunk-3AWR7IKE.js.map +1 -0
- package/dist/chunk-3BQXIHYI.mjs +3 -0
- package/dist/chunk-3BQXIHYI.mjs.map +1 -0
- package/dist/chunk-5236IK5I.js +2 -0
- package/dist/chunk-5236IK5I.js.map +1 -0
- package/dist/{chunk-JHJHIMWD.js → chunk-63AW5ZOC.js} +2 -2
- package/dist/{chunk-JHJHIMWD.js.map → chunk-63AW5ZOC.js.map} +1 -1
- package/dist/chunk-6K44QCMT.mjs +3 -0
- package/dist/chunk-6K44QCMT.mjs.map +1 -0
- package/dist/chunk-7Q4UE442.mjs +2 -0
- package/dist/chunk-7Q4UE442.mjs.map +1 -0
- package/dist/chunk-AJT35P3Z.js +3 -0
- package/dist/chunk-AJT35P3Z.js.map +1 -0
- package/dist/chunk-AYQMU7XC.js +3 -0
- package/dist/chunk-AYQMU7XC.js.map +1 -0
- package/dist/chunk-B7VP6HBY.mjs +2 -0
- package/dist/chunk-B7VP6HBY.mjs.map +1 -0
- package/dist/{chunk-R5CS7UZG.mjs → chunk-BYHIHYRR.mjs} +2 -2
- package/dist/{chunk-R5CS7UZG.mjs.map → chunk-BYHIHYRR.mjs.map} +1 -1
- package/dist/chunk-HLPVL6EK.mjs +2 -0
- package/dist/{chunk-RUXAK74B.mjs.map → chunk-HLPVL6EK.mjs.map} +1 -1
- package/dist/{chunk-HDCPA76O.mjs → chunk-KJPIJNFH.mjs} +2 -2
- package/dist/chunk-KJPIJNFH.mjs.map +1 -0
- package/dist/chunk-PVPY55Z7.mjs +2 -0
- package/dist/{chunk-TRIEKNVZ.mjs.map → chunk-PVPY55Z7.mjs.map} +1 -1
- package/dist/chunk-Q7WT5IIF.mjs +3 -0
- package/dist/chunk-Q7WT5IIF.mjs.map +1 -0
- package/dist/chunk-S3EDPCYT.js +3 -0
- package/dist/chunk-S3EDPCYT.js.map +1 -0
- package/dist/{chunk-L4C5UBOX.js → chunk-WOHSSPKD.js} +2 -2
- package/dist/chunk-WOHSSPKD.js.map +1 -0
- package/dist/{chunk-DFG62GKW.js → chunk-WXEHDEIH.js} +2 -2
- package/dist/{chunk-DFG62GKW.js.map → chunk-WXEHDEIH.js.map} +1 -1
- package/dist/{chunk-3P6DMEGB.js → chunk-YDZ37ZZ4.js} +2 -2
- package/dist/{chunk-3P6DMEGB.js.map → chunk-YDZ37ZZ4.js.map} +1 -1
- package/dist/{components-D4WeooPi.d.ts → components-B7KQ8C-i.d.ts} +2 -2
- package/dist/{components-DZy2r6m5.d.cts → components-CxnAnbpI.d.cts} +2 -2
- package/dist/core.d.cts +48 -136
- package/dist/core.d.ts +48 -136
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/dom.d.cts +2 -2
- package/dist/dom.d.ts +2 -2
- package/dist/dom.js +1 -1
- package/dist/dom.js.map +1 -1
- package/dist/dom.mjs +1 -1
- package/dist/dom.mjs.map +1 -1
- package/dist/{effect-BlnnM1t5.d.cts → effect-14CxUU8r.d.cts} +8 -4
- package/dist/{effect-BlnnM1t5.d.ts → effect-14CxUU8r.d.ts} +8 -4
- package/dist/effect-3LUCHSAZ.mjs +2 -0
- package/dist/effect-3LUCHSAZ.mjs.map +1 -0
- package/dist/effect-K45UU3N4.js +2 -0
- package/dist/effect-K45UU3N4.js.map +1 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/interactive.d.cts +15 -10
- package/dist/interactive.d.ts +15 -10
- package/dist/interactive.js +1 -1
- package/dist/interactive.js.map +1 -1
- package/dist/interactive.mjs +1 -1
- package/dist/interactive.mjs.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/{portal-C3ESJhlv.d.ts → portal-CVqrpmHd.d.ts} +2 -2
- package/dist/{portal-CAEbiMUZ.d.cts → portal-NLlE-fNZ.d.cts} +2 -2
- package/dist/primitives/layout.js +1 -1
- package/dist/primitives/layout.mjs +1 -1
- package/dist/primitives/motion.js +1 -1
- package/dist/primitives/motion.mjs +1 -1
- package/dist/primitives/ui.d.cts +3 -3
- package/dist/primitives/ui.d.ts +3 -3
- package/dist/primitives/ui.js +1 -1
- package/dist/primitives/ui.js.map +1 -1
- package/dist/primitives/ui.mjs +1 -1
- package/dist/primitives/ui.mjs.map +1 -1
- package/dist/primitives.d.cts +4 -4
- package/dist/primitives.d.ts +4 -4
- package/dist/primitives.js +1 -1
- package/dist/primitives.js.map +1 -1
- package/dist/primitives.mjs +1 -1
- package/dist/primitives.mjs.map +1 -1
- package/dist/router.d.cts +3 -3
- package/dist/router.d.ts +3 -3
- package/dist/router.js +1 -1
- package/dist/router.mjs +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +1 -1
- package/dist/server.mjs.map +1 -1
- package/dist/signal-2QUI7H7B.js +2 -0
- package/dist/{signal-3YZHUCLL.js.map → signal-2QUI7H7B.js.map} +1 -1
- package/dist/signal-C6936A3J.d.cts +175 -0
- package/dist/signal-C6936A3J.d.ts +175 -0
- package/dist/signal-L3ZWGOVT.mjs +2 -0
- package/dist/{signal-F2HEYB6F.mjs.map → signal-L3ZWGOVT.mjs.map} +1 -1
- package/dist/test-exports.d.cts +6 -6
- package/dist/test-exports.d.ts +6 -6
- package/dist/test-exports.js +1 -1
- package/dist/test-exports.mjs +1 -1
- package/package.json +2 -1
- package/dist/chunk-2ZHUQBNI.mjs +0 -2
- package/dist/chunk-2ZHUQBNI.mjs.map +0 -1
- package/dist/chunk-HDCPA76O.mjs.map +0 -1
- package/dist/chunk-J4CK5NRW.mjs +0 -3
- package/dist/chunk-J4CK5NRW.mjs.map +0 -1
- package/dist/chunk-JEDCNAAI.mjs +0 -3
- package/dist/chunk-JEDCNAAI.mjs.map +0 -1
- package/dist/chunk-L4C5UBOX.js.map +0 -1
- package/dist/chunk-M4ANLZ6P.js +0 -3
- package/dist/chunk-M4ANLZ6P.js.map +0 -1
- package/dist/chunk-RDA77IE6.js +0 -2
- package/dist/chunk-RDA77IE6.js.map +0 -1
- package/dist/chunk-RUXAK74B.mjs +0 -2
- package/dist/chunk-TRIEKNVZ.mjs +0 -2
- package/dist/chunk-VIVO4FHN.js +0 -3
- package/dist/chunk-VIVO4FHN.js.map +0 -1
- package/dist/chunk-XLE6SMWX.mjs +0 -3
- package/dist/chunk-XLE6SMWX.mjs.map +0 -1
- package/dist/chunk-YGMMJWAA.js +0 -3
- package/dist/chunk-YGMMJWAA.js.map +0 -1
- package/dist/signal-3YZHUCLL.js +0 -2
- package/dist/signal-Dxh9PsKr.d.cts +0 -69
- package/dist/signal-Dxh9PsKr.d.ts +0 -69
- package/dist/signal-F2HEYB6F.mjs +0 -2
package/dist/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server/index.ts"],"names":["VOID_ELEMENTS","renderToString","node","escapeHtml","isSignal","children","result","type","props","html","key","value","styleStr","k","v","str"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/server/index.ts"],"names":["VOID_ELEMENTS","renderToString","node","escapeHtml","isSignal","children","result","type","props","html","key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AAc,GAAA,CAAIO,CAAI,CAAA,CACxBE,CAAAA,EAAQ,IAAA,EAERA,CAAAA,EAAQ,GAAA,CACJJ,CAAAA,GACFI,GAAQ,KAAA,CAAM,OAAA,CAAQJ,CAAQ,CAAA,CAC1BA,EAAS,GAAA,CAAIJ,CAAc,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA,CACpCA,CAAAA,CAAeI,CAAQ,CAAA,CAAA,CAE7BI,CAAAA,EAAQ,CAAA,EAAA,EAAKF,CAAI,CAAA,CAAA,CAAA,CAAA,CAGZE,CACT,CAEA,OAAO,EACT,CAEA,SAASN,CAAAA,CAAWY,CAAAA,CAAqB,CACvC,OAAOA,EACJ,OAAA,CAAQ,IAAA,CAAM,OAAO,CAAA,CACrB,OAAA,CAAQ,IAAA,CAAM,MAAM,CAAA,CACpB,QAAQ,IAAA,CAAM,MAAM,CAAA,CACpB,OAAA,CAAQ,KAAM,QAAQ,CAAA,CACtB,OAAA,CAAQ,IAAA,CAAM,QAAQ,CAC3B","file":"server.mjs","sourcesContent":["import { isSignal } from '../core/signal'\n\nconst VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function renderToString(node: any): string {\n if (node === null || node === undefined || node === false) {\n return ''\n }\n\n if (typeof node === 'string' || typeof node === 'number') {\n return escapeHtml(String(node))\n }\n\n if (Array.isArray(node)) {\n return node.map(renderToString).join('')\n }\n\n if (isSignal(node)) {\n return renderToString(node.value)\n }\n\n // Handle fragments (type === null or type === 'fragment')\n if (node.type === null || node.type === 'fragment') {\n const children = node.children || node.props?.children\n if (children) {\n return Array.isArray(children)\n ? children.map(renderToString).join('')\n : renderToString(children)\n }\n return ''\n }\n\n if (typeof node.type === 'function') {\n const result = node.type({ ...node.props, children: node.children })\n return renderToString(result)\n }\n\n if (typeof node.type === 'string') {\n const { type, props, children } = node\n let html = `<${type}`\n\n if (props) {\n for (const key in props) {\n const value = props[key]\n if (\n key === 'children' ||\n key.startsWith('on') ||\n value === null ||\n value === undefined ||\n value === false\n ) {\n continue\n }\n\n // Security: Validate attribute name to prevent injection\n // Only allow alphanumeric, hyphens, and colons\n if (!/^[a-zA-Z0-9-:]+$/.test(key)) {\n continue\n }\n\n if (key === 'className' || key === 'class') {\n html += ` class=\"${escapeHtml(value)}\"`\n } else if (key === 'style' && typeof value === 'object') {\n const styleStr = Object.entries(value)\n .map(\n ([k, v]) => `${k.replace(/([A-Z])/g, '-$1').toLowerCase()}:${v}`\n )\n .join(';')\n html += ` style=\"${escapeHtml(styleStr)}\"`\n } else {\n html += ` ${key}=\"${escapeHtml(String(value))}\"`\n }\n }\n }\n\n if (VOID_ELEMENTS.has(type)) {\n html += '/>'\n } else {\n html += '>'\n if (children) {\n html += Array.isArray(children)\n ? children.map(renderToString).join('')\n : renderToString(children)\n }\n html += `</${type}>`\n }\n\n return html\n }\n\n return ''\n}\n\nfunction escapeHtml(str: string): string {\n return str\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunk5236IK5I_js=require('./chunk-5236IK5I.js');require('./chunk-AJT35P3Z.js');Object.defineProperty(exports,"ComputedNode",{enumerable:true,get:function(){return chunk5236IK5I_js.e}});Object.defineProperty(exports,"SignalNode",{enumerable:true,get:function(){return chunk5236IK5I_js.d}});Object.defineProperty(exports,"createResource",{enumerable:true,get:function(){return chunk5236IK5I_js.h}});Object.defineProperty(exports,"getDevToolsHooks",{enumerable:true,get:function(){return chunk5236IK5I_js.b}});Object.defineProperty(exports,"isSignal",{enumerable:true,get:function(){return chunk5236IK5I_js.f}});Object.defineProperty(exports,"onCleanup",{enumerable:true,get:function(){return chunk5236IK5I_js.g}});Object.defineProperty(exports,"setDevToolsHooks",{enumerable:true,get:function(){return chunk5236IK5I_js.c}});//# sourceMappingURL=signal-2QUI7H7B.js.map
|
|
2
|
+
//# sourceMappingURL=signal-2QUI7H7B.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"signal-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"signal-2QUI7H7B.js"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph.ts
|
|
3
|
+
*
|
|
4
|
+
* Core Graph Data Structures & Algorithms
|
|
5
|
+
* Implements the "Hardcore" Doubly Linked List for dependency tracking.
|
|
6
|
+
*
|
|
7
|
+
* This module is purely internal and has NO dependencies on other core modules
|
|
8
|
+
* to avoid circular references.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Flags for subscriber state (Optimization: Bitmasking)
|
|
12
|
+
*/
|
|
13
|
+
declare const enum SubscriberFlags {
|
|
14
|
+
Running = 1,
|
|
15
|
+
Notified = 2,
|
|
16
|
+
Dirty = 4,
|
|
17
|
+
Stale = 8,
|
|
18
|
+
Tracking = 16
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Node type identifiers for fast type checking (Performance: Avoid instanceof)
|
|
22
|
+
*/
|
|
23
|
+
declare const enum NodeType {
|
|
24
|
+
Signal = 1,
|
|
25
|
+
Computed = 2,
|
|
26
|
+
Effect = 3,
|
|
27
|
+
Resource = 4
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Link node connecting a Subscriber (Effect/Computed) to a Dependency (Signal/Computed).
|
|
31
|
+
*
|
|
32
|
+
* ASCII Visualization of the Doubly Linked Graph:
|
|
33
|
+
*
|
|
34
|
+
* [Signal A] <==> [Link 1] <==> [Effect B]
|
|
35
|
+
* ^
|
|
36
|
+
* | (Prev/Next Sub on Signal A)
|
|
37
|
+
* v
|
|
38
|
+
* [Link 2] <==> [Effect C]
|
|
39
|
+
*
|
|
40
|
+
* Each Link serves as a node in TWO lists simultaneously:
|
|
41
|
+
* 1. The Subscriber's list of dependencies (prevDep/nextDep)
|
|
42
|
+
* 2. The Dependency's list of subscribers (prevSub/nextSub)
|
|
43
|
+
*/
|
|
44
|
+
interface Link {
|
|
45
|
+
dep: IObservable | undefined;
|
|
46
|
+
sub: ISubscriber | undefined;
|
|
47
|
+
prevSub: Link | undefined;
|
|
48
|
+
nextSub: Link | undefined;
|
|
49
|
+
prevDep: Link | undefined;
|
|
50
|
+
nextDep: Link | undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Base interface for subscriber nodes (Effect, Computed)
|
|
54
|
+
*/
|
|
55
|
+
interface ISubscriber {
|
|
56
|
+
execute(): void;
|
|
57
|
+
depsHead: Link | undefined;
|
|
58
|
+
flags: SubscriberFlags;
|
|
59
|
+
nodeType: NodeType;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Base interface for observable nodes (Signal, Computed)
|
|
63
|
+
*/
|
|
64
|
+
interface IObservable {
|
|
65
|
+
subsHead: Link | undefined;
|
|
66
|
+
version: number;
|
|
67
|
+
notify(): void;
|
|
68
|
+
nodeType: NodeType;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Signal System - Fine-grained reactivity without VDOM
|
|
73
|
+
*
|
|
74
|
+
* Architecture:
|
|
75
|
+
* - Signals are reactive primitives that notify subscribers on change
|
|
76
|
+
* - Computed signals automatically track dependencies and memoize results
|
|
77
|
+
* - Effects run side effects and auto-track dependencies
|
|
78
|
+
* - Batching prevents cascading updates for performance
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Base interface for reactive signals
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
interface Signal<T> {
|
|
86
|
+
value: T;
|
|
87
|
+
(): T;
|
|
88
|
+
set(value: T): void;
|
|
89
|
+
peek(): T;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Computed signal interface (read-only)
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
interface Computed<T> {
|
|
96
|
+
readonly value: T;
|
|
97
|
+
(): T;
|
|
98
|
+
peek(): T;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Internal signal node for writable signals
|
|
102
|
+
*/
|
|
103
|
+
declare class SignalNode<T> implements IObservable {
|
|
104
|
+
private _value;
|
|
105
|
+
version: number;
|
|
106
|
+
nodeType: NodeType;
|
|
107
|
+
subsHead: Link | undefined;
|
|
108
|
+
constructor(_value: T);
|
|
109
|
+
/**
|
|
110
|
+
* Compatibility wrapper for legacy .value access
|
|
111
|
+
*/
|
|
112
|
+
get value(): T;
|
|
113
|
+
set value(newValue: T);
|
|
114
|
+
get(): T;
|
|
115
|
+
set(newValue: T): void;
|
|
116
|
+
peek(): T;
|
|
117
|
+
notify(): void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Internal computed node for derived values
|
|
121
|
+
*/
|
|
122
|
+
declare class ComputedNode<T> implements ISubscriber, IObservable {
|
|
123
|
+
private computeFn;
|
|
124
|
+
version: number;
|
|
125
|
+
nodeType: NodeType;
|
|
126
|
+
flags: number;
|
|
127
|
+
subsHead: Link | undefined;
|
|
128
|
+
depsHead: Link | undefined;
|
|
129
|
+
private _value;
|
|
130
|
+
private lastCleanEpoch;
|
|
131
|
+
constructor(computeFn: () => T);
|
|
132
|
+
/**
|
|
133
|
+
* Compatibility wrapper for legacy .value access
|
|
134
|
+
*/
|
|
135
|
+
get value(): T;
|
|
136
|
+
execute(): void;
|
|
137
|
+
private _updateIfDirty;
|
|
138
|
+
private _needsRefetch;
|
|
139
|
+
get(): T;
|
|
140
|
+
peek(): T;
|
|
141
|
+
notify(): void;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check if a value is a signal
|
|
145
|
+
* @internal Use state() which handles all reactive patterns
|
|
146
|
+
*/
|
|
147
|
+
declare function isSignal(value: unknown): value is SignalNode<any> | ComputedNode<any>;
|
|
148
|
+
/**
|
|
149
|
+
* Registers a cleanup function that runs before the current effect re-runs or is disposed
|
|
150
|
+
*
|
|
151
|
+
* @param fn - Cleanup function
|
|
152
|
+
*/
|
|
153
|
+
declare function onCleanup(fn: () => void): void;
|
|
154
|
+
/**
|
|
155
|
+
* Resource interface for async data
|
|
156
|
+
*/
|
|
157
|
+
interface Resource<T> extends Signal<T | undefined> {
|
|
158
|
+
loading: boolean;
|
|
159
|
+
error: any;
|
|
160
|
+
state: 'unresolved' | 'pending' | 'ready' | 'refreshing' | 'errored';
|
|
161
|
+
latest: T | undefined;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Creates a resource for handling async data
|
|
165
|
+
* @internal Use state(async () => ...) instead which returns [data, refetch, status, error]
|
|
166
|
+
*/
|
|
167
|
+
declare function createResource<T, S = any>(source: S | Signal<S> | (() => S), fetcher: (source: S, { value, refetching }: {
|
|
168
|
+
value: T | undefined;
|
|
169
|
+
refetching: any;
|
|
170
|
+
}) => Promise<T>): [Resource<T>, {
|
|
171
|
+
mutate: (v: T | undefined) => void;
|
|
172
|
+
refetch: () => void;
|
|
173
|
+
}];
|
|
174
|
+
|
|
175
|
+
export { ComputedNode as C, SignalNode as S, type Signal as a, type Computed as b, createResource as c, isSignal as i, onCleanup as o };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph.ts
|
|
3
|
+
*
|
|
4
|
+
* Core Graph Data Structures & Algorithms
|
|
5
|
+
* Implements the "Hardcore" Doubly Linked List for dependency tracking.
|
|
6
|
+
*
|
|
7
|
+
* This module is purely internal and has NO dependencies on other core modules
|
|
8
|
+
* to avoid circular references.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Flags for subscriber state (Optimization: Bitmasking)
|
|
12
|
+
*/
|
|
13
|
+
declare const enum SubscriberFlags {
|
|
14
|
+
Running = 1,
|
|
15
|
+
Notified = 2,
|
|
16
|
+
Dirty = 4,
|
|
17
|
+
Stale = 8,
|
|
18
|
+
Tracking = 16
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Node type identifiers for fast type checking (Performance: Avoid instanceof)
|
|
22
|
+
*/
|
|
23
|
+
declare const enum NodeType {
|
|
24
|
+
Signal = 1,
|
|
25
|
+
Computed = 2,
|
|
26
|
+
Effect = 3,
|
|
27
|
+
Resource = 4
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Link node connecting a Subscriber (Effect/Computed) to a Dependency (Signal/Computed).
|
|
31
|
+
*
|
|
32
|
+
* ASCII Visualization of the Doubly Linked Graph:
|
|
33
|
+
*
|
|
34
|
+
* [Signal A] <==> [Link 1] <==> [Effect B]
|
|
35
|
+
* ^
|
|
36
|
+
* | (Prev/Next Sub on Signal A)
|
|
37
|
+
* v
|
|
38
|
+
* [Link 2] <==> [Effect C]
|
|
39
|
+
*
|
|
40
|
+
* Each Link serves as a node in TWO lists simultaneously:
|
|
41
|
+
* 1. The Subscriber's list of dependencies (prevDep/nextDep)
|
|
42
|
+
* 2. The Dependency's list of subscribers (prevSub/nextSub)
|
|
43
|
+
*/
|
|
44
|
+
interface Link {
|
|
45
|
+
dep: IObservable | undefined;
|
|
46
|
+
sub: ISubscriber | undefined;
|
|
47
|
+
prevSub: Link | undefined;
|
|
48
|
+
nextSub: Link | undefined;
|
|
49
|
+
prevDep: Link | undefined;
|
|
50
|
+
nextDep: Link | undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Base interface for subscriber nodes (Effect, Computed)
|
|
54
|
+
*/
|
|
55
|
+
interface ISubscriber {
|
|
56
|
+
execute(): void;
|
|
57
|
+
depsHead: Link | undefined;
|
|
58
|
+
flags: SubscriberFlags;
|
|
59
|
+
nodeType: NodeType;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Base interface for observable nodes (Signal, Computed)
|
|
63
|
+
*/
|
|
64
|
+
interface IObservable {
|
|
65
|
+
subsHead: Link | undefined;
|
|
66
|
+
version: number;
|
|
67
|
+
notify(): void;
|
|
68
|
+
nodeType: NodeType;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Signal System - Fine-grained reactivity without VDOM
|
|
73
|
+
*
|
|
74
|
+
* Architecture:
|
|
75
|
+
* - Signals are reactive primitives that notify subscribers on change
|
|
76
|
+
* - Computed signals automatically track dependencies and memoize results
|
|
77
|
+
* - Effects run side effects and auto-track dependencies
|
|
78
|
+
* - Batching prevents cascading updates for performance
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Base interface for reactive signals
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
interface Signal<T> {
|
|
86
|
+
value: T;
|
|
87
|
+
(): T;
|
|
88
|
+
set(value: T): void;
|
|
89
|
+
peek(): T;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Computed signal interface (read-only)
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
interface Computed<T> {
|
|
96
|
+
readonly value: T;
|
|
97
|
+
(): T;
|
|
98
|
+
peek(): T;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Internal signal node for writable signals
|
|
102
|
+
*/
|
|
103
|
+
declare class SignalNode<T> implements IObservable {
|
|
104
|
+
private _value;
|
|
105
|
+
version: number;
|
|
106
|
+
nodeType: NodeType;
|
|
107
|
+
subsHead: Link | undefined;
|
|
108
|
+
constructor(_value: T);
|
|
109
|
+
/**
|
|
110
|
+
* Compatibility wrapper for legacy .value access
|
|
111
|
+
*/
|
|
112
|
+
get value(): T;
|
|
113
|
+
set value(newValue: T);
|
|
114
|
+
get(): T;
|
|
115
|
+
set(newValue: T): void;
|
|
116
|
+
peek(): T;
|
|
117
|
+
notify(): void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Internal computed node for derived values
|
|
121
|
+
*/
|
|
122
|
+
declare class ComputedNode<T> implements ISubscriber, IObservable {
|
|
123
|
+
private computeFn;
|
|
124
|
+
version: number;
|
|
125
|
+
nodeType: NodeType;
|
|
126
|
+
flags: number;
|
|
127
|
+
subsHead: Link | undefined;
|
|
128
|
+
depsHead: Link | undefined;
|
|
129
|
+
private _value;
|
|
130
|
+
private lastCleanEpoch;
|
|
131
|
+
constructor(computeFn: () => T);
|
|
132
|
+
/**
|
|
133
|
+
* Compatibility wrapper for legacy .value access
|
|
134
|
+
*/
|
|
135
|
+
get value(): T;
|
|
136
|
+
execute(): void;
|
|
137
|
+
private _updateIfDirty;
|
|
138
|
+
private _needsRefetch;
|
|
139
|
+
get(): T;
|
|
140
|
+
peek(): T;
|
|
141
|
+
notify(): void;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check if a value is a signal
|
|
145
|
+
* @internal Use state() which handles all reactive patterns
|
|
146
|
+
*/
|
|
147
|
+
declare function isSignal(value: unknown): value is SignalNode<any> | ComputedNode<any>;
|
|
148
|
+
/**
|
|
149
|
+
* Registers a cleanup function that runs before the current effect re-runs or is disposed
|
|
150
|
+
*
|
|
151
|
+
* @param fn - Cleanup function
|
|
152
|
+
*/
|
|
153
|
+
declare function onCleanup(fn: () => void): void;
|
|
154
|
+
/**
|
|
155
|
+
* Resource interface for async data
|
|
156
|
+
*/
|
|
157
|
+
interface Resource<T> extends Signal<T | undefined> {
|
|
158
|
+
loading: boolean;
|
|
159
|
+
error: any;
|
|
160
|
+
state: 'unresolved' | 'pending' | 'ready' | 'refreshing' | 'errored';
|
|
161
|
+
latest: T | undefined;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Creates a resource for handling async data
|
|
165
|
+
* @internal Use state(async () => ...) instead which returns [data, refetch, status, error]
|
|
166
|
+
*/
|
|
167
|
+
declare function createResource<T, S = any>(source: S | Signal<S> | (() => S), fetcher: (source: S, { value, refetching }: {
|
|
168
|
+
value: T | undefined;
|
|
169
|
+
refetching: any;
|
|
170
|
+
}) => Promise<T>): [Resource<T>, {
|
|
171
|
+
mutate: (v: T | undefined) => void;
|
|
172
|
+
refetch: () => void;
|
|
173
|
+
}];
|
|
174
|
+
|
|
175
|
+
export { ComputedNode as C, SignalNode as S, type Signal as a, type Computed as b, createResource as c, isSignal as i, onCleanup as o };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export{e as ComputedNode,d as SignalNode,h as createResource,b as getDevToolsHooks,f as isSignal,g as onCleanup,c as setDevToolsHooks}from'./chunk-B7VP6HBY.mjs';import'./chunk-Q7WT5IIF.mjs';//# sourceMappingURL=signal-L3ZWGOVT.mjs.map
|
|
2
|
+
//# sourceMappingURL=signal-L3ZWGOVT.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"signal-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"signal-L3ZWGOVT.mjs"}
|
package/dist/test-exports.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export { c as
|
|
1
|
+
export { c as createResource, i as isSignal, o as onCleanup } from './signal-C6936A3J.cjs';
|
|
2
|
+
export { e as effect } from './effect-14CxUU8r.cjs';
|
|
3
|
+
export { r as root, u as untrack } from './owner-QS9tPwPr.cjs';
|
|
2
4
|
export { s as sync } from './sync-Z4QqUDjF.cjs';
|
|
3
5
|
export { state } from './core.cjs';
|
|
4
6
|
import { a as FNodeChild } from './renderer-DSLb-FGg.cjs';
|
|
5
|
-
export { h as Link, O as Outlet, g as Route, f as Router, e as createLocation, m as matchPath, r as router } from './components-
|
|
6
|
-
import { L as ListComponent } from './portal-
|
|
7
|
-
export { P as Portal, a as createReactiveRoot, d as domRenderer, f, r as render } from './portal-
|
|
7
|
+
export { h as Link, O as Outlet, g as Route, f as Router, e as createLocation, m as matchPath, r as router } from './components-CxnAnbpI.cjs';
|
|
8
|
+
import { L as ListComponent } from './portal-NLlE-fNZ.cjs';
|
|
9
|
+
export { P as Portal, a as createReactiveRoot, d as domRenderer, f, r as render } from './portal-NLlE-fNZ.cjs';
|
|
8
10
|
export { c as cleanupMotionState } from './Motion-BrOAJzgH.cjs';
|
|
9
|
-
export { e as effect } from './effect-BlnnM1t5.cjs';
|
|
10
|
-
export { r as root, u as untrack } from './owner-QS9tPwPr.cjs';
|
|
11
11
|
|
|
12
12
|
/** Marker symbol for List components */
|
|
13
13
|
declare const LIST_MARKER: unique symbol;
|
package/dist/test-exports.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export { c as
|
|
1
|
+
export { c as createResource, i as isSignal, o as onCleanup } from './signal-C6936A3J.js';
|
|
2
|
+
export { e as effect } from './effect-14CxUU8r.js';
|
|
3
|
+
export { r as root, u as untrack } from './owner-QS9tPwPr.js';
|
|
2
4
|
export { s as sync } from './sync-Z4QqUDjF.js';
|
|
3
5
|
export { state } from './core.js';
|
|
4
6
|
import { a as FNodeChild } from './renderer-DSLb-FGg.js';
|
|
5
|
-
export { h as Link, O as Outlet, g as Route, f as Router, e as createLocation, m as matchPath, r as router } from './components-
|
|
6
|
-
import { L as ListComponent } from './portal-
|
|
7
|
-
export { P as Portal, a as createReactiveRoot, d as domRenderer, f, r as render } from './portal-
|
|
7
|
+
export { h as Link, O as Outlet, g as Route, f as Router, e as createLocation, m as matchPath, r as router } from './components-B7KQ8C-i.js';
|
|
8
|
+
import { L as ListComponent } from './portal-CVqrpmHd.js';
|
|
9
|
+
export { P as Portal, a as createReactiveRoot, d as domRenderer, f, r as render } from './portal-CVqrpmHd.js';
|
|
8
10
|
export { c as cleanupMotionState } from './Motion-BrOAJzgH.js';
|
|
9
|
-
export { e as effect } from './effect-BlnnM1t5.js';
|
|
10
|
-
export { r as root, u as untrack } from './owner-QS9tPwPr.js';
|
|
11
11
|
|
|
12
12
|
/** Marker symbol for List components */
|
|
13
13
|
declare const LIST_MARKER: unique symbol;
|
package/dist/test-exports.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkAYQMU7XC_js=require('./chunk-AYQMU7XC.js'),chunkS3EDPCYT_js=require('./chunk-S3EDPCYT.js'),chunkWXEHDEIH_js=require('./chunk-WXEHDEIH.js'),chunk3AWR7IKE_js=require('./chunk-3AWR7IKE.js'),chunk63AW5ZOC_js=require('./chunk-63AW5ZOC.js'),chunkQ7IWDVJ4_js=require('./chunk-Q7IWDVJ4.js');require('./chunk-WQFQO5LK.js');var chunk5236IK5I_js=require('./chunk-5236IK5I.js'),chunkAJT35P3Z_js=require('./chunk-AJT35P3Z.js');Object.defineProperty(exports,"Link",{enumerable:true,get:function(){return chunkAYQMU7XC_js.k}});Object.defineProperty(exports,"Outlet",{enumerable:true,get:function(){return chunkAYQMU7XC_js.j}});Object.defineProperty(exports,"Route",{enumerable:true,get:function(){return chunkAYQMU7XC_js.i}});Object.defineProperty(exports,"Router",{enumerable:true,get:function(){return chunkAYQMU7XC_js.h}});Object.defineProperty(exports,"createLocation",{enumerable:true,get:function(){return chunkAYQMU7XC_js.a}});Object.defineProperty(exports,"matchPath",{enumerable:true,get:function(){return chunkAYQMU7XC_js.d}});Object.defineProperty(exports,"router",{enumerable:true,get:function(){return chunkAYQMU7XC_js.g}});Object.defineProperty(exports,"LIST_MARKER",{enumerable:true,get:function(){return chunkS3EDPCYT_js.c}});Object.defineProperty(exports,"Portal",{enumerable:true,get:function(){return chunkS3EDPCYT_js.i}});Object.defineProperty(exports,"createReactiveRoot",{enumerable:true,get:function(){return chunkS3EDPCYT_js.f}});Object.defineProperty(exports,"domRenderer",{enumerable:true,get:function(){return chunkS3EDPCYT_js.b}});Object.defineProperty(exports,"isListComponent",{enumerable:true,get:function(){return chunkS3EDPCYT_js.d}});Object.defineProperty(exports,"render",{enumerable:true,get:function(){return chunkS3EDPCYT_js.g}});Object.defineProperty(exports,"context",{enumerable:true,get:function(){return chunkWXEHDEIH_js.b}});Object.defineProperty(exports,"createContext",{enumerable:true,get:function(){return chunkWXEHDEIH_js.a}});Object.defineProperty(exports,"state",{enumerable:true,get:function(){return chunk3AWR7IKE_js.h}});Object.defineProperty(exports,"cleanupMotionState",{enumerable:true,get:function(){return chunk63AW5ZOC_js.a}});Object.defineProperty(exports,"f",{enumerable:true,get:function(){return chunkQ7IWDVJ4_js.a}});Object.defineProperty(exports,"createResource",{enumerable:true,get:function(){return chunk5236IK5I_js.h}});Object.defineProperty(exports,"isSignal",{enumerable:true,get:function(){return chunk5236IK5I_js.f}});Object.defineProperty(exports,"onCleanup",{enumerable:true,get:function(){return chunk5236IK5I_js.g}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunk5236IK5I_js.a}});Object.defineProperty(exports,"effect",{enumerable:true,get:function(){return chunkAJT35P3Z_js.k}});Object.defineProperty(exports,"root",{enumerable:true,get:function(){return chunkAJT35P3Z_js.i}});Object.defineProperty(exports,"untrack",{enumerable:true,get:function(){return chunkAJT35P3Z_js.g}});//# sourceMappingURL=test-exports.js.map
|
|
2
2
|
//# sourceMappingURL=test-exports.js.map
|
package/dist/test-exports.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{k as Link,j as Outlet,i as Route,h as Router,a as createLocation,d as matchPath,g as router}from'./chunk-
|
|
1
|
+
export{k as Link,j as Outlet,i as Route,h as Router,a as createLocation,d as matchPath,g as router}from'./chunk-3BQXIHYI.mjs';export{c as LIST_MARKER,i as Portal,f as createReactiveRoot,b as domRenderer,d as isListComponent,g as render}from'./chunk-6K44QCMT.mjs';export{b as context,a as createContext}from'./chunk-HLPVL6EK.mjs';export{h as state}from'./chunk-7Q4UE442.mjs';export{a as cleanupMotionState}from'./chunk-PVPY55Z7.mjs';export{a as f}from'./chunk-WVEJT7HD.mjs';import'./chunk-KNF5ERPK.mjs';export{h as createResource,f as isSignal,g as onCleanup,a as sync}from'./chunk-B7VP6HBY.mjs';export{k as effect,i as root,g as untrack}from'./chunk-Q7WT5IIF.mjs';//# sourceMappingURL=test-exports.mjs.map
|
|
2
2
|
//# sourceMappingURL=test-exports.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flexium",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "A lightweight, signals-based UI framework with cross-platform renderers",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -155,6 +155,7 @@
|
|
|
155
155
|
"url": "https://github.com/Wick-Lim/flexium.js/issues"
|
|
156
156
|
},
|
|
157
157
|
"devDependencies": {
|
|
158
|
+
"@types/node": "^20.10.0",
|
|
158
159
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
159
160
|
"@typescript-eslint/parser": "^6.0.0",
|
|
160
161
|
"@vitest/ui": "^1.0.0",
|
package/dist/chunk-2ZHUQBNI.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {k as k$1,n,j as j$1}from'./chunk-J4CK5NRW.mjs';var P=Symbol.for("flexium.stateSignal");function K(e,r){let o=e;return o._signal=e,o._stateActions=r,o}function N(e){return {value:void 0,peek:e.peek,_signal:e,_isComputed:true}}function M(e){let r=e;return r._signal=e,r}var c=new Map,W=1e4,j=false,k=null;function G(e){k=e;}function H(){return {id:Symbol("component"),hookIndex:0,hooks:[]}}function J(e){e.hookIndex=0;}var z=new WeakMap;function R(e){if(typeof e=="string")return e;let r=z.get(e);if(r!==void 0)return r;try{let o=JSON.stringify(e);return z.set(e,o),o}catch(o){return console.warn("[Flexium] Failed to serialize state key, using fallback:",o),String(e)}}function w(){typeof process<"u"&&process.env?.NODE_ENV!=="production"&&!j&&c.size>=W&&(j=true,console.warn(`[Flexium] Global state registry has ${c.size} entries. Consider using state.delete(key) to clean up unused states, or state.clear() to reset all global states.`));}function I(e){return (typeof e=="object"||typeof e=="function")&&e!==null&&P in e}function B(e){return I(e)?e[P]:null}function U(e,r){return I(e)?e.peek()===r:false}function q(e){return I(e)?!!e.peek():false}var E=new WeakMap,D=new WeakMap;function d(e){let r=E.get(e);if(r)return r;let o=()=>e.value,b="peek",p="valueOf",V="toString",v="toJSON",O=Symbol.toPrimitive;typeof process<"u"&&process.env?.NODE_ENV!=="production"&&typeof process<"u"&&process.env?.FLEXIUM_WARN_COMPARISON==="true";let m=new Proxy(o,{apply(){return e.value},get(i,n){if(n===P)return e;if(n===b)return e.peek;let t=e.value;if(t===null)return n===O?()=>null:n===p?()=>null:n===V?()=>"null":n===v?()=>null:void 0;if(typeof t=="object"){if(n===O)return f=>t;if(n===p)return ()=>t;if(n===V)return ()=>String(t);if(n===v)return ()=>t;let s=t[n];if(typeof s=="function"){let f=D.get(s);f||(f=new WeakMap,D.set(s,f));let y=f.get(t);return y||(y=s.bind(t),f.set(t,y)),y}return s}if(n===O)return S=>t;if(n===p)return ()=>t;if(n===V)return ()=>String(t);if(n===v)return ()=>t},has(i,n){if(n===P)return true;let t=e.value;return t===null?false:typeof t=="object"&&n in t},ownKeys(i){let n=e.value;return n===null?[]:typeof n=="object"?Reflect.ownKeys(n):[]},getOwnPropertyDescriptor(i,n){if(n===P)return {configurable:true,enumerable:false,value:e};let t=e.value;if(t!==null&&typeof t=="object"){let l=Object.getOwnPropertyDescriptor(t,n);if(l)return {...l,configurable:true}}}});return E.set(e,m),m}function g(e,r){let o=r?.key?R(r.key):void 0,b=r?.params;if(k&&!o){let a=k,u=a.hookIndex++;if(u<a.hooks.length)return a.hooks[u];let m=k;k=null;let i=g(e,r);return k=m,a.hooks.push(i),i}if(o&&c.has(o)){let a=c.get(o),u="loading"in a&&a._stateActions?.refetch!==void 0,m=a._isComputed,i=d(a._signal);if(m)return [i];if(u){let t=a._stateActions?.refetch||(()=>{}),l=k$1(()=>a.error?"error":a.loading?"loading":a.value!==void 0?"success":"idle"),S=k$1(()=>a.error),s=d(l),f=d(S);return [i,t,s,f]}return [i,t=>{typeof t=="function"?a.value=t(a.peek()):a.value=t;}]}if(typeof e=="function"){let a=e,u=b!==void 0?()=>a(b):a;if(a.constructor.name==="AsyncFunction"){let[l,S]=n(u,async _=>_),s=K(l,S);o&&(c.set(o,s),w());let f=d(s._signal),y=k$1(()=>s.error?"error":s.loading?"loading":s.value!==void 0?"success":"idle"),h=k$1(()=>s.error),A=d(y),C=d(h);return [f,S.refetch,A,C]}let i;try{i=u();}catch{let l=k$1(u),S=N(l);return o&&(c.set(o,S),w()),[d(l)]}if(i instanceof Promise){let[l,S]=n(u,async _=>_),s=K(l,S);o&&(c.set(o,s),w());let f=d(s._signal),y=k$1(()=>s.error?"error":s.loading?"loading":s.value!==void 0?"success":"idle"),h=k$1(()=>s.error),A=d(y),C=d(h);return [f,S.refetch,A,C]}let n$1=k$1(u),t=N(n$1);return o&&(c.set(o,t),w()),[d(n$1)]}let p=j$1(e),V=M(p);return o&&(c.set(o,V),w()),[d(p),a=>{typeof a=="function"?p.value=a(p.peek()):p.value=a;}]}g.delete=function(e){let r=R(e);return c.delete(r)};g.clear=function(){c.clear(),j=false;};g.has=function(e){let r=R(e);return c.has(r)};Object.defineProperty(g,"size",{get:()=>c.size,enumerable:true});var X=g;function Y(e){return {current:e}}export{G as a,H as b,J as c,I as d,B as e,U as f,q as g,X as h,Y as i};//# sourceMappingURL=chunk-2ZHUQBNI.mjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-2ZHUQBNI.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/state.ts"],"names":["STATE_SIGNAL","toStateObject","res","actions","s","toComputedStateObject","comp","toSignalStateObject","sig","globalStateRegistry","DEV_WARNING_THRESHOLD","hasWarnedAboutSize","currentComponent","setCurrentComponent","instance","createComponentInstance","resetHookIndex","keyCache","serializeKey","key","cached","serialized","error","checkRegistrySize","isStateValue","value","getStateSignal","stateValue","equals","isTruthy","proxyCache","boundFunctionCache","createStateProxy","target","PEEK_PROP","VALUE_OF_PROP","TO_STRING_PROP","TO_JSON_PROP","TO_PRIMITIVE_SYMBOL","proxy","_target","prop","currentValue","_hint","propValue","functionCache","bound","desc","state","initialValueOrFetcher","options","params","hookIndex","savedComponent","result","isAsync","isComputed","refetch","statusComputed","computed","errorComputed","statusValue","errorValue","newValue","originalFn","fn","resActions","createResource","val","testResult","signal","serializedKey","_state","ref","initialValue"],"mappings":"uDAMO,IAAMA,CAAAA,CAAe,MAAA,CAAO,GAAA,CAAI,qBAAqB,CAAA,CA2B5D,SAASC,CAAAA,CACPC,CAAAA,CACAC,CAAAA,CACa,CACb,IAAMC,CAAAA,CAAIF,CAAAA,CACV,OAAAE,CAAAA,CAAE,OAAA,CAAUF,CAAAA,CACZE,CAAAA,CAAE,aAAA,CAAgBD,CAAAA,CACXC,CACT,CAMA,SAASC,CAAAA,CAAyBC,CAAAA,CAAgC,CAChE,OAAO,CACL,KAAA,CAAO,MAAA,CACP,IAAA,CAAMA,CAAAA,CAAK,IAAA,CACX,OAAA,CAASA,CAAAA,CACT,WAAA,CAAa,IACf,CACF,CAMA,SAASC,CAAAA,CAAuBC,CAAAA,CAA6B,CAC3D,IAAMJ,CAAAA,CAAII,CAAAA,CACV,OAAAJ,CAAAA,CAAE,OAAA,CAAUI,CAAAA,CACLJ,CACT,CAGA,IAAMK,CAAAA,CAAsB,IAAI,GAAA,CAG1BC,CAAAA,CAAwB,GAAA,CAC1BC,CAAAA,CAAqB,KAAA,CAYrBC,CAAAA,CAA6C,IAAA,CAO1C,SAASC,CAAAA,CAAoBC,CAAAA,CAA0C,CAC5EF,CAAAA,CAAmBE,EACrB,CAcO,SAASC,CAAAA,EAA6C,CAC3D,OAAO,CACL,EAAA,CAAI,MAAA,CAAO,WAAW,CAAA,CACtB,SAAA,CAAW,CAAA,CACX,KAAA,CAAO,EACT,CACF,CAMO,SAASC,CAAAA,CAAeF,CAAAA,CAAmC,CAChEA,CAAAA,CAAS,SAAA,CAAY,EACvB,CAMA,IAAMG,CAAAA,CAAW,IAAI,OAAA,CAOrB,SAASC,CAAAA,CA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CAC5C,IAAMoD,CAAAA,CAAgBrD,CAAAA,CAAaC,CAAG,CAAA,CACtC,OAAOV,CAAAA,CAAoB,GAAA,CAAI8D,CAAa,CAC9C,CAAA,CAKA,MAAA,CAAO,cAAA,CAAevB,CAAAA,CAAO,MAAA,CAAQ,CACnC,GAAA,CAAK,IAAMvC,CAAAA,CAAoB,IAAA,CAC/B,UAAA,CAAY,IACd,CAAC,CAAA,CAGD,IAAM+D,CAAAA,CAASxB,EAmCR,SAASyB,CAAAA,CAAOC,CAAAA,CAAsC,CAC3D,OAAO,CAAE,OAAA,CAASA,CAAa,CACjC","file":"chunk-2ZHUQBNI.mjs","sourcesContent":["import { signal, computed, createResource } from './signal'\nimport type { Signal, Computed, Resource } from './signal'\n\n/** Symbol to identify StateProxy and access underlying signal */\n// Use Symbol.for() to ensure the symbol is shared across module boundaries\n// This is important for Vite dev mode where modules may be loaded separately\nexport const STATE_SIGNAL = Symbol.for('flexium.stateSignal')\n\n/** Internal state object that may be a Signal, Computed, or Resource */\ninterface StateObject {\n value: unknown\n peek: () => unknown\n loading?: boolean\n error?: unknown\n state?: 'unresolved' | 'pending' | 'ready' | 'refreshing' | 'errored'\n latest?: unknown\n\n _stateActions?: StateActions\n _signal?: Signal<unknown> | Computed<unknown> | Resource<unknown>\n _isComputed?: boolean\n}\n\n/** Actions available for state mutation */\ninterface StateActions {\n mutate?: (value: unknown) => void\n refetch?: () => void\n}\n\n/**\n * Type-safe helper to wrap Resource as StateObject.\n * Consolidates unsafe type assertions in one place.\n * @internal\n */\nfunction toStateObject<T>(\n res: Resource<T>,\n actions: { mutate: (v: T | undefined) => void; refetch: () => void }\n): StateObject {\n const s = res as unknown as StateObject\n s._signal = res as Resource<unknown>\n s._stateActions = actions as StateActions\n return s\n}\n\n/**\n * Type-safe helper to create a computed StateObject.\n * @internal\n */\nfunction toComputedStateObject<T>(comp: Computed<T>): StateObject {\n return {\n value: undefined,\n peek: comp.peek,\n _signal: comp as Computed<unknown>,\n _isComputed: true,\n }\n}\n\n/**\n * Type-safe helper to wrap Signal as StateObject.\n * @internal\n */\nfunction toSignalStateObject<T>(sig: Signal<T>): StateObject {\n const s = sig as unknown as StateObject\n s._signal = sig as Signal<unknown>\n return s\n}\n\n// Global registry for keyed states\nconst globalStateRegistry = new Map<string, StateObject>()\n\n// Dev mode warning thresholds\nconst DEV_WARNING_THRESHOLD = 10000\nlet hasWarnedAboutSize = false\n\n// ============================================================================\n// Component Hook System - enables state() inside components\n// ============================================================================\n\ninterface ComponentInstance {\n id: symbol\n hookIndex: number\n hooks: unknown[]\n}\n\nlet currentComponent: ComponentInstance | null = null\n\n/**\n * Set the current component context for hook tracking.\n * Called by the renderer before executing a component function.\n * @internal\n */\nexport function setCurrentComponent(instance: ComponentInstance | null): void {\n currentComponent = instance\n}\n\n/**\n * Get the current component context.\n * @internal\n */\nexport function getCurrentComponent(): ComponentInstance | null {\n return currentComponent\n}\n\n/**\n * Create a new component instance for hook tracking.\n * @internal\n */\nexport function createComponentInstance(): ComponentInstance {\n return {\n id: Symbol('component'),\n hookIndex: 0,\n hooks: [],\n }\n}\n\n/**\n * Reset hook index for re-renders.\n * @internal\n */\nexport function resetHookIndex(instance: ComponentInstance): void {\n instance.hookIndex = 0\n}\n\n/** Key type - string or array of serializable values */\nexport type StateKey = string | readonly (string | number | boolean | null | undefined | object)[]\n\n// Cache for array key serialization to avoid repeated JSON.stringify calls\nconst keyCache = new WeakMap<readonly unknown[], string>()\n\n/**\n * Serialize a key to a string for registry lookup.\n * Arrays are JSON-stringified for consistent comparison.\n * Uses WeakMap cache to avoid repeated serialization of array keys.\n */\nfunction serializeKey(key: StateKey): string {\n if (typeof key === 'string') {\n return key\n }\n\n // Check cache first for array keys\n const cached = keyCache.get(key)\n if (cached !== undefined) {\n return cached\n }\n\n try {\n const serialized = JSON.stringify(key)\n keyCache.set(key, serialized)\n return serialized\n } catch (error) {\n // Handle circular references or other serialization errors\n console.warn('[Flexium] Failed to serialize state key, using fallback:', error)\n const fallback = String(key)\n return fallback\n }\n}\n\n/**\n * Check global state registry size and warn in development mode.\n * Does not enforce hard limits - use state.delete() or state.clear() for cleanup.\n * @internal\n */\nfunction checkRegistrySize(): void {\n const isDev = typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production'\n if (\n isDev &&\n !hasWarnedAboutSize &&\n globalStateRegistry.size >= DEV_WARNING_THRESHOLD\n ) {\n hasWarnedAboutSize = true\n console.warn(\n `[Flexium] Global state registry has ${globalStateRegistry.size} entries. ` +\n `Consider using state.delete(key) to clean up unused states, ` +\n `or state.clear() to reset all global states.`\n )\n }\n}\n\n/** Action function type for state mutation */\nexport type StateAction<T> = (newValue: T | ((prev: T) => T)) => void\n\n/**\n * StateValue type - a value-like proxy that behaves like T.\n * Can be used directly in expressions and JSX.\n */\nexport type StateValue<T> = T & (() => T) & { peek(): T }\n\n/**\n * Check if a value is a StateValue (created by the state() API).\n * Useful for type guards and runtime detection of reactive state.\n * @internal\n * @param value - The value to check\n * @returns true if the value is a StateValue proxy, false otherwise\n *\n * @example\n * ```tsx\n * const count = state(0)\n * isStateValue(count) // true\n * isStateValue(5) // false\n * ```\n */\nexport function isStateValue(value: unknown): boolean {\n return (\n (typeof value === 'object' || typeof value === 'function') &&\n value !== null &&\n STATE_SIGNAL in value\n )\n}\n\n/**\n * Get the underlying signal from a StateValue proxy.\n * Used internally for reactive binding detection and DOM updates.\n * @internal\n * @param stateValue - The StateValue proxy to extract the signal from\n * @returns The underlying Signal if stateValue is a StateValue, null otherwise\n *\n * @example\n * ```tsx\n * const count = state(0)\n * const signal = getStateSignal(count) // Returns the internal Signal<number>\n * ```\n */\nexport function getStateSignal(stateValue: unknown): Signal<unknown> | null {\n if (isStateValue(stateValue)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (stateValue as any)[STATE_SIGNAL]\n }\n return null\n}\n\n/**\n * Compare a StateValue with a primitive value safely.\n * Handles Proxy comparison automatically by extracting the underlying value.\n * \n * @param stateValue - The StateValue to compare\n * @param value - The value to compare against\n * @returns true if the StateValue's underlying value equals the comparison value\n * \n * @example\n * ```tsx\n * const [count, setCount] = state(0)\n * \n * // ✅ Safe comparison using helper\n * if (equals(count, 5)) {\n * console.log('Count is 5')\n * }\n * \n * // ❌ Direct comparison (always false)\n * if (count === 5) { ... }\n * ```\n */\nexport function equals<T>(stateValue: StateValue<T>, value: T): boolean {\n if (!isStateValue(stateValue)) {\n return false\n }\n const actualValue = stateValue.peek()\n return actualValue === value\n}\n\n/**\n * Check if a StateValue is truthy.\n * Useful for boolean checks without explicit conversion.\n * \n * @param stateValue - The StateValue to check\n * @returns true if the underlying value is truthy\n * \n * @example\n * ```tsx\n * const [user, setUser] = state<User | null>(null)\n * \n * // ✅ Safe boolean check\n * if (isTruthy(user)) {\n * console.log('User exists:', user.name)\n * }\n * \n * // ❌ Direct check (always true for Proxy)\n * if (user) { ... }\n * ```\n */\nexport function isTruthy<T>(stateValue: StateValue<T>): boolean {\n if (!isStateValue(stateValue)) {\n return false\n }\n return Boolean(stateValue.peek())\n}\n\n/**\n * Cache for StateProxy instances to avoid repeated Proxy creation for the same signal.\n * Uses WeakMap so proxies are automatically garbage collected when signals are no longer referenced.\n */\nconst proxyCache = new WeakMap<Signal<unknown> | Computed<unknown>, StateValue<unknown>>()\n\n/**\n * Cache for bound functions to avoid repeated bind() calls.\n * Uses nested WeakMap: function -> (object -> bound function)\n * Performance: Reuse bound functions instead of creating new ones on each access\n */\nconst boundFunctionCache = new WeakMap<Function, WeakMap<object, Function>>()\n\n/**\n * Create a reactive proxy that behaves like a value but stays reactive.\n * The proxy is also callable - calling it returns the current value.\n * This ensures compatibility with code expecting getter functions.\n * \n * Performance optimization: Cache value and type checks to avoid repeated sig.value calls.\n * Performance optimization: Reuse Proxy instances for the same signal to reduce allocation overhead.\n */\nfunction createStateProxy<T>(sig: Signal<T> | Computed<T>): StateValue<T> {\n // Check cache first - reuse existing proxy if available\n const cached = proxyCache.get(sig as Signal<unknown> | Computed<unknown>)\n if (cached) {\n return cached as StateValue<T>\n }\n\n // Use an arrow function as the target so the proxy is callable but has no prototype\n // This prevents invariant violations in ownKeys trap\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const target = () => sig.value\n\n // Performance: Cache common property accessors to avoid repeated lookups\n const PEEK_PROP = 'peek'\n const VALUE_OF_PROP = 'valueOf'\n const TO_STRING_PROP = 'toString'\n const TO_JSON_PROP = 'toJSON'\n const TO_PRIMITIVE_SYMBOL = Symbol.toPrimitive\n\n // Performance: Cache dev mode check (rarely changes, so cache at proxy creation time)\n const isDev = typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production'\n const warnComparison = isDev && typeof process !== 'undefined' && process.env?.FLEXIUM_WARN_COMPARISON === 'true'\n\n const proxy = new Proxy(target, {\n // Make the proxy callable - returns current value\n apply() {\n return sig.value\n },\n\n get(_target, prop) {\n // Performance: Check most common cases first (branch prediction optimization)\n // STATE_SIGNAL is checked first as it's used internally for reactive binding\n if (prop === STATE_SIGNAL) {\n return sig\n }\n\n // peek() is frequently accessed, check early\n if (prop === PEEK_PROP) {\n return sig.peek\n }\n\n // Performance: Early return for object property access (most common case)\n // Read value once and check type before special property checks\n // Note: accessing sig.value here tracks the signal in any enclosing effect\n const currentValue = sig.value\n\n // Early return for null (most common non-object case)\n if (currentValue === null) {\n // Still need to check special properties even for null values\n if (prop === TO_PRIMITIVE_SYMBOL) return () => null\n if (prop === VALUE_OF_PROP) return () => null\n if (prop === TO_STRING_PROP) return () => 'null'\n if (prop === TO_JSON_PROP) return () => null\n return undefined\n }\n\n // Type check once - reuse result\n const isObject = typeof currentValue === 'object'\n \n // Handle special properties for object values\n if (isObject) {\n // Check special properties first before accessing object properties\n if (prop === TO_PRIMITIVE_SYMBOL) {\n return (_hint: string) => currentValue\n }\n if (prop === VALUE_OF_PROP) {\n return () => {\n // Performance: Use cached warnComparison instead of checking env every time\n if (warnComparison) {\n // Only warn if explicitly enabled via environment variable\n // Most users should rely on ESLint rules instead\n }\n return currentValue\n }\n }\n if (prop === TO_STRING_PROP) {\n return () => String(currentValue)\n }\n if (prop === TO_JSON_PROP) {\n return () => currentValue\n }\n\n // Access object property\n const obj = currentValue as Record<string | symbol, unknown>\n const propValue = obj[prop]\n // Performance: Cache bound functions to avoid repeated bind() calls\n // If it's a function (like array methods), bind it to the current value\n if (typeof propValue === 'function') {\n // Check cache first\n let functionCache = boundFunctionCache.get(propValue)\n if (!functionCache) {\n functionCache = new WeakMap()\n boundFunctionCache.set(propValue, functionCache)\n }\n \n let bound: Function | undefined = functionCache.get(currentValue)\n if (!bound) {\n bound = propValue.bind(currentValue)\n // TypeScript: bound is guaranteed to be Function here\n functionCache.set(currentValue, bound as Function)\n }\n return bound\n }\n return propValue\n }\n\n // Handle special properties for primitive values\n if (prop === TO_PRIMITIVE_SYMBOL) {\n return (_hint: string) => currentValue\n }\n if (prop === VALUE_OF_PROP) {\n return () => {\n // Performance: Use cached warnComparison instead of checking env every time\n if (warnComparison) {\n // Only warn if explicitly enabled via environment variable\n }\n return currentValue\n }\n }\n if (prop === TO_STRING_PROP) {\n return () => String(currentValue)\n }\n if (prop === TO_JSON_PROP) {\n return () => currentValue\n }\n\n return undefined\n },\n\n // For property checks (like 'length' in array)\n has(_target, prop) {\n if (prop === STATE_SIGNAL) return true\n // Performance: Read value once\n const currentValue = sig.value\n // Performance: Early return for null\n if (currentValue === null) return false\n // Performance: Type check once\n return typeof currentValue === 'object' && prop in (currentValue as object)\n },\n\n // For Object.keys, for...in loops\n ownKeys(_target) {\n // Performance: Read value once\n const currentValue = sig.value\n // Performance: Early return for null\n if (currentValue === null) return []\n // Performance: Type check once\n if (typeof currentValue === 'object') {\n return Reflect.ownKeys(currentValue as object)\n }\n return []\n },\n\n getOwnPropertyDescriptor(_target, prop) {\n if (prop === STATE_SIGNAL) {\n return { configurable: true, enumerable: false, value: sig }\n }\n // Performance: Read value once\n const currentValue = sig.value\n // Performance: Early return for null\n if (currentValue === null) return undefined\n // Performance: Type check once\n if (typeof currentValue === 'object') {\n const desc = Object.getOwnPropertyDescriptor(currentValue as object, prop)\n if (desc) {\n // Make it configurable to satisfy Proxy invariants\n return { ...desc, configurable: true }\n }\n }\n return undefined\n },\n })\n\n // Cache the proxy for future reuse\n proxyCache.set(sig as Signal<unknown> | Computed<unknown>, proxy as StateValue<unknown>)\n\n return proxy as StateValue<T>\n}\n\n/** Async state status */\nexport type AsyncStatus = 'idle' | 'loading' | 'success' | 'error'\n\n/** Options for state() */\nexport interface StateOptions<P = unknown> {\n /**\n * Key for global state sharing. Can be a string or array.\n * Array keys are useful for hierarchical namespacing.\n * @example\n * state('light', { key: 'theme' })\n * state(null, { key: ['user', 'profile', userId] })\n */\n key?: StateKey\n /**\n * Parameters to pass to the function (for computed/async state).\n * Improves DX by making dependencies explicit.\n * @example\n * state(\n * async ({ userId }) => fetch(`/api/users/${userId}`),\n * { key: ['user', userId], params: { userId } }\n * )\n */\n params?: P\n}\n\n/**\n * Unified State API\n *\n * One function for all reactive state needs - always returns an array for consistency:\n * 1. Simple state: const [count, setCount] = state(0)\n * 2. Derived state: const [doubled] = state(() => count * 2)\n * 3. Async state: const [data, refetch, status, error] = state(async () => fetch(...))\n * 4. Global state: const [theme, setTheme] = state('light', { key: 'theme' })\n * 5. With params: const [user] = state(async (p) => fetch(`/api/${p.id}`), { params: { id } })\n *\n * @example\n * ```tsx\n * function Counter() {\n * const [count, setCount] = state(0)\n * const [doubled] = state(() => count * 2)\n * return <Button onPress={() => setCount(count + 1)}>{doubled}</Button>\n * }\n * ```\n */\n// Static methods interface for the state function\ninterface StateFunction {\n // Overloads\n <T>(initialValue: T, options?: StateOptions): [StateValue<T>, StateAction<T>]\n <T, P>(computeFn: (params: P) => T, options: StateOptions<P> & { params: P }): [StateValue<T>]\n <T>(computeFn: () => T, options?: StateOptions): [StateValue<T>]\n <T, P>(fetcher: (params: P) => Promise<T>, options: StateOptions<P> & { params: P }): [StateValue<T | undefined>, () => void, StateValue<AsyncStatus>, StateValue<unknown>]\n <T>(fetcher: () => Promise<T>, options?: StateOptions): [StateValue<T | undefined>, () => void, StateValue<AsyncStatus>, StateValue<unknown>]\n\n /** Delete a specific global state by key */\n delete: (key: StateKey) => boolean\n /** Clear all global states */\n clear: () => void\n /** Check if a global state exists */\n has: (key: StateKey) => boolean\n /** Current number of global states */\n readonly size: number\n}\n\n// Overload 1: Value → [StateValue, Setter]\nfunction state<T>(\n initialValue: T,\n options?: StateOptions\n): [StateValue<T>, StateAction<T>]\n\n// Overload 2: Sync function with params → [StateValue] (derived, no setter)\nfunction state<T, P>(\n computeFn: (params: P) => T,\n options: StateOptions<P> & { params: P }\n): [StateValue<T>]\n\n// Overload 3: Sync function without params → [StateValue] (derived, no setter)\nfunction state<T>(\n computeFn: () => T,\n options?: StateOptions\n): [StateValue<T>]\n\n// Overload 4: Async function with params → [StateValue, refetch, status, error]\nfunction state<T, P>(\n fetcher: (params: P) => Promise<T>,\n options: StateOptions<P> & { params: P }\n): [StateValue<T | undefined>, () => void, StateValue<AsyncStatus>, StateValue<unknown>]\n\n// Overload 5: Async function without params → [StateValue, refetch, status, error]\nfunction state<T>(\n fetcher: () => Promise<T>,\n options?: StateOptions\n): [StateValue<T | undefined>, () => void, StateValue<AsyncStatus>, StateValue<unknown>]\n\nfunction state<T, P = unknown>(\n initialValueOrFetcher: T | ((params?: P) => T) | ((params?: P) => Promise<T>),\n options?: StateOptions<P>\n): [StateValue<T>] | [StateValue<T>, StateAction<T>] | [StateValue<T | undefined>, () => void, StateValue<AsyncStatus>, StateValue<unknown>] {\n const key = options?.key ? serializeKey(options.key) : undefined\n const params = options?.params\n\n // 0. Hook System - reuse state from previous render if inside a component\n if (currentComponent && !key) {\n const comp = currentComponent\n const hookIndex = comp.hookIndex++\n\n // Return existing hook if available\n if (hookIndex < comp.hooks.length) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return comp.hooks[hookIndex] as any\n }\n\n // Create new state and store in hooks array\n // Temporarily clear currentComponent to avoid infinite recursion\n const savedComponent = currentComponent\n currentComponent = null\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result = state(initialValueOrFetcher as any, options as any)\n currentComponent = savedComponent\n\n comp.hooks.push(result)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return result as any\n }\n\n // 1. Check Global Registry for keyed state\n if (key && globalStateRegistry.has(key)) {\n const cached = globalStateRegistry.get(key)!\n const isAsync = 'loading' in cached && cached._stateActions?.refetch !== undefined\n const isComputed = cached._isComputed\n\n const proxy = createStateProxy(cached._signal as Signal<T>)\n\n if (isComputed) {\n return [proxy] as [StateValue<T>]\n }\n\n if (isAsync) {\n const refetch = cached._stateActions?.refetch || (() => { })\n // Performance: Use computed directly instead of state() to avoid recursion\n const statusComputed = computed<AsyncStatus>(() => {\n if (cached.error) return 'error'\n if (cached.loading) return 'loading'\n if (cached.value !== undefined) return 'success'\n return 'idle'\n })\n const errorComputed = computed<unknown>(() => cached.error)\n const statusValue = createStateProxy(statusComputed)\n const errorValue = createStateProxy(errorComputed)\n return [proxy, refetch, statusValue, errorValue] as [StateValue<T | undefined>, () => void, StateValue<AsyncStatus>, StateValue<unknown>]\n }\n\n const setter: StateAction<T> = (newValue) => {\n if (typeof newValue === 'function') {\n cached.value = (newValue as (prev: T) => T)(cached.peek() as T)\n } else {\n cached.value = newValue\n }\n }\n return [proxy, setter] as [StateValue<T>, StateAction<T>]\n }\n\n // 2. Handle function input (computed or async)\n if (typeof initialValueOrFetcher === 'function') {\n const originalFn = initialValueOrFetcher as (params?: P) => T | Promise<T>\n \n // Performance: Avoid function wrapping when params is undefined\n // Reuse original function directly to avoid closure overhead\n const fn = params !== undefined\n ? () => originalFn(params)\n : (originalFn as () => T | Promise<T>)\n\n // Try to detect if it's async by checking constructor name\n // This handles `async () => ...` functions\n const isAsyncFn = originalFn.constructor.name === 'AsyncFunction'\n\n if (isAsyncFn) {\n // Async function → Resource\n const [res, resActions] = createResource(fn, async (val) => val)\n const s = toStateObject(res, resActions)\n\n if (key) {\n globalStateRegistry.set(key, s)\n checkRegistrySize()\n }\n\n const proxy = createStateProxy(s._signal as Signal<T>)\n // Performance: Use computed directly instead of state() to avoid recursion\n const statusComputed = computed<AsyncStatus>(() => {\n if (s.error) return 'error'\n if (s.loading) return 'loading'\n if (s.value !== undefined) return 'success'\n return 'idle'\n })\n const errorComputed = computed<unknown>(() => s.error)\n const statusValue = createStateProxy(statusComputed)\n const errorValue = createStateProxy(errorComputed)\n\n return [proxy, resActions.refetch, statusValue, errorValue] as [StateValue<T | undefined>, () => void, StateValue<AsyncStatus>, StateValue<unknown>]\n }\n\n // Sync function → Computed\n // First, try running to check if it returns a Promise (for non-async functions that return Promise)\n let testResult: T | Promise<T>\n try {\n testResult = fn()\n } catch {\n // If it throws during initial call, treat as computed (will throw on access)\n const comp = computed(fn as () => T)\n const s = toComputedStateObject(comp)\n if (key) {\n globalStateRegistry.set(key, s)\n checkRegistrySize()\n }\n return [createStateProxy(comp)] as [StateValue<T>]\n }\n\n if (testResult instanceof Promise) {\n // It's a Promise-returning function → Resource\n const [res, resActions] = createResource(fn, async (val) => val)\n const s = toStateObject(res, resActions)\n\n if (key) {\n globalStateRegistry.set(key, s)\n checkRegistrySize()\n }\n\n const proxy = createStateProxy(s._signal as Signal<T>)\n // Performance: Use computed directly instead of state() to avoid recursion\n const statusComputed = computed<AsyncStatus>(() => {\n if (s.error) return 'error'\n if (s.loading) return 'loading'\n if (s.value !== undefined) return 'success'\n return 'idle'\n })\n const errorComputed = computed<unknown>(() => s.error)\n const statusValue = createStateProxy(statusComputed)\n const errorValue = createStateProxy(errorComputed)\n\n return [proxy, resActions.refetch, statusValue, errorValue] as [StateValue<T | undefined>, () => void, StateValue<AsyncStatus>, StateValue<unknown>]\n }\n\n // Sync function → Computed (memoized derived value)\n const comp = computed(fn as () => T)\n const s = toComputedStateObject(comp)\n if (key) {\n globalStateRegistry.set(key, s)\n checkRegistrySize()\n }\n return [createStateProxy(comp)] as [StateValue<T>]\n }\n\n // 3. Plain value → Signal with setter\n const sig = signal<T>(initialValueOrFetcher)\n const s = toSignalStateObject(sig)\n\n if (key) {\n globalStateRegistry.set(key, s)\n checkRegistrySize()\n }\n\n const proxy = createStateProxy(sig)\n const setter: StateAction<T> = (newValue) => {\n if (typeof newValue === 'function') {\n sig.value = (newValue as (prev: T) => T)(sig.peek())\n } else {\n sig.value = newValue\n }\n }\n\n return [proxy, setter] as [StateValue<T>, StateAction<T>]\n}\n\n/**\n * Delete a specific global state by key\n * @param key - The key of the state to delete\n * @returns true if the state was deleted, false if it didn't exist\n *\n * @example\n * ```ts\n * state.delete('theme')\n * state.delete(['user', 'profile', userId])\n * ```\n */\nstate.delete = function (key: StateKey): boolean {\n const serializedKey = serializeKey(key)\n return globalStateRegistry.delete(serializedKey)\n}\n\n/**\n * Clear all global states (useful for testing or resetting app)\n *\n * @example\n * ```ts\n * state.clear()\n * ```\n */\nstate.clear = function (): void {\n globalStateRegistry.clear()\n hasWarnedAboutSize = false\n}\n\n/**\n * Check if a global state exists\n * @param key - The key to check\n * @returns true if the state exists\n *\n * @example\n * ```ts\n * if (state.has('theme')) { ... }\n * ```\n */\nstate.has = function (key: StateKey): boolean {\n const serializedKey = serializeKey(key)\n return globalStateRegistry.has(serializedKey)\n}\n\n/**\n * Get the current number of global states\n */\nObject.defineProperty(state, 'size', {\n get: () => globalStateRegistry.size,\n enumerable: true,\n})\n\n// Export with proper typing (cast to include static methods)\nconst _state = state as StateFunction\nexport { _state as state }\n\n/**\n * Ref object type for DOM element references\n */\nexport interface RefObject<T> {\n current: T | null\n}\n\n/**\n * Create a ref object to hold a reference to a DOM element.\n * Use with the `ref` prop on JSX elements.\n *\n * @param initialValue - Initial value (typically null)\n * @returns A ref object with a `current` property\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const inputRef = ref<HTMLInputElement>(null)\n *\n * const focusInput = () => {\n * inputRef.current?.focus()\n * }\n *\n * return (\n * <div>\n * <input ref={inputRef} type=\"text\" />\n * <button onclick={focusInput}>Focus</button>\n * </div>\n * )\n * }\n * ```\n */\nexport function ref<T>(initialValue: T | null): RefObject<T> {\n return { current: initialValue }\n}\n\n\n"]}
|