@perkyzz/emvb 1.0.0 → 1.2.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 (142) hide show
  1. package/README.md +9 -0
  2. package/THIRD_PARTY_NOTICES.md +1 -0
  3. package/package.json +10 -9
  4. package/src/admin/agents-api.ts +5 -1
  5. package/src/admin/bulk-api.ts +67 -0
  6. package/src/admin/content-api.ts +39 -6
  7. package/src/admin/copy-rich-text.ts +119 -0
  8. package/src/admin/dialog-tab-wrap.ts +78 -0
  9. package/src/admin/editor/A11yCopilot.tsx +2 -0
  10. package/src/admin/editor/Editor.tsx +24 -7
  11. package/src/admin/editor/ScheduleDialog.tsx +167 -0
  12. package/src/admin/editor/Timeline.tsx +6 -2
  13. package/src/admin/editor/TopBar.tsx +60 -8
  14. package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
  15. package/src/admin/editor/canvas/DeviceBar.tsx +22 -9
  16. package/src/admin/editor/canvas/canvas-scale.ts +3 -3
  17. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  18. package/src/admin/editor/dnd/new-element.ts +68 -0
  19. package/src/admin/editor/editor-chrome.tsx +16 -5
  20. package/src/admin/editor/editor-commands.ts +10 -4
  21. package/src/admin/editor/editor-css.ts +2 -1
  22. package/src/admin/editor/element-chrome.ts +22 -0
  23. package/src/admin/editor/panels/ElementPanel.tsx +34 -17
  24. package/src/admin/editor/panels/SettingsPanel.tsx +2 -2
  25. package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
  26. package/src/admin/editor/panels/settings/EffectsControls.tsx +79 -1
  27. package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
  28. package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
  29. package/src/admin/editor/panels/settings/IconControls.tsx +11 -0
  30. package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
  31. package/src/admin/editor/panels/settings/ItemList.tsx +36 -2
  32. package/src/admin/editor/panels/settings/LengthRow.tsx +36 -3
  33. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +18 -0
  34. package/src/admin/editor/panels/settings/StyleRow.tsx +7 -0
  35. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  36. package/src/admin/editor/panels/settings/length-units.ts +15 -3
  37. package/src/admin/editor/panels/settings/style-sections.ts +1 -0
  38. package/src/admin/editor/panels/style-target.ts +17 -4
  39. package/src/admin/editor/section-templates.ts +26 -4
  40. package/src/admin/editor/store.ts +15 -3
  41. package/src/admin/editor/useEditorCommands.ts +7 -5
  42. package/src/admin/editor/useEditorData.ts +4 -0
  43. package/src/admin/editor/useNodeActions.ts +4 -2
  44. package/src/admin/editor/useSave.ts +47 -3
  45. package/src/admin/export-api.ts +238 -0
  46. package/src/admin/index.tsx +6 -1
  47. package/src/admin/menus-api.ts +113 -0
  48. package/src/admin/pages/ExportDialog.tsx +395 -0
  49. package/src/admin/pages/ImportElementorDialog.tsx +25 -1
  50. package/src/admin/pages/PageList.tsx +67 -2
  51. package/src/admin/pages/ThemePartList.tsx +37 -1
  52. package/src/admin/pages/bulk.tsx +303 -0
  53. package/src/admin/search.ts +20 -0
  54. package/src/admin/theme-api.ts +4 -0
  55. package/src/admin/ui.ts +11 -2
  56. package/src/admin/widgets/CanvasField.tsx +8 -0
  57. package/src/admin/widgets/ConvertToRichText.tsx +136 -0
  58. package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
  59. package/src/admin/widgets/convert-body.ts +73 -2
  60. package/src/astro/EmVBPage.astro +3 -0
  61. package/src/astro/render.ts +47 -22
  62. package/src/astro/request-data.ts +3 -0
  63. package/src/astro/resolve-theme.ts +88 -51
  64. package/src/astro/tabs/runtime.ts +16 -6
  65. package/src/astro/visitor.ts +23 -4
  66. package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
  67. package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
  68. package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
  69. package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
  70. package/src/astro/widgets/alerts.ts +37 -0
  71. package/src/astro/widgets/carousel.ts +167 -0
  72. package/src/astro/widgets/index.ts +1 -0
  73. package/src/astro/widgets/lightbox.ts +123 -0
  74. package/src/constants.ts +1 -1
  75. package/src/core/a11y/audit.ts +103 -3
  76. package/src/core/arrange.ts +57 -1
  77. package/src/core/bounded-array.ts +16 -13
  78. package/src/core/contract.ts +26 -3
  79. package/src/core/css/generate.ts +83 -21
  80. package/src/core/css/scope.ts +10 -2
  81. package/src/core/css/trace.ts +33 -8
  82. package/src/core/design/classes.ts +25 -5
  83. package/src/core/design/devices.ts +78 -2
  84. package/src/core/design/variables.ts +14 -1
  85. package/src/core/elements/icon-svg.ts +135 -0
  86. package/src/core/elements/index.ts +33 -127
  87. package/src/core/elements/widgets.ts +907 -0
  88. package/src/core/export/runtimes.generated.ts +12 -0
  89. package/src/core/export/site.ts +579 -0
  90. package/src/core/export/zip.ts +95 -0
  91. package/src/core/extensions/schema.ts +2 -1
  92. package/src/core/geo-trust.ts +18 -0
  93. package/src/core/history/diff.ts +25 -0
  94. package/src/core/icons/social.generated.ts +29 -0
  95. package/src/core/image-edit/schema.ts +2 -1
  96. package/src/core/import/elementor/atomic.ts +22 -9
  97. package/src/core/import/elementor/context.ts +18 -0
  98. package/src/core/import/elementor/index.ts +72 -11
  99. package/src/core/import/elementor/style.ts +21 -1
  100. package/src/core/import/elementor/widgets.ts +394 -133
  101. package/src/core/index.ts +14 -0
  102. package/src/core/issue-cap.ts +19 -0
  103. package/src/core/json-schema.ts +8 -1
  104. package/src/core/limits.ts +6 -0
  105. package/src/core/loop-collections.ts +33 -0
  106. package/src/core/perf/meter.ts +37 -19
  107. package/src/core/portable-text-export.ts +243 -0
  108. package/src/core/proposals.ts +8 -2
  109. package/src/core/public-attributes.ts +30 -0
  110. package/src/core/render/index.ts +115 -13
  111. package/src/core/render/tabs.ts +18 -11
  112. package/src/core/render/vnode.ts +44 -6
  113. package/src/core/sanitize/css.ts +26 -0
  114. package/src/core/sanitize/svg-upload.ts +276 -23
  115. package/src/core/sanitize/svg.ts +3 -3
  116. package/src/core/schema/descriptors.ts +4 -0
  117. package/src/core/schema/design.ts +8 -7
  118. package/src/core/schema/layout.ts +406 -18
  119. package/src/core/schema/style.ts +49 -1
  120. package/src/core/search-text.ts +70 -0
  121. package/src/core/shadowing-ids.ts +41 -0
  122. package/src/core/theme/conditions.ts +2 -1
  123. package/src/core/theme/float.ts +1 -0
  124. package/src/core/theme/parse-doc.ts +10 -5
  125. package/src/core/theme/popup-rules.ts +16 -0
  126. package/src/core/theme/triggers.ts +3 -2
  127. package/src/core/validate.ts +3 -2
  128. package/src/index.ts +23 -2
  129. package/src/mcp/ports.ts +18 -7
  130. package/src/mcp/proposals.ts +36 -11
  131. package/src/mcp/read.ts +2 -3
  132. package/src/mcp/tools.ts +1 -1
  133. package/src/server/agent-settings.ts +12 -1
  134. package/src/server/hooks.ts +41 -6
  135. package/src/server/icon-routes.ts +52 -12
  136. package/src/server/mcp-routes.ts +11 -5
  137. package/src/server/plugin.ts +27 -2
  138. package/src/server/presence.ts +5 -1
  139. package/src/server/proposals.ts +16 -4
  140. package/src/server/requests.ts +60 -11
  141. package/src/server/site-origin.ts +13 -0
  142. package/src/server/targets.ts +26 -0
@@ -0,0 +1,167 @@
1
+ /**
2
+ * W-1018: the opt-in Carousel controls. A carousel works without this script (a snapping track
3
+ * you swipe, scroll or move with the arrow keys); this adds what it asked for:
4
+ * - Previous and Next buttons (`data-emvb-arrows`), disabled at the ends unless it loops;
5
+ * - one button per slide (`data-emvb-dots`), the current one marked aria-current;
6
+ * - autoplay (`data-emvb-autoplay="<seconds>"`) with a visible Pause/Play button placed before
7
+ * the slides, paused while the carousel is hovered or holds focus, and starting paused when
8
+ * the visitor prefers reduced motion (WCAG 2.2.2).
9
+ */
10
+
11
+ type Carousel = {
12
+ root: HTMLElement;
13
+ track: HTMLElement;
14
+ slides: HTMLElement[];
15
+ loop: boolean;
16
+ index: number;
17
+ prev?: HTMLButtonElement;
18
+ next?: HTMLButtonElement;
19
+ dots: HTMLButtonElement[];
20
+ timer?: ReturnType<typeof setInterval>;
21
+ /** The visitor pressed Pause (or reduced motion started it paused). */
22
+ stopped: boolean;
23
+ /** Hovered or focused: paused for now. */
24
+ held: boolean;
25
+ };
26
+
27
+ function button(label: string, text: string, className = ""): HTMLButtonElement {
28
+ const el = document.createElement("button");
29
+ el.type = "button";
30
+ el.setAttribute("aria-label", label);
31
+ el.textContent = text;
32
+ if (className) el.className = className;
33
+ return el;
34
+ }
35
+
36
+ /** How many slides show at once, from the layout (1 when it can't be measured). */
37
+ function perView(c: Carousel): number {
38
+ const first = c.slides[0];
39
+ if (!first || first.offsetWidth === 0) return 1;
40
+ return Math.max(1, Math.round(c.track.clientWidth / first.offsetWidth));
41
+ }
42
+
43
+ /** The last slide a view can start at. */
44
+ const lastStart = (c: Carousel) => Math.max(0, c.slides.length - perView(c));
45
+
46
+ function update(c: Carousel): void {
47
+ const last = lastStart(c);
48
+ if (c.prev) c.prev.disabled = !c.loop && c.index <= 0;
49
+ if (c.next) c.next.disabled = !c.loop && c.index >= last;
50
+ c.dots.forEach((dot, i) => {
51
+ if (i === c.index) dot.setAttribute("aria-current", "true");
52
+ else dot.removeAttribute("aria-current");
53
+ });
54
+ }
55
+
56
+ /** Shows slide `index` (wrapped when looping or playing, else kept in range). */
57
+ function go(c: Carousel, index: number, wrap = c.loop): void {
58
+ const last = lastStart(c);
59
+ c.index = wrap
60
+ ? index > last
61
+ ? 0
62
+ : index < 0
63
+ ? last
64
+ : index
65
+ : Math.min(Math.max(index, 0), last);
66
+ const target = c.slides[c.index];
67
+ const origin = c.slides[0];
68
+ if (target && origin) c.track.scrollTo({ left: target.offsetLeft - origin.offsetLeft });
69
+ update(c);
70
+ }
71
+
72
+ const present = (els: (HTMLElement | undefined)[]): HTMLElement[] =>
73
+ els.filter((el): el is HTMLElement => el !== undefined);
74
+
75
+ function setup(root: HTMLElement): void {
76
+ const track = root.querySelector<HTMLElement>(":scope > .emvb-carousel-track");
77
+ if (!track) return;
78
+ const c: Carousel = {
79
+ root,
80
+ track,
81
+ slides: [...track.children].filter((el): el is HTMLElement => el instanceof HTMLElement),
82
+ loop: root.hasAttribute("data-emvb-loop"),
83
+ index: 0,
84
+ dots: [],
85
+ stopped: false,
86
+ held: false,
87
+ };
88
+ if (c.slides.length < 2) return;
89
+ const controls = document.createElement("div");
90
+ controls.className = "emvb-carousel-controls";
91
+ if (root.hasAttribute("data-emvb-arrows")) {
92
+ c.prev = button("Previous slide", "‹");
93
+ c.next = button("Next slide", "›");
94
+ c.prev.addEventListener("click", () => go(c, c.index - 1));
95
+ c.next.addEventListener("click", () => go(c, c.index + 1));
96
+ }
97
+ if (root.hasAttribute("data-emvb-dots")) {
98
+ const dots = document.createElement("div");
99
+ dots.className = "emvb-carousel-dots";
100
+ for (let i = 0; i <= lastStart(c); i++) {
101
+ const dot = button(`Go to slide ${i + 1}`, "");
102
+ dot.addEventListener("click", () => go(c, i, false));
103
+ c.dots.push(dot);
104
+ dots.append(dot);
105
+ }
106
+ controls.append(...present([c.prev, dots, c.next]));
107
+ } else {
108
+ controls.append(...present([c.prev, c.next]));
109
+ }
110
+ if (controls.childElementCount > 0) track.after(controls);
111
+ const seconds = Number(root.dataset["emvbAutoplay"]);
112
+ if (Number.isFinite(seconds) && seconds > 0) autoplay(c, seconds);
113
+ // Swipes and scrolls move the current slide too.
114
+ let frame = 0;
115
+ track.addEventListener("scroll", () => {
116
+ cancelAnimationFrame(frame);
117
+ frame = requestAnimationFrame(() => {
118
+ const first = c.slides[0];
119
+ const step = first?.offsetWidth ?? 0;
120
+ if (step <= 0) return;
121
+ c.index = Math.min(Math.round(track.scrollLeft / step), lastStart(c));
122
+ update(c);
123
+ });
124
+ });
125
+ update(c);
126
+ }
127
+
128
+ function autoplay(c: Carousel, seconds: number): void {
129
+ const reduced = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
130
+ c.stopped = reduced;
131
+ const toggle = button("", "", "emvb-carousel-play");
132
+ const label = () => {
133
+ toggle.textContent = c.stopped ? "Play" : "Pause";
134
+ toggle.setAttribute("aria-label", c.stopped ? "Play slides" : "Pause slides");
135
+ };
136
+ const tick = () => {
137
+ if (!c.stopped && !c.held) go(c, c.index + 1, true);
138
+ };
139
+ toggle.addEventListener("click", () => {
140
+ c.stopped = !c.stopped;
141
+ label();
142
+ });
143
+ label();
144
+ // The rotation control comes before the slides, so keyboard users reach it first.
145
+ const bar = document.createElement("div");
146
+ bar.className = "emvb-carousel-controls emvb-carousel-autoplay";
147
+ bar.append(toggle);
148
+ c.track.before(bar);
149
+ const hold = (held: boolean) => () => {
150
+ c.held = held;
151
+ };
152
+ c.root.addEventListener("pointerenter", hold(true));
153
+ c.root.addEventListener("pointerleave", hold(false));
154
+ c.root.addEventListener("focusin", hold(true));
155
+ c.root.addEventListener("focusout", (event) => {
156
+ if (!c.root.contains(event.relatedTarget as Node | null)) c.held = false;
157
+ });
158
+ c.timer = setInterval(tick, seconds * 1000);
159
+ }
160
+
161
+ export function initCarousels(root: ParentNode = document): void {
162
+ for (const el of root.querySelectorAll<HTMLElement>("section.emvb-carousel")) {
163
+ if (el.dataset["emvbCarouselReady"] !== undefined) continue;
164
+ el.dataset["emvbCarouselReady"] = "";
165
+ setup(el);
166
+ }
167
+ }
@@ -0,0 +1 @@
1
+ export { default as EmVBWidgetRuntimes } from "./EmVBWidgetRuntimes.astro";
@@ -0,0 +1,123 @@
1
+ /**
2
+ * W-1019: the opt-in Gallery lightbox. In each gallery marked `data-emvb-lightbox` every picture
3
+ * becomes a button that opens it large in one native modal <dialog>: Previous and Next (also the
4
+ * arrow keys), a counter that screen readers hear, Close and Escape. Focus goes back to the
5
+ * picture's button when the dialog closes. Without this script the gallery is plain pictures.
6
+ */
7
+
8
+ type Viewer = {
9
+ dialog: HTMLDialogElement;
10
+ image: HTMLImageElement;
11
+ caption: HTMLElement;
12
+ count: HTMLElement;
13
+ prev: HTMLButtonElement;
14
+ next: HTMLButtonElement;
15
+ };
16
+
17
+ type Show = { images: HTMLImageElement[]; index: number; opener: HTMLElement };
18
+
19
+ let viewer: Viewer | undefined;
20
+ let showing: Show | undefined;
21
+
22
+ const captionOf = (image: HTMLImageElement) =>
23
+ image.closest("figure")?.querySelector("figcaption")?.textContent?.trim() ?? "";
24
+
25
+ /** What a picture's button is called: its alt text, else its caption, else its place. */
26
+ export function pictureName(image: HTMLImageElement, index: number, total: number): string {
27
+ return image.alt.trim() || captionOf(image) || `Picture ${index + 1} of ${total}`;
28
+ }
29
+
30
+ function button(label: string, text: string): HTMLButtonElement {
31
+ const el = document.createElement("button");
32
+ el.type = "button";
33
+ el.setAttribute("aria-label", label);
34
+ el.textContent = text;
35
+ return el;
36
+ }
37
+
38
+ function build(doc: Document): Viewer {
39
+ const dialog = doc.createElement("dialog");
40
+ dialog.className = "emvb-lightbox";
41
+ dialog.setAttribute("aria-label", "Picture viewer");
42
+ const figure = doc.createElement("figure");
43
+ figure.className = "emvb-lightbox-figure";
44
+ const image = doc.createElement("img");
45
+ const bar = doc.createElement("div");
46
+ bar.className = "emvb-lightbox-bar";
47
+ const prev = button("Previous picture", "‹");
48
+ const next = button("Next picture", "›");
49
+ const close = button("Close", "×");
50
+ const caption = doc.createElement("figcaption");
51
+ caption.className = "emvb-lightbox-caption";
52
+ const count = doc.createElement("span");
53
+ count.setAttribute("aria-live", "polite");
54
+ caption.append(count);
55
+ bar.append(prev, caption, next, close);
56
+ figure.append(image, bar);
57
+ dialog.append(figure);
58
+ doc.body.append(dialog);
59
+ prev.addEventListener("click", () => step(-1));
60
+ next.addEventListener("click", () => step(1));
61
+ close.addEventListener("click", () => dialog.close());
62
+ dialog.addEventListener("keydown", (event) => {
63
+ if (event.key === "ArrowLeft") step(document.dir === "rtl" ? 1 : -1);
64
+ else if (event.key === "ArrowRight") step(document.dir === "rtl" ? -1 : 1);
65
+ });
66
+ dialog.addEventListener("close", () => {
67
+ showing?.opener.focus();
68
+ showing = undefined;
69
+ });
70
+ return { dialog, image, caption, count, prev, next };
71
+ }
72
+
73
+ function render(): void {
74
+ if (!viewer || !showing) return;
75
+ const { images, index } = showing;
76
+ const source = images[index];
77
+ if (!source) return;
78
+ viewer.image.src = source.currentSrc || source.src;
79
+ viewer.image.alt = source.alt;
80
+ const words = captionOf(source);
81
+ viewer.count.textContent = `${words ? `${words} · ` : ""}${index + 1} of ${images.length}`;
82
+ const single = images.length < 2;
83
+ viewer.prev.hidden = single;
84
+ viewer.next.hidden = single;
85
+ }
86
+
87
+ function step(by: number): void {
88
+ if (!showing) return;
89
+ const total = showing.images.length;
90
+ showing.index = (showing.index + by + total) % total;
91
+ render();
92
+ }
93
+
94
+ function open(images: HTMLImageElement[], index: number, opener: HTMLElement): void {
95
+ viewer ??= build(opener.ownerDocument);
96
+ showing = { images, index, opener };
97
+ render();
98
+ if (!viewer.dialog.open) viewer.dialog.showModal();
99
+ }
100
+
101
+ export function initLightbox(root: ParentNode = document): void {
102
+ for (const list of root.querySelectorAll<HTMLElement>("[data-emvb-lightbox]")) {
103
+ if (list.dataset["emvbLightboxReady"] !== undefined) continue;
104
+ list.dataset["emvbLightboxReady"] = "";
105
+ const images = [
106
+ ...list.querySelectorAll<HTMLImageElement>(":scope > .emvb-gallery-image > figure > img"),
107
+ ];
108
+ images.forEach((image, index) => {
109
+ const opener = button(`View larger: ${pictureName(image, index, images.length)}`, "");
110
+ opener.className = "emvb-gallery-open";
111
+ image.replaceWith(opener);
112
+ opener.append(image);
113
+ opener.addEventListener("click", () => open(images, index, opener));
114
+ });
115
+ }
116
+ }
117
+
118
+ /** Test seam: forget the shared viewer between tests. */
119
+ export function resetLightboxForTest(): void {
120
+ viewer?.dialog.remove();
121
+ viewer = undefined;
122
+ showing = undefined;
123
+ }
package/src/constants.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PLUGIN_ID = "emvb";
2
- export const PLUGIN_VERSION = "1.0.0";
2
+ export const PLUGIN_VERSION = "1.2.0";
3
3
  export const PACKAGE_NAME = "@perkyzz/emvb";
4
4
  export const ADMIN_ENTRY = `${PACKAGE_NAME}/admin`;
5
5
  export const PAGES_COLLECTION = "emvb_pages";
@@ -6,6 +6,9 @@ import { boxBecomesLink } from "../render/extras.ts";
6
6
  import { ICON_ANIMATION_LIMIT_MS, iconAnimationRuns } from "../icons/animation-runs.ts";
7
7
  import { updateNode } from "../tree-ops.ts";
8
8
  import { DEVICES } from "../theme/popup-rules.ts";
9
+ import { hiddenOnEveryDevice } from "../design/devices.ts";
10
+ import { sanitizeHref } from "../sanitize/href.ts";
11
+ import { SOCIAL_COLORS, SOCIAL_NAMES } from "../elements/widgets.ts";
9
12
 
10
13
  /**
11
14
  * W-572: text as a screen reader says it: invisible format characters (zero-width space, word
@@ -41,7 +44,8 @@ export type A11yIssue = {
41
44
  | "control-name"
42
45
  | "empty-heading"
43
46
  | "landmark-name"
44
- | "motion";
47
+ | "motion"
48
+ | "empty-alert";
45
49
  severity: "error" | "warning";
46
50
  message: string;
47
51
  /** The one-click fix, when there is a safe one. */
@@ -255,7 +259,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
255
259
  const menuNames = DEVICES.map(() => new Set<string>());
256
260
  const walk = (node: LayoutNode, bg: string | undefined, color: string | undefined): void => {
257
261
  // W-413: an element hidden on every device (and what's inside it) is never shown or read.
258
- if (node !== layout.root && DEVICES.every((d) => node.hiddenOn?.includes(d))) {
262
+ if (node !== layout.root && hiddenOnEveryDevice(node)) {
259
263
  return;
260
264
  }
261
265
  const variant = node.variant;
@@ -302,7 +306,12 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
302
306
  severity: "error",
303
307
  message: "This image is a link but is marked decorative, so the link has no name.",
304
308
  });
305
- } else if (node.type === "image" && props["decorative"] !== true) {
309
+ } else if (
310
+ // W-1021: an image box's picture needs real alt text as an Image does, once it has one.
311
+ (node.type === "image" ||
312
+ ((node.type === "image-box" || node.type === "gallery-image") && spoken(props["src"]))) &&
313
+ props["decorative"] !== true
314
+ ) {
306
315
  const alt = typeof props["alt"] === "string" ? spoken(props["alt"]) : "";
307
316
  if (USELESS_ALT.test(alt)) {
308
317
  add({
@@ -458,6 +467,97 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
458
467
  if (shownOn[i]) names.add(key);
459
468
  });
460
469
  }
470
+ // W-1023: a Rating is an image of stars; its screen-reader text is the only way to hear the
471
+ // rating, so a custom one has to say it ({value}, or the number written out).
472
+ if (node.type === "rating") {
473
+ const label = spoken(props["label"]);
474
+ if (label && !label.includes("{value}") && !/\d/.test(label)) {
475
+ add({
476
+ nodeId: node.id,
477
+ rule: "image-alt",
478
+ severity: "warning",
479
+ message:
480
+ "This rating's text for screen readers doesn't say the rating. Add {value}, such as \"Rated {value} out of {max}\".",
481
+ });
482
+ }
483
+ }
484
+ // W-1020: a box's link is its title; with no title the link is left out of the page.
485
+ if (
486
+ (node.type === "icon-box" || node.type === "image-box") &&
487
+ spoken(props["href"]) &&
488
+ !spoken(props["title"]) &&
489
+ !node.bind
490
+ ) {
491
+ add({
492
+ nodeId: node.id,
493
+ rule: "link-name",
494
+ severity: "warning",
495
+ message:
496
+ "This box has a link but no title. The title is the link, so the link is left out.",
497
+ });
498
+ }
499
+ // W-1022: a testimonial without words is an empty quotation.
500
+ if (node.type === "testimonial" && !spoken(props["quote"]) && !node.bind) {
501
+ add({
502
+ nodeId: node.id,
503
+ rule: "empty-alert",
504
+ severity: "warning",
505
+ message: "This testimonial has no quote, so screen readers find an empty quotation.",
506
+ });
507
+ }
508
+ // W-1024: a Social link without a usable address shows a dimmed icon that goes nowhere.
509
+ if (node.type === "social-link" && !node.bind) {
510
+ const href = typeof props["href"] === "string" ? props["href"].trim() : "";
511
+ if (!href || !sanitizeHref(href)) {
512
+ add({
513
+ nodeId: node.id,
514
+ rule: "link-name",
515
+ severity: "warning",
516
+ message:
517
+ "This social link has no address it can use, so it shows a dimmed icon and links nowhere.",
518
+ });
519
+ }
520
+ }
521
+ // W-1024: some networks' own colours are too faint on white for an icon (under 3:1).
522
+ if (node.type === "social-icons" && props["brandColors"] === true && isParentNode(node)) {
523
+ const faint = node.children
524
+ .map((child) => (child.props as { network?: string }).network)
525
+ .filter(
526
+ (network): network is keyof typeof SOCIAL_COLORS =>
527
+ typeof network === "string" &&
528
+ network in SOCIAL_COLORS &&
529
+ contrastRatio(SOCIAL_COLORS[network as keyof typeof SOCIAL_COLORS], "#ffffff") < 3,
530
+ );
531
+ if (faint.length > 0) {
532
+ add({
533
+ nodeId: node.id,
534
+ rule: "contrast",
535
+ severity: "warning",
536
+ message: `On a light background, ${[...new Set(faint)].map((n) => SOCIAL_NAMES[n]).join(", ")} in brand colours is under 3:1, as an icon or as a badge behind a white icon. Turn Brand colours off or put the icons on a dark background.`,
537
+ });
538
+ }
539
+ }
540
+ // W-1018: slides that move on by themselves faster than about 5 seconds are hard to read.
541
+ if (node.type === "carousel" && props["autoplay"] === true) {
542
+ const seconds = typeof props["interval"] === "number" ? props["interval"] : 6;
543
+ if (seconds < 5) {
544
+ add({
545
+ nodeId: node.id,
546
+ rule: "motion",
547
+ severity: "warning",
548
+ message: `Slides change every ${seconds} seconds; many people need longer to read them. Use 5 seconds or more.`,
549
+ });
550
+ }
551
+ }
552
+ // W-1025: a notice with neither title nor text is a coloured box screen readers call a note.
553
+ if (node.type === "alert" && !spoken(props["title"]) && !spoken(props["text"]) && !node.bind) {
554
+ add({
555
+ nodeId: node.id,
556
+ rule: "empty-alert",
557
+ severity: "warning",
558
+ message: "This alert has no title or text, so it shows an empty box and says nothing.",
559
+ });
560
+ }
461
561
  // W-419: an empty heading still shows up in screen readers' heading list, with nothing to say.
462
562
  if (node.type === "heading" && !spoken(props["text"]) && !node.bind) {
463
563
  add({
@@ -1,4 +1,11 @@
1
- import { MAX_DEPTH, MAX_NODES, MAX_TABS } from "./limits.ts";
1
+ import {
2
+ MAX_CAROUSEL_SLIDES,
3
+ MAX_DEPTH,
4
+ MAX_GALLERY_IMAGES,
5
+ MAX_NODES,
6
+ MAX_SOCIAL_LINKS,
7
+ MAX_TABS,
8
+ } from "./limits.ts";
2
9
  import {
3
10
  isContainerNode,
4
11
  isFormFieldType,
@@ -64,6 +71,15 @@ export const REASONS = {
64
71
  onlyAccordionItems: "An accordion can only hold accordion items.",
65
72
  itemOutsideMenu: "Menu items can only go inside a Menu.",
66
73
  onlyMenuItems: "A menu can only hold menu items.",
74
+ linkOutsideSocial: "Social links can only go inside Social icons.",
75
+ onlySocialLinks: "Social icons can only hold social links.",
76
+ tooManySocialLinks: `Social icons can hold up to ${MAX_SOCIAL_LINKS} links.`,
77
+ imageOutsideGallery: "Gallery images can only go inside a Gallery.",
78
+ onlyGalleryImages: "A gallery can only hold gallery images.",
79
+ tooManyGalleryImages: `A gallery can hold up to ${MAX_GALLERY_IMAGES} pictures.`,
80
+ slideOutsideCarousel: "Slides can only go inside a Carousel.",
81
+ onlySlides: "A carousel can only hold slides.",
82
+ tooManySlides: `A carousel can hold up to ${MAX_CAROUSEL_SLIDES} slides.`,
67
83
  emptyOutsideLoop: "An Empty state can only go inside a Loop.",
68
84
  } as const;
69
85
 
@@ -143,6 +159,22 @@ export function parentChildRefusal(
143
159
  return REASONS.itemOutsideMenu;
144
160
  }
145
161
  if (parent.type === "menu" && child.type !== "menu-item") return REASONS.onlyMenuItems;
162
+ if (child.type === "social-link" && parent.type !== "social-icons") {
163
+ return REASONS.linkOutsideSocial;
164
+ }
165
+ if (parent.type === "social-icons" && child.type !== "social-link") {
166
+ return REASONS.onlySocialLinks;
167
+ }
168
+ if (child.type === "gallery-image" && parent.type !== "gallery") {
169
+ return REASONS.imageOutsideGallery;
170
+ }
171
+ if (parent.type === "gallery" && child.type !== "gallery-image") {
172
+ return REASONS.onlyGalleryImages;
173
+ }
174
+ if (child.type === "carousel-slide" && parent.type !== "carousel") {
175
+ return REASONS.slideOutsideCarousel;
176
+ }
177
+ if (parent.type === "carousel" && child.type !== "carousel-slide") return REASONS.onlySlides;
146
178
  if (isFormNode(child) && inForm) return REASONS.nestedForm;
147
179
  if (isFormFieldType(child.type) && !inForm) return REASONS.fieldOutsideForm;
148
180
  return undefined;
@@ -159,6 +191,30 @@ const DROP_RULES: [breaks: (drop: Drop) => boolean, reason: string][] = [
159
191
  nodeChildren(into.node).length >= MAX_TABS,
160
192
  REASONS.tooManyTabs,
161
193
  ],
194
+ // W-1024: as Tabs, a full Social icons takes no new link; moving within it is fine.
195
+ [
196
+ ({ node, into }) =>
197
+ into.node.type === "social-icons" &&
198
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
199
+ nodeChildren(into.node).length >= MAX_SOCIAL_LINKS,
200
+ REASONS.tooManySocialLinks,
201
+ ],
202
+ // W-1019: a full Gallery takes no new picture; moving within it is fine.
203
+ [
204
+ ({ node, into }) =>
205
+ into.node.type === "gallery" &&
206
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
207
+ nodeChildren(into.node).length >= MAX_GALLERY_IMAGES,
208
+ REASONS.tooManyGalleryImages,
209
+ ],
210
+ // W-1018: a full Carousel takes no new slide; moving within it is fine.
211
+ [
212
+ ({ node, into }) =>
213
+ into.node.type === "carousel" &&
214
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
215
+ nodeChildren(into.node).length >= MAX_CAROUSEL_SLIDES,
216
+ REASONS.tooManySlides,
217
+ ],
162
218
  [({ node, into }) => into.depth + height(node) > MAX_DEPTH, REASONS.tooDeep],
163
219
  [
164
220
  ({ node, layout, isNew }) => isNew && size(layout.root) + size(node) > MAX_NODES,
@@ -8,24 +8,27 @@ import { z } from "zod";
8
8
  * JSON Schema output (MCP `tools/list`) is the plain array, with minItems/maxItems.
9
9
  */
10
10
  export function boundedArray<T extends z.ZodType>(item: T, max: number, min = 0) {
11
- return z
12
- .unknown()
13
- .check((ctx) => {
14
- const value = ctx.value;
15
- if (!Array.isArray(value)) return;
16
- if (value.length > max || value.length < min) {
11
+ // S-03: a transform in front (not a check) keeps the JSON Schema the plain array for input
12
+ // and output alike, so the published layout schemas are unchanged.
13
+ const schema = z
14
+ .transform((value: unknown, ctx) => {
15
+ if (Array.isArray(value) && value.length > max) {
17
16
  ctx.issues.push({
18
- code: value.length > max ? "too_big" : "too_small",
17
+ code: "too_big",
19
18
  origin: "array",
20
- ...(value.length > max ? { maximum: max } : { minimum: min }),
19
+ maximum: max,
21
20
  inclusive: true,
22
21
  input: value,
23
- message:
24
- value.length > max
25
- ? `Too many items: at most ${max}.`
26
- : `Too few items: at least ${min}.`,
22
+ message: `Too many items: at most ${max}.`,
27
23
  } as never);
24
+ return z.NEVER;
28
25
  }
26
+ return value;
29
27
  })
30
- .pipe(z.array(item).min(min).max(max));
28
+ .pipe((min > 0 ? z.array(item).min(min) : z.array(item)).max(max));
29
+ // A transform counts as an optional input, which would make a tuple slot holding this array
30
+ // optional in the JSON Schema; the array itself is required.
31
+ // oxlint-disable-next-line no-underscore-dangle -- zod keeps the flag on its internals
32
+ Object.defineProperty(schema._zod, "optin", { value: undefined, configurable: true });
33
+ return schema;
31
34
  }
@@ -2,7 +2,7 @@ import { MAX_UNKNOWN_DEPTH, MAX_UNKNOWN_KEYS, UNKNOWN_KEY_PATTERN } from "./limi
2
2
  import { flattenMotion, isFlatMotionKey, withoutStrayMotionKeys } from "./migrate/v18.ts";
3
3
  import { isRecord } from "./record.ts";
4
4
  import { KNOWN_NODE_SCHEMAS } from "./schema/layout.ts";
5
- import { FlatStyleProps, StyleProps } from "./schema/style.ts";
5
+ import { FlatStyleProps, OwnStyle, StyleProps, WideStyle } from "./schema/style.ts";
6
6
 
7
7
  /**
8
8
  * D-065 (W-925, contract 1.0): a 1.x document may carry keys this version does not know, on a
@@ -30,6 +30,9 @@ for (const schema of KNOWN_NODE_SCHEMAS) {
30
30
  if (typeof type === "string") PROP_KEYS.set(type, shapeKeys(shape["props"]));
31
31
  }
32
32
  const STYLE_KEYS = shapeKeys(StyleProps);
33
+ /** W-959: an element's or class's own style also knows `wide`, whose record is open too. */
34
+ const OWN_STYLE_KEYS = shapeKeys(OwnStyle);
35
+ const WIDE_KEYS = shapeKeys(WideStyle);
33
36
  const FLAT_STYLE_KEYS = shapeKeys(FlatStyleProps);
34
37
  const STATES = ["hover", "focus", "active"] as const;
35
38
  const DEVICES = ["laptop", "tablet", "mobile"] as const;
@@ -49,7 +52,10 @@ function depthOf(value: unknown, limit: number): number {
49
52
  if (typeof v !== "object" || v === null) continue;
50
53
  max = Math.max(max, depth);
51
54
  if (max > limit) return max;
52
- for (const child of Object.values(v)) stack.push({ value: child, depth: depth + 1 });
55
+ // S-03: only objects go on the stack; a long array of numbers held one entry per item.
56
+ for (const child of Array.isArray(v) ? v : Object.values(v))
57
+ if (typeof child === "object" && child !== null)
58
+ stack.push({ value: child, depth: depth + 1 });
53
59
  }
54
60
  return max;
55
61
  }
@@ -92,7 +98,9 @@ class Splitter {
92
98
  }
93
99
 
94
100
  styleRecords(owner: Record<string, unknown>, path: Path): void {
95
- this.take(owner["style"], STYLE_KEYS, [...path, "style"]);
101
+ this.take(owner["style"], OWN_STYLE_KEYS, [...path, "style"]);
102
+ const style = owner["style"];
103
+ if (isRecord(style)) this.take(style["wide"], WIDE_KEYS, [...path, "style", "wide"]);
96
104
  const states = owner["states"];
97
105
  if (isRecord(states)) {
98
106
  // `motion` is a known key here so the schema refuses it in a state, not kept as unknown.
@@ -199,6 +207,20 @@ export function renderableStyle<T>(style: T): T {
199
207
  return inFlatOrder(known(flattenMotion(withoutStrayMotionKeys(style)), FLAT_STYLE_KEYS), style);
200
208
  }
201
209
 
210
+ /**
211
+ * W-959: the renderer reads Wide screen as one more device: `style.wide` becomes `devices.wide`
212
+ * (known keys only) and its `hidden` becomes `wideHidden`. Without `style.wide` nothing changes.
213
+ */
214
+ function wideAsDevice(owner: Record<string, unknown>, out: Record<string, unknown>): void {
215
+ const style = owner["style"];
216
+ const wide = isRecord(style) ? style["wide"] : undefined;
217
+ if (!isRecord(wide)) return;
218
+ const { hidden, ...rest } = wide;
219
+ const devices = isRecord(out["devices"]) ? out["devices"] : {};
220
+ if (Object.keys(rest).length > 0) out["devices"] = { ...devices, wide: renderableStyle(rest) };
221
+ if (typeof hidden === "boolean") out["wideHidden"] = hidden;
222
+ }
223
+
202
224
  function renderableStyles<T extends Record<string, unknown>>(owner: T): T {
203
225
  const out: Record<string, unknown> = { ...owner };
204
226
  if ("style" in owner) out["style"] = renderableStyle(owner["style"]);
@@ -217,6 +239,7 @@ function renderableStyles<T extends Record<string, unknown>>(owner: T): T {
217
239
  for (const [device, style] of Object.entries(devices)) next[device] = renderableStyle(style);
218
240
  out["devices"] = next;
219
241
  }
242
+ wideAsDevice(owner, out);
220
243
  return out as T;
221
244
  }
222
245