@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.
Files changed (113) hide show
  1. package/ADAPTER.md +6 -6
  2. package/CHANGELOG.md +30 -0
  3. package/README.md +46 -21
  4. package/dist/adapters/dom/components/index.d.cts +2 -2
  5. package/dist/adapters/dom/components/index.d.ts +2 -2
  6. package/dist/adapters/dom/index.cjs +163 -34
  7. package/dist/adapters/dom/index.cjs.map +1 -1
  8. package/dist/adapters/dom/index.d.cts +2 -2
  9. package/dist/adapters/dom/index.d.ts +2 -2
  10. package/dist/adapters/dom/index.js +6 -6
  11. package/dist/adapters/dom/server.cjs +0 -2
  12. package/dist/adapters/dom/server.cjs.map +1 -1
  13. package/dist/adapters/dom/server.d.cts +2 -2
  14. package/dist/adapters/dom/server.d.ts +2 -2
  15. package/dist/adapters/dom/server.js +6 -6
  16. package/dist/adapters/react/components/index.cjs +6 -8
  17. package/dist/adapters/react/components/index.cjs.map +1 -1
  18. package/dist/adapters/react/components/index.d.cts +4 -4
  19. package/dist/adapters/react/components/index.d.ts +4 -4
  20. package/dist/adapters/react/components/index.js +7 -7
  21. package/dist/adapters/react/index.cjs +181 -51
  22. package/dist/adapters/react/index.cjs.map +1 -1
  23. package/dist/adapters/react/index.d.cts +4 -4
  24. package/dist/adapters/react/index.d.ts +4 -4
  25. package/dist/adapters/react/index.js +7 -7
  26. package/dist/adapters/tty/components/index.d.cts +2 -2
  27. package/dist/adapters/tty/components/index.d.ts +2 -2
  28. package/dist/adapters/tty/index.cjs +0 -2
  29. package/dist/adapters/tty/index.cjs.map +1 -1
  30. package/dist/adapters/tty/index.d.cts +2 -2
  31. package/dist/adapters/tty/index.d.ts +2 -2
  32. package/dist/adapters/tty/index.js +4 -4
  33. package/dist/adapters/tty/index.js.map +1 -1
  34. package/dist/adapters/vue/components/index.cjs +4 -6
  35. package/dist/adapters/vue/components/index.cjs.map +1 -1
  36. package/dist/adapters/vue/components/index.d.cts +9 -9
  37. package/dist/adapters/vue/components/index.d.ts +9 -9
  38. package/dist/adapters/vue/components/index.js +7 -7
  39. package/dist/adapters/vue/index.cjs +175 -46
  40. package/dist/adapters/vue/index.cjs.map +1 -1
  41. package/dist/adapters/vue/index.d.cts +4 -4
  42. package/dist/adapters/vue/index.d.ts +4 -4
  43. package/dist/adapters/vue/index.js +9 -9
  44. package/dist/adapters/vue/index.js.map +1 -1
  45. package/dist/agent/index.d.cts +2 -2
  46. package/dist/agent/index.d.ts +2 -2
  47. package/dist/{chunk-7PKS7UYL.js → chunk-3JRTELLC.js} +3 -3
  48. package/dist/{chunk-7PKS7UYL.js.map → chunk-3JRTELLC.js.map} +1 -1
  49. package/dist/{chunk-4I2PFMY7.js → chunk-MHW5VEIM.js} +8 -8
  50. package/dist/chunk-MHW5VEIM.js.map +1 -0
  51. package/dist/chunk-OE4E6IBD.js +25 -0
  52. package/dist/chunk-OE4E6IBD.js.map +1 -0
  53. package/dist/{chunk-KYQ4EAQH.js → chunk-QXQCPH33.js} +17 -17
  54. package/dist/chunk-QXQCPH33.js.map +1 -0
  55. package/dist/chunk-RFBIGRCI.js +127 -0
  56. package/dist/chunk-RFBIGRCI.js.map +1 -0
  57. package/dist/{chunk-WZVQ5PUB.js → chunk-RYIIIXDX.js} +4 -4
  58. package/dist/{chunk-WZVQ5PUB.js.map → chunk-RYIIIXDX.js.map} +1 -1
  59. package/dist/{chunk-4ERQYDF6.js → chunk-UDCXGDLQ.js} +10 -10
  60. package/dist/chunk-UDCXGDLQ.js.map +1 -0
  61. package/dist/chunk-V4BPFFFV.js +152 -0
  62. package/dist/chunk-V4BPFFFV.js.map +1 -0
  63. package/dist/{chunk-UUYXVOK2.js → chunk-VU6NNCEJ.js} +16 -16
  64. package/dist/chunk-VU6NNCEJ.js.map +1 -0
  65. package/dist/{chunk-RXECI7DE.js → chunk-Y6XVPRYH.js} +33 -17
  66. package/dist/chunk-Y6XVPRYH.js.map +1 -0
  67. package/dist/devtools/index.d.cts +2 -2
  68. package/dist/devtools/index.d.ts +2 -2
  69. package/dist/devtools/index.js +3 -3
  70. package/dist/document/index.cjs +228 -119
  71. package/dist/document/index.cjs.map +1 -1
  72. package/dist/document/index.d.cts +10 -8
  73. package/dist/document/index.d.ts +10 -8
  74. package/dist/document/index.js +3 -122
  75. package/dist/document/index.js.map +1 -1
  76. package/dist/head-CAzfTnpV.d.cts +25 -0
  77. package/dist/head-DRpbbj-l.d.ts +25 -0
  78. package/dist/i18n/index.d.cts +2 -2
  79. package/dist/i18n/index.d.ts +2 -2
  80. package/dist/index.cjs +151 -41
  81. package/dist/index.cjs.map +1 -1
  82. package/dist/index.d.cts +19 -31
  83. package/dist/index.d.ts +19 -31
  84. package/dist/index.js +4 -4
  85. package/dist/{palette-Mx7XHYC6.d.ts → palette-CIpPH90W.d.ts} +1 -1
  86. package/dist/{palette-wbJB_svk.d.cts → palette-CvwZZCkx.d.cts} +1 -1
  87. package/dist/reflect/index.d.cts +2 -2
  88. package/dist/reflect/index.d.ts +2 -2
  89. package/dist/reflect/index.js +3 -3
  90. package/dist/{types-B-rjaUX0.d.ts → types-BSKx5MXW.d.ts} +1 -1
  91. package/dist/{types-B_nOtkyt.d.ts → types-BWc-olbY.d.ts} +1 -1
  92. package/dist/{types-mRKXqZPX.d.cts → types-C9734_lJ.d.cts} +1 -1
  93. package/dist/{types-BB9RXel5.d.ts → types-D23TRvqe.d.ts} +1 -1
  94. package/dist/{types-uk19d6KC.d.cts → types-DsWNYc7R.d.cts} +1 -1
  95. package/dist/{types-BLVRduoz.d.cts → types-j290XhCn.d.cts} +1 -1
  96. package/dist/{types-PDXOkvtK.d.cts → types-qkzTfSye.d.cts} +1 -1
  97. package/dist/{types-DE77Jl2W.d.ts → types-qnKMx0_V.d.ts} +1 -1
  98. package/package.json +3 -3
  99. package/dist/chunk-4ERQYDF6.js.map +0 -1
  100. package/dist/chunk-4I2PFMY7.js.map +0 -1
  101. package/dist/chunk-EHHJJLRX.js +0 -16
  102. package/dist/chunk-EHHJJLRX.js.map +0 -1
  103. package/dist/chunk-KYQ4EAQH.js.map +0 -1
  104. package/dist/chunk-RXECI7DE.js.map +0 -1
  105. package/dist/chunk-UUYXVOK2.js.map +0 -1
  106. package/dist/chunk-UV5YGBHQ.js +0 -62
  107. package/dist/chunk-UV5YGBHQ.js.map +0 -1
  108. package/dist/chunk-X7SSNSQC.js +0 -6
  109. package/dist/chunk-X7SSNSQC.js.map +0 -1
  110. package/dist/head-BNj8GwPO.d.cts +0 -20
  111. package/dist/head-CS6X6ZKr.d.ts +0 -20
  112. package/dist/{primitive-props-Cl5jiC8g.d.cts → primitive-props-CGoJvmcH.d.cts} +5 -5
  113. package/dist/{primitive-props-Cl5jiC8g.d.ts → primitive-props-CGoJvmcH.d.ts} +5 -5
@@ -12,6 +12,24 @@ var NovaShellKey = /* @__PURE__ */ Symbol.for("@niscorp/nova/adapters/vue:shell"
12
12
 
13
13
  // src/layout/head.ts
14
14
  var HEAD_NAME = "nova:head";
15
+ var HEAD_TITLE_NAME = "nova:title";
16
+ var HEAD_META_NAME = "nova:meta";
17
+ var HEAD_LINK_NAME = "nova:link";
18
+ var HEAD_SCRIPT_NAME = "nova:script";
19
+ var headKeyOf = (element) => {
20
+ const said = (name) => {
21
+ const found = Object.entries(element.attributes).find(([key]) => key.toLowerCase() === name)?.[1].trim().toLowerCase();
22
+ return found === void 0 || found === "" ? void 0 : found;
23
+ };
24
+ if (element.tag === "title") return "title";
25
+ if (element.tag === "meta") {
26
+ const [name, property] = [said("name"), said("property")];
27
+ if (name !== void 0) return `meta name ${name}`;
28
+ return property === void 0 ? void 0 : `meta property ${property}`;
29
+ }
30
+ if (element.tag === "link") return (said("rel") ?? "").split(/\s+/).includes("canonical") ? "link canonical" : void 0;
31
+ return void 0;
32
+ };
15
33
 
16
34
  // src/layout/adapter.ts
17
35
  var NOVA_MODEL_PROP = "novaModel";
@@ -37,29 +55,93 @@ var CANVAS_SLOT_NAME = "CanvasSlot";
37
55
  var ACTION_SLOT_NAME = "ActionSlot";
38
56
 
39
57
  // src/shell/head.ts
40
- var said = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
41
- var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
42
- var structuredOf = (value) => {
43
- if (isObject(value)) return value;
44
- if (Array.isArray(value) && value.length > 0 && value.every(isObject)) return value;
45
- return void 0;
58
+ var ATTRIBUTE_NAME = /^[A-Za-z][A-Za-z0-9:._-]*$/;
59
+ var DATA_TYPE = /^application\/([a-z0-9.-]+\+)?json$/i;
60
+ var written = (value) => {
61
+ if (typeof value === "string") return value.trim() === "" ? void 0 : value;
62
+ if (typeof value === "number") return String(value);
63
+ return value === true ? "" : void 0;
46
64
  };
47
- var headFrom = (props) => {
48
- const [title, description, image] = [said(props["title"]), said(props["description"]), said(props["image"])];
49
- const kind = props["kind"] === "website" || props["kind"] === "article" ? props["kind"] : void 0;
50
- const structured = structuredOf(props["structured"]);
51
- return {
52
- ...title !== void 0 ? { title } : {},
53
- ...description !== void 0 ? { description } : {},
54
- ...image !== void 0 ? { image } : {},
55
- ...kind !== void 0 ? { kind } : {},
56
- ...structured !== void 0 ? { structured } : {}
57
- };
65
+ var attributesOf = (what, props, skip = []) => {
66
+ const attributes = {};
67
+ for (const [name, value] of Object.entries(props)) {
68
+ if (skip.includes(name)) continue;
69
+ if (!ATTRIBUTE_NAME.test(name)) return { refused: `${what}: "${name}" is not an attribute\u2019s name` };
70
+ if (/^on/i.test(name)) return { refused: `${what}: \`${name}\` is a handler, and a layout does not run` };
71
+ const text = written(value);
72
+ if (text !== void 0) attributes[name] = text;
73
+ }
74
+ return { attributes };
75
+ };
76
+ var has = (attributes, name) => Object.keys(attributes).some((key) => key.toLowerCase() === name);
77
+ var valueOf = (attributes, name) => Object.entries(attributes).find(([key]) => key.toLowerCase() === name)?.[1] ?? "";
78
+ var textOf = (nodes) => nodes.map((node) => node.type === "text" ? node.value : node.type === "fragment" ? textOf(node.children) : "").join("");
79
+ var titleOf = (node) => {
80
+ const text = textOf(node.children).trim();
81
+ return text === "" ? void 0 : { element: { tag: "title", attributes: {}, text } };
82
+ };
83
+ var metaOf = (node) => {
84
+ const read = attributesOf(HEAD_META_NAME, node.props);
85
+ if ("refused" in read) return read;
86
+ if (has(read.attributes, "http-equiv")) return { refused: `${HEAD_META_NAME}: \`http-equiv\` instructs the browser, and a layout does not` };
87
+ return has(read.attributes, "content") ? { element: { tag: "meta", attributes: read.attributes } } : void 0;
88
+ };
89
+ var linkOf = (node) => {
90
+ const read = attributesOf(HEAD_LINK_NAME, node.props);
91
+ if ("refused" in read) return read;
92
+ 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` };
93
+ return has(read.attributes, "href") ? { element: { tag: "link", attributes: read.attributes } } : void 0;
94
+ };
95
+ var scriptOf = (node) => {
96
+ const read = attributesOf(HEAD_SCRIPT_NAME, node.props, ["data"]);
97
+ if ("refused" in read) return read;
98
+ if (has(read.attributes, "src")) return { refused: `${HEAD_SCRIPT_NAME}: a script with a \`src\` runs, and a layout does not` };
99
+ const type = valueOf(read.attributes, "type");
100
+ 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` };
101
+ const data = node.props["data"];
102
+ if (data === void 0 || data === null || data === "") return void 0;
103
+ return { element: { tag: "script", attributes: read.attributes, text: JSON.stringify(data) } };
104
+ };
105
+ var READERS = {
106
+ [HEAD_TITLE_NAME]: titleOf,
107
+ [HEAD_META_NAME]: metaOf,
108
+ [HEAD_LINK_NAME]: linkOf,
109
+ [HEAD_SCRIPT_NAME]: scriptOf
58
110
  };
59
111
  var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
60
112
  var headOf = (api) => {
61
- const found = [];
113
+ let heads = 0;
114
+ const said = [];
115
+ const refused = [];
62
116
  const open = /* @__PURE__ */ new Set();
117
+ const hold = (nodes, action) => {
118
+ for (const node of nodes) {
119
+ if (node.type === "fragment") {
120
+ hold(node.children, action);
121
+ continue;
122
+ }
123
+ if (node.type === "error") {
124
+ refused.push(`${HEAD_NAME}: ${node.message}`);
125
+ continue;
126
+ }
127
+ if (node.type !== "component") continue;
128
+ const read = READERS[node.name];
129
+ if (read === void 0) {
130
+ refused.push(`${HEAD_NAME}: "${node.name}" is not something a head holds`);
131
+ continue;
132
+ }
133
+ const found = read(node);
134
+ if (found === void 0) continue;
135
+ if ("refused" in found) {
136
+ refused.push(found.refused);
137
+ continue;
138
+ }
139
+ const key = headKeyOf(found.element);
140
+ const earlier = key === void 0 ? -1 : said.findIndex((other) => headKeyOf(other.element) === key);
141
+ if (earlier >= 0) said.splice(earlier, 1);
142
+ said.push({ element: found.element, action });
143
+ }
144
+ };
63
145
  const walk = (nodes, action) => {
64
146
  for (const node of nodes) {
65
147
  if (node.type === "fragment") {
@@ -68,7 +150,8 @@ var headOf = (api) => {
68
150
  }
69
151
  if (node.type !== "component") continue;
70
152
  if (node.name === HEAD_NAME) {
71
- found.push({ props: node.props, action });
153
+ heads += 1;
154
+ hold(node.children, action);
72
155
  continue;
73
156
  }
74
157
  if (node.name === CANVAS_SLOT_NAME) {
@@ -84,9 +167,9 @@ var headOf = (api) => {
84
167
  }
85
168
  };
86
169
  walk(api.frame(), void 0);
87
- const last = found[found.length - 1];
88
- if (last === void 0) return void 0;
89
- return { head: headFrom(last.props), ...last.action !== void 0 ? { action: last.action } : {} };
170
+ if (heads === 0) return void 0;
171
+ const actions = [...new Set(said.flatMap((one) => one.action === void 0 ? [] : [one.action]))];
172
+ return { elements: said.map((one) => one.element), actions, refused };
90
173
  };
91
174
 
92
175
  // src/shell/view.ts
@@ -136,21 +219,67 @@ var shellView = (shell) => ({
136
219
  }
137
220
  });
138
221
 
139
- // src/document/title.ts
140
- var createTitleKeeper = (doc) => {
141
- const own = doc.querySelector("title")?.getAttribute("data-own") ?? doc.title;
142
- let said2;
143
- return (head) => {
144
- const title = head?.title;
145
- if (title === said2) return;
146
- said2 = title;
147
- const next = title ?? own;
148
- if (doc.title !== next) doc.title = next;
222
+ // src/document/place-head.ts
223
+ var HEAD_MARK = "data-nova-head";
224
+ var OWN_MARK = "data-nova-own";
225
+
226
+ // src/document/head-keeper.ts
227
+ var TAGS2 = ["title", "meta", "link"];
228
+ var keyOfNode = (node) => {
229
+ const tag = TAGS2.find((name) => name === node.tagName.toLowerCase());
230
+ if (tag !== "title" && tag !== "meta" && tag !== "link") return void 0;
231
+ return headKeyOf({ tag, attributes: Object.fromEntries([...node.attributes].map((attribute) => [attribute.name, attribute.value])) });
232
+ };
233
+ var createHeadKeeper = (doc) => {
234
+ let mine = [];
235
+ let away = [];
236
+ let said;
237
+ const built = (element) => {
238
+ const node = doc.createElement(element.tag);
239
+ for (const [name, value] of Object.entries(element.attributes)) node.setAttribute(name, value);
240
+ node.setAttribute(HEAD_MARK, "");
241
+ if (element.text !== void 0) node.textContent = element.text;
242
+ return node;
243
+ };
244
+ const adopt = () => {
245
+ mine = [...doc.head.querySelectorAll(`[${HEAD_MARK}]`)];
246
+ const view = doc.defaultView;
247
+ for (const stash of doc.head.querySelectorAll(`template[${OWN_MARK}]`)) {
248
+ if (view === null || !(stash instanceof view.HTMLTemplateElement)) continue;
249
+ for (const child of [...stash.content.children]) {
250
+ const key = keyOfNode(child);
251
+ if (key !== void 0) away.push({ key, node: doc.importNode(child, true), before: null });
252
+ }
253
+ stash.remove();
254
+ }
255
+ };
256
+ return (elements) => {
257
+ const now = elements ?? [];
258
+ const next = JSON.stringify(now);
259
+ if (said === void 0) {
260
+ if (now.length === 0) return;
261
+ adopt();
262
+ }
263
+ if (next === said) return;
264
+ said = next;
265
+ for (const node of mine) node.remove();
266
+ mine = now.map(built);
267
+ const keys = new Set(now.flatMap((element) => headKeyOf(element) ?? []));
268
+ for (const node of [...doc.head.children]) {
269
+ const key = keyOfNode(node);
270
+ if (key === void 0 || !keys.has(key)) continue;
271
+ away.push({ key, node, before: node.nextSibling });
272
+ node.remove();
273
+ }
274
+ const [back, still] = [away.filter((gone) => !keys.has(gone.key)), away.filter((gone) => keys.has(gone.key))];
275
+ for (const gone of [...back].reverse()) doc.head.insertBefore(gone.node, gone.before !== null && gone.before.parentNode === doc.head ? gone.before : null);
276
+ away = still;
277
+ doc.head.append(...mine);
149
278
  };
150
279
  };
151
280
 
152
- // src/document/shell-title.ts
153
- var createShellTitle = (shell) => {
281
+ // src/document/shell-head.ts
282
+ var createShellHead = (shell) => {
154
283
  const view = shellView(shell);
155
284
  let present = 0;
156
285
  let keep;
@@ -160,8 +289,8 @@ var createShellTitle = (shell) => {
160
289
  queued = true;
161
290
  queueMicrotask(() => {
162
291
  queued = false;
163
- keep ??= createTitleKeeper(document);
164
- keep(present > 0 ? headOf(view.api)?.head : void 0);
292
+ keep ??= createHeadKeeper(document);
293
+ keep(present > 0 ? headOf(view.api)?.elements : void 0);
165
294
  });
166
295
  };
167
296
  return {
@@ -180,14 +309,14 @@ var createShellTitle = (shell) => {
180
309
  };
181
310
 
182
311
  // src/adapters/vue/head.ts
183
- var ShellTitleKey = /* @__PURE__ */ Symbol.for("@niscorp/nova/adapters/vue:title");
312
+ var ShellHeadKey = /* @__PURE__ */ Symbol.for("@niscorp/nova/adapters/vue:head");
184
313
  var HeadMark = vue.defineComponent(
185
314
  () => {
186
- const title = vue.inject(ShellTitleKey, void 0);
315
+ const head = vue.inject(ShellHeadKey, void 0);
187
316
  vue.onMounted(() => {
188
- if (title === void 0) return;
317
+ if (head === void 0) return;
189
318
  vue.watch(
190
- title,
319
+ head,
191
320
  (current, _previous, onCleanup) => {
192
321
  current.enter();
193
322
  onCleanup(current.leave);
@@ -199,19 +328,19 @@ var HeadMark = vue.defineComponent(
199
328
  },
200
329
  { name: "NovaHeadMark" }
201
330
  );
202
- var provideShellTitle = (shell) => {
331
+ var provideShellHead = (shell) => {
203
332
  let held = shell();
204
- const title = vue.shallowRef(createShellTitle(held));
205
- vue.provide(ShellTitleKey, title);
333
+ const head = vue.shallowRef(createShellHead(held));
334
+ vue.provide(ShellHeadKey, head);
206
335
  vue.onMounted(() => {
207
336
  vue.watch(
208
337
  shell,
209
338
  (next, _previous, onCleanup) => {
210
339
  if (next !== held) {
211
340
  held = next;
212
- title.value = createShellTitle(next);
341
+ head.value = createShellHead(next);
213
342
  }
214
- onCleanup(title.value.watch());
343
+ onCleanup(head.value.watch());
215
344
  },
216
345
  { immediate: true }
217
346
  );
@@ -255,7 +384,7 @@ var NovaShellProvider = vue.defineComponent(
255
384
  }
256
385
  };
257
386
  vue.provide(NovaShellKey, source);
258
- provideShellTitle(() => props.shell);
387
+ provideShellHead(() => props.shell);
259
388
  const dispatch = (event) => props.shell.dispatch(event);
260
389
  const publish = (channel, payload) => props.shell.publish(channel, payload);
261
390
  return () => vue.h(