brumate 0.2.0 → 0.4.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 (138) hide show
  1. package/README.md +2 -2
  2. package/check.d.ts +49 -0
  3. package/dist/{boot-D-IdPy7B.d.ts → boot-DLlRmD9z.d.ts} +11 -10
  4. package/dist/cli.js +275 -15
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client-BvDsC6Qr.js +3463 -0
  7. package/dist/client-BvDsC6Qr.js.map +1 -0
  8. package/dist/client-DBwL2wKQ.d.ts +669 -0
  9. package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
  10. package/dist/client-routes-BtGpYCef.js.map +1 -0
  11. package/dist/{cookies-Av5WFmcf.js → cookies-Cnbf4w-S.js} +15 -7
  12. package/dist/cookies-Cnbf4w-S.js.map +1 -0
  13. package/dist/{defer-D0bo1Gqx.js → defer-CKWZLv2K.js} +8 -4
  14. package/dist/defer-CKWZLv2K.js.map +1 -0
  15. package/dist/devtools-4uTPwR_v.js +597 -0
  16. package/dist/devtools-4uTPwR_v.js.map +1 -0
  17. package/dist/devtools-panel-Be9pxYgv.js +1994 -0
  18. package/dist/devtools-panel-Be9pxYgv.js.map +1 -0
  19. package/dist/events-LgLdp1R7.js +114 -0
  20. package/dist/events-LgLdp1R7.js.map +1 -0
  21. package/dist/features-CHY5Ekku.js +30 -0
  22. package/dist/features-CHY5Ekku.js.map +1 -0
  23. package/dist/files-WW4RlajL.js +506 -0
  24. package/dist/files-WW4RlajL.js.map +1 -0
  25. package/dist/forms-j1xPAR14.d.ts +281 -0
  26. package/dist/forms-nXK7-Lv_.js +440 -0
  27. package/dist/forms-nXK7-Lv_.js.map +1 -0
  28. package/dist/highlight.d.ts +17 -0
  29. package/dist/highlight.js +278 -0
  30. package/dist/highlight.js.map +1 -0
  31. package/dist/html-BtKRyi7g.js +305 -0
  32. package/dist/html-BtKRyi7g.js.map +1 -0
  33. package/dist/html-Bw9Qwu6F.d.ts +107 -0
  34. package/dist/index.d.ts +142 -11
  35. package/dist/index.js +641 -106
  36. package/dist/index.js.map +1 -1
  37. package/dist/{inspect-BJtACnQp.js → inspect-Y6y4uNZp.js} +4333 -681
  38. package/dist/inspect-Y6y4uNZp.js.map +1 -0
  39. package/dist/{loader-B18i3_-T.js → loader-BjKGJzLN.js} +21 -14
  40. package/dist/loader-BjKGJzLN.js.map +1 -0
  41. package/dist/logo-DQ_OYhBi.js +10 -0
  42. package/dist/logo-DQ_OYhBi.js.map +1 -0
  43. package/dist/{navigate-BwuZveDF.js → navigate-CfOr-TRF.js} +130 -24
  44. package/dist/navigate-CfOr-TRF.js.map +1 -0
  45. package/dist/nesting-DA5vJw9X.js +265 -0
  46. package/dist/nesting-DA5vJw9X.js.map +1 -0
  47. package/dist/produce-B7X9ori9.js +402 -0
  48. package/dist/produce-B7X9ori9.js.map +1 -0
  49. package/dist/produce-DIgHBVwL.d.ts +148 -0
  50. package/dist/{rpc-B-Zkn6Ch.js → rpc-Q-XkLwFh.js} +28 -13
  51. package/dist/rpc-Q-XkLwFh.js.map +1 -0
  52. package/dist/runtime/batch.js +9 -7
  53. package/dist/runtime/batch.js.map +1 -1
  54. package/dist/runtime/client.d.ts +4 -4
  55. package/dist/runtime/client.js +4 -4
  56. package/dist/runtime/devtools.d.ts +172 -5
  57. package/dist/runtime/devtools.js +3 -1
  58. package/dist/runtime/env.js +14 -2
  59. package/dist/runtime/env.js.map +1 -1
  60. package/dist/runtime/events.d.ts +38 -1
  61. package/dist/runtime/events.js +1 -1
  62. package/dist/runtime/forms.d.ts +2 -0
  63. package/dist/runtime/forms.js +1 -0
  64. package/dist/runtime/gather.d.ts +25 -0
  65. package/dist/runtime/gather.js +33 -0
  66. package/dist/runtime/gather.js.map +1 -0
  67. package/dist/runtime/hot.d.ts +1 -1
  68. package/dist/runtime/hot.js +5 -2
  69. package/dist/runtime/hot.js.map +1 -1
  70. package/dist/runtime/html.d.ts +2 -2
  71. package/dist/runtime/html.js +1 -1
  72. package/dist/runtime/loader.d.ts +2 -2
  73. package/dist/runtime/loader.js +2 -2
  74. package/dist/runtime/routes.js +4 -1
  75. package/dist/runtime/routes.js.map +1 -1
  76. package/dist/runtime/server.d.ts +5 -4
  77. package/dist/runtime/server.js +5 -5
  78. package/dist/runtime/signals.d.ts +75 -2
  79. package/dist/runtime/signals.js +44 -2
  80. package/dist/runtime/signals.js.map +1 -1
  81. package/dist/runtime/static-loader.d.ts +2 -2
  82. package/dist/runtime/static-loader.js +1 -1
  83. package/dist/runtime/testing.d.ts +18 -3
  84. package/dist/runtime/testing.js +150 -33
  85. package/dist/runtime/testing.js.map +1 -1
  86. package/dist/runtime/values.d.ts +2 -0
  87. package/dist/runtime/values.js +24 -0
  88. package/dist/runtime/values.js.map +1 -0
  89. package/dist/{server-BA9SJ2Vm.d.ts → server-BvPIg9pT.d.ts} +363 -32
  90. package/dist/{server-BqfM95r1.js → server-DjyOVJtJ.js} +1309 -220
  91. package/dist/server-DjyOVJtJ.js.map +1 -0
  92. package/dist/{static-loader-BzE9SRaj.d.ts → static-loader-BGgdp_Y5.d.ts} +2 -2
  93. package/dist/static-loader-BZR17hSw.js +312 -0
  94. package/dist/static-loader-BZR17hSw.js.map +1 -0
  95. package/dist/{stream-JaMHMdBD.js → stream-BP5AVmg5.js} +182 -17
  96. package/dist/stream-BP5AVmg5.js.map +1 -0
  97. package/dist/values-B8C7CLvG.d.ts +63 -0
  98. package/dist/vite.d.ts +20 -20
  99. package/dist/vite.js +2031 -539
  100. package/dist/vite.js.map +1 -1
  101. package/elements.d.ts +951 -0
  102. package/forms/forms.brm.ts +141 -0
  103. package/package.json +41 -3
  104. package/skills/brumate/SKILL.md +58 -0
  105. package/skills/brumate/references/errors.md +2078 -0
  106. package/skills/brumate/references/events.md +117 -0
  107. package/skills/brumate/references/signals.md +61 -0
  108. package/skills/brumate/references/state.md +235 -0
  109. package/skills/brumate/references/syntax.md +250 -0
  110. package/types.d.ts +4 -4
  111. package/dist/client-C0UCNL3J.js +0 -1643
  112. package/dist/client-C0UCNL3J.js.map +0 -1
  113. package/dist/client-MD0ZmcFR.d.ts +0 -354
  114. package/dist/client-routes-JTbGtukf.js.map +0 -1
  115. package/dist/cookies-Av5WFmcf.js.map +0 -1
  116. package/dist/defer-D0bo1Gqx.js.map +0 -1
  117. package/dist/devtools-C50VH8gZ.js +0 -113
  118. package/dist/devtools-C50VH8gZ.js.map +0 -1
  119. package/dist/devtools-panel-AYjfwPhj.js +0 -435
  120. package/dist/devtools-panel-AYjfwPhj.js.map +0 -1
  121. package/dist/events-BKWRqtMg.js +0 -52
  122. package/dist/events-BKWRqtMg.js.map +0 -1
  123. package/dist/files-Bnn1JqHx.js +0 -192
  124. package/dist/files-Bnn1JqHx.js.map +0 -1
  125. package/dist/html-bHZbkK-h.js +0 -170
  126. package/dist/html-bHZbkK-h.js.map +0 -1
  127. package/dist/html-y1q7-t7D.d.ts +0 -60
  128. package/dist/inspect-BJtACnQp.js.map +0 -1
  129. package/dist/loader-B18i3_-T.js.map +0 -1
  130. package/dist/navigate-BwuZveDF.js.map +0 -1
  131. package/dist/produce-CWfJ4byV.js +0 -167
  132. package/dist/produce-CWfJ4byV.js.map +0 -1
  133. package/dist/produce-D4K7qpaL.d.ts +0 -72
  134. package/dist/rpc-B-Zkn6Ch.js.map +0 -1
  135. package/dist/server-BqfM95r1.js.map +0 -1
  136. package/dist/static-loader-DOygOFj5.js +0 -216
  137. package/dist/static-loader-DOygOFj5.js.map +0 -1
  138. package/dist/stream-JaMHMdBD.js.map +0 -1
@@ -1,354 +0,0 @@
1
- import { t as Raw } from "./html-y1q7-t7D.js";
2
- import { a as PageState, n as ElementReference, o as ScopeId } from "./produce-D4K7qpaL.js";
3
- import { t as Context } from "./context-btHuB01Z.js";
4
- //#region src/runtime/client.d.ts
5
- type Update = [kind: number, name: string];
6
- /** The entry of a compiled client module. */
7
- interface ClientModule {
8
- id: string;
9
- /** Prop names to slot indices. `*` is the slot of a props object. */
10
- props: Record<string, number>;
11
- /** Scope kind, then slot, to the updates that read it. */
12
- g: Record<number, Record<number, Update[]>>;
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>;
18
- /** Server function ID to the memos that call it, as scope kind and update, for `refresh`. */
19
- refresh?: Record<string, Update[]>;
20
- /**
21
- * The `#try` blocks that catch errors of client code, by the scope kinds
22
- * inside their bodies: the kind of the scope that holds the block, the
23
- * anchor of the block, the render functions of the body and the `#catch`
24
- * body, and the kinds of both bodies.
25
- */
26
- t?: Record<number, [owner: number, anchor: number, body: string, fallback: string, kinds: number[]]>;
27
- }
28
- /** A part of a client module: one client root, or the updates. */
29
- type Part = Record<string, unknown>;
30
- /** The instance of a scope in the page. */
31
- interface Scope {
32
- id: ScopeId;
33
- /** The scope's ID in the compiled component. */
34
- k: number;
35
- p?: Scope;
36
- /** The component ID, for a component's root scope. */
37
- m?: string;
38
- s: unknown[];
39
- /** The item of a list item scope. */
40
- i?: unknown;
41
- c?: Record<number, ScopeId>;
42
- /** The scope that rendered a component's root scope. */
43
- o?: Scope;
44
- /** For children that a component inserted, the scope where they are, for contexts. */
45
- t?: Scope;
46
- /** The values that the scope provides, by context key. */
47
- v?: Record<string, unknown>;
48
- /** The slots that hold the contexts that the scope reads, by context key. */
49
- x?: Record<string, number>;
50
- children: Set<Scope>;
51
- /** The `b-root` of the render that the server rendered the scope in. */
52
- r?: string;
53
- cleanups?: Map<string, () => void>;
54
- keys?: Map<number, unknown>;
55
- /** Set while the scope is the body of an `#offscreen` block that is hidden. */
56
- h?: HiddenBody;
57
- /** Effects and `$client` callbacks to run when the `#offscreen` body around the scope shows. */
58
- w?: Set<string>;
59
- }
60
- interface CoreOptions {
61
- /**
62
- * Imports the client module of a component. Undefined for a component that
63
- * has no client code, which a build leaves out.
64
- */
65
- load: (id: string) => Promise<ClientModule> | undefined;
66
- /** Adds event listeners for the `b-on` attributes in new markup. */
67
- listen: (root: ParentNode) => void;
68
- /** The URL prefix of server function calls. Defaults to `/_brumate`. */
69
- rpc?: string;
70
- /** The ID of the build of the page, for skew protection. Calls send it, and a deploy is noticed. */
71
- build?: string;
72
- /**
73
- * Receives every error of client code first: of a handler, an effect, a
74
- * `$client` callback or a memo that loads. `scope` is the ID of the scope
75
- * that the code belongs to, when it has one.
76
- */
77
- onError?: (error: unknown, info: {
78
- scope?: ScopeId;
79
- }) => void;
80
- }
81
- /** The URL prefix of server function calls, from the options. */
82
- declare let rpcPrefix: string;
83
- /** The ID of the build of the page, from the loader. Undefined on the dev server. */
84
- declare let build: string | undefined;
85
- /**
86
- * Tells the page that the site changed since it loaded: a call answered 409
87
- * with another build, or the code of a handler is gone. The loader then
88
- * loads the next page in full, and an app can save a draft first.
89
- */
90
- declare function skew(reason: "call" | "code" | "defer"): void;
91
- /** The scopes of the page, by ID. */
92
- declare const scopes: Map<ScopeId, Scope>;
93
- /** What modules of optional features add to the core. See `client-routes.ts` and `hot`. */
94
- declare const hooks: {
95
- /** Changes a state record before its scopes are added, such as for a page that navigation added. */
96
- record?: (script: Element, state: PageState) => PageState;
97
- /** Runs after the scopes of a state record are added. */
98
- added?: (added: Scope[]) => void;
99
- };
100
- /** What the devtools overlay hears from the core. It is set only in development. */
101
- interface DevtoolsHooks {
102
- /** The core started, with the scopes of the page, and a way to write a slot, as a handler does. */
103
- attach?(core: {
104
- scopes: Map<ScopeId, Scope>;
105
- set: (scope: Scope, slot: number, value: unknown) => void;
106
- }): void;
107
- /** A handler starts for an event. */
108
- handler?(ref: string, element: Element, event?: Event): void;
109
- /** A part of a component's client code loaded. */
110
- part?(component: string, name: string): void;
111
- /** A slot got a new value. */
112
- write?(scope: Scope, slot: number, value: unknown): void;
113
- }
114
- /** The global key of the devtools hooks. */
115
- declare const DEVTOOLS: unique symbol;
116
- /** Stops reading state records and markers that arrive later. Later records wait for `init`. */
117
- declare function dispose(): void;
118
- /**
119
- * Stops reading, before client navigation replaces only some routes. The
120
- * server renders the new routes with its current values, so only the writes
121
- * that come after count for the records that stream in later.
122
- */
123
- declare function leaveRoutes(): void;
124
- /**
125
- * Removes the scopes of a render, by its `b-root`, with the scopes inside
126
- * them. Their cleanups run, and their memos no longer load. Its markup
127
- * stays. `brumate/testing` calls it when a mounted component unmounts.
128
- */
129
- declare function removeRoot(root: string): void;
130
- /**
131
- * Forgets the code of components that changed on the dev server, so the next
132
- * event or update loads the new code. Their state stays. `brumate/hot` calls it.
133
- */
134
- declare function forget(ids: string[]): void;
135
- /**
136
- * Keeps the values of the signals of each instance of a component, by
137
- * name, before the page renders again with its new markup. `brumate/hot` calls it.
138
- */
139
- declare function remount(detail: {
140
- id: string;
141
- before: Record<number, string[]>;
142
- after: Record<number, string[]>;
143
- signals: string[];
144
- }[]): void;
145
- /**
146
- * Forgets the page, before another page replaces it. Cleanups run. Loaded
147
- * modules and parts stay, so the next page does not load them again. Only
148
- * client navigation calls it.
149
- */
150
- declare function leavePage(): void;
151
- /** Reads the page state. The loader calls it once, before the first handler. */
152
- declare function init(value: CoreOptions): void;
153
- declare function loadModule(id: string): Promise<ClientModule>;
154
- declare function loadPart(module: ClientModule, name: string): Promise<Part>;
155
- /**
156
- * Runs the handler `ref` for an element. The scope comes from the element's
157
- * `b-b` anchor, or from the nearest element around it that has one, which
158
- * the compiler checks is in the same scope.
159
- */
160
- declare function handle(element: Element, entry: string, event?: Event): Promise<unknown>;
161
- /**
162
- * Reports an error of client code: a handler, an effect, a `$client`
163
- * callback or a memo that loads. It renders the `#catch` body of the nearest
164
- * `#try` around the scope of the code, through the parents and the owners of
165
- * scopes. Without one, the page gets a `brumate:error` event on `window`,
166
- * with the error and the scope, and the error is logged.
167
- */
168
- declare function fail(scope: Scope | undefined, error: unknown): void;
169
- /** Returns the instance of a scope by its ID. */
170
- declare function scopeOf(id: ScopeId): Scope | undefined;
171
- declare function get(scope: Scope, slot: number): any;
172
- declare function set<T>(scope: Scope, slot: number, value: T): T;
173
- /**
174
- * The names of a call of a module function, for its shared code. Each ref
175
- * is a slot of `scope`, `[scope, slot]` for a slot of another scope, or
176
- * `[value]` for a value that does not change, such as a literal argument.
177
- */
178
- declare function cells(scope: Scope, links: unknown[], names: string[]): Record<string, unknown>;
179
- /**
180
- * Computes a memo of `$debounced` after its value stops changing for `ms`,
181
- * or one of `$throttled` at most once every `ms`, with the last value after
182
- * the wait. The memo is pending while it waits.
183
- */
184
- declare function timed(scope: Scope, slot: number, ms: number, throttle: boolean, compute: () => unknown): void;
185
- /**
186
- * Writes the result of an async memo when it arrives. Until then the slot
187
- * keeps its value, and `pending` is true. Only the latest load is written.
188
- */
189
- declare function asyncMemo(scope: Scope, slot: number, promise: Promise<unknown>): void;
190
- /**
191
- * Computes a memo. A promise loads, and the memo keeps its value until it
192
- * settles. A memo that reads a value that is still loading keeps its value
193
- * too, and is pending until that value arrives and the memo computes again.
194
- */
195
- declare function memo(scope: Scope, slot: number, compute: () => unknown): void;
196
- /**
197
- * Writes a guess into an optimistic value. It goes back to its source when
198
- * the source changes, which computes it again, or when every server call of
199
- * the page finishes, such as after a post failed.
200
- */
201
- declare function guess<T>(scope: Scope, slot: number, ...rest: [value: T] | [sourceScope: Scope, sourceSlot: number, value: T]): T;
202
- /** Counts a server call, and puts guesses back when the last one finishes. */
203
- declare function track<T>(request: Promise<T>): Promise<T>;
204
- /** True while a new value of a memo loads, or while the server still streams its value. */
205
- declare function pending(scope: Scope, slot: number): boolean;
206
- /** `x++`, `x--`, `++x` and `--x`. */
207
- declare function update(scope: Scope, slot: number, delta: number, prefix: boolean): number;
208
- declare function descendants(scope: Scope, kind: number, result?: Scope[]): Scope[];
209
- /**
210
- * Removes a scope from the page: its cleanups run, and its memo state goes,
211
- * so a load that settles later is not written. Its markup stays.
212
- */
213
- declare function removeScope(scope: Scope): void;
214
- /**
215
- * Renders a `#portal` body into its target, between markers with its scope
216
- * ID. `kinds` names the body, so a new target first removes it from the old one.
217
- */
218
- declare function portalTo(scope: Scope, target: unknown, render: Render, kinds?: number[]): void;
219
- /** Writes an inserted value between `<!--t…-->` and `<!--/t-->`. */
220
- declare function text(scope: Scope, anchor: number, value: unknown): void;
221
- /** Writes an inserted value that is the whole content of the element with the anchor. */
222
- declare function content(scope: Scope, anchor: number, value: unknown): void;
223
- /**
224
- * Writes the text of an element whose content is text, such as a `<textarea>`
225
- * or a `<title>`. A `<textarea>` gets the value too, as `value` does on an
226
- * `<input>`, so a change replaces what the user typed.
227
- */
228
- declare function writeText(scope: Scope, anchor: number, value: unknown): void;
229
- declare function attr(scope: Scope, anchor: number, name: string, value: unknown): void;
230
- declare function attrs(scope: Scope, anchor: number, values: Record<string, unknown>, own?: string[]): void;
231
- type Render = (parent: Scope, item?: unknown, index?: number) => string;
232
- /** Shows the branch at `index` of `#if` or `#switch`, or nothing for -1. */
233
- declare function branch(scope: Scope, anchor: number, index: number, renders: (Render | undefined)[], kinds: number[]): void;
234
- /** Renders the body of `#key` again when its value changes. */
235
- declare function rekey(scope: Scope, anchor: number, value: unknown, render: Render, kinds: number[]): void;
236
- /**
237
- * Renders the body of a `#try` block again, for its `reset` function. If the
238
- * body throws, the fallback renders again with the error.
239
- */
240
- declare function reset(scope: Scope, anchor: number, id: string, body: string, fallback: string, kinds: number[]): Promise<void>;
241
- /**
242
- * Renders the body of a `#client` block once, in place of its fallback.
243
- * `kinds` are the scope IDs inside the fallback, whose instances go.
244
- */
245
- declare function fill(scope: Scope, anchor: number, render: Render, kinds?: number[]): void;
246
- /**
247
- * Shows or hides the body of an `#offscreen` block. A body that the page
248
- * does not have yet renders the first time it shows. `kind` is the body's
249
- * scope ID in the compiled component.
250
- */
251
- declare function offscreen(scope: Scope, anchor: number, value: unknown, render: Render, kind: number): void;
252
- /** A hidden `#offscreen` body: its scope, and the ranges of its markup and of its portals. */
253
- interface HiddenBody {
254
- scope: Scope;
255
- ranges: [start: Comment, end: Comment][];
256
- }
257
- /** Updates the items of `#for` or `#repeat`, keeping the elements of items whose keys stay. */
258
- 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;
259
- /** Sets a style variable on the top-level elements of a component instance. */
260
- declare function setVar(scope: Scope, name: string, value: unknown): void;
261
- /** Writes a provided value, and the slot of every scope that reads it from this provider. */
262
- declare function updateContext(scope: Scope, context: Context<unknown>, value: unknown): void;
263
- /** Sets the title of the page. */
264
- declare function title(value: unknown): void;
265
- /** Writes a prop of a child component. */
266
- declare function prop(scope: Scope, anchor: number, name: string, value: unknown): void;
267
- /** Runs an effect or a `$client` callback, after the cleanup of its previous run. */
268
- declare function effect(scope: Scope, name: string, callback: () => unknown): void;
269
- /** Renders the attributes of a form or button that posts to a server function. */
270
- declare function action(name: string, id: string, method?: string, result?: string): string;
271
- /**
272
- * Sends a form of an `$action`. The code is in `rpc.ts`, which every server
273
- * call loads, so the core holds only this.
274
- */
275
- declare function submitAction(form: HTMLFormElement, submitter: HTMLElement | null): void;
276
- /** Calls a server function. */
277
- declare function rpc(id: string, args: unknown[]): Promise<unknown>;
278
- /** Renders a value inserted in markup. Children render here, at `scope`, for their contexts. */
279
- declare function insert(value: unknown, _ctx?: unknown, scope?: Scope | ScopeId): string;
280
- /**
281
- * Children of a component that the client renders. They render where the
282
- * component inserts them, so they read the contexts that it provides. `from`
283
- * is the scope of the markup that wrote them.
284
- */
285
- declare class Children {
286
- private readonly from;
287
- private readonly html;
288
- constructor(from: Scope | ScopeId | undefined, html: () => string);
289
- render(at: Scope | undefined): string;
290
- }
291
- /** The children of a component that the client renders. See `Children`. */
292
- declare function children(from: Scope | ScopeId | undefined, html: () => string): Children;
293
- /** A component's client render function, from its `?brumate-render` module. */
294
- type Component<P = any> = (props: P) => string;
295
- /**
296
- * Renders a child component on the client. With `scope` and `anchor`,
297
- * records the child's scope so the parent can update its props.
298
- */
299
- declare function component<P>(Child: Component<P>, props: P, _ctx?: unknown, scope?: Scope | number, anchor?: number): string;
300
- declare function dynamic(tag: unknown, attributes: Record<string, unknown>, inner: Raw | Children | undefined, _ctx?: unknown, scope?: Scope | number): string;
301
- /** Work that waits until rendered markup is in the page. */
302
- declare const afterInsert: (() => void)[];
303
- /** Creates a scope for markup that the client renders, and returns its ID. */
304
- declare function createScope(kind: number, parent?: Scope | ScopeId, module?: string): number;
305
- /**
306
- * The ID that `$id()` makes, as the server does. Client scope IDs are
307
- * negative, so they differ from the server's.
308
- */
309
- declare function makeId(scope: Scope | ScopeId, index: number): string;
310
- /** Sets the owner of the next component's root scope. */
311
- declare function setOwner(scope: Scope | ScopeId): void;
312
- /** Provides a value of a context to the scopes inside `scope`. */
313
- declare function provideValue<T>(context: Context<T>, value: T, scope: Scope | ScopeId): void;
314
- /** Reads a context, and records its slot so that changes to the provided value reach it. */
315
- declare function consumeContext<T>(context: Context<T>, scope: Scope | ScopeId, slot?: number): T;
316
- /**
317
- * Writes a context that the runtime provides to the whole page, and the
318
- * slot of every scope that reads it without a provider above it.
319
- */
320
- declare function setGlobal(key: string, value: unknown): void;
321
- /** Reads the route of the page again, after navigation changed it. */
322
- declare function updateRoute(): void;
323
- declare function setSlots(id: ScopeId, values: unknown[]): void;
324
- declare function setItem(id: ScopeId, value: unknown): void;
325
- declare function elementAt(scope: ScopeId, anchor: number): ElementReference;
326
- /**
327
- * Warns in development that the browser renders a `#defer` block of a
328
- * component, such as inside a `#client` body of its parent. Only the server
329
- * renders the body, so the fallback stays.
330
- */
331
- declare function deferInBrowser(id: string): void;
332
- /** Adds the markup of a `#head` block to the document's head. */
333
- declare function addHead(html: string): void;
334
- /** Adds the markup of a `#portal` block at the end of the page, after the markup around it. */
335
- declare function addPortal(html: string): void;
336
- /** Adds a component's stylesheet to the page, if the server did not. */
337
- declare function addStyle(id: string, css: string): string;
338
- /** A function prop rendered on the client calls the parent's exported handler. */
339
- declare function handlerProp(value: unknown, ref: string, scope: Scope | number): unknown;
340
- /**
341
- * What the loader calls. It is one export, so the loader's import of the core
342
- * names one export, and a build keeps the rest only when components call them.
343
- */
344
- declare const loader: {
345
- init: typeof init;
346
- handle: typeof handle;
347
- dispose: typeof dispose;
348
- submitAction: typeof submitAction;
349
- setGlobal: typeof setGlobal;
350
- updateRoute: typeof updateRoute;
351
- };
352
- //#endregion
353
- export { provideValue as $, elementAt as A, insert as B, content as C, updateRoute as Ct, dispose as D, descendants as E, guess as F, loadPart as G, leaveRoutes as H, handle as I, memo as J, loader as K, handlerProp as L, fill as M, forget as N, dynamic as O, get as P, prop as Q, hooks as R, consumeContext as S, updateContext as St, deferInBrowser as T, list as U, leavePage as V, loadModule as W, pending as X, offscreen as Y, portalTo as Z, branch as _, text as _t, DevtoolsHooks as a, rpc as at, children as b, track as bt, Scope as c, scopes as ct, addPortal as d, setItem as dt, rekey as et, addStyle as f, setOwner as ft, attrs as g, submitAction as gt, attr as h, skew as ht, DEVTOOLS as i, reset as it, fail as j, effect as k, action as l, set as lt, asyncMemo as m, setVar as mt, Component as n, removeRoot as nt, HiddenBody as o, rpcPrefix as ot, afterInsert as p, setSlots as pt, makeId as q, CoreOptions as r, removeScope as rt, Part as s, scopeOf as st, ClientModule as t, remount as tt, addHead as u, setGlobal as ut, build as v, timed as vt, createScope as w, writeText as wt, component as x, update as xt, cells as y, title as yt, init as z };
354
- //# sourceMappingURL=client-MD0ZmcFR.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-routes-JTbGtukf.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, ScopeId, 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/** Reads an ID, as `parseId` in `shared.ts` does. This module imports no code of its own. */\nfunction readId(text: string): ScopeId {\n return /^-?\\d+$/.test(text) ? Number(text) : text;\n}\n\n/** Adds a number to an ID, as `shiftId` in `shared.ts` does. */\nfunction shiftId(id: ScopeId, by: number): ScopeId {\n if (typeof id === 'number') {\n return id + by;\n }\n const dot = id.indexOf('.');\n return `${Number(id.slice(0, dot)) + by}${id.slice(dot)}`;\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(shiftId(value.scope, by), value.anchor);\n }\n if (value instanceof FunctionReference) {\n return new FunctionReference(value.ref, shiftId(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[shiftId(readId(key), by)] = {\n ...record,\n p: record.p === undefined ? undefined : shiftId(record.p, by),\n o: record.o === undefined ? undefined : shiftId(record.o, by),\n c:\n record.c &&\n Object.fromEntries(\n Object.entries(record.c).map(([anchor, id]) => [anchor, shiftId(id, by)]),\n ),\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<ScopeId>): 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(readId)));\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(readId));\n const alias = new Map<ScopeId, ScopeId>();\n for (const pair of (script.getAttribute('b-alias') ?? '').split(',').filter(Boolean)) {\n const [from, to] = pair.split(':').map(readId) as [ScopeId, ScopeId];\n alias.set(from, to);\n }\n const kept = (id: ScopeId): boolean => {\n for (let current: ScopeId | 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: ScopeId | undefined): ScopeId | 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 const id = readId(key);\n if (kept(id)) {\n result[id] = { ...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":";;AAsBA,SAAS,OAAO,MAAuB;CACrC,OAAO,UAAU,KAAK,IAAI,IAAI,OAAO,IAAI,IAAI;AAC/C;;AAGA,SAAS,QAAQ,IAAa,IAAqB;CACjD,IAAI,OAAO,OAAO,UAChB,OAAO,KAAK;CAEd,MAAM,MAAM,GAAG,QAAQ,GAAG;CAC1B,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,MAAM,GAAG;AACxD;;AAGA,SAAS,WAAW,MAAY,OAAkB,IAAuB;CACvE,MAAM,EAAE,kBAAkB,sBAAsB;CAChD,MAAM,uBAAO,IAAI,IAAY;CAE7B,MAAM,cAAc,UAA4B;EAC9C,IAAI,iBAAiB,kBACnB,OAAO,IAAI,iBAAiB,QAAQ,MAAM,OAAO,EAAE,GAAG,MAAM,MAAM;EAEpE,IAAI,iBAAiB,mBACnB,OAAO,IAAI,kBAAkB,MAAM,KAAK,QAAQ,MAAM,OAAO,EAAE,CAAC;EAGlE,IAAI,iBAAiB,SACnB,OAAO,MAAM,KAAK,UAAU;EAE9B,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,KAAK,IAAI,KAAK,GAAG;GACnE,KAAK,IAAI,KAAK;GACd,IAAI,MAAM,QAAQ,KAAK,GACrB,MAAM,SAAS,MAAM,UAAU;IAC7B,MAAM,SAAS,WAAW,IAAI;GAChC,CAAC;QACI,IAAI,OAAO,eAAe,KAAK,MAAM,OAAO,WACjD,KAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,KAAK,GAC5C,MAAmC,OAAO,WAAW,IAA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,OAAO,CAAC,CAAC,IAAI,MAAM,CAAC;CACjE,MAAM,wBAAQ,IAAI,IAAsB;CACxC,KAAK,MAAM,SAAS,OAAO,aAAa,SAAS,KAAK,GAAA,CAAI,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,GAAG;EACpF,MAAM,CAAC,MAAM,MAAM,KAAK,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;EAC7C,MAAM,IAAI,MAAM,EAAE;CACpB;CACA,MAAM,QAAQ,OAAyB;EACrC,KAAK,IAAI,UAA+B,IAAI,YAAY,KAAA,IAAY;GAClE,IAAI,MAAM,IAAI,OAAO,GACnB,OAAO;GAET,MAAM,SAAiC,MAAM;GAC7C,UAAU,QAAQ,KAAK,QAAQ;EACjC;EACA,OAAO;CACT;CACA,MAAM,WAAW,OACf,OAAO,KAAA,IAAY,KAAA,IAAa,MAAM,IAAI,EAAE,KAAK;CACnD,MAAM,SAAoB,CAAC;CAC3B,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,KAAK,GAAG;EAEjD,MAAM,KAAK,OAAO,GAAG;EACrB,IAAI,KAAK,EAAE,GACT,OAAO,MAAM;GAAE,GAAG;GAAQ,GAAG,QAAQ,OAAO,CAAC;GAAG,GAAG,QAAQ,OAAO,CAAC;EAAE;CAEzE;CACA,OAAO;AACT;;;;;;AAOA,MAAa,QAA6C,OAAO,sBAAc,CAAC,MAC7E,EAAE,kBAAkB,mBAAmB,OAAO,WAAW,aAAa,aAAa,aAAa;CAC/F,MAAM,OAAO;EAAE;EAAkB;EAAmB;EAAO;EAAa;CAAO;CAC/E,MAAM,UAAU,QAAQ,UAAU,YAAY,MAAM,QAAQ,KAAK;CACjE,QAAQ,YAAa,UAAU,YAAY,IAAI,UAAU;AAC3D,CACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cookies-Av5WFmcf.js","names":[],"sources":["../src/runtime/cookies.ts"],"sourcesContent":["// Cookies and sessions, for server functions, rendering, middleware and\n// endpoints. They read the request of a `RequestEvent` and write `set-cookie`\n// headers on its response.\n\nimport type { RequestEvent } from './request.ts';\n\nexport interface CookieOptions {\n /** Seconds until the cookie expires. Without it, the cookie lasts until the browser closes. */\n maxAge?: number;\n expires?: Date;\n /** Defaults to `/`. */\n path?: string;\n domain?: string;\n /** Defaults to true when the request is HTTPS. */\n secure?: boolean;\n /** Keeps the cookie from browser code. Defaults to true. */\n httpOnly?: boolean;\n /** Defaults to `lax`. */\n sameSite?: 'strict' | 'lax' | 'none';\n}\n\n/** Reads the cookies of a `cookie` header. */\nexport function parseCookies(header: string | null): Record<string, string> {\n const result: Record<string, string> = {};\n for (const part of (header ?? '').split(';')) {\n const index = part.indexOf('=');\n if (index === -1) {\n continue;\n }\n const name = part.slice(0, index).trim();\n if (name && !(name in result)) {\n const value = part.slice(index + 1).trim();\n try {\n result[name] = decodeURIComponent(value);\n } catch {\n result[name] = value;\n }\n }\n }\n return result;\n}\n\n/** Writes a `set-cookie` header value. */\nexport function serializeCookie(name: string, value: string, options: CookieOptions = {}): string {\n if (!/^[\\w!#$%&'*+.^`|~-]+$/.test(name)) {\n throw new Error(`\"${name}\" is not a valid cookie name`);\n }\n const parts = [`${name}=${encodeURIComponent(value)}`, `Path=${options.path ?? '/'}`];\n if (options.maxAge !== undefined) {\n parts.push(`Max-Age=${Math.floor(options.maxAge)}`);\n }\n if (options.expires) {\n parts.push(`Expires=${options.expires.toUTCString()}`);\n }\n if (options.domain) {\n parts.push(`Domain=${options.domain}`);\n }\n if (options.httpOnly !== false) {\n parts.push('HttpOnly');\n }\n if (options.secure) {\n parts.push('Secure');\n }\n parts.push(\n `SameSite=${(options.sameSite ?? 'lax').replace(/^./, (letter) => letter.toUpperCase())}`,\n );\n return parts.join('; ');\n}\n\n/** The parsed `cookie` header of each event, with the header it was parsed from. */\nconst parsed = new WeakMap<\n RequestEvent,\n { header: string | null; cookies: Record<string, string> }\n>();\n\n/** The cookies of the request, with the ones that this request set or deleted. */\nexport function getCookies(event: RequestEvent): Record<string, string> {\n const header = event.request.headers.get('cookie');\n let cached = parsed.get(event);\n if (cached?.header !== header) {\n cached = { header, cookies: parseCookies(header) };\n parsed.set(event, cached);\n }\n // A copy, so the caller cannot change the cache.\n const result = { ...cached.cookies };\n for (const [name, value] of event.cookies ?? []) {\n if (value === undefined) {\n delete result[name];\n } else {\n result[name] = value;\n }\n }\n return result;\n}\n\n/** Sets a cookie on the response of an event. See `RequestEvent.setCookie`. */\nexport function setCookie(\n event: RequestEvent,\n name: string,\n value: string,\n options: CookieOptions = {},\n): void {\n const secure = options.secure ?? new URL(event.request.url).protocol === 'https:';\n event.headers.append('set-cookie', serializeCookie(name, value, { ...options, secure }));\n event.cookies ??= new Map();\n event.cookies.set(name, value);\n}\n\n/** Deletes a cookie. Pass the `path` and `domain` that it was set with, if they were not the defaults. */\nexport function deleteCookie(\n event: RequestEvent,\n name: string,\n options: Pick<CookieOptions, 'path' | 'domain'> = {},\n): void {\n // `secure` follows the request, as for a cookie set without it.\n setCookie(event, name, '', { ...options, secure: undefined, maxAge: 0, expires: new Date(0) });\n event.cookies!.set(name, undefined);\n}\n\nexport interface SessionOptions {\n /**\n * Signs the cookie, so a browser cannot change it. Use a random string of\n * at least 32 characters, kept out of the code, such as in an environment\n * variable. A list signs with the first and accepts all, for changing it.\n */\n secret: string | string[];\n /** The name of the cookie. Defaults to `session`. */\n name?: string;\n /** Seconds until the session expires. Defaults to 7 days. */\n maxAge?: number;\n /** Other options of the cookie. */\n cookie?: Omit<CookieOptions, 'maxAge' | 'expires'>;\n}\n\nexport interface Session<T> {\n /** The data of the session, or undefined when there is none, it expired, or its signature does not match. */\n get(event: RequestEvent): Promise<T | undefined>;\n /** Replaces the data of the session, and starts its time again. */\n set(event: RequestEvent, data: T): Promise<void>;\n /** Changes some fields of the data, and returns the new data. */\n update(event: RequestEvent, change: Partial<T>): Promise<T>;\n /** Ends the session. */\n clear(event: RequestEvent): void;\n}\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder();\nconst keys = new Map<string, Promise<CryptoKey>>();\n\nfunction key(secret: string): Promise<CryptoKey> {\n let promise = keys.get(secret);\n if (!promise) {\n promise = crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign', 'verify'],\n );\n keys.set(secret, promise);\n }\n return promise;\n}\n\nfunction toBase64Url(bytes: Uint8Array): string {\n let text = '';\n for (const byte of bytes) {\n text += String.fromCharCode(byte);\n }\n return btoa(text).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n}\n\nfunction fromBase64Url(text: string): Uint8Array<ArrayBuffer> {\n const base64 = text.replace(/-/g, '+').replace(/_/g, '/');\n return Uint8Array.from(atob(base64), (char) => char.charCodeAt(0));\n}\n\n/**\n * A session in a signed cookie. The browser can read the data, but cannot\n * change it, so keep secrets out of it: store an ID, and look the rest up\n * on the server.\n *\n * ```ts\n * export const session = createSession<{ userId: string }>({ secret: process.env.SESSION_SECRET! });\n *\n * async function login(form: FormData) {\n * 'use server';\n * const event = getEvent();\n * await session.set(event, { userId: await checkPassword(form) });\n * }\n * ```\n */\nexport function createSession<T>(options: SessionOptions): Session<T> {\n const secrets = Array.isArray(options.secret) ? options.secret : [options.secret];\n if (secrets.length === 0 || secrets.some((secret) => secret.length < 32)) {\n throw new Error('A session secret needs at least 32 characters');\n }\n const name = options.name ?? 'session';\n const maxAge = options.maxAge ?? 7 * 24 * 60 * 60;\n\n const read = async (event: RequestEvent): Promise<T | undefined> => {\n const value = getCookies(event)[name];\n const dot = value?.lastIndexOf('.') ?? -1;\n if (!value || dot === -1) {\n return undefined;\n }\n const payload = value.slice(0, dot);\n let signature: Uint8Array<ArrayBuffer>;\n try {\n signature = fromBase64Url(value.slice(dot + 1));\n } catch {\n return undefined;\n }\n // Any of the secrets can have signed it, such as an older one while a secret changes.\n const checks = await Promise.all(\n secrets.map(async (secret) =>\n crypto.subtle.verify('HMAC', await key(secret), signature, encoder.encode(payload)),\n ),\n );\n if (!checks.includes(true)) {\n return undefined;\n }\n try {\n const { d: data, e: expires } = JSON.parse(decoder.decode(fromBase64Url(payload))) as {\n d: T;\n e: number;\n };\n return expires > Date.now() ? data : undefined;\n } catch {\n return undefined;\n }\n };\n\n const write = async (event: RequestEvent, data: T): Promise<void> => {\n const payload = toBase64Url(\n encoder.encode(JSON.stringify({ d: data, e: Date.now() + maxAge * 1000 })),\n );\n const signature = new Uint8Array(\n await crypto.subtle.sign('HMAC', await key(secrets[0]!), encoder.encode(payload)),\n );\n const value = `${payload}.${toBase64Url(signature)}`;\n // Browsers drop cookies over about 4 KB.\n if (value.length > 4000) {\n throw new Error(\n `The session is ${value.length} bytes, over the 4000 that a cookie can hold. Store an ID in it instead`,\n );\n }\n setCookie(event, name, value, { ...options.cookie, maxAge });\n };\n\n return {\n get: read,\n set: write,\n async update(event, change) {\n const data = { ...(await read(event)), ...change } as T;\n await write(event, data);\n return data;\n },\n clear: (event) =>\n deleteCookie(event, name, { path: options.cookie?.path, domain: options.cookie?.domain }),\n };\n}\n\n/**\n * The headers of a response for Node's `writeHead`, with each `set-cookie`\n * apart. `Object.fromEntries(headers)` joins them into one, which browsers\n * read as a single cookie.\n */\nexport function toNodeHeaders(headers: Headers): Record<string, string | string[]> {\n const result: Record<string, string | string[]> = Object.fromEntries(headers);\n const cookies = headers.getSetCookie();\n if (cookies.length > 0) {\n result['set-cookie'] = cookies;\n }\n return result;\n}\n"],"mappings":";;AAsBA,SAAgB,aAAa,QAA+C;CAC1E,MAAM,SAAiC,CAAC;CACxC,KAAK,MAAM,SAAS,UAAU,GAAA,CAAI,MAAM,GAAG,GAAG;EAC5C,MAAM,QAAQ,KAAK,QAAQ,GAAG;EAC9B,IAAI,UAAU,IACZ;EAEF,MAAM,OAAO,KAAK,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK;EACvC,IAAI,QAAQ,EAAE,QAAQ,SAAS;GAC7B,MAAM,QAAQ,KAAK,MAAM,QAAQ,CAAC,CAAC,CAAC,KAA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AAK,QAAQ,MAAM,IAAI,QAAQ,EAAG,GAAG,QAAQ,OAAO,OAAO,CAAC,CAElC,CAAC;EAEjD,IAAI,MAAM,SAAS,KACjB,MAAM,IAAI,MACR,kBAAkB,MAAM,OAAO,wEACjC;EAEF,UAAU,OAAO,MAAM,OAAO;GAAE,GAAG,QAAQ;GAAQ;EAAO,CAAC;CAC7D;CAEA,OAAO;EACL,KAAK;EACL,KAAK;EACL,MAAM,OAAO,OAAO,QAAQ;GAC1B,MAAM,OAAO;IAAE,GAAI,MAAM,KAAK,KAAK;IAAI,GAAG;GAAO;GACjD,MAAM,MAAM,OAAO,IAAI;GACvB,OAAO;EACT;EACA,QAAQ,UACN,aAAa,OAAO,MAAM;GAAE,MAAM,QAAQ,QAAQ;GAAM,QAAQ,QAAQ,QAAQ;EAAO,CAAC;CAC5F;AACF;;;;;;AAOA,SAAgB,cAAc,SAAqD;CACjF,MAAM,SAA4C,OAAO,YAAY,OAAO;CAC5E,MAAM,UAAU,QAAQ,aAAa;CACrC,IAAI,QAAQ,SAAS,GACnB,OAAO,gBAAgB;CAEzB,OAAO;AACT"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"defer-D0bo1Gqx.js","names":[],"sources":["../src/runtime/defer.ts"],"sourcesContent":["// Loads the body of a `#defer` block. The loader imports this module when\n// the block's trigger fires, so a page without `#defer` does not load it.\n//\n// The server renders the route again for the request and answers with what\n// it streams for a `#loading` body that is ready: the body in a\n// `<template b-l>`, the script that swaps it in, and its state records.\n// This module adds that markup to the page and runs its scripts, in order.\n\nimport { build, skew } from './client.ts';\nimport { trustedHTML, trustedScript } from './trusted.ts';\n/** The nonce of a script. Browsers hide the attribute once the page loads, and keep the property. */\nfunction nonceOf(script: HTMLScriptElement): string | null {\n return script.nonce || script.getAttribute('nonce');\n}\n\n/** The Content Security Policy nonce of the page, which the scripts of the answer need to run. */\nfunction pageNonce(): string | undefined {\n for (const script of document.querySelectorAll('script')) {\n const nonce = nonceOf(script);\n if (nonce) {\n return nonce;\n }\n }\n return undefined;\n}\n\n/**\n * Asks the server for the body of the `#defer` block of a `<template\n * b-defer>`, and puts it in place of the fallback. When the server cannot\n * render it, such as a page that changed since it loaded, or a static host\n * that answers with the whole page, the fallback stays.\n */\nexport async function loadDeferred(template: Element): Promise<void> {\n const [, boundary, base] = template.getAttribute('b-defer')!.split(':') as [\n string,\n string,\n string,\n ];\n const response = await fetch(location.href, {\n headers: {\n 'x-brumate-defer': `${boundary} ${template.getAttribute('b-b')}`,\n 'x-brumate-base': base,\n ...(build === undefined ? {} : { 'x-brumate-build': build }),\n },\n });\n if (response.status === 409 && response.headers.get('x-brumate-build')) {\n // The site changed since the page loaded. The fallback stays, and the next page loads in full.\n skew('defer');\n return;\n }\n if (!response.ok || response.headers.get('x-brumate-defer') !== boundary) {\n return;\n }\n const parsed = document.createElement('template');\n parsed.innerHTML = trustedHTML(await response.text());\n const nonce = pageNonce();\n // A copy, because appending moves nodes out of the live list.\n for (const node of Array.from(parsed.content.childNodes)) {\n if (node.nodeName !== 'SCRIPT') {\n document.body.append(node);\n continue;\n }\n // A script from `innerHTML` does not run, so a copy goes in its place.\n const script = node as HTMLScriptElement;\n const copy = document.createElement('script');\n for (const attribute of script.attributes) {\n if (attribute.name !== 'nonce') {\n copy.setAttribute(attribute.name, attribute.value);\n }\n }\n if (nonce) {\n copy.nonce = nonce;\n }\n copy.textContent = trustedScript(script.textContent ?? '');\n document.body.append(copy);\n }\n}\n"],"mappings":";;;;AAWA,SAAS,QAAQ,QAA0C;CACzD,OAAO,OAAO,SAAS,OAAO,aAAa,OAAO;AACpD;;AAGA,SAAS,YAAgC;CACvC,KAAK,MAAM,UAAU,SAAS,iBAAiB,QAAQ,GAAG;EACxD,MAAM,QAAQ,QAAQ,MAAM;EAC5B,IAAI,OACF,OAAO;CAEX;AAEF;;;;;;;AAQA,eAAsB,aAAa,UAAkC;CACnE,MAAM,GAAG,UAAU,QAAQ,SAAS,aAAa,SAAS,CAAC,CAAE,MAAM,GAAG;CAKtE,MAAM,WAAW,MAAM,MAAM,SAAS,MAAM,EAC1C,SAAS;EACP,mBAAmB,GAAG,SAAS,GAAG,SAAS,aAAa,KAAK;EAC7D,kBAAkB;EAClB,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,mBAAmB,MAAM;CAC5D,EACF,CAAC;CACD,IAAI,SAAS,WAAW,OAAO,SAAS,QAAQ,IAAI,iBAAiB,GAAG;EAEtE,KAAK,OAAO;EACZ;CACF;CACA,IAAI,CAAC,SAAS,MAAM,SAAS,QAAQ,IAAI,iBAAiB,MAAM,UAC9D;CAEF,MAAM,SAAS,SAAS,cAAc,UAAU;CAChD,OAAO,YAAY,YAAY,MAAM,SAAS,KAAK,CAAC;CACpD,MAAM,QAAQ,UAAU;CAExB,KAAK,MAAM,QAAQ,MAAM,KAAK,OAAO,QAAQ,UAAU,GAAG;EACxD,IAAI,KAAK,aAAa,UAAU;GAC9B,SAAS,KAAK,OAAO,IAAI;GACzB;EACF;EAEA,MAAM,SAAS;EACf,MAAM,OAAO,SAAS,cAAc,QAAQ;EAC5C,KAAK,MAAM,aAAa,OAAO,YAC7B,IAAI,UAAU,SAAS,SACrB,KAAK,aAAa,UAAU,MAAM,UAAU,KAAK;EAGrD,IAAI,OACF,KAAK,QAAQ;EAEf,KAAK,cAAc,cAAc,OAAO,eAAe,EAAE;EACzD,SAAS,KAAK,OAAO,IAAI;CAC3B;AACF"}
@@ -1,113 +0,0 @@
1
- //#region src/runtime/devtools.ts
2
- const DEVTOOLS = Symbol.for("brumate.devtools");
3
- const MAX_LOG = 300;
4
- /** The root scope of a scope, whose `m` names its component. */
5
- function rootOf(scope) {
6
- let root = scope;
7
- while (root.p) root = root.p;
8
- return root;
9
- }
10
- /** A short text for a value in the log. */
11
- function preview(value) {
12
- if (typeof value === "string") return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);
13
- if (typeof value === "function") return "function";
14
- if (Array.isArray(value)) return `Array(${value.length})`;
15
- if (value instanceof Element) return `<${value.tagName.toLowerCase()}>`;
16
- if (value !== null && typeof value === "object") {
17
- const name = value.constructor?.name;
18
- return name && name !== "Object" ? name : `{${Object.keys(value).slice(0, 3).join(", ")}}`;
19
- }
20
- return String(value);
21
- }
22
- /** Listens to the core, and adds the button that opens the panel. */
23
- function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate") {
24
- const state = {
25
- log: [],
26
- written: /* @__PURE__ */ new Set(),
27
- endpoint
28
- };
29
- const add = (entry) => {
30
- state.log.push({
31
- ...entry,
32
- time: performance.now()
33
- });
34
- if (state.log.length > MAX_LOG) state.log.splice(0, state.log.length - MAX_LOG);
35
- state.changed?.();
36
- };
37
- globalThis[DEVTOOLS] = {
38
- attach(core) {
39
- state.scopes = core.scopes;
40
- state.set = core.set;
41
- state.changed?.();
42
- },
43
- handler(ref, element, event) {
44
- add({
45
- kind: "handler",
46
- text: `${event?.type ?? "call"} on <${element.tagName.toLowerCase()}>: ${ref}`
47
- });
48
- },
49
- part(component, name) {
50
- add({
51
- kind: "part",
52
- text: `loaded ${component} ${name}`
53
- });
54
- },
55
- write(scope, slot, value) {
56
- state.written.add(scope.id);
57
- const root = rootOf(scope);
58
- add({
59
- kind: "write",
60
- text: `scope ${scope.id} slot ${slot} = ${preview(value)}`,
61
- scope: scope.id,
62
- write: {
63
- component: root.m ?? "",
64
- k: scope.k,
65
- slot
66
- }
67
- });
68
- }
69
- };
70
- const original = globalThis.fetch.bind(globalThis);
71
- globalThis.fetch = async (input, init) => {
72
- const url = new URL(input instanceof Request ? input.url : String(input), location.href);
73
- if (url.origin !== location.origin || !url.pathname.startsWith(`${rpc}/`)) return original(input, init);
74
- const name = decodeURIComponent(url.pathname.slice(rpc.length + 1));
75
- const started = performance.now();
76
- try {
77
- const response = await original(input, init);
78
- const took = Math.round(performance.now() - started);
79
- const redirect = response.headers.get("x-brumate-redirect");
80
- add({
81
- kind: "call",
82
- text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`
83
- });
84
- return response;
85
- } catch (error) {
86
- add({
87
- kind: "call",
88
- text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`
89
- });
90
- throw error;
91
- }
92
- };
93
- const host = document.createElement("brumate-devtools");
94
- const root = host.attachShadow({ mode: "open" });
95
- const button = document.createElement("button");
96
- button.textContent = "brm";
97
- button.title = "Open the brumate devtools";
98
- button.setAttribute("style", "position:fixed;right:12px;bottom:12px;z-index:2147483647;font:600 12px ui-monospace,monospace;padding:6px 10px;border-radius:999px;border:1px solid #8884;background:#111;color:#fff;cursor:pointer");
99
- button.addEventListener("click", () => {
100
- import("./devtools-panel-AYjfwPhj.js").then(({ togglePanel }) => togglePanel(root, state));
101
- });
102
- root.append(button);
103
- const append = () => {
104
- document.documentElement.append(host);
105
- };
106
- if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", append);
107
- else append();
108
- return state;
109
- }
110
- //#endregion
111
- export { preview as n, rootOf as r, installDevtools as t };
112
-
113
- //# sourceMappingURL=devtools-C50VH8gZ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"devtools-C50VH8gZ.js","names":[],"sources":["../src/runtime/devtools.ts"],"sourcesContent":["// The devtools overlay of development builds. This module only listens to\n// the core and shows a button. The panel loads when the button is pressed,\n// so the page behaves as in production until then.\n\nimport type { DevtoolsHooks, Scope } from './client.ts';\nimport type { ScopeId } from './shared.ts';\n\n// The same key as the core's, without importing the core.\nconst DEVTOOLS = Symbol.for('brumate.devtools');\n\n/** Something that happened on the page, for the log of the panel. */\nexport interface DevtoolsEntry {\n time: number;\n kind: 'handler' | 'part' | 'write' | 'call';\n text: string;\n /** The scope of a write, so the panel can mark it. */\n scope?: ScopeId;\n /** For a write: the component, the scope in the compiled component, and the slot. */\n write?: { component: string; k: number; slot: number };\n}\n\nexport interface DevtoolsState {\n scopes?: Map<ScopeId, Scope>;\n /** Writes a slot, as a handler does, so the page updates. */\n set?: (scope: Scope, slot: number, value: unknown) => void;\n log: DevtoolsEntry[];\n /** The scopes written since the panel last drew, by scope ID. */\n written: Set<ScopeId>;\n /** The URL prefix of the inspect endpoint of the dev server. */\n endpoint: string;\n /** Called after each change, while the panel is open. */\n changed?: () => void;\n}\n\nconst MAX_LOG = 300;\n\n/** The root scope of a scope, whose `m` names its component. */\nexport function rootOf(scope: Scope): Scope {\n let root = scope;\n while (root.p) {\n root = root.p;\n }\n return root;\n}\n\n/** A short text for a value in the log. */\nexport function preview(value: unknown): string {\n if (typeof value === 'string') {\n return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);\n }\n if (typeof value === 'function') {\n return 'function';\n }\n if (Array.isArray(value)) {\n return `Array(${value.length})`;\n }\n if (value instanceof Element) {\n return `<${value.tagName.toLowerCase()}>`;\n }\n if (value !== null && typeof value === 'object') {\n const name = value.constructor?.name;\n return name && name !== 'Object' ? name : `{${Object.keys(value).slice(0, 3).join(', ')}}`;\n }\n return String(value);\n}\n\n/** Listens to the core, and adds the button that opens the panel. */\nexport function installDevtools(endpoint = '/__brumate/inspect', rpc = '/_brumate'): DevtoolsState {\n const state: DevtoolsState = { log: [], written: new Set(), endpoint };\n const add = (entry: Omit<DevtoolsEntry, 'time'>): void => {\n state.log.push({ ...entry, time: performance.now() });\n if (state.log.length > MAX_LOG) {\n state.log.splice(0, state.log.length - MAX_LOG);\n }\n state.changed?.();\n };\n const hooks: DevtoolsHooks = {\n attach(core) {\n state.scopes = core.scopes;\n state.set = core.set;\n state.changed?.();\n },\n handler(ref, element, event) {\n add({\n kind: 'handler',\n text: `${event?.type ?? 'call'} on <${element.tagName.toLowerCase()}>: ${ref}`,\n });\n },\n part(component, name) {\n add({ kind: 'part', text: `loaded ${component} ${name}` });\n },\n write(scope, slot, value) {\n state.written.add(scope.id);\n const root = rootOf(scope);\n add({\n kind: 'write',\n text: `scope ${scope.id} slot ${slot} = ${preview(value)}`,\n scope: scope.id,\n write: { component: root.m ?? '', k: scope.k, slot },\n });\n },\n };\n (globalThis as Record<symbol, DevtoolsHooks | undefined>)[DEVTOOLS] = hooks;\n\n // Server function calls, with how long each took and how it answered.\n const original = globalThis.fetch.bind(globalThis);\n globalThis.fetch = async (input, init) => {\n const url = new URL(input instanceof Request ? input.url : String(input), location.href);\n if (url.origin !== location.origin || !url.pathname.startsWith(`${rpc}/`)) {\n return original(input, init);\n }\n const name = decodeURIComponent(url.pathname.slice(rpc.length + 1));\n const started = performance.now();\n try {\n const response = await original(input, init);\n const took = Math.round(performance.now() - started);\n const redirect = response.headers.get('x-brumate-redirect');\n add({\n kind: 'call',\n text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`,\n });\n return response;\n } catch (error) {\n add({\n kind: 'call',\n text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`,\n });\n throw error;\n }\n };\n\n const host = document.createElement('brumate-devtools');\n const root = host.attachShadow({ mode: 'open' });\n const button = document.createElement('button');\n button.textContent = 'brm';\n button.title = 'Open the brumate devtools';\n button.setAttribute(\n 'style',\n 'position:fixed;right:12px;bottom:12px;z-index:2147483647;font:600 12px ui-monospace,monospace;padding:6px 10px;border-radius:999px;border:1px solid #8884;background:#111;color:#fff;cursor:pointer',\n );\n button.addEventListener('click', () => {\n void import('./devtools-panel.ts').then(({ togglePanel }) => togglePanel(root, state));\n });\n root.append(button);\n const append = (): void => {\n // Navigation replaces the body, so the button goes on the document element.\n document.documentElement.append(host);\n };\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', append);\n } else {\n append();\n }\n return state;\n}\n"],"mappings":";AAQA,MAAM,WAAW,OAAO,IAAI,kBAAkB;AA0B9C,MAAM,UAAU;;AAGhB,SAAgB,OAAO,OAAqB;CAC1C,IAAI,OAAO;CACX,OAAO,KAAK,GACV,OAAO,KAAK;CAEd,OAAO;AACT;;AAGA,SAAgB,QAAQ,OAAwB;CAC9C,IAAI,OAAO,UAAU,UACnB,OAAO,KAAK,UAAU,MAAM,SAAS,KAAK,GAAG,MAAM,MAAM,GAAG,EAAE,EAAE,KAAK,KAAK;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