@perkyzz/emvb 0.3.0 → 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 (121) 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 +1 -1
  10. package/src/admin/editor/Editor.tsx +106 -332
  11. package/src/admin/editor/EditorOverlay.tsx +3 -1
  12. package/src/admin/editor/PerfMeter.tsx +1 -1
  13. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  14. package/src/admin/editor/Timeline.tsx +16 -3
  15. package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
  16. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  17. package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
  18. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  19. package/src/admin/editor/canvas/drop-line.ts +24 -0
  20. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  21. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  22. package/src/admin/editor/collection-previews.ts +28 -5
  23. package/src/admin/editor/editor-chrome.tsx +346 -0
  24. package/src/admin/editor/editor-commands.ts +360 -0
  25. package/src/admin/editor/element-chrome.ts +89 -0
  26. package/src/admin/editor/feature-css.ts +15 -15
  27. package/src/admin/editor/host.ts +33 -0
  28. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  29. package/src/admin/editor/icons/library.ts +29 -19
  30. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  31. package/src/admin/editor/palette-items.ts +36 -5
  32. package/src/admin/editor/palette.ts +3 -2
  33. package/src/admin/editor/panels/AddPanel.tsx +2 -67
  34. package/src/admin/editor/panels/ColorControl.tsx +2 -10
  35. package/src/admin/editor/panels/ElementPanel.tsx +40 -99
  36. package/src/admin/editor/panels/LayersPanel.tsx +34 -62
  37. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  38. package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
  39. package/src/admin/editor/panels/VariableSection.tsx +1 -10
  40. package/src/admin/editor/panels/inline-error.tsx +11 -0
  41. package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
  42. package/src/admin/editor/panels/settings/AudienceEditor.tsx +73 -3
  43. package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
  44. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  45. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  46. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
  47. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  48. package/src/admin/editor/panels/settings/length-units.ts +15 -4
  49. package/src/admin/editor/panels/settings/style-sections.ts +5 -1
  50. package/src/admin/editor/panels/style-target.ts +105 -0
  51. package/src/admin/editor/section-templates.ts +43 -21
  52. package/src/admin/editor/shortcuts.ts +4 -0
  53. package/src/admin/editor/store.ts +10 -1
  54. package/src/admin/editor/useClipboardActions.ts +1 -1
  55. package/src/admin/editor/useEditorCommands.ts +61 -13
  56. package/src/admin/editor/useEditorData.ts +7 -1
  57. package/src/admin/editor/useEditorShortcuts.ts +23 -15
  58. package/src/admin/editor/useNodeActions.ts +6 -1
  59. package/src/admin/forms-api.ts +17 -6
  60. package/src/admin/icon-uploads-api.ts +18 -0
  61. package/src/admin/theme-api.ts +5 -18
  62. package/src/astro/content-port.ts +24 -0
  63. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  64. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  65. package/src/astro/forms/client.ts +1 -0
  66. package/src/astro/forms-definitions.ts +24 -11
  67. package/src/astro/index.ts +1 -0
  68. package/src/astro/render-session.ts +85 -0
  69. package/src/astro/request-data.ts +20 -8
  70. package/src/astro/resolve-theme.ts +166 -76
  71. package/src/astro/resolve.ts +57 -16
  72. package/src/astro/theme-posts.ts +16 -5
  73. package/src/astro/visitor.ts +67 -5
  74. package/src/constants.ts +1 -1
  75. package/src/core/arrange.ts +63 -38
  76. package/src/core/audience/rules.ts +22 -2
  77. package/src/core/canvas-styles.ts +24 -0
  78. package/src/core/clipboard.ts +11 -32
  79. package/src/core/css/generate.ts +9 -0
  80. package/src/core/css/print.ts +12 -0
  81. package/src/core/css/scope.ts +3 -3
  82. package/src/core/css-keywords.ts +83 -0
  83. package/src/core/data/bindings.ts +4 -6
  84. package/src/core/design/classes.ts +13 -15
  85. package/src/core/design/diff.ts +55 -0
  86. package/src/core/design/merge.ts +127 -0
  87. package/src/core/design/variables.ts +25 -21
  88. package/src/core/elements/dynamic-elements.ts +30 -0
  89. package/src/core/elements/form-elements.ts +1 -0
  90. package/src/core/elements/index.ts +183 -7
  91. package/src/core/forms/binding.ts +4 -13
  92. package/src/core/index.ts +10 -0
  93. package/src/core/local-style.ts +27 -0
  94. package/src/core/migrate/index.ts +9 -4
  95. package/src/core/nesting.ts +4 -23
  96. package/src/core/perf/scripts.ts +9 -6
  97. package/src/core/record.ts +3 -0
  98. package/src/core/render/context.ts +2 -0
  99. package/src/core/render/dynamic-post.ts +1 -2
  100. package/src/core/render/form.ts +133 -10
  101. package/src/core/render/index.ts +155 -13
  102. package/src/core/render/vnode.ts +12 -2
  103. package/src/core/sanitize/css.ts +90 -77
  104. package/src/core/sanitize/svg.ts +8 -3
  105. package/src/core/sanitize/url.ts +10 -1
  106. package/src/core/schema/design.ts +5 -7
  107. package/src/core/schema/layout.ts +153 -181
  108. package/src/core/schema/style.ts +53 -63
  109. package/src/core/share/link.ts +68 -28
  110. package/src/core/tabs/presence.ts +7 -17
  111. package/src/core/theme/dynamic.ts +200 -39
  112. package/src/core/theme/float.ts +1 -1
  113. package/src/core/tree-ops.ts +57 -0
  114. package/src/index.ts +14 -2
  115. package/src/server/design-routes.ts +4 -1
  116. package/src/server/icon-routes.ts +68 -16
  117. package/src/server/plugin.ts +8 -2
  118. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  119. package/src/admin/editor/icons/sets/lucide.json +0 -1
  120. package/src/admin/editor/icons/sets/remix.json +0 -1
  121. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -12,6 +12,7 @@ import type {
12
12
  AccordionItemNode,
13
13
  DividerNode,
14
14
  HeadingNode,
15
+ TocNode,
15
16
  IconNode,
16
17
  ImageNode,
17
18
  LabelNode,
@@ -47,7 +48,7 @@ import {
47
48
  postAuthor,
48
49
  } from "./dynamic-elements.ts";
49
50
 
50
- const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"] as const;
51
+ export const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"] as const;
51
52
 
52
53
  const newTabAttrs = (newTab: boolean | undefined): Record<string, string> =>
53
54
  newTab ? { target: "_blank", rel: "noopener noreferrer" } : {};
@@ -257,7 +258,7 @@ const link: ElementDefinition<LinkNode> = {
257
258
  const button: ElementDefinition<ButtonNode> = {
258
259
  baseCss:
259
260
  // The look sits in :where() so site tag defaults, classes and local styles all win (W-148).
260
- ".emvb-button{display:inline-flex;align-items:center;justify-content:center;margin:0;font:inherit;text-decoration:none;cursor:pointer}:where(.emvb-button){color:inherit;background:transparent;border:1px solid currentColor;border-radius:6px;padding:0.625em 1.25em;line-height:1.2}",
261
+ ".emvb-button{display:inline-flex;align-items:center;justify-content:center;gap:0.5em;margin:0;font:inherit;text-decoration:none;cursor:pointer}:where(.emvb-button){color:inherit;background:transparent;border:1px solid currentColor;border-radius:6px;padding:0.625em 1.25em;line-height:1.2}.emvb-button-icon{display:inline-flex;flex:none}.emvb-button-icon svg{width:100%;height:100%;display:block}.emvb-button-icon--sm{width:1em;height:1em}.emvb-button-icon--md{width:1.25em;height:1.25em}.emvb-button-icon--lg{width:1.5em;height:1.5em}.emvb-figure{margin:0}.emvb-figcaption{margin-top:0.35em}.emvb-image-link{display:contents}",
261
262
  defaults: () => ({ type: "button", props: { text: "Button" } }),
262
263
  descriptor: {
263
264
  type: "button",
@@ -274,25 +275,86 @@ const button: ElementDefinition<ButtonNode> = {
274
275
  message: "Use a full URL such as https://example.com or a path such as /pricing.",
275
276
  },
276
277
  { key: "newTab", kind: "boolean", label: "Open in a new tab", optional: true },
278
+ { key: "iconId", kind: "icon", label: "Icon", optional: true },
279
+ {
280
+ key: "iconPosition",
281
+ kind: "select",
282
+ label: "Icon position",
283
+ optional: true,
284
+ options: [
285
+ { value: "before", label: "Before the label" },
286
+ { value: "after", label: "After the label" },
287
+ ],
288
+ },
289
+ {
290
+ key: "iconSize",
291
+ kind: "select",
292
+ label: "Icon size",
293
+ optional: true,
294
+ options: [
295
+ { value: "sm", label: "Small" },
296
+ { value: "md", label: "Medium" },
297
+ { value: "lg", label: "Large" },
298
+ ],
299
+ },
300
+ { key: "iconGap", kind: "int", label: "Gap (px)", optional: true },
277
301
  ],
278
302
  },
279
303
  build: (node, attrs) => {
280
304
  const href = node.props.href !== undefined ? sanitizeHref(node.props.href) : undefined;
305
+ const children = buttonChildren(node);
281
306
  if (href) {
282
307
  return {
283
308
  tag: "a",
284
309
  attrs: { ...attrs, href, ...newTabAttrs(node.props.newTab) },
285
- children: [node.props.text],
310
+ children,
286
311
  };
287
312
  }
288
313
  return {
289
314
  tag: "button",
290
315
  attrs: { ...attrs, type: "button" },
291
- children: [node.props.text],
316
+ children,
292
317
  };
293
318
  },
294
319
  };
295
320
 
321
+ function buttonChildren(node: ButtonNode): (VNode | string)[] {
322
+ const buttonText = node.props.text;
323
+ const picked = node.props.iconSvg ? sanitizeSvgMarkup(node.props.iconSvg) : undefined;
324
+ const bundled = picked || !node.props.iconId ? undefined : getBundledIcon(node.props.iconId);
325
+ if (!picked && !bundled) return [buttonText];
326
+ const svg: VNode = {
327
+ tag: "svg",
328
+ attrs: picked
329
+ ? { ...picked.attrs, focusable: "false", "aria-hidden": "true" }
330
+ : {
331
+ xmlns: "http://www.w3.org/2000/svg",
332
+ viewBox: "0 0 24 24",
333
+ fill: "none",
334
+ stroke: "currentColor",
335
+ "stroke-width": "2",
336
+ "stroke-linecap": "round",
337
+ "stroke-linejoin": "round",
338
+ focusable: "false",
339
+ "aria-hidden": "true",
340
+ },
341
+ children: picked
342
+ ? picked.children
343
+ : (bundled?.children ?? []).map((child) => ({
344
+ tag: child.tag,
345
+ attrs: { ...child.attrs },
346
+ children: [],
347
+ })),
348
+ };
349
+ const size = node.props.iconSize ?? "md";
350
+ const icon: VNode = {
351
+ tag: "span",
352
+ attrs: { class: `emvb-button-icon emvb-button-icon--${size}`, "aria-hidden": "true" },
353
+ children: [svg],
354
+ };
355
+ return node.props.iconPosition === "after" ? [buttonText, icon] : [icon, buttonText];
356
+ }
357
+
296
358
  const list: ElementDefinition<ListNode> = {
297
359
  baseCss: ".emvb-list{margin:0;padding-inline-start:1.25em}.emvb-list li{margin:0}",
298
360
  defaults: () => ({ type: "list", props: { items: ["Item"] } }),
@@ -347,6 +409,17 @@ const image: ElementDefinition<ImageNode> = {
347
409
  },
348
410
  // The first big image people see (hero, LCP) shouldn't wait for lazy loading (W-226).
349
411
  { key: "priority", kind: "boolean", label: "Load right away", optional: true },
412
+ {
413
+ key: "href",
414
+ kind: "href",
415
+ label: "Link URL",
416
+ optional: true,
417
+ message: "Use a full URL or a path such as /pricing. Size styles stay on the image.",
418
+ },
419
+ { key: "newTab", kind: "boolean", label: "Open link in a new tab", optional: true },
420
+ { key: "caption", kind: "text", label: "Caption", optional: true },
421
+ { key: "focalX", kind: "int", label: "Focal point X (%)", optional: true },
422
+ { key: "focalY", kind: "int", label: "Focal point Y (%)", optional: true },
350
423
  {
351
424
  key: "width",
352
425
  kind: "int",
@@ -384,10 +457,51 @@ const image: ElementDefinition<ImageNode> = {
384
457
  if (decorative) imgAttrs.role = "presentation";
385
458
  if (node.props.width !== undefined) imgAttrs.width = String(node.props.width);
386
459
  if (node.props.height !== undefined) imgAttrs.height = String(node.props.height);
387
- return { tag: "img", attrs: imgAttrs, children: [] };
460
+ const sources = imageSources(node.props.src, node.props.sources);
461
+ if (sources) {
462
+ imgAttrs.srcset = sources;
463
+ imgAttrs.sizes = "100vw";
464
+ }
465
+ const img: VNode = { tag: "img", attrs: imgAttrs, children: [] };
466
+ const href = node.props.href ? sanitizeHref(node.props.href) : undefined;
467
+ const linked: VNode = href
468
+ ? {
469
+ tag: "a",
470
+ attrs: { href, class: "emvb-image-link", ...newTabAttrs(node.props.newTab) },
471
+ children: [img],
472
+ }
473
+ : img;
474
+ const caption = node.props.caption?.trim();
475
+ if (!caption) return linked;
476
+ return {
477
+ tag: "figure",
478
+ attrs: { class: "emvb-figure" },
479
+ children: [
480
+ linked,
481
+ { tag: "figcaption", attrs: { class: "emvb-figcaption" }, children: [caption] },
482
+ ],
483
+ };
388
484
  },
389
485
  };
390
486
 
487
+ function imageSources(
488
+ src: string,
489
+ sources: { src: string; width: number }[] | undefined,
490
+ ): string | undefined {
491
+ if (!sources || sources.length === 0) return undefined;
492
+ const parts: string[] = [];
493
+ const seen = new Set<string>();
494
+ for (const source of sources) {
495
+ const url = sanitizeMediaUrl(source.src);
496
+ // A comma or space is another srcset candidate, so one field would request a second host.
497
+ if (!url || /[\s,]/.test(url) || url === sanitizeMediaUrl(src) || seen.has(url)) continue;
498
+ if (!Number.isInteger(source.width) || source.width < 1 || source.width > 8000) continue;
499
+ seen.add(url);
500
+ parts.push(`${url} ${source.width}w`);
501
+ }
502
+ return parts.length > 0 ? parts.join(", ") : undefined;
503
+ }
504
+
391
505
  /** Root stroke widths the Stroke width control can override (W-237); Lucide and Tabler use 2. */
392
506
  const ICON_STROKE_WIDTHS = ["1", "1.5", "2", "2.5", "3"] as const;
393
507
 
@@ -626,6 +740,9 @@ const video: ElementDefinition<VideoNode> = {
626
740
  loading: "lazy",
627
741
  referrerpolicy: "strict-origin-when-cross-origin",
628
742
  allow: "encrypted-media; picture-in-picture; fullscreen",
743
+ // The player can run on its own origin. It cannot navigate this page.
744
+ sandbox:
745
+ "allow-scripts allow-same-origin allow-presentation allow-popups allow-popups-to-escape-sandbox",
629
746
  },
630
747
  children: [],
631
748
  };
@@ -644,6 +761,26 @@ const video: ElementDefinition<VideoNode> = {
644
761
  },
645
762
  };
646
763
 
764
+ const SVG_WSP = String.raw`[ \t\r\n]`;
765
+ const SVG_NUM = String.raw`[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?`;
766
+ const SVG_SEP = `(?:${SVG_WSP}*,${SVG_WSP}*|${SVG_WSP}+)`;
767
+ const VIEW_BOX = new RegExp(
768
+ `^${SVG_WSP}*${SVG_NUM}${SVG_SEP}${SVG_NUM}${SVG_SEP}(${SVG_NUM})${SVG_SEP}(${SVG_NUM})${SVG_WSP}*$`,
769
+ );
770
+
771
+ /** Longer side at `size`; the other side keeps the viewBox ratio. Square or unreadable stays square. */
772
+ function svgBox(size: number, viewBox: string | undefined): { width: string; height: string } {
773
+ const match = VIEW_BOX.exec(viewBox ?? "");
774
+ const vbWidth = Number(match?.[1]);
775
+ const vbHeight = Number(match?.[2]);
776
+ const across = vbWidth / vbHeight;
777
+ const down = vbHeight / vbWidth;
778
+ const valid = vbWidth > 0 && [across, down].every((ratio) => Number.isFinite(ratio) && ratio > 0);
779
+ if (!valid) return { width: String(size), height: String(size) };
780
+ const side = (ratio: number) => String(Math.max(1, Math.round(size * Math.min(1, ratio))));
781
+ return { width: side(across), height: side(down) };
782
+ }
783
+
647
784
  const DEFAULT_SVG =
648
785
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M8 12h8"/></svg>';
649
786
 
@@ -700,8 +837,7 @@ const svgEl: ElementDefinition<SvgNode> = {
700
837
  const svgAttrs: Record<string, string> = {
701
838
  ...tree.attrs,
702
839
  xmlns: tree.attrs.xmlns ?? "http://www.w3.org/2000/svg",
703
- width: String(size),
704
- height: String(size),
840
+ ...svgBox(size, tree.attrs.viewBox),
705
841
  focusable: "false",
706
842
  };
707
843
  if (!svgAttrs.fill && !svgAttrs.stroke) {
@@ -840,6 +976,27 @@ const grid: ElementDefinition<GridNode> = {
840
976
  label: String(n),
841
977
  })),
842
978
  },
979
+ {
980
+ key: "columnTracks",
981
+ kind: "list-items",
982
+ label: "Custom tracks",
983
+ optional: true,
984
+ message: "One track per line: 1fr, 2fr, 3fr, auto, min-content, max-content, or a length.",
985
+ },
986
+ {
987
+ key: "columnTracksTablet",
988
+ kind: "list-items",
989
+ label: "Custom tracks on tablet",
990
+ optional: true,
991
+ message: "Leave empty to follow the desktop tracks.",
992
+ },
993
+ {
994
+ key: "columnTracksMobile",
995
+ kind: "list-items",
996
+ label: "Custom tracks on mobile",
997
+ optional: true,
998
+ message: "Leave empty to follow the next wider device.",
999
+ },
843
1000
  ...BOX_LINK_FIELDS,
844
1001
  ],
845
1002
  },
@@ -903,8 +1060,27 @@ const accordionItem: ElementDefinition<AccordionItemNode> = {
903
1060
  },
904
1061
  };
905
1062
 
1063
+ const toc: ElementDefinition<TocNode> = {
1064
+ baseCss:
1065
+ ".emvb-toc{margin:0}.emvb-toc-title{margin:0 0 0.5em;font:inherit;font-weight:600}.emvb-toc ol{margin:0;padding-inline-start:1.25em}.emvb-toc a{color:inherit}",
1066
+ defaults: () => ({ type: "toc", props: {} }),
1067
+ descriptor: {
1068
+ type: "toc",
1069
+ name: "Table of contents",
1070
+ group: "content",
1071
+ defaultTab: "content",
1072
+ fields: [{ key: "title", kind: "text", label: "Title", optional: true }],
1073
+ },
1074
+ build: (node, attrs) => ({
1075
+ tag: "nav",
1076
+ attrs: { ...attrs, "aria-label": node.props.title?.trim() || "Table of contents" },
1077
+ children: [],
1078
+ }),
1079
+ };
1080
+
906
1081
  export const ELEMENTS = {
907
1082
  heading,
1083
+ toc,
908
1084
  container,
909
1085
  "layout-section": layoutSection,
910
1086
  spacer,
@@ -1,5 +1,5 @@
1
1
  import { isFormNode, type Layout, type LayoutNode } from "../schema/layout.ts";
2
- import { nodeChildren } from "../tree-ops.ts";
2
+ import { forEachNode, someNode } from "../tree-ops.ts";
3
3
  import { fieldsOf, type FormDefinitions } from "./definition.ts";
4
4
 
5
5
  export type MissingRequiredField = {
@@ -8,14 +8,9 @@ export type MissingRequiredField = {
8
8
  field: string;
9
9
  };
10
10
 
11
- function walk(node: LayoutNode, visit: (node: LayoutNode) => void): void {
12
- visit(node);
13
- for (const child of nodeChildren(node)) walk(child, visit);
14
- }
15
-
16
11
  function boundFields(form: LayoutNode): Set<string> {
17
12
  const names = new Set<string>();
18
- walk(form, (node) => {
13
+ forEachNode(form, (node) => {
19
14
  if (
20
15
  node.type === "text-input" ||
21
16
  node.type === "textarea" ||
@@ -38,7 +33,7 @@ export function findMissingRequiredFields(
38
33
  definitions: FormDefinitions,
39
34
  ): MissingRequiredField[] {
40
35
  const missing: MissingRequiredField[] = [];
41
- walk(layout.root, (node) => {
36
+ forEachNode(layout.root, (node) => {
42
37
  if (!isFormNode(node) || !node.props.formId) return;
43
38
  const definition = definitions.get(node.props.formId);
44
39
  if (!definition) return;
@@ -53,9 +48,5 @@ export function findMissingRequiredFields(
53
48
  }
54
49
 
55
50
  export function layoutHasForm(layout: Layout): boolean {
56
- let found = false;
57
- walk(layout.root, (node) => {
58
- if (isFormNode(node) && node.props.formId.trim()) found = true;
59
- });
60
- return found;
51
+ return someNode(layout.root, (node) => isFormNode(node) && node.props.formId.trim() !== "");
61
52
  }
package/src/core/index.ts CHANGED
@@ -47,6 +47,7 @@ export {
47
47
  AB_TEST_NAME,
48
48
  Audience,
49
49
  AUDIENCE_DEVICES,
50
+ AUDIENCE_SEGMENT,
50
51
  LOOP_DISPLAYS,
51
52
  LOOP_ORDERS,
52
53
  SectionNode,
@@ -117,6 +118,8 @@ export {
117
118
  type DesignValidation,
118
119
  } from "./validate.ts";
119
120
  export { nestingIssues } from "./nesting.ts";
121
+ export { mergeDesign, type DesignConflict } from "./design/merge.ts";
122
+ export { designChanges, designChangeLabel, type DesignChange } from "./design/diff.ts";
120
123
  export {
121
124
  DESIGN_SCHEMA_VERSION,
122
125
  DEFAULT_STYLE_TAGS,
@@ -258,6 +261,9 @@ export {
258
261
  addSectionNear,
259
262
  canDrop,
260
263
  duplicateNode,
264
+ wrapNode,
265
+ WRAP_TYPES,
266
+ type WrapType,
261
267
  createVariantB,
262
268
  endAbTest,
263
269
  defaultTestName,
@@ -371,6 +377,8 @@ export {
371
377
  collectLoopItemPartIds,
372
378
  collectSectionPartIds,
373
379
  collectCollectionLoops,
380
+ loopPermalink,
381
+ parseLoopFilter,
374
382
  type CollectionLoop,
375
383
  resolvePostForRender,
376
384
  resolvePostsForLoop,
@@ -443,6 +451,7 @@ export {
443
451
  clockIn,
444
452
  deviceFromUserAgent,
445
453
  layoutUsesAudience,
454
+ layoutUsesVisitorRule,
446
455
  type VisitorInfo,
447
456
  } from "./audience/rules.ts";
448
457
  export { changedIds, diffSections, restoreSection, type SectionChange } from "./history/diff.ts";
@@ -489,3 +498,4 @@ export {
489
498
  type SharedPage,
490
499
  type ShareRead,
491
500
  } from "./share/link.ts";
501
+ export { canvasStyleUrls, MAX_CANVAS_STYLES } from "./canvas-styles.ts";
@@ -0,0 +1,27 @@
1
+ import type { LayoutNode } from "./schema/layout.ts";
2
+
3
+ /** Local style keys. Classes and `query` stay on the element (D-033, W-355). */
4
+ const LOCAL_STYLE_KEYS = ["style", "states", "devices", "hiddenOn"] as const;
5
+
6
+ export type LocalStyle = Pick<LayoutNode, (typeof LOCAL_STYLE_KEYS)[number]>;
7
+
8
+ /** The local style of a node; classes stay behind (D-033). */
9
+ export function localStyleOf(node: LayoutNode): LocalStyle {
10
+ const copied: LocalStyle = {};
11
+ for (const key of LOCAL_STYLE_KEYS) {
12
+ const value = node[key];
13
+ if (value !== undefined) (copied as Record<string, unknown>)[key] = structuredClone(value);
14
+ }
15
+ return copied;
16
+ }
17
+
18
+ /** Replaces style, states, devices and hiddenOn. Other fields stay. `query` is not a local style. */
19
+ export function withLocalStyle<T extends LayoutNode>(node: T, copied: LocalStyle): T {
20
+ const next = { ...node } as Record<string, unknown>;
21
+ for (const key of LOCAL_STYLE_KEYS) {
22
+ delete next[key];
23
+ const value = copied[key];
24
+ if (value !== undefined) next[key] = structuredClone(value);
25
+ }
26
+ return next as T;
27
+ }
@@ -1,3 +1,4 @@
1
+ import { isRecord } from "../record.ts";
1
2
  import { LAYOUT_SCHEMA_VERSION } from "../schema/layout.ts";
2
3
 
3
4
  export type Migration = (doc: Record<string, unknown>) => Record<string, unknown>;
@@ -12,13 +13,13 @@ export type Migration = (doc: Record<string, unknown>) => Record<string, unknown
12
13
  * per-corner radii and grid columns per device, and v10 → v11 (D-045) the layout Section and node
13
14
  * labels, and v11 → v12 (W-160) rewrites a gradient `{ angle, from, to }` into
14
15
  * `{ type: "linear", angle, stops }`, and v12 → v13 (W-307 onward) adds optional fields only
15
- * (bindings, and the rest of the W-307 feature batch). Every other value is unchanged.
16
+ * (bindings, and the rest of the W-307 feature batch), and v13 → v14 (W-329 onward) adds
17
+ * optional fields only (audience segments, Loop options, `ch` and negative margins), and
18
+ * v14 → v15 (W-341 onward) adds optional fields only (direction, image link and caption,
19
+ * button icons, table of contents, container queries). Every other value is unchanged.
16
20
  */
17
21
  const unchanged: Migration = (doc) => doc;
18
22
 
19
- const isRecord = (value: unknown): value is Record<string, unknown> =>
20
- typeof value === "object" && value !== null && !Array.isArray(value);
21
-
22
23
  /** v11 two-stop gradient → v12 stops. A gradient that already has `stops` is left as it is. */
23
24
  function convertGradient(value: unknown): unknown {
24
25
  if (!isRecord(value) || Array.isArray(value["stops"])) return value;
@@ -71,6 +72,8 @@ export const LAYOUT_MIGRATIONS: Readonly<Record<number, Migration>> = {
71
72
  10: unchanged,
72
73
  11: gradients,
73
74
  12: unchanged,
75
+ 13: unchanged,
76
+ 14: unchanged,
74
77
  };
75
78
 
76
79
  /** `DESIGN_MIGRATIONS[n]` upgrades a version-n design document to version n + 1. */
@@ -87,6 +90,8 @@ export const DESIGN_MIGRATIONS: Readonly<Record<number, Migration>> = {
87
90
  10: unchanged,
88
91
  11: gradients,
89
92
  12: unchanged,
93
+ 13: unchanged,
94
+ 14: unchanged,
90
95
  };
91
96
 
92
97
  export type UpgradeResult =
@@ -1,12 +1,12 @@
1
- import { REASONS } from "./arrange.ts";
2
- import { isFormFieldType, isFormNode, type Layout, type LayoutNode } from "./schema/layout.ts";
1
+ import { parentChildRefusal } from "./arrange.ts";
2
+ import { isFormNode, type Layout, type LayoutNode } from "./schema/layout.ts";
3
3
  import { nodeChildren } from "./tree-ops.ts";
4
4
  import type { LayoutIssue } from "./validate.ts";
5
5
 
6
6
  /**
7
7
  * Elements in a parent the editor would never let them into: a menu item outside a Menu, a tab
8
8
  * panel outside Tabs, a form field outside a form, a form in a form, and so on (W-225). The
9
- * same rules and messages as drag and drop (arrange.ts DROP_RULES). The editor can't build
9
+ * same rules and messages as drag and drop (`parentChildRefusal`). The editor can't build
10
10
  * these trees, but the content API accepted them and they render broken markup (an orphan
11
11
  * `<li>`, a panel no tab opens). Not part of validateLayout, so stored pages still render and
12
12
  * a copied field can still be pasted; the save hook refuses them instead.
@@ -23,7 +23,7 @@ export function nestingIssues(layout: Layout, max = 5): LayoutIssue[] {
23
23
  for (const [i, child] of kids.entries()) {
24
24
  if (issues.length >= max) return;
25
25
  const at = `${path}.children[${i}]`;
26
- const reason = misplaced(node, child, inForm);
26
+ const reason = parentChildRefusal(node, child, inForm);
27
27
  if (reason) add(at, child, reason);
28
28
  walk(child, at, inForm || isFormNode(child));
29
29
  }
@@ -31,22 +31,3 @@ export function nestingIssues(layout: Layout, max = 5): LayoutIssue[] {
31
31
  walk(layout.root, "root", isFormNode(layout.root));
32
32
  return issues;
33
33
  }
34
-
35
- function misplaced(parent: LayoutNode, child: LayoutNode, inForm: boolean): string | undefined {
36
- if (child.type === "loop-empty" && parent.type !== "loop") return REASONS.emptyOutsideLoop;
37
- if (child.type === "tab-panel" && parent.type !== "tabs") return REASONS.tabOutsideTabs;
38
- if (parent.type === "tabs" && child.type !== "tab-panel") return REASONS.onlyTabPanels;
39
- if (child.type === "accordion-item" && parent.type !== "accordion") {
40
- return REASONS.itemOutsideAccordion;
41
- }
42
- if (parent.type === "accordion" && child.type !== "accordion-item") {
43
- return REASONS.onlyAccordionItems;
44
- }
45
- if (child.type === "menu-item" && parent.type !== "menu" && parent.type !== "menu-item") {
46
- return REASONS.itemOutsideMenu;
47
- }
48
- if (parent.type === "menu" && child.type !== "menu-item") return REASONS.onlyMenuItems;
49
- if (isFormNode(child) && inForm) return REASONS.nestedForm;
50
- if (isFormFieldType(child.type) && !inForm) return REASONS.fieldOutsideForm;
51
- return undefined;
52
- }
@@ -1,4 +1,5 @@
1
1
  import { isParentNode, type Layout, type LayoutNode } from "../schema/layout.ts";
2
+ import { forEachNode, knownChildren } from "../tree-ops.ts";
2
3
 
3
4
  /** The small scripts an EmVB page can load; everything else is plain HTML and CSS (W-311). */
4
5
  export type PageScript = "forms" | "tabs" | "menu";
@@ -48,11 +49,13 @@ export const typeMayAddScript = (type: string): boolean =>
48
49
  /** Every script the layout loads, with the elements that cause it (W-311). */
49
50
  export function layoutScripts(layout: Layout): Map<PageScript, string[]> {
50
51
  const found = new Map<PageScript, string[]>();
51
- const walk = (node: LayoutNode): void => {
52
- const script = nodeScript(node);
53
- if (script) found.set(script, [...(found.get(script) ?? []), node.id]);
54
- if (isParentNode(node)) for (const child of node.children) walk(child);
55
- };
56
- walk(layout.root);
52
+ forEachNode(
53
+ layout.root,
54
+ (node) => {
55
+ const script = nodeScript(node);
56
+ if (script) found.set(script, [...(found.get(script) ?? []), node.id]);
57
+ },
58
+ knownChildren,
59
+ );
57
60
  return found;
58
61
  }
@@ -0,0 +1,3 @@
1
+ /** A plain object. Arrays and null are not records. */
2
+ export const isRecord = (value: unknown): value is Record<string, unknown> =>
3
+ typeof value === "object" && value !== null && !Array.isArray(value);
@@ -18,4 +18,6 @@ export type RenderContext = {
18
18
  * stay with their own copy.
19
19
  */
20
20
  uniqueId: (base: string) => string;
21
+ /** The form whose children are rendering, so each field reads that form's definition. */
22
+ formId?: string;
21
23
  };
@@ -1,3 +1,4 @@
1
+ import { HEADING_TAGS } from "../elements/index.ts";
1
2
  import type { LayoutNode, POST_DATE_FORMATS } from "../schema/layout.ts";
2
3
  import { sanitizeHref } from "../sanitize/href.ts";
3
4
  import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
@@ -31,8 +32,6 @@ type PostField = {
31
32
  render: (node: LayoutNode, attrs: Attrs, post: ThemePostFields) => VNode | undefined;
32
33
  };
33
34
 
34
- const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"] as const;
35
-
36
35
  type PostDateFormat = (typeof POST_DATE_FORMATS)[number];
37
36
 
38
37
  /** In UTC, so the date doesn't move with the server's time zone. */