@niscorp/nova 0.2.1 → 0.2.2

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 (80) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/adapters/dom/components/index.cjs +4 -51
  3. package/dist/adapters/dom/components/index.cjs.map +1 -1
  4. package/dist/adapters/dom/index.cjs +22 -686
  5. package/dist/adapters/dom/index.cjs.map +1 -1
  6. package/dist/adapters/dom/server.cjs +14 -411
  7. package/dist/adapters/dom/server.cjs.map +1 -1
  8. package/dist/adapters/react/components/index.cjs +87 -562
  9. package/dist/adapters/react/components/index.cjs.map +1 -1
  10. package/dist/adapters/react/components/index.d.cts +2 -2
  11. package/dist/adapters/react/components/index.d.ts +2 -2
  12. package/dist/adapters/react/index.cjs +97 -1815
  13. package/dist/adapters/react/index.cjs.map +1 -1
  14. package/dist/adapters/tty/components/index.cjs +3 -44
  15. package/dist/adapters/tty/components/index.cjs.map +1 -1
  16. package/dist/adapters/tty/index.cjs +13 -5
  17. package/dist/adapters/tty/index.cjs.map +1 -1
  18. package/dist/adapters/vue/components/index.cjs +88 -639
  19. package/dist/adapters/vue/components/index.cjs.map +1 -1
  20. package/dist/adapters/vue/components/index.d.cts +10 -10
  21. package/dist/adapters/vue/components/index.d.ts +10 -10
  22. package/dist/adapters/vue/index.cjs +96 -962
  23. package/dist/adapters/vue/index.cjs.map +1 -1
  24. package/dist/agent/index.cjs +13 -151
  25. package/dist/agent/index.cjs.map +1 -1
  26. package/dist/chunk-3IPM5QBT.cjs +436 -0
  27. package/dist/chunk-3IPM5QBT.cjs.map +1 -0
  28. package/dist/chunk-5AF72LOE.cjs +97 -0
  29. package/dist/chunk-5AF72LOE.cjs.map +1 -0
  30. package/dist/chunk-5YQIAS4V.cjs +184 -0
  31. package/dist/chunk-5YQIAS4V.cjs.map +1 -0
  32. package/dist/chunk-D4PUWBN6.cjs +72 -0
  33. package/dist/chunk-D4PUWBN6.cjs.map +1 -0
  34. package/dist/chunk-FSUMCJAR.cjs +646 -0
  35. package/dist/chunk-FSUMCJAR.cjs.map +1 -0
  36. package/dist/chunk-GV7UC3SS.cjs +33 -0
  37. package/dist/chunk-GV7UC3SS.cjs.map +1 -0
  38. package/dist/chunk-IZ2UU5UL.cjs +808 -0
  39. package/dist/chunk-IZ2UU5UL.cjs.map +1 -0
  40. package/dist/chunk-KOYRJXTI.cjs +123 -0
  41. package/dist/chunk-KOYRJXTI.cjs.map +1 -0
  42. package/dist/chunk-KW34ZKF5.cjs +12 -0
  43. package/dist/chunk-KW34ZKF5.cjs.map +1 -0
  44. package/dist/chunk-OE527MXF.cjs +49 -0
  45. package/dist/chunk-OE527MXF.cjs.map +1 -0
  46. package/dist/chunk-OO247V4J.cjs +2117 -0
  47. package/dist/chunk-OO247V4J.cjs.map +1 -0
  48. package/dist/chunk-PMKWYOOX.cjs +64 -0
  49. package/dist/chunk-PMKWYOOX.cjs.map +1 -0
  50. package/dist/chunk-PNQY6OFB.cjs +132 -0
  51. package/dist/chunk-PNQY6OFB.cjs.map +1 -0
  52. package/dist/chunk-Q7SFCCGT.cjs +11 -0
  53. package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
  54. package/dist/chunk-TMLNVU5W.cjs +318 -0
  55. package/dist/chunk-TMLNVU5W.cjs.map +1 -0
  56. package/dist/chunk-TRJYDVWK.cjs +623 -0
  57. package/dist/chunk-TRJYDVWK.cjs.map +1 -0
  58. package/dist/chunk-UGG7MCX4.cjs +34 -0
  59. package/dist/chunk-UGG7MCX4.cjs.map +1 -0
  60. package/dist/chunk-WGPFR7MN.cjs +808 -0
  61. package/dist/chunk-WGPFR7MN.cjs.map +1 -0
  62. package/dist/chunk-WGZZKCJQ.cjs +157 -0
  63. package/dist/chunk-WGZZKCJQ.cjs.map +1 -0
  64. package/dist/devtools/index.cjs +13 -697
  65. package/dist/devtools/index.cjs.map +1 -1
  66. package/dist/document/index.cjs +56 -301
  67. package/dist/document/index.cjs.map +1 -1
  68. package/dist/examples/index.cjs +6 -31
  69. package/dist/examples/index.cjs.map +1 -1
  70. package/dist/i18n/index.cjs +44 -292
  71. package/dist/i18n/index.cjs.map +1 -1
  72. package/dist/index.cjs +335 -3954
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/migrations/index.cjs +7 -590
  75. package/dist/migrations/index.cjs.map +1 -1
  76. package/dist/reflect/index.cjs +85 -994
  77. package/dist/reflect/index.cjs.map +1 -1
  78. package/package.json +5 -5
  79. package/dist/{primitive-props-CGoJvmcH.d.cts → primitive-props-Cl5jiC8g.d.cts} +5 -5
  80. package/dist/{primitive-props-CGoJvmcH.d.ts → primitive-props-Cl5jiC8g.d.ts} +5 -5
@@ -0,0 +1,808 @@
1
+ 'use strict';
2
+
3
+ var chunkPMKWYOOX_cjs = require('./chunk-PMKWYOOX.cjs');
4
+ var chunkKOYRJXTI_cjs = require('./chunk-KOYRJXTI.cjs');
5
+ var chunkGV7UC3SS_cjs = require('./chunk-GV7UC3SS.cjs');
6
+ var chunkFSUMCJAR_cjs = require('./chunk-FSUMCJAR.cjs');
7
+ var chunkD4PUWBN6_cjs = require('./chunk-D4PUWBN6.cjs');
8
+ var chunkKW34ZKF5_cjs = require('./chunk-KW34ZKF5.cjs');
9
+ var prism = require('@niscorp/prism');
10
+ var strata = require('@niscorp/strata');
11
+ var zod = require('zod');
12
+
13
+ // src/shared/bindings/scope.ts
14
+ var createScopeChain = (data) => [data];
15
+ var pushScope = (chain, scope) => [scope, ...chain];
16
+ var TEMPLATE_REGEX = /\{\{\s*([^}]+?)\s*\}\}/g;
17
+ var SOLE_TEMPLATE_REGEX = /^\{\{\s*([^}]+?)\s*\}\}$/;
18
+ var BARE_PATH_REGEX = /^\$(\.|[A-Za-z_]|$)/;
19
+ var matchExtra = (expression, extras) => {
20
+ let matched;
21
+ for (const key of Object.keys(extras)) {
22
+ if (expression === key || expression.startsWith(`${key}.`)) {
23
+ if (matched === void 0 || key.length > matched.length) matched = key;
24
+ }
25
+ }
26
+ return matched;
27
+ };
28
+ var resolveExtraExpression = (expression, matchedKey, extras) => {
29
+ const root = extras[matchedKey];
30
+ if (expression === matchedKey) return root;
31
+ const rest = expression.slice(matchedKey.length + 1);
32
+ if (rest.length === 0) return root;
33
+ return chunkFSUMCJAR_cjs.getPath(root, rest);
34
+ };
35
+ var walkFromScopeHead = (head, restSegments) => {
36
+ if (restSegments.length === 0) return head;
37
+ return chunkFSUMCJAR_cjs.getPath(head, restSegments.join("."));
38
+ };
39
+ var resolvePath = (path, chain, extras = {}) => {
40
+ const extraKey = matchExtra(path, extras);
41
+ if (extraKey !== void 0) return resolveExtraExpression(path, extraKey, extras);
42
+ if (!path.startsWith("$")) return void 0;
43
+ if (path === "$") return chain[0];
44
+ const afterDollar = path.slice(1);
45
+ if (afterDollar.startsWith(".")) {
46
+ const rest = afterDollar.slice(1);
47
+ if (rest.length === 0) return chain[0];
48
+ const segments2 = rest.split(".");
49
+ const head = segments2[0];
50
+ if (head === void 0) return void 0;
51
+ for (const scope of chain) {
52
+ if (chunkKW34ZKF5_cjs.hasKey(scope, head)) {
53
+ return walkFromScopeHead(scope[head], segments2.slice(1));
54
+ }
55
+ }
56
+ return void 0;
57
+ }
58
+ const segments = afterDollar.split(".");
59
+ const varName = segments[0];
60
+ if (varName === void 0 || varName.length === 0) return void 0;
61
+ for (const scope of chain) {
62
+ if (chunkKW34ZKF5_cjs.hasKey(scope, varName)) {
63
+ return walkFromScopeHead(scope[varName], segments.slice(1));
64
+ }
65
+ }
66
+ return void 0;
67
+ };
68
+ var stringify = (value) => {
69
+ if (value === null || value === void 0) return "";
70
+ if (typeof value === "string") return value;
71
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
72
+ try {
73
+ return JSON.stringify(value);
74
+ } catch {
75
+ return "";
76
+ }
77
+ };
78
+ var isTruthy = (value) => {
79
+ if (value === null || value === void 0) return false;
80
+ if (value === false) return false;
81
+ if (value === 0) return false;
82
+ if (value === "") return false;
83
+ if (chunkKW34ZKF5_cjs.isArray(value) && value.length === 0) return false;
84
+ return true;
85
+ };
86
+ var DIRECTIVES = {
87
+ $if: (node, chain, extras) => {
88
+ if (isTruthy(resolve(node.$if, chain, extras))) return resolve(node.$then, chain, extras);
89
+ if (chunkKW34ZKF5_cjs.hasKey(node, "$else")) return resolve(node.$else, chain, extras);
90
+ return void 0;
91
+ },
92
+ $eq: (node, chain, extras) => {
93
+ const args = chunkKW34ZKF5_cjs.isArray(node.$eq) ? node.$eq : [];
94
+ return resolve(args[0], chain, extras) === resolve(args[1], chain, extras);
95
+ },
96
+ // True when the operand path resolves to a present value. The structural
97
+ // counterpart to `$eq`: discriminate a union by which key a branch carries
98
+ // (`{ $exists: "$.shape.component" }`) rather than a shared tag's value.
99
+ $exists: (node, chain, extras) => resolve(node.$exists, chain, extras) !== void 0,
100
+ // Read an array element by a (dynamic) index: `{ $at: ["$.results", "$.i"] }`.
101
+ // An optional third arg pulls one field off the element: `["$.results", "$.i",
102
+ // "id"]`. Returns undefined when the array/index doesn't resolve.
103
+ $at: (node, chain, extras) => {
104
+ const args = chunkKW34ZKF5_cjs.isArray(node.$at) ? node.$at : [];
105
+ const arr = resolve(args[0], chain, extras);
106
+ const index = Number(resolve(args[1], chain, extras));
107
+ if (!chunkKW34ZKF5_cjs.isArray(arr) || Number.isNaN(index)) return void 0;
108
+ const element = arr[index];
109
+ const field = args[2];
110
+ return field !== void 0 && chunkKW34ZKF5_cjs.isObject(element) ? element[String(field)] : element;
111
+ },
112
+ // THE WHOLE TRANSFORM GRAMMAR, BEHIND ONE EXPLICIT DOOR. The directives
113
+ // above stay the small binding set; a value that needs a real transformation
114
+ // — a join, a projection, a group — says so out loud: `{ $prism: <node> }`
115
+ // evaluates the node with prism against the action's ROOT data. One grammar,
116
+ // one evaluator, nothing ambient — a prism-shaped object OUTSIDE this
117
+ // wrapper stays what it always was, a plain object walked for strings.
118
+ //
119
+ // The quiet failure this replaces was worse than a crash: an unrecognised
120
+ // op-shaped value passed through `resolve` as structure, landed in data, and
121
+ // rendered as garbage three screens later. Inside the wrapper, a bad node
122
+ // resolves to undefined — absent, not wrong.
123
+ $prism: (node, chain) => {
124
+ const result = prism.evaluateSafe(node.$prism, chain[0] ?? {});
125
+ return result.ok ? result.data : void 0;
126
+ }
127
+ };
128
+ var directiveOf = (value) => {
129
+ for (const key of Object.keys(value)) {
130
+ const directive = DIRECTIVES[key];
131
+ if (directive !== void 0) return directive;
132
+ }
133
+ return void 0;
134
+ };
135
+ var resolveString = (value, chain, extras) => {
136
+ const sole = value.match(SOLE_TEMPLATE_REGEX);
137
+ if (sole !== null) {
138
+ const expr = sole[1];
139
+ if (expr === void 0) return value;
140
+ return resolvePath(expr.trim(), chain, extras);
141
+ }
142
+ if (value.includes("{{")) {
143
+ return value.replace(TEMPLATE_REGEX, (_match, expression) => {
144
+ const resolved = resolvePath(expression.trim(), chain, extras);
145
+ return stringify(resolved);
146
+ });
147
+ }
148
+ if (BARE_PATH_REGEX.test(value)) {
149
+ return resolvePath(value, chain, extras);
150
+ }
151
+ if (matchExtra(value, extras) !== void 0) {
152
+ return resolvePath(value, chain, extras);
153
+ }
154
+ return value;
155
+ };
156
+ var resolve = (value, chain, extras = {}) => {
157
+ if (typeof value === "string") return resolveString(value, chain, extras);
158
+ if (chunkKW34ZKF5_cjs.isArray(value)) return value.map((entry) => resolve(entry, chain, extras));
159
+ if (chunkKW34ZKF5_cjs.isObject(value)) {
160
+ const directive = directiveOf(value);
161
+ if (directive !== void 0) return directive(value, chain, extras);
162
+ const out = {};
163
+ for (const key of Object.keys(value)) {
164
+ out[key] = resolve(value[key], chain, extras);
165
+ }
166
+ return out;
167
+ }
168
+ return value;
169
+ };
170
+
171
+ // src/layout/guards.ts
172
+ var isLayoutPrimitive = (value) => value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
173
+ var isComponentNode = (value) => chunkKW34ZKF5_cjs.hasKey(value, "component") && typeof value["component"] === "string";
174
+ var isConditionalNode = (value) => chunkKW34ZKF5_cjs.hasKey(value, "if") && chunkKW34ZKF5_cjs.hasKey(value, "then") && !chunkKW34ZKF5_cjs.hasKey(value, "for");
175
+ var isLoopNode = (value) => chunkKW34ZKF5_cjs.hasKey(value, "for") && chunkKW34ZKF5_cjs.hasKey(value, "as") && chunkKW34ZKF5_cjs.hasKey(value, "do");
176
+ var isLayoutRefNode = (value) => chunkKW34ZKF5_cjs.isObject(value) && chunkKW34ZKF5_cjs.hasKey(value, "ref") && typeof value["ref"] === "string" && !chunkKW34ZKF5_cjs.hasKey(value, "component") && Object.keys(value).length === 1;
177
+ var isSlotNode = (value) => chunkKW34ZKF5_cjs.isObject(value) && chunkKW34ZKF5_cjs.hasKey(value, "slot") && typeof value["slot"] === "string" && Object.keys(value).length === 1;
178
+ var isLayoutNode = (value) => isLayoutPrimitive(value) || Array.isArray(value) || isComponentNode(value) || isConditionalNode(value) || isLoopNode(value) || isLayoutRefNode(value) || isSlotNode(value);
179
+
180
+ // src/layout/renderer.ts
181
+ var noopOnError = (_error) => {
182
+ };
183
+ var textNode = (value) => ({ type: "text", value });
184
+ var fragment = (children) => ({ type: "fragment", children });
185
+ var errorNode = (error, nodeRef) => ({
186
+ type: "error",
187
+ code: error.code,
188
+ message: error.message,
189
+ ...{}
190
+ });
191
+ var toRenderError = (err) => {
192
+ if (err instanceof chunkFSUMCJAR_cjs.NovaError) return err;
193
+ const message = err instanceof Error ? err.message : String(err);
194
+ return new chunkFSUMCJAR_cjs.RenderError(message, {}, { cause: err });
195
+ };
196
+ var resolveDataPath = (binding, scopePaths) => {
197
+ if (!binding.startsWith("$")) return void 0;
198
+ const after = binding.slice(1);
199
+ if (after.startsWith(".")) return after.slice(1);
200
+ const segments = after.split(".");
201
+ const head = segments[0];
202
+ if (head === void 0 || head.length === 0) return void 0;
203
+ for (let i = scopePaths.length - 1; i >= 0; i -= 1) {
204
+ const entry = scopePaths[i];
205
+ if (entry === void 0) continue;
206
+ const eq = entry.indexOf("=");
207
+ if (eq < 0) continue;
208
+ const key = entry.slice(0, eq);
209
+ if (key !== head) continue;
210
+ const rooted = entry.slice(eq + 1);
211
+ const rest = segments.slice(1).join(".");
212
+ if (rest.length === 0) return rooted;
213
+ return `${rooted}.${rest}`;
214
+ }
215
+ return void 0;
216
+ };
217
+ var makeAutoRef = (componentName, path) => `auto-${componentName}-${path}`;
218
+ var renderNode = (node, chain, ctx) => {
219
+ if (node === null) return [textNode("")];
220
+ if (typeof node === "string") {
221
+ const resolved = resolve(node, chain);
222
+ if (resolved === void 0 || resolved === null) return [textNode("")];
223
+ const value = String(resolved);
224
+ if (ctx.pass === void 0 || !ctx.pass.text || chunkKOYRJXTI_cjs.isBinding(node)) return [textNode(value)];
225
+ return [textNode(chunkKOYRJXTI_cjs.swap(value, `${ctx.where}#text`, ctx.pass))];
226
+ }
227
+ if (isLayoutPrimitive(node)) {
228
+ return [textNode(String(node))];
229
+ }
230
+ if (chunkKW34ZKF5_cjs.isArray(node)) {
231
+ const children = renderChildArray(node, chain, ctx);
232
+ return [fragment(children)];
233
+ }
234
+ if (isLayoutRefNode(node)) {
235
+ const target = ctx.store.get(node.ref);
236
+ if (target === void 0) {
237
+ throw new chunkFSUMCJAR_cjs.LayoutRefNotFoundError(`Layout ref not found: ${node.ref}`, { ref: node.ref });
238
+ }
239
+ return renderNode(target, chain, ctx);
240
+ }
241
+ if (isSlotNode(node)) {
242
+ return [];
243
+ }
244
+ if (isConditionalNode(node)) {
245
+ const condition = resolve(node.if, chain);
246
+ const truthy = condition !== void 0 && condition !== null && condition !== false && condition !== 0 && condition !== "";
247
+ const branchTruthy = chunkKW34ZKF5_cjs.isArray(condition) ? condition.length > 0 : truthy;
248
+ if (branchTruthy) return renderNode(node.then, chain, ctx);
249
+ if (node.else !== void 0) return renderNode(node.else, chain, ctx);
250
+ return [];
251
+ }
252
+ if (isLoopNode(node)) {
253
+ const items = resolve(node.for, chain);
254
+ if (!chunkKW34ZKF5_cjs.isArray(items)) return [];
255
+ const loopBasePath = typeof node.for === "string" ? resolveDataPath(node.for, ctx.scopePaths) : void 0;
256
+ const out = [];
257
+ items.forEach((item, index) => {
258
+ const innerChain = pushScope(chain, { [node.as]: item, index, items });
259
+ const nextScopePaths = loopBasePath === void 0 ? ctx.scopePaths : [...ctx.scopePaths, `${node.as}=${loopBasePath}.${index}`, `items=${loopBasePath}`];
260
+ const innerCtx = { ...ctx, scopePaths: nextScopePaths };
261
+ const idKey = node.key !== void 0 ? chunkFSUMCJAR_cjs.getPath(item, node.key) : index;
262
+ const rendered = safeRenderSingle(node.do, innerChain, innerCtx);
263
+ rendered.forEach((rn, sub) => {
264
+ out.push({ ...rn, key: rendered.length === 1 ? String(idKey) : `${String(idKey)}:${sub}` });
265
+ });
266
+ });
267
+ return [fragment(out)];
268
+ }
269
+ if (isComponentNode(node)) {
270
+ return [renderComponent(node, chain, ctx)];
271
+ }
272
+ return [];
273
+ };
274
+ var renderComponent = (node, chain, ctx) => {
275
+ if (!chunkGV7UC3SS_cjs.HEAD_NAMES.includes(node.component) && !ctx.registry.has(node.component)) {
276
+ throw new chunkFSUMCJAR_cjs.ComponentNotFoundError(
277
+ `Component not found in registry: ${node.component}`,
278
+ { name: node.component }
279
+ );
280
+ }
281
+ const pass = ctx.pass;
282
+ const at = pass === void 0 ? "" : `${ctx.where}/${node.component}`;
283
+ const props = Object.fromEntries(
284
+ Object.entries(node.props ?? {}).map(([k, v]) => {
285
+ const resolved = resolve(v, chain);
286
+ if (pass === void 0) return [k, resolved];
287
+ return [k, chunkKOYRJXTI_cjs.walkValue(resolved, pass.isProse(k), `${at}.${k}`, pass)];
288
+ })
289
+ );
290
+ const children = renderChildren(node.children, chain, pass === void 0 ? ctx : { ...ctx, where: at });
291
+ let model;
292
+ if (node.model !== void 0) {
293
+ const resolvedPath = resolveDataPath(node.model, ctx.scopePaths);
294
+ if (resolvedPath !== void 0) {
295
+ const ref = node.ref ?? makeAutoRef(node.component, resolvedPath);
296
+ model = { path: resolvedPath, ref };
297
+ if (!("value" in props)) {
298
+ props["value"] = resolve(node.model, chain);
299
+ }
300
+ }
301
+ }
302
+ const component = {
303
+ type: "component",
304
+ name: node.component,
305
+ props,
306
+ children,
307
+ ...node.ref === void 0 ? {} : { ref: node.ref },
308
+ ...model === void 0 ? {} : { model }
309
+ };
310
+ return component;
311
+ };
312
+ var safeRenderSingle = (node, chain, ctx, nodeRef) => {
313
+ try {
314
+ return renderNode(node, chain, ctx);
315
+ } catch (err) {
316
+ const novaError = toRenderError(err);
317
+ if (ctx.strict) throw novaError;
318
+ ctx.onError(novaError);
319
+ return [errorNode(novaError)];
320
+ }
321
+ };
322
+ var renderChildArray = (nodes, chain, ctx) => {
323
+ const out = [];
324
+ for (const child of nodes) out.push(...safeRenderSingle(child, chain, ctx));
325
+ return out;
326
+ };
327
+ var renderChildren = (children, chain, ctx) => {
328
+ if (children === void 0) return [];
329
+ if (chunkKW34ZKF5_cjs.isArray(children)) return renderChildArray(children, chain, ctx);
330
+ return safeRenderSingle(children, chain, ctx);
331
+ };
332
+ var toInternal = (ctx) => ({
333
+ store: ctx.store,
334
+ registry: ctx.registry,
335
+ strict: ctx.strict ?? false,
336
+ onError: ctx.onError ?? noopOnError,
337
+ scopePaths: [],
338
+ // Built once per render call. The matcher compiles a Set and a suffix list,
339
+ // and doing that per node would make the cheapest branch the expensive one.
340
+ pass: chunkKOYRJXTI_cjs.passFor({
341
+ ...ctx.phrases === void 0 ? {} : { phrases: ctx.phrases },
342
+ ...ctx.phraseKeys === void 0 ? {} : { keys: ctx.phraseKeys },
343
+ ...ctx.onPhraseMiss === void 0 ? {} : { onMiss: ctx.onPhraseMiss }
344
+ }),
345
+ where: ""
346
+ });
347
+ var renderLayout = (node, data, ctx) => {
348
+ const internal = toInternal(ctx);
349
+ return safeRenderSingle(node, createScopeChain(data), internal);
350
+ };
351
+ var render = (options) => renderLayout(options.layout, options.data ?? {}, {
352
+ store: options.store,
353
+ registry: options.registry,
354
+ ...options.strict === void 0 ? {} : { strict: options.strict },
355
+ ...options.onError === void 0 ? {} : { onError: options.onError },
356
+ ...options.phrases === void 0 ? {} : { phrases: options.phrases },
357
+ ...options.phraseKeys === void 0 ? {} : { phraseKeys: options.phraseKeys },
358
+ ...options.onPhraseMiss === void 0 ? {} : { onPhraseMiss: options.onPhraseMiss }
359
+ });
360
+ var renderLayoutFromStore = (node, store, ctx) => {
361
+ const internal = toInternal(ctx);
362
+ return safeRenderSingle(node, createScopeChain(store.get()), internal);
363
+ };
364
+
365
+ // src/layout/compose.ts
366
+ var fillSlots = (layout, fills) => {
367
+ if (isSlotNode(layout)) {
368
+ const fill = fills[layout.slot];
369
+ return fill === void 0 ? layout : fill;
370
+ }
371
+ if (Array.isArray(layout)) {
372
+ return layout.map((node) => fillSlots(node, fills));
373
+ }
374
+ if (isComponentNode(layout)) {
375
+ const { children } = layout;
376
+ if (children === void 0) return layout;
377
+ const next = Array.isArray(children) ? children.map((child) => fillSlots(child, fills)) : fillSlots(children, fills);
378
+ return { ...layout, children: next };
379
+ }
380
+ if (isConditionalNode(layout)) {
381
+ return {
382
+ ...layout,
383
+ then: fillSlots(layout.then, fills),
384
+ ...layout.else === void 0 ? {} : { else: fillSlots(layout.else, fills) }
385
+ };
386
+ }
387
+ if (isLoopNode(layout)) {
388
+ return { ...layout, do: fillSlots(layout.do, fills) };
389
+ }
390
+ return layout;
391
+ };
392
+
393
+ // src/layout/adapter.ts
394
+ var NOVA_MODEL_PROP = "novaModel";
395
+ var NOVA_REF_PROP = "novaRef";
396
+ var renderNodeKey = (node, index) => {
397
+ if (node.key !== void 0) return `k:${node.key}`;
398
+ if (node.type === "component") {
399
+ if (node.ref !== void 0) return `c:${node.ref}`;
400
+ return `c:${node.name}:${index}`;
401
+ }
402
+ if (node.type === "text") return `t:${index}`;
403
+ if (node.type === "fragment") return `f:${index}`;
404
+ return `e:${node.code}:${index}`;
405
+ };
406
+ var createLayoutStore = () => {
407
+ const layouts = /* @__PURE__ */ new Map();
408
+ const get = (id) => layouts.get(id);
409
+ const set = (id, layout) => {
410
+ if (strata.exceedsDepth(layout)) {
411
+ throw new chunkFSUMCJAR_cjs.DefinitionValidationError(`Invalid layout for id "${id}"`, { failures: [{ id, issues: [{ code: "custom", path: [], message: strata.depthRefusal(), input: void 0 }] }] });
412
+ }
413
+ const result = chunkD4PUWBN6_cjs.LayoutNodeSchema.safeParse(layout);
414
+ if (!result.success) {
415
+ throw new chunkFSUMCJAR_cjs.DefinitionValidationError(`Invalid layout for id "${id}"`, {
416
+ failures: [{ id, issues: result.error.issues }]
417
+ });
418
+ }
419
+ layouts.set(id, layout);
420
+ };
421
+ const remove = (id) => {
422
+ layouts.delete(id);
423
+ };
424
+ const list = () => Array.from(layouts.keys());
425
+ const resolveReferences = (layout) => {
426
+ if (isLayoutRefNode(layout)) {
427
+ const target = layouts.get(layout.ref);
428
+ if (target === void 0) return layout;
429
+ return resolveReferences(target);
430
+ }
431
+ if (Array.isArray(layout)) {
432
+ return layout.map(resolveReferences);
433
+ }
434
+ if (isComponentNode(layout)) {
435
+ const children = layout.children;
436
+ let resolvedChildren;
437
+ if (children === void 0) {
438
+ resolvedChildren = void 0;
439
+ } else if (Array.isArray(children)) {
440
+ resolvedChildren = children.map(resolveReferences);
441
+ } else {
442
+ resolvedChildren = resolveReferences(children);
443
+ }
444
+ return {
445
+ ...layout,
446
+ ...resolvedChildren === void 0 ? {} : { children: resolvedChildren }
447
+ };
448
+ }
449
+ if (isConditionalNode(layout)) {
450
+ return {
451
+ ...layout,
452
+ then: resolveReferences(layout.then),
453
+ ...layout.else === void 0 ? {} : { else: resolveReferences(layout.else) }
454
+ };
455
+ }
456
+ if (isLoopNode(layout)) {
457
+ return {
458
+ ...layout,
459
+ do: resolveReferences(layout.do)
460
+ };
461
+ }
462
+ return layout;
463
+ };
464
+ return { get, set, delete: remove, list, resolveReferences };
465
+ };
466
+ var REFUSED_ATTRIBUTES = "an attribute whose name starts with `on`, or a prop whose name is not an attribute\u2019s name";
467
+ var AttributeSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).describe(
468
+ "An attribute\u2019s value. Text is written as given, a number as text. `true` writes the attribute with no value. `false`, an empty or blank string, and anything that is none of these (a binding not answered yet, an object, a list) leave the attribute out."
469
+ );
470
+ var HeadPropsSchema = zod.z.object({}).strict().describe(
471
+ "The document\u2019s <head>. Takes no props. Its children are the elements the head holds \u2014 `nova:title`, `nova:meta`, `nova:link`, `nova:script` \u2014 placed directly or through loops and conditions; any other component among them is refused and left out, and the rest stand. Draws nothing on the screen. Elements are read in the order written, and where a screen holds several heads, in the order the screen is drawn. A later element takes an earlier one\u2019s place when both are the title, both are a `nova:meta` of the same `name` or `property`, or both are a `nova:link` whose `rel` includes `canonical`. Any other two stand side by side."
472
+ );
473
+ var HeadTitlePropsSchema = zod.z.object({}).strict().describe(
474
+ "The document\u2019s <title>, inside `nova:head`. Takes no props. Its text is given as its children: a text string, which may hold bindings \u2014 not components. A title with no text is left out."
475
+ );
476
+ var HeadMetaPropsSchema = zod.z.record(zod.z.string(), AttributeSchema).describe(
477
+ `A <meta> element, inside \`nova:head\`. Its props are the element\u2019s attributes, written as given: \`name\` or \`property\` to say what it is, \`content\` for its value. Left out while it has no \`content\`. A later one with the same \`name\` or \`property\` takes an earlier one\u2019s place (compared without regard to case; \`name\` decides when both are set), and one with neither stands beside the rest. The whole element is refused and left out if it has \`http-equiv\`, which instructs the browser rather than describing the document, ${REFUSED_ATTRIBUTES}.`
478
+ );
479
+ var HeadLinkPropsSchema = zod.z.record(zod.z.string(), AttributeSchema).describe(
480
+ `A <link> element, inside \`nova:head\`. Its props are the element\u2019s attributes, written as given: \`rel\` to say what the link is, \`href\` for its address, and any other the element takes (\`type\`, \`hreflang\`, \`sizes\`, \`media\`). Left out while it has no \`href\`. A later one whose \`rel\` includes \`canonical\` takes an earlier canonical\u2019s place; all other links stand side by side. The whole element is refused and left out if its \`rel\` includes \`stylesheet\`, which styles the page, or it has ${REFUSED_ATTRIBUTES}.`
481
+ );
482
+ var HeadScriptPropsSchema = zod.z.object({
483
+ type: zod.z.string().describe("The kind of data the block holds. Only a JSON type is accepted: `application/json`, or one ending in `+json` such as `application/ld+json`. Any other type, or none, is refused."),
484
+ data: zod.z.unknown().describe("What the block holds: the value itself \u2014 an object, a list, a number, text \u2014 which is serialised as JSON. Not JSON already written as text. Nothing, `null` or an empty string counts as no data.")
485
+ }).catchall(AttributeSchema).describe(
486
+ `A <script> element that holds data, inside \`nova:head\`: \`type\`, \`data\`, and any other attribute the element takes. Left out while it has no \`data\`. Data blocks never take one another\u2019s place. It never runs: the whole element is refused and left out unless its \`type\` is a JSON type, and if it has a \`src\` or ${REFUSED_ATTRIBUTES}.`
487
+ );
488
+ var described = (schema) => ({ description: schema.description ?? "", propsSchema: schema });
489
+ var HEAD_META = {
490
+ [chunkGV7UC3SS_cjs.HEAD_NAME]: described(HeadPropsSchema),
491
+ [chunkGV7UC3SS_cjs.HEAD_TITLE_NAME]: described(HeadTitlePropsSchema),
492
+ [chunkGV7UC3SS_cjs.HEAD_META_NAME]: described(HeadMetaPropsSchema),
493
+ [chunkGV7UC3SS_cjs.HEAD_LINK_NAME]: described(HeadLinkPropsSchema),
494
+ [chunkGV7UC3SS_cjs.HEAD_SCRIPT_NAME]: described(HeadScriptPropsSchema)
495
+ };
496
+
497
+ // src/action/compose.ts
498
+ var HOOKS = ["mount", "unmount", "suspend", "resume"];
499
+ var composeAction = (action, fragments) => {
500
+ if (fragments.length === 0) return action;
501
+ let layout = action.layout;
502
+ for (const frag of fragments) {
503
+ const wrap = frag.layout;
504
+ if (wrap === void 0) continue;
505
+ if (typeof wrap === "string") {
506
+ layout = wrap;
507
+ continue;
508
+ }
509
+ layout = fillSlots(wrap, layout === void 0 ? {} : { body: layout });
510
+ }
511
+ const data = {};
512
+ for (const frag of fragments) Object.assign(data, frag.data ?? {});
513
+ Object.assign(data, action.data ?? {});
514
+ const triggers = [
515
+ ...fragments.flatMap((f) => f.triggers ?? []),
516
+ ...action.triggers ?? []
517
+ ];
518
+ const endpoints = {};
519
+ for (const frag of fragments) Object.assign(endpoints, frag.endpoints ?? {});
520
+ Object.assign(endpoints, action.endpoints ?? {});
521
+ const lifecycle = {};
522
+ for (const hook of HOOKS) {
523
+ const steps = [
524
+ ...fragments.flatMap((f) => f.lifecycle?.[hook] ?? []),
525
+ ...action.lifecycle?.[hook] ?? []
526
+ ];
527
+ if (steps.length > 0) lifecycle[hook] = steps;
528
+ }
529
+ return {
530
+ id: action.id,
531
+ ...action.name === void 0 ? {} : { name: action.name },
532
+ ...action.description === void 0 ? {} : { description: action.description },
533
+ ...action.title === void 0 ? {} : { title: action.title },
534
+ ...action.input === void 0 ? {} : { input: action.input },
535
+ ...layout === void 0 ? {} : { layout },
536
+ ...Object.keys(data).length > 0 ? { data } : {},
537
+ ...triggers.length > 0 ? { triggers } : {},
538
+ ...Object.keys(endpoints).length > 0 ? { endpoints } : {},
539
+ ...Object.keys(lifecycle).length > 0 ? { lifecycle } : {}
540
+ };
541
+ };
542
+
543
+ // src/action/grammar.ts
544
+ var MUTATION_KEYS = [...new Set(chunkFSUMCJAR_cjs.OPS.map((op) => op.key))];
545
+ var MATCHERS = chunkFSUMCJAR_cjs.OPS.map((op) => op.match ?? ((step) => op.key in step));
546
+ var isMutationStep = (step) => MATCHERS.some((match) => match(step));
547
+ var mutationPaths = (steps) => {
548
+ const found = [];
549
+ const walk = (node) => {
550
+ if (Array.isArray(node)) {
551
+ for (const item of node) walk(item);
552
+ return;
553
+ }
554
+ if (node === null || typeof node !== "object") return;
555
+ const step = node;
556
+ if (isMutationStep(step)) {
557
+ for (const key of MUTATION_KEYS) {
558
+ const value = step[key];
559
+ if (typeof value === "string") found.push(value);
560
+ }
561
+ }
562
+ walk(step["onSuccess"]);
563
+ walk(step["onError"]);
564
+ };
565
+ walk(steps);
566
+ return found;
567
+ };
568
+ var rootOf = (path) => path.split(".")[0] ?? path;
569
+
570
+ // src/action/audit.ts
571
+ var collectChannels = (definition) => {
572
+ const emits = /* @__PURE__ */ new Set();
573
+ const listens = /* @__PURE__ */ new Set();
574
+ const walkSteps = (list) => {
575
+ if (!Array.isArray(list)) return;
576
+ for (const step of list) {
577
+ if (!isRecord(step)) continue;
578
+ const emit = step["emit"];
579
+ if (isRecord(emit) && typeof emit["channel"] === "string") emits.add(emit["channel"]);
580
+ if (typeof step["call"] === "string") {
581
+ walkSteps(step["onSuccess"]);
582
+ walkSteps(step["onError"]);
583
+ }
584
+ }
585
+ };
586
+ for (const trigger of definition.triggers ?? []) {
587
+ if (typeof trigger.message === "string") listens.add(trigger.message);
588
+ walkSteps(trigger.do);
589
+ }
590
+ for (const hook of Object.values(definition.lifecycle ?? {})) walkSteps(hook);
591
+ return { emits: [...emits].sort(), listens: [...listens].sort() };
592
+ };
593
+ var firstSegment = (path) => {
594
+ const segment = path.split(".")[0];
595
+ return segment === void 0 || segment.length === 0 ? path : segment;
596
+ };
597
+ var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
598
+ var navTargetOf = (step) => {
599
+ for (const key of ["push", "replace", "resetTo"]) {
600
+ const value = step[key];
601
+ if (isRecord(value) && typeof value["action"] === "string") {
602
+ const input = value["input"];
603
+ return { action: value["action"], ...isRecord(input) ? { input } : {} };
604
+ }
605
+ }
606
+ return void 0;
607
+ };
608
+ var auditAction = (definition, options) => {
609
+ const issues = [];
610
+ const dataKeys = new Set(Object.keys(definition.data ?? {}));
611
+ const endpointNames = new Set(Object.keys(definition.endpoints ?? {}));
612
+ const steps = [];
613
+ const pushSteps = (list) => {
614
+ if (!Array.isArray(list)) return;
615
+ for (const step of list) {
616
+ if (!isRecord(step)) continue;
617
+ steps.push(step);
618
+ if (typeof step["call"] === "string") {
619
+ pushSteps(step["onSuccess"]);
620
+ pushSteps(step["onError"]);
621
+ }
622
+ }
623
+ };
624
+ for (const trigger of definition.triggers ?? []) pushSteps(trigger.do);
625
+ for (const hook of Object.values(definition.lifecycle ?? {})) pushSteps(hook);
626
+ for (const step of steps) {
627
+ const call = step["call"];
628
+ if (typeof call === "string" && !endpointNames.has(call)) {
629
+ issues.push(`step calls endpoint "${call}" but endpoints has no "${call}"`);
630
+ }
631
+ for (const key of MUTATION_KEYS) {
632
+ const path = step[key];
633
+ if (typeof path === "string" && path.length > 0 && !dataKeys.has(firstSegment(path))) {
634
+ issues.push(`step "${key}: ${path}" writes a key with no default in data`);
635
+ }
636
+ }
637
+ const nav = navTargetOf(step);
638
+ if (nav !== void 0 && options?.catalog !== void 0) {
639
+ const entry = options.catalog.find((candidate) => candidate.id === nav.action);
640
+ if (entry === void 0 && nav.action !== definition.id) {
641
+ issues.push(`step pushes action "${nav.action}" which is not in the catalog`);
642
+ continue;
643
+ }
644
+ const properties = entry?.input?.["properties"];
645
+ if (nav.input !== void 0 && isRecord(properties)) {
646
+ for (const key of Object.keys(nav.input)) {
647
+ if (!(key in properties)) {
648
+ issues.push(`push to "${nav.action}" seeds input key "${key}" which is not in its input contract`);
649
+ }
650
+ }
651
+ }
652
+ }
653
+ }
654
+ for (const [name, endpoint] of Object.entries(definition.endpoints ?? {})) {
655
+ for (const field of ["target", "errorTarget"]) {
656
+ const target = endpoint[field];
657
+ if (typeof target === "string" && target.length > 0 && !dataKeys.has(firstSegment(target))) {
658
+ issues.push(`endpoint "${name}" ${field} "${target}" has no default in data`);
659
+ }
660
+ }
661
+ }
662
+ if (options?.channels !== void 0) {
663
+ const known = new Set(options.channels);
664
+ const usage = collectChannels(definition);
665
+ for (const channel of usage.listens) {
666
+ if (!known.has(channel) && !usage.emits.includes(channel)) {
667
+ issues.push(`trigger listens on channel "${channel}" which nothing is known to emit`);
668
+ }
669
+ }
670
+ for (const channel of usage.emits) {
671
+ if (!known.has(channel) && !usage.listens.includes(channel)) {
672
+ issues.push(`step emits channel "${channel}" which nothing is known to listen on`);
673
+ }
674
+ }
675
+ }
676
+ if (definition.layout !== void 0 && typeof definition.layout !== "string") {
677
+ const surface = chunkPMKWYOOX_cjs.collectInteractive(definition.layout);
678
+ for (const key of surface.boundKeys) {
679
+ if (!dataKeys.has(key)) {
680
+ issues.push(`layout binds "$.${key}" but data has no "${key}" default`);
681
+ }
682
+ }
683
+ for (const suspect of surface.suspectBindings) {
684
+ issues.push(
685
+ `layout binding "${suspect}\u2026" is malformed \u2014 the data root is "$." ("$.key"), and "$name." is only legal for a loop variable declared by an enclosing for/as`
686
+ );
687
+ }
688
+ const layoutRefs = new Set(surface.refs.map((entry) => entry.ref));
689
+ const triggerRefs = new Set(
690
+ (definition.triggers ?? []).map((trigger) => trigger.ref).filter((ref) => typeof ref === "string")
691
+ );
692
+ for (const ref of layoutRefs) {
693
+ if (!triggerRefs.has(ref)) {
694
+ issues.push(`layout ref "${ref}" has no trigger \u2014 dead chrome`);
695
+ }
696
+ }
697
+ for (const ref of triggerRefs) {
698
+ if (!layoutRefs.has(ref)) {
699
+ issues.push(`trigger listens on ref "${ref}" but no layout node carries it`);
700
+ }
701
+ }
702
+ }
703
+ return { ok: issues.length === 0, issues };
704
+ };
705
+
706
+ // src/reflect/grammar.ts
707
+ var gesturedKeys = (definition) => [
708
+ ...new Set(
709
+ (definition.triggers ?? []).filter((trigger) => typeof trigger.event === "string" && trigger.event.startsWith("ui:")).flatMap((trigger) => mutationPaths(trigger.do)).map(rootOf)
710
+ )
711
+ ];
712
+ var declaredKeys = (definition) => Object.keys(definition.input?.properties ?? {});
713
+ var loadedKeys = (definition) => {
714
+ const loaded = /* @__PURE__ */ new Set();
715
+ for (const endpoint of Object.values(definition.endpoints ?? {})) {
716
+ const spec = endpoint;
717
+ if (spec.target !== void 0) loaded.add(rootOf(spec.target));
718
+ if (spec.errorTarget !== void 0) loaded.add(rootOf(spec.errorTarget));
719
+ }
720
+ return [...loaded];
721
+ };
722
+ var lifecycleKeys = (definition) => [
723
+ ...new Set(
724
+ Object.values(definition.lifecycle ?? {}).flatMap(mutationPaths).map(rootOf)
725
+ )
726
+ ];
727
+ var mountCalls = (definition) => {
728
+ const names = /* @__PURE__ */ new Set();
729
+ const walk = (node) => {
730
+ if (Array.isArray(node)) {
731
+ for (const item of node) walk(item);
732
+ return;
733
+ }
734
+ if (node === null || typeof node !== "object") return;
735
+ const step = node;
736
+ if (typeof step["call"] === "string") names.add(step["call"]);
737
+ walk(step["onSuccess"]);
738
+ walk(step["onError"]);
739
+ };
740
+ walk(definition.lifecycle?.mount);
741
+ return names;
742
+ };
743
+ var requestKeys = (request) => {
744
+ const found = [];
745
+ const walk = (node) => {
746
+ if (typeof node === "string") {
747
+ if (node.startsWith("$.")) found.push(rootOf(node.slice(2)));
748
+ return;
749
+ }
750
+ if (Array.isArray(node)) {
751
+ for (const item of node) walk(item);
752
+ return;
753
+ }
754
+ if (node === null || typeof node !== "object") return;
755
+ for (const value of Object.values(node)) walk(value);
756
+ };
757
+ walk(request);
758
+ return found.filter((key) => key !== "");
759
+ };
760
+ var mountInputCache = /* @__PURE__ */ new WeakMap();
761
+ var mountInputKeys = (definition) => {
762
+ const cached = mountInputCache.get(definition);
763
+ if (cached !== void 0) return cached;
764
+ const called = mountCalls(definition);
765
+ const declared = new Set(declaredKeys(definition));
766
+ const keys = /* @__PURE__ */ new Set();
767
+ for (const [name, endpoint] of Object.entries(definition.endpoints ?? {})) {
768
+ if (!called.has(name)) continue;
769
+ for (const key of requestKeys(endpoint.request)) if (declared.has(key)) keys.add(key);
770
+ }
771
+ mountInputCache.set(definition, keys);
772
+ return keys;
773
+ };
774
+
775
+ exports.HEAD_META = HEAD_META;
776
+ exports.HeadLinkPropsSchema = HeadLinkPropsSchema;
777
+ exports.HeadMetaPropsSchema = HeadMetaPropsSchema;
778
+ exports.HeadPropsSchema = HeadPropsSchema;
779
+ exports.HeadScriptPropsSchema = HeadScriptPropsSchema;
780
+ exports.HeadTitlePropsSchema = HeadTitlePropsSchema;
781
+ exports.NOVA_MODEL_PROP = NOVA_MODEL_PROP;
782
+ exports.NOVA_REF_PROP = NOVA_REF_PROP;
783
+ exports.auditAction = auditAction;
784
+ exports.collectChannels = collectChannels;
785
+ exports.composeAction = composeAction;
786
+ exports.createLayoutStore = createLayoutStore;
787
+ exports.createScopeChain = createScopeChain;
788
+ exports.declaredKeys = declaredKeys;
789
+ exports.fillSlots = fillSlots;
790
+ exports.gesturedKeys = gesturedKeys;
791
+ exports.isComponentNode = isComponentNode;
792
+ exports.isConditionalNode = isConditionalNode;
793
+ exports.isLayoutNode = isLayoutNode;
794
+ exports.isLayoutPrimitive = isLayoutPrimitive;
795
+ exports.isLayoutRefNode = isLayoutRefNode;
796
+ exports.isLoopNode = isLoopNode;
797
+ exports.isMutationStep = isMutationStep;
798
+ exports.isSlotNode = isSlotNode;
799
+ exports.lifecycleKeys = lifecycleKeys;
800
+ exports.loadedKeys = loadedKeys;
801
+ exports.mountInputKeys = mountInputKeys;
802
+ exports.render = render;
803
+ exports.renderLayout = renderLayout;
804
+ exports.renderLayoutFromStore = renderLayoutFromStore;
805
+ exports.renderNodeKey = renderNodeKey;
806
+ exports.resolve = resolve;
807
+ //# sourceMappingURL=chunk-IZ2UU5UL.cjs.map
808
+ //# sourceMappingURL=chunk-IZ2UU5UL.cjs.map