@perkyzz/emvb 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/package.json +4 -4
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +22 -2
- package/src/admin/editor/Timeline.tsx +1 -8
- package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
- package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
- package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
- package/src/admin/editor/canvas/vnode-react.tsx +5 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/dnd/dragged-source.ts +22 -0
- package/src/admin/editor/dnd/layer-drop.ts +141 -0
- package/src/admin/editor/dnd/new-element.ts +76 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +34 -0
- package/src/admin/editor/feature-css.ts +22 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/FontFaces.tsx +342 -0
- package/src/admin/editor/panels/LayersPanel.tsx +56 -6
- package/src/admin/editor/panels/LeftPanel.tsx +153 -29
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
- package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
- package/src/admin/editor/panels/TokenScales.tsx +2 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
- package/src/admin/editor/panels/VariableSection.tsx +111 -7
- package/src/admin/editor/panels/color-space.ts +71 -6
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +33 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
- package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
- package/src/admin/editor/panels/settings/style-sections.ts +19 -2
- package/src/admin/editor/panels/url-rules.ts +43 -0
- package/src/admin/editor/panels/use-layers-drop.ts +232 -0
- package/src/admin/editor/store.ts +4 -2
- package/src/admin/editor/useExtensions.ts +3 -1
- package/src/admin/editor/useNodeActions.ts +74 -1
- package/src/admin/editor/useSave.ts +116 -85
- package/src/admin/export-api.ts +25 -2
- package/src/admin/extension-outputs.ts +179 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +22 -188
- package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
- package/src/admin/pages/ImportImageCopies.tsx +167 -0
- package/src/admin/pages/ImportReport.tsx +63 -0
- package/src/admin/pages/NewPageDialog.tsx +54 -32
- package/src/admin/pages/PageList.tsx +9 -0
- package/src/admin/pages/ThemePartList.tsx +9 -0
- package/src/astro/EmVBPage.astro +5 -2
- package/src/astro/extension-styles.ts +35 -0
- package/src/astro/forms/EmVBFormsClient.astro +3 -0
- package/src/astro/forms/enhance.ts +107 -0
- package/src/astro/popups/runtime.ts +47 -2
- package/src/astro/render.ts +19 -4
- package/src/astro/request-data.ts +6 -0
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/resolve.ts +9 -0
- package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
- package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
- package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
- package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +22 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +91 -0
- package/src/astro/widgets/counter.ts +98 -0
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +99 -0
- package/src/astro/widgets/map.ts +37 -0
- package/src/astro/widgets/share.ts +21 -0
- package/src/astro/widgets/sticky.ts +87 -0
- package/src/astro/widgets/theme.ts +52 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +177 -6
- package/src/core/arrange.ts +71 -1
- package/src/core/canvas-collections.ts +28 -0
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +35 -1
- package/src/core/elements/counter-format.ts +15 -0
- package/src/core/elements/form-elements.ts +119 -9
- package/src/core/elements/icon-svg.ts +14 -0
- package/src/core/elements/index.ts +54 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/marketing.ts +1490 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +40 -5
- package/src/core/export/runtimes.generated.ts +10 -3
- package/src/core/export/site.ts +55 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +17 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +66 -21
- package/src/core/extensions/safe-nodes.ts +67 -11
- package/src/core/extensions/types.ts +48 -1
- package/src/core/fonts/files.ts +74 -0
- package/src/core/fonts/google.ts +112 -0
- package/src/core/fonts/test-font.ts +9 -0
- package/src/core/import/elementor/context.ts +13 -4
- package/src/core/import/elementor/index.ts +32 -21
- package/src/core/import/elementor/widgets.ts +532 -293
- package/src/core/import/html/blocks.ts +602 -0
- package/src/core/import/html/index.ts +155 -0
- package/src/core/import/html/map.ts +958 -0
- package/src/core/import/html/parse.ts +430 -0
- package/src/core/index.ts +45 -0
- package/src/core/limits.ts +6 -0
- package/src/core/migrate/v18.ts +3 -0
- package/src/core/public-attributes.ts +17 -0
- package/src/core/render/extras.ts +31 -7
- package/src/core/render/form.ts +103 -10
- package/src/core/render/index.ts +172 -16
- package/src/core/render/section.ts +31 -1
- package/src/core/render/spacer-basis.ts +102 -0
- package/src/core/render/theme-boot.ts +16 -0
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +68 -3
- package/src/core/sanitize/motion.ts +12 -0
- package/src/core/schema/design.ts +40 -0
- package/src/core/schema/layout.ts +534 -22
- package/src/core/schema/style.ts +28 -0
- package/src/core/templates/index.ts +218 -0
- package/src/core/templates/pages.ts +29 -0
- package/src/core/templates/sections.ts +794 -0
- package/src/core/templates/types.ts +9 -0
- package/src/core/theme/dynamic.ts +11 -6
- package/src/core/theme/popup-markup.ts +21 -2
- package/src/core/theme/popup-rules.ts +36 -0
- package/src/core/theme/triggers.ts +64 -5
- package/src/core/translatable.ts +5 -2
- package/src/extension-build.ts +331 -0
- package/src/index.ts +25 -3
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +29 -1
- package/src/mcp/tools.ts +40 -1
- package/src/mcp/write.ts +41 -1
- package/src/server/extension-routes.ts +73 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +11 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1046: the opt-in Animated headline runtime. Each headline with rotating words shows them in
|
|
3
|
+
* turn in its highlight, every `data-interval` seconds for `data-turns` rounds, and stops on the
|
|
4
|
+
* first word. A Pause button after the heading stops it at any time (WCAG 2.2.2). Screen readers
|
|
5
|
+
* keep the sentence with the first word: the changing words are hidden from them meanwhile.
|
|
6
|
+
* Under reduced motion nothing rotates and no button is added.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
type Rotation = { words: string[]; interval: number; turns: number };
|
|
10
|
+
|
|
11
|
+
function read(mark: HTMLElement): Rotation | undefined {
|
|
12
|
+
let words: unknown;
|
|
13
|
+
try {
|
|
14
|
+
words = JSON.parse(mark.dataset["emvbRotate"] ?? "");
|
|
15
|
+
} catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (!Array.isArray(words)) return undefined;
|
|
19
|
+
const list = words.filter((w): w is string => typeof w === "string" && w.trim() !== "");
|
|
20
|
+
if (list.length < 2) return undefined;
|
|
21
|
+
const interval = Number(mark.dataset["interval"]);
|
|
22
|
+
const turns = Number(mark.dataset["turns"]);
|
|
23
|
+
return {
|
|
24
|
+
words: list,
|
|
25
|
+
interval: Number.isFinite(interval) ? Math.min(10, Math.max(1.5, interval)) : 2.5,
|
|
26
|
+
turns: Number.isFinite(turns) ? Math.min(5, Math.max(1, Math.round(turns))) : 2,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function start(mark: HTMLElement, r: Rotation): void {
|
|
31
|
+
const doc = mark.ownerDocument;
|
|
32
|
+
const heading = mark.closest("h1, h2, h3, h4, h5, h6") ?? mark;
|
|
33
|
+
// The word changes in its own text node; the circle (if any) stays.
|
|
34
|
+
const found = [...mark.childNodes].find((n) => n.nodeType === Node.TEXT_NODE);
|
|
35
|
+
if (!found) return;
|
|
36
|
+
const text: Node = found;
|
|
37
|
+
const spoken = doc.createElement("span");
|
|
38
|
+
spoken.className = "emvb-headline-sr";
|
|
39
|
+
spoken.textContent = r.words[0] ?? "";
|
|
40
|
+
mark.before(spoken);
|
|
41
|
+
mark.setAttribute("aria-hidden", "true");
|
|
42
|
+
|
|
43
|
+
const pause = doc.createElement("button");
|
|
44
|
+
pause.type = "button";
|
|
45
|
+
pause.className = "emvb-headline-pause";
|
|
46
|
+
pause.setAttribute("aria-pressed", "false");
|
|
47
|
+
pause.textContent = "Pause";
|
|
48
|
+
heading.after(pause);
|
|
49
|
+
|
|
50
|
+
let step = 0;
|
|
51
|
+
const last = r.words.length * r.turns;
|
|
52
|
+
const timer = setInterval(() => {
|
|
53
|
+
step++;
|
|
54
|
+
text.textContent = r.words[step % r.words.length] ?? "";
|
|
55
|
+
if (step < last) return;
|
|
56
|
+
// W-1059: the button goes away at the end; if it had focus, focus moves on as after Pause.
|
|
57
|
+
const focused = doc.activeElement === pause;
|
|
58
|
+
const next = pause.nextElementSibling;
|
|
59
|
+
stop();
|
|
60
|
+
if (focused) moveOn(next);
|
|
61
|
+
}, r.interval * 1000);
|
|
62
|
+
|
|
63
|
+
function stop(): void {
|
|
64
|
+
clearInterval(timer);
|
|
65
|
+
text.textContent = r.words[0] ?? "";
|
|
66
|
+
mark.removeAttribute("aria-hidden");
|
|
67
|
+
spoken.remove();
|
|
68
|
+
pause.remove();
|
|
69
|
+
}
|
|
70
|
+
/** Focus after the removed button: the control that followed it, else the heading. */
|
|
71
|
+
function moveOn(next: Element | null): void {
|
|
72
|
+
if (
|
|
73
|
+
next instanceof HTMLElement &&
|
|
74
|
+
next.matches("a[href], button, input, select, textarea, [tabindex]")
|
|
75
|
+
)
|
|
76
|
+
next.focus();
|
|
77
|
+
else if (heading instanceof HTMLElement) {
|
|
78
|
+
heading.tabIndex = -1;
|
|
79
|
+
heading.focus();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Pausing ends the rotation for good, back on the first word.
|
|
83
|
+
pause.addEventListener("click", () => {
|
|
84
|
+
const next = pause.nextElementSibling;
|
|
85
|
+
stop();
|
|
86
|
+
moveOn(next);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function initHeadlines(root: ParentNode = document): void {
|
|
91
|
+
const reduced = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
|
|
92
|
+
if (reduced) return;
|
|
93
|
+
for (const mark of root.querySelectorAll<HTMLElement>("[data-emvb-rotate]")) {
|
|
94
|
+
if (mark.dataset["emvbReady"] !== undefined) continue;
|
|
95
|
+
mark.dataset["emvbReady"] = "";
|
|
96
|
+
const r = read(mark);
|
|
97
|
+
if (r) start(mark, r);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1041: the opt-in Map runtime. It shows each Map's "Show the map" button (hidden by CSS until
|
|
3
|
+
* this script marks the Map ready) and, only when it is pressed, replaces it with the map in an
|
|
4
|
+
* iframe, so nothing is fetched from the map service before the visitor asks.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const ALLOWED = /^https:\/\/www\.(?:openstreetmap\.org\/export\/embed\.html|google\.com\/maps)\?/;
|
|
8
|
+
|
|
9
|
+
function load(frame: HTMLElement): void {
|
|
10
|
+
const src = frame.dataset["src"] ?? "";
|
|
11
|
+
if (!ALLOWED.test(src)) return;
|
|
12
|
+
// oxlint-disable-next-line react/iframe-missing-sandbox -- set just below, before it loads
|
|
13
|
+
const iframe = frame.ownerDocument.createElement("iframe");
|
|
14
|
+
// Map pages need their own scripts; they stay in their own origin and may open links.
|
|
15
|
+
iframe.setAttribute(
|
|
16
|
+
"sandbox",
|
|
17
|
+
"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox",
|
|
18
|
+
);
|
|
19
|
+
iframe.src = src;
|
|
20
|
+
iframe.title = frame.dataset["title"] || "Map";
|
|
21
|
+
iframe.height = frame.dataset["height"] || "360";
|
|
22
|
+
iframe.loading = "lazy";
|
|
23
|
+
iframe.referrerPolicy = "no-referrer-when-downgrade";
|
|
24
|
+
frame.replaceChildren(iframe);
|
|
25
|
+
iframe.focus();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function initMaps(root: ParentNode = document): void {
|
|
29
|
+
for (const map of root.querySelectorAll<HTMLElement>("[data-emvb-map]")) {
|
|
30
|
+
if (map.dataset["emvbReady"] !== undefined) continue;
|
|
31
|
+
const frame = map.querySelector<HTMLElement>(".emvb-map-frame");
|
|
32
|
+
const button = frame?.querySelector<HTMLButtonElement>(".emvb-map-load");
|
|
33
|
+
if (!frame || !button) continue;
|
|
34
|
+
map.dataset["emvbReady"] = "";
|
|
35
|
+
button.addEventListener("click", () => load(frame));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1047: the opt-in Share runtime. Where the browser has its own share sheet
|
|
3
|
+
* (`navigator.share`), it shows each Share buttons element's Share button (hidden by CSS until
|
|
4
|
+
* then) and opens the sheet for this page when it is pressed. Elsewhere nothing changes: the
|
|
5
|
+
* plain share links stay.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function initShare(root: ParentNode = document): void {
|
|
9
|
+
const nav = globalThis.navigator as Navigator | undefined;
|
|
10
|
+
if (typeof nav?.share !== "function") return;
|
|
11
|
+
for (const list of root.querySelectorAll<HTMLElement>("[data-emvb-share-list]")) {
|
|
12
|
+
if (list.dataset["emvbReady"] !== undefined) continue;
|
|
13
|
+
list.dataset["emvbReady"] = "";
|
|
14
|
+
const button = list.querySelector<HTMLButtonElement>("[data-emvb-share]");
|
|
15
|
+
button?.addEventListener("click", () => {
|
|
16
|
+
const doc = list.ownerDocument;
|
|
17
|
+
// A visitor closing the sheet rejects the promise; there is nothing to report.
|
|
18
|
+
nav.share({ title: doc.title, url: doc.location.href.split("#")[0] }).catch(() => {});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1070: the opt-in sticky script. An element marked `data-emvb-sticky-hide` (its style's "Hide
|
|
3
|
+
* while scrolling down") slides out of view once the page scrolls down past it, and back as soon
|
|
4
|
+
* as the visitor scrolls up. Its CSS custom property `--emvb-sticky-hide` says whether that is on
|
|
5
|
+
* at the current width (`0` turns it off on a device). A bar held at the top slides up; one held
|
|
6
|
+
* at the bottom slides down. It never hides while focus is inside it (WCAG 2.4.11), and it moves
|
|
7
|
+
* without animation for visitors who prefer reduced motion. The slide is a Web Animation, so the
|
|
8
|
+
* element's own CSS transitions stay as they are.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Scrolls smaller than this (px) don't change direction: trackpads jitter. */
|
|
12
|
+
const SLACK = 4;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Moves `el` to `to` (`""` is its place), sliding from where it was unless motion is reduced. A
|
|
16
|
+
* slide started before is left to finish: the newer one sits above it and wins.
|
|
17
|
+
*/
|
|
18
|
+
function move(el: HTMLElement, to: string, reduced: boolean): void {
|
|
19
|
+
const from = el.style.translate;
|
|
20
|
+
if (from === to) return;
|
|
21
|
+
el.style.translate = to;
|
|
22
|
+
if (reduced || typeof el.animate !== "function") return;
|
|
23
|
+
el.animate([{ translate: from || "0 0" }, { translate: to || "0 0" }], {
|
|
24
|
+
duration: 250,
|
|
25
|
+
easing: "ease",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function show(el: HTMLElement, reduced: boolean): void {
|
|
30
|
+
delete el.dataset["emvbAway"];
|
|
31
|
+
move(el, "", reduced);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Whether hiding is on at this width; an older page without the property always hides. */
|
|
35
|
+
function hidesHere(style: CSSStyleDeclaration): boolean {
|
|
36
|
+
return style.getPropertyValue("--emvb-sticky-hide").trim() !== "0";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Held in the lower half of the screen (a bar fixed or stuck to the bottom): it leaves downwards.
|
|
41
|
+
* Read from where it sits, as the computed `top` of a placed element is a length, never `auto`.
|
|
42
|
+
*/
|
|
43
|
+
function heldAtBottom(el: HTMLElement): boolean {
|
|
44
|
+
const { top, height } = el.getBoundingClientRect();
|
|
45
|
+
return top + height / 2 > globalThis.innerHeight / 2;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function initSticky(root: ParentNode = document): void {
|
|
49
|
+
const all = [...root.querySelectorAll<HTMLElement>("[data-emvb-sticky-hide]")].filter(
|
|
50
|
+
(el) => el.dataset["emvbReady"] === undefined,
|
|
51
|
+
);
|
|
52
|
+
if (all.length === 0) return;
|
|
53
|
+
const reduced = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
|
|
54
|
+
for (const el of all) {
|
|
55
|
+
el.dataset["emvbReady"] = "";
|
|
56
|
+
// Focus moving in (a Tab from the address bar, a skip link) brings it back at once.
|
|
57
|
+
el.addEventListener("focusin", () => show(el, reduced));
|
|
58
|
+
}
|
|
59
|
+
let last = globalThis.scrollY;
|
|
60
|
+
let frame = 0;
|
|
61
|
+
const update = () => {
|
|
62
|
+
const y = globalThis.scrollY;
|
|
63
|
+
if (Math.abs(y - last) < SLACK) return;
|
|
64
|
+
const down = y > last;
|
|
65
|
+
last = y;
|
|
66
|
+
for (const el of all) {
|
|
67
|
+
const style = getComputedStyle(el);
|
|
68
|
+
if (!hidesHere(style)) {
|
|
69
|
+
if (el.dataset["emvbAway"] !== undefined) show(el, reduced);
|
|
70
|
+
} else if (down && y > el.offsetHeight && !el.contains(document.activeElement)) {
|
|
71
|
+
if (el.dataset["emvbAway"] !== undefined) continue;
|
|
72
|
+
el.dataset["emvbAway"] = "";
|
|
73
|
+
move(el, heldAtBottom(el) ? "0 100%" : "0 -100%", reduced);
|
|
74
|
+
} else if (!down) {
|
|
75
|
+
show(el, reduced);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
globalThis.addEventListener(
|
|
80
|
+
"scroll",
|
|
81
|
+
() => {
|
|
82
|
+
cancelAnimationFrame(frame);
|
|
83
|
+
frame = requestAnimationFrame(update);
|
|
84
|
+
},
|
|
85
|
+
{ passive: true },
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1067: the opt-in Theme toggle runtime. A choice made with a Theme toggle is kept in this
|
|
3
|
+
* browser and marks `<html data-emvb-theme="light|dark">`, which the page CSS reads before the
|
|
4
|
+
* visitor's system setting. Each toggle shows once this runs, and says whether dark is on. The
|
|
5
|
+
* page itself puts a saved choice back before it is drawn (THEME_BOOT_SCRIPT).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { THEME_STORAGE_KEY } from "../../core/render/theme-boot.ts";
|
|
9
|
+
|
|
10
|
+
function stored(): "light" | "dark" | null {
|
|
11
|
+
try {
|
|
12
|
+
const value = localStorage.getItem(THEME_STORAGE_KEY);
|
|
13
|
+
return value === "light" || value === "dark" ? value : null;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const systemDark = () => globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches === true;
|
|
20
|
+
|
|
21
|
+
/** Dark is on: chosen, or by the system with no choice made. */
|
|
22
|
+
const isDark = () => {
|
|
23
|
+
const chosen = document.documentElement.dataset["emvbTheme"];
|
|
24
|
+
return chosen === "dark" || (chosen !== "light" && systemDark());
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function sync(): void {
|
|
28
|
+
const dark = String(isDark());
|
|
29
|
+
for (const toggle of document.querySelectorAll<HTMLElement>("[data-emvb-theme-toggle]"))
|
|
30
|
+
toggle.setAttribute("aria-pressed", dark);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function initTheme(root: ParentNode = document): void {
|
|
34
|
+
const choice = stored();
|
|
35
|
+
if (choice) document.documentElement.dataset["emvbTheme"] = choice;
|
|
36
|
+
for (const toggle of root.querySelectorAll<HTMLElement>("[data-emvb-theme-toggle]")) {
|
|
37
|
+
if (toggle.dataset["emvbReady"] !== undefined) continue;
|
|
38
|
+
toggle.dataset["emvbReady"] = "";
|
|
39
|
+
toggle.addEventListener("click", () => {
|
|
40
|
+
const next = isDark() ? "light" : "dark";
|
|
41
|
+
document.documentElement.dataset["emvbTheme"] = next;
|
|
42
|
+
try {
|
|
43
|
+
localStorage.setItem(THEME_STORAGE_KEY, next);
|
|
44
|
+
} catch {
|
|
45
|
+
// Private mode: the choice lasts for this page only.
|
|
46
|
+
}
|
|
47
|
+
sync();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
globalThis.matchMedia?.("(prefers-color-scheme: dark)").addEventListener?.("change", sync);
|
|
51
|
+
sync();
|
|
52
|
+
}
|
package/src/constants.ts
CHANGED
package/src/core/a11y/audit.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { DesignSystem } from "../schema/design.ts";
|
|
|
4
4
|
import { isParentNode, type Layout, type LayoutNode } from "../schema/layout.ts";
|
|
5
5
|
import { boxBecomesLink } from "../render/extras.ts";
|
|
6
6
|
import { ICON_ANIMATION_LIMIT_MS, iconAnimationRuns } from "../icons/animation-runs.ts";
|
|
7
|
-
import { updateNode } from "../tree-ops.ts";
|
|
7
|
+
import { someNode, updateNode } from "../tree-ops.ts";
|
|
8
8
|
import { DEVICES } from "../theme/popup-rules.ts";
|
|
9
9
|
import { hiddenOnEveryDevice } from "../design/devices.ts";
|
|
10
10
|
import { sanitizeHref } from "../sanitize/href.ts";
|
|
@@ -45,7 +45,13 @@ export type A11yIssue = {
|
|
|
45
45
|
| "empty-heading"
|
|
46
46
|
| "landmark-name"
|
|
47
47
|
| "motion"
|
|
48
|
-
| "empty-alert"
|
|
48
|
+
| "empty-alert"
|
|
49
|
+
| "counter-title"
|
|
50
|
+
| "flip-box-face"
|
|
51
|
+
| "countdown-title"
|
|
52
|
+
| "hotspot-names"
|
|
53
|
+
| "mega-panel"
|
|
54
|
+
| "form-steps";
|
|
49
55
|
severity: "error" | "warning";
|
|
50
56
|
message: string;
|
|
51
57
|
/** The one-click fix, when there is a safe one. */
|
|
@@ -129,6 +135,7 @@ const TEXT_TYPES = new Set([
|
|
|
129
135
|
"post-excerpt",
|
|
130
136
|
]);
|
|
131
137
|
const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
|
|
138
|
+
const isStep = (node: LayoutNode) => node.type === "form-step";
|
|
132
139
|
const LINKISH = new Set(["link", "button", "menu-item"]);
|
|
133
140
|
|
|
134
141
|
function px(value: unknown, design?: DesignSystem): number | undefined {
|
|
@@ -150,7 +157,8 @@ function px(value: unknown, design?: DesignSystem): number | undefined {
|
|
|
150
157
|
const HEADING_PX = [32, 24, 18.72, 16, 13.28, 10.72];
|
|
151
158
|
|
|
152
159
|
const headingLevel = (node: LayoutNode): number | undefined => {
|
|
153
|
-
|
|
160
|
+
// W-1046: an Animated headline is a heading too.
|
|
161
|
+
if (node.type !== "heading" && node.type !== "headline") return undefined;
|
|
154
162
|
const level = (node.props as { level?: unknown }).level;
|
|
155
163
|
return typeof level === "number" && level >= 1 && level <= 6 ? level : 2;
|
|
156
164
|
};
|
|
@@ -257,6 +265,10 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
257
265
|
let fade = 1;
|
|
258
266
|
// W-445: per device, like H1s, so a desktop menu and a mobile menu may share a name.
|
|
259
267
|
const menuNames = DEVICES.map(() => new Set<string>());
|
|
268
|
+
// W-1076: carousels are regions, listed by name like menus.
|
|
269
|
+
const carouselNames = DEVICES.map(() => new Set<string>());
|
|
270
|
+
// W-1069: inside a menu item's dropdown, where a mega panel would open from a flyout.
|
|
271
|
+
let inDropdown = false;
|
|
260
272
|
const walk = (node: LayoutNode, bg: string | undefined, color: string | undefined): void => {
|
|
261
273
|
// W-413: an element hidden on every device (and what's inside it) is never shown or read.
|
|
262
274
|
if (node !== layout.root && hiddenOnEveryDevice(node)) {
|
|
@@ -309,7 +321,8 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
309
321
|
} else if (
|
|
310
322
|
// W-1021: an image box's picture needs real alt text as an Image does, once it has one.
|
|
311
323
|
(node.type === "image" ||
|
|
312
|
-
((node.type === "image-box" || node.type === "gallery-image"
|
|
324
|
+
((node.type === "image-box" || node.type === "gallery-image" || node.type === "hotspots") &&
|
|
325
|
+
spoken(props["src"]))) &&
|
|
313
326
|
props["decorative"] !== true
|
|
314
327
|
) {
|
|
315
328
|
const alt = typeof props["alt"] === "string" ? spoken(props["alt"]) : "";
|
|
@@ -558,6 +571,139 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
558
571
|
message: "This alert has no title or text, so it shows an empty box and says nothing.",
|
|
559
572
|
});
|
|
560
573
|
}
|
|
574
|
+
// W-1039: a bar without a title is a meter screen readers can't name.
|
|
575
|
+
if (node.type === "progress" && !spoken(props["label"]) && !node.bind) {
|
|
576
|
+
add({
|
|
577
|
+
nodeId: node.id,
|
|
578
|
+
rule: "control-name",
|
|
579
|
+
severity: "warning",
|
|
580
|
+
message:
|
|
581
|
+
'This progress bar has no title, so screen readers can\'t say what it measures. Add a title such as "Design".',
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
// W-1038: a Counter's number alone ("1,200+") doesn't say what was counted.
|
|
585
|
+
if (node.type === "counter" && !spoken(props["title"]) && !node.bind) {
|
|
586
|
+
add({
|
|
587
|
+
nodeId: node.id,
|
|
588
|
+
rule: "counter-title",
|
|
589
|
+
severity: "warning",
|
|
590
|
+
message:
|
|
591
|
+
'This counter has no title, so its number doesn\'t say what it counts. Add a title such as "Happy clients".',
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
// W-1076: screen readers list carousels as regions by name; two with one name sound the same.
|
|
595
|
+
if (node.type === "carousel") {
|
|
596
|
+
const name = spoken(props["label"]) || "Carousel";
|
|
597
|
+
const key = name.toLowerCase();
|
|
598
|
+
if (carouselNames.some((names, i) => shownOn[i] && names.has(key))) {
|
|
599
|
+
add({
|
|
600
|
+
nodeId: node.id,
|
|
601
|
+
rule: "landmark-name",
|
|
602
|
+
severity: "warning",
|
|
603
|
+
message: `Another carousel on this page is also named "${name}"; give each carousel its own name, such as "Customer stories".`,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
carouselNames.forEach((listed, i) => {
|
|
607
|
+
if (shownOn[i]) listed.add(key);
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
// W-1076: a Flip box's faces are headings and text; an empty one turns over to nothing.
|
|
611
|
+
if (node.type === "flip-box" && !node.bind) {
|
|
612
|
+
if (!spoken(props["frontTitle"])) {
|
|
613
|
+
add({
|
|
614
|
+
nodeId: node.id,
|
|
615
|
+
rule: "flip-box-face",
|
|
616
|
+
severity: "warning",
|
|
617
|
+
message:
|
|
618
|
+
"This flip box's front has no title, so its heading is empty. Add a front title.",
|
|
619
|
+
});
|
|
620
|
+
} else if (
|
|
621
|
+
!spoken(props["backTitle"]) &&
|
|
622
|
+
!spoken(props["backText"]) &&
|
|
623
|
+
!spoken(props["buttonText"])
|
|
624
|
+
) {
|
|
625
|
+
add({
|
|
626
|
+
nodeId: node.id,
|
|
627
|
+
rule: "flip-box-face",
|
|
628
|
+
severity: "warning",
|
|
629
|
+
message:
|
|
630
|
+
"This flip box's back is empty, so turning it over shows nothing. Add a back title, text or button.",
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
// The back's button is a link: with no address it can use, the page leaves it out.
|
|
634
|
+
const href = typeof props["href"] === "string" ? props["href"].trim() : "";
|
|
635
|
+
if (spoken(props["buttonText"]) && (!href || !sanitizeHref(href))) {
|
|
636
|
+
add({
|
|
637
|
+
nodeId: node.id,
|
|
638
|
+
rule: "link-name",
|
|
639
|
+
severity: "warning",
|
|
640
|
+
message:
|
|
641
|
+
"This flip box's button has no link it can use, so the page leaves the button out. Add a button link, or clear the button text.",
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
// W-1076: "Ends 1 Dec 2026" alone doesn't say what ends.
|
|
646
|
+
if (node.type === "countdown" && !spoken(props["title"]) && !node.bind) {
|
|
647
|
+
add({
|
|
648
|
+
nodeId: node.id,
|
|
649
|
+
rule: "countdown-title",
|
|
650
|
+
severity: "warning",
|
|
651
|
+
message:
|
|
652
|
+
'This countdown has no title, so its date doesn\'t say what ends. Add a title such as "Launch sale".',
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
// W-1076: each marker is a button named by its title; two alike can't be told apart.
|
|
656
|
+
if (node.type === "hotspots" && isParentNode(node)) {
|
|
657
|
+
const seen = new Set<string>();
|
|
658
|
+
for (const marker of node.children) {
|
|
659
|
+
const title = spoken((marker.props as Record<string, unknown>)["title"]).toLowerCase();
|
|
660
|
+
if (title && seen.has(title)) {
|
|
661
|
+
add({
|
|
662
|
+
nodeId: marker.id,
|
|
663
|
+
rule: "hotspot-names",
|
|
664
|
+
severity: "warning",
|
|
665
|
+
message: `Another marker on this picture is also called "${spoken((marker.props as Record<string, unknown>)["title"])}"; screen readers can't tell them apart. Give each its own title.`,
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
seen.add(title);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
// W-1065: a form with steps shows one step at a time; each is read out by its title.
|
|
672
|
+
if (node.type === "form" && isParentNode(node) && node.children.some(isStep)) {
|
|
673
|
+
let place = 0;
|
|
674
|
+
for (const child of node.children) {
|
|
675
|
+
if (!isStep(child)) {
|
|
676
|
+
if (someNode(child, (n) => FIELD_TYPES.has(n.type))) {
|
|
677
|
+
add({
|
|
678
|
+
nodeId: child.id,
|
|
679
|
+
rule: "form-steps",
|
|
680
|
+
severity: "warning",
|
|
681
|
+
message:
|
|
682
|
+
"This field is outside the form's steps, so it shows on every step and isn't checked before Next. Move it into a step.",
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
place += 1;
|
|
688
|
+
const title = spoken((child.props as Record<string, unknown>)["title"]);
|
|
689
|
+
if (!title && !child.bind) {
|
|
690
|
+
add({
|
|
691
|
+
nodeId: child.id,
|
|
692
|
+
rule: "form-steps",
|
|
693
|
+
severity: "warning",
|
|
694
|
+
message: `This form step has no title, so screen readers only hear "Step ${place}". Give it a title, such as "Your details".`,
|
|
695
|
+
});
|
|
696
|
+
} else if (!someNode(child, (n) => FIELD_TYPES.has(n.type))) {
|
|
697
|
+
add({
|
|
698
|
+
nodeId: child.id,
|
|
699
|
+
rule: "form-steps",
|
|
700
|
+
severity: "warning",
|
|
701
|
+
message:
|
|
702
|
+
"This form step has no fields, so Next opens an empty step. Add fields or remove it.",
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
561
707
|
// W-419: an empty heading still shows up in screen readers' heading list, with nothing to say.
|
|
562
708
|
if (node.type === "heading" && !spoken(props["text"]) && !node.bind) {
|
|
563
709
|
add({
|
|
@@ -567,7 +713,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
567
713
|
message: "This heading is empty; screen readers list it as a heading with no words.",
|
|
568
714
|
});
|
|
569
715
|
}
|
|
570
|
-
if (node.type === "heading") {
|
|
716
|
+
if (node.type === "heading" || node.type === "headline") {
|
|
571
717
|
const level = typeof props["level"] === "number" ? props["level"] : 2;
|
|
572
718
|
if (level === 1) {
|
|
573
719
|
h1s = h1s.map((count, i) => count + (shownOn[i] ? 1 : 0));
|
|
@@ -603,6 +749,28 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
603
749
|
message: "This box is a link, but nothing inside it has text, so the link has no name.",
|
|
604
750
|
});
|
|
605
751
|
}
|
|
752
|
+
// W-1069: a mega panel's toggle is named by its item's text ("Open Products", or the text
|
|
753
|
+
// itself), so a vague one says nothing about what opens; and one in a dropdown is a whole
|
|
754
|
+
// layout opened from a flyout, two disclosures deep for keyboard and screen reader users.
|
|
755
|
+
if (node.type === "menu-item" && spoken(props["panelPartId"])) {
|
|
756
|
+
const text = spoken(props["text"]);
|
|
757
|
+
if (inDropdown) {
|
|
758
|
+
add({
|
|
759
|
+
nodeId: node.id,
|
|
760
|
+
rule: "mega-panel",
|
|
761
|
+
severity: "warning",
|
|
762
|
+
message:
|
|
763
|
+
"This mega panel opens from inside another dropdown; put the item straight in the Menu so it opens from the menu bar.",
|
|
764
|
+
});
|
|
765
|
+
} else if (text && VAGUE.test(text)) {
|
|
766
|
+
add({
|
|
767
|
+
nodeId: node.id,
|
|
768
|
+
rule: "mega-panel",
|
|
769
|
+
severity: "warning",
|
|
770
|
+
message: `"${text}" doesn't say what this item's panel holds; name it for its contents, such as "Products".`,
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
}
|
|
606
774
|
if (LINKISH.has(node.type) || (node.type === "icon" && props["href"])) {
|
|
607
775
|
const text = spoken(props["text"] ?? props["title"]);
|
|
608
776
|
const hasHref = typeof props["href"] === "string" && props["href"].trim() !== "";
|
|
@@ -694,9 +862,12 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
694
862
|
});
|
|
695
863
|
}
|
|
696
864
|
const outerHidden = ariaHiddenAbove;
|
|
865
|
+
const outerDropdown = inDropdown;
|
|
697
866
|
if (ownAriaHidden) ariaHiddenAbove = true;
|
|
867
|
+
if (node.type === "menu-item") inDropdown = true;
|
|
698
868
|
if (isParentNode(node)) for (const child of node.children) walk(child, nextBg, nextColor);
|
|
699
869
|
ariaHiddenAbove = outerHidden;
|
|
870
|
+
inDropdown = outerDropdown;
|
|
700
871
|
};
|
|
701
872
|
walk(layout.root, undefined, undefined);
|
|
702
873
|
if (h1s.every((count) => count === 0) && layout.root.children.length > 0) {
|
|
@@ -743,7 +914,7 @@ export function applyAllA11yFixes(layout: Layout, issues: A11yIssue[]): Layout {
|
|
|
743
914
|
const levels = new Map<string, number>();
|
|
744
915
|
let last = 0;
|
|
745
916
|
const walk = (node: LayoutNode) => {
|
|
746
|
-
if (node.type === "heading") {
|
|
917
|
+
if (node.type === "heading" || node.type === "headline") {
|
|
747
918
|
const own = typeof node.props["level"] === "number" ? node.props["level"] : 2;
|
|
748
919
|
const level = order.has(node.id) ? Math.min(own, Math.max(2, last + 1)) : own;
|
|
749
920
|
if (level !== own) levels.set(node.id, level);
|