@perkyzz/emvb 0.2.1 → 0.4.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 (150) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +3 -1
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/api.ts +17 -7
  6. package/src/admin/content-api.ts +7 -51
  7. package/src/admin/content-item.ts +22 -0
  8. package/src/admin/design-api.ts +30 -0
  9. package/src/admin/editor/A11yCopilot.tsx +126 -0
  10. package/src/admin/editor/CommandPalette.tsx +118 -0
  11. package/src/admin/editor/Editor.tsx +188 -152
  12. package/src/admin/editor/EditorOverlay.tsx +9 -1
  13. package/src/admin/editor/PerfMeter.tsx +121 -0
  14. package/src/admin/editor/ShareLink.tsx +164 -0
  15. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  16. package/src/admin/editor/Timeline.tsx +287 -0
  17. package/src/admin/editor/TopBar.tsx +4 -0
  18. package/src/admin/editor/canvas/CanvasFrame.tsx +62 -370
  19. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  20. package/src/admin/editor/canvas/SelectionOverlay.tsx +87 -47
  21. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  22. package/src/admin/editor/canvas/drop-line.ts +24 -0
  23. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  24. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  25. package/src/admin/editor/collection-previews.ts +114 -0
  26. package/src/admin/editor/editor-chrome.tsx +346 -0
  27. package/src/admin/editor/editor-commands.ts +360 -0
  28. package/src/admin/editor/editor-css.ts +5 -3
  29. package/src/admin/editor/element-chrome.ts +89 -0
  30. package/src/admin/editor/feature-css.ts +105 -0
  31. package/src/admin/editor/host.ts +35 -0
  32. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  33. package/src/admin/editor/icons/library.ts +29 -19
  34. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  35. package/src/admin/editor/live-data.tsx +71 -0
  36. package/src/admin/editor/palette-items.ts +136 -0
  37. package/src/admin/editor/palette.ts +68 -0
  38. package/src/admin/editor/panels/AddPanel.tsx +48 -68
  39. package/src/admin/editor/panels/ClassesSection.tsx +5 -1
  40. package/src/admin/editor/panels/ColorControl.tsx +2 -10
  41. package/src/admin/editor/panels/ElementPanel.tsx +74 -102
  42. package/src/admin/editor/panels/LayersPanel.tsx +72 -63
  43. package/src/admin/editor/panels/LeftPanel.tsx +4 -1
  44. package/src/admin/editor/panels/SettingsPanel.tsx +13 -0
  45. package/src/admin/editor/panels/SiteStylesDrawer.tsx +18 -10
  46. package/src/admin/editor/panels/TokenScales.tsx +168 -0
  47. package/src/admin/editor/panels/VariableSection.tsx +10 -14
  48. package/src/admin/editor/panels/inline-error.tsx +11 -0
  49. package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
  50. package/src/admin/editor/panels/settings/AudienceEditor.tsx +285 -0
  51. package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
  52. package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
  53. package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
  54. package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
  55. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  56. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  57. package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
  58. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  59. package/src/admin/editor/panels/settings/StyleRow.tsx +26 -2
  60. package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
  61. package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
  62. package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
  63. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  64. package/src/admin/editor/panels/settings/length-units.ts +16 -5
  65. package/src/admin/editor/panels/settings/style-sections.ts +7 -2
  66. package/src/admin/editor/panels/style-target.ts +105 -0
  67. package/src/admin/editor/section-templates.ts +43 -21
  68. package/src/admin/editor/shortcuts.ts +6 -1
  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 +30 -14
  74. package/src/admin/editor/useNodeActions.ts +44 -16
  75. package/src/admin/forms-api.ts +17 -6
  76. package/src/admin/icon-uploads-api.ts +18 -0
  77. package/src/admin/theme-api.ts +5 -18
  78. package/src/admin/ui.ts +4 -4
  79. package/src/astro/content-port.ts +24 -0
  80. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  81. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  82. package/src/astro/forms/client.ts +1 -0
  83. package/src/astro/forms-definitions.ts +24 -11
  84. package/src/astro/index.ts +1 -0
  85. package/src/astro/render-session.ts +85 -0
  86. package/src/astro/request-data.ts +109 -0
  87. package/src/astro/resolve-theme.ts +184 -64
  88. package/src/astro/resolve.ts +63 -16
  89. package/src/astro/theme-posts.ts +48 -5
  90. package/src/astro/visitor.ts +204 -0
  91. package/src/constants.ts +1 -1
  92. package/src/core/a11y/audit.ts +282 -0
  93. package/src/core/arrange.ts +150 -34
  94. package/src/core/audience/rules.ts +124 -0
  95. package/src/core/audience/variants.ts +51 -0
  96. package/src/core/canvas-styles.ts +24 -0
  97. package/src/core/clipboard.ts +11 -32
  98. package/src/core/css/generate.ts +29 -2
  99. package/src/core/css/print.ts +12 -0
  100. package/src/core/css/scope.ts +3 -3
  101. package/src/core/css/trace.ts +169 -0
  102. package/src/core/css-keywords.ts +83 -0
  103. package/src/core/data/bindings.ts +255 -0
  104. package/src/core/design/classes.ts +13 -15
  105. package/src/core/design/diff.ts +55 -0
  106. package/src/core/design/merge.ts +127 -0
  107. package/src/core/design/tokens.ts +127 -0
  108. package/src/core/design/variables.ts +25 -21
  109. package/src/core/elements/dynamic-elements.ts +117 -2
  110. package/src/core/elements/form-elements.ts +1 -0
  111. package/src/core/elements/index.ts +185 -7
  112. package/src/core/forms/binding.ts +4 -13
  113. package/src/core/history/diff.ts +152 -0
  114. package/src/core/index.ts +121 -0
  115. package/src/core/local-style.ts +27 -0
  116. package/src/core/migrate/index.ts +12 -4
  117. package/src/core/nesting.ts +4 -22
  118. package/src/core/perf/meter.ts +160 -0
  119. package/src/core/perf/scripts.ts +61 -0
  120. package/src/core/recipes/index.ts +433 -0
  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 +1 -2
  124. package/src/core/render/form.ts +133 -10
  125. package/src/core/render/index.ts +206 -17
  126. package/src/core/render/loop.ts +54 -7
  127. package/src/core/render/pagination.ts +9 -1
  128. package/src/core/render/vnode.ts +12 -2
  129. package/src/core/sanitize/css.ts +129 -80
  130. package/src/core/sanitize/motion.ts +129 -0
  131. package/src/core/sanitize/svg.ts +8 -3
  132. package/src/core/sanitize/url.ts +10 -1
  133. package/src/core/schema/design.ts +29 -8
  134. package/src/core/schema/layout.ts +291 -169
  135. package/src/core/schema/motion.ts +14 -0
  136. package/src/core/schema/style.ts +101 -66
  137. package/src/core/share/link.ts +187 -0
  138. package/src/core/tabs/presence.ts +7 -17
  139. package/src/core/theme/dynamic.ts +242 -32
  140. package/src/core/theme/float.ts +1 -1
  141. package/src/core/theme/pagination.ts +56 -0
  142. package/src/core/tree-ops.ts +57 -0
  143. package/src/index.ts +14 -2
  144. package/src/server/design-routes.ts +4 -1
  145. package/src/server/icon-routes.ts +68 -16
  146. package/src/server/plugin.ts +8 -2
  147. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  148. package/src/admin/editor/icons/sets/lucide.json +0 -1
  149. package/src/admin/editor/icons/sets/remix.json +0 -1
  150. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -3,11 +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.
11
+ * 13 since W-307: optional `bind` on a node (live data bindings); W-308 collection Loops and the
12
+ * Loop's Empty state element. Every other value is unchanged.
6
13
  * 12 since W-160: gradient type, stop locations, and up to 10 stops. v11 gradients
7
14
  * (`{ angle, from, to }`) become a linear gradient on read.
8
15
  * 11 since W-156 and W-157 (D-045): the layout Section element and an editor-only node label.
9
16
  */
10
- export const LAYOUT_SCHEMA_VERSION = 12;
17
+ export const LAYOUT_SCHEMA_VERSION = 15;
11
18
 
12
19
  export const NodeId = z
13
20
  .string()
@@ -49,17 +56,103 @@ const HtmlAttribute = z.strictObject({
49
56
 
50
57
  const HtmlAttributes = z.array(HtmlAttribute).max(20);
51
58
 
59
+ /** Where a bound field reads its live value (W-307). */
60
+ export const BIND_SOURCES = ["post", "site", "param"] as const;
61
+ export type BindSource = (typeof BIND_SOURCES)[number];
62
+
63
+ /**
64
+ * A field bound to live data (W-307): a post field, a site setting or a URL parameter. The
65
+ * field's own value stays as the fallback when the source has nothing to show.
66
+ */
67
+ export const Binding = z.strictObject({
68
+ source: z.enum(BIND_SOURCES),
69
+ key: z
70
+ .string()
71
+ .regex(
72
+ /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/,
73
+ "Keys start with a letter: letters, digits, _, . or -, up to 64",
74
+ ),
75
+ /**
76
+ * A link or image bound to a URL parameter takes only same-site URLs (relative, or this site's
77
+ * origin) unless this is set (W-307). Anyone can craft such a link, so outside sites are opt-in.
78
+ */
79
+ outside: z.boolean().optional(),
80
+ });
81
+ export type Binding = z.infer<typeof Binding>;
82
+
83
+ /** Prop name → binding. Which props may be bound is checked against BINDABLE_FIELDS on render. */
84
+ const Bindings = z
85
+ .record(z.string().regex(/^[a-zA-Z]{1,32}$/), Binding)
86
+ .refine((value) => Object.keys(value).length <= 8, "At most 8 bound fields per element");
87
+
88
+ /** A/B test names (W-312): lowercase letters, digits and dashes, up to 32. */
89
+ export const AB_TEST_NAME = /^[a-z0-9][a-z0-9-]{0,31}$/;
90
+
91
+ /**
92
+ * One arm of an edge A/B test (W-312). Elements sharing a `test` are the variants; the host picks
93
+ * one arm per visitor on the server (a cookie keeps it), so there is no flicker and no script.
94
+ */
95
+ export const Variant = z.strictObject({
96
+ test: z.string().regex(AB_TEST_NAME, "Lowercase letters, digits and -, up to 32"),
97
+ arm: z.enum(["a", "b"]),
98
+ /** Share of visitors who see B, 1–99 %. Read from the test's B element. Unset = 50. */
99
+ split: z.number().int().min(1).max(99).optional(),
100
+ });
101
+ export type Variant = z.infer<typeof Variant>;
102
+
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. member";
108
+
109
+ /**
110
+ * Who sees an element (W-313): visitors from these countries, on these devices, new or
111
+ * returning, at these hours and days. Every rule set must match; `hide` flips it to "everyone
112
+ * except". Hosts evaluate it on the server; a rule the host can't read (no country header) does
113
+ * not match.
114
+ */
115
+ export const Audience = z.strictObject({
116
+ countries: z
117
+ .array(z.string().regex(/^[A-Z]{2}$/, "Two-letter country codes, e.g. CA"))
118
+ .min(1)
119
+ .max(50)
120
+ .optional(),
121
+ devices: z.array(z.enum(AUDIENCE_DEVICES)).min(1).max(3).optional(),
122
+ visitor: z.enum(["new", "returning"]).optional(),
123
+ /** From hour `from` up to (not including) hour `to`, 0–24; wraps past midnight when to < from. */
124
+ hours: z
125
+ .strictObject({ from: z.number().int().min(0).max(23), to: z.number().int().min(0).max(24) })
126
+ .optional(),
127
+ /** Days of the week, 0 = Sunday. */
128
+ days: z.array(z.number().int().min(0).max(6)).min(1).max(7).optional(),
129
+ /** IANA time zone for hours and days, e.g. America/Toronto. Unset = UTC. */
130
+ timeZone: z
131
+ .string()
132
+ .regex(/^[A-Za-z][A-Za-z0-9_+-]*(\/[A-Za-z0-9_+-]+){0,2}$/)
133
+ .max(64)
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(),
140
+ hide: z.boolean().optional(),
141
+ });
142
+ export type Audience = z.infer<typeof Audience>;
143
+
52
144
  /** A box may be the link. A link inside a link is dropped at render time (W-111). */
53
145
  const BoxLink = {
54
146
  href: z.string().max(2000).optional(),
55
147
  newTab: z.boolean().optional(),
56
148
  };
57
149
 
58
- /** The fields every element has; `props` is the element's own strict props schema. */
59
- const nodeFields = <T extends string, P extends z.ZodType>(type: T, props: P) => ({
60
- id: NodeId,
61
- type: z.literal(type),
62
- 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 = {
63
156
  style: StyleProps.optional(),
64
157
  states: StyleStates.optional(),
65
158
  devices: DeviceStyles.optional(),
@@ -68,6 +161,31 @@ const nodeFields = <T extends string, P extends z.ZodType>(type: T, props: P) =>
68
161
  htmlId: HtmlId.optional(),
69
162
  attributes: HtmlAttributes.optional(),
70
163
  label: NodeLabel.optional(),
164
+ bind: Bindings.optional(),
165
+ variant: Variant.optional(),
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,
71
189
  });
72
190
 
73
191
  const leafNode = <T extends string, P extends z.ZodType>(type: T, props: P) =>
@@ -131,6 +249,12 @@ export const ButtonNode = leafNode(
131
249
  text: z.string().max(MAX_TEXT_LENGTH),
132
250
  href: z.string().max(2000).optional(),
133
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(),
134
258
  }),
135
259
  );
136
260
 
@@ -198,6 +322,23 @@ export const ImageNode = leafNode(
198
322
  mediaId: z.string().min(1).max(128).optional(),
199
323
  /** Load right away (eager, high fetch priority) for the hero/LCP image (W-226). */
200
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(),
201
342
  }),
202
343
  ).refine((node) => node.props.decorative === true || node.props.alt.length > 0, {
203
344
  message: "Alt text is required unless the image is marked decorative.",
@@ -240,15 +381,29 @@ export const LayoutSectionNode = parentNode(
240
381
  export const FlexboxNode = parentNode("flexbox", z.strictObject({ ...BoxLink }));
241
382
 
242
383
  /**
243
- * Equal columns. Children span with `gridColumnSpan` and `gridRowSpan` on their style. Tablet
244
- * 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.
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`).
245
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
+
246
397
  export const GridNode = parentNode(
247
398
  "grid",
248
399
  z.strictObject({
249
400
  columns: z.number().int().min(1).max(12),
250
401
  columnsTablet: z.number().int().min(1).max(12).optional(),
251
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(),
252
407
  ...BoxLink,
253
408
  }),
254
409
  );
@@ -403,15 +558,71 @@ export const PostLinkNode = leafNode(
403
558
  * When `itemPartId` is set, the host supplies that Loop Item layout in loopTemplates;
404
559
  * otherwise children are the inline item template.
405
560
  */
561
+ /** How a Loop lays out its items (W-308): one design, shown as a list, a grid or cards. */
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
+ /** `field=value` pairs separated by `;` (W-330). Values have no `;`, `=` or angle brackets. */
570
+ export const LOOP_FILTER =
571
+ /^\s*[a-z][a-z0-9_]{0,63}\s*=\s*[^;=<>]{1,100}?(?:\s*;\s*[a-z][a-z0-9_]{0,63}\s*=\s*[^;=<>]{1,100}?)*\s*;?\s*$/;
572
+ /** Which entries a collection Loop shows first (W-308). */
573
+ export const LOOP_ORDERS = ["newest", "oldest", "title"] as const;
574
+
406
575
  export const LoopNode = parentNode(
407
576
  "loop",
408
577
  z.strictObject({
409
578
  itemPartId: z.string().max(128).optional(),
410
579
  /** Posts per archive page, 1–50 (W-221). Unset = 20. */
411
580
  perPage: z.number().int().min(1).max(50).optional(),
581
+ /**
582
+ * A collection to list on any page (W-308), e.g. `team`. Unset lists the archive's posts on
583
+ * an Archive part, as before.
584
+ */
585
+ collection: z
586
+ .string()
587
+ .regex(/^[a-z][a-z0-9_]{0,63}$/, "Use the collection's slug, e.g. team")
588
+ .optional(),
589
+ /** How many entries a collection Loop shows, 1–50. Unset = 6. */
590
+ limit: z.number().int().min(1).max(50).optional(),
591
+ order: z.enum(LOOP_ORDERS).optional(),
592
+ display: z.enum(LOOP_DISPLAYS).optional(),
593
+ /** Columns for grid and cards, 1–6 (one column on phones). Unset = 3. */
594
+ columns: z.number().int().min(1).max(6).optional(),
595
+ /**
596
+ * Where each entry links (W-330), e.g. `/team/{slug}`; `{slug}` and `{id}` are filled in.
597
+ * Unset = `/<collection>/{slug}`.
598
+ */
599
+ permalink: z
600
+ .string()
601
+ .max(200)
602
+ .regex(LOOP_PERMALINK, "A site path with {slug} or {id}, e.g. /team/{slug}")
603
+ .optional(),
604
+ /** The entry field holding the image Post Image shows (W-330). Unset = featured_image. */
605
+ imageField: z.string().regex(FIELD_SLUG, FIELD_SLUG_HINT).optional(),
606
+ /** The entry field Post Excerpt shows (W-330). Unset = excerpt. */
607
+ excerptField: z.string().regex(FIELD_SLUG, FIELD_SLUG_HINT).optional(),
608
+ /**
609
+ * Only entries where `field=value` (W-330), pairs separated by `;`, at most 5. A taxonomy name
610
+ * filters by term; the same field twice matches either value.
611
+ */
612
+ filter: z
613
+ .string()
614
+ .max(300)
615
+ .regex(LOOP_FILTER, "Use field=value pairs separated by ;")
616
+ .optional(),
412
617
  }),
413
618
  );
414
619
 
620
+ /**
621
+ * What a Loop shows when it has no entries (W-308). Only inside a Loop; its children are designed
622
+ * like any box, and it is left out of the item template.
623
+ */
624
+ export const LoopEmptyNode = parentNode("loop-empty", z.strictObject({}));
625
+
415
626
  /**
416
627
  * Previous / page numbers / Next links for an archive (W-222). Renders only on an archive with
417
628
  * more than one page; the host supplies `ThemeDynamicData.pagination`.
@@ -421,6 +632,10 @@ export const PaginationNode = leafNode(
421
632
  z.strictObject({
422
633
  prevText: z.string().max(40).optional(),
423
634
  nextText: z.string().max(40).optional(),
635
+ /** Show "Page N of M" beside the links (W-309). */
636
+ showCount: z.boolean().optional(),
637
+ /** The count's text; `{page}` and `{total}` are filled in. Unset = "Page {page} of {total}". */
638
+ countText: z.string().max(60).optional(),
424
639
  }),
425
640
  );
426
641
 
@@ -464,6 +679,7 @@ export const KNOWN_ELEMENT_TYPES = [
464
679
  "post-date",
465
680
  "post-author",
466
681
  "loop",
682
+ "loop-empty",
467
683
  "pagination",
468
684
  "section",
469
685
  "div-block",
@@ -477,8 +693,17 @@ export const KNOWN_ELEMENT_TYPES = [
477
693
  "menu",
478
694
  "menu-item",
479
695
  "layout-section",
696
+ "toc",
480
697
  ] as const;
481
698
 
699
+ /** Headings on this page, as a list of links. No script (W-345). */
700
+ export const TocNode = leafNode(
701
+ "toc",
702
+ z.strictObject({
703
+ title: z.string().max(80).optional(),
704
+ }),
705
+ );
706
+
482
707
  const knownTypeSet = new Set<string>(KNOWN_ELEMENT_TYPES);
483
708
 
484
709
  /**
@@ -493,12 +718,7 @@ const UnknownNodeSchema = z.strictObject({
493
718
  .max(64)
494
719
  .refine((value) => !knownTypeSet.has(value), "Unknown element type"),
495
720
  props: z.record(z.string(), z.unknown()),
496
- style: StyleProps.optional(),
497
- states: StyleStates.optional(),
498
- classes: ClassIds.optional(),
499
- htmlId: HtmlId.optional(),
500
- attributes: HtmlAttributes.optional(),
501
- label: NodeLabel.optional(),
721
+ ...sharedNodeFields,
502
722
  get children(): z.ZodType<LayoutNode[] | undefined> {
503
723
  return z.array(LayoutNode).optional();
504
724
  },
@@ -514,6 +734,7 @@ const KnownLayoutNode = z.discriminatedUnion("type", [
514
734
  TabsNodeSchema,
515
735
  TabPanelNode,
516
736
  HeadingNode,
737
+ TocNode,
517
738
  SpacerNode,
518
739
  DividerNode,
519
740
  TextNode,
@@ -539,6 +760,7 @@ const KnownLayoutNode = z.discriminatedUnion("type", [
539
760
  PostDateNode,
540
761
  PostAuthorNode,
541
762
  LoopNode,
763
+ LoopEmptyNode,
542
764
  PaginationNode,
543
765
  SectionNode,
544
766
  AccordionNode,
@@ -548,6 +770,7 @@ const KnownLayoutNode = z.discriminatedUnion("type", [
548
770
  ]);
549
771
 
550
772
  export type HeadingNode = z.infer<typeof HeadingNode>;
773
+ export type TocNode = z.infer<typeof TocNode>;
551
774
  export type SpacerNode = z.infer<typeof SpacerNode>;
552
775
  export type DividerNode = z.infer<typeof DividerNode>;
553
776
  export type TextNode = z.infer<typeof TextNode>;
@@ -582,11 +805,19 @@ type HtmlIdOf = z.infer<typeof HtmlId>;
582
805
  type HtmlAttributeOf = z.infer<typeof HtmlAttribute>;
583
806
  type IdOf = z.infer<typeof NodeId>;
584
807
 
585
- /** Manual recursive types so UnknownNode does not poison `z.infer` of the tree. */
586
- export type UnknownNode = {
808
+ /** Fields every node may carry beyond its props and style (W-307 onward). */
809
+ export type NodeExtras = {
810
+ bind?: Record<string, Binding>;
811
+ variant?: Variant;
812
+ audience?: Audience;
813
+ dir?: "ltr" | "rtl" | "auto";
814
+ container?: true;
815
+ query?: { min: number; style: StyleOf };
816
+ };
817
+
818
+ /** Identity, style and extras shared by every node type (W-352). */
819
+ type NodeEnvelope = {
587
820
  id: IdOf;
588
- type: string;
589
- props: Record<string, unknown>;
590
821
  style?: StyleOf;
591
822
  states?: StatesOf;
592
823
  devices?: DevicesOf;
@@ -595,60 +826,38 @@ export type UnknownNode = {
595
826
  htmlId?: HtmlIdOf;
596
827
  attributes?: HtmlAttributeOf[];
597
828
  label?: string;
829
+ } & NodeExtras;
830
+
831
+ /** Manual recursive types so UnknownNode does not poison `z.infer` of the tree. */
832
+ export type UnknownNode = NodeEnvelope & {
833
+ type: string;
834
+ props: Record<string, unknown>;
598
835
  children?: LayoutNode[];
599
836
  };
600
837
 
601
- export type ContainerNode = {
602
- id: IdOf;
838
+ export type ContainerNode = NodeEnvelope & {
603
839
  type: "container";
604
840
  props: { tag?: (typeof CONTAINER_TAGS)[number]; href?: string; newTab?: boolean };
605
- style?: StyleOf;
606
- states?: StatesOf;
607
- devices?: DevicesOf;
608
- hiddenOn?: HiddenOnOf;
609
- classes?: ClassesOf;
610
- htmlId?: HtmlIdOf;
611
- attributes?: HtmlAttributeOf[];
612
- label?: string;
613
841
  children: LayoutNode[];
614
842
  };
615
843
 
616
- export type DivBlockNode = {
617
- id: IdOf;
844
+ export type DivBlockNode = NodeEnvelope & {
618
845
  type: "div-block";
619
846
  props: { href?: string; newTab?: boolean };
620
- style?: StyleOf;
621
- states?: StatesOf;
622
- devices?: DevicesOf;
623
- hiddenOn?: HiddenOnOf;
624
- classes?: ClassesOf;
625
- htmlId?: HtmlIdOf;
626
- attributes?: HtmlAttributeOf[];
627
- label?: string;
628
847
  children: LayoutNode[];
629
848
  };
630
849
 
631
- export type LayoutSectionNode = {
632
- id: IdOf;
850
+ export type LayoutSectionNode = NodeEnvelope & {
633
851
  type: "layout-section";
634
852
  props: {
635
853
  tag?: (typeof CONTAINER_TAGS)[number];
636
854
  contentWidth?: z.infer<typeof Length>;
637
855
  fullWidth?: boolean;
638
856
  };
639
- style?: StyleOf;
640
- states?: StatesOf;
641
- devices?: DevicesOf;
642
- hiddenOn?: HiddenOnOf;
643
- classes?: ClassesOf;
644
- htmlId?: HtmlIdOf;
645
- attributes?: HtmlAttributeOf[];
646
- label?: string;
647
857
  children: LayoutNode[];
648
858
  };
649
859
 
650
- export type GridNode = {
651
- id: IdOf;
860
+ export type GridNode = NodeEnvelope & {
652
861
  type: "grid";
653
862
  props: {
654
863
  columns: number;
@@ -657,34 +866,16 @@ export type GridNode = {
657
866
  href?: string;
658
867
  newTab?: boolean;
659
868
  };
660
- style?: StyleOf;
661
- states?: StatesOf;
662
- devices?: DevicesOf;
663
- hiddenOn?: HiddenOnOf;
664
- classes?: ClassesOf;
665
- htmlId?: HtmlIdOf;
666
- attributes?: HtmlAttributeOf[];
667
- label?: string;
668
869
  children: LayoutNode[];
669
870
  };
670
871
 
671
- export type FlexboxNode = {
672
- id: IdOf;
872
+ export type FlexboxNode = NodeEnvelope & {
673
873
  type: "flexbox";
674
874
  props: { href?: string; newTab?: boolean };
675
- style?: StyleOf;
676
- states?: StatesOf;
677
- devices?: DevicesOf;
678
- hiddenOn?: HiddenOnOf;
679
- classes?: ClassesOf;
680
- htmlId?: HtmlIdOf;
681
- attributes?: HtmlAttributeOf[];
682
- label?: string;
683
875
  children: LayoutNode[];
684
876
  };
685
877
 
686
- export type SvgNode = {
687
- id: IdOf;
878
+ export type SvgNode = NodeEnvelope & {
688
879
  type: "svg";
689
880
  props: {
690
881
  markup: string;
@@ -692,148 +883,73 @@ export type SvgNode = {
692
883
  decorative?: boolean;
693
884
  size?: number;
694
885
  };
695
- style?: StyleOf;
696
- states?: StatesOf;
697
- devices?: DevicesOf;
698
- hiddenOn?: HiddenOnOf;
699
- classes?: ClassesOf;
700
- htmlId?: HtmlIdOf;
701
- attributes?: HtmlAttributeOf[];
702
- label?: string;
703
886
  };
704
887
 
705
- export type TabPanelNode = {
706
- id: IdOf;
888
+ export type TabPanelNode = NodeEnvelope & {
707
889
  type: "tab-panel";
708
890
  props: { label: string };
709
- style?: StyleOf;
710
- states?: StatesOf;
711
- devices?: DevicesOf;
712
- hiddenOn?: HiddenOnOf;
713
- classes?: ClassesOf;
714
- htmlId?: HtmlIdOf;
715
- attributes?: HtmlAttributeOf[];
716
- label?: string;
717
891
  children: LayoutNode[];
718
892
  };
719
893
 
720
- export type TabsNode = {
721
- id: IdOf;
894
+ export type TabsNode = NodeEnvelope & {
722
895
  type: "tabs";
723
896
  props: { href?: string; newTab?: boolean };
724
- style?: StyleOf;
725
- states?: StatesOf;
726
- devices?: DevicesOf;
727
- hiddenOn?: HiddenOnOf;
728
- classes?: ClassesOf;
729
- htmlId?: HtmlIdOf;
730
- attributes?: HtmlAttributeOf[];
731
- label?: string;
732
897
  children: LayoutNode[];
733
898
  };
734
899
 
735
- export type FormNode = {
736
- id: IdOf;
900
+ export type FormNode = NodeEnvelope & {
737
901
  type: "form";
738
902
  props: { formId: string };
739
- style?: StyleOf;
740
- states?: StatesOf;
741
- devices?: DevicesOf;
742
- hiddenOn?: HiddenOnOf;
743
- classes?: ClassesOf;
744
- htmlId?: HtmlIdOf;
745
- attributes?: HtmlAttributeOf[];
746
- label?: string;
747
903
  children: LayoutNode[];
748
904
  };
749
905
 
750
- export type LoopNode = {
751
- id: IdOf;
906
+ export type LoopNode = NodeEnvelope & {
752
907
  type: "loop";
753
- props: { itemPartId?: string; perPage?: number };
754
- style?: StyleOf;
755
- states?: StatesOf;
756
- devices?: DevicesOf;
757
- hiddenOn?: HiddenOnOf;
758
- classes?: ClassesOf;
759
- htmlId?: HtmlIdOf;
760
- attributes?: HtmlAttributeOf[];
761
- label?: string;
908
+ props: {
909
+ itemPartId?: string;
910
+ perPage?: number;
911
+ collection?: string;
912
+ limit?: number;
913
+ order?: (typeof LOOP_ORDERS)[number];
914
+ display?: (typeof LOOP_DISPLAYS)[number];
915
+ columns?: number;
916
+ };
762
917
  children: LayoutNode[];
763
918
  };
764
919
 
765
- export type SectionNode = {
766
- id: IdOf;
920
+ export type LoopEmptyNode = NodeEnvelope & {
921
+ type: "loop-empty";
922
+ props: Record<string, never>;
923
+ children: LayoutNode[];
924
+ };
925
+
926
+ export type SectionNode = NodeEnvelope & {
767
927
  type: "section";
768
928
  props: { partId?: string };
769
- style?: StyleOf;
770
- states?: StatesOf;
771
- devices?: DevicesOf;
772
- hiddenOn?: HiddenOnOf;
773
- classes?: ClassesOf;
774
- htmlId?: HtmlIdOf;
775
- attributes?: HtmlAttributeOf[];
776
- label?: string;
777
929
  children: LayoutNode[];
778
930
  };
779
931
 
780
- export type AccordionNode = {
781
- id: IdOf;
932
+ export type AccordionNode = NodeEnvelope & {
782
933
  type: "accordion";
783
934
  props: Record<string, never>;
784
- style?: StyleOf;
785
- states?: StatesOf;
786
- devices?: DevicesOf;
787
- hiddenOn?: HiddenOnOf;
788
- classes?: ClassesOf;
789
- htmlId?: HtmlIdOf;
790
- attributes?: HtmlAttributeOf[];
791
- label?: string;
792
935
  children: LayoutNode[];
793
936
  };
794
937
 
795
- export type MenuNode = {
796
- id: IdOf;
938
+ export type MenuNode = NodeEnvelope & {
797
939
  type: "menu";
798
940
  props: { direction: "row" | "column"; label?: string };
799
- style?: StyleOf;
800
- states?: StatesOf;
801
- devices?: DevicesOf;
802
- hiddenOn?: HiddenOnOf;
803
- classes?: ClassesOf;
804
- htmlId?: HtmlIdOf;
805
- attributes?: HtmlAttributeOf[];
806
- label?: string;
807
941
  children: LayoutNode[];
808
942
  };
809
943
 
810
- export type MenuItemNode = {
811
- id: IdOf;
944
+ export type MenuItemNode = NodeEnvelope & {
812
945
  type: "menu-item";
813
946
  props: { text: string; href?: string; newTab?: boolean; wide?: boolean };
814
- style?: StyleOf;
815
- states?: StatesOf;
816
- devices?: DevicesOf;
817
- hiddenOn?: HiddenOnOf;
818
- classes?: ClassesOf;
819
- htmlId?: HtmlIdOf;
820
- attributes?: HtmlAttributeOf[];
821
- label?: string;
822
947
  children: LayoutNode[];
823
948
  };
824
949
 
825
- export type AccordionItemNode = {
826
- id: IdOf;
950
+ export type AccordionItemNode = NodeEnvelope & {
827
951
  type: "accordion-item";
828
952
  props: { summary: string; open?: boolean };
829
- style?: StyleOf;
830
- states?: StatesOf;
831
- devices?: DevicesOf;
832
- hiddenOn?: HiddenOnOf;
833
- classes?: ClassesOf;
834
- htmlId?: HtmlIdOf;
835
- attributes?: HtmlAttributeOf[];
836
- label?: string;
837
953
  children: LayoutNode[];
838
954
  };
839
955
 
@@ -848,8 +964,10 @@ export type LayoutNode =
848
964
  | TabPanelNode
849
965
  | FormNode
850
966
  | LoopNode
967
+ | LoopEmptyNode
851
968
  | SectionNode
852
969
  | HeadingNode
970
+ | TocNode
853
971
  | SpacerNode
854
972
  | DividerNode
855
973
  | TextNode
@@ -954,6 +1072,7 @@ export const isLayoutParentNode = (
954
1072
  | GridNode
955
1073
  | TabPanelNode
956
1074
  | SectionNode
1075
+ | LoopEmptyNode
957
1076
  | AccordionItemNode
958
1077
  | MenuItemNode =>
959
1078
  node.type === "container" ||
@@ -963,6 +1082,7 @@ export const isLayoutParentNode = (
963
1082
  node.type === "grid" ||
964
1083
  node.type === "tab-panel" ||
965
1084
  node.type === "section" ||
1085
+ node.type === "loop-empty" ||
966
1086
  node.type === "accordion-item" ||
967
1087
  node.type === "menu-item";
968
1088
 
@@ -977,6 +1097,7 @@ export const isParentNode = (
977
1097
  | GridNode
978
1098
  | FormNode
979
1099
  | LoopNode
1100
+ | LoopEmptyNode
980
1101
  | SectionNode
981
1102
  | TabsNode
982
1103
  | TabPanelNode
@@ -991,6 +1112,7 @@ export const isParentNode = (
991
1112
  node.type === "grid" ||
992
1113
  node.type === "form" ||
993
1114
  node.type === "loop" ||
1115
+ node.type === "loop-empty" ||
994
1116
  node.type === "section" ||
995
1117
  node.type === "tabs" ||
996
1118
  node.type === "tab-panel" ||