@perkyzz/emvb 1.3.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.
Files changed (134) hide show
  1. package/README.md +2 -2
  2. package/package.json +2 -2
  3. package/src/admin/bulk-api.ts +5 -1
  4. package/src/admin/editor/A11yCopilot.tsx +3 -1
  5. package/src/admin/editor/Editor.tsx +22 -2
  6. package/src/admin/editor/Timeline.tsx +1 -8
  7. package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
  8. package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
  9. package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
  10. package/src/admin/editor/canvas/vnode-react.tsx +2 -0
  11. package/src/admin/editor/co-design.ts +36 -1
  12. package/src/admin/editor/dnd/dragged-source.ts +22 -0
  13. package/src/admin/editor/dnd/layer-drop.ts +141 -0
  14. package/src/admin/editor/dnd/new-element.ts +16 -0
  15. package/src/admin/editor/editor-css.ts +9 -1
  16. package/src/admin/editor/element-chrome.ts +6 -0
  17. package/src/admin/editor/feature-css.ts +22 -0
  18. package/src/admin/editor/inert-links.ts +8 -0
  19. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  20. package/src/admin/editor/panels/FontFaces.tsx +342 -0
  21. package/src/admin/editor/panels/LayersPanel.tsx +56 -6
  22. package/src/admin/editor/panels/LeftPanel.tsx +153 -29
  23. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  24. package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
  25. package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
  26. package/src/admin/editor/panels/TokenScales.tsx +2 -0
  27. package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
  28. package/src/admin/editor/panels/VariableSection.tsx +111 -7
  29. package/src/admin/editor/panels/color-space.ts +71 -6
  30. package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
  31. package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
  32. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
  33. package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
  34. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
  35. package/src/admin/editor/panels/settings/style-sections.ts +19 -2
  36. package/src/admin/editor/panels/url-rules.ts +43 -0
  37. package/src/admin/editor/panels/use-layers-drop.ts +232 -0
  38. package/src/admin/editor/store.ts +4 -2
  39. package/src/admin/editor/useExtensions.ts +3 -1
  40. package/src/admin/editor/useNodeActions.ts +74 -1
  41. package/src/admin/editor/useSave.ts +116 -85
  42. package/src/admin/export-api.ts +25 -2
  43. package/src/admin/extension-outputs.ts +179 -0
  44. package/src/admin/font-files-api.ts +38 -0
  45. package/src/admin/pages/ImportButton.tsx +15 -4
  46. package/src/admin/pages/ImportElementorDialog.tsx +22 -188
  47. package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
  48. package/src/admin/pages/ImportImageCopies.tsx +167 -0
  49. package/src/admin/pages/ImportReport.tsx +63 -0
  50. package/src/admin/pages/NewPageDialog.tsx +54 -32
  51. package/src/admin/pages/PageList.tsx +9 -0
  52. package/src/admin/pages/ThemePartList.tsx +9 -0
  53. package/src/astro/EmVBPage.astro +5 -2
  54. package/src/astro/extension-styles.ts +35 -0
  55. package/src/astro/forms/EmVBFormsClient.astro +3 -0
  56. package/src/astro/forms/enhance.ts +107 -0
  57. package/src/astro/popups/runtime.ts +47 -2
  58. package/src/astro/render.ts +19 -4
  59. package/src/astro/resolve-theme.ts +11 -4
  60. package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
  61. package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
  62. package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
  63. package/src/astro/widgets/alerts.ts +16 -2
  64. package/src/astro/widgets/carousel.ts +65 -24
  65. package/src/astro/widgets/countdown.ts +18 -7
  66. package/src/astro/widgets/extension-runtimes.ts +27 -0
  67. package/src/astro/widgets/headline.ts +14 -5
  68. package/src/astro/widgets/sticky.ts +87 -0
  69. package/src/astro/widgets/theme.ts +52 -0
  70. package/src/constants.ts +1 -1
  71. package/src/core/a11y/audit.ts +150 -2
  72. package/src/core/arrange.ts +19 -1
  73. package/src/core/css/font-face.ts +72 -0
  74. package/src/core/css/generate.ts +35 -1
  75. package/src/core/elements/form-elements.ts +119 -9
  76. package/src/core/elements/icon-svg.ts +14 -0
  77. package/src/core/elements/index.ts +24 -4
  78. package/src/core/elements/input-limits.ts +44 -0
  79. package/src/core/elements/menu.ts +109 -47
  80. package/src/core/elements/site.ts +108 -0
  81. package/src/core/elements/widgets.ts +13 -3
  82. package/src/core/export/runtimes.generated.ts +7 -5
  83. package/src/core/export/site.ts +50 -4
  84. package/src/core/extensions/classes.ts +114 -0
  85. package/src/core/extensions/index.ts +17 -2
  86. package/src/core/extensions/normalize.ts +13 -0
  87. package/src/core/extensions/registry.ts +134 -10
  88. package/src/core/extensions/render-ext.ts +66 -21
  89. package/src/core/extensions/safe-nodes.ts +67 -11
  90. package/src/core/extensions/types.ts +48 -1
  91. package/src/core/fonts/files.ts +74 -0
  92. package/src/core/fonts/google.ts +112 -0
  93. package/src/core/fonts/test-font.ts +9 -0
  94. package/src/core/import/elementor/context.ts +13 -4
  95. package/src/core/import/elementor/index.ts +32 -21
  96. package/src/core/import/elementor/widgets.ts +114 -12
  97. package/src/core/import/html/blocks.ts +602 -0
  98. package/src/core/import/html/index.ts +155 -0
  99. package/src/core/import/html/map.ts +958 -0
  100. package/src/core/import/html/parse.ts +430 -0
  101. package/src/core/index.ts +45 -0
  102. package/src/core/migrate/v18.ts +3 -0
  103. package/src/core/public-attributes.ts +17 -0
  104. package/src/core/render/extras.ts +31 -7
  105. package/src/core/render/form.ts +103 -10
  106. package/src/core/render/index.ts +151 -15
  107. package/src/core/render/section.ts +31 -1
  108. package/src/core/render/spacer-basis.ts +102 -0
  109. package/src/core/render/theme-boot.ts +16 -0
  110. package/src/core/render/vnode.ts +1 -1
  111. package/src/core/sanitize/css.ts +68 -3
  112. package/src/core/sanitize/motion.ts +12 -0
  113. package/src/core/schema/design.ts +40 -0
  114. package/src/core/schema/layout.ts +114 -5
  115. package/src/core/schema/style.ts +28 -0
  116. package/src/core/templates/index.ts +218 -0
  117. package/src/core/templates/pages.ts +29 -0
  118. package/src/core/templates/sections.ts +794 -0
  119. package/src/core/templates/types.ts +9 -0
  120. package/src/core/theme/dynamic.ts +9 -6
  121. package/src/core/theme/popup-markup.ts +21 -2
  122. package/src/core/theme/popup-rules.ts +36 -0
  123. package/src/core/theme/triggers.ts +64 -5
  124. package/src/core/translatable.ts +5 -2
  125. package/src/extension-build.ts +331 -0
  126. package/src/index.ts +25 -3
  127. package/src/mcp/brief.ts +191 -0
  128. package/src/mcp/prompts.ts +33 -0
  129. package/src/mcp/read.ts +29 -1
  130. package/src/mcp/tools.ts +40 -1
  131. package/src/mcp/write.ts +41 -1
  132. package/src/server/extension-routes.ts +73 -0
  133. package/src/server/font-routes.ts +301 -0
  134. package/src/server/plugin.ts +9 -0
@@ -37,7 +37,9 @@ import {
37
37
  } from "../core/index.ts";
38
38
  import { THEME_PARTS_COLLECTION } from "../constants.ts";
39
39
  import { readLayout, renderStored, type RenderedPage } from "./render.ts";
40
- import type { WidgetRuntime } from "../core/elements/widgets.ts";
40
+ import { noteExtensionStyles } from "./extension-styles.ts";
41
+ import { extensionStylesheets } from "../core/extensions/index.ts";
42
+ import type { PageRuntime } from "../core/elements/widgets.ts";
41
43
  import { designFor, formsFor, layoutFor, partsFor } from "./render-session.ts";
42
44
  import type { HostVisitor, VisitorAstro } from "./visitor.ts";
43
45
  import { bindingDataFor } from "./request-data.ts";
@@ -103,7 +105,7 @@ export type ResolvedThemeParts = {
103
105
  * W-1025: the opt-in widget scripts the winning parts need; set only when there is one. Mount
104
106
  * `<EmVBWidgetRuntimes names={theme.runtimes} />` from `@perkyzz/emvb/astro/widgets`.
105
107
  */
106
- runtimes?: WidgetRuntime[];
108
+ runtimes?: PageRuntime[];
107
109
  /**
108
110
  * True for an archive page past the last one (`/posts/page/9` with no posts there). Hosts
109
111
  * answer 404 (W-221). Page 1 with no posts is not a 404.
@@ -418,7 +420,7 @@ async function buildDynamicForContent(
418
420
  }
419
421
 
420
422
  /** W-1025: every widget runtime the rendered parts need, once each, or nothing. */
421
- function partRuntimes(rendered: readonly RenderedPage[]): { runtimes?: WidgetRuntime[] } {
423
+ function partRuntimes(rendered: readonly RenderedPage[]): { runtimes?: PageRuntime[] } {
422
424
  const names = [...new Set(rendered.flatMap((page) => page.runtimes ?? []))].toSorted();
423
425
  return names.length > 0 ? { runtimes: names } : {};
424
426
  }
@@ -612,7 +614,8 @@ export async function resolveThemePartsWith(
612
614
  const html = page.html
613
615
  ? `<${tag} class="emvb-theme-${stored.partType}" data-emvb-theme-part="${partId}">${page.html}</${tag}>`
614
616
  : "";
615
- return { html, css: page.css };
617
+ // W-1086: a part's own css stays whole; the shared `css` below writes extension sheets once.
618
+ return { html, css: page.css + extensionStylesheets(page.extensions ?? []) };
616
619
  };
617
620
 
618
621
  /** Synced sections and loop items a part uses, for every part type (W-200). */
@@ -754,6 +757,10 @@ export async function resolveThemePartsWith(
754
757
  return sheet ? [sheet] : [];
755
758
  });
756
759
  const cssParts = [sharedPartCss(ordered)];
760
+ // W-1086: each extension stylesheet once for all the parts; the page in this response skips them.
761
+ const extensionIds = [...new Set(rendered.flatMap((page) => page.extensions ?? []))].toSorted();
762
+ cssParts.push(extensionStylesheets(extensionIds));
763
+ noteExtensionStyles(astro.request, extensionIds);
757
764
  if (popups.length > 0) cssParts.push(POPUP_CHROME_CSS);
758
765
  if (floats.length > 0) cssParts.push(FLOAT_CHROME_CSS);
759
766
  const css = cssParts.filter(Boolean).join("\n");
@@ -0,0 +1,9 @@
1
+ ---
2
+ // W-1070: hides a sticky header while scrolling down. `EmVBWidgetRuntimes` mounts this only when
3
+ // a page or theme part asks for it.
4
+ ---
5
+
6
+ <script>
7
+ import { initSticky } from "./sticky.ts";
8
+ initSticky();
9
+ </script>
@@ -0,0 +1,9 @@
1
+ ---
2
+ // W-1067: the Theme toggle's script. `EmVBWidgetRuntimes` mounts this only when a page or theme
3
+ // part has a Theme toggle.
4
+ ---
5
+
6
+ <script>
7
+ import { initTheme } from "./theme.ts";
8
+ initTheme();
9
+ </script>
@@ -11,12 +11,17 @@ import EmVBHeadlineRuntime from "./EmVBHeadlineRuntime.astro";
11
11
  import EmVBLightboxRuntime from "./EmVBLightboxRuntime.astro";
12
12
  import EmVBMapRuntime from "./EmVBMapRuntime.astro";
13
13
  import EmVBShareRuntime from "./EmVBShareRuntime.astro";
14
+ import EmVBStickyRuntime from "./EmVBStickyRuntime.astro";
15
+ import EmVBThemeRuntime from "./EmVBThemeRuntime.astro";
16
+ import { extensionRuntimeScripts } from "./extension-runtimes.ts";
14
17
 
15
18
  interface Props {
16
19
  names?: readonly string[] | undefined;
17
20
  }
18
21
 
19
22
  const names = new Set(Astro.props.names ?? []);
23
+ // W-1086: extension runtimes (`ext:<package>`), inline, each once per response.
24
+ const extensionScripts = extensionRuntimeScripts(Astro.request, Astro.props.names ?? []);
20
25
  ---
21
26
 
22
27
  {names.has("alerts") && <EmVBAlertsRuntime />}
@@ -27,3 +32,10 @@ const names = new Set(Astro.props.names ?? []);
27
32
  {names.has("map") && <EmVBMapRuntime />}
28
33
  {names.has("headline") && <EmVBHeadlineRuntime />}
29
34
  {names.has("share") && <EmVBShareRuntime />}
35
+ {names.has("sticky") && <EmVBStickyRuntime />}
36
+ {names.has("theme") && <EmVBThemeRuntime />}
37
+ {
38
+ extensionScripts.map(({ id, code }) => (
39
+ <script type="module" is:inline data-emvb-ext-runtime={id} set:html={code} />
40
+ ))
41
+ }
@@ -7,10 +7,24 @@
7
7
  const FOCUSABLE =
8
8
  "a[href], button:not([disabled]), input:not([disabled]):not([type=hidden]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1']), summary, iframe";
9
9
 
10
- /** The first focusable element after `from` in the document, else the last one before it. */
10
+ const rendered = (el: HTMLElement): boolean =>
11
+ typeof el.checkVisibility === "function"
12
+ ? el.checkVisibility({ visibilityProperty: true })
13
+ : el.getClientRects().length > 0;
14
+
15
+ /**
16
+ * The first element after `from` that Tab reaches, else the last one before it. Elements taken out
17
+ * of the Tab order (`tabindex="-1"`, such as the radios behind enhanced Tabs) or hidden from
18
+ * assistive tech don't count (W-1054), nor do ones without a box (an element hidden on this
19
+ * device is display:none), which focus() can't reach: focus fell to <body>.
20
+ */
11
21
  function neighbour(from: Element): HTMLElement | null {
12
22
  const all = [...from.ownerDocument.querySelectorAll<HTMLElement>(FOCUSABLE)].filter(
13
- (el) => !from.contains(el) && !el.closest("[hidden]"),
23
+ (el) =>
24
+ !from.contains(el) &&
25
+ el.tabIndex >= 0 &&
26
+ !el.closest("[hidden], [inert], [aria-hidden='true']") &&
27
+ rendered(el),
14
28
  );
15
29
  const after = all.find(
16
30
  (el) => from.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING,
@@ -6,6 +6,8 @@
6
6
  * - autoplay (`data-emvb-autoplay="<seconds>"`) with a visible Pause/Play button placed before
7
7
  * the slides, paused while the carousel is hovered or holds focus, and starting paused when
8
8
  * the visitor prefers reduced motion (WCAG 2.2.2).
9
+ * The dots follow the track's size (W-1055): a resize, or a carousel shown from a hidden tab,
10
+ * rebuilds them for the start positions that view can reach.
9
11
  */
10
12
 
11
13
  type Carousel = {
@@ -16,12 +18,14 @@ type Carousel = {
16
18
  index: number;
17
19
  prev?: HTMLButtonElement;
18
20
  next?: HTMLButtonElement;
21
+ dotsBox?: HTMLElement;
19
22
  dots: HTMLButtonElement[];
20
23
  timer?: ReturnType<typeof setInterval>;
21
24
  /** The visitor pressed Pause (or reduced motion started it paused). */
22
25
  stopped: boolean;
23
- /** Hovered or focused: paused for now. */
24
- held: boolean;
26
+ /** Hovered or holding focus: paused for now, until both have ended (W-1058). */
27
+ hovered: boolean;
28
+ focused: boolean;
25
29
  };
26
30
 
27
31
  function button(label: string, text: string, className = ""): HTMLButtonElement {
@@ -53,6 +57,45 @@ function update(c: Carousel): void {
53
57
  });
54
58
  }
55
59
 
60
+ /** How far each slide starts from the first, in scroll pixels (positive in RTL too). */
61
+ const offsets = (c: Carousel): number[] => {
62
+ const origin = c.slides[0]?.offsetLeft ?? 0;
63
+ return c.slides.map((slide) => Math.abs(slide.offsetLeft - origin));
64
+ };
65
+
66
+ /** The slide the track is scrolled to: the nearest real offset, so gaps and RTL count (W-1057). */
67
+ function scrolledIndex(c: Carousel): number {
68
+ const at = Math.abs(c.track.scrollLeft);
69
+ let best = 0;
70
+ offsets(c).forEach((offset, i, all) => {
71
+ if (Math.abs(offset - at) < Math.abs((all[best] ?? 0) - at)) best = i;
72
+ });
73
+ return Math.min(best, lastStart(c));
74
+ }
75
+
76
+ /** One dot per start position the current view can reach; rebuilt when that number changes. */
77
+ function renderDots(c: Carousel): void {
78
+ if (!c.dotsBox) return;
79
+ const count = lastStart(c) + 1;
80
+ if (c.dots.length === count) return;
81
+ const focusedAt = c.dots.findIndex((dot) => dot === document.activeElement);
82
+ c.dots = [];
83
+ for (let i = 0; i < count; i++) {
84
+ const dot = button(`Go to slide ${i + 1}`, "");
85
+ dot.addEventListener("click", () => go(c, i, false));
86
+ c.dots.push(dot);
87
+ }
88
+ c.dotsBox.replaceChildren(...c.dots);
89
+ if (focusedAt >= 0) c.dots[Math.min(focusedAt, count - 1)]?.focus();
90
+ }
91
+
92
+ /** Re-reads the layout after a resize or once a hidden carousel can be measured. */
93
+ function refresh(c: Carousel): void {
94
+ renderDots(c);
95
+ c.index = scrolledIndex(c);
96
+ update(c);
97
+ }
98
+
56
99
  /** Shows slide `index` (wrapped when looping or playing, else kept in range). */
57
100
  function go(c: Carousel, index: number, wrap = c.loop): void {
58
101
  const last = lastStart(c);
@@ -83,7 +126,8 @@ function setup(root: HTMLElement): void {
83
126
  index: 0,
84
127
  dots: [],
85
128
  stopped: false,
86
- held: false,
129
+ hovered: false,
130
+ focused: false,
87
131
  };
88
132
  if (c.slides.length < 2) return;
89
133
  const controls = document.createElement("div");
@@ -95,15 +139,10 @@ function setup(root: HTMLElement): void {
95
139
  c.next.addEventListener("click", () => go(c, c.index + 1));
96
140
  }
97
141
  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]));
142
+ c.dotsBox = document.createElement("div");
143
+ c.dotsBox.className = "emvb-carousel-dots";
144
+ renderDots(c);
145
+ controls.append(...present([c.prev, c.dotsBox, c.next]));
107
146
  } else {
108
147
  controls.append(...present([c.prev, c.next]));
109
148
  }
@@ -115,13 +154,12 @@ function setup(root: HTMLElement): void {
115
154
  track.addEventListener("scroll", () => {
116
155
  cancelAnimationFrame(frame);
117
156
  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));
157
+ if ((c.slides[0]?.offsetWidth ?? 0) <= 0) return;
158
+ c.index = scrolledIndex(c);
122
159
  update(c);
123
160
  });
124
161
  });
162
+ if (typeof ResizeObserver === "function") new ResizeObserver(() => refresh(c)).observe(track);
125
163
  update(c);
126
164
  }
127
165
 
@@ -134,7 +172,7 @@ function autoplay(c: Carousel, seconds: number): void {
134
172
  toggle.setAttribute("aria-label", c.stopped ? "Play slides" : "Pause slides");
135
173
  };
136
174
  const tick = () => {
137
- if (!c.stopped && !c.held) go(c, c.index + 1, true);
175
+ if (!c.stopped && !c.hovered && !c.focused) go(c, c.index + 1, true);
138
176
  };
139
177
  toggle.addEventListener("click", () => {
140
178
  c.stopped = !c.stopped;
@@ -146,14 +184,17 @@ function autoplay(c: Carousel, seconds: number): void {
146
184
  bar.className = "emvb-carousel-controls emvb-carousel-autoplay";
147
185
  bar.append(toggle);
148
186
  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));
187
+ c.root.addEventListener("pointerenter", () => {
188
+ c.hovered = true;
189
+ });
190
+ c.root.addEventListener("pointerleave", () => {
191
+ c.hovered = false;
192
+ });
193
+ c.root.addEventListener("focusin", () => {
194
+ c.focused = true;
195
+ });
155
196
  c.root.addEventListener("focusout", (event) => {
156
- if (!c.root.contains(event.relatedTarget as Node | null)) c.held = false;
197
+ if (!c.root.contains(event.relatedTarget as Node | null)) c.focused = false;
157
198
  });
158
199
  c.timer = setInterval(tick, seconds * 1000);
159
200
  }
@@ -26,10 +26,16 @@ function start(root: HTMLElement, target: number): void {
26
26
  nums.set(el.dataset["unit"] ?? "", el);
27
27
  const pause = root.querySelector<HTMLButtonElement>(".emvb-countdown-pause");
28
28
  let timer: ReturnType<typeof setInterval> | undefined;
29
-
30
- const end = () => {
29
+ let finish: ReturnType<typeof setTimeout> | undefined;
30
+ const halt = () => {
31
31
  if (timer !== undefined) clearInterval(timer);
32
+ if (finish !== undefined) clearTimeout(finish);
32
33
  timer = undefined;
34
+ finish = undefined;
35
+ };
36
+
37
+ const end = () => {
38
+ halt();
33
39
  if (root.dataset["expired"] === "hide") {
34
40
  root.hidden = true;
35
41
  return;
@@ -48,7 +54,15 @@ function start(root: HTMLElement, target: number): void {
48
54
  const el = nums.get(unit);
49
55
  if (el) el.textContent = pad(shown[unit]);
50
56
  }
51
- if (left.total === 0) end();
57
+ // W-1060: time is up only when the clock reaches the target, not when the whole seconds
58
+ // left round down to zero; the last part-second gets its own timer so the end isn't late.
59
+ const ms = target - Date.now();
60
+ if (ms <= 0) end();
61
+ else if (ms < 1000 && finish === undefined)
62
+ finish = setTimeout(() => {
63
+ finish = undefined;
64
+ tick();
65
+ }, ms);
52
66
  };
53
67
 
54
68
  const run = () => {
@@ -61,10 +75,7 @@ function start(root: HTMLElement, target: number): void {
61
75
  const paused = pause.getAttribute("aria-pressed") === "true";
62
76
  pause.setAttribute("aria-pressed", String(!paused));
63
77
  if (paused) run();
64
- else if (timer !== undefined) {
65
- clearInterval(timer);
66
- timer = undefined;
67
- }
78
+ else halt();
68
79
  });
69
80
  run();
70
81
  }
@@ -0,0 +1,27 @@
1
+ import { extensionAssets } from "../../core/extensions/index.ts";
2
+
3
+ /** Extension runtimes already written in one response (page plus theme parts), per request. */
4
+ const written = new WeakMap<object, Set<string>>();
5
+
6
+ /**
7
+ * W-1086: the runtimes of the `ext:<package>` names a page or theme part asked for, each once per
8
+ * request. The text was read from the extension's package at build time and checked so it can't
9
+ * close its `<script>` (classes.ts).
10
+ */
11
+ export function extensionRuntimeScripts(
12
+ request: object,
13
+ names: readonly string[],
14
+ ): { id: string; code: string }[] {
15
+ const done = written.get(request) ?? new Set<string>();
16
+ written.set(request, done);
17
+ const out: { id: string; code: string }[] = [];
18
+ for (const name of names) {
19
+ if (!name.startsWith("ext:")) continue;
20
+ const id = name.slice(4);
21
+ const code = extensionAssets(id)?.runtime;
22
+ if (!code || done.has(id)) continue;
23
+ done.add(id);
24
+ out.push({ id, code });
25
+ }
26
+ return out;
27
+ }
@@ -52,7 +52,12 @@ function start(mark: HTMLElement, r: Rotation): void {
52
52
  const timer = setInterval(() => {
53
53
  step++;
54
54
  text.textContent = r.words[step % r.words.length] ?? "";
55
- if (step >= last) stop();
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);
56
61
  }, r.interval * 1000);
57
62
 
58
63
  function stop(): void {
@@ -62,10 +67,8 @@ function start(mark: HTMLElement, r: Rotation): void {
62
67
  spoken.remove();
63
68
  pause.remove();
64
69
  }
65
- // Pausing ends the rotation for good, back on the first word.
66
- pause.addEventListener("click", () => {
67
- const next = pause.nextElementSibling;
68
- stop();
70
+ /** Focus after the removed button: the control that followed it, else the heading. */
71
+ function moveOn(next: Element | null): void {
69
72
  if (
70
73
  next instanceof HTMLElement &&
71
74
  next.matches("a[href], button, input, select, textarea, [tabindex]")
@@ -75,6 +78,12 @@ function start(mark: HTMLElement, r: Rotation): void {
75
78
  heading.tabIndex = -1;
76
79
  heading.focus();
77
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);
78
87
  });
79
88
  }
80
89
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  export const PLUGIN_ID = "emvb";
2
- export const PLUGIN_VERSION = "1.3.0";
2
+ export const PLUGIN_VERSION = "1.4.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";