@hedystia/view 2.1.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/dist/constants.cjs +13 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.mjs +13 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/context/context.cjs +51 -0
- package/dist/context/context.cjs.map +1 -0
- package/dist/context/context.d.cts +25 -0
- package/dist/context/context.d.mts +25 -0
- package/dist/context/context.mjs +50 -0
- package/dist/context/context.mjs.map +1 -0
- package/dist/fetch/resource.cjs +89 -0
- package/dist/fetch/resource.cjs.map +1 -0
- package/dist/fetch/resource.d.cts +14 -0
- package/dist/fetch/resource.d.mts +14 -0
- package/dist/fetch/resource.mjs +88 -0
- package/dist/fetch/resource.mjs.map +1 -0
- package/dist/index.cjs +58 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.mjs +14 -0
- package/dist/jsx/element.cjs +201 -0
- package/dist/jsx/element.cjs.map +1 -0
- package/dist/jsx/element.d.cts +48 -0
- package/dist/jsx/element.d.mts +48 -0
- package/dist/jsx/element.mjs +199 -0
- package/dist/jsx/element.mjs.map +1 -0
- package/dist/jsx-dev-runtime.cjs +40 -0
- package/dist/jsx-dev-runtime.cjs.map +1 -0
- package/dist/jsx-dev-runtime.d.cts +21 -0
- package/dist/jsx-dev-runtime.d.mts +21 -0
- package/dist/jsx-dev-runtime.mjs +36 -0
- package/dist/jsx-dev-runtime.mjs.map +1 -0
- package/dist/jsx-runtime.cjs +5 -0
- package/dist/jsx-runtime.d.cts +3 -0
- package/dist/jsx-runtime.d.mts +3 -0
- package/dist/jsx-runtime.mjs +2 -0
- package/dist/jsx.d.cts +942 -0
- package/dist/jsx.d.mts +942 -0
- package/dist/lifecycle/hooks.cjs +56 -0
- package/dist/lifecycle/hooks.cjs.map +1 -0
- package/dist/lifecycle/hooks.d.cts +37 -0
- package/dist/lifecycle/hooks.d.mts +37 -0
- package/dist/lifecycle/hooks.mjs +54 -0
- package/dist/lifecycle/hooks.mjs.map +1 -0
- package/dist/render/engine.cjs +52 -0
- package/dist/render/engine.cjs.map +1 -0
- package/dist/render/engine.d.cts +31 -0
- package/dist/render/engine.d.mts +31 -0
- package/dist/render/engine.mjs +51 -0
- package/dist/render/engine.mjs.map +1 -0
- package/dist/render/flow.cjs +286 -0
- package/dist/render/flow.cjs.map +1 -0
- package/dist/render/flow.d.cts +64 -0
- package/dist/render/flow.d.mts +64 -0
- package/dist/render/flow.mjs +279 -0
- package/dist/render/flow.mjs.map +1 -0
- package/dist/scheduler/scheduler.cjs +61 -0
- package/dist/scheduler/scheduler.cjs.map +1 -0
- package/dist/scheduler/scheduler.d.cts +31 -0
- package/dist/scheduler/scheduler.d.mts +31 -0
- package/dist/scheduler/scheduler.mjs +59 -0
- package/dist/scheduler/scheduler.mjs.map +1 -0
- package/dist/signal/signal.cjs +387 -0
- package/dist/signal/signal.cjs.map +1 -0
- package/dist/signal/signal.d.cts +44 -0
- package/dist/signal/signal.d.mts +44 -0
- package/dist/signal/signal.mjs +370 -0
- package/dist/signal/signal.mjs.map +1 -0
- package/dist/store/index.cjs +1 -0
- package/dist/store/index.mjs +2 -0
- package/dist/store/store.cjs +94 -0
- package/dist/store/store.cjs.map +1 -0
- package/dist/store/store.d.cts +22 -0
- package/dist/store/store.d.mts +22 -0
- package/dist/store/store.mjs +91 -0
- package/dist/store/store.mjs.map +1 -0
- package/dist/style/computed.cjs +65 -0
- package/dist/style/computed.cjs.map +1 -0
- package/dist/style/computed.d.cts +18 -0
- package/dist/style/computed.d.mts +18 -0
- package/dist/style/computed.mjs +63 -0
- package/dist/style/computed.mjs.map +1 -0
- package/dist/text/text.cjs +74 -0
- package/dist/text/text.cjs.map +1 -0
- package/dist/text/text.d.cts +31 -0
- package/dist/text/text.d.mts +31 -0
- package/dist/text/text.mjs +72 -0
- package/dist/text/text.mjs.map +1 -0
- package/dist/types.d.cts +185 -0
- package/dist/types.d.mts +185 -0
- package/dist/utils/index.cjs +34 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.mjs +33 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/watch/watcher.cjs +71 -0
- package/dist/watch/watcher.cjs.map +1 -0
- package/dist/watch/watcher.d.cts +17 -0
- package/dist/watch/watcher.d.mts +17 -0
- package/dist/watch/watcher.mjs +70 -0
- package/dist/watch/watcher.mjs.map +1 -0
- package/package.json +34 -0
- package/readme.md +395 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/scheduler/scheduler.ts
|
|
2
|
+
/**
|
|
3
|
+
* Frame scheduler for @hedystia/view
|
|
4
|
+
*
|
|
5
|
+
* Provides requestAnimationFrame-based batching for visual updates.
|
|
6
|
+
*/
|
|
7
|
+
let scheduledRaf = null;
|
|
8
|
+
let rafCallbacks = [];
|
|
9
|
+
/**
|
|
10
|
+
* Schedule a callback for the next animation frame
|
|
11
|
+
* @param {() => void} fn - The callback to run on next frame
|
|
12
|
+
* @example
|
|
13
|
+
* tick(() => {
|
|
14
|
+
* // DOM updates here
|
|
15
|
+
* });
|
|
16
|
+
*/
|
|
17
|
+
function tick(fn) {
|
|
18
|
+
rafCallbacks.push(fn);
|
|
19
|
+
if (scheduledRaf === null) scheduledRaf = requestAnimationFrame(flushRaf);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Wait for the next animation frame
|
|
23
|
+
* @returns {Promise<void>} A promise that resolves on next frame
|
|
24
|
+
* @example
|
|
25
|
+
* await nextFrame();
|
|
26
|
+
*/
|
|
27
|
+
function nextFrame() {
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
tick(resolve);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** @internal */
|
|
33
|
+
function flushRaf() {
|
|
34
|
+
scheduledRaf = null;
|
|
35
|
+
const callbacks = rafCallbacks;
|
|
36
|
+
rafCallbacks = [];
|
|
37
|
+
for (let i = 0; i < callbacks.length; i++) callbacks[i]();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Force flush all pending RAF callbacks synchronously (for testing)
|
|
41
|
+
* @example
|
|
42
|
+
* await tick(); // forces flush
|
|
43
|
+
*/
|
|
44
|
+
function forceFlush() {
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
if (scheduledRaf !== null) {
|
|
47
|
+
cancelAnimationFrame(scheduledRaf);
|
|
48
|
+
scheduledRaf = null;
|
|
49
|
+
}
|
|
50
|
+
const callbacks = rafCallbacks;
|
|
51
|
+
rafCallbacks = [];
|
|
52
|
+
for (let i = 0; i < callbacks.length; i++) callbacks[i]();
|
|
53
|
+
resolve();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { forceFlush, nextFrame, tick };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=scheduler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.mjs","names":[],"sources":["../../src/scheduler/scheduler.ts"],"sourcesContent":["/**\n * Frame scheduler for @hedystia/view\n *\n * Provides requestAnimationFrame-based batching for visual updates.\n */\n\nlet scheduledRaf: number | null = null;\nlet rafCallbacks: Array<() => void> = [];\n\n/**\n * Schedule a callback for the next animation frame\n * @param {() => void} fn - The callback to run on next frame\n * @example\n * tick(() => {\n * // DOM updates here\n * });\n */\nexport function tick(fn: () => void): void {\n rafCallbacks.push(fn);\n if (scheduledRaf === null) {\n scheduledRaf = requestAnimationFrame(flushRaf);\n }\n}\n\n/**\n * Wait for the next animation frame\n * @returns {Promise<void>} A promise that resolves on next frame\n * @example\n * await nextFrame();\n */\nexport function nextFrame(): Promise<void> {\n return new Promise((resolve) => {\n tick(resolve);\n });\n}\n\n/** @internal */\nfunction flushRaf(): void {\n scheduledRaf = null;\n const callbacks = rafCallbacks;\n rafCallbacks = [];\n for (let i = 0; i < callbacks.length; i++) {\n callbacks[i]!();\n }\n}\n\n/**\n * Force flush all pending RAF callbacks synchronously (for testing)\n * @example\n * await tick(); // forces flush\n */\nexport function forceFlush(): Promise<void> {\n return new Promise((resolve) => {\n if (scheduledRaf !== null) {\n cancelAnimationFrame(scheduledRaf);\n scheduledRaf = null;\n }\n const callbacks = rafCallbacks;\n rafCallbacks = [];\n for (let i = 0; i < callbacks.length; i++) {\n callbacks[i]!();\n }\n resolve();\n });\n}\n"],"mappings":";;;;;;AAMA,IAAI,eAA8B;AAClC,IAAI,eAAkC,EAAE;;;;;;;;;AAUxC,SAAgB,KAAK,IAAsB;AACzC,cAAa,KAAK,GAAG;AACrB,KAAI,iBAAiB,KACnB,gBAAe,sBAAsB,SAAS;;;;;;;;AAUlD,SAAgB,YAA2B;AACzC,QAAO,IAAI,SAAS,YAAY;AAC9B,OAAK,QAAQ;GACb;;;AAIJ,SAAS,WAAiB;AACxB,gBAAe;CACf,MAAM,YAAY;AAClB,gBAAe,EAAE;AACjB,MAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,IACpC,WAAU,IAAK;;;;;;;AASnB,SAAgB,aAA4B;AAC1C,QAAO,IAAI,SAAS,YAAY;AAC9B,MAAI,iBAAiB,MAAM;AACzB,wBAAqB,aAAa;AAClC,kBAAe;;EAEjB,MAAM,YAAY;AAClB,iBAAe,EAAE;AACjB,OAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,IACpC,WAAU,IAAK;AAEjB,WAAS;GACT"}
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
const require_index = require("../utils/index.cjs");
|
|
2
|
+
//#region src/signal/signal.ts
|
|
3
|
+
/** @internal */
|
|
4
|
+
let Owner = null;
|
|
5
|
+
/** @internal */
|
|
6
|
+
let Listener = null;
|
|
7
|
+
/** @internal */
|
|
8
|
+
let Updates = null;
|
|
9
|
+
/** @internal */
|
|
10
|
+
let Pending = null;
|
|
11
|
+
/**
|
|
12
|
+
* Create a reactive signal with an initial value
|
|
13
|
+
*/
|
|
14
|
+
function sig(initial, options) {
|
|
15
|
+
return {
|
|
16
|
+
_value: initial,
|
|
17
|
+
_observers: null,
|
|
18
|
+
_observerSlots: null,
|
|
19
|
+
_comparator: options?.equals !== void 0 ? options.equals : require_index.equalFn
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Read the value of a signal, registering a dependency if inside a reactive context
|
|
24
|
+
*/
|
|
25
|
+
function val(signal) {
|
|
26
|
+
if (Listener !== null) {
|
|
27
|
+
if (signal._observers === null) {
|
|
28
|
+
signal._observers = [];
|
|
29
|
+
signal._observerSlots = [];
|
|
30
|
+
}
|
|
31
|
+
let index = signal._observers.indexOf(Listener);
|
|
32
|
+
if (index === -1) {
|
|
33
|
+
index = signal._observers.length;
|
|
34
|
+
signal._observers.push(Listener);
|
|
35
|
+
signal._observerSlots.push(Listener._sources === null ? 0 : Listener._sources.length);
|
|
36
|
+
if (Listener._sources === null) {
|
|
37
|
+
Listener._sources = [];
|
|
38
|
+
Listener._sourceSlots = [];
|
|
39
|
+
}
|
|
40
|
+
Listener._sources.push(signal);
|
|
41
|
+
Listener._sourceSlots.push(index);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const computed = signal;
|
|
45
|
+
if (computed._state === 1) recompute(computed);
|
|
46
|
+
return signal._value;
|
|
47
|
+
}
|
|
48
|
+
/** @internal - Remove a computation from all its source observer lists */
|
|
49
|
+
function cleanupSources(computation) {
|
|
50
|
+
if (computation._sources !== null) {
|
|
51
|
+
for (let j = computation._sources.length - 1; j >= 0; j--) {
|
|
52
|
+
const source = computation._sources[j];
|
|
53
|
+
const index = computation._sourceSlots[j];
|
|
54
|
+
const obs = source._observers;
|
|
55
|
+
const obsSlots = source._observerSlots;
|
|
56
|
+
if (obs && obsSlots && index < obs.length) {
|
|
57
|
+
const last = obs.pop();
|
|
58
|
+
const lastSlot = obsSlots.pop();
|
|
59
|
+
if (index < obs.length) {
|
|
60
|
+
obs[index] = last;
|
|
61
|
+
obsSlots[index] = lastSlot;
|
|
62
|
+
if (last._sourceSlots) last._sourceSlots[lastSlot] = index;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
computation._sources = null;
|
|
67
|
+
computation._sourceSlots = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** @internal - Run a computation with proper Listener tracking */
|
|
71
|
+
function runComputation(computation) {
|
|
72
|
+
const prevListener = Listener;
|
|
73
|
+
const prevOwner = Owner;
|
|
74
|
+
cleanupSources(computation);
|
|
75
|
+
Listener = computation;
|
|
76
|
+
Owner = computation._owner;
|
|
77
|
+
try {
|
|
78
|
+
const value = computation._fn(computation._value);
|
|
79
|
+
computation._value = value;
|
|
80
|
+
computation._state = 0;
|
|
81
|
+
const computed = computation._computed;
|
|
82
|
+
if (computed) {
|
|
83
|
+
computed._value = value;
|
|
84
|
+
computed._state = 0;
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
} finally {
|
|
88
|
+
Listener = prevListener;
|
|
89
|
+
Owner = prevOwner;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** @internal */
|
|
93
|
+
function recompute(computed) {
|
|
94
|
+
const computation = computed._computation;
|
|
95
|
+
if (!computation?._fn) return;
|
|
96
|
+
runComputation(computation);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Set the value of a signal, notifying dependents
|
|
100
|
+
*/
|
|
101
|
+
function set(signal, value) {
|
|
102
|
+
const comparator = signal._comparator;
|
|
103
|
+
if (comparator?.(signal._value, value)) return value;
|
|
104
|
+
signal._value = value;
|
|
105
|
+
if (signal._observers !== null) scheduleUpdate(signal);
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Update a signal's value using a function of the previous value
|
|
110
|
+
*/
|
|
111
|
+
function update(signal, fn) {
|
|
112
|
+
return set(signal, fn(signal._value));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Read a signal's value without registering a dependency
|
|
116
|
+
*/
|
|
117
|
+
function peek(signal) {
|
|
118
|
+
return signal._value;
|
|
119
|
+
}
|
|
120
|
+
/** @internal - Propagate stale state through computed/memo observers */
|
|
121
|
+
function markDownstream(node) {
|
|
122
|
+
const observers = node._observers;
|
|
123
|
+
if (!observers) return;
|
|
124
|
+
for (let i = 0; i < observers.length; i++) {
|
|
125
|
+
const observer = observers[i];
|
|
126
|
+
if (observer._state !== 0) continue;
|
|
127
|
+
observer._state = 1;
|
|
128
|
+
const computed = observer._computed;
|
|
129
|
+
if (computed) {
|
|
130
|
+
computed._state = 1;
|
|
131
|
+
markDownstream(computed);
|
|
132
|
+
}
|
|
133
|
+
if (observer._user) {
|
|
134
|
+
if (Pending === null) Pending = [];
|
|
135
|
+
Pending.push(observer);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** @internal */
|
|
140
|
+
function scheduleUpdate(signal) {
|
|
141
|
+
const observers = signal._observers;
|
|
142
|
+
if (observers === null) return;
|
|
143
|
+
for (let i = 0; i < observers.length; i++) {
|
|
144
|
+
const observer = observers[i];
|
|
145
|
+
if (observer._state === 0) {
|
|
146
|
+
observer._state = 1;
|
|
147
|
+
const computed = observer._computed;
|
|
148
|
+
if (computed) {
|
|
149
|
+
computed._state = 1;
|
|
150
|
+
markDownstream(computed);
|
|
151
|
+
}
|
|
152
|
+
if (Pending === null) Pending = [];
|
|
153
|
+
Pending.push(observer);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (Updates === null) flushUpdates();
|
|
157
|
+
}
|
|
158
|
+
/** @internal */
|
|
159
|
+
function flushUpdates() {
|
|
160
|
+
const updates = Pending;
|
|
161
|
+
Pending = null;
|
|
162
|
+
if (updates === null) return;
|
|
163
|
+
for (let i = 0; i < updates.length; i++) {
|
|
164
|
+
const computation = updates[i];
|
|
165
|
+
if (computation._user && computation._state === 1) runComputation(computation);
|
|
166
|
+
}
|
|
167
|
+
Updates = null;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Create a derived reactive signal (computed value)
|
|
171
|
+
*/
|
|
172
|
+
function memo(fn) {
|
|
173
|
+
const computed = {
|
|
174
|
+
_fn: fn,
|
|
175
|
+
_value: void 0,
|
|
176
|
+
_observers: null,
|
|
177
|
+
_observerSlots: null,
|
|
178
|
+
_sources: null,
|
|
179
|
+
_sourceSlots: null,
|
|
180
|
+
_state: 1
|
|
181
|
+
};
|
|
182
|
+
const computation = {
|
|
183
|
+
_fn: fn,
|
|
184
|
+
_value: void 0,
|
|
185
|
+
_sources: null,
|
|
186
|
+
_sourceSlots: null,
|
|
187
|
+
_observers: null,
|
|
188
|
+
_observerSlots: null,
|
|
189
|
+
_owner: Owner,
|
|
190
|
+
_cleanups: null,
|
|
191
|
+
_context: null,
|
|
192
|
+
_suspense: null,
|
|
193
|
+
_user: false,
|
|
194
|
+
_pure: true,
|
|
195
|
+
_state: 1,
|
|
196
|
+
_updatedAt: null
|
|
197
|
+
};
|
|
198
|
+
computed._computation = computation;
|
|
199
|
+
computation._computed = computed;
|
|
200
|
+
const callable = (() => {
|
|
201
|
+
if (computed._state === 1) recompute(computed);
|
|
202
|
+
return computed._value;
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(callable, "_state", {
|
|
205
|
+
get() {
|
|
206
|
+
return computed._state;
|
|
207
|
+
},
|
|
208
|
+
set(v) {
|
|
209
|
+
computed._state = v;
|
|
210
|
+
},
|
|
211
|
+
enumerable: true,
|
|
212
|
+
configurable: true
|
|
213
|
+
});
|
|
214
|
+
Object.defineProperty(callable, "_value", {
|
|
215
|
+
get() {
|
|
216
|
+
return computed._value;
|
|
217
|
+
},
|
|
218
|
+
set(v) {
|
|
219
|
+
computed._value = v;
|
|
220
|
+
},
|
|
221
|
+
enumerable: true,
|
|
222
|
+
configurable: true
|
|
223
|
+
});
|
|
224
|
+
Object.defineProperty(callable, "_observers", {
|
|
225
|
+
get() {
|
|
226
|
+
return computed._observers;
|
|
227
|
+
},
|
|
228
|
+
set(v) {
|
|
229
|
+
computed._observers = v;
|
|
230
|
+
},
|
|
231
|
+
enumerable: true,
|
|
232
|
+
configurable: true
|
|
233
|
+
});
|
|
234
|
+
Object.defineProperty(callable, "_observerSlots", {
|
|
235
|
+
get() {
|
|
236
|
+
return computed._observerSlots;
|
|
237
|
+
},
|
|
238
|
+
set(v) {
|
|
239
|
+
computed._observerSlots = v;
|
|
240
|
+
},
|
|
241
|
+
enumerable: true,
|
|
242
|
+
configurable: true
|
|
243
|
+
});
|
|
244
|
+
Object.defineProperty(callable, "_sources", {
|
|
245
|
+
get() {
|
|
246
|
+
return computed._sources;
|
|
247
|
+
},
|
|
248
|
+
set(v) {
|
|
249
|
+
computed._sources = v;
|
|
250
|
+
},
|
|
251
|
+
enumerable: true,
|
|
252
|
+
configurable: true
|
|
253
|
+
});
|
|
254
|
+
Object.defineProperty(callable, "_sourceSlots", {
|
|
255
|
+
get() {
|
|
256
|
+
return computed._sourceSlots;
|
|
257
|
+
},
|
|
258
|
+
set(v) {
|
|
259
|
+
computed._sourceSlots = v;
|
|
260
|
+
},
|
|
261
|
+
enumerable: true,
|
|
262
|
+
configurable: true
|
|
263
|
+
});
|
|
264
|
+
Object.defineProperty(callable, "_fn", {
|
|
265
|
+
get() {
|
|
266
|
+
return computed._fn;
|
|
267
|
+
},
|
|
268
|
+
enumerable: true,
|
|
269
|
+
configurable: true
|
|
270
|
+
});
|
|
271
|
+
Object.defineProperty(callable, "_computation", {
|
|
272
|
+
get() {
|
|
273
|
+
return computed._computation;
|
|
274
|
+
},
|
|
275
|
+
set(v) {
|
|
276
|
+
computed._computation = v;
|
|
277
|
+
},
|
|
278
|
+
enumerable: true,
|
|
279
|
+
configurable: true
|
|
280
|
+
});
|
|
281
|
+
recompute(computed);
|
|
282
|
+
return callable;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Execute a function without tracking signal dependencies
|
|
286
|
+
*/
|
|
287
|
+
function untrack(fn) {
|
|
288
|
+
const prevListener = Listener;
|
|
289
|
+
Listener = null;
|
|
290
|
+
try {
|
|
291
|
+
return fn();
|
|
292
|
+
} finally {
|
|
293
|
+
Listener = prevListener;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Batch multiple signal updates into a single reactive cycle
|
|
298
|
+
*/
|
|
299
|
+
function batch(fn) {
|
|
300
|
+
const prevUpdates = Updates;
|
|
301
|
+
const prevPending = Pending;
|
|
302
|
+
Updates = [];
|
|
303
|
+
Pending = [];
|
|
304
|
+
try {
|
|
305
|
+
fn();
|
|
306
|
+
} finally {
|
|
307
|
+
if (prevPending !== null && prevPending.length > 0) Pending = prevPending.concat(Pending);
|
|
308
|
+
Updates = prevUpdates;
|
|
309
|
+
flushUpdates();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Create a reactive root context
|
|
314
|
+
*/
|
|
315
|
+
function createRoot(fn) {
|
|
316
|
+
const prevOwner = Owner;
|
|
317
|
+
const prevListener = Listener;
|
|
318
|
+
const root = {
|
|
319
|
+
_owned: null,
|
|
320
|
+
_cleanups: null,
|
|
321
|
+
_owner: prevOwner,
|
|
322
|
+
_context: null
|
|
323
|
+
};
|
|
324
|
+
Owner = root;
|
|
325
|
+
Listener = null;
|
|
326
|
+
try {
|
|
327
|
+
return fn(() => cleanRoot(root));
|
|
328
|
+
} finally {
|
|
329
|
+
Owner = prevOwner;
|
|
330
|
+
Listener = prevListener;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/** @internal */
|
|
334
|
+
function cleanRoot(root) {
|
|
335
|
+
if (root._cleanups !== null) {
|
|
336
|
+
const cleanups = root._cleanups;
|
|
337
|
+
root._cleanups = null;
|
|
338
|
+
for (let i = cleanups.length - 1; i >= 0; i--) cleanups[i]();
|
|
339
|
+
}
|
|
340
|
+
if (root._owned !== null) {
|
|
341
|
+
const owned = root._owned;
|
|
342
|
+
root._owned = null;
|
|
343
|
+
for (let i = 0; i < owned.length; i++) cleanNode(owned[i]);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Register a cleanup callback to run when the owner is disposed
|
|
348
|
+
*/
|
|
349
|
+
function onCleanup(fn) {
|
|
350
|
+
if (Owner === null) return;
|
|
351
|
+
if (Owner._cleanups === null) Owner._cleanups = [];
|
|
352
|
+
Owner._cleanups.push(fn);
|
|
353
|
+
}
|
|
354
|
+
/** @internal */
|
|
355
|
+
function cleanNode(node) {
|
|
356
|
+
if ("_cleanups" in node && node._cleanups !== null) {
|
|
357
|
+
const cleanups = node._cleanups;
|
|
358
|
+
node._cleanups = null;
|
|
359
|
+
for (let i = cleanups.length - 1; i >= 0; i--) cleanups[i]();
|
|
360
|
+
}
|
|
361
|
+
if ("_owned" in node && node._owned !== null) {
|
|
362
|
+
const owned = node._owned;
|
|
363
|
+
node._owned = null;
|
|
364
|
+
for (let i = 0; i < owned.length; i++) cleanNode(owned[i]);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
//#endregion
|
|
368
|
+
Object.defineProperty(exports, "Owner", {
|
|
369
|
+
enumerable: true,
|
|
370
|
+
get: function() {
|
|
371
|
+
return Owner;
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
exports.batch = batch;
|
|
375
|
+
exports.cleanupSources = cleanupSources;
|
|
376
|
+
exports.createRoot = createRoot;
|
|
377
|
+
exports.memo = memo;
|
|
378
|
+
exports.onCleanup = onCleanup;
|
|
379
|
+
exports.peek = peek;
|
|
380
|
+
exports.runComputation = runComputation;
|
|
381
|
+
exports.set = set;
|
|
382
|
+
exports.sig = sig;
|
|
383
|
+
exports.untrack = untrack;
|
|
384
|
+
exports.update = update;
|
|
385
|
+
exports.val = val;
|
|
386
|
+
|
|
387
|
+
//# sourceMappingURL=signal.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal.cjs","names":["equalFn"],"sources":["../../src/signal/signal.ts"],"sourcesContent":["/**\n * Reactive signal system for @hedystia/view\n *\n * Signals provide mutable state with automatic dependency tracking.\n */\n\nimport type {\n Computation,\n Computed,\n EffectFunction,\n Owner as OwnerType,\n Signal,\n SignalOptions,\n} from \"../types\";\nimport { equalFn } from \"../utils\";\n\n/** @internal */\nexport let Owner: OwnerType | null = null;\n\n/** @internal */\nexport let Listener: Computation<any> | null = null;\n\n/** @internal */\nlet Updates: Computation<any>[] | null = null;\n\n/** @internal */\nconst _Effects: Computation<any>[] | null = null;\n\n/** @internal */\nexport let Pending: Computation<any>[] | null = null;\n\n/**\n * Create a reactive signal with an initial value\n */\nexport function sig<T>(initial: T, options?: SignalOptions<T>): Signal<T> {\n const s: Signal<T> = {\n _value: initial,\n _observers: null,\n _observerSlots: null,\n _comparator: options?.equals !== undefined ? (options.equals as any) : equalFn,\n };\n return s;\n}\n\n/**\n * Read the value of a signal, registering a dependency if inside a reactive context\n */\nexport function val<T>(signal: Signal<T> | Computed<T>): T {\n if (Listener !== null) {\n if (signal._observers === null) {\n signal._observers = [];\n signal._observerSlots = [];\n }\n\n // Check if already registered\n let index = signal._observers.indexOf(Listener);\n if (index === -1) {\n index = signal._observers.length;\n signal._observers.push(Listener);\n signal._observerSlots!.push(Listener._sources === null ? 0 : Listener._sources.length);\n\n if (Listener._sources === null) {\n Listener._sources = [];\n Listener._sourceSlots = [];\n }\n Listener._sources.push(signal);\n Listener._sourceSlots!.push(index);\n }\n }\n\n // Check if computed needs re-evaluation\n const computed = signal as Computed<T>;\n if (computed._state === 1) {\n recompute(computed);\n }\n\n return signal._value;\n}\n\n/** @internal - Remove a computation from all its source observer lists */\nexport function cleanupSources(computation: Computation<any>): void {\n if (computation._sources !== null) {\n for (let j = computation._sources.length - 1; j >= 0; j--) {\n const source: Signal<any> = computation._sources[j]!;\n const index = computation._sourceSlots![j]!;\n const obs = source._observers;\n const obsSlots: number[] | null = source._observerSlots;\n if (obs && obsSlots && index < obs.length) {\n // Swap-and-pop: move last observer into this slot\n const last = obs.pop()!;\n const lastSlot = obsSlots.pop()!;\n if (index < obs.length) {\n obs[index] = last;\n obsSlots[index] = lastSlot;\n // Update the swapped observer's _sourceSlots to point to new index\n if (last._sourceSlots) {\n last._sourceSlots[lastSlot] = index;\n }\n }\n }\n }\n computation._sources = null;\n computation._sourceSlots = null;\n }\n}\n\n/** @internal - Run a computation with proper Listener tracking */\nexport function runComputation<T>(computation: Computation<T>): T | undefined {\n const prevListener = Listener;\n const prevOwner = Owner;\n\n cleanupSources(computation);\n Listener = computation;\n Owner = computation._owner;\n\n try {\n const value = computation._fn(computation._value as any);\n computation._value = value;\n computation._state = 0;\n\n const computed = (computation as any)._computed as Computed<T> | undefined;\n if (computed) {\n computed._value = value as T;\n computed._state = 0;\n }\n\n return value;\n } finally {\n Listener = prevListener;\n Owner = prevOwner;\n }\n}\n\n/** @internal */\nfunction recompute<T>(computed: Computed<T>): void {\n const computation = (computed as any)._computation as Computation<T>;\n if (!computation?._fn) {\n return;\n }\n runComputation(computation);\n}\n\n/**\n * Set the value of a signal, notifying dependents\n */\nexport function set<T>(signal: Signal<T>, value: T): T {\n const comparator = signal._comparator;\n if (comparator?.(signal._value, value)) {\n return value;\n }\n signal._value = value;\n if (signal._observers !== null) {\n scheduleUpdate(signal);\n }\n return value;\n}\n\n/**\n * Update a signal's value using a function of the previous value\n */\nexport function update<T>(signal: Signal<T>, fn: (prev: T) => T): T {\n const value = fn(signal._value);\n return set(signal, value);\n}\n\n/**\n * Read a signal's value without registering a dependency\n */\nexport function peek<T>(signal: Signal<T>): T {\n return signal._value;\n}\n\n/** @internal - Propagate stale state through computed/memo observers */\nfunction markDownstream(node: { _observers: Computation<any>[] | null }): void {\n const observers = node._observers;\n if (!observers) {\n return;\n }\n\n for (let i = 0; i < observers.length; i++) {\n const observer = observers[i]!;\n if (observer._state !== 0) {\n continue;\n }\n\n observer._state = 1;\n\n const computed = (observer as any)._computed as Computed<any> | undefined;\n if (computed) {\n computed._state = 1;\n markDownstream(computed);\n }\n\n if (observer._user) {\n if (Pending === null) {\n Pending = [];\n }\n Pending.push(observer);\n }\n }\n}\n\n/** @internal */\nfunction scheduleUpdate<T>(signal: Signal<T>): void {\n const observers = signal._observers;\n if (observers === null) {\n return;\n }\n\n for (let i = 0; i < observers.length; i++) {\n const observer = observers[i]!;\n if (observer._state === 0) {\n observer._state = 1;\n\n const computed = (observer as any)._computed as any;\n if (computed) {\n computed._state = 1;\n // Propagate stale state through downstream observers of this computed\n markDownstream(computed);\n }\n\n if (Pending === null) {\n Pending = [];\n }\n Pending.push(observer);\n }\n }\n\n // Only flush if not in a batch\n if (Updates === null) {\n flushUpdates();\n }\n}\n\n/** @internal */\nfunction flushUpdates(): void {\n const updates = Pending;\n Pending = null;\n if (updates === null) {\n return;\n }\n\n for (let i = 0; i < updates.length; i++) {\n const computation = updates[i]!;\n\n if (computation._user && computation._state === 1) {\n runComputation(computation);\n }\n // Non-user computations (memos) stay stale for lazy re-evaluation.\n // Don't force _state=1 here — recompute() may have already resolved it to 0.\n }\n Updates = null;\n}\n\n/**\n * Create a derived reactive signal (computed value)\n */\nexport function memo<T>(fn: () => T): Computed<T> {\n const computed: Computed<T> = {\n _fn: fn,\n _value: undefined as T,\n _observers: null,\n _observerSlots: null,\n _sources: null,\n _sourceSlots: null,\n _state: 1,\n } as Computed<T>;\n\n const computation: Computation<T> = {\n _fn: fn as EffectFunction<T>,\n _value: undefined,\n _sources: null,\n _sourceSlots: null,\n _observers: null,\n _observerSlots: null,\n _owner: Owner,\n _cleanups: null,\n _context: null,\n _suspense: null,\n _user: false,\n _pure: true,\n _state: 1,\n _updatedAt: null,\n };\n\n // Link computed and computation bidirectionally\n (computed as any)._computation = computation;\n (computation as any)._computed = computed;\n\n // Make computed callable and proxy all properties to computed\n const callable = (() => {\n if (computed._state === 1) {\n recompute(computed);\n }\n return computed._value;\n }) as Computed<T>;\n\n // Proxy all properties to computed so they stay in sync\n Object.defineProperty(callable, \"_state\", {\n get() {\n return computed._state;\n },\n set(v: 0 | 1 | 2) {\n computed._state = v;\n },\n enumerable: true,\n configurable: true,\n });\n Object.defineProperty(callable, \"_value\", {\n get() {\n return computed._value;\n },\n set(v: T) {\n computed._value = v;\n },\n enumerable: true,\n configurable: true,\n });\n Object.defineProperty(callable, \"_observers\", {\n get() {\n return computed._observers;\n },\n set(v: any) {\n computed._observers = v;\n },\n enumerable: true,\n configurable: true,\n });\n Object.defineProperty(callable, \"_observerSlots\", {\n get() {\n return computed._observerSlots;\n },\n set(v: any) {\n computed._observerSlots = v;\n },\n enumerable: true,\n configurable: true,\n });\n Object.defineProperty(callable, \"_sources\", {\n get() {\n return computed._sources;\n },\n set(v: any) {\n computed._sources = v;\n },\n enumerable: true,\n configurable: true,\n });\n Object.defineProperty(callable, \"_sourceSlots\", {\n get() {\n return computed._sourceSlots;\n },\n set(v: any) {\n computed._sourceSlots = v;\n },\n enumerable: true,\n configurable: true,\n });\n Object.defineProperty(callable, \"_fn\", {\n get() {\n return computed._fn;\n },\n enumerable: true,\n configurable: true,\n });\n Object.defineProperty(callable, \"_computation\", {\n get() {\n return (computed as any)._computation;\n },\n set(v: any) {\n (computed as any)._computation = v;\n },\n enumerable: true,\n configurable: true,\n });\n\n // Initial computation\n recompute(computed);\n\n return callable;\n}\n\n/**\n * Execute a function without tracking signal dependencies\n */\nexport function untrack<T>(fn: () => T): T {\n const prevListener = Listener;\n Listener = null;\n try {\n return fn();\n } finally {\n Listener = prevListener;\n }\n}\n\n/**\n * Batch multiple signal updates into a single reactive cycle\n */\nexport function batch(fn: () => void): void {\n const prevUpdates = Updates;\n const prevPending = Pending;\n Updates = [];\n Pending = [];\n try {\n fn();\n } finally {\n // Collect all pending updates\n if (prevPending !== null && prevPending.length > 0) {\n Pending = prevPending.concat(Pending);\n }\n Updates = prevUpdates;\n // Flush after batch completes\n flushUpdates();\n }\n}\n\n/**\n * Create a reactive root context\n */\nexport function createRoot<T>(fn: (dispose: () => void) => T): T {\n const prevOwner = Owner;\n const prevListener = Listener;\n const root: OwnerType = {\n _owned: null,\n _cleanups: null,\n _owner: prevOwner,\n _context: null,\n };\n Owner = root;\n Listener = null;\n\n try {\n return fn(() => cleanRoot(root));\n } finally {\n Owner = prevOwner;\n Listener = prevListener;\n }\n}\n\n/** @internal */\nfunction cleanRoot(root: OwnerType): void {\n if (root._cleanups !== null) {\n const cleanups = root._cleanups;\n root._cleanups = null;\n // Run cleanups in reverse order (LIFO)\n for (let i = cleanups.length - 1; i >= 0; i--) {\n cleanups[i]!();\n }\n }\n if (root._owned !== null) {\n const owned = root._owned;\n root._owned = null;\n for (let i = 0; i < owned.length; i++) {\n cleanNode(owned[i]!);\n }\n }\n}\n\n/**\n * Register a cleanup callback to run when the owner is disposed\n */\nexport function onCleanup(fn: () => void): void {\n if (Owner === null) {\n return;\n }\n if (Owner._cleanups === null) {\n Owner._cleanups = [];\n }\n Owner._cleanups.push(fn);\n}\n\n/** @internal */\nexport function cleanNode(node: Computation<any> | OwnerType): void {\n if (\"_cleanups\" in node && node._cleanups !== null) {\n const cleanups = node._cleanups;\n node._cleanups = null;\n // Run cleanups in reverse order (LIFO)\n for (let i = cleanups.length - 1; i >= 0; i--) {\n cleanups[i]!();\n }\n }\n if (\"_owned\" in node && node._owned !== null) {\n const owned = node._owned;\n node._owned = null;\n for (let i = 0; i < owned.length; i++) {\n cleanNode(owned[i]!);\n }\n }\n}\n"],"mappings":";;;AAiBA,IAAW,QAA0B;;AAGrC,IAAW,WAAoC;;AAG/C,IAAI,UAAqC;;AAMzC,IAAW,UAAqC;;;;AAKhD,SAAgB,IAAO,SAAY,SAAuC;AAOxE,QANqB;EACnB,QAAQ;EACR,YAAY;EACZ,gBAAgB;EAChB,aAAa,SAAS,WAAW,KAAA,IAAa,QAAQ,SAAiBA,cAAAA;EACxE;;;;;AAOH,SAAgB,IAAO,QAAoC;AACzD,KAAI,aAAa,MAAM;AACrB,MAAI,OAAO,eAAe,MAAM;AAC9B,UAAO,aAAa,EAAE;AACtB,UAAO,iBAAiB,EAAE;;EAI5B,IAAI,QAAQ,O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S,IAAK;;AAGlB,KAAI,KAAK,WAAW,MAAM;EACxB,MAAM,QAAQ,KAAK;AACnB,OAAK,SAAS;AACd,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,WAAU,MAAM,GAAI;;;;;;AAQ1B,SAAgB,UAAU,IAAsB;AAC9C,KAAI,UAAU,KACZ;AAEF,KAAI,MAAM,cAAc,KACtB,OAAM,YAAY,EAAE;AAEtB,OAAM,UAAU,KAAK,GAAG;;;AAI1B,SAAgB,UAAU,MAA0C;AAClE,KAAI,eAAe,QAAQ,KAAK,cAAc,MAAM;EAClD,MAAM,WAAW,KAAK;AACtB,OAAK,YAAY;AAEjB,OAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,IACxC,UAAS,IAAK;;AAGlB,KAAI,YAAY,QAAQ,KAAK,WAAW,MAAM;EAC5C,MAAM,QAAQ,KAAK;AACnB,OAAK,SAAS;AACd,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,WAAU,MAAM,GAAI"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Computed, Owner as Owner$1, Signal, SignalOptions } from "../types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/signal/signal.d.ts
|
|
4
|
+
/** @internal */
|
|
5
|
+
declare let Owner: Owner$1 | null;
|
|
6
|
+
/**
|
|
7
|
+
* Create a reactive signal with an initial value
|
|
8
|
+
*/
|
|
9
|
+
declare function sig<T>(initial: T, options?: SignalOptions<T>): Signal<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Read the value of a signal, registering a dependency if inside a reactive context
|
|
12
|
+
*/
|
|
13
|
+
declare function val<T>(signal: Signal<T> | Computed<T>): T;
|
|
14
|
+
/**
|
|
15
|
+
* Set the value of a signal, notifying dependents
|
|
16
|
+
*/
|
|
17
|
+
declare function set<T>(signal: Signal<T>, value: T): T;
|
|
18
|
+
/**
|
|
19
|
+
* Update a signal's value using a function of the previous value
|
|
20
|
+
*/
|
|
21
|
+
declare function update<T>(signal: Signal<T>, fn: (prev: T) => T): T;
|
|
22
|
+
/**
|
|
23
|
+
* Read a signal's value without registering a dependency
|
|
24
|
+
*/
|
|
25
|
+
declare function peek<T>(signal: Signal<T>): T;
|
|
26
|
+
/**
|
|
27
|
+
* Create a derived reactive signal (computed value)
|
|
28
|
+
*/
|
|
29
|
+
declare function memo<T>(fn: () => T): Computed<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Execute a function without tracking signal dependencies
|
|
32
|
+
*/
|
|
33
|
+
declare function untrack<T>(fn: () => T): T;
|
|
34
|
+
/**
|
|
35
|
+
* Batch multiple signal updates into a single reactive cycle
|
|
36
|
+
*/
|
|
37
|
+
declare function batch(fn: () => void): void;
|
|
38
|
+
/**
|
|
39
|
+
* Create a reactive root context
|
|
40
|
+
*/
|
|
41
|
+
declare function createRoot<T>(fn: (dispose: () => void) => T): T;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { Owner, batch, createRoot, memo, peek, set, sig, untrack, update, val };
|
|
44
|
+
//# sourceMappingURL=signal.d.cts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Computed, Owner as Owner$1, Signal, SignalOptions } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/signal/signal.d.ts
|
|
4
|
+
/** @internal */
|
|
5
|
+
declare let Owner: Owner$1 | null;
|
|
6
|
+
/**
|
|
7
|
+
* Create a reactive signal with an initial value
|
|
8
|
+
*/
|
|
9
|
+
declare function sig<T>(initial: T, options?: SignalOptions<T>): Signal<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Read the value of a signal, registering a dependency if inside a reactive context
|
|
12
|
+
*/
|
|
13
|
+
declare function val<T>(signal: Signal<T> | Computed<T>): T;
|
|
14
|
+
/**
|
|
15
|
+
* Set the value of a signal, notifying dependents
|
|
16
|
+
*/
|
|
17
|
+
declare function set<T>(signal: Signal<T>, value: T): T;
|
|
18
|
+
/**
|
|
19
|
+
* Update a signal's value using a function of the previous value
|
|
20
|
+
*/
|
|
21
|
+
declare function update<T>(signal: Signal<T>, fn: (prev: T) => T): T;
|
|
22
|
+
/**
|
|
23
|
+
* Read a signal's value without registering a dependency
|
|
24
|
+
*/
|
|
25
|
+
declare function peek<T>(signal: Signal<T>): T;
|
|
26
|
+
/**
|
|
27
|
+
* Create a derived reactive signal (computed value)
|
|
28
|
+
*/
|
|
29
|
+
declare function memo<T>(fn: () => T): Computed<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Execute a function without tracking signal dependencies
|
|
32
|
+
*/
|
|
33
|
+
declare function untrack<T>(fn: () => T): T;
|
|
34
|
+
/**
|
|
35
|
+
* Batch multiple signal updates into a single reactive cycle
|
|
36
|
+
*/
|
|
37
|
+
declare function batch(fn: () => void): void;
|
|
38
|
+
/**
|
|
39
|
+
* Create a reactive root context
|
|
40
|
+
*/
|
|
41
|
+
declare function createRoot<T>(fn: (dispose: () => void) => T): T;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { Owner, batch, createRoot, memo, peek, set, sig, untrack, update, val };
|
|
44
|
+
//# sourceMappingURL=signal.d.mts.map
|