keits 0.0.4 → 0.1.0

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 (70) hide show
  1. package/README.md +93 -79
  2. package/dist/dev/api.js +8 -3
  3. package/dist/dev/forms.js +6 -4
  4. package/dist/dev/index.js +26 -35
  5. package/dist/dev/router.js +24 -7
  6. package/dist/dev/shared/{computed-3UO-KiH1.js → computed-DrF8O8b4.js} +1 -1
  7. package/dist/dev/shared/{element-CQPqagu1.js → element-DXwmUAnz.js} +30 -76
  8. package/dist/dev/shared/{graph-D6-x_CWC.js → graph-SIvYLXSv.js} +62 -3
  9. package/dist/dev/shared/hydrate-C8cOsDDH.js +588 -0
  10. package/dist/dev/shared/mount-CDB2HgN5.js +23 -0
  11. package/dist/dev/shared/namespaces-Cz82B0Pr.js +84 -0
  12. package/dist/dev/shared/{owner-Dmge21OW.js → owner-BuwIoI4j.js} +12 -2
  13. package/dist/dev/shared/render-context-k2uu_dM_.js +34 -0
  14. package/dist/dev/shared/render-effect-Uk9dDmuU.js +32 -0
  15. package/dist/dev/shared/{resource-CbXVATvq.js → resource-DlgzdtcG.js} +24 -33
  16. package/dist/dev/shared/{signal-BOXkY-Iv.js → signal-B3xOKbVm.js} +1 -1
  17. package/dist/dev/shared/{store-BzUN1qE5.js → store-0vEg2bQV.js} +7 -3
  18. package/dist/dev/shared/unsafe-keys-CB1P22No.js +8 -0
  19. package/dist/dev/static.js +76 -0
  20. package/dist/dev/svg.js +2 -1
  21. package/dist/dev/testing.js +216 -0
  22. package/dist/dev/vite.js +141 -0
  23. package/dist/prod/api.js +76 -71
  24. package/dist/prod/forms.js +63 -60
  25. package/dist/prod/index.js +56 -64
  26. package/dist/prod/router.js +86 -73
  27. package/dist/prod/shared/{computed-CAPpOLCY.js → computed-BjqJ6Pps.js} +1 -1
  28. package/dist/prod/shared/element-DCit4-3e.js +129 -0
  29. package/dist/prod/shared/{graph-C_aA46c6.js → graph-CR2WKbwr.js} +107 -63
  30. package/dist/prod/shared/hydrate-kKnJbkV7.js +480 -0
  31. package/dist/prod/shared/mount-DbeKIoyD.js +18 -0
  32. package/dist/prod/shared/namespaces-BSRrBJIU.js +71 -0
  33. package/dist/prod/shared/owner-DBi3odT4.js +67 -0
  34. package/dist/prod/shared/render-context-DF8lr1uu.js +30 -0
  35. package/dist/prod/shared/render-effect-UFDi2Pfh.js +25 -0
  36. package/dist/prod/shared/resource-Ch5tVseZ.js +91 -0
  37. package/dist/prod/shared/signal-BDMlfa0Z.js +16 -0
  38. package/dist/prod/shared/store-CvW0DbmK.js +110 -0
  39. package/dist/prod/shared/unsafe-keys-C5PMlerl.js +7 -0
  40. package/dist/prod/static.js +48 -0
  41. package/dist/prod/svg.js +3 -2
  42. package/dist/prod/testing.js +144 -0
  43. package/dist/prod/vite.js +106 -0
  44. package/dist/types/async/render-context.d.ts +10 -0
  45. package/dist/types/core/effect.d.ts +1 -0
  46. package/dist/types/core/graph.d.ts +11 -0
  47. package/dist/types/core/owner.d.ts +1 -0
  48. package/dist/types/core/unsafe-keys.d.ts +2 -0
  49. package/dist/types/dom/hooks.d.ts +4 -0
  50. package/dist/types/dom/types.d.ts +5 -0
  51. package/dist/types/router/index.d.ts +1 -0
  52. package/dist/types/router/match.d.ts +1 -0
  53. package/dist/types/router/types.d.ts +1 -0
  54. package/dist/types/static/head.d.ts +36 -0
  55. package/dist/types/static/hydrate.d.ts +3 -0
  56. package/dist/types/static/index.d.ts +4 -0
  57. package/dist/types/static/island.d.ts +14 -0
  58. package/dist/types/static/json.d.ts +1 -0
  59. package/dist/types/static/render.d.ts +11 -0
  60. package/dist/types/static/server-dom.d.ts +100 -0
  61. package/dist/types/testing/index.d.ts +62 -0
  62. package/dist/types/vite/index.d.ts +24 -0
  63. package/package.json +34 -7
  64. package/dist/dev/shared/render-effect-kOGnLNbL.js +0 -26
  65. package/dist/prod/shared/element-DGyQ01Vs.js +0 -164
  66. package/dist/prod/shared/owner-6BFHIPR9.js +0 -59
  67. package/dist/prod/shared/render-effect-DjaUT3Cn.js +0 -23
  68. package/dist/prod/shared/resource-CNC2DBO3.js +0 -109
  69. package/dist/prod/shared/signal-DGrl3r9T.js +0 -16
  70. package/dist/prod/shared/store-Dcscpk_h.js +0 -109
package/README.md CHANGED
@@ -1,126 +1,140 @@
1
1
  # keits
2
2
 
3
3
  A fine-grained reactive TypeScript framework. Real DOM, no virtual DOM, zero dependencies.
4
-
5
- > **Status: 0.0.x, early.** This release is the **reactive core** only. The DOM layer
6
- > (`$div`, `mount`, `$if`, `$for`, …), router, forms and static builds are in progress.
7
- > Expect breaking changes before 1.0.
4
+ Build SPAs, static websites with islands, and server-rendered apps from the same components.
8
5
 
9
6
  ```sh
10
7
  npm install keits
11
8
  ```
12
9
 
13
- About 2.6 KB min+gzip for the whole core, and about 1.6 KB if you only use the basics
14
- (everything is tree-shakable).
10
+ About 7.4 KB min+gzip for the whole core. Everything is tree-shakable: a small app ships about 3 KB,
11
+ a static page with one interactive island about 4 KB.
12
+
13
+ > **Status: 0.1.** The API is complete and tested; expect small breaking changes before 1.0.
15
14
 
16
- ## Signals
15
+ ## A component
17
16
 
18
17
  ```ts
19
- import { signal, computed, effect } from "keits";
18
+ import { $button, $p, mount, signal } from "keits";
20
19
 
21
- const count = signal(0);
22
- const double = computed(() => count() * 2); // lazy and cached
20
+ function Counter() {
21
+ const count = signal(0);
22
+ return [
23
+ $p(() => `Clicked ${count()} times`), // a function child updates by itself
24
+ $button({ onclick: () => count.set((n) => n + 1) }, "+1"),
25
+ ];
26
+ }
23
27
 
24
- effect(() => {
25
- console.log(`${count()} × 2 = ${double()}`); // re-runs when count changes
26
- });
27
-
28
- count.set(1); // logs "1 × 2 = 2" before set() returns
29
- count.set((prev) => prev + 1);
28
+ mount(Counter, document.getElementById("app")!);
30
29
  ```
31
30
 
32
- - Read by calling: `count()`. Write with `.set(value)` or `.set(prev => next)`.
33
- - Updates are **synchronous** and **glitch-free**: an effect never sees a half-updated state,
34
- and runs once per change even when several computeds it reads changed.
35
- - Equal values don't notify (`Object.is` by default; pass `{ equals }` to customise,
36
- or `equals: false` to always notify).
37
- - `batch(fn)` groups writes; `untrack(fn)` reads without subscribing.
31
+ Components run once. Only the parts that read a signal update, without re-rendering anything else.
32
+ Every HTML tag has a factory (`$div`, `$input`, ...); SVG ones come from `keits/svg`.
33
+ Text is always escaped: `unsafeHTML()` is the only way to insert HTML, and `javascript:` URLs are blocked.
34
+
35
+ ## What's included
38
36
 
39
- ## Ownership and cleanup
37
+ | Import | What it does |
38
+ | --- | --- |
39
+ | `keits` | `signal`, `computed`, `effect`, `batch`, `store`, context, error boundaries, the `$tag` factories, control flow (`$if`, `$for`, `$show`, `$switch`, `$dynamic`, `$portal`), `$catch`, `$suspense`, `resource`, `lazy` |
40
+ | `keits/router` | Typed routes, params and query (`navigate("/jobs/:id", { params: { id } })` is checked), layouts that stay mounted, guards, `onLeave`, link clicks, scroll restoration |
41
+ | `keits/api` | `createApi()`: JSON requests, `ApiError`, timeouts, one shared token refresh on 401, cached queries with `invalidate("/jobs")` |
42
+ | `keits/forms` | `form()`: `bind()` for inputs, Standard Schema (zod, valibot...) or plain checks, typed paths, lists, submit, server errors on their fields |
43
+ | `keits/static` | `renderToString()`, `head()`, `hydrate()`, `island()` and `hydrateIslands()` |
44
+ | `keits/vite` | Vite plugin: builds every page to HTML, with `sitemap.xml`, `robots.txt` and incremental builds |
45
+ | `keits/testing` | `render()`, queries by role, label and text, `user.click/type/submit`, `renderOnServer()` |
46
+ | `keits/svg` | SVG element factories |
40
47
 
41
- Every effect and computed belongs to an **owner**. Disposing the owner disposes everything
42
- created inside it, so nothing leaks.
48
+ ## Data
43
49
 
44
50
  ```ts
45
- import { createRoot, effect, onCleanup, onMount } from "keits";
46
-
47
- const dispose = createRoot((dispose) => {
48
- effect(() => {
49
- const id = setInterval(tick, 1000);
50
- onCleanup(() => clearInterval(id)); // runs before each re-run, and on dispose
51
- });
52
- onMount(() => console.log("ready")); // once, after the current update settles
53
- return dispose;
54
- });
51
+ import { $for, $li, $suspense, $ul } from "keits";
52
+ import { createApi } from "keits/api";
53
+
54
+ const api = createApi({ baseUrl: "/api", headers: () => ({ Authorization: `Bearer ${token()}` }) });
55
55
 
56
- dispose();
56
+ function Jobs() {
57
+ const jobs = api.query<Job[]>("/jobs", { query: () => ({ page: page() }) }); // reloads when page changes
58
+ return $suspense(() => $ul($for(() => jobs() ?? [], (job) => $li(job.title))), () => "Loading…");
59
+ }
60
+
61
+ await api.post("/jobs", { body: draft, invalidate: "/jobs" }); // lists under /jobs refresh
57
62
  ```
58
63
 
59
- - An effect created inside another effect is disposed when the outer one re-runs.
60
- - Parent effects always run before their children.
61
- - `getOwner()` / `runWithOwner(owner, fn)` resume an owner later, e.g. after an `await`.
64
+ Create resources and queries in the component body, and read them inside `() =>`.
62
65
 
63
- ## Errors
66
+ ## Routing
64
67
 
65
68
  ```ts
66
- import { catchError, effect } from "keits";
67
-
68
- catchError(
69
- () => {
70
- effect(() => {
71
- if (input() < 0) throw new Error("negative");
72
- });
73
- },
74
- (error) => showError(error), // error: unknown
75
- );
69
+ import { createRouter } from "keits/router";
70
+
71
+ export const router = createRouter({
72
+ routes: [
73
+ {
74
+ path: "/",
75
+ layout: Shell, // stays mounted while its pages change
76
+ children: [
77
+ { path: "", component: Home },
78
+ { path: "jobs/:id", component: Job, guard: () => loggedIn() || "/login" },
79
+ ],
80
+ },
81
+ { path: "*", component: NotFound },
82
+ ],
83
+ });
84
+
85
+ mount(() => router.view(), document.getElementById("app")!);
76
86
  ```
77
87
 
78
- Errors from effects, cleanups and `onMount` go to the nearest `catchError`. With none,
79
- the rest of the update still finishes and the error is rethrown afterwards (several
80
- become one `AggregateError`). A failed effect keeps its subscriptions and retries when
81
- its inputs change.
88
+ ## Static sites and server rendering
82
89
 
83
- ## Context
90
+ Pages render to HTML at build time. Only islands load JavaScript in the browser:
84
91
 
85
92
  ```ts
86
- import { createContext, provide, useContext } from "keits";
93
+ // The interactive part. Everything else on the page stays plain HTML.
94
+ export const ContactForm = island("contact-form", (props: { to: string }) => ...);
87
95
 
88
- const Theme = createContext("light");
96
+ // In the browser:
97
+ hydrateIslands({ "contact-form": () => import("./contact-form").then((m) => m.ContactForm) });
98
+ ```
89
99
 
90
- provide(Theme, "dark", () => {
91
- useContext(Theme); // "dark", here and in anything created in here, even later
92
- });
100
+ ```ts
101
+ // vite.config.ts
102
+ import { keits } from "keits/vite";
103
+ export default { plugins: [keits({ entry: "src/server.ts", site: "https://example.com" })] };
104
+
105
+ // src/server.ts: the pages to build, and how to render one
106
+ export const pages = () => staticPaths(routes); // param routes list theirs with `paths: () => [...]`
107
+ export const render = (url: string) => renderToString(() => App(url));
93
108
  ```
94
109
 
95
- ## Stores
110
+ `index.html` needs `<!--app-head-->` in `<head>` and `<!--app-html-->` where the page goes.
111
+ For a whole app, use `renderToString(App, { hydrate: true })` on the server and `hydrate(App, el)` in the browser.
96
112
 
97
- Fine-grained reactivity for nested objects and arrays.
113
+ ## Testing
98
114
 
99
115
  ```ts
100
- import { store, reconcile, unwrap } from "keits";
116
+ import { cleanup, render, user } from "keits/testing";
101
117
 
102
- const [state, setState] = store({ filter: "all", jobs: [] as Job[] });
118
+ afterEach(cleanup);
103
119
 
104
- effect(() => console.log(state.jobs[0]?.amount)); // tracks exactly that field
105
-
106
- setState((draft) => {
107
- draft.jobs.push({ id: 1, amount: 100 }); // only readers of what changed re-run
108
- draft.filter = "paid";
120
+ it("signs up", () => {
121
+ const page = render(() => SignupForm());
122
+ user.type(page.getByLabelText("Email"), "kei@example.com");
123
+ user.click(page.getByRole("button", { name: "Sign up" }));
109
124
  });
110
-
111
- // Fresh data from an API: keep existing objects, update only what changed
112
- setState((draft) => reconcile(draft.jobs, freshJobs, { key: "id" }));
113
-
114
- localStorage.setItem("state", JSON.stringify(unwrap(state)));
115
125
  ```
116
126
 
117
- Stores are read-only outside `setState`, enforced both by the types and at runtime in dev.
127
+ ## Security
128
+
129
+ - Text is always escaped, in the browser and on the server. `unsafeHTML()` is the only way to insert markup.
130
+ - URL props (`href`, `src`, `action`...) block `javascript:` URLs, `innerHTML` and `srcdoc` aren't allowed as props, and event props must be functions.
131
+ - Validate data you don't control with `parse`, so its types are true at runtime as well:
118
132
 
119
- ## Static rendering
133
+ ```ts
134
+ const comments = api.query("/comments", { parse: Comments.parse }); // a zod or valibot schema
135
+ ```
120
136
 
121
- `renderStatic(fn)` runs components the way a static build does: `effect` and `onMount`
122
- are skipped, everything else works, and it all gets disposed afterwards. `isServer` is
123
- `true` outside the browser.
137
+ - A plain object as the first argument is read as props. When a value from outside might not be a string, write `$p(String(value))` or put it after a props object: `$p({}, value)`. A plain object there is refused with an error.
124
138
 
125
139
  ## License
126
140
 
package/dist/dev/api.js CHANGED
@@ -1,11 +1,14 @@
1
- import { t as resource } from "./shared/resource-CbXVATvq.js";
2
- import { i as onCleanup } from "./shared/owner-Dmge21OW.js";
1
+ import { t as resource } from "./shared/resource-DlgzdtcG.js";
2
+ import { f as isStaticRender } from "./shared/graph-SIvYLXSv.js";
3
+ import { a as onCleanup } from "./shared/owner-BuwIoI4j.js";
3
4
  // src/api/url.ts
4
5
  function buildPath(path, params, query) {
5
6
  const filled = path.replace(/:([A-Za-z0-9_]+)/g, (_, name) => {
6
7
  const value = params?.[name];
7
8
  if (value === void 0) throw new Error(`[keits/api] Missing param "${name}" for "${path}".`);
8
- return encodeURIComponent(String(value));
9
+ const text = String(value);
10
+ if (text === "." || text === "..") throw new Error(`[keits/api] Param "${name}" can't be "${text}" (in "${path}").`);
11
+ return encodeURIComponent(text);
9
12
  });
10
13
  if (query === void 0) return filled;
11
14
  const search = new URLSearchParams();
@@ -122,6 +125,7 @@ function createApi(config = {}) {
122
125
  refreshing = null;
123
126
  });
124
127
  async function send(method, path, options, retried = false) {
128
+ if (!/^\/(?![/\\])/.test(path)) throw new Error(`[keits/api] "${path}" must start with a single "/".`);
125
129
  const url = base + path;
126
130
  const headers = new Headers({ Accept: "application/json" });
127
131
  const shared = typeof config.headers === "function" ? await config.headers() : config.headers;
@@ -201,6 +205,7 @@ function createApi(config = {}) {
201
205
  return shownUrl;
202
206
  };
203
207
  const result = resource(key, (url, { refetching }) => {
208
+ if (isStaticRender()) return send("GET", url, {}).then(parse);
204
209
  const cached = refetching ? null : cache.peek(url);
205
210
  if (cached === null) return cache.fetch(url).then(parse);
206
211
  if (cached.stale) cache.fetch(url).catch(() => {});
package/dist/dev/forms.js CHANGED
@@ -1,7 +1,8 @@
1
- import { t as computed } from "./shared/computed-3UO-KiH1.js";
2
- import { h as untrack, i as batch } from "./shared/graph-D6-x_CWC.js";
3
- import { t as signal } from "./shared/signal-BOXkY-Iv.js";
4
- import { n as store, r as unwrap } from "./shared/store-BzUN1qE5.js";
1
+ import { t as computed } from "./shared/computed-DrF8O8b4.js";
2
+ import { S as untrack, i as batch } from "./shared/graph-SIvYLXSv.js";
3
+ import { t as signal } from "./shared/signal-B3xOKbVm.js";
4
+ import { n as store, r as unwrap } from "./shared/store-0vEg2bQV.js";
5
+ import { t as UNSAFE_KEYS } from "./shared/unsafe-keys-CB1P22No.js";
5
6
  // src/forms/paths.ts
6
7
  function getAt(source, path) {
7
8
  if (path === "") return source;
@@ -14,6 +15,7 @@ function getAt(source, path) {
14
15
  }
15
16
  function setAt(target, path, value) {
16
17
  const keys = path.split(".");
18
+ if (keys.some((key) => UNSAFE_KEYS.has(key))) throw new Error(`[keits/forms] "${path}" is not a field path: "__proto__", "constructor" and "prototype" aren't allowed.`);
17
19
  const last = keys.pop();
18
20
  let current = target;
19
21
  keys.forEach((key, i) => {
package/dist/dev/index.js CHANGED
@@ -1,11 +1,14 @@
1
- import { t as signal } from "./shared/signal-BOXkY-Iv.js";
2
- import { n as effect, t as renderEffect } from "./shared/render-effect-kOGnLNbL.js";
3
- import { t as computed } from "./shared/computed-3UO-KiH1.js";
4
- import { a as deferMounts, h as untrack, i as batch, l as isStaticRender, t as addCleanup } from "./shared/graph-D6-x_CWC.js";
5
- import { a as onMount, i as onCleanup, n as createRoot, o as renderStatic, r as getOwner, s as runWithOwner, t as catchError } from "./shared/owner-Dmge21OW.js";
6
- import { a as useContext, i as provide, n as SuspenseContext, r as createContext, t as resource } from "./shared/resource-CbXVATvq.js";
7
- import { n as store, r as unwrap, t as reconcile } from "./shared/store-BzUN1qE5.js";
8
- import { a as hooks, i as insert, n as html } from "./shared/element-CQPqagu1.js";
1
+ import { t as signal } from "./shared/signal-B3xOKbVm.js";
2
+ import { n as effect, t as renderEffect } from "./shared/render-effect-Uk9dDmuU.js";
3
+ import { t as computed } from "./shared/computed-DrF8O8b4.js";
4
+ import { S as untrack, a as deferMounts, f as isStaticRender, i as batch, m as nextKey, t as addCleanup } from "./shared/graph-SIvYLXSv.js";
5
+ import { a as onCleanup, c as runWithOwner, n as createRoot, o as onMount, r as getOwner, s as renderStatic, t as catchError } from "./shared/owner-BuwIoI4j.js";
6
+ import { a as provide, i as createContext, o as useContext } from "./shared/render-context-k2uu_dM_.js";
7
+ import { n as store, r as unwrap, t as reconcile } from "./shared/store-0vEg2bQV.js";
8
+ import { n as html } from "./shared/element-DXwmUAnz.js";
9
+ import { a as hooks, n as insert, s as withoutClaims } from "./shared/namespaces-Cz82B0Pr.js";
10
+ import { t as mount } from "./shared/mount-CDB2HgN5.js";
11
+ import { n as SuspenseContext, t as resource } from "./shared/resource-DlgzdtcG.js";
9
12
  // src/core/env.ts
10
13
  var isServer = typeof window === "undefined";
11
14
  // src/dom/tags.ts
@@ -121,28 +124,9 @@ var $ul = /* @__PURE__ */ html("ul");
121
124
  var $var = /* @__PURE__ */ html("var");
122
125
  var $video = /* @__PURE__ */ html("video");
123
126
  var $wbr = /* @__PURE__ */ html("wbr");
124
- // src/dom/mount.ts
125
- function mount(app, target) {
126
- if (target === null) throw new Error("[keits] mount(): the target element was not found (null).");
127
- const start = hooks.marker();
128
- const end = hooks.marker();
129
- target.append(start, end);
130
- const dispose = createRoot((dispose) => {
131
- insert(target, app(), end);
132
- return dispose;
133
- });
134
- return () => {
135
- dispose();
136
- let node = start;
137
- while (node !== null) {
138
- const next = node === end ? null : node.nextSibling;
139
- node.remove();
140
- node = next;
141
- }
142
- };
143
- }
144
127
  // src/dom/unsafe.ts
145
128
  function unsafeHTML(markup) {
129
+ if (hooks.html !== void 0) return hooks.html(markup);
146
130
  const template = document.createElement("template");
147
131
  template.innerHTML = markup;
148
132
  return template.content;
@@ -158,7 +142,7 @@ function createRow(build, item) {
158
142
  first: result,
159
143
  last: result
160
144
  };
161
- const holder = document.createDocumentFragment();
145
+ const holder = hooks.fragment();
162
146
  const first = hooks.marker();
163
147
  const last = hooks.marker();
164
148
  holder.append(first, last);
@@ -199,7 +183,7 @@ function removeRow(row) {
199
183
  // src/flow/for.ts
200
184
  function $for(each, render, options) {
201
185
  const end = hooks.marker();
202
- const container = document.createDocumentFragment();
186
+ const container = hooks.fragment();
203
187
  container.append(end);
204
188
  let rows = [];
205
189
  let fallback = null;
@@ -333,7 +317,7 @@ function $catch(children, fallback) {
333
317
  const current = failure();
334
318
  if (current !== null) return untrack(() => fallback(current.error, reset));
335
319
  return untrack(() => catchError(() => {
336
- const content = document.createDocumentFragment();
320
+ const content = hooks.fragment();
337
321
  insert(content, children());
338
322
  return content;
339
323
  }, (error) => failure.set({ error })));
@@ -341,14 +325,21 @@ function $catch(children, fallback) {
341
325
  }
342
326
  // src/flow/portal.ts
343
327
  function $portal(children, target) {
344
- if (isStaticRender()) return null;
328
+ if (isStaticRender()) {
329
+ nextKey();
330
+ return null;
331
+ }
345
332
  const host = target === void 0 ? document.body : target;
346
333
  if (host === null) throw new Error("[keits] $portal(): the target element was not found (null).");
347
334
  const start = hooks.marker();
348
335
  const end = hooks.marker();
349
336
  host.append(start, end);
350
- insert(host, untrack(children), end);
337
+ const disposeContent = createRoot((dispose) => {
338
+ withoutClaims(() => insert(host, untrack(children), end));
339
+ return dispose;
340
+ });
351
341
  addCleanup(() => {
342
+ disposeContent();
352
343
  let node = start;
353
344
  while (node !== null) {
354
345
  const next = node === end ? null : node.nextSibling;
@@ -371,7 +362,7 @@ function $suspense(children, fallback) {
371
362
  pendingCount.set((n) => n - 1);
372
363
  });
373
364
  } };
374
- const offscreen = document.createDocumentFragment();
365
+ const offscreen = hooks.fragment();
375
366
  const contentStart = hooks.marker();
376
367
  const contentEnd = hooks.marker();
377
368
  offscreen.append(contentStart, contentEnd);
@@ -384,7 +375,7 @@ function $suspense(children, fallback) {
384
375
  last: contentEnd
385
376
  };
386
377
  const end = hooks.marker();
387
- const container = document.createDocumentFragment();
378
+ const container = hooks.fragment();
388
379
  container.append(end);
389
380
  let fallbackRow = null;
390
381
  addCleanup(() => fallbackRow?.dispose());
@@ -1,7 +1,7 @@
1
- import { t as computed } from "./shared/computed-3UO-KiH1.js";
2
- import { t as signal } from "./shared/signal-BOXkY-Iv.js";
3
- import { c as handleError, h as untrack, i as batch, n as addMount, p as runWithOwner, s as getOwner } from "./shared/graph-D6-x_CWC.js";
4
- import { i as onCleanup } from "./shared/owner-Dmge21OW.js";
1
+ import { t as computed } from "./shared/computed-DrF8O8b4.js";
2
+ import { t as signal } from "./shared/signal-B3xOKbVm.js";
3
+ import { S as untrack, _ as runWithOwner, c as getOwner, i as batch, n as addMount, u as handleError } from "./shared/graph-SIvYLXSv.js";
4
+ import { a as onCleanup } from "./shared/owner-BuwIoI4j.js";
5
5
  // src/router/history.ts
6
6
  var newKey = () => Math.random().toString(36).slice(2, 10);
7
7
  var stateKey = () => window.history.state?.keitsKey ?? "start";
@@ -10,7 +10,7 @@ function browserHistory(base = "") {
10
10
  return {
11
11
  read() {
12
12
  let path = window.location.pathname;
13
- if (prefix !== "" && path.startsWith(prefix)) path = path.slice(prefix.length);
13
+ if (prefix !== "" && (path === prefix || path.startsWith(`${prefix}/`))) path = path.slice(prefix.length);
14
14
  return {
15
15
  path: path || "/",
16
16
  search: window.location.search,
@@ -234,6 +234,23 @@ function fillParams(path, params) {
234
234
  return encodeURIComponent(String(value));
235
235
  });
236
236
  }
237
+ async function staticPaths(routes) {
238
+ const urls = [];
239
+ for (const branch of compileRoutes(routes)) {
240
+ if (branch.keys.includes("*")) continue;
241
+ if (branch.keys.length === 0) {
242
+ urls.push(branch.path);
243
+ continue;
244
+ }
245
+ const withPaths = [...branch.routes].reverse().find((route) => route.paths !== void 0);
246
+ if (withPaths === void 0) {
247
+ console.warn(`[keits/router] staticPaths(): "${branch.path}" has params but no paths(), so it isn't built.`);
248
+ continue;
249
+ }
250
+ for (const params of await withPaths.paths()) urls.push(fillParams(branch.path, params));
251
+ }
252
+ return [...new Set(urls)];
253
+ }
237
254
  // src/router/scroll.ts
238
255
  function createScroller() {
239
256
  const positions = /* @__PURE__ */ new Map();
@@ -268,7 +285,7 @@ function decodeHash(hash) {
268
285
  }
269
286
  // src/router/router.ts
270
287
  function createRouter(config) {
271
- const history = typeof config.history === "object" ? config.history : config.history === "hash" ? hashHistory() : browserHistory(config.base);
288
+ const history = typeof config.history === "object" ? config.history : config.history === "hash" ? hashHistory() : typeof window === "undefined" ? memoryHistory() : browserHistory(config.base);
272
289
  const owner = getOwner();
273
290
  const branches = compileRoutes(config.routes);
274
291
  const sameLocation = (a, b) => a.path === b.path && a.search === b.search && a.hash === b.hash;
@@ -442,4 +459,4 @@ function shallowEqual(a, b) {
442
459
  if (keys.length !== Object.keys(b).length) return false;
443
460
  return keys.every((key) => Object.is(a[key], b[key]));
444
461
  }
445
- export { browserHistory, createRouter, hashHistory, memoryHistory };
462
+ export { browserHistory, createRouter, hashHistory, memoryHistory, staticPaths };
@@ -1,4 +1,4 @@
1
- import { g as updateIfNeeded, m as track, r as adopt } from "./graph-D6-x_CWC.js";
1
+ import { C as updateIfNeeded, r as adopt, x as track } from "./graph-SIvYLXSv.js";
2
2
  // src/core/computed.ts
3
3
  function computed(fn, options) {
4
4
  const node = {
@@ -1,64 +1,7 @@
1
- import { t as renderEffect } from "./render-effect-kOGnLNbL.js";
2
- import { c as handleError, i as batch, l as isStaticRender, p as runWithOwner, s as getOwner } from "./graph-D6-x_CWC.js";
3
- var hooks = {
4
- element: (tag, namespace) => namespace === null ? document.createElement(tag) : document.createElementNS(namespace, tag),
5
- text: (value) => document.createTextNode(value),
6
- marker: () => document.createComment("")
7
- };
8
- // src/dom/insert.ts
9
- function insert(parent, child, before = null) {
10
- if (child === null || child === void 0 || typeof child === "boolean") return;
11
- if (typeof child === "function") return insertDynamic(parent, child, before);
12
- if (isChildArray(child)) {
13
- for (const item of child) insert(parent, item, before);
14
- return;
15
- }
16
- if (typeof child === "object") {
17
- parent.insertBefore(child, before);
18
- return;
19
- }
20
- parent.insertBefore(hooks.text(String(child)), before);
21
- }
22
- function isChildArray(value) {
23
- return Array.isArray(value);
24
- }
25
- function isTextValue(value) {
26
- return value === null || typeof value !== "object" && typeof value !== "function";
27
- }
28
- function toText(value) {
29
- return value === null || value === void 0 || typeof value === "boolean" ? "" : String(value);
30
- }
31
- function insertDynamic(parent, fn, before) {
32
- const text = hooks.text("");
33
- parent.insertBefore(text, before);
34
- let start = null;
35
- let end = null;
36
- renderEffect(() => {
37
- const value = fn();
38
- if (start === null || end === null) {
39
- if (isTextValue(value)) {
40
- const next = toText(value);
41
- if (text.data !== next) text.data = next;
42
- return;
43
- }
44
- start = hooks.marker();
45
- end = hooks.marker();
46
- text.before(start);
47
- text.after(end);
48
- text.remove();
49
- }
50
- clearRange(start, end);
51
- insert(end.parentNode, value, end);
52
- });
53
- }
54
- function clearRange(start, end) {
55
- let node = start.nextSibling;
56
- while (node !== null && node !== end) {
57
- const next = node.nextSibling;
58
- node.remove();
59
- node = next;
60
- }
61
- }
1
+ import { a as hooks, n as insert } from "./namespaces-Cz82B0Pr.js";
2
+ import { _ as runWithOwner, c as getOwner, f as isStaticRender, i as batch, u as handleError } from "./graph-SIvYLXSv.js";
3
+ import { t as UNSAFE_KEYS } from "./unsafe-keys-CB1P22No.js";
4
+ import { t as renderEffect } from "./render-effect-Uk9dDmuU.js";
62
5
  // src/dom/events.ts
63
6
  function applyEvent(element, key, value) {
64
7
  let handler = value;
@@ -84,24 +27,24 @@ function listen(element, type, handler, options) {
84
27
  function isPromiseLike(value) {
85
28
  return typeof value?.then === "function";
86
29
  }
87
- // src/dom/namespaces.ts
88
- var SVG_NS = "http://www.w3.org/2000/svg";
89
30
  // src/dom/props.ts
90
31
  var UNSAFE_PROPS = /* @__PURE__ */ new Set([
91
- "innerHTML",
92
- "outerHTML",
32
+ "innerhtml",
33
+ "outerhtml",
93
34
  "srcdoc"
94
35
  ]);
95
36
  var URL_PROPS = /* @__PURE__ */ new Set([
96
37
  "href",
97
38
  "src",
98
39
  "action",
99
- "formAction",
100
40
  "formaction",
101
41
  "poster",
102
42
  "cite",
103
43
  "data",
104
- "xlink:href"
44
+ "xlink:href",
45
+ "to",
46
+ "from",
47
+ "values"
105
48
  ]);
106
49
  var BLOCKED_URL = "about:invalid#keits-blocked";
107
50
  function applyProps(element, props) {
@@ -110,43 +53,54 @@ function applyProps(element, props) {
110
53
  if (key === "ref") continue;
111
54
  if (key === "class") applyClass(element, value);
112
55
  else if (key === "style") applyStyle(element, value);
113
- else if (key.startsWith("on")) applyEvent(element, key, value);
56
+ else if (key.toLowerCase().startsWith("on")) applyEvent(element, key, value);
114
57
  else if (typeof value === "function") renderEffect(() => setProp(element, key, value()));
115
58
  else setProp(element, key, value);
116
59
  }
117
60
  }
118
61
  function setProp(element, key, value) {
119
- if (UNSAFE_PROPS.has(key)) throw new Error(`[keits] "${key}" is not allowed as a prop: it would allow HTML injection.`);
120
- if (URL_PROPS.has(key) && typeof value === "string" && isJavaScriptUrl(value)) {
62
+ const name = key.toLowerCase();
63
+ if (UNSAFE_PROPS.has(name) || UNSAFE_KEYS.has(key) || name.startsWith("on") && typeof value === "string") throw new Error(`[keits] "${key}" is not allowed as a prop: it would allow HTML injection.`);
64
+ if (URL_PROPS.has(name) && value != null && value !== false && isJavaScriptUrl(String(value))) {
121
65
  console.warn(`[keits] Blocked a javascript: URL in "${key}".`);
122
66
  value = BLOCKED_URL;
123
67
  }
124
68
  if (key in element && element.namespaceURI !== "http://www.w3.org/2000/svg") {
125
69
  element[key] = value;
126
70
  if (isStaticRender()) reflectForStatic(element, key, value);
127
- } else if (value === null || value === void 0 || value === false) element.removeAttribute(key);
71
+ } else if (key.startsWith("aria-") && typeof value === "boolean") element.setAttribute(key, String(value));
72
+ else if (value === null || value === void 0 || value === false) element.removeAttribute(key);
128
73
  else element.setAttribute(key, value === true ? "" : String(value));
129
74
  }
130
75
  function isJavaScriptUrl(url) {
131
- return url.replace(/[\u0000-\u0020]/g, "").toLowerCase().startsWith("javascript");
76
+ return url.replace(/[\u0000-\u0020]/g, "").toLowerCase().split(";").some((part) => part.startsWith("javascript:"));
132
77
  }
133
78
  function reflectForStatic(element, key, value) {
134
79
  if (key === "value") {
135
80
  if (element.localName === "textarea") element.textContent = value == null ? "" : String(value);
81
+ else if (element.localName === "select") selectOption(element, value == null ? "" : String(value));
136
82
  else if (value == null) element.removeAttribute("value");
137
83
  else element.setAttribute("value", String(value));
138
84
  } else if (key === "checked" || key === "selected") element.toggleAttribute(key, value === true);
139
85
  }
86
+ function selectOption(node, value) {
87
+ for (let child = node.firstChild; child !== null; child = child.nextSibling) {
88
+ if (child.nodeType !== 1) continue;
89
+ const element = child;
90
+ if (element.localName === "option") element.toggleAttribute("selected", (element.getAttribute("value") ?? element.textContent) === value);
91
+ else selectOption(element, value);
92
+ }
93
+ }
140
94
  function applyClass(element, value) {
141
95
  if (typeof value === "function") {
142
96
  renderEffect(() => writeClass(element, toClassString(value())));
143
97
  return;
144
98
  }
145
99
  const fixed = [];
146
- collectClasses(value, fixed, (name, on) => {
147
- renderEffect(() => element.classList.toggle(name, on()));
148
- });
100
+ const reactive = [];
101
+ collectClasses(value, fixed, (name, on) => reactive.push([name, on]));
149
102
  if (fixed.length > 0) element.classList.add(...fixed);
103
+ for (const [name, on] of reactive) renderEffect(() => element.classList.toggle(name, on()));
150
104
  }
151
105
  function writeClass(element, className) {
152
106
  if (className === "") element.removeAttribute("class");
@@ -219,4 +173,4 @@ function createFactory(tag, namespace) {
219
173
  function isProps(value) {
220
174
  return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.nodeType !== "number";
221
175
  }
222
- export { hooks as a, insert as i, html as n, SVG_NS as r, createFactory as t };
176
+ export { html as n, createFactory as t };