@perkyzz/emvb 1.1.0 → 1.3.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 (99) hide show
  1. package/THIRD_PARTY_NOTICES.md +3 -2
  2. package/package.json +11 -10
  3. package/src/admin/agents-api.ts +5 -1
  4. package/src/admin/content-api.ts +29 -0
  5. package/src/admin/editor/Editor.tsx +6 -1
  6. package/src/admin/editor/ScheduleDialog.tsx +167 -0
  7. package/src/admin/editor/TopBar.tsx +33 -1
  8. package/src/admin/editor/canvas/vnode-react.tsx +3 -0
  9. package/src/admin/editor/dnd/new-element.ts +106 -0
  10. package/src/admin/editor/editor-chrome.tsx +9 -0
  11. package/src/admin/editor/element-chrome.ts +50 -0
  12. package/src/admin/editor/panels/ElementPanel.tsx +5 -1
  13. package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
  14. package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
  15. package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
  16. package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
  17. package/src/admin/editor/panels/settings/ItemList.tsx +69 -2
  18. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  19. package/src/admin/editor/store.ts +7 -1
  20. package/src/admin/editor/useEditorData.ts +4 -0
  21. package/src/admin/editor/useSave.ts +47 -3
  22. package/src/admin/export-api.ts +20 -3
  23. package/src/admin/menus-api.ts +113 -0
  24. package/src/admin/pages/ImportElementorDialog.tsx +25 -1
  25. package/src/astro/EmVBPage.astro +3 -0
  26. package/src/astro/render.ts +43 -18
  27. package/src/astro/request-data.ts +9 -0
  28. package/src/astro/resolve-theme.ts +77 -44
  29. package/src/astro/resolve.ts +9 -0
  30. package/src/astro/visitor.ts +23 -4
  31. package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
  32. package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
  33. package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
  34. package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
  35. package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
  36. package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
  37. package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
  38. package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
  39. package/src/astro/widgets/EmVBWidgetRuntimes.astro +29 -0
  40. package/src/astro/widgets/alerts.ts +37 -0
  41. package/src/astro/widgets/carousel.ts +167 -0
  42. package/src/astro/widgets/countdown.ts +80 -0
  43. package/src/astro/widgets/counter.ts +98 -0
  44. package/src/astro/widgets/headline.ts +90 -0
  45. package/src/astro/widgets/index.ts +1 -0
  46. package/src/astro/widgets/lightbox.ts +123 -0
  47. package/src/astro/widgets/map.ts +37 -0
  48. package/src/astro/widgets/share.ts +21 -0
  49. package/src/constants.ts +1 -1
  50. package/src/core/a11y/audit.ts +127 -5
  51. package/src/core/arrange.ts +109 -1
  52. package/src/core/bounded-array.ts +16 -13
  53. package/src/core/canvas-collections.ts +28 -0
  54. package/src/core/contract.ts +4 -1
  55. package/src/core/elements/counter-format.ts +15 -0
  56. package/src/core/elements/icon-svg.ts +135 -0
  57. package/src/core/elements/index.ts +63 -127
  58. package/src/core/elements/marketing.ts +1490 -0
  59. package/src/core/elements/widgets.ts +932 -0
  60. package/src/core/export/runtimes.generated.ts +8 -0
  61. package/src/core/export/site.ts +25 -3
  62. package/src/core/extensions/schema.ts +2 -1
  63. package/src/core/geo-trust.ts +18 -0
  64. package/src/core/icons/social.generated.ts +29 -0
  65. package/src/core/image-edit/schema.ts +2 -1
  66. package/src/core/import/elementor/context.ts +18 -0
  67. package/src/core/import/elementor/index.ts +50 -7
  68. package/src/core/import/elementor/widgets.ts +783 -385
  69. package/src/core/issue-cap.ts +19 -0
  70. package/src/core/limits.ts +12 -0
  71. package/src/core/loop-collections.ts +33 -0
  72. package/src/core/proposals.ts +8 -2
  73. package/src/core/render/index.ts +48 -5
  74. package/src/core/render/vnode.ts +44 -6
  75. package/src/core/sanitize/svg-upload.ts +276 -23
  76. package/src/core/sanitize/svg.ts +3 -3
  77. package/src/core/schema/descriptors.ts +4 -0
  78. package/src/core/schema/design.ts +6 -5
  79. package/src/core/schema/layout.ts +798 -15
  80. package/src/core/schema/style.ts +2 -1
  81. package/src/core/shadowing-ids.ts +41 -0
  82. package/src/core/theme/conditions.ts +2 -1
  83. package/src/core/theme/dynamic.ts +2 -0
  84. package/src/core/theme/parse-doc.ts +10 -5
  85. package/src/core/theme/triggers.ts +3 -2
  86. package/src/core/validate.ts +3 -2
  87. package/src/index.ts +23 -2
  88. package/src/mcp/ports.ts +18 -7
  89. package/src/mcp/proposals.ts +36 -11
  90. package/src/mcp/tools.ts +1 -1
  91. package/src/server/agent-settings.ts +12 -1
  92. package/src/server/hooks.ts +41 -6
  93. package/src/server/mcp-routes.ts +11 -5
  94. package/src/server/plugin.ts +29 -3
  95. package/src/server/presence.ts +5 -1
  96. package/src/server/proposals.ts +16 -4
  97. package/src/server/requests.ts +60 -11
  98. package/src/server/site-origin.ts +13 -0
  99. package/src/server/targets.ts +26 -0
@@ -0,0 +1,167 @@
1
+ /**
2
+ * W-1018: the opt-in Carousel controls. A carousel works without this script (a snapping track
3
+ * you swipe, scroll or move with the arrow keys); this adds what it asked for:
4
+ * - Previous and Next buttons (`data-emvb-arrows`), disabled at the ends unless it loops;
5
+ * - one button per slide (`data-emvb-dots`), the current one marked aria-current;
6
+ * - autoplay (`data-emvb-autoplay="<seconds>"`) with a visible Pause/Play button placed before
7
+ * the slides, paused while the carousel is hovered or holds focus, and starting paused when
8
+ * the visitor prefers reduced motion (WCAG 2.2.2).
9
+ */
10
+
11
+ type Carousel = {
12
+ root: HTMLElement;
13
+ track: HTMLElement;
14
+ slides: HTMLElement[];
15
+ loop: boolean;
16
+ index: number;
17
+ prev?: HTMLButtonElement;
18
+ next?: HTMLButtonElement;
19
+ dots: HTMLButtonElement[];
20
+ timer?: ReturnType<typeof setInterval>;
21
+ /** The visitor pressed Pause (or reduced motion started it paused). */
22
+ stopped: boolean;
23
+ /** Hovered or focused: paused for now. */
24
+ held: boolean;
25
+ };
26
+
27
+ function button(label: string, text: string, className = ""): HTMLButtonElement {
28
+ const el = document.createElement("button");
29
+ el.type = "button";
30
+ el.setAttribute("aria-label", label);
31
+ el.textContent = text;
32
+ if (className) el.className = className;
33
+ return el;
34
+ }
35
+
36
+ /** How many slides show at once, from the layout (1 when it can't be measured). */
37
+ function perView(c: Carousel): number {
38
+ const first = c.slides[0];
39
+ if (!first || first.offsetWidth === 0) return 1;
40
+ return Math.max(1, Math.round(c.track.clientWidth / first.offsetWidth));
41
+ }
42
+
43
+ /** The last slide a view can start at. */
44
+ const lastStart = (c: Carousel) => Math.max(0, c.slides.length - perView(c));
45
+
46
+ function update(c: Carousel): void {
47
+ const last = lastStart(c);
48
+ if (c.prev) c.prev.disabled = !c.loop && c.index <= 0;
49
+ if (c.next) c.next.disabled = !c.loop && c.index >= last;
50
+ c.dots.forEach((dot, i) => {
51
+ if (i === c.index) dot.setAttribute("aria-current", "true");
52
+ else dot.removeAttribute("aria-current");
53
+ });
54
+ }
55
+
56
+ /** Shows slide `index` (wrapped when looping or playing, else kept in range). */
57
+ function go(c: Carousel, index: number, wrap = c.loop): void {
58
+ const last = lastStart(c);
59
+ c.index = wrap
60
+ ? index > last
61
+ ? 0
62
+ : index < 0
63
+ ? last
64
+ : index
65
+ : Math.min(Math.max(index, 0), last);
66
+ const target = c.slides[c.index];
67
+ const origin = c.slides[0];
68
+ if (target && origin) c.track.scrollTo({ left: target.offsetLeft - origin.offsetLeft });
69
+ update(c);
70
+ }
71
+
72
+ const present = (els: (HTMLElement | undefined)[]): HTMLElement[] =>
73
+ els.filter((el): el is HTMLElement => el !== undefined);
74
+
75
+ function setup(root: HTMLElement): void {
76
+ const track = root.querySelector<HTMLElement>(":scope > .emvb-carousel-track");
77
+ if (!track) return;
78
+ const c: Carousel = {
79
+ root,
80
+ track,
81
+ slides: [...track.children].filter((el): el is HTMLElement => el instanceof HTMLElement),
82
+ loop: root.hasAttribute("data-emvb-loop"),
83
+ index: 0,
84
+ dots: [],
85
+ stopped: false,
86
+ held: false,
87
+ };
88
+ if (c.slides.length < 2) return;
89
+ const controls = document.createElement("div");
90
+ controls.className = "emvb-carousel-controls";
91
+ if (root.hasAttribute("data-emvb-arrows")) {
92
+ c.prev = button("Previous slide", "‹");
93
+ c.next = button("Next slide", "›");
94
+ c.prev.addEventListener("click", () => go(c, c.index - 1));
95
+ c.next.addEventListener("click", () => go(c, c.index + 1));
96
+ }
97
+ if (root.hasAttribute("data-emvb-dots")) {
98
+ const dots = document.createElement("div");
99
+ dots.className = "emvb-carousel-dots";
100
+ for (let i = 0; i <= lastStart(c); i++) {
101
+ const dot = button(`Go to slide ${i + 1}`, "");
102
+ dot.addEventListener("click", () => go(c, i, false));
103
+ c.dots.push(dot);
104
+ dots.append(dot);
105
+ }
106
+ controls.append(...present([c.prev, dots, c.next]));
107
+ } else {
108
+ controls.append(...present([c.prev, c.next]));
109
+ }
110
+ if (controls.childElementCount > 0) track.after(controls);
111
+ const seconds = Number(root.dataset["emvbAutoplay"]);
112
+ if (Number.isFinite(seconds) && seconds > 0) autoplay(c, seconds);
113
+ // Swipes and scrolls move the current slide too.
114
+ let frame = 0;
115
+ track.addEventListener("scroll", () => {
116
+ cancelAnimationFrame(frame);
117
+ frame = requestAnimationFrame(() => {
118
+ const first = c.slides[0];
119
+ const step = first?.offsetWidth ?? 0;
120
+ if (step <= 0) return;
121
+ c.index = Math.min(Math.round(track.scrollLeft / step), lastStart(c));
122
+ update(c);
123
+ });
124
+ });
125
+ update(c);
126
+ }
127
+
128
+ function autoplay(c: Carousel, seconds: number): void {
129
+ const reduced = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
130
+ c.stopped = reduced;
131
+ const toggle = button("", "", "emvb-carousel-play");
132
+ const label = () => {
133
+ toggle.textContent = c.stopped ? "Play" : "Pause";
134
+ toggle.setAttribute("aria-label", c.stopped ? "Play slides" : "Pause slides");
135
+ };
136
+ const tick = () => {
137
+ if (!c.stopped && !c.held) go(c, c.index + 1, true);
138
+ };
139
+ toggle.addEventListener("click", () => {
140
+ c.stopped = !c.stopped;
141
+ label();
142
+ });
143
+ label();
144
+ // The rotation control comes before the slides, so keyboard users reach it first.
145
+ const bar = document.createElement("div");
146
+ bar.className = "emvb-carousel-controls emvb-carousel-autoplay";
147
+ bar.append(toggle);
148
+ c.track.before(bar);
149
+ const hold = (held: boolean) => () => {
150
+ c.held = held;
151
+ };
152
+ c.root.addEventListener("pointerenter", hold(true));
153
+ c.root.addEventListener("pointerleave", hold(false));
154
+ c.root.addEventListener("focusin", hold(true));
155
+ c.root.addEventListener("focusout", (event) => {
156
+ if (!c.root.contains(event.relatedTarget as Node | null)) c.held = false;
157
+ });
158
+ c.timer = setInterval(tick, seconds * 1000);
159
+ }
160
+
161
+ export function initCarousels(root: ParentNode = document): void {
162
+ for (const el of root.querySelectorAll<HTMLElement>("section.emvb-carousel")) {
163
+ if (el.dataset["emvbCarouselReady"] !== undefined) continue;
164
+ el.dataset["emvbCarouselReady"] = "";
165
+ setup(el);
166
+ }
167
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * W-1040: the opt-in Countdown runtime. It shows each ticking Countdown's clock (hidden by CSS
3
+ * until this script marks it ready) and updates it every second. The clock is hidden from
4
+ * screen readers, which read the sentence with the date instead of a number every second. A
5
+ * Pause button stops the updates (WCAG 2.2.2). When time is up it shows the ended text, or hides
6
+ * the Countdown.
7
+ */
8
+
9
+ const pad = (n: number) => String(n).padStart(2, "0");
10
+
11
+ /** Whole days, hours, minutes and seconds left until `target`, never below zero. */
12
+ export function remaining(target: number, now: number) {
13
+ const total = Math.max(0, Math.floor((target - now) / 1000));
14
+ return {
15
+ total,
16
+ days: Math.floor(total / 86_400),
17
+ hours: Math.floor((total % 86_400) / 3600),
18
+ minutes: Math.floor((total % 3600) / 60),
19
+ seconds: total % 60,
20
+ };
21
+ }
22
+
23
+ function start(root: HTMLElement, target: number): void {
24
+ const nums = new Map<string, HTMLElement>();
25
+ for (const el of root.querySelectorAll<HTMLElement>(".emvb-countdown-num[data-unit]"))
26
+ nums.set(el.dataset["unit"] ?? "", el);
27
+ const pause = root.querySelector<HTMLButtonElement>(".emvb-countdown-pause");
28
+ let timer: ReturnType<typeof setInterval> | undefined;
29
+
30
+ const end = () => {
31
+ if (timer !== undefined) clearInterval(timer);
32
+ timer = undefined;
33
+ if (root.dataset["expired"] === "hide") {
34
+ root.hidden = true;
35
+ return;
36
+ }
37
+ const clock = root.querySelector<HTMLElement>(".emvb-countdown-clock");
38
+ if (clock) clock.hidden = true;
39
+ root.querySelector<HTMLElement>(".emvb-countdown-expired")?.setAttribute("data-emvb-shown", "");
40
+ };
41
+
42
+ const tick = () => {
43
+ const left = remaining(target, Date.now());
44
+ const hasSeconds = nums.has("seconds");
45
+ // Without seconds, the days to minutes left round up, so the clock never shows 0 too early.
46
+ const shown = hasSeconds ? left : remaining(target + 59_000, Date.now());
47
+ for (const unit of ["days", "hours", "minutes", "seconds"] as const) {
48
+ const el = nums.get(unit);
49
+ if (el) el.textContent = pad(shown[unit]);
50
+ }
51
+ if (left.total === 0) end();
52
+ };
53
+
54
+ const run = () => {
55
+ tick();
56
+ if (root.hidden || root.querySelector(".emvb-countdown-clock[hidden]")) return;
57
+ timer = setInterval(tick, 1000);
58
+ };
59
+
60
+ pause?.addEventListener("click", () => {
61
+ const paused = pause.getAttribute("aria-pressed") === "true";
62
+ pause.setAttribute("aria-pressed", String(!paused));
63
+ if (paused) run();
64
+ else if (timer !== undefined) {
65
+ clearInterval(timer);
66
+ timer = undefined;
67
+ }
68
+ });
69
+ run();
70
+ }
71
+
72
+ export function initCountdowns(root: ParentNode = document): void {
73
+ for (const el of root.querySelectorAll<HTMLElement>("[data-emvb-countdown]")) {
74
+ if (el.dataset["emvbReady"] !== undefined) continue;
75
+ const target = Date.parse(el.dataset["target"] ?? "");
76
+ if (Number.isNaN(target)) continue;
77
+ el.dataset["emvbReady"] = "";
78
+ start(el, target);
79
+ }
80
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * W-1038: the opt-in Counter runtime. A Counter that asks for it counts up from its start to its
3
+ * number when it scrolls into view. The page is rendered with the final number, so without this
4
+ * script, and under reduced motion, visitors see that at once. While it counts, screen readers
5
+ * get the final number from a hidden copy instead of every step.
6
+ */
7
+ import { formatCounter } from "../../core/elements/counter-format.ts";
8
+
9
+ type Counter = {
10
+ el: HTMLElement;
11
+ from: number;
12
+ to: number;
13
+ decimals: number;
14
+ separator: string;
15
+ duration: number;
16
+ final: string;
17
+ };
18
+
19
+ const easeOut = (t: number) => 1 - (1 - t) ** 3;
20
+
21
+ function read(el: HTMLElement): Counter | undefined {
22
+ const num = (key: string, fallback: number) => {
23
+ const value = Number(el.dataset[key] ?? fallback);
24
+ return Number.isFinite(value) ? value : fallback;
25
+ };
26
+ const to = Number(el.dataset["to"]);
27
+ if (!Number.isFinite(to)) return undefined;
28
+ return {
29
+ el,
30
+ from: num("from", 0),
31
+ to,
32
+ decimals: Math.min(3, Math.max(0, Math.round(num("decimals", 0)))),
33
+ separator: el.dataset["separator"] ?? "",
34
+ duration: Math.min(5000, Math.max(0, num("duration", 2000))),
35
+ final: el.textContent ?? "",
36
+ };
37
+ }
38
+
39
+ /** Shows `c.from`, with the final number kept for screen readers. */
40
+ function prepare(c: Counter): void {
41
+ c.el.setAttribute("aria-hidden", "true");
42
+ const copy = c.el.ownerDocument.createElement("span");
43
+ copy.className = "emvb-counter-sr";
44
+ copy.textContent = c.final;
45
+ c.el.after(copy);
46
+ c.el.textContent = formatCounter(c.from, c.decimals, c.separator);
47
+ }
48
+
49
+ /** Ends on the rendered text, and gives the number back to screen readers. */
50
+ function finish(c: Counter): void {
51
+ c.el.textContent = c.final;
52
+ c.el.removeAttribute("aria-hidden");
53
+ const copy = c.el.nextElementSibling;
54
+ if (copy?.classList.contains("emvb-counter-sr")) copy.remove();
55
+ }
56
+
57
+ function run(c: Counter): void {
58
+ const began = performance.now();
59
+ const step = (now: number) => {
60
+ const t = c.duration > 0 ? Math.min(1, (now - began) / c.duration) : 1;
61
+ if (t >= 1) {
62
+ finish(c);
63
+ return;
64
+ }
65
+ const value = c.from + (c.to - c.from) * easeOut(t);
66
+ c.el.textContent = formatCounter(value, c.decimals, c.separator);
67
+ requestAnimationFrame(step);
68
+ };
69
+ requestAnimationFrame(step);
70
+ }
71
+
72
+ export function initCounters(root: ParentNode = document): void {
73
+ const reduced = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
74
+ if (reduced || typeof IntersectionObserver === "undefined") return;
75
+ const counters = new Map<Element, Counter>();
76
+ for (const el of root.querySelectorAll<HTMLElement>("[data-emvb-counter]")) {
77
+ if (el.dataset["emvbReady"] !== undefined) continue;
78
+ el.dataset["emvbReady"] = "";
79
+ const c = read(el);
80
+ if (!c || c.from === c.to) continue;
81
+ prepare(c);
82
+ counters.set(el, c);
83
+ }
84
+ if (counters.size === 0) return;
85
+ const observer = new IntersectionObserver(
86
+ (entries) => {
87
+ for (const entry of entries) {
88
+ const c = counters.get(entry.target);
89
+ if (!entry.isIntersecting || !c) continue;
90
+ observer.unobserve(entry.target);
91
+ counters.delete(entry.target);
92
+ run(c);
93
+ }
94
+ },
95
+ { threshold: 0.5 },
96
+ );
97
+ for (const el of counters.keys()) observer.observe(el);
98
+ }
@@ -0,0 +1,90 @@
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) stop();
56
+ }, r.interval * 1000);
57
+
58
+ function stop(): void {
59
+ clearInterval(timer);
60
+ text.textContent = r.words[0] ?? "";
61
+ mark.removeAttribute("aria-hidden");
62
+ spoken.remove();
63
+ pause.remove();
64
+ }
65
+ // Pausing ends the rotation for good, back on the first word.
66
+ pause.addEventListener("click", () => {
67
+ const next = pause.nextElementSibling;
68
+ stop();
69
+ if (
70
+ next instanceof HTMLElement &&
71
+ next.matches("a[href], button, input, select, textarea, [tabindex]")
72
+ )
73
+ next.focus();
74
+ else if (heading instanceof HTMLElement) {
75
+ heading.tabIndex = -1;
76
+ heading.focus();
77
+ }
78
+ });
79
+ }
80
+
81
+ export function initHeadlines(root: ParentNode = document): void {
82
+ const reduced = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
83
+ if (reduced) return;
84
+ for (const mark of root.querySelectorAll<HTMLElement>("[data-emvb-rotate]")) {
85
+ if (mark.dataset["emvbReady"] !== undefined) continue;
86
+ mark.dataset["emvbReady"] = "";
87
+ const r = read(mark);
88
+ if (r) start(mark, r);
89
+ }
90
+ }
@@ -0,0 +1 @@
1
+ export { default as EmVBWidgetRuntimes } from "./EmVBWidgetRuntimes.astro";
@@ -0,0 +1,123 @@
1
+ /**
2
+ * W-1019: the opt-in Gallery lightbox. In each gallery marked `data-emvb-lightbox` every picture
3
+ * becomes a button that opens it large in one native modal <dialog>: Previous and Next (also the
4
+ * arrow keys), a counter that screen readers hear, Close and Escape. Focus goes back to the
5
+ * picture's button when the dialog closes. Without this script the gallery is plain pictures.
6
+ */
7
+
8
+ type Viewer = {
9
+ dialog: HTMLDialogElement;
10
+ image: HTMLImageElement;
11
+ caption: HTMLElement;
12
+ count: HTMLElement;
13
+ prev: HTMLButtonElement;
14
+ next: HTMLButtonElement;
15
+ };
16
+
17
+ type Show = { images: HTMLImageElement[]; index: number; opener: HTMLElement };
18
+
19
+ let viewer: Viewer | undefined;
20
+ let showing: Show | undefined;
21
+
22
+ const captionOf = (image: HTMLImageElement) =>
23
+ image.closest("figure")?.querySelector("figcaption")?.textContent?.trim() ?? "";
24
+
25
+ /** What a picture's button is called: its alt text, else its caption, else its place. */
26
+ export function pictureName(image: HTMLImageElement, index: number, total: number): string {
27
+ return image.alt.trim() || captionOf(image) || `Picture ${index + 1} of ${total}`;
28
+ }
29
+
30
+ function button(label: string, text: string): HTMLButtonElement {
31
+ const el = document.createElement("button");
32
+ el.type = "button";
33
+ el.setAttribute("aria-label", label);
34
+ el.textContent = text;
35
+ return el;
36
+ }
37
+
38
+ function build(doc: Document): Viewer {
39
+ const dialog = doc.createElement("dialog");
40
+ dialog.className = "emvb-lightbox";
41
+ dialog.setAttribute("aria-label", "Picture viewer");
42
+ const figure = doc.createElement("figure");
43
+ figure.className = "emvb-lightbox-figure";
44
+ const image = doc.createElement("img");
45
+ const bar = doc.createElement("div");
46
+ bar.className = "emvb-lightbox-bar";
47
+ const prev = button("Previous picture", "‹");
48
+ const next = button("Next picture", "›");
49
+ const close = button("Close", "×");
50
+ const caption = doc.createElement("figcaption");
51
+ caption.className = "emvb-lightbox-caption";
52
+ const count = doc.createElement("span");
53
+ count.setAttribute("aria-live", "polite");
54
+ caption.append(count);
55
+ bar.append(prev, caption, next, close);
56
+ figure.append(image, bar);
57
+ dialog.append(figure);
58
+ doc.body.append(dialog);
59
+ prev.addEventListener("click", () => step(-1));
60
+ next.addEventListener("click", () => step(1));
61
+ close.addEventListener("click", () => dialog.close());
62
+ dialog.addEventListener("keydown", (event) => {
63
+ if (event.key === "ArrowLeft") step(document.dir === "rtl" ? 1 : -1);
64
+ else if (event.key === "ArrowRight") step(document.dir === "rtl" ? -1 : 1);
65
+ });
66
+ dialog.addEventListener("close", () => {
67
+ showing?.opener.focus();
68
+ showing = undefined;
69
+ });
70
+ return { dialog, image, caption, count, prev, next };
71
+ }
72
+
73
+ function render(): void {
74
+ if (!viewer || !showing) return;
75
+ const { images, index } = showing;
76
+ const source = images[index];
77
+ if (!source) return;
78
+ viewer.image.src = source.currentSrc || source.src;
79
+ viewer.image.alt = source.alt;
80
+ const words = captionOf(source);
81
+ viewer.count.textContent = `${words ? `${words} · ` : ""}${index + 1} of ${images.length}`;
82
+ const single = images.length < 2;
83
+ viewer.prev.hidden = single;
84
+ viewer.next.hidden = single;
85
+ }
86
+
87
+ function step(by: number): void {
88
+ if (!showing) return;
89
+ const total = showing.images.length;
90
+ showing.index = (showing.index + by + total) % total;
91
+ render();
92
+ }
93
+
94
+ function open(images: HTMLImageElement[], index: number, opener: HTMLElement): void {
95
+ viewer ??= build(opener.ownerDocument);
96
+ showing = { images, index, opener };
97
+ render();
98
+ if (!viewer.dialog.open) viewer.dialog.showModal();
99
+ }
100
+
101
+ export function initLightbox(root: ParentNode = document): void {
102
+ for (const list of root.querySelectorAll<HTMLElement>("[data-emvb-lightbox]")) {
103
+ if (list.dataset["emvbLightboxReady"] !== undefined) continue;
104
+ list.dataset["emvbLightboxReady"] = "";
105
+ const images = [
106
+ ...list.querySelectorAll<HTMLImageElement>(":scope > .emvb-gallery-image > figure > img"),
107
+ ];
108
+ images.forEach((image, index) => {
109
+ const opener = button(`View larger: ${pictureName(image, index, images.length)}`, "");
110
+ opener.className = "emvb-gallery-open";
111
+ image.replaceWith(opener);
112
+ opener.append(image);
113
+ opener.addEventListener("click", () => open(images, index, opener));
114
+ });
115
+ }
116
+ }
117
+
118
+ /** Test seam: forget the shared viewer between tests. */
119
+ export function resetLightboxForTest(): void {
120
+ viewer?.dialog.remove();
121
+ viewer = undefined;
122
+ showing = undefined;
123
+ }
@@ -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
+ }
package/src/constants.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PLUGIN_ID = "emvb";
2
- export const PLUGIN_VERSION = "1.1.0";
2
+ export const PLUGIN_VERSION = "1.3.0";
3
3
  export const PACKAGE_NAME = "@perkyzz/emvb";
4
4
  export const ADMIN_ENTRY = `${PACKAGE_NAME}/admin`;
5
5
  export const PAGES_COLLECTION = "emvb_pages";