@perkyzz/emvb 0.2.0 → 0.3.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 (80) hide show
  1. package/README.md +2 -2
  2. package/package.json +2 -2
  3. package/src/admin/editor/A11yCopilot.tsx +126 -0
  4. package/src/admin/editor/CommandPalette.tsx +118 -0
  5. package/src/admin/editor/Editor.tsx +274 -12
  6. package/src/admin/editor/EditorOverlay.tsx +6 -0
  7. package/src/admin/editor/PerfMeter.tsx +121 -0
  8. package/src/admin/editor/ShareLink.tsx +164 -0
  9. package/src/admin/editor/Timeline.tsx +274 -0
  10. package/src/admin/editor/TopBar.tsx +4 -0
  11. package/src/admin/editor/canvas/CanvasFrame.tsx +12 -3
  12. package/src/admin/editor/canvas/SelectionOverlay.tsx +1 -1
  13. package/src/admin/editor/collection-previews.ts +91 -0
  14. package/src/admin/editor/editor-css.ts +5 -3
  15. package/src/admin/editor/feature-css.ts +105 -0
  16. package/src/admin/editor/host.ts +2 -0
  17. package/src/admin/editor/live-data.tsx +71 -0
  18. package/src/admin/editor/palette-items.ts +105 -0
  19. package/src/admin/editor/palette.ts +67 -0
  20. package/src/admin/editor/panels/AddPanel.tsx +47 -2
  21. package/src/admin/editor/panels/ClassesSection.tsx +5 -1
  22. package/src/admin/editor/panels/ElementPanel.tsx +34 -3
  23. package/src/admin/editor/panels/LayersPanel.tsx +38 -1
  24. package/src/admin/editor/panels/LeftPanel.tsx +4 -1
  25. package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
  26. package/src/admin/editor/panels/SiteStylesDrawer.tsx +2 -0
  27. package/src/admin/editor/panels/TokenScales.tsx +168 -0
  28. package/src/admin/editor/panels/VariableSection.tsx +9 -4
  29. package/src/admin/editor/panels/settings/AudienceEditor.tsx +215 -0
  30. package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
  31. package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
  32. package/src/admin/editor/panels/settings/EffectsControls.tsx +4 -2
  33. package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
  34. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  35. package/src/admin/editor/panels/settings/StyleRow.tsx +12 -0
  36. package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
  37. package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
  38. package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
  39. package/src/admin/editor/panels/settings/length-units.ts +1 -1
  40. package/src/admin/editor/panels/settings/style-sections.ts +2 -1
  41. package/src/admin/editor/shortcuts.ts +2 -1
  42. package/src/admin/editor/useEditorShortcuts.ts +8 -0
  43. package/src/admin/editor/useNodeActions.ts +38 -15
  44. package/src/admin/ui.ts +4 -4
  45. package/src/astro/request-data.ts +97 -0
  46. package/src/astro/resolve-theme.ts +39 -9
  47. package/src/astro/resolve.ts +8 -2
  48. package/src/astro/theme-context.ts +14 -2
  49. package/src/astro/theme-posts.ts +51 -1
  50. package/src/astro/visitor.ts +142 -0
  51. package/src/constants.ts +1 -1
  52. package/src/core/a11y/audit.ts +282 -0
  53. package/src/core/arrange.ts +91 -0
  54. package/src/core/audience/rules.ts +104 -0
  55. package/src/core/audience/variants.ts +51 -0
  56. package/src/core/css/generate.ts +20 -2
  57. package/src/core/css/trace.ts +169 -0
  58. package/src/core/data/bindings.ts +257 -0
  59. package/src/core/design/tokens.ts +127 -0
  60. package/src/core/elements/dynamic-elements.ts +87 -2
  61. package/src/core/elements/index.ts +2 -0
  62. package/src/core/history/diff.ts +152 -0
  63. package/src/core/index.ts +111 -0
  64. package/src/core/migrate/index.ts +4 -1
  65. package/src/core/nesting.ts +1 -0
  66. package/src/core/perf/meter.ts +160 -0
  67. package/src/core/perf/scripts.ts +58 -0
  68. package/src/core/recipes/index.ts +433 -0
  69. package/src/core/render/index.ts +51 -4
  70. package/src/core/render/loop.ts +54 -7
  71. package/src/core/render/pagination.ts +9 -1
  72. package/src/core/sanitize/css.ts +39 -3
  73. package/src/core/sanitize/motion.ts +129 -0
  74. package/src/core/schema/design.ts +25 -2
  75. package/src/core/schema/layout.ts +168 -18
  76. package/src/core/schema/motion.ts +14 -0
  77. package/src/core/schema/style.ts +48 -3
  78. package/src/core/share/link.ts +147 -0
  79. package/src/core/theme/dynamic.ts +49 -0
  80. package/src/core/theme/pagination.ts +56 -0
@@ -1,6 +1,6 @@
1
1
  import type { PaginationNode } from "../schema/layout.ts";
2
2
  import type { ThemeDynamicData } from "../theme/dynamic.ts";
3
- import { paginationItems, type ArchivePagination } from "../theme/pagination.ts";
3
+ import { pageCountText, paginationItems, type ArchivePagination } from "../theme/pagination.ts";
4
4
  import type { VNode } from "./vnode.ts";
5
5
 
6
6
  /** What the editor canvas shows: page 2 of several, links going nowhere (W-222). */
@@ -72,5 +72,13 @@ export function renderPagination(
72
72
  };
73
73
  }
74
74
  });
75
+ if (node.props.showCount) {
76
+ // W-309: "Page N of M", or "Page N" while the host has no total.
77
+ children.unshift({
78
+ tag: "span",
79
+ attrs: { class: "emvb-pagination-count" },
80
+ children: [pageCountText(data, node.props.countText)],
81
+ });
82
+ }
75
83
  return { tag: "nav", attrs: { ...attrs, "aria-label": "Pagination" }, children };
76
84
  }
@@ -1,6 +1,7 @@
1
1
  import { STYLE_STATES, type StyleStateName } from "../schema/state-names.ts";
2
2
  import type { StyleProps } from "../schema/style.ts";
3
3
  import { sanitizeMediaUrl } from "./media-url.ts";
4
+ import { motionDeclarations, withMotion } from "./motion.ts";
4
5
 
5
6
  const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
6
7
  const VAR_ID = /^[a-z0-9-]{1,40}$/;
@@ -645,6 +646,8 @@ const PROPERTY_MAP: {
645
646
  cursor: { css: "cursor", toValue: keyword(CURSOR) },
646
647
  transition: { css: "transition", toValue: cssTransition },
647
648
  entrance: { css: "animation", toValue: cssEntrance },
649
+ // W-319: written by `motionDeclarations` in `styleDeclarations`; this entry only names it.
650
+ scrollMotion: { css: "animation", toValue: () => undefined },
648
651
  iconRotate: { css: "--emvb-icon-rotate", toValue: cssIconRotate },
649
652
  iconFlip: { css: "--emvb-icon-flip", toValue: cssIconFlip },
650
653
  iconScale: { css: "scale", toValue: cssIconScale },
@@ -677,8 +680,15 @@ export function styleDeclarations(style: unknown): {
677
680
  const rejected: string[] = [];
678
681
  if (typeof style !== "object" || style === null) return { declarations, rejected };
679
682
  const record = style as Record<string, unknown>;
683
+ let motion: Declaration[] = [];
680
684
  for (const [key, raw] of shorthandsFirst(record)) {
681
685
  if (BACKGROUND_KEYS.has(key)) continue;
686
+ if (key === "scrollMotion") {
687
+ const found = motionDeclarations(raw);
688
+ if (found && found.every((d) => isSafeCssValue(d.value))) motion = found;
689
+ else rejected.push(key);
690
+ continue;
691
+ }
682
692
  const entry = Object.hasOwn(PROPERTY_MAP, key)
683
693
  ? PROPERTY_MAP[key as keyof StyleProps]
684
694
  : undefined;
@@ -704,15 +714,20 @@ export function styleDeclarations(style: unknown): {
704
714
  const background = composeBackground(record);
705
715
  declarations.push(...background.declarations);
706
716
  rejected.push(...background.rejected);
707
- return { declarations, rejected };
717
+ return { declarations: withMotion(declarations, motion), rejected };
708
718
  }
709
719
 
710
720
  /** Normal only (W-089, W-237): a state's `transition` and `iconAnimation` are dropped and reported. */
711
- const NORMAL_ONLY = ["transition", "iconAnimation"] as const;
721
+ const NORMAL_ONLY = ["transition", "iconAnimation", "scrollMotion"] as const;
712
722
  const withoutTransition = (style: unknown): unknown => {
713
723
  if (typeof style !== "object" || style === null) return style;
714
724
  if (!NORMAL_ONLY.some((key) => key in style)) return style;
715
- const { transition: _drop, iconAnimation: _loop, ...rest } = style as Record<string, unknown>;
725
+ const {
726
+ transition: _drop,
727
+ iconAnimation: _loop,
728
+ scrollMotion: _scroll,
729
+ ...rest
730
+ } = style as Record<string, unknown>;
716
731
  return rest;
717
732
  };
718
733
 
@@ -760,7 +775,28 @@ const BACKGROUND_LAYER_KEYS = [
760
775
  * whole `background-image` stack for that device, so the layers it inherits (the desktop image or
761
776
  * gradient) are filled in from `inherited` here. Otherwise they vanish on that device.
762
777
  */
778
+ /** Both write `animation` (W-319), so one set alone would drop the other it inherits. */
779
+ const ANIMATION_KEYS = ["entrance", "scrollMotion"] as const;
780
+
781
+ /**
782
+ * A style that sets an entrance or scroll motion keeps the other one it inherits from a wider
783
+ * device or its classes (W-319): both are one `animation` list in CSS.
784
+ */
785
+ export function withInheritedAnimation(style: unknown, inherited: unknown): unknown {
786
+ if (!isRecord(style) || !isRecord(inherited)) return style;
787
+ if (!ANIMATION_KEYS.some((key) => style[key] !== undefined)) return style;
788
+ const next: Record<string, unknown> = { ...style };
789
+ for (const key of ANIMATION_KEYS) {
790
+ if (next[key] === undefined && inherited[key] !== undefined) next[key] = inherited[key];
791
+ }
792
+ return next;
793
+ }
794
+
763
795
  export function withInheritedLayers(device: unknown, inherited: unknown): unknown {
796
+ return withInheritedBackground(withInheritedAnimation(device, inherited), inherited);
797
+ }
798
+
799
+ function withInheritedBackground(device: unknown, inherited: unknown): unknown {
764
800
  if (!isRecord(device) || !isRecord(inherited)) return device;
765
801
  if (!BACKGROUND_LAYER_KEYS.some((key) => device[key] !== undefined)) return device;
766
802
  const next: Record<string, unknown> = { ...device };
@@ -0,0 +1,129 @@
1
+ import { MOTION_EFFECTS, MOTION_LIMITS, type MotionEffect } from "../schema/motion.ts";
2
+ import type { Declaration } from "./css.ts";
3
+
4
+ type Effect = { type: MotionEffect; from: number; to: number };
5
+ type Range = "enter" | "cross" | "exit" | "page";
6
+
7
+ const RANGES: Record<Range, string> = {
8
+ enter: "entry 0% entry 100%",
9
+ cross: "cover 0% cover 100%",
10
+ exit: "exit 0% exit 100%",
11
+ page: "normal",
12
+ };
13
+
14
+ /** One keyframes per CSS property, so an unused effect never pins that property. */
15
+ const KEYFRAMES: Record<string, string> = {
16
+ mo: "opacity",
17
+ mt: "translate",
18
+ ms: "scale",
19
+ mr: "rotate",
20
+ mb: "filter",
21
+ };
22
+
23
+ /**
24
+ * The scroll motion keyframes (W-319). They exist only where scroll-driven animations do and the
25
+ * visitor has not asked for reduced motion, so anywhere else `emvb-m*` names nothing and the
26
+ * element stays still in its normal place.
27
+ */
28
+ export const MOTION_KEYFRAMES = `@media (prefers-reduced-motion: no-preference){@supports (animation-timeline: view()){${Object.entries(
29
+ KEYFRAMES,
30
+ )
31
+ .map(
32
+ ([name, prop]) =>
33
+ `@keyframes emvb-${name}{from{${prop}:var(--emvb-${name}0)}to{${prop}:var(--emvb-${name}1)}}`,
34
+ )
35
+ .join("")}}}`;
36
+
37
+ const isEffect = (value: unknown): value is Effect => {
38
+ if (typeof value !== "object" || value === null) return false;
39
+ const { type, from, to } = value as Record<string, unknown>;
40
+ if (typeof type !== "string" || !(MOTION_EFFECTS as readonly string[]).includes(type)) {
41
+ return false;
42
+ }
43
+ const [min, max] = MOTION_LIMITS[type as MotionEffect];
44
+ return [from, to].every(
45
+ (n) => typeof n === "number" && Number.isFinite(n) && n >= min && n <= max,
46
+ );
47
+ };
48
+
49
+ const num = (n: number) => String(Math.round(n * 100) / 100);
50
+
51
+ /**
52
+ * Declarations for a `scrollMotion` value (W-319): `animation` (one per animated property), its
53
+ * timeline and range, and the `--emvb-m*` values the keyframes read. Undefined for a bad value;
54
+ * `{ type: "none" }` is `animation: none`.
55
+ */
56
+ export function motionDeclarations(value: unknown): Declaration[] | undefined {
57
+ if (typeof value !== "object" || value === null) return undefined;
58
+ const record = value as Record<string, unknown>;
59
+ if (record["type"] === "none" && Object.keys(record).length === 1) {
60
+ return [{ property: "animation", value: "none" }];
61
+ }
62
+ const { effects, range } = record as { effects?: unknown; range?: unknown };
63
+ if (typeof range !== "string" || !Object.hasOwn(RANGES, range)) return undefined;
64
+ if (!Array.isArray(effects) || effects.length === 0 || effects.length > MOTION_EFFECTS.length) {
65
+ return undefined;
66
+ }
67
+ if (!effects.every(isEffect)) return undefined;
68
+ const by = new Map(effects.map((e) => [e.type, e]));
69
+ if (by.size !== effects.length) return undefined;
70
+ const frames: [string, string, string][] = [];
71
+ const fade = by.get("fade");
72
+ if (fade) frames.push(["mo", num(fade.from / 100), num(fade.to / 100)]);
73
+ const x = by.get("move-x");
74
+ const y = by.get("move-y");
75
+ if (x || y) {
76
+ frames.push([
77
+ "mt",
78
+ `${num(x?.from ?? 0)}px ${num(y?.from ?? 0)}px`,
79
+ `${num(x?.to ?? 0)}px ${num(y?.to ?? 0)}px`,
80
+ ]);
81
+ }
82
+ const scale = by.get("scale");
83
+ if (scale) frames.push(["ms", num(scale.from / 100), num(scale.to / 100)]);
84
+ const rotate = by.get("rotate");
85
+ if (rotate) frames.push(["mr", `${num(rotate.from)}deg`, `${num(rotate.to)}deg`]);
86
+ const blur = by.get("blur");
87
+ if (blur) frames.push(["mb", `blur(${num(blur.from)}px)`, `blur(${num(blur.to)}px)`]);
88
+ const timeline = range === "page" ? "scroll(root)" : "view()";
89
+ const rangeValue = RANGES[range as Range];
90
+ return [
91
+ { property: "animation", value: frames.map(([n]) => `emvb-${n} linear both`).join(", ") },
92
+ { property: "animation-timeline", value: frames.map(() => timeline).join(", ") },
93
+ { property: "animation-range", value: frames.map(() => rangeValue).join(", ") },
94
+ ...frames.flatMap(([n, from, to]) => [
95
+ { property: `--emvb-${n}0`, value: from },
96
+ { property: `--emvb-${n}1`, value: to },
97
+ ]),
98
+ ];
99
+ }
100
+
101
+ /**
102
+ * Adds scroll motion to an element's declarations (W-319). An entrance and scroll motion share
103
+ * `animation`, so they are joined, entrance first, with matching timeline and range lists; motion
104
+ * `none` leaves an entrance on the same style alone.
105
+ */
106
+ export function withMotion(declarations: Declaration[], motion: Declaration[]): Declaration[] {
107
+ const entrance = declarations.find((d) => d.property === "animation");
108
+ if (!entrance) return [...declarations, ...motion];
109
+ const [animation, timeline, range, ...vars] = motion;
110
+ if (!animation || animation.value === "none" || !timeline || !range) return declarations;
111
+ const entranceTimeline = declarations.find((d) => d.property === "animation-timeline");
112
+ const entranceRange = declarations.find((d) => d.property === "animation-range");
113
+ const rest = declarations.filter(
114
+ (d) => d !== entrance && d !== entranceTimeline && d !== entranceRange,
115
+ );
116
+ return [
117
+ ...rest,
118
+ { property: "animation", value: `${entrance.value}, ${animation.value}` },
119
+ {
120
+ property: "animation-timeline",
121
+ value: `${entranceTimeline?.value ?? "auto"}, ${timeline.value}`,
122
+ },
123
+ {
124
+ property: "animation-range",
125
+ value: `${entranceRange?.value ?? "normal"}, ${range.value}`,
126
+ },
127
+ ...vars,
128
+ ];
129
+ }
@@ -1,8 +1,11 @@
1
1
  import { z } from "zod";
2
2
  import { DeviceStyles, HiddenOn, StyleProps, StyleStates } from "./style.ts";
3
3
 
4
- /** 12 since W-160: class gradients use the same stops as layouts. v11 `{ angle, from, to }` upgrades on read. */
5
- export const DESIGN_SCHEMA_VERSION = 12;
4
+ /**
5
+ * 13 since W-307, in step with layouts (the W-307 batch only adds optional fields).
6
+ * 12 since W-160: class gradients use the same stops as layouts. v11 `{ angle, from, to }` upgrades on read.
7
+ */
8
+ export const DESIGN_SCHEMA_VERSION = 13;
6
9
 
7
10
  /** Tags a site can give a starting style. Classes and local styles still win. */
8
11
  export const DEFAULT_STYLE_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "a", "button"] as const;
@@ -31,6 +34,15 @@ export const FontVariable = z.strictObject({
31
34
  value: z.string().min(1).max(200),
32
35
  });
33
36
 
37
+ /**
38
+ * A fluid size (W-316): `min` px on small screens growing to `max` px on large ones, emitted as
39
+ * `clamp()` between the site's fluid range. `value` stays as the fixed fallback the editor shows.
40
+ */
41
+ const FluidSize = z.strictObject({
42
+ min: z.number().finite().min(0).max(1000),
43
+ max: z.number().finite().min(0).max(1000),
44
+ });
45
+
34
46
  export const LengthVariable = z.strictObject({
35
47
  id: VariableId,
36
48
  name: z.string().min(1).max(60),
@@ -38,8 +50,18 @@ export const LengthVariable = z.strictObject({
38
50
  value: z.number().finite().min(0).max(10_000),
39
51
  unit: z.enum(["px", "rem", "em", "%"]),
40
52
  }),
53
+ fluid: FluidSize.optional(),
41
54
  });
42
55
 
56
+ /** Screen widths fluid sizes grow between (W-316). Unset = 360 to 1280 px. */
57
+ const FluidRange = z
58
+ .strictObject({
59
+ minWidth: z.number().int().min(240).max(1200),
60
+ maxWidth: z.number().int().min(480).max(3840),
61
+ })
62
+ .refine((range) => range.minWidth < range.maxWidth, "The small screen must be narrower");
63
+ export type FluidRange = z.infer<typeof FluidRange>;
64
+
43
65
  /** Shared style class (R-021 / W-030). CSS selector is always `.emvb-k-<id>`. */
44
66
  const StyleClass = z.strictObject({
45
67
  id: VariableId,
@@ -60,6 +82,7 @@ export const DesignSystem = z.strictObject({
60
82
  spacings: z.array(LengthVariable).max(100).optional(),
61
83
  }),
62
84
  classes: z.array(StyleClass).max(100).optional(),
85
+ fluidRange: FluidRange.optional(),
63
86
  /**
64
87
  * Site text direction (W-230). Unset is left to right. Rendered as `dir` on every EmVB root
65
88
  * and returned to hosts for `<html dir>`. Layout uses logical properties, so styles flip.
@@ -3,11 +3,13 @@ import { MAX_TEXT_LENGTH } from "../limits.ts";
3
3
  import { DeviceStyles, HiddenOn, Length, StyleProps, StyleStates } from "./style.ts";
4
4
 
5
5
  /**
6
+ * 13 since W-307: optional `bind` on a node (live data bindings); W-308 collection Loops and the
7
+ * Loop's Empty state element. Every other value is unchanged.
6
8
  * 12 since W-160: gradient type, stop locations, and up to 10 stops. v11 gradients
7
9
  * (`{ angle, from, to }`) become a linear gradient on read.
8
10
  * 11 since W-156 and W-157 (D-045): the layout Section element and an editor-only node label.
9
11
  */
10
- export const LAYOUT_SCHEMA_VERSION = 12;
12
+ export const LAYOUT_SCHEMA_VERSION = 13;
11
13
 
12
14
  export const NodeId = z
13
15
  .string()
@@ -49,6 +51,82 @@ const HtmlAttribute = z.strictObject({
49
51
 
50
52
  const HtmlAttributes = z.array(HtmlAttribute).max(20);
51
53
 
54
+ /** Where a bound field reads its live value (W-307). */
55
+ export const BIND_SOURCES = ["post", "site", "param"] as const;
56
+ export type BindSource = (typeof BIND_SOURCES)[number];
57
+
58
+ /**
59
+ * A field bound to live data (W-307): a post field, a site setting or a URL parameter. The
60
+ * field's own value stays as the fallback when the source has nothing to show.
61
+ */
62
+ export const Binding = z.strictObject({
63
+ source: z.enum(BIND_SOURCES),
64
+ key: z
65
+ .string()
66
+ .regex(
67
+ /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/,
68
+ "Keys start with a letter: letters, digits, _, . or -, up to 64",
69
+ ),
70
+ /**
71
+ * A link or image bound to a URL parameter takes only same-site URLs (relative, or this site's
72
+ * origin) unless this is set (W-307). Anyone can craft such a link, so outside sites are opt-in.
73
+ */
74
+ outside: z.boolean().optional(),
75
+ });
76
+ export type Binding = z.infer<typeof Binding>;
77
+
78
+ /** Prop name → binding. Which props may be bound is checked against BINDABLE_FIELDS on render. */
79
+ const Bindings = z
80
+ .record(z.string().regex(/^[a-zA-Z]{1,32}$/), Binding)
81
+ .refine((value) => Object.keys(value).length <= 8, "At most 8 bound fields per element");
82
+
83
+ /** A/B test names (W-312): lowercase letters, digits and dashes, up to 32. */
84
+ export const AB_TEST_NAME = /^[a-z0-9][a-z0-9-]{0,31}$/;
85
+
86
+ /**
87
+ * One arm of an edge A/B test (W-312). Elements sharing a `test` are the variants; the host picks
88
+ * one arm per visitor on the server (a cookie keeps it), so there is no flicker and no script.
89
+ */
90
+ export const Variant = z.strictObject({
91
+ test: z.string().regex(AB_TEST_NAME, "Lowercase letters, digits and -, up to 32"),
92
+ arm: z.enum(["a", "b"]),
93
+ /** Share of visitors who see B, 1–99 %. Read from the test's B element. Unset = 50. */
94
+ split: z.number().int().min(1).max(99).optional(),
95
+ });
96
+ export type Variant = z.infer<typeof Variant>;
97
+
98
+ export const AUDIENCE_DEVICES = ["mobile", "tablet", "desktop"] as const;
99
+
100
+ /**
101
+ * Who sees an element (W-313): visitors from these countries, on these devices, new or
102
+ * returning, at these hours and days. Every rule set must match; `hide` flips it to "everyone
103
+ * except". Hosts evaluate it on the server; a rule the host can't read (no country header) does
104
+ * not match.
105
+ */
106
+ export const Audience = z.strictObject({
107
+ countries: z
108
+ .array(z.string().regex(/^[A-Z]{2}$/, "Two-letter country codes, e.g. CA"))
109
+ .min(1)
110
+ .max(50)
111
+ .optional(),
112
+ devices: z.array(z.enum(AUDIENCE_DEVICES)).min(1).max(3).optional(),
113
+ visitor: z.enum(["new", "returning"]).optional(),
114
+ /** From hour `from` up to (not including) hour `to`, 0–24; wraps past midnight when to < from. */
115
+ hours: z
116
+ .strictObject({ from: z.number().int().min(0).max(23), to: z.number().int().min(0).max(24) })
117
+ .optional(),
118
+ /** Days of the week, 0 = Sunday. */
119
+ days: z.array(z.number().int().min(0).max(6)).min(1).max(7).optional(),
120
+ /** IANA time zone for hours and days, e.g. America/Toronto. Unset = UTC. */
121
+ timeZone: z
122
+ .string()
123
+ .regex(/^[A-Za-z][A-Za-z0-9_+-]*(\/[A-Za-z0-9_+-]+){0,2}$/)
124
+ .max(64)
125
+ .optional(),
126
+ hide: z.boolean().optional(),
127
+ });
128
+ export type Audience = z.infer<typeof Audience>;
129
+
52
130
  /** A box may be the link. A link inside a link is dropped at render time (W-111). */
53
131
  const BoxLink = {
54
132
  href: z.string().max(2000).optional(),
@@ -68,6 +146,9 @@ const nodeFields = <T extends string, P extends z.ZodType>(type: T, props: P) =>
68
146
  htmlId: HtmlId.optional(),
69
147
  attributes: HtmlAttributes.optional(),
70
148
  label: NodeLabel.optional(),
149
+ bind: Bindings.optional(),
150
+ variant: Variant.optional(),
151
+ audience: Audience.optional(),
71
152
  });
72
153
 
73
154
  const leafNode = <T extends string, P extends z.ZodType>(type: T, props: P) =>
@@ -403,15 +484,40 @@ export const PostLinkNode = leafNode(
403
484
  * When `itemPartId` is set, the host supplies that Loop Item layout in loopTemplates;
404
485
  * otherwise children are the inline item template.
405
486
  */
487
+ /** How a Loop lays out its items (W-308): one design, shown as a list, a grid or cards. */
488
+ export const LOOP_DISPLAYS = ["list", "grid", "cards"] as const;
489
+ /** Which entries a collection Loop shows first (W-308). */
490
+ export const LOOP_ORDERS = ["newest", "oldest", "title"] as const;
491
+
406
492
  export const LoopNode = parentNode(
407
493
  "loop",
408
494
  z.strictObject({
409
495
  itemPartId: z.string().max(128).optional(),
410
496
  /** Posts per archive page, 1–50 (W-221). Unset = 20. */
411
497
  perPage: z.number().int().min(1).max(50).optional(),
498
+ /**
499
+ * A collection to list on any page (W-308), e.g. `team`. Unset lists the archive's posts on
500
+ * an Archive part, as before.
501
+ */
502
+ collection: z
503
+ .string()
504
+ .regex(/^[a-z][a-z0-9_]{0,63}$/, "Use the collection's slug, e.g. team")
505
+ .optional(),
506
+ /** How many entries a collection Loop shows, 1–50. Unset = 6. */
507
+ limit: z.number().int().min(1).max(50).optional(),
508
+ order: z.enum(LOOP_ORDERS).optional(),
509
+ display: z.enum(LOOP_DISPLAYS).optional(),
510
+ /** Columns for grid and cards, 1–6 (one column on phones). Unset = 3. */
511
+ columns: z.number().int().min(1).max(6).optional(),
412
512
  }),
413
513
  );
414
514
 
515
+ /**
516
+ * What a Loop shows when it has no entries (W-308). Only inside a Loop; its children are designed
517
+ * like any box, and it is left out of the item template.
518
+ */
519
+ export const LoopEmptyNode = parentNode("loop-empty", z.strictObject({}));
520
+
415
521
  /**
416
522
  * Previous / page numbers / Next links for an archive (W-222). Renders only on an archive with
417
523
  * more than one page; the host supplies `ThemeDynamicData.pagination`.
@@ -421,6 +527,10 @@ export const PaginationNode = leafNode(
421
527
  z.strictObject({
422
528
  prevText: z.string().max(40).optional(),
423
529
  nextText: z.string().max(40).optional(),
530
+ /** Show "Page N of M" beside the links (W-309). */
531
+ showCount: z.boolean().optional(),
532
+ /** The count's text; `{page}` and `{total}` are filled in. Unset = "Page {page} of {total}". */
533
+ countText: z.string().max(60).optional(),
424
534
  }),
425
535
  );
426
536
 
@@ -464,6 +574,7 @@ export const KNOWN_ELEMENT_TYPES = [
464
574
  "post-date",
465
575
  "post-author",
466
576
  "loop",
577
+ "loop-empty",
467
578
  "pagination",
468
579
  "section",
469
580
  "div-block",
@@ -499,6 +610,9 @@ const UnknownNodeSchema = z.strictObject({
499
610
  htmlId: HtmlId.optional(),
500
611
  attributes: HtmlAttributes.optional(),
501
612
  label: NodeLabel.optional(),
613
+ bind: Bindings.optional(),
614
+ variant: Variant.optional(),
615
+ audience: Audience.optional(),
502
616
  get children(): z.ZodType<LayoutNode[] | undefined> {
503
617
  return z.array(LayoutNode).optional();
504
618
  },
@@ -539,6 +653,7 @@ const KnownLayoutNode = z.discriminatedUnion("type", [
539
653
  PostDateNode,
540
654
  PostAuthorNode,
541
655
  LoopNode,
656
+ LoopEmptyNode,
542
657
  PaginationNode,
543
658
  SectionNode,
544
659
  AccordionNode,
@@ -582,8 +697,15 @@ type HtmlIdOf = z.infer<typeof HtmlId>;
582
697
  type HtmlAttributeOf = z.infer<typeof HtmlAttribute>;
583
698
  type IdOf = z.infer<typeof NodeId>;
584
699
 
700
+ /** Fields every node may carry beyond its props and style (W-307 onward). */
701
+ export type NodeExtras = {
702
+ bind?: Record<string, Binding>;
703
+ variant?: Variant;
704
+ audience?: Audience;
705
+ };
706
+
585
707
  /** Manual recursive types so UnknownNode does not poison `z.infer` of the tree. */
586
- export type UnknownNode = {
708
+ export type UnknownNode = NodeExtras & {
587
709
  id: IdOf;
588
710
  type: string;
589
711
  props: Record<string, unknown>;
@@ -598,7 +720,7 @@ export type UnknownNode = {
598
720
  children?: LayoutNode[];
599
721
  };
600
722
 
601
- export type ContainerNode = {
723
+ export type ContainerNode = NodeExtras & {
602
724
  id: IdOf;
603
725
  type: "container";
604
726
  props: { tag?: (typeof CONTAINER_TAGS)[number]; href?: string; newTab?: boolean };
@@ -613,7 +735,7 @@ export type ContainerNode = {
613
735
  children: LayoutNode[];
614
736
  };
615
737
 
616
- export type DivBlockNode = {
738
+ export type DivBlockNode = NodeExtras & {
617
739
  id: IdOf;
618
740
  type: "div-block";
619
741
  props: { href?: string; newTab?: boolean };
@@ -628,7 +750,7 @@ export type DivBlockNode = {
628
750
  children: LayoutNode[];
629
751
  };
630
752
 
631
- export type LayoutSectionNode = {
753
+ export type LayoutSectionNode = NodeExtras & {
632
754
  id: IdOf;
633
755
  type: "layout-section";
634
756
  props: {
@@ -647,7 +769,7 @@ export type LayoutSectionNode = {
647
769
  children: LayoutNode[];
648
770
  };
649
771
 
650
- export type GridNode = {
772
+ export type GridNode = NodeExtras & {
651
773
  id: IdOf;
652
774
  type: "grid";
653
775
  props: {
@@ -668,7 +790,7 @@ export type GridNode = {
668
790
  children: LayoutNode[];
669
791
  };
670
792
 
671
- export type FlexboxNode = {
793
+ export type FlexboxNode = NodeExtras & {
672
794
  id: IdOf;
673
795
  type: "flexbox";
674
796
  props: { href?: string; newTab?: boolean };
@@ -683,7 +805,7 @@ export type FlexboxNode = {
683
805
  children: LayoutNode[];
684
806
  };
685
807
 
686
- export type SvgNode = {
808
+ export type SvgNode = NodeExtras & {
687
809
  id: IdOf;
688
810
  type: "svg";
689
811
  props: {
@@ -702,7 +824,7 @@ export type SvgNode = {
702
824
  label?: string;
703
825
  };
704
826
 
705
- export type TabPanelNode = {
827
+ export type TabPanelNode = NodeExtras & {
706
828
  id: IdOf;
707
829
  type: "tab-panel";
708
830
  props: { label: string };
@@ -717,7 +839,7 @@ export type TabPanelNode = {
717
839
  children: LayoutNode[];
718
840
  };
719
841
 
720
- export type TabsNode = {
842
+ export type TabsNode = NodeExtras & {
721
843
  id: IdOf;
722
844
  type: "tabs";
723
845
  props: { href?: string; newTab?: boolean };
@@ -732,7 +854,7 @@ export type TabsNode = {
732
854
  children: LayoutNode[];
733
855
  };
734
856
 
735
- export type FormNode = {
857
+ export type FormNode = NodeExtras & {
736
858
  id: IdOf;
737
859
  type: "form";
738
860
  props: { formId: string };
@@ -747,10 +869,33 @@ export type FormNode = {
747
869
  children: LayoutNode[];
748
870
  };
749
871
 
750
- export type LoopNode = {
872
+ export type LoopNode = NodeExtras & {
751
873
  id: IdOf;
752
874
  type: "loop";
753
- props: { itemPartId?: string; perPage?: number };
875
+ props: {
876
+ itemPartId?: string;
877
+ perPage?: number;
878
+ collection?: string;
879
+ limit?: number;
880
+ order?: (typeof LOOP_ORDERS)[number];
881
+ display?: (typeof LOOP_DISPLAYS)[number];
882
+ columns?: number;
883
+ };
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
+ children: LayoutNode[];
893
+ };
894
+
895
+ export type LoopEmptyNode = NodeExtras & {
896
+ id: IdOf;
897
+ type: "loop-empty";
898
+ props: Record<string, never>;
754
899
  style?: StyleOf;
755
900
  states?: StatesOf;
756
901
  devices?: DevicesOf;
@@ -762,7 +907,7 @@ export type LoopNode = {
762
907
  children: LayoutNode[];
763
908
  };
764
909
 
765
- export type SectionNode = {
910
+ export type SectionNode = NodeExtras & {
766
911
  id: IdOf;
767
912
  type: "section";
768
913
  props: { partId?: string };
@@ -777,7 +922,7 @@ export type SectionNode = {
777
922
  children: LayoutNode[];
778
923
  };
779
924
 
780
- export type AccordionNode = {
925
+ export type AccordionNode = NodeExtras & {
781
926
  id: IdOf;
782
927
  type: "accordion";
783
928
  props: Record<string, never>;
@@ -792,7 +937,7 @@ export type AccordionNode = {
792
937
  children: LayoutNode[];
793
938
  };
794
939
 
795
- export type MenuNode = {
940
+ export type MenuNode = NodeExtras & {
796
941
  id: IdOf;
797
942
  type: "menu";
798
943
  props: { direction: "row" | "column"; label?: string };
@@ -807,7 +952,7 @@ export type MenuNode = {
807
952
  children: LayoutNode[];
808
953
  };
809
954
 
810
- export type MenuItemNode = {
955
+ export type MenuItemNode = NodeExtras & {
811
956
  id: IdOf;
812
957
  type: "menu-item";
813
958
  props: { text: string; href?: string; newTab?: boolean; wide?: boolean };
@@ -822,7 +967,7 @@ export type MenuItemNode = {
822
967
  children: LayoutNode[];
823
968
  };
824
969
 
825
- export type AccordionItemNode = {
970
+ export type AccordionItemNode = NodeExtras & {
826
971
  id: IdOf;
827
972
  type: "accordion-item";
828
973
  props: { summary: string; open?: boolean };
@@ -848,6 +993,7 @@ export type LayoutNode =
848
993
  | TabPanelNode
849
994
  | FormNode
850
995
  | LoopNode
996
+ | LoopEmptyNode
851
997
  | SectionNode
852
998
  | HeadingNode
853
999
  | SpacerNode
@@ -954,6 +1100,7 @@ export const isLayoutParentNode = (
954
1100
  | GridNode
955
1101
  | TabPanelNode
956
1102
  | SectionNode
1103
+ | LoopEmptyNode
957
1104
  | AccordionItemNode
958
1105
  | MenuItemNode =>
959
1106
  node.type === "container" ||
@@ -963,6 +1110,7 @@ export const isLayoutParentNode = (
963
1110
  node.type === "grid" ||
964
1111
  node.type === "tab-panel" ||
965
1112
  node.type === "section" ||
1113
+ node.type === "loop-empty" ||
966
1114
  node.type === "accordion-item" ||
967
1115
  node.type === "menu-item";
968
1116
 
@@ -977,6 +1125,7 @@ export const isParentNode = (
977
1125
  | GridNode
978
1126
  | FormNode
979
1127
  | LoopNode
1128
+ | LoopEmptyNode
980
1129
  | SectionNode
981
1130
  | TabsNode
982
1131
  | TabPanelNode
@@ -991,6 +1140,7 @@ export const isParentNode = (
991
1140
  node.type === "grid" ||
992
1141
  node.type === "form" ||
993
1142
  node.type === "loop" ||
1143
+ node.type === "loop-empty" ||
994
1144
  node.type === "section" ||
995
1145
  node.type === "tabs" ||
996
1146
  node.type === "tab-panel" ||