@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
@@ -420,6 +420,25 @@ var walkValue = (value, prose, where, pass) => {
420
420
 
421
421
  // src/layout/head.ts
422
422
  var HEAD_NAME = "nova:head";
423
+ var HEAD_TITLE_NAME = "nova:title";
424
+ var HEAD_META_NAME = "nova:meta";
425
+ var HEAD_LINK_NAME = "nova:link";
426
+ var HEAD_SCRIPT_NAME = "nova:script";
427
+ var HEAD_NAMES = [HEAD_NAME, HEAD_TITLE_NAME, HEAD_META_NAME, HEAD_LINK_NAME, HEAD_SCRIPT_NAME];
428
+ var headKeyOf = (element) => {
429
+ const said = (name) => {
430
+ const found = Object.entries(element.attributes).find(([key]) => key.toLowerCase() === name)?.[1].trim().toLowerCase();
431
+ return found === void 0 || found === "" ? void 0 : found;
432
+ };
433
+ if (element.tag === "title") return "title";
434
+ if (element.tag === "meta") {
435
+ const [name, property] = [said("name"), said("property")];
436
+ if (name !== void 0) return `meta name ${name}`;
437
+ return property === void 0 ? void 0 : `meta property ${property}`;
438
+ }
439
+ if (element.tag === "link") return (said("rel") ?? "").split(/\s+/).includes("canonical") ? "link canonical" : void 0;
440
+ return void 0;
441
+ };
423
442
 
424
443
  // src/layout/renderer.ts
425
444
  var noopOnError = (_error) => {
@@ -516,7 +535,7 @@ var renderNode = (node, chain, ctx) => {
516
535
  return [];
517
536
  };
518
537
  var renderComponent = (node, chain, ctx) => {
519
- if (node.component !== HEAD_NAME && !ctx.registry.has(node.component)) {
538
+ if (!HEAD_NAMES.includes(node.component) && !ctx.registry.has(node.component)) {
520
539
  throw new ComponentNotFoundError(
521
540
  `Component not found in registry: ${node.component}`,
522
541
  { name: node.component }
@@ -706,9 +725,9 @@ var createComponentRegistry = () => {
706
725
  }
707
726
  };
708
727
  const get = (name) => entries.get(name);
709
- const has = (name) => entries.has(name);
728
+ const has2 = (name) => entries.has(name);
710
729
  const list = () => Array.from(entries.keys());
711
- return { register, registerAll, get, has, list };
730
+ return { register, registerAll, get, has: has2, list };
712
731
  };
713
732
 
714
733
  // src/shared/event-bus/scope-dispatch.ts
@@ -721,29 +740,93 @@ var CANVAS_SLOT_NAME = "CanvasSlot";
721
740
  var ACTION_SLOT_NAME = "ActionSlot";
722
741
 
723
742
  // src/shell/head.ts
724
- var said = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
725
- var isObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
726
- var structuredOf = (value) => {
727
- if (isObject2(value)) return value;
728
- if (Array.isArray(value) && value.length > 0 && value.every(isObject2)) return value;
729
- return void 0;
730
- };
731
- var headFrom = (props) => {
732
- const [title, description, image] = [said(props["title"]), said(props["description"]), said(props["image"])];
733
- const kind = props["kind"] === "website" || props["kind"] === "article" ? props["kind"] : void 0;
734
- const structured = structuredOf(props["structured"]);
735
- return {
736
- ...title !== void 0 ? { title } : {},
737
- ...description !== void 0 ? { description } : {},
738
- ...image !== void 0 ? { image } : {},
739
- ...kind !== void 0 ? { kind } : {},
740
- ...structured !== void 0 ? { structured } : {}
741
- };
743
+ var ATTRIBUTE_NAME = /^[A-Za-z][A-Za-z0-9:._-]*$/;
744
+ var DATA_TYPE = /^application\/([a-z0-9.-]+\+)?json$/i;
745
+ var written = (value) => {
746
+ if (typeof value === "string") return value.trim() === "" ? void 0 : value;
747
+ if (typeof value === "number") return String(value);
748
+ return value === true ? "" : void 0;
749
+ };
750
+ var attributesOf = (what, props, skip = []) => {
751
+ const attributes = {};
752
+ for (const [name, value] of Object.entries(props)) {
753
+ if (skip.includes(name)) continue;
754
+ if (!ATTRIBUTE_NAME.test(name)) return { refused: `${what}: "${name}" is not an attribute\u2019s name` };
755
+ if (/^on/i.test(name)) return { refused: `${what}: \`${name}\` is a handler, and a layout does not run` };
756
+ const text = written(value);
757
+ if (text !== void 0) attributes[name] = text;
758
+ }
759
+ return { attributes };
760
+ };
761
+ var has = (attributes, name) => Object.keys(attributes).some((key) => key.toLowerCase() === name);
762
+ var valueOf = (attributes, name) => Object.entries(attributes).find(([key]) => key.toLowerCase() === name)?.[1] ?? "";
763
+ var textOf = (nodes) => nodes.map((node) => node.type === "text" ? node.value : node.type === "fragment" ? textOf(node.children) : "").join("");
764
+ var titleOf = (node) => {
765
+ const text = textOf(node.children).trim();
766
+ return text === "" ? void 0 : { element: { tag: "title", attributes: {}, text } };
767
+ };
768
+ var metaOf = (node) => {
769
+ const read = attributesOf(HEAD_META_NAME, node.props);
770
+ if ("refused" in read) return read;
771
+ if (has(read.attributes, "http-equiv")) return { refused: `${HEAD_META_NAME}: \`http-equiv\` instructs the browser, and a layout does not` };
772
+ return has(read.attributes, "content") ? { element: { tag: "meta", attributes: read.attributes } } : void 0;
773
+ };
774
+ var linkOf = (node) => {
775
+ const read = attributesOf(HEAD_LINK_NAME, node.props);
776
+ if ("refused" in read) return read;
777
+ 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` };
778
+ return has(read.attributes, "href") ? { element: { tag: "link", attributes: read.attributes } } : void 0;
779
+ };
780
+ var scriptOf = (node) => {
781
+ const read = attributesOf(HEAD_SCRIPT_NAME, node.props, ["data"]);
782
+ if ("refused" in read) return read;
783
+ if (has(read.attributes, "src")) return { refused: `${HEAD_SCRIPT_NAME}: a script with a \`src\` runs, and a layout does not` };
784
+ const type = valueOf(read.attributes, "type");
785
+ 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` };
786
+ const data = node.props["data"];
787
+ if (data === void 0 || data === null || data === "") return void 0;
788
+ return { element: { tag: "script", attributes: read.attributes, text: JSON.stringify(data) } };
789
+ };
790
+ var READERS = {
791
+ [HEAD_TITLE_NAME]: titleOf,
792
+ [HEAD_META_NAME]: metaOf,
793
+ [HEAD_LINK_NAME]: linkOf,
794
+ [HEAD_SCRIPT_NAME]: scriptOf
742
795
  };
743
796
  var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
744
797
  var headOf = (api) => {
745
- const found = [];
798
+ let heads = 0;
799
+ const said = [];
800
+ const refused = [];
746
801
  const open = /* @__PURE__ */ new Set();
802
+ const hold = (nodes, action) => {
803
+ for (const node of nodes) {
804
+ if (node.type === "fragment") {
805
+ hold(node.children, action);
806
+ continue;
807
+ }
808
+ if (node.type === "error") {
809
+ refused.push(`${HEAD_NAME}: ${node.message}`);
810
+ continue;
811
+ }
812
+ if (node.type !== "component") continue;
813
+ const read = READERS[node.name];
814
+ if (read === void 0) {
815
+ refused.push(`${HEAD_NAME}: "${node.name}" is not something a head holds`);
816
+ continue;
817
+ }
818
+ const found = read(node);
819
+ if (found === void 0) continue;
820
+ if ("refused" in found) {
821
+ refused.push(found.refused);
822
+ continue;
823
+ }
824
+ const key = headKeyOf(found.element);
825
+ const earlier = key === void 0 ? -1 : said.findIndex((other) => headKeyOf(other.element) === key);
826
+ if (earlier >= 0) said.splice(earlier, 1);
827
+ said.push({ element: found.element, action });
828
+ }
829
+ };
747
830
  const walk = (nodes, action) => {
748
831
  for (const node of nodes) {
749
832
  if (node.type === "fragment") {
@@ -752,7 +835,8 @@ var headOf = (api) => {
752
835
  }
753
836
  if (node.type !== "component") continue;
754
837
  if (node.name === HEAD_NAME) {
755
- found.push({ props: node.props, action });
838
+ heads += 1;
839
+ hold(node.children, action);
756
840
  continue;
757
841
  }
758
842
  if (node.name === CANVAS_SLOT_NAME) {
@@ -768,9 +852,9 @@ var headOf = (api) => {
768
852
  }
769
853
  };
770
854
  walk(api.frame(), void 0);
771
- const last = found[found.length - 1];
772
- if (last === void 0) return void 0;
773
- return { head: headFrom(last.props), ...last.action !== void 0 ? { action: last.action } : {} };
855
+ if (heads === 0) return void 0;
856
+ const actions = [...new Set(said.flatMap((one) => one.action === void 0 ? [] : [one.action]))];
857
+ return { elements: said.map((one) => one.element), actions, refused };
774
858
  };
775
859
 
776
860
  // src/shell/view.ts
@@ -820,21 +904,67 @@ var shellView = (shell) => ({
820
904
  }
821
905
  });
822
906
 
823
- // src/document/title.ts
824
- var createTitleKeeper = (doc) => {
825
- const own = doc.querySelector("title")?.getAttribute("data-own") ?? doc.title;
826
- let said2;
827
- return (head) => {
828
- const title = head?.title;
829
- if (title === said2) return;
830
- said2 = title;
831
- const next = title ?? own;
832
- if (doc.title !== next) doc.title = next;
907
+ // src/document/place-head.ts
908
+ var HEAD_MARK = "data-nova-head";
909
+ var OWN_MARK = "data-nova-own";
910
+
911
+ // src/document/head-keeper.ts
912
+ var TAGS2 = ["title", "meta", "link"];
913
+ var keyOfNode = (node) => {
914
+ const tag = TAGS2.find((name) => name === node.tagName.toLowerCase());
915
+ if (tag !== "title" && tag !== "meta" && tag !== "link") return void 0;
916
+ return headKeyOf({ tag, attributes: Object.fromEntries([...node.attributes].map((attribute) => [attribute.name, attribute.value])) });
917
+ };
918
+ var createHeadKeeper = (doc) => {
919
+ let mine = [];
920
+ let away = [];
921
+ let said;
922
+ const built = (element) => {
923
+ const node = doc.createElement(element.tag);
924
+ for (const [name, value] of Object.entries(element.attributes)) node.setAttribute(name, value);
925
+ node.setAttribute(HEAD_MARK, "");
926
+ if (element.text !== void 0) node.textContent = element.text;
927
+ return node;
928
+ };
929
+ const adopt = () => {
930
+ mine = [...doc.head.querySelectorAll(`[${HEAD_MARK}]`)];
931
+ const view = doc.defaultView;
932
+ for (const stash of doc.head.querySelectorAll(`template[${OWN_MARK}]`)) {
933
+ if (view === null || !(stash instanceof view.HTMLTemplateElement)) continue;
934
+ for (const child of [...stash.content.children]) {
935
+ const key = keyOfNode(child);
936
+ if (key !== void 0) away.push({ key, node: doc.importNode(child, true), before: null });
937
+ }
938
+ stash.remove();
939
+ }
940
+ };
941
+ return (elements) => {
942
+ const now = elements ?? [];
943
+ const next = JSON.stringify(now);
944
+ if (said === void 0) {
945
+ if (now.length === 0) return;
946
+ adopt();
947
+ }
948
+ if (next === said) return;
949
+ said = next;
950
+ for (const node of mine) node.remove();
951
+ mine = now.map(built);
952
+ const keys = new Set(now.flatMap((element) => headKeyOf(element) ?? []));
953
+ for (const node of [...doc.head.children]) {
954
+ const key = keyOfNode(node);
955
+ if (key === void 0 || !keys.has(key)) continue;
956
+ away.push({ key, node, before: node.nextSibling });
957
+ node.remove();
958
+ }
959
+ const [back, still] = [away.filter((gone) => !keys.has(gone.key)), away.filter((gone) => keys.has(gone.key))];
960
+ for (const gone of [...back].reverse()) doc.head.insertBefore(gone.node, gone.before !== null && gone.before.parentNode === doc.head ? gone.before : null);
961
+ away = still;
962
+ doc.head.append(...mine);
833
963
  };
834
964
  };
835
965
 
836
- // src/document/shell-title.ts
837
- var createShellTitle = (shell) => {
966
+ // src/document/shell-head.ts
967
+ var createShellHead = (shell) => {
838
968
  const view = shellView(shell);
839
969
  let present = 0;
840
970
  let keep;
@@ -844,8 +974,8 @@ var createShellTitle = (shell) => {
844
974
  queued = true;
845
975
  queueMicrotask(() => {
846
976
  queued = false;
847
- keep ??= createTitleKeeper(document);
848
- keep(present > 0 ? headOf(view.api)?.head : void 0);
977
+ keep ??= createHeadKeeper(document);
978
+ keep(present > 0 ? headOf(view.api)?.elements : void 0);
849
979
  });
850
980
  };
851
981
  return {
@@ -862,20 +992,20 @@ var createShellTitle = (shell) => {
862
992
  })
863
993
  };
864
994
  };
865
- var ShellTitleContext = react.createContext(void 0);
995
+ var ShellHeadContext = react.createContext(void 0);
866
996
  var HeadMark = () => {
867
- const title = react.useContext(ShellTitleContext);
997
+ const head = react.useContext(ShellHeadContext);
868
998
  react.useEffect(() => {
869
- if (title === void 0) return void 0;
870
- title.enter();
871
- return title.leave;
872
- }, [title]);
999
+ if (head === void 0) return void 0;
1000
+ head.enter();
1001
+ return head.leave;
1002
+ }, [head]);
873
1003
  return null;
874
1004
  };
875
- var ShellTitleProvider = ({ shell, children }) => {
876
- const title = react.useMemo(() => createShellTitle(shell), [shell]);
877
- react.useEffect(() => title.watch(), [title]);
878
- return /* @__PURE__ */ jsxRuntime.jsx(ShellTitleContext.Provider, { value: title, children });
1005
+ var ShellHeadProvider = ({ shell, children }) => {
1006
+ const head = react.useMemo(() => createShellHead(shell), [shell]);
1007
+ react.useEffect(() => head.watch(), [head]);
1008
+ return /* @__PURE__ */ jsxRuntime.jsx(ShellHeadContext.Provider, { value: head, children });
879
1009
  };
880
1010
  var noopDispatch = () => {
881
1011
  };
@@ -916,7 +1046,7 @@ var NovaShellProvider = ({
916
1046
  dispatch,
917
1047
  publish,
918
1048
  slotWrapper,
919
- children: /* @__PURE__ */ jsxRuntime.jsx(ShellTitleProvider, { shell, children })
1049
+ children: /* @__PURE__ */ jsxRuntime.jsx(ShellHeadProvider, { shell, children })
920
1050
  }
921
1051
  ) });
922
1052
  };