@niscorp/nova 0.1.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 (170) hide show
  1. package/ACTION_DOCS.md +552 -0
  2. package/ADAPTER.md +170 -0
  3. package/DESIGN.md +719 -0
  4. package/I18N_DOCS.md +224 -0
  5. package/LAYOUT_DOCS.md +505 -0
  6. package/LICENSE +202 -0
  7. package/REACT_DOCS.md +562 -0
  8. package/README.md +379 -0
  9. package/SHELL_DOCS.md +615 -0
  10. package/TERMINAL_DOCS.md +124 -0
  11. package/dist/adapters/dom/components/index.cjs +473 -0
  12. package/dist/adapters/dom/components/index.cjs.map +1 -0
  13. package/dist/adapters/dom/components/index.d.cts +48 -0
  14. package/dist/adapters/dom/components/index.d.ts +48 -0
  15. package/dist/adapters/dom/components/index.js +420 -0
  16. package/dist/adapters/dom/components/index.js.map +1 -0
  17. package/dist/adapters/dom/index.cjs +171 -0
  18. package/dist/adapters/dom/index.cjs.map +1 -0
  19. package/dist/adapters/dom/index.d.cts +29 -0
  20. package/dist/adapters/dom/index.d.ts +29 -0
  21. package/dist/adapters/dom/index.js +15 -0
  22. package/dist/adapters/dom/index.js.map +1 -0
  23. package/dist/adapters/dom/server.cjs +129 -0
  24. package/dist/adapters/dom/server.cjs.map +1 -0
  25. package/dist/adapters/dom/server.d.cts +15 -0
  26. package/dist/adapters/dom/server.d.ts +15 -0
  27. package/dist/adapters/dom/server.js +37 -0
  28. package/dist/adapters/dom/server.js.map +1 -0
  29. package/dist/adapters/ink/index.d.ts +75 -0
  30. package/dist/adapters/ink/index.js +472 -0
  31. package/dist/adapters/ink/index.js.map +1 -0
  32. package/dist/adapters/react/components/index.cjs +552 -0
  33. package/dist/adapters/react/components/index.cjs.map +1 -0
  34. package/dist/adapters/react/components/index.d.cts +30 -0
  35. package/dist/adapters/react/components/index.d.ts +30 -0
  36. package/dist/adapters/react/components/index.js +12 -0
  37. package/dist/adapters/react/components/index.js.map +1 -0
  38. package/dist/adapters/react/index.cjs +1526 -0
  39. package/dist/adapters/react/index.cjs.map +1 -0
  40. package/dist/adapters/react/index.d.cts +149 -0
  41. package/dist/adapters/react/index.d.ts +149 -0
  42. package/dist/adapters/react/index.js +12 -0
  43. package/dist/adapters/react/index.js.map +1 -0
  44. package/dist/adapters/tty/components/index.cjs +255 -0
  45. package/dist/adapters/tty/components/index.cjs.map +1 -0
  46. package/dist/adapters/tty/components/index.d.cts +40 -0
  47. package/dist/adapters/tty/components/index.d.ts +40 -0
  48. package/dist/adapters/tty/components/index.js +187 -0
  49. package/dist/adapters/tty/components/index.js.map +1 -0
  50. package/dist/adapters/tty/index.cjs +76 -0
  51. package/dist/adapters/tty/index.cjs.map +1 -0
  52. package/dist/adapters/tty/index.d.cts +47 -0
  53. package/dist/adapters/tty/index.d.ts +47 -0
  54. package/dist/adapters/tty/index.js +76 -0
  55. package/dist/adapters/tty/index.js.map +1 -0
  56. package/dist/adapters/vue/components/index.cjs +619 -0
  57. package/dist/adapters/vue/components/index.cjs.map +1 -0
  58. package/dist/adapters/vue/components/index.d.cts +224 -0
  59. package/dist/adapters/vue/components/index.d.ts +224 -0
  60. package/dist/adapters/vue/components/index.js +12 -0
  61. package/dist/adapters/vue/components/index.js.map +1 -0
  62. package/dist/adapters/vue/index.cjs +747 -0
  63. package/dist/adapters/vue/index.cjs.map +1 -0
  64. package/dist/adapters/vue/index.d.cts +98 -0
  65. package/dist/adapters/vue/index.d.ts +98 -0
  66. package/dist/adapters/vue/index.js +127 -0
  67. package/dist/adapters/vue/index.js.map +1 -0
  68. package/dist/agent/index.cjs +178 -0
  69. package/dist/agent/index.cjs.map +1 -0
  70. package/dist/agent/index.d.cts +28 -0
  71. package/dist/agent/index.d.ts +28 -0
  72. package/dist/agent/index.js +30 -0
  73. package/dist/agent/index.js.map +1 -0
  74. package/dist/chunk-2MNLEL45.js +47 -0
  75. package/dist/chunk-2MNLEL45.js.map +1 -0
  76. package/dist/chunk-3HGE3VWK.js +753 -0
  77. package/dist/chunk-3HGE3VWK.js.map +1 -0
  78. package/dist/chunk-4ZID7UX5.js +549 -0
  79. package/dist/chunk-4ZID7UX5.js.map +1 -0
  80. package/dist/chunk-7B3RDENH.js +1982 -0
  81. package/dist/chunk-7B3RDENH.js.map +1 -0
  82. package/dist/chunk-7S5BNPUS.js +54 -0
  83. package/dist/chunk-7S5BNPUS.js.map +1 -0
  84. package/dist/chunk-7TS3YVQR.js +114 -0
  85. package/dist/chunk-7TS3YVQR.js.map +1 -0
  86. package/dist/chunk-EG2RUXJN.js +266 -0
  87. package/dist/chunk-EG2RUXJN.js.map +1 -0
  88. package/dist/chunk-GVBBL36G.js +429 -0
  89. package/dist/chunk-GVBBL36G.js.map +1 -0
  90. package/dist/chunk-I5D2R5UA.js +753 -0
  91. package/dist/chunk-I5D2R5UA.js.map +1 -0
  92. package/dist/chunk-IGLCWXQ3.js +304 -0
  93. package/dist/chunk-IGLCWXQ3.js.map +1 -0
  94. package/dist/chunk-JI7ZRESP.js +64 -0
  95. package/dist/chunk-JI7ZRESP.js.map +1 -0
  96. package/dist/chunk-L5223LLX.js +31 -0
  97. package/dist/chunk-L5223LLX.js.map +1 -0
  98. package/dist/chunk-LA3BSEMX.js +1905 -0
  99. package/dist/chunk-LA3BSEMX.js.map +1 -0
  100. package/dist/chunk-OAMC6R6E.js +121 -0
  101. package/dist/chunk-OAMC6R6E.js.map +1 -0
  102. package/dist/chunk-OGD5CCMZ.js +62 -0
  103. package/dist/chunk-OGD5CCMZ.js.map +1 -0
  104. package/dist/chunk-PF4OJTYU.js +199 -0
  105. package/dist/chunk-PF4OJTYU.js.map +1 -0
  106. package/dist/chunk-PZ5AY32C.js +9 -0
  107. package/dist/chunk-PZ5AY32C.js.map +1 -0
  108. package/dist/chunk-RBU5PHN4.js +8 -0
  109. package/dist/chunk-RBU5PHN4.js.map +1 -0
  110. package/dist/chunk-RQB4PRPV.js +285 -0
  111. package/dist/chunk-RQB4PRPV.js.map +1 -0
  112. package/dist/chunk-V32EVEVM.js +464 -0
  113. package/dist/chunk-V32EVEVM.js.map +1 -0
  114. package/dist/chunk-ZITHBBF3.js +85 -0
  115. package/dist/chunk-ZITHBBF3.js.map +1 -0
  116. package/dist/devtools/index.cjs +1088 -0
  117. package/dist/devtools/index.cjs.map +1 -0
  118. package/dist/devtools/index.d.cts +33 -0
  119. package/dist/devtools/index.d.ts +33 -0
  120. package/dist/devtools/index.js +399 -0
  121. package/dist/devtools/index.js.map +1 -0
  122. package/dist/effects-CndX9K7D.d.cts +123 -0
  123. package/dist/effects-CndX9K7D.d.ts +123 -0
  124. package/dist/endpoints-CD-6Jl-H.d.ts +36 -0
  125. package/dist/endpoints-Dem-EdRx.d.cts +36 -0
  126. package/dist/i18n/index.cjs +299 -0
  127. package/dist/i18n/index.cjs.map +1 -0
  128. package/dist/i18n/index.d.cts +28 -0
  129. package/dist/i18n/index.d.ts +28 -0
  130. package/dist/i18n/index.js +180 -0
  131. package/dist/i18n/index.js.map +1 -0
  132. package/dist/index-CNfzSBe2.d.ts +93 -0
  133. package/dist/index-caZoXSwr.d.cts +93 -0
  134. package/dist/index.cjs +3723 -0
  135. package/dist/index.cjs.map +1 -0
  136. package/dist/index.d.cts +144 -0
  137. package/dist/index.d.ts +144 -0
  138. package/dist/index.js +15 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/migrations/index.cjs +635 -0
  141. package/dist/migrations/index.cjs.map +1 -0
  142. package/dist/migrations/index.d.cts +97 -0
  143. package/dist/migrations/index.d.ts +97 -0
  144. package/dist/migrations/index.js +50 -0
  145. package/dist/migrations/index.js.map +1 -0
  146. package/dist/palette-CP0wd3bE.d.ts +15 -0
  147. package/dist/palette-lm0bU9i5.d.cts +15 -0
  148. package/dist/primitive-props-BH_EJWIe.d.cts +100 -0
  149. package/dist/primitive-props-BH_EJWIe.d.ts +100 -0
  150. package/dist/primitive-props-CGoJvmcH.d.cts +100 -0
  151. package/dist/primitive-props-CGoJvmcH.d.ts +100 -0
  152. package/dist/reflect/index.cjs +998 -0
  153. package/dist/reflect/index.cjs.map +1 -0
  154. package/dist/reflect/index.d.cts +125 -0
  155. package/dist/reflect/index.d.ts +125 -0
  156. package/dist/reflect/index.js +13 -0
  157. package/dist/reflect/index.js.map +1 -0
  158. package/dist/schemas-DPdeFlCT.d.cts +38 -0
  159. package/dist/schemas-DPdeFlCT.d.ts +38 -0
  160. package/dist/schemas-pMyyuXV7.d.cts +47 -0
  161. package/dist/schemas-pMyyuXV7.d.ts +47 -0
  162. package/dist/types-Boh9ckdG.d.ts +194 -0
  163. package/dist/types-Brc7v_pS.d.ts +198 -0
  164. package/dist/types-ByNSwtUV.d.cts +20 -0
  165. package/dist/types-DdltMfw7.d.ts +20 -0
  166. package/dist/types-De0KpxfI.d.cts +198 -0
  167. package/dist/types-DhHL0twe.d.ts +20 -0
  168. package/dist/types-Dv6JLmgo.d.cts +194 -0
  169. package/dist/types-Q80YtOQt.d.cts +20 -0
  170. package/package.json +237 -0
@@ -0,0 +1,171 @@
1
+ 'use strict';
2
+
3
+ // src/shell/slot-names.ts
4
+ var ACTION_SLOT_NAME = "ActionSlot";
5
+
6
+ // src/shell/view.ts
7
+ var hasVisibleContent = (nodes) => nodes.some((node) => {
8
+ if (node.type === "text") return node.value !== "";
9
+ if (node.type === "fragment") return hasVisibleContent(node.children);
10
+ if (node.type === "component" && node.name === ACTION_SLOT_NAME) return hasVisibleContent(node.children);
11
+ return true;
12
+ });
13
+ var canvasTreeOf = (shell, canvasId) => {
14
+ const tree = shell.flattenRenderTree(shell.getCanvasRenderTree(canvasId));
15
+ return hasVisibleContent(tree) ? tree : [];
16
+ };
17
+ var shellView = (shell) => ({
18
+ api: {
19
+ frame: () => shell.getShellRenderTree(),
20
+ canvasTree: (canvasId) => canvasTreeOf(shell, canvasId),
21
+ // An event that names no origin belongs to the canvas's ACTIVE instance — on
22
+ // a card deck that is the only one drawn. One that names its own (an
23
+ // adapter stamps it at the instance boundary, `scopeDispatch`) keeps it. A
24
+ // canvas with nothing mounted dispatches unstamped.
25
+ dispatch: (canvasId, event) => {
26
+ const active = shell.getState().canvases[canvasId]?.active;
27
+ shell.dispatch(event.origin === void 0 && active !== void 0 ? { ...event, origin: active.id } : event);
28
+ },
29
+ publish: (channel, payload) => shell.publish(channel, payload)
30
+ },
31
+ subscribe: (listener) => {
32
+ let pending = false;
33
+ let stopped = false;
34
+ const changed = () => {
35
+ if (pending || stopped) return;
36
+ pending = true;
37
+ queueMicrotask(() => {
38
+ pending = false;
39
+ if (!stopped) listener();
40
+ });
41
+ };
42
+ const offState = shell.onStateChange(changed);
43
+ const offData = shell.onDataChange(changed);
44
+ return () => {
45
+ stopped = true;
46
+ offState();
47
+ offData();
48
+ };
49
+ }
50
+ });
51
+
52
+ // src/adapters/dom/index.ts
53
+ var CANVAS_SLOT = "CanvasSlot";
54
+ var ACTION_SLOT = "ActionSlot";
55
+ var errorEl = (code, message) => {
56
+ const el = document.createElement("div");
57
+ el.setAttribute("data-nova-error", code);
58
+ el.textContent = `${code}: ${message}`;
59
+ return el;
60
+ };
61
+ var readValue = (target) => {
62
+ if (target instanceof HTMLInputElement && target.type === "checkbox") return target.checked;
63
+ if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return target.value;
64
+ return "";
65
+ };
66
+ var wireEvents = (el, node, dispatch) => {
67
+ if (node.model !== void 0) {
68
+ const ref = node.model.ref;
69
+ const debounce = typeof node.props["debounce"] === "number" ? node.props["debounce"] : 0;
70
+ let timer;
71
+ const fire = (value) => dispatch({ type: "ui:model", ref, payload: value });
72
+ el.addEventListener("input", (e) => {
73
+ const value = readValue(e.target);
74
+ if (debounce > 0) {
75
+ clearTimeout(timer);
76
+ timer = setTimeout(() => fire(value), debounce);
77
+ } else fire(value);
78
+ });
79
+ el.addEventListener("keydown", (e) => {
80
+ if (e instanceof KeyboardEvent) dispatch({ type: "ui:key", ref, key: e.key });
81
+ });
82
+ return;
83
+ }
84
+ if (node.ref !== void 0) {
85
+ const ref = node.ref;
86
+ el.addEventListener("click", (e) => {
87
+ e.stopPropagation();
88
+ const value = node.props["value"];
89
+ dispatch(value === void 0 ? { type: "ui:click", ref } : { type: "ui:click", ref, payload: value });
90
+ });
91
+ }
92
+ };
93
+ var inInstance = (node, ctx) => {
94
+ if (node.type !== "component" || node.name !== ACTION_SLOT) return ctx;
95
+ const instanceId = node.props["instanceId"];
96
+ if (typeof instanceId !== "string" || instanceId === "") return ctx;
97
+ const outer = ctx.dispatch;
98
+ return { ...ctx, dispatch: (event) => outer(event.origin === void 0 ? { ...event, origin: instanceId } : event) };
99
+ };
100
+ var renderNode = (node, parent) => {
101
+ const ctx = inInstance(node, parent);
102
+ if (node.type === "text") return document.createTextNode(node.value);
103
+ if (node.type === "fragment") {
104
+ const frag = document.createDocumentFragment();
105
+ for (const child of node.children) frag.appendChild(renderNode(child, ctx));
106
+ return frag;
107
+ }
108
+ if (node.type === "error") return errorEl(node.code, node.message);
109
+ if (node.name === CANVAS_SLOT) {
110
+ const canvasId = typeof node.props["canvasId"] === "string" ? node.props["canvasId"] : "";
111
+ const host = document.createElement("div");
112
+ host.setAttribute("data-canvas", canvasId);
113
+ if (canvasId === "") return host;
114
+ const canvasCtx = { ...ctx, dispatch: (event) => ctx.api.dispatch(canvasId, event) };
115
+ for (const child of ctx.api.canvasTree(canvasId)) host.appendChild(renderNode(child, canvasCtx));
116
+ return host;
117
+ }
118
+ const entry = ctx.registry.get(node.name);
119
+ const build = entry !== void 0 ? entry.component : ctx.fallback;
120
+ if (build === void 0) return errorEl("COMPONENT_NOT_FOUND", node.name);
121
+ const children = node.children.map((child) => renderNode(child, ctx));
122
+ const el = build({ props: node.props, children, dispatch: ctx.dispatch });
123
+ el.setAttribute("data-component", node.name);
124
+ if (node.ref !== void 0) el.setAttribute("data-ref", node.ref);
125
+ wireEvents(el, node, ctx.dispatch);
126
+ return el;
127
+ };
128
+ var captureFocus = (root) => {
129
+ const active = root.ownerDocument.activeElement;
130
+ if (!(active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement)) return void 0;
131
+ const ref = active.getAttribute("data-ref");
132
+ if (ref === null || !root.contains(active)) return void 0;
133
+ return { ref, value: active.value, start: active.selectionStart, end: active.selectionEnd };
134
+ };
135
+ var restoreFocus = (root, focus) => {
136
+ const el = root.querySelector(`[data-ref="${focus.ref}"]`);
137
+ if (!(el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)) return;
138
+ el.value = focus.value;
139
+ el.focus();
140
+ try {
141
+ el.setSelectionRange(focus.start ?? el.value.length, focus.end ?? el.value.length);
142
+ } catch {
143
+ }
144
+ };
145
+ var createDomView = (root, registry, api, options = {}) => {
146
+ const ctx = { registry, dispatch: () => void 0, api, ...options.fallback !== void 0 ? { fallback: options.fallback } : {} };
147
+ const render = () => {
148
+ const focus = captureFocus(root);
149
+ root.replaceChildren();
150
+ for (const node of api.frame()) root.appendChild(renderNode(node, ctx));
151
+ if (focus !== void 0) restoreFocus(root, focus);
152
+ };
153
+ return { render, destroy: () => root.replaceChildren() };
154
+ };
155
+ var mountShell = (root, registry, shell, options = {}) => {
156
+ const view = shellView(shell);
157
+ const dom = createDomView(root, registry, view.api, options);
158
+ dom.render();
159
+ const stop = view.subscribe(dom.render);
160
+ return {
161
+ destroy: () => {
162
+ stop();
163
+ dom.destroy();
164
+ }
165
+ };
166
+ };
167
+
168
+ exports.createDomView = createDomView;
169
+ exports.mountShell = mountShell;
170
+ //# sourceMappingURL=index.cjs.map
171
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/shell/slot-names.ts","../../../src/shell/view.ts","../../../src/adapters/dom/index.ts"],"names":[],"mappings":";;;AAiBO,IAAM,gBAAA,GAAmB,YAAA;;;ACkBzB,IAAM,oBAAoB,CAAC,KAAA,KAChC,KAAA,CAAM,IAAA,CAAK,CAAC,IAAA,KAAS;AACnB,EAAA,IAAI,IAAA,CAAK,IAAA,KAAS,MAAA,EAAQ,OAAO,KAAK,KAAA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SAAS,MAAM;AACb,MAAA,IAAA,EAAK;AACL,MAAA,GAAA,CAAI,OAAA,EAAQ;AAAA,IACd;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["// ═══════════════════════════════════════════════════════════\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 type { RenderNode } from '../layout';\nimport type { RenderApi, Shell } from './types';\nimport { ACTION_SLOT_NAME } from './slot-names';\n\n// ═══════════════════════════════════════════════════════════\n// A shell, as something an adapter draws.\n//\n// Every adapter that draws a SERVED screen draws it through `RenderApi` — the\n// frame, a tree per canvas, events up, messages across — and has always been\n// handed one by a transport (moss's socket wire). A shell that lives in the\n// same process as its adapter is the other case that type was written for, and\n// this is it: the shell's own trees, read as they stand, and its own dispatch.\n// The DOM and TTY adapters draw a local shell through this exactly as they draw\n// a remote one; nothing about them knows the difference.\n//\n// It is also what makes a shell DRAWABLE AHEAD OF TIME. A build runs the app's\n// own boot, waits for the screen to be whole (`shellSettled`), and has an\n// adapter draw this view to markup; the browser runs the same boot and draws\n// the same view over that markup. Where the shell lives was never the\n// adapter's business.\n// ═══════════════════════════════════════════════════════════\n\nexport type ShellView = {\n api: RenderApi;\n // Called after the shell changed — coalesced, so a burst of changes (a press\n // that sets three keys) is one call. Returns the unsubscribe.\n subscribe: (listener: () => void) => () => void;\n};\n\n// NO VISIBLE CONTENT IS AN EMPTY TREE. A canvas whose layout renders nothing but\n// empty text and empty wrappers is handed to an adapter as `[]`, so an adapter\n// collapses the chrome around it on `length` alone, knowing nothing about node\n// shapes. An ActionSlot marker is a boundary, not content — what is inside it\n// decides. One rule for a canvas that is served and one that is local, so a\n// frame looks the same over both.\nexport const hasVisibleContent = (nodes: readonly RenderNode[]): boolean =>\n nodes.some((node) => {\n if (node.type === 'text') return node.value !== '';\n if (node.type === 'fragment') return hasVisibleContent(node.children);\n if (node.type === 'component' && node.name === ACTION_SLOT_NAME) return hasVisibleContent(node.children);\n return true;\n });\n\n// One canvas, as an adapter is handed it.\nexport const canvasTreeOf = (shell: Shell, canvasId: string): RenderNode[] => {\n const tree = shell.flattenRenderTree(shell.getCanvasRenderTree(canvasId));\n return hasVisibleContent(tree) ? tree : [];\n};\n\nexport const shellView = (shell: Shell): ShellView => ({\n api: {\n frame: () => shell.getShellRenderTree(),\n canvasTree: (canvasId) => canvasTreeOf(shell, canvasId),\n // An event that names no origin belongs to the canvas's ACTIVE instance — on\n // a card deck that is the only one drawn. One that names its own (an\n // adapter stamps it at the instance boundary, `scopeDispatch`) keeps it. A\n // canvas with nothing mounted dispatches unstamped.\n dispatch: (canvasId, event) => {\n const active = shell.getState().canvases[canvasId]?.active;\n shell.dispatch(event.origin === undefined && active !== undefined ? { ...event, origin: active.id } : event);\n },\n publish: (channel, payload) => shell.publish(channel, payload),\n },\n subscribe: (listener) => {\n let pending = false;\n let stopped = false;\n const changed = (): void => {\n if (pending || stopped) return;\n pending = true;\n queueMicrotask(() => {\n pending = false;\n if (!stopped) listener();\n });\n };\n const offState = shell.onStateChange(changed);\n const offData = shell.onDataChange(changed);\n return () => {\n stopped = true;\n offState();\n offData();\n };\n },\n});\n\n// THE FIRST SCREEN IS WHOLE. An instance is `initializing` until its mount hook\n// — the loads, and whatever they chain to — has been awaited, so \"nothing is\n// initializing\" is the shell saying its opening screen is complete. A mount can\n// open another action, which starts initializing in turn, so the question is\n// asked again on every change and answered true only when it still holds a\n// macrotask later.\n//\n// Resolves `false` when `waitMs` runs out first: the screen is then drawn as it\n// stands, with whatever is still loading drawn as loading. Default 300ms — a\n// page should not hang on one slow endpoint.\nexport const DEFAULT_SETTLE_WAIT_MS = 300;\n\nexport const shellSettled = async (shell: Shell, options: { waitMs?: number; stopped?: () => boolean } = {}): Promise<boolean> => {\n const waitMs = options.waitMs ?? DEFAULT_SETTLE_WAIT_MS;\n const mounting = (): boolean =>\n Object.values(shell.getState().canvases).some((canvas) => canvas.stack.some((instance) => instance.status === 'initializing'));\n let timer: ReturnType<typeof setTimeout> | undefined;\n const deadline = new Promise<boolean>((resolve) => {\n timer = setTimeout(() => resolve(false), waitMs);\n });\n const quiet = (async (): Promise<boolean> => {\n for (;;) {\n if (options.stopped?.() === true) return false;\n if (!mounting()) {\n await new Promise<void>((resolve) => setTimeout(resolve, 0));\n if (!mounting()) return true;\n }\n await new Promise<void>((resolve) => {\n const off = shell.onStateChange(() => {\n off();\n resolve();\n });\n // a change that lands with no notification must not leave this waiting\n setTimeout(() => {\n off();\n resolve();\n }, 10);\n });\n }\n })();\n const settled = await Promise.race([quiet, deadline]);\n clearTimeout(timer);\n return settled;\n};\n","import type { ComponentRegistry, RenderNode } from '@layout/types';\nimport type { NovaEvent } from '@shared/event-bus/schemas';\nimport { shellView } from '@shell';\nimport type { RenderApi, Shell } from '@shell';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/adapters/dom — a vanilla-DOM adapter, the platform sibling of\n// nova/react. It turns a served RenderNode tree into DOM: registry lookup →\n// element, recurse children, and wire events BY CONVENTION — a `ref`'d\n// element dispatches `ui:click`, a `model`'d element dispatches `ui:model`\n// (+ `ui:key`), the payload of a click is the node's `value` prop. Origin is\n// never stamped here — moss stamps the active instance server-side.\n//\n// No framework: the registry maps a component name to a function that builds\n// an element from props + already-rendered children. `CanvasSlot` is resolved\n// here (the frame's markers → per-canvas trees), the one piece of terminal\n// structure the renderer owns; the terminal hands in `canvasTree`/`dispatch`.\n// See packages/nova/ADAPTER.md for the shared adapter contract.\n// ═══════════════════════════════════════════════════════════\n\nexport type DomComponentContext = {\n props: Record<string, unknown>;\n // the node's children, already rendered — the component appends them where\n // it wants (most append to their own element; leaves ignore them).\n children: Node[];\n // the dispatch in force here (canvas-scoped inside a CanvasSlot) — for\n // data-driven components with INTERNAL interactivity (a table's row clicks,\n // an inline checkbox); simple components ignore it and let the renderer wire\n // their `ref`/`model` by convention.\n dispatch: (event: NovaEvent) => void;\n};\n\n// A DOM component: props + rendered children in, one element out.\nexport type DomComponent = (ctx: DomComponentContext) => HTMLElement;\n\n// What the terminal hands the view: core's `RenderApi` (the frame, per-canvas\n// trees, a canvas-scoped dispatch, publish). Aliased, not redeclared, so the\n// dom adapter, the react adapter, and moss's terminal share ONE definition —\n// drift is impossible. CanvasSlot resolution + event routing ride these; the\n// renderer never touches the wire directly.\nexport type DomRenderApi = RenderApi;\n\nexport type DomView = {\n // (re)render from the current snapshot; call on every wire change\n render: () => void;\n destroy: () => void;\n};\n\nconst CANVAS_SLOT = 'CanvasSlot';\nconst ACTION_SLOT = 'ActionSlot';\n\n// The recursion context: the registry, the dispatch in force (frame chrome\n// dispatches nothing; a CanvasSlot switches it to that canvas's), publish,\n// and the canvas resolver.\ntype Ctx = {\n registry: ComponentRegistry<DomComponent>;\n dispatch: (event: NovaEvent) => void;\n api: DomRenderApi;\n // used when a component name is unregistered — a permissive renderer (the\n // html terminal's default kit) supplies one so unknown primitives render\n // their children instead of an error; strict consumers omit it.\n fallback?: DomComponent;\n};\n\nconst errorEl = (code: string, message: string): HTMLElement => {\n const el = document.createElement('div');\n el.setAttribute('data-nova-error', code);\n el.textContent = `${code}: ${message}`;\n return el;\n};\n\n// Read the model value off an event target — a checkbox reports `checked`,\n// everything else `value`.\nconst readValue = (target: EventTarget | null): unknown => {\n if (target instanceof HTMLInputElement && target.type === 'checkbox') return target.checked;\n if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return target.value;\n return '';\n};\n\n// Attach the conventional listeners: a model'd element is an input (dispatch\n// ui:model on change, ui:key on keydown); a bare ref'd element is clickable\n// (dispatch ui:click, payload = its `value` prop). Uniform across every\n// component — the event vocabulary is the convention, not per-component code.\nconst wireEvents = (el: HTMLElement, node: Extract<RenderNode, { type: 'component' }>, dispatch: (event: NovaEvent) => void): void => {\n if (node.model !== undefined) {\n const ref = node.model.ref;\n const debounce = typeof node.props['debounce'] === 'number' ? (node.props['debounce'] as number) : 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n const fire = (value: unknown): void => dispatch({ type: 'ui:model', ref, payload: value });\n el.addEventListener('input', (e) => {\n const value = readValue(e.target);\n if (debounce > 0) {\n clearTimeout(timer);\n timer = setTimeout(() => fire(value), debounce);\n } else fire(value);\n });\n el.addEventListener('keydown', (e) => {\n if (e instanceof KeyboardEvent) dispatch({ type: 'ui:key', ref, key: e.key });\n });\n return;\n }\n if (node.ref !== undefined) {\n const ref = node.ref;\n el.addEventListener('click', (e) => {\n e.stopPropagation();\n const value = node.props['value'];\n dispatch(value === undefined ? { type: 'ui:click', ref } : { type: 'ui:click', ref, payload: value });\n });\n }\n};\n\n// The per-instance boundary a served tree carries. A list canvas renders\n// several live instances at once, so a click inside THIS boundary must reach\n// THIS instance: its events carry it as their origin (the server's\n// active-instance fallback only holds for a card-deck canvas). An event that\n// already has an origin keeps it — moss's react terminal does the same.\nconst inInstance = (node: RenderNode, ctx: Ctx): Ctx => {\n if (node.type !== 'component' || node.name !== ACTION_SLOT) return ctx;\n const instanceId = node.props['instanceId'];\n if (typeof instanceId !== 'string' || instanceId === '') return ctx;\n const outer = ctx.dispatch;\n return { ...ctx, dispatch: (event) => outer(event.origin === undefined ? { ...event, origin: instanceId } : event) };\n};\n\nconst renderNode = (node: RenderNode, parent: Ctx): Node => {\n const ctx = inInstance(node, parent);\n if (node.type === 'text') return document.createTextNode(node.value);\n if (node.type === 'fragment') {\n const frag = document.createDocumentFragment();\n for (const child of node.children) frag.appendChild(renderNode(child, ctx));\n return frag;\n }\n if (node.type === 'error') return errorEl(node.code, node.message);\n\n // component\n if (node.name === CANVAS_SLOT) {\n const canvasId = typeof node.props['canvasId'] === 'string' ? (node.props['canvasId'] as string) : '';\n const host = document.createElement('div');\n host.setAttribute('data-canvas', canvasId);\n if (canvasId === '') return host;\n // Switch dispatch to this canvas's; the server stamps origin, so the\n // terminal just tags the canvas.\n const canvasCtx: Ctx = { ...ctx, dispatch: (event) => ctx.api.dispatch(canvasId, event) };\n for (const child of ctx.api.canvasTree(canvasId)) host.appendChild(renderNode(child, canvasCtx));\n return host;\n }\n\n const entry = ctx.registry.get(node.name);\n const build = entry !== undefined ? entry.component : ctx.fallback;\n if (build === undefined) return errorEl('COMPONENT_NOT_FOUND', node.name);\n\n const children = node.children.map((child) => renderNode(child, ctx));\n const el = build({ props: node.props, children, dispatch: ctx.dispatch });\n el.setAttribute('data-component', node.name);\n if (node.ref !== undefined) el.setAttribute('data-ref', node.ref);\n wireEvents(el, node, ctx.dispatch);\n return el;\n};\n\n// The one interactive concession: never overwrite the value of the focused\n// input when a new tree arrives. We rebuild fully (the\n// server is authoritative), so capture the focused ref + value + caret before,\n// and restore them after — the in-progress value wins over the server's.\ntype Focus = { ref: string; value: string; start: number | null; end: number | null };\n\nconst captureFocus = (root: HTMLElement): Focus | undefined => {\n const active = root.ownerDocument.activeElement;\n if (!(active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement)) return undefined;\n const ref = active.getAttribute('data-ref');\n if (ref === null || !root.contains(active)) return undefined;\n return { ref, value: active.value, start: active.selectionStart, end: active.selectionEnd };\n};\n\nconst restoreFocus = (root: HTMLElement, focus: Focus): void => {\n const el = root.querySelector(`[data-ref=\"${focus.ref}\"]`);\n if (!(el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)) return;\n el.value = focus.value; // the user's in-progress value, not the server's\n el.focus();\n try {\n el.setSelectionRange(focus.start ?? el.value.length, focus.end ?? el.value.length);\n } catch {\n /* selectionRange throws on some input types — harmless */\n }\n};\n\nexport const createDomView = (\n root: HTMLElement,\n registry: ComponentRegistry<DomComponent>,\n api: DomRenderApi,\n options: { fallback?: DomComponent } = {},\n): DomView => {\n // The frame dispatches nothing (chrome); only a CanvasSlot's subtree does.\n const ctx: Ctx = { registry, dispatch: () => undefined, api, ...(options.fallback !== undefined ? { fallback: options.fallback } : {}) };\n const render = (): void => {\n const focus = captureFocus(root);\n root.replaceChildren();\n for (const node of api.frame()) root.appendChild(renderNode(node, ctx));\n if (focus !== undefined) restoreFocus(root, focus);\n };\n return { render, destroy: () => root.replaceChildren() };\n};\n\n// A SHELL THAT LIVES IN THIS PAGE, drawn into `root` and kept current: the\n// shell's own view (`shellView`), this adapter over it, and a re-render on every\n// change. The whole of a browser entry for an app whose shell runs in the\n// browser:\n//\n// mountShell(root, registry, await boot());\n//\n// A `root` that already holds the same screen as markup — drawn ahead of time\n// by `renderToString` (./server) from the same boot — is picked up by the first\n// render: the adapter rebuilds its root, so those elements are replaced with the\n// same elements in one step, and nothing can disagree with them.\nexport const mountShell = (\n root: HTMLElement,\n registry: ComponentRegistry<DomComponent>,\n shell: Shell,\n options: { fallback?: DomComponent } = {},\n): { destroy: () => void } => {\n const view = shellView(shell);\n const dom = createDomView(root, registry, view.api, options);\n dom.render();\n const stop = view.subscribe(dom.render);\n return {\n destroy: () => {\n stop();\n dom.destroy();\n },\n };\n};\n"]}
@@ -0,0 +1,29 @@
1
+ import { C as ComponentRegistry } from '../../types-De0KpxfI.cjs';
2
+ import { N as NovaEvent } from '../../schemas-pMyyuXV7.cjs';
3
+ import { R as RenderApi, a as Shell } from '../../types-Dv6JLmgo.cjs';
4
+ import 'zod';
5
+ import '../../schemas-DPdeFlCT.cjs';
6
+ import '../../index-caZoXSwr.cjs';
7
+ import '../../effects-CndX9K7D.cjs';
8
+
9
+ type DomComponentContext = {
10
+ props: Record<string, unknown>;
11
+ children: Node[];
12
+ dispatch: (event: NovaEvent) => void;
13
+ };
14
+ type DomComponent = (ctx: DomComponentContext) => HTMLElement;
15
+ type DomRenderApi = RenderApi;
16
+ type DomView = {
17
+ render: () => void;
18
+ destroy: () => void;
19
+ };
20
+ declare const createDomView: (root: HTMLElement, registry: ComponentRegistry<DomComponent>, api: DomRenderApi, options?: {
21
+ fallback?: DomComponent;
22
+ }) => DomView;
23
+ declare const mountShell: (root: HTMLElement, registry: ComponentRegistry<DomComponent>, shell: Shell, options?: {
24
+ fallback?: DomComponent;
25
+ }) => {
26
+ destroy: () => void;
27
+ };
28
+
29
+ export { type DomComponent, type DomComponentContext, type DomRenderApi, type DomView, createDomView, mountShell };
@@ -0,0 +1,29 @@
1
+ import { C as ComponentRegistry } from '../../types-Brc7v_pS.js';
2
+ import { N as NovaEvent } from '../../schemas-pMyyuXV7.js';
3
+ import { R as RenderApi, a as Shell } from '../../types-Boh9ckdG.js';
4
+ import 'zod';
5
+ import '../../schemas-DPdeFlCT.js';
6
+ import '../../index-CNfzSBe2.js';
7
+ import '../../effects-CndX9K7D.js';
8
+
9
+ type DomComponentContext = {
10
+ props: Record<string, unknown>;
11
+ children: Node[];
12
+ dispatch: (event: NovaEvent) => void;
13
+ };
14
+ type DomComponent = (ctx: DomComponentContext) => HTMLElement;
15
+ type DomRenderApi = RenderApi;
16
+ type DomView = {
17
+ render: () => void;
18
+ destroy: () => void;
19
+ };
20
+ declare const createDomView: (root: HTMLElement, registry: ComponentRegistry<DomComponent>, api: DomRenderApi, options?: {
21
+ fallback?: DomComponent;
22
+ }) => DomView;
23
+ declare const mountShell: (root: HTMLElement, registry: ComponentRegistry<DomComponent>, shell: Shell, options?: {
24
+ fallback?: DomComponent;
25
+ }) => {
26
+ destroy: () => void;
27
+ };
28
+
29
+ export { type DomComponent, type DomComponentContext, type DomRenderApi, type DomView, createDomView, mountShell };
@@ -0,0 +1,15 @@
1
+ export { createDomView, mountShell } from '../../chunk-OAMC6R6E.js';
2
+ import '../../chunk-7B3RDENH.js';
3
+ import '../../chunk-RQB4PRPV.js';
4
+ import '../../chunk-OGD5CCMZ.js';
5
+ import '../../chunk-GVBBL36G.js';
6
+ import '../../chunk-ZITHBBF3.js';
7
+ import '../../chunk-V32EVEVM.js';
8
+ import '../../chunk-7TS3YVQR.js';
9
+ import '../../chunk-PF4OJTYU.js';
10
+ import '../../chunk-JI7ZRESP.js';
11
+ import '../../chunk-RBU5PHN4.js';
12
+ import '../../chunk-2MNLEL45.js';
13
+ import '../../chunk-PZ5AY32C.js';
14
+ //# sourceMappingURL=index.js.map
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,129 @@
1
+ 'use strict';
2
+
3
+ // src/adapters/dom/index.ts
4
+ var CANVAS_SLOT = "CanvasSlot";
5
+ var ACTION_SLOT = "ActionSlot";
6
+ var errorEl = (code, message) => {
7
+ const el = document.createElement("div");
8
+ el.setAttribute("data-nova-error", code);
9
+ el.textContent = `${code}: ${message}`;
10
+ return el;
11
+ };
12
+ var readValue = (target) => {
13
+ if (target instanceof HTMLInputElement && target.type === "checkbox") return target.checked;
14
+ if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return target.value;
15
+ return "";
16
+ };
17
+ var wireEvents = (el, node, dispatch) => {
18
+ if (node.model !== void 0) {
19
+ const ref = node.model.ref;
20
+ const debounce = typeof node.props["debounce"] === "number" ? node.props["debounce"] : 0;
21
+ let timer;
22
+ const fire = (value) => dispatch({ type: "ui:model", ref, payload: value });
23
+ el.addEventListener("input", (e) => {
24
+ const value = readValue(e.target);
25
+ if (debounce > 0) {
26
+ clearTimeout(timer);
27
+ timer = setTimeout(() => fire(value), debounce);
28
+ } else fire(value);
29
+ });
30
+ el.addEventListener("keydown", (e) => {
31
+ if (e instanceof KeyboardEvent) dispatch({ type: "ui:key", ref, key: e.key });
32
+ });
33
+ return;
34
+ }
35
+ if (node.ref !== void 0) {
36
+ const ref = node.ref;
37
+ el.addEventListener("click", (e) => {
38
+ e.stopPropagation();
39
+ const value = node.props["value"];
40
+ dispatch(value === void 0 ? { type: "ui:click", ref } : { type: "ui:click", ref, payload: value });
41
+ });
42
+ }
43
+ };
44
+ var inInstance = (node, ctx) => {
45
+ if (node.type !== "component" || node.name !== ACTION_SLOT) return ctx;
46
+ const instanceId = node.props["instanceId"];
47
+ if (typeof instanceId !== "string" || instanceId === "") return ctx;
48
+ const outer = ctx.dispatch;
49
+ return { ...ctx, dispatch: (event) => outer(event.origin === void 0 ? { ...event, origin: instanceId } : event) };
50
+ };
51
+ var renderNode = (node, parent) => {
52
+ const ctx = inInstance(node, parent);
53
+ if (node.type === "text") return document.createTextNode(node.value);
54
+ if (node.type === "fragment") {
55
+ const frag = document.createDocumentFragment();
56
+ for (const child of node.children) frag.appendChild(renderNode(child, ctx));
57
+ return frag;
58
+ }
59
+ if (node.type === "error") return errorEl(node.code, node.message);
60
+ if (node.name === CANVAS_SLOT) {
61
+ const canvasId = typeof node.props["canvasId"] === "string" ? node.props["canvasId"] : "";
62
+ const host = document.createElement("div");
63
+ host.setAttribute("data-canvas", canvasId);
64
+ if (canvasId === "") return host;
65
+ const canvasCtx = { ...ctx, dispatch: (event) => ctx.api.dispatch(canvasId, event) };
66
+ for (const child of ctx.api.canvasTree(canvasId)) host.appendChild(renderNode(child, canvasCtx));
67
+ return host;
68
+ }
69
+ const entry = ctx.registry.get(node.name);
70
+ const build = entry !== void 0 ? entry.component : ctx.fallback;
71
+ if (build === void 0) return errorEl("COMPONENT_NOT_FOUND", node.name);
72
+ const children = node.children.map((child) => renderNode(child, ctx));
73
+ const el = build({ props: node.props, children, dispatch: ctx.dispatch });
74
+ el.setAttribute("data-component", node.name);
75
+ if (node.ref !== void 0) el.setAttribute("data-ref", node.ref);
76
+ wireEvents(el, node, ctx.dispatch);
77
+ return el;
78
+ };
79
+ var captureFocus = (root) => {
80
+ const active = root.ownerDocument.activeElement;
81
+ if (!(active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement)) return void 0;
82
+ const ref = active.getAttribute("data-ref");
83
+ if (ref === null || !root.contains(active)) return void 0;
84
+ return { ref, value: active.value, start: active.selectionStart, end: active.selectionEnd };
85
+ };
86
+ var restoreFocus = (root, focus) => {
87
+ const el = root.querySelector(`[data-ref="${focus.ref}"]`);
88
+ if (!(el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)) return;
89
+ el.value = focus.value;
90
+ el.focus();
91
+ try {
92
+ el.setSelectionRange(focus.start ?? el.value.length, focus.end ?? el.value.length);
93
+ } catch {
94
+ }
95
+ };
96
+ var createDomView = (root, registry, api, options = {}) => {
97
+ const ctx = { registry, dispatch: () => void 0, api, ...options.fallback !== void 0 ? { fallback: options.fallback } : {} };
98
+ const render = () => {
99
+ const focus = captureFocus(root);
100
+ root.replaceChildren();
101
+ for (const node of api.frame()) root.appendChild(renderNode(node, ctx));
102
+ if (focus !== void 0) restoreFocus(root, focus);
103
+ };
104
+ return { render, destroy: () => root.replaceChildren() };
105
+ };
106
+
107
+ // src/adapters/dom/server.ts
108
+ var LENT = ["document", "Node", "Element", "HTMLElement", "SVGElement", "HTMLInputElement", "HTMLTextAreaElement", "HTMLSelectElement", "KeyboardEvent", "Event"];
109
+ var renderToString = (registry, api, options) => {
110
+ const before = LENT.map((name) => [name, Object.getOwnPropertyDescriptor(globalThis, name)]);
111
+ try {
112
+ for (const name of LENT) {
113
+ const value = Reflect.get(options.window, name);
114
+ if (value !== void 0) Object.defineProperty(globalThis, name, { value, configurable: true, writable: true });
115
+ }
116
+ const root = document.createElement("div");
117
+ createDomView(root, registry, api, options.fallback !== void 0 ? { fallback: options.fallback } : {}).render();
118
+ return root.innerHTML;
119
+ } finally {
120
+ for (const [name, descriptor] of before) {
121
+ if (descriptor === void 0) Reflect.deleteProperty(globalThis, name);
122
+ else Object.defineProperty(globalThis, name, descriptor);
123
+ }
124
+ }
125
+ };
126
+
127
+ exports.renderToString = renderToString;
128
+ //# sourceMappingURL=server.cjs.map
129
+ //# sourceMappingURL=server.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapters/d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,aAAa,KAAA,CAAA,GAAY,EAAE,QAAA,EAAU,OAAA,CAAQ,QAAA,EAAS,GAAI,EAAE,EAAE,MAAA,EAAO;AAChH,IAAA,OAAO,IAAA,CAAK,SAAA;AAAA,EACd,CAAA,SAAE;AACA,IAAA,KAAA,MAAW,CAAC,IAAA,EAAM,UAAU,CAAA,IAAK,MAAA,EAAQ;AACvC,MAAA,IAAI,UAAA,KAAe,MAAA,EAAW,OAAA,CAAQ,cAAA,CAAe,YAAY,IAAI,CAAA;AAAA,WAChE,MAAA,CAAO,cAAA,CAAe,UAAA,EAAY,IAAA,EAAM,UAAU,CAAA;AAAA,IACzD;AAAA,EACF;AACF","file":"server.cjs","sourcesContent":["import type { ComponentRegistry, RenderNode } from '@layout/types';\nimport type { NovaEvent } from '@shared/event-bus/schemas';\nimport { shellView } from '@shell';\nimport type { RenderApi, Shell } from '@shell';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/adapters/dom — a vanilla-DOM adapter, the platform sibling of\n// nova/react. It turns a served RenderNode tree into DOM: registry lookup →\n// element, recurse children, and wire events BY CONVENTION — a `ref`'d\n// element dispatches `ui:click`, a `model`'d element dispatches `ui:model`\n// (+ `ui:key`), the payload of a click is the node's `value` prop. Origin is\n// never stamped here — moss stamps the active instance server-side.\n//\n// No framework: the registry maps a component name to a function that builds\n// an element from props + already-rendered children. `CanvasSlot` is resolved\n// here (the frame's markers → per-canvas trees), the one piece of terminal\n// structure the renderer owns; the terminal hands in `canvasTree`/`dispatch`.\n// See packages/nova/ADAPTER.md for the shared adapter contract.\n// ═══════════════════════════════════════════════════════════\n\nexport type DomComponentContext = {\n props: Record<string, unknown>;\n // the node's children, already rendered — the component appends them where\n // it wants (most append to their own element; leaves ignore them).\n children: Node[];\n // the dispatch in force here (canvas-scoped inside a CanvasSlot) — for\n // data-driven components with INTERNAL interactivity (a table's row clicks,\n // an inline checkbox); simple components ignore it and let the renderer wire\n // their `ref`/`model` by convention.\n dispatch: (event: NovaEvent) => void;\n};\n\n// A DOM component: props + rendered children in, one element out.\nexport type DomComponent = (ctx: DomComponentContext) => HTMLElement;\n\n// What the terminal hands the view: core's `RenderApi` (the frame, per-canvas\n// trees, a canvas-scoped dispatch, publish). Aliased, not redeclared, so the\n// dom adapter, the react adapter, and moss's terminal share ONE definition —\n// drift is impossible. CanvasSlot resolution + event routing ride these; the\n// renderer never touches the wire directly.\nexport type DomRenderApi = RenderApi;\n\nexport type DomView = {\n // (re)render from the current snapshot; call on every wire change\n render: () => void;\n destroy: () => void;\n};\n\nconst CANVAS_SLOT = 'CanvasSlot';\nconst ACTION_SLOT = 'ActionSlot';\n\n// The recursion context: the registry, the dispatch in force (frame chrome\n// dispatches nothing; a CanvasSlot switches it to that canvas's), publish,\n// and the canvas resolver.\ntype Ctx = {\n registry: ComponentRegistry<DomComponent>;\n dispatch: (event: NovaEvent) => void;\n api: DomRenderApi;\n // used when a component name is unregistered — a permissive renderer (the\n // html terminal's default kit) supplies one so unknown primitives render\n // their children instead of an error; strict consumers omit it.\n fallback?: DomComponent;\n};\n\nconst errorEl = (code: string, message: string): HTMLElement => {\n const el = document.createElement('div');\n el.setAttribute('data-nova-error', code);\n el.textContent = `${code}: ${message}`;\n return el;\n};\n\n// Read the model value off an event target — a checkbox reports `checked`,\n// everything else `value`.\nconst readValue = (target: EventTarget | null): unknown => {\n if (target instanceof HTMLInputElement && target.type === 'checkbox') return target.checked;\n if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return target.value;\n return '';\n};\n\n// Attach the conventional listeners: a model'd element is an input (dispatch\n// ui:model on change, ui:key on keydown); a bare ref'd element is clickable\n// (dispatch ui:click, payload = its `value` prop). Uniform across every\n// component — the event vocabulary is the convention, not per-component code.\nconst wireEvents = (el: HTMLElement, node: Extract<RenderNode, { type: 'component' }>, dispatch: (event: NovaEvent) => void): void => {\n if (node.model !== undefined) {\n const ref = node.model.ref;\n const debounce = typeof node.props['debounce'] === 'number' ? (node.props['debounce'] as number) : 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n const fire = (value: unknown): void => dispatch({ type: 'ui:model', ref, payload: value });\n el.addEventListener('input', (e) => {\n const value = readValue(e.target);\n if (debounce > 0) {\n clearTimeout(timer);\n timer = setTimeout(() => fire(value), debounce);\n } else fire(value);\n });\n el.addEventListener('keydown', (e) => {\n if (e instanceof KeyboardEvent) dispatch({ type: 'ui:key', ref, key: e.key });\n });\n return;\n }\n if (node.ref !== undefined) {\n const ref = node.ref;\n el.addEventListener('click', (e) => {\n e.stopPropagation();\n const value = node.props['value'];\n dispatch(value === undefined ? { type: 'ui:click', ref } : { type: 'ui:click', ref, payload: value });\n });\n }\n};\n\n// The per-instance boundary a served tree carries. A list canvas renders\n// several live instances at once, so a click inside THIS boundary must reach\n// THIS instance: its events carry it as their origin (the server's\n// active-instance fallback only holds for a card-deck canvas). An event that\n// already has an origin keeps it — moss's react terminal does the same.\nconst inInstance = (node: RenderNode, ctx: Ctx): Ctx => {\n if (node.type !== 'component' || node.name !== ACTION_SLOT) return ctx;\n const instanceId = node.props['instanceId'];\n if (typeof instanceId !== 'string' || instanceId === '') return ctx;\n const outer = ctx.dispatch;\n return { ...ctx, dispatch: (event) => outer(event.origin === undefined ? { ...event, origin: instanceId } : event) };\n};\n\nconst renderNode = (node: RenderNode, parent: Ctx): Node => {\n const ctx = inInstance(node, parent);\n if (node.type === 'text') return document.createTextNode(node.value);\n if (node.type === 'fragment') {\n const frag = document.createDocumentFragment();\n for (const child of node.children) frag.appendChild(renderNode(child, ctx));\n return frag;\n }\n if (node.type === 'error') return errorEl(node.code, node.message);\n\n // component\n if (node.name === CANVAS_SLOT) {\n const canvasId = typeof node.props['canvasId'] === 'string' ? (node.props['canvasId'] as string) : '';\n const host = document.createElement('div');\n host.setAttribute('data-canvas', canvasId);\n if (canvasId === '') return host;\n // Switch dispatch to this canvas's; the server stamps origin, so the\n // terminal just tags the canvas.\n const canvasCtx: Ctx = { ...ctx, dispatch: (event) => ctx.api.dispatch(canvasId, event) };\n for (const child of ctx.api.canvasTree(canvasId)) host.appendChild(renderNode(child, canvasCtx));\n return host;\n }\n\n const entry = ctx.registry.get(node.name);\n const build = entry !== undefined ? entry.component : ctx.fallback;\n if (build === undefined) return errorEl('COMPONENT_NOT_FOUND', node.name);\n\n const children = node.children.map((child) => renderNode(child, ctx));\n const el = build({ props: node.props, children, dispatch: ctx.dispatch });\n el.setAttribute('data-component', node.name);\n if (node.ref !== undefined) el.setAttribute('data-ref', node.ref);\n wireEvents(el, node, ctx.dispatch);\n return el;\n};\n\n// The one interactive concession: never overwrite the value of the focused\n// input when a new tree arrives. We rebuild fully (the\n// server is authoritative), so capture the focused ref + value + caret before,\n// and restore them after — the in-progress value wins over the server's.\ntype Focus = { ref: string; value: string; start: number | null; end: number | null };\n\nconst captureFocus = (root: HTMLElement): Focus | undefined => {\n const active = root.ownerDocument.activeElement;\n if (!(active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement)) return undefined;\n const ref = active.getAttribute('data-ref');\n if (ref === null || !root.contains(active)) return undefined;\n return { ref, value: active.value, start: active.selectionStart, end: active.selectionEnd };\n};\n\nconst restoreFocus = (root: HTMLElement, focus: Focus): void => {\n const el = root.querySelector(`[data-ref=\"${focus.ref}\"]`);\n if (!(el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)) return;\n el.value = focus.value; // the user's in-progress value, not the server's\n el.focus();\n try {\n el.setSelectionRange(focus.start ?? el.value.length, focus.end ?? el.value.length);\n } catch {\n /* selectionRange throws on some input types — harmless */\n }\n};\n\nexport const createDomView = (\n root: HTMLElement,\n registry: ComponentRegistry<DomComponent>,\n api: DomRenderApi,\n options: { fallback?: DomComponent } = {},\n): DomView => {\n // The frame dispatches nothing (chrome); only a CanvasSlot's subtree does.\n const ctx: Ctx = { registry, dispatch: () => undefined, api, ...(options.fallback !== undefined ? { fallback: options.fallback } : {}) };\n const render = (): void => {\n const focus = captureFocus(root);\n root.replaceChildren();\n for (const node of api.frame()) root.appendChild(renderNode(node, ctx));\n if (focus !== undefined) restoreFocus(root, focus);\n };\n return { render, destroy: () => root.replaceChildren() };\n};\n\n// A SHELL THAT LIVES IN THIS PAGE, drawn into `root` and kept current: the\n// shell's own view (`shellView`), this adapter over it, and a re-render on every\n// change. The whole of a browser entry for an app whose shell runs in the\n// browser:\n//\n// mountShell(root, registry, await boot());\n//\n// A `root` that already holds the same screen as markup — drawn ahead of time\n// by `renderToString` (./server) from the same boot — is picked up by the first\n// render: the adapter rebuilds its root, so those elements are replaced with the\n// same elements in one step, and nothing can disagree with them.\nexport const mountShell = (\n root: HTMLElement,\n registry: ComponentRegistry<DomComponent>,\n shell: Shell,\n options: { fallback?: DomComponent } = {},\n): { destroy: () => void } => {\n const view = shellView(shell);\n const dom = createDomView(root, registry, view.api, options);\n dom.render();\n const stop = view.subscribe(dom.render);\n return {\n destroy: () => {\n stop();\n dom.destroy();\n },\n };\n};\n","import type { ComponentRegistry } from '@layout/types';\nimport type { RenderApi } from '@shell';\nimport { createDomView } from './index';\nimport type { DomComponent } from './index';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/adapters/dom/server — the DOM adapter, drawing to a string.\n//\n// A DOM kit builds real elements, so drawing one where there is no browser needs\n// a DOM to build them in. The caller hands one in — a `window` from jsdom,\n// happy-dom or linkedom; nova depends on none of them — and this draws into it\n// and reads the markup back. What is drawn is whatever the `RenderApi` holds: a\n// served snapshot, or a shell that lives in this process (`shellView`).\n//\n// A kit's components name `document` as a global, the way they do in a browser.\n// So for the length of one draw — synchronous from start to end, and so unable\n// to interleave with another — the window's own names are lent to the global\n// scope, and taken back whatever happens.\n//\n// The browser needs no twin of this to pick the page up: the adapter rebuilds\n// its root on every render, so its first render replaces these elements with\n// the same elements, in one step (`mountShell`).\n// ═══════════════════════════════════════════════════════════\n\n// What a DOM kit and the adapter itself name as globals.\nconst LENT = ['document', 'Node', 'Element', 'HTMLElement', 'SVGElement', 'HTMLInputElement', 'HTMLTextAreaElement', 'HTMLSelectElement', 'KeyboardEvent', 'Event'];\n\nexport const renderToString = (registry: ComponentRegistry<DomComponent>, api: RenderApi, options: { window: object; fallback?: DomComponent }): string => {\n const before = LENT.map((name) => [name, Object.getOwnPropertyDescriptor(globalThis, name)] as const);\n try {\n for (const name of LENT) {\n const value: unknown = Reflect.get(options.window, name);\n if (value !== undefined) Object.defineProperty(globalThis, name, { value, configurable: true, writable: true });\n }\n const root = document.createElement('div');\n createDomView(root, registry, api, options.fallback !== undefined ? { fallback: options.fallback } : {}).render();\n return root.innerHTML;\n } finally {\n for (const [name, descriptor] of before) {\n if (descriptor === undefined) Reflect.deleteProperty(globalThis, name);\n else Object.defineProperty(globalThis, name, descriptor);\n }\n }\n};\n"]}
@@ -0,0 +1,15 @@
1
+ import { C as ComponentRegistry } from '../../types-De0KpxfI.cjs';
2
+ import { R as RenderApi } from '../../types-Dv6JLmgo.cjs';
3
+ import { DomComponent } from './index.cjs';
4
+ import 'zod';
5
+ import '../../schemas-DPdeFlCT.cjs';
6
+ import '../../index-caZoXSwr.cjs';
7
+ import '../../effects-CndX9K7D.cjs';
8
+ import '../../schemas-pMyyuXV7.cjs';
9
+
10
+ declare const renderToString: (registry: ComponentRegistry<DomComponent>, api: RenderApi, options: {
11
+ window: object;
12
+ fallback?: DomComponent;
13
+ }) => string;
14
+
15
+ export { renderToString };
@@ -0,0 +1,15 @@
1
+ import { C as ComponentRegistry } from '../../types-Brc7v_pS.js';
2
+ import { R as RenderApi } from '../../types-Boh9ckdG.js';
3
+ import { DomComponent } from './index.js';
4
+ import 'zod';
5
+ import '../../schemas-DPdeFlCT.js';
6
+ import '../../index-CNfzSBe2.js';
7
+ import '../../effects-CndX9K7D.js';
8
+ import '../../schemas-pMyyuXV7.js';
9
+
10
+ declare const renderToString: (registry: ComponentRegistry<DomComponent>, api: RenderApi, options: {
11
+ window: object;
12
+ fallback?: DomComponent;
13
+ }) => string;
14
+
15
+ export { renderToString };
@@ -0,0 +1,37 @@
1
+ import { createDomView } from '../../chunk-OAMC6R6E.js';
2
+ import '../../chunk-7B3RDENH.js';
3
+ import '../../chunk-RQB4PRPV.js';
4
+ import '../../chunk-OGD5CCMZ.js';
5
+ import '../../chunk-GVBBL36G.js';
6
+ import '../../chunk-ZITHBBF3.js';
7
+ import '../../chunk-V32EVEVM.js';
8
+ import '../../chunk-7TS3YVQR.js';
9
+ import '../../chunk-PF4OJTYU.js';
10
+ import '../../chunk-JI7ZRESP.js';
11
+ import '../../chunk-RBU5PHN4.js';
12
+ import '../../chunk-2MNLEL45.js';
13
+ import '../../chunk-PZ5AY32C.js';
14
+
15
+ // src/adapters/dom/server.ts
16
+ var LENT = ["document", "Node", "Element", "HTMLElement", "SVGElement", "HTMLInputElement", "HTMLTextAreaElement", "HTMLSelectElement", "KeyboardEvent", "Event"];
17
+ var renderToString = (registry, api, options) => {
18
+ const before = LENT.map((name) => [name, Object.getOwnPropertyDescriptor(globalThis, name)]);
19
+ try {
20
+ for (const name of LENT) {
21
+ const value = Reflect.get(options.window, name);
22
+ if (value !== void 0) Object.defineProperty(globalThis, name, { value, configurable: true, writable: true });
23
+ }
24
+ const root = document.createElement("div");
25
+ createDomView(root, registry, api, options.fallback !== void 0 ? { fallback: options.fallback } : {}).render();
26
+ return root.innerHTML;
27
+ } finally {
28
+ for (const [name, descriptor] of before) {
29
+ if (descriptor === void 0) Reflect.deleteProperty(globalThis, name);
30
+ else Object.defineProperty(globalThis, name, descriptor);
31
+ }
32
+ }
33
+ };
34
+
35
+ export { renderToString };
36
+ //# sourceMappingURL=server.js.map
37
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapters/dom/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAyBA,IAAM,IAAA,GAAO,CAAC,UAAA,EAAY,MAAA,EAAQ,SAAA,EAAW,aAAA,EAAe,YAAA,EAAc,kBAAA,EAAoB,qBAAA,EAAuB,mBAAA,EAAqB,eAAA,EAAiB,OAAO,CAAA;AAE3J,IAAM,cAAA,GAAiB,CAAC,QAAA,EAA2C,GAAA,EAAgB,OAAA,KAAiE;AACzJ,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,GAAA,CAAI,CAAC,IAAA,KAAS,CAAC,IAAA,EAAM,MAAA,CAAO,wBAAA,CAAyB,UAAA,EAAY,IAAI,CAAC,CAAU,CAAA;AACpG,EAAA,IAAI;AACF,IAAA,KAAA,MAAW,QAAQ,IAAA,EAAM;AACvB,MAAA,MAAM,KAAA,GAAiB,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,QAAQ,IAAI,CAAA;AACvD,MAAA,IAAI,KAAA,KAAU,KAAA,CAAA,EAAW,MAAA,CAAO,cAAA,CAAe,UAAA,EAAY,IAAA,EAAM,EAAE,KAAA,EAAO,YAAA,EAAc,IAAA,EAAM,QAAA,EAAU,IAAA,EAAM,CAAA;AAAA,IAChH;AACA,IAAA,MAAM,IAAA,GAAO,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AACzC,IAAA,aAAA,CAAc,IAAA,EAAM,QAAA,EAAU,GAAA,EAAK,OAAA,CAAQ,aAAa,KAAA,CAAA,GAAY,EAAE,QAAA,EAAU,OAAA,CAAQ,QAAA,EAAS,GAAI,EAAE,EAAE,MAAA,EAAO;AAChH,IAAA,OAAO,IAAA,CAAK,SAAA;AAAA,EACd,CAAA,SAAE;AACA,IAAA,KAAA,MAAW,CAAC,IAAA,EAAM,UAAU,CAAA,IAAK,MAAA,EAAQ;AACvC,MAAA,IAAI,UAAA,KAAe,MAAA,EAAW,OAAA,CAAQ,cAAA,CAAe,YAAY,IAAI,CAAA;AAAA,WAChE,MAAA,CAAO,cAAA,CAAe,UAAA,EAAY,IAAA,EAAM,UAAU,CAAA;AAAA,IACzD;AAAA,EACF;AACF","file":"server.js","sourcesContent":["import type { ComponentRegistry } from '@layout/types';\nimport type { RenderApi } from '@shell';\nimport { createDomView } from './index';\nimport type { DomComponent } from './index';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/adapters/dom/server — the DOM adapter, drawing to a string.\n//\n// A DOM kit builds real elements, so drawing one where there is no browser needs\n// a DOM to build them in. The caller hands one in — a `window` from jsdom,\n// happy-dom or linkedom; nova depends on none of them — and this draws into it\n// and reads the markup back. What is drawn is whatever the `RenderApi` holds: a\n// served snapshot, or a shell that lives in this process (`shellView`).\n//\n// A kit's components name `document` as a global, the way they do in a browser.\n// So for the length of one draw — synchronous from start to end, and so unable\n// to interleave with another — the window's own names are lent to the global\n// scope, and taken back whatever happens.\n//\n// The browser needs no twin of this to pick the page up: the adapter rebuilds\n// its root on every render, so its first render replaces these elements with\n// the same elements, in one step (`mountShell`).\n// ═══════════════════════════════════════════════════════════\n\n// What a DOM kit and the adapter itself name as globals.\nconst LENT = ['document', 'Node', 'Element', 'HTMLElement', 'SVGElement', 'HTMLInputElement', 'HTMLTextAreaElement', 'HTMLSelectElement', 'KeyboardEvent', 'Event'];\n\nexport const renderToString = (registry: ComponentRegistry<DomComponent>, api: RenderApi, options: { window: object; fallback?: DomComponent }): string => {\n const before = LENT.map((name) => [name, Object.getOwnPropertyDescriptor(globalThis, name)] as const);\n try {\n for (const name of LENT) {\n const value: unknown = Reflect.get(options.window, name);\n if (value !== undefined) Object.defineProperty(globalThis, name, { value, configurable: true, writable: true });\n }\n const root = document.createElement('div');\n createDomView(root, registry, api, options.fallback !== undefined ? { fallback: options.fallback } : {}).render();\n return root.innerHTML;\n } finally {\n for (const [name, descriptor] of before) {\n if (descriptor === undefined) Reflect.deleteProperty(globalThis, name);\n else Object.defineProperty(globalThis, name, descriptor);\n }\n }\n};\n"]}