keits 0.0.1 → 0.0.2

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/dev/index.js CHANGED
@@ -1,293 +1,4 @@
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
- }
1
+ import { _ as runWithOwner$1, a as hooks, b as updateIfNeeded, c as addMount, d as dispose, f as getOwner$1, g as notify, h as isTracking, i as insert, l as adopt, m as isStaticRender, n as html, o as effect, p as handleError, s as addCleanup, u as batch, v as track, x as withStaticRender, y as untrack } from "./shared/element-By0uLZli.js";
291
2
  // src/core/signal.ts
292
3
  function signal(value, options) {
293
4
  const node = {
@@ -310,25 +21,6 @@ function signal(value, options) {
310
21
  };
311
22
  return Object.assign(read, { set });
312
23
  }
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
24
  // src/core/computed.ts
333
25
  function computed(fn, options) {
334
26
  const node = {
@@ -601,4 +293,143 @@ function matchAndUpdate(existing, next, key) {
601
293
  }
602
294
  return next;
603
295
  }
604
- export { batch, catchError, computed, createContext, createRoot, effect, getOwner, isServer, isStaticRender, onCleanup, onMount, provide, reconcile, renderStatic, runWithOwner, signal, store, untrack, unwrap, useContext };
296
+ // src/dom/tags.ts
297
+ var $a = /* @__PURE__ */ html("a");
298
+ var $abbr = /* @__PURE__ */ html("abbr");
299
+ var $address = /* @__PURE__ */ html("address");
300
+ var $area = /* @__PURE__ */ html("area");
301
+ var $article = /* @__PURE__ */ html("article");
302
+ var $aside = /* @__PURE__ */ html("aside");
303
+ var $audio = /* @__PURE__ */ html("audio");
304
+ var $b = /* @__PURE__ */ html("b");
305
+ var $base = /* @__PURE__ */ html("base");
306
+ var $bdi = /* @__PURE__ */ html("bdi");
307
+ var $bdo = /* @__PURE__ */ html("bdo");
308
+ var $blockquote = /* @__PURE__ */ html("blockquote");
309
+ var $body = /* @__PURE__ */ html("body");
310
+ var $br = /* @__PURE__ */ html("br");
311
+ var $button = /* @__PURE__ */ html("button");
312
+ var $canvas = /* @__PURE__ */ html("canvas");
313
+ var $caption = /* @__PURE__ */ html("caption");
314
+ var $cite = /* @__PURE__ */ html("cite");
315
+ var $code = /* @__PURE__ */ html("code");
316
+ var $col = /* @__PURE__ */ html("col");
317
+ var $colgroup = /* @__PURE__ */ html("colgroup");
318
+ var $data = /* @__PURE__ */ html("data");
319
+ var $datalist = /* @__PURE__ */ html("datalist");
320
+ var $dd = /* @__PURE__ */ html("dd");
321
+ var $del = /* @__PURE__ */ html("del");
322
+ var $details = /* @__PURE__ */ html("details");
323
+ var $dfn = /* @__PURE__ */ html("dfn");
324
+ var $dialog = /* @__PURE__ */ html("dialog");
325
+ var $div = /* @__PURE__ */ html("div");
326
+ var $dl = /* @__PURE__ */ html("dl");
327
+ var $dt = /* @__PURE__ */ html("dt");
328
+ var $em = /* @__PURE__ */ html("em");
329
+ var $embed = /* @__PURE__ */ html("embed");
330
+ var $fieldset = /* @__PURE__ */ html("fieldset");
331
+ var $figcaption = /* @__PURE__ */ html("figcaption");
332
+ var $figure = /* @__PURE__ */ html("figure");
333
+ var $footer = /* @__PURE__ */ html("footer");
334
+ var $form = /* @__PURE__ */ html("form");
335
+ var $h1 = /* @__PURE__ */ html("h1");
336
+ var $h2 = /* @__PURE__ */ html("h2");
337
+ var $h3 = /* @__PURE__ */ html("h3");
338
+ var $h4 = /* @__PURE__ */ html("h4");
339
+ var $h5 = /* @__PURE__ */ html("h5");
340
+ var $h6 = /* @__PURE__ */ html("h6");
341
+ var $head = /* @__PURE__ */ html("head");
342
+ var $header = /* @__PURE__ */ html("header");
343
+ var $hgroup = /* @__PURE__ */ html("hgroup");
344
+ var $hr = /* @__PURE__ */ html("hr");
345
+ var $html = /* @__PURE__ */ html("html");
346
+ var $i = /* @__PURE__ */ html("i");
347
+ var $iframe = /* @__PURE__ */ html("iframe");
348
+ var $img = /* @__PURE__ */ html("img");
349
+ var $input = /* @__PURE__ */ html("input");
350
+ var $ins = /* @__PURE__ */ html("ins");
351
+ var $kbd = /* @__PURE__ */ html("kbd");
352
+ var $label = /* @__PURE__ */ html("label");
353
+ var $legend = /* @__PURE__ */ html("legend");
354
+ var $li = /* @__PURE__ */ html("li");
355
+ var $link = /* @__PURE__ */ html("link");
356
+ var $main = /* @__PURE__ */ html("main");
357
+ var $map = /* @__PURE__ */ html("map");
358
+ var $mark = /* @__PURE__ */ html("mark");
359
+ var $menu = /* @__PURE__ */ html("menu");
360
+ var $meta = /* @__PURE__ */ html("meta");
361
+ var $meter = /* @__PURE__ */ html("meter");
362
+ var $nav = /* @__PURE__ */ html("nav");
363
+ var $noscript = /* @__PURE__ */ html("noscript");
364
+ var $object = /* @__PURE__ */ html("object");
365
+ var $ol = /* @__PURE__ */ html("ol");
366
+ var $optgroup = /* @__PURE__ */ html("optgroup");
367
+ var $option = /* @__PURE__ */ html("option");
368
+ var $output = /* @__PURE__ */ html("output");
369
+ var $p = /* @__PURE__ */ html("p");
370
+ var $picture = /* @__PURE__ */ html("picture");
371
+ var $pre = /* @__PURE__ */ html("pre");
372
+ var $progress = /* @__PURE__ */ html("progress");
373
+ var $q = /* @__PURE__ */ html("q");
374
+ var $rp = /* @__PURE__ */ html("rp");
375
+ var $rt = /* @__PURE__ */ html("rt");
376
+ var $ruby = /* @__PURE__ */ html("ruby");
377
+ var $s = /* @__PURE__ */ html("s");
378
+ var $samp = /* @__PURE__ */ html("samp");
379
+ var $script = /* @__PURE__ */ html("script");
380
+ var $search = /* @__PURE__ */ html("search");
381
+ var $section = /* @__PURE__ */ html("section");
382
+ var $select = /* @__PURE__ */ html("select");
383
+ var $slot = /* @__PURE__ */ html("slot");
384
+ var $small = /* @__PURE__ */ html("small");
385
+ var $source = /* @__PURE__ */ html("source");
386
+ var $span = /* @__PURE__ */ html("span");
387
+ var $strong = /* @__PURE__ */ html("strong");
388
+ var $style = /* @__PURE__ */ html("style");
389
+ var $sub = /* @__PURE__ */ html("sub");
390
+ var $summary = /* @__PURE__ */ html("summary");
391
+ var $sup = /* @__PURE__ */ html("sup");
392
+ var $table = /* @__PURE__ */ html("table");
393
+ var $tbody = /* @__PURE__ */ html("tbody");
394
+ var $td = /* @__PURE__ */ html("td");
395
+ var $template = /* @__PURE__ */ html("template");
396
+ var $textarea = /* @__PURE__ */ html("textarea");
397
+ var $tfoot = /* @__PURE__ */ html("tfoot");
398
+ var $th = /* @__PURE__ */ html("th");
399
+ var $thead = /* @__PURE__ */ html("thead");
400
+ var $time = /* @__PURE__ */ html("time");
401
+ var $title = /* @__PURE__ */ html("title");
402
+ var $tr = /* @__PURE__ */ html("tr");
403
+ var $track = /* @__PURE__ */ html("track");
404
+ var $u = /* @__PURE__ */ html("u");
405
+ var $ul = /* @__PURE__ */ html("ul");
406
+ var $var = /* @__PURE__ */ html("var");
407
+ var $video = /* @__PURE__ */ html("video");
408
+ var $wbr = /* @__PURE__ */ html("wbr");
409
+ // src/dom/mount.ts
410
+ function mount(app, target) {
411
+ if (target === null) throw new Error("[keits] mount(): the target element was not found (null).");
412
+ const start = hooks.marker();
413
+ const end = hooks.marker();
414
+ target.append(start, end);
415
+ const dispose = createRoot((dispose) => {
416
+ insert(target, app(), end);
417
+ return dispose;
418
+ });
419
+ return () => {
420
+ dispose();
421
+ let node = start;
422
+ while (node !== null) {
423
+ const next = node === end ? null : node.nextSibling;
424
+ node.remove();
425
+ node = next;
426
+ }
427
+ };
428
+ }
429
+ // src/dom/unsafe.ts
430
+ function unsafeHTML(markup) {
431
+ const template = document.createElement("template");
432
+ template.innerHTML = markup;
433
+ return template.content;
434
+ }
435
+ export { $a, $abbr, $address, $area, $article, $aside, $audio, $b, $base, $bdi, $bdo, $blockquote, $body, $br, $button, $canvas, $caption, $cite, $code, $col, $colgroup, $data, $datalist, $dd, $del, $details, $dfn, $dialog, $div, $dl, $dt, $em, $embed, $fieldset, $figcaption, $figure, $footer, $form, $h1, $h2, $h3, $h4, $h5, $h6, $head, $header, $hgroup, $hr, $html, $i, $iframe, $img, $input, $ins, $kbd, $label, $legend, $li, $link, $main, $map, $mark, $menu, $meta, $meter, $nav, $noscript, $object, $ol, $optgroup, $option, $output, $p, $picture, $pre, $progress, $q, $rp, $rt, $ruby, $s, $samp, $script, $search, $section, $select, $slot, $small, $source, $span, $strong, $style, $sub, $summary, $sup, $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, mount, onCleanup, onMount, provide, reconcile, renderStatic, runWithOwner, signal, store, unsafeHTML, untrack, unwrap, useContext };