keits 0.0.1 → 0.0.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.
Files changed (52) hide show
  1. package/dist/dev/index.js +548 -430
  2. package/dist/dev/router.js +443 -0
  3. package/dist/dev/shared/element-C4DfKtZW.js +255 -0
  4. package/dist/dev/shared/graph-D6-x_CWC.js +324 -0
  5. package/dist/dev/shared/owner-DlUsXKXE.js +122 -0
  6. package/dist/dev/svg.js +70 -0
  7. package/dist/prod/index.js +359 -377
  8. package/dist/prod/router.js +343 -0
  9. package/dist/prod/shared/element-DUtXb3px.js +187 -0
  10. package/dist/prod/shared/graph-C_aA46c6.js +240 -0
  11. package/dist/prod/shared/owner-DgJNPM0P.js +104 -0
  12. package/dist/prod/svg.js +8 -0
  13. package/dist/types/async/index.d.ts +2 -0
  14. package/dist/types/async/lazy.d.ts +7 -0
  15. package/dist/types/async/resource.d.ts +23 -0
  16. package/dist/types/async/suspense-context.d.ts +4 -0
  17. package/dist/types/core/graph.d.ts +8 -0
  18. package/dist/types/dom/element.d.ts +3 -0
  19. package/dist/types/dom/events.d.ts +1 -0
  20. package/dist/types/dom/hooks.d.ts +8 -0
  21. package/dist/types/dom/index.d.ts +6 -0
  22. package/dist/types/dom/insert.d.ts +2 -0
  23. package/dist/types/dom/mount.d.ts +2 -0
  24. package/dist/types/dom/namespaces.d.ts +1 -0
  25. package/dist/types/dom/props.d.ts +3 -0
  26. package/dist/types/dom/render-effect.d.ts +1 -0
  27. package/dist/types/dom/tags.d.ts +112 -0
  28. package/dist/types/dom/types.d.ts +43 -0
  29. package/dist/types/dom/unsafe.d.ts +1 -0
  30. package/dist/types/flow/catch.d.ts +2 -0
  31. package/dist/types/flow/dynamic.d.ts +6 -0
  32. package/dist/types/flow/for.d.ts +7 -0
  33. package/dist/types/flow/if.d.ts +4 -0
  34. package/dist/types/flow/index.d.ts +8 -0
  35. package/dist/types/flow/portal.d.ts +2 -0
  36. package/dist/types/flow/range.d.ts +11 -0
  37. package/dist/types/flow/show.d.ts +1 -0
  38. package/dist/types/flow/suspense.d.ts +2 -0
  39. package/dist/types/flow/switch.d.ts +9 -0
  40. package/dist/types/index.d.ts +3 -0
  41. package/dist/types/router/history.d.ts +21 -0
  42. package/dist/types/router/index.d.ts +3 -0
  43. package/dist/types/router/links.d.ts +1 -0
  44. package/dist/types/router/match.d.ts +15 -0
  45. package/dist/types/router/router.d.ts +10 -0
  46. package/dist/types/router/scroll.d.ts +5 -0
  47. package/dist/types/router/types.d.ts +87 -0
  48. package/dist/types/svg/element.d.ts +2 -0
  49. package/dist/types/svg/index.d.ts +3 -0
  50. package/dist/types/svg/tags.d.ts +63 -0
  51. package/dist/types/svg/types.d.ts +13 -0
  52. package/package.json +31 -6
package/dist/dev/index.js CHANGED
@@ -1,434 +1,8 @@
1
- var LOOP_LIMIT = 100;
2
- var currentObserver = null;
3
- var currentOwner = null;
4
- var currentRunId = 0;
5
- var runCounter = 0;
6
- var newSources = null;
7
- var keptCount = 0;
8
- var batchDepth = 0;
9
- var flushCounter = 0;
10
- var queue = [];
11
- var mounts = [];
12
- var lastWritten = null;
13
- var unhandledErrors = [];
14
- var staticDepth = 0;
15
- function track(source) {
16
- const observer = currentObserver;
17
- if (observer === null || source.seenBy === currentRunId) return;
18
- source.seenBy = currentRunId;
19
- if (newSources === null && observer.sources[keptCount] === source) {
20
- keptCount++;
21
- return;
22
- }
23
- (newSources ??= []).push(source);
24
- source.observers.push(observer);
25
- }
26
- function isTracking() {
27
- return currentObserver !== null;
28
- }
29
- function notify(source) {
30
- if (source.observers.length === 0) return;
31
- lastWritten = source;
32
- batchDepth++;
33
- try {
34
- for (const observer of source.observers) mark(observer, 2);
35
- } finally {
36
- endBatch();
37
- }
38
- }
39
- function mark(node, state) {
40
- if (node.state >= state) return;
41
- const wasClean = node.state === 0;
42
- node.state = state;
43
- if (!wasClean) return;
44
- if (node.kind === 1) queue.push(node);
45
- else for (const observer of node.observers) mark(observer, 1);
46
- }
47
- function updateIfNeeded(node) {
48
- if (node.state === 1) for (const source of node.sources) {
49
- if (source.kind !== 2) continue;
50
- updateIfNeeded(source);
51
- if (node.state === 2) break;
52
- }
53
- if (node.state === 2) {
54
- if (node.kind === 1) runEffect(node);
55
- else recompute(node);
56
- } else node.state = 0;
57
- }
58
- function recompute(node) {
59
- let changed;
60
- node.computing = true;
61
- try {
62
- const next = run(node, () => node.fn(node.value));
63
- changed = !node.hasValue || node.hasError || node.equals === false || !node.equals(node.value, next);
64
- if (changed) node.value = next;
65
- node.hasValue = true;
66
- node.hasError = false;
67
- node.error = void 0;
68
- } catch (error) {
69
- changed = true;
70
- node.hasError = true;
71
- node.error = error;
72
- } finally {
73
- node.computing = false;
74
- }
75
- if (changed) {
76
- for (const observer of node.observers) if (observer.state === 1) observer.state = 2;
77
- }
78
- }
79
- function runEffect(node) {
80
- try {
81
- run(node, node.fn);
82
- } catch (error) {
83
- handleError(error, node);
84
- }
85
- }
86
- function run(node, fn) {
87
- cleanNode(node);
88
- const prevObserver = currentObserver;
89
- const prevOwner = currentOwner;
90
- const prevRunId = currentRunId;
91
- const prevNew = newSources;
92
- const prevKept = keptCount;
93
- currentObserver = node;
94
- currentOwner = node;
95
- currentRunId = ++runCounter;
96
- newSources = null;
97
- keptCount = 0;
98
- node.state = 0;
99
- try {
100
- return fn();
101
- } finally {
102
- updateSources(node, newSources, keptCount);
103
- currentObserver = prevObserver;
104
- currentOwner = prevOwner;
105
- currentRunId = prevRunId;
106
- newSources = prevNew;
107
- keptCount = prevKept;
108
- }
109
- }
110
- function updateSources(node, added, kept) {
111
- if (node.disposed) {
112
- if (added !== null) for (const source of added) unlink(source, node);
113
- return;
114
- }
115
- const sources = node.sources;
116
- for (let i = kept; i < sources.length; i++) unlink(sources[i], node);
117
- sources.length = kept;
118
- if (added !== null) for (const source of added) sources.push(source);
119
- }
120
- function unlink(source, node) {
121
- const observers = source.observers;
122
- const i = observers.lastIndexOf(node);
123
- if (i === -1) return;
124
- observers[i] = observers[observers.length - 1];
125
- observers.pop();
126
- }
127
- function batch(fn) {
128
- batchDepth++;
129
- try {
130
- return fn();
131
- } finally {
132
- endBatch();
133
- }
134
- }
135
- function endBatch() {
136
- if (--batchDepth === 0) settle();
137
- }
138
- function settle() {
139
- do {
140
- flush();
141
- if (mounts.length > 0) runMounts();
142
- } while (queue.length > 0 || mounts.length > 0);
143
- if (unhandledErrors.length > 0) {
144
- const errors = unhandledErrors.splice(0);
145
- throw errors.length === 1 ? errors[0] : new AggregateError(errors, "[keits] multiple unhandled errors");
146
- }
147
- }
148
- function runMounts() {
149
- batchDepth++;
150
- const pending = mounts.splice(0);
151
- try {
152
- for (const { owner, fn } of pending) {
153
- if (owner?.disposed) continue;
154
- try {
155
- runWithOwner$1(owner, fn);
156
- } catch (error) {
157
- handleError(error, owner);
158
- }
159
- }
160
- } finally {
161
- batchDepth--;
162
- }
163
- }
164
- function flush() {
165
- batchDepth++;
166
- const flushId = ++flushCounter;
167
- let completed = false;
168
- try {
169
- for (let i = 0; i < queue.length; i++) {
170
- const node = queue[i];
171
- if (node.state === 0) continue;
172
- if (node.flushId !== flushId) {
173
- node.flushId = flushId;
174
- node.flushRuns = 0;
175
- }
176
- if (++node.flushRuns > LOOP_LIMIT) {
177
- node.state = 0;
178
- handleError(loopError(node), node);
179
- continue;
180
- }
181
- runTop(node);
182
- }
183
- completed = true;
184
- } finally {
185
- if (!completed) for (const node of queue) node.state = 0;
186
- queue.length = 0;
187
- batchDepth--;
188
- }
189
- }
190
- function runTop(node) {
191
- const staleOwners = [];
192
- for (let o = node.owner; o !== null; o = o.owner) if (o.kind !== 3 && o.state !== 0) staleOwners.push(o);
193
- for (let i = staleOwners.length - 1; i >= 0; i--) updateIfNeeded(staleOwners[i]);
194
- updateIfNeeded(node);
195
- }
196
- function loopError(node) {
197
- {
198
- const who = node.name ? `"${node.name}"` : "an unnamed effect";
199
- const what = lastWritten?.name ? ` Last signal written: "${lastWritten.name}".` : "";
200
- return /* @__PURE__ */ new Error(`[keits] Infinite update loop: ${who} re-ran ${LOOP_LIMIT} times in one update. It probably writes a signal it also reads.${what}`);
201
- }
202
- }
203
- function untrack(fn) {
204
- const prev = currentObserver;
205
- currentObserver = null;
206
- try {
207
- return fn();
208
- } finally {
209
- currentObserver = prev;
210
- }
211
- }
212
- function adopt(node) {
213
- const owner = currentOwner;
214
- node.owner = owner;
215
- if (owner !== null) (owner.children ??= []).push(node);
216
- }
217
- function getOwner$1() {
218
- return currentOwner;
219
- }
220
- function runWithOwner$1(owner, fn) {
221
- const prevOwner = currentOwner;
222
- const prevObserver = currentObserver;
223
- currentOwner = owner;
224
- currentObserver = null;
225
- try {
226
- return fn();
227
- } finally {
228
- currentOwner = prevOwner;
229
- currentObserver = prevObserver;
230
- }
231
- }
232
- function addCleanup(fn) {
233
- if (currentOwner === null) return false;
234
- (currentOwner.cleanups ??= []).push(fn);
235
- return true;
236
- }
237
- function addMount(fn) {
238
- if (staticDepth > 0) return;
239
- mounts.push({
240
- owner: currentOwner,
241
- fn
242
- });
243
- }
244
- function cleanNode(node) {
245
- const children = node.children;
246
- const cleanups = node.cleanups;
247
- node.children = null;
248
- node.cleanups = null;
249
- if (children !== null) for (let i = children.length - 1; i >= 0; i--) dispose(children[i]);
250
- if (cleanups !== null) for (let i = cleanups.length - 1; i >= 0; i--) try {
251
- cleanups[i]();
252
- } catch (error) {
253
- handleError(error, node);
254
- }
255
- }
256
- function dispose(node) {
257
- if (node.disposed) return;
258
- node.disposed = true;
259
- if (node.kind !== 3) {
260
- for (const source of node.sources) unlink(source, node);
261
- node.sources.length = 0;
262
- node.state = 0;
263
- }
264
- cleanNode(node);
265
- }
266
- function handleError(error, owner) {
267
- for (let o = owner; o !== null; o = o.owner) {
268
- if (o.kind !== 3 || o.handler === null || o.disposed) continue;
269
- const handler = o.handler;
270
- try {
271
- runWithOwner$1(o.owner, () => handler(error));
272
- return;
273
- } catch (handlerError) {
274
- error = handlerError;
275
- }
276
- }
277
- if (batchDepth === 0) throw error;
278
- unhandledErrors.push(error);
279
- }
280
- function isStaticRender() {
281
- return staticDepth > 0;
282
- }
283
- function withStaticRender(fn) {
284
- staticDepth++;
285
- try {
286
- return fn();
287
- } finally {
288
- staticDepth--;
289
- }
290
- }
291
- // src/core/signal.ts
292
- function signal(value, options) {
293
- const node = {
294
- kind: 0,
295
- value,
296
- equals: options?.equals ?? Object.is,
297
- observers: [],
298
- seenBy: 0
299
- };
300
- if (options?.name !== void 0) node.name = options.name;
301
- const read = () => {
302
- track(node);
303
- return node.value;
304
- };
305
- const set = (next) => {
306
- const value = typeof next === "function" ? next(node.value) : next;
307
- if (node.equals !== false && node.equals(node.value, value)) return;
308
- node.value = value;
309
- notify(node);
310
- };
311
- return Object.assign(read, { set });
312
- }
313
- // src/core/effect.ts
314
- function effect(fn, options) {
315
- if (isStaticRender()) return;
316
- const node = {
317
- kind: 1,
318
- fn,
319
- state: 0,
320
- sources: [],
321
- flushId: 0,
322
- flushRuns: 0,
323
- owner: null,
324
- children: null,
325
- cleanups: null,
326
- disposed: false
327
- };
328
- if (options?.name !== void 0) node.name = options.name;
329
- adopt(node);
330
- batch(() => runEffect(node));
331
- }
332
- // src/core/computed.ts
333
- function computed(fn, options) {
334
- const node = {
335
- kind: 2,
336
- fn,
337
- value: void 0,
338
- equals: options?.equals ?? Object.is,
339
- hasValue: false,
340
- hasError: false,
341
- error: void 0,
342
- computing: false,
343
- state: 2,
344
- sources: [],
345
- observers: [],
346
- seenBy: 0,
347
- flushId: 0,
348
- flushRuns: 0,
349
- owner: null,
350
- children: null,
351
- cleanups: null,
352
- disposed: false
353
- };
354
- if (options?.name !== void 0) node.name = options.name;
355
- adopt(node);
356
- return () => {
357
- if (node.computing) throw cycleError(node);
358
- if (node.state !== 0) updateIfNeeded(node);
359
- track(node);
360
- if (node.hasError) throw node.error;
361
- return node.value;
362
- };
363
- }
364
- function cycleError(node) {
365
- {
366
- const who = node.name ? `"${node.name}"` : "a computed";
367
- return /* @__PURE__ */ new Error(`[keits] Cycle detected: ${who} reads itself (directly or through other computeds).`);
368
- }
369
- }
1
+ import { a as onMount, c as computed, i as onCleanup, l as signal, n as createRoot, o as renderStatic, r as getOwner, s as runWithOwner, t as catchError } from "./shared/owner-DlUsXKXE.js";
2
+ import { a as renderEffect, i as insert, n as html, o as hooks, s as effect } from "./shared/element-C4DfKtZW.js";
3
+ import { a as deferMounts, c as handleError, d as notify, h as untrack, i as batch, l as isStaticRender, m as track, p as runWithOwner$1, r as adopt, s as getOwner$1, t as addCleanup, u as isTracking } from "./shared/graph-D6-x_CWC.js";
370
4
  // src/core/env.ts
371
5
  var isServer = typeof window === "undefined";
372
- // src/core/owner.ts
373
- function getOwner() {
374
- return getOwner$1();
375
- }
376
- function runWithOwner(owner, fn) {
377
- return runWithOwner$1(owner, fn);
378
- }
379
- function createRoot(fn) {
380
- const root = {
381
- kind: 3,
382
- owner: getOwner$1(),
383
- children: null,
384
- cleanups: null,
385
- disposed: false,
386
- handler: null
387
- };
388
- const disposeRoot = () => batch(() => dispose(root));
389
- return batch(() => {
390
- try {
391
- return runWithOwner$1(root, () => fn(disposeRoot));
392
- } catch (error) {
393
- dispose(root);
394
- throw error;
395
- }
396
- });
397
- }
398
- function onCleanup(fn) {
399
- if (!addCleanup(fn) && true) console.warn("[keits] onCleanup was called outside an owner, so it will never run.");
400
- }
401
- function onMount(fn) {
402
- addMount(fn);
403
- }
404
- function catchError(fn, handler) {
405
- const boundary = {
406
- kind: 3,
407
- owner: null,
408
- children: null,
409
- cleanups: null,
410
- disposed: false,
411
- handler
412
- };
413
- adopt(boundary);
414
- return batch(() => {
415
- try {
416
- return runWithOwner$1(boundary, fn);
417
- } catch (error) {
418
- handleError(error, boundary);
419
- return;
420
- }
421
- });
422
- }
423
- function renderStatic(fn) {
424
- return withStaticRender(() => createRoot((dispose) => {
425
- try {
426
- return fn();
427
- } finally {
428
- dispose();
429
- }
430
- }));
431
- }
432
6
  // src/core/context.ts
433
7
  function createContext(defaultValue, options) {
434
8
  const context = { defaultValue };
@@ -601,4 +175,548 @@ function matchAndUpdate(existing, next, key) {
601
175
  }
602
176
  return next;
603
177
  }
604
- export { batch, catchError, computed, createContext, createRoot, effect, getOwner, isServer, isStaticRender, onCleanup, onMount, provide, reconcile, renderStatic, runWithOwner, signal, store, untrack, unwrap, useContext };
178
+ // src/dom/tags.ts
179
+ var $a = /* @__PURE__ */ html("a");
180
+ var $abbr = /* @__PURE__ */ html("abbr");
181
+ var $address = /* @__PURE__ */ html("address");
182
+ var $area = /* @__PURE__ */ html("area");
183
+ var $article = /* @__PURE__ */ html("article");
184
+ var $aside = /* @__PURE__ */ html("aside");
185
+ var $audio = /* @__PURE__ */ html("audio");
186
+ var $b = /* @__PURE__ */ html("b");
187
+ var $base = /* @__PURE__ */ html("base");
188
+ var $bdi = /* @__PURE__ */ html("bdi");
189
+ var $bdo = /* @__PURE__ */ html("bdo");
190
+ var $blockquote = /* @__PURE__ */ html("blockquote");
191
+ var $body = /* @__PURE__ */ html("body");
192
+ var $br = /* @__PURE__ */ html("br");
193
+ var $button = /* @__PURE__ */ html("button");
194
+ var $canvas = /* @__PURE__ */ html("canvas");
195
+ var $caption = /* @__PURE__ */ html("caption");
196
+ var $cite = /* @__PURE__ */ html("cite");
197
+ var $code = /* @__PURE__ */ html("code");
198
+ var $col = /* @__PURE__ */ html("col");
199
+ var $colgroup = /* @__PURE__ */ html("colgroup");
200
+ var $data = /* @__PURE__ */ html("data");
201
+ var $datalist = /* @__PURE__ */ html("datalist");
202
+ var $dd = /* @__PURE__ */ html("dd");
203
+ var $del = /* @__PURE__ */ html("del");
204
+ var $details = /* @__PURE__ */ html("details");
205
+ var $dfn = /* @__PURE__ */ html("dfn");
206
+ var $dialog = /* @__PURE__ */ html("dialog");
207
+ var $div = /* @__PURE__ */ html("div");
208
+ var $dl = /* @__PURE__ */ html("dl");
209
+ var $dt = /* @__PURE__ */ html("dt");
210
+ var $em = /* @__PURE__ */ html("em");
211
+ var $embed = /* @__PURE__ */ html("embed");
212
+ var $fieldset = /* @__PURE__ */ html("fieldset");
213
+ var $figcaption = /* @__PURE__ */ html("figcaption");
214
+ var $figure = /* @__PURE__ */ html("figure");
215
+ var $footer = /* @__PURE__ */ html("footer");
216
+ var $form = /* @__PURE__ */ html("form");
217
+ var $h1 = /* @__PURE__ */ html("h1");
218
+ var $h2 = /* @__PURE__ */ html("h2");
219
+ var $h3 = /* @__PURE__ */ html("h3");
220
+ var $h4 = /* @__PURE__ */ html("h4");
221
+ var $h5 = /* @__PURE__ */ html("h5");
222
+ var $h6 = /* @__PURE__ */ html("h6");
223
+ var $head = /* @__PURE__ */ html("head");
224
+ var $header = /* @__PURE__ */ html("header");
225
+ var $hgroup = /* @__PURE__ */ html("hgroup");
226
+ var $hr = /* @__PURE__ */ html("hr");
227
+ var $html = /* @__PURE__ */ html("html");
228
+ var $i = /* @__PURE__ */ html("i");
229
+ var $iframe = /* @__PURE__ */ html("iframe");
230
+ var $img = /* @__PURE__ */ html("img");
231
+ var $input = /* @__PURE__ */ html("input");
232
+ var $ins = /* @__PURE__ */ html("ins");
233
+ var $kbd = /* @__PURE__ */ html("kbd");
234
+ var $label = /* @__PURE__ */ html("label");
235
+ var $legend = /* @__PURE__ */ html("legend");
236
+ var $li = /* @__PURE__ */ html("li");
237
+ var $link = /* @__PURE__ */ html("link");
238
+ var $main = /* @__PURE__ */ html("main");
239
+ var $map = /* @__PURE__ */ html("map");
240
+ var $mark = /* @__PURE__ */ html("mark");
241
+ var $menu = /* @__PURE__ */ html("menu");
242
+ var $meta = /* @__PURE__ */ html("meta");
243
+ var $meter = /* @__PURE__ */ html("meter");
244
+ var $nav = /* @__PURE__ */ html("nav");
245
+ var $noscript = /* @__PURE__ */ html("noscript");
246
+ var $object = /* @__PURE__ */ html("object");
247
+ var $ol = /* @__PURE__ */ html("ol");
248
+ var $optgroup = /* @__PURE__ */ html("optgroup");
249
+ var $option = /* @__PURE__ */ html("option");
250
+ var $output = /* @__PURE__ */ html("output");
251
+ var $p = /* @__PURE__ */ html("p");
252
+ var $picture = /* @__PURE__ */ html("picture");
253
+ var $pre = /* @__PURE__ */ html("pre");
254
+ var $progress = /* @__PURE__ */ html("progress");
255
+ var $q = /* @__PURE__ */ html("q");
256
+ var $rp = /* @__PURE__ */ html("rp");
257
+ var $rt = /* @__PURE__ */ html("rt");
258
+ var $ruby = /* @__PURE__ */ html("ruby");
259
+ var $s = /* @__PURE__ */ html("s");
260
+ var $samp = /* @__PURE__ */ html("samp");
261
+ var $script = /* @__PURE__ */ html("script");
262
+ var $search = /* @__PURE__ */ html("search");
263
+ var $section = /* @__PURE__ */ html("section");
264
+ var $select = /* @__PURE__ */ html("select");
265
+ var $slot = /* @__PURE__ */ html("slot");
266
+ var $small = /* @__PURE__ */ html("small");
267
+ var $source = /* @__PURE__ */ html("source");
268
+ var $span = /* @__PURE__ */ html("span");
269
+ var $strong = /* @__PURE__ */ html("strong");
270
+ var $style = /* @__PURE__ */ html("style");
271
+ var $sub = /* @__PURE__ */ html("sub");
272
+ var $summary = /* @__PURE__ */ html("summary");
273
+ var $sup = /* @__PURE__ */ html("sup");
274
+ var $table = /* @__PURE__ */ html("table");
275
+ var $tbody = /* @__PURE__ */ html("tbody");
276
+ var $td = /* @__PURE__ */ html("td");
277
+ var $template = /* @__PURE__ */ html("template");
278
+ var $textarea = /* @__PURE__ */ html("textarea");
279
+ var $tfoot = /* @__PURE__ */ html("tfoot");
280
+ var $th = /* @__PURE__ */ html("th");
281
+ var $thead = /* @__PURE__ */ html("thead");
282
+ var $time = /* @__PURE__ */ html("time");
283
+ var $title = /* @__PURE__ */ html("title");
284
+ var $tr = /* @__PURE__ */ html("tr");
285
+ var $track = /* @__PURE__ */ html("track");
286
+ var $u = /* @__PURE__ */ html("u");
287
+ var $ul = /* @__PURE__ */ html("ul");
288
+ var $var = /* @__PURE__ */ html("var");
289
+ var $video = /* @__PURE__ */ html("video");
290
+ var $wbr = /* @__PURE__ */ html("wbr");
291
+ // src/dom/mount.ts
292
+ function mount(app, target) {
293
+ if (target === null) throw new Error("[keits] mount(): the target element was not found (null).");
294
+ const start = hooks.marker();
295
+ const end = hooks.marker();
296
+ target.append(start, end);
297
+ const dispose = createRoot((dispose) => {
298
+ insert(target, app(), end);
299
+ return dispose;
300
+ });
301
+ return () => {
302
+ dispose();
303
+ let node = start;
304
+ while (node !== null) {
305
+ const next = node === end ? null : node.nextSibling;
306
+ node.remove();
307
+ node = next;
308
+ }
309
+ };
310
+ }
311
+ // src/dom/unsafe.ts
312
+ function unsafeHTML(markup) {
313
+ const template = document.createElement("template");
314
+ template.innerHTML = markup;
315
+ return template.content;
316
+ }
317
+ // src/flow/range.ts
318
+ function createRow(build, item) {
319
+ return createRoot((dispose) => {
320
+ const result = build();
321
+ if (isElement(result)) return {
322
+ item,
323
+ index: null,
324
+ dispose,
325
+ first: result,
326
+ last: result
327
+ };
328
+ const holder = document.createDocumentFragment();
329
+ const first = hooks.marker();
330
+ const last = hooks.marker();
331
+ holder.append(first, last);
332
+ insert(holder, result, last);
333
+ return {
334
+ item,
335
+ index: null,
336
+ dispose,
337
+ first,
338
+ last
339
+ };
340
+ });
341
+ }
342
+ function isElement(value) {
343
+ return typeof value === "object" && value !== null && value.nodeType === 1;
344
+ }
345
+ function moveRow(parent, row, anchor) {
346
+ if (row.first === row.last) {
347
+ parent.insertBefore(row.first, anchor);
348
+ return;
349
+ }
350
+ let node = row.first;
351
+ while (node !== null) {
352
+ const nextNode = node === row.last ? null : node.nextSibling;
353
+ parent.insertBefore(node, anchor);
354
+ node = nextNode;
355
+ }
356
+ }
357
+ function removeRow(row) {
358
+ row.dispose();
359
+ let node = row.first;
360
+ while (node !== null) {
361
+ const nextNode = node === row.last ? null : node.nextSibling;
362
+ node.remove();
363
+ node = nextNode;
364
+ }
365
+ }
366
+ // src/flow/for.ts
367
+ function $for(each, render, options) {
368
+ const end = hooks.marker();
369
+ const container = document.createDocumentFragment();
370
+ container.append(end);
371
+ let rows = [];
372
+ let fallback = null;
373
+ addCleanup(() => {
374
+ for (const row of rows) row.dispose();
375
+ fallback?.dispose();
376
+ });
377
+ renderEffect(() => {
378
+ const value = each();
379
+ update(value ? Array.from(value) : []);
380
+ });
381
+ function update(items) {
382
+ const parent = end.parentNode;
383
+ if (items.length === 0) {
384
+ for (const row of rows) removeRow(row);
385
+ rows = [];
386
+ if (fallback === null && options?.fallback) {
387
+ fallback = createRow(options.fallback, null);
388
+ moveRow(parent, fallback, end);
389
+ }
390
+ return;
391
+ }
392
+ if (fallback !== null) {
393
+ removeRow(fallback);
394
+ fallback = null;
395
+ }
396
+ const available = /* @__PURE__ */ new Map();
397
+ rows.forEach((row, i) => {
398
+ const queue = available.get(row.item);
399
+ if (queue) queue.push(i);
400
+ else available.set(row.item, [i]);
401
+ });
402
+ const reused = new Array(rows.length).fill(false);
403
+ const next = new Array(items.length);
404
+ const oldIndex = new Array(items.length);
405
+ for (let i = 0; i < items.length; i++) {
406
+ const item = items[i];
407
+ const queue = available.get(item);
408
+ const old = queue !== void 0 && queue.length > 0 ? queue.shift() : -1;
409
+ if (old >= 0) {
410
+ const row = rows[old];
411
+ row.index(i);
412
+ reused[old] = true;
413
+ next[i] = row;
414
+ } else next[i] = createItemRow(item, i);
415
+ oldIndex[i] = old;
416
+ }
417
+ for (let i = 0; i < rows.length; i++) if (!reused[i]) removeRow(rows[i]);
418
+ const stay = longestIncreasing(oldIndex);
419
+ let anchor = end;
420
+ for (let i = next.length - 1; i >= 0; i--) {
421
+ const row = next[i];
422
+ if (!stay.has(i)) moveRow(parent, row, anchor);
423
+ anchor = row.first;
424
+ }
425
+ rows = next;
426
+ }
427
+ function createItemRow(item, i) {
428
+ let setIndex = () => {};
429
+ const row = createRow(() => {
430
+ const index = signal(i);
431
+ setIndex = index.set;
432
+ return render(item, index);
433
+ }, item);
434
+ row.index = setIndex;
435
+ return row;
436
+ }
437
+ return container;
438
+ }
439
+ function longestIncreasing(sequence) {
440
+ const tails = [];
441
+ const previous = new Array(sequence.length);
442
+ for (let i = 0; i < sequence.length; i++) {
443
+ const value = sequence[i];
444
+ if (value < 0) continue;
445
+ let low = 0;
446
+ let high = tails.length;
447
+ while (low < high) {
448
+ const mid = low + high >> 1;
449
+ if (sequence[tails[mid]] < value) low = mid + 1;
450
+ else high = mid;
451
+ }
452
+ previous[i] = low > 0 ? tails[low - 1] : -1;
453
+ tails[low] = i;
454
+ }
455
+ const result = /* @__PURE__ */ new Set();
456
+ let position = tails.length > 0 ? tails[tails.length - 1] : -1;
457
+ while (position >= 0) {
458
+ result.add(position);
459
+ position = previous[position];
460
+ }
461
+ return result;
462
+ }
463
+ // src/flow/if.ts
464
+ function $if(when, then, otherwise) {
465
+ const value = computed(when);
466
+ const isTruthy = computed(() => Boolean(value()));
467
+ const narrowed = value;
468
+ return () => isTruthy() ? untrack(() => then(narrowed)) : otherwise ? untrack(otherwise) : null;
469
+ }
470
+ // src/flow/show.ts
471
+ function $show(when, element) {
472
+ const original = element.style.display;
473
+ renderEffect(() => {
474
+ if (when()) element.style.display = original;
475
+ else element.style.display = "none";
476
+ });
477
+ return element;
478
+ }
479
+ // src/flow/switch.ts
480
+ function $switch(value, cases, fallback) {
481
+ const key = computed(value);
482
+ return () => {
483
+ const branch = cases[key()] ?? fallback;
484
+ return branch ? untrack(branch) : null;
485
+ };
486
+ }
487
+ // src/flow/dynamic.ts
488
+ function $dynamic(component, props) {
489
+ const current = computed(component);
490
+ return () => {
491
+ const Component = current();
492
+ return Component ? untrack(() => Component(props)) : null;
493
+ };
494
+ }
495
+ // src/flow/catch.ts
496
+ function $catch(children, fallback) {
497
+ const failure = signal(null);
498
+ const reset = () => failure.set(null);
499
+ return () => {
500
+ const current = failure();
501
+ if (current !== null) return untrack(() => fallback(current.error, reset));
502
+ return untrack(() => catchError(() => {
503
+ const content = document.createDocumentFragment();
504
+ insert(content, children());
505
+ return content;
506
+ }, (error) => failure.set({ error })));
507
+ };
508
+ }
509
+ // src/flow/portal.ts
510
+ function $portal(children, target) {
511
+ if (isStaticRender()) return null;
512
+ const host = target === void 0 ? document.body : target;
513
+ if (host === null) throw new Error("[keits] $portal(): the target element was not found (null).");
514
+ const start = hooks.marker();
515
+ const end = hooks.marker();
516
+ host.append(start, end);
517
+ insert(host, untrack(children), end);
518
+ addCleanup(() => {
519
+ let node = start;
520
+ while (node !== null) {
521
+ const next = node === end ? null : node.nextSibling;
522
+ node.remove();
523
+ node = next;
524
+ }
525
+ });
526
+ return null;
527
+ }
528
+ // src/async/suspense-context.ts
529
+ var SuspenseContext = createContext(null);
530
+ // src/flow/suspense.ts
531
+ function $suspense(children, fallback) {
532
+ const pendingCount = signal(0);
533
+ const pending = /* @__PURE__ */ new Set();
534
+ const boundary = { wait(key, subscribe) {
535
+ if (pending.has(key)) return;
536
+ pending.add(key);
537
+ pendingCount.set((n) => n + 1);
538
+ subscribe(() => {
539
+ pending.delete(key);
540
+ pendingCount.set((n) => n - 1);
541
+ });
542
+ } };
543
+ const offscreen = document.createDocumentFragment();
544
+ const contentStart = hooks.marker();
545
+ const contentEnd = hooks.marker();
546
+ offscreen.append(contentStart, contentEnd);
547
+ const { release } = deferMounts(() => provide(SuspenseContext, boundary, () => insert(offscreen, untrack(children), contentEnd)));
548
+ const content = {
549
+ item: null,
550
+ index: null,
551
+ dispose: () => {},
552
+ first: contentStart,
553
+ last: contentEnd
554
+ };
555
+ const end = hooks.marker();
556
+ const container = document.createDocumentFragment();
557
+ container.append(end);
558
+ let fallbackRow = null;
559
+ addCleanup(() => fallbackRow?.dispose());
560
+ renderEffect(() => {
561
+ const waiting = pendingCount() > 0;
562
+ untrack(() => {
563
+ const parent = end.parentNode;
564
+ if (waiting) {
565
+ moveRow(offscreen, content, null);
566
+ if (fallbackRow === null) {
567
+ fallbackRow = createRow(fallback, null);
568
+ moveRow(parent, fallbackRow, end);
569
+ }
570
+ } else {
571
+ if (fallbackRow !== null) {
572
+ removeRow(fallbackRow);
573
+ fallbackRow = null;
574
+ }
575
+ moveRow(parent, content, end);
576
+ release();
577
+ }
578
+ });
579
+ });
580
+ return container;
581
+ }
582
+ // src/async/resource.ts
583
+ function resource(first, second, third) {
584
+ const hasSource = typeof second === "function";
585
+ const source = hasSource ? first : () => true;
586
+ const fetcher = hasSource ? second : (_, info) => first(info);
587
+ const options = hasSource ? third : second;
588
+ const owner = getOwner$1();
589
+ const hasInitial = options !== void 0 && "initialValue" in options;
590
+ const value = signal(options?.initialValue);
591
+ const state = signal(hasInitial ? "ready" : "unresolved");
592
+ const failure = signal(null);
593
+ let controller = null;
594
+ let version = 0;
595
+ let waiters = [];
596
+ let currentSource = null;
597
+ const settleWaiters = () => {
598
+ const list = waiters;
599
+ waiters = [];
600
+ for (const done of list) done();
601
+ };
602
+ function load(src, refetching) {
603
+ controller?.abort();
604
+ controller = null;
605
+ const id = ++version;
606
+ if (src === null || src === void 0 || src === false) {
607
+ currentSource = null;
608
+ state.set(untrack(value) === void 0 ? "unresolved" : "ready");
609
+ settleWaiters();
610
+ return Promise.resolve();
611
+ }
612
+ currentSource = src;
613
+ const abort = new AbortController();
614
+ controller = abort;
615
+ let result;
616
+ try {
617
+ result = fetcher(src, {
618
+ signal: abort.signal,
619
+ refetching,
620
+ value: untrack(value)
621
+ });
622
+ } catch (error) {
623
+ fail(error);
624
+ return Promise.resolve();
625
+ }
626
+ if (!isPromiseLike(result)) {
627
+ succeed(result);
628
+ return Promise.resolve();
629
+ }
630
+ state.set(untrack(value) === void 0 && untrack(state) !== "ready" ? "pending" : "refreshing");
631
+ return Promise.resolve(result).then((data) => {
632
+ if (id === version) succeed(data);
633
+ }, (error) => {
634
+ if (id === version) fail(error);
635
+ });
636
+ }
637
+ function succeed(data) {
638
+ controller = null;
639
+ batch(() => {
640
+ value.set(() => data);
641
+ failure.set(null);
642
+ state.set("ready");
643
+ });
644
+ settleWaiters();
645
+ }
646
+ function fail(error) {
647
+ controller = null;
648
+ batch(() => {
649
+ failure.set({ error });
650
+ state.set("errored");
651
+ });
652
+ settleWaiters();
653
+ }
654
+ renderEffect(() => {
655
+ const src = source();
656
+ untrack(() => load(src, false));
657
+ });
658
+ addCleanup(() => {
659
+ version++;
660
+ controller?.abort();
661
+ controller = null;
662
+ });
663
+ const read = () => {
664
+ const current = state();
665
+ if (current === "errored") throw failure().error;
666
+ if (current === "pending") {
667
+ const boundary = useContext(SuspenseContext);
668
+ if (boundary !== null) boundary.wait(resourceApi, (done) => waiters.push(done));
669
+ }
670
+ return value();
671
+ };
672
+ const resourceApi = Object.assign(read, {
673
+ state: () => state(),
674
+ loading: () => {
675
+ const current = state();
676
+ return current === "pending" || current === "refreshing";
677
+ },
678
+ error: () => failure()?.error,
679
+ refetch: () => untrack(() => load(currentSource ?? source(), true)),
680
+ mutate: (next) => batch(() => {
681
+ value.set(() => next);
682
+ failure.set(null);
683
+ state.set(next === void 0 ? "unresolved" : "ready");
684
+ }),
685
+ optimistic: async (update, action) => {
686
+ const previous = untrack(value);
687
+ const next = update(previous);
688
+ value.set(() => next);
689
+ try {
690
+ await action();
691
+ return true;
692
+ } catch (error) {
693
+ if (untrack(value) === next) value.set(() => previous);
694
+ batch(() => handleError(error, owner));
695
+ return false;
696
+ }
697
+ }
698
+ });
699
+ return resourceApi;
700
+ }
701
+ function isPromiseLike(value) {
702
+ return typeof value?.then === "function";
703
+ }
704
+ // src/async/lazy.ts
705
+ function lazy(load) {
706
+ let loaded;
707
+ let loading;
708
+ const preload = () => loading ??= Promise.resolve(load()).then((module) => loaded = module.default, (error) => {
709
+ loading = void 0;
710
+ throw error;
711
+ });
712
+ const Lazy = (props) => {
713
+ if (loaded !== void 0) return untrack(() => loaded(props));
714
+ const component = resource(() => loaded ?? preload());
715
+ return () => {
716
+ const Loaded = component();
717
+ return Loaded ? untrack(() => Loaded(props)) : null;
718
+ };
719
+ };
720
+ return Object.assign(Lazy, { preload });
721
+ }
722
+ export { $a, $abbr, $address, $area, $article, $aside, $audio, $b, $base, $bdi, $bdo, $blockquote, $body, $br, $button, $canvas, $caption, $catch, $cite, $code, $col, $colgroup, $data, $datalist, $dd, $del, $details, $dfn, $dialog, $div, $dl, $dt, $dynamic, $em, $embed, $fieldset, $figcaption, $figure, $footer, $for, $form, $h1, $h2, $h3, $h4, $h5, $h6, $head, $header, $hgroup, $hr, $html, $i, $if, $iframe, $img, $input, $ins, $kbd, $label, $legend, $li, $link, $main, $map, $mark, $menu, $meta, $meter, $nav, $noscript, $object, $ol, $optgroup, $option, $output, $p, $picture, $portal, $pre, $progress, $q, $rp, $rt, $ruby, $s, $samp, $script, $search, $section, $select, $show, $slot, $small, $source, $span, $strong, $style, $sub, $summary, $sup, $suspense, $switch, $table, $tbody, $td, $template, $textarea, $tfoot, $th, $thead, $time, $title, $tr, $track, $u, $ul, $var, $video, $wbr, batch, catchError, computed, createContext, createRoot, effect, getOwner, html, insert, isServer, isStaticRender, lazy, mount, onCleanup, onMount, provide, reconcile, renderStatic, resource, runWithOwner, signal, store, unsafeHTML, untrack, unwrap, useContext };