@niscorp/nova 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADAPTER.md +6 -6
- package/CHANGELOG.md +30 -0
- package/README.md +46 -21
- package/dist/adapters/dom/components/index.d.cts +2 -2
- package/dist/adapters/dom/components/index.d.ts +2 -2
- package/dist/adapters/dom/index.cjs +163 -34
- package/dist/adapters/dom/index.cjs.map +1 -1
- package/dist/adapters/dom/index.d.cts +2 -2
- package/dist/adapters/dom/index.d.ts +2 -2
- package/dist/adapters/dom/index.js +6 -6
- package/dist/adapters/dom/server.cjs +0 -2
- package/dist/adapters/dom/server.cjs.map +1 -1
- package/dist/adapters/dom/server.d.cts +2 -2
- package/dist/adapters/dom/server.d.ts +2 -2
- package/dist/adapters/dom/server.js +6 -6
- package/dist/adapters/react/components/index.cjs +6 -8
- package/dist/adapters/react/components/index.cjs.map +1 -1
- package/dist/adapters/react/components/index.d.cts +4 -4
- package/dist/adapters/react/components/index.d.ts +4 -4
- package/dist/adapters/react/components/index.js +7 -7
- package/dist/adapters/react/index.cjs +181 -51
- package/dist/adapters/react/index.cjs.map +1 -1
- package/dist/adapters/react/index.d.cts +4 -4
- package/dist/adapters/react/index.d.ts +4 -4
- package/dist/adapters/react/index.js +7 -7
- package/dist/adapters/tty/components/index.d.cts +2 -2
- package/dist/adapters/tty/components/index.d.ts +2 -2
- package/dist/adapters/tty/index.cjs +0 -2
- package/dist/adapters/tty/index.cjs.map +1 -1
- package/dist/adapters/tty/index.d.cts +2 -2
- package/dist/adapters/tty/index.d.ts +2 -2
- package/dist/adapters/tty/index.js +4 -4
- package/dist/adapters/tty/index.js.map +1 -1
- package/dist/adapters/vue/components/index.cjs +4 -6
- package/dist/adapters/vue/components/index.cjs.map +1 -1
- package/dist/adapters/vue/components/index.d.cts +9 -9
- package/dist/adapters/vue/components/index.d.ts +9 -9
- package/dist/adapters/vue/components/index.js +7 -7
- package/dist/adapters/vue/index.cjs +175 -46
- package/dist/adapters/vue/index.cjs.map +1 -1
- package/dist/adapters/vue/index.d.cts +4 -4
- package/dist/adapters/vue/index.d.ts +4 -4
- package/dist/adapters/vue/index.js +9 -9
- package/dist/adapters/vue/index.js.map +1 -1
- package/dist/agent/index.d.cts +2 -2
- package/dist/agent/index.d.ts +2 -2
- package/dist/{chunk-7PKS7UYL.js → chunk-3JRTELLC.js} +3 -3
- package/dist/{chunk-7PKS7UYL.js.map → chunk-3JRTELLC.js.map} +1 -1
- package/dist/{chunk-4I2PFMY7.js → chunk-MHW5VEIM.js} +8 -8
- package/dist/chunk-MHW5VEIM.js.map +1 -0
- package/dist/chunk-OE4E6IBD.js +25 -0
- package/dist/chunk-OE4E6IBD.js.map +1 -0
- package/dist/{chunk-KYQ4EAQH.js → chunk-QXQCPH33.js} +17 -17
- package/dist/chunk-QXQCPH33.js.map +1 -0
- package/dist/chunk-RFBIGRCI.js +127 -0
- package/dist/chunk-RFBIGRCI.js.map +1 -0
- package/dist/{chunk-WZVQ5PUB.js → chunk-RYIIIXDX.js} +4 -4
- package/dist/{chunk-WZVQ5PUB.js.map → chunk-RYIIIXDX.js.map} +1 -1
- package/dist/{chunk-4ERQYDF6.js → chunk-UDCXGDLQ.js} +10 -10
- package/dist/chunk-UDCXGDLQ.js.map +1 -0
- package/dist/chunk-V4BPFFFV.js +152 -0
- package/dist/chunk-V4BPFFFV.js.map +1 -0
- package/dist/{chunk-UUYXVOK2.js → chunk-VU6NNCEJ.js} +16 -16
- package/dist/chunk-VU6NNCEJ.js.map +1 -0
- package/dist/{chunk-RXECI7DE.js → chunk-Y6XVPRYH.js} +33 -17
- package/dist/chunk-Y6XVPRYH.js.map +1 -0
- package/dist/devtools/index.d.cts +2 -2
- package/dist/devtools/index.d.ts +2 -2
- package/dist/devtools/index.js +3 -3
- package/dist/document/index.cjs +228 -119
- package/dist/document/index.cjs.map +1 -1
- package/dist/document/index.d.cts +10 -8
- package/dist/document/index.d.ts +10 -8
- package/dist/document/index.js +3 -122
- package/dist/document/index.js.map +1 -1
- package/dist/head-CAzfTnpV.d.cts +25 -0
- package/dist/head-DRpbbj-l.d.ts +25 -0
- package/dist/i18n/index.d.cts +2 -2
- package/dist/i18n/index.d.ts +2 -2
- package/dist/index.cjs +151 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -31
- package/dist/index.d.ts +19 -31
- package/dist/index.js +4 -4
- package/dist/{palette-Mx7XHYC6.d.ts → palette-CIpPH90W.d.ts} +1 -1
- package/dist/{palette-wbJB_svk.d.cts → palette-CvwZZCkx.d.cts} +1 -1
- package/dist/reflect/index.d.cts +2 -2
- package/dist/reflect/index.d.ts +2 -2
- package/dist/reflect/index.js +3 -3
- package/dist/{types-B-rjaUX0.d.ts → types-BSKx5MXW.d.ts} +1 -1
- package/dist/{types-B_nOtkyt.d.ts → types-BWc-olbY.d.ts} +1 -1
- package/dist/{types-mRKXqZPX.d.cts → types-C9734_lJ.d.cts} +1 -1
- package/dist/{types-BB9RXel5.d.ts → types-D23TRvqe.d.ts} +1 -1
- package/dist/{types-uk19d6KC.d.cts → types-DsWNYc7R.d.cts} +1 -1
- package/dist/{types-BLVRduoz.d.cts → types-j290XhCn.d.cts} +1 -1
- package/dist/{types-PDXOkvtK.d.cts → types-qkzTfSye.d.cts} +1 -1
- package/dist/{types-DE77Jl2W.d.ts → types-qnKMx0_V.d.ts} +1 -1
- package/package.json +3 -3
- package/dist/chunk-4ERQYDF6.js.map +0 -1
- package/dist/chunk-4I2PFMY7.js.map +0 -1
- package/dist/chunk-EHHJJLRX.js +0 -16
- package/dist/chunk-EHHJJLRX.js.map +0 -1
- package/dist/chunk-KYQ4EAQH.js.map +0 -1
- package/dist/chunk-RXECI7DE.js.map +0 -1
- package/dist/chunk-UUYXVOK2.js.map +0 -1
- package/dist/chunk-UV5YGBHQ.js +0 -62
- package/dist/chunk-UV5YGBHQ.js.map +0 -1
- package/dist/chunk-X7SSNSQC.js +0 -6
- package/dist/chunk-X7SSNSQC.js.map +0 -1
- package/dist/head-BNj8GwPO.d.cts +0 -20
- package/dist/head-CS6X6ZKr.d.ts +0 -20
- package/dist/{primitive-props-Cl5jiC8g.d.cts → primitive-props-CGoJvmcH.d.cts} +5 -5
- package/dist/{primitive-props-Cl5jiC8g.d.ts → primitive-props-CGoJvmcH.d.ts} +5 -5
package/dist/document/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { H as HEAD_NAME, S as ScreenHead, h as headOf, i as isHeadNode } from '../head-
|
|
3
|
-
import '../types-
|
|
1
|
+
import { f as HeadElement } from '../head-DRpbbj-l.js';
|
|
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-DRpbbj-l.js';
|
|
3
|
+
import '../types-qnKMx0_V.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '../schemas-DPdeFlCT.js';
|
|
6
|
-
import '../types-
|
|
6
|
+
import '../types-D23TRvqe.js';
|
|
7
7
|
import '../index-CNfzSBe2.js';
|
|
8
8
|
import '../effects-CndX9K7D.js';
|
|
9
9
|
import '../schemas-pMyyuXV7.js';
|
|
@@ -12,9 +12,11 @@ type HeadPlace = {
|
|
|
12
12
|
site?: string;
|
|
13
13
|
path?: string;
|
|
14
14
|
};
|
|
15
|
-
declare const
|
|
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
|
|
18
|
-
declare const
|
|
19
|
+
type HeadKeeper = (elements: readonly HeadElement[] | undefined) => void;
|
|
20
|
+
declare const createHeadKeeper: (doc: Document) => HeadKeeper;
|
|
19
21
|
|
|
20
|
-
export {
|
|
22
|
+
export { HEAD_MARK, HeadElement, type HeadKeeper, type HeadPlace, OWN_MARK, createHeadKeeper, placeHead };
|
package/dist/document/index.js
CHANGED
|
@@ -1,125 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { headOf, isHeadNode } from '../chunk-
|
|
3
|
-
export { HEAD_NAME } from '../chunk-
|
|
1
|
+
export { HEAD_MARK, OWN_MARK, createHeadKeeper, placeHead } from '../chunk-V4BPFFFV.js';
|
|
2
|
+
export { headOf, isHeadNode } from '../chunk-RFBIGRCI.js';
|
|
3
|
+
export { HEAD_LINK_NAME, HEAD_META_NAME, HEAD_NAME, HEAD_NAMES, HEAD_SCRIPT_NAME, HEAD_TITLE_NAME, headKeyOf } from '../chunk-OE4E6IBD.js';
|
|
4
4
|
import '../chunk-PZ5AY32C.js';
|
|
5
|
-
|
|
6
|
-
// src/document/place-head.ts
|
|
7
|
-
var escapeAttribute = (value) => value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
8
|
-
var escapeText = (value) => value.replace(/&/g, "&").replace(/</g, "<");
|
|
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, """);
|
|
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
5
|
//# sourceMappingURL=index.js.map
|
|
125
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/document/place-head.ts"],"names":[],"mappings":";;;;;;AA4BA,IAAM,eAAA,GAAkB,CAAC,KAAA,KAA0B,KAAA,CAAM,QAAQ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AAU,OAAA;AACd,EAAA,KAAA,MAAW,MAAA,IAAU,CAAC,GAAG,OAAO,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM,CAAA,CAAE,KAAA,GAAQ,CAAA,CAAE,KAAK,CAAA,EAAG;AACnE,IAAA,OAAA,GAAU,CAAA,EAAG,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,OAAO,KAAK,CAAC,CAAA,EAAG,MAAA,CAAO,IAAI,CAAA,EAAG,OAAA,CAAQ,KAAA,CAAM,MAAA,CAAO,GAAG,CAAC,CAAA,CAAA;AAAA,EACvF;AAGA,EAAA,MAAM,OAAO,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA,GAAI,CAAC,CAAA,IAAK,EAAA;AAC1C,EAAA,MAAM,OAAO,OAAA,CAAQ,KAAA,CAAM,GAAG,OAAA,CAAQ,MAAA,GAAS,KAAK,MAAM,CAAA;AAC1D,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, '&').replace(/\"/g, '"').replace(/</g, '<');\nconst escapeText = (value: string): string => value.replace(/&/g, '&').replace(/</g, '<');\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, '"'));\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"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { b as RenderNode } from './types-j290XhCn.cjs';
|
|
2
|
+
import { R as RenderApi } from './types-qkzTfSye.cjs';
|
|
3
|
+
|
|
4
|
+
declare const HEAD_NAME = "nova:head";
|
|
5
|
+
declare const HEAD_TITLE_NAME = "nova:title";
|
|
6
|
+
declare const HEAD_META_NAME = "nova:meta";
|
|
7
|
+
declare const HEAD_LINK_NAME = "nova:link";
|
|
8
|
+
declare const HEAD_SCRIPT_NAME = "nova:script";
|
|
9
|
+
declare const HEAD_NAMES: readonly string[];
|
|
10
|
+
type HeadElement = {
|
|
11
|
+
tag: 'title' | 'meta' | 'link' | 'script';
|
|
12
|
+
attributes: Record<string, string>;
|
|
13
|
+
text?: string;
|
|
14
|
+
};
|
|
15
|
+
declare const headKeyOf: (element: Pick<HeadElement, "tag" | "attributes">) => string | undefined;
|
|
16
|
+
|
|
17
|
+
type ScreenHead = {
|
|
18
|
+
elements: HeadElement[];
|
|
19
|
+
actions: string[];
|
|
20
|
+
refused: string[];
|
|
21
|
+
};
|
|
22
|
+
declare const isHeadNode: (node: RenderNode) => boolean;
|
|
23
|
+
declare const headOf: (api: Pick<RenderApi, "frame" | "canvasTree">) => ScreenHead | undefined;
|
|
24
|
+
|
|
25
|
+
export { HEAD_LINK_NAME as H, type ScreenHead as S, HEAD_META_NAME as a, HEAD_NAME as b, HEAD_NAMES as c, HEAD_SCRIPT_NAME as d, HEAD_TITLE_NAME as e, type HeadElement as f, headOf as g, headKeyOf as h, isHeadNode as i };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { b as RenderNode } from './types-qnKMx0_V.js';
|
|
2
|
+
import { R as RenderApi } from './types-D23TRvqe.js';
|
|
3
|
+
|
|
4
|
+
declare const HEAD_NAME = "nova:head";
|
|
5
|
+
declare const HEAD_TITLE_NAME = "nova:title";
|
|
6
|
+
declare const HEAD_META_NAME = "nova:meta";
|
|
7
|
+
declare const HEAD_LINK_NAME = "nova:link";
|
|
8
|
+
declare const HEAD_SCRIPT_NAME = "nova:script";
|
|
9
|
+
declare const HEAD_NAMES: readonly string[];
|
|
10
|
+
type HeadElement = {
|
|
11
|
+
tag: 'title' | 'meta' | 'link' | 'script';
|
|
12
|
+
attributes: Record<string, string>;
|
|
13
|
+
text?: string;
|
|
14
|
+
};
|
|
15
|
+
declare const headKeyOf: (element: Pick<HeadElement, "tag" | "attributes">) => string | undefined;
|
|
16
|
+
|
|
17
|
+
type ScreenHead = {
|
|
18
|
+
elements: HeadElement[];
|
|
19
|
+
actions: string[];
|
|
20
|
+
refused: string[];
|
|
21
|
+
};
|
|
22
|
+
declare const isHeadNode: (node: RenderNode) => boolean;
|
|
23
|
+
declare const headOf: (api: Pick<RenderApi, "frame" | "canvasTree">) => ScreenHead | undefined;
|
|
24
|
+
|
|
25
|
+
export { HEAD_LINK_NAME as H, type ScreenHead as S, HEAD_META_NAME as a, HEAD_NAME as b, HEAD_NAMES as c, HEAD_SCRIPT_NAME as d, HEAD_TITLE_NAME as e, type HeadElement as f, headOf as g, headKeyOf as h, isHeadNode as i };
|
package/dist/i18n/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Phrasebook, H as PhraseKeys, b as RenderNode } from '../types-
|
|
2
|
-
export { I as DEFAULT_PHRASE_KEYS, J as PhraseKeyMatcher, K as isBinding, O as isPhrase, Q as matcherFor } from '../types-
|
|
1
|
+
import { P as Phrasebook, H as PhraseKeys, b as RenderNode } from '../types-j290XhCn.cjs';
|
|
2
|
+
export { I as DEFAULT_PHRASE_KEYS, J as PhraseKeyMatcher, K as isBinding, O as isPhrase, Q as matcherFor } from '../types-j290XhCn.cjs';
|
|
3
3
|
import { A as ActionDefinition } from '../index-caZoXSwr.cjs';
|
|
4
4
|
import { L as LayoutNode } from '../schemas-DPdeFlCT.cjs';
|
|
5
5
|
import 'zod';
|
package/dist/i18n/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Phrasebook, H as PhraseKeys, b as RenderNode } from '../types-
|
|
2
|
-
export { I as DEFAULT_PHRASE_KEYS, J as PhraseKeyMatcher, K as isBinding, O as isPhrase, Q as matcherFor } from '../types-
|
|
1
|
+
import { P as Phrasebook, H as PhraseKeys, b as RenderNode } from '../types-qnKMx0_V.js';
|
|
2
|
+
export { I as DEFAULT_PHRASE_KEYS, J as PhraseKeyMatcher, K as isBinding, O as isPhrase, Q as matcherFor } from '../types-qnKMx0_V.js';
|
|
3
3
|
import { A as ActionDefinition } from '../index-CNfzSBe2.js';
|
|
4
4
|
import { L as LayoutNode } from '../schemas-DPdeFlCT.js';
|
|
5
5
|
import 'zod';
|
package/dist/index.cjs
CHANGED
|
@@ -688,6 +688,25 @@ var walkValue = (value, prose, where, pass) => {
|
|
|
688
688
|
|
|
689
689
|
// src/layout/head.ts
|
|
690
690
|
var HEAD_NAME = "nova:head";
|
|
691
|
+
var HEAD_TITLE_NAME = "nova:title";
|
|
692
|
+
var HEAD_META_NAME = "nova:meta";
|
|
693
|
+
var HEAD_LINK_NAME = "nova:link";
|
|
694
|
+
var HEAD_SCRIPT_NAME = "nova:script";
|
|
695
|
+
var HEAD_NAMES = [HEAD_NAME, HEAD_TITLE_NAME, HEAD_META_NAME, HEAD_LINK_NAME, HEAD_SCRIPT_NAME];
|
|
696
|
+
var headKeyOf = (element) => {
|
|
697
|
+
const said = (name) => {
|
|
698
|
+
const found = Object.entries(element.attributes).find(([key]) => key.toLowerCase() === name)?.[1].trim().toLowerCase();
|
|
699
|
+
return found === void 0 || found === "" ? void 0 : found;
|
|
700
|
+
};
|
|
701
|
+
if (element.tag === "title") return "title";
|
|
702
|
+
if (element.tag === "meta") {
|
|
703
|
+
const [name, property] = [said("name"), said("property")];
|
|
704
|
+
if (name !== void 0) return `meta name ${name}`;
|
|
705
|
+
return property === void 0 ? void 0 : `meta property ${property}`;
|
|
706
|
+
}
|
|
707
|
+
if (element.tag === "link") return (said("rel") ?? "").split(/\s+/).includes("canonical") ? "link canonical" : void 0;
|
|
708
|
+
return void 0;
|
|
709
|
+
};
|
|
691
710
|
|
|
692
711
|
// src/layout/renderer.ts
|
|
693
712
|
var noopOnError = (_error) => {
|
|
@@ -784,7 +803,7 @@ var renderNode = (node, chain, ctx) => {
|
|
|
784
803
|
return [];
|
|
785
804
|
};
|
|
786
805
|
var renderComponent = (node, chain, ctx) => {
|
|
787
|
-
if (node.component
|
|
806
|
+
if (!HEAD_NAMES.includes(node.component) && !ctx.registry.has(node.component)) {
|
|
788
807
|
throw new ComponentNotFoundError(
|
|
789
808
|
`Component not found in registry: ${node.component}`,
|
|
790
809
|
{ name: node.component }
|
|
@@ -1015,23 +1034,39 @@ var createComponentRegistry = () => {
|
|
|
1015
1034
|
}
|
|
1016
1035
|
};
|
|
1017
1036
|
const get = (name) => entries.get(name);
|
|
1018
|
-
const
|
|
1037
|
+
const has2 = (name) => entries.has(name);
|
|
1019
1038
|
const list = () => Array.from(entries.keys());
|
|
1020
|
-
return { register, registerAll, get, has, list };
|
|
1021
|
-
};
|
|
1022
|
-
var
|
|
1023
|
-
var
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1039
|
+
return { register, registerAll, get, has: has2, list };
|
|
1040
|
+
};
|
|
1041
|
+
var REFUSED_ATTRIBUTES = "an attribute whose name starts with `on`, or a prop whose name is not an attribute\u2019s name";
|
|
1042
|
+
var AttributeSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).describe(
|
|
1043
|
+
"An attribute\u2019s value. Text is written as given, a number as text. `true` writes the attribute with no value. `false`, an empty or blank string, and anything that is none of these (a binding not answered yet, an object, a list) leave the attribute out."
|
|
1044
|
+
);
|
|
1045
|
+
var HeadPropsSchema = zod.z.object({}).strict().describe(
|
|
1046
|
+
"The document\u2019s <head>. Takes no props. Its children are the elements the head holds \u2014 `nova:title`, `nova:meta`, `nova:link`, `nova:script` \u2014 placed directly or through loops and conditions; any other component among them is refused and left out, and the rest stand. Draws nothing on the screen. Elements are read in the order written, and where a screen holds several heads, in the order the screen is drawn. A later element takes an earlier one\u2019s place when both are the title, both are a `nova:meta` of the same `name` or `property`, or both are a `nova:link` whose `rel` includes `canonical`. Any other two stand side by side."
|
|
1047
|
+
);
|
|
1048
|
+
var HeadTitlePropsSchema = zod.z.object({}).strict().describe(
|
|
1049
|
+
"The document\u2019s <title>, inside `nova:head`. Takes no props. Its text is given as its children: a text string, which may hold bindings \u2014 not components. A title with no text is left out."
|
|
1050
|
+
);
|
|
1051
|
+
var HeadMetaPropsSchema = zod.z.record(zod.z.string(), AttributeSchema).describe(
|
|
1052
|
+
`A <meta> element, inside \`nova:head\`. Its props are the element\u2019s attributes, written as given: \`name\` or \`property\` to say what it is, \`content\` for its value. Left out while it has no \`content\`. A later one with the same \`name\` or \`property\` takes an earlier one\u2019s place (compared without regard to case; \`name\` decides when both are set), and one with neither stands beside the rest. The whole element is refused and left out if it has \`http-equiv\`, which instructs the browser rather than describing the document, ${REFUSED_ATTRIBUTES}.`
|
|
1053
|
+
);
|
|
1054
|
+
var HeadLinkPropsSchema = zod.z.record(zod.z.string(), AttributeSchema).describe(
|
|
1055
|
+
`A <link> element, inside \`nova:head\`. Its props are the element\u2019s attributes, written as given: \`rel\` to say what the link is, \`href\` for its address, and any other the element takes (\`type\`, \`hreflang\`, \`sizes\`, \`media\`). Left out while it has no \`href\`. A later one whose \`rel\` includes \`canonical\` takes an earlier canonical\u2019s place; all other links stand side by side. The whole element is refused and left out if its \`rel\` includes \`stylesheet\`, which styles the page, or it has ${REFUSED_ATTRIBUTES}.`
|
|
1056
|
+
);
|
|
1057
|
+
var HeadScriptPropsSchema = zod.z.object({
|
|
1058
|
+
type: zod.z.string().describe("The kind of data the block holds. Only a JSON type is accepted: `application/json`, or one ending in `+json` such as `application/ld+json`. Any other type, or none, is refused."),
|
|
1059
|
+
data: zod.z.unknown().describe("What the block holds: the value itself \u2014 an object, a list, a number, text \u2014 which is serialised as JSON. Not JSON already written as text. Nothing, `null` or an empty string counts as no data.")
|
|
1060
|
+
}).catchall(AttributeSchema).describe(
|
|
1061
|
+
`A <script> element that holds data, inside \`nova:head\`: \`type\`, \`data\`, and any other attribute the element takes. Left out while it has no \`data\`. Data blocks never take one another\u2019s place. It never runs: the whole element is refused and left out unless its \`type\` is a JSON type, and if it has a \`src\` or ${REFUSED_ATTRIBUTES}.`
|
|
1062
|
+
);
|
|
1063
|
+
var described = (schema) => ({ description: schema.description ?? "", propsSchema: schema });
|
|
1032
1064
|
var HEAD_META = {
|
|
1033
|
-
|
|
1034
|
-
|
|
1065
|
+
[HEAD_NAME]: described(HeadPropsSchema),
|
|
1066
|
+
[HEAD_TITLE_NAME]: described(HeadTitlePropsSchema),
|
|
1067
|
+
[HEAD_META_NAME]: described(HeadMetaPropsSchema),
|
|
1068
|
+
[HEAD_LINK_NAME]: described(HeadLinkPropsSchema),
|
|
1069
|
+
[HEAD_SCRIPT_NAME]: described(HeadScriptPropsSchema)
|
|
1035
1070
|
};
|
|
1036
1071
|
|
|
1037
1072
|
// src/agent/palette.ts
|
|
@@ -3536,7 +3571,7 @@ var createShell = (config) => {
|
|
|
3536
3571
|
}
|
|
3537
3572
|
return renderLayoutOrRef(canvasLayout ?? DEFAULT_SHELL_LAYOUT, { canvases: canvasList });
|
|
3538
3573
|
};
|
|
3539
|
-
const
|
|
3574
|
+
const titleOf2 = (instance) => {
|
|
3540
3575
|
const def = registry.get(instance.id)?.definition ?? actions[instance.definitionId];
|
|
3541
3576
|
if (def?.title !== void 0) {
|
|
3542
3577
|
const resolved = resolve(def.title, createScopeChain(instance.data));
|
|
@@ -3547,7 +3582,7 @@ var createShell = (config) => {
|
|
|
3547
3582
|
const getCanvasRenderTree = (canvasId) => {
|
|
3548
3583
|
const canvas = canvases.get(canvasId);
|
|
3549
3584
|
const state = canvas === void 0 ? { stack: []} : snapshotCanvas(canvas);
|
|
3550
|
-
const instances = state.stack.map((i) => ({ ...i, title:
|
|
3585
|
+
const instances = state.stack.map((i) => ({ ...i, title: titleOf2(i) }));
|
|
3551
3586
|
const scope = {
|
|
3552
3587
|
instances,
|
|
3553
3588
|
active: instances.length === 0 ? void 0 : instances[instances.length - 1],
|
|
@@ -3602,29 +3637,93 @@ var createShell = (config) => {
|
|
|
3602
3637
|
};
|
|
3603
3638
|
|
|
3604
3639
|
// src/shell/head.ts
|
|
3605
|
-
var
|
|
3606
|
-
var
|
|
3607
|
-
var
|
|
3608
|
-
if (
|
|
3609
|
-
if (
|
|
3610
|
-
return void 0;
|
|
3611
|
-
};
|
|
3612
|
-
var
|
|
3613
|
-
const
|
|
3614
|
-
const
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3640
|
+
var ATTRIBUTE_NAME = /^[A-Za-z][A-Za-z0-9:._-]*$/;
|
|
3641
|
+
var DATA_TYPE = /^application\/([a-z0-9.-]+\+)?json$/i;
|
|
3642
|
+
var written = (value) => {
|
|
3643
|
+
if (typeof value === "string") return value.trim() === "" ? void 0 : value;
|
|
3644
|
+
if (typeof value === "number") return String(value);
|
|
3645
|
+
return value === true ? "" : void 0;
|
|
3646
|
+
};
|
|
3647
|
+
var attributesOf = (what, props, skip = []) => {
|
|
3648
|
+
const attributes = {};
|
|
3649
|
+
for (const [name, value] of Object.entries(props)) {
|
|
3650
|
+
if (skip.includes(name)) continue;
|
|
3651
|
+
if (!ATTRIBUTE_NAME.test(name)) return { refused: `${what}: "${name}" is not an attribute\u2019s name` };
|
|
3652
|
+
if (/^on/i.test(name)) return { refused: `${what}: \`${name}\` is a handler, and a layout does not run` };
|
|
3653
|
+
const text = written(value);
|
|
3654
|
+
if (text !== void 0) attributes[name] = text;
|
|
3655
|
+
}
|
|
3656
|
+
return { attributes };
|
|
3657
|
+
};
|
|
3658
|
+
var has = (attributes, name) => Object.keys(attributes).some((key) => key.toLowerCase() === name);
|
|
3659
|
+
var valueOf = (attributes, name) => Object.entries(attributes).find(([key]) => key.toLowerCase() === name)?.[1] ?? "";
|
|
3660
|
+
var textOf = (nodes) => nodes.map((node) => node.type === "text" ? node.value : node.type === "fragment" ? textOf(node.children) : "").join("");
|
|
3661
|
+
var titleOf = (node) => {
|
|
3662
|
+
const text = textOf(node.children).trim();
|
|
3663
|
+
return text === "" ? void 0 : { element: { tag: "title", attributes: {}, text } };
|
|
3664
|
+
};
|
|
3665
|
+
var metaOf = (node) => {
|
|
3666
|
+
const read = attributesOf(HEAD_META_NAME, node.props);
|
|
3667
|
+
if ("refused" in read) return read;
|
|
3668
|
+
if (has(read.attributes, "http-equiv")) return { refused: `${HEAD_META_NAME}: \`http-equiv\` instructs the browser, and a layout does not` };
|
|
3669
|
+
return has(read.attributes, "content") ? { element: { tag: "meta", attributes: read.attributes } } : void 0;
|
|
3670
|
+
};
|
|
3671
|
+
var linkOf = (node) => {
|
|
3672
|
+
const read = attributesOf(HEAD_LINK_NAME, node.props);
|
|
3673
|
+
if ("refused" in read) return read;
|
|
3674
|
+
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` };
|
|
3675
|
+
return has(read.attributes, "href") ? { element: { tag: "link", attributes: read.attributes } } : void 0;
|
|
3676
|
+
};
|
|
3677
|
+
var scriptOf = (node) => {
|
|
3678
|
+
const read = attributesOf(HEAD_SCRIPT_NAME, node.props, ["data"]);
|
|
3679
|
+
if ("refused" in read) return read;
|
|
3680
|
+
if (has(read.attributes, "src")) return { refused: `${HEAD_SCRIPT_NAME}: a script with a \`src\` runs, and a layout does not` };
|
|
3681
|
+
const type = valueOf(read.attributes, "type");
|
|
3682
|
+
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` };
|
|
3683
|
+
const data = node.props["data"];
|
|
3684
|
+
if (data === void 0 || data === null || data === "") return void 0;
|
|
3685
|
+
return { element: { tag: "script", attributes: read.attributes, text: JSON.stringify(data) } };
|
|
3686
|
+
};
|
|
3687
|
+
var READERS = {
|
|
3688
|
+
[HEAD_TITLE_NAME]: titleOf,
|
|
3689
|
+
[HEAD_META_NAME]: metaOf,
|
|
3690
|
+
[HEAD_LINK_NAME]: linkOf,
|
|
3691
|
+
[HEAD_SCRIPT_NAME]: scriptOf
|
|
3623
3692
|
};
|
|
3624
3693
|
var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
|
|
3625
3694
|
var headOf = (api) => {
|
|
3626
|
-
|
|
3695
|
+
let heads = 0;
|
|
3696
|
+
const said = [];
|
|
3697
|
+
const refused = [];
|
|
3627
3698
|
const open = /* @__PURE__ */ new Set();
|
|
3699
|
+
const hold = (nodes, action) => {
|
|
3700
|
+
for (const node of nodes) {
|
|
3701
|
+
if (node.type === "fragment") {
|
|
3702
|
+
hold(node.children, action);
|
|
3703
|
+
continue;
|
|
3704
|
+
}
|
|
3705
|
+
if (node.type === "error") {
|
|
3706
|
+
refused.push(`${HEAD_NAME}: ${node.message}`);
|
|
3707
|
+
continue;
|
|
3708
|
+
}
|
|
3709
|
+
if (node.type !== "component") continue;
|
|
3710
|
+
const read = READERS[node.name];
|
|
3711
|
+
if (read === void 0) {
|
|
3712
|
+
refused.push(`${HEAD_NAME}: "${node.name}" is not something a head holds`);
|
|
3713
|
+
continue;
|
|
3714
|
+
}
|
|
3715
|
+
const found = read(node);
|
|
3716
|
+
if (found === void 0) continue;
|
|
3717
|
+
if ("refused" in found) {
|
|
3718
|
+
refused.push(found.refused);
|
|
3719
|
+
continue;
|
|
3720
|
+
}
|
|
3721
|
+
const key = headKeyOf(found.element);
|
|
3722
|
+
const earlier = key === void 0 ? -1 : said.findIndex((other) => headKeyOf(other.element) === key);
|
|
3723
|
+
if (earlier >= 0) said.splice(earlier, 1);
|
|
3724
|
+
said.push({ element: found.element, action });
|
|
3725
|
+
}
|
|
3726
|
+
};
|
|
3628
3727
|
const walk2 = (nodes, action) => {
|
|
3629
3728
|
for (const node of nodes) {
|
|
3630
3729
|
if (node.type === "fragment") {
|
|
@@ -3633,7 +3732,8 @@ var headOf = (api) => {
|
|
|
3633
3732
|
}
|
|
3634
3733
|
if (node.type !== "component") continue;
|
|
3635
3734
|
if (node.name === HEAD_NAME) {
|
|
3636
|
-
|
|
3735
|
+
heads += 1;
|
|
3736
|
+
hold(node.children, action);
|
|
3637
3737
|
continue;
|
|
3638
3738
|
}
|
|
3639
3739
|
if (node.name === CANVAS_SLOT_NAME) {
|
|
@@ -3649,9 +3749,9 @@ var headOf = (api) => {
|
|
|
3649
3749
|
}
|
|
3650
3750
|
};
|
|
3651
3751
|
walk2(api.frame(), void 0);
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
return {
|
|
3752
|
+
if (heads === 0) return void 0;
|
|
3753
|
+
const actions = [...new Set(said.flatMap((one) => one.action === void 0 ? [] : [one.action]))];
|
|
3754
|
+
return { elements: said.map((one) => one.element), actions, refused };
|
|
3655
3755
|
};
|
|
3656
3756
|
|
|
3657
3757
|
// src/shell/view.ts
|
|
@@ -3745,9 +3845,18 @@ exports.DefinitionValidationError = DefinitionValidationError;
|
|
|
3745
3845
|
exports.EffectSchema = EffectSchema;
|
|
3746
3846
|
exports.EndpointConfigSchema = EndpointConfigSchema;
|
|
3747
3847
|
exports.ErrorCodes = ErrorCodes;
|
|
3848
|
+
exports.HEAD_LINK_NAME = HEAD_LINK_NAME;
|
|
3748
3849
|
exports.HEAD_META = HEAD_META;
|
|
3850
|
+
exports.HEAD_META_NAME = HEAD_META_NAME;
|
|
3749
3851
|
exports.HEAD_NAME = HEAD_NAME;
|
|
3852
|
+
exports.HEAD_NAMES = HEAD_NAMES;
|
|
3853
|
+
exports.HEAD_SCRIPT_NAME = HEAD_SCRIPT_NAME;
|
|
3854
|
+
exports.HEAD_TITLE_NAME = HEAD_TITLE_NAME;
|
|
3855
|
+
exports.HeadLinkPropsSchema = HeadLinkPropsSchema;
|
|
3856
|
+
exports.HeadMetaPropsSchema = HeadMetaPropsSchema;
|
|
3750
3857
|
exports.HeadPropsSchema = HeadPropsSchema;
|
|
3858
|
+
exports.HeadScriptPropsSchema = HeadScriptPropsSchema;
|
|
3859
|
+
exports.HeadTitlePropsSchema = HeadTitlePropsSchema;
|
|
3751
3860
|
exports.LayoutNodeSchema = LayoutNodeSchema;
|
|
3752
3861
|
exports.LayoutPrimitiveSchema = LayoutPrimitiveSchema;
|
|
3753
3862
|
exports.LayoutRefNodeSchema = LayoutRefNodeSchema;
|
|
@@ -3781,6 +3890,7 @@ exports.createShell = createShell;
|
|
|
3781
3890
|
exports.fillSlots = fillSlots;
|
|
3782
3891
|
exports.getPath = getPath;
|
|
3783
3892
|
exports.hasVisibleContent = hasVisibleContent;
|
|
3893
|
+
exports.headKeyOf = headKeyOf;
|
|
3784
3894
|
exports.headOf = headOf;
|
|
3785
3895
|
exports.isComponentNode = isComponentNode;
|
|
3786
3896
|
exports.isConditionalNode = isConditionalNode;
|