brumate 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -72
- package/dist/boot-DN1ZU8Hg.d.ts +37 -0
- package/dist/cli.js +2 -2
- package/dist/{client-DuDTDePF.d.ts → client-DwJInP_a.d.ts} +133 -44
- package/dist/client-routes-DakuM32C.js +94 -0
- package/dist/client-routes-DakuM32C.js.map +1 -0
- package/dist/{cookies-rgIAc8IE.js → cookies-Av5WFmcf.js} +18 -8
- package/dist/cookies-Av5WFmcf.js.map +1 -0
- package/dist/{devtools-Bm8cS7hX.js → devtools-BKjnHrnv.js} +10 -5
- package/dist/devtools-BKjnHrnv.js.map +1 -0
- package/dist/{devtools-panel-CTbDSBBA.js → devtools-panel-AWOn0VK2.js} +23 -26
- package/dist/devtools-panel-AWOn0VK2.js.map +1 -0
- package/dist/{files-D_JUcSU5.js → files-DdT84mPy.js} +22 -3
- package/dist/{files-D_JUcSU5.js.map → files-DdT84mPy.js.map} +1 -1
- package/dist/{html-CxWpXngy.js → html-DEeoepg3.js} +47 -10
- package/dist/html-DEeoepg3.js.map +1 -0
- package/dist/{html-DV-Tezgq.d.ts → html-Du8jY2Cc.d.ts} +14 -2
- package/dist/index.d.ts +65 -6
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/{inspect-CGCWfaEx.js → inspect-BPchdWbU.js} +887 -172
- package/dist/inspect-BPchdWbU.js.map +1 -0
- package/dist/loader-Dc9OwY5I.js +101 -0
- package/dist/loader-Dc9OwY5I.js.map +1 -0
- package/dist/{navigate-C5dP89YL.js → navigate-CzLjnoPH.js} +112 -59
- package/dist/navigate-CzLjnoPH.js.map +1 -0
- package/dist/{produce-BjQGMpqL.d.ts → produce-CtZ32UGG.d.ts} +13 -3
- package/dist/{rpc-B86KKjzx.js → rpc-9fSqL_YK.js} +57 -12
- package/dist/rpc-9fSqL_YK.js.map +1 -0
- package/dist/runtime/client.d.ts +4 -4
- package/dist/runtime/client.js +599 -306
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/devtools.d.ts +3 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +9 -5
- package/dist/runtime/hot.js.map +1 -1
- package/dist/runtime/html.d.ts +2 -2
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +12 -2
- package/dist/runtime/loader.js +3 -1
- package/dist/runtime/server.d.ts +4 -4
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +2 -2
- package/dist/runtime/signals.js +5 -5
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +3 -0
- package/dist/runtime/static-loader.js +1 -0
- package/dist/runtime/testing.d.ts +21 -2
- package/dist/runtime/testing.js +83 -7
- package/dist/runtime/testing.js.map +1 -1
- package/dist/{server-sQCvduOz.d.ts → server-BxqjLUnV.d.ts} +211 -20
- package/dist/{server-CX3JnPCs.js → server-DZsgnPKS.js} +595 -185
- package/dist/server-DZsgnPKS.js.map +1 -0
- package/dist/shared-CWYOd0H3.js +40 -0
- package/dist/shared-CWYOd0H3.js.map +1 -0
- package/dist/static-loader-BcFh4ebX.d.ts +11 -0
- package/dist/static-loader-ClNkHZGn.js +185 -0
- package/dist/static-loader-ClNkHZGn.js.map +1 -0
- package/dist/stream-bgNCMcaA.js +280 -0
- package/dist/stream-bgNCMcaA.js.map +1 -0
- package/dist/vite.d.ts +30 -5
- package/dist/vite.js +501 -62
- package/dist/vite.js.map +1 -1
- package/package.json +7 -2
- package/types.d.ts +5 -0
- package/dist/cookies-rgIAc8IE.js.map +0 -1
- package/dist/devtools-Bm8cS7hX.js.map +0 -1
- package/dist/devtools-panel-CTbDSBBA.js.map +0 -1
- package/dist/html-CxWpXngy.js.map +0 -1
- package/dist/inspect-CGCWfaEx.js.map +0 -1
- package/dist/loader-BUhNqDHw.d.ts +0 -30
- package/dist/loader-py4qu6tQ.js +0 -215
- package/dist/loader-py4qu6tQ.js.map +0 -1
- package/dist/navigate-C5dP89YL.js.map +0 -1
- package/dist/rpc-B86KKjzx.js.map +0 -1
- package/dist/server-CX3JnPCs.js.map +0 -1
- package/dist/shared-BE_oBSDM.js +0 -176
- package/dist/shared-BE_oBSDM.js.map +0 -1
- package/dist/stream-cvhqOzfs.js +0 -145
- package/dist/stream-cvhqOzfs.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,96 +2,67 @@
|
|
|
2
2
|
|
|
3
3
|
> A component language and compiler for resumable web apps.
|
|
4
4
|
|
|
5
|
-
`brumate` compiles single-file components into server-rendered HTML and small client
|
|
5
|
+
`brumate` compiles single-file `.brm` components into server-rendered HTML and small client modules. The browser does not hydrate. It reads the state that the server wrote into the page, and loads the code of an event handler only when that event fires.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- Never run component code again on the client to rebuild state.
|
|
13
|
-
- Keep a loader under 1 KB that is the only code loaded before the first interaction.
|
|
14
|
-
- Keep the syntax small: scripts, markup with `#` blocks, and a few compile-time functions.
|
|
15
|
-
|
|
16
|
-
## Example
|
|
17
|
-
|
|
18
|
-
```html
|
|
19
|
-
<script>
|
|
20
|
-
import { $memo, $props, $signal } from 'brumate/signals';
|
|
21
|
-
import { persist } from './todos.server';
|
|
22
|
-
|
|
23
|
-
const { initial } = $props<{ initial: Todo[] }>();
|
|
24
|
-
let todos = $signal(initial);
|
|
25
|
-
let draft = $signal('');
|
|
26
|
-
const left = $memo(todos.filter((todo) => !todo.done).length);
|
|
27
|
-
|
|
28
|
-
async function add() {
|
|
29
|
-
todos = [...todos, { id: crypto.randomUUID(), title: draft, done: false }];
|
|
30
|
-
draft = '';
|
|
31
|
-
await persist(todos);
|
|
32
|
-
}
|
|
33
|
-
</script>
|
|
34
|
-
|
|
35
|
-
<h1>Todos</h1>
|
|
36
|
-
<form onSubmit:prevent=add>
|
|
37
|
-
<input value=draft onInput=((event) => (draft = event.currentTarget.value))>
|
|
38
|
-
</form>
|
|
39
|
-
<ul>
|
|
40
|
-
#for (todo of todos by todo.id) {
|
|
41
|
-
<li class={ done: todo.done }>{todo.title}</li>
|
|
42
|
-
}
|
|
43
|
-
</ul>
|
|
44
|
-
<p>{left} left</p>
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add brumate
|
|
11
|
+
pnpm add -D vite @brumate/tsc typescript
|
|
45
12
|
```
|
|
46
13
|
|
|
47
|
-
|
|
14
|
+
brumate needs Node 22.18 or newer, and Vite.
|
|
48
15
|
|
|
49
|
-
|
|
16
|
+
```ts
|
|
17
|
+
// vite.config.ts
|
|
18
|
+
import brumate from 'brumate/vite';
|
|
19
|
+
import { defineConfig } from 'vite';
|
|
50
20
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
plugins: [brumate()],
|
|
23
|
+
build: {
|
|
24
|
+
manifest: true,
|
|
25
|
+
rolldownOptions: { input: 'src/client.ts' },
|
|
26
|
+
},
|
|
27
|
+
});
|
|
55
28
|
```
|
|
56
29
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
30
|
+
```ts
|
|
31
|
+
// src/client.ts
|
|
32
|
+
import 'virtual:brumate/start';
|
|
33
|
+
```
|
|
60
34
|
|
|
61
|
-
|
|
35
|
+
## A component
|
|
62
36
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
- The reference lists every [compile-time function](./website/docs/reference-signals.md), [block](./website/docs/reference-blocks.md), [runtime export](./website/docs/reference-server.md) and [plugin option](./website/docs/reference-plugin.md).
|
|
67
|
-
- The internals describe the [reactive graph](./website/docs/reactive-graph.md), the [page format](./website/docs/page-format.md) and the [server function protocol](./website/docs/server-protocol.md).
|
|
37
|
+
```html
|
|
38
|
+
<script>
|
|
39
|
+
import { $memo, $signal } from 'brumate/signals';
|
|
68
40
|
|
|
69
|
-
|
|
41
|
+
let count = $signal(0);
|
|
42
|
+
const double = $memo(count * 2);
|
|
43
|
+
</script>
|
|
70
44
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
- [Decisions](./docs/decisions.md) lists what is decided and what is still open.
|
|
75
|
-
- [Proposals](./docs/proposals.md) lists features that would be good to add, with a sketch of each.
|
|
76
|
-
- [Prior art](./docs/prior-art.md) compares other resumable and partially hydrated frameworks.
|
|
45
|
+
<button onClick=(() => count++)>Clicked {count} times</button>
|
|
46
|
+
<p>Double: {double}</p>
|
|
47
|
+
```
|
|
77
48
|
|
|
78
|
-
|
|
49
|
+
The server renders the button and the text. The browser loads the code of the click handler, and of the updates it causes, the first time the button is clicked.
|
|
79
50
|
|
|
80
|
-
|
|
81
|
-
pnpm install
|
|
82
|
-
pnpm test
|
|
83
|
-
pnpm typecheck
|
|
84
|
-
pnpm lint
|
|
85
|
-
pnpm format
|
|
86
|
-
```
|
|
51
|
+
## What it includes
|
|
87
52
|
|
|
88
|
-
|
|
53
|
+
- `brumate/signals`: the compile-time functions, such as `$signal`, `$memo`, `$effect`, `$props`, `$action` and `$optimistic`.
|
|
54
|
+
- `brumate/vite`: the Vite plugin. It compiles `.brm` files, splits client code per handler, serves server function calls in development, and can prerender pages.
|
|
55
|
+
- `brumate/server`: rendering, streaming, routes, server functions, sessions, cookies, and validation with Standard Schema.
|
|
56
|
+
- `brumate/loader` and `brumate/client`: the loader and the core that run in the browser.
|
|
57
|
+
- `brumate/testing`: mounting components in a DOM test, with the real server functions.
|
|
89
58
|
|
|
90
|
-
##
|
|
59
|
+
## Documentation
|
|
91
60
|
|
|
92
|
-
|
|
61
|
+
- [Getting started](https://github.com/lxsmnsyc/brumate/blob/main/website/docs/getting-started.md)
|
|
62
|
+
- [Your first app](https://github.com/lxsmnsyc/brumate/blob/main/website/docs/tutorial.md)
|
|
63
|
+
- [All guides and reference](https://github.com/lxsmnsyc/brumate/tree/main/website/docs)
|
|
93
64
|
|
|
94
|
-
The
|
|
65
|
+
brumate is at 0.x. The page format can change between versions, so the server and the client must come from the same version.
|
|
95
66
|
|
|
96
67
|
## License
|
|
97
68
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { t as ClientModule } from "./client-DwJInP_a.js";
|
|
2
|
+
//#region src/runtime/boot.d.ts
|
|
3
|
+
interface LoaderOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Imports the client module of a component, by component ID. Undefined for
|
|
6
|
+
* a component that has no client code.
|
|
7
|
+
*/
|
|
8
|
+
load: (id: string) => Promise<ClientModule> | undefined;
|
|
9
|
+
/** The URL prefix of server function calls. */
|
|
10
|
+
rpc?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Loads pages without a full page load: links to the same origin, the back
|
|
13
|
+
* and forward buttons, forms that post to a server function, and redirects
|
|
14
|
+
* from server functions to the same origin. Defaults to true.
|
|
15
|
+
*/
|
|
16
|
+
navigate?: boolean | NavigateOptions;
|
|
17
|
+
/**
|
|
18
|
+
* After the page loads, while the browser is idle, loads the core and the
|
|
19
|
+
* code of the handlers of elements in or near the viewport, so a first
|
|
20
|
+
* event needs no request. Elements with `data-prefetch="none"` are left
|
|
21
|
+
* out, and nothing loads when the browser asks to save data or the
|
|
22
|
+
* connection is 2G. Defaults to true.
|
|
23
|
+
*/
|
|
24
|
+
preload?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface NavigateOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Swaps the page inside a view transition, where the browser has them.
|
|
29
|
+
* CSS can tell links, the back and forward buttons and forms apart with
|
|
30
|
+
* the types `push`, `traverse` and `form`. A redirect from a server
|
|
31
|
+
* function has the type `form`.
|
|
32
|
+
*/
|
|
33
|
+
transition?: boolean;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { NavigateOptions as n, LoaderOptions as t };
|
|
37
|
+
//# sourceMappingURL=boot-DN1ZU8Hg.d.ts.map
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { n as findFiles, t as defaultExclude } from "./files-
|
|
2
|
+
import { D as analyzeProjectProps, a as CompileError, n as inspect } from "./inspect-BPchdWbU.js";
|
|
3
|
+
import { n as findFiles, t as defaultExclude } from "./files-DdT84mPy.js";
|
|
4
4
|
import { readFile, stat } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
//#region src/cli.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Raw } from "./html-
|
|
2
|
-
import { n as ElementReference } from "./produce-
|
|
1
|
+
import { t as Raw } from "./html-Du8jY2Cc.js";
|
|
2
|
+
import { a as PageState, n as ElementReference } from "./produce-CtZ32UGG.js";
|
|
3
3
|
import { t as Context } from "./context-aeo9esY9.js";
|
|
4
4
|
//#region src/runtime/client.d.ts
|
|
5
5
|
type Update = [kind: number, name: string];
|
|
@@ -10,8 +10,11 @@ interface ClientModule {
|
|
|
10
10
|
props: Record<string, number>;
|
|
11
11
|
/** Scope kind, then slot, to the updates that read it. */
|
|
12
12
|
g: Record<number, Record<number, Update[]>>;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Imports a part of the module. A module without it holds every part
|
|
15
|
+
* itself, as a small component's module does.
|
|
16
|
+
*/
|
|
17
|
+
load?: (part: string) => Promise<Part>;
|
|
15
18
|
/** Server function ID to the memos that call it, as scope kind and update, for `refresh`. */
|
|
16
19
|
refresh?: Record<string, Update[]>;
|
|
17
20
|
}
|
|
@@ -36,16 +39,37 @@ interface Scope {
|
|
|
36
39
|
/** The slots that hold the contexts that the scope reads, by context key. */
|
|
37
40
|
x?: Record<string, number>;
|
|
38
41
|
children: Set<Scope>;
|
|
42
|
+
/** The `b-root` of the render that the server rendered the scope in. */
|
|
43
|
+
r?: string;
|
|
39
44
|
cleanups?: Map<string, () => void>;
|
|
40
45
|
keys?: Map<number, unknown>;
|
|
46
|
+
/** Set while the scope is the body of an `#offscreen` block that is hidden. */
|
|
47
|
+
h?: HiddenBody;
|
|
48
|
+
/** Effects and `$client` callbacks to run when the `#offscreen` body around the scope shows. */
|
|
49
|
+
w?: Set<string>;
|
|
41
50
|
}
|
|
42
51
|
interface CoreOptions {
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Imports the client module of a component. Undefined for a component that
|
|
54
|
+
* has no client code, which a build leaves out.
|
|
55
|
+
*/
|
|
56
|
+
load: (id: string) => Promise<ClientModule> | undefined;
|
|
57
|
+
/** Adds event listeners for the `b-on` attributes in new markup. */
|
|
45
58
|
listen: (root: ParentNode) => void;
|
|
46
59
|
/** The URL prefix of server function calls. Defaults to `/_brumate`. */
|
|
47
60
|
rpc?: string;
|
|
48
61
|
}
|
|
62
|
+
/** The URL prefix of server function calls, from the options. */
|
|
63
|
+
declare let rpcPrefix: string;
|
|
64
|
+
/** The scopes of the page, by ID. */
|
|
65
|
+
declare const scopes: Map<number, Scope>;
|
|
66
|
+
/** What modules of optional features add to the core. See `client-routes.ts` and `hot`. */
|
|
67
|
+
declare const hooks: {
|
|
68
|
+
/** Changes a state record before its scopes are added, such as for a page that navigation added. */
|
|
69
|
+
record?: (script: Element, state: PageState) => PageState;
|
|
70
|
+
/** Runs after the scopes of a state record are added. */
|
|
71
|
+
added?: (added: Scope[]) => void;
|
|
72
|
+
};
|
|
49
73
|
/** What the devtools overlay hears from the core. It is set only in development. */
|
|
50
74
|
interface DevtoolsHooks {
|
|
51
75
|
/** The core started, with the scopes of the page, and a way to write a slot, as a handler does. */
|
|
@@ -62,17 +86,50 @@ interface DevtoolsHooks {
|
|
|
62
86
|
}
|
|
63
87
|
/** The global key of the devtools hooks. */
|
|
64
88
|
declare const DEVTOOLS: unique symbol;
|
|
65
|
-
/** Stops reading state records that arrive later. */
|
|
89
|
+
/** Stops reading state records and markers that arrive later. Later records wait for `init`. */
|
|
66
90
|
declare function dispose(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Stops reading, before client navigation replaces only some routes. The
|
|
93
|
+
* server renders the new routes with its current values, so only the writes
|
|
94
|
+
* that come after count for the records that stream in later.
|
|
95
|
+
*/
|
|
96
|
+
declare function leaveRoutes(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Removes the scopes of a render, by its `b-root`, with the scopes inside
|
|
99
|
+
* them. Their cleanups run, and their memos no longer load. Its markup
|
|
100
|
+
* stays. `brumate/testing` calls it when a mounted component unmounts.
|
|
101
|
+
*/
|
|
102
|
+
declare function removeRoot(root: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* Forgets the code of components that changed on the dev server, so the next
|
|
105
|
+
* event or update loads the new code. Their state stays. `brumate/hot` calls it.
|
|
106
|
+
*/
|
|
107
|
+
declare function forget(ids: string[]): void;
|
|
108
|
+
/**
|
|
109
|
+
* Keeps the values of the signals of each instance of a component, by
|
|
110
|
+
* name, before the page renders again with its new markup. `brumate/hot` calls it.
|
|
111
|
+
*/
|
|
112
|
+
declare function remount(detail: {
|
|
113
|
+
id: string;
|
|
114
|
+
before: Record<number, string[]>;
|
|
115
|
+
after: Record<number, string[]>;
|
|
116
|
+
signals: string[];
|
|
117
|
+
}[]): void;
|
|
67
118
|
/**
|
|
68
119
|
* Forgets the page, before another page replaces it. Cleanups run. Loaded
|
|
69
|
-
* modules and parts stay, so the next page does not load them again.
|
|
120
|
+
* modules and parts stay, so the next page does not load them again. Only
|
|
121
|
+
* client navigation calls it.
|
|
70
122
|
*/
|
|
71
123
|
declare function leavePage(): void;
|
|
72
124
|
/** Reads the page state. The loader calls it once, before the first handler. */
|
|
73
125
|
declare function init(value: CoreOptions): void;
|
|
74
126
|
declare function loadModule(id: string): Promise<ClientModule>;
|
|
75
|
-
|
|
127
|
+
declare function loadPart(module: ClientModule, name: string): Promise<Part>;
|
|
128
|
+
/**
|
|
129
|
+
* Runs the handler `ref` for an element. The scope comes from the element's
|
|
130
|
+
* `b-b` anchor, or from the nearest element around it that has one, which
|
|
131
|
+
* the compiler checks is in the same scope.
|
|
132
|
+
*/
|
|
76
133
|
declare function handle(element: Element, ref: string, event?: Event): Promise<unknown>;
|
|
77
134
|
/** Returns the instance of a scope by its ID. */
|
|
78
135
|
declare function scopeOf(id: number): Scope | undefined;
|
|
@@ -101,16 +158,33 @@ declare function memo(scope: Scope, slot: number, compute: () => unknown): void;
|
|
|
101
158
|
* the page finishes, such as after a post failed.
|
|
102
159
|
*/
|
|
103
160
|
declare function guess<T>(scope: Scope, slot: number, ...rest: [value: T] | [sourceScope: Scope, sourceSlot: number, value: T]): T;
|
|
161
|
+
/** Counts a server call, and puts guesses back when the last one finishes. */
|
|
162
|
+
declare function track<T>(request: Promise<T>): Promise<T>;
|
|
104
163
|
/** True while a new value of a memo loads, or while the server still streams its value. */
|
|
105
164
|
declare function pending(scope: Scope, slot: number): boolean;
|
|
106
165
|
/** `x++`, `x--`, `++x` and `--x`. */
|
|
107
166
|
declare function update(scope: Scope, slot: number, delta: number, prefix: boolean): number;
|
|
167
|
+
declare function descendants(scope: Scope, kind: number, result?: Scope[]): Scope[];
|
|
168
|
+
/**
|
|
169
|
+
* Removes a scope from the page: its cleanups run, and its memo state goes,
|
|
170
|
+
* so a load that settles later is not written. Its markup stays.
|
|
171
|
+
*/
|
|
172
|
+
declare function removeScope(scope: Scope): void;
|
|
108
173
|
/**
|
|
109
174
|
* Renders a `#portal` body into its target, between markers with its scope
|
|
110
175
|
* ID. `kinds` names the body, so a new target first removes it from the old one.
|
|
111
176
|
*/
|
|
112
|
-
declare function
|
|
177
|
+
declare function portalTo(scope: Scope, target: unknown, render: Render, kinds?: number[]): void;
|
|
178
|
+
/** Writes an inserted value between `<!--t…-->` and `<!--/t-->`. */
|
|
113
179
|
declare function text(scope: Scope, anchor: number, value: unknown): void;
|
|
180
|
+
/** Writes an inserted value that is the whole content of the element with the anchor. */
|
|
181
|
+
declare function content(scope: Scope, anchor: number, value: unknown): void;
|
|
182
|
+
/**
|
|
183
|
+
* Writes the text of an element whose content is text, such as a `<textarea>`
|
|
184
|
+
* or a `<title>`. A `<textarea>` gets the value too, as `value` does on an
|
|
185
|
+
* `<input>`, so a change replaces what the user typed.
|
|
186
|
+
*/
|
|
187
|
+
declare function writeText(scope: Scope, anchor: number, value: unknown): void;
|
|
114
188
|
declare function attr(scope: Scope, anchor: number, name: string, value: unknown): void;
|
|
115
189
|
declare function attrs(scope: Scope, anchor: number, values: Record<string, unknown>): void;
|
|
116
190
|
type Render = (parent: Scope, item?: unknown, index?: number) => string;
|
|
@@ -125,12 +199,23 @@ declare function rekey(scope: Scope, anchor: number, value: unknown, render: Ren
|
|
|
125
199
|
declare function reset(scope: Scope, anchor: number, id: string, body: string, fallback: string, kinds: number[]): Promise<void>;
|
|
126
200
|
/** Renders the body of a `#client` block once. */
|
|
127
201
|
declare function fill(scope: Scope, anchor: number, render: Render): void;
|
|
202
|
+
/**
|
|
203
|
+
* Shows or hides the body of an `#offscreen` block. A body that the page
|
|
204
|
+
* does not have yet renders the first time it shows. `kind` is the body's
|
|
205
|
+
* scope ID in the compiled component.
|
|
206
|
+
*/
|
|
207
|
+
declare function offscreen(scope: Scope, anchor: number, value: unknown, render: Render, kind: number): void;
|
|
208
|
+
/** A hidden `#offscreen` body: its scope, and the ranges of its markup and of its portals. */
|
|
209
|
+
interface HiddenBody {
|
|
210
|
+
scope: Scope;
|
|
211
|
+
ranges: [start: Comment, end: Comment][];
|
|
212
|
+
}
|
|
128
213
|
/** Updates the items of `#for` or `#repeat`, keeping the elements of items whose keys stay. */
|
|
129
214
|
declare function list(scope: Scope, anchor: number, items: unknown[], key: (item: unknown, index: number) => unknown, render: Render, assign: (scope: Scope, item: unknown, index: number) => void, fallback: Render | undefined, fallbackKinds: number[]): void;
|
|
130
215
|
/** Sets a style variable on the top-level elements of a component instance. */
|
|
131
216
|
declare function setVar(scope: Scope, name: string, value: unknown): void;
|
|
132
217
|
/** Writes a provided value, and the slot of every scope that reads it from this provider. */
|
|
133
|
-
declare function
|
|
218
|
+
declare function updateContext(scope: Scope, context: Context<unknown>, value: unknown): void;
|
|
134
219
|
/** Sets the title of the page. */
|
|
135
220
|
declare function title(value: unknown): void;
|
|
136
221
|
/** Writes a prop of a child component. */
|
|
@@ -140,8 +225,8 @@ declare function effect(scope: Scope, name: string, callback: () => unknown): vo
|
|
|
140
225
|
/** Renders the attributes of a form or button that posts to a server function. */
|
|
141
226
|
declare function action(name: string, id: string, method?: string, result?: string): string;
|
|
142
227
|
/**
|
|
143
|
-
* Sends a form
|
|
144
|
-
*
|
|
228
|
+
* Sends a form of an `$action`. The code is in `rpc.ts`, which every server
|
|
229
|
+
* call loads, so the core holds only this.
|
|
145
230
|
*/
|
|
146
231
|
declare function submitAction(form: HTMLFormElement, submitter: HTMLElement | null): void;
|
|
147
232
|
/** Calls a server function. */
|
|
@@ -156,35 +241,39 @@ type Component<P = any> = (props: P) => string;
|
|
|
156
241
|
*/
|
|
157
242
|
declare function component<P>(Child: Component<P>, props: P, _ctx?: unknown, scope?: Scope | number, anchor?: number): string;
|
|
158
243
|
declare function dynamic(tag: unknown, attributes: Record<string, unknown>, children: Raw | undefined, _ctx?: unknown, scope?: Scope | number): string;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
244
|
+
/** Work that waits until rendered markup is in the page. */
|
|
245
|
+
declare const afterInsert: (() => void)[];
|
|
246
|
+
/** Creates a scope for markup that the client renders, and returns its ID. */
|
|
247
|
+
declare function createScope(kind: number, parent?: Scope | number, module?: string): number;
|
|
248
|
+
/** The ID that `$id()` makes. Client scope IDs are negative, so they differ from the server's. */
|
|
249
|
+
declare function makeId(scope: Scope | number, index: number): string;
|
|
250
|
+
/** Sets the owner of the next component's root scope. */
|
|
251
|
+
declare function setOwner(scope: Scope | number): void;
|
|
252
|
+
/** Provides a value of a context to the scopes inside `scope`. */
|
|
253
|
+
declare function provideValue<T>(context: Context<T>, value: T, scope: Scope | number): void;
|
|
254
|
+
/** Reads a context, and records its slot so that changes to the provided value reach it. */
|
|
255
|
+
declare function consumeContext<T>(context: Context<T>, scope: Scope | number, slot?: number): T;
|
|
256
|
+
declare function setSlots(id: number, values: unknown[]): void;
|
|
257
|
+
declare function setItem(id: number, value: unknown): void;
|
|
258
|
+
declare function elementAt(scope: number, anchor: number): ElementReference;
|
|
259
|
+
/** Adds the markup of a `#head` block to the document's head. */
|
|
260
|
+
declare function addHead(html: string): void;
|
|
261
|
+
/** Adds the markup of a `#portal` block at the end of the page, after the markup around it. */
|
|
262
|
+
declare function addPortal(html: string): void;
|
|
263
|
+
/** Adds a component's stylesheet to the page, if the server did not. */
|
|
264
|
+
declare function addStyle(id: string, css: string): string;
|
|
265
|
+
/** A function prop rendered on the client calls the parent's exported handler. */
|
|
266
|
+
declare function handlerProp(value: unknown, ref: string, scope: Scope | number): unknown;
|
|
267
|
+
/**
|
|
268
|
+
* What the loader calls. It is one export, so the loader's import of the core
|
|
269
|
+
* names one export, and a build keeps the rest only when components call them.
|
|
270
|
+
*/
|
|
271
|
+
declare const loader: {
|
|
272
|
+
init: typeof init;
|
|
273
|
+
handle: typeof handle;
|
|
274
|
+
dispose: typeof dispose;
|
|
275
|
+
submitAction: typeof submitAction;
|
|
276
|
+
};
|
|
188
277
|
//#endregion
|
|
189
|
-
export {
|
|
190
|
-
//# sourceMappingURL=client-
|
|
278
|
+
export { removeScope as $, get as A, loadModule as B, descendants as C, elementAt as D, effect as E, init as F, offscreen as G, loader as H, insert as I, prop as J, pending as K, leavePage as L, handle as M, handlerProp as N, fill as O, hooks as P, removeRoot as Q, leaveRoutes as R, createScope as S, dynamic as T, makeId as U, loadPart as V, memo as W, rekey as X, provideValue as Y, remount as Z, branch as _, DevtoolsHooks as a, set as at, consumeContext as b, Scope as c, setSlots as ct, addPortal as d, text as dt, reset as et, addStyle as f, title as ft, attrs as g, writeText as gt, attr as h, updateContext as ht, DEVTOOLS as i, scopes as it, guess as j, forget as k, action as l, setVar as lt, asyncMemo as m, update as mt, Component as n, rpcPrefix as nt, HiddenBody as o, setItem as ot, afterInsert as p, track as pt, portalTo as q, CoreOptions as r, scopeOf as rt, Part as s, setOwner as st, ClientModule as t, rpc as tt, addHead as u, submitAction as ut, cells as v, dispose as w, content as x, component as y, list as z };
|
|
279
|
+
//# sourceMappingURL=client-DwJInP_a.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//#region src/runtime/client-routes.ts
|
|
2
|
+
/** Adds a number to the scope IDs of a state record. */
|
|
3
|
+
function shiftState(core, state, by) {
|
|
4
|
+
const { ElementReference, FunctionReference } = core;
|
|
5
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6
|
+
const shiftValue = (value) => {
|
|
7
|
+
if (value instanceof ElementReference) return new ElementReference(value.scope + by, value.anchor);
|
|
8
|
+
if (value instanceof FunctionReference) return new FunctionReference(value.ref, value.scope + by);
|
|
9
|
+
if (value instanceof Promise) return value.then(shiftValue);
|
|
10
|
+
if (typeof value === "object" && value !== null && !seen.has(value)) {
|
|
11
|
+
seen.add(value);
|
|
12
|
+
if (Array.isArray(value)) value.forEach((item, index) => {
|
|
13
|
+
value[index] = shiftValue(item);
|
|
14
|
+
});
|
|
15
|
+
else if (Object.getPrototypeOf(value) === Object.prototype) for (const [key, item] of Object.entries(value)) value[key] = shiftValue(item);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
const result = {};
|
|
20
|
+
for (const [key, record] of Object.entries(state)) result[Number(key) + by] = {
|
|
21
|
+
...record,
|
|
22
|
+
p: record.p === void 0 ? void 0 : record.p + by,
|
|
23
|
+
o: record.o === void 0 ? void 0 : record.o + by,
|
|
24
|
+
c: record.c && Object.fromEntries(Object.entries(record.c).map(([anchor, id]) => [anchor, id + by])),
|
|
25
|
+
s: record.s?.map(shiftValue)
|
|
26
|
+
};
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
/** Removes scopes and the scopes inside them, and runs their cleanups. */
|
|
30
|
+
function dropScopes(core, roots) {
|
|
31
|
+
const inside = (scope) => {
|
|
32
|
+
for (let current = scope; current; current = current.p ?? current.o) if (roots.has(current.id)) return true;
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
for (const scope of core.scopes.values()) if (inside(scope)) core.removeScope(scope);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reads the attributes that navigation set on a state record. A page whose
|
|
39
|
+
* IDs started at another number, such as a prerendered file, has them moved
|
|
40
|
+
* with `b-offset`. A page that replaced only some routes of the one before
|
|
41
|
+
* it drops the old routes with `b-drop`, and adds only the scopes inside
|
|
42
|
+
* `b-roots`, with the scopes of the kept layouts in place of the new
|
|
43
|
+
* page's copies of them, by `b-alias`.
|
|
44
|
+
*/
|
|
45
|
+
function routeRecord(core, script, state) {
|
|
46
|
+
const offset = Number(script.getAttribute("b-offset") ?? 0);
|
|
47
|
+
const value = offset ? shiftState(core, state, offset) : state;
|
|
48
|
+
const drop = script.getAttribute("b-drop");
|
|
49
|
+
if (drop) dropScopes(core, new Set(drop.split(",").map(Number)));
|
|
50
|
+
const list = script.getAttribute("b-roots");
|
|
51
|
+
if (list === null) return value;
|
|
52
|
+
const roots = new Set(list.split(",").filter(Boolean).map(Number));
|
|
53
|
+
const alias = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const pair of (script.getAttribute("b-alias") ?? "").split(",").filter(Boolean)) {
|
|
55
|
+
const [from, to] = pair.split(":").map(Number);
|
|
56
|
+
alias.set(from, to);
|
|
57
|
+
}
|
|
58
|
+
const kept = (id) => {
|
|
59
|
+
for (let current = id; current !== void 0;) {
|
|
60
|
+
if (roots.has(current)) return true;
|
|
61
|
+
const record = value[current];
|
|
62
|
+
current = record?.p ?? record?.o;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
};
|
|
66
|
+
const resolve = (id) => id === void 0 ? void 0 : alias.get(id) ?? id;
|
|
67
|
+
const result = {};
|
|
68
|
+
for (const [key, record] of Object.entries(value)) if (kept(Number(key))) result[Number(key)] = {
|
|
69
|
+
...record,
|
|
70
|
+
p: resolve(record.p),
|
|
71
|
+
o: resolve(record.o)
|
|
72
|
+
};
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Settles once the core reads records with this module, with the function
|
|
77
|
+
* that forgets the page before navigation replaces it, or only stops reading
|
|
78
|
+
* when layouts stay.
|
|
79
|
+
*/
|
|
80
|
+
const ready = import("./runtime/client.js").then(({ ElementReference, FunctionReference, hooks, leavePage, leaveRoutes, removeScope, scopes }) => {
|
|
81
|
+
const core = {
|
|
82
|
+
ElementReference,
|
|
83
|
+
FunctionReference,
|
|
84
|
+
hooks,
|
|
85
|
+
removeScope,
|
|
86
|
+
scopes
|
|
87
|
+
};
|
|
88
|
+
hooks.record = (script, state) => routeRecord(core, script, state);
|
|
89
|
+
return (partial) => partial ? leaveRoutes() : leavePage();
|
|
90
|
+
});
|
|
91
|
+
//#endregion
|
|
92
|
+
export { ready };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=client-routes-DakuM32C.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-routes-DakuM32C.js","names":[],"sources":["../src/runtime/client-routes.ts"],"sourcesContent":["// What the core needs to read the pages that client navigation adds. Only\n// `navigate.ts` writes the attributes that this module reads, so the loader\n// imports it when it navigates or finds such a record, and a page that never\n// navigates does not load it. Importing it sets the core's `record` hook.\n//\n// It reads the core with `import()`, as `rpc.ts` does, and imports nothing\n// else. A static import of the core would make the package build move the\n// core into a chunk behind a module that only re-exports it, and a static\n// import of `shared.ts` would split that module out of the core of a page.\n// The core is loaded already, or loads with this module.\n\nimport type * as Client from './client.ts';\nimport type { Scope } from './client.ts';\nimport type { PageState, ScopeState } from './shared.ts';\n\n/** The parts of the core that this module uses. */\ntype Core = Pick<\n typeof Client,\n 'ElementReference' | 'FunctionReference' | 'hooks' | 'removeScope' | 'scopes'\n>;\n\n/** Adds a number to the scope IDs of a state record. */\nfunction shiftState(core: Core, state: PageState, by: number): PageState {\n const { ElementReference, FunctionReference } = core;\n const seen = new Set<object>();\n // References to elements and client functions name the scope of their markup.\n const shiftValue = (value: unknown): unknown => {\n if (value instanceof ElementReference) {\n return new ElementReference(value.scope + by, value.anchor);\n }\n if (value instanceof FunctionReference) {\n return new FunctionReference(value.ref, value.scope + by);\n }\n // A later record settles it, with a value whose IDs move too.\n if (value instanceof Promise) {\n return value.then(shiftValue);\n }\n if (typeof value === 'object' && value !== null && !seen.has(value)) {\n seen.add(value);\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n value[index] = shiftValue(item);\n });\n } else if (Object.getPrototypeOf(value) === Object.prototype) {\n for (const [key, item] of Object.entries(value)) {\n (value as Record<string, unknown>)[key] = shiftValue(item);\n }\n }\n }\n return value;\n };\n const result: PageState = {};\n for (const [key, record] of Object.entries(state)) {\n result[Number(key) + by] = {\n ...record,\n p: record.p === undefined ? undefined : record.p + by,\n o: record.o === undefined ? undefined : record.o + by,\n c:\n record.c &&\n Object.fromEntries(Object.entries(record.c).map(([anchor, id]) => [anchor, id + by])),\n s: record.s?.map(shiftValue),\n };\n }\n return result;\n}\n\n/** Removes scopes and the scopes inside them, and runs their cleanups. */\nfunction dropScopes(core: Core, roots: Set<number>): void {\n const inside = (scope: Scope): boolean => {\n for (let current: Scope | undefined = scope; current; current = current.p ?? current.o) {\n if (roots.has(current.id)) {\n return true;\n }\n }\n return false;\n };\n // Deleting from a map while iterating it is safe.\n for (const scope of core.scopes.values()) {\n if (inside(scope)) {\n core.removeScope(scope);\n }\n }\n}\n\n/**\n * Reads the attributes that navigation set on a state record. A page whose\n * IDs started at another number, such as a prerendered file, has them moved\n * with `b-offset`. A page that replaced only some routes of the one before\n * it drops the old routes with `b-drop`, and adds only the scopes inside\n * `b-roots`, with the scopes of the kept layouts in place of the new\n * page's copies of them, by `b-alias`.\n */\nfunction routeRecord(core: Core, script: Element, state: PageState): PageState {\n // Only records with scopes hold IDs. Later records settle promises, which `shiftState` wraps.\n const offset = Number(script.getAttribute('b-offset') ?? 0);\n const value = offset ? shiftState(core, state, offset) : state;\n const drop = script.getAttribute('b-drop');\n if (drop) {\n dropScopes(core, new Set(drop.split(',').map(Number)));\n }\n const list = script.getAttribute('b-roots');\n if (list === null) {\n return value;\n }\n const roots = new Set(list.split(',').filter(Boolean).map(Number));\n const alias = new Map<number, number>();\n for (const pair of (script.getAttribute('b-alias') ?? '').split(',').filter(Boolean)) {\n const [from, to] = pair.split(':').map(Number) as [number, number];\n alias.set(from, to);\n }\n const kept = (id: number): boolean => {\n for (let current: number | undefined = id; current !== undefined;) {\n if (roots.has(current)) {\n return true;\n }\n const record: ScopeState | undefined = value[current];\n current = record?.p ?? record?.o;\n }\n return false;\n };\n const resolve = (id: number | undefined): number | undefined =>\n id === undefined ? undefined : (alias.get(id) ?? id);\n const result: PageState = {};\n for (const [key, record] of Object.entries(value)) {\n // The new page renders the kept layouts again. Their scopes are not added.\n if (kept(Number(key))) {\n result[Number(key)] = { ...record, p: resolve(record.p), o: resolve(record.o) };\n }\n }\n return result;\n}\n\n/**\n * Settles once the core reads records with this module, with the function\n * that forgets the page before navigation replaces it, or only stops reading\n * when layouts stay.\n */\nexport const ready: Promise<(partial: boolean) => void> = import('./client.ts').then(\n ({ ElementReference, FunctionReference, hooks, leavePage, leaveRoutes, removeScope, scopes }) => {\n const core = { ElementReference, FunctionReference, hooks, removeScope, scopes };\n hooks.record = (script, state) => routeRecord(core, script, state);\n return (partial) => (partial ? leaveRoutes() : leavePage());\n },\n);\n"],"mappings":"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"}
|
|
@@ -29,9 +29,20 @@ function serializeCookie(name, value, options = {}) {
|
|
|
29
29
|
parts.push(`SameSite=${(options.sameSite ?? "lax").replace(/^./, (letter) => letter.toUpperCase())}`);
|
|
30
30
|
return parts.join("; ");
|
|
31
31
|
}
|
|
32
|
+
/** The parsed `cookie` header of each event, with the header it was parsed from. */
|
|
33
|
+
const parsed = /* @__PURE__ */ new WeakMap();
|
|
32
34
|
/** The cookies of the request, with the ones that this request set or deleted. */
|
|
33
35
|
function getCookies(event) {
|
|
34
|
-
const
|
|
36
|
+
const header = event.request.headers.get("cookie");
|
|
37
|
+
let cached = parsed.get(event);
|
|
38
|
+
if (cached?.header !== header) {
|
|
39
|
+
cached = {
|
|
40
|
+
header,
|
|
41
|
+
cookies: parseCookies(header)
|
|
42
|
+
};
|
|
43
|
+
parsed.set(event, cached);
|
|
44
|
+
}
|
|
45
|
+
const result = { ...cached.cookies };
|
|
35
46
|
for (const [name, value] of event.cookies ?? []) if (value === void 0) delete result[name];
|
|
36
47
|
else result[name] = value;
|
|
37
48
|
return result;
|
|
@@ -48,17 +59,16 @@ function setCookie(event, name, value, options = {}) {
|
|
|
48
59
|
}
|
|
49
60
|
/** Deletes a cookie. Pass the `path` and `domain` that it was set with, if they were not the defaults. */
|
|
50
61
|
function deleteCookie(event, name, options = {}) {
|
|
51
|
-
|
|
52
|
-
event.headers.append("set-cookie", serializeCookie(name, "", {
|
|
62
|
+
setCookie(event, name, "", {
|
|
53
63
|
...options,
|
|
54
|
-
secure,
|
|
64
|
+
secure: void 0,
|
|
55
65
|
maxAge: 0,
|
|
56
66
|
expires: /* @__PURE__ */ new Date(0)
|
|
57
|
-
})
|
|
58
|
-
event.cookies ??= /* @__PURE__ */ new Map();
|
|
67
|
+
});
|
|
59
68
|
event.cookies.set(name, void 0);
|
|
60
69
|
}
|
|
61
70
|
const encoder = new TextEncoder();
|
|
71
|
+
const decoder = new TextDecoder();
|
|
62
72
|
const keys = /* @__PURE__ */ new Map();
|
|
63
73
|
function key(secret) {
|
|
64
74
|
let promise = keys.get(secret);
|
|
@@ -113,7 +123,7 @@ function createSession(options) {
|
|
|
113
123
|
}
|
|
114
124
|
if (!(await Promise.all(secrets.map(async (secret) => crypto.subtle.verify("HMAC", await key(secret), signature, encoder.encode(payload))))).includes(true)) return;
|
|
115
125
|
try {
|
|
116
|
-
const { d: data, e: expires } = JSON.parse(
|
|
126
|
+
const { d: data, e: expires } = JSON.parse(decoder.decode(fromBase64Url(payload)));
|
|
117
127
|
return expires > Date.now() ? data : void 0;
|
|
118
128
|
} catch {
|
|
119
129
|
return;
|
|
@@ -162,4 +172,4 @@ function toNodeHeaders(headers) {
|
|
|
162
172
|
//#endregion
|
|
163
173
|
export { serializeCookie as a, parseCookies as i, deleteCookie as n, setCookie as o, getCookies as r, toNodeHeaders as s, createSession as t };
|
|
164
174
|
|
|
165
|
-
//# sourceMappingURL=cookies-
|
|
175
|
+
//# sourceMappingURL=cookies-Av5WFmcf.js.map
|