keits 0.0.2 → 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 (39) hide show
  1. package/dist/dev/index.js +409 -122
  2. package/dist/dev/router.js +443 -0
  3. package/dist/dev/shared/{element-By0uLZli.js → element-C4DfKtZW.js} +2 -291
  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 +1 -1
  7. package/dist/prod/index.js +350 -166
  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 +1 -1
  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/types.d.ts +1 -1
  19. package/dist/types/flow/catch.d.ts +2 -0
  20. package/dist/types/flow/dynamic.d.ts +6 -0
  21. package/dist/types/flow/for.d.ts +7 -0
  22. package/dist/types/flow/if.d.ts +4 -0
  23. package/dist/types/flow/index.d.ts +8 -0
  24. package/dist/types/flow/portal.d.ts +2 -0
  25. package/dist/types/flow/range.d.ts +11 -0
  26. package/dist/types/flow/show.d.ts +1 -0
  27. package/dist/types/flow/suspense.d.ts +2 -0
  28. package/dist/types/flow/switch.d.ts +9 -0
  29. package/dist/types/index.d.ts +2 -0
  30. package/dist/types/router/history.d.ts +21 -0
  31. package/dist/types/router/index.d.ts +3 -0
  32. package/dist/types/router/links.d.ts +1 -0
  33. package/dist/types/router/match.d.ts +15 -0
  34. package/dist/types/router/router.d.ts +10 -0
  35. package/dist/types/router/scroll.d.ts +5 -0
  36. package/dist/types/router/types.d.ts +87 -0
  37. package/dist/types/svg/types.d.ts +1 -1
  38. package/package.json +23 -6
  39. package/dist/prod/shared/element-C8c5hIhH.js +0 -394
@@ -0,0 +1,240 @@
1
+ var e = null, t = null, n = 0, r = 0, i = null, a = 0, o = 0, s = 0, c = [], l = [], u = [], d = 0;
2
+ function f(t) {
3
+ let r = e;
4
+ r !== null && t.seenBy !== n && (t.seenBy = n, i === null && r.sources[a] === t ? a++ : ((i ??= []).push(t), t.observers.push(r)));
5
+ }
6
+ function p() {
7
+ return e !== null;
8
+ }
9
+ function m(e) {
10
+ if (e.observers.length !== 0) {
11
+ o++;
12
+ try {
13
+ for (let t of e.observers) h(t, 2);
14
+ } finally {
15
+ C();
16
+ }
17
+ }
18
+ }
19
+ function h(e, t) {
20
+ if (e.state >= t) return;
21
+ let n = e.state === 0;
22
+ if (e.state = t, n) {
23
+ if (e.kind === 1) c.push(e);
24
+ else for (let t of e.observers) h(t, 1);
25
+ }
26
+ }
27
+ function g(e) {
28
+ if (e.state === 1) {
29
+ for (let t of e.sources) if (t.kind === 2 && (g(t), e.state === 2)) break;
30
+ }
31
+ e.state === 2 ? e.kind === 1 ? v(e) : _(e) : e.state = 0;
32
+ }
33
+ function _(e) {
34
+ let t;
35
+ e.computing = !0;
36
+ try {
37
+ let n = y(e, () => e.fn(e.value));
38
+ t = !e.hasValue || e.hasError || e.equals === !1 || !e.equals(e.value, n), t && (e.value = n), e.hasValue = !0, e.hasError = !1, e.error = void 0;
39
+ } catch (n) {
40
+ t = !0, e.hasError = !0, e.error = n;
41
+ } finally {
42
+ e.computing = !1;
43
+ }
44
+ if (t) for (let t of e.observers) t.state === 1 && (t.state = 2);
45
+ }
46
+ function v(e) {
47
+ try {
48
+ y(e, e.fn);
49
+ } catch (t) {
50
+ z(t, e);
51
+ }
52
+ }
53
+ function y(o, s) {
54
+ L(o);
55
+ let c = e, l = t, u = n, d = i, f = a;
56
+ e = o, t = o, n = ++r, i = null, a = 0, o.state = 0;
57
+ try {
58
+ return s();
59
+ } finally {
60
+ b(o, i, a), e = c, t = l, n = u, i = d, a = f;
61
+ }
62
+ }
63
+ function b(e, t, n) {
64
+ if (e.disposed) {
65
+ if (t !== null) for (let n of t) x(n, e);
66
+ return;
67
+ }
68
+ let r = e.sources;
69
+ for (let t = n; t < r.length; t++) x(r[t], e);
70
+ if (r.length = n, t !== null) for (let e of t) r.push(e);
71
+ }
72
+ function x(e, t) {
73
+ let n = e.observers, r = n.lastIndexOf(t);
74
+ r !== -1 && (n[r] = n[n.length - 1], n.pop());
75
+ }
76
+ function S(e) {
77
+ o++;
78
+ try {
79
+ return e();
80
+ } finally {
81
+ C();
82
+ }
83
+ }
84
+ function C() {
85
+ --o === 0 && w();
86
+ }
87
+ function w() {
88
+ do
89
+ E(), l.length > 0 && T();
90
+ while (c.length > 0 || l.length > 0);
91
+ if (u.length > 0) {
92
+ let e = u.splice(0);
93
+ throw e.length === 1 ? e[0] : AggregateError(e, "[keits] multiple unhandled errors");
94
+ }
95
+ }
96
+ function T() {
97
+ o++;
98
+ let e = l.splice(0);
99
+ try {
100
+ for (let { owner: t, fn: n } of e) if (!t?.disposed) try {
101
+ M(t, n);
102
+ } catch (e) {
103
+ z(e, t);
104
+ }
105
+ } finally {
106
+ o--;
107
+ }
108
+ }
109
+ function E() {
110
+ o++;
111
+ let e = ++s, t = !1;
112
+ try {
113
+ for (let t = 0; t < c.length; t++) {
114
+ let n = c[t];
115
+ n.state !== 0 && (n.flushId !== e && (n.flushId = e, n.flushRuns = 0), ++n.flushRuns > 100 ? (n.state = 0, z(O(n), n)) : D(n));
116
+ }
117
+ t = !0;
118
+ } finally {
119
+ if (!t) for (let e of c) e.state = 0;
120
+ c.length = 0, o--;
121
+ }
122
+ }
123
+ function D(e) {
124
+ let t = [];
125
+ for (let n = e.owner; n !== null; n = n.owner) n.kind !== 3 && n.state !== 0 && t.push(n);
126
+ for (let e = t.length - 1; e >= 0; e--) g(t[e]);
127
+ g(e);
128
+ }
129
+ function O(e) {
130
+ return /* @__PURE__ */ Error("[keits] infinite update loop");
131
+ }
132
+ function k(t) {
133
+ let n = e;
134
+ e = null;
135
+ try {
136
+ return t();
137
+ } finally {
138
+ e = n;
139
+ }
140
+ }
141
+ function A(e) {
142
+ let n = t;
143
+ e.owner = n, n !== null && (n.children ??= []).push(e);
144
+ }
145
+ function j() {
146
+ return t;
147
+ }
148
+ function M(n, r) {
149
+ let i = t, a = e;
150
+ t = n, e = null;
151
+ try {
152
+ return r();
153
+ } finally {
154
+ t = i, e = a;
155
+ }
156
+ }
157
+ function N(e) {
158
+ return t !== null && ((t.cleanups ??= []).push(e), !0);
159
+ }
160
+ function P(e) {
161
+ d > 0 || F(t, e);
162
+ }
163
+ function F(e, t) {
164
+ for (let n = e; n !== null; n = n.owner) if (n.kind === 3 && n.held) {
165
+ n.held.push({
166
+ owner: e,
167
+ fn: t
168
+ });
169
+ return;
170
+ }
171
+ l.push({
172
+ owner: e,
173
+ fn: t
174
+ });
175
+ }
176
+ function I(e) {
177
+ let t = {
178
+ kind: 3,
179
+ owner: null,
180
+ children: null,
181
+ cleanups: null,
182
+ disposed: !1,
183
+ handler: null,
184
+ held: []
185
+ };
186
+ return A(t), {
187
+ result: M(t, e),
188
+ release: () => {
189
+ let e = t.held;
190
+ if (e) {
191
+ t.held = null;
192
+ for (let { owner: t, fn: n } of e) F(t, n);
193
+ }
194
+ }
195
+ };
196
+ }
197
+ function L(e) {
198
+ let t = e.children, n = e.cleanups;
199
+ if (e.children = null, e.cleanups = null, t !== null) for (let e = t.length - 1; e >= 0; e--) R(t[e]);
200
+ if (n !== null) for (let t = n.length - 1; t >= 0; t--) try {
201
+ n[t]();
202
+ } catch (t) {
203
+ z(t, e);
204
+ }
205
+ }
206
+ function R(e) {
207
+ if (!e.disposed) {
208
+ if (e.disposed = !0, e.kind !== 3) {
209
+ for (let t of e.sources) x(t, e);
210
+ e.sources.length = 0, e.state = 0;
211
+ }
212
+ L(e);
213
+ }
214
+ }
215
+ function z(e, t) {
216
+ for (let n = t; n !== null; n = n.owner) {
217
+ if (n.kind !== 3 || n.handler === null || n.disposed) continue;
218
+ let t = n.handler;
219
+ try {
220
+ M(n.owner, () => t(e));
221
+ return;
222
+ } catch (t) {
223
+ e = t;
224
+ }
225
+ }
226
+ if (o === 0) throw e;
227
+ u.push(e);
228
+ }
229
+ function B() {
230
+ return d > 0;
231
+ }
232
+ function V(e) {
233
+ d++;
234
+ try {
235
+ return e();
236
+ } finally {
237
+ d--;
238
+ }
239
+ }
240
+ export { V as _, I as a, z as c, m as d, v as f, g, k as h, S as i, B as l, f as m, P as n, R as o, M as p, A as r, j as s, N as t, p as u };
@@ -0,0 +1,104 @@
1
+ import { _ as e, c as t, d as n, g as r, i, m as a, n as o, o as s, p as c, r as l, s as u, t as d } from "./graph-C_aA46c6.js";
2
+ // src/core/signal.ts
3
+ function f(e, t) {
4
+ let r = {
5
+ kind: 0,
6
+ value: e,
7
+ equals: t?.equals ?? Object.is,
8
+ observers: [],
9
+ seenBy: 0
10
+ };
11
+ return Object.assign(() => (a(r), r.value), { set: (e) => {
12
+ let t = typeof e == "function" ? e(r.value) : e;
13
+ r.equals !== !1 && r.equals(r.value, t) || (r.value = t, n(r));
14
+ } });
15
+ }
16
+ // src/core/computed.ts
17
+ function p(e, t) {
18
+ let n = {
19
+ kind: 2,
20
+ fn: e,
21
+ value: void 0,
22
+ equals: t?.equals ?? Object.is,
23
+ hasValue: !1,
24
+ hasError: !1,
25
+ error: void 0,
26
+ computing: !1,
27
+ state: 2,
28
+ sources: [],
29
+ observers: [],
30
+ seenBy: 0,
31
+ flushId: 0,
32
+ flushRuns: 0,
33
+ owner: null,
34
+ children: null,
35
+ cleanups: null,
36
+ disposed: !1
37
+ };
38
+ return l(n), () => {
39
+ if (n.computing) throw m(n);
40
+ if (n.state !== 0 && r(n), a(n), n.hasError) throw n.error;
41
+ return n.value;
42
+ };
43
+ }
44
+ function m(e) {
45
+ return /* @__PURE__ */ Error("[keits] cycle detected");
46
+ }
47
+ // src/core/owner.ts
48
+ function h() {
49
+ return u();
50
+ }
51
+ function g(e, t) {
52
+ return c(e, t);
53
+ }
54
+ function _(e) {
55
+ let t = {
56
+ kind: 3,
57
+ owner: u(),
58
+ children: null,
59
+ cleanups: null,
60
+ disposed: !1,
61
+ handler: null
62
+ }, n = () => i(() => s(t));
63
+ return i(() => {
64
+ try {
65
+ return c(t, () => e(n));
66
+ } catch (e) {
67
+ throw s(t), e;
68
+ }
69
+ });
70
+ }
71
+ function v(e) {
72
+ d(e);
73
+ }
74
+ function y(e) {
75
+ o(e);
76
+ }
77
+ function b(e, n) {
78
+ let r = {
79
+ kind: 3,
80
+ owner: null,
81
+ children: null,
82
+ cleanups: null,
83
+ disposed: !1,
84
+ handler: n
85
+ };
86
+ return l(r), i(() => {
87
+ try {
88
+ return c(r, e);
89
+ } catch (e) {
90
+ t(e, r);
91
+ return;
92
+ }
93
+ });
94
+ }
95
+ function x(t) {
96
+ return e(() => _((e) => {
97
+ try {
98
+ return t();
99
+ } finally {
100
+ e();
101
+ }
102
+ }));
103
+ }
104
+ export { y as a, p as c, v as i, f as l, _ as n, x as o, h as r, g as s, b as t };
package/dist/prod/svg.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as e, t } from "./shared/element-C8c5hIhH.js";
1
+ import { r as e, t } from "./shared/element-DUtXb3px.js";
2
2
  // src/svg/element.ts
3
3
  function n(n) {
4
4
  return t(n, e);
@@ -0,0 +1,2 @@
1
+ export { resource, type FetchInfo, type Resource, type ResourceOptions, type ResourceState } from "./resource";
2
+ export { lazy, type LazyComponent } from "./lazy";
@@ -0,0 +1,7 @@
1
+ import type { Component } from "../flow/dynamic";
2
+ export interface LazyComponent<P> extends Component<P> {
3
+ preload(): Promise<Component<P>>;
4
+ }
5
+ export declare function lazy<P = void>(load: () => PromiseLike<{
6
+ default: Component<P>;
7
+ }>): LazyComponent<P>;
@@ -0,0 +1,23 @@
1
+ import type { Accessor } from "../core/types";
2
+ export type ResourceState = "unresolved" | "pending" | "ready" | "refreshing" | "errored";
3
+ export interface FetchInfo<T> {
4
+ signal: AbortSignal;
5
+ refetching: boolean;
6
+ value: T | undefined;
7
+ }
8
+ export interface ResourceOptions<T> {
9
+ initialValue?: T;
10
+ }
11
+ export interface Resource<T> extends Accessor<T | undefined> {
12
+ state: Accessor<ResourceState>;
13
+ loading: Accessor<boolean>;
14
+ error: Accessor<unknown>;
15
+ refetch(): Promise<void>;
16
+ mutate(value: T | undefined): void;
17
+ optimistic(update: (current: T | undefined) => T, action: () => PromiseLike<unknown>): Promise<boolean>;
18
+ }
19
+ type Fetcher<S, T> = (source: S, info: FetchInfo<T>) => T | PromiseLike<T>;
20
+ type Source<S> = () => S | null | undefined | false;
21
+ export declare function resource<T>(fetcher: (info: FetchInfo<T>) => T | PromiseLike<T>, options?: ResourceOptions<T>): Resource<T>;
22
+ export declare function resource<T, S>(source: Source<S>, fetcher: Fetcher<S, T>, options?: ResourceOptions<T>): Resource<T>;
23
+ export {};
@@ -0,0 +1,4 @@
1
+ export interface SuspenseBoundary {
2
+ wait(key: object, subscribe: (done: () => void) => void): void;
3
+ }
4
+ export declare const SuspenseContext: import("..").Context<SuspenseBoundary | null>;
@@ -48,6 +48,10 @@ export interface RootNode extends OwnerFields {
48
48
  key: object;
49
49
  value: unknown;
50
50
  };
51
+ held?: {
52
+ owner: Owner | null;
53
+ fn: () => void;
54
+ }[] | null;
51
55
  }
52
56
  export type Source = SignalSource | ComputedNode;
53
57
  export type Computation = EffectNode | ComputedNode;
@@ -66,6 +70,10 @@ export declare function getOwner(): Owner | null;
66
70
  export declare function runWithOwner<T>(owner: Owner | null, fn: () => T): T;
67
71
  export declare function addCleanup(fn: () => void): boolean;
68
72
  export declare function addMount(fn: () => void): void;
73
+ export declare function deferMounts<T>(fn: () => T): {
74
+ result: T;
75
+ release: () => void;
76
+ };
69
77
  export declare function dispose(node: Owner): void;
70
78
  export declare function handleError(error: unknown, owner: Owner | null): void;
71
79
  export declare function isStaticRender(): boolean;
@@ -37,7 +37,7 @@ export type Props<E extends Element> = ElementProps<E> & AttributeProps & EventP
37
37
  ref?: (element: E) => void;
38
38
  };
39
39
  export interface ElementFactory<E extends Element> {
40
- (props?: Props<E> | null, children?: Child): E;
41
40
  (children: Child): E;
41
+ (props?: Props<E> | null, children?: Child): E;
42
42
  }
43
43
  export {};
@@ -0,0 +1,2 @@
1
+ import type { Child } from "../dom/types";
2
+ export declare function $catch(children: () => Child, fallback: (error: unknown, reset: () => void) => Child): Child;
@@ -0,0 +1,6 @@
1
+ import type { Child } from "../dom/types";
2
+ export type Component<P> = (props: P) => Child;
3
+ type MaybeComponent<P> = Component<P> | null | undefined | false;
4
+ export declare function $dynamic(component: () => MaybeComponent<void>): Child;
5
+ export declare function $dynamic<P>(component: () => MaybeComponent<P>, props: P): Child;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { Accessor } from "../core/types";
2
+ import type { Child } from "../dom/types";
3
+ export interface ForOptions {
4
+ fallback?: () => Child;
5
+ }
6
+ export declare function $for<T>(each: () => readonly T[] | null | undefined | false, render: (item: T, index: Accessor<number>) => Child, options?: ForOptions): Child;
7
+ export declare function longestIncreasing(sequence: readonly number[]): Set<number>;
@@ -0,0 +1,4 @@
1
+ import type { Accessor } from "../core/types";
2
+ import type { Child } from "../dom/types";
3
+ export type Truthy<T> = Exclude<T, null | undefined | false | 0 | "" | 0>;
4
+ export declare function $if<T>(when: () => T, then: (value: Accessor<Truthy<T>>) => Child, otherwise?: () => Child): Child;
@@ -0,0 +1,8 @@
1
+ export { $for, type ForOptions } from "./for";
2
+ export { $if, type Truthy } from "./if";
3
+ export { $show } from "./show";
4
+ export { $switch, type PartialSwitchCases, type SwitchCases } from "./switch";
5
+ export { $dynamic, type Component } from "./dynamic";
6
+ export { $catch } from "./catch";
7
+ export { $portal } from "./portal";
8
+ export { $suspense } from "./suspense";
@@ -0,0 +1,2 @@
1
+ import type { Child } from "../dom/types";
2
+ export declare function $portal(children: () => Child, target?: Element | null): Child;
@@ -0,0 +1,11 @@
1
+ import type { Child } from "../dom/types";
2
+ export interface Row {
3
+ item: unknown;
4
+ index: ((next: number) => void) | null;
5
+ dispose: () => void;
6
+ first: Node;
7
+ last: Node;
8
+ }
9
+ export declare function createRow(build: () => Child, item: unknown): Row;
10
+ export declare function moveRow(parent: Node, row: Row, anchor: Node | null): void;
11
+ export declare function removeRow(row: Row): void;
@@ -0,0 +1 @@
1
+ export declare function $show<E extends HTMLElement | SVGElement>(when: () => unknown, element: E): E;
@@ -0,0 +1,2 @@
1
+ import type { Child } from "../dom/types";
2
+ export declare function $suspense(children: () => Child, fallback: () => Child): Child;
@@ -0,0 +1,9 @@
1
+ import type { Child } from "../dom/types";
2
+ export type SwitchCases<V extends PropertyKey> = {
3
+ readonly [K in V]: () => Child;
4
+ };
5
+ export type PartialSwitchCases<V extends PropertyKey> = {
6
+ readonly [K in V]?: () => Child;
7
+ };
8
+ export declare function $switch<V extends PropertyKey>(value: () => V, cases: SwitchCases<NoInfer<V>>): Child;
9
+ export declare function $switch<V extends PropertyKey>(value: () => V, cases: PartialSwitchCases<NoInfer<V>>, fallback: () => Child): Child;
@@ -8,3 +8,5 @@ export { catchError, createRoot, getOwner, onCleanup, onMount, renderStatic, run
8
8
  export { createContext, provide, useContext, type Context, type ContextOptions } from "./core/context";
9
9
  export { reconcile, store, unwrap, type ReconcileOptions, type SetStore, type Store, type StoreOptions } from "./core/store";
10
10
  export * from "./dom/index";
11
+ export * from "./flow/index";
12
+ export * from "./async/index";
@@ -0,0 +1,21 @@
1
+ export interface HistoryLocation {
2
+ path: string;
3
+ search: string;
4
+ hash: string;
5
+ }
6
+ export interface RouterHistory {
7
+ read(): HistoryLocation;
8
+ push(url: string): void;
9
+ replace(url: string): void;
10
+ listen(callback: () => void): () => void;
11
+ href(url: string): string;
12
+ toAppUrl(url: URL): string | null;
13
+ key(): string;
14
+ }
15
+ export declare function browserHistory(base?: string): RouterHistory;
16
+ export declare function hashHistory(): RouterHistory;
17
+ export declare function memoryHistory(initial?: string): RouterHistory & {
18
+ back(): void;
19
+ forward(): void;
20
+ };
21
+ export declare function splitUrl(url: string): HistoryLocation;
@@ -0,0 +1,3 @@
1
+ export { createRouter, type RouterConfig } from "./router";
2
+ export { browserHistory, hashHistory, memoryHistory, type HistoryLocation, type RouterHistory } from "./history";
3
+ export type { GuardResult, LayoutProps, LinkOptions, NavigateOptions, NavigationTarget, ParamNames, Params, QueryOf, QuerySchema, QuerySpec, QueryValues, RouteDef, RouteMatch, RoutePath, Router } from "./types";
@@ -0,0 +1 @@
1
+ export declare function linkTarget(event: MouseEvent, toAppUrl: (url: URL) => string | null): string | null;
@@ -0,0 +1,15 @@
1
+ import type { QuerySchema, RouteDef, RouteMatch } from "./types";
2
+ export interface Branch {
3
+ path: string;
4
+ routes: readonly RouteDef[];
5
+ pattern: RegExp;
6
+ keys: string[];
7
+ score: number;
8
+ }
9
+ export declare function joinPath(parent: string, path: string): string;
10
+ export declare function compileRoutes(routes: readonly RouteDef[]): Branch[];
11
+ export declare function matchPath(branches: readonly Branch[], pathname: string): RouteMatch | null;
12
+ export declare function branchSchema(match: RouteMatch | null): QuerySchema;
13
+ export declare function parseQuery(schema: QuerySchema, search: string): Record<string, string | number | boolean>;
14
+ export declare function buildSearch(values: Readonly<Record<string, string | number | boolean | undefined>>): string;
15
+ export declare function fillParams(path: string, params: Readonly<Record<string, string | number>> | undefined): string;
@@ -0,0 +1,10 @@
1
+ import { type RouterHistory } from "./history";
2
+ import type { RouteDef, Router } from "./types";
3
+ export interface RouterConfig<Routes extends readonly RouteDef[]> {
4
+ routes: Routes;
5
+ history?: "browser" | "hash" | RouterHistory;
6
+ base?: string;
7
+ links?: boolean;
8
+ scroll?: boolean;
9
+ }
10
+ export declare function createRouter<const Routes extends readonly RouteDef[]>(config: RouterConfig<Routes>): Router<Routes>;
@@ -0,0 +1,5 @@
1
+ export interface Scroller {
2
+ save(key: string): void;
3
+ restore(key: string, popped: boolean, pathChanged: boolean, hash: string, hashChanged: boolean): void;
4
+ }
5
+ export declare function createScroller(): Scroller;
@@ -0,0 +1,87 @@
1
+ import type { Child } from "../dom/types";
2
+ import type { Accessor } from "../core/types";
3
+ export type QuerySpec = "string" | "number" | "boolean" | readonly string[];
4
+ export type QuerySchema = Readonly<Record<string, QuerySpec>>;
5
+ export type QueryValues<S> = {
6
+ -readonly [K in keyof S]?: S[K] extends "number" ? number : S[K] extends "boolean" ? boolean : S[K] extends readonly (infer V)[] ? V : string;
7
+ };
8
+ export interface NavigationTarget {
9
+ path: string;
10
+ route: string | null;
11
+ params: Readonly<Record<string, string>>;
12
+ search: string;
13
+ from: string | null;
14
+ }
15
+ export type GuardResult = boolean | string;
16
+ export interface LayoutProps {
17
+ children: Child;
18
+ }
19
+ export interface RouteDef {
20
+ readonly path: string;
21
+ readonly component?: () => Child;
22
+ readonly layout?: (props: LayoutProps) => Child;
23
+ readonly children?: readonly RouteDef[];
24
+ readonly query?: QuerySchema;
25
+ readonly guard?: (to: NavigationTarget) => GuardResult | PromiseLike<GuardResult>;
26
+ }
27
+ type Join<Parent extends string, Path extends string> = Path extends `/${string}` ? Path : Path extends "" ? Parent extends "" ? "/" : Parent : Parent extends "" | "/" ? `/${Path}` : `${Parent}/${Path}`;
28
+ type OwnQuery<D> = D extends {
29
+ readonly query: infer Q;
30
+ } ? Q : {};
31
+ export type RouteEntries<Routes, Parent extends string = "", ParentQuery = {}> = Routes extends readonly (infer D)[] ? D extends {
32
+ readonly path: infer P extends string;
33
+ } ? {
34
+ path: Join<Parent, P>;
35
+ query: ParentQuery & OwnQuery<D>;
36
+ } | (D extends {
37
+ readonly children: infer C;
38
+ } ? RouteEntries<C, Join<Parent, P>, ParentQuery & OwnQuery<D>> : never) : never : never;
39
+ export type RoutePath<Routes> = Exclude<RouteEntries<Routes>["path"], `${string}*${string}`>;
40
+ export type ParamNames<P extends string> = P extends `${string}:${infer Name}/${infer Rest}` ? Name | ParamNames<`/${Rest}`> : P extends `${string}:${infer Name}` ? Name : never;
41
+ export type Params<P extends string> = {
42
+ [K in ParamNames<P>]: string;
43
+ };
44
+ export type QueryOf<Routes, P extends string> = QueryValues<Extract<RouteEntries<Routes>, {
45
+ path: P;
46
+ }>["query"]>;
47
+ export type LinkOptions<Routes, P extends string> = {
48
+ query?: QueryOf<Routes, P>;
49
+ hash?: string;
50
+ } & ([ParamNames<P>] extends [never] ? {
51
+ params?: undefined;
52
+ } : {
53
+ params: {
54
+ [K in ParamNames<P>]: string | number;
55
+ };
56
+ });
57
+ export type PlainUrl<U extends string> = U extends `${string}/:${string}` ? never : U;
58
+ export interface NavigateOptions {
59
+ replace?: boolean;
60
+ }
61
+ export interface RouteMatch {
62
+ path: string;
63
+ routes: readonly RouteDef[];
64
+ params: Readonly<Record<string, string>>;
65
+ }
66
+ export interface Router<Routes extends readonly RouteDef[]> {
67
+ location: Accessor<{
68
+ path: string;
69
+ search: string;
70
+ hash: string;
71
+ }>;
72
+ match: Accessor<RouteMatch | null>;
73
+ params: Accessor<Readonly<Record<string, string>>>;
74
+ query: Accessor<Readonly<Record<string, string | number | boolean>>>;
75
+ pending: Accessor<boolean>;
76
+ navigate<P extends RoutePath<Routes>>(path: P, ...options: [ParamNames<P>] extends [never] ? [(LinkOptions<Routes, P> & NavigateOptions)?] : [LinkOptions<Routes, P> & NavigateOptions]): Promise<boolean>;
77
+ navigate<U extends string>(url: PlainUrl<U>, options?: NavigateOptions): Promise<boolean>;
78
+ href<P extends RoutePath<Routes>>(path: P, ...options: [ParamNames<P>] extends [never] ? [LinkOptions<Routes, P>?] : [LinkOptions<Routes, P>]): string;
79
+ onLeave(check: (to: NavigationTarget) => boolean | PromiseLike<boolean>): void;
80
+ view(): Child;
81
+ setQuery(values: Readonly<Record<string, string | number | boolean | undefined>>, options?: {
82
+ push?: boolean;
83
+ }): void;
84
+ isActive(path: string, exact?: boolean): boolean;
85
+ dispose(): void;
86
+ }
87
+ export {};
@@ -8,6 +8,6 @@ export type SvgProps<E extends SVGElement> = AttributeProps & EventProps<E> & {
8
8
  ref?: (element: E) => void;
9
9
  };
10
10
  export interface SvgElementFactory<E extends SVGElement> {
11
- (props?: SvgProps<E> | null, children?: Child): E;
12
11
  (children: Child): E;
12
+ (props?: SvgProps<E> | null, children?: Child): E;
13
13
  }