@niscorp/nova 0.1.4 → 0.2.1

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 (125) hide show
  1. package/ADAPTER.md +6 -6
  2. package/CHANGELOG.md +78 -0
  3. package/README.md +102 -34
  4. package/SHELL_DOCS.md +13 -4
  5. package/dist/adapters/dom/components/index.d.cts +2 -2
  6. package/dist/adapters/dom/components/index.d.ts +2 -2
  7. package/dist/adapters/dom/index.cjs +163 -34
  8. package/dist/adapters/dom/index.cjs.map +1 -1
  9. package/dist/adapters/dom/index.d.cts +2 -2
  10. package/dist/adapters/dom/index.d.ts +2 -2
  11. package/dist/adapters/dom/index.js +6 -6
  12. package/dist/adapters/dom/server.cjs +0 -2
  13. package/dist/adapters/dom/server.cjs.map +1 -1
  14. package/dist/adapters/dom/server.d.cts +2 -2
  15. package/dist/adapters/dom/server.d.ts +2 -2
  16. package/dist/adapters/dom/server.js +6 -6
  17. package/dist/adapters/react/components/index.cjs +6 -8
  18. package/dist/adapters/react/components/index.cjs.map +1 -1
  19. package/dist/adapters/react/components/index.d.cts +4 -4
  20. package/dist/adapters/react/components/index.d.ts +4 -4
  21. package/dist/adapters/react/components/index.js +7 -7
  22. package/dist/adapters/react/index.cjs +181 -51
  23. package/dist/adapters/react/index.cjs.map +1 -1
  24. package/dist/adapters/react/index.d.cts +4 -4
  25. package/dist/adapters/react/index.d.ts +4 -4
  26. package/dist/adapters/react/index.js +7 -7
  27. package/dist/adapters/tty/components/index.d.cts +2 -2
  28. package/dist/adapters/tty/components/index.d.ts +2 -2
  29. package/dist/adapters/tty/index.cjs +0 -2
  30. package/dist/adapters/tty/index.cjs.map +1 -1
  31. package/dist/adapters/tty/index.d.cts +2 -2
  32. package/dist/adapters/tty/index.d.ts +2 -2
  33. package/dist/adapters/tty/index.js +4 -4
  34. package/dist/adapters/tty/index.js.map +1 -1
  35. package/dist/adapters/vue/components/index.cjs +4 -6
  36. package/dist/adapters/vue/components/index.cjs.map +1 -1
  37. package/dist/adapters/vue/components/index.d.cts +9 -9
  38. package/dist/adapters/vue/components/index.d.ts +9 -9
  39. package/dist/adapters/vue/components/index.js +7 -7
  40. package/dist/adapters/vue/index.cjs +175 -46
  41. package/dist/adapters/vue/index.cjs.map +1 -1
  42. package/dist/adapters/vue/index.d.cts +4 -4
  43. package/dist/adapters/vue/index.d.ts +4 -4
  44. package/dist/adapters/vue/index.js +9 -9
  45. package/dist/adapters/vue/index.js.map +1 -1
  46. package/dist/agent/index.d.cts +2 -2
  47. package/dist/agent/index.d.ts +2 -2
  48. package/dist/{chunk-7PKS7UYL.js → chunk-3JRTELLC.js} +3 -3
  49. package/dist/{chunk-7PKS7UYL.js.map → chunk-3JRTELLC.js.map} +1 -1
  50. package/dist/{chunk-WZVQ5PUB.js → chunk-DU2VIJAF.js} +59 -17
  51. package/dist/chunk-DU2VIJAF.js.map +1 -0
  52. package/dist/{chunk-UUYXVOK2.js → chunk-F2H7WP6R.js} +16 -16
  53. package/dist/chunk-F2H7WP6R.js.map +1 -0
  54. package/dist/{chunk-KYQ4EAQH.js → chunk-G4LSLLGI.js} +17 -17
  55. package/dist/chunk-G4LSLLGI.js.map +1 -0
  56. package/dist/chunk-OE4E6IBD.js +25 -0
  57. package/dist/chunk-OE4E6IBD.js.map +1 -0
  58. package/dist/chunk-RFBIGRCI.js +127 -0
  59. package/dist/chunk-RFBIGRCI.js.map +1 -0
  60. package/dist/{chunk-4I2PFMY7.js → chunk-SVNK5NIK.js} +8 -8
  61. package/dist/chunk-SVNK5NIK.js.map +1 -0
  62. package/dist/chunk-V4BPFFFV.js +152 -0
  63. package/dist/chunk-V4BPFFFV.js.map +1 -0
  64. package/dist/{chunk-4ERQYDF6.js → chunk-VOD5JA4D.js} +10 -10
  65. package/dist/chunk-VOD5JA4D.js.map +1 -0
  66. package/dist/chunk-XQTI4Q4I.js +178 -0
  67. package/dist/chunk-XQTI4Q4I.js.map +1 -0
  68. package/dist/{chunk-RXECI7DE.js → chunk-Y6XVPRYH.js} +33 -17
  69. package/dist/chunk-Y6XVPRYH.js.map +1 -0
  70. package/dist/devtools/index.d.cts +2 -2
  71. package/dist/devtools/index.d.ts +2 -2
  72. package/dist/devtools/index.js +3 -3
  73. package/dist/document/index.cjs +228 -119
  74. package/dist/document/index.cjs.map +1 -1
  75. package/dist/document/index.d.cts +10 -8
  76. package/dist/document/index.d.ts +10 -8
  77. package/dist/document/index.js +3 -122
  78. package/dist/document/index.js.map +1 -1
  79. package/dist/examples/index.cjs +1186 -0
  80. package/dist/examples/index.cjs.map +1 -0
  81. package/dist/examples/index.d.cts +63 -0
  82. package/dist/examples/index.d.ts +63 -0
  83. package/dist/examples/index.js +1158 -0
  84. package/dist/examples/index.js.map +1 -0
  85. package/dist/head-CAzfTnpV.d.cts +25 -0
  86. package/dist/head-DRpbbj-l.d.ts +25 -0
  87. package/dist/i18n/index.d.cts +2 -2
  88. package/dist/i18n/index.d.ts +2 -2
  89. package/dist/i18n/index.js +2 -176
  90. package/dist/i18n/index.js.map +1 -1
  91. package/dist/index.cjs +206 -53
  92. package/dist/index.cjs.map +1 -1
  93. package/dist/index.d.cts +23 -31
  94. package/dist/index.d.ts +23 -31
  95. package/dist/index.js +4 -4
  96. package/dist/{palette-Mx7XHYC6.d.ts → palette-CIpPH90W.d.ts} +1 -1
  97. package/dist/{palette-wbJB_svk.d.cts → palette-CvwZZCkx.d.cts} +1 -1
  98. package/dist/reflect/index.d.cts +2 -2
  99. package/dist/reflect/index.d.ts +2 -2
  100. package/dist/reflect/index.js +3 -3
  101. package/dist/{types-B-rjaUX0.d.ts → types-BSKx5MXW.d.ts} +1 -1
  102. package/dist/{types-B_nOtkyt.d.ts → types-BWc-olbY.d.ts} +1 -1
  103. package/dist/{types-mRKXqZPX.d.cts → types-C9734_lJ.d.cts} +1 -1
  104. package/dist/{types-BB9RXel5.d.ts → types-D23TRvqe.d.ts} +1 -1
  105. package/dist/{types-uk19d6KC.d.cts → types-DsWNYc7R.d.cts} +1 -1
  106. package/dist/{types-BLVRduoz.d.cts → types-j290XhCn.d.cts} +1 -1
  107. package/dist/{types-PDXOkvtK.d.cts → types-qkzTfSye.d.cts} +1 -1
  108. package/dist/{types-DE77Jl2W.d.ts → types-qnKMx0_V.d.ts} +1 -1
  109. package/package.json +19 -8
  110. package/dist/chunk-4ERQYDF6.js.map +0 -1
  111. package/dist/chunk-4I2PFMY7.js.map +0 -1
  112. package/dist/chunk-EHHJJLRX.js +0 -16
  113. package/dist/chunk-EHHJJLRX.js.map +0 -1
  114. package/dist/chunk-KYQ4EAQH.js.map +0 -1
  115. package/dist/chunk-RXECI7DE.js.map +0 -1
  116. package/dist/chunk-UUYXVOK2.js.map +0 -1
  117. package/dist/chunk-UV5YGBHQ.js +0 -62
  118. package/dist/chunk-UV5YGBHQ.js.map +0 -1
  119. package/dist/chunk-WZVQ5PUB.js.map +0 -1
  120. package/dist/chunk-X7SSNSQC.js +0 -6
  121. package/dist/chunk-X7SSNSQC.js.map +0 -1
  122. package/dist/head-BNj8GwPO.d.cts +0 -20
  123. package/dist/head-CS6X6ZKr.d.ts +0 -20
  124. package/dist/{primitive-props-Cl5jiC8g.d.cts → primitive-props-CGoJvmcH.d.cts} +5 -5
  125. package/dist/{primitive-props-Cl5jiC8g.d.ts → primitive-props-CGoJvmcH.d.ts} +5 -5
@@ -2,35 +2,118 @@
2
2
 
3
3
  // src/layout/head.ts
4
4
  var HEAD_NAME = "nova:head";
5
+ var HEAD_TITLE_NAME = "nova:title";
6
+ var HEAD_META_NAME = "nova:meta";
7
+ var HEAD_LINK_NAME = "nova:link";
8
+ var HEAD_SCRIPT_NAME = "nova:script";
9
+ var HEAD_NAMES = [HEAD_NAME, HEAD_TITLE_NAME, HEAD_META_NAME, HEAD_LINK_NAME, HEAD_SCRIPT_NAME];
10
+ var headKeyOf = (element) => {
11
+ const said = (name) => {
12
+ const found = Object.entries(element.attributes).find(([key]) => key.toLowerCase() === name)?.[1].trim().toLowerCase();
13
+ return found === void 0 || found === "" ? void 0 : found;
14
+ };
15
+ if (element.tag === "title") return "title";
16
+ if (element.tag === "meta") {
17
+ const [name, property] = [said("name"), said("property")];
18
+ if (name !== void 0) return `meta name ${name}`;
19
+ return property === void 0 ? void 0 : `meta property ${property}`;
20
+ }
21
+ if (element.tag === "link") return (said("rel") ?? "").split(/\s+/).includes("canonical") ? "link canonical" : void 0;
22
+ return void 0;
23
+ };
5
24
 
6
25
  // src/shell/slot-names.ts
7
26
  var CANVAS_SLOT_NAME = "CanvasSlot";
8
27
  var ACTION_SLOT_NAME = "ActionSlot";
9
28
 
10
29
  // src/shell/head.ts
11
- var said = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
12
- var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
13
- var structuredOf = (value) => {
14
- if (isObject(value)) return value;
15
- if (Array.isArray(value) && value.length > 0 && value.every(isObject)) return value;
16
- return void 0;
30
+ var ATTRIBUTE_NAME = /^[A-Za-z][A-Za-z0-9:._-]*$/;
31
+ var DATA_TYPE = /^application\/([a-z0-9.-]+\+)?json$/i;
32
+ var written = (value) => {
33
+ if (typeof value === "string") return value.trim() === "" ? void 0 : value;
34
+ if (typeof value === "number") return String(value);
35
+ return value === true ? "" : void 0;
17
36
  };
18
- var headFrom = (props) => {
19
- const [title, description, image] = [said(props["title"]), said(props["description"]), said(props["image"])];
20
- const kind = props["kind"] === "website" || props["kind"] === "article" ? props["kind"] : void 0;
21
- const structured = structuredOf(props["structured"]);
22
- return {
23
- ...title !== void 0 ? { title } : {},
24
- ...description !== void 0 ? { description } : {},
25
- ...image !== void 0 ? { image } : {},
26
- ...kind !== void 0 ? { kind } : {},
27
- ...structured !== void 0 ? { structured } : {}
28
- };
37
+ var attributesOf = (what, props, skip = []) => {
38
+ const attributes = {};
39
+ for (const [name, value] of Object.entries(props)) {
40
+ if (skip.includes(name)) continue;
41
+ if (!ATTRIBUTE_NAME.test(name)) return { refused: `${what}: "${name}" is not an attribute\u2019s name` };
42
+ if (/^on/i.test(name)) return { refused: `${what}: \`${name}\` is a handler, and a layout does not run` };
43
+ const text = written(value);
44
+ if (text !== void 0) attributes[name] = text;
45
+ }
46
+ return { attributes };
47
+ };
48
+ var has = (attributes, name) => Object.keys(attributes).some((key) => key.toLowerCase() === name);
49
+ var valueOf = (attributes, name) => Object.entries(attributes).find(([key]) => key.toLowerCase() === name)?.[1] ?? "";
50
+ var textOf = (nodes) => nodes.map((node) => node.type === "text" ? node.value : node.type === "fragment" ? textOf(node.children) : "").join("");
51
+ var titleOf = (node) => {
52
+ const text = textOf(node.children).trim();
53
+ return text === "" ? void 0 : { element: { tag: "title", attributes: {}, text } };
54
+ };
55
+ var metaOf = (node) => {
56
+ const read = attributesOf(HEAD_META_NAME, node.props);
57
+ if ("refused" in read) return read;
58
+ if (has(read.attributes, "http-equiv")) return { refused: `${HEAD_META_NAME}: \`http-equiv\` instructs the browser, and a layout does not` };
59
+ return has(read.attributes, "content") ? { element: { tag: "meta", attributes: read.attributes } } : void 0;
60
+ };
61
+ var linkOf = (node) => {
62
+ const read = attributesOf(HEAD_LINK_NAME, node.props);
63
+ if ("refused" in read) return read;
64
+ if (valueOf(read.attributes, "rel").toLowerCase().split(/\s+/).includes("stylesheet")) return { refused: `${HEAD_LINK_NAME}: a stylesheet styles the page, and a layout does not` };
65
+ return has(read.attributes, "href") ? { element: { tag: "link", attributes: read.attributes } } : void 0;
66
+ };
67
+ var scriptOf = (node) => {
68
+ const read = attributesOf(HEAD_SCRIPT_NAME, node.props, ["data"]);
69
+ if ("refused" in read) return read;
70
+ if (has(read.attributes, "src")) return { refused: `${HEAD_SCRIPT_NAME}: a script with a \`src\` runs, and a layout does not` };
71
+ const type = valueOf(read.attributes, "type");
72
+ if (!DATA_TYPE.test(type)) return { refused: `${HEAD_SCRIPT_NAME}: only a data block may be written (a JSON \`type\`), and "${type}" is not one` };
73
+ const data = node.props["data"];
74
+ if (data === void 0 || data === null || data === "") return void 0;
75
+ return { element: { tag: "script", attributes: read.attributes, text: JSON.stringify(data) } };
76
+ };
77
+ var READERS = {
78
+ [HEAD_TITLE_NAME]: titleOf,
79
+ [HEAD_META_NAME]: metaOf,
80
+ [HEAD_LINK_NAME]: linkOf,
81
+ [HEAD_SCRIPT_NAME]: scriptOf
29
82
  };
30
83
  var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
31
84
  var headOf = (api) => {
32
- const found = [];
85
+ let heads = 0;
86
+ const said = [];
87
+ const refused = [];
33
88
  const open = /* @__PURE__ */ new Set();
89
+ const hold = (nodes, action) => {
90
+ for (const node of nodes) {
91
+ if (node.type === "fragment") {
92
+ hold(node.children, action);
93
+ continue;
94
+ }
95
+ if (node.type === "error") {
96
+ refused.push(`${HEAD_NAME}: ${node.message}`);
97
+ continue;
98
+ }
99
+ if (node.type !== "component") continue;
100
+ const read = READERS[node.name];
101
+ if (read === void 0) {
102
+ refused.push(`${HEAD_NAME}: "${node.name}" is not something a head holds`);
103
+ continue;
104
+ }
105
+ const found = read(node);
106
+ if (found === void 0) continue;
107
+ if ("refused" in found) {
108
+ refused.push(found.refused);
109
+ continue;
110
+ }
111
+ const key = headKeyOf(found.element);
112
+ const earlier = key === void 0 ? -1 : said.findIndex((other) => headKeyOf(other.element) === key);
113
+ if (earlier >= 0) said.splice(earlier, 1);
114
+ said.push({ element: found.element, action });
115
+ }
116
+ };
34
117
  const walk = (nodes, action) => {
35
118
  for (const node of nodes) {
36
119
  if (node.type === "fragment") {
@@ -39,7 +122,8 @@ var headOf = (api) => {
39
122
  }
40
123
  if (node.type !== "component") continue;
41
124
  if (node.name === HEAD_NAME) {
42
- found.push({ props: node.props, action });
125
+ heads += 1;
126
+ hold(node.children, action);
43
127
  continue;
44
128
  }
45
129
  if (node.name === CANVAS_SLOT_NAME) {
@@ -55,143 +139,168 @@ var headOf = (api) => {
55
139
  }
56
140
  };
57
141
  walk(api.frame(), void 0);
58
- const last = found[found.length - 1];
59
- if (last === void 0) return void 0;
60
- return { head: headFrom(last.props), ...last.action !== void 0 ? { action: last.action } : {} };
142
+ if (heads === 0) return void 0;
143
+ const actions = [...new Set(said.flatMap((one) => one.action === void 0 ? [] : [one.action]))];
144
+ return { elements: said.map((one) => one.element), actions, refused };
61
145
  };
62
146
 
63
147
  // src/document/place-head.ts
148
+ var HEAD_MARK = "data-nova-head";
149
+ var OWN_MARK = "data-nova-own";
64
150
  var escapeAttribute = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
65
151
  var escapeText = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;");
66
152
  var LINE_ENDS = [8232, 8233];
67
- var escapeScript = (value) => LINE_ENDS.reduce(
68
- (text, code) => text.split(String.fromCharCode(code)).join(`\\u${code.toString(16)}`),
69
- JSON.stringify(value).replace(/</g, "\\u003c")
70
- );
153
+ var escapeScript = (json) => LINE_ENDS.reduce((text, code) => text.split(String.fromCharCode(code)).join(`\\u${code.toString(16)}`), json.replace(/</g, "\\u003c"));
71
154
  var ATTRIBUTES = `((?:[^>"']|"[^"]*"|'[^']*')*)`;
72
- var ELEMENTS = new RegExp(`<!--[\\s\\S]*?-->|<(script|style|title)\\b${ATTRIBUTES}>([\\s\\S]*?)<\\/\\1\\s*>|<(meta|link)\\b${ATTRIBUTES}>`, "gi");
155
+ var TAGS = new RegExp(`<!--[\\s\\S]*?-->|<(script|style|title|template)\\b${ATTRIBUTES}>([\\s\\S]*?)<\\/\\1\\s*>|<(meta|link)\\b${ATTRIBUTES}>`, "gi");
73
156
  var ATTRIBUTE = /([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
74
- var attributesOf = (written) => {
157
+ var attributesOf2 = (source) => {
75
158
  const attributes = {};
76
- for (const match of written.matchAll(ATTRIBUTE)) {
159
+ for (const match of source.matchAll(ATTRIBUTE)) {
77
160
  const name = match[1]?.toLowerCase();
78
161
  if (name === void 0 || name in attributes) continue;
79
162
  attributes[name] = match[2] ?? match[3] ?? match[4] ?? "";
80
163
  }
81
164
  return attributes;
82
165
  };
83
- var elementsOf = (section) => {
84
- const elements = [];
85
- for (const match of section.matchAll(ELEMENTS)) {
166
+ var tagsOf = (section) => {
167
+ const tags = [];
168
+ for (const match of section.matchAll(TAGS)) {
86
169
  const name = (match[1] ?? match[4])?.toLowerCase();
87
170
  if (name === void 0) continue;
88
- elements.push({ start: match.index, end: match.index + match[0].length, name, attributes: attributesOf(match[2] ?? match[5] ?? ""), text: match[3] ?? "" });
171
+ tags.push({ start: match.index, end: match.index + match[0].length, name, attributes: attributesOf2(match[2] ?? match[5] ?? ""), inner: match[3] ?? "", text: match[0] });
89
172
  }
90
- return elements;
173
+ return tags;
174
+ };
175
+ var keyOfTag = (tag) => tag.name === "title" || tag.name === "meta" || tag.name === "link" ? headKeyOf({ tag: tag.name, attributes: tag.attributes }) : void 0;
176
+ var markupOf = (element, marked) => {
177
+ const written2 = Object.entries(element.attributes).map(([name, value]) => value === "" ? ` ${name}` : ` ${name}="${escapeAttribute(value)}"`);
178
+ const attributes = [...written2, ...marked ? [` ${HEAD_MARK}`] : []].join("");
179
+ if (element.tag === "title") return `<title${attributes}>${escapeText(element.text ?? "")}</title>`;
180
+ if (element.tag === "script") return `<script${attributes}>${escapeScript(element.text ?? "")}</script>`;
181
+ return `<${element.tag}${attributes}>`;
91
182
  };
92
- var says = (element, attribute, value) => element.attributes[attribute]?.trim().toLowerCase() === value;
93
- var isAbsolute = (address) => /^[a-z][a-z0-9+.-]*:/i.test(address) || address.startsWith("//");
94
183
  var addressOf = (place) => {
95
- if (place.site === void 0 || place.path === void 0) return void 0;
184
+ if (place.site === void 0 || place.path === void 0) return [];
96
185
  const path = place.path.split(/[?#]/)[0] ?? "";
97
- return `${place.site.replace(/\/+$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
98
- };
99
- var wholeAddress = (address, base) => {
100
- if (base === void 0 || isAbsolute(address)) return address;
101
- try {
102
- return new URL(address, base).href;
103
- } catch {
104
- return address;
105
- }
186
+ const address = `${place.site.replace(/\/+$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
187
+ return [
188
+ { tag: "link", attributes: { rel: "canonical", href: address } },
189
+ { tag: "meta", attributes: { property: "og:url", content: address } }
190
+ ];
106
191
  };
107
- var meta = (attribute, key, content) => ({
108
- is: (element) => element.name === "meta" && says(element, attribute, key),
109
- tag: () => `<meta ${attribute}="${key}" content="${escapeAttribute(content)}">`
110
- });
111
- var sayingsOf = (head, place) => {
112
- const address = addressOf(place);
113
- const sayings = [];
114
- if (head.title !== void 0) {
115
- const title = head.title;
116
- sayings.push({
117
- is: (element) => element.name === "title",
118
- // The document's own title is kept beside the screen's, so a page that
119
- // moves on to a screen with no head can say its own again.
120
- tag: (was) => {
121
- const own = was === void 0 ? void 0 : was.attributes["data-own"] ?? was.text.trim().replace(/"/g, "&quot;");
122
- return `<title${own === void 0 || own === escapeText(title) ? "" : ` data-own="${own}"`}>${escapeText(title)}</title>`;
123
- }
124
- });
125
- }
126
- if (head.description !== void 0) sayings.push(meta("name", "description", head.description));
127
- if (address !== void 0) {
128
- sayings.push({
129
- is: (element) => element.name === "link" && (element.attributes["rel"] ?? "").toLowerCase().split(/\s+/).includes("canonical"),
130
- tag: () => `<link rel="canonical" href="${escapeAttribute(address)}">`
131
- });
132
- sayings.push(meta("property", "og:url", address));
133
- }
134
- if (head.kind !== void 0) sayings.push(meta("property", "og:type", head.kind));
135
- if (head.title !== void 0) sayings.push(meta("property", "og:title", head.title));
136
- if (head.description !== void 0) sayings.push(meta("property", "og:description", head.description));
137
- if (head.image !== void 0) sayings.push(meta("property", "og:image", wholeAddress(head.image, address)));
138
- return sayings;
139
- };
140
- var placeHead = (html, head, place = {}) => {
141
- const said2 = head ?? {};
142
- const sayings = sayingsOf(said2, place);
143
- if (sayings.length === 0 && said2.structured === void 0) return html;
144
- const opening = /<head\b[^>]*>/i.exec(html);
145
- if (opening === null) return html;
146
- const from = opening.index + opening[0].length;
147
- const closing = html.slice(from).search(/<\/head\s*>/i);
148
- if (closing < 0) return html;
149
- const section = html.slice(from, from + closing);
150
- const elements = elementsOf(section);
192
+ var changed = (text, changes) => [...changes].sort((a, b) => b.start - a.start).reduce((at, change) => `${at.slice(0, change.start)}${change.text}${at.slice(change.end)}`, text);
193
+ var restored = (section) => changed(
194
+ section,
195
+ tagsOf(section).flatMap((tag) => {
196
+ if (tag.name === "template" && OWN_MARK in tag.attributes) return [{ start: tag.start, end: tag.end, text: tag.inner }];
197
+ return HEAD_MARK in tag.attributes ? [{ start: tag.start, end: tag.end, text: "" }] : [];
198
+ })
199
+ );
200
+ var write = (section, elements, screen) => {
201
+ if (elements.length === 0) return section;
202
+ const tags = tagsOf(section);
151
203
  const changes = [];
152
204
  const added = [];
153
- for (const saying of sayings) {
154
- const [first, ...others] = elements.filter(saying.is);
205
+ const own = [];
206
+ for (const element of elements) {
207
+ const key = headKeyOf(element);
208
+ const [first, ...others] = key === void 0 ? [] : tags.filter((tag) => keyOfTag(tag) === key);
155
209
  if (first === void 0) {
156
- added.push(saying.tag(void 0));
210
+ added.push(markupOf(element, screen));
157
211
  continue;
158
212
  }
159
- changes.push({ start: first.start, end: first.end, text: saying.tag(first) });
160
- for (const other of others) changes.push({ start: other.start, end: other.end, text: "" });
161
- }
162
- if (said2.structured !== void 0) {
163
- const script = `<script type="application/ld+json">${escapeScript(said2.structured)}</script>`;
164
- const was = elements.find((element) => element.name === "script" && says(element, "type", "application/ld+json"));
165
- if (was === void 0) added.push(script);
166
- else changes.push({ start: was.start, end: was.end, text: script });
167
- }
168
- let written = section;
169
- for (const change of [...changes].sort((a, b) => b.start - a.start)) {
170
- written = `${written.slice(0, change.start)}${change.text}${written.slice(change.end)}`;
213
+ changes.push({ start: first.start, end: first.end, text: markupOf(element, screen) });
214
+ own.push(first.text);
215
+ for (const other of others) {
216
+ changes.push({ start: other.start, end: other.end, text: "" });
217
+ own.push(other.text);
218
+ }
171
219
  }
172
- const tail = /\s*$/.exec(written)?.[0] ?? "";
173
- const body = written.slice(0, written.length - tail.length);
220
+ if (screen && own.length > 0) added.push(`<template ${OWN_MARK}>${own.join("")}</template>`);
221
+ const written2 = changed(section, changes);
222
+ const tail = /\s*$/.exec(written2)?.[0] ?? "";
223
+ const body = written2.slice(0, written2.length - tail.length);
174
224
  const indent = /(?:^|\n)([ \t]*)\S[^\n]*$/.exec(body)?.[1] ?? "";
175
225
  const lead = tail.includes("\n") ? `
176
226
  ${indent}` : "";
177
- return `${html.slice(0, from)}${body}${added.map((tag) => `${lead}${tag}`).join("")}${tail}${html.slice(from + closing)}`;
227
+ return `${body}${added.map((tag) => `${lead}${tag}`).join("")}${tail}`;
228
+ };
229
+ var placeHead = (html, elements, place = {}) => {
230
+ const opening = /<head\b[^>]*>/i.exec(html);
231
+ if (opening === null) return html;
232
+ const from = opening.index + opening[0].length;
233
+ const closing = html.slice(from).search(/<\/head\s*>/i);
234
+ if (closing < 0) return html;
235
+ const located = write(restored(html.slice(from, from + closing)), addressOf(place), false);
236
+ return `${html.slice(0, from)}${write(located, elements ?? [], true)}${html.slice(from + closing)}`;
178
237
  };
179
238
 
180
- // src/document/title.ts
181
- var createTitleKeeper = (doc) => {
182
- const own = doc.querySelector("title")?.getAttribute("data-own") ?? doc.title;
183
- let said2;
184
- return (head) => {
185
- const title = head?.title;
186
- if (title === said2) return;
187
- said2 = title;
188
- const next = title ?? own;
189
- if (doc.title !== next) doc.title = next;
239
+ // src/document/head-keeper.ts
240
+ var TAGS2 = ["title", "meta", "link"];
241
+ var keyOfNode = (node) => {
242
+ const tag = TAGS2.find((name) => name === node.tagName.toLowerCase());
243
+ if (tag !== "title" && tag !== "meta" && tag !== "link") return void 0;
244
+ return headKeyOf({ tag, attributes: Object.fromEntries([...node.attributes].map((attribute) => [attribute.name, attribute.value])) });
245
+ };
246
+ var createHeadKeeper = (doc) => {
247
+ let mine = [];
248
+ let away = [];
249
+ let said;
250
+ const built = (element) => {
251
+ const node = doc.createElement(element.tag);
252
+ for (const [name, value] of Object.entries(element.attributes)) node.setAttribute(name, value);
253
+ node.setAttribute(HEAD_MARK, "");
254
+ if (element.text !== void 0) node.textContent = element.text;
255
+ return node;
256
+ };
257
+ const adopt = () => {
258
+ mine = [...doc.head.querySelectorAll(`[${HEAD_MARK}]`)];
259
+ const view = doc.defaultView;
260
+ for (const stash of doc.head.querySelectorAll(`template[${OWN_MARK}]`)) {
261
+ if (view === null || !(stash instanceof view.HTMLTemplateElement)) continue;
262
+ for (const child of [...stash.content.children]) {
263
+ const key = keyOfNode(child);
264
+ if (key !== void 0) away.push({ key, node: doc.importNode(child, true), before: null });
265
+ }
266
+ stash.remove();
267
+ }
268
+ };
269
+ return (elements) => {
270
+ const now = elements ?? [];
271
+ const next = JSON.stringify(now);
272
+ if (said === void 0) {
273
+ if (now.length === 0) return;
274
+ adopt();
275
+ }
276
+ if (next === said) return;
277
+ said = next;
278
+ for (const node of mine) node.remove();
279
+ mine = now.map(built);
280
+ const keys = new Set(now.flatMap((element) => headKeyOf(element) ?? []));
281
+ for (const node of [...doc.head.children]) {
282
+ const key = keyOfNode(node);
283
+ if (key === void 0 || !keys.has(key)) continue;
284
+ away.push({ key, node, before: node.nextSibling });
285
+ node.remove();
286
+ }
287
+ const [back, still] = [away.filter((gone) => !keys.has(gone.key)), away.filter((gone) => keys.has(gone.key))];
288
+ for (const gone of [...back].reverse()) doc.head.insertBefore(gone.node, gone.before !== null && gone.before.parentNode === doc.head ? gone.before : null);
289
+ away = still;
290
+ doc.head.append(...mine);
190
291
  };
191
292
  };
192
293
 
294
+ exports.HEAD_LINK_NAME = HEAD_LINK_NAME;
295
+ exports.HEAD_MARK = HEAD_MARK;
296
+ exports.HEAD_META_NAME = HEAD_META_NAME;
193
297
  exports.HEAD_NAME = HEAD_NAME;
194
- exports.createTitleKeeper = createTitleKeeper;
298
+ exports.HEAD_NAMES = HEAD_NAMES;
299
+ exports.HEAD_SCRIPT_NAME = HEAD_SCRIPT_NAME;
300
+ exports.HEAD_TITLE_NAME = HEAD_TITLE_NAME;
301
+ exports.OWN_MARK = OWN_MARK;
302
+ exports.createHeadKeeper = createHeadKeeper;
303
+ exports.headKeyOf = headKeyOf;
195
304
  exports.headOf = headOf;
196
305
  exports.isHeadNode = isHeadNode;
197
306
  exports.placeHead = placeHead;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/layout/head.ts","../../src/shell/slot-names.ts","../../src/shell/head.ts","../../src/document/place-head.ts","../../src/document/title.ts"],"names":["said"],"mappings":";;;AAwBO,IAAM,SAAA,GAAY;;;ACRlB,IAAM,gBAAA,GAAmB,YAAA;AACzB,IAAM,gBAAA,GAAmB,YAAA;;;ACYhC,IAAM,IAAA,GAAO,CAAC,KAAA,KAAwC,OAAO,KAAA,KAAU,YAAY,KAAA,CAAM,IAAA,EAAK,KAAM,EAAA,GAAK,KAAA,GAAQ,MAAA;AAEjH,IAAM,QAAA,GAAW,CAAC,KAAA,KAAqD,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AAE1I,IAAM,YAAA,GAAe,CAAC,KAAA,KAAuC;AAC3D,EAAA,IAAI,QAAA,CAAS,KAAK,CAAA,EAAG,OAAO,KAAA;AAC5B,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,IAAK,KAAA,CAAM,MAAA,GAAS,CAAA,IAAK,KAAA,CAAM,KAAA,CAAM,QAAQ,CAAA,EAAG,OAAO,KAAA;AAC9E,EAAA,OAAO,MAAA;AACT,CAAA;AAIA,IAAM,QAAA,GAAW,CAAC,KAAA,KAAyC;AACzD,EAAA,MAAM,CAAC,OAAO,WAAA,EAAa,KAAK,IAAI,CAAC,IAAA,CAAK,MAAM,OAAO,CAAC,GAAG,IAAA,CAAK,KAAA,CAAM,aAAa,CAAC,CAAA,EAAG,KAAK,KAAA,CAAM,OAAO,CAAC,CAAC,CAAA;AAC3G,EAAA,MAAM,IAAA,GAAO,KAAA,CAAM,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IAAAA,KAAAA,GAAO,KAAA;AACP,IAAA,MAAM,OAAO,KAAA,IAAS,GAAA;AACtB,IAAA,IAAI,GAAA,CAAI,KAAA,KAAU,IAAA,EAAM,GAAA,CAAI,KAAA,GAAQ,IAAA;AAAA,EACtC,CAAA;AACF","file":"index.cjs","sourcesContent":["// ═══════════════════════════════════════════════════════════\n// THE HEAD — what a screen says it is, as a node in its layout.\n//\n// A document has a part nobody sees on the screen: its title, the sentence\n// that describes it, the picture shown where a link to it is pasted. Those are\n// facts about what the screen shows, so they come from where everything else\n// on the screen comes from — a layout node, its props bound to the action's\n// data — and travel the way everything else does, in the render tree.\n//\n// The node draws nothing. No adapter builds an element for it and no registry\n// has to hold it. Whoever writes the document reads it off the tree (`headOf`)\n// and says it in the surface's own terms: a browser's <head>, a tab's title.\n//\n// The props say what the screen IS, from a closed set of names\n// (./head.schema). How that is spelled in tags is the writer's business, and\n// where the document lives (its address) is not the screen's to say at all — a\n// layout never holds a URL of its own page.\n//\n// This file holds no schema on purpose: a terminal that only reads a head off\n// the wire needs the name and the shape, and nothing to validate with.\n// ═══════════════════════════════════════════════════════════\n\n// Namespaced as a package's own in-layout components are (`loom:field`), so it\n// can never be a name an app's kit already uses for something else.\nexport const HEAD_NAME = 'nova:head';\n\n// What a head node said, once its bindings are resolved and anything it left\n// empty is gone.\nexport type Head = {\n title?: string;\n description?: string;\n image?: string;\n kind?: 'website' | 'article';\n structured?: Record<string, unknown> | Record<string, unknown>[];\n};\n","// ═══════════════════════════════════════════════════════════\n// Slot component name constants.\n//\n// Every framework adapter (React, future Vue/Svelte/etc.) must\n// register components under these names in its ComponentRegistry\n// to participate in shell/canvas layout rendering:\n//\n// CANVAS_SLOT_NAME — renders a canvas by id (props: canvasId?)\n// ACTION_SLOT_NAME — renders an action instance by id (props: instanceId?)\n//\n// The shell uses these names in its default layouts and when\n// flattening a render tree for non-React consumers (evaluators,\n// export, testing), so they are part of the package's public\n// contract — not React-only.\n// ═══════════════════════════════════════════════════════════\n\nexport const CANVAS_SLOT_NAME = 'CanvasSlot';\nexport const ACTION_SLOT_NAME = 'ActionSlot';\n","import { HEAD_NAME } from '../layout/head';\nimport type { Head } from '../layout/head';\nimport type { RenderNode } from '../layout';\nimport type { RenderApi } from './types';\nimport { ACTION_SLOT_NAME, CANVAS_SLOT_NAME } from './slot-names';\n\n// ═══════════════════════════════════════════════════════════\n// The head a screen has, read off its render tree.\n//\n// The frame is walked in the order it is drawn, into each canvas where its\n// slot stands and into each instance on it. A screen can hold more than one\n// head node — a dialog opened over a page — and then THE LAST ONE SPEAKS, whole:\n// two heads are two things, and a title from one beside a description from the\n// other describes neither.\n//\n// A node that says nothing (its bindings are not answered yet) is still the\n// one that speaks: the document keeps what it had rather than borrow from a\n// screen underneath.\n// ═══════════════════════════════════════════════════════════\n\nexport type ScreenHead = {\n head: Head;\n // the action whose instance the node stands in; absent for a node in the\n // frame or in a canvas's own layout\n action?: string;\n};\n\ntype Found = { props: Record<string, unknown>; action: string | undefined };\n\nconst said = (value: unknown): string | undefined => (typeof value === 'string' && value.trim() !== '' ? value : undefined);\n\nconst isObject = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === 'object' && !Array.isArray(value);\n\nconst structuredOf = (value: unknown): Head['structured'] => {\n if (isObject(value)) return value;\n if (Array.isArray(value) && value.length > 0 && value.every(isObject)) return value;\n return undefined;\n};\n\n// A prop that is not one of the names, or holds something other than what its\n// name takes, is left out — the document keeps what it had there.\nconst headFrom = (props: Record<string, unknown>): Head => {\n const [title, description, image] = [said(props['title']), said(props['description']), said(props['image'])];\n const kind = props['kind'] === 'website' || props['kind'] === 'article' ? props['kind'] : undefined;\n const structured = structuredOf(props['structured']);\n return {\n ...(title !== undefined ? { title } : {}),\n ...(description !== undefined ? { description } : {}),\n ...(image !== undefined ? { image } : {}),\n ...(kind !== undefined ? { kind } : {}),\n ...(structured !== undefined ? { structured } : {}),\n };\n};\n\nexport const isHeadNode = (node: RenderNode): boolean => node.type === 'component' && node.name === HEAD_NAME;\n\nexport const headOf = (api: Pick<RenderApi, 'frame' | 'canvasTree'>): ScreenHead | undefined => {\n const found: Found[] = [];\n // a canvas whose own tree names it again would never end\n const open = new Set<string>();\n\n const walk = (nodes: readonly RenderNode[], action: string | undefined): void => {\n for (const node of nodes) {\n if (node.type === 'fragment') {\n walk(node.children, action);\n continue;\n }\n if (node.type !== 'component') continue;\n if (node.name === HEAD_NAME) {\n found.push({ props: node.props, action });\n continue;\n }\n if (node.name === CANVAS_SLOT_NAME) {\n const canvasId = node.props['canvasId'];\n if (typeof canvasId !== 'string' || canvasId === '' || open.has(canvasId)) continue;\n open.add(canvasId);\n walk(api.canvasTree(canvasId), undefined);\n open.delete(canvasId);\n continue;\n }\n const definitionId = node.name === ACTION_SLOT_NAME ? node.props['definitionId'] : undefined;\n walk(node.children, typeof definitionId === 'string' ? definitionId : action);\n }\n };\n\n walk(api.frame(), undefined);\n const last = found[found.length - 1];\n if (last === undefined) return undefined;\n return { head: headFrom(last.props), ...(last.action !== undefined ? { action: last.action } : {}) };\n};\n","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","import type { Head } from '../layout/head';\n\n// ═══════════════════════════════════════════════════════════\n// The tab's title follows the screen.\n//\n// A drawn page arrives with its head written (`placeHead`). From then on the\n// shell is live and the screen moves without the page being fetched again, so\n// the one part of a head a person can see — the title — is kept on whatever\n// head the screen has now.\n//\n// A screen with no head has the document's own title: the one `index.html`\n// was written with, which a drawn page keeps beside the screen's (`data-own`).\n//\n// A keeper that was never handed a head never writes. Two shells can share a\n// page (an inspector beside the app), and the one with nothing to say must not\n// take the title back from the one that has.\n// ═══════════════════════════════════════════════════════════\n\nexport type TitleKeeper = (head: Head | undefined) => void;\n\nexport const createTitleKeeper = (doc: Pick<Document, 'title' | 'querySelector'>): TitleKeeper => {\n const own = doc.querySelector('title')?.getAttribute('data-own') ?? doc.title;\n let said: string | undefined;\n return (head) => {\n const title = head?.title;\n if (title === said) return;\n said = title;\n const next = title ?? own;\n if (doc.title !== next) doc.title = next;\n };\n};\n"]}
1
+ {"version":3,"sources":["../../src/layout/head.ts","../../src/shell/slot-names.ts","../../src/shell/head.ts","../../src/document/place-head.ts","../../src/document/head-keeper.ts"],"names":["attributesOf","written","TAGS"],"mappings":";;;AA+BO,IAAM,SAAA,GAAY;AAClB,IAAM,eAAA,GAAkB;AACxB,IAAM,cAAA,GAAiB;AACvB,IAAM,cAAA,GAAiB;AACvB,IAAM,gBAAA,GAAmB;AAIzB,IAAM,aAAgC,CAAC,SAAA,EAAW,eAAA,EAAiB,cAAA,EAAgB,gBAAgB,gBAAgB;AAenH,IAAM,SAAA,GAAY,CAAC,OAAA,KAAyE;AACjG,EAAA,MAAM,IAAA,GAAO,CAAC,IAAA,KAAqC;AACjD,IAAA,MAAM,KAAA,GAAQ,OAAO,OAAA,CAAQ,OAAA,CAAQ,UAAU,CAAA,CAAE,IAAA,CAAK,CAAC,CAAC,GAAG,MAAM,GAAA,CAAI,WAAA,OAAkB,IAAI,CAAA,GAAI,CAAC,CAAA,CAAE,IAAA,GAAO,WAAA,EAAY;AACrH,IAAA,OAAO,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,EAAA,GAAK,MAAA,GAAY,KAAA;AAAA,EAC3D,CAAA;AACA,EAAA,IAAI,OAAA,CAAQ,GAAA,KAAQ,OAAA,EAAS,O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I,CAAC,KAAK,MAAA,CAAO,CAAC,IAAA,KAAS,CAAC,IAAA,CAAK,GAAA,CAAI,KAAK,GAAG,CAAC,CAAA,EAAG,IAAA,CAAK,MAAA,CAAO,CAAC,IAAA,KAAS,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,GAAG,CAAC,CAAC,CAAA;AAC5G,IAAA,KAAA,MAAW,IAAA,IAAQ,CAAC,GAAG,IAAI,EAAE,OAAA,EAAQ,EAAG,GAAA,CAAI,IAAA,CAAK,YAAA,CAAa,IAAA,CAAK,MAAM,IAAA,CAAK,MAAA,KAAW,QAAQ,IAAA,CAAK,MAAA,CAAO,eAAe,GAAA,CAAI,IAAA,GAAO,IAAA,CAAK,MAAA,GAAS,IAAI,CAAA;AACzJ,IAAA,IAAA,GAAO,KAAA;AAEP,IAAA,GAAA,CAAI,IAAA,CAAK,MAAA,CAAO,GAAG,IAAI,CAAA;AAAA,EACzB,CAAA;AACF","file":"index.cjs","sourcesContent":["// ═══════════════════════════════════════════════════════════\n// THE HEAD — `nova:head` is the document's <head>, as a node in a layout.\n//\n// A document has a part nobody sees on the screen: its title, the sentence\n// that describes it, the card shown where a link to it is pasted. That part\n// is written the way the rest of the screen is — a layout node, its children\n// bound to the action's data — and travels the way the rest does, in the\n// render tree.\n//\n// Its children are the elements a head holds, named as HTML names them:\n// `nova:title`, `nova:meta`, `nova:link`, `nova:script`. A child's props are\n// that element's ATTRIBUTES, written as given. Nova keeps no list of them, so\n// any `name`, `property` or `rel` there is — or will be — can be said without\n// nova learning it.\n//\n// Nothing here is drawn on the screen. No adapter builds an element for a head\n// or for anything in it, and no registry has to hold the names. Whoever writes\n// the document reads the elements off the tree (`headOf`) and writes them into\n// its <head>.\n//\n// WHAT A HEAD DOES NOT HOLD is what runs or styles: a script that executes, a\n// stylesheet, a <base>, an instruction to the browser (`http-equiv`), a handler\n// attribute. A layout is data, and data that reaches every page must not be\n// able to run. Those stay in the app's own index.html, which holds anything.\n//\n// This file holds no schema on purpose: a terminal that only reads a head off\n// the wire needs the names and the shape, and nothing to validate with.\n// ═══════════════════════════════════════════════════════════\n\n// Namespaced as a package's own in-layout components are (`loom:field`), so\n// none can be a name an app's kit already uses for something else.\nexport const HEAD_NAME = 'nova:head';\nexport const HEAD_TITLE_NAME = 'nova:title';\nexport const HEAD_META_NAME = 'nova:meta';\nexport const HEAD_LINK_NAME = 'nova:link';\nexport const HEAD_SCRIPT_NAME = 'nova:script';\n\n// The head and what it holds: the names a layout may use with no registry\n// entry behind them.\nexport const HEAD_NAMES: readonly string[] = [HEAD_NAME, HEAD_TITLE_NAME, HEAD_META_NAME, HEAD_LINK_NAME, HEAD_SCRIPT_NAME];\n\n// One element of a head, as data: what to write, wherever a head is written.\nexport type HeadElement = {\n tag: 'title' | 'meta' | 'link' | 'script';\n // as the layout gave them, in the order it gave them\n attributes: Record<string, string>;\n // a title's words; a script's data, as JSON\n text?: string;\n};\n\n// What two elements both say, when they say the same thing — the later one\n// then takes the earlier one's place. A document has one title, one <meta> of\n// a given name or property, one canonical address. Anything else stands beside\n// its like: two alternates, two data blocks.\nexport const headKeyOf = (element: Pick<HeadElement, 'tag' | 'attributes'>): string | undefined => {\n const said = (name: string): string | undefined => {\n const found = Object.entries(element.attributes).find(([key]) => key.toLowerCase() === name)?.[1].trim().toLowerCase();\n return found === undefined || found === '' ? undefined : found;\n };\n if (element.tag === 'title') return 'title';\n if (element.tag === 'meta') {\n const [name, property] = [said('name'), said('property')];\n if (name !== undefined) return `meta name ${name}`;\n return property === undefined ? undefined : `meta property ${property}`;\n }\n if (element.tag === 'link') return (said('rel') ?? '').split(/\\s+/).includes('canonical') ? 'link canonical' : undefined;\n return undefined;\n};\n","// ═══════════════════════════════════════════════════════════\n// Slot component name constants.\n//\n// Every framework adapter (React, future Vue/Svelte/etc.) must\n// register components under these names in its ComponentRegistry\n// to participate in shell/canvas layout rendering:\n//\n// CANVAS_SLOT_NAME — renders a canvas by id (props: canvasId?)\n// ACTION_SLOT_NAME — renders an action instance by id (props: instanceId?)\n//\n// The shell uses these names in its default layouts and when\n// flattening a render tree for non-React consumers (evaluators,\n// export, testing), so they are part of the package's public\n// contract — not React-only.\n// ═══════════════════════════════════════════════════════════\n\nexport const CANVAS_SLOT_NAME = 'CanvasSlot';\nexport const ACTION_SLOT_NAME = 'ActionSlot';\n","import { HEAD_LINK_NAME, HEAD_META_NAME, HEAD_NAME, HEAD_SCRIPT_NAME, HEAD_TITLE_NAME, headKeyOf } from '../layout/head';\nimport type { HeadElement } from '../layout/head';\nimport type { RenderNode } from '../layout';\nimport type { RenderApi } from './types';\nimport { ACTION_SLOT_NAME, CANVAS_SLOT_NAME } from './slot-names';\n\n// ═══════════════════════════════════════════════════════════\n// The head a screen has, read off its render tree.\n//\n// The frame is walked in the order it is drawn, into each canvas where its\n// slot stands and into each instance on it, and every `nova:head` it meets\n// gives its elements in turn. A screen can hold more than one head — the\n// shell's chrome says what holds on every screen, an action says its own, a\n// dialog opens over a page. An element that says the same thing as an earlier\n// one (the title, a <meta> of that name) takes its place; anything else stands\n// beside what came before.\n//\n// What a head may not hold is refused here, once, for every writer: the\n// element is left out and the reason is given. See ../layout/head.\n// ═══════════════════════════════════════════════════════════\n\nexport type ScreenHead = {\n // what the document's head is to hold, in the order the screen said it\n elements: HeadElement[];\n // the actions whose instances said any of it (none: only the shell's chrome did)\n actions: string[];\n // what a head held that it may not — left out, each with why\n refused: string[];\n};\n\ntype ComponentNode = Extract<RenderNode, { type: 'component' }>;\ntype Read = { element: HeadElement } | { refused: string } | undefined;\n\nconst ATTRIBUTE_NAME = /^[A-Za-z][A-Za-z0-9:._-]*$/;\n// a data block: a type no browser runs\nconst DATA_TYPE = /^application\\/([a-z0-9.-]+\\+)?json$/i;\n\n// A prop, as the attribute it is written as — or nothing, when it says nothing.\nconst written = (value: unknown): string | undefined => {\n if (typeof value === 'string') return value.trim() === '' ? undefined : value;\n if (typeof value === 'number') return String(value);\n return value === true ? '' : undefined;\n};\n\n// An element's attributes, from its props — or why it may not be written.\nconst attributesOf = (what: string, props: Record<string, unknown>, skip: readonly string[] = []): { attributes: Record<string, string> } | { refused: string } => {\n const attributes: Record<string, string> = {};\n for (const [name, value] of Object.entries(props)) {\n if (skip.includes(name)) continue;\n if (!ATTRIBUTE_NAME.test(name)) return { refused: `${what}: \"${name}\" is not an attribute’s name` };\n if (/^on/i.test(name)) return { refused: `${what}: \\`${name}\\` is a handler, and a layout does not run` };\n const text = written(value);\n if (text !== undefined) attributes[name] = text;\n }\n return { attributes };\n};\n\nconst has = (attributes: Record<string, string>, name: string): boolean => Object.keys(attributes).some((key) => key.toLowerCase() === name);\nconst valueOf = (attributes: Record<string, string>, name: string): string => Object.entries(attributes).find(([key]) => key.toLowerCase() === name)?.[1] ?? '';\n\nconst textOf = (nodes: readonly RenderNode[]): string =>\n nodes.map((node) => (node.type === 'text' ? node.value : node.type === 'fragment' ? textOf(node.children) : '')).join('');\n\nconst titleOf = (node: ComponentNode): Read => {\n const text = textOf(node.children).trim();\n return text === '' ? undefined : { element: { tag: 'title', attributes: {}, text } };\n};\n\nconst metaOf = (node: ComponentNode): Read => {\n const read = attributesOf(HEAD_META_NAME, node.props);\n if ('refused' in read) return read;\n if (has(read.attributes, 'http-equiv')) return { refused: `${HEAD_META_NAME}: \\`http-equiv\\` instructs the browser, and a layout does not` };\n // nothing to say yet: its value is not answered\n return has(read.attributes, 'content') ? { element: { tag: 'meta', attributes: read.attributes } } : undefined;\n};\n\nconst linkOf = (node: ComponentNode): Read => {\n const read = attributesOf(HEAD_LINK_NAME, node.props);\n if ('refused' in read) return read;\n if (valueOf(read.attributes, 'rel').toLowerCase().split(/\\s+/).includes('stylesheet')) return { refused: `${HEAD_LINK_NAME}: a stylesheet styles the page, and a layout does not` };\n return has(read.attributes, 'href') ? { element: { tag: 'link', attributes: read.attributes } } : undefined;\n};\n\nconst scriptOf = (node: ComponentNode): Read => {\n const read = attributesOf(HEAD_SCRIPT_NAME, node.props, ['data']);\n if ('refused' in read) return read;\n if (has(read.attributes, 'src')) return { refused: `${HEAD_SCRIPT_NAME}: a script with a \\`src\\` runs, and a layout does not` };\n const type = valueOf(read.attributes, 'type');\n if (!DATA_TYPE.test(type)) return { refused: `${HEAD_SCRIPT_NAME}: only a data block may be written (a JSON \\`type\\`), and \"${type}\" is not one` };\n const data = node.props['data'];\n if (data === undefined || data === null || data === '') return undefined;\n return { element: { tag: 'script', attributes: read.attributes, text: JSON.stringify(data) } };\n};\n\nconst READERS: Record<string, (node: ComponentNode) => Read> = {\n [HEAD_TITLE_NAME]: titleOf,\n [HEAD_META_NAME]: metaOf,\n [HEAD_LINK_NAME]: linkOf,\n [HEAD_SCRIPT_NAME]: scriptOf,\n};\n\nexport const isHeadNode = (node: RenderNode): boolean => node.type === 'component' && node.name === HEAD_NAME;\n\nexport const headOf = (api: Pick<RenderApi, 'frame' | 'canvasTree'>): ScreenHead | undefined => {\n let heads = 0;\n const said: { element: HeadElement; action: string | undefined }[] = [];\n const refused: string[] = [];\n // a canvas whose own tree names it again would never end\n const open = new Set<string>();\n\n const hold = (nodes: readonly RenderNode[], action: string | undefined): void => {\n for (const node of nodes) {\n if (node.type === 'fragment') {\n hold(node.children, action);\n continue;\n }\n if (node.type === 'error') {\n refused.push(`${HEAD_NAME}: ${node.message}`);\n continue;\n }\n // text between a head's elements is nothing\n if (node.type !== 'component') continue;\n const read = READERS[node.name];\n if (read === undefined) {\n refused.push(`${HEAD_NAME}: \"${node.name}\" is not something a head holds`);\n continue;\n }\n const found = read(node);\n if (found === undefined) continue;\n if ('refused' in found) {\n refused.push(found.refused);\n continue;\n }\n const key = headKeyOf(found.element);\n const earlier = key === undefined ? -1 : said.findIndex((other) => headKeyOf(other.element) === key);\n if (earlier >= 0) said.splice(earlier, 1);\n said.push({ element: found.element, action });\n }\n };\n\n const walk = (nodes: readonly RenderNode[], action: string | undefined): void => {\n for (const node of nodes) {\n if (node.type === 'fragment') {\n walk(node.children, action);\n continue;\n }\n if (node.type !== 'component') continue;\n if (node.name === HEAD_NAME) {\n heads += 1;\n hold(node.children, action);\n continue;\n }\n if (node.name === CANVAS_SLOT_NAME) {\n const canvasId = node.props['canvasId'];\n if (typeof canvasId !== 'string' || canvasId === '' || open.has(canvasId)) continue;\n open.add(canvasId);\n walk(api.canvasTree(canvasId), undefined);\n open.delete(canvasId);\n continue;\n }\n const definitionId = node.name === ACTION_SLOT_NAME ? node.props['definitionId'] : undefined;\n walk(node.children, typeof definitionId === 'string' ? definitionId : action);\n }\n };\n\n walk(api.frame(), undefined);\n if (heads === 0) return undefined;\n const actions = [...new Set(said.flatMap((one) => (one.action === undefined ? [] : [one.action])))];\n return { elements: said.map((one) => one.element), actions, refused };\n};\n","import { headKeyOf } from '../layout/head';\nimport type { HeadElement } 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. Its <head> is what holds on every page; the screen's head elements are\n// what this page says. An element that says the same thing as a tag the\n// document already has — its <title>, a <meta> of that name or property, its\n// canonical address — takes that tag's place, where it stood. Anything else is\n// added after what is there. Everything the screen does not speak of is left\n// exactly as it was: the icon, the viewport, the stylesheet.\n//\n// TWO THINGS ARE KEPT FOR THE PAGE ITSELF, which goes on living after the file\n// is read (./head-keeper). What was written is marked (`data-nova-head`), so\n// the page can tell the screen's elements from the document's own. And a tag\n// that gave up its place is kept, inert, in a <template data-nova-own>: when\n// the screen moves on to one that no longer says it, the document's own comes\n// back.\n//\n// WHERE the document lives is known to whoever writes the file: the site plus\n// the path it was drawn at. With a `site`, every path is given its own\n// canonical address, whether or not its screen has a head. That address is the\n// document's own for this path — unmarked, and it stays when the screen moves\n// on. A screen that says a canonical address itself is taken at its word.\n//\n// With nothing to write, 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.\n site?: string;\n // The path this document was drawn at.\n path?: string;\n};\n\nexport const HEAD_MARK = 'data-nova-head';\nexport const OWN_MARK = 'data-nova-own';\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 = (json: string): string =>\n LINE_ENDS.reduce((text, code) => text.split(String.fromCharCode(code)).join(`\\\\u${code.toString(16)}`), json.replace(/</g, '\\\\u003c'));\n\n// What stands in a head, read a tag at a time: comments and the bodies of\n// scripts, styles and templates are passed over whole, so a tag written inside\n// one is not mistaken for a tag.\nconst ATTRIBUTES = `((?:[^>\"']|\"[^\"]*\"|'[^']*')*)`;\nconst TAGS = new RegExp(`<!--[\\\\s\\\\S]*?-->|<(script|style|title|template)\\\\b${ATTRIBUTES}>([\\\\s\\\\S]*?)<\\\\/\\\\1\\\\s*>|<(meta|link)\\\\b${ATTRIBUTES}>`, 'gi');\nconst ATTRIBUTE = /([^\\s\"'=<>/]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+)))?/g;\n\ntype Tag = { start: number; end: number; name: string; attributes: Record<string, string>; inner: string; text: string };\n\nconst attributesOf = (source: string): Record<string, string> => {\n const attributes: Record<string, string> = {};\n for (const match of source.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 tagsOf = (section: string): Tag[] => {\n const tags: Tag[] = [];\n for (const match of section.matchAll(TAGS)) {\n const name = (match[1] ?? match[4])?.toLowerCase();\n if (name === undefined) continue;\n tags.push({ start: match.index, end: match.index + match[0].length, name, attributes: attributesOf(match[2] ?? match[5] ?? ''), inner: match[3] ?? '', text: match[0] });\n }\n return tags;\n};\n\n// What a tag in the document says, in the same terms as an element.\nconst keyOfTag = (tag: Tag): string | undefined =>\n tag.name === 'title' || tag.name === 'meta' || tag.name === 'link' ? headKeyOf({ tag: tag.name, attributes: tag.attributes }) : undefined;\n\n// An element, as the tag it is written as.\nconst markupOf = (element: HeadElement, marked: boolean): string => {\n const written = Object.entries(element.attributes).map(([name, value]) => (value === '' ? ` ${name}` : ` ${name}=\"${escapeAttribute(value)}\"`));\n const attributes = [...written, ...(marked ? [` ${HEAD_MARK}`] : [])].join('');\n if (element.tag === 'title') return `<title${attributes}>${escapeText(element.text ?? '')}</title>`;\n if (element.tag === 'script') return `<script${attributes}>${escapeScript(element.text ?? '')}</script>`;\n return `<${element.tag}${attributes}>`;\n};\n\n// Where the document lives, as elements: what a `site` and a path say.\nconst addressOf = (place: HeadPlace): HeadElement[] => {\n if (place.site === undefined || place.path === undefined) return [];\n const path = place.path.split(/[?#]/)[0] ?? '';\n const address = `${place.site.replace(/\\/+$/, '')}${path.startsWith('/') ? path : `/${path}`}`;\n return [\n { tag: 'link', attributes: { rel: 'canonical', href: address } },\n { tag: 'meta', attributes: { property: 'og:url', content: address } },\n ];\n};\n\nconst changed = (text: string, changes: readonly { start: number; end: number; text: string }[]): string =>\n [...changes].sort((a, b) => b.start - a.start).reduce((at, change) => `${at.slice(0, change.start)}${change.text}${at.slice(change.end)}`, text);\n\n// A head that was written before, put back as the document had it: what the\n// last screen said is taken out, and what the document gave up for it is given\n// back. A head never written comes back as it is.\nconst restored = (section: string): string =>\n changed(\n section,\n tagsOf(section).flatMap((tag) => {\n if (tag.name === 'template' && OWN_MARK in tag.attributes) return [{ start: tag.start, end: tag.end, text: tag.inner }];\n return HEAD_MARK in tag.attributes ? [{ start: tag.start, end: tag.end, text: '' }] : [];\n }),\n );\n\n// Elements, written into a head. `screen`: they are what a screen says — each\n// is marked, and a tag that gives up its place is kept for the page. Otherwise\n// they are the document's own from here on, and what they replace is gone.\nconst write = (section: string, elements: readonly HeadElement[], screen: boolean): string => {\n if (elements.length === 0) return section;\n const tags = tagsOf(section);\n const changes: { start: number; end: number; text: string }[] = [];\n const added: string[] = [];\n const own: string[] = [];\n for (const element of elements) {\n const key = headKeyOf(element);\n const [first, ...others] = key === undefined ? [] : tags.filter((tag) => keyOfTag(tag) === key);\n if (first === undefined) {\n added.push(markupOf(element, screen));\n continue;\n }\n changes.push({ start: first.start, end: first.end, text: markupOf(element, screen) });\n own.push(first.text);\n // said twice, the second would still say the old thing\n for (const other of others) {\n changes.push({ start: other.start, end: other.end, text: '' });\n own.push(other.text);\n }\n }\n if (screen && own.length > 0) added.push(`<template ${OWN_MARK}>${own.join('')}</template>`);\n\n const written = changed(section, changes);\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 `${body}${added.map((tag) => `${lead}${tag}`).join('')}${tail}`;\n};\n\nexport const placeHead = (html: string, elements: readonly HeadElement[] | undefined, place: HeadPlace = {}): string => {\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 // Where the document lives is the document's own, for this path: written\n // first and unmarked, so a screen that says an address of its own takes its\n // place — and gives it back.\n const located = write(restored(html.slice(from, from + closing)), addressOf(place), false);\n return `${html.slice(0, from)}${write(located, elements ?? [], true)}${html.slice(from + closing)}`;\n};\n","import { headKeyOf } from '../layout/head';\nimport type { HeadElement } from '../layout/head';\nimport { HEAD_MARK, OWN_MARK } from './place-head';\n\n// ═══════════════════════════════════════════════════════════\n// A page's <head>, kept on the screen.\n//\n// A drawn page arrives with its head written (`placeHead`). From then on the\n// shell is live and the screen moves without the page being fetched again, so\n// the head is kept on whatever the screen says now: its elements are put in\n// `document.head`, and taken out again when the screen stops saying them.\n//\n// THE DOCUMENT'S OWN TAGS GIVE WAY AND COME BACK. A tag the page was written\n// with — the title in index.html, its description — is taken out while the\n// screen says the same thing itself, and put back where it stood when the\n// screen no longer does. A drawn page has already given some up: they arrive\n// inert, in the <template data-nova-own> the writer left, and come back the\n// same way.\n//\n// A KEEPER THAT WAS NEVER HANDED AN ELEMENT NEVER WRITES. Two shells can share\n// a page (an inspector beside the app), and the one with nothing to say must\n// not touch what the other wrote — nor what the page arrived with.\n// ═══════════════════════════════════════════════════════════\n\nexport type HeadKeeper = (elements: readonly HeadElement[] | undefined) => void;\n\ntype Away = { key: string; node: Element; before: Node | null };\n\nconst TAGS = ['title', 'meta', 'link'];\n\n// What a tag standing in the page says, in the same terms as an element.\nconst keyOfNode = (node: Element): string | undefined => {\n const tag = TAGS.find((name) => name === node.tagName.toLowerCase());\n if (tag !== 'title' && tag !== 'meta' && tag !== 'link') return undefined;\n return headKeyOf({ tag, attributes: Object.fromEntries([...node.attributes].map((attribute) => [attribute.name, attribute.value])) });\n};\n\nexport const createHeadKeeper = (doc: Document): HeadKeeper => {\n // the screen's elements standing in the head\n let mine: Element[] = [];\n // the document's own tags that have given up their place\n let away: Away[] = [];\n let said: string | undefined;\n\n const built = (element: HeadElement): Element => {\n const node = doc.createElement(element.tag);\n for (const [name, value] of Object.entries(element.attributes)) node.setAttribute(name, value);\n node.setAttribute(HEAD_MARK, '');\n if (element.text !== undefined) node.textContent = element.text;\n return node;\n };\n\n // What the page arrived with: the elements a writer put there for the first\n // screen, and the tags that gave way to them.\n const adopt = (): void => {\n mine = [...doc.head.querySelectorAll(`[${HEAD_MARK}]`)];\n // the document's own window, not a global: a page's document is not always\n // the one the code was loaded in\n const view = doc.defaultView;\n for (const stash of doc.head.querySelectorAll(`template[${OWN_MARK}]`)) {\n if (view === null || !(stash instanceof view.HTMLTemplateElement)) continue;\n for (const child of [...stash.content.children]) {\n const key = keyOfNode(child);\n if (key !== undefined) away.push({ key, node: doc.importNode(child, true), before: null });\n }\n stash.remove();\n }\n };\n\n return (elements) => {\n const now = elements ?? [];\n const next = JSON.stringify(now);\n if (said === undefined) {\n if (now.length === 0) return;\n adopt();\n }\n if (next === said) return;\n said = next;\n\n for (const node of mine) node.remove();\n mine = now.map(built);\n const keys = new Set(now.flatMap((element) => headKeyOf(element) ?? []));\n\n // the document's own that now say what the screen says: out, each remembering where it stood\n for (const node of [...doc.head.children]) {\n const key = keyOfNode(node);\n if (key === undefined || !keys.has(key)) continue;\n away.push({ key, node, before: node.nextSibling });\n node.remove();\n }\n // Those the screen no longer says: back where each stood. The last to leave\n // goes back first — what stood after an earlier one may have left after it,\n // and has to be standing again for the earlier one to go in front of it.\n const [back, still] = [away.filter((gone) => !keys.has(gone.key)), away.filter((gone) => keys.has(gone.key))];\n for (const gone of [...back].reverse()) doc.head.insertBefore(gone.node, gone.before !== null && gone.before.parentNode === doc.head ? gone.before : null);\n away = still;\n\n doc.head.append(...mine);\n };\n};\n"]}
@@ -1,9 +1,9 @@
1
- import { a as Head } from '../head-BNj8GwPO.cjs';
2
- export { H as HEAD_NAME, S as ScreenHead, h as headOf, i as isHeadNode } from '../head-BNj8GwPO.cjs';
3
- import '../types-BLVRduoz.cjs';
1
+ import { f as HeadElement } from '../head-CAzfTnpV.cjs';
2
+ export { H as HEAD_LINK_NAME, a as HEAD_META_NAME, b as HEAD_NAME, c as HEAD_NAMES, d as HEAD_SCRIPT_NAME, e as HEAD_TITLE_NAME, S as ScreenHead, h as headKeyOf, g as headOf, i as isHeadNode } from '../head-CAzfTnpV.cjs';
3
+ import '../types-j290XhCn.cjs';
4
4
  import 'zod';
5
5
  import '../schemas-DPdeFlCT.cjs';
6
- import '../types-PDXOkvtK.cjs';
6
+ import '../types-qkzTfSye.cjs';
7
7
  import '../index-caZoXSwr.cjs';
8
8
  import '../effects-CndX9K7D.cjs';
9
9
  import '../schemas-pMyyuXV7.cjs';
@@ -12,9 +12,11 @@ type HeadPlace = {
12
12
  site?: string;
13
13
  path?: string;
14
14
  };
15
- declare const placeHead: (html: string, head: Head | undefined, place?: HeadPlace) => string;
15
+ declare const HEAD_MARK = "data-nova-head";
16
+ declare const OWN_MARK = "data-nova-own";
17
+ declare const placeHead: (html: string, elements: readonly HeadElement[] | undefined, place?: HeadPlace) => string;
16
18
 
17
- type TitleKeeper = (head: Head | undefined) => void;
18
- declare const createTitleKeeper: (doc: Pick<Document, "title" | "querySelector">) => TitleKeeper;
19
+ type HeadKeeper = (elements: readonly HeadElement[] | undefined) => void;
20
+ declare const createHeadKeeper: (doc: Document) => HeadKeeper;
19
21
 
20
- export { Head, type HeadPlace, type TitleKeeper, createTitleKeeper, placeHead };
22
+ export { HEAD_MARK, HeadElement, type HeadKeeper, type HeadPlace, OWN_MARK, createHeadKeeper, placeHead };