@perkyzz/emvb 0.6.0 → 0.8.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 (208) hide show
  1. package/README.md +2 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +7 -7
  4. package/src/admin/access/RequireEditor.tsx +7 -7
  5. package/src/admin/access/role.ts +5 -2
  6. package/src/admin/content-api.ts +10 -3
  7. package/src/admin/content-item.ts +1 -1
  8. package/src/admin/editor/A11yCopilot.tsx +104 -56
  9. package/src/admin/editor/CommandPalette.tsx +29 -13
  10. package/src/admin/editor/DialogCloseButton.tsx +16 -0
  11. package/src/admin/editor/Editor.tsx +115 -20
  12. package/src/admin/editor/EditorToasts.tsx +26 -0
  13. package/src/admin/editor/PerfMeter.tsx +92 -73
  14. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  15. package/src/admin/editor/ShareLink.tsx +102 -72
  16. package/src/admin/editor/ShortcutsDialog.tsx +37 -18
  17. package/src/admin/editor/Timeline.tsx +250 -160
  18. package/src/admin/editor/TopBar.tsx +71 -14
  19. package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
  20. package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
  21. package/src/admin/editor/canvas/drop-line.ts +11 -3
  22. package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
  23. package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
  24. package/src/admin/editor/canvas/vnode-react.tsx +7 -0
  25. package/src/admin/editor/collection-previews.ts +10 -0
  26. package/src/admin/editor/dialogs.tsx +41 -28
  27. package/src/admin/editor/dnd/drop-target.ts +26 -1
  28. package/src/admin/editor/edited-noun.ts +15 -0
  29. package/src/admin/editor/editor-chrome.tsx +43 -7
  30. package/src/admin/editor/editor-commands.ts +17 -2
  31. package/src/admin/editor/editor-css.ts +75 -24
  32. package/src/admin/editor/element-chrome.ts +21 -11
  33. package/src/admin/editor/feature-css.ts +56 -14
  34. package/src/admin/editor/focus-when-lost.ts +23 -0
  35. package/src/admin/editor/icons/IconLibraryDialog.tsx +54 -18
  36. package/src/admin/editor/icons/library.ts +1 -1
  37. package/src/admin/editor/icons/use-icon-library.ts +5 -2
  38. package/src/admin/editor/ime.ts +29 -0
  39. package/src/admin/editor/palette-items.ts +27 -3
  40. package/src/admin/editor/panels/AddPanel.tsx +44 -11
  41. package/src/admin/editor/panels/ClassesSection.tsx +18 -7
  42. package/src/admin/editor/panels/ColorControl.tsx +130 -23
  43. package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
  44. package/src/admin/editor/panels/ElementPanel.tsx +134 -24
  45. package/src/admin/editor/panels/LayersPanel.tsx +61 -20
  46. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  47. package/src/admin/editor/panels/PageSettings.tsx +66 -35
  48. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  49. package/src/admin/editor/panels/SiteStylesDrawer.tsx +224 -42
  50. package/src/admin/editor/panels/TokenScales.tsx +88 -48
  51. package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
  52. package/src/admin/editor/panels/TriggersEditor.tsx +3 -2
  53. package/src/admin/editor/panels/VariableSection.tsx +48 -18
  54. package/src/admin/editor/panels/color-space.ts +23 -29
  55. package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
  56. package/src/admin/editor/panels/settings/AudienceEditor.tsx +87 -74
  57. package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
  58. package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
  59. package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
  60. package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
  61. package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
  62. package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
  63. package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
  64. package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
  65. package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
  66. package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
  67. package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
  68. package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
  69. package/src/admin/editor/panels/settings/IconControls.tsx +33 -13
  70. package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
  71. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
  72. package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
  73. package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
  74. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  75. package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
  76. package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
  77. package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
  78. package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
  79. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
  80. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
  81. package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
  82. package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
  83. package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
  84. package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
  85. package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
  86. package/src/admin/editor/panels/settings/query-style.ts +38 -9
  87. package/src/admin/editor/panels/settings/svg-images.ts +13 -0
  88. package/src/admin/editor/panels/site-list.tsx +20 -6
  89. package/src/admin/editor/panels/variable-values.ts +11 -4
  90. package/src/admin/editor/restore-deleted.ts +21 -2
  91. package/src/admin/editor/section-templates.ts +81 -12
  92. package/src/admin/editor/shortcuts.ts +31 -2
  93. package/src/admin/editor/store.ts +7 -0
  94. package/src/admin/editor/useEditorCommands.ts +61 -15
  95. package/src/admin/editor/useEditorData.ts +4 -2
  96. package/src/admin/editor/useEditorShortcuts.ts +17 -7
  97. package/src/admin/editor/useNodeActions.ts +61 -6
  98. package/src/admin/editor/useSave.ts +22 -7
  99. package/src/admin/editor/useSavedSections.ts +197 -0
  100. package/src/admin/forms-api.ts +2 -0
  101. package/src/admin/image-editor/Canvas.tsx +61 -17
  102. package/src/admin/image-editor/CurvesPanel.tsx +2 -1
  103. package/src/admin/image-editor/ExportDialog.tsx +48 -18
  104. package/src/admin/image-editor/ImageEditorDialog.tsx +179 -8
  105. package/src/admin/image-editor/MetadataPanel.tsx +15 -4
  106. package/src/admin/image-editor/crop-geometry.ts +3 -2
  107. package/src/admin/image-editor/image-editor-css.ts +15 -10
  108. package/src/admin/image-editor/load.ts +9 -2
  109. package/src/admin/image-editor/parts.tsx +69 -19
  110. package/src/admin/image-editor/save.ts +54 -8
  111. package/src/admin/media-api.ts +2 -1
  112. package/src/admin/pages/AgentsPage.tsx +138 -27
  113. package/src/admin/pages/CreateDialog.tsx +97 -30
  114. package/src/admin/pages/NewPageDialog.tsx +21 -3
  115. package/src/admin/pages/NewThemePartDialog.tsx +11 -3
  116. package/src/admin/pages/PageList.tsx +14 -6
  117. package/src/admin/pages/SetupShell.tsx +28 -12
  118. package/src/admin/pages/ThemePartList.tsx +59 -11
  119. package/src/admin/pages/list-kit.tsx +106 -24
  120. package/src/admin/saved-sections-api.ts +51 -0
  121. package/src/admin/search.ts +15 -0
  122. package/src/admin/setup/useSetupStatus.ts +1 -1
  123. package/src/admin/theme-api.ts +16 -5
  124. package/src/admin/ui.ts +82 -22
  125. package/src/astro/floats/runtime.ts +21 -0
  126. package/src/astro/menu/runtime.ts +34 -1
  127. package/src/astro/popups/runtime.ts +41 -9
  128. package/src/astro/render.ts +3 -0
  129. package/src/astro/resolve-theme.ts +53 -11
  130. package/src/astro/resolve.ts +9 -1
  131. package/src/astro/tabs/runtime.ts +12 -0
  132. package/src/astro/theme-posts.ts +2 -2
  133. package/src/astro/visitor.ts +2 -0
  134. package/src/constants.ts +1 -1
  135. package/src/core/a11y/audit.ts +196 -24
  136. package/src/core/arrange.ts +48 -12
  137. package/src/core/audience/rules.ts +5 -1
  138. package/src/core/audience/variants.ts +29 -3
  139. package/src/core/clipboard.ts +7 -0
  140. package/src/core/css/generate.ts +31 -6
  141. package/src/core/css/print.ts +5 -0
  142. package/src/core/data/bindings.ts +8 -1
  143. package/src/core/design/classes.ts +39 -16
  144. package/src/core/design/devices.ts +7 -13
  145. package/src/core/design/diff.ts +6 -0
  146. package/src/core/design/merge.ts +90 -2
  147. package/src/core/design/states.ts +7 -13
  148. package/src/core/design/tokens.ts +16 -2
  149. package/src/core/design/transfer.ts +33 -6
  150. package/src/core/design/variables.ts +30 -9
  151. package/src/core/elements/dynamic-elements.ts +53 -14
  152. package/src/core/elements/form-elements.ts +55 -16
  153. package/src/core/elements/index.ts +84 -39
  154. package/src/core/elements/menu.ts +40 -19
  155. package/src/core/elements/select-prompt.ts +3 -0
  156. package/src/core/elements/svg-ids.ts +39 -0
  157. package/src/core/forms/binding.ts +57 -16
  158. package/src/core/forms/definition.ts +72 -0
  159. package/src/core/history/diff.ts +18 -1
  160. package/src/core/icons/animation-runs.ts +11 -0
  161. package/src/core/icons/catalog.ts +3 -2
  162. package/src/core/image-edit/schema.ts +11 -1
  163. package/src/core/image-edit/summary.ts +6 -3
  164. package/src/core/index.ts +35 -1
  165. package/src/core/limits.ts +12 -1
  166. package/src/core/migrate/index.ts +3 -0
  167. package/src/core/perf/meter.ts +42 -7
  168. package/src/core/recipes/index.ts +5 -4
  169. package/src/core/render/context.ts +8 -0
  170. package/src/core/render/dynamic-post.ts +69 -12
  171. package/src/core/render/extras.ts +77 -4
  172. package/src/core/render/form.ts +140 -6
  173. package/src/core/render/index.ts +156 -20
  174. package/src/core/render/loop.ts +44 -8
  175. package/src/core/render/pagination.ts +18 -4
  176. package/src/core/render/section.ts +27 -0
  177. package/src/core/render/tabs.ts +12 -3
  178. package/src/core/render/vnode.ts +1 -1
  179. package/src/core/sanitize/css.ts +29 -8
  180. package/src/core/sanitize/embed-url.ts +42 -5
  181. package/src/core/sanitize/url.ts +2 -1
  182. package/src/core/saved-sections.ts +318 -0
  183. package/src/core/schema/design.ts +1 -1
  184. package/src/core/schema/layout.ts +16 -7
  185. package/src/core/schema/style.ts +4 -2
  186. package/src/core/stats.ts +2 -1
  187. package/src/core/theme/conditions.ts +3 -1
  188. package/src/core/theme/dynamic.ts +36 -5
  189. package/src/core/theme/float.ts +12 -2
  190. package/src/core/theme/pagination.ts +50 -29
  191. package/src/core/theme/part-types.ts +4 -4
  192. package/src/core/theme/popup-markup.ts +23 -5
  193. package/src/core/theme/popup-rules.ts +1 -0
  194. package/src/core/theme/triggers.ts +3 -2
  195. package/src/core/tree-ops.ts +27 -0
  196. package/src/mcp/ports.ts +22 -1
  197. package/src/mcp/rate-limit.ts +2 -1
  198. package/src/mcp/read.ts +15 -3
  199. package/src/mcp/refs.ts +18 -0
  200. package/src/mcp/sections.ts +183 -0
  201. package/src/mcp/tools.ts +44 -0
  202. package/src/mcp/write.ts +178 -14
  203. package/src/server/agent-settings.ts +1 -1
  204. package/src/server/hooks.ts +5 -3
  205. package/src/server/icon-routes.ts +30 -9
  206. package/src/server/mcp-routes.ts +8 -1
  207. package/src/server/plugin.ts +14 -0
  208. package/src/server/saved-sections.ts +163 -0
@@ -1,7 +1,20 @@
1
+ import { clipText } from "../limits.ts";
1
2
  import type { DesignSystem } from "../schema/design.ts";
2
3
  import { isParentNode, type Layout, type LayoutNode } from "../schema/layout.ts";
4
+ import { boxBecomesLink } from "../render/extras.ts";
5
+ import { ICON_ANIMATION_LIMIT_MS, iconAnimationRuns } from "../icons/animation-runs.ts";
3
6
  import { updateNode } from "../tree-ops.ts";
4
7
 
8
+ /**
9
+ * W-572: text as a screen reader says it: invisible format characters (zero-width space, word
10
+ * joiner, BOM, bidi marks, soft hyphen) and blank-looking fillers go, then spaces are trimmed.
11
+ * A label of only those reads as nothing.
12
+ */
13
+ const spoken = (value: unknown): string =>
14
+ String(value ?? "")
15
+ .replace(/[\p{Cf}\u115F\u1160\u2800\u3164\uFFA0]/gu, "")
16
+ .trim();
17
+
5
18
  export type A11yFix =
6
19
  | { kind: "heading-level"; level: number }
7
20
  | { kind: "decorative" }
@@ -25,7 +38,8 @@ export type A11yIssue = {
25
38
  | "image-sizes"
26
39
  | "control-name"
27
40
  | "empty-heading"
28
- | "landmark-name";
41
+ | "landmark-name"
42
+ | "motion";
29
43
  severity: "error" | "warning";
30
44
  message: string;
31
45
  /** The one-click fix, when there is a safe one. */
@@ -111,7 +125,14 @@ const TEXT_TYPES = new Set([
111
125
  const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
112
126
  const LINKISH = new Set(["link", "button", "menu-item"]);
113
127
 
114
- function px(value: unknown): number | undefined {
128
+ function px(value: unknown, design?: DesignSystem): number | undefined {
129
+ // W-651: a font size variable counts at its size; a fluid one at its smallest, where the text
130
+ // is hardest to read.
131
+ if (design && value && typeof value === "object" && "var" in value) {
132
+ const found = design.variables.fontSizes?.find((v) => v.id === (value as { var: unknown }).var);
133
+ if (!found) return undefined;
134
+ return found.fluid ? Math.min(found.fluid.min, found.fluid.max) : px(found.value);
135
+ }
115
136
  if (!value || typeof value !== "object" || !("unit" in value)) return undefined;
116
137
  const v = value as { value: number; unit: string };
117
138
  if (v.unit === "px") return v.value;
@@ -119,10 +140,60 @@ function px(value: unknown): number | undefined {
119
140
  return undefined;
120
141
  }
121
142
 
122
- /** Large text (24 px, or 18.66 px bold) needs 3:1; other text 4.5:1. */
123
- function largeText(node: LayoutNode): boolean {
124
- const style = node.style as { fontSize?: unknown; fontWeight?: unknown } | undefined;
125
- const size = px(style?.fontSize) ?? (node.type === "heading" ? 24 : 16);
143
+ /** Browser default heading sizes in px, H1 to H6 (all bold). */
144
+ const HEADING_PX = [32, 24, 18.72, 16, 13.28, 10.72];
145
+
146
+ const headingLevel = (node: LayoutNode): number | undefined => {
147
+ if (node.type !== "heading") return undefined;
148
+ const level = (node.props as { level?: unknown }).level;
149
+ return typeof level === "number" && level >= 1 && level <= 6 ? level : 2;
150
+ };
151
+
152
+ /**
153
+ * The site's starting styles for the tag (W-639), then global classes in stylesheet order, then
154
+ * the element's own style (W-637, W-638).
155
+ */
156
+ function effectiveStyle(
157
+ node: LayoutNode,
158
+ design: DesignSystem,
159
+ ): Record<string, unknown> | undefined {
160
+ const level = headingLevel(node);
161
+ const tagDefaults =
162
+ level === undefined
163
+ ? undefined
164
+ : (design.defaults?.[`h${level}` as "h1"] as Record<string, unknown> | undefined);
165
+ const classIds = new Set(node.classes ?? []);
166
+ if (classIds.size === 0 && !tagDefaults) return node.style as Record<string, unknown> | undefined;
167
+ const fromClasses = (design.classes ?? [])
168
+ .filter((c) => classIds.has(c.id))
169
+ .reduce<Record<string, unknown>>((acc, c) => Object.assign(acc, c.style), { ...tagDefaults });
170
+ return { ...fromClasses, ...(node.style as Record<string, unknown> | undefined) };
171
+ }
172
+
173
+ /** Each device's style with the node's classes under the node's own (W-882). */
174
+ function deviceStyles(node: LayoutNode, design: DesignSystem): Record<string, unknown>[] {
175
+ const ids = new Set(node.classes ?? []);
176
+ const merged: Record<string, Record<string, unknown>> = {};
177
+ const layers = [
178
+ ...(design.classes ?? []).filter((c) => ids.has(c.id)).map((c) => c.devices),
179
+ node.devices,
180
+ ];
181
+ for (const devices of layers) {
182
+ for (const [key, st] of Object.entries(devices ?? {})) {
183
+ merged[key] = { ...merged[key], ...(st as Record<string, unknown>) };
184
+ }
185
+ }
186
+ return Object.values(merged);
187
+ }
188
+
189
+ /** Large text (24 px, or 18.66 px bold) needs 3:1; other text 4.5:1. H4 to H6 are not large (W-639). */
190
+ function largeText(node: LayoutNode, design: DesignSystem): boolean {
191
+ const style = effectiveStyle(node, design) as
192
+ | { fontSize?: unknown; fontWeight?: unknown }
193
+ | undefined;
194
+ const level = headingLevel(node);
195
+ const size =
196
+ px(style?.fontSize, design) ?? (level === undefined ? 16 : (HEADING_PX[level - 1] ?? 24));
126
197
  const weight =
127
198
  typeof style?.fontWeight === "number" ? style.fontWeight : node.type === "heading" ? 700 : 400;
128
199
  return size >= 24 || (size >= 18.66 && weight >= 700);
@@ -133,6 +204,24 @@ function largeText(node: LayoutNode): boolean {
133
204
  * the single H1, link names, vague link text, text contrast against its background, focusable
134
205
  * elements hidden with aria-hidden, and unannounced new tabs. Each issue points at an element; most have a safe fix.
135
206
  */
207
+ /**
208
+ * W-798: whether a linked box has anything inside for its link name: text, a heading, a label, a
209
+ * non-decorative image's alt, or an icon's or SVG's title. Bound and dynamic content counts, as
210
+ * its text isn't known here.
211
+ */
212
+ function boxHasName(node: LayoutNode): boolean {
213
+ if (node.bind || node.type.startsWith("post-") || node.type === "loop" || node.type === "section")
214
+ return true;
215
+ const props = node.props as Record<string, unknown>;
216
+ const decorative = props["decorative"] === true;
217
+ const named =
218
+ node.type === "image" || node.type === "icon" || node.type === "svg"
219
+ ? !decorative && spoken(node.type === "image" ? props["alt"] : props["title"]) !== ""
220
+ : ["text", "title", "label", "summary", "caption"].some((key) => spoken(props[key]) !== "");
221
+ if (named) return true;
222
+ return isParentNode(node) && node.children.some(boxHasName);
223
+ }
224
+
136
225
  export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
137
226
  const issues: A11yIssue[] = [];
138
227
  const add = (issue: Omit<A11yIssue, "id">) =>
@@ -164,7 +253,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
164
253
  const before = variant?.arm === "b" ? beforeA.get(variant.test) : undefined;
165
254
  if (before) [h1s, lastLevel] = [[...before[0]], before[1]];
166
255
  const outerFade = fade;
167
- const opacity = (node.style as { opacity?: unknown } | undefined)?.opacity;
256
+ const opacity = effectiveStyle(node, design)?.opacity;
168
257
  if (typeof opacity === "number" && opacity >= 0 && opacity < 1) fade *= opacity;
169
258
  const outerShown = shownOn;
170
259
  shownOn = shownOn.map((shown, i) => shown && !node.hiddenOn?.includes(DEVICES[i] ?? "desktop"));
@@ -177,11 +266,19 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
177
266
  };
178
267
  const visitNode = (node: LayoutNode, bg: string | undefined, color: string | undefined): void => {
179
268
  const props = node.props as Record<string, unknown>;
180
- const style = node.style as
181
- | { backgroundColor?: unknown; color?: unknown; backgroundImage?: unknown }
269
+ const style = effectiveStyle(node, design) as
270
+ | {
271
+ backgroundColor?: unknown;
272
+ color?: unknown;
273
+ backgroundImage?: unknown;
274
+ backgroundVideo?: unknown;
275
+ gradient?: unknown;
276
+ }
182
277
  | undefined;
183
- // A background image hides the colour behind the text: contrast can't be judged below it.
184
- const ownBg = style?.backgroundImage ? "unknown" : hexOf(style?.backgroundColor, design);
278
+ // A background image, video or gradient hides the colour behind the text: contrast can't be
279
+ // judged below it (W-633: a gradient or video was judged against the colour under it).
280
+ const covered = style?.backgroundImage || style?.backgroundVideo || style?.gradient;
281
+ const ownBg = covered ? "unknown" : hexOf(style?.backgroundColor, design);
185
282
  const nextBg =
186
283
  ownBg && ownBg !== "unknown" && bg && bg !== "unknown" ? over(ownBg, bg) : (ownBg ?? bg);
187
284
  const nextColor = hexOf(style?.color, design) ?? color;
@@ -196,14 +293,14 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
196
293
  message: "This image is a link but is marked decorative, so the link has no name.",
197
294
  });
198
295
  } else if (node.type === "image" && props["decorative"] !== true) {
199
- const alt = typeof props["alt"] === "string" ? props["alt"].trim() : "";
296
+ const alt = typeof props["alt"] === "string" ? spoken(props["alt"]) : "";
200
297
  if (USELESS_ALT.test(alt)) {
201
298
  add({
202
299
  nodeId: node.id,
203
300
  rule: "image-alt",
204
301
  severity: "error",
205
302
  message: alt
206
- ? `The alt text "${alt.slice(0, 40)}" doesn't describe the image.`
303
+ ? `The alt text "${clipText(alt, 40)}" doesn't describe the image.`
207
304
  : "This image has no alt text.",
208
305
  ...(imageLinked
209
306
  ? {}
@@ -211,6 +308,46 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
211
308
  });
212
309
  }
213
310
  }
311
+ // W-786: a non-decorative SVG renders role="img"; with no Title and no <title> in its markup
312
+ // it reached visitors with no name.
313
+ if (
314
+ node.type === "svg" &&
315
+ props["decorative"] !== true &&
316
+ !spoken(props["title"]) &&
317
+ !/<title\b[^>]*>\s*[^<\s]/i.test(String(props["markup"] ?? ""))
318
+ ) {
319
+ add({
320
+ nodeId: node.id,
321
+ rule: "image-alt",
322
+ severity: "error",
323
+ message: "This SVG has no title, so screen readers can't say what it shows.",
324
+ fix: { kind: "decorative" as const },
325
+ fixLabel: "Mark as decorative",
326
+ });
327
+ }
328
+ // W-791: motion visitors can't pause breaks WCAG 2.2.2 past 5 seconds, unless it is essential.
329
+ // W-848: a spin or pulse now stops by itself after about 5 s, so only one whose single run
330
+ // (a pulse's there and back) is longer than that is still flagged.
331
+ // W-882: an animation from a class counts too, and the element's own style wins over it.
332
+ const tooLong = [effectiveStyle(node, design), ...deviceStyles(node, design)].some((st) => {
333
+ const anim = (
334
+ st as { iconAnimation?: { type?: unknown; duration?: unknown; loop?: unknown } } | undefined
335
+ )?.iconAnimation;
336
+ if (anim?.type !== "spin" && anim?.type !== "pulse") return false;
337
+ // W-853: Loop forever is motion without end, so it is flagged like before W-848.
338
+ if (anim.loop === true) return true;
339
+ const ms = typeof anim.duration === "number" ? anim.duration : 0;
340
+ return iconAnimationRuns(anim.type, ms) * ms > ICON_ANIMATION_LIMIT_MS;
341
+ });
342
+ if (tooLong) {
343
+ add({
344
+ nodeId: node.id,
345
+ rule: "motion",
346
+ severity: "warning",
347
+ message:
348
+ "This icon animates for more than 5 seconds and visitors can't pause it. Shorten the duration, or keep it only if the motion is essential.",
349
+ });
350
+ }
214
351
  // W-403: with extra sizes but no Width, the main image is left out of srcset, so wide screens
215
352
  // can only get the listed copies.
216
353
  if (node.type === "image" && Array.isArray(props["sources"]) && props["sources"].length > 0) {
@@ -243,12 +380,12 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
243
380
  }
244
381
  // W-408: a blank tab label or accordion title renders a tab or summary with no name.
245
382
  // 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) {
383
+ if (FIELD_TYPES.has(node.type) && !spoken(props["label"]) && !node.bind) {
247
384
  add({
248
385
  nodeId: node.id,
249
386
  rule: "control-name",
250
387
  severity: "error",
251
- message: String(props["placeholder"] ?? "").trim()
388
+ message: spoken(props["placeholder"])
252
389
  ? "This field has only a placeholder, which disappears once you type; give it a label."
253
390
  : "This field has no label, so screen readers can't say what it's for.",
254
391
  });
@@ -259,7 +396,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
259
396
  video: "title",
260
397
  } as const;
261
398
  if (node.type === "tab-panel" || node.type === "accordion-item" || node.type === "video") {
262
- const name = String(props[NAME_PROP[node.type]] ?? "").trim();
399
+ const name = spoken(props[NAME_PROP[node.type]]);
263
400
  if (!name && !node.bind) {
264
401
  add({
265
402
  nodeId: node.id,
@@ -277,7 +414,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
277
414
  }
278
415
  // W-424: two menus with the same name are two "Menu navigation" landmarks nobody can tell apart.
279
416
  if (node.type === "menu" && (node.children?.length ?? 0) > 0) {
280
- const name = String(props["label"] ?? "").trim() || "Menu";
417
+ const name = spoken(props["label"]) || "Menu";
281
418
  const key = name.toLowerCase();
282
419
  if (menuNames.some((names, i) => shownOn[i] && names.has(key))) {
283
420
  add({
@@ -292,7 +429,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
292
429
  });
293
430
  }
294
431
  // 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) {
432
+ if (node.type === "heading" && !spoken(props["text"]) && !node.bind) {
296
433
  add({
297
434
  nodeId: node.id,
298
435
  rule: "empty-heading",
@@ -328,8 +465,16 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
328
465
  }
329
466
  lastLevel = level;
330
467
  }
468
+ if (boxBecomesLink(node) && !boxHasName(node)) {
469
+ add({
470
+ nodeId: node.id,
471
+ rule: "link-name",
472
+ severity: "error",
473
+ message: "This box is a link, but nothing inside it has text, so the link has no name.",
474
+ });
475
+ }
331
476
  if (LINKISH.has(node.type) || (node.type === "icon" && props["href"])) {
332
- const text = String(props["text"] ?? props["title"] ?? "").trim();
477
+ const text = spoken(props["text"] ?? props["title"]);
333
478
  const hasHref = typeof props["href"] === "string" && props["href"].trim() !== "";
334
479
  if (!text && !node.bind) {
335
480
  add({
@@ -365,7 +510,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
365
510
  }
366
511
  if (TEXT_TYPES.has(node.type) && nextColor && nextBg && nextBg !== "unknown") {
367
512
  const ratio = contrastRatio(over(nextColor, nextBg, fade), nextBg);
368
- const needed = largeText(node) ? 3 : 4.5;
513
+ const needed = largeText(node, design) ? 3 : 4.5;
369
514
  if (ratio < needed) {
370
515
  const black = contrastRatio("#000000", nextBg);
371
516
  const white = contrastRatio("#ffffff", nextBg);
@@ -373,13 +518,15 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
373
518
  // W-421: when opacity is what fades the text, a new colour can't fix it; say so instead
374
519
  // of offering a fix that leaves the issue in place.
375
520
  const fixable = contrastRatio(over(better, nextBg, fade), nextBg) >= needed;
521
+ // W-772: round down, so 4.48:1 reads "4.4:1", never "4.5:1; it needs 4.5:1".
522
+ const shown = (Math.floor(ratio * 10) / 10).toFixed(1);
376
523
  add({
377
524
  nodeId: node.id,
378
525
  rule: "contrast",
379
526
  severity: "error",
380
527
  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.`,
528
+ ? `Text contrast is ${shown}:1; it needs ${needed}:1.`
529
+ : `Text contrast is ${shown}:1; it needs ${needed}:1. Opacity on this element or a parent fades it; raise the opacity.`,
383
530
  ...(fixable
384
531
  ? {
385
532
  fix: { kind: "text-color" as const, color: better },
@@ -389,8 +536,12 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
389
536
  });
390
537
  }
391
538
  }
539
+ // W-650: every form control takes keyboard focus, not just a text box.
392
540
  const focusable =
393
- LINKISH.has(node.type) || node.type === "text-input" || Boolean(props["href"]);
541
+ LINKISH.has(node.type) ||
542
+ FIELD_TYPES.has(node.type) ||
543
+ node.type === "submit" ||
544
+ Boolean(props["href"]);
394
545
  const ownAriaHidden = (node.attributes ?? []).some(
395
546
  (a) => a.name === "aria-hidden" && a.value === "true",
396
547
  );
@@ -454,5 +605,26 @@ export function applyA11yFix(layout: Layout, issue: A11yIssue): Layout {
454
605
 
455
606
  /** Applies every issue's fix at once (W-317). */
456
607
  export function applyAllA11yFixes(layout: Layout, issues: A11yIssue[]): Layout {
457
- return issues.reduce((next, issue) => applyA11yFix(next, issue), layout);
608
+ const fixed = issues.reduce((next, issue) => applyA11yFix(next, issue), layout);
609
+ // W-773: each heading-order fix was worked out against the page before any fix, so H1, H4,
610
+ // H6 became H1, H2, H5 and the H5 still skipped. Re-chain the fixed headings in page order.
611
+ const order = new Set(issues.filter((i) => i.rule === "heading-order").map((i) => i.nodeId));
612
+ if (order.size === 0) return fixed;
613
+ const levels = new Map<string, number>();
614
+ let last = 0;
615
+ const walk = (node: LayoutNode) => {
616
+ if (node.type === "heading") {
617
+ const own = typeof node.props["level"] === "number" ? node.props["level"] : 2;
618
+ const level = order.has(node.id) ? Math.min(own, Math.max(2, last + 1)) : own;
619
+ if (level !== own) levels.set(node.id, level);
620
+ last = level;
621
+ }
622
+ if (isParentNode(node)) node.children.forEach(walk);
623
+ };
624
+ walk(fixed.root);
625
+ return [...levels].reduce(
626
+ (next, [id, level]) =>
627
+ updateNode(next, id, (node) => ({ ...node, props: { ...node.props, level } }) as LayoutNode),
628
+ fixed,
629
+ );
458
630
  }
@@ -266,7 +266,8 @@ export const CSS_ID_KEPT = "The CSS id stays on the original: CSS ids must be un
266
266
  /** `node` without the CSS id on it or any descendant; returns how many it dropped. */
267
267
  function withoutHtmlIds(node: LayoutNode): { node: LayoutNode; dropped: number } {
268
268
  let dropped = node.htmlId ? 1 : 0;
269
- const { htmlId: _htmlId, ...rest } = node;
269
+ // A copy is never part of an A/B test: it would join the original's test as an extra arm (W-629).
270
+ const { htmlId: _htmlId, variant: _variant, ...rest } = node;
270
271
  const kids = nodeChildren(node);
271
272
  if (kids.length === 0) return { node: rest as LayoutNode, dropped };
272
273
  const children = kids.map((child) => {
@@ -318,16 +319,31 @@ export function wrapNode(
318
319
  type: WrapType,
319
320
  random: () => number = Math.random,
320
321
  ): Arranged {
322
+ return wrapWith(layout, id, {
323
+ id: newNodeId(random),
324
+ type,
325
+ props: type === "grid" ? { columns: 2 } : {},
326
+ } as LayoutNode);
327
+ }
328
+
329
+ /**
330
+ * W-876: puts `id` inside a Theme section that embeds the Section theme part `partId`. The element
331
+ * stays as the Theme section's own content, so the page looks the same until the part is published.
332
+ */
333
+ export const wrapInThemeSection = (
334
+ layout: Layout,
335
+ id: string,
336
+ partId: string,
337
+ random: () => number = Math.random,
338
+ ): Arranged =>
339
+ wrapWith(layout, id, { id: newNodeId(random), type: "section", props: { partId } } as LayoutNode);
340
+
341
+ function wrapWith(layout: Layout, id: string, shell: LayoutNode): Arranged {
321
342
  const found = locate(layout, id);
322
343
  if (!found) return refuse(REASONS.missing);
323
344
  if (!found.parent) return refuse(REASONS.rootFixed);
324
345
  if (size(layout.root) + 1 > MAX_NODES) return refuse(REASONS.tooMany);
325
- const wrapper: LayoutNode = {
326
- id: newNodeId(random),
327
- type,
328
- props: type === "grid" ? { columns: 2 } : {},
329
- children: [found.node],
330
- } as LayoutNode;
346
+ const wrapper = { ...shell, children: [found.node] } as LayoutNode;
331
347
  // W-389: the same parent/child rules as a drop, so an accordion item, tab panel or menu item
332
348
  // isn't wrapped into a page that can't save, and the extra level stays within the depth cap.
333
349
  const inForm = underForm(layout, found.parent.id);
@@ -511,14 +527,34 @@ export function subtreeSize(layout: Layout, id: string): number {
511
527
  return node ? size(node) : 0;
512
528
  }
513
529
 
514
- /** The default A/B test name for an element (W-312): `test-` and its id, lowercased. */
515
- export const defaultTestName = (id: string): string =>
516
- `test-${
530
+ /**
531
+ * The default A/B test name for an element (W-312): `test-` and its id, lowercased.
532
+ * W-701: `taken` names are skipped (`-2`, `-3`…). Ids that only differ in case, punctuation or
533
+ * after their 12th character ("featurecard01", "featurecard02") made the same name, which merged
534
+ * two tests: ending one deleted the other's elements.
535
+ */
536
+ export const defaultTestName = (id: string, taken: ReadonlySet<string> = new Set()): string => {
537
+ const base = `test-${
517
538
  id
518
539
  .toLowerCase()
519
540
  .replace(/[^a-z0-9]/g, "")
520
- .slice(0, 12) || "1"
541
+ .slice(0, 20) || "1"
521
542
  }`;
543
+ let name = base;
544
+ for (let n = 2; taken.has(name); n++) name = `${base}-${n}`;
545
+ return name;
546
+ };
547
+
548
+ /** The A/B test names already used in a layout. */
549
+ function testNames(layout: Layout): Set<string> {
550
+ const names = new Set<string>();
551
+ const walk = (node: LayoutNode): void => {
552
+ if (node.variant?.test) names.add(node.variant.test);
553
+ for (const child of nodeChildren(node)) walk(child);
554
+ };
555
+ walk(layout.root);
556
+ return names;
557
+ }
522
558
 
523
559
  /**
524
560
  * Edge A/B testing (W-312): the element becomes arm A of a new test and a copy right after it
@@ -533,7 +569,7 @@ export function createVariantB(
533
569
  if (!found) return refuse(REASONS.missing);
534
570
  if (found.node.variant) return refuse("This element is already in an A/B test.");
535
571
  if (found.node.type === "loop-empty" || !found.parent) return refuse(REASONS.rootCopy);
536
- const variant = { test: defaultTestName(found.node.id), arm: "a" as const };
572
+ const variant = { test: defaultTestName(found.node.id, testNames(layout)), arm: "a" as const };
537
573
  const marked = updateNode(layout, id, (node) => ({ ...node, variant }) as LayoutNode);
538
574
  const copied = duplicateNode(marked, id, random);
539
575
  if (!copied.ok) return copied;
@@ -60,7 +60,11 @@ function matches(audience: Audience, visitor: VisitorInfo): boolean {
60
60
  if (visitor.now === undefined) return false;
61
61
  const { hour, day } = clockIn(visitor.now, audience.timeZone);
62
62
  if (audience.hours && !inHours(hour, audience.hours.from, audience.hours.to)) return false;
63
- if (audience.days && !audience.days.includes(day)) return false;
63
+ // W-665: the hours past midnight of an overnight window (Fri 22:00–02:00) belong to the day
64
+ // it started; on Saturday at 01:00 a Friday-only rule hid the element mid-window.
65
+ const { from, to } = audience.hours ?? { from: 0, to: 0 };
66
+ const startedDay = from > to && hour < to ? (day + 6) % 7 : day;
67
+ if (audience.days && !audience.days.includes(startedDay)) return false;
64
68
  }
65
69
  return true;
66
70
  }
@@ -8,12 +8,37 @@ export type AbTest = { test: string; split: number };
8
8
  /** The cookie that keeps a visitor on one arm of a test (W-312). */
9
9
  export const abCookieName = (test: string) => `emvb_ab_${test.replaceAll("-", "_")}`;
10
10
 
11
- /** Every A/B test in the layout, at most 10, with B's split (default 50 %). */
11
+ /**
12
+ * Tests in the layout that have only one arm (W-625): the other was deleted, cut or moved away.
13
+ * Such a test isn't run and its remaining elements show to every visitor, so nobody sees a gap.
14
+ */
15
+ export function loneAbTests(layout: Layout): Set<string> {
16
+ const arms = new Map<string, Set<AbArm>>();
17
+ const walk = (node: LayoutNode): void => {
18
+ const v = node.variant;
19
+ if (v) {
20
+ const seen = arms.get(v.test) ?? new Set<AbArm>();
21
+ seen.add(v.arm);
22
+ arms.set(v.test, seen);
23
+ }
24
+ if (isParentNode(node)) for (const child of node.children) walk(child);
25
+ };
26
+ walk(layout.root);
27
+ return new Set([...arms].filter(([, seen]) => seen.size < 2).map(([test]) => test));
28
+ }
29
+
30
+ /** Every A/B test in the layout with both arms, at most 10, with B's split (default 50 %). */
12
31
  export function collectAbTests(layout: Layout): AbTest[] {
32
+ const lone = loneAbTests(layout);
13
33
  const tests = new Map<string, number>();
14
34
  const walk = (node: LayoutNode): void => {
15
35
  const v = node.variant;
16
- if (v && AB_TEST_NAME.test(v.test) && (tests.has(v.test) || tests.size < 10)) {
36
+ if (
37
+ v &&
38
+ !lone.has(v.test) &&
39
+ AB_TEST_NAME.test(v.test) &&
40
+ (tests.has(v.test) || tests.size < 10)
41
+ ) {
17
42
  const known = tests.get(v.test);
18
43
  if (v.arm === "b" && v.split !== undefined) tests.set(v.test, v.split);
19
44
  else if (known === undefined) tests.set(v.test, 50);
@@ -44,8 +69,9 @@ export function pickArm(
44
69
  export function variantShows(
45
70
  node: LayoutNode,
46
71
  arms: Readonly<Record<string, AbArm>> | undefined,
72
+ lone?: ReadonlySet<string>,
47
73
  ): boolean {
48
74
  const v = node.variant;
49
- if (!v) return true;
75
+ if (!v || lone?.has(v.test)) return true;
50
76
  return (arms?.[v.test] ?? "a") === v.arm;
51
77
  }
@@ -205,6 +205,8 @@ const refsOf = (owner: CopiedStyle): Ref[] => [
205
205
  ...STYLE_STATES.flatMap((state) => refsInStyle(owner.states?.[state])),
206
206
  ...refsInStyle(owner.devices?.tablet),
207
207
  ...refsInStyle(owner.devices?.mobile),
208
+ // W-643: a container-query override (W-346) can use a variable too.
209
+ ...refsInStyle((owner as { query?: { style?: StyleProps } }).query?.style),
208
210
  ];
209
211
 
210
212
  const hasVariable = (design: DesignSystem, ref: Ref) =>
@@ -311,6 +313,11 @@ function cleanNode(
311
313
  next = { ...next };
312
314
  delete next.htmlId;
313
315
  }
316
+ if (next.variant) {
317
+ // A pasted copy is never part of an A/B test, like a duplicate (W-632).
318
+ next = { ...next };
319
+ delete next.variant;
320
+ }
314
321
  const kids = nodeChildren(next);
315
322
  if (kids.length === 0) return next;
316
323
  return {
@@ -75,15 +75,20 @@ const block = (selector: string, declarations: Declaration[]) =>
75
75
  : `${selector}{${declarations.map((d) => `${d.property}:${d.value}`).join(";")}}`;
76
76
 
77
77
  /** Tag defaults sit under `:where` so a class (0,1,0) still beats the tag (0,0,1). */
78
- function tagDefaultCss(design: DesignSystem): string {
78
+ function tagDefaultCss(
79
+ design: DesignSystem,
80
+ track: (selector: string, declarations: Declaration[]) => Declaration[],
81
+ ): string {
79
82
  const defaults = design.defaults;
80
83
  if (!defaults) return "";
81
84
  let css = "";
82
85
  for (const tag of DEFAULT_STYLE_TAGS) {
83
86
  const style = defaults[tag];
84
87
  if (!style) continue;
85
- const { declarations } = styleDeclarations(style);
86
- css += block(`:where(.emvb-root) ${tag}`, declarations);
88
+ // W-670: tracked like classes, so a tag default's entrance gets its keyframes and turns off
89
+ // for reduced motion.
90
+ const selector = `:where(.emvb-root) ${tag}`;
91
+ css += block(selector, track(selector, styleDeclarations(style).declarations));
87
92
  }
88
93
  return css;
89
94
  }
@@ -189,6 +194,8 @@ export function generateCss({
189
194
  withInheritedLayers(cls.devices?.mobile, { ...cls.style, ...cls.devices?.tablet }),
190
195
  ).declarations,
191
196
  hiddenOn: cls.hiddenOn,
197
+ // W-571: the page root is never hidden (W-567), not even by a class.
198
+ hideSelector: `.${className}:not(.emvb-root)`,
192
199
  },
193
200
  ]
194
201
  : [];
@@ -220,7 +227,7 @@ export function generateCss({
220
227
  .flatMap((rule) =>
221
228
  "figure" in rule && rule.figure
222
229
  ? [rule.selector, `.emvb-figure:has(>${rule.selector},>a>${rule.selector})`]
223
- : [rule.selector],
230
+ : ["hideSelector" in rule && rule.hideSelector ? rule.hideSelector : rule.selector],
224
231
  );
225
232
  return forDevices(
226
233
  [device],
@@ -237,15 +244,33 @@ export function generateCss({
237
244
  entrances.push(rule.selector);
238
245
  }
239
246
  }
247
+ const defaultsCss = tagDefaultCss(design, track);
248
+ // W-670: an entrance or scroll motion set only in a container query override pointed at
249
+ // keyframes that were never sent (no animation at all) and ignored reduced motion.
250
+ for (const rule of localRules) {
251
+ const query = rule.query ?? [];
252
+ const selector = `.emvb-e-${rule.id}`;
253
+ if (usesMotion(query)) motion = true;
254
+ if (!entrances.includes(selector) && query.some((d) => d.property === "animation")) {
255
+ entrances.push(selector);
256
+ }
257
+ if (!animated.includes(selector) && query.some((d) => d.property === "transition")) {
258
+ animated.push(selector);
259
+ }
260
+ }
240
261
  return [
241
262
  entrances.length > 0
242
263
  ? "@keyframes emvb-fade{from{opacity:0}to{opacity:1}}@keyframes emvb-fade-up{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}@keyframes emvb-fade-down{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:none}}@keyframes emvb-slide-up{from{opacity:0;transform:translateY(16px)}to{opacity:1;transform:none}}@keyframes emvb-slide-down{from{opacity:0;transform:translateY(-16px)}to{opacity:1;transform:none}}@keyframes emvb-scale{from{opacity:0;transform:scale(0.96)}to{opacity:1;transform:none}}"
243
264
  : "",
244
265
  entrances.length > 0 && motion ? MOTION_KEYFRAMES : "",
245
266
  block(".emvb-root", variables),
246
- tagDefaultCss(design),
267
+ defaultsCss,
247
268
  backgroundVideo
248
- ? ".emvb-has-bg-video{position:relative;overflow:hidden}.emvb-bg-video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:0;pointer-events:none}.emvb-has-bg-video>:not(.emvb-bg-video){position:relative;z-index:1}"
269
+ ? ".emvb-has-bg-video{position:relative;overflow:hidden}.emvb-bg-video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:0;pointer-events:none}.emvb-has-bg-video>:not(.emvb-bg-video){position:relative;z-index:1}" +
270
+ // W-802: the overlay above the video, under the content; reset so a nested box's own wins.
271
+ '.emvb-has-bg-video{--emvb-bg-overlay:none}.emvb-has-bg-video::after{content:"";position:absolute;inset:0;z-index:0;pointer-events:none;background:var(--emvb-bg-overlay)}' +
272
+ // W-801: a looping video kept playing for visitors who ask for reduced motion.
273
+ "@media (prefers-reduced-motion: reduce){.emvb-bg-video{display:none}}"
249
274
  : "",
250
275
  ...[...usedTypes].toSorted().map((type) => baseCss.get(type) ?? ""),
251
276
  ...classes,
@@ -2,11 +2,16 @@
2
2
  * Print stylesheet (W-335). Chrome that only makes sense on screen is hidden.
3
3
  * Appended after scoped page CSS so the selectors stay global: a header, float or popup
4
4
  * is not inside the page's scope wrapper.
5
+ * W-845 (D-054): every tab panel and accordion panel prints, not just the open one. The tab rule
6
+ * matches the specificity of the screen rule that hides the other panels and comes later. A
7
+ * closed <details> opens through ::details-content, so a browser without it prints the summary.
5
8
  */
6
9
  export function printCss(): string {
7
10
  return (
8
11
  "@media print{" +
9
12
  ".emvb-theme-header,.emvb-theme-footer,.emvb-float,.emvb-popup{display:none!important}" +
13
+ ".emvb-tabs:has(> .emvb-tab-input:nth-of-type(n):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(n){display:block!important}" +
14
+ ".emvb-accordion-item::details-content{content-visibility:visible;display:block}" +
10
15
  "}"
11
16
  );
12
17
  }
@@ -100,7 +100,14 @@ 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
- const kept = code === 9 ? " " : code === 10 || (code >= 32 && code !== 127) ? char : "";
103
+ // W-677: C1 controls and bidi overrides, embeddings and isolates too: a URL parameter
104
+ // could make a bound heading or link read backwards ("exe.jpg" shown as "gpj.exe").
105
+ const dropped =
106
+ code === 127 ||
107
+ (code >= 0x80 && code <= 0x9f) ||
108
+ (code >= 0x202a && code <= 0x202e) ||
109
+ (code >= 0x2066 && code <= 0x2069);
110
+ const kept = code === 9 ? " " : code === 10 || (code >= 32 && !dropped) ? char : "";
104
111
  // W-502: cutting at a UTF-16 length split an emoji at the limit into a broken half.
105
112
  if (out.length + kept.length > MAX_BOUND_LENGTH) break;
106
113
  out += kept;