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.
- package/README.md +2 -2
- package/check.d.ts +49 -0
- package/dist/{boot-D-IdPy7B.d.ts → boot-DLlRmD9z.d.ts} +11 -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-DBwL2wKQ.d.ts +669 -0
- package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
- package/dist/client-routes-BtGpYCef.js.map +1 -0
- package/dist/{cookies-Av5WFmcf.js → cookies-Cnbf4w-S.js} +15 -7
- package/dist/cookies-Cnbf4w-S.js.map +1 -0
- package/dist/{defer-D0bo1Gqx.js → defer-CKWZLv2K.js} +8 -4
- package/dist/defer-CKWZLv2K.js.map +1 -0
- package/dist/devtools-4uTPwR_v.js +597 -0
- package/dist/devtools-4uTPwR_v.js.map +1 -0
- package/dist/devtools-panel-Be9pxYgv.js +1994 -0
- package/dist/devtools-panel-Be9pxYgv.js.map +1 -0
- package/dist/events-LgLdp1R7.js +114 -0
- 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-j1xPAR14.d.ts +281 -0
- package/dist/forms-nXK7-Lv_.js +440 -0
- package/dist/forms-nXK7-Lv_.js.map +1 -0
- package/dist/highlight.d.ts +17 -0
- package/dist/highlight.js +278 -0
- package/dist/highlight.js.map +1 -0
- package/dist/html-BtKRyi7g.js +305 -0
- package/dist/html-BtKRyi7g.js.map +1 -0
- package/dist/html-Bw9Qwu6F.d.ts +107 -0
- package/dist/index.d.ts +142 -11
- package/dist/index.js +641 -106
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BJtACnQp.js → inspect-Y6y4uNZp.js} +4333 -681
- package/dist/inspect-Y6y4uNZp.js.map +1 -0
- package/dist/{loader-B18i3_-T.js → loader-BjKGJzLN.js} +21 -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-BwuZveDF.js → navigate-CfOr-TRF.js} +130 -24
- 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-B7X9ori9.js +402 -0
- package/dist/produce-B7X9ori9.js.map +1 -0
- package/dist/produce-DIgHBVwL.d.ts +148 -0
- package/dist/{rpc-B-Zkn6Ch.js → rpc-Q-XkLwFh.js} +28 -13
- 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 +172 -5
- 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 +38 -1
- package/dist/runtime/events.js +1 -1
- package/dist/runtime/forms.d.ts +2 -0
- package/dist/runtime/forms.js +1 -0
- package/dist/runtime/gather.d.ts +25 -0
- package/dist/runtime/gather.js +33 -0
- package/dist/runtime/gather.js.map +1 -0
- 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 -4
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +75 -2
- package/dist/runtime/signals.js +44 -2
- 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/runtime/values.d.ts +2 -0
- package/dist/runtime/values.js +24 -0
- package/dist/runtime/values.js.map +1 -0
- package/dist/{server-BA9SJ2Vm.d.ts → server-BvPIg9pT.d.ts} +363 -32
- package/dist/{server-BqfM95r1.js → server-DjyOVJtJ.js} +1309 -220
- package/dist/server-DjyOVJtJ.js.map +1 -0
- package/dist/{static-loader-BzE9SRaj.d.ts → static-loader-BGgdp_Y5.d.ts} +2 -2
- package/dist/static-loader-BZR17hSw.js +312 -0
- package/dist/static-loader-BZR17hSw.js.map +1 -0
- package/dist/{stream-JaMHMdBD.js → stream-BP5AVmg5.js} +182 -17
- package/dist/stream-BP5AVmg5.js.map +1 -0
- package/dist/values-B8C7CLvG.d.ts +63 -0
- package/dist/vite.d.ts +20 -20
- package/dist/vite.js +2031 -539
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +951 -0
- package/forms/forms.brm.ts +141 -0
- package/package.json +41 -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-C0UCNL3J.js +0 -1643
- package/dist/client-C0UCNL3J.js.map +0 -1
- package/dist/client-MD0ZmcFR.d.ts +0 -354
- package/dist/client-routes-JTbGtukf.js.map +0 -1
- package/dist/cookies-Av5WFmcf.js.map +0 -1
- package/dist/defer-D0bo1Gqx.js.map +0 -1
- package/dist/devtools-C50VH8gZ.js +0 -113
- package/dist/devtools-C50VH8gZ.js.map +0 -1
- package/dist/devtools-panel-AYjfwPhj.js +0 -435
- package/dist/devtools-panel-AYjfwPhj.js.map +0 -1
- package/dist/events-BKWRqtMg.js +0 -52
- package/dist/events-BKWRqtMg.js.map +0 -1
- package/dist/files-Bnn1JqHx.js +0 -192
- package/dist/files-Bnn1JqHx.js.map +0 -1
- package/dist/html-bHZbkK-h.js +0 -170
- package/dist/html-bHZbkK-h.js.map +0 -1
- package/dist/html-y1q7-t7D.d.ts +0 -60
- package/dist/inspect-BJtACnQp.js.map +0 -1
- package/dist/loader-B18i3_-T.js.map +0 -1
- package/dist/navigate-BwuZveDF.js.map +0 -1
- package/dist/produce-CWfJ4byV.js +0 -167
- package/dist/produce-CWfJ4byV.js.map +0 -1
- package/dist/produce-D4K7qpaL.d.ts +0 -72
- package/dist/rpc-B-Zkn6Ch.js.map +0 -1
- package/dist/server-BqfM95r1.js.map +0 -1
- package/dist/static-loader-DOygOFj5.js +0 -216
- package/dist/static-loader-DOygOFj5.js.map +0 -1
- package/dist/stream-JaMHMdBD.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as LoaderOptions } from "./boot-
|
|
1
|
+
import { t as LoaderOptions } from "./boot-DLlRmD9z.js";
|
|
2
2
|
//#region src/runtime/static-loader.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* `start` for a site that loads every page with a full page load, as with
|
|
@@ -8,4 +8,4 @@ import { t as LoaderOptions } from "./boot-D-IdPy7B.js";
|
|
|
8
8
|
declare function startWithoutNavigation(options: LoaderOptions): () => void;
|
|
9
9
|
//#endregion
|
|
10
10
|
export { startWithoutNavigation as t };
|
|
11
|
-
//# sourceMappingURL=static-loader-
|
|
11
|
+
//# sourceMappingURL=static-loader-BGgdp_Y5.d.ts.map
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { o as HAS_LATE_MARKUP, r as HAS_BLOCKS, s as HAS_LISTENERS, t as HAS_ACTIONS } from "./features-CHY5Ekku.js";
|
|
2
|
+
//#region src/runtime/boot.ts
|
|
3
|
+
/** True on the dev server. A Vite build replaces it with `false`, so the devtools calls go. */
|
|
4
|
+
const DEV = import.meta.env?.DEV;
|
|
5
|
+
/** The hooks of the devtools overlay, under the same key as the core's. */
|
|
6
|
+
function devtools() {
|
|
7
|
+
return globalThis[Symbol.for("brumate.devtools")];
|
|
8
|
+
}
|
|
9
|
+
const parsed = /* @__PURE__ */ new Map();
|
|
10
|
+
function entries(element) {
|
|
11
|
+
const value = element.getAttribute("b-on") ?? "";
|
|
12
|
+
return parsed.get(value) ?? parsed.set(value, value.split(" ").filter(Boolean).map((entry) => {
|
|
13
|
+
const [name, ref] = entry.split("=");
|
|
14
|
+
const [type, ...modifiers] = name.split(":");
|
|
15
|
+
return {
|
|
16
|
+
raw: entry,
|
|
17
|
+
type,
|
|
18
|
+
modifiers,
|
|
19
|
+
ref
|
|
20
|
+
};
|
|
21
|
+
})).get(value);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Imports the core. It reads one export by name, so a build keeps only it and
|
|
25
|
+
* the helpers that compiled components call.
|
|
26
|
+
*/
|
|
27
|
+
let corePromise;
|
|
28
|
+
const importCore = () => corePromise ??= import("./runtime/client.js").then((client) => client.loader, (error) => {
|
|
29
|
+
corePromise = void 0;
|
|
30
|
+
throw error;
|
|
31
|
+
});
|
|
32
|
+
/** Runs a function when the browser is idle. */
|
|
33
|
+
const idle = (fn) => (window.requestIdleCallback ?? setTimeout)(fn);
|
|
34
|
+
/**
|
|
35
|
+
* Starts resuming the page. Listens to the events in `b-on` attributes
|
|
36
|
+
* and loads `brumate/client` and the component's module on the first one.
|
|
37
|
+
* `navigate` adds client navigation, and returns how to import the core.
|
|
38
|
+
* Returns a function that removes the listeners and stops the core.
|
|
39
|
+
*/
|
|
40
|
+
function boot(options, navigate) {
|
|
41
|
+
let core;
|
|
42
|
+
let stopped = false;
|
|
43
|
+
/** The event types that the document listens to, and whether each listener is passive. */
|
|
44
|
+
const types = /* @__PURE__ */ new Map();
|
|
45
|
+
const removers = [];
|
|
46
|
+
const listen = (target, type, listener, flags) => {
|
|
47
|
+
target.addEventListener(type, listener, flags);
|
|
48
|
+
removers.push(() => target.removeEventListener(type, listener, flags));
|
|
49
|
+
};
|
|
50
|
+
let load = importCore;
|
|
51
|
+
const modules = /* @__PURE__ */ new Map();
|
|
52
|
+
const loadModule = (id) => {
|
|
53
|
+
if (modules.has(id)) return modules.get(id);
|
|
54
|
+
const promise = options.load(id);
|
|
55
|
+
modules.set(id, promise);
|
|
56
|
+
promise?.catch(() => modules.delete(id));
|
|
57
|
+
return promise;
|
|
58
|
+
};
|
|
59
|
+
const partLoads = /* @__PURE__ */ new Map();
|
|
60
|
+
const loadPart = (module, part) => {
|
|
61
|
+
const key = `${module.id}#${part}`;
|
|
62
|
+
let promise = partLoads.get(key);
|
|
63
|
+
if (!promise) {
|
|
64
|
+
promise = module.load(part);
|
|
65
|
+
partLoads.set(key, promise);
|
|
66
|
+
promise.catch(() => partLoads.delete(key));
|
|
67
|
+
}
|
|
68
|
+
return promise;
|
|
69
|
+
};
|
|
70
|
+
let serialLoad;
|
|
71
|
+
const loadSerial = () => {
|
|
72
|
+
serialLoad ??= options.serial?.();
|
|
73
|
+
serialLoad?.catch(() => serialLoad = void 0);
|
|
74
|
+
return serialLoad;
|
|
75
|
+
};
|
|
76
|
+
const loadCore = () => core ??= Promise.all([load(), loadSerial()]).then(([client, serial]) => {
|
|
77
|
+
client.init({
|
|
78
|
+
...options,
|
|
79
|
+
load: loadModule,
|
|
80
|
+
loadPart,
|
|
81
|
+
listen: scanInsert,
|
|
82
|
+
inserted,
|
|
83
|
+
serial
|
|
84
|
+
});
|
|
85
|
+
return client;
|
|
86
|
+
});
|
|
87
|
+
listen(document, "brumate:core", () => void loadCore());
|
|
88
|
+
const run = (element, ref, event) => {
|
|
89
|
+
if (stopped) return;
|
|
90
|
+
loadCore().then((client) => client.handle(element, ref, event));
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* A key of `prevent` matches its `event.key` while only the modifier that it names is held. A
|
|
94
|
+
* key alone matches while Ctrl, Meta and Alt are up, so the shortcuts of the browser, such as
|
|
95
|
+
* Cmd+Left or Alt+Left, keep their default. `Mod+` is Ctrl or Meta. Shift does not count.
|
|
96
|
+
*/
|
|
97
|
+
const keyMatches = (key, event) => {
|
|
98
|
+
const plus = key.indexOf("+", 1);
|
|
99
|
+
const modifier = plus > 0 ? key.slice(0, plus) : "";
|
|
100
|
+
if ((event.key === " " ? "Space" : event.key) !== (plus > 0 ? key.slice(plus + 1) : key)) return false;
|
|
101
|
+
switch (modifier) {
|
|
102
|
+
case "Mod": return (event.ctrlKey || event.metaKey) && !event.altKey;
|
|
103
|
+
case "Ctrl": return event.ctrlKey && !event.metaKey && !event.altKey;
|
|
104
|
+
case "Meta": return event.metaKey && !event.ctrlKey && !event.altKey;
|
|
105
|
+
case "Alt": return event.altKey && !event.ctrlKey && !event.metaKey;
|
|
106
|
+
default: return !event.ctrlKey && !event.metaKey && !event.altKey;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const apply = (event, element, entry) => {
|
|
110
|
+
for (const modifier of entry.modifiers) if (modifier === "prevent" || modifier.startsWith("prevent(") && !event.isComposing && modifier.slice(8, -1).split(",").some((key) => keyMatches(key, event))) event.preventDefault();
|
|
111
|
+
if (entry.modifiers.includes("once")) element.setAttribute("b-on", entries(element).map((item) => item.raw).filter((raw) => raw !== entry.raw).join(" "));
|
|
112
|
+
run(element, entry.ref, event);
|
|
113
|
+
return entry.modifiers.includes("stop");
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Handlers run as if each element had its own listener: those with
|
|
117
|
+
* `capture` from the outside in, then the others from the target outwards.
|
|
118
|
+
* An event that does not bubble, such as `focus`, reaches only the others
|
|
119
|
+
* of its target. `stop` ends the event where it is.
|
|
120
|
+
*/
|
|
121
|
+
const onEvent = (event) => {
|
|
122
|
+
for (let node = event.target; node; node = node.parentNode) for (const [type, check] of cancels.get(node) ?? []) {
|
|
123
|
+
if (type !== event.type) continue;
|
|
124
|
+
let cancel = false;
|
|
125
|
+
try {
|
|
126
|
+
cancel = check(event);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error(error);
|
|
129
|
+
}
|
|
130
|
+
if (cancel) {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const path = [];
|
|
136
|
+
for (let node = event.target; node && node !== document; node = node.parentNode) if (node.nodeType === 1 && node.hasAttribute("b-on")) path.push(node);
|
|
137
|
+
const phase = (elements, capture) => {
|
|
138
|
+
for (const element of elements) {
|
|
139
|
+
let stop = false;
|
|
140
|
+
for (const entry of entries(element)) if (entry.type === event.type && entry.modifiers.includes("capture") === capture && apply(event, element, entry)) stop = true;
|
|
141
|
+
if (stop) {
|
|
142
|
+
event.stopPropagation();
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
};
|
|
148
|
+
if (!phase([...path].reverse(), true)) phase(event.bubbles ? path : path.filter((element) => element === event.target), false);
|
|
149
|
+
};
|
|
150
|
+
const cancels = /* @__PURE__ */ new WeakMap();
|
|
151
|
+
globalThis[Symbol.for("brumate.cancel")] = (element, type, check) => {
|
|
152
|
+
const entry = [type, check];
|
|
153
|
+
let set = cancels.get(element);
|
|
154
|
+
if (!set) cancels.set(element, set = /* @__PURE__ */ new Set());
|
|
155
|
+
set.add(entry);
|
|
156
|
+
delegate(type, false);
|
|
157
|
+
return () => void set.delete(entry);
|
|
158
|
+
};
|
|
159
|
+
/** True for an entry that prevents the default action, which a passive listener cannot do. */
|
|
160
|
+
const prevents = (entry) => entry.modifiers.some((modifier) => modifier.startsWith("prevent"));
|
|
161
|
+
/**
|
|
162
|
+
* Listens to an event type on the document. The listener is passive, so
|
|
163
|
+
* scrolling does not wait for it, until an entry of the type prevents. `click` and `submit` never
|
|
164
|
+
* scroll, so they are never passive: a `prevent` that is written after load cancels them.
|
|
165
|
+
*/
|
|
166
|
+
const delegate = (type, cancel) => {
|
|
167
|
+
const prevent = cancel || type === "click" || type === "submit";
|
|
168
|
+
const passive = types.get(type);
|
|
169
|
+
if (passive === false || passive === true && !prevent) return;
|
|
170
|
+
if (passive) document.removeEventListener(type, onEvent, true);
|
|
171
|
+
types.set(type, !prevent);
|
|
172
|
+
listen(document, type, onEvent, {
|
|
173
|
+
capture: true,
|
|
174
|
+
passive: !prevent
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
const started = /* @__PURE__ */ new WeakSet();
|
|
178
|
+
const select = (root, selector) => {
|
|
179
|
+
const found = [];
|
|
180
|
+
const add = (element) => {
|
|
181
|
+
if (element.tagName === "TEMPLATE") {
|
|
182
|
+
if (started.has(element)) return;
|
|
183
|
+
started.add(element);
|
|
184
|
+
}
|
|
185
|
+
found.push(element);
|
|
186
|
+
};
|
|
187
|
+
if (root.matches?.(selector)) add(root);
|
|
188
|
+
for (const element of root.querySelectorAll(selector)) add(element);
|
|
189
|
+
return found;
|
|
190
|
+
};
|
|
191
|
+
const delegated = /* @__PURE__ */ new Set();
|
|
192
|
+
const onElement = (element) => {
|
|
193
|
+
const value = element.getAttribute("b-on");
|
|
194
|
+
if (!delegated.has(value)) {
|
|
195
|
+
delegated.add(value);
|
|
196
|
+
for (const entry of entries(element)) delegate(entry.type, prevents(entry));
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const onListener = (template) => {
|
|
200
|
+
const target = template.getAttribute("b-listen") === "window" ? window : document;
|
|
201
|
+
for (const entry of entries(template)) listen(target, entry.type, (event) => {
|
|
202
|
+
if (template.isConnected) apply(event, template, entry);
|
|
203
|
+
}, {
|
|
204
|
+
capture: entry.modifiers.includes("capture"),
|
|
205
|
+
passive: !prevents(entry)
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
const onBlock = (root, template) => {
|
|
209
|
+
const client = template.getAttribute("b-client");
|
|
210
|
+
const [trigger, ref] = (client ?? template.getAttribute("b-defer")).split(client ? "=" : ":");
|
|
211
|
+
const go = () => {
|
|
212
|
+
if (client) {
|
|
213
|
+
run(template, ref);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const done = import("./defer-CKWZLv2K.js").then((module) => module.loadDeferred(template));
|
|
217
|
+
if (DEV) devtools()?.defer?.(template, done);
|
|
218
|
+
};
|
|
219
|
+
const near = template.getAttribute("b-near");
|
|
220
|
+
let after = template.nextElementSibling;
|
|
221
|
+
while (after?.tagName === "TEMPLATE") after = after.nextElementSibling;
|
|
222
|
+
const next = near && (root.querySelector(`[b-b="${near}"]`) ?? document.querySelector(`[b-b="${near}"]`)) || after;
|
|
223
|
+
if (trigger === "idle") idle(go);
|
|
224
|
+
else if (trigger === "visible" && next && typeof IntersectionObserver !== "undefined") {
|
|
225
|
+
const observer = new IntersectionObserver((records) => {
|
|
226
|
+
if (records.some((record) => record.isIntersecting)) {
|
|
227
|
+
observer.disconnect();
|
|
228
|
+
go();
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
observer.observe(next);
|
|
232
|
+
} else go();
|
|
233
|
+
};
|
|
234
|
+
const SCANNED = "[b-on],template[b-listen],template[b-client],template[b-defer]";
|
|
235
|
+
const scan = (root) => {
|
|
236
|
+
if (stopped) return;
|
|
237
|
+
const blocks = [];
|
|
238
|
+
for (const element of select(root, SCANNED)) {
|
|
239
|
+
if (element.tagName === "TEMPLATE") {
|
|
240
|
+
if (HAS_LISTENERS && element.hasAttribute("b-listen")) onListener(element);
|
|
241
|
+
else if (HAS_BLOCKS && (element.hasAttribute("b-client") || element.hasAttribute("b-defer") && !element.hasAttribute("b-hole"))) blocks.push(element);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (element.hasAttribute("b-on")) onElement(element);
|
|
245
|
+
}
|
|
246
|
+
for (const template of blocks) onBlock(root, template);
|
|
247
|
+
};
|
|
248
|
+
listen(document, "submit", (event) => {
|
|
249
|
+
const form = event.target;
|
|
250
|
+
if (!HAS_ACTIONS || event.defaultPrevented || !form.hasAttribute?.("b-result")) return;
|
|
251
|
+
event.preventDefault();
|
|
252
|
+
const submitter = event.submitter;
|
|
253
|
+
loadCore().then((client) => client.submitAction(form, submitter));
|
|
254
|
+
});
|
|
255
|
+
if (navigate) load = navigate({
|
|
256
|
+
options,
|
|
257
|
+
listen,
|
|
258
|
+
core: () => core,
|
|
259
|
+
start: loadCore,
|
|
260
|
+
scan
|
|
261
|
+
});
|
|
262
|
+
else listen(document, "brumate:reload", () => location.reload());
|
|
263
|
+
scan(document);
|
|
264
|
+
const scanAdded = (records) => {
|
|
265
|
+
for (const record of records) for (const node of record.addedNodes) if (node.nodeType === 1) scan(node);
|
|
266
|
+
};
|
|
267
|
+
const observer = HAS_LATE_MARKUP ? new MutationObserver(scanAdded) : void 0;
|
|
268
|
+
observer?.observe(document, {
|
|
269
|
+
childList: true,
|
|
270
|
+
subtree: true
|
|
271
|
+
});
|
|
272
|
+
if (!HAS_LATE_MARKUP && document.readyState === "loading") listen(document, "DOMContentLoaded", () => scan(document));
|
|
273
|
+
const scanInsert = (root) => {
|
|
274
|
+
if (observer) scanAdded(observer.takeRecords());
|
|
275
|
+
scan(root);
|
|
276
|
+
};
|
|
277
|
+
const inserted = () => {
|
|
278
|
+
observer?.takeRecords();
|
|
279
|
+
};
|
|
280
|
+
loadCore().catch(() => {});
|
|
281
|
+
const bundled = /* @__PURE__ */ new Set();
|
|
282
|
+
const loadBundles = () => {
|
|
283
|
+
for (const script of document.querySelectorAll("script[b-state]")) for (const [, id] of script.textContent?.matchAll(/\bm:"([^"]+)"/g) ?? []) if (!bundled.has(id)) {
|
|
284
|
+
bundled.add(id);
|
|
285
|
+
options.loadBundle?.(id)?.catch(() => {});
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
if (options.loadBundle) {
|
|
289
|
+
loadBundles();
|
|
290
|
+
if (document.readyState === "loading") listen(document, "DOMContentLoaded", loadBundles);
|
|
291
|
+
}
|
|
292
|
+
return () => {
|
|
293
|
+
stopped = true;
|
|
294
|
+
observer?.disconnect();
|
|
295
|
+
for (const remove of removers.splice(0)) remove();
|
|
296
|
+
core?.then((client) => client.dispose());
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/runtime/static-loader.ts
|
|
301
|
+
/**
|
|
302
|
+
* `start` for a site that loads every page with a full page load, as with
|
|
303
|
+
* `navigate: false`. A bundle that only calls it leaves out the code of
|
|
304
|
+
* client navigation.
|
|
305
|
+
*/
|
|
306
|
+
function startWithoutNavigation(options) {
|
|
307
|
+
return boot(options);
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
export { boot as n, importCore as r, startWithoutNavigation as t };
|
|
311
|
+
|
|
312
|
+
//# sourceMappingURL=static-loader-BZR17hSw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-loader-BZR17hSw.js","names":[],"sources":["../src/runtime/boot.ts","../src/runtime/static-loader.ts"],"sourcesContent":["// The loader's code that every page runs. `loader.ts` adds client navigation,\n// and `static-loader.ts` starts it without, so a site that turns navigation\n// off does not have its code, or the parts of the core that only it uses, in\n// its bundle.\n//\n// This file keeps its arrow functions and its Array methods, for size: the loader ships to every\n// page, and the function declarations and loops measured 20 to 50 bytes of gzip larger.\n\nimport { HAS_ACTIONS, HAS_BLOCKS, HAS_LATE_MARKUP, HAS_LISTENERS } from './features.ts';\nimport type * as Client from './client.ts';\nimport type { ClientModule, DevtoolsHooks, Part } from './client.ts';\nimport type { SerialEntry } from './values.ts';\n\n/** True on the dev server. A Vite build replaces it with `false`, so the devtools calls go. */\nconst DEV = (import.meta as { env?: { DEV?: boolean } }).env?.DEV;\n\n/** The hooks of the devtools overlay, under the same key as the core's. */\nfunction devtools(): DevtoolsHooks | undefined {\n return (globalThis as Record<symbol, DevtoolsHooks | undefined>)[Symbol.for('brumate.devtools')];\n}\n\nexport interface LoaderOptions {\n /**\n * Imports the client module of a component, by component ID. Undefined for\n * a component that has no client code.\n */\n load: (id: string) => Promise<ClientModule> | undefined;\n /**\n * Loads the bundle of a root component of the page, such as a route: the client modules of\n * the components that it can render, in one chunk. Undefined for a component that is not a\n * root.\n */\n loadBundle?: (id: string) => Promise<unknown> | undefined;\n /** The URL prefix of server function calls. */\n rpc?: string;\n /** Imports the serial entry, which the core takes before it reads the page state. */\n serial?: () => Promise<SerialEntry>;\n /**\n * Loads pages without a full page load: links to the same origin, the back\n * and forward buttons, forms that post to a server function, and redirects\n * from server functions to the same origin. Defaults to true.\n */\n navigate?: boolean | NavigateOptions;\n /**\n * The ID of the build of the page, for skew protection. The Vite plugin\n * sets it. Calls send it, and a page of another build, or a call that\n * answers 409 after a deploy, makes the next navigation a full page load.\n */\n build?: string;\n /**\n * Receives every error of client code first: of a handler, an effect, a\n * `$client` callback or a memo that loads, such as for a reporting\n * service. `scope` is the ID of the scope that the code belongs to. The\n * error then renders the `#catch` body of the nearest `#try`, or the page\n * gets a `brumate:error` event on `window` and the error is logged.\n */\n onError?: (error: unknown, info: { scope?: number | string }) => void;\n}\n\nexport interface NavigateOptions {\n /**\n * Swaps the page inside a view transition, where the browser has them.\n * CSS can tell links, the back and forward buttons and forms apart with\n * the types `push`, `traverse` and `form`. A redirect from a server\n * function has the type `form`.\n */\n transition?: boolean;\n /**\n * After a navigation, moves the focus to the first `<h1>` of the routes\n * that changed, or to `<main>`, as a full page load starts it at the top.\n * Defaults to true.\n */\n focus?: boolean;\n}\n\ninterface Entry {\n raw: string;\n type: string;\n modifiers: string[];\n ref: string;\n}\n\n// Parsed `b-on` values, so repeated events do not parse them again.\nconst parsed = new Map<string, Entry[]>();\n\nexport function entries(element: Element): Entry[] {\n const value = element.getAttribute('b-on') ?? '';\n return (parsed.get(value) ??\n parsed\n .set(\n value,\n value\n .split(' ')\n .filter(Boolean)\n .map((entry) => {\n const [name, ref] = entry.split('=') as [string, string];\n const [type, ...modifiers] = name.split(':') as [string, ...string[]];\n return { raw: entry, type, modifiers, ref };\n }),\n )\n .get(value))!;\n}\n\n/** The functions of the core that the loader calls. */\nexport type Core = (typeof Client)['loader'];\n\n/**\n * Imports the core. It reads one export by name, so a build keeps only it and\n * the helpers that compiled components call.\n */\nlet corePromise: Promise<Core> | undefined;\nexport const importCore = (): Promise<Core> =>\n (corePromise ??= import('./client.ts').then(\n (client) => client.loader,\n (error: unknown) => {\n // A load that fails can start again, such as after the network comes back.\n corePromise = undefined;\n throw error;\n },\n ));\n\n/** Runs a function when the browser is idle. */\nconst idle = (fn: () => void): unknown => (window.requestIdleCallback ?? setTimeout)(fn);\n\n/** What the loader gives the code that loads pages without a full page load. */\nexport interface Navigation {\n options: LoaderOptions;\n listen: (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ) => void;\n core: () => Promise<Core> | undefined;\n /** Starts the core, or returns the one that runs. */\n start: () => Promise<Core>;\n scan: (root: ParentNode) => void;\n}\n\n/**\n * Starts resuming the page. Listens to the events in `b-on` attributes\n * and loads `brumate/client` and the component's module on the first one.\n * `navigate` adds client navigation, and returns how to import the core.\n * Returns a function that removes the listeners and stops the core.\n */\nexport function boot(\n options: LoaderOptions,\n navigate?: (navigation: Navigation) => () => Promise<Core>,\n): () => void {\n let core: Promise<Core> | undefined;\n // Once stopped, the loader starts nothing, also from markup that the core inserts later with the\n // hooks that this loader gave it. A new loader can reuse the IDs of client scopes, so a stale\n // start would run in a scope of the new page.\n let stopped = false;\n /** The event types that the document listens to, and whether each listener is passive. */\n const types = new Map<string, boolean>();\n const removers: (() => void)[] = [];\n const listen = (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ): void => {\n target.addEventListener(type, listener, flags);\n removers.push(() => target.removeEventListener(type, listener, flags));\n };\n\n // Client navigation imports the core with the code that reads the pages it adds.\n let load = importCore;\n // The modules and parts that the loader asked for, which the core takes, so a handler whose\n // code loaded runs without another `import()`. In Chrome, an `import()` of a module that is\n // loaded already still resolves in a task of its own, which can wait for the next frame.\n const modules = new Map<string, Promise<ClientModule> | undefined>();\n const loadModule = (id: string): Promise<ClientModule> | undefined => {\n if (modules.has(id)) {\n return modules.get(id);\n }\n const promise = options.load(id);\n modules.set(id, promise);\n // A load that fails can start again, such as after the network comes back.\n promise?.catch(() => modules.delete(id));\n return promise;\n };\n const partLoads = new Map<string, Promise<Part>>();\n const loadPart = (module: ClientModule, part: string): Promise<Part> => {\n const key = `${module.id}#${part}`;\n let promise = partLoads.get(key);\n if (!promise) {\n promise = module.load!(part);\n partLoads.set(key, promise);\n promise.catch(() => partLoads.delete(key));\n }\n return promise;\n };\n // The serial entry loads with the core, so the core can make the values of the app.\n let serialLoad: Promise<SerialEntry> | undefined;\n const loadSerial = (): Promise<SerialEntry> | undefined => {\n serialLoad ??= options.serial?.();\n serialLoad?.catch(() => (serialLoad = undefined));\n return serialLoad;\n };\n const loadCore = (): Promise<Core> =>\n (core ??= Promise.all([load(), loadSerial()]).then(([client, serial]) => {\n client.init({ ...options, load: loadModule, loadPart, listen: scanInsert, inserted, serial });\n return client;\n }));\n\n // The devtools panel asks for the core when it opens, so it can show the page before any event.\n listen(document, 'brumate:core', () => void loadCore());\n\n const run = (element: Element, ref: string, event?: Event): void => {\n if (stopped) {\n return;\n }\n void loadCore().then((client) => client.handle(element, ref, event));\n };\n\n /**\n * A key of `prevent` matches its `event.key` while only the modifier that it names is held. A\n * key alone matches while Ctrl, Meta and Alt are up, so the shortcuts of the browser, such as\n * Cmd+Left or Alt+Left, keep their default. `Mod+` is Ctrl or Meta. Shift does not count.\n */\n const keyMatches = (key: string, event: KeyboardEvent): boolean => {\n const plus = key.indexOf('+', 1);\n const modifier = plus > 0 ? key.slice(0, plus) : '';\n if ((event.key === ' ' ? 'Space' : event.key) !== (plus > 0 ? key.slice(plus + 1) : key)) {\n return false;\n }\n switch (modifier) {\n case 'Mod':\n return (event.ctrlKey || event.metaKey) && !event.altKey;\n case 'Ctrl':\n return event.ctrlKey && !event.metaKey && !event.altKey;\n case 'Meta':\n return event.metaKey && !event.ctrlKey && !event.altKey;\n case 'Alt':\n return event.altKey && !event.ctrlKey && !event.metaKey;\n default:\n return !event.ctrlKey && !event.metaKey && !event.altKey;\n }\n };\n\n const apply = (event: Event, element: Element, entry: Entry): boolean => {\n for (const modifier of entry.modifiers) {\n // `prevent(ArrowDown,Enter)` prevents only these keys, by `event.key`. A key that commits\n // or moves within the text of an input method, such as Enter while it composes, is the\n // input method's, so it keeps its default.\n if (\n modifier === 'prevent' ||\n (modifier.startsWith('prevent(') &&\n !(event as KeyboardEvent).isComposing &&\n modifier\n .slice(8, -1)\n .split(',')\n .some((key) => keyMatches(key, event as KeyboardEvent)))\n ) {\n event.preventDefault();\n }\n }\n if (entry.modifiers.includes('once')) {\n element.setAttribute(\n 'b-on',\n entries(element)\n .map((item) => item.raw)\n .filter((raw) => raw !== entry.raw)\n .join(' '),\n );\n }\n run(element, entry.ref, event);\n return entry.modifiers.includes('stop');\n };\n\n /**\n * Handlers run as if each element had its own listener: those with\n * `capture` from the outside in, then the others from the target outwards.\n * An event that does not bubble, such as `focus`, reaches only the others\n * of its target. `stop` ends the event where it is.\n */\n const onEvent = (event: Event): void => {\n // The checks of `cancelWhen`, from the target up, run before any handler.\n for (let node = event.target as Node | null; node; node = node.parentNode) {\n for (const [type, check] of cancels.get(node as Element) ?? []) {\n if (type !== event.type) {\n continue;\n }\n let cancel = false;\n try {\n cancel = check(event);\n } catch (error) {\n // A check that throws cancels nothing, and the other checks and the handlers still run.\n console.error(error);\n }\n if (cancel) {\n event.preventDefault();\n return;\n }\n }\n }\n const path: Element[] = [];\n for (\n let node = event.target as Node | null;\n node && node !== document;\n node = node.parentNode\n ) {\n if (node.nodeType === 1 && (node as Element).hasAttribute('b-on')) {\n path.push(node as Element);\n }\n }\n const phase = (elements: Element[], capture: boolean): boolean => {\n for (const element of elements) {\n let stop = false;\n for (const entry of entries(element)) {\n if (\n entry.type === event.type &&\n entry.modifiers.includes('capture') === capture &&\n apply(event, element, entry)\n ) {\n stop = true;\n }\n }\n if (stop) {\n event.stopPropagation();\n return true;\n }\n }\n return false;\n };\n if (!phase([...path].reverse(), true)) {\n phase(event.bubbles ? path : path.filter((element) => element === event.target), false);\n }\n };\n\n // The checks of `cancelWhen`, by element. `events.ts` reaches them through a symbol of the registry.\n const cancels = new WeakMap<Node, Set<[string, (event: Event) => boolean]>>();\n (globalThis as { [key: symbol]: unknown })[Symbol.for('brumate.cancel')] = (\n element: Element,\n type: string,\n check: (event: Event) => boolean,\n ): (() => void) => {\n const entry: [string, typeof check] = [type, check];\n let set = cancels.get(element);\n if (!set) {\n cancels.set(element, (set = new Set()));\n }\n set.add(entry);\n delegate(type, false);\n return () => void set.delete(entry);\n };\n\n /** True for an entry that prevents the default action, which a passive listener cannot do. */\n const prevents = (entry: Entry): boolean =>\n entry.modifiers.some((modifier) => modifier.startsWith('prevent'));\n\n /**\n * Listens to an event type on the document. The listener is passive, so\n * scrolling does not wait for it, until an entry of the type prevents. `click` and `submit` never\n * scroll, so they are never passive: a `prevent` that is written after load cancels them.\n */\n const delegate = (type: string, cancel: boolean): void => {\n const prevent = cancel || type === 'click' || type === 'submit';\n const passive = types.get(type);\n if (passive === false || (passive === true && !prevent)) {\n return;\n }\n if (passive) {\n document.removeEventListener(type, onEvent, true);\n }\n types.set(type, !prevent);\n listen(document, type, onEvent, { capture: true, passive: !prevent });\n };\n\n // Templates are started once, even when markup is scanned again.\n const started = new WeakSet<Element>();\n const select = (root: ParentNode, selector: string): Element[] => {\n const found: Element[] = [];\n const add = (element: Element): void => {\n if (element.tagName === 'TEMPLATE') {\n if (started.has(element)) {\n return;\n }\n started.add(element);\n }\n found.push(element);\n };\n if ((root as Element).matches?.(selector)) {\n add(root as Element);\n }\n for (const element of root.querySelectorAll(selector)) {\n add(element);\n }\n return found;\n };\n\n // The values of `b-on` whose event types the document listens to already. The rows of a\n // list repeat the same few values.\n const delegated = new Set<string>();\n const onElement = (element: Element): void => {\n const value = element.getAttribute('b-on')!;\n if (!delegated.has(value)) {\n delegated.add(value);\n for (const entry of entries(element)) {\n delegate(entry.type, prevents(entry));\n }\n }\n };\n const onListener = (template: Element): void => {\n const target = template.getAttribute('b-listen') === 'window' ? window : document;\n for (const entry of entries(template)) {\n // Markup that is gone, such as a page that navigation replaced, no longer listens.\n listen(\n target,\n entry.type,\n (event) => {\n if (template.isConnected) {\n apply(event, template, entry);\n }\n },\n { capture: entry.modifiers.includes('capture'), passive: !prevents(entry) },\n );\n }\n };\n // A `#defer` block whose body the server sends in the same response, with `b-hole`, waits for it.\n const onBlock = (root: ParentNode, template: Element): void => {\n const client = template.getAttribute('b-client');\n const [trigger, ref] = (client ?? template.getAttribute('b-defer')!).split(\n client ? '=' : ':',\n ) as [string, string];\n // A `#defer` block asks the server for its body, with a module that only it needs.\n const go = (): void => {\n if (client) {\n run(template, ref);\n return;\n }\n const done = import('./defer.ts').then((module) => module.loadDeferred(template));\n if (DEV) {\n devtools()?.defer?.(template, done);\n }\n };\n // The element that a `$client` callback reads through `ref`, or the one after the marker.\n // Other markers can follow it, and a template has no box, so it is never in view.\n const near = template.getAttribute('b-near');\n let after = template.nextElementSibling;\n while (after?.tagName === 'TEMPLATE') {\n after = after.nextElementSibling;\n }\n const next =\n (near &&\n (root.querySelector(`[b-b=\"${near}\"]`) ?? document.querySelector(`[b-b=\"${near}\"]`))) ||\n after;\n if (trigger === 'idle') {\n idle(go);\n } else if (trigger === 'visible' && next && typeof IntersectionObserver !== 'undefined') {\n const observer = new IntersectionObserver((records) => {\n if (records.some((record) => record.isIntersecting)) {\n observer.disconnect();\n go();\n }\n });\n observer.observe(next);\n } else {\n go();\n }\n };\n const SCANNED = '[b-on],template[b-listen],template[b-client],template[b-defer]';\n // One query of the markup for everything that the loader starts. The blocks start after the\n // rest, as they did when each kind had its own query.\n const scan = (root: ParentNode): void => {\n if (stopped) {\n return;\n }\n const blocks: Element[] = [];\n for (const element of select(root, SCANNED)) {\n if (element.tagName === 'TEMPLATE') {\n if (HAS_LISTENERS && element.hasAttribute('b-listen')) {\n onListener(element);\n } else if (\n HAS_BLOCKS &&\n (element.hasAttribute('b-client') ||\n (element.hasAttribute('b-defer') && !element.hasAttribute('b-hole')))\n ) {\n blocks.push(element);\n }\n continue;\n }\n if (element.hasAttribute('b-on')) {\n onElement(element);\n }\n }\n for (const template of blocks) {\n onBlock(root, template);\n }\n };\n\n // A form of an `$action` sends its data with `fetch`, and the core writes the result into the page.\n listen(document, 'submit', (event) => {\n const form = event.target as HTMLFormElement;\n if (!HAS_ACTIONS || event.defaultPrevented || !form.hasAttribute?.('b-result')) {\n return;\n }\n event.preventDefault();\n const submitter = (event as SubmitEvent).submitter;\n void loadCore().then((client) => client.submitAction(form, submitter));\n });\n\n if (navigate) {\n load = navigate({ options, listen, core: () => core, start: loadCore, scan });\n } else {\n // A hot update whose markup changed loads the page again.\n listen(document, 'brumate:reload', () => location.reload());\n }\n\n scan(document);\n // Markup that streams in later, such as a `#loading` body, has handlers too.\n const scanAdded = (records: MutationRecord[]): void => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeType === 1) {\n scan(node as Element);\n }\n }\n }\n };\n // Without markup that others insert, the core scans all that comes into the page. The rest of\n // the page that the browser reads after an `async` script starts is scanned when it ends.\n const observer = HAS_LATE_MARKUP ? new MutationObserver(scanAdded) : undefined;\n observer?.observe(document, { childList: true, subtree: true });\n if (!HAS_LATE_MARKUP && document.readyState === 'loading') {\n listen(document, 'DOMContentLoaded', () => scan(document));\n }\n // The core scans the markup that it inserts before the insert, so the records of the insert\n // are dropped instead of scanned again. The markup that others inserted first is scanned\n // first.\n const scanInsert = (root: ParentNode): void => {\n if (observer) {\n scanAdded(observer.takeRecords());\n }\n scan(root);\n };\n const inserted = (): void => {\n observer?.takeRecords();\n };\n\n // The core starts at once and loads the code of the components on the page, so a call of a\n // function of another component, such as a function prop, runs at once and in order.\n void loadCore().catch(() => {});\n // The bundles of the components in the state start with it, so the code of the page comes in\n // the same round trip as the core. The core asks for them again when it reads the state.\n const bundled = new Set<string>();\n const loadBundles = (): void => {\n for (const script of document.querySelectorAll('script[b-state]')) {\n for (const [, id] of script.textContent?.matchAll(/\\bm:\"([^\"]+)\"/g) ?? []) {\n if (!bundled.has(id!)) {\n bundled.add(id!);\n void options.loadBundle?.(id!)?.catch(() => {});\n }\n }\n }\n };\n if (options.loadBundle) {\n loadBundles();\n if (document.readyState === 'loading') {\n listen(document, 'DOMContentLoaded', loadBundles);\n }\n }\n return () => {\n stopped = true;\n observer?.disconnect();\n for (const remove of removers.splice(0)) {\n remove();\n }\n void core?.then((client) => client.dispose());\n };\n}\n","// The loader without client navigation, for `navigate: false`. It is a module\n// of its own, so a bundle that starts it has no import of the navigation code,\n// and keeps none of the core's exports that only navigation reads.\n\nimport { boot } from './boot.ts';\nimport type { LoaderOptions } from './boot.ts';\n\nexport type { LoaderOptions } from './boot.ts';\n\n/**\n * `start` for a site that loads every page with a full page load, as with\n * `navigate: false`. A bundle that only calls it leaves out the code of\n * client navigation.\n */\nexport function startWithoutNavigation(options: LoaderOptions): () => void {\n return boot(options);\n}\n"],"mappings":";;;AAcA,MAAM,MAAO,YAA4C,KAAK;;AAG9D,SAAS,WAAsC;CAC7C,OAAQ,WAAyD,OAAO,IAAI,kBAAkB;AAChG;AAgEA,MAAM,yBAAS,IAAI,IAAqB;AAExC,SAAgB,QAAQ,SAA2B;CACjD,MAAM,QAAQ,QAAQ,aAAa,MAAM,KAAK;CAC9C,OAAQ,OAAO,IAAI,KAAK,KACtB,OACG,IACC,OACA,MACG,MAAM,GAAG,CAAC,CACV,OAAO,OAAO,CAAC,CACf,KAAK,UAAU;EACd,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,GAAG;EACnC,MAAM,CAAC,MAAM,GAAG,aAAa,KAAK,MAAM,GAAG;EAC3C,OAAO;GAAE,KAAK;GAAO;GAAM;GAAW;EAAI;CAC5C,CAAC,CACL,CAAC,CACA,IAAI,KAAK;AAChB;;;;;AASA,I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AM,iBAAuB;EAC3B,UAAU,YAAY;CACxB;CAIA,SAAc,CAAC,CAAC,YAAY,CAAC,CAAC;CAG9B,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,oBAA0B;EAC9B,KAAK,MAAM,UAAU,SAAS,iBAAiB,iBAAiB,GAC9D,KAAK,MAAM,GAAG,OAAO,OAAO,aAAa,SAAS,gBAAgB,KAAK,CAAC,GACtE,IAAI,CAAC,QAAQ,IAAI,EAAG,GAAG;GACrB,QAAQ,IAAI,EAAG;GACf,QAAa,aAAa,EAAG,CAAC,EAAE,YAAY,CAAC,CAAC;EAChD;CAGN;CACA,IAAI,QAAQ,YAAY;EACtB,YAAY;EACZ,IAAI,SAAS,eAAe,WAC1B,OAAO,UAAU,oBAAoB,WAAW;CAEpD;CACA,aAAa;EACX,UAAU;EACV,UAAU,WAAW;EACrB,KAAK,MAAM,UAAU,SAAS,OAAO,CAAC,GACpC,OAAO;EAET,MAAW,MAAM,WAAW,OAAO,QAAQ,CAAC;CAC9C;AACF;;;;;;;;AC9iBA,SAAgB,uBAAuB,SAAoC;CACzE,OAAO,KAAK,OAAO;AACrB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as MODIFIERS } from "./events-LgLdp1R7.js";
|
|
2
|
+
import { h as isRaw, t as Internal, x as rawHTML } from "./html-BtKRyi7g.js";
|
|
3
|
+
import { a as ElementReference, c as PARTS, g as isSlotReference, h as isPropWrapper, m as isBinding, r as CHILDREN_REF, v as onSerialOptions, x as stateValues, y as onValuePlugin } from "./produce-B7X9ori9.js";
|
|
3
4
|
import { Feature, Stream, createPlugin, fromCrossJSON, toCrossJSONStream } from "seroval";
|
|
4
5
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ImageDataPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLPlugin, URLSearchParamsPlugin } from "seroval-plugins/web";
|
|
5
6
|
//#region src/runtime/calls.ts
|
|
@@ -20,16 +21,22 @@ function isBlob(value) {
|
|
|
20
21
|
}
|
|
21
22
|
//#endregion
|
|
22
23
|
//#region src/runtime/serial.ts
|
|
24
|
+
/** Serializes the parts of a node that are set, joined as call arguments. */
|
|
25
|
+
function serializeParts(parts, ctx) {
|
|
26
|
+
const written = [];
|
|
27
|
+
for (const part of parts) if (part !== void 0) written.push(ctx.serialize(part));
|
|
28
|
+
return written.join(",");
|
|
29
|
+
}
|
|
23
30
|
/**
|
|
24
31
|
* Returns the parse functions of a plugin. `read` returns the values of the
|
|
25
32
|
* node by key, and each mode parses them in that order, so the nodes match.
|
|
26
33
|
*/
|
|
27
34
|
function parsers(read) {
|
|
28
|
-
|
|
35
|
+
function parse(value, ctx) {
|
|
29
36
|
const node = read(value);
|
|
30
37
|
for (const key in node) node[key] = ctx.parse(node[key]);
|
|
31
38
|
return node;
|
|
32
|
-
}
|
|
39
|
+
}
|
|
33
40
|
return {
|
|
34
41
|
sync: parse,
|
|
35
42
|
stream: parse,
|
|
@@ -51,19 +58,134 @@ const ElementPlugin = createPlugin({
|
|
|
51
58
|
serialize: (node, ctx) => `$b.e(${ctx.serialize(node.a)},${ctx.serialize(node.b)})`,
|
|
52
59
|
deserialize: (node, ctx) => stateValues.e(ctx.deserialize(node.a), ctx.deserialize(node.b))
|
|
53
60
|
});
|
|
61
|
+
const SlotPlugin = createPlugin({
|
|
62
|
+
tag: "brumate/slot",
|
|
63
|
+
skipPlainObjects: true,
|
|
64
|
+
test: (value) => isSlotReference(value),
|
|
65
|
+
parse: parsers((value) => ({
|
|
66
|
+
a: value.scope,
|
|
67
|
+
b: value.slot
|
|
68
|
+
})),
|
|
69
|
+
serialize: (node, ctx) => `$b.l(${ctx.serialize(node.a)},${ctx.serialize(node.b)})`,
|
|
70
|
+
deserialize: (node, ctx) => stateValues.l(ctx.deserialize(node.a), ctx.deserialize(node.b))
|
|
71
|
+
});
|
|
72
|
+
/** A binding that a rest prop holds: its value, and the scope and the slot it writes. */
|
|
73
|
+
const BindingPlugin = createPlugin({
|
|
74
|
+
tag: "brumate/binding",
|
|
75
|
+
skipPlainObjects: true,
|
|
76
|
+
test: (value) => isBinding(value),
|
|
77
|
+
parse: parsers((value) => {
|
|
78
|
+
const node = {
|
|
79
|
+
a: value.value,
|
|
80
|
+
b: value.ref.scope,
|
|
81
|
+
c: value.ref.slot
|
|
82
|
+
};
|
|
83
|
+
if (value.set !== void 0) node.d = value.set;
|
|
84
|
+
return node;
|
|
85
|
+
}),
|
|
86
|
+
serialize: (node, ctx) => `$b.b(${serializeParts([
|
|
87
|
+
node.a,
|
|
88
|
+
node.b,
|
|
89
|
+
node.c,
|
|
90
|
+
node.d
|
|
91
|
+
], ctx)})`,
|
|
92
|
+
deserialize: (node, ctx) => stateValues.b(ctx.deserialize(node.a), ctx.deserialize(node.b), ctx.deserialize(node.c), node.d === void 0 ? void 0 : ctx.deserialize(node.d))
|
|
93
|
+
});
|
|
54
94
|
const FunctionPlugin = createPlugin({
|
|
55
95
|
tag: "brumate/function",
|
|
56
96
|
skipPlainObjects: true,
|
|
57
97
|
test: (value) => typeof value === "function" && functionReferences.has(value),
|
|
58
98
|
parse: parsers((value) => {
|
|
59
99
|
const reference = functionReferences.get(value);
|
|
60
|
-
|
|
100
|
+
const node = {
|
|
61
101
|
a: reference.ref,
|
|
62
102
|
b: reference.scope
|
|
63
103
|
};
|
|
104
|
+
const modifiers = value[MODIFIERS];
|
|
105
|
+
if (reference.args !== void 0 || modifiers) node.c = reference.args ?? null;
|
|
106
|
+
if (modifiers) node.d = modifiers;
|
|
107
|
+
return node;
|
|
108
|
+
}),
|
|
109
|
+
serialize: (node, ctx) => `$b.f(${serializeParts([
|
|
110
|
+
node.a,
|
|
111
|
+
node.b,
|
|
112
|
+
node.c,
|
|
113
|
+
node.d
|
|
114
|
+
], ctx)})`,
|
|
115
|
+
deserialize: (node, ctx) => stateValues.f(ctx.deserialize(node.a), ctx.deserialize(node.b), node.c === void 0 ? void 0 : ctx.deserialize(node.c), node.d === void 0 ? void 0 : ctx.deserialize(node.d))
|
|
116
|
+
});
|
|
117
|
+
/** A handler that merges the handlers of one event, as the parts that refer to client functions. */
|
|
118
|
+
const MergedPlugin = createPlugin({
|
|
119
|
+
tag: "brumate/merged",
|
|
120
|
+
skipPlainObjects: true,
|
|
121
|
+
test: (value) => typeof value === "function" && PARTS in value,
|
|
122
|
+
parse: parsers((value) => {
|
|
123
|
+
const parts = [];
|
|
124
|
+
for (const part of value[PARTS]) if (functionReferences.has(part)) parts.push(part);
|
|
125
|
+
return { a: parts };
|
|
64
126
|
}),
|
|
65
|
-
serialize: (node, ctx) => `$b.
|
|
66
|
-
deserialize: (node, ctx) => stateValues.
|
|
127
|
+
serialize: (node, ctx) => `$b.m(${ctx.serialize(node.a)})`,
|
|
128
|
+
deserialize: (node, ctx) => stateValues.m(ctx.deserialize(node.a))
|
|
129
|
+
});
|
|
130
|
+
/**
|
|
131
|
+
* A value of an attribute that brumate writes, which a live rest prop can hold. The ones that
|
|
132
|
+
* reach the page state are the scoped style attribute and `b-v`. The error "holds a Internal"
|
|
133
|
+
* no longer catches any other, so a new one needs a check of its own.
|
|
134
|
+
*/
|
|
135
|
+
const InternalPlugin = createPlugin({
|
|
136
|
+
tag: "brumate/internal",
|
|
137
|
+
skipPlainObjects: true,
|
|
138
|
+
test: (value) => value instanceof Internal,
|
|
139
|
+
parse: parsers((value) => ({ a: value.value })),
|
|
140
|
+
serialize: (node, ctx) => `$b.i(${ctx.serialize(node.a)})`,
|
|
141
|
+
deserialize: (node, ctx) => stateValues.i(ctx.deserialize(node.a))
|
|
142
|
+
});
|
|
143
|
+
/** Children of a component, as the export that renders them in the browser. */
|
|
144
|
+
const ChildrenPlugin = createPlugin({
|
|
145
|
+
tag: "brumate/children",
|
|
146
|
+
skipPlainObjects: true,
|
|
147
|
+
test: (value) => typeof value === "object" && value !== null && CHILDREN_REF in value,
|
|
148
|
+
parse: parsers((value) => {
|
|
149
|
+
const reference = value[CHILDREN_REF];
|
|
150
|
+
const node = {
|
|
151
|
+
a: reference.ref,
|
|
152
|
+
b: reference.scope
|
|
153
|
+
};
|
|
154
|
+
if (reference.at !== void 0) {
|
|
155
|
+
node.c = reference.at;
|
|
156
|
+
node.d = reference.anchor;
|
|
157
|
+
}
|
|
158
|
+
return node;
|
|
159
|
+
}),
|
|
160
|
+
serialize: (node, ctx) => `$b.n(${serializeParts([
|
|
161
|
+
node.a,
|
|
162
|
+
node.b,
|
|
163
|
+
node.c,
|
|
164
|
+
node.d
|
|
165
|
+
], ctx)})`,
|
|
166
|
+
deserialize: (node, ctx) => stateValues.n(ctx.deserialize(node.a), ctx.deserialize(node.b), node.c === void 0 ? void 0 : ctx.deserialize(node.c), node.d === void 0 ? void 0 : ctx.deserialize(node.d))
|
|
167
|
+
});
|
|
168
|
+
/**
|
|
169
|
+
* A memo that failed on the server. The page state holds its error, so a read in the browser
|
|
170
|
+
* throws it, as a memo that failed there. The server writes the error that is safe to send. See
|
|
171
|
+
* `stateValue`.
|
|
172
|
+
*/
|
|
173
|
+
const MemoErrorPlugin = createPlugin({
|
|
174
|
+
tag: "brumate/memo-error",
|
|
175
|
+
skipPlainObjects: true,
|
|
176
|
+
test: (value) => typeof value === "object" && value !== null && Symbol.for("brumate.held") in value,
|
|
177
|
+
parse: parsers((value) => ({ e: value.error })),
|
|
178
|
+
serialize: (node, ctx) => `$b.x(${ctx.serialize(node.e)})`,
|
|
179
|
+
deserialize: (node, ctx) => stateValues.x(ctx.deserialize(node.e))
|
|
180
|
+
});
|
|
181
|
+
/** A promise prop in the page state. See `PropPromise`. */
|
|
182
|
+
const PropPromisePlugin = createPlugin({
|
|
183
|
+
tag: "brumate/prop-promise",
|
|
184
|
+
skipPlainObjects: true,
|
|
185
|
+
test: isPropWrapper,
|
|
186
|
+
parse: parsers((value) => ({ p: value.promise })),
|
|
187
|
+
serialize: (node, ctx) => `$b.q(${ctx.serialize(node.p)})`,
|
|
188
|
+
deserialize: (node, ctx) => stateValues.q(ctx.deserialize(node.p))
|
|
67
189
|
});
|
|
68
190
|
/** HTML, such as the `children` of a component, so the client can insert it again. */
|
|
69
191
|
const RawPlugin = createPlugin({
|
|
@@ -139,7 +261,14 @@ const BodyRequestPlugin = {
|
|
|
139
261
|
/** The plugins after the plugin of uploads, which a call makes for its files. */
|
|
140
262
|
const valuePlugins = [
|
|
141
263
|
ElementPlugin,
|
|
264
|
+
SlotPlugin,
|
|
265
|
+
BindingPlugin,
|
|
142
266
|
FunctionPlugin,
|
|
267
|
+
MergedPlugin,
|
|
268
|
+
InternalPlugin,
|
|
269
|
+
MemoErrorPlugin,
|
|
270
|
+
PropPromisePlugin,
|
|
271
|
+
ChildrenPlugin,
|
|
143
272
|
RawPlugin,
|
|
144
273
|
ComponentPlugin,
|
|
145
274
|
SignalPlugin,
|
|
@@ -181,6 +310,25 @@ const syncPlugins = [createPlugin({
|
|
|
181
310
|
deserialize: () => ({})
|
|
182
311
|
}), ...plugins];
|
|
183
312
|
/**
|
|
313
|
+
* The seroval plugin of a plugin of the app. The page state writes its value
|
|
314
|
+
* as `$b.u(tag, data)`, so the record does not need the class in scope.
|
|
315
|
+
*/
|
|
316
|
+
function appPlugin(plugin) {
|
|
317
|
+
return createPlugin({
|
|
318
|
+
tag: `app:${plugin.tag}`,
|
|
319
|
+
test: plugin.test,
|
|
320
|
+
parse: parsers((value) => ({ d: plugin.toData(value) })),
|
|
321
|
+
serialize: (node, ctx) => `$b.u(${JSON.stringify(plugin.tag)},${ctx.serialize(node.d)})`,
|
|
322
|
+
deserialize: (node, ctx) => plugin.fromData(ctx.deserialize(node.d))
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
onValuePlugin((plugin) => {
|
|
326
|
+
const added = appPlugin(plugin);
|
|
327
|
+
valuePlugins.unshift(added);
|
|
328
|
+
plugins.splice(1, 0, added);
|
|
329
|
+
syncPlugins.splice(2, 0, added);
|
|
330
|
+
});
|
|
331
|
+
/**
|
|
184
332
|
* Features that are off in both directions:
|
|
185
333
|
*
|
|
186
334
|
* - Errors keep their name and message only. A stack trace would show the
|
|
@@ -188,7 +336,22 @@ const syncPlugins = [createPlugin({
|
|
|
188
336
|
* - Regular expressions are not sent. A pattern from a client could take
|
|
189
337
|
* the server a long time to match, and reading one is refused as well.
|
|
190
338
|
*/
|
|
191
|
-
const
|
|
339
|
+
const BRUMATE_DISABLED = Feature.ErrorPrototypeStack | Feature.RegExp;
|
|
340
|
+
let disabledFeatures = BRUMATE_DISABLED;
|
|
341
|
+
let depthLimit;
|
|
342
|
+
/** The options of every call of seroval: the features that are off, and the depth limit of the entry. */
|
|
343
|
+
function serialOptions() {
|
|
344
|
+
return depthLimit === void 0 ? { disabledFeatures } : {
|
|
345
|
+
disabledFeatures,
|
|
346
|
+
depthLimit
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
onSerialOptions((options) => {
|
|
350
|
+
disabledFeatures = options.disabledFeatures ?? BRUMATE_DISABLED;
|
|
351
|
+
depthLimit = options.depthLimit;
|
|
352
|
+
const enabled = BRUMATE_DISABLED & ~disabledFeatures;
|
|
353
|
+
if (enabled !== 0) console.warn(`The serial entry turns on ${enabled & Feature.RegExp ? "RegExp" : "ErrorPrototypeStack"}, which brumate turns off: ${enabled & Feature.RegExp ? "a pattern from a client can take the server a long time to match" : "a stack shows the files and code of the server to the browser"}.`);
|
|
354
|
+
});
|
|
192
355
|
//#endregion
|
|
193
356
|
//#region src/runtime/stream.ts
|
|
194
357
|
const HEADER_SIZE = 12;
|
|
@@ -212,7 +375,7 @@ function toChunkStream(value, onCancel) {
|
|
|
212
375
|
toCrossJSONStream(value, {
|
|
213
376
|
refs: /* @__PURE__ */ new Map(),
|
|
214
377
|
plugins,
|
|
215
|
-
|
|
378
|
+
...serialOptions(),
|
|
216
379
|
onParse(node) {
|
|
217
380
|
if (!cancelled) controller.enqueue(chunk(JSON.stringify(node)));
|
|
218
381
|
},
|
|
@@ -280,7 +443,7 @@ var ChunkReader = class {
|
|
|
280
443
|
this.reader.cancel(reason).catch(() => {});
|
|
281
444
|
}
|
|
282
445
|
};
|
|
283
|
-
|
|
446
|
+
function ignore() {}
|
|
284
447
|
/**
|
|
285
448
|
* The refs of a stream. A promise in the answer can fail with nothing that
|
|
286
449
|
* reads it, such as a field the caller ignores, so its failure is claimed
|
|
@@ -316,11 +479,13 @@ function failPending(refs, error) {
|
|
|
316
479
|
async function fromChunkStream(stream) {
|
|
317
480
|
const reader = new ChunkReader(stream);
|
|
318
481
|
const refs = new Refs();
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
482
|
+
function read(data) {
|
|
483
|
+
return fromCrossJSON(JSON.parse(data), {
|
|
484
|
+
refs,
|
|
485
|
+
plugins,
|
|
486
|
+
...serialOptions()
|
|
487
|
+
});
|
|
488
|
+
}
|
|
324
489
|
const first = await reader.next();
|
|
325
490
|
if (first === void 0) throw new Error("The answer of a server function is empty");
|
|
326
491
|
const value = read(first);
|
|
@@ -340,6 +505,6 @@ async function fromChunkStream(stream) {
|
|
|
340
505
|
return value;
|
|
341
506
|
}
|
|
342
507
|
//#endregion
|
|
343
|
-
export {
|
|
508
|
+
export { plugins as a, functionReferences as c, callPlugins as i, fromChunkStream as n, serialOptions as o, toChunkStream as r, syncPlugins as s, STREAM_TYPE as t };
|
|
344
509
|
|
|
345
|
-
//# sourceMappingURL=stream-
|
|
510
|
+
//# sourceMappingURL=stream-BP5AVmg5.js.map
|