brumate 0.3.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.
- package/README.md +2 -2
- package/check.d.ts +49 -0
- package/dist/{boot-C25Sa6vq.d.ts → boot-DLlRmD9z.d.ts} +8 -10
- package/dist/cli.js +275 -15
- package/dist/cli.js.map +1 -1
- package/dist/client-BvDsC6Qr.js +3463 -0
- package/dist/client-BvDsC6Qr.js.map +1 -0
- package/dist/{client-D0CqSxoO.d.ts → client-DBwL2wKQ.d.ts} +390 -181
- package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
- package/dist/client-routes-BtGpYCef.js.map +1 -0
- package/dist/{cookies-BzllthiF.js → cookies-Cnbf4w-S.js} +14 -7
- package/dist/cookies-Cnbf4w-S.js.map +1 -0
- package/dist/{defer-BbD7JQhj.js → defer-CKWZLv2K.js} +4 -4
- package/dist/defer-CKWZLv2K.js.map +1 -0
- package/dist/{devtools-CQgD7NPB.js → devtools-4uTPwR_v.js} +56 -82
- package/dist/devtools-4uTPwR_v.js.map +1 -0
- package/dist/{devtools-panel-BVB-W5q4.js → devtools-panel-Be9pxYgv.js} +397 -333
- package/dist/devtools-panel-Be9pxYgv.js.map +1 -0
- package/dist/{events-CSs7OwIC.js → events-LgLdp1R7.js} +34 -5
- package/dist/events-LgLdp1R7.js.map +1 -0
- package/dist/features-CHY5Ekku.js +30 -0
- package/dist/features-CHY5Ekku.js.map +1 -0
- package/dist/files-WW4RlajL.js +506 -0
- package/dist/files-WW4RlajL.js.map +1 -0
- package/dist/{forms-Cl21hkHt.d.ts → forms-j1xPAR14.d.ts} +3 -3
- package/dist/{forms-Bg-CwGqX.js → forms-nXK7-Lv_.js} +78 -44
- package/dist/forms-nXK7-Lv_.js.map +1 -0
- package/dist/highlight.js +31 -22
- package/dist/highlight.js.map +1 -1
- package/dist/{html-mNTKzaDD.js → html-BtKRyi7g.js} +86 -22
- package/dist/html-BtKRyi7g.js.map +1 -0
- package/dist/{html-Bq1rFxX_.d.ts → html-Bw9Qwu6F.d.ts} +20 -5
- package/dist/index.d.ts +96 -10
- package/dist/index.js +639 -104
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BHpOw1LF.js → inspect-Y6y4uNZp.js} +3751 -676
- package/dist/inspect-Y6y4uNZp.js.map +1 -0
- package/dist/{loader-Dos_3NP0.js → loader-BjKGJzLN.js} +20 -14
- package/dist/loader-BjKGJzLN.js.map +1 -0
- package/dist/logo-DQ_OYhBi.js +10 -0
- package/dist/logo-DQ_OYhBi.js.map +1 -0
- package/dist/{navigate-O78d_zGN.js → navigate-CfOr-TRF.js} +94 -31
- package/dist/navigate-CfOr-TRF.js.map +1 -0
- package/dist/nesting-DA5vJw9X.js +265 -0
- package/dist/nesting-DA5vJw9X.js.map +1 -0
- package/dist/{produce-Doc91GkX.js → produce-B7X9ori9.js} +137 -9
- package/dist/produce-B7X9ori9.js.map +1 -0
- package/dist/{produce-D0V0ICkz.d.ts → produce-DIgHBVwL.d.ts} +39 -5
- package/dist/{rpc-ygMRPmN4.js → rpc-Q-XkLwFh.js} +11 -6
- package/dist/rpc-Q-XkLwFh.js.map +1 -0
- package/dist/runtime/batch.js +9 -7
- package/dist/runtime/batch.js.map +1 -1
- package/dist/runtime/client.d.ts +4 -4
- package/dist/runtime/client.js +4 -4
- package/dist/runtime/devtools.d.ts +11 -29
- package/dist/runtime/devtools.js +3 -1
- package/dist/runtime/env.js +14 -2
- package/dist/runtime/env.js.map +1 -1
- package/dist/runtime/events.d.ts +23 -1
- package/dist/runtime/events.js +1 -1
- package/dist/runtime/forms.d.ts +2 -2
- package/dist/runtime/forms.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +5 -2
- 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 +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/routes.js +4 -1
- package/dist/runtime/routes.js.map +1 -1
- package/dist/runtime/server.d.ts +5 -5
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +38 -1
- package/dist/runtime/signals.js +33 -1
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/testing.d.ts +18 -3
- package/dist/runtime/testing.js +150 -33
- package/dist/runtime/testing.js.map +1 -1
- package/dist/{server-DuFYRXrd.d.ts → server-BvPIg9pT.d.ts} +84 -22
- package/dist/{server-CxVDYE_V.js → server-DjyOVJtJ.js} +598 -164
- package/dist/server-DjyOVJtJ.js.map +1 -0
- package/dist/{static-loader-Drpr0AzI.d.ts → static-loader-BGgdp_Y5.d.ts} +2 -2
- package/dist/{static-loader-nZssh66R.js → static-loader-BZR17hSw.js} +78 -99
- package/dist/static-loader-BZR17hSw.js.map +1 -0
- package/dist/{stream-DCYZO4IF.js → stream-BP5AVmg5.js} +102 -16
- package/dist/stream-BP5AVmg5.js.map +1 -0
- package/dist/vite.d.ts +13 -20
- package/dist/vite.js +1890 -548
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +951 -0
- package/forms/forms.brm.ts +3 -3
- package/package.json +12 -3
- package/skills/brumate/SKILL.md +58 -0
- package/skills/brumate/references/errors.md +2078 -0
- package/skills/brumate/references/events.md +117 -0
- package/skills/brumate/references/signals.md +61 -0
- package/skills/brumate/references/state.md +235 -0
- package/skills/brumate/references/syntax.md +250 -0
- package/types.d.ts +4 -4
- package/dist/client-BD6XT-s5.js +0 -1968
- package/dist/client-BD6XT-s5.js.map +0 -1
- package/dist/client-routes-JTbGtukf.js.map +0 -1
- package/dist/cookies-BzllthiF.js.map +0 -1
- package/dist/defer-BbD7JQhj.js.map +0 -1
- package/dist/devtools-CQgD7NPB.js.map +0 -1
- package/dist/devtools-panel-BVB-W5q4.js.map +0 -1
- package/dist/events-CSs7OwIC.js.map +0 -1
- package/dist/files-BXSSrQgc.js +0 -205
- package/dist/files-BXSSrQgc.js.map +0 -1
- package/dist/forms-Bg-CwGqX.js.map +0 -1
- package/dist/html-mNTKzaDD.js.map +0 -1
- package/dist/inspect-BHpOw1LF.js.map +0 -1
- package/dist/loader-Dos_3NP0.js.map +0 -1
- package/dist/navigate-O78d_zGN.js.map +0 -1
- package/dist/produce-Doc91GkX.js.map +0 -1
- package/dist/rpc-ygMRPmN4.js.map +0 -1
- package/dist/server-CxVDYE_V.js.map +0 -1
- package/dist/static-loader-nZssh66R.js.map +0 -1
- package/dist/stream-DCYZO4IF.js.map +0 -1
package/dist/runtime/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as serializeCookie, i as parseCookies, s as toNodeHeaders, t as createSession } from "../cookies-
|
|
3
|
-
import {
|
|
4
|
-
import { $ as
|
|
1
|
+
import { T as vars, _ as onAttribute, a as attribute, b as raw, c as classAttribute, d as escapeAttribute, g as mergeAttributes, i as affix, m as internal, u as escape } from "../html-BtKRyi7g.js";
|
|
2
|
+
import { a as serializeCookie, i as parseCookies, s as toNodeHeaders, t as createSession } from "../cookies-Cnbf4w-S.js";
|
|
3
|
+
import { C as useSerialEntry, S as unbind, a as ElementReference, o as FunctionReference, t as produce } from "../produce-B7X9ori9.js";
|
|
4
|
+
import { $ as isRedirect, A as waitAll, B as parseForm, C as spacerTag, D as streamParts, E as stateValue, F as rateLimit, G as revalidate, H as matchRoute, I as parseSubmission, J as RequestEvent, K as setCacheStore, L as ValidationError, M as RateLimitError, N as clientAddress, O as streamState, P as configureRateLimit, Q as getEvent, R as fieldErrors, S as settled, T as stateScript, U as cached, V as safeParse, W as memoryStore, X as dedupe, Y as ServerError, Z as defineMiddleware, _ as packState, a as binding, b as render, c as component, d as handleRoute, et as redirect, f as inlineBodies, g as memo, h as lazy, i as actionResult, j as idempotent, k as wait, l as dynamic, m as isCrossSite, n as NotReady, o as caught, p as insert, q as storageStore, r as action, s as children, t as Context, tt as withEvent, u as handleRequest, v as read, w as spread, x as renderToStream, y as ready, z as parse } from "../server-DjyOVJtJ.js";
|
|
5
5
|
import { a as routeContext, i as navigationContext, r as createContext } from "../context-CTiSzQRc.js";
|
|
6
|
-
export { Context, ElementReference, FunctionReference, NotReady, RateLimitError, RequestEvent, ServerError, ValidationError, action, actionResult, affix, attribute, binding, cached, children, classAttribute, clientAddress, component, configureRateLimit, createContext, createSession, dedupe, defineMiddleware, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, idempotent, inlineBodies, insert, isCrossSite, isRedirect, lazy, matchRoute, memo, memoryStore, mergeAttributes, navigationContext, onAttribute, packState, parse, parseCookies, parseForm, parseSubmission, produce, rateLimit, raw, read, ready, redirect, render, renderToStream, revalidate, routeContext, safeParse, serializeCookie, setCacheStore, settled, spread, stateScript, stateValue, storageStore, streamParts, streamState, toNodeHeaders, unbind, useSerialEntry, vars, wait, waitAll, withEvent };
|
|
6
|
+
export { Context, ElementReference, FunctionReference, NotReady, RateLimitError, RequestEvent, ServerError, ValidationError, action, actionResult, affix, attribute, binding, cached, caught, children, classAttribute, clientAddress, component, configureRateLimit, createContext, createSession, dedupe, defineMiddleware, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, idempotent, inlineBodies, insert, internal, isCrossSite, isRedirect, lazy, matchRoute, memo, memoryStore, mergeAttributes, navigationContext, onAttribute, packState, parse, parseCookies, parseForm, parseSubmission, produce, rateLimit, raw, read, ready, redirect, render, renderToStream, revalidate, routeContext, safeParse, serializeCookie, setCacheStore, settled, spacerTag, spread, stateScript, stateValue, storageStore, streamParts, streamState, toNodeHeaders, unbind, useSerialEntry, vars, wait, waitAll, withEvent };
|
|
@@ -2,10 +2,20 @@ import { a as Route, r as NavigationState, t as Context } from "../context-btHuB
|
|
|
2
2
|
import { n as RouteParams, r as RoutePath } from "../routes-BZNt7DSZ.js";
|
|
3
3
|
//#region src/runtime/signals.d.ts
|
|
4
4
|
declare const BINDABLE: unique symbol;
|
|
5
|
+
declare const WRITES: unique symbol;
|
|
5
6
|
/** The mark of a prop that a parent can bind. It has no value at runtime. */
|
|
6
7
|
export interface BindableMark<T> {
|
|
7
8
|
readonly [BINDABLE]: T;
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* What a binding writes. A binding of a signal of `T` takes a prop that writes `W` when `W` is
|
|
12
|
+
* assignable to `T`, as a signal of `HTMLElement | undefined` takes the ref of a `div`.
|
|
13
|
+
*/
|
|
14
|
+
export interface WritableMark<W> {
|
|
15
|
+
readonly [WRITES]: (value: W) => void;
|
|
16
|
+
}
|
|
17
|
+
/** What `$bind` returns: the mark of a prop, and the write side that checks the type of a ref. */
|
|
18
|
+
export interface BoundSignal<T> extends BindableMark<T>, WritableMark<T> {}
|
|
9
19
|
/**
|
|
10
20
|
* Marks a prop that a parent can bind with `$bind`, such as
|
|
11
21
|
* `open?: Bindable<boolean>`. The parent passes `T` or `$bind(name)`.
|
|
@@ -57,6 +67,27 @@ export declare function $client(_callback: () => void | (() => void), _trigger?:
|
|
|
57
67
|
export declare function $untrack<T>(_value: T): T;
|
|
58
68
|
/** True while a new value of a memo, or of a memo it reads, loads on the client. Always false on the server. */
|
|
59
69
|
export declare function $isPending(_memo: unknown): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Waits for a memo to have its value, and gives it. It resolves at once when the memo is settled,
|
|
72
|
+
* and after the load when the memo loads its first value or loads again. When the inputs of the
|
|
73
|
+
* memo change while it waits, it waits for the load of the current inputs. It rejects with the
|
|
74
|
+
* error of the memo, when `timeout` milliseconds pass, or when `signal` aborts. Use it in a handler,
|
|
75
|
+
* an effect or a `$client` callback, never where a memo computes or markup renders.
|
|
76
|
+
*/
|
|
77
|
+
export declare function $resolve<T>(_memo: T, _options?: {
|
|
78
|
+
timeout?: number;
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
}): Promise<Awaited<T>>;
|
|
81
|
+
/**
|
|
82
|
+
* True when the parent passed a prop with `$bind`, so a write of it reaches the parent. The prop is
|
|
83
|
+
* one that the component destructures with `let`. Always false on the server, where nothing writes.
|
|
84
|
+
*/
|
|
85
|
+
export declare function $isBound(_prop: unknown): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* True when the caller passed the prop, even as `undefined`. A part uses it to tell a controlled
|
|
88
|
+
* value, such as `value=(null)`, from no value. Declare it with `const` in the component script.
|
|
89
|
+
*/
|
|
90
|
+
export declare function $isPassed(_prop: unknown): boolean;
|
|
60
91
|
/** Returns an ID that is unique in the page and the same on the server and the client. */
|
|
61
92
|
export declare function $id(): string;
|
|
62
93
|
/** Provides a value of a context to the components inside this one. */
|
|
@@ -88,7 +119,7 @@ export declare function $action<F extends (...args: never[]) => unknown>(_fn: F)
|
|
|
88
119
|
* - Only a prop of type `Bindable<T>` takes it.
|
|
89
120
|
* - With `set`, a write calls `set(next)` in place of writing the signal.
|
|
90
121
|
*/
|
|
91
|
-
export declare function $bind<T>(signal: T, set?: (next: T) => unknown):
|
|
122
|
+
export declare function $bind<T>(signal: T, set?: (next: T) => unknown): BoundSignal<T>;
|
|
92
123
|
/**
|
|
93
124
|
* Marks a function that a script makes as an event handler, so a spread can
|
|
94
125
|
* pass it on, as it passes on a handler that a caller writes in markup.
|
|
@@ -98,6 +129,12 @@ export declare function $bind<T>(signal: T, set?: (next: T) => unknown): Bindabl
|
|
|
98
129
|
export declare function $handler<A extends unknown[], E = Event>(fn: (...args: [...A, E]) => unknown, ...args: A): (event: E) => unknown;
|
|
99
130
|
/** A function that does not read the event. */
|
|
100
131
|
export declare function $handler<A extends unknown[]>(fn: (...args: A) => unknown, ...args: A): (event: Event) => unknown;
|
|
132
|
+
/**
|
|
133
|
+
* Writes what the writes of the handler so far changed to the page, so the code after it can read
|
|
134
|
+
* the DOM, such as to focus or measure what a write rendered. A handler is one pass, and the page
|
|
135
|
+
* changes when it returns. Does nothing outside a handler, and on the server.
|
|
136
|
+
*/
|
|
137
|
+
export declare function flush(): void;
|
|
101
138
|
//#endregion
|
|
102
139
|
export {};
|
|
103
140
|
//# sourceMappingURL=signals.d.ts.map
|
package/dist/runtime/signals.js
CHANGED
|
@@ -61,6 +61,30 @@ function $untrack(_value) {
|
|
|
61
61
|
function $isPending(_memo) {
|
|
62
62
|
return compileTimeOnly("$isPending");
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Waits for a memo to have its value, and gives it. It resolves at once when the memo is settled,
|
|
66
|
+
* and after the load when the memo loads its first value or loads again. When the inputs of the
|
|
67
|
+
* memo change while it waits, it waits for the load of the current inputs. It rejects with the
|
|
68
|
+
* error of the memo, when `timeout` milliseconds pass, or when `signal` aborts. Use it in a handler,
|
|
69
|
+
* an effect or a `$client` callback, never where a memo computes or markup renders.
|
|
70
|
+
*/
|
|
71
|
+
function $resolve(_memo, _options) {
|
|
72
|
+
return compileTimeOnly("$resolve");
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* True when the parent passed a prop with `$bind`, so a write of it reaches the parent. The prop is
|
|
76
|
+
* one that the component destructures with `let`. Always false on the server, where nothing writes.
|
|
77
|
+
*/
|
|
78
|
+
function $isBound(_prop) {
|
|
79
|
+
return compileTimeOnly("$isBound");
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* True when the caller passed the prop, even as `undefined`. A part uses it to tell a controlled
|
|
83
|
+
* value, such as `value=(null)`, from no value. Declare it with `const` in the component script.
|
|
84
|
+
*/
|
|
85
|
+
function $isPassed(_prop) {
|
|
86
|
+
return compileTimeOnly("$isPassed");
|
|
87
|
+
}
|
|
64
88
|
/** Returns an ID that is unique in the page and the same on the server and the client. */
|
|
65
89
|
function $id() {
|
|
66
90
|
return compileTimeOnly("$id");
|
|
@@ -106,7 +130,15 @@ function $bind() {
|
|
|
106
130
|
function $handler() {
|
|
107
131
|
return compileTimeOnly("$handler");
|
|
108
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Writes what the writes of the handler so far changed to the page, so the code after it can read
|
|
135
|
+
* the DOM, such as to focus or measure what a write rendered. A handler is one pass, and the page
|
|
136
|
+
* changes when it returns. Does nothing outside a handler, and on the server.
|
|
137
|
+
*/
|
|
138
|
+
function flush() {
|
|
139
|
+
globalThis[Symbol.for("brumate.flush")]?.();
|
|
140
|
+
}
|
|
109
141
|
//#endregion
|
|
110
|
-
export { $action, $bind, $client, $debounced, $effect, $getContext, $handler, $id, $isPending, $memo, $navigation, $optimistic, $produce, $props, $route, $setContext, $signal, $throttled, $title, $untrack };
|
|
142
|
+
export { $action, $bind, $client, $debounced, $effect, $getContext, $handler, $id, $isBound, $isPassed, $isPending, $memo, $navigation, $optimistic, $produce, $props, $resolve, $route, $setContext, $signal, $throttled, $title, $untrack, flush };
|
|
111
143
|
|
|
112
144
|
//# sourceMappingURL=signals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signals.js","names":[],"sources":["../../src/runtime/signals.ts"],"sourcesContent":["// The compile-time functions of `.brm` files. The compiler replaces every\n// call and removes the import, so this module only gives them their types.\n// A call outside a `.brm` file throws.\n\nimport type { Context, NavigationState, Route } from './context.ts';\nimport type { RoutePath, RouteParams } from './routes.ts';\n\nfunction compileTimeOnly(name: string): never {\n throw new Error(`${name} works only in .brm files, which the brumate compiler compiles`);\n}\n\ndeclare const BINDABLE: unique symbol;\n\n/** The mark of a prop that a parent can bind. It has no value at runtime. */\nexport interface BindableMark<T> {\n readonly [BINDABLE]: T;\n}\n\n/**\n * Marks a prop that a parent can bind with `$bind`, such as\n * `open?: Bindable<boolean>`. The parent passes `T` or `$bind(name)`.\n * Inside the component, `$props<T>()` gives `T`.\n */\nexport type Bindable<T> = T | BindableMark<T>;\n\n/** The props as the component reads them, with `Bindable<T>` as `T`. */\nexport type Unbound<T> = { [K in keyof T]: Exclude<T[K], BindableMark<unknown>> };\n\n/**\n * Returns the props of the component. Destructure the call to keep each prop\n * reactive. Destructure it with `let` to write props, such as\n * `let { open = false } = $props()`.\n */\n// oxlint-disable-next-line typescript/no-explicit-any -- Props are any object unless typed.\nexport function $props<T = Record<string, any>>(): Unbound<T> {\n return compileTimeOnly('$props');\n}\n\n/** Declares writable state. The variable reads and writes the signal. */\nexport function $signal<T>(value: T): T;\nexport function $signal<T>(): T | undefined;\nexport function $signal(): never {\n return compileTimeOnly('$signal');\n}\n\n/** The value of a memo: what a promise settles to, or the latest value of an async iterable. */\nexport type MemoValue<T> = Awaited<T> extends AsyncIterable<infer U> ? U : Awaited<T>;\n\n/**\n * Declares a value computed from other values. A promise is awaited where it\n * is read. An async iterable gives each of its values in turn.\n */\nexport function $memo<T>(_value: T): MemoValue<T> {\n return compileTimeOnly('$memo');\n}\n\n/**\n * Declares a memo that takes the value once it stops changing for `ms`\n * milliseconds, such as a search query while the user types. On the server,\n * and until the value first changes, it is the value.\n */\nexport function $debounced<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$debounced');\n}\n\n/**\n * Declares a memo that takes the value at most once every `ms`\n * milliseconds, and the last value after the wait, such as a position while\n * the pointer moves. On the server, and until the value first changes, it is the value.\n */\nexport function $throttled<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$throttled');\n}\n\n/**\n * Declares a value that follows a memo, and that handlers can write. A write\n * shows a guess, such as a new item while the form that adds it posts. The\n * value goes back to the memo when the memo changes, or when the server\n * calls of the page finish, such as after a failed post.\n */\nexport function $optimistic<T>(_source: T): T {\n return compileTimeOnly('$optimistic');\n}\n\n/** Runs a callback when the values it reads change, after the page resumes. Never on load. */\nexport function $effect(_callback: () => void | (() => void)): void {\n compileTimeOnly('$effect');\n}\n\n/** Runs a callback in the browser when a trigger fires. */\nexport function $client(\n _callback: () => void | (() => void),\n _trigger?: 'visible' | 'idle' | 'load',\n): void {\n compileTimeOnly('$client');\n}\n\n/** Reads a value without depending on it. */\nexport function $untrack<T>(_value: T): T {\n return compileTimeOnly('$untrack');\n}\n\n/** True while a new value of a memo, or of a memo it reads, loads on the client. Always false on the server. */\nexport function $isPending(_memo: unknown): boolean {\n return compileTimeOnly('$isPending');\n}\n\n/** Returns an ID that is unique in the page and the same on the server and the client. */\nexport function $id(): string {\n return compileTimeOnly('$id');\n}\n\n/** Provides a value of a context to the components inside this one. */\nexport function $setContext<T>(_context: Context<T>, _value: T): void {\n compileTimeOnly('$setContext');\n}\n\n/** Reads a context from the nearest component above that provides it, or its default value. */\nexport function $getContext<T>(_context: Context<T>): T {\n return compileTimeOnly('$getContext');\n}\n\n/**\n * The route of the page: its URL, its query string and its params, typed\n * from the route files as `href` is. The server reads the request, and the\n * browser reads `location`. It changes when navigation changes the URL.\n */\nexport function $route<P extends RoutePath = RoutePath>(_path?: P): Route<RouteParams<P>> {\n return compileTimeOnly('$route');\n}\n\n/** The navigation that loads, with `pending` false when none does. Always `{ pending: false }` on the server. */\nexport function $navigation(): NavigationState {\n return compileTimeOnly('$navigation');\n}\n\n/** Changes an object or an array in a signal through a draft, and writes the signal with the result. */\nexport function $produce<T>(_signal: T, _recipe: (draft: T) => T | void): void {\n compileTimeOnly('$produce');\n}\n\n/** Sets the title of the page. The last component that sets it wins. */\nexport function $title(_value: unknown): void {\n compileTimeOnly('$title');\n}\n\n/**\n * The latest result of a server function that a form of this component posts\n * to, or undefined before the first post. Pending while the form sends.\n */\nexport function $action<F extends (...args: never[]) => unknown>(\n _fn: F,\n): Awaited<ReturnType<F>> | undefined {\n return compileTimeOnly('$action');\n}\n\n/**\n * Passes a child a signal, or a prop that the component writes, so a write\n * of the prop in the child writes it. The child destructures the prop with\n * `let`. Pass it as the value of a prop: `<Dialog open=$bind(open) />`.\n *\n * - Only a prop of type `Bindable<T>` takes it.\n * - With `set`, a write calls `set(next)` in place of writing the signal.\n */\nexport function $bind<T>(signal: T, set?: (next: T) => unknown): BindableMark<T>;\nexport function $bind(): never {\n return compileTimeOnly('$bind');\n}\n\n/**\n * Marks a function that a script makes as an event handler, so a spread can\n * pass it on, as it passes on a handler that a caller writes in markup.\n * `args` are JSON values that go with the handler, and it runs as\n * `fn(...args, event)`.\n */\nexport function $handler<A extends unknown[], E = Event>(\n fn: (...args: [...A, E]) => unknown,\n ...args: A\n): (event: E) => unknown;\n/** A function that does not read the event. */\nexport function $handler<A extends unknown[]>(\n fn: (...args: A) => unknown,\n ...args: A\n): (event: Event) => unknown;\nexport function $handler(): never {\n return compileTimeOnly('$handler');\n}\n"],"mappings":";AAOA,SAAS,gBAAgB,MAAqB;CAC5C,MAAM,IAAI,MAAM,GAAG,KAAK,+DAA+D;AACzF;;;;;;AAyBA,SAAgB,SAA8C;CAC5D,OAAO,gBAAgB,QAAQ;AACjC;AAKA,SAAgB,UAAiB;CAC/B,OAAO,gBAAgB,SAAS;AAClC;;;;;AASA,SAAgB,MAAS,QAAyB;CAChD,OAAO,gBAAgB,OAAO;AAChC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;;AAQA,SAAgB,YAAe,SAAe;CAC5C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,QAAQ,WAA4C;CAClE,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,QACd,WACA,UACM;CACN,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,SAAY,QAAc;CACxC,OAAO,gBAAgB,UAAU;AACnC;;AAGA,SAAgB,WAAW,OAAyB;CAClD,OAAO,gBAAgB,YAAY;AACrC;;AAGA,SAAgB,MAAc;CAC5B,OAAO,gBAAgB,KAAK;AAC9B;;AAGA,SAAgB,YAAe,UAAsB,QAAiB;CACpE,gBAAgB,aAAa;AAC/B;;AAGA,SAAgB,YAAe,UAAyB;CACtD,OAAO,gBAAgB,aAAa;AACtC;;;;;;AAOA,SAAgB,OAAwC,OAAkC;CACxF,OAAO,gBAAgB,QAAQ;AACjC;;AAGA,SAAgB,cAA+B;CAC7C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,SAAY,SAAY,SAAuC;CAC7E,gBAAgB,UAAU;AAC5B;;AAGA,SAAgB,OAAO,QAAuB;CAC5C,gBAAgB,QAAQ;AAC1B;;;;;AAMA,SAAgB,QACd,KACoC;CACpC,OAAO,gBAAgB,SAAS;AAClC;AAWA,SAAgB,QAAe;CAC7B,OAAO,gBAAgB,OAAO;AAChC;AAiBA,SAAgB,WAAkB;CAChC,OAAO,gBAAgB,UAAU;AACnC"}
|
|
1
|
+
{"version":3,"file":"signals.js","names":[],"sources":["../../src/runtime/signals.ts"],"sourcesContent":["// The compile-time functions of `.brm` files. The compiler replaces every\n// call and removes the import, so this module only gives them their types.\n// A call outside a `.brm` file throws.\n\nimport type { Context, NavigationState, Route } from './context.ts';\nimport type { RoutePath, RouteParams } from './routes.ts';\n\nfunction compileTimeOnly(name: string): never {\n throw new Error(`${name} works only in .brm files, which the brumate compiler compiles`);\n}\n\ndeclare const BINDABLE: unique symbol;\ndeclare const WRITES: unique symbol;\n\n/** The mark of a prop that a parent can bind. It has no value at runtime. */\nexport interface BindableMark<T> {\n readonly [BINDABLE]: T;\n}\n\n/**\n * What a binding writes. A binding of a signal of `T` takes a prop that writes `W` when `W` is\n * assignable to `T`, as a signal of `HTMLElement | undefined` takes the ref of a `div`.\n */\nexport interface WritableMark<W> {\n readonly [WRITES]: (value: W) => void;\n}\n\n/** What `$bind` returns: the mark of a prop, and the write side that checks the type of a ref. */\n// oxlint-disable-next-line typescript/no-empty-object-type, typescript/no-empty-interface -- An interface keeps its name in messages.\nexport interface BoundSignal<T> extends BindableMark<T>, WritableMark<T> {}\n\n/**\n * Marks a prop that a parent can bind with `$bind`, such as\n * `open?: Bindable<boolean>`. The parent passes `T` or `$bind(name)`.\n * Inside the component, `$props<T>()` gives `T`.\n */\nexport type Bindable<T> = T | BindableMark<T>;\n\n/** The props as the component reads them, with `Bindable<T>` as `T`. */\nexport type Unbound<T> = { [K in keyof T]: Exclude<T[K], BindableMark<unknown>> };\n\n/**\n * Returns the props of the component. Destructure the call to keep each prop\n * reactive. Destructure it with `let` to write props, such as\n * `let { open = false } = $props()`.\n */\n// oxlint-disable-next-line typescript/no-explicit-any -- Props are any object unless typed.\nexport function $props<T = Record<string, any>>(): Unbound<T> {\n return compileTimeOnly('$props');\n}\n\n/** Declares writable state. The variable reads and writes the signal. */\nexport function $signal<T>(value: T): T;\nexport function $signal<T>(): T | undefined;\nexport function $signal(): never {\n return compileTimeOnly('$signal');\n}\n\n/** The value of a memo: what a promise settles to, or the latest value of an async iterable. */\nexport type MemoValue<T> = Awaited<T> extends AsyncIterable<infer U> ? U : Awaited<T>;\n\n/**\n * Declares a value computed from other values. A promise is awaited where it\n * is read. An async iterable gives each of its values in turn.\n */\nexport function $memo<T>(_value: T): MemoValue<T> {\n return compileTimeOnly('$memo');\n}\n\n/**\n * Declares a memo that takes the value once it stops changing for `ms`\n * milliseconds, such as a search query while the user types. On the server,\n * and until the value first changes, it is the value.\n */\nexport function $debounced<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$debounced');\n}\n\n/**\n * Declares a memo that takes the value at most once every `ms`\n * milliseconds, and the last value after the wait, such as a position while\n * the pointer moves. On the server, and until the value first changes, it is the value.\n */\nexport function $throttled<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$throttled');\n}\n\n/**\n * Declares a value that follows a memo, and that handlers can write. A write\n * shows a guess, such as a new item while the form that adds it posts. The\n * value goes back to the memo when the memo changes, or when the server\n * calls of the page finish, such as after a failed post.\n */\nexport function $optimistic<T>(_source: T): T {\n return compileTimeOnly('$optimistic');\n}\n\n/** Runs a callback when the values it reads change, after the page resumes. Never on load. */\nexport function $effect(_callback: () => void | (() => void)): void {\n compileTimeOnly('$effect');\n}\n\n/** Runs a callback in the browser when a trigger fires. */\nexport function $client(\n _callback: () => void | (() => void),\n _trigger?: 'visible' | 'idle' | 'load',\n): void {\n compileTimeOnly('$client');\n}\n\n/** Reads a value without depending on it. */\nexport function $untrack<T>(_value: T): T {\n return compileTimeOnly('$untrack');\n}\n\n/** True while a new value of a memo, or of a memo it reads, loads on the client. Always false on the server. */\nexport function $isPending(_memo: unknown): boolean {\n return compileTimeOnly('$isPending');\n}\n\n/**\n * Waits for a memo to have its value, and gives it. It resolves at once when the memo is settled,\n * and after the load when the memo loads its first value or loads again. When the inputs of the\n * memo change while it waits, it waits for the load of the current inputs. It rejects with the\n * error of the memo, when `timeout` milliseconds pass, or when `signal` aborts. Use it in a handler,\n * an effect or a `$client` callback, never where a memo computes or markup renders.\n */\nexport function $resolve<T>(\n _memo: T,\n _options?: { timeout?: number; signal?: AbortSignal },\n): Promise<Awaited<T>> {\n return compileTimeOnly('$resolve');\n}\n\n/**\n * True when the parent passed a prop with `$bind`, so a write of it reaches the parent. The prop is\n * one that the component destructures with `let`. Always false on the server, where nothing writes.\n */\nexport function $isBound(_prop: unknown): boolean {\n return compileTimeOnly('$isBound');\n}\n\n/**\n * True when the caller passed the prop, even as `undefined`. A part uses it to tell a controlled\n * value, such as `value=(null)`, from no value. Declare it with `const` in the component script.\n */\nexport function $isPassed(_prop: unknown): boolean {\n return compileTimeOnly('$isPassed');\n}\n\n/** Returns an ID that is unique in the page and the same on the server and the client. */\nexport function $id(): string {\n return compileTimeOnly('$id');\n}\n\n/** Provides a value of a context to the components inside this one. */\nexport function $setContext<T>(_context: Context<T>, _value: T): void {\n compileTimeOnly('$setContext');\n}\n\n/** Reads a context from the nearest component above that provides it, or its default value. */\nexport function $getContext<T>(_context: Context<T>): T {\n return compileTimeOnly('$getContext');\n}\n\n/**\n * The route of the page: its URL, its query string and its params, typed\n * from the route files as `href` is. The server reads the request, and the\n * browser reads `location`. It changes when navigation changes the URL.\n */\nexport function $route<P extends RoutePath = RoutePath>(_path?: P): Route<RouteParams<P>> {\n return compileTimeOnly('$route');\n}\n\n/** The navigation that loads, with `pending` false when none does. Always `{ pending: false }` on the server. */\nexport function $navigation(): NavigationState {\n return compileTimeOnly('$navigation');\n}\n\n/** Changes an object or an array in a signal through a draft, and writes the signal with the result. */\nexport function $produce<T>(_signal: T, _recipe: (draft: T) => T | void): void {\n compileTimeOnly('$produce');\n}\n\n/** Sets the title of the page. The last component that sets it wins. */\nexport function $title(_value: unknown): void {\n compileTimeOnly('$title');\n}\n\n/**\n * The latest result of a server function that a form of this component posts\n * to, or undefined before the first post. Pending while the form sends.\n */\nexport function $action<F extends (...args: never[]) => unknown>(\n _fn: F,\n): Awaited<ReturnType<F>> | undefined {\n return compileTimeOnly('$action');\n}\n\n/**\n * Passes a child a signal, or a prop that the component writes, so a write\n * of the prop in the child writes it. The child destructures the prop with\n * `let`. Pass it as the value of a prop: `<Dialog open=$bind(open) />`.\n *\n * - Only a prop of type `Bindable<T>` takes it.\n * - With `set`, a write calls `set(next)` in place of writing the signal.\n */\nexport function $bind<T>(signal: T, set?: (next: T) => unknown): BoundSignal<T>;\nexport function $bind(): never {\n return compileTimeOnly('$bind');\n}\n\n/**\n * Marks a function that a script makes as an event handler, so a spread can\n * pass it on, as it passes on a handler that a caller writes in markup.\n * `args` are JSON values that go with the handler, and it runs as\n * `fn(...args, event)`.\n */\nexport function $handler<A extends unknown[], E = Event>(\n fn: (...args: [...A, E]) => unknown,\n ...args: A\n): (event: E) => unknown;\n/** A function that does not read the event. */\nexport function $handler<A extends unknown[]>(\n fn: (...args: A) => unknown,\n ...args: A\n): (event: Event) => unknown;\nexport function $handler(): never {\n return compileTimeOnly('$handler');\n}\n\n/**\n * Writes what the writes of the handler so far changed to the page, so the code after it can read\n * the DOM, such as to focus or measure what a write rendered. A handler is one pass, and the page\n * changes when it returns. Does nothing outside a handler, and on the server.\n */\nexport function flush(): void {\n (globalThis as { [key: symbol]: (() => void) | undefined })[Symbol.for('brumate.flush')]?.();\n}\n"],"mappings":";AAOA,SAAS,gBAAgB,MAAqB;CAC5C,MAAM,IAAI,MAAM,GAAG,KAAK,+DAA+D;AACzF;;;;;;AAsCA,SAAgB,SAA8C;CAC5D,OAAO,gBAAgB,QAAQ;AACjC;AAKA,SAAgB,UAAiB;CAC/B,OAAO,gBAAgB,SAAS;AAClC;;;;;AASA,SAAgB,MAAS,QAAyB;CAChD,OAAO,gBAAgB,OAAO;AAChC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;;AAQA,SAAgB,YAAe,SAAe;CAC5C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,QAAQ,WAA4C;CAClE,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,QACd,WACA,UACM;CACN,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,SAAY,QAAc;CACxC,OAAO,gBAAgB,UAAU;AACnC;;AAGA,SAAgB,WAAW,OAAyB;CAClD,OAAO,gBAAgB,YAAY;AACrC;;;;;;;;AASA,SAAgB,SACd,OACA,UACqB;CACrB,OAAO,gBAAgB,UAAU;AACnC;;;;;AAMA,SAAgB,SAAS,OAAyB;CAChD,OAAO,gBAAgB,UAAU;AACnC;;;;;AAMA,SAAgB,UAAU,OAAyB;CACjD,OAAO,gBAAgB,WAAW;AACpC;;AAGA,SAAgB,MAAc;CAC5B,OAAO,gBAAgB,KAAK;AAC9B;;AAGA,SAAgB,YAAe,UAAsB,QAAiB;CACpE,gBAAgB,aAAa;AAC/B;;AAGA,SAAgB,YAAe,UAAyB;CACtD,OAAO,gBAAgB,aAAa;AACtC;;;;;;AAOA,SAAgB,OAAwC,OAAkC;CACxF,OAAO,gBAAgB,QAAQ;AACjC;;AAGA,SAAgB,cAA+B;CAC7C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,SAAY,SAAY,SAAuC;CAC7E,gBAAgB,UAAU;AAC5B;;AAGA,SAAgB,OAAO,QAAuB;CAC5C,gBAAgB,QAAQ;AAC1B;;;;;AAMA,SAAgB,QACd,KACoC;CACpC,OAAO,gBAAgB,SAAS;AAClC;AAWA,SAAgB,QAAe;CAC7B,OAAO,gBAAgB,OAAO;AAChC;AAiBA,SAAgB,WAAkB;CAChC,OAAO,gBAAgB,UAAU;AACnC;;;;;;AAOA,SAAgB,QAAc;CAC5B,WAA4D,OAAO,IAAI,eAAe,EAAE,GAAG;AAC7F"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as LoaderOptions } from "../boot-
|
|
2
|
-
import { t as startWithoutNavigation } from "../static-loader-
|
|
1
|
+
import { t as LoaderOptions } from "../boot-DLlRmD9z.js";
|
|
2
|
+
import { t as startWithoutNavigation } from "../static-loader-BGgdp_Y5.js";
|
|
3
3
|
export { type LoaderOptions, startWithoutNavigation };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as startWithoutNavigation } from "../static-loader-
|
|
1
|
+
export { t as startWithoutNavigation } from "../static-loader-BZR17hSw.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { At as ClientModule } from "../client-DBwL2wKQ.js";
|
|
2
|
+
import { It as EntryMiddleware, d as RenderOptions, t as Component } from "../server-BvPIg9pT.js";
|
|
3
3
|
//#region src/runtime/testing.d.ts
|
|
4
4
|
/** The middleware of files of server functions, by function ID. */
|
|
5
5
|
type FileMiddleware = Record<string, EntryMiddleware>;
|
|
@@ -21,6 +21,11 @@ export interface Actions {
|
|
|
21
21
|
input: (selector: string, value: string) => void;
|
|
22
22
|
/** Submits a form, as its submit button does. */
|
|
23
23
|
submit: (selector: string) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Brings the elements that match a selector into view, so what waits for
|
|
26
|
+
* them with the 'visible' trigger runs. See `offscreen`.
|
|
27
|
+
*/
|
|
28
|
+
reveal: (selector: string) => void;
|
|
24
29
|
/**
|
|
25
30
|
* Retries an assertion until it passes. The first event of a test loads
|
|
26
31
|
* client code, so its effects arrive a moment later.
|
|
@@ -34,7 +39,15 @@ export interface Mounted extends Actions {
|
|
|
34
39
|
unmount: () => void;
|
|
35
40
|
}
|
|
36
41
|
/** Renders a component on the server and resumes it in the document of a test. */
|
|
37
|
-
export type Mount = <P>(component: Component<P>, props: P, renderOptions?:
|
|
42
|
+
export type Mount = <P>(component: Component<P>, props: P, renderOptions?: MountRenderOptions) => Promise<Mounted>;
|
|
43
|
+
/** The options of `render`, and the elements to keep out of view. */
|
|
44
|
+
export interface MountRenderOptions extends RenderOptions {
|
|
45
|
+
/**
|
|
46
|
+
* A selector of elements that stay out of view, for a test of what waits
|
|
47
|
+
* for them with the 'visible' trigger. `reveal` brings them into view.
|
|
48
|
+
*/
|
|
49
|
+
offscreen?: string;
|
|
50
|
+
}
|
|
38
51
|
/** Returns `mount`, which loads client modules with `options.load`. */
|
|
39
52
|
export declare function createMount(options: TestingOptions): Mount;
|
|
40
53
|
/** Server functions by ID, as `functions` of `virtual:brumate/server` has them. */
|
|
@@ -76,6 +89,8 @@ export interface VisitOptions {
|
|
|
76
89
|
cookies?: Record<string, string>;
|
|
77
90
|
/** Headers of every request, such as `accept-language`. */
|
|
78
91
|
headers?: HeadersInit;
|
|
92
|
+
/** A selector of elements that stay out of view until `reveal` brings them in. */
|
|
93
|
+
offscreen?: string;
|
|
79
94
|
}
|
|
80
95
|
export interface Visited extends Actions {
|
|
81
96
|
/** The path and the query of the page, such as `/issues?q=bug`. It changes with client navigation. */
|
package/dist/runtime/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as start } from "../loader-
|
|
1
|
+
import { b as render, u as handleRequest } from "../server-DjyOVJtJ.js";
|
|
2
|
+
import { t as start } from "../loader-BjKGJzLN.js";
|
|
3
3
|
//#region src/runtime/nodes.ts
|
|
4
4
|
const VOID = /* @__PURE__ */ new Set([
|
|
5
5
|
"area",
|
|
@@ -42,13 +42,110 @@ function wholeNodes(markup) {
|
|
|
42
42
|
}
|
|
43
43
|
//#endregion
|
|
44
44
|
//#region src/runtime/testing.ts
|
|
45
|
+
let view;
|
|
46
|
+
/** Reports an element that waits out of view, as visible. */
|
|
47
|
+
function reveal(element) {
|
|
48
|
+
view?.revealed.add(element);
|
|
49
|
+
for (const entry of view?.waiting ?? []) if (entry.element === element) {
|
|
50
|
+
view.waiting.delete(entry);
|
|
51
|
+
entry.report();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Replaces the IntersectionObserver of the environment with one that reports
|
|
56
|
+
* each element it observes as visible, except the ones that match a selector
|
|
57
|
+
* of `offscreen`. happy-dom has an observer that never reports. Returns what
|
|
58
|
+
* puts the observer of the environment back.
|
|
59
|
+
*/
|
|
60
|
+
function watchView(offscreen) {
|
|
61
|
+
if (!view) {
|
|
62
|
+
const current = {
|
|
63
|
+
hidden: /* @__PURE__ */ new Set(),
|
|
64
|
+
revealed: /* @__PURE__ */ new WeakSet(),
|
|
65
|
+
waiting: /* @__PURE__ */ new Set(),
|
|
66
|
+
users: 0,
|
|
67
|
+
original: globalThis.IntersectionObserver
|
|
68
|
+
};
|
|
69
|
+
class Reporting {
|
|
70
|
+
#callback;
|
|
71
|
+
#entries = /* @__PURE__ */ new Set();
|
|
72
|
+
root = null;
|
|
73
|
+
rootMargin = "0px";
|
|
74
|
+
thresholds = [0];
|
|
75
|
+
constructor(callback) {
|
|
76
|
+
this.#callback = callback;
|
|
77
|
+
}
|
|
78
|
+
observe(element) {
|
|
79
|
+
const report = () => {
|
|
80
|
+
const rect = element.getBoundingClientRect();
|
|
81
|
+
this.#callback([{
|
|
82
|
+
target: element,
|
|
83
|
+
isIntersecting: true,
|
|
84
|
+
intersectionRatio: 1,
|
|
85
|
+
boundingClientRect: rect,
|
|
86
|
+
intersectionRect: rect,
|
|
87
|
+
rootBounds: null,
|
|
88
|
+
time: performance.now()
|
|
89
|
+
}], this);
|
|
90
|
+
};
|
|
91
|
+
const entry = {
|
|
92
|
+
element,
|
|
93
|
+
report
|
|
94
|
+
};
|
|
95
|
+
this.#entries.add(entry);
|
|
96
|
+
let isHidden = false;
|
|
97
|
+
if (!current.revealed.has(element)) {
|
|
98
|
+
for (const { selector } of current.hidden) if (element.matches(selector)) {
|
|
99
|
+
isHidden = true;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (isHidden) current.waiting.add(entry);
|
|
104
|
+
else queueMicrotask(() => {
|
|
105
|
+
if (this.#entries.has(entry)) report();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
unobserve(element) {
|
|
109
|
+
for (const entry of this.#entries) if (entry.element === element) {
|
|
110
|
+
this.#entries.delete(entry);
|
|
111
|
+
current.waiting.delete(entry);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
disconnect() {
|
|
115
|
+
for (const entry of this.#entries) current.waiting.delete(entry);
|
|
116
|
+
this.#entries.clear();
|
|
117
|
+
}
|
|
118
|
+
takeRecords() {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
globalThis.IntersectionObserver = Reporting;
|
|
123
|
+
view = current;
|
|
124
|
+
}
|
|
125
|
+
const current = view;
|
|
126
|
+
current.users++;
|
|
127
|
+
const hidden = { selector: offscreen ?? "" };
|
|
128
|
+
if (offscreen !== void 0) current.hidden.add(hidden);
|
|
129
|
+
let released = false;
|
|
130
|
+
return () => {
|
|
131
|
+
if (released) return;
|
|
132
|
+
released = true;
|
|
133
|
+
current.hidden.delete(hidden);
|
|
134
|
+
if (--current.users === 0) {
|
|
135
|
+
if (current.original) globalThis.IntersectionObserver = current.original;
|
|
136
|
+
else delete globalThis.IntersectionObserver;
|
|
137
|
+
current.waiting.clear();
|
|
138
|
+
view = void 0;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
45
142
|
/** The actions on the elements inside `root`. */
|
|
46
143
|
function actions(root) {
|
|
47
|
-
|
|
144
|
+
function get(selector) {
|
|
48
145
|
const element = root.querySelector(selector);
|
|
49
146
|
if (!element) throw new Error(`No element matches ${selector}`);
|
|
50
147
|
return element;
|
|
51
|
-
}
|
|
148
|
+
}
|
|
52
149
|
return {
|
|
53
150
|
get,
|
|
54
151
|
text: (selector) => get(selector).textContent ?? "",
|
|
@@ -64,6 +161,9 @@ function actions(root) {
|
|
|
64
161
|
cancelable: true
|
|
65
162
|
}));
|
|
66
163
|
},
|
|
164
|
+
reveal: (selector) => {
|
|
165
|
+
for (const element of root.querySelectorAll(selector)) reveal(element);
|
|
166
|
+
},
|
|
67
167
|
waitFor: async (assertion, timeout = 2e3) => {
|
|
68
168
|
const until = Date.now() + timeout;
|
|
69
169
|
for (;;) try {
|
|
@@ -115,35 +215,36 @@ function createMount(options) {
|
|
|
115
215
|
* state, and starts the loader. Markup that streams in later is added as
|
|
116
216
|
* it arrives.
|
|
117
217
|
*/
|
|
118
|
-
return async function mount(component, props, renderOptions = {}) {
|
|
218
|
+
return async function mount(component, props, { offscreen, ...renderOptions } = {}) {
|
|
119
219
|
const base = renderOptions.base ?? ++mounts * 1e6;
|
|
120
220
|
const { html, state, pending } = await render(component, props, {
|
|
121
221
|
...renderOptions,
|
|
122
222
|
base
|
|
123
223
|
});
|
|
224
|
+
const unwatch = watchView(offscreen);
|
|
124
225
|
const container = document.createElement("div");
|
|
125
226
|
container.innerHTML = html + state;
|
|
126
227
|
document.body.append(container);
|
|
127
|
-
container.querySelectorAll("script[b-state]")
|
|
228
|
+
for (const script of container.querySelectorAll("script[b-state]")) run(script);
|
|
128
229
|
loader ??= {
|
|
129
230
|
stop: start({
|
|
130
231
|
load: options.load,
|
|
131
232
|
rpc: options.rpc,
|
|
132
|
-
navigate: false
|
|
133
|
-
preload: false
|
|
233
|
+
navigate: false
|
|
134
234
|
}),
|
|
135
235
|
users: 0
|
|
136
236
|
};
|
|
137
237
|
loader.users++;
|
|
138
238
|
let mounted = true;
|
|
139
|
-
|
|
239
|
+
function stop() {
|
|
140
240
|
if (!mounted || !loader) return;
|
|
141
241
|
mounted = false;
|
|
242
|
+
unwatch();
|
|
142
243
|
if (--loader.users === 0) {
|
|
143
244
|
loader.stop();
|
|
144
245
|
loader = void 0;
|
|
145
246
|
}
|
|
146
|
-
}
|
|
247
|
+
}
|
|
147
248
|
(async () => {
|
|
148
249
|
for await (const chunk of pending) append(container, chunk);
|
|
149
250
|
})();
|
|
@@ -184,7 +285,7 @@ function answerCalls(functions, options = {}) {
|
|
|
184
285
|
let loaded;
|
|
185
286
|
/** The error of a call that a server function made through `fetch`. */
|
|
186
287
|
let failure;
|
|
187
|
-
|
|
288
|
+
async function answer(input, init) {
|
|
188
289
|
const base = globalThis.location?.href ?? "http://localhost/";
|
|
189
290
|
const url = new URL(input instanceof Request ? input.url : String(input), base);
|
|
190
291
|
if (!url.pathname.startsWith(`${prefix}/`)) return original(input, init);
|
|
@@ -201,10 +302,12 @@ function answerCalls(functions, options = {}) {
|
|
|
201
302
|
const request = input instanceof Request ? new Request(input, init) : new Request(url, init);
|
|
202
303
|
const guards = options.fileMiddleware;
|
|
203
304
|
const fileMiddleware = typeof guards === "function" ? await guards() : guards;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
305
|
+
function handle() {
|
|
306
|
+
return handleRequest(registry, request, prefix, {
|
|
307
|
+
middleware: options.middleware,
|
|
308
|
+
fileMiddleware
|
|
309
|
+
});
|
|
310
|
+
}
|
|
208
311
|
const response = await (calls ? calls.run(id, handle) : handle());
|
|
209
312
|
if (failure) {
|
|
210
313
|
const error = failure;
|
|
@@ -212,7 +315,7 @@ function answerCalls(functions, options = {}) {
|
|
|
212
315
|
throw error;
|
|
213
316
|
}
|
|
214
317
|
return response ?? original(input, init);
|
|
215
|
-
}
|
|
318
|
+
}
|
|
216
319
|
globalThis.fetch = answer;
|
|
217
320
|
return () => {
|
|
218
321
|
if (globalThis.fetch === answer) globalThis.fetch = original;
|
|
@@ -232,11 +335,16 @@ function storeCookies(jar, response) {
|
|
|
232
335
|
const equals = pair.indexOf("=");
|
|
233
336
|
const name = pair.slice(0, equals).trim();
|
|
234
337
|
if (equals < 1) continue;
|
|
235
|
-
|
|
338
|
+
let gone = false;
|
|
339
|
+
for (const attribute of attributes) {
|
|
236
340
|
const [key = "", value = ""] = attribute.trim().split("=");
|
|
237
341
|
const lower = key.toLowerCase();
|
|
238
|
-
|
|
239
|
-
|
|
342
|
+
if (lower === "max-age" && Number(value) <= 0 || lower === "expires" && Date.parse(value) <= Date.now()) {
|
|
343
|
+
gone = true;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (gone) jar.delete(name);
|
|
240
348
|
else jar.set(name, pair.slice(equals + 1).trim());
|
|
241
349
|
}
|
|
242
350
|
}
|
|
@@ -257,22 +365,26 @@ function createVisit(options) {
|
|
|
257
365
|
const original = globalThis.fetch;
|
|
258
366
|
const origin = location.origin;
|
|
259
367
|
history.replaceState(null, "", new URL(path, origin));
|
|
260
|
-
|
|
368
|
+
async function answer(input, init) {
|
|
261
369
|
let url = new URL(input instanceof Request ? input.url : String(input), location.href);
|
|
262
370
|
if (url.origin !== origin) return original(input, init);
|
|
263
371
|
let method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
264
372
|
let body = init?.body ?? void 0;
|
|
265
373
|
const extra = new Headers(input instanceof Request ? input.headers : void 0);
|
|
266
|
-
new Headers(init?.headers)
|
|
374
|
+
for (const [name, value] of new Headers(init?.headers)) extra.set(name, value);
|
|
267
375
|
for (let hops = 0;; hops++) {
|
|
268
376
|
const request = new Request(url, {
|
|
269
377
|
method,
|
|
270
378
|
body,
|
|
271
379
|
signal: init?.signal ?? null
|
|
272
380
|
});
|
|
273
|
-
new Headers(visitOptions.headers)
|
|
274
|
-
|
|
275
|
-
if (jar.size > 0)
|
|
381
|
+
for (const [name, value] of new Headers(visitOptions.headers)) request.headers.set(name, value);
|
|
382
|
+
for (const [name, value] of extra) request.headers.set(name, value);
|
|
383
|
+
if (jar.size > 0) {
|
|
384
|
+
const cookies = [];
|
|
385
|
+
for (const [name, value] of jar) cookies.push(`${name}=${value}`);
|
|
386
|
+
request.headers.set("cookie", cookies.join("; "));
|
|
387
|
+
}
|
|
276
388
|
if (method !== "GET" && method !== "HEAD") request.headers.set("origin", origin);
|
|
277
389
|
const response = await (url.pathname.startsWith(`${prefix}/`) ? options.calls : options.routes)().then((handler) => handler(request)) ?? new Response("Not found", { status: 404 });
|
|
278
390
|
storeCookies(jar, response);
|
|
@@ -289,18 +401,18 @@ function createVisit(options) {
|
|
|
289
401
|
extra.delete("content-type");
|
|
290
402
|
}
|
|
291
403
|
}
|
|
292
|
-
}
|
|
404
|
+
}
|
|
293
405
|
globalThis.fetch = answer;
|
|
294
406
|
const ran = /* @__PURE__ */ new WeakSet();
|
|
295
|
-
|
|
407
|
+
function runOnce(script) {
|
|
296
408
|
if (!ran.has(script) && !script.hasAttribute("src") && !script.hasAttribute("type")) {
|
|
297
409
|
ran.add(script);
|
|
298
410
|
run(script);
|
|
299
411
|
}
|
|
300
|
-
}
|
|
412
|
+
}
|
|
301
413
|
const scripts = new MutationObserver((records) => {
|
|
302
414
|
for (const record of records) for (const node of record.addedNodes) if (node.nodeName === "SCRIPT") runOnce(node);
|
|
303
|
-
else if (node instanceof Element) node.querySelectorAll("script")
|
|
415
|
+
else if (node instanceof Element) for (const script of node.querySelectorAll("script")) runOnce(script);
|
|
304
416
|
});
|
|
305
417
|
const response = await answer(path);
|
|
306
418
|
history.replaceState(null, "", response.url);
|
|
@@ -318,18 +430,22 @@ function createVisit(options) {
|
|
|
318
430
|
const page = new DOMParser().parseFromString(html.slice(0, cut), "text/html");
|
|
319
431
|
for (const name of document.documentElement.getAttributeNames()) document.documentElement.removeAttribute(name);
|
|
320
432
|
for (const attribute of page.documentElement.attributes) document.documentElement.setAttribute(attribute.name, attribute.value);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
document.
|
|
433
|
+
const headNodes = [];
|
|
434
|
+
for (const node of page.head.childNodes) headNodes.push(document.importNode(node, true));
|
|
435
|
+
document.head.replaceChildren(...headNodes);
|
|
436
|
+
const bodyNodes = [];
|
|
437
|
+
for (const node of page.body.childNodes) bodyNodes.push(document.importNode(node, true));
|
|
438
|
+
document.body.replaceChildren(...bodyNodes);
|
|
439
|
+
for (const script of document.querySelectorAll("script")) runOnce(script);
|
|
324
440
|
scripts.observe(document, {
|
|
325
441
|
childList: true,
|
|
326
442
|
subtree: true
|
|
327
443
|
});
|
|
444
|
+
const unwatch = watchView(visitOptions.offscreen);
|
|
328
445
|
const stop = start({
|
|
329
446
|
load: options.load,
|
|
330
447
|
rpc: prefix,
|
|
331
|
-
navigate: true
|
|
332
|
-
preload: false
|
|
448
|
+
navigate: true
|
|
333
449
|
});
|
|
334
450
|
let rest = html.slice(cut);
|
|
335
451
|
let open = true;
|
|
@@ -361,6 +477,7 @@ function createVisit(options) {
|
|
|
361
477
|
open = false;
|
|
362
478
|
visited = void 0;
|
|
363
479
|
stop();
|
|
480
|
+
unwatch();
|
|
364
481
|
scripts.disconnect();
|
|
365
482
|
reader.cancel().catch(() => {});
|
|
366
483
|
if (globalThis.fetch === answer) globalThis.fetch = original;
|