@perkyzz/emvb 0.4.0 → 0.5.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.
- package/README.md +19 -3
- package/package.json +4 -3
- package/src/admin/agents-api.ts +39 -0
- package/src/admin/editor/CommandPalette.tsx +43 -2
- package/src/admin/editor/Editor.tsx +27 -0
- package/src/admin/editor/Timeline.tsx +108 -6
- package/src/admin/editor/editor-css.ts +4 -0
- package/src/admin/editor/feature-css.ts +22 -3
- package/src/admin/editor/palette.ts +6 -2
- package/src/admin/editor/panels/ColorControl.tsx +19 -8
- package/src/admin/editor/panels/ElementPanel.tsx +1 -1
- package/src/admin/editor/panels/TokenScales.tsx +4 -2
- package/src/admin/editor/panels/color-space.ts +12 -1
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +84 -28
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +42 -4
- package/src/admin/editor/panels/settings/DraftTextField.tsx +38 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +6 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +2 -3
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/panels/settings/link-rules.ts +19 -0
- package/src/admin/editor/panels/settings/number-input.ts +11 -0
- package/src/admin/editor/panels/settings/query-style.ts +65 -0
- package/src/admin/editor/panels/variable-values.ts +4 -2
- package/src/admin/editor/remote-change.ts +67 -0
- package/src/admin/index.tsx +3 -1
- package/src/admin/media-api.ts +20 -0
- package/src/admin/pages/AgentsPage.tsx +274 -0
- package/src/admin/ui.ts +28 -0
- package/src/astro/floats/runtime.ts +10 -0
- package/src/astro/popups/runtime.ts +15 -0
- package/src/astro/tabs/runtime.ts +60 -1
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +202 -26
- package/src/core/arrange.ts +11 -3
- package/src/core/css/generate.ts +9 -1
- package/src/core/elements/form-elements.ts +19 -3
- package/src/core/elements/index.ts +39 -11
- package/src/core/render/dynamic-post.ts +21 -5
- package/src/core/render/form.ts +12 -5
- package/src/core/render/index.ts +50 -11
- package/src/core/render/pagination.ts +21 -2
- package/src/core/sanitize/embed-url.ts +7 -1
- package/src/core/sanitize/href.ts +13 -1
- package/src/core/schema/descriptors.ts +4 -1
- package/src/core/schema/layout.ts +10 -3
- package/src/core/share/link.ts +4 -1
- package/src/core/theme/dynamic.ts +12 -7
- package/src/mcp/errors.ts +44 -0
- package/src/mcp/index.ts +4 -0
- package/src/mcp/ports.ts +78 -0
- package/src/mcp/prompts.ts +76 -0
- package/src/mcp/publish.ts +60 -0
- package/src/mcp/queue.ts +19 -0
- package/src/mcp/rate-limit.ts +80 -0
- package/src/mcp/read.ts +419 -0
- package/src/mcp/refs.ts +84 -0
- package/src/mcp/settings.ts +18 -0
- package/src/mcp/tools.ts +265 -0
- package/src/mcp/write.ts +582 -0
- package/src/server/agent-settings.ts +134 -0
- package/src/server/design-routes.ts +71 -17
- package/src/server/icon-routes.ts +5 -1
- package/src/server/mcp-routes.ts +265 -0
- package/src/server/plugin.ts +32 -2
package/src/core/a11y/audit.ts
CHANGED
|
@@ -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|
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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
|
|
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
|
-
:
|
|
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:
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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,
|
package/src/core/arrange.ts
CHANGED
|
@@ -320,14 +320,22 @@ export function wrapNode(
|
|
|
320
320
|
if (!found) return refuse(REASONS.missing);
|
|
321
321
|
if (!found.parent) return refuse(REASONS.rootFixed);
|
|
322
322
|
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
323
|
const wrapper: LayoutNode = {
|
|
326
324
|
id: newNodeId(random),
|
|
327
325
|
type,
|
|
328
326
|
props: type === "grid" ? { columns: 2 } : {},
|
|
329
|
-
children: [
|
|
327
|
+
children: [found.node],
|
|
330
328
|
} as LayoutNode;
|
|
329
|
+
// W-389: the same parent/child rules as a drop, so an accordion item, tab panel or menu item
|
|
330
|
+
// isn't wrapped into a page that can't save, and the extra level stays within the depth cap.
|
|
331
|
+
const inForm = underForm(layout, found.parent.id);
|
|
332
|
+
const nesting =
|
|
333
|
+
parentChildRefusal(found.parent, wrapper, inForm) ??
|
|
334
|
+
parentChildRefusal(wrapper, found.node, inForm);
|
|
335
|
+
if (nesting) return refuse(nesting);
|
|
336
|
+
if (found.depth + height(found.node) > MAX_DEPTH) return refuse(REASONS.tooDeep);
|
|
337
|
+
const { layout: without, removed } = removeNode(layout, id);
|
|
338
|
+
if (!removed) return refuse(REASONS.missing);
|
|
331
339
|
return {
|
|
332
340
|
ok: true,
|
|
333
341
|
layout: insertNode(without, found.parent.id, found.index, wrapper),
|
package/src/core/css/generate.ts
CHANGED
|
@@ -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
|
-
.
|
|
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,
|
|
@@ -184,9 +184,15 @@ export const radio: ElementDefinition<RadioNode> = {
|
|
|
184
184
|
build: (node, attrs) => {
|
|
185
185
|
const name = node.props.field;
|
|
186
186
|
// Options filled from definition in W-035; placeholder single option for schema/render smoke.
|
|
187
|
+
const id = controlId(node.id);
|
|
188
|
+
// W-442: a fieldset can't be the target of <label for>, so the question named nothing and
|
|
189
|
+
// the group was read without it. The label names the group through aria-labelledby.
|
|
190
|
+
const labelled: Record<string, string> = node.props.label
|
|
191
|
+
? { "aria-labelledby": `${id}-label` }
|
|
192
|
+
: {};
|
|
187
193
|
const control: VNode = {
|
|
188
194
|
tag: "fieldset",
|
|
189
|
-
attrs: { class: "emvb-radio-group" },
|
|
195
|
+
attrs: { class: "emvb-radio-group", ...labelled },
|
|
190
196
|
children: [
|
|
191
197
|
{
|
|
192
198
|
tag: "label",
|
|
@@ -198,7 +204,16 @@ export const radio: ElementDefinition<RadioNode> = {
|
|
|
198
204
|
},
|
|
199
205
|
],
|
|
200
206
|
};
|
|
201
|
-
|
|
207
|
+
const label: VNode[] = node.props.label
|
|
208
|
+
? [
|
|
209
|
+
{
|
|
210
|
+
tag: "label",
|
|
211
|
+
attrs: { class: "emvb-form-label", id: `${id}-label` },
|
|
212
|
+
children: [node.props.label],
|
|
213
|
+
},
|
|
214
|
+
]
|
|
215
|
+
: [];
|
|
216
|
+
return fieldBox(attrs, [...label, control, errorSlot(name)]);
|
|
202
217
|
},
|
|
203
218
|
};
|
|
204
219
|
|
|
@@ -215,6 +230,7 @@ export const submit: ElementDefinition<SubmitNode> = {
|
|
|
215
230
|
type: "submit",
|
|
216
231
|
class: `${attrs.class ?? ""} ec-form-submit`.trim(),
|
|
217
232
|
},
|
|
218
|
-
|
|
233
|
+
// W-447: a blank label left an empty button with no name; it falls back like an unset one.
|
|
234
|
+
children: [node.props.label?.trim() || "Submit"],
|
|
219
235
|
}),
|
|
220
236
|
};
|
|
@@ -297,7 +297,7 @@ const button: ElementDefinition<ButtonNode> = {
|
|
|
297
297
|
{ value: "lg", label: "Large" },
|
|
298
298
|
],
|
|
299
299
|
},
|
|
300
|
-
{ key: "iconGap", kind: "int", label: "Gap (px)", optional: true },
|
|
300
|
+
{ key: "iconGap", kind: "int", label: "Gap (px)", optional: true, min: 0, max: 64 },
|
|
301
301
|
],
|
|
302
302
|
},
|
|
303
303
|
build: (node, attrs) => {
|
|
@@ -418,8 +418,8 @@ const image: ElementDefinition<ImageNode> = {
|
|
|
418
418
|
},
|
|
419
419
|
{ key: "newTab", kind: "boolean", label: "Open link in a new tab", optional: true },
|
|
420
420
|
{ key: "caption", kind: "text", label: "Caption", optional: true },
|
|
421
|
-
{ key: "focalX", kind: "int", label: "Focal point X (%)", optional: true },
|
|
422
|
-
{ key: "focalY", kind: "int", label: "Focal point Y (%)", optional: true },
|
|
421
|
+
{ key: "focalX", kind: "int", label: "Focal point X (%)", optional: true, min: 0, max: 100 },
|
|
422
|
+
{ key: "focalY", kind: "int", label: "Focal point Y (%)", optional: true, min: 0, max: 100 },
|
|
423
423
|
{
|
|
424
424
|
key: "width",
|
|
425
425
|
kind: "int",
|
|
@@ -434,6 +434,7 @@ const image: ElementDefinition<ImageNode> = {
|
|
|
434
434
|
optional: true,
|
|
435
435
|
message: "Height must be a positive whole number.",
|
|
436
436
|
},
|
|
437
|
+
{ key: "sources", kind: "image-sources", label: "Extra sizes (srcset)", optional: true },
|
|
437
438
|
],
|
|
438
439
|
},
|
|
439
440
|
build: (node, attrs) => {
|
|
@@ -457,7 +458,7 @@ const image: ElementDefinition<ImageNode> = {
|
|
|
457
458
|
if (decorative) imgAttrs.role = "presentation";
|
|
458
459
|
if (node.props.width !== undefined) imgAttrs.width = String(node.props.width);
|
|
459
460
|
if (node.props.height !== undefined) imgAttrs.height = String(node.props.height);
|
|
460
|
-
const sources = imageSources(node.props.
|
|
461
|
+
const sources = imageSources(src, node.props.sources, node.props.width);
|
|
461
462
|
if (sources) {
|
|
462
463
|
imgAttrs.srcset = sources;
|
|
463
464
|
imgAttrs.sizes = "100vw";
|
|
@@ -484,22 +485,45 @@ const image: ElementDefinition<ImageNode> = {
|
|
|
484
485
|
},
|
|
485
486
|
};
|
|
486
487
|
|
|
488
|
+
const validSourceWidth = (width: unknown): width is number =>
|
|
489
|
+
Number.isInteger(width) && (width as number) >= 1 && (width as number) <= 8000;
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* W-428: a same-site path may hold a space ("/uploads/my photo.jpg"); in srcset that space ends
|
|
493
|
+
* the URL, so the size was dropped. It's encoded; full addresses can't hold spaces anyway.
|
|
494
|
+
*/
|
|
495
|
+
const srcsetUrl = (url: string | undefined): string | undefined => url?.replaceAll(" ", "%20");
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* W-385: with `w` descriptors the browser picks only from srcset and ignores `src`, so the main
|
|
499
|
+
* image is listed too when its width is known (its own source entry, else the Width field).
|
|
500
|
+
*/
|
|
487
501
|
function imageSources(
|
|
488
502
|
src: string,
|
|
489
503
|
sources: { src: string; width: number }[] | undefined,
|
|
504
|
+
width: number | undefined,
|
|
490
505
|
): string | undefined {
|
|
491
506
|
if (!sources || sources.length === 0) return undefined;
|
|
492
507
|
const parts: string[] = [];
|
|
493
508
|
const seen = new Set<string>();
|
|
509
|
+
let srcWidth: number | undefined;
|
|
494
510
|
for (const source of sources) {
|
|
495
|
-
const url = sanitizeMediaUrl(source.src);
|
|
511
|
+
const url = srcsetUrl(sanitizeMediaUrl(source.src));
|
|
512
|
+
if (!validSourceWidth(source.width)) continue;
|
|
513
|
+
if (url === srcsetUrl(src)) {
|
|
514
|
+
srcWidth ??= source.width;
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
496
517
|
// A comma or space is another srcset candidate, so one field would request a second host.
|
|
497
|
-
if (!url || /[\s,]/.test(url) ||
|
|
498
|
-
if (!Number.isInteger(source.width) || source.width < 1 || source.width > 8000) continue;
|
|
518
|
+
if (!url || /[\s,]/.test(url) || seen.has(url)) continue;
|
|
499
519
|
seen.add(url);
|
|
500
520
|
parts.push(`${url} ${source.width}w`);
|
|
501
521
|
}
|
|
502
|
-
|
|
522
|
+
if (parts.length === 0) return undefined;
|
|
523
|
+
srcWidth ??= validSourceWidth(width) ? width : undefined;
|
|
524
|
+
const main = srcsetUrl(src);
|
|
525
|
+
if (srcWidth !== undefined && main && !/[\s,]/.test(main)) parts.push(`${main} ${srcWidth}w`);
|
|
526
|
+
return parts.join(", ");
|
|
503
527
|
}
|
|
504
528
|
|
|
505
529
|
/** Root stroke widths the Stroke width control can override (W-237); Lucide and Tabler use 2. */
|
|
@@ -957,6 +981,10 @@ const layoutSection: ElementDefinition<LayoutSectionNode> = {
|
|
|
957
981
|
},
|
|
958
982
|
};
|
|
959
983
|
|
|
984
|
+
/** W-394: shown when a custom track line can't be saved. */
|
|
985
|
+
const TRACKS_HINT =
|
|
986
|
+
"Up to 12 tracks, one per line: 1fr, 2fr, 3fr, auto, min-content, max-content, or a length.";
|
|
987
|
+
|
|
960
988
|
const grid: ElementDefinition<GridNode> = {
|
|
961
989
|
baseCss: ".emvb-grid{display:grid;min-width:0}",
|
|
962
990
|
defaults: () => ({ type: "grid", props: { columns: 3 }, children: [] }),
|
|
@@ -981,21 +1009,21 @@ const grid: ElementDefinition<GridNode> = {
|
|
|
981
1009
|
kind: "list-items",
|
|
982
1010
|
label: "Custom tracks",
|
|
983
1011
|
optional: true,
|
|
984
|
-
message:
|
|
1012
|
+
message: TRACKS_HINT,
|
|
985
1013
|
},
|
|
986
1014
|
{
|
|
987
1015
|
key: "columnTracksTablet",
|
|
988
1016
|
kind: "list-items",
|
|
989
1017
|
label: "Custom tracks on tablet",
|
|
990
1018
|
optional: true,
|
|
991
|
-
message:
|
|
1019
|
+
message: `${TRACKS_HINT} Leave empty to follow the desktop tracks.`,
|
|
992
1020
|
},
|
|
993
1021
|
{
|
|
994
1022
|
key: "columnTracksMobile",
|
|
995
1023
|
kind: "list-items",
|
|
996
1024
|
label: "Custom tracks on mobile",
|
|
997
1025
|
optional: true,
|
|
998
|
-
message:
|
|
1026
|
+
message: `${TRACKS_HINT} Leave empty to follow the next wider device.`,
|
|
999
1027
|
},
|
|
1000
1028
|
...BOX_LINK_FIELDS,
|
|
1001
1029
|
],
|
|
@@ -29,7 +29,12 @@ type PostField = {
|
|
|
29
29
|
/** Whether the post has this field; the placeholder stands in when it doesn't. */
|
|
30
30
|
has?: (post: ThemePostFields) => boolean;
|
|
31
31
|
/** The field's markup, or nothing when the post's value is empty or unsafe. */
|
|
32
|
-
render: (
|
|
32
|
+
render: (
|
|
33
|
+
node: LayoutNode,
|
|
34
|
+
attrs: Attrs,
|
|
35
|
+
post: ThemePostFields,
|
|
36
|
+
inLoop: boolean,
|
|
37
|
+
) => VNode | undefined;
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
type PostDateFormat = (typeof POST_DATE_FORMATS)[number];
|
|
@@ -91,13 +96,16 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
91
96
|
children: ["Featured image"],
|
|
92
97
|
}),
|
|
93
98
|
has: (post) => !!post.featuredImageUrl,
|
|
94
|
-
render: (node, attrs, post) => {
|
|
99
|
+
render: (node, attrs, post, inLoop) => {
|
|
95
100
|
const src = sanitizeMediaUrl(post.featuredImageUrl ?? "");
|
|
96
101
|
if (!src) return undefined;
|
|
97
102
|
const alt = props<{ decorative?: boolean }>(node).decorative
|
|
98
103
|
? ""
|
|
99
104
|
: post.featuredImageAlt?.trim() || post.title || "Featured image";
|
|
100
|
-
|
|
105
|
+
// W-440: a Loop's images below the fold loaded all at once; like Image, they wait.
|
|
106
|
+
// A single post's featured image is usually the hero, so it isn't delayed.
|
|
107
|
+
const lazy: Attrs = inLoop ? { loading: "lazy", decoding: "async" } : {};
|
|
108
|
+
return { tag: "img", attrs: { ...attrs, src, alt, ...lazy }, children: [] };
|
|
101
109
|
},
|
|
102
110
|
},
|
|
103
111
|
],
|
|
@@ -118,10 +126,17 @@ const POST_FIELDS = new Map<string, PostField>([
|
|
|
118
126
|
linkAttrs.target = "_blank";
|
|
119
127
|
linkAttrs.rel = "noopener noreferrer";
|
|
120
128
|
}
|
|
129
|
+
const label = text?.trim();
|
|
130
|
+
const title = post.title.trim();
|
|
131
|
+
// W-439: a Loop repeats the same "Read more" for every post; screen readers listing links
|
|
132
|
+
// heard it N times. The name keeps the visible text first and adds the post's title.
|
|
133
|
+
if (label && title && !label.toLowerCase().includes(title.toLowerCase())) {
|
|
134
|
+
linkAttrs["aria-label"] = `${label}: ${title}`;
|
|
135
|
+
}
|
|
121
136
|
return {
|
|
122
137
|
tag: "a",
|
|
123
138
|
attrs: linkAttrs,
|
|
124
|
-
children: [
|
|
139
|
+
children: [label || title || post.permalink],
|
|
125
140
|
};
|
|
126
141
|
},
|
|
127
142
|
},
|
|
@@ -164,11 +179,12 @@ export function renderDynamicPost(
|
|
|
164
179
|
attrs: Attrs,
|
|
165
180
|
post: ThemePostFields | undefined,
|
|
166
181
|
mode: RenderMode,
|
|
182
|
+
inLoop = false,
|
|
167
183
|
): VNode | undefined {
|
|
168
184
|
const field = POST_FIELDS.get(node.type);
|
|
169
185
|
if (!field) return undefined;
|
|
170
186
|
if (!post || field.has?.(post) === false) {
|
|
171
187
|
return mode === "editor" ? field.placeholder(attrs) : undefined;
|
|
172
188
|
}
|
|
173
|
-
return field.render(node, attrs, post);
|
|
189
|
+
return field.render(node, attrs, post, inLoop);
|
|
174
190
|
}
|
package/src/core/render/form.ts
CHANGED
|
@@ -40,7 +40,9 @@ const honeypot = (inputId: string): VNode => ({
|
|
|
40
40
|
/** The text of the form's first Submit button, as the page renders it. */
|
|
41
41
|
function firstSubmitLabel(nodes: readonly LayoutNode[]): string | undefined {
|
|
42
42
|
for (const child of nodes) {
|
|
43
|
-
if (child.type === "submit")
|
|
43
|
+
if (child.type === "submit") {
|
|
44
|
+
return (child.props as { label?: string }).label?.trim() || "Submit";
|
|
45
|
+
}
|
|
44
46
|
const found = firstSubmitLabel(nodeChildren(child));
|
|
45
47
|
if (found !== undefined) return found;
|
|
46
48
|
}
|
|
@@ -299,11 +301,16 @@ function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): V
|
|
|
299
301
|
return { ...child, children: [...child.children, mark] };
|
|
300
302
|
}
|
|
301
303
|
// The checkbox label wraps the input and the label text; the mark follows the text.
|
|
304
|
+
// W-441: the same hidden mark as other labels; a plain " *" was read out as "star".
|
|
302
305
|
if (child.attrs.class === "emvb-form-checkbox-label") {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
};
|
|
306
|
+
let last = -1;
|
|
307
|
+
child.children.forEach((part, i) => {
|
|
308
|
+
if (typeof part === "string") last = i;
|
|
309
|
+
});
|
|
310
|
+
if (last === -1) return child;
|
|
311
|
+
const children = [...child.children];
|
|
312
|
+
children.splice(last + 1, 0, mark);
|
|
313
|
+
return { ...child, children };
|
|
307
314
|
}
|
|
308
315
|
return child;
|
|
309
316
|
});
|