brumate 0.1.1 → 0.2.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/dist/{boot-DN1ZU8Hg.d.ts → boot-D-IdPy7B.d.ts} +24 -2
- package/dist/cli.js +2 -2
- package/dist/client-C0UCNL3J.js +1643 -0
- package/dist/client-C0UCNL3J.js.map +1 -0
- package/dist/{client-DwJInP_a.d.ts → client-MD0ZmcFR.d.ts} +101 -26
- package/dist/{client-routes-DakuM32C.js → client-routes-JTbGtukf.js} +28 -15
- package/dist/client-routes-JTbGtukf.js.map +1 -0
- package/dist/context-CTiSzQRc.js +27 -0
- package/dist/context-CTiSzQRc.js.map +1 -0
- package/dist/context-btHuB01Z.d.ts +42 -0
- package/dist/defer-D0bo1Gqx.js +52 -0
- package/dist/defer-D0bo1Gqx.js.map +1 -0
- package/dist/{devtools-BKjnHrnv.js → devtools-C50VH8gZ.js} +2 -2
- package/dist/devtools-C50VH8gZ.js.map +1 -0
- package/dist/{devtools-panel-AWOn0VK2.js → devtools-panel-AYjfwPhj.js} +4 -3
- package/dist/devtools-panel-AYjfwPhj.js.map +1 -0
- package/dist/events-BKWRqtMg.js +52 -0
- package/dist/events-BKWRqtMg.js.map +1 -0
- package/dist/{files-DdT84mPy.js → files-Bnn1JqHx.js} +18 -3
- package/dist/files-Bnn1JqHx.js.map +1 -0
- package/dist/{html-DEeoepg3.js → html-bHZbkK-h.js} +26 -8
- package/dist/html-bHZbkK-h.js.map +1 -0
- package/dist/{html-Du8jY2Cc.d.ts → html-y1q7-t7D.d.ts} +12 -5
- package/dist/index.d.ts +77 -29
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BPchdWbU.js → inspect-BJtACnQp.js} +784 -82
- package/dist/inspect-BJtACnQp.js.map +1 -0
- package/dist/{loader-Dc9OwY5I.js → loader-B18i3_-T.js} +46 -11
- package/dist/loader-B18i3_-T.js.map +1 -0
- package/dist/{navigate-CzLjnoPH.js → navigate-BwuZveDF.js} +71 -12
- package/dist/navigate-BwuZveDF.js.map +1 -0
- package/dist/{produce-BRGHP7e0.js → produce-CWfJ4byV.js} +43 -2
- package/dist/produce-CWfJ4byV.js.map +1 -0
- package/dist/{produce-CtZ32UGG.d.ts → produce-D4K7qpaL.d.ts} +23 -11
- package/dist/routes-BZNt7DSZ.d.ts +38 -0
- package/dist/{rpc-9fSqL_YK.js → rpc-B-Zkn6Ch.js} +24 -18
- package/dist/rpc-B-Zkn6Ch.js.map +1 -0
- package/dist/runtime/batch.d.ts +23 -0
- package/dist/runtime/batch.js +69 -0
- package/dist/runtime/batch.js.map +1 -0
- package/dist/runtime/client.d.ts +5 -5
- package/dist/runtime/client.js +5 -1345
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.js +1 -1
- package/dist/runtime/devtools.d.ts +5 -4
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/env.d.ts +44 -0
- package/dist/runtime/env.js +61 -0
- package/dist/runtime/env.js.map +1 -0
- package/dist/runtime/events.d.ts +27 -0
- package/dist/runtime/events.js +1 -0
- package/dist/runtime/hot.d.ts +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.d.ts +2 -21
- package/dist/runtime/routes.js +31 -1
- package/dist/runtime/routes.js.map +1 -1
- package/dist/runtime/server.d.ts +6 -5
- package/dist/runtime/server.js +5 -6
- package/dist/runtime/signals.d.ts +22 -1
- package/dist/runtime/signals.js +29 -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 +46 -5
- package/dist/runtime/testing.js +240 -33
- package/dist/runtime/testing.js.map +1 -1
- package/dist/secrets-BxagsJxJ.js +23 -0
- package/dist/secrets-BxagsJxJ.js.map +1 -0
- package/dist/{server-BxqjLUnV.d.ts → server-BA9SJ2Vm.d.ts} +544 -106
- package/dist/server-BqfM95r1.js +2762 -0
- package/dist/server-BqfM95r1.js.map +1 -0
- package/dist/skew-FRmAy9iy.js +49 -0
- package/dist/skew-FRmAy9iy.js.map +1 -0
- package/dist/standard-schema-BNY82yX3.d.ts +63 -0
- package/dist/{static-loader-BcFh4ebX.d.ts → static-loader-BzE9SRaj.d.ts} +2 -2
- package/dist/{static-loader-ClNkHZGn.js → static-loader-DOygOFj5.js} +52 -21
- package/dist/static-loader-DOygOFj5.js.map +1 -0
- package/dist/{stream-bgNCMcaA.js → stream-JaMHMdBD.js} +126 -61
- package/dist/stream-JaMHMdBD.js.map +1 -0
- package/dist/vite.d.ts +42 -1
- package/dist/vite.js +435 -55
- package/dist/vite.js.map +1 -1
- package/package.json +15 -2
- package/types.d.ts +9 -1
- package/dist/client-routes-DakuM32C.js.map +0 -1
- package/dist/context-BG8KCF3v.js +0 -15
- package/dist/context-BG8KCF3v.js.map +0 -1
- package/dist/context-aeo9esY9.d.ts +0 -16
- package/dist/devtools-BKjnHrnv.js.map +0 -1
- package/dist/devtools-panel-AWOn0VK2.js.map +0 -1
- package/dist/files-DdT84mPy.js.map +0 -1
- package/dist/html-DEeoepg3.js.map +0 -1
- package/dist/inspect-BPchdWbU.js.map +0 -1
- package/dist/loader-Dc9OwY5I.js.map +0 -1
- package/dist/navigate-CzLjnoPH.js.map +0 -1
- package/dist/produce-BRGHP7e0.js.map +0 -1
- package/dist/rpc-9fSqL_YK.js.map +0 -1
- package/dist/runtime/client.js.map +0 -1
- package/dist/server-DZsgnPKS.js +0 -1615
- package/dist/server-DZsgnPKS.js.map +0 -1
- package/dist/shared-CWYOd0H3.js +0 -40
- package/dist/shared-CWYOd0H3.js.map +0 -1
- package/dist/static-loader-ClNkHZGn.js.map +0 -1
- package/dist/stream-bgNCMcaA.js.map +0 -1
package/dist/runtime/client.js
CHANGED
|
@@ -1,1345 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
|
|
6
|
-
/** The part that holds an export: `h<n>` and `c<n>` have their own, the rest are in `update`. */
|
|
7
|
-
function partOf(name) {
|
|
8
|
-
return /^[hc]\d/.test(name) ? name : "update";
|
|
9
|
-
}
|
|
10
|
-
let options;
|
|
11
|
-
/** The URL prefix of server function calls, from the options. */
|
|
12
|
-
let rpcPrefix = "/_brumate";
|
|
13
|
-
/** The scopes of the page, by ID. */
|
|
14
|
-
const scopes = /* @__PURE__ */ new Map();
|
|
15
|
-
/** What modules of optional features add to the core. See `client-routes.ts` and `hot`. */
|
|
16
|
-
const hooks = {};
|
|
17
|
-
/** The global key of the devtools hooks. */
|
|
18
|
-
const DEVTOOLS = Symbol.for("brumate.devtools");
|
|
19
|
-
/**
|
|
20
|
-
* True on the dev server, which has the devtools. A Vite build replaces it
|
|
21
|
-
* with `false`, so the calls of the devtools hooks are left out. Without
|
|
22
|
-
* Vite, `import.meta.env` is undefined, and the hooks are off.
|
|
23
|
-
*/
|
|
24
|
-
const DEV = import.meta.env?.DEV;
|
|
25
|
-
function devtools() {
|
|
26
|
-
return globalThis[DEVTOOLS];
|
|
27
|
-
}
|
|
28
|
-
const modules = /* @__PURE__ */ new Map();
|
|
29
|
-
const loading = /* @__PURE__ */ new Map();
|
|
30
|
-
const parts = /* @__PURE__ */ new Map();
|
|
31
|
-
const loadedParts = /* @__PURE__ */ new Map();
|
|
32
|
-
const comments = /* @__PURE__ */ new Map();
|
|
33
|
-
const elements = /* @__PURE__ */ new Map();
|
|
34
|
-
let nextId = -1;
|
|
35
|
-
const refs = /* @__PURE__ */ new Map();
|
|
36
|
-
/**
|
|
37
|
-
* The records that ran before the core started, or while it stopped. Each
|
|
38
|
-
* state script hands its record to `push`, which the core replaces while it
|
|
39
|
-
* runs, so it reads later records at once.
|
|
40
|
-
*/
|
|
41
|
-
function stateQueue() {
|
|
42
|
-
const global = globalThis;
|
|
43
|
-
return global.$brm ??= [];
|
|
44
|
-
}
|
|
45
|
-
/** Reads the records that later state scripts hand over. Set while the core runs. */
|
|
46
|
-
function pushRecords(...added) {
|
|
47
|
-
for (const record of added) readRecord(record);
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Reads a state record. The first record holds the page state, and later
|
|
52
|
-
* records settle the promises in it.
|
|
53
|
-
*/
|
|
54
|
-
function readRecord([script, code]) {
|
|
55
|
-
if (!script?.isConnected) return;
|
|
56
|
-
const root = script.getAttribute("b-root") ?? "0";
|
|
57
|
-
if (!refs.has(root)) refs.set(root, []);
|
|
58
|
-
const decoded = code(refs.get(root), stateValues);
|
|
59
|
-
if (script.hasAttribute("b-scopes")) {
|
|
60
|
-
const unpacked = unpackState(decoded);
|
|
61
|
-
const added = addScopes(hooks.record ? hooks.record(script, unpacked) : unpacked, root);
|
|
62
|
-
if (writes > 0) refresh(added);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Updates scopes that the server rendered before values changed on the
|
|
67
|
-
* client, such as the body of a `#loading` block that streams in after an
|
|
68
|
-
* event. Effects do not run: they run only when a value changes.
|
|
69
|
-
*/
|
|
70
|
-
function refresh(added) {
|
|
71
|
-
for (const scope of added) {
|
|
72
|
-
const id = rootOf(scope).m;
|
|
73
|
-
if (!id) continue;
|
|
74
|
-
loadModule(id).then(async (module) => {
|
|
75
|
-
const names = /* @__PURE__ */ new Set();
|
|
76
|
-
for (const slots of Object.values(module.g)) for (const entries of Object.values(slots)) for (const [kind, name] of entries) if (kind === scope.k && name[0] !== "e") names.add(name);
|
|
77
|
-
if (names.size === 0) return;
|
|
78
|
-
const updates = await loadPart(module, "update");
|
|
79
|
-
for (const name of [...names].toSorted((a, b) => Number(b[0] === "m") - Number(a[0] === "m"))) if (scopes.has(scope.id)) updates[name](scope);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/** Reads the groups of scope records back into one record per scope. See `PackedState`. */
|
|
84
|
-
function unpackState(state) {
|
|
85
|
-
const taken = [];
|
|
86
|
-
for (const group of state.g ?? []) {
|
|
87
|
-
const [k, base, flags] = group;
|
|
88
|
-
const count = group[3];
|
|
89
|
-
let at = 4;
|
|
90
|
-
const m = flags & 16 ? group[at++] : void 0;
|
|
91
|
-
const source = flags & 32 ? [] : void 0;
|
|
92
|
-
if (source) taken.push([
|
|
93
|
-
source,
|
|
94
|
-
group[at++],
|
|
95
|
-
group[at++],
|
|
96
|
-
flags & 1
|
|
97
|
-
]);
|
|
98
|
-
const skip = source && flags & 1 ? 1 : 0;
|
|
99
|
-
let id = flags & 8 ? 0 : base;
|
|
100
|
-
while (at < group.length) {
|
|
101
|
-
id += group[at++];
|
|
102
|
-
const s = group.slice(at - skip, at += count - skip);
|
|
103
|
-
const record = flags & 8 ? {
|
|
104
|
-
k,
|
|
105
|
-
o: id - base
|
|
106
|
-
} : {
|
|
107
|
-
k,
|
|
108
|
-
p: base
|
|
109
|
-
};
|
|
110
|
-
record.s = s;
|
|
111
|
-
if (m !== void 0) record.m = m;
|
|
112
|
-
if (source) source.push(record);
|
|
113
|
-
else if (flags & 1) record.i = s[0];
|
|
114
|
-
else if (flags & 2) record.i = group[at++];
|
|
115
|
-
if (flags & 4) record.c = group[at++];
|
|
116
|
-
state[id] = record;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
delete state.g;
|
|
120
|
-
for (const [records, source, slot, first] of taken) {
|
|
121
|
-
const values = Array.from(state[source].s[slot]);
|
|
122
|
-
for (let n = 0; n < records.length; n++) {
|
|
123
|
-
const record = records[n];
|
|
124
|
-
record.i = values[n];
|
|
125
|
-
if (first) record.s[0] = values[n];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return state;
|
|
129
|
-
}
|
|
130
|
-
function addScopes(state, root) {
|
|
131
|
-
const added = [];
|
|
132
|
-
for (const [key, record] of Object.entries(state)) {
|
|
133
|
-
const id = Number(key);
|
|
134
|
-
const scope = {
|
|
135
|
-
id,
|
|
136
|
-
k: record.k ?? 0,
|
|
137
|
-
m: record.m,
|
|
138
|
-
s: record.s ?? [],
|
|
139
|
-
i: record.i,
|
|
140
|
-
c: record.c,
|
|
141
|
-
v: record.v,
|
|
142
|
-
x: record.x,
|
|
143
|
-
children: /* @__PURE__ */ new Set(),
|
|
144
|
-
r: root
|
|
145
|
-
};
|
|
146
|
-
scopes.set(id, scope);
|
|
147
|
-
added.push(scope);
|
|
148
|
-
}
|
|
149
|
-
for (const scope of added) {
|
|
150
|
-
const record = state[scope.id];
|
|
151
|
-
if (record.p !== void 0) {
|
|
152
|
-
scope.p = scopes.get(record.p);
|
|
153
|
-
scope.p?.children.add(scope);
|
|
154
|
-
treeChanges++;
|
|
155
|
-
}
|
|
156
|
-
if (record.o !== void 0) scope.o = scopes.get(record.o);
|
|
157
|
-
}
|
|
158
|
-
const seen = /* @__PURE__ */ new Set();
|
|
159
|
-
for (const scope of added) {
|
|
160
|
-
for (const key of Object.keys(scope.v ?? {})) scope.v[key] = callable(scope.v[key], seen);
|
|
161
|
-
for (let i = 0; i < scope.s.length; i++) {
|
|
162
|
-
const value = callable(scope.s[i], seen);
|
|
163
|
-
scope.s[i] = value;
|
|
164
|
-
if (value instanceof Promise) value.then((result) => {
|
|
165
|
-
settled.set(value, result);
|
|
166
|
-
if (scope.s[i] === value) set(scope, i, result);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
hooks.added?.(added);
|
|
171
|
-
return added;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Indexes the markers of markup that others insert, such as streamed
|
|
175
|
-
* `#loading` bodies and the pages that navigation adds, so `findComment` can
|
|
176
|
-
* take its records at once.
|
|
177
|
-
*/
|
|
178
|
-
let markerObserver;
|
|
179
|
-
/** Stops reading state records and markers that arrive later. Later records wait for `init`. */
|
|
180
|
-
function dispose() {
|
|
181
|
-
const queue = stateQueue();
|
|
182
|
-
if (queue.push === pushRecords) delete queue.push;
|
|
183
|
-
markerObserver?.disconnect();
|
|
184
|
-
markerObserver = void 0;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Stops reading, before client navigation replaces only some routes. The
|
|
188
|
-
* server renders the new routes with its current values, so only the writes
|
|
189
|
-
* that come after count for the records that stream in later.
|
|
190
|
-
*/
|
|
191
|
-
function leaveRoutes() {
|
|
192
|
-
dispose();
|
|
193
|
-
writes = 0;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Removes the scopes of a render, by its `b-root`, with the scopes inside
|
|
197
|
-
* them. Their cleanups run, and their memos no longer load. Its markup
|
|
198
|
-
* stays. `brumate/testing` calls it when a mounted component unmounts.
|
|
199
|
-
*/
|
|
200
|
-
function removeRoot(root) {
|
|
201
|
-
const inside = (scope) => {
|
|
202
|
-
for (let current = scope; current; current = current.p ?? current.o) if (current.r === root) return true;
|
|
203
|
-
return false;
|
|
204
|
-
};
|
|
205
|
-
for (const scope of scopes.values()) if (inside(scope)) removeScope(scope);
|
|
206
|
-
refs.delete(root);
|
|
207
|
-
for (const cache of [comments, elements]) for (const [key, node] of cache) if (!node.isConnected) cache.delete(key);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Forgets the code of components that changed on the dev server, so the next
|
|
211
|
-
* event or update loads the new code. Their state stays. `brumate/hot` calls it.
|
|
212
|
-
*/
|
|
213
|
-
function forget(ids) {
|
|
214
|
-
for (const id of ids) {
|
|
215
|
-
modules.delete(id);
|
|
216
|
-
loading.delete(id);
|
|
217
|
-
for (const key of parts.keys()) if (key.startsWith(`${id}:`)) {
|
|
218
|
-
parts.delete(key);
|
|
219
|
-
loadedParts.delete(key);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
/** The values of the signals of components whose markup changed, for when the page renders again. */
|
|
224
|
-
const remounts = /* @__PURE__ */ new Map();
|
|
225
|
-
/**
|
|
226
|
-
* Keeps the values of the signals of each instance of a component, by
|
|
227
|
-
* name, before the page renders again with its new markup. `brumate/hot` calls it.
|
|
228
|
-
*/
|
|
229
|
-
function remount(detail) {
|
|
230
|
-
hooks.added = restoreRemounts;
|
|
231
|
-
for (const { id, before, after, signals } of detail) {
|
|
232
|
-
const names = new Set(signals);
|
|
233
|
-
const instances = [...scopes.values()].filter((scope) => scope.m === id);
|
|
234
|
-
remounts.set(id, {
|
|
235
|
-
after,
|
|
236
|
-
values: instances.map((root) => {
|
|
237
|
-
const values = {};
|
|
238
|
-
(before[root.k] ?? []).forEach((name, slot) => {
|
|
239
|
-
if (names.has(name)) values[name] = root.s[slot];
|
|
240
|
-
});
|
|
241
|
-
return values;
|
|
242
|
-
})
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
/** Writes back the values of signals that `onRemount` kept, into the instances of the new page. */
|
|
247
|
-
function restoreRemounts(added) {
|
|
248
|
-
for (const [id, { after, values }] of remounts) {
|
|
249
|
-
const instances = added.filter((scope) => scope.m === id);
|
|
250
|
-
if (instances.length === 0) continue;
|
|
251
|
-
remounts.delete(id);
|
|
252
|
-
instances.forEach((root, index) => {
|
|
253
|
-
const saved = values[index];
|
|
254
|
-
(after[root.k] ?? []).forEach((name, slot) => {
|
|
255
|
-
if (saved && name in saved) set(root, slot, saved[name]);
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Forgets the page, before another page replaces it. Cleanups run. Loaded
|
|
262
|
-
* modules and parts stay, so the next page does not load them again. Only
|
|
263
|
-
* client navigation calls it.
|
|
264
|
-
*/
|
|
265
|
-
function leavePage() {
|
|
266
|
-
dispose();
|
|
267
|
-
for (const scope of scopes.values()) for (const cleanup of scope.cleanups?.values() ?? []) cleanup();
|
|
268
|
-
scopes.clear();
|
|
269
|
-
comments.clear();
|
|
270
|
-
elements.clear();
|
|
271
|
-
pendingEffects.clear();
|
|
272
|
-
hiding = void 0;
|
|
273
|
-
loads.clear();
|
|
274
|
-
loadingSlots.clear();
|
|
275
|
-
for (const memoController of memoControllers.values()) memoController.abort();
|
|
276
|
-
memoControllers.clear();
|
|
277
|
-
guesses?.map.clear();
|
|
278
|
-
nextId = -1;
|
|
279
|
-
refs.clear();
|
|
280
|
-
writes = 0;
|
|
281
|
-
calling = 0;
|
|
282
|
-
callEpoch++;
|
|
283
|
-
lastHandler = Promise.resolve();
|
|
284
|
-
}
|
|
285
|
-
/** Reads the page state. The loader calls it once, before the first handler. */
|
|
286
|
-
function init(value) {
|
|
287
|
-
options = value;
|
|
288
|
-
rpcPrefix = value.rpc ?? "/_brumate";
|
|
289
|
-
const queue = stateQueue();
|
|
290
|
-
queue.push = pushRecords;
|
|
291
|
-
for (const record of queue.splice(0)) readRecord(record);
|
|
292
|
-
markerObserver = new MutationObserver(indexAdded);
|
|
293
|
-
markerObserver.observe(document, {
|
|
294
|
-
childList: true,
|
|
295
|
-
subtree: true
|
|
296
|
-
});
|
|
297
|
-
indexMarkers(document.documentElement);
|
|
298
|
-
if (DEV) devtools()?.attach?.({
|
|
299
|
-
scopes,
|
|
300
|
-
set
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
/** Replaces function references with functions that call them. */
|
|
304
|
-
function callable(value, seen) {
|
|
305
|
-
if (value instanceof FunctionReference) return (...args) => call(value.ref, scopes.get(value.scope), args);
|
|
306
|
-
if (typeof value === "object" && value !== null && !seen.has(value)) {
|
|
307
|
-
seen.add(value);
|
|
308
|
-
const prototype = Object.getPrototypeOf(value);
|
|
309
|
-
if (Array.isArray(value) || prototype === Object.prototype || prototype === null) {
|
|
310
|
-
const record = value;
|
|
311
|
-
for (const key of Object.keys(record)) record[key] = callable(record[key], seen);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return value;
|
|
315
|
-
}
|
|
316
|
-
function loadModule(id) {
|
|
317
|
-
let promise = loading.get(id);
|
|
318
|
-
if (!promise) {
|
|
319
|
-
promise = Promise.resolve(options.load(id)).then((loaded) => {
|
|
320
|
-
const module = loaded ?? {
|
|
321
|
-
id,
|
|
322
|
-
props: {},
|
|
323
|
-
g: {}
|
|
324
|
-
};
|
|
325
|
-
modules.set(id, module);
|
|
326
|
-
return module;
|
|
327
|
-
});
|
|
328
|
-
loading.set(id, promise);
|
|
329
|
-
}
|
|
330
|
-
return promise;
|
|
331
|
-
}
|
|
332
|
-
function loadPart(module, name) {
|
|
333
|
-
const key = `${module.id}:${name}`;
|
|
334
|
-
let promise = parts.get(key);
|
|
335
|
-
if (!promise) {
|
|
336
|
-
promise = (module.load ? module.load(name) : Promise.resolve(module)).then((part) => {
|
|
337
|
-
loadedParts.set(key, part);
|
|
338
|
-
if (DEV) devtools()?.part?.(module.id, name);
|
|
339
|
-
return part;
|
|
340
|
-
});
|
|
341
|
-
parts.set(key, promise);
|
|
342
|
-
}
|
|
343
|
-
return promise;
|
|
344
|
-
}
|
|
345
|
-
async function resolve(ref) {
|
|
346
|
-
const [id, name] = ref.split("#");
|
|
347
|
-
return (await loadPart(await loadModule(id), partOf(name)))[name];
|
|
348
|
-
}
|
|
349
|
-
async function call(ref, scope, args) {
|
|
350
|
-
return (await resolve(ref))(scope, ...args);
|
|
351
|
-
}
|
|
352
|
-
let lastHandler = Promise.resolve();
|
|
353
|
-
/**
|
|
354
|
-
* Keeps `currentTarget` on an event. The handler runs after the event has
|
|
355
|
-
* finished dispatching, when the browser has already cleared it.
|
|
356
|
-
*/
|
|
357
|
-
function withTarget(event, element) {
|
|
358
|
-
return new Proxy(event, { get(target, key) {
|
|
359
|
-
if (key === "currentTarget") return element;
|
|
360
|
-
const value = Reflect.get(target, key);
|
|
361
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
362
|
-
} });
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Runs the handler `ref` for an element. The scope comes from the element's
|
|
366
|
-
* `b-b` anchor, or from the nearest element around it that has one, which
|
|
367
|
-
* the compiler checks is in the same scope.
|
|
368
|
-
*/
|
|
369
|
-
function handle(element, ref, event) {
|
|
370
|
-
const anchor = element.closest("[b-b]")?.getAttribute("b-b");
|
|
371
|
-
const scope = anchor ? scopes.get(Number(anchor.split(":")[0])) : void 0;
|
|
372
|
-
if (scope && hiding?.hidden(scope) && element.hasAttribute("b-listen")) return Promise.resolve();
|
|
373
|
-
const args = event ? [withTarget(event, element)] : [];
|
|
374
|
-
if (DEV) devtools()?.handler?.(ref, element, event);
|
|
375
|
-
const loaded = resolve(ref);
|
|
376
|
-
const started = lastHandler.then(() => loaded).then((handler) => ({ value: handler(scope, ...args) }));
|
|
377
|
-
lastHandler = started.catch(() => {});
|
|
378
|
-
return started.then((result) => result.value);
|
|
379
|
-
}
|
|
380
|
-
/** Returns the instance of a scope by its ID. */
|
|
381
|
-
function scopeOf(id) {
|
|
382
|
-
return scopes.get(id);
|
|
383
|
-
}
|
|
384
|
-
function get(scope, slot) {
|
|
385
|
-
const value = scope.s[slot];
|
|
386
|
-
if (computing > 0 && value instanceof Promise) throw new NotReady(value);
|
|
387
|
-
if (value instanceof ElementReference) {
|
|
388
|
-
const element = findElement(value.scope, value.anchor);
|
|
389
|
-
if (element) scope.s[slot] = element;
|
|
390
|
-
return element ?? void 0;
|
|
391
|
-
}
|
|
392
|
-
return value;
|
|
393
|
-
}
|
|
394
|
-
let writes = 0;
|
|
395
|
-
function set(scope, slot, value) {
|
|
396
|
-
if (!Object.is(scope.s[slot], value)) {
|
|
397
|
-
writes++;
|
|
398
|
-
scope.s[slot] = value;
|
|
399
|
-
if (DEV) devtools()?.write?.(scope, slot, value);
|
|
400
|
-
trigger(scope, slot);
|
|
401
|
-
}
|
|
402
|
-
return value;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* The names of a call of a module function, for its shared code. Each ref
|
|
406
|
-
* is a slot of `scope`, `[scope, slot]` for a slot of another scope, or
|
|
407
|
-
* `[value]` for a value that does not change, such as a literal argument.
|
|
408
|
-
*/
|
|
409
|
-
function cells(scope, links, names) {
|
|
410
|
-
const result = {};
|
|
411
|
-
names.forEach((name, index) => {
|
|
412
|
-
const ref = links[index];
|
|
413
|
-
let owner = scope;
|
|
414
|
-
let slot;
|
|
415
|
-
if (typeof ref === "number") slot = ref;
|
|
416
|
-
else if (ref.length === 2) [owner, slot] = ref;
|
|
417
|
-
else {
|
|
418
|
-
Object.defineProperty(result, name, {
|
|
419
|
-
get: () => ref[0],
|
|
420
|
-
set: () => {}
|
|
421
|
-
});
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
Object.defineProperty(result, name, {
|
|
425
|
-
get: () => get(owner, slot),
|
|
426
|
-
set: (value) => set(owner, slot, value)
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
return result;
|
|
430
|
-
}
|
|
431
|
-
const loads = /* @__PURE__ */ new Map();
|
|
432
|
-
let loadCount = 0;
|
|
433
|
-
const loadingSlots = /* @__PURE__ */ new Set();
|
|
434
|
-
/** Marks a memo as loading. Its readers update the first time, so `$isPending` becomes true. */
|
|
435
|
-
function startLoading(scope, slot, key) {
|
|
436
|
-
if (!loadingSlots.has(key)) {
|
|
437
|
-
loadingSlots.add(key);
|
|
438
|
-
trigger(scope, slot);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
/** True for a promise, or any object with a `then` method. */
|
|
442
|
-
function isThenable(value) {
|
|
443
|
-
return value !== null && typeof value === "object" && typeof value.then === "function";
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Writes the result of an async memo when it arrives. Until then the slot
|
|
447
|
-
* keeps its value, and `pending` is true. Only the latest load is written.
|
|
448
|
-
*/
|
|
449
|
-
function asyncMemo(scope, slot, promise) {
|
|
450
|
-
const key = `${scope.id}:${slot}`;
|
|
451
|
-
const load = ++loadCount;
|
|
452
|
-
loads.set(key, load);
|
|
453
|
-
startLoading(scope, slot, key);
|
|
454
|
-
const settle = (value, failed = false) => {
|
|
455
|
-
if (loads.get(key) !== load) return;
|
|
456
|
-
loadingSlots.delete(key);
|
|
457
|
-
if (!failed && !Object.is(scope.s[slot], value)) set(scope, slot, value);
|
|
458
|
-
else trigger(scope, slot);
|
|
459
|
-
};
|
|
460
|
-
const fail = (error) => {
|
|
461
|
-
if (loads.get(key) === load) {
|
|
462
|
-
console.error(error);
|
|
463
|
-
settle(void 0, true);
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
promise.then((value) => {
|
|
467
|
-
if (!isAsyncIterable(value)) {
|
|
468
|
-
settle(value);
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
(async () => {
|
|
472
|
-
try {
|
|
473
|
-
for await (const item of value) {
|
|
474
|
-
if (loads.get(key) !== load) break;
|
|
475
|
-
if (loadingSlots.has(key)) settle(item);
|
|
476
|
-
else if (!Object.is(scope.s[slot], item)) set(scope, slot, item);
|
|
477
|
-
}
|
|
478
|
-
} catch (error) {
|
|
479
|
-
fail(error);
|
|
480
|
-
}
|
|
481
|
-
})();
|
|
482
|
-
}, fail);
|
|
483
|
-
}
|
|
484
|
-
/** Thrown when a memo reads a value that is still loading. */
|
|
485
|
-
var NotReady = class extends Error {
|
|
486
|
-
source;
|
|
487
|
-
constructor(source) {
|
|
488
|
-
super("The value is still loading");
|
|
489
|
-
this.source = source;
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
let computing = 0;
|
|
493
|
-
/** Aborts the server function calls of a memo's compute, by memo key. */
|
|
494
|
-
const memoControllers = /* @__PURE__ */ new Map();
|
|
495
|
-
/** The key of the memo that computes, if any. */
|
|
496
|
-
let memoKey;
|
|
497
|
-
/** The signal for server function calls while a memo computes. It is made on the first call. */
|
|
498
|
-
function memoSignal() {
|
|
499
|
-
if (memoKey === void 0) return;
|
|
500
|
-
let controller = memoControllers.get(memoKey);
|
|
501
|
-
if (!controller) {
|
|
502
|
-
controller = new AbortController();
|
|
503
|
-
memoControllers.set(memoKey, controller);
|
|
504
|
-
}
|
|
505
|
-
return controller.signal;
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Computes a memo. A promise loads, and the memo keeps its value until it
|
|
509
|
-
* settles. A memo that reads a value that is still loading keeps its value
|
|
510
|
-
* too, and is pending until that value arrives and the memo computes again.
|
|
511
|
-
*/
|
|
512
|
-
function memo(scope, slot, compute) {
|
|
513
|
-
const key = `${scope.id}:${slot}`;
|
|
514
|
-
if (guesses?.same(key)) return;
|
|
515
|
-
let value;
|
|
516
|
-
memoControllers.get(key)?.abort();
|
|
517
|
-
memoControllers.delete(key);
|
|
518
|
-
const outer = memoKey;
|
|
519
|
-
memoKey = key;
|
|
520
|
-
computing++;
|
|
521
|
-
try {
|
|
522
|
-
value = compute();
|
|
523
|
-
} catch (error) {
|
|
524
|
-
if (!(error instanceof NotReady)) throw error;
|
|
525
|
-
startLoading(scope, slot, key);
|
|
526
|
-
return;
|
|
527
|
-
} finally {
|
|
528
|
-
computing--;
|
|
529
|
-
memoKey = outer;
|
|
530
|
-
}
|
|
531
|
-
if (isThenable(value) || isAsyncIterable(value)) {
|
|
532
|
-
asyncMemo(scope, slot, Promise.resolve(value));
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
const waited = loadingSlots.delete(key);
|
|
536
|
-
loads.delete(key);
|
|
537
|
-
guesses?.map.delete(key);
|
|
538
|
-
if (!Object.is(scope.s[slot], value)) set(scope, slot, value);
|
|
539
|
-
else if (waited) trigger(scope, slot);
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* The guesses of `$optimistic` values. The first `guess` sets it, so the
|
|
543
|
-
* code that reads guesses is left out of a build that makes none.
|
|
544
|
-
*/
|
|
545
|
-
let guesses;
|
|
546
|
-
/** The values of promises that the server streamed, so a guess knows its source did not change. */
|
|
547
|
-
const settled = /* @__PURE__ */ new WeakMap();
|
|
548
|
-
/** True while the source of a guess holds the value it had when the guess was made. */
|
|
549
|
-
function sameSource(key) {
|
|
550
|
-
const entry = guesses.map.get(key);
|
|
551
|
-
if (!entry?.source) return false;
|
|
552
|
-
const current = entry.source[0].s[entry.source[1]];
|
|
553
|
-
return Object.is(current, entry.base) || entry.base instanceof Promise && settled.get(entry.base) === current;
|
|
554
|
-
}
|
|
555
|
-
/** Server calls that have not finished, from forms and from `rpc`. */
|
|
556
|
-
let calling = 0;
|
|
557
|
-
/** Counts the pages that client navigation left, so calls of an old page are not counted down. */
|
|
558
|
-
let callEpoch = 0;
|
|
559
|
-
/**
|
|
560
|
-
* Writes a guess into an optimistic value. It goes back to its source when
|
|
561
|
-
* the source changes, which computes it again, or when every server call of
|
|
562
|
-
* the page finishes, such as after a post failed.
|
|
563
|
-
*/
|
|
564
|
-
function guess(scope, slot, ...rest) {
|
|
565
|
-
const value = rest.at(-1);
|
|
566
|
-
const source = rest.length === 3 ? [rest[0], rest[1]] : void 0;
|
|
567
|
-
const base = source && source[0].s[source[1]];
|
|
568
|
-
guesses ??= {
|
|
569
|
-
map: /* @__PURE__ */ new Map(),
|
|
570
|
-
same: sameSource,
|
|
571
|
-
reset: resetGuesses
|
|
572
|
-
};
|
|
573
|
-
guesses.map.set(`${scope.id}:${slot}`, {
|
|
574
|
-
scope,
|
|
575
|
-
slot,
|
|
576
|
-
source,
|
|
577
|
-
base
|
|
578
|
-
});
|
|
579
|
-
return set(scope, slot, value);
|
|
580
|
-
}
|
|
581
|
-
/** Counts a server call, and puts guesses back when the last one finishes. */
|
|
582
|
-
function track(request) {
|
|
583
|
-
calling++;
|
|
584
|
-
const epoch = callEpoch;
|
|
585
|
-
const done = () => {
|
|
586
|
-
if (epoch !== callEpoch) return;
|
|
587
|
-
calling--;
|
|
588
|
-
setTimeout(() => calling || guesses?.reset(), 0);
|
|
589
|
-
};
|
|
590
|
-
request.then(done, done);
|
|
591
|
-
return request;
|
|
592
|
-
}
|
|
593
|
-
function resetGuesses() {
|
|
594
|
-
for (const [key, { scope, slot, source }] of guesses.map) {
|
|
595
|
-
if (source && pending(source[0], source[1])) continue;
|
|
596
|
-
guesses.map.delete(key);
|
|
597
|
-
if (source && scopes.has(scope.id) && !Object.is(scope.s[slot], source[0].s[source[1]])) set(scope, slot, source[0].s[source[1]]);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
/** True while a new value of a memo loads, or while the server still streams its value. */
|
|
601
|
-
function pending(scope, slot) {
|
|
602
|
-
return loadingSlots.has(`${scope.id}:${slot}`) || scope.s[slot] instanceof Promise;
|
|
603
|
-
}
|
|
604
|
-
/** `x++`, `x--`, `++x` and `--x`. */
|
|
605
|
-
function update(scope, slot, delta, prefix) {
|
|
606
|
-
const previous = get(scope, slot);
|
|
607
|
-
set(scope, slot, previous + delta);
|
|
608
|
-
return prefix ? previous + delta : previous;
|
|
609
|
-
}
|
|
610
|
-
function rootOf(scope) {
|
|
611
|
-
let current = scope;
|
|
612
|
-
while (current.p) current = current.p;
|
|
613
|
-
return current;
|
|
614
|
-
}
|
|
615
|
-
function trigger(scope, slot) {
|
|
616
|
-
const id = rootOf(scope).m;
|
|
617
|
-
const module = modules.get(id);
|
|
618
|
-
const updates = loadedParts.get(`${id}:update`);
|
|
619
|
-
if (module && updates) {
|
|
620
|
-
run(module, updates, scope, slot);
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
loadModule(id).then(async (loaded) => {
|
|
624
|
-
if (loaded.g[scope.k]?.[slot]) run(loaded, await loadPart(loaded, "update"), scope, slot);
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
const pendingEffects = /* @__PURE__ */ new Map();
|
|
628
|
-
let running = 0;
|
|
629
|
-
let flushing = false;
|
|
630
|
-
/** Counts changes to the scope tree, so `run` knows when the descendants it found are out of date. */
|
|
631
|
-
let treeChanges = 0;
|
|
632
|
-
function run(module, updates, scope, slot) {
|
|
633
|
-
running++;
|
|
634
|
-
let found;
|
|
635
|
-
let foundAt = treeChanges;
|
|
636
|
-
try {
|
|
637
|
-
for (const [kind, name] of module.g[scope.k]?.[slot] ?? []) {
|
|
638
|
-
const fn = updates[name];
|
|
639
|
-
if (kind === scope.k) {
|
|
640
|
-
runUpdate(fn, name, scope);
|
|
641
|
-
continue;
|
|
642
|
-
}
|
|
643
|
-
if (foundAt !== treeChanges) {
|
|
644
|
-
found = void 0;
|
|
645
|
-
foundAt = treeChanges;
|
|
646
|
-
}
|
|
647
|
-
found ??= /* @__PURE__ */ new Map();
|
|
648
|
-
let targets = found.get(kind);
|
|
649
|
-
if (!targets) {
|
|
650
|
-
targets = descendants(scope, kind);
|
|
651
|
-
found.set(kind, targets);
|
|
652
|
-
}
|
|
653
|
-
for (const target of targets) runUpdate(fn, name, target);
|
|
654
|
-
}
|
|
655
|
-
} finally {
|
|
656
|
-
running--;
|
|
657
|
-
}
|
|
658
|
-
if (running === 0) flushEffects();
|
|
659
|
-
}
|
|
660
|
-
/** Runs an update on a scope. An effect waits until the other updates have run. */
|
|
661
|
-
function runUpdate(fn, name, target) {
|
|
662
|
-
if (name[0] === "e") pendingEffects.set(`${target.id}:${name}`, () => {
|
|
663
|
-
if (scopes.has(target.id)) fn(target);
|
|
664
|
-
});
|
|
665
|
-
else fn(target);
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Runs the effects that writes scheduled, in the order they were first
|
|
669
|
-
* scheduled. Writes in an effect schedule more effects, which run after.
|
|
670
|
-
*/
|
|
671
|
-
function flushEffects() {
|
|
672
|
-
if (flushing) return;
|
|
673
|
-
flushing = true;
|
|
674
|
-
try {
|
|
675
|
-
for (const [key, runEffect] of pendingEffects) {
|
|
676
|
-
pendingEffects.delete(key);
|
|
677
|
-
runEffect();
|
|
678
|
-
}
|
|
679
|
-
} finally {
|
|
680
|
-
flushing = false;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
function descendants(scope, kind, result = []) {
|
|
684
|
-
for (const child of scope.children) {
|
|
685
|
-
if (child.k === kind) result.push(child);
|
|
686
|
-
descendants(child, kind, result);
|
|
687
|
-
}
|
|
688
|
-
return result;
|
|
689
|
-
}
|
|
690
|
-
function destroy(scope) {
|
|
691
|
-
for (const child of Array.from(scope.children)) destroy(child);
|
|
692
|
-
const start = comments.get(`P${scope.id}`);
|
|
693
|
-
if (start?.isConnected) {
|
|
694
|
-
const end = rangeEnd(start);
|
|
695
|
-
clear(start, end);
|
|
696
|
-
start.remove();
|
|
697
|
-
end.remove();
|
|
698
|
-
}
|
|
699
|
-
removeScope(scope);
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Removes a scope from the page: its cleanups run, and its memo state goes,
|
|
703
|
-
* so a load that settles later is not written. Its markup stays.
|
|
704
|
-
*/
|
|
705
|
-
function removeScope(scope) {
|
|
706
|
-
for (const cleanup of scope.cleanups?.values() ?? []) cleanup();
|
|
707
|
-
for (let slot = 0; slot < scope.s.length; slot++) {
|
|
708
|
-
const key = `${scope.id}:${slot}`;
|
|
709
|
-
memoControllers.get(key)?.abort();
|
|
710
|
-
memoControllers.delete(key);
|
|
711
|
-
loads.delete(key);
|
|
712
|
-
loadingSlots.delete(key);
|
|
713
|
-
guesses?.map.delete(key);
|
|
714
|
-
}
|
|
715
|
-
if (scope.h) hiding?.bodies.delete(scope.h);
|
|
716
|
-
scopes.delete(scope.id);
|
|
717
|
-
scope.p?.children.delete(scope);
|
|
718
|
-
treeChanges++;
|
|
719
|
-
}
|
|
720
|
-
function disposeKinds(scope, kinds) {
|
|
721
|
-
for (const child of Array.from(scope.children)) if (kinds.includes(child.k)) destroy(child);
|
|
722
|
-
}
|
|
723
|
-
const MARKER = /^[btilP]-?\d/;
|
|
724
|
-
function markerKey(data) {
|
|
725
|
-
return data[0] === "b" ? data.split(":").slice(0, 2).join(":") : data;
|
|
726
|
-
}
|
|
727
|
-
function indexMarkers(root) {
|
|
728
|
-
const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
|
|
729
|
-
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
730
|
-
const data = node.data;
|
|
731
|
-
if (MARKER.test(data)) comments.set(markerKey(data), node);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
/** Indexes the markers in the nodes that mutation records added. */
|
|
735
|
-
function indexAdded(records) {
|
|
736
|
-
for (const record of records) for (const node of record.addedNodes) if (node.nodeType === 1) indexMarkers(node);
|
|
737
|
-
else if (node.nodeType === 8 && MARKER.test(node.data)) comments.set(markerKey(node.data), node);
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* Finds a marker in the page. Returns undefined when the markup is not in
|
|
741
|
-
* the page, such as `children` inside a block that is closed. Updates to it
|
|
742
|
-
* do nothing, and it updates when the client inserts it again.
|
|
743
|
-
*/
|
|
744
|
-
function findComment(key) {
|
|
745
|
-
let comment = comments.get(key);
|
|
746
|
-
if (!comment?.isConnected) {
|
|
747
|
-
if (markerObserver) indexAdded(markerObserver.takeRecords());
|
|
748
|
-
else indexMarkers(document.documentElement);
|
|
749
|
-
comment = comments.get(key);
|
|
750
|
-
}
|
|
751
|
-
return comment?.isConnected ? comment : void 0;
|
|
752
|
-
}
|
|
753
|
-
function findElement(scope, anchor) {
|
|
754
|
-
const key = `${scope}:${anchor}`;
|
|
755
|
-
let element = elements.get(key);
|
|
756
|
-
if (!element?.isConnected) {
|
|
757
|
-
element = document.querySelector(`[b-b="${key}"]`) ?? void 0;
|
|
758
|
-
if (element) elements.set(key, element);
|
|
759
|
-
}
|
|
760
|
-
return element ?? null;
|
|
761
|
-
}
|
|
762
|
-
/** Returns the marker that ends the range that `start` opens. */
|
|
763
|
-
function rangeEnd(start) {
|
|
764
|
-
let depth = 0;
|
|
765
|
-
for (let node = start.nextSibling; node; node = node.nextSibling) if (node.nodeType === 8) {
|
|
766
|
-
const data = node.data;
|
|
767
|
-
if (data[0] === "/") {
|
|
768
|
-
if (depth === 0) return node;
|
|
769
|
-
depth--;
|
|
770
|
-
} else if (MARKER.test(data)) depth++;
|
|
771
|
-
}
|
|
772
|
-
throw new Error(`Missing end marker for <!--${start.data}-->`);
|
|
773
|
-
}
|
|
774
|
-
function clear(start, end) {
|
|
775
|
-
while (start.nextSibling && start.nextSibling !== end) start.nextSibling.remove();
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Inserts rendered HTML before a node, or at the end of a parent, and runs
|
|
779
|
-
* the work that waits for it.
|
|
780
|
-
*/
|
|
781
|
-
function insertHTML(before, html) {
|
|
782
|
-
const template = document.createElement("template");
|
|
783
|
-
template.innerHTML = html;
|
|
784
|
-
const fragment = template.content;
|
|
785
|
-
if (markerObserver) indexAdded(markerObserver.takeRecords());
|
|
786
|
-
indexMarkers(fragment);
|
|
787
|
-
options.listen(fragment);
|
|
788
|
-
const server = serverScopes(fragment);
|
|
789
|
-
const added = hiding?.bodies.size ? [...fragment.childNodes] : void 0;
|
|
790
|
-
if ("parent" in before) before.parent.append(fragment);
|
|
791
|
-
else before.parentNode.insertBefore(fragment, before);
|
|
792
|
-
if (added) hiding.added(added);
|
|
793
|
-
markerObserver?.takeRecords();
|
|
794
|
-
for (const fn of afterInsert.splice(0)) fn();
|
|
795
|
-
if (server.length > 0) refresh(server);
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
* Returns the scopes from the server that markup refers to. Markup that the
|
|
799
|
-
* client renders has client scopes, so these come from HTML that the server
|
|
800
|
-
* rendered, such as the `children` of a component.
|
|
801
|
-
*/
|
|
802
|
-
function serverScopes(root) {
|
|
803
|
-
const ids = /* @__PURE__ */ new Set();
|
|
804
|
-
for (const element of root.querySelectorAll("[b-b]")) ids.add(Number(element.getAttribute("b-b").split(":")[0]));
|
|
805
|
-
const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
|
|
806
|
-
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
807
|
-
const match = /^[tb](\d+):/.exec(node.data);
|
|
808
|
-
if (match) ids.add(Number(match[1]));
|
|
809
|
-
}
|
|
810
|
-
return [...ids].flatMap((id) => {
|
|
811
|
-
const scope = scopes.get(id);
|
|
812
|
-
return scope ? [scope] : [];
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* Renders a `#portal` body into its target, between markers with its scope
|
|
817
|
-
* ID. `kinds` names the body, so a new target first removes it from the old one.
|
|
818
|
-
*/
|
|
819
|
-
function portalTo(scope, target, render, kinds = []) {
|
|
820
|
-
disposeKinds(scope, kinds);
|
|
821
|
-
const element = typeof target === "string" ? document.querySelector(target) : target;
|
|
822
|
-
if (!(element instanceof Element)) return;
|
|
823
|
-
insertHTML({ parent: element }, `<!--P${nextId}-->${render(scope)}<!--/P-->`);
|
|
824
|
-
}
|
|
825
|
-
/** Writes an inserted value between `<!--t…-->` and `<!--/t-->`. */
|
|
826
|
-
function text(scope, anchor, value) {
|
|
827
|
-
const start = findComment(`t${scope.id}:${anchor}`);
|
|
828
|
-
if (start) write(start.parentNode, start.nextSibling, rangeEnd(start), value);
|
|
829
|
-
}
|
|
830
|
-
/** Writes an inserted value that is the whole content of the element with the anchor. */
|
|
831
|
-
function content(scope, anchor, value) {
|
|
832
|
-
const element = findElement(scope.id, anchor);
|
|
833
|
-
if (element) write(element, element.firstChild, null, value);
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
* Writes the text of an element whose content is text, such as a `<textarea>`
|
|
837
|
-
* or a `<title>`. A `<textarea>` gets the value too, as `value` does on an
|
|
838
|
-
* `<input>`, so a change replaces what the user typed.
|
|
839
|
-
*/
|
|
840
|
-
function writeText(scope, anchor, value) {
|
|
841
|
-
const element = findElement(scope.id, anchor);
|
|
842
|
-
if (element) {
|
|
843
|
-
const written = textValue(value);
|
|
844
|
-
element.textContent = written;
|
|
845
|
-
if (element instanceof HTMLTextAreaElement) element.value = written;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
/**
|
|
849
|
-
* Replaces the nodes of `parent` from `first` up to `end`, or to its last
|
|
850
|
-
* child, with a value. A text node that stays a text node keeps its node.
|
|
851
|
-
*/
|
|
852
|
-
function write(parent, first, end, value) {
|
|
853
|
-
if ((typeof value === "string" || typeof value === "number") && first?.nodeType === 3 && first.nextSibling === end) {
|
|
854
|
-
const saved = hiding?.nodes.get(first);
|
|
855
|
-
if (saved) saved.v = String(value);
|
|
856
|
-
else first.data = String(value);
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
while (first && first !== end) {
|
|
860
|
-
const next = first.nextSibling;
|
|
861
|
-
first.remove();
|
|
862
|
-
first = next;
|
|
863
|
-
}
|
|
864
|
-
insertHTML(end ?? { parent }, insertValue(value));
|
|
865
|
-
}
|
|
866
|
-
function setAttribute(element, name, value) {
|
|
867
|
-
if (name === "value" || name === "checked") element[name] = name === "checked" ? Boolean(value) : value ?? "";
|
|
868
|
-
const written = attributeText(name, value);
|
|
869
|
-
if (written === void 0) element.removeAttribute(name);
|
|
870
|
-
else element.setAttribute(name, written);
|
|
871
|
-
if (name === "style") hiding?.styled(element);
|
|
872
|
-
}
|
|
873
|
-
function attr(scope, anchor, name, value) {
|
|
874
|
-
const element = findElement(scope.id, anchor);
|
|
875
|
-
if (element) setAttribute(element, name, value);
|
|
876
|
-
}
|
|
877
|
-
function attrs(scope, anchor, values) {
|
|
878
|
-
const element = findElement(scope.id, anchor);
|
|
879
|
-
if (element) {
|
|
880
|
-
for (const [name, value] of Object.entries(values)) if (name !== "children" && !/^on[A-Z]/.test(name)) setAttribute(element, name, value);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
/** Shows the branch at `index` of `#if` or `#switch`, or nothing for -1. */
|
|
884
|
-
function branch(scope, anchor, index, renders, kinds) {
|
|
885
|
-
const start = findComment(`b${scope.id}:${anchor}`);
|
|
886
|
-
if (!start) return;
|
|
887
|
-
if (Number(start.data.split(":")[2]) === index) return;
|
|
888
|
-
const end = rangeEnd(start);
|
|
889
|
-
disposeKinds(scope, kinds);
|
|
890
|
-
clear(start, end);
|
|
891
|
-
start.data = `b${scope.id}:${anchor}:${index}`;
|
|
892
|
-
const render = renders[index];
|
|
893
|
-
if (render) insertHTML(end, render(scope));
|
|
894
|
-
}
|
|
895
|
-
/** Renders the body of `#key` again when its value changes. */
|
|
896
|
-
function rekey(scope, anchor, value, render, kinds) {
|
|
897
|
-
scope.keys ??= /* @__PURE__ */ new Map();
|
|
898
|
-
if (scope.keys.has(anchor) && Object.is(scope.keys.get(anchor), value)) return;
|
|
899
|
-
scope.keys.set(anchor, value);
|
|
900
|
-
const start = findComment(`b${scope.id}:${anchor}`);
|
|
901
|
-
if (!start) return;
|
|
902
|
-
const end = rangeEnd(start);
|
|
903
|
-
disposeKinds(scope, kinds);
|
|
904
|
-
clear(start, end);
|
|
905
|
-
insertHTML(end, render(scope));
|
|
906
|
-
}
|
|
907
|
-
/**
|
|
908
|
-
* Renders the body of a `#try` block again, for its `reset` function. If the
|
|
909
|
-
* body throws, the fallback renders again with the error.
|
|
910
|
-
*/
|
|
911
|
-
async function reset(scope, anchor, id, body, fallback, kinds) {
|
|
912
|
-
const updates = await loadPart(await loadModule(id), "update");
|
|
913
|
-
const start = findComment(`b${scope.id}:${anchor}`);
|
|
914
|
-
if (!start) return;
|
|
915
|
-
const end = rangeEnd(start);
|
|
916
|
-
disposeKinds(scope, kinds);
|
|
917
|
-
clear(start, end);
|
|
918
|
-
let html;
|
|
919
|
-
try {
|
|
920
|
-
html = updates[body](scope);
|
|
921
|
-
} catch (error) {
|
|
922
|
-
disposeKinds(scope, kinds);
|
|
923
|
-
afterInsert.length = 0;
|
|
924
|
-
html = updates[fallback](scope, error);
|
|
925
|
-
}
|
|
926
|
-
insertHTML(end, html);
|
|
927
|
-
}
|
|
928
|
-
/** Renders the body of a `#client` block once. */
|
|
929
|
-
function fill(scope, anchor, render) {
|
|
930
|
-
const start = findComment(`b${scope.id}:${anchor}`);
|
|
931
|
-
if (!start) return;
|
|
932
|
-
const end = rangeEnd(start);
|
|
933
|
-
if (start.nextSibling === end) insertHTML(end, render(scope));
|
|
934
|
-
}
|
|
935
|
-
/**
|
|
936
|
-
* Shows or hides the body of an `#offscreen` block. A body that the page
|
|
937
|
-
* does not have yet renders the first time it shows. `kind` is the body's
|
|
938
|
-
* scope ID in the compiled component.
|
|
939
|
-
*/
|
|
940
|
-
function offscreen(scope, anchor, value, render, kind) {
|
|
941
|
-
const start = findComment(`b${scope.id}:${anchor}`);
|
|
942
|
-
if (!start) return;
|
|
943
|
-
const visible = Boolean(value);
|
|
944
|
-
const state = start.data.split(":")[2];
|
|
945
|
-
if (visible ? state === "1" : state !== "1") return;
|
|
946
|
-
start.data = `b${scope.id}:${anchor}:${visible ? 1 : 0}`;
|
|
947
|
-
const end = rangeEnd(start);
|
|
948
|
-
if (state === "-1") {
|
|
949
|
-
insertHTML(end, render(scope));
|
|
950
|
-
return;
|
|
951
|
-
}
|
|
952
|
-
let body;
|
|
953
|
-
for (const child of scope.children) if (child.k === kind) body = child;
|
|
954
|
-
if (body) {
|
|
955
|
-
hiding ??= createHiding();
|
|
956
|
-
if (visible) hiding.show(body);
|
|
957
|
-
else hiding.hide(body, start, end);
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* The code of hidden `#offscreen` bodies. The first body that hides sets it
|
|
962
|
-
* up, so the core of a page without one only checks that it is not there.
|
|
963
|
-
* A body is hidden with an inline `display: none !important` on each element
|
|
964
|
-
* at its top level, which no stylesheet overrides, and empty text for each
|
|
965
|
-
* text node. The nodes stay in the page, so form fields, focus and media
|
|
966
|
-
* keep their state.
|
|
967
|
-
*/
|
|
968
|
-
let hiding;
|
|
969
|
-
/** True for a scope that is `ancestor` or inside it, also through the owner of a component. */
|
|
970
|
-
function within(scope, ancestor) {
|
|
971
|
-
for (let current = scope; current; current = current.p ?? current.o) if (current === ancestor) return true;
|
|
972
|
-
return false;
|
|
973
|
-
}
|
|
974
|
-
/** True for a scope in a hidden `#offscreen` body. */
|
|
975
|
-
function hidden(scope) {
|
|
976
|
-
for (let current = scope; current; current = current.p ?? current.o) if (current.h) return true;
|
|
977
|
-
return false;
|
|
978
|
-
}
|
|
979
|
-
/** The nodes between two markers. */
|
|
980
|
-
function between([start, end]) {
|
|
981
|
-
const result = [];
|
|
982
|
-
for (let node = start.nextSibling; node && node !== end; node = node.nextSibling) result.push(node);
|
|
983
|
-
return result;
|
|
984
|
-
}
|
|
985
|
-
/** The inline style of an element, which an element that is not HTML or SVG may not have. */
|
|
986
|
-
function display(element) {
|
|
987
|
-
return element.style;
|
|
988
|
-
}
|
|
989
|
-
function createHiding() {
|
|
990
|
-
const bodies = /* @__PURE__ */ new Set();
|
|
991
|
-
const nodes = /* @__PURE__ */ new WeakMap();
|
|
992
|
-
const hideNode = (node) => {
|
|
993
|
-
const saved = nodes.get(node);
|
|
994
|
-
if (saved) {
|
|
995
|
-
saved.n++;
|
|
996
|
-
return;
|
|
997
|
-
}
|
|
998
|
-
if (node.nodeType === 3) {
|
|
999
|
-
nodes.set(node, {
|
|
1000
|
-
n: 1,
|
|
1001
|
-
v: node.data
|
|
1002
|
-
});
|
|
1003
|
-
node.data = "";
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
const style = node.nodeType === 1 ? display(node) : void 0;
|
|
1007
|
-
if (style) {
|
|
1008
|
-
nodes.set(node, {
|
|
1009
|
-
n: 1,
|
|
1010
|
-
v: style.getPropertyValue("display"),
|
|
1011
|
-
p: style.getPropertyPriority("display"),
|
|
1012
|
-
a: node.hasAttribute("style")
|
|
1013
|
-
});
|
|
1014
|
-
style.setProperty("display", "none", "important");
|
|
1015
|
-
}
|
|
1016
|
-
};
|
|
1017
|
-
const showNode = (node) => {
|
|
1018
|
-
const saved = nodes.get(node);
|
|
1019
|
-
if (!saved || --saved.n > 0) return;
|
|
1020
|
-
nodes.delete(node);
|
|
1021
|
-
if (node.nodeType === 3) {
|
|
1022
|
-
node.data = saved.v;
|
|
1023
|
-
return;
|
|
1024
|
-
}
|
|
1025
|
-
const element = node;
|
|
1026
|
-
const style = display(element);
|
|
1027
|
-
if (saved.v) style.setProperty("display", saved.v, saved.p);
|
|
1028
|
-
else style.removeProperty("display");
|
|
1029
|
-
if (!saved.a && element.getAttribute("style") === "") element.removeAttribute("style");
|
|
1030
|
-
};
|
|
1031
|
-
return {
|
|
1032
|
-
bodies,
|
|
1033
|
-
nodes,
|
|
1034
|
-
hidden,
|
|
1035
|
-
hide(body, start, end) {
|
|
1036
|
-
const record = {
|
|
1037
|
-
scope: body,
|
|
1038
|
-
ranges: [[start, end]]
|
|
1039
|
-
};
|
|
1040
|
-
body.h = record;
|
|
1041
|
-
bodies.add(record);
|
|
1042
|
-
const inside = [...scopes.values()].filter((scope) => within(scope, body));
|
|
1043
|
-
for (const scope of inside) {
|
|
1044
|
-
const portal = comments.get(`P${scope.id}`);
|
|
1045
|
-
if (portal?.isConnected) record.ranges.push([portal, rangeEnd(portal)]);
|
|
1046
|
-
}
|
|
1047
|
-
for (const range of record.ranges) between(range).forEach(hideNode);
|
|
1048
|
-
for (const scope of inside) {
|
|
1049
|
-
for (const [name, cleanup] of scope.cleanups ?? []) {
|
|
1050
|
-
cleanup();
|
|
1051
|
-
(scope.w ??= /* @__PURE__ */ new Set()).add(name);
|
|
1052
|
-
}
|
|
1053
|
-
scope.cleanups?.clear();
|
|
1054
|
-
}
|
|
1055
|
-
},
|
|
1056
|
-
show(body) {
|
|
1057
|
-
const record = body.h;
|
|
1058
|
-
if (!record) return;
|
|
1059
|
-
body.h = void 0;
|
|
1060
|
-
bodies.delete(record);
|
|
1061
|
-
for (const range of record.ranges) if (range[0].isConnected) between(range).forEach(showNode);
|
|
1062
|
-
for (const scope of scopes.values()) if (scope.w && within(scope, body) && !hidden(scope)) {
|
|
1063
|
-
const ref = `${rootOf(scope).m}#`;
|
|
1064
|
-
for (const name of scope.w) call(ref + name, scope, []);
|
|
1065
|
-
scope.w = void 0;
|
|
1066
|
-
}
|
|
1067
|
-
},
|
|
1068
|
-
paused(scope, name) {
|
|
1069
|
-
if (bodies.size === 0 || !hidden(scope)) return false;
|
|
1070
|
-
(scope.w ??= /* @__PURE__ */ new Set()).add(name);
|
|
1071
|
-
return true;
|
|
1072
|
-
},
|
|
1073
|
-
added(added) {
|
|
1074
|
-
for (const node of added) for (const record of bodies) {
|
|
1075
|
-
for (const [start, end] of record.ranges) if (node.parentNode === start.parentNode && start.compareDocumentPosition(node) & 4 && node.compareDocumentPosition(end) & 4) hideNode(node);
|
|
1076
|
-
const data = node.nodeType === 8 ? node.data : "";
|
|
1077
|
-
const scope = /^P-?\d+$/.test(data) ? scopes.get(Number(data.slice(1))) : void 0;
|
|
1078
|
-
if (scope && within(scope, record.scope)) record.ranges.push([node, rangeEnd(node)]);
|
|
1079
|
-
}
|
|
1080
|
-
},
|
|
1081
|
-
styled(element) {
|
|
1082
|
-
const saved = nodes.get(element);
|
|
1083
|
-
const style = display(element);
|
|
1084
|
-
if (saved && style) {
|
|
1085
|
-
saved.v = style.getPropertyValue("display");
|
|
1086
|
-
saved.p = style.getPropertyPriority("display");
|
|
1087
|
-
saved.a = element.hasAttribute("style");
|
|
1088
|
-
style.setProperty("display", "none", "important");
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
};
|
|
1092
|
-
}
|
|
1093
|
-
/** Updates the items of `#for` or `#repeat`, keeping the elements of items whose keys stay. */
|
|
1094
|
-
function list(scope, anchor, items, key, render, assign, fallback, fallbackKinds) {
|
|
1095
|
-
const start = findComment(`b${scope.id}:${anchor}`);
|
|
1096
|
-
if (!start) return;
|
|
1097
|
-
const end = rangeEnd(start);
|
|
1098
|
-
const previous = /* @__PURE__ */ new Map();
|
|
1099
|
-
const others = [];
|
|
1100
|
-
let position = 0;
|
|
1101
|
-
for (let node = start.nextSibling; node && node !== end;) {
|
|
1102
|
-
const data = node.nodeType === 8 ? node.data : void 0;
|
|
1103
|
-
const id = data ? /^i(-?\d+)$/.exec(data)?.[1] : node.getAttribute?.("b-b")?.split(":")[0];
|
|
1104
|
-
const item = id === void 0 ? void 0 : scopes.get(Number(id));
|
|
1105
|
-
let last = node;
|
|
1106
|
-
if (item && (data || item.p === scope && !fallbackKinds.includes(item.k))) {
|
|
1107
|
-
if (data) last = rangeEnd(node);
|
|
1108
|
-
const nodes = [node];
|
|
1109
|
-
for (let current = node; current !== last;) nodes.push(current = current.nextSibling);
|
|
1110
|
-
previous.set(key(item.i, position++), {
|
|
1111
|
-
scope: item,
|
|
1112
|
-
nodes
|
|
1113
|
-
});
|
|
1114
|
-
} else others.push(node);
|
|
1115
|
-
node = last.nextSibling;
|
|
1116
|
-
}
|
|
1117
|
-
if (items.length === 0) {
|
|
1118
|
-
if (previous.size === 0 && others.length > 0) return;
|
|
1119
|
-
for (const item of previous.values()) destroy(item.scope);
|
|
1120
|
-
clear(start, end);
|
|
1121
|
-
if (fallback) insertHTML(end, fallback(scope));
|
|
1122
|
-
return;
|
|
1123
|
-
}
|
|
1124
|
-
disposeKinds(scope, fallbackKinds);
|
|
1125
|
-
for (const node of others) node.parentNode?.removeChild(node);
|
|
1126
|
-
const parent = end.parentNode;
|
|
1127
|
-
let cursor = start.nextSibling;
|
|
1128
|
-
let added = "";
|
|
1129
|
-
const flush = () => {
|
|
1130
|
-
if (added) {
|
|
1131
|
-
insertHTML(cursor, added);
|
|
1132
|
-
added = "";
|
|
1133
|
-
}
|
|
1134
|
-
};
|
|
1135
|
-
items.forEach((value, index) => {
|
|
1136
|
-
const id = key(value, index);
|
|
1137
|
-
const item = previous.get(id);
|
|
1138
|
-
if (item) {
|
|
1139
|
-
flush();
|
|
1140
|
-
previous.delete(id);
|
|
1141
|
-
assign(item.scope, value, index);
|
|
1142
|
-
if (item.nodes[0] === cursor) cursor = item.nodes.at(-1).nextSibling;
|
|
1143
|
-
else for (const node of item.nodes) parent.insertBefore(node, cursor);
|
|
1144
|
-
} else added += render(scope, value, index);
|
|
1145
|
-
});
|
|
1146
|
-
flush();
|
|
1147
|
-
for (const item of previous.values()) {
|
|
1148
|
-
destroy(item.scope);
|
|
1149
|
-
for (const node of item.nodes) node.parentNode?.removeChild(node);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
/** Sets a style variable on the top-level elements of a component instance. */
|
|
1153
|
-
function setVar(scope, name, value) {
|
|
1154
|
-
const css = value === null || value === void 0 || value === false ? "" : String(value);
|
|
1155
|
-
for (const element of document.querySelectorAll(`[b-v="${scope.id}"]`)) element.style.setProperty(name, css);
|
|
1156
|
-
}
|
|
1157
|
-
/** The scope that provides a context to `scope`: itself or the nearest one above it. */
|
|
1158
|
-
function findProvider(scope, key) {
|
|
1159
|
-
for (let current = scope; current; current = current.p ?? current.o) if (current.v && key in current.v) return current;
|
|
1160
|
-
}
|
|
1161
|
-
/** Writes a provided value, and the slot of every scope that reads it from this provider. */
|
|
1162
|
-
function updateContext(scope, context, value) {
|
|
1163
|
-
scope.v ??= {};
|
|
1164
|
-
scope.v[context.key] = value;
|
|
1165
|
-
for (const target of scopes.values()) {
|
|
1166
|
-
const slot = target.x?.[context.key];
|
|
1167
|
-
if (slot !== void 0 && findProvider(target, context.key) === scope) set(target, slot, value);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
/** Sets the title of the page. */
|
|
1171
|
-
function title(value) {
|
|
1172
|
-
document.title = value === null || value === void 0 ? "" : String(value);
|
|
1173
|
-
}
|
|
1174
|
-
/** Writes a prop of a child component. */
|
|
1175
|
-
function prop(scope, anchor, name, value) {
|
|
1176
|
-
const id = scope.c?.[anchor];
|
|
1177
|
-
const child = id === void 0 ? void 0 : scopes.get(id);
|
|
1178
|
-
if (!child?.m) return;
|
|
1179
|
-
const apply = (module) => {
|
|
1180
|
-
const slot = module.props[name];
|
|
1181
|
-
if (slot !== void 0) {
|
|
1182
|
-
if (isThenable(value)) asyncMemo(child, slot, Promise.resolve(value));
|
|
1183
|
-
else set(child, slot, value);
|
|
1184
|
-
return;
|
|
1185
|
-
}
|
|
1186
|
-
const all = module.props["*"];
|
|
1187
|
-
if (all !== void 0) set(child, all, {
|
|
1188
|
-
...get(child, all),
|
|
1189
|
-
[name]: value
|
|
1190
|
-
});
|
|
1191
|
-
};
|
|
1192
|
-
const module = modules.get(child.m);
|
|
1193
|
-
if (module) apply(module);
|
|
1194
|
-
else loadModule(child.m).then(apply);
|
|
1195
|
-
}
|
|
1196
|
-
/** Runs an effect or a `$client` callback, after the cleanup of its previous run. */
|
|
1197
|
-
function effect(scope, name, callback) {
|
|
1198
|
-
if (hiding?.paused(scope, name)) return;
|
|
1199
|
-
scope.cleanups ??= /* @__PURE__ */ new Map();
|
|
1200
|
-
scope.cleanups.get(name)?.();
|
|
1201
|
-
const cleanup = callback();
|
|
1202
|
-
scope.cleanups.set(name, typeof cleanup === "function" ? cleanup : noop);
|
|
1203
|
-
}
|
|
1204
|
-
function noop() {}
|
|
1205
|
-
/** Renders the attributes of a form or button that posts to a server function. */
|
|
1206
|
-
function action(name, id, method, result) {
|
|
1207
|
-
return actionAttributes(rpcPrefix, name, id, method, result);
|
|
1208
|
-
}
|
|
1209
|
-
/**
|
|
1210
|
-
* Sends a form of an `$action`. The code is in `rpc.ts`, which every server
|
|
1211
|
-
* call loads, so the core holds only this.
|
|
1212
|
-
*/
|
|
1213
|
-
function submitAction(form, submitter) {
|
|
1214
|
-
import("../rpc-9fSqL_YK.js").then((module) => module.sendAction(form, submitter));
|
|
1215
|
-
}
|
|
1216
|
-
/** Calls a server function. */
|
|
1217
|
-
async function rpc(id, args) {
|
|
1218
|
-
const signal = memoSignal();
|
|
1219
|
-
return track(import("../rpc-9fSqL_YK.js").then((module) => module.call(rpcPrefix, id, args, signal)));
|
|
1220
|
-
}
|
|
1221
|
-
/** Renders a value inserted in markup. */
|
|
1222
|
-
function insert(value) {
|
|
1223
|
-
return insertValue(value);
|
|
1224
|
-
}
|
|
1225
|
-
function resolveScope(scope) {
|
|
1226
|
-
return typeof scope === "number" ? scopes.get(scope) : scope;
|
|
1227
|
-
}
|
|
1228
|
-
/**
|
|
1229
|
-
* Renders a child component on the client. With `scope` and `anchor`,
|
|
1230
|
-
* records the child's scope so the parent can update its props.
|
|
1231
|
-
*/
|
|
1232
|
-
function component(Child, props, _ctx, scope, anchor) {
|
|
1233
|
-
const parent = resolveScope(scope);
|
|
1234
|
-
if (parent && anchor !== void 0) {
|
|
1235
|
-
parent.c ??= {};
|
|
1236
|
-
parent.c[anchor] = nextId;
|
|
1237
|
-
}
|
|
1238
|
-
if (parent) setOwner(parent);
|
|
1239
|
-
return Child(props);
|
|
1240
|
-
}
|
|
1241
|
-
function dynamic(tag, attributes, children, _ctx, scope) {
|
|
1242
|
-
if (typeof tag === "function") return component(tag, children ? {
|
|
1243
|
-
...attributes,
|
|
1244
|
-
children
|
|
1245
|
-
} : attributes, void 0, scope);
|
|
1246
|
-
const name = String(tag);
|
|
1247
|
-
const open = `<${name}${spread(attributes)}>`;
|
|
1248
|
-
return VOID_ELEMENTS.has(name) ? open : `${open}${children ? rawHTML(children) : ""}</${name}>`;
|
|
1249
|
-
}
|
|
1250
|
-
/** Work that waits until rendered markup is in the page. */
|
|
1251
|
-
const afterInsert = [];
|
|
1252
|
-
/** The scope that renders the next component, which becomes its owner. */
|
|
1253
|
-
let owner;
|
|
1254
|
-
/** Creates a scope for markup that the client renders, and returns its ID. */
|
|
1255
|
-
function createScope(kind, parent, module) {
|
|
1256
|
-
const id = nextId--;
|
|
1257
|
-
const parentScope = resolveScope(parent);
|
|
1258
|
-
const created = {
|
|
1259
|
-
id,
|
|
1260
|
-
k: kind,
|
|
1261
|
-
p: parentScope,
|
|
1262
|
-
m: module,
|
|
1263
|
-
s: [],
|
|
1264
|
-
children: /* @__PURE__ */ new Set()
|
|
1265
|
-
};
|
|
1266
|
-
if (module !== void 0 && owner) {
|
|
1267
|
-
created.o = owner;
|
|
1268
|
-
owner = void 0;
|
|
1269
|
-
}
|
|
1270
|
-
parentScope?.children.add(created);
|
|
1271
|
-
treeChanges++;
|
|
1272
|
-
scopes.set(id, created);
|
|
1273
|
-
return id;
|
|
1274
|
-
}
|
|
1275
|
-
/** The ID that `$id()` makes. Client scope IDs are negative, so they differ from the server's. */
|
|
1276
|
-
function makeId(scope, index) {
|
|
1277
|
-
return `b${resolveScope(scope).id}-${index}`;
|
|
1278
|
-
}
|
|
1279
|
-
/** Sets the owner of the next component's root scope. */
|
|
1280
|
-
function setOwner(scope) {
|
|
1281
|
-
owner = resolveScope(scope);
|
|
1282
|
-
}
|
|
1283
|
-
/** Provides a value of a context to the scopes inside `scope`. */
|
|
1284
|
-
function provideValue(context, value, scope) {
|
|
1285
|
-
const target = resolveScope(scope);
|
|
1286
|
-
target.v ??= {};
|
|
1287
|
-
target.v[context.key] = value;
|
|
1288
|
-
}
|
|
1289
|
-
/** Reads a context, and records its slot so that changes to the provided value reach it. */
|
|
1290
|
-
function consumeContext(context, scope, slot) {
|
|
1291
|
-
const target = resolveScope(scope);
|
|
1292
|
-
if (slot !== void 0) {
|
|
1293
|
-
target.x ??= {};
|
|
1294
|
-
target.x[context.key] = slot;
|
|
1295
|
-
}
|
|
1296
|
-
const provider = findProvider(target, context.key);
|
|
1297
|
-
return provider ? provider.v[context.key] : context.defaultValue;
|
|
1298
|
-
}
|
|
1299
|
-
function setSlots(id, values) {
|
|
1300
|
-
scopes.get(id).s = values;
|
|
1301
|
-
}
|
|
1302
|
-
function setItem(id, value) {
|
|
1303
|
-
scopes.get(id).i = value;
|
|
1304
|
-
}
|
|
1305
|
-
function elementAt(scope, anchor) {
|
|
1306
|
-
return new ElementReference(scope, anchor);
|
|
1307
|
-
}
|
|
1308
|
-
/** Adds the markup of a `#head` block to the document's head. */
|
|
1309
|
-
function addHead(html) {
|
|
1310
|
-
afterInsert.push(() => insertHTML({ parent: document.head }, html));
|
|
1311
|
-
}
|
|
1312
|
-
/** Adds the markup of a `#portal` block at the end of the page, after the markup around it. */
|
|
1313
|
-
function addPortal(html) {
|
|
1314
|
-
afterInsert.push(() => insertHTML({ parent: document.body }, html));
|
|
1315
|
-
}
|
|
1316
|
-
/** Adds a component's stylesheet to the page, if the server did not. */
|
|
1317
|
-
function addStyle(id, css) {
|
|
1318
|
-
if (!document.querySelector(`style[b-style="${id}"]`)) {
|
|
1319
|
-
const sheet = document.createElement("style");
|
|
1320
|
-
sheet.setAttribute("b-style", id);
|
|
1321
|
-
sheet.textContent = css;
|
|
1322
|
-
document.head.append(sheet);
|
|
1323
|
-
}
|
|
1324
|
-
return "";
|
|
1325
|
-
}
|
|
1326
|
-
/** A function prop rendered on the client calls the parent's exported handler. */
|
|
1327
|
-
function handlerProp(value, ref, scope) {
|
|
1328
|
-
if (typeof value !== "function") return value;
|
|
1329
|
-
const instance = resolveScope(scope);
|
|
1330
|
-
return (...args) => call(ref, instance, args);
|
|
1331
|
-
}
|
|
1332
|
-
/**
|
|
1333
|
-
* What the loader calls. It is one export, so the loader's import of the core
|
|
1334
|
-
* names one export, and a build keeps the rest only when components call them.
|
|
1335
|
-
*/
|
|
1336
|
-
const loader = {
|
|
1337
|
-
init,
|
|
1338
|
-
handle,
|
|
1339
|
-
dispose,
|
|
1340
|
-
submitAction
|
|
1341
|
-
};
|
|
1342
|
-
//#endregion
|
|
1343
|
-
export { DEVTOOLS, ElementReference, FunctionReference, action, addHead, addPortal, addStyle, affix, afterInsert, asyncMemo, attr, attribute, attrs, branch, cells, classAttribute, component, consumeContext, content, createContext, createScope, descendants, dispose, dynamic, effect, elementAt, escape, fill, forget, get, guess, handle, handlerProp, hooks, init, insert, leavePage, leaveRoutes, list, loadModule, loadPart, loader, makeId, memo, offscreen, pending, portalTo, produce, prop, provideValue, raw, rekey, remount, removeRoot, removeScope, reset, rpc, rpcPrefix, scopeOf, scopes, set, setItem, setOwner, setSlots, setVar, spread, submitAction, text, title, track, update, updateContext, vars, writeText };
|
|
1344
|
-
|
|
1345
|
-
//# sourceMappingURL=client.js.map
|
|
1
|
+
import { c as escape, f as mergeAttributes, h as spread, i as attribute, o as classAttribute, p as raw, r as affix, v as vars } from "../html-bHZbkK-h.js";
|
|
2
|
+
import { n as ElementReference, r as FunctionReference, t as produce } from "../produce-CWfJ4byV.js";
|
|
3
|
+
import { a as routeContext, i as navigationContext, r as createContext } from "../context-CTiSzQRc.js";
|
|
4
|
+
import { $ as rpcPrefix, A as handlerProp, B as makeId, C as elementAt, D as get, E as forget, F as leaveRoutes, G as prop, H as offscreen, I as list, J as remount, K as provideValue, L as loadModule, M as init, N as insert, O as guess, P as leavePage, Q as rpc, R as loadPart, S as effect, T as fill, U as pending, V as memo, W as portalTo, X as removeScope, Y as removeRoot, Z as reset, _ as createScope, _t as writeText, a as addStyle, at as setOwner, b as dispose, c as attr, ct as skew, d as build, dt as timed, et as scopeOf, f as cells, ft as title, g as content, gt as updateRoute, h as consumeContext, ht as updateContext, i as addPortal, it as setItem, j as hooks, k as handle, l as attrs, lt as submitAction, m as component, mt as update, n as action, nt as set, o as afterInsert, ot as setSlots, p as children, pt as track, q as rekey, r as addHead, rt as setGlobal, s as asyncMemo, st as setVar, t as DEVTOOLS, tt as scopes, u as branch, ut as text, v as deferInBrowser, w as fail, x as dynamic, y as descendants, z as loader } from "../client-C0UCNL3J.js";
|
|
5
|
+
export { DEVTOOLS, ElementReference, FunctionReference, action, addHead, addPortal, addStyle, affix, afterInsert, asyncMemo, attr, attribute, attrs, branch, build, cells, children, classAttribute, component, consumeContext, content, createContext, createScope, deferInBrowser, descendants, dispose, dynamic, effect, elementAt, escape, fail, fill, forget, get, guess, handle, handlerProp, hooks, init, insert, leavePage, leaveRoutes, list, loadModule, loadPart, loader, makeId, memo, mergeAttributes, navigationContext, offscreen, pending, portalTo, produce, prop, provideValue, raw, rekey, remount, removeRoot, removeScope, reset, routeContext, rpc, rpcPrefix, scopeOf, scopes, set, setGlobal, setItem, setOwner, setSlots, setVar, skew, spread, submitAction, text, timed, title, track, update, updateContext, updateRoute, vars, writeText };
|