@perkyzz/emvb 0.3.0 → 0.5.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 (163) hide show
  1. package/README.md +22 -4
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +5 -2
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/agents-api.ts +39 -0
  6. package/src/admin/api.ts +17 -7
  7. package/src/admin/content-api.ts +7 -51
  8. package/src/admin/content-item.ts +22 -0
  9. package/src/admin/design-api.ts +30 -0
  10. package/src/admin/editor/A11yCopilot.tsx +1 -1
  11. package/src/admin/editor/CommandPalette.tsx +43 -2
  12. package/src/admin/editor/Editor.tsx +133 -332
  13. package/src/admin/editor/EditorOverlay.tsx +3 -1
  14. package/src/admin/editor/PerfMeter.tsx +1 -1
  15. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  16. package/src/admin/editor/Timeline.tsx +124 -9
  17. package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
  18. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  19. package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
  20. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  21. package/src/admin/editor/canvas/drop-line.ts +24 -0
  22. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  23. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  24. package/src/admin/editor/collection-previews.ts +28 -5
  25. package/src/admin/editor/editor-chrome.tsx +346 -0
  26. package/src/admin/editor/editor-commands.ts +360 -0
  27. package/src/admin/editor/editor-css.ts +4 -0
  28. package/src/admin/editor/element-chrome.ts +89 -0
  29. package/src/admin/editor/feature-css.ts +37 -18
  30. package/src/admin/editor/host.ts +33 -0
  31. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  32. package/src/admin/editor/icons/library.ts +29 -19
  33. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  34. package/src/admin/editor/palette-items.ts +36 -5
  35. package/src/admin/editor/palette.ts +9 -4
  36. package/src/admin/editor/panels/AddPanel.tsx +2 -67
  37. package/src/admin/editor/panels/ColorControl.tsx +21 -18
  38. package/src/admin/editor/panels/ElementPanel.tsx +40 -99
  39. package/src/admin/editor/panels/LayersPanel.tsx +34 -62
  40. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  41. package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
  42. package/src/admin/editor/panels/TokenScales.tsx +4 -2
  43. package/src/admin/editor/panels/VariableSection.tsx +1 -10
  44. package/src/admin/editor/panels/color-space.ts +12 -1
  45. package/src/admin/editor/panels/inline-error.tsx +11 -0
  46. package/src/admin/editor/panels/settings/AdvancedFields.tsx +143 -1
  47. package/src/admin/editor/panels/settings/AudienceEditor.tsx +115 -7
  48. package/src/admin/editor/panels/settings/DraftTextField.tsx +42 -9
  49. package/src/admin/editor/panels/settings/FieldControl.tsx +6 -0
  50. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  51. package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
  52. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
  53. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  54. package/src/admin/editor/panels/settings/MediaPicker.tsx +2 -3
  55. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
  56. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
  57. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  58. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  59. package/src/admin/editor/panels/settings/length-units.ts +15 -4
  60. package/src/admin/editor/panels/settings/link-rules.ts +19 -0
  61. package/src/admin/editor/panels/settings/number-input.ts +11 -0
  62. package/src/admin/editor/panels/settings/query-style.ts +65 -0
  63. package/src/admin/editor/panels/settings/style-sections.ts +5 -1
  64. package/src/admin/editor/panels/style-target.ts +105 -0
  65. package/src/admin/editor/panels/variable-values.ts +4 -2
  66. package/src/admin/editor/remote-change.ts +67 -0
  67. package/src/admin/editor/section-templates.ts +43 -21
  68. package/src/admin/editor/shortcuts.ts +4 -0
  69. package/src/admin/editor/store.ts +10 -1
  70. package/src/admin/editor/useClipboardActions.ts +1 -1
  71. package/src/admin/editor/useEditorCommands.ts +61 -13
  72. package/src/admin/editor/useEditorData.ts +7 -1
  73. package/src/admin/editor/useEditorShortcuts.ts +23 -15
  74. package/src/admin/editor/useNodeActions.ts +6 -1
  75. package/src/admin/forms-api.ts +17 -6
  76. package/src/admin/icon-uploads-api.ts +18 -0
  77. package/src/admin/index.tsx +3 -1
  78. package/src/admin/media-api.ts +20 -0
  79. package/src/admin/pages/AgentsPage.tsx +274 -0
  80. package/src/admin/theme-api.ts +5 -18
  81. package/src/admin/ui.ts +28 -0
  82. package/src/astro/content-port.ts +24 -0
  83. package/src/astro/floats/runtime.ts +10 -0
  84. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  85. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  86. package/src/astro/forms/client.ts +1 -0
  87. package/src/astro/forms-definitions.ts +24 -11
  88. package/src/astro/index.ts +1 -0
  89. package/src/astro/popups/runtime.ts +15 -0
  90. package/src/astro/render-session.ts +85 -0
  91. package/src/astro/request-data.ts +20 -8
  92. package/src/astro/resolve-theme.ts +166 -76
  93. package/src/astro/resolve.ts +57 -16
  94. package/src/astro/tabs/runtime.ts +60 -1
  95. package/src/astro/theme-posts.ts +16 -5
  96. package/src/astro/visitor.ts +67 -5
  97. package/src/constants.ts +1 -1
  98. package/src/core/a11y/audit.ts +202 -26
  99. package/src/core/arrange.ts +71 -38
  100. package/src/core/audience/rules.ts +22 -2
  101. package/src/core/canvas-styles.ts +24 -0
  102. package/src/core/clipboard.ts +11 -32
  103. package/src/core/css/generate.ts +18 -1
  104. package/src/core/css/print.ts +12 -0
  105. package/src/core/css/scope.ts +3 -3
  106. package/src/core/css-keywords.ts +83 -0
  107. package/src/core/data/bindings.ts +4 -6
  108. package/src/core/design/classes.ts +13 -15
  109. package/src/core/design/diff.ts +55 -0
  110. package/src/core/design/merge.ts +127 -0
  111. package/src/core/design/variables.ts +25 -21
  112. package/src/core/elements/dynamic-elements.ts +30 -0
  113. package/src/core/elements/form-elements.ts +20 -3
  114. package/src/core/elements/index.ts +211 -7
  115. package/src/core/forms/binding.ts +4 -13
  116. package/src/core/index.ts +10 -0
  117. package/src/core/local-style.ts +27 -0
  118. package/src/core/migrate/index.ts +9 -4
  119. package/src/core/nesting.ts +4 -23
  120. package/src/core/perf/scripts.ts +9 -6
  121. package/src/core/record.ts +3 -0
  122. package/src/core/render/context.ts +2 -0
  123. package/src/core/render/dynamic-post.ts +22 -7
  124. package/src/core/render/form.ts +145 -15
  125. package/src/core/render/index.ts +195 -14
  126. package/src/core/render/pagination.ts +21 -2
  127. package/src/core/render/vnode.ts +12 -2
  128. package/src/core/sanitize/css.ts +90 -77
  129. package/src/core/sanitize/embed-url.ts +7 -1
  130. package/src/core/sanitize/href.ts +13 -1
  131. package/src/core/sanitize/svg.ts +8 -3
  132. package/src/core/sanitize/url.ts +10 -1
  133. package/src/core/schema/descriptors.ts +4 -1
  134. package/src/core/schema/design.ts +5 -7
  135. package/src/core/schema/layout.ts +160 -181
  136. package/src/core/schema/style.ts +53 -63
  137. package/src/core/share/link.ts +72 -29
  138. package/src/core/tabs/presence.ts +7 -17
  139. package/src/core/theme/dynamic.ts +205 -39
  140. package/src/core/theme/float.ts +1 -1
  141. package/src/core/tree-ops.ts +57 -0
  142. package/src/index.ts +14 -2
  143. package/src/mcp/errors.ts +44 -0
  144. package/src/mcp/index.ts +4 -0
  145. package/src/mcp/ports.ts +78 -0
  146. package/src/mcp/prompts.ts +76 -0
  147. package/src/mcp/publish.ts +60 -0
  148. package/src/mcp/queue.ts +19 -0
  149. package/src/mcp/rate-limit.ts +80 -0
  150. package/src/mcp/read.ts +419 -0
  151. package/src/mcp/refs.ts +84 -0
  152. package/src/mcp/settings.ts +18 -0
  153. package/src/mcp/tools.ts +265 -0
  154. package/src/mcp/write.ts +582 -0
  155. package/src/server/agent-settings.ts +134 -0
  156. package/src/server/design-routes.ts +75 -18
  157. package/src/server/icon-routes.ts +72 -16
  158. package/src/server/mcp-routes.ts +265 -0
  159. package/src/server/plugin.ts +40 -4
  160. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  161. package/src/admin/editor/icons/sets/lucide.json +0 -1
  162. package/src/admin/editor/icons/sets/remix.json +0 -1
  163. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -3,4 +3,16 @@ import { sanitizeUrl } from "./url.ts";
3
3
  const HREF_SCHEMES: ReadonlySet<string> = new Set(["http:", "https:", "mailto:", "tel:"]);
4
4
 
5
5
  /** Allowed public hrefs (R-032): http(s), mailto, tel, and relative paths, queries and hashes. */
6
- export const sanitizeHref = (value: string): string | undefined => sanitizeUrl(value, HREF_SCHEMES);
6
+ export function sanitizeHref(value: string): string | undefined {
7
+ // W-417: phone numbers are usually written with spaces ("tel:+1 555 010 0199"); the spaces
8
+ // made the link fall back to "#". They're dropped, as phones ignore them anyway.
9
+ if (/^\s*tel:/i.test(value)) return sanitizeUrl(value.replace(/\s+/g, ""), HREF_SCHEMES);
10
+ // W-427: "www.example.com" is a site, not a page path next to the current one.
11
+ const trimmed = value.trim().replace(/^www\./i, (w) => `https://${w}`);
12
+ // W-428: a plain space in an email link ("mailto:me@x.com?subject=Hi there") is encoded, as a
13
+ // browser would; the link used to fall back to "#". Web addresses with spaces are still refused.
14
+ return sanitizeUrl(
15
+ /^mailto:/i.test(trimmed) ? trimmed.replaceAll(" ", "%20") : trimmed,
16
+ HREF_SCHEMES,
17
+ );
18
+ }
@@ -198,9 +198,14 @@ function isSafeHref(tag: string, name: string, value: string): boolean {
198
198
  const isHrefName = (name: string) => name === "href" || name === "xlink:href";
199
199
 
200
200
  function isSafeUrlRefAttr(name: string, value: string): boolean {
201
- if (name !== "clip-path" && name !== "mask") return true;
202
- if (value === "none") return true;
203
- return URL_HASH_REF.test(value);
201
+ if (name === "clip-path" || name === "mask") {
202
+ if (value === "none") return true;
203
+ return URL_HASH_REF.test(value);
204
+ }
205
+ // fill, stroke and the rest: `url(https://…)` is a request from the visitor's browser.
206
+ // A fragment (`url(#id)`) stays inside this SVG.
207
+ if (/url\s*\(/i.test(value)) return URL_HASH_REF.test(value);
208
+ return true;
204
209
  }
205
210
 
206
211
  type ParsedAttrs = { attrs: Record<string, string>; external: boolean };
@@ -16,16 +16,25 @@ export function sanitizeUrl(value: string, schemes: ReadonlySet<string>): string
16
16
  if (!hasScheme) {
17
17
  // Browsers resolve `//host` and `/\host` to another site; EmDash 1.0 refuses them for `url` fields too.
18
18
  if (/^\/[/\\]/.test(trimmed)) return undefined;
19
+ // A normal space can sit in a relative path. Any other whitespace, or a backslash, is how a
20
+ // second address hides in the same string.
21
+ if (/[^\S ]|\\/.test(trimmed)) return undefined;
19
22
  // Relative: /path, ./path, ../path, ?query, #hash, or bare path segment
20
23
  if (/^(?:[/?#.]|[A-Za-z0-9._~-])/.test(trimmed)) return trimmed;
21
24
  return undefined;
22
25
  }
23
26
 
27
+ // Parse the string we will return. Stripping whitespace first, then returning the original,
28
+ // accepted `https://site/a.png 1w, https://evil/x` because only the stripped copy was checked.
29
+ if (/[\s\\]/.test(trimmed)) return undefined;
30
+
24
31
  let parsed: URL;
25
32
  try {
26
- parsed = new URL(trimmed.replace(/\s+/g, ""));
33
+ parsed = new URL(trimmed);
27
34
  } catch {
28
35
  return undefined;
29
36
  }
37
+ // `user:pass@host` would publish the password in the page.
38
+ if (parsed.username || parsed.password) return undefined;
30
39
  return schemes.has(parsed.protocol.toLowerCase()) ? trimmed : undefined;
31
40
  }
@@ -9,7 +9,8 @@ export type FieldKind =
9
9
  | "href"
10
10
  | "media"
11
11
  | "icon"
12
- | "list-items";
12
+ | "list-items"
13
+ | "image-sources";
13
14
 
14
15
  export type FieldOption = { value: string | number | boolean; label: string };
15
16
 
@@ -23,6 +24,8 @@ export type FieldDescriptor = {
23
24
  optional?: boolean;
24
25
  /** Highest value a whole-number field accepts, matching its schema (W-223). */
25
26
  max?: number;
27
+ /** Lowest value a whole-number field accepts; unset is 1 (W-388). */
28
+ min?: number;
26
29
  /** Props that hold this field's tablet and mobile values (W-139); unset follows the wider device. */
27
30
  devices?: { tablet: string; mobile: string };
28
31
  };
@@ -1,11 +1,14 @@
1
1
  import { z } from "zod";
2
+ import { HEX_COLOR } from "../css-keywords.ts";
2
3
  import { DeviceStyles, HiddenOn, StyleProps, StyleStates } from "./style.ts";
3
4
 
4
5
  /**
6
+ * 15 since W-341, in step with layouts (optional fields only; the design document itself is unchanged).
7
+ * 14 since W-329, in step with layouts (optional fields only: `ch` lengths, negative margins).
5
8
  * 13 since W-307, in step with layouts (the W-307 batch only adds optional fields).
6
9
  * 12 since W-160: class gradients use the same stops as layouts. v11 `{ angle, from, to }` upgrades on read.
7
10
  */
8
- export const DESIGN_SCHEMA_VERSION = 13;
11
+ export const DESIGN_SCHEMA_VERSION = 15;
9
12
 
10
13
  /** Tags a site can give a starting style. Classes and local styles still win. */
11
14
  export const DEFAULT_STYLE_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "a", "button"] as const;
@@ -19,12 +22,7 @@ const VariableId = z
19
22
  export const ColorVariable = z.strictObject({
20
23
  id: VariableId,
21
24
  name: z.string().min(1).max(60),
22
- value: z
23
- .string()
24
- .regex(
25
- /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,
26
- "Use a hex color such as #1a2b3c",
27
- ),
25
+ value: z.string().regex(HEX_COLOR, "Use a hex color such as #1a2b3c"),
28
26
  });
29
27
 
30
28
  /** Font stack string — commas and quoted family names allowed; `generateCss` drops an unsafe one. */
@@ -3,13 +3,18 @@ import { MAX_TEXT_LENGTH } from "../limits.ts";
3
3
  import { DeviceStyles, HiddenOn, Length, StyleProps, StyleStates } from "./style.ts";
4
4
 
5
5
  /**
6
+ * 15 since W-341: optional per-element `dir`, image link/caption/focal point/sources, button icons,
7
+ * a table-of-contents element, and container queries. Every other value is unchanged.
8
+ * 14 since W-329: optional visitor `segments` in an element's audience (the host names them);
9
+ * W-330 Loop permalink, image, excerpt and filter options; W-331 `ch` lengths and negative
10
+ * margins. Every other value is unchanged.
6
11
  * 13 since W-307: optional `bind` on a node (live data bindings); W-308 collection Loops and the
7
12
  * Loop's Empty state element. Every other value is unchanged.
8
13
  * 12 since W-160: gradient type, stop locations, and up to 10 stops. v11 gradients
9
14
  * (`{ angle, from, to }`) become a linear gradient on read.
10
15
  * 11 since W-156 and W-157 (D-045): the layout Section element and an editor-only node label.
11
16
  */
12
- export const LAYOUT_SCHEMA_VERSION = 13;
17
+ export const LAYOUT_SCHEMA_VERSION = 15;
13
18
 
14
19
  export const NodeId = z
15
20
  .string()
@@ -96,6 +101,10 @@ export const Variant = z.strictObject({
96
101
  export type Variant = z.infer<typeof Variant>;
97
102
 
98
103
  export const AUDIENCE_DEVICES = ["mobile", "tablet", "desktop"] as const;
104
+ /** A visitor segment name the host passes and a Visitors rule matches (W-329). */
105
+ /** A host segment name: letters, digits, and `:` `_` `-`, up to 64 characters (`plan:pro`). */
106
+ export const AUDIENCE_SEGMENT = /^[a-z0-9][a-z0-9:_-]{0,63}$/;
107
+ const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _, e.g. plan:pro";
99
108
 
100
109
  /**
101
110
  * Who sees an element (W-313): visitors from these countries, on these devices, new or
@@ -123,6 +132,11 @@ export const Audience = z.strictObject({
123
132
  .regex(/^[A-Za-z][A-Za-z0-9_+-]*(\/[A-Za-z0-9_+-]+){0,2}$/)
124
133
  .max(64)
125
134
  .optional(),
135
+ /**
136
+ * Visitor segments the host passes (W-329), e.g. `member`, `plan:pro`: the rule matches a
137
+ * visitor in any of them. A letter or digit, then letters, digits, `:`, `_` or `-`, up to 64.
138
+ */
139
+ segments: z.array(z.string().regex(AUDIENCE_SEGMENT, SEGMENT_HINT)).min(1).max(20).optional(),
126
140
  hide: z.boolean().optional(),
127
141
  });
128
142
  export type Audience = z.infer<typeof Audience>;
@@ -133,11 +147,12 @@ const BoxLink = {
133
147
  newTab: z.boolean().optional(),
134
148
  };
135
149
 
136
- /** The fields every element has; `props` is the element's own strict props schema. */
137
- const nodeFields = <T extends string, P extends z.ZodType>(type: T, props: P) => ({
138
- id: NodeId,
139
- type: z.literal(type),
140
- props,
150
+ /**
151
+ * Fields every element carries, known or unknown (W-352). One object so a new field cannot
152
+ * land on known nodes and be stripped from unknown ones, which is what happened to
153
+ * `dir`, `container` and `query` before this.
154
+ */
155
+ const sharedNodeFields = {
141
156
  style: StyleProps.optional(),
142
157
  states: StyleStates.optional(),
143
158
  devices: DeviceStyles.optional(),
@@ -149,6 +164,28 @@ const nodeFields = <T extends string, P extends z.ZodType>(type: T, props: P) =>
149
164
  bind: Bindings.optional(),
150
165
  variant: Variant.optional(),
151
166
  audience: Audience.optional(),
167
+ /** Text direction for this element only (W-341). Unset follows the site direction. */
168
+ dir: z.enum(["ltr", "rtl", "auto"]).optional(),
169
+ /** This box is a container-query container (`container-type: inline-size`) (W-346). */
170
+ container: z.literal(true).optional(),
171
+ /**
172
+ * Style overrides when the nearest query container is at least `min` px wide (W-346).
173
+ * Emitted as `@container (min-width: Npx)`, not a viewport media query.
174
+ */
175
+ query: z
176
+ .strictObject({
177
+ min: z.number().int().min(1).max(3840),
178
+ style: StyleProps,
179
+ })
180
+ .optional(),
181
+ };
182
+
183
+ /** The fields every element has; `props` is the element's own strict props schema. */
184
+ const nodeFields = <T extends string, P extends z.ZodType>(type: T, props: P) => ({
185
+ id: NodeId,
186
+ type: z.literal(type),
187
+ props,
188
+ ...sharedNodeFields,
152
189
  });
153
190
 
154
191
  const leafNode = <T extends string, P extends z.ZodType>(type: T, props: P) =>
@@ -212,6 +249,12 @@ export const ButtonNode = leafNode(
212
249
  text: z.string().max(MAX_TEXT_LENGTH),
213
250
  href: z.string().max(2000).optional(),
214
251
  newTab: z.boolean().optional(),
252
+ /** Icon shown with the label (W-343). The SVG is stored on the button, like an Icon element. */
253
+ iconId: z.string().max(64).optional(),
254
+ iconSvg: z.string().max(32_768).optional(),
255
+ iconPosition: z.enum(["before", "after"]).optional(),
256
+ iconGap: z.number().int().min(0).max(64).optional(),
257
+ iconSize: z.enum(["sm", "md", "lg"]).optional(),
215
258
  }),
216
259
  );
217
260
 
@@ -279,6 +322,23 @@ export const ImageNode = leafNode(
279
322
  mediaId: z.string().min(1).max(128).optional(),
280
323
  /** Load right away (eager, high fetch priority) for the hero/LCP image (W-226). */
281
324
  priority: z.boolean().optional(),
325
+ /** Link around the image. Size styles stay on the img (W-342). */
326
+ href: z.string().max(2000).optional(),
327
+ newTab: z.boolean().optional(),
328
+ caption: z.string().max(500).optional(),
329
+ /** Focal point as object-position percentages (W-344). */
330
+ focalX: z.number().int().min(0).max(100).optional(),
331
+ focalY: z.number().int().min(0).max(100).optional(),
332
+ /** Extra widths for srcset. Omitted when there is no distinct URL (W-344). */
333
+ sources: z
334
+ .array(
335
+ z.strictObject({
336
+ src: z.string().max(2000),
337
+ width: z.number().int().min(1).max(8000),
338
+ }),
339
+ )
340
+ .max(6)
341
+ .optional(),
282
342
  }),
283
343
  ).refine((node) => node.props.decorative === true || node.props.alt.length > 0, {
284
344
  message: "Alt text is required unless the image is marked decorative.",
@@ -321,15 +381,29 @@ export const LayoutSectionNode = parentNode(
321
381
  export const FlexboxNode = parentNode("flexbox", z.strictObject({ ...BoxLink }));
322
382
 
323
383
  /**
324
- * Equal columns. Children span with `gridColumnSpan` and `gridRowSpan` on their style. Tablet
325
- * and mobile may have their own count (W-139); unset follows the next wider device.
384
+ * Equal columns, or custom tracks when `columnTracks` is set for that device. Children span
385
+ * with `gridColumnSpan` and `gridRowSpan`, and can start on a line with `gridColumnStart` and
386
+ * `gridRowStart`. Tablet and mobile may have their own count (W-139); unset follows the next
387
+ * wider device.
326
388
  */
389
+ /**
390
+ * One grid track: `1fr`/`2fr`/`3fr`, `auto`, `min-content`, `max-content`, or a length
391
+ * in the same units as other lengths (`200px`, `20%`, `1.5rem`).
392
+ */
393
+ const GRID_TRACK =
394
+ /^(?:1fr|2fr|3fr|auto|min-content|max-content|0|(?:\d+(?:\.\d+)?)(?:px|rem|em|%|vw|vh|ch))$/;
395
+ const GridTracks = z.array(z.string().regex(GRID_TRACK)).min(1).max(12);
396
+
327
397
  export const GridNode = parentNode(
328
398
  "grid",
329
399
  z.strictObject({
330
400
  columns: z.number().int().min(1).max(12),
331
401
  columnsTablet: z.number().int().min(1).max(12).optional(),
332
402
  columnsMobile: z.number().int().min(1).max(12).optional(),
403
+ /** Replaces equal `columns` on that device when set. */
404
+ columnTracks: GridTracks.optional(),
405
+ columnTracksTablet: GridTracks.optional(),
406
+ columnTracksMobile: GridTracks.optional(),
333
407
  ...BoxLink,
334
408
  }),
335
409
  );
@@ -486,6 +560,19 @@ export const PostLinkNode = leafNode(
486
560
  */
487
561
  /** How a Loop lays out its items (W-308): one design, shown as a list, a grid or cards. */
488
562
  export const LOOP_DISPLAYS = ["list", "grid", "cards"] as const;
563
+ /** A collection field's slug, e.g. `photo` (W-330). */
564
+ const FIELD_SLUG = /^[a-z][a-z0-9_]{0,63}$/;
565
+ const FIELD_SLUG_HINT = "Use the field's slug, e.g. photo";
566
+ /** A site path with `{slug}` or `{id}`, and no other placeholders (W-330). */
567
+ export const LOOP_PERMALINK =
568
+ /^(?=.*\{(?:slug|id)\})\/(?!\/)(?:[A-Za-z0-9._~/-]|\{slug\}|\{id\})*$/;
569
+ /**
570
+ * `field=value` pairs separated by `;` (W-330). Values have no `;`, `=` or angle brackets.
571
+ * W-391: a value starts and ends with a non-space, so the spaces around it can only be matched
572
+ * one way; the earlier pattern let both sides take them and a 265-character filter took ~50 s.
573
+ */
574
+ export const LOOP_FILTER =
575
+ /^\s*[a-z][a-z0-9_]{0,63}\s*=\s*[^;=<>\s](?:[^;=<>]{0,98}[^;=<>\s])?(?:\s*;\s*[a-z][a-z0-9_]{0,63}\s*=\s*[^;=<>\s](?:[^;=<>]{0,98}[^;=<>\s])?)*\s*;?\s*$/;
489
576
  /** Which entries a collection Loop shows first (W-308). */
490
577
  export const LOOP_ORDERS = ["newest", "oldest", "title"] as const;
491
578
 
@@ -509,6 +596,28 @@ export const LoopNode = parentNode(
509
596
  display: z.enum(LOOP_DISPLAYS).optional(),
510
597
  /** Columns for grid and cards, 1–6 (one column on phones). Unset = 3. */
511
598
  columns: z.number().int().min(1).max(6).optional(),
599
+ /**
600
+ * Where each entry links (W-330), e.g. `/team/{slug}`; `{slug}` and `{id}` are filled in.
601
+ * Unset = `/<collection>/{slug}`.
602
+ */
603
+ permalink: z
604
+ .string()
605
+ .max(200)
606
+ .regex(LOOP_PERMALINK, "A site path with {slug} or {id}, e.g. /team/{slug}")
607
+ .optional(),
608
+ /** The entry field holding the image Post Image shows (W-330). Unset = featured_image. */
609
+ imageField: z.string().regex(FIELD_SLUG, FIELD_SLUG_HINT).optional(),
610
+ /** The entry field Post Excerpt shows (W-330). Unset = excerpt. */
611
+ excerptField: z.string().regex(FIELD_SLUG, FIELD_SLUG_HINT).optional(),
612
+ /**
613
+ * Only entries where `field=value` (W-330), pairs separated by `;`, at most 5. A taxonomy name
614
+ * filters by term; the same field twice matches either value.
615
+ */
616
+ filter: z
617
+ .string()
618
+ .max(300)
619
+ .regex(LOOP_FILTER, "Use field=value pairs separated by ;")
620
+ .optional(),
512
621
  }),
513
622
  );
514
623
 
@@ -588,8 +697,17 @@ export const KNOWN_ELEMENT_TYPES = [
588
697
  "menu",
589
698
  "menu-item",
590
699
  "layout-section",
700
+ "toc",
591
701
  ] as const;
592
702
 
703
+ /** Headings on this page, as a list of links. No script (W-345). */
704
+ export const TocNode = leafNode(
705
+ "toc",
706
+ z.strictObject({
707
+ title: z.string().max(80).optional(),
708
+ }),
709
+ );
710
+
593
711
  const knownTypeSet = new Set<string>(KNOWN_ELEMENT_TYPES);
594
712
 
595
713
  /**
@@ -604,15 +722,7 @@ const UnknownNodeSchema = z.strictObject({
604
722
  .max(64)
605
723
  .refine((value) => !knownTypeSet.has(value), "Unknown element type"),
606
724
  props: z.record(z.string(), z.unknown()),
607
- style: StyleProps.optional(),
608
- states: StyleStates.optional(),
609
- classes: ClassIds.optional(),
610
- htmlId: HtmlId.optional(),
611
- attributes: HtmlAttributes.optional(),
612
- label: NodeLabel.optional(),
613
- bind: Bindings.optional(),
614
- variant: Variant.optional(),
615
- audience: Audience.optional(),
725
+ ...sharedNodeFields,
616
726
  get children(): z.ZodType<LayoutNode[] | undefined> {
617
727
  return z.array(LayoutNode).optional();
618
728
  },
@@ -628,6 +738,7 @@ const KnownLayoutNode = z.discriminatedUnion("type", [
628
738
  TabsNodeSchema,
629
739
  TabPanelNode,
630
740
  HeadingNode,
741
+ TocNode,
631
742
  SpacerNode,
632
743
  DividerNode,
633
744
  TextNode,
@@ -662,7 +773,11 @@ const KnownLayoutNode = z.discriminatedUnion("type", [
662
773
  MenuItemNode,
663
774
  ]);
664
775
 
776
+ /** One strict schema per known element type, for the MCP element catalogue (W-453). */
777
+ export const KNOWN_NODE_SCHEMAS = KnownLayoutNode.options;
778
+
665
779
  export type HeadingNode = z.infer<typeof HeadingNode>;
780
+ export type TocNode = z.infer<typeof TocNode>;
666
781
  export type SpacerNode = z.infer<typeof SpacerNode>;
667
782
  export type DividerNode = z.infer<typeof DividerNode>;
668
783
  export type TextNode = z.infer<typeof TextNode>;
@@ -702,13 +817,14 @@ export type NodeExtras = {
702
817
  bind?: Record<string, Binding>;
703
818
  variant?: Variant;
704
819
  audience?: Audience;
820
+ dir?: "ltr" | "rtl" | "auto";
821
+ container?: true;
822
+ query?: { min: number; style: StyleOf };
705
823
  };
706
824
 
707
- /** Manual recursive types so UnknownNode does not poison `z.infer` of the tree. */
708
- export type UnknownNode = NodeExtras & {
825
+ /** Identity, style and extras shared by every node type (W-352). */
826
+ type NodeEnvelope = {
709
827
  id: IdOf;
710
- type: string;
711
- props: Record<string, unknown>;
712
828
  style?: StyleOf;
713
829
  states?: StatesOf;
714
830
  devices?: DevicesOf;
@@ -717,60 +833,38 @@ export type UnknownNode = NodeExtras & {
717
833
  htmlId?: HtmlIdOf;
718
834
  attributes?: HtmlAttributeOf[];
719
835
  label?: string;
836
+ } & NodeExtras;
837
+
838
+ /** Manual recursive types so UnknownNode does not poison `z.infer` of the tree. */
839
+ export type UnknownNode = NodeEnvelope & {
840
+ type: string;
841
+ props: Record<string, unknown>;
720
842
  children?: LayoutNode[];
721
843
  };
722
844
 
723
- export type ContainerNode = NodeExtras & {
724
- id: IdOf;
845
+ export type ContainerNode = NodeEnvelope & {
725
846
  type: "container";
726
847
  props: { tag?: (typeof CONTAINER_TAGS)[number]; href?: string; newTab?: boolean };
727
- style?: StyleOf;
728
- states?: StatesOf;
729
- devices?: DevicesOf;
730
- hiddenOn?: HiddenOnOf;
731
- classes?: ClassesOf;
732
- htmlId?: HtmlIdOf;
733
- attributes?: HtmlAttributeOf[];
734
- label?: string;
735
848
  children: LayoutNode[];
736
849
  };
737
850
 
738
- export type DivBlockNode = NodeExtras & {
739
- id: IdOf;
851
+ export type DivBlockNode = NodeEnvelope & {
740
852
  type: "div-block";
741
853
  props: { href?: string; newTab?: boolean };
742
- style?: StyleOf;
743
- states?: StatesOf;
744
- devices?: DevicesOf;
745
- hiddenOn?: HiddenOnOf;
746
- classes?: ClassesOf;
747
- htmlId?: HtmlIdOf;
748
- attributes?: HtmlAttributeOf[];
749
- label?: string;
750
854
  children: LayoutNode[];
751
855
  };
752
856
 
753
- export type LayoutSectionNode = NodeExtras & {
754
- id: IdOf;
857
+ export type LayoutSectionNode = NodeEnvelope & {
755
858
  type: "layout-section";
756
859
  props: {
757
860
  tag?: (typeof CONTAINER_TAGS)[number];
758
861
  contentWidth?: z.infer<typeof Length>;
759
862
  fullWidth?: boolean;
760
863
  };
761
- style?: StyleOf;
762
- states?: StatesOf;
763
- devices?: DevicesOf;
764
- hiddenOn?: HiddenOnOf;
765
- classes?: ClassesOf;
766
- htmlId?: HtmlIdOf;
767
- attributes?: HtmlAttributeOf[];
768
- label?: string;
769
864
  children: LayoutNode[];
770
865
  };
771
866
 
772
- export type GridNode = NodeExtras & {
773
- id: IdOf;
867
+ export type GridNode = NodeEnvelope & {
774
868
  type: "grid";
775
869
  props: {
776
870
  columns: number;
@@ -779,34 +873,16 @@ export type GridNode = NodeExtras & {
779
873
  href?: string;
780
874
  newTab?: boolean;
781
875
  };
782
- style?: StyleOf;
783
- states?: StatesOf;
784
- devices?: DevicesOf;
785
- hiddenOn?: HiddenOnOf;
786
- classes?: ClassesOf;
787
- htmlId?: HtmlIdOf;
788
- attributes?: HtmlAttributeOf[];
789
- label?: string;
790
876
  children: LayoutNode[];
791
877
  };
792
878
 
793
- export type FlexboxNode = NodeExtras & {
794
- id: IdOf;
879
+ export type FlexboxNode = NodeEnvelope & {
795
880
  type: "flexbox";
796
881
  props: { href?: string; newTab?: boolean };
797
- style?: StyleOf;
798
- states?: StatesOf;
799
- devices?: DevicesOf;
800
- hiddenOn?: HiddenOnOf;
801
- classes?: ClassesOf;
802
- htmlId?: HtmlIdOf;
803
- attributes?: HtmlAttributeOf[];
804
- label?: string;
805
882
  children: LayoutNode[];
806
883
  };
807
884
 
808
- export type SvgNode = NodeExtras & {
809
- id: IdOf;
885
+ export type SvgNode = NodeEnvelope & {
810
886
  type: "svg";
811
887
  props: {
812
888
  markup: string;
@@ -814,63 +890,27 @@ export type SvgNode = NodeExtras & {
814
890
  decorative?: boolean;
815
891
  size?: number;
816
892
  };
817
- style?: StyleOf;
818
- states?: StatesOf;
819
- devices?: DevicesOf;
820
- hiddenOn?: HiddenOnOf;
821
- classes?: ClassesOf;
822
- htmlId?: HtmlIdOf;
823
- attributes?: HtmlAttributeOf[];
824
- label?: string;
825
893
  };
826
894
 
827
- export type TabPanelNode = NodeExtras & {
828
- id: IdOf;
895
+ export type TabPanelNode = NodeEnvelope & {
829
896
  type: "tab-panel";
830
897
  props: { label: string };
831
- style?: StyleOf;
832
- states?: StatesOf;
833
- devices?: DevicesOf;
834
- hiddenOn?: HiddenOnOf;
835
- classes?: ClassesOf;
836
- htmlId?: HtmlIdOf;
837
- attributes?: HtmlAttributeOf[];
838
- label?: string;
839
898
  children: LayoutNode[];
840
899
  };
841
900
 
842
- export type TabsNode = NodeExtras & {
843
- id: IdOf;
901
+ export type TabsNode = NodeEnvelope & {
844
902
  type: "tabs";
845
903
  props: { href?: string; newTab?: boolean };
846
- style?: StyleOf;
847
- states?: StatesOf;
848
- devices?: DevicesOf;
849
- hiddenOn?: HiddenOnOf;
850
- classes?: ClassesOf;
851
- htmlId?: HtmlIdOf;
852
- attributes?: HtmlAttributeOf[];
853
- label?: string;
854
904
  children: LayoutNode[];
855
905
  };
856
906
 
857
- export type FormNode = NodeExtras & {
858
- id: IdOf;
907
+ export type FormNode = NodeEnvelope & {
859
908
  type: "form";
860
909
  props: { formId: string };
861
- style?: StyleOf;
862
- states?: StatesOf;
863
- devices?: DevicesOf;
864
- hiddenOn?: HiddenOnOf;
865
- classes?: ClassesOf;
866
- htmlId?: HtmlIdOf;
867
- attributes?: HtmlAttributeOf[];
868
- label?: string;
869
910
  children: LayoutNode[];
870
911
  };
871
912
 
872
- export type LoopNode = NodeExtras & {
873
- id: IdOf;
913
+ export type LoopNode = NodeEnvelope & {
874
914
  type: "loop";
875
915
  props: {
876
916
  itemPartId?: string;
@@ -881,104 +921,42 @@ export type LoopNode = NodeExtras & {
881
921
  display?: (typeof LOOP_DISPLAYS)[number];
882
922
  columns?: number;
883
923
  };
884
- style?: StyleOf;
885
- states?: StatesOf;
886
- devices?: DevicesOf;
887
- hiddenOn?: HiddenOnOf;
888
- classes?: ClassesOf;
889
- htmlId?: HtmlIdOf;
890
- attributes?: HtmlAttributeOf[];
891
- label?: string;
892
924
  children: LayoutNode[];
893
925
  };
894
926
 
895
- export type LoopEmptyNode = NodeExtras & {
896
- id: IdOf;
927
+ export type LoopEmptyNode = NodeEnvelope & {
897
928
  type: "loop-empty";
898
929
  props: Record<string, never>;
899
- style?: StyleOf;
900
- states?: StatesOf;
901
- devices?: DevicesOf;
902
- hiddenOn?: HiddenOnOf;
903
- classes?: ClassesOf;
904
- htmlId?: HtmlIdOf;
905
- attributes?: HtmlAttributeOf[];
906
- label?: string;
907
930
  children: LayoutNode[];
908
931
  };
909
932
 
910
- export type SectionNode = NodeExtras & {
911
- id: IdOf;
933
+ export type SectionNode = NodeEnvelope & {
912
934
  type: "section";
913
935
  props: { partId?: string };
914
- style?: StyleOf;
915
- states?: StatesOf;
916
- devices?: DevicesOf;
917
- hiddenOn?: HiddenOnOf;
918
- classes?: ClassesOf;
919
- htmlId?: HtmlIdOf;
920
- attributes?: HtmlAttributeOf[];
921
- label?: string;
922
936
  children: LayoutNode[];
923
937
  };
924
938
 
925
- export type AccordionNode = NodeExtras & {
926
- id: IdOf;
939
+ export type AccordionNode = NodeEnvelope & {
927
940
  type: "accordion";
928
941
  props: Record<string, never>;
929
- style?: StyleOf;
930
- states?: StatesOf;
931
- devices?: DevicesOf;
932
- hiddenOn?: HiddenOnOf;
933
- classes?: ClassesOf;
934
- htmlId?: HtmlIdOf;
935
- attributes?: HtmlAttributeOf[];
936
- label?: string;
937
942
  children: LayoutNode[];
938
943
  };
939
944
 
940
- export type MenuNode = NodeExtras & {
941
- id: IdOf;
945
+ export type MenuNode = NodeEnvelope & {
942
946
  type: "menu";
943
947
  props: { direction: "row" | "column"; label?: string };
944
- style?: StyleOf;
945
- states?: StatesOf;
946
- devices?: DevicesOf;
947
- hiddenOn?: HiddenOnOf;
948
- classes?: ClassesOf;
949
- htmlId?: HtmlIdOf;
950
- attributes?: HtmlAttributeOf[];
951
- label?: string;
952
948
  children: LayoutNode[];
953
949
  };
954
950
 
955
- export type MenuItemNode = NodeExtras & {
956
- id: IdOf;
951
+ export type MenuItemNode = NodeEnvelope & {
957
952
  type: "menu-item";
958
953
  props: { text: string; href?: string; newTab?: boolean; wide?: boolean };
959
- style?: StyleOf;
960
- states?: StatesOf;
961
- devices?: DevicesOf;
962
- hiddenOn?: HiddenOnOf;
963
- classes?: ClassesOf;
964
- htmlId?: HtmlIdOf;
965
- attributes?: HtmlAttributeOf[];
966
- label?: string;
967
954
  children: LayoutNode[];
968
955
  };
969
956
 
970
- export type AccordionItemNode = NodeExtras & {
971
- id: IdOf;
957
+ export type AccordionItemNode = NodeEnvelope & {
972
958
  type: "accordion-item";
973
959
  props: { summary: string; open?: boolean };
974
- style?: StyleOf;
975
- states?: StatesOf;
976
- devices?: DevicesOf;
977
- hiddenOn?: HiddenOnOf;
978
- classes?: ClassesOf;
979
- htmlId?: HtmlIdOf;
980
- attributes?: HtmlAttributeOf[];
981
- label?: string;
982
960
  children: LayoutNode[];
983
961
  };
984
962
 
@@ -996,6 +974,7 @@ export type LayoutNode =
996
974
  | LoopEmptyNode
997
975
  | SectionNode
998
976
  | HeadingNode
977
+ | TocNode
999
978
  | SpacerNode
1000
979
  | DividerNode
1001
980
  | TextNode