@perkyzz/emvb 0.2.1 → 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 (78) hide show
  1. package/package.json +1 -1
  2. package/src/admin/editor/A11yCopilot.tsx +126 -0
  3. package/src/admin/editor/CommandPalette.tsx +118 -0
  4. package/src/admin/editor/Editor.tsx +274 -12
  5. package/src/admin/editor/EditorOverlay.tsx +6 -0
  6. package/src/admin/editor/PerfMeter.tsx +121 -0
  7. package/src/admin/editor/ShareLink.tsx +164 -0
  8. package/src/admin/editor/Timeline.tsx +274 -0
  9. package/src/admin/editor/TopBar.tsx +4 -0
  10. package/src/admin/editor/canvas/CanvasFrame.tsx +12 -3
  11. package/src/admin/editor/canvas/SelectionOverlay.tsx +1 -1
  12. package/src/admin/editor/collection-previews.ts +91 -0
  13. package/src/admin/editor/editor-css.ts +5 -3
  14. package/src/admin/editor/feature-css.ts +105 -0
  15. package/src/admin/editor/host.ts +2 -0
  16. package/src/admin/editor/live-data.tsx +71 -0
  17. package/src/admin/editor/palette-items.ts +105 -0
  18. package/src/admin/editor/palette.ts +67 -0
  19. package/src/admin/editor/panels/AddPanel.tsx +47 -2
  20. package/src/admin/editor/panels/ClassesSection.tsx +5 -1
  21. package/src/admin/editor/panels/ElementPanel.tsx +34 -3
  22. package/src/admin/editor/panels/LayersPanel.tsx +38 -1
  23. package/src/admin/editor/panels/LeftPanel.tsx +4 -1
  24. package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
  25. package/src/admin/editor/panels/SiteStylesDrawer.tsx +2 -0
  26. package/src/admin/editor/panels/TokenScales.tsx +168 -0
  27. package/src/admin/editor/panels/VariableSection.tsx +9 -4
  28. package/src/admin/editor/panels/settings/AudienceEditor.tsx +215 -0
  29. package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
  30. package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
  31. package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
  32. package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
  33. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  34. package/src/admin/editor/panels/settings/StyleRow.tsx +12 -0
  35. package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
  36. package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
  37. package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
  38. package/src/admin/editor/panels/settings/length-units.ts +1 -1
  39. package/src/admin/editor/panels/settings/style-sections.ts +2 -1
  40. package/src/admin/editor/shortcuts.ts +2 -1
  41. package/src/admin/editor/useEditorShortcuts.ts +8 -0
  42. package/src/admin/editor/useNodeActions.ts +38 -15
  43. package/src/admin/ui.ts +4 -4
  44. package/src/astro/request-data.ts +97 -0
  45. package/src/astro/resolve-theme.ts +35 -5
  46. package/src/astro/resolve.ts +8 -2
  47. package/src/astro/theme-posts.ts +32 -0
  48. package/src/astro/visitor.ts +142 -0
  49. package/src/constants.ts +1 -1
  50. package/src/core/a11y/audit.ts +282 -0
  51. package/src/core/arrange.ts +91 -0
  52. package/src/core/audience/rules.ts +104 -0
  53. package/src/core/audience/variants.ts +51 -0
  54. package/src/core/css/generate.ts +20 -2
  55. package/src/core/css/trace.ts +169 -0
  56. package/src/core/data/bindings.ts +257 -0
  57. package/src/core/design/tokens.ts +127 -0
  58. package/src/core/elements/dynamic-elements.ts +87 -2
  59. package/src/core/elements/index.ts +2 -0
  60. package/src/core/history/diff.ts +152 -0
  61. package/src/core/index.ts +111 -0
  62. package/src/core/migrate/index.ts +4 -1
  63. package/src/core/nesting.ts +1 -0
  64. package/src/core/perf/meter.ts +160 -0
  65. package/src/core/perf/scripts.ts +58 -0
  66. package/src/core/recipes/index.ts +433 -0
  67. package/src/core/render/index.ts +51 -4
  68. package/src/core/render/loop.ts +54 -7
  69. package/src/core/render/pagination.ts +9 -1
  70. package/src/core/sanitize/css.ts +39 -3
  71. package/src/core/sanitize/motion.ts +129 -0
  72. package/src/core/schema/design.ts +25 -2
  73. package/src/core/schema/layout.ts +168 -18
  74. package/src/core/schema/motion.ts +14 -0
  75. package/src/core/schema/style.ts +48 -3
  76. package/src/core/share/link.ts +147 -0
  77. package/src/core/theme/dynamic.ts +49 -0
  78. package/src/core/theme/pagination.ts +56 -0
@@ -0,0 +1,433 @@
1
+ import { contrastRatio } from "../a11y/audit.ts";
2
+ import type { DesignSystem } from "../schema/design.ts";
3
+ import type { Layout, LayoutNode } from "../schema/layout.ts";
4
+ import type { StyleProps } from "../schema/style.ts";
5
+ import { nodeChildren, newNodeId } from "../tree-ops.ts";
6
+
7
+ type Color = NonNullable<StyleProps["color"]>;
8
+ type Size = NonNullable<StyleProps["fontSize"]>;
9
+
10
+ /** What a recipe takes from Site styles (W-320); unset parts fall back to plain values. */
11
+ export type RecipeTokens = {
12
+ accent?: Color;
13
+ onAccent?: Color;
14
+ ink?: Color;
15
+ muted?: Color;
16
+ surface?: Color;
17
+ display: Size;
18
+ heading: Size;
19
+ subheading: Size;
20
+ body: Size;
21
+ small: Size;
22
+ sectionSpace: Size;
23
+ blockSpace: Size;
24
+ gap: Size;
25
+ tight: Size;
26
+ buttonClass?: string;
27
+ cardClass?: string;
28
+ /** Plain words for what came from the site, for the Add panel. */
29
+ used: string[];
30
+ };
31
+
32
+ const px = (value: number): Size => ({ value, unit: "px" });
33
+
34
+ type Named = { id: string; name: string };
35
+ const words = (v: Named) => `${v.id} ${v.name}`.toLowerCase();
36
+
37
+ /** The first variable whose id or name matches a pattern, trying patterns in order. */
38
+ function pick<T extends Named>(
39
+ list: readonly T[] | undefined,
40
+ ...patterns: RegExp[]
41
+ ): T | undefined {
42
+ for (const pattern of patterns) {
43
+ const found = list?.find((v) => pattern.test(words(v)));
44
+ if (found) return found;
45
+ }
46
+ return undefined;
47
+ }
48
+
49
+ const byId = <T extends Named>(list: readonly T[] | undefined, ...ids: string[]): T | undefined => {
50
+ for (const id of ids) {
51
+ const found = list?.find((v) => v.id === id);
52
+ if (found) return found;
53
+ }
54
+ return undefined;
55
+ };
56
+
57
+ /**
58
+ * The site's colours, type scale, spacing scale and button/card classes a recipe uses (W-320).
59
+ * Colours are matched by name (Primary, Brand, Accent; Text, Ink; Surface, Background…), sizes by
60
+ * the Scales ids (`fs-4xl`, `space-xl`…) or similar names; anything missing falls back.
61
+ */
62
+ export function siteTokens(design: DesignSystem): RecipeTokens {
63
+ const { colors, fontSizes, spacings } = design.variables;
64
+ const used: string[] = [];
65
+ const color = (v: Named | undefined): Color | undefined => {
66
+ if (!v) return undefined;
67
+ used.push(v.name);
68
+ return { var: v.id };
69
+ };
70
+ const sized =
71
+ (from: "fontSize" | "spacing") =>
72
+ (v: Named | undefined, fallback: number): Size => {
73
+ if (!v) return px(fallback);
74
+ used.push(v.name);
75
+ return { var: v.id, from };
76
+ };
77
+ const size = sized("fontSize");
78
+ const space = sized("spacing");
79
+ const accentVar = pick(colors, /\b(primary|brand)\b/, /accent/, /\bmain\b/) ?? colors[0];
80
+ const tokens: RecipeTokens = {
81
+ display: size(byId(fontSizes, "fs-4xl", "fs-3xl") ?? pick(fontSizes, /display|hero|huge/), 48),
82
+ heading: size(byId(fontSizes, "fs-2xl") ?? pick(fontSizes, /\bh2\b|heading (m|l)|title/), 32),
83
+ subheading: size(byId(fontSizes, "fs-xl") ?? pick(fontSizes, /\bh3\b|heading s|subtitle/), 22),
84
+ body: size(byId(fontSizes, "fs-m") ?? pick(fontSizes, /body|base|text m|normal/), 17),
85
+ small: size(byId(fontSizes, "fs-s") ?? pick(fontSizes, /small|caption|text s/), 14),
86
+ sectionSpace: space(
87
+ byId(spacings, "space-3xl", "space-2xl") ?? pick(spacings, /section|huge|2xl|xxl/),
88
+ 80,
89
+ ),
90
+ blockSpace: space(byId(spacings, "space-l") ?? pick(spacings, /\blarge\b|\bl\b/), 32),
91
+ gap: space(byId(spacings, "space-m") ?? pick(spacings, /medium|\bm\b/), 24),
92
+ tight: space(byId(spacings, "space-xs", "space-s") ?? pick(spacings, /small|\bs\b|xs/), 12),
93
+ used,
94
+ };
95
+ const accent = color(accentVar);
96
+ if (accent) tokens.accent = accent;
97
+ const others = colors.filter((c) => c !== accentVar);
98
+ const ink = color(pick(others, /\b(text|ink|foreground|body)\b/, /\bdark\b|black/));
99
+ if (ink) tokens.ink = ink;
100
+ const muted = color(pick(others, /muted|subtle|grey|gray|secondary text/));
101
+ if (muted) tokens.muted = muted;
102
+ const surface = color(pick(others, /surface|background|\bbg\b|light|canvas/));
103
+ if (surface) tokens.surface = surface;
104
+ const onAccent = color(pick(others, /on[- ]?(primary|brand|accent)|inverse|white/));
105
+ if (onAccent) tokens.onAccent = onAccent;
106
+ else if (accentVar && /^#[0-9a-f]{6}$/i.test(accentVar.value)) {
107
+ // No "on accent" colour: white or near-black, whichever reads better on the accent.
108
+ tokens.onAccent =
109
+ contrastRatio(accentVar.value, "#ffffff") >= contrastRatio(accentVar.value, "#111111")
110
+ ? "#ffffff"
111
+ : "#111111";
112
+ }
113
+ const buttonCls = pick(design.classes, /\b(button|btn)\b/, /cta/);
114
+ if (buttonCls) {
115
+ tokens.buttonClass = buttonCls.id;
116
+ used.push(`.${buttonCls.name}`);
117
+ }
118
+ const cardCls = pick(design.classes, /\bcard\b/, /tile|panel|box/);
119
+ if (cardCls) {
120
+ tokens.cardClass = cardCls.id;
121
+ used.push(`.${cardCls.name}`);
122
+ }
123
+ tokens.used = [...new Set(used)];
124
+ return tokens;
125
+ }
126
+
127
+ type Draft = Omit<LayoutNode, "id"> & { children?: Draft[] };
128
+
129
+ const pad = (block: Size, inline: Size = px(24)): StyleProps => ({
130
+ paddingTop: block,
131
+ paddingBottom: block,
132
+ paddingLeft: inline,
133
+ paddingRight: inline,
134
+ });
135
+
136
+ const withClass = (draft: Draft, cls: string | undefined): Draft =>
137
+ cls ? { ...draft, classes: [cls] } : draft;
138
+
139
+ const heading = (text: string, level: number, fontSize: Size, extra: StyleProps = {}): Draft =>
140
+ ({ type: "heading", props: { text, level }, style: { fontSize, ...extra } }) as Draft;
141
+ const text = (value: string, t: RecipeTokens, extra: StyleProps = {}): Draft =>
142
+ ({
143
+ type: "text",
144
+ props: { text: value },
145
+ style: { fontSize: t.body, ...(t.muted ? { color: t.muted } : {}), ...extra },
146
+ }) as Draft;
147
+
148
+ function button(label: string, t: RecipeTokens, primary = true): Draft {
149
+ if (t.buttonClass) {
150
+ return withClass({ type: "button", props: { text: label, href: "#" } } as Draft, t.buttonClass);
151
+ }
152
+ const style: StyleProps = {
153
+ paddingTop: px(12),
154
+ paddingBottom: px(12),
155
+ paddingLeft: px(24),
156
+ paddingRight: px(24),
157
+ borderRadius: px(8),
158
+ fontWeight: 600,
159
+ };
160
+ if (primary && t.accent) {
161
+ style.backgroundColor = t.accent;
162
+ style.color = t.onAccent ?? "#ffffff";
163
+ } else if (t.accent) {
164
+ style.color = t.accent;
165
+ style.borderWidth = px(1);
166
+ style.borderStyle = "solid";
167
+ style.borderColor = t.accent;
168
+ }
169
+ return { type: "button", props: { text: label, href: "#" }, style } as Draft;
170
+ }
171
+
172
+ const flex = (children: Draft[], style: StyleProps): Draft =>
173
+ ({
174
+ type: "flexbox",
175
+ props: {},
176
+ style: { flexDirection: "row", flexWrap: "wrap", ...style },
177
+ children,
178
+ }) as Draft;
179
+ const column = (children: Draft[], style: StyleProps = {}): Draft =>
180
+ ({
181
+ type: "flexbox",
182
+ props: {},
183
+ style: { flexDirection: "column", flexWrap: "nowrap", ...style },
184
+ children,
185
+ }) as Draft;
186
+ const grid = (columns: number, children: Draft[], t: RecipeTokens): Draft =>
187
+ ({
188
+ type: "grid",
189
+ props: { columns, columnsTablet: Math.min(columns, 2), columnsMobile: 1 },
190
+ style: { gap: t.gap },
191
+ children,
192
+ }) as Draft;
193
+
194
+ function band(t: RecipeTokens, children: Draft[], extra: StyleProps = {}): Draft {
195
+ return {
196
+ type: "layout-section",
197
+ props: { tag: "section" },
198
+ style: { ...pad(t.sectionSpace), ...extra },
199
+ children,
200
+ } as Draft;
201
+ }
202
+
203
+ function card(t: RecipeTokens, children: Draft[]): Draft {
204
+ const base = column(children, { gap: t.tight });
205
+ if (t.cardClass) return withClass(base, t.cardClass);
206
+ return {
207
+ ...base,
208
+ style: {
209
+ ...base.style,
210
+ ...pad(t.blockSpace, t.blockSpace),
211
+ borderRadius: px(12),
212
+ borderWidth: px(1),
213
+ borderStyle: "solid",
214
+ borderColor: "#e5e7eb",
215
+ ...(t.surface ? { backgroundColor: t.surface } : {}),
216
+ },
217
+ };
218
+ }
219
+
220
+ type Options = { topLevel: 1 | 2 };
221
+
222
+ /** Section recipes (W-320): whole sections built from the site's own tokens. */
223
+ export const SECTION_RECIPES = [
224
+ {
225
+ id: "hero",
226
+ name: "Hero",
227
+ description: "Big headline, a line of text and two buttons.",
228
+ build: (t: RecipeTokens, o: Options): Draft =>
229
+ band(
230
+ t,
231
+ [
232
+ column(
233
+ [
234
+ heading("Say what you do in one line", o.topLevel, t.display, {
235
+ ...(t.ink ? { color: t.ink } : {}),
236
+ lineHeight: 1.1,
237
+ }),
238
+ text("A sentence or two on who it's for and why it's better.", t, {
239
+ fontSize: t.subheading,
240
+ maxWidth: px(640),
241
+ }),
242
+ flex([button("Get started", t), button("Learn more", t, false)], {
243
+ gap: t.tight,
244
+ justifyContent: "center",
245
+ marginTop: t.tight,
246
+ }),
247
+ ],
248
+ { gap: t.gap, alignItems: "center", textAlign: "center" },
249
+ ),
250
+ ],
251
+ t.surface ? { backgroundColor: t.surface } : {},
252
+ ),
253
+ },
254
+ {
255
+ id: "features",
256
+ name: "Features",
257
+ description: "A heading over three cards.",
258
+ build: (t: RecipeTokens): Draft =>
259
+ band(t, [
260
+ column(
261
+ [
262
+ heading("Why people choose us", 2, t.heading, {
263
+ textAlign: "center",
264
+ }),
265
+ grid(
266
+ 3,
267
+ ["Fast", "Simple", "Yours"].map((title) =>
268
+ card(t, [
269
+ heading(title, 3, t.subheading),
270
+ text("One or two sentences about this benefit.", t),
271
+ ]),
272
+ ),
273
+ t,
274
+ ),
275
+ ],
276
+ { gap: t.blockSpace },
277
+ ),
278
+ ]),
279
+ },
280
+ {
281
+ id: "cta",
282
+ name: "Call to action",
283
+ description: "A coloured band with a headline and a button.",
284
+ build: (t: RecipeTokens): Draft =>
285
+ band(
286
+ t,
287
+ [
288
+ column(
289
+ [
290
+ heading(
291
+ "Ready to start?",
292
+ 2,
293
+ t.heading,
294
+ t.accent ? { color: t.onAccent ?? "#ffffff" } : {},
295
+ ),
296
+ text(
297
+ "Tell visitors what happens when they click.",
298
+ t,
299
+ t.accent ? { color: t.onAccent ?? "#ffffff" } : {},
300
+ ),
301
+ t.accent && !t.buttonClass
302
+ ? ({
303
+ type: "button",
304
+ props: { text: "Start now", href: "#" },
305
+ style: {
306
+ paddingTop: px(12),
307
+ paddingBottom: px(12),
308
+ paddingLeft: px(28),
309
+ paddingRight: px(28),
310
+ borderRadius: px(8),
311
+ fontWeight: 600,
312
+ backgroundColor: t.onAccent ?? "#ffffff",
313
+ color: t.accent,
314
+ },
315
+ } as Draft)
316
+ : button("Start now", t),
317
+ ],
318
+ { gap: t.gap, alignItems: "center", textAlign: "center" },
319
+ ),
320
+ ],
321
+ t.accent ? { backgroundColor: t.accent } : {},
322
+ ),
323
+ },
324
+ {
325
+ id: "testimonial",
326
+ name: "Testimonial",
327
+ description: "A quote with the person's name.",
328
+ build: (t: RecipeTokens): Draft =>
329
+ band(t, [
330
+ column(
331
+ [
332
+ text("“EmVB made our site feel like ours again. We ship pages in minutes.”", t, {
333
+ fontSize: t.subheading,
334
+ ...(t.ink ? { color: t.ink } : {}),
335
+ maxWidth: px(720),
336
+ }),
337
+ text("Alex Doe, Founder at Example", t, { fontSize: t.small, fontWeight: 600 }),
338
+ ],
339
+ { gap: t.gap, alignItems: "center", textAlign: "center" },
340
+ ),
341
+ ]),
342
+ },
343
+ {
344
+ id: "stats",
345
+ name: "Stats",
346
+ description: "Three numbers that prove it.",
347
+ build: (t: RecipeTokens): Draft =>
348
+ band(t, [
349
+ grid(
350
+ 3,
351
+ [
352
+ ["10k+", "Happy customers"],
353
+ ["99.9%", "Uptime"],
354
+ ["24/7", "Support"],
355
+ ].map(([value, label]) =>
356
+ column(
357
+ [
358
+ text(value ?? "", t, {
359
+ fontSize: t.display,
360
+ fontWeight: 700,
361
+ ...(t.accent ? { color: t.accent } : {}),
362
+ }),
363
+ text(label ?? "", t, { fontSize: t.small }),
364
+ ],
365
+ { gap: t.tight, alignItems: "center", textAlign: "center" },
366
+ ),
367
+ ),
368
+ t,
369
+ ),
370
+ ]),
371
+ },
372
+ {
373
+ id: "faq",
374
+ name: "FAQ",
375
+ description: "Questions that open to their answers, no script.",
376
+ build: (t: RecipeTokens): Draft =>
377
+ band(t, [
378
+ column(
379
+ [
380
+ heading("Questions and answers", 2, t.heading),
381
+ {
382
+ type: "accordion",
383
+ props: {},
384
+ children: [
385
+ ["How long does it take?", "Most people are set up in an afternoon."],
386
+ ["Can I cancel?", "Any time, from your account page."],
387
+ ["Do you offer support?", "Yes, by email, every day."],
388
+ ].map(([q, a]) => ({
389
+ type: "accordion-item",
390
+ props: { summary: q ?? "" },
391
+ children: [text(a ?? "", t)],
392
+ })),
393
+ } as Draft,
394
+ ],
395
+ { gap: t.blockSpace, maxWidth: px(760) },
396
+ ),
397
+ ]),
398
+ },
399
+ ] as const;
400
+
401
+ export type RecipeId = (typeof SECTION_RECIPES)[number]["id"];
402
+
403
+ function hasH1(node: LayoutNode): boolean {
404
+ const props = node.props as Record<string, unknown>;
405
+ if (node.type === "heading" && props["level"] === 1) return true;
406
+ if (node.type === "post-title") return true;
407
+ return nodeChildren(node).some(hasH1);
408
+ }
409
+
410
+ function withIds(draft: Draft, random: () => number): LayoutNode {
411
+ const { children, ...rest } = draft;
412
+ const node = { ...rest, id: newNodeId(random) } as LayoutNode;
413
+ if (!children) return node;
414
+ return { ...node, children: children.map((child) => withIds(child, random)) } as LayoutNode;
415
+ }
416
+
417
+ /**
418
+ * A recipe's section, adapted to the site's styles (W-320). The hero's headline is the page's
419
+ * H1 only when the page has none yet. Ids are new; pass the result through `withFreshIds` (or
420
+ * `addNodeNear`) as for any new element.
421
+ */
422
+ export function recipeNode(
423
+ id: string,
424
+ design: DesignSystem,
425
+ layout: Layout | null,
426
+ random: () => number = Math.random,
427
+ ): LayoutNode | undefined {
428
+ const recipe = SECTION_RECIPES.find((r) => r.id === id);
429
+ if (!recipe) return undefined;
430
+ const topLevel = layout && hasH1(layout.root) ? 2 : 1;
431
+ const node = withIds(recipe.build(siteTokens(design), { topLevel }), random);
432
+ return { ...node, label: recipe.name } as LayoutNode;
433
+ }
@@ -1,3 +1,5 @@
1
+ import { variantShows } from "../audience/variants.ts";
2
+ import { audienceShows, audienceSummary } from "../audience/rules.ts";
1
3
  import { generateCss } from "../css/generate.ts";
2
4
  import { cssScopeToken, scopeAttribute, scopeCss, scopeWrapperCss } from "../css/scope.ts";
3
5
  import { ELEMENTS } from "../elements/index.ts";
@@ -20,6 +22,7 @@ import {
20
22
  stateDeclarations,
21
23
  styleClassName,
22
24
  styleDeclarations,
25
+ withInheritedAnimation,
23
26
  withInheritedLayers,
24
27
  type Declaration,
25
28
  type StateDeclarations,
@@ -37,7 +40,8 @@ import { renderPagination } from "./pagination.ts";
37
40
  import { renderSection } from "./section.ts";
38
41
  import { renderTabs } from "./tabs.ts";
39
42
  import { serialize, type VNode } from "./vnode.ts";
40
- import { classStylesInListOrder } from "../design/cascade.ts";
43
+ import { classStylesInListOrder, resolveCascade } from "../design/cascade.ts";
44
+ import { applyBindings, hasBindings, type BindingData } from "../data/bindings.ts";
41
45
  import {
42
46
  applyBackgroundVideo,
43
47
  applyBoxLink,
@@ -207,9 +211,18 @@ export function renderPage(
207
211
  const name = styleClassName(classId);
208
212
  if (name) classes.push(name);
209
213
  }
210
- const { declarations, rejected } = styleDeclarations(node.style);
214
+ // W-319: an element's own entrance or scroll motion keeps the other one its classes set.
215
+ const fromClasses = resolveCascade(classStylesInListOrder(design.classes, node.classes ?? []));
216
+ const classAnimation = {
217
+ ...(fromClasses.entrance ? { entrance: fromClasses.entrance } : {}),
218
+ ...(fromClasses.scrollMotion ? { scrollMotion: fromClasses.scrollMotion } : {}),
219
+ };
220
+ const own = node.style
221
+ ? (withInheritedAnimation(node.style, classAnimation) as typeof node.style)
222
+ : undefined;
223
+ const { declarations, rejected } = styleDeclarations(own);
211
224
  // W-210: a device that sets one background layer keeps the layers it inherits.
212
- const base = node.style ?? {};
225
+ const base = { ...classAnimation, ...own };
213
226
  const tabletStyle = node.devices?.tablet;
214
227
  const tablet = styleDeclarations(withInheritedLayers(tabletStyle, base));
215
228
  const mobile = styleDeclarations(
@@ -228,6 +241,18 @@ export function renderPage(
228
241
  const width = props.fullWidth === true ? "none" : cssLength(props.contentWidth);
229
242
  if (width) declarations.push({ property: "--emvb-content-width", value: width });
230
243
  }
244
+ if (node.type === "loop") {
245
+ // W-308: grid and cards columns, as a custom property the Loop's base CSS reads.
246
+ const columns = (node as { props: { columns?: unknown } }).props.columns;
247
+ if (
248
+ typeof columns === "number" &&
249
+ Number.isInteger(columns) &&
250
+ columns >= 1 &&
251
+ columns <= 6
252
+ ) {
253
+ declarations.push({ property: "--emvb-loop-columns", value: String(columns) });
254
+ }
255
+ }
231
256
  if (node.type === "grid") {
232
257
  const props = (node as { props: Record<string, unknown> }).props;
233
258
  declarations.push(...gridTracks(props["columns"]));
@@ -272,10 +297,16 @@ export function renderPage(
272
297
  };
273
298
 
274
299
  function visit(
275
- node: LayoutNode,
300
+ stored: LayoutNode,
276
301
  isRoot: boolean,
277
302
  dynamic: ThemeDynamicData | undefined = baseDynamic,
278
303
  ): VNode | undefined {
304
+ // W-307: bound fields read their live value; the typed value is the fallback.
305
+ const node = stored.bind ? applyBindings(stored, bindingData(dynamic)) : stored;
306
+ // W-312: only the visitor's arm of an A/B test renders; the editor shows every arm.
307
+ if (mode === "public" && !variantShows(stored, dynamic?.abArms)) return undefined;
308
+ // W-313: visitor-aware elements render only for their audience; the editor shows them all.
309
+ if (mode === "public" && !audienceShows(stored, dynamic?.visitor)) return undefined;
279
310
  const id = ID.test(node.id) ? node.id : undefined;
280
311
  const nodeId = id ?? "(invalid id)";
281
312
  const type: string = node.type;
@@ -294,6 +325,13 @@ export function renderPage(
294
325
  if (type === "menu-item" && hasChildren(node)) rendered.menuDropdown = true;
295
326
  const ruleId = id === undefined ? undefined : ruleIdFor(id, dynamic?.idOrigin ?? "");
296
327
  const attrs = nodeAttrs(node, isRoot, id, nodeId, ruleId);
328
+ if (mode === "editor" && hasBindings(stored)) attrs["data-emvb-bound"] = "";
329
+ if (mode === "editor" && stored.audience) {
330
+ attrs["data-emvb-audience"] = audienceSummary(stored.audience);
331
+ }
332
+ if (mode === "editor" && stored.variant) {
333
+ attrs["data-emvb-variant"] = `${stored.variant.test} · ${stored.variant.arm.toUpperCase()}`;
334
+ }
297
335
  const def = ELEMENTS[type as keyof typeof ELEMENTS];
298
336
  if (isFormNode(node)) return finish(node, renderForm(node, attrs, ctx, dynamic));
299
337
  if (isLoopNode(node)) return finish(node, renderLoop(node, attrs, ctx, dynamic));
@@ -342,6 +380,15 @@ export function renderPage(
342
380
  return applyBackgroundVideo(applyBoxLink(node, vnode), src);
343
381
  }
344
382
 
383
+ function bindingData(dynamic: ThemeDynamicData | undefined): BindingData {
384
+ return {
385
+ post: resolvePostForRender(dynamic, mode),
386
+ ...(dynamic?.site ? { site: dynamic.site } : {}),
387
+ ...(dynamic?.params ? { params: dynamic.params } : {}),
388
+ ...(dynamic?.origin ? { origin: dynamic.origin } : {}),
389
+ };
390
+ }
391
+
345
392
  const vnode = visit(layout.root, true) ?? {
346
393
  tag: "div",
347
394
  attrs: { class: "emvb-root" },
@@ -1,33 +1,79 @@
1
1
  import { ELEMENTS } from "../elements/index.ts";
2
2
  import type { LayoutNode, LoopNode } from "../schema/layout.ts";
3
- import { resolvePostsForLoop, type ThemeDynamicData } from "../theme/dynamic.ts";
3
+ import {
4
+ resolvePostsForLoop,
5
+ type ThemeDynamicData,
6
+ type ThemePostFields,
7
+ } from "../theme/dynamic.ts";
4
8
  import type { RenderContext } from "./context.ts";
5
9
  import type { VNode } from "./vnode.ts";
6
10
 
7
- /** One item per post, from the chosen loop-item part or the loop's own children. */
11
+ /** Entries a collection Loop shows when the Loop doesn't say (W-308). */
12
+ const DEFAULT_LOOP_LIMIT = 6;
13
+
14
+ /** Editor stand-ins for a collection Loop before its entries load (W-308). */
15
+ const sampleEntries = (collection: string, count: number): ThemePostFields[] =>
16
+ Array.from({ length: Math.min(count, 3) }, (_, i) => ({
17
+ id: `sample-${i + 1}`,
18
+ slug: `sample-${i + 1}`,
19
+ title: `${collection} entry ${i + 1}`,
20
+ excerpt: "Entry excerpt…",
21
+ content: "",
22
+ permalink: "#",
23
+ }));
24
+
25
+ /** The entries a Loop lists: a collection's (W-308) or the archive's posts. */
26
+ function entriesFor(
27
+ node: LoopNode,
28
+ dynamic: ThemeDynamicData | undefined,
29
+ mode: "public" | "editor",
30
+ ): ThemePostFields[] {
31
+ const collection = node.props.collection;
32
+ if (!collection) return resolvePostsForLoop(dynamic, mode);
33
+ const limit = node.props.limit ?? DEFAULT_LOOP_LIMIT;
34
+ const found = dynamic?.collections?.[node.id];
35
+ if (found) return found.slice(0, limit);
36
+ return mode === "editor" ? sampleEntries(collection, limit) : [];
37
+ }
38
+
39
+ /**
40
+ * One item per entry, from the chosen loop-item part or the loop's own children. A Loop's Empty
41
+ * state child (W-308) is left out of the item design and shows when there are no entries; the
42
+ * editor shows it under the items too, so it can be designed.
43
+ */
8
44
  export function renderLoop(
9
45
  node: LoopNode,
10
46
  attrs: Record<string, string>,
11
47
  ctx: RenderContext,
12
48
  dynamic: ThemeDynamicData | undefined,
13
49
  ): VNode | undefined {
14
- const posts = resolvePostsForLoop(dynamic, ctx.mode);
50
+ const posts = entriesFor(node, dynamic, ctx.mode);
15
51
  const itemPartId = node.props.itemPartId?.trim() ?? "";
16
52
  const templateLayout =
17
53
  itemPartId && dynamic?.loopTemplates ? dynamic.loopTemplates[itemPartId] : undefined;
18
- const templateNodes: LayoutNode[] = templateLayout ? templateLayout.root.children : node.children;
54
+ const own = node.children.filter((child) => child.type !== "loop-empty");
55
+ const emptyNodes = node.children.filter((child) => child.type === "loop-empty");
56
+ const templateNodes: LayoutNode[] = templateLayout ? templateLayout.root.children : own;
57
+ // Items don't get the archive's page data: a Pagination belongs after the Loop (W-228).
58
+ const { pagination: _pagination, ...rest } = dynamic ?? {};
59
+ const empty = () => ctx.children(emptyNodes, rest);
60
+ if (posts.length === 0) {
61
+ const designed = empty();
62
+ if (designed.length > 0) return ELEMENTS.loop.build(node as never, attrs, designed);
63
+ }
19
64
  // Editor mode always has a sample post, so an empty item template would paint a zero-height box.
20
65
  if (posts.length === 0 || (ctx.mode === "editor" && templateNodes.length === 0)) {
21
66
  if (ctx.mode !== "editor") return undefined;
22
67
  return {
23
68
  tag: "div",
24
69
  attrs: { ...attrs, "data-emvb-loop-empty": "" },
25
- children: ["Choose a Loop Item, or add elements here to design the item."],
70
+ children: [
71
+ ...ctx.children(emptyNodes, rest),
72
+ "Choose a Loop Item, or add elements here to design the item.",
73
+ ],
26
74
  };
27
75
  }
28
76
  const children: VNode[] = [];
29
- // Items don't get the archive's page data: a Pagination belongs after the Loop (W-228).
30
- const { pagination: _pagination, ...rest } = dynamic ?? {};
31
77
  // A loop item part is another layout, so its ids may match the page's (W-250).
32
78
  const itemDynamic = templateLayout
33
79
  ? { ...rest, idOrigin: `${rest.idOrigin ?? ""}/l:${itemPartId}` }
@@ -39,5 +85,6 @@ export function renderLoop(
39
85
  children: ctx.children(templateNodes, { ...itemDynamic, post, inLoopItem: true }),
40
86
  });
41
87
  }
88
+ if (ctx.mode === "editor") children.push(...empty());
42
89
  return ELEMENTS.loop.build(node as never, attrs, children);
43
90
  }
@@ -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
  }