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
@@ -0,0 +1,324 @@
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
+ queueMount(currentOwner, fn);
240
+ }
241
+ function queueMount(owner, fn) {
242
+ for (let o = owner; o !== null; o = o.owner) if (o.kind === 3 && o.held) {
243
+ o.held.push({
244
+ owner,
245
+ fn
246
+ });
247
+ return;
248
+ }
249
+ mounts.push({
250
+ owner,
251
+ fn
252
+ });
253
+ }
254
+ function deferMounts(fn) {
255
+ const holder = {
256
+ kind: 3,
257
+ owner: null,
258
+ children: null,
259
+ cleanups: null,
260
+ disposed: false,
261
+ handler: null,
262
+ held: []
263
+ };
264
+ adopt(holder);
265
+ const result = runWithOwner(holder, fn);
266
+ const release = () => {
267
+ const list = holder.held;
268
+ if (!list) return;
269
+ holder.held = null;
270
+ for (const { owner, fn } of list) queueMount(owner, fn);
271
+ };
272
+ return {
273
+ result,
274
+ release
275
+ };
276
+ }
277
+ function cleanNode(node) {
278
+ const children = node.children;
279
+ const cleanups = node.cleanups;
280
+ node.children = null;
281
+ node.cleanups = null;
282
+ if (children !== null) for (let i = children.length - 1; i >= 0; i--) dispose(children[i]);
283
+ if (cleanups !== null) for (let i = cleanups.length - 1; i >= 0; i--) try {
284
+ cleanups[i]();
285
+ } catch (error) {
286
+ handleError(error, node);
287
+ }
288
+ }
289
+ function dispose(node) {
290
+ if (node.disposed) return;
291
+ node.disposed = true;
292
+ if (node.kind !== 3) {
293
+ for (const source of node.sources) unlink(source, node);
294
+ node.sources.length = 0;
295
+ node.state = 0;
296
+ }
297
+ cleanNode(node);
298
+ }
299
+ function handleError(error, owner) {
300
+ for (let o = owner; o !== null; o = o.owner) {
301
+ if (o.kind !== 3 || o.handler === null || o.disposed) continue;
302
+ const handler = o.handler;
303
+ try {
304
+ runWithOwner(o.owner, () => handler(error));
305
+ return;
306
+ } catch (handlerError) {
307
+ error = handlerError;
308
+ }
309
+ }
310
+ if (batchDepth === 0) throw error;
311
+ unhandledErrors.push(error);
312
+ }
313
+ function isStaticRender() {
314
+ return staticDepth > 0;
315
+ }
316
+ function withStaticRender(fn) {
317
+ staticDepth++;
318
+ try {
319
+ return fn();
320
+ } finally {
321
+ staticDepth--;
322
+ }
323
+ }
324
+ export { withStaticRender as _, deferMounts as a, handleError as c, notify as d, runEffect as f, updateIfNeeded as g, untrack as h, batch as i, isStaticRender as l, track as m, addMount as n, dispose as o, runWithOwner as p, adopt as r, getOwner as s, addCleanup as t, isTracking as u };
@@ -0,0 +1,62 @@
1
+ import { _ as withStaticRender, c as handleError, i as batch, n as addMount, o as dispose, p as runWithOwner$1, r as adopt, s as getOwner$1, t as addCleanup } from "./graph-D6-x_CWC.js";
2
+ // src/core/owner.ts
3
+ function getOwner() {
4
+ return getOwner$1();
5
+ }
6
+ function runWithOwner(owner, fn) {
7
+ return runWithOwner$1(owner, fn);
8
+ }
9
+ function createRoot(fn) {
10
+ const root = {
11
+ kind: 3,
12
+ owner: getOwner$1(),
13
+ children: null,
14
+ cleanups: null,
15
+ disposed: false,
16
+ handler: null
17
+ };
18
+ const disposeRoot = () => batch(() => dispose(root));
19
+ return batch(() => {
20
+ try {
21
+ return runWithOwner$1(root, () => fn(disposeRoot));
22
+ } catch (error) {
23
+ dispose(root);
24
+ throw error;
25
+ }
26
+ });
27
+ }
28
+ function onCleanup(fn) {
29
+ if (!addCleanup(fn) && true) console.warn("[keits] onCleanup was called outside an owner, so it will never run.");
30
+ }
31
+ function onMount(fn) {
32
+ addMount(fn);
33
+ }
34
+ function catchError(fn, handler) {
35
+ const boundary = {
36
+ kind: 3,
37
+ owner: null,
38
+ children: null,
39
+ cleanups: null,
40
+ disposed: false,
41
+ handler
42
+ };
43
+ adopt(boundary);
44
+ return batch(() => {
45
+ try {
46
+ return runWithOwner$1(boundary, fn);
47
+ } catch (error) {
48
+ handleError(error, boundary);
49
+ return;
50
+ }
51
+ });
52
+ }
53
+ function renderStatic(fn) {
54
+ return withStaticRender(() => createRoot((dispose) => {
55
+ try {
56
+ return fn();
57
+ } finally {
58
+ dispose();
59
+ }
60
+ }));
61
+ }
62
+ export { onMount as a, onCleanup as i, createRoot as n, renderStatic as o, getOwner as r, runWithOwner as s, catchError as t };
@@ -0,0 +1,26 @@
1
+ import { f as runEffect, i as batch, l as isStaticRender, r as adopt } from "./graph-D6-x_CWC.js";
2
+ // src/core/effect.ts
3
+ function effect(fn, options) {
4
+ if (isStaticRender()) return;
5
+ const node = {
6
+ kind: 1,
7
+ fn,
8
+ state: 0,
9
+ sources: [],
10
+ flushId: 0,
11
+ flushRuns: 0,
12
+ owner: null,
13
+ children: null,
14
+ cleanups: null,
15
+ disposed: false
16
+ };
17
+ if (options?.name !== void 0) node.name = options.name;
18
+ adopt(node);
19
+ batch(() => runEffect(node));
20
+ }
21
+ // src/dom/render-effect.ts
22
+ function renderEffect(fn) {
23
+ if (isStaticRender()) fn();
24
+ else effect(fn);
25
+ }
26
+ export { effect as n, renderEffect as t };
@@ -0,0 +1,154 @@
1
+ import { c as handleError, h as untrack, i as batch, p as runWithOwner, r as adopt, s as getOwner, t as addCleanup } from "./graph-D6-x_CWC.js";
2
+ import { t as signal } from "./signal-BOXkY-Iv.js";
3
+ import { t as renderEffect } from "./render-effect-kOGnLNbL.js";
4
+ // src/core/context.ts
5
+ function createContext(defaultValue, options) {
6
+ const context = { defaultValue };
7
+ if (options?.name !== void 0) context.name = options.name;
8
+ return context;
9
+ }
10
+ function provide(context, value, fn) {
11
+ const provider = {
12
+ kind: 3,
13
+ owner: null,
14
+ children: null,
15
+ cleanups: null,
16
+ disposed: false,
17
+ handler: null,
18
+ context: {
19
+ key: context,
20
+ value
21
+ }
22
+ };
23
+ adopt(provider);
24
+ return runWithOwner(provider, fn);
25
+ }
26
+ function useContext(context) {
27
+ for (let o = getOwner(); o !== null; o = o.owner) if (o.kind === 3 && o.context?.key === context) return o.context.value;
28
+ return context.defaultValue;
29
+ }
30
+ // src/async/suspense-context.ts
31
+ var SuspenseContext = createContext(null);
32
+ // src/async/resource.ts
33
+ function resource(first, second, third) {
34
+ const hasSource = typeof second === "function";
35
+ const source = hasSource ? first : () => true;
36
+ const fetcher = hasSource ? second : (_, info) => first(info);
37
+ const options = hasSource ? third : second;
38
+ const owner = getOwner();
39
+ const hasInitial = options !== void 0 && "initialValue" in options;
40
+ const value = signal(options?.initialValue);
41
+ const state = signal(hasInitial ? "ready" : "unresolved");
42
+ const failure = signal(null);
43
+ let controller = null;
44
+ let version = 0;
45
+ let waiters = [];
46
+ let currentSource = null;
47
+ const settleWaiters = () => {
48
+ const list = waiters;
49
+ waiters = [];
50
+ for (const done of list) done();
51
+ };
52
+ function load(src, refetching) {
53
+ controller?.abort();
54
+ controller = null;
55
+ const id = ++version;
56
+ if (src === null || src === void 0 || src === false) {
57
+ currentSource = null;
58
+ state.set(untrack(value) === void 0 ? "unresolved" : "ready");
59
+ settleWaiters();
60
+ return Promise.resolve();
61
+ }
62
+ currentSource = src;
63
+ const abort = new AbortController();
64
+ controller = abort;
65
+ let result;
66
+ try {
67
+ result = fetcher(src, {
68
+ signal: abort.signal,
69
+ refetching,
70
+ value: untrack(value)
71
+ });
72
+ } catch (error) {
73
+ fail(error);
74
+ return Promise.resolve();
75
+ }
76
+ if (!isPromiseLike(result)) {
77
+ succeed(result);
78
+ return Promise.resolve();
79
+ }
80
+ state.set(untrack(value) === void 0 && untrack(state) !== "ready" ? "pending" : "refreshing");
81
+ return Promise.resolve(result).then((data) => {
82
+ if (id === version) succeed(data);
83
+ }, (error) => {
84
+ if (id === version) fail(error);
85
+ });
86
+ }
87
+ function succeed(data) {
88
+ controller = null;
89
+ batch(() => {
90
+ value.set(() => data);
91
+ failure.set(null);
92
+ state.set("ready");
93
+ });
94
+ settleWaiters();
95
+ }
96
+ function fail(error) {
97
+ controller = null;
98
+ batch(() => {
99
+ failure.set({ error });
100
+ state.set("errored");
101
+ });
102
+ settleWaiters();
103
+ }
104
+ renderEffect(() => {
105
+ const src = source();
106
+ untrack(() => load(src, false));
107
+ });
108
+ addCleanup(() => {
109
+ version++;
110
+ controller?.abort();
111
+ controller = null;
112
+ });
113
+ const read = () => {
114
+ const current = state();
115
+ if (current === "errored") throw failure().error;
116
+ if (current === "pending") {
117
+ const boundary = useContext(SuspenseContext);
118
+ if (boundary !== null) boundary.wait(resourceApi, (done) => waiters.push(done));
119
+ }
120
+ return value();
121
+ };
122
+ const resourceApi = Object.assign(read, {
123
+ state: () => state(),
124
+ loading: () => {
125
+ const current = state();
126
+ return current === "pending" || current === "refreshing";
127
+ },
128
+ error: () => failure()?.error,
129
+ refetch: () => untrack(() => load(currentSource ?? source(), true)),
130
+ mutate: (next) => batch(() => {
131
+ value.set(() => next);
132
+ failure.set(null);
133
+ state.set(next === void 0 ? "unresolved" : "ready");
134
+ }),
135
+ optimistic: async (update, action) => {
136
+ const previous = untrack(value);
137
+ const next = update(previous);
138
+ value.set(() => next);
139
+ try {
140
+ await action();
141
+ return true;
142
+ } catch (error) {
143
+ if (untrack(value) === next) value.set(() => previous);
144
+ batch(() => handleError(error, owner));
145
+ return false;
146
+ }
147
+ }
148
+ });
149
+ return resourceApi;
150
+ }
151
+ function isPromiseLike(value) {
152
+ return typeof value?.then === "function";
153
+ }
154
+ export { useContext as a, provide as i, SuspenseContext as n, createContext as r, resource as t };
@@ -0,0 +1,24 @@
1
+ import { d as notify, m as track } from "./graph-D6-x_CWC.js";
2
+ // src/core/signal.ts
3
+ function signal(value, options) {
4
+ const node = {
5
+ kind: 0,
6
+ value,
7
+ equals: options?.equals ?? Object.is,
8
+ observers: [],
9
+ seenBy: 0
10
+ };
11
+ if (options?.name !== void 0) node.name = options.name;
12
+ const read = () => {
13
+ track(node);
14
+ return node.value;
15
+ };
16
+ const set = (next) => {
17
+ const value = typeof next === "function" ? next(node.value) : next;
18
+ if (node.equals !== false && node.equals(node.value, value)) return;
19
+ node.value = value;
20
+ notify(node);
21
+ };
22
+ return Object.assign(read, { set });
23
+ }
24
+ export { signal as t };