tannijs 0.1.1 → 0.1.3
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/chunk-B42XHE7V.js +318 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +13 -1
- package/dist/internals.d.ts +1 -9
- package/dist/internals.js +6 -147
- package/package.json +1 -1
- package/dist/chunk-GQWZEFRY.js +0 -163
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// src/reactivity.ts
|
|
2
|
+
var Signal = class {
|
|
3
|
+
constructor(value) {
|
|
4
|
+
this.value = value;
|
|
5
|
+
}
|
|
6
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
7
|
+
read() {
|
|
8
|
+
trackDependency(this);
|
|
9
|
+
return this.value;
|
|
10
|
+
}
|
|
11
|
+
peek() {
|
|
12
|
+
return this.value;
|
|
13
|
+
}
|
|
14
|
+
write(next) {
|
|
15
|
+
if (Object.is(this.value, next)) {
|
|
16
|
+
return this.value;
|
|
17
|
+
}
|
|
18
|
+
this.value = next;
|
|
19
|
+
notifySubscribers(this.subscribers);
|
|
20
|
+
return this.value;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var Memo = class {
|
|
24
|
+
constructor(fn) {
|
|
25
|
+
this.fn = fn;
|
|
26
|
+
this.execute();
|
|
27
|
+
}
|
|
28
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
29
|
+
deps = /* @__PURE__ */ new Set();
|
|
30
|
+
cleanups = [];
|
|
31
|
+
value;
|
|
32
|
+
read() {
|
|
33
|
+
trackDependency(this);
|
|
34
|
+
return this.value;
|
|
35
|
+
}
|
|
36
|
+
execute() {
|
|
37
|
+
cleanupComputation(this);
|
|
38
|
+
const previous = currentComputation;
|
|
39
|
+
currentComputation = this;
|
|
40
|
+
let nextValue;
|
|
41
|
+
try {
|
|
42
|
+
nextValue = this.fn();
|
|
43
|
+
} finally {
|
|
44
|
+
currentComputation = previous;
|
|
45
|
+
}
|
|
46
|
+
if (!Object.is(nextValue, this.value)) {
|
|
47
|
+
this.value = nextValue;
|
|
48
|
+
notifySubscribers(this.subscribers);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var pendingComputations = /* @__PURE__ */ new Set();
|
|
53
|
+
var batchDepth = 0;
|
|
54
|
+
var currentComputation = null;
|
|
55
|
+
function trackDependency(source) {
|
|
56
|
+
if (!currentComputation) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
source.subscribers.add(currentComputation);
|
|
60
|
+
currentComputation.deps.add(source);
|
|
61
|
+
}
|
|
62
|
+
function cleanupComputation(computation) {
|
|
63
|
+
for (const source of computation.deps) {
|
|
64
|
+
source.subscribers.delete(computation);
|
|
65
|
+
}
|
|
66
|
+
computation.deps.clear();
|
|
67
|
+
const cleanups = computation.cleanups;
|
|
68
|
+
computation.cleanups = [];
|
|
69
|
+
for (const cleanup of cleanups) {
|
|
70
|
+
cleanup();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function runComputation(computation) {
|
|
74
|
+
if (batchDepth > 0) {
|
|
75
|
+
pendingComputations.add(computation);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
computation.execute();
|
|
79
|
+
}
|
|
80
|
+
function notifySubscribers(subscribers) {
|
|
81
|
+
const queue = Array.from(subscribers);
|
|
82
|
+
for (const subscriber of queue) {
|
|
83
|
+
runComputation(subscriber);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function flushPending() {
|
|
87
|
+
if (pendingComputations.size === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const queue = Array.from(pendingComputations);
|
|
91
|
+
pendingComputations.clear();
|
|
92
|
+
for (const computation of queue) {
|
|
93
|
+
computation.execute();
|
|
94
|
+
}
|
|
95
|
+
if (pendingComputations.size > 0) {
|
|
96
|
+
flushPending();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function createSignal(initialValue) {
|
|
100
|
+
const signal = new Signal(initialValue);
|
|
101
|
+
const accessor = () => signal.read();
|
|
102
|
+
const setter = (value) => {
|
|
103
|
+
const nextValue = typeof value === "function" ? value(signal.peek()) : value;
|
|
104
|
+
return signal.write(nextValue);
|
|
105
|
+
};
|
|
106
|
+
return [accessor, setter];
|
|
107
|
+
}
|
|
108
|
+
function createEffect(fn) {
|
|
109
|
+
const effect2 = {
|
|
110
|
+
deps: /* @__PURE__ */ new Set(),
|
|
111
|
+
cleanups: [],
|
|
112
|
+
execute() {
|
|
113
|
+
cleanupComputation(effect2);
|
|
114
|
+
const previous = currentComputation;
|
|
115
|
+
currentComputation = effect2;
|
|
116
|
+
try {
|
|
117
|
+
fn();
|
|
118
|
+
} finally {
|
|
119
|
+
currentComputation = previous;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
effect2.execute();
|
|
124
|
+
}
|
|
125
|
+
function createMemo(fn) {
|
|
126
|
+
const memo = new Memo(fn);
|
|
127
|
+
return () => memo.read();
|
|
128
|
+
}
|
|
129
|
+
function batch(fn) {
|
|
130
|
+
batchDepth += 1;
|
|
131
|
+
try {
|
|
132
|
+
return fn();
|
|
133
|
+
} finally {
|
|
134
|
+
batchDepth -= 1;
|
|
135
|
+
if (batchDepth === 0) {
|
|
136
|
+
flushPending();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function untrack(fn) {
|
|
141
|
+
const previous = currentComputation;
|
|
142
|
+
currentComputation = null;
|
|
143
|
+
try {
|
|
144
|
+
return fn();
|
|
145
|
+
} finally {
|
|
146
|
+
currentComputation = previous;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function onCleanup(fn) {
|
|
150
|
+
if (!currentComputation) {
|
|
151
|
+
throw new Error("onCleanup must be called inside a tracked computation.");
|
|
152
|
+
}
|
|
153
|
+
currentComputation.cleanups.push(fn);
|
|
154
|
+
}
|
|
155
|
+
function onMount(fn) {
|
|
156
|
+
queueMicrotask(fn);
|
|
157
|
+
}
|
|
158
|
+
var effect = createEffect;
|
|
159
|
+
|
|
160
|
+
// src/dom.ts
|
|
161
|
+
var delegatedEvents = /* @__PURE__ */ new Set();
|
|
162
|
+
var listeningEvents = /* @__PURE__ */ new Set();
|
|
163
|
+
var directListeners = /* @__PURE__ */ new WeakMap();
|
|
164
|
+
function template(html) {
|
|
165
|
+
const tpl = document.createElement("template");
|
|
166
|
+
tpl.innerHTML = html.trim();
|
|
167
|
+
if (tpl.content.childNodes.length === 1) {
|
|
168
|
+
return tpl.content.firstChild;
|
|
169
|
+
}
|
|
170
|
+
return tpl.content;
|
|
171
|
+
}
|
|
172
|
+
function insert(parent, value, marker = null) {
|
|
173
|
+
if (typeof value === "function") {
|
|
174
|
+
let currentNodes = [];
|
|
175
|
+
createEffect(() => {
|
|
176
|
+
const resolved = value();
|
|
177
|
+
const nextNodes2 = normalizeNodes(resolved);
|
|
178
|
+
currentNodes = replaceNodes(parent, currentNodes, nextNodes2, marker);
|
|
179
|
+
});
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const nextNodes = normalizeNodes(value);
|
|
183
|
+
replaceNodes(parent, [], nextNodes, marker);
|
|
184
|
+
}
|
|
185
|
+
function spread(element, props) {
|
|
186
|
+
for (const [key, value] of Object.entries(props)) {
|
|
187
|
+
if (key === "children") {
|
|
188
|
+
insert(element, value);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (key === "style" && value && typeof value === "object") {
|
|
192
|
+
Object.assign(element.style, value);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const eventName = toEventName(key);
|
|
196
|
+
if (eventName) {
|
|
197
|
+
applyEventHandler(element, eventName, value);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
applyProperty(element, key, value);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function delegateEvents(eventNames) {
|
|
204
|
+
for (const eventName of eventNames) {
|
|
205
|
+
const normalized = eventName.toLowerCase();
|
|
206
|
+
delegatedEvents.add(normalized);
|
|
207
|
+
if (listeningEvents.has(normalized)) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
listeningEvents.add(normalized);
|
|
211
|
+
document.addEventListener(normalized, handleDelegatedEvent);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function handleDelegatedEvent(event) {
|
|
215
|
+
const type = event.type.toLowerCase();
|
|
216
|
+
let node = event.target;
|
|
217
|
+
while (node && node !== document) {
|
|
218
|
+
if (node instanceof Element) {
|
|
219
|
+
const handlers = node.__tnDelegatedHandlers;
|
|
220
|
+
const handler = handlers?.[type];
|
|
221
|
+
if (handler) {
|
|
222
|
+
handler(event);
|
|
223
|
+
if (event.cancelBubble) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
node = node.parentNode;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function applyEventHandler(element, eventName, value) {
|
|
232
|
+
if (typeof value !== "function") {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const handler = value;
|
|
236
|
+
if (delegatedEvents.has(eventName)) {
|
|
237
|
+
const delegatedElement = element;
|
|
238
|
+
delegatedElement.__tnDelegatedHandlers ??= {};
|
|
239
|
+
delegatedElement.__tnDelegatedHandlers[eventName] = handler;
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
let listenersForElement = directListeners.get(element);
|
|
243
|
+
if (!listenersForElement) {
|
|
244
|
+
listenersForElement = /* @__PURE__ */ new Map();
|
|
245
|
+
directListeners.set(element, listenersForElement);
|
|
246
|
+
}
|
|
247
|
+
const previous = listenersForElement.get(eventName);
|
|
248
|
+
if (previous) {
|
|
249
|
+
element.removeEventListener(eventName, previous);
|
|
250
|
+
}
|
|
251
|
+
listenersForElement.set(eventName, handler);
|
|
252
|
+
element.addEventListener(eventName, handler);
|
|
253
|
+
}
|
|
254
|
+
function applyProperty(element, key, value) {
|
|
255
|
+
const writableElement = element;
|
|
256
|
+
if (value === false || value == null) {
|
|
257
|
+
element.removeAttribute(key);
|
|
258
|
+
if (key in element) {
|
|
259
|
+
writableElement[key] = "";
|
|
260
|
+
}
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (key in element && !key.startsWith("aria-") && !key.startsWith("data-")) {
|
|
264
|
+
writableElement[key] = value;
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
element.setAttribute(key, String(value));
|
|
268
|
+
}
|
|
269
|
+
function toEventName(key) {
|
|
270
|
+
if (key.startsWith("on:")) {
|
|
271
|
+
return key.slice(3).toLowerCase();
|
|
272
|
+
}
|
|
273
|
+
if (key.startsWith("@")) {
|
|
274
|
+
return key.slice(1).toLowerCase();
|
|
275
|
+
}
|
|
276
|
+
if (key.startsWith("on") && key.length > 2) {
|
|
277
|
+
return key.slice(2).toLowerCase();
|
|
278
|
+
}
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
function normalizeNodes(value) {
|
|
282
|
+
if (value == null || value === false || value === true) {
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
if (Array.isArray(value)) {
|
|
286
|
+
return value.flatMap((entry) => normalizeNodes(entry));
|
|
287
|
+
}
|
|
288
|
+
if (value instanceof Node) {
|
|
289
|
+
return [value];
|
|
290
|
+
}
|
|
291
|
+
return [document.createTextNode(String(value))];
|
|
292
|
+
}
|
|
293
|
+
function replaceNodes(parent, currentNodes, nextNodes, marker) {
|
|
294
|
+
for (const node of currentNodes) {
|
|
295
|
+
if (node.parentNode === parent) {
|
|
296
|
+
parent.removeChild(node);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
for (const node of nextNodes) {
|
|
300
|
+
parent.insertBefore(node, marker);
|
|
301
|
+
}
|
|
302
|
+
return nextNodes;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export {
|
|
306
|
+
createSignal,
|
|
307
|
+
createEffect,
|
|
308
|
+
createMemo,
|
|
309
|
+
batch,
|
|
310
|
+
untrack,
|
|
311
|
+
onCleanup,
|
|
312
|
+
onMount,
|
|
313
|
+
effect,
|
|
314
|
+
template,
|
|
315
|
+
insert,
|
|
316
|
+
spread,
|
|
317
|
+
delegateEvents
|
|
318
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,13 @@ declare function createMemo<T>(fn: () => T): Accessor<T>;
|
|
|
7
7
|
declare function batch<T>(fn: () => T): T;
|
|
8
8
|
declare function untrack<T>(fn: () => T): T;
|
|
9
9
|
declare function onCleanup(fn: CleanupFn): void;
|
|
10
|
+
declare function onMount(fn: () => void): void;
|
|
11
|
+
declare const effect: typeof createEffect;
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
type InsertValue = Node | string | number | boolean | null | undefined | InsertValue[] | (() => InsertValue);
|
|
14
|
+
declare function template(html: string): Node;
|
|
15
|
+
declare function insert(parent: Node, value: InsertValue, marker?: Node | null): void;
|
|
16
|
+
declare function spread(element: Element, props: Record<string, unknown>): void;
|
|
17
|
+
declare function delegateEvents(eventNames: string[]): void;
|
|
18
|
+
|
|
19
|
+
export { type Accessor, type InsertValue, type Setter, batch, createEffect, createMemo, createSignal, delegateEvents, effect, insert, onCleanup, onMount, spread, template, untrack };
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,26 @@ import {
|
|
|
3
3
|
createEffect,
|
|
4
4
|
createMemo,
|
|
5
5
|
createSignal,
|
|
6
|
+
delegateEvents,
|
|
7
|
+
effect,
|
|
8
|
+
insert,
|
|
6
9
|
onCleanup,
|
|
10
|
+
onMount,
|
|
11
|
+
spread,
|
|
12
|
+
template,
|
|
7
13
|
untrack
|
|
8
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-B42XHE7V.js";
|
|
9
15
|
export {
|
|
10
16
|
batch,
|
|
11
17
|
createEffect,
|
|
12
18
|
createMemo,
|
|
13
19
|
createSignal,
|
|
20
|
+
delegateEvents,
|
|
21
|
+
effect,
|
|
22
|
+
insert,
|
|
14
23
|
onCleanup,
|
|
24
|
+
onMount,
|
|
25
|
+
spread,
|
|
26
|
+
template,
|
|
15
27
|
untrack
|
|
16
28
|
};
|
package/dist/internals.d.ts
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export { createEffect } from './index.js';
|
|
2
|
-
|
|
3
|
-
type InsertValue = Node | string | number | boolean | null | undefined | InsertValue[] | (() => InsertValue);
|
|
4
|
-
declare function template(html: string): Node;
|
|
5
|
-
declare function insert(parent: Node, value: InsertValue, marker?: Node | null): void;
|
|
6
|
-
declare function spread(element: Element, props: Record<string, unknown>): void;
|
|
7
|
-
declare function delegateEvents(eventNames: string[]): void;
|
|
8
|
-
|
|
9
|
-
export { type InsertValue, delegateEvents, insert, spread, template };
|
|
1
|
+
export { InsertValue, createEffect, delegateEvents, insert, spread, template } from './index.js';
|
package/dist/internals.js
CHANGED
|
@@ -1,151 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createEffect
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var directListeners = /* @__PURE__ */ new WeakMap();
|
|
9
|
-
function template(html) {
|
|
10
|
-
const tpl = document.createElement("template");
|
|
11
|
-
tpl.innerHTML = html.trim();
|
|
12
|
-
if (tpl.content.childNodes.length === 1) {
|
|
13
|
-
return tpl.content.firstChild;
|
|
14
|
-
}
|
|
15
|
-
return tpl.content;
|
|
16
|
-
}
|
|
17
|
-
function insert(parent, value, marker = null) {
|
|
18
|
-
if (typeof value === "function") {
|
|
19
|
-
let currentNodes = [];
|
|
20
|
-
createEffect(() => {
|
|
21
|
-
const resolved = value();
|
|
22
|
-
const nextNodes2 = normalizeNodes(resolved);
|
|
23
|
-
currentNodes = replaceNodes(parent, currentNodes, nextNodes2, marker);
|
|
24
|
-
});
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const nextNodes = normalizeNodes(value);
|
|
28
|
-
replaceNodes(parent, [], nextNodes, marker);
|
|
29
|
-
}
|
|
30
|
-
function spread(element, props) {
|
|
31
|
-
for (const [key, value] of Object.entries(props)) {
|
|
32
|
-
if (key === "children") {
|
|
33
|
-
insert(element, value);
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (key === "style" && value && typeof value === "object") {
|
|
37
|
-
Object.assign(element.style, value);
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const eventName = toEventName(key);
|
|
41
|
-
if (eventName) {
|
|
42
|
-
applyEventHandler(element, eventName, value);
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
applyProperty(element, key, value);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function delegateEvents(eventNames) {
|
|
49
|
-
for (const eventName of eventNames) {
|
|
50
|
-
const normalized = eventName.toLowerCase();
|
|
51
|
-
delegatedEvents.add(normalized);
|
|
52
|
-
if (listeningEvents.has(normalized)) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
listeningEvents.add(normalized);
|
|
56
|
-
document.addEventListener(normalized, handleDelegatedEvent);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function handleDelegatedEvent(event) {
|
|
60
|
-
const type = event.type.toLowerCase();
|
|
61
|
-
let node = event.target;
|
|
62
|
-
while (node && node !== document) {
|
|
63
|
-
if (node instanceof Element) {
|
|
64
|
-
const handlers = node.__tnDelegatedHandlers;
|
|
65
|
-
const handler = handlers?.[type];
|
|
66
|
-
if (handler) {
|
|
67
|
-
handler(event);
|
|
68
|
-
if (event.cancelBubble) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
node = node.parentNode;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function applyEventHandler(element, eventName, value) {
|
|
77
|
-
if (typeof value !== "function") {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const handler = value;
|
|
81
|
-
if (delegatedEvents.has(eventName)) {
|
|
82
|
-
const delegatedElement = element;
|
|
83
|
-
delegatedElement.__tnDelegatedHandlers ??= {};
|
|
84
|
-
delegatedElement.__tnDelegatedHandlers[eventName] = handler;
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
let listenersForElement = directListeners.get(element);
|
|
88
|
-
if (!listenersForElement) {
|
|
89
|
-
listenersForElement = /* @__PURE__ */ new Map();
|
|
90
|
-
directListeners.set(element, listenersForElement);
|
|
91
|
-
}
|
|
92
|
-
const previous = listenersForElement.get(eventName);
|
|
93
|
-
if (previous) {
|
|
94
|
-
element.removeEventListener(eventName, previous);
|
|
95
|
-
}
|
|
96
|
-
listenersForElement.set(eventName, handler);
|
|
97
|
-
element.addEventListener(eventName, handler);
|
|
98
|
-
}
|
|
99
|
-
function applyProperty(element, key, value) {
|
|
100
|
-
const writableElement = element;
|
|
101
|
-
if (value === false || value == null) {
|
|
102
|
-
element.removeAttribute(key);
|
|
103
|
-
if (key in element) {
|
|
104
|
-
writableElement[key] = "";
|
|
105
|
-
}
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (key in element && !key.startsWith("aria-") && !key.startsWith("data-")) {
|
|
109
|
-
writableElement[key] = value;
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
element.setAttribute(key, String(value));
|
|
113
|
-
}
|
|
114
|
-
function toEventName(key) {
|
|
115
|
-
if (key.startsWith("on:")) {
|
|
116
|
-
return key.slice(3).toLowerCase();
|
|
117
|
-
}
|
|
118
|
-
if (key.startsWith("@")) {
|
|
119
|
-
return key.slice(1).toLowerCase();
|
|
120
|
-
}
|
|
121
|
-
if (key.startsWith("on") && key.length > 2) {
|
|
122
|
-
return key.slice(2).toLowerCase();
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
function normalizeNodes(value) {
|
|
127
|
-
if (value == null || value === false || value === true) {
|
|
128
|
-
return [];
|
|
129
|
-
}
|
|
130
|
-
if (Array.isArray(value)) {
|
|
131
|
-
return value.flatMap((entry) => normalizeNodes(entry));
|
|
132
|
-
}
|
|
133
|
-
if (value instanceof Node) {
|
|
134
|
-
return [value];
|
|
135
|
-
}
|
|
136
|
-
return [document.createTextNode(String(value))];
|
|
137
|
-
}
|
|
138
|
-
function replaceNodes(parent, currentNodes, nextNodes, marker) {
|
|
139
|
-
for (const node of currentNodes) {
|
|
140
|
-
if (node.parentNode === parent) {
|
|
141
|
-
parent.removeChild(node);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
for (const node of nextNodes) {
|
|
145
|
-
parent.insertBefore(node, marker);
|
|
146
|
-
}
|
|
147
|
-
return nextNodes;
|
|
148
|
-
}
|
|
2
|
+
createEffect,
|
|
3
|
+
delegateEvents,
|
|
4
|
+
insert,
|
|
5
|
+
spread,
|
|
6
|
+
template
|
|
7
|
+
} from "./chunk-B42XHE7V.js";
|
|
149
8
|
export {
|
|
150
9
|
createEffect,
|
|
151
10
|
delegateEvents,
|
package/package.json
CHANGED
package/dist/chunk-GQWZEFRY.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
// src/reactivity.ts
|
|
2
|
-
var Signal = class {
|
|
3
|
-
constructor(value) {
|
|
4
|
-
this.value = value;
|
|
5
|
-
}
|
|
6
|
-
subscribers = /* @__PURE__ */ new Set();
|
|
7
|
-
read() {
|
|
8
|
-
trackDependency(this);
|
|
9
|
-
return this.value;
|
|
10
|
-
}
|
|
11
|
-
peek() {
|
|
12
|
-
return this.value;
|
|
13
|
-
}
|
|
14
|
-
write(next) {
|
|
15
|
-
if (Object.is(this.value, next)) {
|
|
16
|
-
return this.value;
|
|
17
|
-
}
|
|
18
|
-
this.value = next;
|
|
19
|
-
notifySubscribers(this.subscribers);
|
|
20
|
-
return this.value;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
var Memo = class {
|
|
24
|
-
constructor(fn) {
|
|
25
|
-
this.fn = fn;
|
|
26
|
-
this.execute();
|
|
27
|
-
}
|
|
28
|
-
subscribers = /* @__PURE__ */ new Set();
|
|
29
|
-
deps = /* @__PURE__ */ new Set();
|
|
30
|
-
cleanups = [];
|
|
31
|
-
value;
|
|
32
|
-
read() {
|
|
33
|
-
trackDependency(this);
|
|
34
|
-
return this.value;
|
|
35
|
-
}
|
|
36
|
-
execute() {
|
|
37
|
-
cleanupComputation(this);
|
|
38
|
-
const previous = currentComputation;
|
|
39
|
-
currentComputation = this;
|
|
40
|
-
let nextValue;
|
|
41
|
-
try {
|
|
42
|
-
nextValue = this.fn();
|
|
43
|
-
} finally {
|
|
44
|
-
currentComputation = previous;
|
|
45
|
-
}
|
|
46
|
-
if (!Object.is(nextValue, this.value)) {
|
|
47
|
-
this.value = nextValue;
|
|
48
|
-
notifySubscribers(this.subscribers);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var pendingComputations = /* @__PURE__ */ new Set();
|
|
53
|
-
var batchDepth = 0;
|
|
54
|
-
var currentComputation = null;
|
|
55
|
-
function trackDependency(source) {
|
|
56
|
-
if (!currentComputation) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
source.subscribers.add(currentComputation);
|
|
60
|
-
currentComputation.deps.add(source);
|
|
61
|
-
}
|
|
62
|
-
function cleanupComputation(computation) {
|
|
63
|
-
for (const source of computation.deps) {
|
|
64
|
-
source.subscribers.delete(computation);
|
|
65
|
-
}
|
|
66
|
-
computation.deps.clear();
|
|
67
|
-
const cleanups = computation.cleanups;
|
|
68
|
-
computation.cleanups = [];
|
|
69
|
-
for (const cleanup of cleanups) {
|
|
70
|
-
cleanup();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function runComputation(computation) {
|
|
74
|
-
if (batchDepth > 0) {
|
|
75
|
-
pendingComputations.add(computation);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
computation.execute();
|
|
79
|
-
}
|
|
80
|
-
function notifySubscribers(subscribers) {
|
|
81
|
-
const queue = Array.from(subscribers);
|
|
82
|
-
for (const subscriber of queue) {
|
|
83
|
-
runComputation(subscriber);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function flushPending() {
|
|
87
|
-
if (pendingComputations.size === 0) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const queue = Array.from(pendingComputations);
|
|
91
|
-
pendingComputations.clear();
|
|
92
|
-
for (const computation of queue) {
|
|
93
|
-
computation.execute();
|
|
94
|
-
}
|
|
95
|
-
if (pendingComputations.size > 0) {
|
|
96
|
-
flushPending();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
function createSignal(initialValue) {
|
|
100
|
-
const signal = new Signal(initialValue);
|
|
101
|
-
const accessor = () => signal.read();
|
|
102
|
-
const setter = (value) => {
|
|
103
|
-
const nextValue = typeof value === "function" ? value(signal.peek()) : value;
|
|
104
|
-
return signal.write(nextValue);
|
|
105
|
-
};
|
|
106
|
-
return [accessor, setter];
|
|
107
|
-
}
|
|
108
|
-
function createEffect(fn) {
|
|
109
|
-
const effect = {
|
|
110
|
-
deps: /* @__PURE__ */ new Set(),
|
|
111
|
-
cleanups: [],
|
|
112
|
-
execute() {
|
|
113
|
-
cleanupComputation(effect);
|
|
114
|
-
const previous = currentComputation;
|
|
115
|
-
currentComputation = effect;
|
|
116
|
-
try {
|
|
117
|
-
fn();
|
|
118
|
-
} finally {
|
|
119
|
-
currentComputation = previous;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
effect.execute();
|
|
124
|
-
}
|
|
125
|
-
function createMemo(fn) {
|
|
126
|
-
const memo = new Memo(fn);
|
|
127
|
-
return () => memo.read();
|
|
128
|
-
}
|
|
129
|
-
function batch(fn) {
|
|
130
|
-
batchDepth += 1;
|
|
131
|
-
try {
|
|
132
|
-
return fn();
|
|
133
|
-
} finally {
|
|
134
|
-
batchDepth -= 1;
|
|
135
|
-
if (batchDepth === 0) {
|
|
136
|
-
flushPending();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function untrack(fn) {
|
|
141
|
-
const previous = currentComputation;
|
|
142
|
-
currentComputation = null;
|
|
143
|
-
try {
|
|
144
|
-
return fn();
|
|
145
|
-
} finally {
|
|
146
|
-
currentComputation = previous;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function onCleanup(fn) {
|
|
150
|
-
if (!currentComputation) {
|
|
151
|
-
throw new Error("onCleanup must be called inside a tracked computation.");
|
|
152
|
-
}
|
|
153
|
-
currentComputation.cleanups.push(fn);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export {
|
|
157
|
-
createSignal,
|
|
158
|
-
createEffect,
|
|
159
|
-
createMemo,
|
|
160
|
-
batch,
|
|
161
|
-
untrack,
|
|
162
|
-
onCleanup
|
|
163
|
-
};
|