@niscorp/nova 0.1.4 → 0.2.1

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 (125) hide show
  1. package/ADAPTER.md +6 -6
  2. package/CHANGELOG.md +78 -0
  3. package/README.md +102 -34
  4. package/SHELL_DOCS.md +13 -4
  5. package/dist/adapters/dom/components/index.d.cts +2 -2
  6. package/dist/adapters/dom/components/index.d.ts +2 -2
  7. package/dist/adapters/dom/index.cjs +163 -34
  8. package/dist/adapters/dom/index.cjs.map +1 -1
  9. package/dist/adapters/dom/index.d.cts +2 -2
  10. package/dist/adapters/dom/index.d.ts +2 -2
  11. package/dist/adapters/dom/index.js +6 -6
  12. package/dist/adapters/dom/server.cjs +0 -2
  13. package/dist/adapters/dom/server.cjs.map +1 -1
  14. package/dist/adapters/dom/server.d.cts +2 -2
  15. package/dist/adapters/dom/server.d.ts +2 -2
  16. package/dist/adapters/dom/server.js +6 -6
  17. package/dist/adapters/react/components/index.cjs +6 -8
  18. package/dist/adapters/react/components/index.cjs.map +1 -1
  19. package/dist/adapters/react/components/index.d.cts +4 -4
  20. package/dist/adapters/react/components/index.d.ts +4 -4
  21. package/dist/adapters/react/components/index.js +7 -7
  22. package/dist/adapters/react/index.cjs +181 -51
  23. package/dist/adapters/react/index.cjs.map +1 -1
  24. package/dist/adapters/react/index.d.cts +4 -4
  25. package/dist/adapters/react/index.d.ts +4 -4
  26. package/dist/adapters/react/index.js +7 -7
  27. package/dist/adapters/tty/components/index.d.cts +2 -2
  28. package/dist/adapters/tty/components/index.d.ts +2 -2
  29. package/dist/adapters/tty/index.cjs +0 -2
  30. package/dist/adapters/tty/index.cjs.map +1 -1
  31. package/dist/adapters/tty/index.d.cts +2 -2
  32. package/dist/adapters/tty/index.d.ts +2 -2
  33. package/dist/adapters/tty/index.js +4 -4
  34. package/dist/adapters/tty/index.js.map +1 -1
  35. package/dist/adapters/vue/components/index.cjs +4 -6
  36. package/dist/adapters/vue/components/index.cjs.map +1 -1
  37. package/dist/adapters/vue/components/index.d.cts +9 -9
  38. package/dist/adapters/vue/components/index.d.ts +9 -9
  39. package/dist/adapters/vue/components/index.js +7 -7
  40. package/dist/adapters/vue/index.cjs +175 -46
  41. package/dist/adapters/vue/index.cjs.map +1 -1
  42. package/dist/adapters/vue/index.d.cts +4 -4
  43. package/dist/adapters/vue/index.d.ts +4 -4
  44. package/dist/adapters/vue/index.js +9 -9
  45. package/dist/adapters/vue/index.js.map +1 -1
  46. package/dist/agent/index.d.cts +2 -2
  47. package/dist/agent/index.d.ts +2 -2
  48. package/dist/{chunk-7PKS7UYL.js → chunk-3JRTELLC.js} +3 -3
  49. package/dist/{chunk-7PKS7UYL.js.map → chunk-3JRTELLC.js.map} +1 -1
  50. package/dist/{chunk-WZVQ5PUB.js → chunk-DU2VIJAF.js} +59 -17
  51. package/dist/chunk-DU2VIJAF.js.map +1 -0
  52. package/dist/{chunk-UUYXVOK2.js → chunk-F2H7WP6R.js} +16 -16
  53. package/dist/chunk-F2H7WP6R.js.map +1 -0
  54. package/dist/{chunk-KYQ4EAQH.js → chunk-G4LSLLGI.js} +17 -17
  55. package/dist/chunk-G4LSLLGI.js.map +1 -0
  56. package/dist/chunk-OE4E6IBD.js +25 -0
  57. package/dist/chunk-OE4E6IBD.js.map +1 -0
  58. package/dist/chunk-RFBIGRCI.js +127 -0
  59. package/dist/chunk-RFBIGRCI.js.map +1 -0
  60. package/dist/{chunk-4I2PFMY7.js → chunk-SVNK5NIK.js} +8 -8
  61. package/dist/chunk-SVNK5NIK.js.map +1 -0
  62. package/dist/chunk-V4BPFFFV.js +152 -0
  63. package/dist/chunk-V4BPFFFV.js.map +1 -0
  64. package/dist/{chunk-4ERQYDF6.js → chunk-VOD5JA4D.js} +10 -10
  65. package/dist/chunk-VOD5JA4D.js.map +1 -0
  66. package/dist/chunk-XQTI4Q4I.js +178 -0
  67. package/dist/chunk-XQTI4Q4I.js.map +1 -0
  68. package/dist/{chunk-RXECI7DE.js → chunk-Y6XVPRYH.js} +33 -17
  69. package/dist/chunk-Y6XVPRYH.js.map +1 -0
  70. package/dist/devtools/index.d.cts +2 -2
  71. package/dist/devtools/index.d.ts +2 -2
  72. package/dist/devtools/index.js +3 -3
  73. package/dist/document/index.cjs +228 -119
  74. package/dist/document/index.cjs.map +1 -1
  75. package/dist/document/index.d.cts +10 -8
  76. package/dist/document/index.d.ts +10 -8
  77. package/dist/document/index.js +3 -122
  78. package/dist/document/index.js.map +1 -1
  79. package/dist/examples/index.cjs +1186 -0
  80. package/dist/examples/index.cjs.map +1 -0
  81. package/dist/examples/index.d.cts +63 -0
  82. package/dist/examples/index.d.ts +63 -0
  83. package/dist/examples/index.js +1158 -0
  84. package/dist/examples/index.js.map +1 -0
  85. package/dist/head-CAzfTnpV.d.cts +25 -0
  86. package/dist/head-DRpbbj-l.d.ts +25 -0
  87. package/dist/i18n/index.d.cts +2 -2
  88. package/dist/i18n/index.d.ts +2 -2
  89. package/dist/i18n/index.js +2 -176
  90. package/dist/i18n/index.js.map +1 -1
  91. package/dist/index.cjs +206 -53
  92. package/dist/index.cjs.map +1 -1
  93. package/dist/index.d.cts +23 -31
  94. package/dist/index.d.ts +23 -31
  95. package/dist/index.js +4 -4
  96. package/dist/{palette-Mx7XHYC6.d.ts → palette-CIpPH90W.d.ts} +1 -1
  97. package/dist/{palette-wbJB_svk.d.cts → palette-CvwZZCkx.d.cts} +1 -1
  98. package/dist/reflect/index.d.cts +2 -2
  99. package/dist/reflect/index.d.ts +2 -2
  100. package/dist/reflect/index.js +3 -3
  101. package/dist/{types-B-rjaUX0.d.ts → types-BSKx5MXW.d.ts} +1 -1
  102. package/dist/{types-B_nOtkyt.d.ts → types-BWc-olbY.d.ts} +1 -1
  103. package/dist/{types-mRKXqZPX.d.cts → types-C9734_lJ.d.cts} +1 -1
  104. package/dist/{types-BB9RXel5.d.ts → types-D23TRvqe.d.ts} +1 -1
  105. package/dist/{types-uk19d6KC.d.cts → types-DsWNYc7R.d.cts} +1 -1
  106. package/dist/{types-BLVRduoz.d.cts → types-j290XhCn.d.cts} +1 -1
  107. package/dist/{types-PDXOkvtK.d.cts → types-qkzTfSye.d.cts} +1 -1
  108. package/dist/{types-DE77Jl2W.d.ts → types-qnKMx0_V.d.ts} +1 -1
  109. package/package.json +19 -8
  110. package/dist/chunk-4ERQYDF6.js.map +0 -1
  111. package/dist/chunk-4I2PFMY7.js.map +0 -1
  112. package/dist/chunk-EHHJJLRX.js +0 -16
  113. package/dist/chunk-EHHJJLRX.js.map +0 -1
  114. package/dist/chunk-KYQ4EAQH.js.map +0 -1
  115. package/dist/chunk-RXECI7DE.js.map +0 -1
  116. package/dist/chunk-UUYXVOK2.js.map +0 -1
  117. package/dist/chunk-UV5YGBHQ.js +0 -62
  118. package/dist/chunk-UV5YGBHQ.js.map +0 -1
  119. package/dist/chunk-WZVQ5PUB.js.map +0 -1
  120. package/dist/chunk-X7SSNSQC.js +0 -6
  121. package/dist/chunk-X7SSNSQC.js.map +0 -1
  122. package/dist/head-BNj8GwPO.d.cts +0 -20
  123. package/dist/head-CS6X6ZKr.d.ts +0 -20
  124. package/dist/{primitive-props-Cl5jiC8g.d.cts → primitive-props-CGoJvmcH.d.cts} +5 -5
  125. package/dist/{primitive-props-Cl5jiC8g.d.ts → primitive-props-CGoJvmcH.d.ts} +5 -5
package/dist/index.cjs CHANGED
@@ -688,6 +688,25 @@ var walkValue = (value, prose, where, pass) => {
688
688
 
689
689
  // src/layout/head.ts
690
690
  var HEAD_NAME = "nova:head";
691
+ var HEAD_TITLE_NAME = "nova:title";
692
+ var HEAD_META_NAME = "nova:meta";
693
+ var HEAD_LINK_NAME = "nova:link";
694
+ var HEAD_SCRIPT_NAME = "nova:script";
695
+ var HEAD_NAMES = [HEAD_NAME, HEAD_TITLE_NAME, HEAD_META_NAME, HEAD_LINK_NAME, HEAD_SCRIPT_NAME];
696
+ var headKeyOf = (element) => {
697
+ const said = (name) => {
698
+ const found = Object.entries(element.attributes).find(([key]) => key.toLowerCase() === name)?.[1].trim().toLowerCase();
699
+ return found === void 0 || found === "" ? void 0 : found;
700
+ };
701
+ if (element.tag === "title") return "title";
702
+ if (element.tag === "meta") {
703
+ const [name, property] = [said("name"), said("property")];
704
+ if (name !== void 0) return `meta name ${name}`;
705
+ return property === void 0 ? void 0 : `meta property ${property}`;
706
+ }
707
+ if (element.tag === "link") return (said("rel") ?? "").split(/\s+/).includes("canonical") ? "link canonical" : void 0;
708
+ return void 0;
709
+ };
691
710
 
692
711
  // src/layout/renderer.ts
693
712
  var noopOnError = (_error) => {
@@ -784,7 +803,7 @@ var renderNode = (node, chain, ctx) => {
784
803
  return [];
785
804
  };
786
805
  var renderComponent = (node, chain, ctx) => {
787
- if (node.component !== HEAD_NAME && !ctx.registry.has(node.component)) {
806
+ if (!HEAD_NAMES.includes(node.component) && !ctx.registry.has(node.component)) {
788
807
  throw new ComponentNotFoundError(
789
808
  `Component not found in registry: ${node.component}`,
790
809
  { name: node.component }
@@ -1015,23 +1034,39 @@ var createComponentRegistry = () => {
1015
1034
  }
1016
1035
  };
1017
1036
  const get = (name) => entries.get(name);
1018
- const has = (name) => entries.has(name);
1037
+ const has2 = (name) => entries.has(name);
1019
1038
  const list = () => Array.from(entries.keys());
1020
- return { register, registerAll, get, has, list };
1021
- };
1022
- var HEAD_DESCRIPTION = "What this screen says it is: its title, description and preview picture. Draws nothing. One per screen, holding everything it says: where several are on a screen the last one is used whole, and they are never merged.";
1023
- var HeadPropsSchema = zod.z.object({
1024
- title: zod.z.string().optional().describe("The name of what this screen shows. Written as given: it becomes the document title and the title of its preview."),
1025
- description: zod.z.string().optional().describe("One or two sentences saying what this screen shows, as plain text."),
1026
- image: zod.z.string().optional().describe(
1027
- "Address of a picture that stands for this screen where a link to it is previewed: an absolute URL, or a path. A path is made absolute against the page\u2019s own address when the site\u2019s address is known, and written as given when it is not."
1028
- ),
1029
- kind: zod.z.enum(["website", "article"]).optional().describe("What sort of thing this screen is. `article`: a piece of writing that stands on its own. `website`: anything else. Left out, nothing is written and the document keeps what it already says."),
1030
- structured: zod.z.union([zod.z.record(zod.z.string(), zod.z.unknown()), zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown()))]).optional().describe("Structured data about what this screen shows: a JSON-LD object, or a list of them. Written as given, so each object carries its own `@context` and `@type`.")
1031
- }).strict().describe(HEAD_DESCRIPTION);
1039
+ return { register, registerAll, get, has: has2, list };
1040
+ };
1041
+ var REFUSED_ATTRIBUTES = "an attribute whose name starts with `on`, or a prop whose name is not an attribute\u2019s name";
1042
+ var AttributeSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]).describe(
1043
+ "An attribute\u2019s value. Text is written as given, a number as text. `true` writes the attribute with no value. `false`, an empty or blank string, and anything that is none of these (a binding not answered yet, an object, a list) leave the attribute out."
1044
+ );
1045
+ var HeadPropsSchema = zod.z.object({}).strict().describe(
1046
+ "The document\u2019s <head>. Takes no props. Its children are the elements the head holds \u2014 `nova:title`, `nova:meta`, `nova:link`, `nova:script` \u2014 placed directly or through loops and conditions; any other component among them is refused and left out, and the rest stand. Draws nothing on the screen. Elements are read in the order written, and where a screen holds several heads, in the order the screen is drawn. A later element takes an earlier one\u2019s place when both are the title, both are a `nova:meta` of the same `name` or `property`, or both are a `nova:link` whose `rel` includes `canonical`. Any other two stand side by side."
1047
+ );
1048
+ var HeadTitlePropsSchema = zod.z.object({}).strict().describe(
1049
+ "The document\u2019s <title>, inside `nova:head`. Takes no props. Its text is given as its children: a text string, which may hold bindings \u2014 not components. A title with no text is left out."
1050
+ );
1051
+ var HeadMetaPropsSchema = zod.z.record(zod.z.string(), AttributeSchema).describe(
1052
+ `A <meta> element, inside \`nova:head\`. Its props are the element\u2019s attributes, written as given: \`name\` or \`property\` to say what it is, \`content\` for its value. Left out while it has no \`content\`. A later one with the same \`name\` or \`property\` takes an earlier one\u2019s place (compared without regard to case; \`name\` decides when both are set), and one with neither stands beside the rest. The whole element is refused and left out if it has \`http-equiv\`, which instructs the browser rather than describing the document, ${REFUSED_ATTRIBUTES}.`
1053
+ );
1054
+ var HeadLinkPropsSchema = zod.z.record(zod.z.string(), AttributeSchema).describe(
1055
+ `A <link> element, inside \`nova:head\`. Its props are the element\u2019s attributes, written as given: \`rel\` to say what the link is, \`href\` for its address, and any other the element takes (\`type\`, \`hreflang\`, \`sizes\`, \`media\`). Left out while it has no \`href\`. A later one whose \`rel\` includes \`canonical\` takes an earlier canonical\u2019s place; all other links stand side by side. The whole element is refused and left out if its \`rel\` includes \`stylesheet\`, which styles the page, or it has ${REFUSED_ATTRIBUTES}.`
1056
+ );
1057
+ var HeadScriptPropsSchema = zod.z.object({
1058
+ type: zod.z.string().describe("The kind of data the block holds. Only a JSON type is accepted: `application/json`, or one ending in `+json` such as `application/ld+json`. Any other type, or none, is refused."),
1059
+ data: zod.z.unknown().describe("What the block holds: the value itself \u2014 an object, a list, a number, text \u2014 which is serialised as JSON. Not JSON already written as text. Nothing, `null` or an empty string counts as no data.")
1060
+ }).catchall(AttributeSchema).describe(
1061
+ `A <script> element that holds data, inside \`nova:head\`: \`type\`, \`data\`, and any other attribute the element takes. Left out while it has no \`data\`. Data blocks never take one another\u2019s place. It never runs: the whole element is refused and left out unless its \`type\` is a JSON type, and if it has a \`src\` or ${REFUSED_ATTRIBUTES}.`
1062
+ );
1063
+ var described = (schema) => ({ description: schema.description ?? "", propsSchema: schema });
1032
1064
  var HEAD_META = {
1033
- description: HEAD_DESCRIPTION,
1034
- propsSchema: HeadPropsSchema
1065
+ [HEAD_NAME]: described(HeadPropsSchema),
1066
+ [HEAD_TITLE_NAME]: described(HeadTitlePropsSchema),
1067
+ [HEAD_META_NAME]: described(HeadMetaPropsSchema),
1068
+ [HEAD_LINK_NAME]: described(HeadLinkPropsSchema),
1069
+ [HEAD_SCRIPT_NAME]: described(HeadScriptPropsSchema)
1035
1070
  };
1036
1071
 
1037
1072
  // src/agent/palette.ts
@@ -2131,7 +2166,16 @@ var executeSteps = async (steps, ctx) => {
2131
2166
  const channel = typeof resolvedChannel === "string" ? resolvedChannel : String(resolvedChannel ?? "");
2132
2167
  const payload = step.emit.payload === void 0 ? void 0 : resolve(step.emit.payload, chain, ctx.extras);
2133
2168
  const { messageBus, cause } = ctx;
2134
- nextTask(() => messageBus.publish(channel, payload, cause));
2169
+ const delivered = new Promise((resolve2) => {
2170
+ nextTask(() => {
2171
+ try {
2172
+ messageBus.publish(channel, payload, cause);
2173
+ } finally {
2174
+ resolve2();
2175
+ }
2176
+ });
2177
+ });
2178
+ ctx.onChain?.(delivered);
2135
2179
  continue;
2136
2180
  }
2137
2181
  if ("push" in step) {
@@ -2275,9 +2319,10 @@ var fireTrigger = (trigger, buildContext, event, cause) => {
2275
2319
  }
2276
2320
  const base = { ...built, cause };
2277
2321
  const ctx = event === void 0 ? base : { ...base, extras: { ...base.extras, "@event": event } };
2278
- void executeSteps(trigger.do, ctx).catch((err) => {
2322
+ const chain = executeSteps(trigger.do, ctx).catch((err) => {
2279
2323
  ctx.onError(toNovaError(err));
2280
2324
  });
2325
+ ctx.onChain?.(chain);
2281
2326
  };
2282
2327
  var eventOrigin = (event) => {
2283
2328
  if (!hasKey(event, "origin")) return void 0;
@@ -2422,6 +2467,7 @@ var createActionRuntime = (config) => {
2422
2467
  // the shell's telemetry — `runCall` only knows the endpoint, the runtime
2423
2468
  // knows who made it.
2424
2469
  ...config.onEndpoint === void 0 ? {} : { onEndpoint: (event) => config.onEndpoint({ ...event, instanceId: instance.id, canvasId: instance.canvasId }) },
2470
+ ...config.onChain === void 0 ? {} : { onChain: config.onChain },
2425
2471
  calls,
2426
2472
  extras: {},
2427
2473
  initial: initialSnapshot,
@@ -2653,6 +2699,7 @@ var createRuntimeFactory = (deps) => (canvasId, definition, input) => createActi
2653
2699
  ...deps.endpointTimeoutMs === void 0 ? {} : { endpointTimeoutMs: deps.endpointTimeoutMs },
2654
2700
  onNavigate: (effect) => deps.onNavigate(canvasId, effect),
2655
2701
  ...deps.onEndpoint === void 0 ? {} : { onEndpoint: deps.onEndpoint },
2702
+ ...deps.onChain === void 0 ? {} : { onChain: deps.onChain },
2656
2703
  strict: deps.strict,
2657
2704
  ...deps.onError === void 0 ? {} : { onError: deps.onError },
2658
2705
  ...deps.i18n === void 0 ? {} : { i18n: deps.i18n },
@@ -2897,14 +2944,18 @@ var createJournal = (limit) => {
2897
2944
 
2898
2945
  // src/shell/lifecycle-ops.ts
2899
2946
  var createLifecycleOps = (deps) => {
2900
- const { registry, onLifecycleError, onUnmount } = deps;
2947
+ const { registry, onLifecycleError, onUnmount, onChain } = deps;
2948
+ const detached = (hook) => {
2949
+ const chain = hook.catch(onLifecycleError);
2950
+ onChain?.(chain);
2951
+ };
2901
2952
  const unmounted = /* @__PURE__ */ new Set();
2902
2953
  const unmountInstance = (instanceId) => {
2903
2954
  if (unmounted.has(instanceId)) return;
2904
2955
  const runtime = registry.get(instanceId);
2905
2956
  if (runtime === void 0) return;
2906
2957
  unmounted.add(instanceId);
2907
- runtime.unmount().catch(onLifecycleError);
2958
+ detached(runtime.unmount());
2908
2959
  runtime.dispose();
2909
2960
  registry.unregister(instanceId);
2910
2961
  onUnmount?.(instanceId);
@@ -2915,17 +2966,37 @@ var createLifecycleOps = (deps) => {
2915
2966
  if (top === void 0) return;
2916
2967
  if (top.status === "suspended") return;
2917
2968
  const runtime = registry.get(top.id);
2918
- if (runtime !== void 0) runtime.suspend().catch(onLifecycleError);
2969
+ if (runtime !== void 0) detached(runtime.suspend());
2919
2970
  };
2920
2971
  const resumeTop = (canvas) => {
2921
2972
  const top = canvas.peek();
2922
2973
  if (top === void 0) return;
2923
2974
  const runtime = registry.get(top.id);
2924
- if (runtime !== void 0) runtime.resume().catch(onLifecycleError);
2975
+ if (runtime !== void 0) detached(runtime.resume());
2925
2976
  };
2926
2977
  return { unmountInstance, suspendTop, resumeTop };
2927
2978
  };
2928
2979
 
2980
+ // src/shell/chains.ts
2981
+ var createChainCount = () => {
2982
+ let count = 0;
2983
+ const release = () => {
2984
+ count -= 1;
2985
+ };
2986
+ return {
2987
+ hold: (chain) => {
2988
+ count += 1;
2989
+ chain.then(release, release);
2990
+ },
2991
+ inFlight: () => count
2992
+ };
2993
+ };
2994
+ var chainCounts = /* @__PURE__ */ new WeakMap();
2995
+ var rememberChainCount = (shell, count) => {
2996
+ chainCounts.set(shell, count);
2997
+ };
2998
+ var chainsInFlight = (shell) => chainCounts.get(shell)?.inFlight() ?? 0;
2999
+
2929
3000
  // src/shell/navigation.ts
2930
3001
  var navigatedChannel = (canvasId) => `nova:navigated:${canvasId}`;
2931
3002
  var createNavigationHandler = (ops) => {
@@ -3080,9 +3151,11 @@ var createShell = (config) => {
3080
3151
  const origins = /* @__PURE__ */ new Map();
3081
3152
  const births = /* @__PURE__ */ new Map();
3082
3153
  const journal = createJournal(config.historyDepth ?? DEFAULT_HISTORY_DEPTH);
3154
+ const chains = createChainCount();
3083
3155
  const ops = createLifecycleOps({
3084
3156
  registry,
3085
3157
  onLifecycleError: handleLifecycleRejection,
3158
+ onChain: chains.hold,
3086
3159
  onUnmount: (instanceId) => {
3087
3160
  origins.delete(instanceId);
3088
3161
  births.delete(instanceId);
@@ -3268,7 +3341,8 @@ var createShell = (config) => {
3268
3341
  onNavigate: (cid, effect) => navigationHandler(cid, effect),
3269
3342
  // Every endpoint call an action makes flows to telemetry — the shell's one
3270
3343
  // observability surface (state, data, and now endpoints all land here).
3271
- onEndpoint: (event) => telemetry.fireEndpoint(event)
3344
+ onEndpoint: (event) => telemetry.fireEndpoint(event),
3345
+ onChain: chains.hold
3272
3346
  });
3273
3347
  const spawn = (canvasId, definition, input) => {
3274
3348
  const runtime = buildRuntime(canvasId, definition, input);
@@ -3536,7 +3610,7 @@ var createShell = (config) => {
3536
3610
  }
3537
3611
  return renderLayoutOrRef(canvasLayout ?? DEFAULT_SHELL_LAYOUT, { canvases: canvasList });
3538
3612
  };
3539
- const titleOf = (instance) => {
3613
+ const titleOf2 = (instance) => {
3540
3614
  const def = registry.get(instance.id)?.definition ?? actions[instance.definitionId];
3541
3615
  if (def?.title !== void 0) {
3542
3616
  const resolved = resolve(def.title, createScopeChain(instance.data));
@@ -3547,7 +3621,7 @@ var createShell = (config) => {
3547
3621
  const getCanvasRenderTree = (canvasId) => {
3548
3622
  const canvas = canvases.get(canvasId);
3549
3623
  const state = canvas === void 0 ? { stack: []} : snapshotCanvas(canvas);
3550
- const instances = state.stack.map((i) => ({ ...i, title: titleOf(i) }));
3624
+ const instances = state.stack.map((i) => ({ ...i, title: titleOf2(i) }));
3551
3625
  const scope = {
3552
3626
  instances,
3553
3627
  active: instances.length === 0 ? void 0 : instances[instances.length - 1],
@@ -3597,34 +3671,99 @@ var createShell = (config) => {
3597
3671
  dispose
3598
3672
  };
3599
3673
  rememberShellRegistry(shell, registry);
3674
+ rememberChainCount(shell, chains);
3600
3675
  for (const cfg of config.canvases) seedCanvas(cfg);
3601
3676
  return shell;
3602
3677
  };
3603
3678
 
3604
3679
  // src/shell/head.ts
3605
- var said = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
3606
- var isObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
3607
- var structuredOf = (value) => {
3608
- if (isObject2(value)) return value;
3609
- if (Array.isArray(value) && value.length > 0 && value.every(isObject2)) return value;
3610
- return void 0;
3611
- };
3612
- var headFrom = (props) => {
3613
- const [title, description, image] = [said(props["title"]), said(props["description"]), said(props["image"])];
3614
- const kind = props["kind"] === "website" || props["kind"] === "article" ? props["kind"] : void 0;
3615
- const structured = structuredOf(props["structured"]);
3616
- return {
3617
- ...title !== void 0 ? { title } : {},
3618
- ...description !== void 0 ? { description } : {},
3619
- ...image !== void 0 ? { image } : {},
3620
- ...kind !== void 0 ? { kind } : {},
3621
- ...structured !== void 0 ? { structured } : {}
3622
- };
3680
+ var ATTRIBUTE_NAME = /^[A-Za-z][A-Za-z0-9:._-]*$/;
3681
+ var DATA_TYPE = /^application\/([a-z0-9.-]+\+)?json$/i;
3682
+ var written = (value) => {
3683
+ if (typeof value === "string") return value.trim() === "" ? void 0 : value;
3684
+ if (typeof value === "number") return String(value);
3685
+ return value === true ? "" : void 0;
3686
+ };
3687
+ var attributesOf = (what, props, skip = []) => {
3688
+ const attributes = {};
3689
+ for (const [name, value] of Object.entries(props)) {
3690
+ if (skip.includes(name)) continue;
3691
+ if (!ATTRIBUTE_NAME.test(name)) return { refused: `${what}: "${name}" is not an attribute\u2019s name` };
3692
+ if (/^on/i.test(name)) return { refused: `${what}: \`${name}\` is a handler, and a layout does not run` };
3693
+ const text = written(value);
3694
+ if (text !== void 0) attributes[name] = text;
3695
+ }
3696
+ return { attributes };
3697
+ };
3698
+ var has = (attributes, name) => Object.keys(attributes).some((key) => key.toLowerCase() === name);
3699
+ var valueOf = (attributes, name) => Object.entries(attributes).find(([key]) => key.toLowerCase() === name)?.[1] ?? "";
3700
+ var textOf = (nodes) => nodes.map((node) => node.type === "text" ? node.value : node.type === "fragment" ? textOf(node.children) : "").join("");
3701
+ var titleOf = (node) => {
3702
+ const text = textOf(node.children).trim();
3703
+ return text === "" ? void 0 : { element: { tag: "title", attributes: {}, text } };
3704
+ };
3705
+ var metaOf = (node) => {
3706
+ const read = attributesOf(HEAD_META_NAME, node.props);
3707
+ if ("refused" in read) return read;
3708
+ if (has(read.attributes, "http-equiv")) return { refused: `${HEAD_META_NAME}: \`http-equiv\` instructs the browser, and a layout does not` };
3709
+ return has(read.attributes, "content") ? { element: { tag: "meta", attributes: read.attributes } } : void 0;
3710
+ };
3711
+ var linkOf = (node) => {
3712
+ const read = attributesOf(HEAD_LINK_NAME, node.props);
3713
+ if ("refused" in read) return read;
3714
+ if (valueOf(read.attributes, "rel").toLowerCase().split(/\s+/).includes("stylesheet")) return { refused: `${HEAD_LINK_NAME}: a stylesheet styles the page, and a layout does not` };
3715
+ return has(read.attributes, "href") ? { element: { tag: "link", attributes: read.attributes } } : void 0;
3716
+ };
3717
+ var scriptOf = (node) => {
3718
+ const read = attributesOf(HEAD_SCRIPT_NAME, node.props, ["data"]);
3719
+ if ("refused" in read) return read;
3720
+ if (has(read.attributes, "src")) return { refused: `${HEAD_SCRIPT_NAME}: a script with a \`src\` runs, and a layout does not` };
3721
+ const type = valueOf(read.attributes, "type");
3722
+ if (!DATA_TYPE.test(type)) return { refused: `${HEAD_SCRIPT_NAME}: only a data block may be written (a JSON \`type\`), and "${type}" is not one` };
3723
+ const data = node.props["data"];
3724
+ if (data === void 0 || data === null || data === "") return void 0;
3725
+ return { element: { tag: "script", attributes: read.attributes, text: JSON.stringify(data) } };
3726
+ };
3727
+ var READERS = {
3728
+ [HEAD_TITLE_NAME]: titleOf,
3729
+ [HEAD_META_NAME]: metaOf,
3730
+ [HEAD_LINK_NAME]: linkOf,
3731
+ [HEAD_SCRIPT_NAME]: scriptOf
3623
3732
  };
3624
3733
  var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
3625
3734
  var headOf = (api) => {
3626
- const found = [];
3735
+ let heads = 0;
3736
+ const said = [];
3737
+ const refused = [];
3627
3738
  const open = /* @__PURE__ */ new Set();
3739
+ const hold = (nodes, action) => {
3740
+ for (const node of nodes) {
3741
+ if (node.type === "fragment") {
3742
+ hold(node.children, action);
3743
+ continue;
3744
+ }
3745
+ if (node.type === "error") {
3746
+ refused.push(`${HEAD_NAME}: ${node.message}`);
3747
+ continue;
3748
+ }
3749
+ if (node.type !== "component") continue;
3750
+ const read = READERS[node.name];
3751
+ if (read === void 0) {
3752
+ refused.push(`${HEAD_NAME}: "${node.name}" is not something a head holds`);
3753
+ continue;
3754
+ }
3755
+ const found = read(node);
3756
+ if (found === void 0) continue;
3757
+ if ("refused" in found) {
3758
+ refused.push(found.refused);
3759
+ continue;
3760
+ }
3761
+ const key = headKeyOf(found.element);
3762
+ const earlier = key === void 0 ? -1 : said.findIndex((other) => headKeyOf(other.element) === key);
3763
+ if (earlier >= 0) said.splice(earlier, 1);
3764
+ said.push({ element: found.element, action });
3765
+ }
3766
+ };
3628
3767
  const walk2 = (nodes, action) => {
3629
3768
  for (const node of nodes) {
3630
3769
  if (node.type === "fragment") {
@@ -3633,7 +3772,8 @@ var headOf = (api) => {
3633
3772
  }
3634
3773
  if (node.type !== "component") continue;
3635
3774
  if (node.name === HEAD_NAME) {
3636
- found.push({ props: node.props, action });
3775
+ heads += 1;
3776
+ hold(node.children, action);
3637
3777
  continue;
3638
3778
  }
3639
3779
  if (node.name === CANVAS_SLOT_NAME) {
@@ -3649,9 +3789,9 @@ var headOf = (api) => {
3649
3789
  }
3650
3790
  };
3651
3791
  walk2(api.frame(), void 0);
3652
- const last = found[found.length - 1];
3653
- if (last === void 0) return void 0;
3654
- return { head: headFrom(last.props), ...last.action !== void 0 ? { action: last.action } : {} };
3792
+ if (heads === 0) return void 0;
3793
+ const actions = [...new Set(said.flatMap((one) => one.action === void 0 ? [] : [one.action]))];
3794
+ return { elements: said.map((one) => one.element), actions, refused };
3655
3795
  };
3656
3796
 
3657
3797
  // src/shell/view.ts
@@ -3700,10 +3840,8 @@ var shellView = (shell) => ({
3700
3840
  };
3701
3841
  }
3702
3842
  });
3703
- var DEFAULT_SETTLE_WAIT_MS = 300;
3704
- var shellSettled = async (shell, options = {}) => {
3843
+ var shellQuietWithin = async (shell, isBusy, options) => {
3705
3844
  const waitMs = options.waitMs ?? DEFAULT_SETTLE_WAIT_MS;
3706
- const mounting = () => Object.values(shell.getState().canvases).some((canvas) => canvas.stack.some((instance) => instance.status === "initializing"));
3707
3845
  let timer;
3708
3846
  const deadline = new Promise((resolve2) => {
3709
3847
  timer = setTimeout(() => resolve2(false), waitMs);
@@ -3711,9 +3849,9 @@ var shellSettled = async (shell, options = {}) => {
3711
3849
  const quiet = (async () => {
3712
3850
  for (; ; ) {
3713
3851
  if (options.stopped?.() === true) return false;
3714
- if (!mounting()) {
3852
+ if (!isBusy()) {
3715
3853
  await new Promise((resolve2) => setTimeout(resolve2, 0));
3716
- if (!mounting()) return true;
3854
+ if (!isBusy()) return true;
3717
3855
  }
3718
3856
  await new Promise((resolve2) => {
3719
3857
  const off = shell.onStateChange(() => {
@@ -3731,6 +3869,10 @@ var shellSettled = async (shell, options = {}) => {
3731
3869
  clearTimeout(timer);
3732
3870
  return settled;
3733
3871
  };
3872
+ var isMounting = (shell) => Object.values(shell.getState().canvases).some((canvas) => canvas.stack.some((instance) => instance.status === "initializing"));
3873
+ var DEFAULT_SETTLE_WAIT_MS = 300;
3874
+ var shellSettled = (shell, options = {}) => shellQuietWithin(shell, () => isMounting(shell), options);
3875
+ var shellIdle = (shell, options = {}) => shellQuietWithin(shell, () => isMounting(shell) || chainsInFlight(shell) > 0, options);
3734
3876
 
3735
3877
  exports.ACTION_SLOT_NAME = ACTION_SLOT_NAME;
3736
3878
  exports.ActionDefinitionSchema = ActionDefinitionSchema;
@@ -3745,9 +3887,18 @@ exports.DefinitionValidationError = DefinitionValidationError;
3745
3887
  exports.EffectSchema = EffectSchema;
3746
3888
  exports.EndpointConfigSchema = EndpointConfigSchema;
3747
3889
  exports.ErrorCodes = ErrorCodes;
3890
+ exports.HEAD_LINK_NAME = HEAD_LINK_NAME;
3748
3891
  exports.HEAD_META = HEAD_META;
3892
+ exports.HEAD_META_NAME = HEAD_META_NAME;
3749
3893
  exports.HEAD_NAME = HEAD_NAME;
3894
+ exports.HEAD_NAMES = HEAD_NAMES;
3895
+ exports.HEAD_SCRIPT_NAME = HEAD_SCRIPT_NAME;
3896
+ exports.HEAD_TITLE_NAME = HEAD_TITLE_NAME;
3897
+ exports.HeadLinkPropsSchema = HeadLinkPropsSchema;
3898
+ exports.HeadMetaPropsSchema = HeadMetaPropsSchema;
3750
3899
  exports.HeadPropsSchema = HeadPropsSchema;
3900
+ exports.HeadScriptPropsSchema = HeadScriptPropsSchema;
3901
+ exports.HeadTitlePropsSchema = HeadTitlePropsSchema;
3751
3902
  exports.LayoutNodeSchema = LayoutNodeSchema;
3752
3903
  exports.LayoutPrimitiveSchema = LayoutPrimitiveSchema;
3753
3904
  exports.LayoutRefNodeSchema = LayoutRefNodeSchema;
@@ -3781,6 +3932,7 @@ exports.createShell = createShell;
3781
3932
  exports.fillSlots = fillSlots;
3782
3933
  exports.getPath = getPath;
3783
3934
  exports.hasVisibleContent = hasVisibleContent;
3935
+ exports.headKeyOf = headKeyOf;
3784
3936
  exports.headOf = headOf;
3785
3937
  exports.isComponentNode = isComponentNode;
3786
3938
  exports.isConditionalNode = isConditionalNode;
@@ -3799,6 +3951,7 @@ exports.renderLayout = renderLayout;
3799
3951
  exports.renderLayoutFromStore = renderLayoutFromStore;
3800
3952
  exports.renderNodeKey = renderNodeKey;
3801
3953
  exports.scopeDispatch = scopeDispatch;
3954
+ exports.shellIdle = shellIdle;
3802
3955
  exports.shellSettled = shellSettled;
3803
3956
  exports.shellView = shellView;
3804
3957
  //# sourceMappingURL=index.cjs.map