ferrovue 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +201 -50
  2. package/dist/attrs.d.ts +2 -1
  3. package/dist/attrs.js +7 -4
  4. package/dist/children.d.ts +2 -2
  5. package/dist/children.js +66 -13
  6. package/dist/classes.d.ts +4 -0
  7. package/dist/classes.js +23 -1
  8. package/dist/client.d.ts +9 -4
  9. package/dist/client.js +106 -17
  10. package/dist/compiler.d.ts +1 -1
  11. package/dist/compiler.js +38 -10
  12. package/dist/component.d.ts +1 -1
  13. package/dist/component.js +2 -3
  14. package/dist/conformance.d.ts +64 -0
  15. package/dist/conformance.js +276 -0
  16. package/dist/context.d.ts +15 -6
  17. package/dist/context.js +3 -0
  18. package/dist/dynamic.d.ts +18 -0
  19. package/dist/dynamic.js +576 -0
  20. package/dist/errors.d.ts +168 -1
  21. package/dist/errors.js +96 -1
  22. package/dist/file-routes.d.ts +33 -0
  23. package/dist/file-routes.js +224 -0
  24. package/dist/fixture.d.ts +16 -0
  25. package/dist/fixture.js +22 -7
  26. package/dist/index.d.ts +1 -1
  27. package/dist/link-router.d.ts +1 -1
  28. package/dist/link-router.js +1 -0
  29. package/dist/lists.d.ts +4 -0
  30. package/dist/lists.js +2 -2
  31. package/dist/loops.js +4 -4
  32. package/dist/model.d.ts +11 -0
  33. package/dist/model.js +44 -1
  34. package/dist/numbers.js +3 -2
  35. package/dist/page-routes.d.ts +9 -0
  36. package/dist/page-routes.js +10 -0
  37. package/dist/plugin.d.ts +13 -1
  38. package/dist/plugin.js +3 -0
  39. package/dist/plugins/client-only.js +3 -0
  40. package/dist/plugins/head.d.ts +15 -0
  41. package/dist/plugins/head.js +385 -0
  42. package/dist/plugins/index.js +3 -1
  43. package/dist/plugins/provide.d.ts +44 -0
  44. package/dist/plugins/provide.js +528 -0
  45. package/dist/plugins/router-link.js +7 -3
  46. package/dist/plugins/router.d.ts +4 -1
  47. package/dist/plugins/router.js +56 -10
  48. package/dist/plugins/stores.js +19 -9
  49. package/dist/routes.d.ts +5 -2
  50. package/dist/routes.js +8 -2
  51. package/dist/rust.js +46 -18
  52. package/dist/script.js +19 -3
  53. package/dist/settle.d.ts +2 -0
  54. package/dist/settle.js +5 -0
  55. package/dist/slots.js +18 -4
  56. package/dist/ssr.d.ts +3 -0
  57. package/dist/ssr.js +29 -0
  58. package/dist/strings.d.ts +3 -0
  59. package/dist/strings.js +16 -2
  60. package/dist/template.js +92 -11
  61. package/dist/testing.d.ts +2 -3
  62. package/dist/testing.js +2 -29
  63. package/dist/types.d.ts +5 -0
  64. package/dist/typescript.js +7 -3
  65. package/dist/vhtml.d.ts +4 -0
  66. package/dist/vhtml.js +63 -0
  67. package/dist/vite.d.ts +7 -1
  68. package/dist/vite.js +65 -5
  69. package/package.json +15 -1
@@ -0,0 +1,385 @@
1
+ import { absence, fail, rustStr } from "../model.js";
2
+ import { describeTy, expr } from "../expr.js";
3
+ import { arrow, items } from "../lists.js";
4
+ import { bare, strArg } from "../parens.js";
5
+ import { runOf, scopeOf } from "../plugin.js";
6
+ const COMPOSABLES = {
7
+ useHead: "head",
8
+ useServerHead: "head",
9
+ useSeoMeta: "seo",
10
+ useServerSeoMeta: "seo",
11
+ useHeadSafe: "safe",
12
+ useServerHeadSafe: "safe",
13
+ };
14
+ const TAG_LISTS = new Set(["meta", "link", "script", "style", "noscript"]);
15
+ const ATTR_OBJECTS = new Set(["htmlAttrs", "bodyAttrs", "base"]);
16
+ const WITH_CONTENT = new Set(["script", "style", "noscript"]);
17
+ const POSITIONS = new Set(["head", "bodyClose", "bodyOpen"]);
18
+ const PRIORITIES = new Set(["critical", "high", "low"]);
19
+ const STRATEGIES = new Set(["replace", "merge"]);
20
+ const OBJECT_KEYS = new Set(Object.getOwnPropertyNames(Object.prototype));
21
+ const META_NAMESPACES = ["twitter", "fediverse"];
22
+ const PROPERTY_NAMESPACES = ["og", "book", "article", "profile", "fb", "payment"];
23
+ const HTTP_EQUIV_KEYS = new Set(["contentType", "defaultStyle", "xUaCompatible", "refresh", "contentSecurityPolicy"]);
24
+ const META_ALIASES = {
25
+ articleExpirationTime: "article:expiration_time",
26
+ articleModifiedTime: "article:modified_time",
27
+ articlePublishedTime: "article:published_time",
28
+ bookReleaseDate: "book:release_date",
29
+ fbAppId: "fb:app_id",
30
+ ogAudioSecureUrl: "og:audio:secure_url",
31
+ ogAudioUrl: "og:audio",
32
+ ogImageSecureUrl: "og:image:secure_url",
33
+ ogImageUrl: "og:image",
34
+ ogSiteName: "og:site_name",
35
+ ogVideoSecureUrl: "og:video:secure_url",
36
+ ogVideoUrl: "og:video",
37
+ paymentExpiresAt: "payment:expires_at",
38
+ paymentSuccessUrl: "payment:success_url",
39
+ profileFirstName: "profile:first_name",
40
+ profileLastName: "profile:last_name",
41
+ profileUsername: "profile:username",
42
+ msapplicationConfig: "msapplication-Config",
43
+ msapplicationTileColor: "msapplication-TileColor",
44
+ msapplicationTileImage: "msapplication-TileImage",
45
+ };
46
+ function fixKeyCase(key) {
47
+ const updated = key.replace(/([A-Z])/g, "-$1").toLowerCase();
48
+ const prefix = updated.indexOf("-");
49
+ if (prefix === -1)
50
+ return updated;
51
+ const ns = updated.slice(0, prefix);
52
+ return META_NAMESPACES.includes(ns) || PROPERTY_NAMESPACES.includes(ns) ? key.replace(/([A-Z])/g, ":$1").toLowerCase() : updated;
53
+ }
54
+ /** The meta tag `useSeoMeta` writes for a key with a string value: the attribute it sets, and the
55
+ * name it gives (`ogTitle` is `property="og:title"`). */
56
+ export function seoMetaKey(key) {
57
+ if (key === "charset")
58
+ return ["charset", ""];
59
+ const name = Object.hasOwn(META_ALIASES, key) ? META_ALIASES[key] : fixKeyCase(key);
60
+ if (HTTP_EQUIV_KEYS.has(key))
61
+ return ["http-equiv", name];
62
+ const fixed = fixKeyCase(key);
63
+ const colon = fixed.indexOf(":");
64
+ return [colon !== -1 && PROPERTY_NAMESPACES.includes(fixed.slice(0, colon)) ? "property" : "name", name];
65
+ }
66
+ function keyOf(comp, p) {
67
+ if (p.type !== "ObjectProperty" || p.computed) {
68
+ fail(comp, "FV1704", "a head input is an object literal of plain keys and values: no spread, computed key or method", p);
69
+ }
70
+ const key = p.key.type === "Identifier" ? p.key.name : p.key.type === "StringLiteral" ? p.key.value : String(p.key.value);
71
+ if (key === "__proto__")
72
+ fail(comp, "FV1704", "`__proto__` sets an object's prototype in JavaScript, and is not a key of the head", p);
73
+ return key;
74
+ }
75
+ function getter(s, n) {
76
+ if (n?.type === "ArrowFunctionExpression" || n?.type === "FunctionExpression") {
77
+ const body = n.body?.type === "BlockStatement" ? (n.body.body.length === 1 && n.body.body[0].type === "ReturnStatement" ? n.body.body[0].argument : null) : n.body;
78
+ if (n.params.length || n.async || n.generator || !body) {
79
+ fail(s.comp, "FV1705", "a function in a head input is a getter of its value, `() => props.title`, which the server calls; one taking arguments runs only on the client", n);
80
+ }
81
+ return getter(s, body);
82
+ }
83
+ if (n?.type === "TSAsExpression" || n?.type === "TSSatisfiesExpression")
84
+ return getter(s, n.expression);
85
+ return n;
86
+ }
87
+ function scalar(s, v, n, where) {
88
+ switch (v.ty.k) {
89
+ case "str":
90
+ return `fv::HeadValue::str(${strArg(v.code)})`;
91
+ case "int":
92
+ return `fv::HeadValue::int(${bare(v.code)})`;
93
+ case "float":
94
+ return `fv::HeadValue::float(${bare(v.code)})`;
95
+ case "bool":
96
+ return `fv::HeadValue::bool(${bare(v.code)})`;
97
+ case "undef":
98
+ return "fv::HeadValue::Undefined";
99
+ case "null":
100
+ return "fv::HeadValue::Null";
101
+ case "opt": {
102
+ const none = absence(v.ty);
103
+ if (none === "either")
104
+ fail(s.comp, "FV1706", `${where} may be \`undefined\` or \`null\`, which unhead treats apart and its Rust type cannot tell apart`, n);
105
+ return `if let Some(v) = ${v.code} { ${scalar(s, { code: "v", ty: v.ty.of }, n, where)} } else { fv::HeadValue::${none === "null" ? "Null" : "Undefined"} }`;
106
+ }
107
+ default:
108
+ return fail(s.comp, "FV1706", `${where} is ${describeTy(v.ty)}: a head value here is a string, a number or a boolean`, n);
109
+ }
110
+ }
111
+ function value(s, raw, where, lists) {
112
+ const n = getter(s, raw);
113
+ const v = expr(s, n);
114
+ if (v.ty.k === "list" && lists) {
115
+ const of = v.ty.of;
116
+ const each = scalar(s, { code: of.k === "str" ? "&*v" : "v", ty: of }, n, `an item of ${where}`);
117
+ return `fv::HeadValue::Array(${items(v)}.map(|v| ${each}).collect())`;
118
+ }
119
+ return scalar(s, v, n, where);
120
+ }
121
+ function objectOf(entries) {
122
+ return entries.length ? `fv::HeadValue::object([${entries.join(", ")}])` : "fv::HeadValue::Object(Vec::new())";
123
+ }
124
+ function object(s, raw, where, field) {
125
+ const n = getter(s, raw);
126
+ if (n?.type !== "ObjectExpression")
127
+ fail(s.comp, "FV1706", `${where} is an object literal`, n ?? raw);
128
+ return objectOf(n.properties.map((p) => {
129
+ const key = keyOf(s.comp, p);
130
+ return `(${rustStr(key)}, ${field(key, p.value, p)})`;
131
+ }));
132
+ }
133
+ function floatLiteral(x) {
134
+ const spelled = String(x).replace("e+", "e");
135
+ return `${/[.e]/.test(spelled) ? spelled : `${spelled}.0`}_f64`;
136
+ }
137
+ function literal(s, n, allowed, key) {
138
+ const v = getter(s, n);
139
+ if (allowed === "number") {
140
+ if (v?.type === "NumericLiteral")
141
+ return `fv::HeadValue::Number(${floatLiteral(v.value)})`;
142
+ if (v?.type === "UnaryExpression" && v.operator === "-" && v.argument.type === "NumericLiteral")
143
+ return `fv::HeadValue::Number(-${floatLiteral(v.argument.value)})`;
144
+ if (v?.type === "StringLiteral" && PRIORITIES.has(v.value))
145
+ return `fv::HeadValue::str(${rustStr(v.value)})`;
146
+ return fail(s.comp, "FV1707", `\`${key}\` is a number literal or one of ${[...PRIORITIES].map((p) => `"${p}"`).join(", ")}`, v ?? n);
147
+ }
148
+ if (v?.type !== "StringLiteral" || !allowed.has(v.value))
149
+ fail(s.comp, "FV1707", `\`${key}\` is one of ${[...allowed].map((p) => `"${p}"`).join(", ")}, written as a literal`, v ?? n);
150
+ return `fv::HeadValue::str(${rustStr(v.value)})`;
151
+ }
152
+ function json(s, raw, where) {
153
+ const n = getter(s, raw);
154
+ if (n?.type === "ObjectExpression")
155
+ return object(s, n, where, (_key, v) => json(s, v, where));
156
+ if (n?.type === "ArrayExpression") {
157
+ const parts = n.elements.map((el) => {
158
+ if (!el || el.type === "SpreadElement")
159
+ fail(s.comp, "FV1704", "an array in a head input holds plain values: no hole or spread", n);
160
+ return json(s, el, where);
161
+ });
162
+ return `fv::HeadValue::array([${parts.join(", ")}])`;
163
+ }
164
+ return value(s, n, where, true);
165
+ }
166
+ function tagObject(s, tag, raw) {
167
+ return object(s, raw, `a \`${tag}\` entry`, (key, v, p) => {
168
+ if (key === "key")
169
+ return value(s, v, "`key`", false);
170
+ if (key === "tagPosition")
171
+ return literal(s, v, POSITIONS, key);
172
+ if (key === "tagPriority")
173
+ return literal(s, v, "number", key);
174
+ if (key === "tagDuplicateStrategy")
175
+ return literal(s, v, STRATEGIES, key);
176
+ if (key === "processTemplateParams")
177
+ return fail(s.comp, "FV1703", "`processTemplateParams` needs unhead's template params plugin, which ferrovue does not reproduce", p);
178
+ if (key === "innerHTML" || key === "textContent") {
179
+ if (!WITH_CONTENT.has(tag))
180
+ fail(s.comp, "FV1711", `\`${key}\` on a \`${tag}\`, which has no content: only \`script\`, \`style\` and \`noscript\` take it`, p);
181
+ return tag === "script" ? json(s, v, `\`${key}\``) : value(s, v, `\`${key}\``, false);
182
+ }
183
+ if (key.startsWith("on") && (v.type === "ArrowFunctionExpression" || v.type === "FunctionExpression")) {
184
+ fail(s.comp, "FV1705", `\`${key}\` is an event handler, which runs only on the client`, p);
185
+ }
186
+ if (key === "class" || key === "style")
187
+ return classOrStyle(s, key, v);
188
+ return value(s, v, `\`${key}\``, tag === "meta" && key === "content");
189
+ });
190
+ }
191
+ function classOrStyle(s, key, raw) {
192
+ const n = getter(s, raw);
193
+ const where = `\`${key}\``;
194
+ if (n?.type === "ObjectExpression")
195
+ return object(s, n, where, (_k, v) => value(s, v, `a value of ${where}`, false));
196
+ if (n?.type === "ArrayExpression") {
197
+ const parts = n.elements.map((el) => {
198
+ if (!el || el.type === "SpreadElement")
199
+ fail(s.comp, "FV1704", "an array in a head input holds plain values: no hole or spread", n);
200
+ return strict(s, el, `an item of ${where}`);
201
+ });
202
+ return `fv::HeadValue::array([${parts.join(", ")}])`;
203
+ }
204
+ const v = expr(s, n);
205
+ if (absence(v.ty) === "null" || absence(v.ty) === "either")
206
+ fail(s.comp, "FV1710", `${where} may be \`null\`, on which unhead's renderer throws; write \`?? undefined\``, n);
207
+ if (v.ty.k === "list" && (v.ty.of.k === "str"))
208
+ return `fv::HeadValue::Array(${items(v)}.map(|v| fv::HeadValue::str(&*v)).collect())`;
209
+ if (v.ty.k !== "str" && !(v.ty.k === "opt" && v.ty.of.k === "str") && v.ty.k !== "undef")
210
+ fail(s.comp, "FV1706", `${where} is a string, a list of strings or an object literal`, n);
211
+ return scalar(s, v, n, where);
212
+ }
213
+ function strict(s, raw, where) {
214
+ const n = getter(s, raw);
215
+ const v = expr(s, n);
216
+ if (v.ty.k !== "str")
217
+ fail(s.comp, "FV1706", `${where} is a string`, n);
218
+ return scalar(s, v, n, where);
219
+ }
220
+ function tagList(s, tag, raw) {
221
+ const n = getter(s, raw);
222
+ if (n?.type === "ObjectExpression")
223
+ return tagObject(s, tag, n);
224
+ if (n?.type === "ArrayExpression") {
225
+ const parts = n.elements.map((el) => {
226
+ if (!el || el.type === "SpreadElement")
227
+ fail(s.comp, "FV1704", "an array in a head input holds plain values: no hole or spread", n);
228
+ return tagObject(s, tag, el);
229
+ });
230
+ return `fv::HeadValue::array([${parts.join(", ")}])`;
231
+ }
232
+ const mapped = n?.type === "CallExpression" && n.callee.type === "MemberExpression" && !n.callee.computed && n.callee.property.name === "map" && n.arguments.length === 1 ? n : null;
233
+ if (mapped) {
234
+ const list = expr(s, mapped.callee.object);
235
+ if (list.ty.k !== "list")
236
+ fail(s.comp, "FV1706", `\`${tag}\` maps a list`, mapped.callee.object);
237
+ const fn = mapped.arguments[0];
238
+ const { closure, enumerate } = arrow(s, fn, list, list.ty.of, false, "map", (inner) => tagObject(inner, tag, fn.body));
239
+ return `fv::HeadValue::Array(${items(list)}${enumerate ? ".enumerate()" : ""}.map(${closure}).collect())`;
240
+ }
241
+ return fail(s.comp, "FV1706", `\`${tag}\` is an array of object literals, an object literal, or a list's \`.map(x => ({ … }))\``, n ?? raw);
242
+ }
243
+ function titleTemplate(s, v) {
244
+ if (v.type === "ArrowFunctionExpression" || v.type === "FunctionExpression")
245
+ fail(s.comp, "FV1705", "a `titleTemplate` function runs with the title; write a string with `%s`", v);
246
+ return value(s, v, "`titleTemplate`", false);
247
+ }
248
+ function headInput(s, raw) {
249
+ const n = getter(s, raw);
250
+ if (n?.type !== "ObjectExpression")
251
+ fail(s.comp, "FV1702", "`useHead` takes an object literal, or a getter returning one", raw);
252
+ return object(s, n, "the head input", (key, v, p) => {
253
+ if (key === "title")
254
+ return value(s, v, "`title`", false);
255
+ if (key === "titleTemplate")
256
+ return titleTemplate(s, v);
257
+ if (TAG_LISTS.has(key))
258
+ return tagList(s, key, v);
259
+ if (ATTR_OBJECTS.has(key))
260
+ return tagObject(s, key, v);
261
+ if (key === "templateParams")
262
+ return fail(s.comp, "FV1703", "`templateParams` needs unhead's template params plugin, which ferrovue does not reproduce", p);
263
+ return fail(s.comp, "FV1703", `\`${key}\` is not a key of the head ferrovue translates: \`title\`, \`titleTemplate\`, \`base\`, \`meta\`, \`link\`, \`script\`, \`style\`, \`noscript\`, \`htmlAttrs\` and \`bodyAttrs\` are`, p);
264
+ });
265
+ }
266
+ function seoMeta(s, raw) {
267
+ const n = getter(s, raw);
268
+ if (n?.type !== "ObjectExpression")
269
+ fail(s.comp, "FV1702", "`useSeoMeta` takes an object literal, or a getter returning one", raw);
270
+ const input = [];
271
+ const meta = new Map();
272
+ for (const p of n.properties) {
273
+ const key = keyOf(s.comp, p);
274
+ if (key === "title" || key === "titleTemplate") {
275
+ input[key === "title" ? 0 : 1] = `(${rustStr(key)}, ${key === "title" ? value(s, p.value, "`title`", false) : titleTemplate(s, p.value)})`;
276
+ continue;
277
+ }
278
+ if (!/^[A-Za-z][A-Za-z0-9]*$/.test(key) || OBJECT_KEYS.has(key) || key === "class" || key === "style" || key === "key" || key.startsWith("tag") || key === "innerHTML" || key === "textContent" || key === "processTemplateParams") {
279
+ fail(s.comp, "FV1709", `\`${key}\` is not a key of \`useSeoMeta\` ferrovue translates: its keys are camel-case names, as \`description\` or \`ogTitle\``, p);
280
+ }
281
+ const v = getter(s, p.value);
282
+ if (v.type === "ObjectExpression" || v.type === "ArrayExpression") {
283
+ fail(s.comp, "FV1709", `\`${key}\` given an object or an array, which \`useSeoMeta\` unpacks into tags ferrovue does not reproduce; write its string`, p.value);
284
+ }
285
+ const [attr, name] = seoMetaKey(key);
286
+ meta.set(key, `(${rustStr(attr)}, ${rustStr(name)}, ${value(s, v, `\`${key}\``, false)})`);
287
+ }
288
+ return `${objectOf(input.filter((i) => i !== undefined))}, vec![${[...meta.values()].join(", ")}]`;
289
+ }
290
+ function composableCall(s, n) {
291
+ if (n?.type !== "CallExpression" || n.callee.type !== "Identifier")
292
+ return null;
293
+ const kind = scopeOf(head, s).composables.get(n.callee.name);
294
+ return kind ? { kind, call: n } : null;
295
+ }
296
+ function record(s, found) {
297
+ const { kind, call } = found;
298
+ if (kind === "safe")
299
+ fail(s.comp, "FV1708", "`useHeadSafe` filters its input through unhead's safe input plugin, which ferrovue does not reproduce; use `useHead` with values the page trusts", call);
300
+ if (call.arguments.length > 1)
301
+ fail(s.comp, "FV1701", "`useHead`'s options are not translated: give the input alone", call.arguments[1]);
302
+ scopeOf(head, s).calls.push({ kind, call });
303
+ }
304
+ export const head = {
305
+ name: "head",
306
+ configure: () => new Set(),
307
+ compiled(comp, _code, script) {
308
+ for (const st of script) {
309
+ if (st.type !== "ImportDeclaration" || st.source.value !== "@unhead/vue" || st.importKind === "type")
310
+ continue;
311
+ if (st.specifiers.some((sp) => sp.type === "ImportSpecifier" && sp.importKind !== "type" && Object.hasOwn(COMPOSABLES, sp.imported.name ?? sp.imported.value))) {
312
+ runOf(head).add(comp);
313
+ }
314
+ }
315
+ },
316
+ scope: () => ({ composables: new Map(), calls: [] }),
317
+ scriptImport(s, st, from) {
318
+ if (from !== "@unhead/vue")
319
+ return false;
320
+ for (const sp of st.specifiers) {
321
+ if (st.importKind === "type" || sp.importKind === "type")
322
+ continue;
323
+ const name = sp.type === "ImportSpecifier" ? (sp.imported.name ?? sp.imported.value) : null;
324
+ if (name !== null && Object.hasOwn(COMPOSABLES, name))
325
+ s.clientOnly.delete(sp.local.name);
326
+ if (name !== null && Object.hasOwn(COMPOSABLES, name))
327
+ scopeOf(head, s).composables.set(sp.local.name, COMPOSABLES[name]);
328
+ else
329
+ s.clientOnly.set(sp.local.name, `\`${name ?? sp.local.name}\` from \`@unhead/vue\` runs on the client`);
330
+ }
331
+ return true;
332
+ },
333
+ scriptStatement(s, st) {
334
+ const found = composableCall(s, st.expression);
335
+ if (!found)
336
+ return false;
337
+ record(s, found);
338
+ return true;
339
+ },
340
+ scriptBinding(s, d) {
341
+ const found = composableCall(s, d.init);
342
+ if (!found)
343
+ return false;
344
+ record(s, found);
345
+ for (const name of d.id.type === "Identifier" ? [d.id.name] : [])
346
+ s.clientOnly.set(name, "the entry `useHead` returns is for the client, which patches and disposes it");
347
+ return true;
348
+ },
349
+ loadedLater: (child) => (child.takes.has("fv_head") ? ["let _fv_later = fv_head.deferred();"] : []),
350
+ prelude(s) {
351
+ const after = scopeOf(head, s).calls.map(({ kind, call }) => kind === "seo" ? `fv_head.push_seo_meta(${seoMeta(s, call.arguments[0])});` : `fv_head.push(${headInput(s, call.arguments[0])});`);
352
+ return { before: [], after };
353
+ },
354
+ params: [
355
+ {
356
+ name: "fv_head",
357
+ ty: "&fv::Head",
358
+ pageTy: "&'p fv::Head",
359
+ reads: (c) => runOf(head).has(c),
360
+ test: { lines: ["let head = ferrovue::Head::without_defaults();"], arg: "&head", after: ["head_into(&mut out, &head);"] },
361
+ testSupport: `/// The head, after a marker, as the conformance suite writes unhead's: \`{"headTags":"…",…}\`.
362
+ #[cfg(test)]
363
+ fn head_into(out: &mut String, head: &ferrovue::Head) {
364
+ let html = head.render();
365
+ if html == ferrovue::HeadHtml::default() {
366
+ return;
367
+ }
368
+ let fields = [
369
+ ("headTags", &html.head_tags),
370
+ ("bodyTags", &html.body_tags),
371
+ ("bodyTagsOpen", &html.body_tags_open),
372
+ ("htmlAttrs", &html.html_attrs),
373
+ ("bodyAttrs", &html.body_attrs),
374
+ ];
375
+ let pairs: Vec<String> = fields
376
+ .iter()
377
+ .map(|(k, v)| format!("{}:{}", serde_json::to_string(k).unwrap(), serde_json::to_string(v).unwrap()))
378
+ .collect();
379
+ out.push_str("<!--fv-head-->{");
380
+ out.push_str(&pairs.join(","));
381
+ out.push('}');
382
+ }`,
383
+ },
384
+ ],
385
+ };
@@ -7,4 +7,6 @@ import { teleport } from "./teleport.js";
7
7
  import { scoped } from "./scoped.js";
8
8
  import { clientOnly } from "./client-only.js";
9
9
  import { twinsPlugin } from "./twins.js";
10
- export const PLUGINS = [router, piniaStores, sharedTypes, i18n, teleport, scoped, clientOnly, twinsPlugin];
10
+ import { provideInject } from "./provide.js";
11
+ import { head } from "./head.js";
12
+ export const PLUGINS = [router, piniaStores, sharedTypes, i18n, teleport, scoped, clientOnly, twinsPlugin, provideInject, head];
@@ -0,0 +1,44 @@
1
+ import { type Component, type N, type Ty } from "../model.ts";
2
+ import { type Plugin } from "../plugin.ts";
3
+ interface Key {
4
+ id: string;
5
+ label: string;
6
+ file: string | null;
7
+ field: string;
8
+ declared: {
9
+ ty: Ty | null;
10
+ ref: boolean;
11
+ } | null;
12
+ ty: Ty | null;
13
+ typedAt: Component | null;
14
+ }
15
+ interface Site {
16
+ comp: Component;
17
+ node: N;
18
+ key: Key;
19
+ }
20
+ interface Provided extends Site {
21
+ ref: boolean | Key;
22
+ client: boolean;
23
+ }
24
+ interface ProvideRun {
25
+ keys: Map<string, Key>;
26
+ provided: Map<N, Provided>;
27
+ injected: Map<N, Site>;
28
+ sites: Map<Component, {
29
+ provided: Provided[];
30
+ injected: Site[];
31
+ }>;
32
+ }
33
+ interface ProvideScope {
34
+ provide: Set<string>;
35
+ inject: Set<string>;
36
+ entries: {
37
+ key: Key;
38
+ code: string;
39
+ }[];
40
+ lets: string[];
41
+ injected: Set<string>;
42
+ }
43
+ export declare const provideInject: Plugin<ProvideRun, ProvideScope>;
44
+ export {};