@perkyzz/emvb 0.4.0 → 0.6.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 (127) hide show
  1. package/README.md +23 -3
  2. package/THIRD_PARTY_NOTICES.md +23 -1
  3. package/licenses/exif-js.LICENSE +21 -0
  4. package/licenses/fflate.LICENSE +21 -0
  5. package/licenses/glfx.js.LICENSE +19 -0
  6. package/licenses/mini-photo-editor.LICENSE +21 -0
  7. package/licenses/photocn.LICENSE +21 -0
  8. package/package.json +5 -3
  9. package/src/admin/agents-api.ts +39 -0
  10. package/src/admin/editor/CommandPalette.tsx +43 -2
  11. package/src/admin/editor/Editor.tsx +33 -0
  12. package/src/admin/editor/Timeline.tsx +108 -6
  13. package/src/admin/editor/collection-previews.ts +6 -1
  14. package/src/admin/editor/editor-chrome.tsx +49 -0
  15. package/src/admin/editor/editor-commands.ts +13 -0
  16. package/src/admin/editor/editor-css.ts +7 -0
  17. package/src/admin/editor/feature-css.ts +22 -3
  18. package/src/admin/editor/palette.ts +6 -2
  19. package/src/admin/editor/panels/ColorControl.tsx +24 -12
  20. package/src/admin/editor/panels/ElementPanel.tsx +1 -1
  21. package/src/admin/editor/panels/LayersPanel.tsx +13 -3
  22. package/src/admin/editor/panels/TokenScales.tsx +4 -2
  23. package/src/admin/editor/panels/VariableSection.tsx +5 -3
  24. package/src/admin/editor/panels/color-space.ts +12 -1
  25. package/src/admin/editor/panels/settings/AdvancedFields.tsx +84 -28
  26. package/src/admin/editor/panels/settings/AudienceEditor.tsx +42 -4
  27. package/src/admin/editor/panels/settings/DraftTextField.tsx +38 -9
  28. package/src/admin/editor/panels/settings/FieldControl.tsx +24 -7
  29. package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
  30. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
  31. package/src/admin/editor/panels/settings/MediaPicker.tsx +156 -7
  32. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
  33. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +76 -0
  34. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  35. package/src/admin/editor/panels/settings/link-rules.ts +19 -0
  36. package/src/admin/editor/panels/settings/number-input.ts +11 -0
  37. package/src/admin/editor/panels/settings/query-style.ts +65 -0
  38. package/src/admin/editor/panels/variable-values.ts +18 -2
  39. package/src/admin/editor/remote-change.ts +67 -0
  40. package/src/admin/editor/store.ts +7 -3
  41. package/src/admin/image-editor/BlurFocus.tsx +112 -0
  42. package/src/admin/image-editor/Canvas.tsx +261 -0
  43. package/src/admin/image-editor/CropOverlay.tsx +390 -0
  44. package/src/admin/image-editor/CurvesPanel.tsx +394 -0
  45. package/src/admin/image-editor/ExportDialog.tsx +354 -0
  46. package/src/admin/image-editor/ImageEditButton.tsx +83 -0
  47. package/src/admin/image-editor/ImageEditorDialog.tsx +786 -0
  48. package/src/admin/image-editor/MetadataPanel.tsx +183 -0
  49. package/src/admin/image-editor/announce.tsx +65 -0
  50. package/src/admin/image-editor/crop-geometry.ts +161 -0
  51. package/src/admin/image-editor/curve-math.ts +177 -0
  52. package/src/admin/image-editor/data-url-fetch.ts +59 -0
  53. package/src/admin/image-editor/engine.ts +55 -0
  54. package/src/admin/image-editor/exif.ts +82 -0
  55. package/src/admin/image-editor/flatten.ts +54 -0
  56. package/src/admin/image-editor/gpu-fit.ts +81 -0
  57. package/src/admin/image-editor/image-editor-css.ts +398 -0
  58. package/src/admin/image-editor/load.ts +109 -0
  59. package/src/admin/image-editor/panels.tsx +287 -0
  60. package/src/admin/image-editor/parts.tsx +565 -0
  61. package/src/admin/image-editor/save.ts +125 -0
  62. package/src/admin/image-editor/tone-panels.tsx +338 -0
  63. package/src/admin/image-editor/tools.ts +59 -0
  64. package/src/admin/image-editor/worker.ts +111 -0
  65. package/src/admin/index.tsx +3 -1
  66. package/src/admin/media-api.ts +132 -2
  67. package/src/admin/pages/AgentsPage.tsx +274 -0
  68. package/src/admin/ui.ts +33 -0
  69. package/src/astro/EmVBPage.astro +11 -2
  70. package/src/astro/floats/runtime.ts +10 -0
  71. package/src/astro/popups/runtime.ts +15 -0
  72. package/src/astro/render.ts +3 -0
  73. package/src/astro/resolve-theme.ts +15 -4
  74. package/src/astro/tabs/runtime.ts +60 -1
  75. package/src/astro/visitor.ts +4 -3
  76. package/src/constants.ts +1 -1
  77. package/src/core/a11y/audit.ts +202 -26
  78. package/src/core/arrange.ts +13 -3
  79. package/src/core/css/generate.ts +9 -1
  80. package/src/core/data/bindings.ts +12 -6
  81. package/src/core/design/classes.ts +5 -3
  82. package/src/core/design/diff.ts +3 -1
  83. package/src/core/design/merge.ts +3 -1
  84. package/src/core/design/transfer.ts +13 -2
  85. package/src/core/design/variables.ts +2 -1
  86. package/src/core/elements/dynamic-elements.ts +9 -1
  87. package/src/core/elements/form-elements.ts +18 -3
  88. package/src/core/elements/index.ts +39 -11
  89. package/src/core/elements/plain-text.ts +2 -2
  90. package/src/core/forms/binding.ts +148 -1
  91. package/src/core/history/diff.ts +32 -4
  92. package/src/core/image-edit/schema.ts +145 -0
  93. package/src/core/image-edit/summary.ts +58 -0
  94. package/src/core/index.ts +14 -0
  95. package/src/core/limits.ts +10 -0
  96. package/src/core/migrate/index.ts +3 -1
  97. package/src/core/perf/meter.ts +9 -1
  98. package/src/core/render/dynamic-post.ts +23 -6
  99. package/src/core/render/form.ts +36 -11
  100. package/src/core/render/index.ts +75 -15
  101. package/src/core/render/pagination.ts +21 -2
  102. package/src/core/sanitize/embed-url.ts +7 -1
  103. package/src/core/sanitize/href.ts +13 -1
  104. package/src/core/schema/descriptors.ts +4 -1
  105. package/src/core/schema/layout.ts +21 -4
  106. package/src/core/share/link.ts +9 -3
  107. package/src/core/stable-json.ts +15 -0
  108. package/src/core/theme/dynamic.ts +32 -24
  109. package/src/core/theme/pagination.ts +30 -3
  110. package/src/core/theme/popup-rules.ts +10 -5
  111. package/src/mcp/errors.ts +44 -0
  112. package/src/mcp/index.ts +4 -0
  113. package/src/mcp/ports.ts +85 -0
  114. package/src/mcp/prompts.ts +76 -0
  115. package/src/mcp/publish.ts +60 -0
  116. package/src/mcp/queue.ts +19 -0
  117. package/src/mcp/rate-limit.ts +80 -0
  118. package/src/mcp/read.ts +486 -0
  119. package/src/mcp/refs.ts +84 -0
  120. package/src/mcp/settings.ts +18 -0
  121. package/src/mcp/tools.ts +265 -0
  122. package/src/mcp/write.ts +664 -0
  123. package/src/server/agent-settings.ts +159 -0
  124. package/src/server/design-routes.ts +71 -17
  125. package/src/server/icon-routes.ts +13 -6
  126. package/src/server/mcp-routes.ts +323 -0
  127. package/src/server/plugin.ts +32 -2
@@ -21,7 +21,11 @@ export type A11yIssue = {
21
21
  | "vague-link"
22
22
  | "contrast"
23
23
  | "hidden-focusable"
24
- | "new-tab";
24
+ | "new-tab"
25
+ | "image-sizes"
26
+ | "control-name"
27
+ | "empty-heading"
28
+ | "landmark-name";
25
29
  severity: "error" | "warning";
26
30
  message: string;
27
31
  /** The one-click fix, when there is a safe one. */
@@ -34,10 +38,15 @@ export type A11yReport = { score: number; issues: A11yIssue[] };
34
38
  const WEIGHT = { error: 12, warning: 4 } as const;
35
39
 
36
40
  /** Alt text that names a file or says nothing a screen reader user can use. */
41
+ // W-431: camera and screenshot file names as people get them, spaces included
42
+ // ("Screenshot 2026-10-01 at 10.00.00", "WhatsApp Image 2024-…"), not only with _ or -.
37
43
  const USELESS_ALT =
38
- /^(?:image|img|photo|picture|graphic|logo|icon|untitled|\s*)$|\.(?:jpe?g|png|gif|webp|avif|svg)$|^(?:img|dsc|pxl|screenshot)[_-]?\d+/i;
44
+ /^(?:image|img|photo|picture|graphic|logo|icon|untitled|\s*)$|\.(?:jpe?g|png|gif|webp|avif|svg)$|^(?:img|dsc|pxl|screen ?shot|whatsapp image)[\s_-]?\d+/i;
39
45
  /** Link text that makes no sense out of context. */
40
- const VAGUE = /^(?:click here|here|read more|more|learn more|link|this|go)\.?$/i;
46
+ /** W-411: trailing punctuation and arrows ("Read more…", "Learn more →", "Click here!") too. */
47
+ // W-432: the other common "more" phrasings ("See more", "More info", "Continue reading"…).
48
+ const VAGUE =
49
+ /^(?:click here|here|read more|more|learn more|link|this|go|see more|view more|more info(?:rmation)?|details|find out more|continue reading|read more here|click here to (?:read|learn) more)\s*[.!…:»›→>\u2192\u203a\u00bb-]*$/i;
41
50
  const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
42
51
 
43
52
  /** A style colour as hex: literal, or a site colour variable; undefined when unknown. */
@@ -66,6 +75,24 @@ const lum = (hex: string) => {
66
75
  return 0.2126 * r + 0.7152 * g + 0.0722 * bl;
67
76
  };
68
77
 
78
+ /**
79
+ * W-412: `top` painted over opaque `bottom`, as 6-digit hex. A colour's alpha (#rgba,
80
+ * #rrggbbaa) used to be dropped, so faint text counted as full strength.
81
+ */
82
+ function over(top: string, bottom: string, fade = 1): string {
83
+ let h = top.slice(1);
84
+ if (h.length <= 4) h = [...h].map((c) => c + c).join("");
85
+ // W-415: `fade` is the element's opacity times its ancestors'.
86
+ const alpha = (h.length === 8 ? Number.parseInt(h.slice(6, 8), 16) / 255 : 1) * fade;
87
+ if (alpha >= 1) return `#${h.slice(0, 6)}`;
88
+ const a = rgb(`#${h.slice(0, 6)}`);
89
+ const b = rgb(bottom);
90
+ return `#${a
91
+ .map((c, i) => Math.round(c * alpha + (b[i] ?? 0) * (1 - alpha)))
92
+ .map((c) => c.toString(16).padStart(2, "0"))
93
+ .join("")}`;
94
+ }
95
+
69
96
  /** WCAG contrast ratio between two hex colours, 1–21. */
70
97
  export function contrastRatio(a: string, b: string): number {
71
98
  const [hi, lo] = [lum(a), lum(b)].toSorted((x, y) => y - x) as [number, number];
@@ -81,6 +108,7 @@ const TEXT_TYPES = new Set([
81
108
  "post-title",
82
109
  "post-excerpt",
83
110
  ]);
111
+ const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
84
112
  const LINKISH = new Set(["link", "button", "menu-item"]);
85
113
 
86
114
  function px(value: unknown): number | undefined {
@@ -110,20 +138,42 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
110
138
  const add = (issue: Omit<A11yIssue, "id">) =>
111
139
  issues.push({ ...issue, id: `${issue.rule}:${issue.nodeId}` });
112
140
  let lastLevel = 0;
113
- let h1s = 0;
141
+ // W-444: H1s counted per device, so a desktop H1 and a mobile H1 that swap places aren't two.
142
+ const DEVICES = ["desktop", "tablet", "mobile"] as const;
143
+ let h1s = [0, 0, 0];
144
+ let shownOn = [true, true, true];
145
+ // W-446: aria-hidden on a box hides everything inside it from screen readers, links included.
146
+ let ariaHiddenAbove = false;
114
147
  // W-312 variants are alternatives: B is judged as if it stood where A does, so a page whose
115
148
  // A/B pair each have an H1 doesn't count two.
116
- const beforeA = new Map<string, [number, number]>();
117
- const afterA = new Map<string, [number, number]>();
149
+ const beforeA = new Map<string, [number[], number]>();
150
+ const afterA = new Map<string, [number[], number]>();
151
+ let fade = 1;
152
+ // W-445: per device, like H1s, so a desktop menu and a mobile menu may share a name.
153
+ const menuNames = [new Set<string>(), new Set<string>(), new Set<string>()];
118
154
  const walk = (node: LayoutNode, bg: string | undefined, color: string | undefined): void => {
155
+ // W-413: an element hidden on every device (and what's inside it) is never shown or read.
156
+ if (
157
+ node !== layout.root &&
158
+ (["desktop", "tablet", "mobile"] as const).every((d) => node.hiddenOn?.includes(d))
159
+ ) {
160
+ return;
161
+ }
119
162
  const variant = node.variant;
120
- if (variant?.arm === "a") beforeA.set(variant.test, [h1s, lastLevel]);
163
+ if (variant?.arm === "a") beforeA.set(variant.test, [[...h1s], lastLevel]);
121
164
  const before = variant?.arm === "b" ? beforeA.get(variant.test) : undefined;
122
- if (before) [h1s, lastLevel] = before;
165
+ if (before) [h1s, lastLevel] = [[...before[0]], before[1]];
166
+ const outerFade = fade;
167
+ const opacity = (node.style as { opacity?: unknown } | undefined)?.opacity;
168
+ if (typeof opacity === "number" && opacity >= 0 && opacity < 1) fade *= opacity;
169
+ const outerShown = shownOn;
170
+ shownOn = shownOn.map((shown, i) => shown && !node.hiddenOn?.includes(DEVICES[i] ?? "desktop"));
123
171
  visitNode(node, bg, color);
124
- if (variant?.arm === "a") afterA.set(variant.test, [h1s, lastLevel]);
172
+ fade = outerFade;
173
+ shownOn = outerShown;
174
+ if (variant?.arm === "a") afterA.set(variant.test, [[...h1s], lastLevel]);
125
175
  const after = variant?.arm === "b" ? afterA.get(variant.test) : undefined;
126
- if (after) [h1s, lastLevel] = after;
176
+ if (after) [h1s, lastLevel] = [[...after[0]], after[1]];
127
177
  };
128
178
  const visitNode = (node: LayoutNode, bg: string | undefined, color: string | undefined): void => {
129
179
  const props = node.props as Record<string, unknown>;
@@ -132,9 +182,20 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
132
182
  | undefined;
133
183
  // A background image hides the colour behind the text: contrast can't be judged below it.
134
184
  const ownBg = style?.backgroundImage ? "unknown" : hexOf(style?.backgroundColor, design);
135
- const nextBg = ownBg ?? bg;
185
+ const nextBg =
186
+ ownBg && ownBg !== "unknown" && bg && bg !== "unknown" ? over(ownBg, bg) : (ownBg ?? bg);
136
187
  const nextColor = hexOf(style?.color, design) ?? color;
137
- if (node.type === "image" && props["decorative"] !== true) {
188
+ // W-386: a linked image's alt text is the link's name, so it can't be decorative.
189
+ const imageLinked =
190
+ node.type === "image" && typeof props["href"] === "string" && props["href"].trim() !== "";
191
+ if (node.type === "image" && imageLinked && props["decorative"] === true) {
192
+ add({
193
+ nodeId: node.id,
194
+ rule: "link-name",
195
+ severity: "error",
196
+ message: "This image is a link but is marked decorative, so the link has no name.",
197
+ });
198
+ } else if (node.type === "image" && props["decorative"] !== true) {
138
199
  const alt = typeof props["alt"] === "string" ? props["alt"].trim() : "";
139
200
  if (USELESS_ALT.test(alt)) {
140
201
  add({
@@ -144,16 +205,106 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
144
205
  message: alt
145
206
  ? `The alt text "${alt.slice(0, 40)}" doesn't describe the image.`
146
207
  : "This image has no alt text.",
147
- fix: { kind: "decorative" },
148
- fixLabel: "Mark as decorative",
208
+ ...(imageLinked
209
+ ? {}
210
+ : { fix: { kind: "decorative" as const }, fixLabel: "Mark as decorative" }),
211
+ });
212
+ }
213
+ }
214
+ // W-403: with extra sizes but no Width, the main image is left out of srcset, so wide screens
215
+ // can only get the listed copies.
216
+ if (node.type === "image" && Array.isArray(props["sources"]) && props["sources"].length > 0) {
217
+ const width = props["width"];
218
+ const widthSet = typeof width === "number" && Number.isInteger(width) && width >= 1;
219
+ const mainListed = (props["sources"] as { src?: unknown }[]).some(
220
+ (s) => typeof s?.src === "string" && s.src === props["src"],
221
+ );
222
+ if (!widthSet && !mainListed) {
223
+ add({
224
+ nodeId: node.id,
225
+ rule: "image-sizes",
226
+ severity: "warning",
227
+ message:
228
+ "This image has extra sizes but no Width (px), so the main image is left out of the list the browser picks from.",
149
229
  });
150
230
  }
151
231
  }
232
+ if (
233
+ imageLinked &&
234
+ props["newTab"] === true &&
235
+ !/new (tab|window)/i.test(String(props["alt"] ?? ""))
236
+ ) {
237
+ add({
238
+ nodeId: node.id,
239
+ rule: "new-tab",
240
+ severity: "warning",
241
+ message: "This image link opens a new tab without saying so; say so in the alt text.",
242
+ });
243
+ }
244
+ // W-408: a blank tab label or accordion title renders a tab or summary with no name.
245
+ // W-416: a form field with no label (a placeholder is not one: it goes once you type).
246
+ if (FIELD_TYPES.has(node.type) && !String(props["label"] ?? "").trim() && !node.bind) {
247
+ add({
248
+ nodeId: node.id,
249
+ rule: "control-name",
250
+ severity: "error",
251
+ message: String(props["placeholder"] ?? "").trim()
252
+ ? "This field has only a placeholder, which disappears once you type; give it a label."
253
+ : "This field has no label, so screen readers can't say what it's for.",
254
+ });
255
+ }
256
+ const NAME_PROP = {
257
+ "tab-panel": "label",
258
+ "accordion-item": "summary",
259
+ video: "title",
260
+ } as const;
261
+ if (node.type === "tab-panel" || node.type === "accordion-item" || node.type === "video") {
262
+ const name = String(props[NAME_PROP[node.type]] ?? "").trim();
263
+ if (!name && !node.bind) {
264
+ add({
265
+ nodeId: node.id,
266
+ rule: "control-name",
267
+ severity: "error",
268
+ message:
269
+ node.type === "tab-panel"
270
+ ? "This tab's label is blank, so the tab has no name."
271
+ : node.type === "video"
272
+ ? // W-410: the title names the player for screen readers.
273
+ "This video's title is blank, so the player has no name."
274
+ : "This accordion item's title is blank, so it has no name.",
275
+ });
276
+ }
277
+ }
278
+ // W-424: two menus with the same name are two "Menu navigation" landmarks nobody can tell apart.
279
+ if (node.type === "menu" && (node.children?.length ?? 0) > 0) {
280
+ const name = String(props["label"] ?? "").trim() || "Menu";
281
+ const key = name.toLowerCase();
282
+ if (menuNames.some((names, i) => shownOn[i] && names.has(key))) {
283
+ add({
284
+ nodeId: node.id,
285
+ rule: "landmark-name",
286
+ severity: "warning",
287
+ message: `Another menu on this page is also named "${name}"; give each menu its own label.`,
288
+ });
289
+ }
290
+ menuNames.forEach((names, i) => {
291
+ if (shownOn[i]) names.add(key);
292
+ });
293
+ }
294
+ // W-419: an empty heading still shows up in screen readers' heading list, with nothing to say.
295
+ if (node.type === "heading" && !String(props["text"] ?? "").trim() && !node.bind) {
296
+ add({
297
+ nodeId: node.id,
298
+ rule: "empty-heading",
299
+ severity: "warning",
300
+ message: "This heading is empty; screen readers list it as a heading with no words.",
301
+ });
302
+ }
152
303
  if (node.type === "heading") {
153
304
  const level = typeof props["level"] === "number" ? props["level"] : 2;
154
305
  if (level === 1) {
155
- h1s += 1;
156
- if (h1s > 1) {
306
+ h1s = h1s.map((count, i) => count + (shownOn[i] ? 1 : 0));
307
+ if (h1s.some((count, i) => shownOn[i] && count > 1)) {
157
308
  add({
158
309
  nodeId: node.id,
159
310
  rule: "multiple-h1",
@@ -188,7 +339,12 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
188
339
  message:
189
340
  node.type === "icon"
190
341
  ? "This icon link has no title, so it has no name."
191
- : "This link has no text.",
342
+ : node.type === "button" && !hasHref
343
+ ? // W-400: without a URL this is a <button>, not a link.
344
+ props["iconId"]
345
+ ? "This icon-only button has no text or title, so it has no name."
346
+ : "This button has no text."
347
+ : "This link has no text.",
192
348
  });
193
349
  } else if (hasHref && VAGUE.test(text)) {
194
350
  add({
@@ -208,28 +364,37 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
208
364
  }
209
365
  }
210
366
  if (TEXT_TYPES.has(node.type) && nextColor && nextBg && nextBg !== "unknown") {
211
- const ratio = contrastRatio(nextColor, nextBg);
367
+ const ratio = contrastRatio(over(nextColor, nextBg, fade), nextBg);
212
368
  const needed = largeText(node) ? 3 : 4.5;
213
369
  if (ratio < needed) {
214
370
  const black = contrastRatio("#000000", nextBg);
215
371
  const white = contrastRatio("#ffffff", nextBg);
216
372
  const better = black >= white ? "#111111" : "#ffffff";
373
+ // W-421: when opacity is what fades the text, a new colour can't fix it; say so instead
374
+ // of offering a fix that leaves the issue in place.
375
+ const fixable = contrastRatio(over(better, nextBg, fade), nextBg) >= needed;
217
376
  add({
218
377
  nodeId: node.id,
219
378
  rule: "contrast",
220
379
  severity: "error",
221
- message: `Text contrast is ${ratio.toFixed(1)}:1; it needs ${needed}:1.`,
222
- fix: { kind: "text-color", color: better },
223
- fixLabel: better === "#ffffff" ? "Use white text" : "Use dark text",
380
+ message: fixable
381
+ ? `Text contrast is ${ratio.toFixed(1)}:1; it needs ${needed}:1.`
382
+ : `Text contrast is ${ratio.toFixed(1)}:1; it needs ${needed}:1. Opacity on this element or a parent fades it; raise the opacity.`,
383
+ ...(fixable
384
+ ? {
385
+ fix: { kind: "text-color" as const, color: better },
386
+ fixLabel: better === "#ffffff" ? "Use white text" : "Use dark text",
387
+ }
388
+ : {}),
224
389
  });
225
390
  }
226
391
  }
227
392
  const focusable =
228
393
  LINKISH.has(node.type) || node.type === "text-input" || Boolean(props["href"]);
229
- if (
230
- focusable &&
231
- (node.attributes ?? []).some((a) => a.name === "aria-hidden" && a.value === "true")
232
- ) {
394
+ const ownAriaHidden = (node.attributes ?? []).some(
395
+ (a) => a.name === "aria-hidden" && a.value === "true",
396
+ );
397
+ if (focusable && ownAriaHidden) {
233
398
  add({
234
399
  nodeId: node.id,
235
400
  rule: "hidden-focusable",
@@ -238,11 +403,22 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
238
403
  fix: { kind: "drop-aria-hidden" },
239
404
  fixLabel: "Remove aria-hidden",
240
405
  });
406
+ } else if (focusable && ariaHiddenAbove) {
407
+ add({
408
+ nodeId: node.id,
409
+ rule: "hidden-focusable",
410
+ severity: "error",
411
+ message:
412
+ "This sits inside an element with aria-hidden, so screen readers skip it, but the keyboard still reaches it.",
413
+ });
241
414
  }
415
+ const outerHidden = ariaHiddenAbove;
416
+ if (ownAriaHidden) ariaHiddenAbove = true;
242
417
  if (isParentNode(node)) for (const child of node.children) walk(child, nextBg, nextColor);
418
+ ariaHiddenAbove = outerHidden;
243
419
  };
244
420
  walk(layout.root, undefined, undefined);
245
- if (h1s === 0 && layout.root.children.length > 0) {
421
+ if (h1s.every((count) => count === 0) && layout.root.children.length > 0) {
246
422
  issues.unshift({
247
423
  id: `no-h1:${layout.root.id}`,
248
424
  nodeId: layout.root.id,
@@ -204,6 +204,8 @@ export function moveNode(layout: Layout, id: string, parentId: string, index: nu
204
204
  const from = locate(layout, id) as Located & { parent: ContainerNode | FormNode | LoopNode };
205
205
  const sameParent = from.parent.id === parentId;
206
206
  const at = sameParent && from.index < index ? index - 1 : index;
207
+ // W-521: a drop on its own spot is no edit; the same layout tells callers nothing changed.
208
+ if (sameParent && at === from.index) return { ok: true, layout, selected: id };
207
209
  const { layout: without, removed } = removeNode(layout, id);
208
210
  if (!removed) return refuse(REASONS.missing);
209
211
  return { ok: true, layout: insertNode(without, parentId, at, removed.node), selected: id };
@@ -320,14 +322,22 @@ export function wrapNode(
320
322
  if (!found) return refuse(REASONS.missing);
321
323
  if (!found.parent) return refuse(REASONS.rootFixed);
322
324
  if (size(layout.root) + 1 > MAX_NODES) return refuse(REASONS.tooMany);
323
- const { layout: without, removed } = removeNode(layout, id);
324
- if (!removed) return refuse(REASONS.missing);
325
325
  const wrapper: LayoutNode = {
326
326
  id: newNodeId(random),
327
327
  type,
328
328
  props: type === "grid" ? { columns: 2 } : {},
329
- children: [removed.node],
329
+ children: [found.node],
330
330
  } as LayoutNode;
331
+ // W-389: the same parent/child rules as a drop, so an accordion item, tab panel or menu item
332
+ // isn't wrapped into a page that can't save, and the extra level stays within the depth cap.
333
+ const inForm = underForm(layout, found.parent.id);
334
+ const nesting =
335
+ parentChildRefusal(found.parent, wrapper, inForm) ??
336
+ parentChildRefusal(wrapper, found.node, inForm);
337
+ if (nesting) return refuse(nesting);
338
+ if (found.depth + height(found.node) > MAX_DEPTH) return refuse(REASONS.tooDeep);
339
+ const { layout: without, removed } = removeNode(layout, id);
340
+ if (!removed) return refuse(REASONS.missing);
331
341
  return {
332
342
  ok: true,
333
343
  layout: insertNode(without, found.parent.id, found.index, wrapper),
@@ -32,6 +32,8 @@ export type CssInput = {
32
32
  tablet?: Declaration[];
33
33
  mobile?: Declaration[];
34
34
  hiddenOn?: readonly PopupDevice[];
35
+ /** W-443: an image with a caption, rendered inside a figure that hides with it. */
36
+ figure?: boolean;
35
37
  /** Container-query overrides (W-346). */
36
38
  query?: Declaration[];
37
39
  queryMin?: number;
@@ -196,6 +198,7 @@ export function generateCss({
196
198
  tablet: rule.tablet ?? [],
197
199
  mobile: rule.mobile ?? [],
198
200
  hiddenOn: rule.hiddenOn,
201
+ figure: rule.figure === true,
199
202
  })),
200
203
  ];
201
204
  /** A device block: in its media query, or, for a previewed device, on or off outright. */
@@ -211,9 +214,14 @@ export function generateCss({
211
214
  responsive.map((rule) => block(rule.selector, rule[which])).join(""),
212
215
  );
213
216
  const hide = (device: PopupDevice, query: string) => {
217
+ // W-443: a captioned image hides its figure too, or the caption stayed on its own.
214
218
  const selectors = responsive
215
219
  .filter((rule) => rule.hiddenOn?.includes(device))
216
- .map((rule) => rule.selector);
220
+ .flatMap((rule) =>
221
+ "figure" in rule && rule.figure
222
+ ? [rule.selector, `.emvb-figure:has(>${rule.selector},>a>${rule.selector})`]
223
+ : [rule.selector],
224
+ );
217
225
  return forDevices(
218
226
  [device],
219
227
  query,
@@ -100,11 +100,12 @@ function clean(value: string): string {
100
100
  let out = "";
101
101
  for (const char of value) {
102
102
  const code = char.codePointAt(0) ?? 0;
103
- if (code === 10 || code === 9) out += char === "\t" ? " " : char;
104
- else if (code >= 32 && code !== 127) out += char;
105
- if (out.length >= MAX_BOUND_LENGTH) break;
103
+ const kept = code === 9 ? " " : code === 10 || (code >= 32 && code !== 127) ? char : "";
104
+ // W-502: cutting at a UTF-16 length split an emoji at the limit into a broken half.
105
+ if (out.length + kept.length > MAX_BOUND_LENGTH) break;
106
+ out += kept;
106
107
  }
107
- return out.slice(0, MAX_BOUND_LENGTH).trim();
108
+ return out.trim();
108
109
  }
109
110
 
110
111
  /** The live value of one binding, or undefined when its source has nothing for this key. */
@@ -189,8 +190,13 @@ export function applyBindings(node: LayoutNode, data: BindingData): LayoutNode {
189
190
  if (value === undefined) continue;
190
191
  props ??= { ...(node.props as Record<string, unknown>) };
191
192
  props[field.key] = value;
192
- // A bound image is no longer the media library item it was picked from.
193
- if (field.kind === "image") delete props["mediaId"];
193
+ // A bound image is no longer the media library item it was picked from. W-501: nor are the
194
+ // typed picture's extra sizes; with `w` descriptors the browser picks only from srcset, so
195
+ // they hid the bound image on most screens.
196
+ if (field.kind === "image") {
197
+ delete props["mediaId"];
198
+ delete props["sources"];
199
+ }
194
200
  }
195
201
  return props ? ({ ...node, props } as LayoutNode) : node;
196
202
  }
@@ -1,3 +1,4 @@
1
+ import { clipText } from "../limits.ts";
1
2
  import type { DesignSystem } from "../schema/design.ts";
2
3
  import type { Layout, LayoutNode } from "../schema/layout.ts";
3
4
  import type { StyleProps } from "../schema/style.ts";
@@ -99,7 +100,8 @@ export function cleanClassName(name: string): string {
99
100
  const code = ch.charCodeAt(0);
100
101
  return code < 32 || code === 127 ? " " : ch;
101
102
  }).join("");
102
- return spaced.replace(/ {2,}/g, " ").trim().slice(0, 60).trim();
103
+ const spacedTrim = spaced.replace(/ {2,}/g, " ").trim();
104
+ return clipText(spacedTrim, 60).trim();
103
105
  }
104
106
 
105
107
  export function localToClassRefusal(design: DesignSystem, node: LayoutNode): string | null {
@@ -120,7 +122,7 @@ export function localStylesToClass(
120
122
  node: LayoutNode,
121
123
  name: string,
122
124
  ): { design: DesignSystem; node: LayoutNode; classId: string } | null {
123
- const trimmed = name.trim().slice(0, 60);
125
+ const trimmed = clipText(name.trim(), 60);
124
126
  if (!trimmed || localToClassRefusal(design, node)) return null;
125
127
  const classes = design.classes ?? [];
126
128
  const base = slugify(trimmed).slice(0, 34) || "class";
@@ -154,7 +156,7 @@ export function duplicateClass(
154
156
  // At the cap the copy would make the design invalid and the save fail (W-218).
155
157
  if (!source || classes.length >= MAX_CLASSES) return design;
156
158
  // W-277: "Card copy", then "Card copy 2"…, so the copy's name is free too.
157
- const stem = `${source.name.slice(0, 52).trim()} copy`;
159
+ const stem = `${clipText(source.name, 52).trim()} copy`;
158
160
  let baseName = stem;
159
161
  for (let n = 2; n <= MAX_CLASSES && classNameTaken(design, baseName); n++) {
160
162
  baseName = `${stem} ${n}`;
@@ -1,3 +1,4 @@
1
+ import { sameJson } from "../stable-json.ts";
1
2
  import type { DesignSystem } from "../schema/design.ts";
2
3
 
3
4
  export type DesignChange = {
@@ -6,7 +7,8 @@ export type DesignChange = {
6
7
  name: string;
7
8
  };
8
9
 
9
- const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
10
+ /** Key order is ignored: an edit that removes and re-adds a value is no change (W-519). */
11
+ const same = sameJson;
10
12
 
11
13
  /** What Publish styles will write: draft compared with the published design (W-340). */
12
14
  export function designChanges(published: DesignSystem, draft: DesignSystem): DesignChange[] {
@@ -1,8 +1,10 @@
1
+ import { sameJson } from "../stable-json.ts";
1
2
  import { emptyDesign, type DesignSystem } from "../schema/design.ts";
2
3
 
3
4
  export type DesignConflict = { kind: "variable" | "class" | "setting"; name: string };
4
5
 
5
- const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
6
+ /** Key order is ignored: an edit that removes and re-adds a value is no change (W-519). */
7
+ const same = sameJson;
6
8
 
7
9
  type Named = { id: string; name: string };
8
10
 
@@ -1,3 +1,4 @@
1
+ import { clipText, MAX_DESIGN_BYTES } from "../limits.ts";
1
2
  import { DesignSystem as DesignSystemSchema, DESIGN_SCHEMA_VERSION } from "../schema/design.ts";
2
3
  import type { DesignSystem } from "../schema/design.ts";
3
4
  import { DESIGN_MIGRATIONS, upgradeLayout } from "../migrate/index.ts";
@@ -21,7 +22,7 @@ export type DesignImport =
21
22
  function freeName(name: string, taken: Set<string>): string {
22
23
  for (let n = 2; ; n++) {
23
24
  const suffix = ` ${n}`;
24
- const next = `${name.slice(0, 60 - suffix.length).trim()}${suffix}`;
25
+ const next = `${clipText(name, 60 - suffix.length).trim()}${suffix}`;
25
26
  if (!taken.has(next.toLowerCase())) return next;
26
27
  }
27
28
  }
@@ -83,7 +84,17 @@ export function designFromJson(text: string): DesignImport {
83
84
  }
84
85
  const result = DesignSystemSchema.safeParse(upgraded.doc);
85
86
  if (!result.success) return { ok: false, message: "That file is not an EmVB design document." };
86
- return { ok: true, ...uniqueImportNames(result.data) };
87
+ const imported = uniqueImportNames(result.data);
88
+ // W-516: the file cap is 1 MB, but the saved design is capped lower; a design over that cap
89
+ // replaced the site styles in the editor and then every save of them was refused.
90
+ const bytes = new TextEncoder().encode(JSON.stringify(imported.design)).length;
91
+ if (bytes > MAX_DESIGN_BYTES) {
92
+ return {
93
+ ok: false,
94
+ message: `That design is ${Math.ceil(bytes / 1024)} KB; site styles can be at most ${MAX_DESIGN_BYTES / 1024} KB. Remove some classes or variables from the file, then import it again.`,
95
+ };
96
+ }
97
+ return { ok: true, ...imported };
87
98
  }
88
99
 
89
100
  /** The largest design file Import reads (W-214); the saved design is capped far lower. */
@@ -1,3 +1,4 @@
1
+ import { clipText } from "../limits.ts";
1
2
  import type { DesignSystem } from "../schema/design.ts";
2
3
  import type { Layout } from "../schema/layout.ts";
3
4
  import { cleanClassName } from "./classes.ts";
@@ -279,7 +280,7 @@ export function duplicateVariable(
279
280
  // A copy past the cap, or a name past 60 characters, would fail to save (W-219).
280
281
  if (!source || variableListFull(design, kind)) return design;
281
282
  // W-278: "Brand copy", then "Brand copy 2"…, so the copy's name is free too.
282
- const stem = `${source.name.slice(0, 52).trim()} copy`;
283
+ const stem = `${clipText(source.name, 52).trim()} copy`;
283
284
  let name = stem;
284
285
  for (let n = 2; n <= MAX_VARIABLES[kind] && variableNameTaken(design, kind, name); n++) {
285
286
  name = `${stem} ${n}`;
@@ -166,7 +166,7 @@ export const loop: ElementDefinition<LoopNode> = {
166
166
  ".emvb-loop-grid,.emvb-loop-cards{display:grid;grid-template-columns:repeat(var(--emvb-loop-columns,3),minmax(0,1fr))}" +
167
167
  ".emvb-loop-cards>.emvb-loop-item{padding:1rem;border:1px solid color-mix(in srgb,currentColor 15%,transparent);border-radius:12px;background:color-mix(in srgb,currentColor 3%,transparent)}" +
168
168
  ".emvb-loop-grid>.emvb-loop-empty,.emvb-loop-cards>.emvb-loop-empty{grid-column:1/-1}" +
169
- "@media (max-width: 767px){.emvb-loop-grid,.emvb-loop-cards{grid-template-columns:minmax(0,1fr)}}",
169
+ "@media (max-width: 767.98px){.emvb-loop-grid,.emvb-loop-cards{grid-template-columns:minmax(0,1fr)}}",
170
170
  defaults: () => ({ type: "loop", props: {}, children: [] }),
171
171
  descriptor: {
172
172
  type: "loop",
@@ -310,6 +310,14 @@ export const pagination: ElementDefinition<PaginationNode> = {
310
310
  message:
311
311
  '{page} and {total} are filled in. EmDash 1.2 doesn\'t report a total, so the count shows "Page N" until it does.',
312
312
  },
313
+ {
314
+ key: "titleText",
315
+ kind: "text",
316
+ label: "Page title text",
317
+ optional: true,
318
+ message:
319
+ 'The browser title of page 2 onward. {title} and {page} are filled in; unset is "{title} – page {page}".',
320
+ },
313
321
  ],
314
322
  },
315
323
  // Rendered by core/render/pagination.ts from the archive's page data (W-222).
@@ -44,7 +44,8 @@ const FORM_FIELD_CSS =
44
44
  ':where(.emvb-form .ec-form-input[aria-invalid="true"]){border-color:#b3261e}' +
45
45
  ':where(.emvb-form input[type="checkbox"],.emvb-form input[type="radio"]){width:1.1em;height:1.1em;margin:0;accent-color:currentColor}' +
46
46
  ":where(.emvb-form .emvb-form-checkbox-label,.emvb-form .emvb-form-radio-label){display:inline-flex;align-items:center;gap:.5em}" +
47
- ":where(.emvb-form .emvb-radio-group){display:flex;flex-direction:column;gap:6px;margin:0;padding:0;border:0}" +
47
+ ":where(.emvb-form .emvb-radio-group){display:flex;flex-direction:column;gap:6px;margin:0;padding:0;border:0;min-width:0}" +
48
+ ":where(.emvb-form .emvb-radio-group>legend){float:left;width:100%;margin:0 0 -2px;padding:0}" +
48
49
  ":where(.emvb-form .ec-form-error){font-size:.875em;color:#b3261e}";
49
50
 
50
51
  export const form: ElementDefinition<FormNode> = {
@@ -184,10 +185,23 @@ export const radio: ElementDefinition<RadioNode> = {
184
185
  build: (node, attrs) => {
185
186
  const name = node.props.field;
186
187
  // Options filled from definition in W-035; placeholder single option for schema/render smoke.
188
+ const id = controlId(node.id);
189
+ // W-524: the question is the fieldset's <legend>, so the group is named natively (it was a
190
+ // <label> pointing at nothing plus aria-labelledby, W-442). The id stays for old references.
191
+ const legend: VNode[] = node.props.label
192
+ ? [
193
+ {
194
+ tag: "legend",
195
+ attrs: { class: "emvb-form-label", id: `${id}-label` },
196
+ children: [node.props.label],
197
+ },
198
+ ]
199
+ : [];
187
200
  const control: VNode = {
188
201
  tag: "fieldset",
189
202
  attrs: { class: "emvb-radio-group" },
190
203
  children: [
204
+ ...legend,
191
205
  {
192
206
  tag: "label",
193
207
  attrs: { class: "emvb-form-radio-label" },
@@ -198,7 +212,7 @@ export const radio: ElementDefinition<RadioNode> = {
198
212
  },
199
213
  ],
200
214
  };
201
- return fieldWrap(controlId(node.id), name, node.props.label, control, attrs);
215
+ return fieldBox(attrs, [control, errorSlot(name)]);
202
216
  },
203
217
  };
204
218
 
@@ -215,6 +229,7 @@ export const submit: ElementDefinition<SubmitNode> = {
215
229
  type: "submit",
216
230
  class: `${attrs.class ?? ""} ec-form-submit`.trim(),
217
231
  },
218
- children: [node.props.label ?? "Submit"],
232
+ // W-447: a blank label left an empty button with no name; it falls back like an unset one.
233
+ children: [node.props.label?.trim() || "Submit"],
219
234
  }),
220
235
  };