keits 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/dev/api.js +270 -0
  2. package/dist/dev/forms.js +328 -0
  3. package/dist/dev/index.js +290 -294
  4. package/dist/dev/router.js +445 -0
  5. package/dist/dev/shared/computed-3UO-KiH1.js +40 -0
  6. package/dist/dev/shared/element-CQPqagu1.js +222 -0
  7. package/dist/dev/shared/graph-D6-x_CWC.js +324 -0
  8. package/dist/dev/shared/owner-Dmge21OW.js +62 -0
  9. package/dist/dev/shared/render-effect-kOGnLNbL.js +26 -0
  10. package/dist/dev/shared/resource-CbXVATvq.js +154 -0
  11. package/dist/dev/shared/signal-BOXkY-Iv.js +24 -0
  12. package/dist/dev/shared/store-BzUN1qE5.js +148 -0
  13. package/dist/dev/svg.js +1 -1
  14. package/dist/prod/api.js +210 -0
  15. package/dist/prod/forms.js +237 -0
  16. package/dist/prod/index.js +209 -234
  17. package/dist/prod/router.js +345 -0
  18. package/dist/prod/shared/computed-CAPpOLCY.js +33 -0
  19. package/dist/prod/shared/element-DGyQ01Vs.js +164 -0
  20. package/dist/prod/shared/graph-C_aA46c6.js +240 -0
  21. package/dist/prod/shared/owner-6BFHIPR9.js +59 -0
  22. package/dist/prod/shared/render-effect-DjaUT3Cn.js +23 -0
  23. package/dist/prod/shared/resource-CNC2DBO3.js +109 -0
  24. package/dist/prod/shared/signal-DGrl3r9T.js +16 -0
  25. package/dist/prod/shared/store-Dcscpk_h.js +109 -0
  26. package/dist/prod/svg.js +1 -1
  27. package/dist/types/api/cache.d.ts +16 -0
  28. package/dist/types/api/client.d.ts +42 -0
  29. package/dist/types/api/error.d.ts +16 -0
  30. package/dist/types/api/index.d.ts +3 -0
  31. package/dist/types/api/url.d.ts +5 -0
  32. package/dist/types/async/index.d.ts +2 -0
  33. package/dist/types/async/lazy.d.ts +7 -0
  34. package/dist/types/async/resource.d.ts +23 -0
  35. package/dist/types/async/suspense-context.d.ts +4 -0
  36. package/dist/types/core/graph.d.ts +8 -0
  37. package/dist/types/dom/types.d.ts +1 -1
  38. package/dist/types/flow/catch.d.ts +2 -0
  39. package/dist/types/flow/dynamic.d.ts +6 -0
  40. package/dist/types/flow/for.d.ts +7 -0
  41. package/dist/types/flow/if.d.ts +4 -0
  42. package/dist/types/flow/index.d.ts +8 -0
  43. package/dist/types/flow/portal.d.ts +2 -0
  44. package/dist/types/flow/range.d.ts +11 -0
  45. package/dist/types/flow/show.d.ts +1 -0
  46. package/dist/types/flow/suspense.d.ts +2 -0
  47. package/dist/types/flow/switch.d.ts +9 -0
  48. package/dist/types/forms/form.d.ts +55 -0
  49. package/dist/types/forms/index.d.ts +2 -0
  50. package/dist/types/forms/paths.d.ts +6 -0
  51. package/dist/types/forms/types.d.ts +38 -0
  52. package/dist/types/index.d.ts +2 -0
  53. package/dist/types/router/history.d.ts +21 -0
  54. package/dist/types/router/index.d.ts +3 -0
  55. package/dist/types/router/links.d.ts +1 -0
  56. package/dist/types/router/match.d.ts +15 -0
  57. package/dist/types/router/router.d.ts +10 -0
  58. package/dist/types/router/scroll.d.ts +5 -0
  59. package/dist/types/router/types.d.ts +87 -0
  60. package/dist/types/svg/types.d.ts +1 -1
  61. package/package.json +37 -6
  62. package/dist/dev/shared/element-By0uLZli.js +0 -544
  63. package/dist/prod/shared/element-C8c5hIhH.js +0 -394
@@ -1,544 +0,0 @@
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(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() {
218
- return currentOwner;
219
- }
220
- function runWithOwner(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(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/effect.ts
292
- function effect(fn, options) {
293
- if (isStaticRender()) return;
294
- const node = {
295
- kind: 1,
296
- fn,
297
- state: 0,
298
- sources: [],
299
- flushId: 0,
300
- flushRuns: 0,
301
- owner: null,
302
- children: null,
303
- cleanups: null,
304
- disposed: false
305
- };
306
- if (options?.name !== void 0) node.name = options.name;
307
- adopt(node);
308
- batch(() => runEffect(node));
309
- }
310
- var hooks = {
311
- element: (tag, namespace) => namespace === null ? document.createElement(tag) : document.createElementNS(namespace, tag),
312
- text: (value) => document.createTextNode(value),
313
- marker: () => document.createComment("")
314
- };
315
- // src/dom/render-effect.ts
316
- function renderEffect(fn) {
317
- if (isStaticRender()) fn();
318
- else effect(fn);
319
- }
320
- // src/dom/insert.ts
321
- function insert(parent, child, before = null) {
322
- if (child === null || child === void 0 || typeof child === "boolean") return;
323
- if (typeof child === "function") return insertDynamic(parent, child, before);
324
- if (isChildArray(child)) {
325
- for (const item of child) insert(parent, item, before);
326
- return;
327
- }
328
- if (typeof child === "object") {
329
- parent.insertBefore(child, before);
330
- return;
331
- }
332
- parent.insertBefore(hooks.text(String(child)), before);
333
- }
334
- function isChildArray(value) {
335
- return Array.isArray(value);
336
- }
337
- function isTextValue(value) {
338
- return value === null || typeof value !== "object" && typeof value !== "function";
339
- }
340
- function toText(value) {
341
- return value === null || value === void 0 || typeof value === "boolean" ? "" : String(value);
342
- }
343
- function insertDynamic(parent, fn, before) {
344
- const text = hooks.text("");
345
- parent.insertBefore(text, before);
346
- let start = null;
347
- let end = null;
348
- renderEffect(() => {
349
- const value = fn();
350
- if (start === null || end === null) {
351
- if (isTextValue(value)) {
352
- const next = toText(value);
353
- if (text.data !== next) text.data = next;
354
- return;
355
- }
356
- start = hooks.marker();
357
- end = hooks.marker();
358
- text.before(start);
359
- text.after(end);
360
- text.remove();
361
- }
362
- clearRange(start, end);
363
- insert(end.parentNode, value, end);
364
- });
365
- }
366
- function clearRange(start, end) {
367
- let node = start.nextSibling;
368
- while (node !== null && node !== end) {
369
- const next = node.nextSibling;
370
- node.remove();
371
- node = next;
372
- }
373
- }
374
- // src/dom/events.ts
375
- function applyEvent(element, key, value) {
376
- let handler = value;
377
- let options;
378
- if (Array.isArray(value)) [handler, options] = value;
379
- if (typeof handler !== "function") throw new Error(`[keits] "${key}" must be a function, not a ${typeof handler}.`);
380
- if (isStaticRender()) return;
381
- listen(element, key.slice(2), handler, options);
382
- }
383
- function listen(element, type, handler, options) {
384
- const owner = getOwner();
385
- element.addEventListener(type, (event) => {
386
- batch(() => {
387
- try {
388
- const result = runWithOwner(owner, () => handler(event));
389
- if (isPromiseLike(result)) result.then(void 0, (error) => batch(() => handleError(error, owner)));
390
- } catch (error) {
391
- handleError(error, owner);
392
- }
393
- });
394
- }, options);
395
- }
396
- function isPromiseLike(value) {
397
- return typeof value?.then === "function";
398
- }
399
- // src/dom/namespaces.ts
400
- var SVG_NS = "http://www.w3.org/2000/svg";
401
- // src/dom/props.ts
402
- var UNSAFE_PROPS = /* @__PURE__ */ new Set([
403
- "innerHTML",
404
- "outerHTML",
405
- "srcdoc"
406
- ]);
407
- var URL_PROPS = /* @__PURE__ */ new Set([
408
- "href",
409
- "src",
410
- "action",
411
- "formAction",
412
- "formaction",
413
- "poster",
414
- "cite",
415
- "data",
416
- "xlink:href"
417
- ]);
418
- var BLOCKED_URL = "about:invalid#keits-blocked";
419
- function applyProps(element, props) {
420
- for (const key in props) {
421
- const value = props[key];
422
- if (key === "ref") continue;
423
- if (key === "class") applyClass(element, value);
424
- else if (key === "style") applyStyle(element, value);
425
- else if (key.startsWith("on")) applyEvent(element, key, value);
426
- else if (typeof value === "function") renderEffect(() => setProp(element, key, value()));
427
- else setProp(element, key, value);
428
- }
429
- }
430
- function setProp(element, key, value) {
431
- if (UNSAFE_PROPS.has(key)) throw new Error(`[keits] "${key}" is not allowed as a prop: it would allow HTML injection.`);
432
- if (URL_PROPS.has(key) && typeof value === "string" && isJavaScriptUrl(value)) {
433
- console.warn(`[keits] Blocked a javascript: URL in "${key}".`);
434
- value = BLOCKED_URL;
435
- }
436
- if (key in element && element.namespaceURI !== "http://www.w3.org/2000/svg") {
437
- element[key] = value;
438
- if (isStaticRender()) reflectForStatic(element, key, value);
439
- } else if (value === null || value === void 0 || value === false) element.removeAttribute(key);
440
- else element.setAttribute(key, value === true ? "" : String(value));
441
- }
442
- function isJavaScriptUrl(url) {
443
- return url.replace(/[\u0000-\u0020]/g, "").toLowerCase().startsWith("javascript");
444
- }
445
- function reflectForStatic(element, key, value) {
446
- if (key === "value") {
447
- if (element.localName === "textarea") element.textContent = value == null ? "" : String(value);
448
- else if (value == null) element.removeAttribute("value");
449
- else element.setAttribute("value", String(value));
450
- } else if (key === "checked" || key === "selected") element.toggleAttribute(key, value === true);
451
- }
452
- function applyClass(element, value) {
453
- if (typeof value === "function") {
454
- renderEffect(() => writeClass(element, toClassString(value())));
455
- return;
456
- }
457
- const fixed = [];
458
- collectClasses(value, fixed, (name, on) => {
459
- renderEffect(() => element.classList.toggle(name, on()));
460
- });
461
- if (fixed.length > 0) element.classList.add(...fixed);
462
- }
463
- function writeClass(element, className) {
464
- if (className === "") element.removeAttribute("class");
465
- else element.setAttribute("class", className);
466
- }
467
- function collectClasses(value, out, onReactive) {
468
- if (!value) return;
469
- if (typeof value === "string") {
470
- for (const name of value.split(/\s+/)) if (name) out.push(name);
471
- } else if (Array.isArray(value)) for (const item of value) collectClasses(item, out, onReactive);
472
- else for (const [name, on] of Object.entries(value)) if (typeof on === "function") {
473
- if (onReactive) onReactive(name, on);
474
- else if (on()) out.push(name);
475
- } else if (on) out.push(name);
476
- }
477
- function toClassString(value) {
478
- const names = [];
479
- collectClasses(value, names);
480
- return names.join(" ");
481
- }
482
- function applyStyle(element, value) {
483
- const style = element.style;
484
- if (typeof value === "function") {
485
- let previous = [];
486
- renderEffect(() => {
487
- const next = value();
488
- if (typeof next === "string" || next == null) {
489
- style.cssText = next ?? "";
490
- previous = [];
491
- return;
492
- }
493
- const keys = Object.keys(next);
494
- for (const name of previous) if (!(name in next)) style.removeProperty(name);
495
- for (const name of keys) writeStyle(style, name, readStyle(next[name]));
496
- previous = keys;
497
- });
498
- return;
499
- }
500
- if (typeof value === "string") {
501
- style.cssText = value;
502
- return;
503
- }
504
- if (value == null) return;
505
- for (const [name, entry] of Object.entries(value)) if (typeof entry === "function") renderEffect(() => writeStyle(style, name, entry()));
506
- else writeStyle(style, name, entry);
507
- }
508
- function readStyle(entry) {
509
- return typeof entry === "function" ? entry() : entry;
510
- }
511
- function writeStyle(style, name, value) {
512
- if (value === null || value === void 0 || value === "") style.removeProperty(name);
513
- else style.setProperty(name, String(value));
514
- }
515
- // src/dom/element.ts
516
- function html(tag) {
517
- const factory = (first, children) => {
518
- const element = hooks.element(tag, null);
519
- if (isProps(first)) {
520
- applyProps(element, first);
521
- insert(element, children);
522
- if (typeof first.ref === "function") first.ref(element);
523
- } else if (first === null || first === void 0) insert(element, children);
524
- else insert(element, first);
525
- return element;
526
- };
527
- return factory;
528
- }
529
- function createFactory(tag, namespace) {
530
- return (first, children) => {
531
- const element = hooks.element(tag, namespace);
532
- if (isProps(first)) {
533
- applyProps(element, first);
534
- insert(element, children);
535
- if (typeof first.ref === "function") first.ref(element);
536
- } else if (first === null || first === void 0) insert(element, children);
537
- else insert(element, first);
538
- return element;
539
- };
540
- }
541
- function isProps(value) {
542
- return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.nodeType !== "number";
543
- }
544
- export { runWithOwner as _, hooks as a, updateIfNeeded as b, addMount as c, dispose as d, getOwner as f, notify as g, isTracking as h, insert as i, adopt as l, isStaticRender as m, html as n, effect as o, handleError as p, SVG_NS as r, addCleanup as s, createFactory as t, batch as u, track as v, withStaticRender as x, untrack as y };