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
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
//#region src/nesting.ts
|
|
2
|
+
/**
|
|
3
|
+
* Elements whose start tag closes an open `<p>`, from the "in body" insertion mode of the HTML
|
|
4
|
+
* spec. `table` is left out, since only a document in quirks mode keeps the `<p>` open.
|
|
5
|
+
*/
|
|
6
|
+
const CLOSES_P = /* @__PURE__ */ new Set([
|
|
7
|
+
"address",
|
|
8
|
+
"article",
|
|
9
|
+
"aside",
|
|
10
|
+
"blockquote",
|
|
11
|
+
"center",
|
|
12
|
+
"details",
|
|
13
|
+
"dialog",
|
|
14
|
+
"dir",
|
|
15
|
+
"div",
|
|
16
|
+
"dl",
|
|
17
|
+
"dd",
|
|
18
|
+
"dt",
|
|
19
|
+
"fieldset",
|
|
20
|
+
"figcaption",
|
|
21
|
+
"figure",
|
|
22
|
+
"footer",
|
|
23
|
+
"form",
|
|
24
|
+
"h1",
|
|
25
|
+
"h2",
|
|
26
|
+
"h3",
|
|
27
|
+
"h4",
|
|
28
|
+
"h5",
|
|
29
|
+
"h6",
|
|
30
|
+
"header",
|
|
31
|
+
"hgroup",
|
|
32
|
+
"hr",
|
|
33
|
+
"li",
|
|
34
|
+
"listing",
|
|
35
|
+
"main",
|
|
36
|
+
"menu",
|
|
37
|
+
"nav",
|
|
38
|
+
"ol",
|
|
39
|
+
"p",
|
|
40
|
+
"pre",
|
|
41
|
+
"search",
|
|
42
|
+
"section",
|
|
43
|
+
"summary",
|
|
44
|
+
"ul",
|
|
45
|
+
"xmp"
|
|
46
|
+
]);
|
|
47
|
+
/** Elements that end the "button scope": a `<p>` above one of them stays open. */
|
|
48
|
+
const BUTTON_SCOPE = /* @__PURE__ */ new Set([
|
|
49
|
+
"applet",
|
|
50
|
+
"button",
|
|
51
|
+
"caption",
|
|
52
|
+
"html",
|
|
53
|
+
"marquee",
|
|
54
|
+
"object",
|
|
55
|
+
"table",
|
|
56
|
+
"td",
|
|
57
|
+
"template",
|
|
58
|
+
"th"
|
|
59
|
+
]);
|
|
60
|
+
/** Elements that end the list of open `<a>` elements. */
|
|
61
|
+
const LINK_MARKERS = /* @__PURE__ */ new Set([
|
|
62
|
+
"applet",
|
|
63
|
+
"caption",
|
|
64
|
+
"marquee",
|
|
65
|
+
"object",
|
|
66
|
+
"template",
|
|
67
|
+
"td",
|
|
68
|
+
"th"
|
|
69
|
+
]);
|
|
70
|
+
const HEADINGS = /* @__PURE__ */ new Set([
|
|
71
|
+
"h1",
|
|
72
|
+
"h2",
|
|
73
|
+
"h3",
|
|
74
|
+
"h4",
|
|
75
|
+
"h5",
|
|
76
|
+
"h6"
|
|
77
|
+
]);
|
|
78
|
+
/** What a table, its sections and its rows hold. Anything else moves out of the table. */
|
|
79
|
+
const TABLE_CHILDREN = {
|
|
80
|
+
table: /* @__PURE__ */ new Set([
|
|
81
|
+
"caption",
|
|
82
|
+
"col",
|
|
83
|
+
"colgroup",
|
|
84
|
+
"form",
|
|
85
|
+
"input",
|
|
86
|
+
"script",
|
|
87
|
+
"style",
|
|
88
|
+
"tbody",
|
|
89
|
+
"td",
|
|
90
|
+
"template",
|
|
91
|
+
"tfoot",
|
|
92
|
+
"th",
|
|
93
|
+
"thead",
|
|
94
|
+
"tr"
|
|
95
|
+
]),
|
|
96
|
+
tbody: /* @__PURE__ */ new Set([
|
|
97
|
+
"form",
|
|
98
|
+
"input",
|
|
99
|
+
"script",
|
|
100
|
+
"style",
|
|
101
|
+
"td",
|
|
102
|
+
"template",
|
|
103
|
+
"th",
|
|
104
|
+
"tr"
|
|
105
|
+
]),
|
|
106
|
+
thead: /* @__PURE__ */ new Set([
|
|
107
|
+
"form",
|
|
108
|
+
"input",
|
|
109
|
+
"script",
|
|
110
|
+
"style",
|
|
111
|
+
"td",
|
|
112
|
+
"template",
|
|
113
|
+
"th",
|
|
114
|
+
"tr"
|
|
115
|
+
]),
|
|
116
|
+
tfoot: /* @__PURE__ */ new Set([
|
|
117
|
+
"form",
|
|
118
|
+
"input",
|
|
119
|
+
"script",
|
|
120
|
+
"style",
|
|
121
|
+
"td",
|
|
122
|
+
"template",
|
|
123
|
+
"th",
|
|
124
|
+
"tr"
|
|
125
|
+
]),
|
|
126
|
+
tr: /* @__PURE__ */ new Set([
|
|
127
|
+
"form",
|
|
128
|
+
"input",
|
|
129
|
+
"script",
|
|
130
|
+
"style",
|
|
131
|
+
"td",
|
|
132
|
+
"template",
|
|
133
|
+
"th"
|
|
134
|
+
])
|
|
135
|
+
};
|
|
136
|
+
/** True when a `<p>` is open in button scope in `open`, the tags above an element. */
|
|
137
|
+
function paragraphOpen(open) {
|
|
138
|
+
for (let index = open.length - 1; index >= 0; index--) {
|
|
139
|
+
if (open[index] === "p") return true;
|
|
140
|
+
if (BUTTON_SCOPE.has(open[index])) return false;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The tag in `open`, the tags above an element with the nearest last, that the HTML parser closes
|
|
146
|
+
* or moves the element out of, or undefined. The rules come from the HTML spec and are the ones
|
|
147
|
+
* that hold in every document. The parser keeps a document in standard mode, so the same
|
|
148
|
+
* markup parses the same way everywhere.
|
|
149
|
+
*/
|
|
150
|
+
function nestingProblem(open, tag) {
|
|
151
|
+
if (open.includes("svg") || open.includes("math")) return;
|
|
152
|
+
const parent = open[open.length - 1];
|
|
153
|
+
if (CLOSES_P.has(tag) && paragraphOpen(open)) return "p";
|
|
154
|
+
if (parent !== void 0) {
|
|
155
|
+
if (HEADINGS.has(parent) && HEADINGS.has(tag)) return parent;
|
|
156
|
+
if (parent === "li" && tag === "li") return parent;
|
|
157
|
+
if ((parent === "dd" || parent === "dt") && (tag === "dd" || tag === "dt")) return parent;
|
|
158
|
+
const allowed = TABLE_CHILDREN[parent];
|
|
159
|
+
if (allowed && !allowed.has(tag)) return parent;
|
|
160
|
+
}
|
|
161
|
+
if (tag === "a") for (let index = open.length - 1; index >= 0; index--) {
|
|
162
|
+
if (open[index] === "a") return "a";
|
|
163
|
+
if (LINK_MARKERS.has(open[index])) break;
|
|
164
|
+
}
|
|
165
|
+
if (tag === "form") for (let index = open.length - 1; index >= 0; index--) {
|
|
166
|
+
if (open[index] === "form") return "form";
|
|
167
|
+
if (open[index] === "template") break;
|
|
168
|
+
}
|
|
169
|
+
if (tag === "button") for (let index = open.length - 1; index >= 0; index--) {
|
|
170
|
+
if (open[index] === "button") return "button";
|
|
171
|
+
if (BUTTON_SCOPE.has(open[index])) break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** The message of BRM185. */
|
|
175
|
+
function nestingMessage(tag, parent) {
|
|
176
|
+
return `<${tag}> cannot be inside <${parent}>: the HTML parser closes or moves it before the page runs. Move it out of the <${parent}>, or use a <span> or as="span"`;
|
|
177
|
+
}
|
|
178
|
+
/** Walks the markup of a file, with the tags that are open above each node. */
|
|
179
|
+
function walk(file, onElement, onComponent) {
|
|
180
|
+
function body(content, open) {
|
|
181
|
+
if (!content) return;
|
|
182
|
+
for (const template of content.templates) body(template.body, []);
|
|
183
|
+
nodes(content.children, open);
|
|
184
|
+
}
|
|
185
|
+
function nodes(list, open) {
|
|
186
|
+
for (const node of list) visit(node, open);
|
|
187
|
+
}
|
|
188
|
+
function visit(node, open) {
|
|
189
|
+
switch (node.kind) {
|
|
190
|
+
case "element": {
|
|
191
|
+
const tag = node.tag.toLowerCase();
|
|
192
|
+
onElement(tag, open, node);
|
|
193
|
+
open.push(tag);
|
|
194
|
+
nodes(node.children, open);
|
|
195
|
+
open.pop();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
case "component":
|
|
199
|
+
onComponent(node, open);
|
|
200
|
+
nodes(node.children, []);
|
|
201
|
+
return;
|
|
202
|
+
case "dynamic":
|
|
203
|
+
nodes(node.children, []);
|
|
204
|
+
return;
|
|
205
|
+
case "fragment":
|
|
206
|
+
nodes(node.children, open);
|
|
207
|
+
return;
|
|
208
|
+
case "if":
|
|
209
|
+
for (const branch of node.branches) body(branch.body, open);
|
|
210
|
+
body(node.fallback, open);
|
|
211
|
+
return;
|
|
212
|
+
case "switch":
|
|
213
|
+
for (const branch of node.cases) body(branch.body, open);
|
|
214
|
+
body(node.fallback, open);
|
|
215
|
+
return;
|
|
216
|
+
case "for":
|
|
217
|
+
case "repeat":
|
|
218
|
+
case "loading":
|
|
219
|
+
case "client":
|
|
220
|
+
case "defer":
|
|
221
|
+
case "try":
|
|
222
|
+
body(node.body, open);
|
|
223
|
+
body(node.fallback, open);
|
|
224
|
+
return;
|
|
225
|
+
case "key":
|
|
226
|
+
body(node.body, open);
|
|
227
|
+
return;
|
|
228
|
+
case "portal":
|
|
229
|
+
case "head":
|
|
230
|
+
case "offscreen":
|
|
231
|
+
body(node.body, []);
|
|
232
|
+
return;
|
|
233
|
+
default: return;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
for (const template of file.templates) body(template.body, []);
|
|
237
|
+
nodes(file.children, []);
|
|
238
|
+
}
|
|
239
|
+
/** Reports each element that the HTML parser closes or moves, as BRM185. */
|
|
240
|
+
function checkNesting(file, report) {
|
|
241
|
+
walk(file, (tag, open, node) => {
|
|
242
|
+
const parent = nestingProblem(open, tag);
|
|
243
|
+
if (parent !== void 0) report(nestingMessage(tag, parent), node);
|
|
244
|
+
}, () => {});
|
|
245
|
+
}
|
|
246
|
+
/** The components that sit inside a `<p>`, which the server checks in development. */
|
|
247
|
+
function paragraphComponents(file) {
|
|
248
|
+
const found = /* @__PURE__ */ new Set();
|
|
249
|
+
walk(file, () => {}, (node, open) => {
|
|
250
|
+
if (!open.includes("svg") && !open.includes("math") && paragraphOpen(open)) found.add(node);
|
|
251
|
+
});
|
|
252
|
+
return found;
|
|
253
|
+
}
|
|
254
|
+
/** The tag that the HTML starts with, skipping comments, or undefined. */
|
|
255
|
+
function firstTag(html) {
|
|
256
|
+
return /^(?:\s|<!--[^>]*?-->)*<([a-z][a-z0-9-]*)/i.exec(html)?.[1]?.toLowerCase();
|
|
257
|
+
}
|
|
258
|
+
/** True when a start tag of `tag` closes an open `<p>`. */
|
|
259
|
+
function closesParagraph(tag) {
|
|
260
|
+
return CLOSES_P.has(tag);
|
|
261
|
+
}
|
|
262
|
+
//#endregion
|
|
263
|
+
export { paragraphComponents as i, closesParagraph as n, firstTag as r, checkNesting as t };
|
|
264
|
+
|
|
265
|
+
//# sourceMappingURL=nesting-DA5vJw9X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nesting-DA5vJw9X.js","names":[],"sources":["../src/nesting.ts"],"sourcesContent":["import type { Body, ComponentNode, Markup, Range, SFCFile } from './ast.ts';\n\n/**\n * Elements whose start tag closes an open `<p>`, from the \"in body\" insertion mode of the HTML\n * spec. `table` is left out, since only a document in quirks mode keeps the `<p>` open.\n */\nconst CLOSES_P = new Set([\n 'address',\n 'article',\n 'aside',\n 'blockquote',\n 'center',\n 'details',\n 'dialog',\n 'dir',\n 'div',\n 'dl',\n 'dd',\n 'dt',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'header',\n 'hgroup',\n 'hr',\n 'li',\n 'listing',\n 'main',\n 'menu',\n 'nav',\n 'ol',\n 'p',\n 'pre',\n 'search',\n 'section',\n 'summary',\n 'ul',\n 'xmp',\n]);\n\n/** Elements that end the \"button scope\": a `<p>` above one of them stays open. */\nconst BUTTON_SCOPE = new Set([\n 'applet',\n 'button',\n 'caption',\n 'html',\n 'marquee',\n 'object',\n 'table',\n 'td',\n 'template',\n 'th',\n]);\n\n/** Elements that end the list of open `<a>` elements. */\nconst LINK_MARKERS = new Set(['applet', 'caption', 'marquee', 'object', 'template', 'td', 'th']);\n\nconst HEADINGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);\n\n/** What a table, its sections and its rows hold. Anything else moves out of the table. */\nconst TABLE_CHILDREN: Record<string, ReadonlySet<string>> = {\n table: new Set([\n 'caption',\n 'col',\n 'colgroup',\n 'form',\n 'input',\n 'script',\n 'style',\n 'tbody',\n 'td',\n 'template',\n 'tfoot',\n 'th',\n 'thead',\n 'tr',\n ]),\n tbody: new Set(['form', 'input', 'script', 'style', 'td', 'template', 'th', 'tr']),\n thead: new Set(['form', 'input', 'script', 'style', 'td', 'template', 'th', 'tr']),\n tfoot: new Set(['form', 'input', 'script', 'style', 'td', 'template', 'th', 'tr']),\n tr: new Set(['form', 'input', 'script', 'style', 'td', 'template', 'th']),\n};\n\n/** True when a `<p>` is open in button scope in `open`, the tags above an element. */\nfunction paragraphOpen(open: readonly string[]): boolean {\n for (let index = open.length - 1; index >= 0; index--) {\n if (open[index] === 'p') {\n return true;\n }\n if (BUTTON_SCOPE.has(open[index]!)) {\n return false;\n }\n }\n return false;\n}\n\n/**\n * The tag in `open`, the tags above an element with the nearest last, that the HTML parser closes\n * or moves the element out of, or undefined. The rules come from the HTML spec and are the ones\n * that hold in every document. The parser keeps a document in standard mode, so the same\n * markup parses the same way everywhere.\n */\nexport function nestingProblem(open: readonly string[], tag: string): string | undefined {\n // Inside `<svg>` and `<math>` the parser follows other rules.\n if (open.includes('svg') || open.includes('math')) {\n return undefined;\n }\n const parent = open[open.length - 1];\n if (CLOSES_P.has(tag) && paragraphOpen(open)) {\n return 'p';\n }\n if (parent !== undefined) {\n // `<h1><h2>` closes the first heading. `<li><li>` and `<dd><dt>` close the item.\n if (HEADINGS.has(parent) && HEADINGS.has(tag)) {\n return parent;\n }\n if (parent === 'li' && tag === 'li') {\n return parent;\n }\n if ((parent === 'dd' || parent === 'dt') && (tag === 'dd' || tag === 'dt')) {\n return parent;\n }\n const allowed = TABLE_CHILDREN[parent];\n if (allowed && !allowed.has(tag)) {\n return parent;\n }\n }\n // `<a>` inside `<a>` splits the link. `<form>` inside `<form>` is dropped. `<button>` inside\n // `<button>` closes the first.\n if (tag === 'a') {\n for (let index = open.length - 1; index >= 0; index--) {\n if (open[index] === 'a') {\n return 'a';\n }\n if (LINK_MARKERS.has(open[index]!)) {\n break;\n }\n }\n }\n if (tag === 'form') {\n for (let index = open.length - 1; index >= 0; index--) {\n if (open[index] === 'form') {\n return 'form';\n }\n if (open[index] === 'template') {\n break;\n }\n }\n }\n if (tag === 'button') {\n for (let index = open.length - 1; index >= 0; index--) {\n if (open[index] === 'button') {\n return 'button';\n }\n if (BUTTON_SCOPE.has(open[index]!)) {\n break;\n }\n }\n }\n return undefined;\n}\n\n/** The message of BRM185. */\nexport function nestingMessage(tag: string, parent: string): string {\n return `<${tag}> cannot be inside <${parent}>: the HTML parser closes or moves it before the page runs. Move it out of the <${parent}>, or use a <span> or as=\"span\"`;\n}\n\n/** Walks the markup of a file, with the tags that are open above each node. */\nfunction walk(\n file: SFCFile,\n onElement: (tag: string, open: string[], node: Range) => void,\n onComponent: (node: ComponentNode, open: string[]) => void,\n): void {\n function body(content: Body | undefined, open: string[]): void {\n if (!content) {\n return;\n }\n for (const template of content.templates) {\n body(template.body, []);\n }\n nodes(content.children, open);\n }\n\n function nodes(list: Markup[], open: string[]): void {\n for (const node of list) {\n visit(node, open);\n }\n }\n\n function visit(node: Markup, open: string[]): void {\n switch (node.kind) {\n case 'element': {\n const tag = node.tag.toLowerCase();\n onElement(tag, open, node);\n open.push(tag);\n nodes(node.children, open);\n open.pop();\n return;\n }\n case 'component':\n onComponent(node, open);\n // Children render where the component puts them.\n nodes(node.children, []);\n return;\n case 'dynamic':\n // The tag is not known.\n nodes(node.children, []);\n return;\n case 'fragment':\n nodes(node.children, open);\n return;\n case 'if':\n for (const branch of node.branches) {\n body(branch.body, open);\n }\n body(node.fallback, open);\n return;\n case 'switch':\n for (const branch of node.cases) {\n body(branch.body, open);\n }\n body(node.fallback, open);\n return;\n case 'for':\n case 'repeat':\n case 'loading':\n case 'client':\n case 'defer':\n case 'try':\n body(node.body, open);\n body(node.fallback, open);\n return;\n case 'key':\n body(node.body, open);\n return;\n case 'portal':\n case 'head':\n case 'offscreen':\n // These render somewhere else, or in an element that is not known.\n body(node.body, []);\n return;\n default:\n return;\n }\n }\n\n for (const template of file.templates) {\n body(template.body, []);\n }\n nodes(file.children, []);\n}\n\n/** Reports each element that the HTML parser closes or moves, as BRM185. */\nexport function checkNesting(file: SFCFile, report: (message: string, at: Range) => void): void {\n walk(\n file,\n (tag, open, node) => {\n const parent = nestingProblem(open, tag);\n if (parent !== undefined) {\n report(nestingMessage(tag, parent), node);\n }\n },\n () => {},\n );\n}\n\n/** The components that sit inside a `<p>`, which the server checks in development. */\nexport function paragraphComponents(file: SFCFile): Set<ComponentNode> {\n const found = new Set<ComponentNode>();\n walk(\n file,\n () => {},\n (node, open) => {\n if (!open.includes('svg') && !open.includes('math') && paragraphOpen(open)) {\n found.add(node);\n }\n },\n );\n return found;\n}\n\n/** The tag that the HTML starts with, skipping comments, or undefined. */\nexport function firstTag(html: string): string | undefined {\n return /^(?:\\s|<!--[^>]*?-->)*<([a-z][a-z0-9-]*)/i.exec(html)?.[1]?.toLowerCase();\n}\n\n/** True when a start tag of `tag` closes an open `<p>`. */\nexport function closesParagraph(tag: string): boolean {\n return CLOSES_P.has(tag);\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { b as raw, t as Internal, y as ownValue } from "./html-BtKRyi7g.js";
|
|
2
|
+
import { i as HAS_CHILDREN, n as HAS_BINDINGS } from "./features-CHY5Ekku.js";
|
|
3
|
+
//#region src/runtime/shared.ts
|
|
4
|
+
/** The plugins of values of the app, by tag, which the entry `src/serial.ts` exports. */
|
|
5
|
+
const valuePlugins = /* @__PURE__ */ new Map();
|
|
6
|
+
const pluginListeners = [];
|
|
7
|
+
/** The options of the entry, which the serializer reads when it loads. */
|
|
8
|
+
let entryOptions = {};
|
|
9
|
+
const optionListeners = [];
|
|
10
|
+
/**
|
|
11
|
+
* Takes the exports of the serial entry: its plugins and the options that it
|
|
12
|
+
* changes. The server and the loader call it before the first value is
|
|
13
|
+
* written or read.
|
|
14
|
+
*/
|
|
15
|
+
function useSerialEntry(entry) {
|
|
16
|
+
const { plugins = [], ...options } = entry;
|
|
17
|
+
if (options.disabledFeatures !== void 0 || options.depthLimit !== void 0) {
|
|
18
|
+
entryOptions = options;
|
|
19
|
+
for (const listener of optionListeners) listener(options);
|
|
20
|
+
}
|
|
21
|
+
registerValues(plugins);
|
|
22
|
+
}
|
|
23
|
+
/** Calls `listener` with the options of the entry, now and when they change. */
|
|
24
|
+
function onSerialOptions(listener) {
|
|
25
|
+
optionListeners.push(listener);
|
|
26
|
+
listener(entryOptions);
|
|
27
|
+
}
|
|
28
|
+
/** Adds plugins of values of the app. */
|
|
29
|
+
function registerValues(plugins) {
|
|
30
|
+
for (const plugin of plugins) {
|
|
31
|
+
if (valuePlugins.get(plugin.tag) === plugin) continue;
|
|
32
|
+
valuePlugins.set(plugin.tag, plugin);
|
|
33
|
+
for (const listener of pluginListeners) listener(plugin);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Calls `listener` for each plugin of the app, those added so far and those added later. */
|
|
37
|
+
function onValuePlugin(listener) {
|
|
38
|
+
pluginListeners.push(listener);
|
|
39
|
+
for (const plugin of valuePlugins.values()) listener(plugin);
|
|
40
|
+
}
|
|
41
|
+
/** Reads a scope or boundary ID from markup. */
|
|
42
|
+
function parseId(text) {
|
|
43
|
+
return /^-?\d+$/.test(text) ? Number(text) : text;
|
|
44
|
+
}
|
|
45
|
+
/** An element that the server rendered. The client finds it by its anchor. */
|
|
46
|
+
var ElementReference = class {
|
|
47
|
+
scope;
|
|
48
|
+
anchor;
|
|
49
|
+
constructor(scope, anchor) {
|
|
50
|
+
this.scope = scope;
|
|
51
|
+
this.anchor = anchor;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/** A client function: an export of a client module, and the scope it reads. */
|
|
55
|
+
/** The key of the reference of children on the server, which the page state sends. */
|
|
56
|
+
const CHILDREN_REF = Symbol.for("brumate.children");
|
|
57
|
+
/**
|
|
58
|
+
* The children of a component in the page state: the export that renders them in the browser,
|
|
59
|
+
* such as `Page_1a2b#n0`, and the scope that they were written in. Each insert renders them
|
|
60
|
+
* again, with new scopes, as the body of a block does.
|
|
61
|
+
*/
|
|
62
|
+
var ChildrenReference = class {
|
|
63
|
+
ref;
|
|
64
|
+
scope;
|
|
65
|
+
/** The scope and the anchor of the insert where the server rendered them, if it did. */
|
|
66
|
+
at;
|
|
67
|
+
anchor;
|
|
68
|
+
constructor(ref, scope, at, anchor) {
|
|
69
|
+
this.ref = ref;
|
|
70
|
+
this.scope = scope;
|
|
71
|
+
this.at = at;
|
|
72
|
+
this.anchor = anchor;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var FunctionReference = class {
|
|
76
|
+
/** `<component id>#<export name>`. */
|
|
77
|
+
ref;
|
|
78
|
+
scope;
|
|
79
|
+
/** The arguments of a handler that `$handler` made, which come before the event. */
|
|
80
|
+
args;
|
|
81
|
+
/** The modifiers of the wrappers of a handler, such as `prevent`, for the `b-on` of a spread. */
|
|
82
|
+
modifiers;
|
|
83
|
+
constructor(ref, scope, args, modifiers) {
|
|
84
|
+
this.ref = ref;
|
|
85
|
+
this.scope = scope;
|
|
86
|
+
this.args = args ?? void 0;
|
|
87
|
+
this.modifiers = modifiers;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
/** The handlers that a merged handler calls, in order. A symbol of the registry. */
|
|
91
|
+
const PARTS = Symbol.for("brumate.parts");
|
|
92
|
+
/**
|
|
93
|
+
* One handler that calls each of `handlers` in order, with the same arguments. A prop holds one
|
|
94
|
+
* handler per event, and the browser takes one `b-on` entry for each part. Merged handlers in
|
|
95
|
+
* `handlers` give their parts, so the list stays flat.
|
|
96
|
+
*/
|
|
97
|
+
function mergeHandlers(handlers) {
|
|
98
|
+
const parts = [];
|
|
99
|
+
for (const handler of handlers) parts.push(...handler[PARTS] ?? [handler]);
|
|
100
|
+
return Object.assign((...args) => {
|
|
101
|
+
for (const part of parts) part(...args);
|
|
102
|
+
}, { [PARTS]: parts });
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Adds a handler prop, such as `onClick`, for each entry of the scoped `b-on` of a dynamic tag
|
|
106
|
+
* that names a component. `make` makes the handler of a reference. A handler of the same event in
|
|
107
|
+
* `props`, such as a rest prop passed on, is merged with it and runs first.
|
|
108
|
+
*/
|
|
109
|
+
function addEntryHandlers(props, entries, scope, make) {
|
|
110
|
+
for (const entry of ownValue("b-on", entries)?.split(" ") ?? []) {
|
|
111
|
+
const [event, target] = entry.split("=");
|
|
112
|
+
const [name, ...modifiers] = event.split(":");
|
|
113
|
+
const [ref, at] = target.split("@");
|
|
114
|
+
const handler = make(new FunctionReference(ref, /^\d+$/.test(at ?? "") ? Number(at) : at ?? scope, void 0, modifiers.length > 0 ? modifiers : void 0));
|
|
115
|
+
const key = `on${name[0].toUpperCase()}${name.slice(1)}`;
|
|
116
|
+
const before = props[key];
|
|
117
|
+
props[key] = typeof before === "function" ? mergeHandlers([before, handler]) : handler;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const BINDING = Symbol.for("brumate.binding");
|
|
121
|
+
const SLOT = Symbol.for("brumate.slot");
|
|
122
|
+
/** A slot of a scope, which a write of a bound prop goes to. */
|
|
123
|
+
var SlotReference = class {
|
|
124
|
+
scope;
|
|
125
|
+
slot;
|
|
126
|
+
constructor(scope, slot) {
|
|
127
|
+
this.scope = scope;
|
|
128
|
+
this.slot = slot;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
SlotReference.prototype[SLOT] = true;
|
|
132
|
+
/** True for a slot reference of any copy of the runtime. */
|
|
133
|
+
function isSlotReference(value) {
|
|
134
|
+
return typeof value === "object" && value !== null && SLOT in value;
|
|
135
|
+
}
|
|
136
|
+
/** True for a binding of any copy of the runtime. */
|
|
137
|
+
function isBinding(value) {
|
|
138
|
+
return typeof value === "object" && value !== null && BINDING in value;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* What `$bind(name)` passes a child: the value of the name, and its slot,
|
|
142
|
+
* which the child's writes of the prop go to.
|
|
143
|
+
*/
|
|
144
|
+
var Binding = class {
|
|
145
|
+
value;
|
|
146
|
+
ref;
|
|
147
|
+
/** The function of `$bind(name, fn)`, which a write calls in place of writing the slot. */
|
|
148
|
+
set;
|
|
149
|
+
constructor(value, ref, set) {
|
|
150
|
+
this.value = value;
|
|
151
|
+
this.ref = ref;
|
|
152
|
+
this.set = set;
|
|
153
|
+
}
|
|
154
|
+
/** What a write of the bound prop goes to: the setter, or else the slot. */
|
|
155
|
+
get target() {
|
|
156
|
+
return this.set ?? this.ref;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
Binding.prototype[BINDING] = true;
|
|
160
|
+
/**
|
|
161
|
+
* The props that a component destructures, with the values of their
|
|
162
|
+
* bindings. `names` are the props that it destructures by name: the others,
|
|
163
|
+
* which a rest prop holds, keep their bindings, so a spread passes them on.
|
|
164
|
+
* Without `names`, every binding gives its value. `omit` are props that a rest
|
|
165
|
+
* leaves out, because another `$props()` call of the component names them.
|
|
166
|
+
*/
|
|
167
|
+
function unbind(props, names, omit, sink) {
|
|
168
|
+
let result;
|
|
169
|
+
if (omit) {
|
|
170
|
+
result = { ...props };
|
|
171
|
+
for (const key of omit) delete result[key];
|
|
172
|
+
props = result;
|
|
173
|
+
}
|
|
174
|
+
for (const key of names ?? Object.keys(props)) {
|
|
175
|
+
const value = props[key];
|
|
176
|
+
if (sink && value instanceof Promise) (sink.props ??= []).push(value);
|
|
177
|
+
if (isBinding(value)) {
|
|
178
|
+
result ??= { ...props };
|
|
179
|
+
result[key] = value.value;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return result ?? props;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* What the slot of a memo holds while its compute throws or its promise rejects, and a memo that
|
|
186
|
+
* failed on the server holds from the page state. Each read of the slot throws the error.
|
|
187
|
+
*/
|
|
188
|
+
var MemoError = class {
|
|
189
|
+
error;
|
|
190
|
+
constructor(error) {
|
|
191
|
+
this.error = error;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* A promise that a parent passed as a prop. It stays a promise in the child, so `await` and
|
|
196
|
+
* `then` work on it. The page state holds it in this wrapper, so the browser knows the slot is
|
|
197
|
+
* a prop and does not replace the promise with its value, as it does for a memo that streams.
|
|
198
|
+
*/
|
|
199
|
+
var PropPromise = class {
|
|
200
|
+
promise;
|
|
201
|
+
constructor(promise) {
|
|
202
|
+
this.promise = promise;
|
|
203
|
+
this[PROP_WRAPPER] = true;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const PROP_WRAPPER = Symbol.for("brumate.propWrapper");
|
|
207
|
+
/** True for the wrapper that holds a promise prop in the page state. */
|
|
208
|
+
function isPropWrapper(value) {
|
|
209
|
+
return typeof value === "object" && value !== null && PROP_WRAPPER in value;
|
|
210
|
+
}
|
|
211
|
+
/** The value of a feature that the build turned off, which no page state of it holds. */
|
|
212
|
+
function unused() {
|
|
213
|
+
throw new Error("The page state holds a value of a feature that no component of the build uses");
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Makes the values of brumate's plugins. A state record calls them as `$b`,
|
|
217
|
+
* with one letter each, and the plugins read nodes of server function calls
|
|
218
|
+
* with them too, so both give the same values.
|
|
219
|
+
*/
|
|
220
|
+
const stateValues = {
|
|
221
|
+
e: (scope, anchor) => new ElementReference(scope, anchor),
|
|
222
|
+
f: (ref, scope, args, modifiers) => new FunctionReference(ref, scope, args, modifiers),
|
|
223
|
+
m: (parts) => Object.assign(parts, { [PARTS]: parts }),
|
|
224
|
+
i: (value) => new Internal(value),
|
|
225
|
+
r: raw,
|
|
226
|
+
n: HAS_CHILDREN ? (ref, scope, at, anchor) => new ChildrenReference(ref, scope, at, anchor) : unused,
|
|
227
|
+
c: (id) => Object.assign(() => "", { brumateId: id }),
|
|
228
|
+
l: (scope, slot) => new SlotReference(scope, slot),
|
|
229
|
+
b: HAS_BINDINGS ? (value, scope, slot, set) => new Binding(value, new SlotReference(scope, slot), set) : unused,
|
|
230
|
+
q: (promise) => new PropPromise(promise),
|
|
231
|
+
x: (error) => new MemoError(error),
|
|
232
|
+
u: (tag, data) => {
|
|
233
|
+
const plugin = valuePlugins.get(tag);
|
|
234
|
+
if (!plugin) throw new Error(`No plugin reads the value "${tag}". Export it in the plugins of the serial entry, src/serial.ts`);
|
|
235
|
+
return plugin.fromData(data);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
/** True for a value that `for await` reads, such as the result of an async generator. */
|
|
239
|
+
function isAsyncIterable(value) {
|
|
240
|
+
return value !== null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function";
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* A table of the fields of a state record and the reference classes that hold
|
|
244
|
+
* a scope ID, which each keep it in `scope`. Code that moves the IDs reads it.
|
|
245
|
+
* A new field of `ScopeState` fails to compile until it is in `fields`, and
|
|
246
|
+
* `holders` are the classes that keep references in their own fields, such as
|
|
247
|
+
* `Binding`, whose `ref` and `set` hold IDs. `scope-ids.test.ts` parses this
|
|
248
|
+
* file and fails for any class in it, of any shape, that is not in
|
|
249
|
+
* `references` or `holders` or in the test's list of classes without IDs.
|
|
250
|
+
* It checks class names only, so a person decides which list a new class
|
|
251
|
+
* belongs in.
|
|
252
|
+
*/
|
|
253
|
+
const SCOPE_IDS = {
|
|
254
|
+
fields: {
|
|
255
|
+
k: "none",
|
|
256
|
+
p: "id",
|
|
257
|
+
m: "none",
|
|
258
|
+
i: "value",
|
|
259
|
+
o: "id",
|
|
260
|
+
t: "id",
|
|
261
|
+
f: "id",
|
|
262
|
+
v: "map",
|
|
263
|
+
x: "none",
|
|
264
|
+
s: "values",
|
|
265
|
+
c: "ids",
|
|
266
|
+
b: "map"
|
|
267
|
+
},
|
|
268
|
+
references: [
|
|
269
|
+
ElementReference,
|
|
270
|
+
FunctionReference,
|
|
271
|
+
ChildrenReference,
|
|
272
|
+
SlotReference
|
|
273
|
+
],
|
|
274
|
+
holders: [Binding]
|
|
275
|
+
};
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/runtime/produce.ts
|
|
278
|
+
const DRAFT = Symbol("brumate.draft");
|
|
279
|
+
/** Plain objects and arrays can be drafted. Other values, such as `Map`, are used as they are. */
|
|
280
|
+
function isDraftable(value) {
|
|
281
|
+
if (typeof value !== "object" || value === null) return false;
|
|
282
|
+
if (Array.isArray(value)) return true;
|
|
283
|
+
const prototype = Object.getPrototypeOf(value);
|
|
284
|
+
return prototype === Object.prototype || prototype === null;
|
|
285
|
+
}
|
|
286
|
+
function latest(state) {
|
|
287
|
+
return state.copy ?? state.base;
|
|
288
|
+
}
|
|
289
|
+
/** Copies an object and its parents on the first change. */
|
|
290
|
+
function prepare(state) {
|
|
291
|
+
for (let current = state; current && !current.modified; current = current.parent) {
|
|
292
|
+
current.modified = true;
|
|
293
|
+
current.copy = Array.isArray(current.base) ? [...current.base] : { ...current.base };
|
|
294
|
+
}
|
|
295
|
+
return state.copy;
|
|
296
|
+
}
|
|
297
|
+
function getDraftState(value) {
|
|
298
|
+
return typeof value === "object" && value !== null ? value[DRAFT] : void 0;
|
|
299
|
+
}
|
|
300
|
+
function createDraft(base, parent) {
|
|
301
|
+
const state = {
|
|
302
|
+
base,
|
|
303
|
+
copy: void 0,
|
|
304
|
+
parent,
|
|
305
|
+
children: /* @__PURE__ */ new Map(),
|
|
306
|
+
modified: false
|
|
307
|
+
};
|
|
308
|
+
const target = Array.isArray(base) ? [] : Object.create(Object.getPrototypeOf(base));
|
|
309
|
+
state.proxy = new Proxy(target, {
|
|
310
|
+
get(_, key) {
|
|
311
|
+
if (key === DRAFT) return state;
|
|
312
|
+
const source = latest(state);
|
|
313
|
+
const value = source[key];
|
|
314
|
+
if (!Object.hasOwn(source, key) || !isDraftable(value) || value !== state.base[key]) return value;
|
|
315
|
+
let child = state.children.get(key);
|
|
316
|
+
if (!child) {
|
|
317
|
+
child = createDraft(value, state);
|
|
318
|
+
state.children.set(key, child);
|
|
319
|
+
}
|
|
320
|
+
return child.proxy;
|
|
321
|
+
},
|
|
322
|
+
set(_, key, value) {
|
|
323
|
+
const source = latest(state);
|
|
324
|
+
if (Object.is(source[key], value) && Object.hasOwn(source, key)) return true;
|
|
325
|
+
prepare(state)[key] = value;
|
|
326
|
+
state.children.delete(key);
|
|
327
|
+
return true;
|
|
328
|
+
},
|
|
329
|
+
deleteProperty(_, key) {
|
|
330
|
+
if (Object.hasOwn(latest(state), key)) {
|
|
331
|
+
delete prepare(state)[key];
|
|
332
|
+
state.children.delete(key);
|
|
333
|
+
}
|
|
334
|
+
return true;
|
|
335
|
+
},
|
|
336
|
+
has(_, key) {
|
|
337
|
+
return key in latest(state);
|
|
338
|
+
},
|
|
339
|
+
ownKeys() {
|
|
340
|
+
return Reflect.ownKeys(latest(state));
|
|
341
|
+
},
|
|
342
|
+
getOwnPropertyDescriptor(_, key) {
|
|
343
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(latest(state), key);
|
|
344
|
+
if (descriptor && key !== "length") {
|
|
345
|
+
descriptor.configurable = true;
|
|
346
|
+
descriptor.writable = true;
|
|
347
|
+
}
|
|
348
|
+
return descriptor;
|
|
349
|
+
},
|
|
350
|
+
defineProperty(_, key, descriptor) {
|
|
351
|
+
prepare(state);
|
|
352
|
+
return Reflect.defineProperty(state.copy, key, descriptor);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
return state;
|
|
356
|
+
}
|
|
357
|
+
/** Returns the final value of a draft: the base if nothing changed, or a new object that shares what did not. */
|
|
358
|
+
function finalize(state) {
|
|
359
|
+
if (!state.modified) {
|
|
360
|
+
for (const child of state.children.values()) if (child.modified) {
|
|
361
|
+
prepare(state);
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
if (!state.modified) return state.base;
|
|
365
|
+
}
|
|
366
|
+
const copy = state.copy;
|
|
367
|
+
for (const [key, child] of state.children) if (copy[key] === child.base) copy[key] = finalize(child);
|
|
368
|
+
for (const key of Reflect.ownKeys(copy)) {
|
|
369
|
+
const draft = getDraftState(copy[key]);
|
|
370
|
+
if (draft) copy[key] = finalize(draft);
|
|
371
|
+
}
|
|
372
|
+
return copy;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Returns a changed copy of a value. The recipe changes a draft as if it
|
|
376
|
+
* were the value. Objects that it does not change keep their identity, and
|
|
377
|
+
* if it changes nothing, the value itself is returned. A recipe can also
|
|
378
|
+
* return a new value. Only plain objects and arrays are drafted.
|
|
379
|
+
*/
|
|
380
|
+
function produce(base, recipe) {
|
|
381
|
+
if (!isDraftable(base)) {
|
|
382
|
+
const result = recipe(base);
|
|
383
|
+
return result === void 0 ? base : result;
|
|
384
|
+
}
|
|
385
|
+
const state = createDraft(base, void 0);
|
|
386
|
+
const result = recipe(state.proxy);
|
|
387
|
+
if (result !== void 0 && result !== state.proxy) return resolve(result, /* @__PURE__ */ new Set());
|
|
388
|
+
return finalize(state);
|
|
389
|
+
}
|
|
390
|
+
/** Replaces the drafts in a value that a recipe returns, such as the result of `draft.filter(…)`. */
|
|
391
|
+
function resolve(value, seen) {
|
|
392
|
+
const draft = getDraftState(value);
|
|
393
|
+
if (draft) return finalize(draft);
|
|
394
|
+
if (!isDraftable(value) || seen.has(value)) return value;
|
|
395
|
+
seen.add(value);
|
|
396
|
+
for (const key of Reflect.ownKeys(value)) value[key] = resolve(value[key], seen);
|
|
397
|
+
return value;
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
export { useSerialEntry as C, unbind as S, mergeHandlers as _, ElementReference as a, parseId as b, PARTS as c, SlotReference as d, addEntryHandlers as f, isSlotReference as g, isPropWrapper as h, ChildrenReference as i, PropPromise as l, isBinding as m, Binding as n, FunctionReference as o, isAsyncIterable as p, CHILDREN_REF as r, MemoError as s, produce as t, SCOPE_IDS as u, onSerialOptions as v, stateValues as x, onValuePlugin as y };
|
|
401
|
+
|
|
402
|
+
//# sourceMappingURL=produce-B7X9ori9.js.map
|