@niscorp/nova 0.1.2 → 0.1.4

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 (86) hide show
  1. package/ADAPTER.md +6 -0
  2. package/CHANGELOG.md +20 -0
  3. package/README.md +29 -1
  4. package/dist/adapters/dom/index.cjs +98 -4
  5. package/dist/adapters/dom/index.cjs.map +1 -1
  6. package/dist/adapters/dom/index.js +7 -7
  7. package/dist/adapters/dom/server.cjs +12 -1
  8. package/dist/adapters/dom/server.cjs.map +1 -1
  9. package/dist/adapters/dom/server.js +7 -7
  10. package/dist/adapters/react/components/index.cjs +32 -10
  11. package/dist/adapters/react/components/index.cjs.map +1 -1
  12. package/dist/adapters/react/components/index.d.cts +2 -2
  13. package/dist/adapters/react/components/index.d.ts +2 -2
  14. package/dist/adapters/react/components/index.js +9 -5
  15. package/dist/adapters/react/index.cjs +268 -97
  16. package/dist/adapters/react/index.cjs.map +1 -1
  17. package/dist/adapters/react/index.js +9 -5
  18. package/dist/adapters/tty/index.cjs +8 -1
  19. package/dist/adapters/tty/index.cjs.map +1 -1
  20. package/dist/adapters/tty/index.js +12 -1
  21. package/dist/adapters/tty/index.js.map +1 -1
  22. package/dist/adapters/vue/components/index.cjs +32 -1
  23. package/dist/adapters/vue/components/index.cjs.map +1 -1
  24. package/dist/adapters/vue/components/index.d.cts +1 -1
  25. package/dist/adapters/vue/components/index.d.ts +1 -1
  26. package/dist/adapters/vue/components/index.js +9 -5
  27. package/dist/adapters/vue/index.cjs +218 -23
  28. package/dist/adapters/vue/index.cjs.map +1 -1
  29. package/dist/adapters/vue/index.js +10 -9
  30. package/dist/adapters/vue/index.js.map +1 -1
  31. package/dist/{chunk-7S5BNPUS.js → chunk-4ERQYDF6.js} +36 -4
  32. package/dist/chunk-4ERQYDF6.js.map +1 -0
  33. package/dist/{chunk-FQAJ24KA.js → chunk-4I2PFMY7.js} +33 -8
  34. package/dist/chunk-4I2PFMY7.js.map +1 -0
  35. package/dist/{chunk-IGLCWXQ3.js → chunk-7PKS7UYL.js} +3 -3
  36. package/dist/{chunk-IGLCWXQ3.js.map → chunk-7PKS7UYL.js.map} +1 -1
  37. package/dist/{chunk-GVBBL36G.js → chunk-DIFE573X.js} +196 -4
  38. package/dist/chunk-DIFE573X.js.map +1 -0
  39. package/dist/chunk-EHHJJLRX.js +16 -0
  40. package/dist/chunk-EHHJJLRX.js.map +1 -0
  41. package/dist/{chunk-3HGE3VWK.js → chunk-KYQ4EAQH.js} +33 -11
  42. package/dist/chunk-KYQ4EAQH.js.map +1 -0
  43. package/dist/{chunk-V32EVEVM.js → chunk-RXECI7DE.js} +300 -5
  44. package/dist/chunk-RXECI7DE.js.map +1 -0
  45. package/dist/{chunk-4ZID7UX5.js → chunk-UUYXVOK2.js} +52 -8
  46. package/dist/chunk-UUYXVOK2.js.map +1 -0
  47. package/dist/chunk-UV5YGBHQ.js +62 -0
  48. package/dist/chunk-UV5YGBHQ.js.map +1 -0
  49. package/dist/{chunk-6N4WRC5V.js → chunk-WZVQ5PUB.js} +85 -12
  50. package/dist/chunk-WZVQ5PUB.js.map +1 -0
  51. package/dist/chunk-X7SSNSQC.js +6 -0
  52. package/dist/chunk-X7SSNSQC.js.map +1 -0
  53. package/dist/devtools/index.js +4 -5
  54. package/dist/devtools/index.js.map +1 -1
  55. package/dist/document/index.cjs +199 -0
  56. package/dist/document/index.cjs.map +1 -0
  57. package/dist/document/index.d.cts +20 -0
  58. package/dist/document/index.d.ts +20 -0
  59. package/dist/document/index.js +125 -0
  60. package/dist/document/index.js.map +1 -0
  61. package/dist/head-BNj8GwPO.d.cts +20 -0
  62. package/dist/head-CS6X6ZKr.d.ts +20 -0
  63. package/dist/index.cjs +77 -1
  64. package/dist/index.cjs.map +1 -1
  65. package/dist/index.d.cts +27 -1
  66. package/dist/index.d.ts +27 -1
  67. package/dist/index.js +5 -6
  68. package/dist/migrations/index.js +1 -2
  69. package/dist/migrations/index.js.map +1 -1
  70. package/dist/reflect/index.js +4 -5
  71. package/package.json +13 -3
  72. package/dist/chunk-3HGE3VWK.js.map +0 -1
  73. package/dist/chunk-4ZID7UX5.js.map +0 -1
  74. package/dist/chunk-6N4WRC5V.js.map +0 -1
  75. package/dist/chunk-7S5BNPUS.js.map +0 -1
  76. package/dist/chunk-FQAJ24KA.js.map +0 -1
  77. package/dist/chunk-GVBBL36G.js.map +0 -1
  78. package/dist/chunk-PF4OJTYU.js +0 -199
  79. package/dist/chunk-PF4OJTYU.js.map +0 -1
  80. package/dist/chunk-RQB4PRPV.js +0 -285
  81. package/dist/chunk-RQB4PRPV.js.map +0 -1
  82. package/dist/chunk-V32EVEVM.js.map +0 -1
  83. package/dist/chunk-ZITHBBF3.js +0 -85
  84. package/dist/chunk-ZITHBBF3.js.map +0 -1
  85. package/dist/{primitive-props-BH_EJWIe.d.ts → primitive-props-Cl5jiC8g.d.cts} +1 -1
  86. package/dist/{primitive-props-BH_EJWIe.d.cts → primitive-props-Cl5jiC8g.d.ts} +1 -1
@@ -0,0 +1,125 @@
1
+ export { createTitleKeeper } from '../chunk-EHHJJLRX.js';
2
+ export { headOf, isHeadNode } from '../chunk-UV5YGBHQ.js';
3
+ export { HEAD_NAME } from '../chunk-X7SSNSQC.js';
4
+ import '../chunk-PZ5AY32C.js';
5
+
6
+ // src/document/place-head.ts
7
+ var escapeAttribute = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
8
+ var escapeText = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;");
9
+ var LINE_ENDS = [8232, 8233];
10
+ var escapeScript = (value) => LINE_ENDS.reduce(
11
+ (text, code) => text.split(String.fromCharCode(code)).join(`\\u${code.toString(16)}`),
12
+ JSON.stringify(value).replace(/</g, "\\u003c")
13
+ );
14
+ var ATTRIBUTES = `((?:[^>"']|"[^"]*"|'[^']*')*)`;
15
+ var ELEMENTS = new RegExp(`<!--[\\s\\S]*?-->|<(script|style|title)\\b${ATTRIBUTES}>([\\s\\S]*?)<\\/\\1\\s*>|<(meta|link)\\b${ATTRIBUTES}>`, "gi");
16
+ var ATTRIBUTE = /([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
17
+ var attributesOf = (written) => {
18
+ const attributes = {};
19
+ for (const match of written.matchAll(ATTRIBUTE)) {
20
+ const name = match[1]?.toLowerCase();
21
+ if (name === void 0 || name in attributes) continue;
22
+ attributes[name] = match[2] ?? match[3] ?? match[4] ?? "";
23
+ }
24
+ return attributes;
25
+ };
26
+ var elementsOf = (section) => {
27
+ const elements = [];
28
+ for (const match of section.matchAll(ELEMENTS)) {
29
+ const name = (match[1] ?? match[4])?.toLowerCase();
30
+ if (name === void 0) continue;
31
+ elements.push({ start: match.index, end: match.index + match[0].length, name, attributes: attributesOf(match[2] ?? match[5] ?? ""), text: match[3] ?? "" });
32
+ }
33
+ return elements;
34
+ };
35
+ var says = (element, attribute, value) => element.attributes[attribute]?.trim().toLowerCase() === value;
36
+ var isAbsolute = (address) => /^[a-z][a-z0-9+.-]*:/i.test(address) || address.startsWith("//");
37
+ var addressOf = (place) => {
38
+ if (place.site === void 0 || place.path === void 0) return void 0;
39
+ const path = place.path.split(/[?#]/)[0] ?? "";
40
+ return `${place.site.replace(/\/+$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
41
+ };
42
+ var wholeAddress = (address, base) => {
43
+ if (base === void 0 || isAbsolute(address)) return address;
44
+ try {
45
+ return new URL(address, base).href;
46
+ } catch {
47
+ return address;
48
+ }
49
+ };
50
+ var meta = (attribute, key, content) => ({
51
+ is: (element) => element.name === "meta" && says(element, attribute, key),
52
+ tag: () => `<meta ${attribute}="${key}" content="${escapeAttribute(content)}">`
53
+ });
54
+ var sayingsOf = (head, place) => {
55
+ const address = addressOf(place);
56
+ const sayings = [];
57
+ if (head.title !== void 0) {
58
+ const title = head.title;
59
+ sayings.push({
60
+ is: (element) => element.name === "title",
61
+ // The document's own title is kept beside the screen's, so a page that
62
+ // moves on to a screen with no head can say its own again.
63
+ tag: (was) => {
64
+ const own = was === void 0 ? void 0 : was.attributes["data-own"] ?? was.text.trim().replace(/"/g, "&quot;");
65
+ return `<title${own === void 0 || own === escapeText(title) ? "" : ` data-own="${own}"`}>${escapeText(title)}</title>`;
66
+ }
67
+ });
68
+ }
69
+ if (head.description !== void 0) sayings.push(meta("name", "description", head.description));
70
+ if (address !== void 0) {
71
+ sayings.push({
72
+ is: (element) => element.name === "link" && (element.attributes["rel"] ?? "").toLowerCase().split(/\s+/).includes("canonical"),
73
+ tag: () => `<link rel="canonical" href="${escapeAttribute(address)}">`
74
+ });
75
+ sayings.push(meta("property", "og:url", address));
76
+ }
77
+ if (head.kind !== void 0) sayings.push(meta("property", "og:type", head.kind));
78
+ if (head.title !== void 0) sayings.push(meta("property", "og:title", head.title));
79
+ if (head.description !== void 0) sayings.push(meta("property", "og:description", head.description));
80
+ if (head.image !== void 0) sayings.push(meta("property", "og:image", wholeAddress(head.image, address)));
81
+ return sayings;
82
+ };
83
+ var placeHead = (html, head, place = {}) => {
84
+ const said = head ?? {};
85
+ const sayings = sayingsOf(said, place);
86
+ if (sayings.length === 0 && said.structured === void 0) return html;
87
+ const opening = /<head\b[^>]*>/i.exec(html);
88
+ if (opening === null) return html;
89
+ const from = opening.index + opening[0].length;
90
+ const closing = html.slice(from).search(/<\/head\s*>/i);
91
+ if (closing < 0) return html;
92
+ const section = html.slice(from, from + closing);
93
+ const elements = elementsOf(section);
94
+ const changes = [];
95
+ const added = [];
96
+ for (const saying of sayings) {
97
+ const [first, ...others] = elements.filter(saying.is);
98
+ if (first === void 0) {
99
+ added.push(saying.tag(void 0));
100
+ continue;
101
+ }
102
+ changes.push({ start: first.start, end: first.end, text: saying.tag(first) });
103
+ for (const other of others) changes.push({ start: other.start, end: other.end, text: "" });
104
+ }
105
+ if (said.structured !== void 0) {
106
+ const script = `<script type="application/ld+json">${escapeScript(said.structured)}</script>`;
107
+ const was = elements.find((element) => element.name === "script" && says(element, "type", "application/ld+json"));
108
+ if (was === void 0) added.push(script);
109
+ else changes.push({ start: was.start, end: was.end, text: script });
110
+ }
111
+ let written = section;
112
+ for (const change of [...changes].sort((a, b) => b.start - a.start)) {
113
+ written = `${written.slice(0, change.start)}${change.text}${written.slice(change.end)}`;
114
+ }
115
+ const tail = /\s*$/.exec(written)?.[0] ?? "";
116
+ const body = written.slice(0, written.length - tail.length);
117
+ const indent = /(?:^|\n)([ \t]*)\S[^\n]*$/.exec(body)?.[1] ?? "";
118
+ const lead = tail.includes("\n") ? `
119
+ ${indent}` : "";
120
+ return `${html.slice(0, from)}${body}${added.map((tag) => `${lead}${tag}`).join("")}${tail}${html.slice(from + closing)}`;
121
+ };
122
+
123
+ export { placeHead };
124
+ //# sourceMappingURL=index.js.map
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/document/place-head.ts"],"names":[],"mappings":";;;;;;AA4BA,IAAM,eAAA,GAAkB,CAAC,KAAA,KAA0B,KAAA,CAAM,QAAQ,IAAA,EAAM,OAAO,CAAA,CAAE,OAAA,CAAQ,IAAA,EAAM,QAAQ,CAAA,CAAE,OAAA,CAAQ,MAAM,MAAM,CAAA;AAC5H,IAAM,UAAA,GAAa,CAAC,KAAA,KAA0B,KAAA,CAAM,OAAA,CAAQ,MAAM,OAAO,CAAA,CAAE,OAAA,CAAQ,IAAA,EAAM,MAAM,CAAA;AAK/F,IAAM,SAAA,GAAY,CAAC,IAAA,EAAQ,IAAM,CAAA;AACjC,IAAM,YAAA,GAAe,CAAC,KAAA,KACpB,SAAA,CAAU,MAAA;AAAA,EACR,CAAC,IAAA,EAAM,IAAA,KAAS,IAAA,CAAK,KAAA,CAAM,OAAO,YAAA,CAAa,IAAI,CAAC,CAAA,CAAE,KAAK,CAAA,GAAA,EAAM,IAAA,CAAK,QAAA,CAAS,EAAE,CAAC,CAAA,CAAE,CAAA;AAAA,EACpF,KAAK,SAAA,CAAU,KAAK,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EAAA,MAAM,SAAS,2BAAA,CAA4B,IAAA,CAAK,IAAI,CAAA,GAAI,CAAC,CAAA,IAAK,EAAA;AAC9D,EAAA,MAAM,IAAA,GAAO,IAAA,CAAK,QAAA,CAAS,IAAI,CAAA,GAAI;AAAA,EAAK,MAAM,CAAA,CAAA,GAAK,EAAA;AACnD,EAAA,OAAO,CAAA,EAAG,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,IAAI,CAAC,CAAA,EAAG,IAAI,CAAA,EAAG,KAAA,CAAM,GAAA,CAAI,CAAC,GAAA,KAAQ,CAAA,EAAG,IAAI,CAAA,EAAG,GAAG,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,EAAE,CAAC,CAAA,EAAG,IAAI,CAAA,EAAG,IAAA,CAAK,KAAA,CAAM,IAAA,GAAO,OAAO,CAAC,CAAA,CAAA;AACzH","file":"index.js","sourcesContent":["import type { Head } from '../layout/head';\n\n// ═══════════════════════════════════════════════════════════\n// A screen's head, written into an HTML document.\n//\n// The document is the app's own `index.html` with a screen already drawn into\n// it. What a head says takes the place of the tag that says the same thing —\n// the one <title>, the description, the preview tags — and a tag the document\n// does not have yet is added before </head>. Everything else in the head is\n// left exactly as it was: the icon, the viewport, the stylesheet.\n//\n// WHERE the document lives is not the screen's to say. Its address is the site\n// plus the path it was drawn at, and both are known to whoever writes the\n// file: with a `site`, every path is given its own canonical address, whether\n// or not its screen has a head.\n//\n// With no head and no site, the document comes back untouched.\n// ═══════════════════════════════════════════════════════════\n\nexport type HeadPlace = {\n // The address the site is served at (\"https://example.com\"). With it, each\n // path's canonical address is written and a preview picture's address is\n // made whole.\n site?: string;\n // The path this document was drawn at.\n path?: string;\n};\n\nconst escapeAttribute = (value: string): string => value.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;');\nconst escapeText = (value: string): string => value.replace(/&/g, '&amp;').replace(/</g, '&lt;');\n// Inside a <script>, the one thing that may not appear is the start of a tag.\n// The two separators end a line in a script though not in JSON, so they are\n// written as escapes too (named by code: the characters themselves would end\n// a line here as well).\nconst LINE_ENDS = [0x2028, 0x2029];\nconst escapeScript = (value: unknown): string =>\n LINE_ENDS.reduce(\n (text, code) => text.split(String.fromCharCode(code)).join(`\\\\u${code.toString(16)}`),\n JSON.stringify(value).replace(/</g, '\\\\u003c'),\n );\n\n// What stands in a head, read a tag at a time: comments and the bodies of\n// scripts and styles are passed over whole, so a tag written inside one is not\n// mistaken for a tag.\nconst ATTRIBUTES = `((?:[^>\"']|\"[^\"]*\"|'[^']*')*)`;\nconst ELEMENTS = new RegExp(`<!--[\\\\s\\\\S]*?-->|<(script|style|title)\\\\b${ATTRIBUTES}>([\\\\s\\\\S]*?)<\\\\/\\\\1\\\\s*>|<(meta|link)\\\\b${ATTRIBUTES}>`, 'gi');\nconst ATTRIBUTE = /([^\\s\"'=<>/]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+)))?/g;\n\ntype Element = { start: number; end: number; name: string; attributes: Record<string, string>; text: string };\n\nconst attributesOf = (written: string): Record<string, string> => {\n const attributes: Record<string, string> = {};\n for (const match of written.matchAll(ATTRIBUTE)) {\n const name = match[1]?.toLowerCase();\n if (name === undefined || name in attributes) continue;\n attributes[name] = match[2] ?? match[3] ?? match[4] ?? '';\n }\n return attributes;\n};\n\nconst elementsOf = (section: string): Element[] => {\n const elements: Element[] = [];\n for (const match of section.matchAll(ELEMENTS)) {\n const name = (match[1] ?? match[4])?.toLowerCase();\n if (name === undefined) continue;\n elements.push({ start: match.index, end: match.index + match[0].length, name, attributes: attributesOf(match[2] ?? match[5] ?? ''), text: match[3] ?? '' });\n }\n return elements;\n};\n\nconst says = (element: Element, attribute: string, value: string): boolean => element.attributes[attribute]?.trim().toLowerCase() === value;\n\nconst isAbsolute = (address: string): boolean => /^[a-z][a-z0-9+.-]*:/i.test(address) || address.startsWith('//');\n\nconst addressOf = (place: HeadPlace): string | undefined => {\n if (place.site === undefined || place.path === undefined) return undefined;\n const path = place.path.split(/[?#]/)[0] ?? '';\n return `${place.site.replace(/\\/+$/, '')}${path.startsWith('/') ? path : `/${path}`}`;\n};\n\n// A picture's address as somebody outside the site can fetch it.\nconst wholeAddress = (address: string, base: string | undefined): string => {\n if (base === undefined || isAbsolute(address)) return address;\n try {\n return new URL(address, base).href;\n } catch {\n return address;\n }\n};\n\n// One thing a document says: which tag says it, and the tag as it should stand.\ntype Saying = { is: (element: Element) => boolean; tag: (was: Element | undefined) => string };\n\nconst meta = (attribute: 'name' | 'property', key: string, content: string): Saying => ({\n is: (element) => element.name === 'meta' && says(element, attribute, key),\n tag: () => `<meta ${attribute}=\"${key}\" content=\"${escapeAttribute(content)}\">`,\n});\n\nconst sayingsOf = (head: Head, place: HeadPlace): Saying[] => {\n const address = addressOf(place);\n const sayings: Saying[] = [];\n if (head.title !== undefined) {\n const title = head.title;\n sayings.push({\n is: (element) => element.name === 'title',\n // The document's own title is kept beside the screen's, so a page that\n // moves on to a screen with no head can say its own again.\n tag: (was) => {\n const own = was === undefined ? undefined : (was.attributes['data-own'] ?? was.text.trim().replace(/\"/g, '&quot;'));\n return `<title${own === undefined || own === escapeText(title) ? '' : ` data-own=\"${own}\"`}>${escapeText(title)}</title>`;\n },\n });\n }\n if (head.description !== undefined) sayings.push(meta('name', 'description', head.description));\n if (address !== undefined) {\n sayings.push({\n is: (element) => element.name === 'link' && (element.attributes['rel'] ?? '').toLowerCase().split(/\\s+/).includes('canonical'),\n tag: () => `<link rel=\"canonical\" href=\"${escapeAttribute(address)}\">`,\n });\n sayings.push(meta('property', 'og:url', address));\n }\n if (head.kind !== undefined) sayings.push(meta('property', 'og:type', head.kind));\n if (head.title !== undefined) sayings.push(meta('property', 'og:title', head.title));\n if (head.description !== undefined) sayings.push(meta('property', 'og:description', head.description));\n if (head.image !== undefined) sayings.push(meta('property', 'og:image', wholeAddress(head.image, address)));\n return sayings;\n};\n\nexport const placeHead = (html: string, head: Head | undefined, place: HeadPlace = {}): string => {\n const said = head ?? {};\n const sayings = sayingsOf(said, place);\n if (sayings.length === 0 && said.structured === undefined) return html;\n\n const opening = /<head\\b[^>]*>/i.exec(html);\n if (opening === null) return html;\n const from = opening.index + opening[0].length;\n const closing = html.slice(from).search(/<\\/head\\s*>/i);\n if (closing < 0) return html;\n const section = html.slice(from, from + closing);\n const elements = elementsOf(section);\n\n const changes: { start: number; end: number; text: string }[] = [];\n const added: string[] = [];\n for (const saying of sayings) {\n const [first, ...others] = elements.filter(saying.is);\n if (first === undefined) {\n added.push(saying.tag(undefined));\n continue;\n }\n changes.push({ start: first.start, end: first.end, text: saying.tag(first) });\n // said twice, the second would still say the old thing\n for (const other of others) changes.push({ start: other.start, end: other.end, text: '' });\n }\n if (said.structured !== undefined) {\n const script = `<script type=\"application/ld+json\">${escapeScript(said.structured)}</script>`;\n const was = elements.find((element) => element.name === 'script' && says(element, 'type', 'application/ld+json'));\n if (was === undefined) added.push(script);\n else changes.push({ start: was.start, end: was.end, text: script });\n }\n\n let written = section;\n for (const change of [...changes].sort((a, b) => b.start - a.start)) {\n written = `${written.slice(0, change.start)}${change.text}${written.slice(change.end)}`;\n }\n // What is added goes after the last thing in the head, a line each, indented\n // as that last thing is — or straight on, in a head written on one line.\n const tail = /\\s*$/.exec(written)?.[0] ?? '';\n const body = written.slice(0, written.length - tail.length);\n const indent = /(?:^|\\n)([ \\t]*)\\S[^\\n]*$/.exec(body)?.[1] ?? '';\n const lead = tail.includes('\\n') ? `\\n${indent}` : '';\n return `${html.slice(0, from)}${body}${added.map((tag) => `${lead}${tag}`).join('')}${tail}${html.slice(from + closing)}`;\n};\n"]}
@@ -0,0 +1,20 @@
1
+ import { b as RenderNode } from './types-BLVRduoz.cjs';
2
+ import { R as RenderApi } from './types-PDXOkvtK.cjs';
3
+
4
+ declare const HEAD_NAME = "nova:head";
5
+ type Head = {
6
+ title?: string;
7
+ description?: string;
8
+ image?: string;
9
+ kind?: 'website' | 'article';
10
+ structured?: Record<string, unknown> | Record<string, unknown>[];
11
+ };
12
+
13
+ type ScreenHead = {
14
+ head: Head;
15
+ action?: string;
16
+ };
17
+ declare const isHeadNode: (node: RenderNode) => boolean;
18
+ declare const headOf: (api: Pick<RenderApi, "frame" | "canvasTree">) => ScreenHead | undefined;
19
+
20
+ export { HEAD_NAME as H, type ScreenHead as S, type Head as a, headOf as h, isHeadNode as i };
@@ -0,0 +1,20 @@
1
+ import { b as RenderNode } from './types-DE77Jl2W.js';
2
+ import { R as RenderApi } from './types-BB9RXel5.js';
3
+
4
+ declare const HEAD_NAME = "nova:head";
5
+ type Head = {
6
+ title?: string;
7
+ description?: string;
8
+ image?: string;
9
+ kind?: 'website' | 'article';
10
+ structured?: Record<string, unknown> | Record<string, unknown>[];
11
+ };
12
+
13
+ type ScreenHead = {
14
+ head: Head;
15
+ action?: string;
16
+ };
17
+ declare const isHeadNode: (node: RenderNode) => boolean;
18
+ declare const headOf: (api: Pick<RenderApi, "frame" | "canvasTree">) => ScreenHead | undefined;
19
+
20
+ export { HEAD_NAME as H, type ScreenHead as S, type Head as a, headOf as h, isHeadNode as i };
package/dist/index.cjs CHANGED
@@ -686,6 +686,9 @@ var walkValue = (value, prose, where, pass) => {
686
686
  return value;
687
687
  };
688
688
 
689
+ // src/layout/head.ts
690
+ var HEAD_NAME = "nova:head";
691
+
689
692
  // src/layout/renderer.ts
690
693
  var noopOnError = (_error) => {
691
694
  };
@@ -781,7 +784,7 @@ var renderNode = (node, chain, ctx) => {
781
784
  return [];
782
785
  };
783
786
  var renderComponent = (node, chain, ctx) => {
784
- if (!ctx.registry.has(node.component)) {
787
+ if (node.component !== HEAD_NAME && !ctx.registry.has(node.component)) {
785
788
  throw new ComponentNotFoundError(
786
789
  `Component not found in registry: ${node.component}`,
787
790
  { name: node.component }
@@ -1016,6 +1019,20 @@ var createComponentRegistry = () => {
1016
1019
  const list = () => Array.from(entries.keys());
1017
1020
  return { register, registerAll, get, has, list };
1018
1021
  };
1022
+ var HEAD_DESCRIPTION = "What this screen says it is: its title, description and preview picture. Draws nothing. One per screen, holding everything it says: where several are on a screen the last one is used whole, and they are never merged.";
1023
+ var HeadPropsSchema = zod.z.object({
1024
+ title: zod.z.string().optional().describe("The name of what this screen shows. Written as given: it becomes the document title and the title of its preview."),
1025
+ description: zod.z.string().optional().describe("One or two sentences saying what this screen shows, as plain text."),
1026
+ image: zod.z.string().optional().describe(
1027
+ "Address of a picture that stands for this screen where a link to it is previewed: an absolute URL, or a path. A path is made absolute against the page\u2019s own address when the site\u2019s address is known, and written as given when it is not."
1028
+ ),
1029
+ kind: zod.z.enum(["website", "article"]).optional().describe("What sort of thing this screen is. `article`: a piece of writing that stands on its own. `website`: anything else. Left out, nothing is written and the document keeps what it already says."),
1030
+ structured: zod.z.union([zod.z.record(zod.z.string(), zod.z.unknown()), zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown()))]).optional().describe("Structured data about what this screen shows: a JSON-LD object, or a list of them. Written as given, so each object carries its own `@context` and `@type`.")
1031
+ }).strict().describe(HEAD_DESCRIPTION);
1032
+ var HEAD_META = {
1033
+ description: HEAD_DESCRIPTION,
1034
+ propsSchema: HeadPropsSchema
1035
+ };
1019
1036
 
1020
1037
  // src/agent/palette.ts
1021
1038
  var stripProps = (schema, omit) => {
@@ -3584,11 +3601,65 @@ var createShell = (config) => {
3584
3601
  return shell;
3585
3602
  };
3586
3603
 
3604
+ // src/shell/head.ts
3605
+ var said = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
3606
+ var isObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
3607
+ var structuredOf = (value) => {
3608
+ if (isObject2(value)) return value;
3609
+ if (Array.isArray(value) && value.length > 0 && value.every(isObject2)) return value;
3610
+ return void 0;
3611
+ };
3612
+ var headFrom = (props) => {
3613
+ const [title, description, image] = [said(props["title"]), said(props["description"]), said(props["image"])];
3614
+ const kind = props["kind"] === "website" || props["kind"] === "article" ? props["kind"] : void 0;
3615
+ const structured = structuredOf(props["structured"]);
3616
+ return {
3617
+ ...title !== void 0 ? { title } : {},
3618
+ ...description !== void 0 ? { description } : {},
3619
+ ...image !== void 0 ? { image } : {},
3620
+ ...kind !== void 0 ? { kind } : {},
3621
+ ...structured !== void 0 ? { structured } : {}
3622
+ };
3623
+ };
3624
+ var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
3625
+ var headOf = (api) => {
3626
+ const found = [];
3627
+ const open = /* @__PURE__ */ new Set();
3628
+ const walk2 = (nodes, action) => {
3629
+ for (const node of nodes) {
3630
+ if (node.type === "fragment") {
3631
+ walk2(node.children, action);
3632
+ continue;
3633
+ }
3634
+ if (node.type !== "component") continue;
3635
+ if (node.name === HEAD_NAME) {
3636
+ found.push({ props: node.props, action });
3637
+ continue;
3638
+ }
3639
+ if (node.name === CANVAS_SLOT_NAME) {
3640
+ const canvasId = node.props["canvasId"];
3641
+ if (typeof canvasId !== "string" || canvasId === "" || open.has(canvasId)) continue;
3642
+ open.add(canvasId);
3643
+ walk2(api.canvasTree(canvasId), void 0);
3644
+ open.delete(canvasId);
3645
+ continue;
3646
+ }
3647
+ const definitionId = node.name === ACTION_SLOT_NAME ? node.props["definitionId"] : void 0;
3648
+ walk2(node.children, typeof definitionId === "string" ? definitionId : action);
3649
+ }
3650
+ };
3651
+ walk2(api.frame(), void 0);
3652
+ const last = found[found.length - 1];
3653
+ if (last === void 0) return void 0;
3654
+ return { head: headFrom(last.props), ...last.action !== void 0 ? { action: last.action } : {} };
3655
+ };
3656
+
3587
3657
  // src/shell/view.ts
3588
3658
  var hasVisibleContent = (nodes) => nodes.some((node) => {
3589
3659
  if (node.type === "text") return node.value !== "";
3590
3660
  if (node.type === "fragment") return hasVisibleContent(node.children);
3591
3661
  if (node.type === "component" && node.name === ACTION_SLOT_NAME) return hasVisibleContent(node.children);
3662
+ if (isHeadNode(node)) return false;
3592
3663
  return true;
3593
3664
  });
3594
3665
  var canvasTreeOf = (shell, canvasId) => {
@@ -3674,6 +3745,9 @@ exports.DefinitionValidationError = DefinitionValidationError;
3674
3745
  exports.EffectSchema = EffectSchema;
3675
3746
  exports.EndpointConfigSchema = EndpointConfigSchema;
3676
3747
  exports.ErrorCodes = ErrorCodes;
3748
+ exports.HEAD_META = HEAD_META;
3749
+ exports.HEAD_NAME = HEAD_NAME;
3750
+ exports.HeadPropsSchema = HeadPropsSchema;
3677
3751
  exports.LayoutNodeSchema = LayoutNodeSchema;
3678
3752
  exports.LayoutPrimitiveSchema = LayoutPrimitiveSchema;
3679
3753
  exports.LayoutRefNodeSchema = LayoutRefNodeSchema;
@@ -3707,8 +3781,10 @@ exports.createShell = createShell;
3707
3781
  exports.fillSlots = fillSlots;
3708
3782
  exports.getPath = getPath;
3709
3783
  exports.hasVisibleContent = hasVisibleContent;
3784
+ exports.headOf = headOf;
3710
3785
  exports.isComponentNode = isComponentNode;
3711
3786
  exports.isConditionalNode = isConditionalNode;
3787
+ exports.isHeadNode = isHeadNode;
3712
3788
  exports.isLayoutNode = isLayoutNode;
3713
3789
  exports.isLayoutPrimitive = isLayoutPrimitive;
3714
3790
  exports.isLayoutRefNode = isLayoutRefNode;