@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
|
@@ -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
|
|
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?:
|
|
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?:
|
|
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
|
-
|
|
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");
|
package/src/astro/resolve.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PAGES_COLLECTION } from "../constants.ts";
|
|
2
|
+
import { unlistedCanvasCollectionFirstSeen } from "../core/canvas-collections.ts";
|
|
2
3
|
import { forEachNode } from "../core/tree-ops.ts";
|
|
3
4
|
import type { Layout, LayoutNode } from "../core/schema/layout.ts";
|
|
4
5
|
import { emdashContent, type ContentPort } from "./content-port.ts";
|
|
@@ -136,6 +137,14 @@ export async function resolveEmVBPageWith(
|
|
|
136
137
|
const stored = hosted ? data[options.field ?? "canvas"] : data["layout"];
|
|
137
138
|
// An empty canvas field leaves the entry to the host's own template.
|
|
138
139
|
if (hosted && (stored === null || stored === undefined || stored === "")) return null;
|
|
140
|
+
if (hosted && unlistedCanvasCollectionFirstSeen(options.collection as string)) {
|
|
141
|
+
// W-1036 (S-08): once per collection and process; 2.0 will refuse to render it.
|
|
142
|
+
// oxlint-disable-next-line no-console
|
|
143
|
+
console.warn(
|
|
144
|
+
"emvb: rendering a layout from a collection missing from emvb({ canvasCollections }); add it there (EmVB 2.0 will not render it)",
|
|
145
|
+
{ collection: options.collection },
|
|
146
|
+
);
|
|
147
|
+
}
|
|
139
148
|
const handler = content.pluginHandler(astro.locals as never);
|
|
140
149
|
const design = await designFor(astro, handler, astro.url);
|
|
141
150
|
const layout = readLayout(stored);
|
|
@@ -5,15 +5,37 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import EmVBAlertsRuntime from "./EmVBAlertsRuntime.astro";
|
|
7
7
|
import EmVBCarouselRuntime from "./EmVBCarouselRuntime.astro";
|
|
8
|
+
import EmVBCountdownRuntime from "./EmVBCountdownRuntime.astro";
|
|
9
|
+
import EmVBCounterRuntime from "./EmVBCounterRuntime.astro";
|
|
10
|
+
import EmVBHeadlineRuntime from "./EmVBHeadlineRuntime.astro";
|
|
8
11
|
import EmVBLightboxRuntime from "./EmVBLightboxRuntime.astro";
|
|
12
|
+
import EmVBMapRuntime from "./EmVBMapRuntime.astro";
|
|
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";
|
|
9
17
|
|
|
10
18
|
interface Props {
|
|
11
19
|
names?: readonly string[] | undefined;
|
|
12
20
|
}
|
|
13
21
|
|
|
14
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 ?? []);
|
|
15
25
|
---
|
|
16
26
|
|
|
17
27
|
{names.has("alerts") && <EmVBAlertsRuntime />}
|
|
18
28
|
{names.has("lightbox") && <EmVBLightboxRuntime />}
|
|
19
29
|
{names.has("carousel") && <EmVBCarouselRuntime />}
|
|
30
|
+
{names.has("counter") && <EmVBCounterRuntime />}
|
|
31
|
+
{names.has("countdown") && <EmVBCountdownRuntime />}
|
|
32
|
+
{names.has("map") && <EmVBMapRuntime />}
|
|
33
|
+
{names.has("headline") && <EmVBHeadlineRuntime />}
|
|
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
|
-
|
|
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) =>
|
|
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
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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.
|
|
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
|
-
|
|
150
|
-
c.
|
|
151
|
-
};
|
|
152
|
-
c.root.addEventListener("
|
|
153
|
-
|
|
154
|
-
|
|
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.
|
|
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
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
let finish: ReturnType<typeof setTimeout> | undefined;
|
|
30
|
+
const halt = () => {
|
|
31
|
+
if (timer !== undefined) clearInterval(timer);
|
|
32
|
+
if (finish !== undefined) clearTimeout(finish);
|
|
33
|
+
timer = undefined;
|
|
34
|
+
finish = undefined;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const end = () => {
|
|
38
|
+
halt();
|
|
39
|
+
if (root.dataset["expired"] === "hide") {
|
|
40
|
+
root.hidden = true;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const clock = root.querySelector<HTMLElement>(".emvb-countdown-clock");
|
|
44
|
+
if (clock) clock.hidden = true;
|
|
45
|
+
root.querySelector<HTMLElement>(".emvb-countdown-expired")?.setAttribute("data-emvb-shown", "");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const tick = () => {
|
|
49
|
+
const left = remaining(target, Date.now());
|
|
50
|
+
const hasSeconds = nums.has("seconds");
|
|
51
|
+
// Without seconds, the days to minutes left round up, so the clock never shows 0 too early.
|
|
52
|
+
const shown = hasSeconds ? left : remaining(target + 59_000, Date.now());
|
|
53
|
+
for (const unit of ["days", "hours", "minutes", "seconds"] as const) {
|
|
54
|
+
const el = nums.get(unit);
|
|
55
|
+
if (el) el.textContent = pad(shown[unit]);
|
|
56
|
+
}
|
|
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);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const run = () => {
|
|
69
|
+
tick();
|
|
70
|
+
if (root.hidden || root.querySelector(".emvb-countdown-clock[hidden]")) return;
|
|
71
|
+
timer = setInterval(tick, 1000);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
pause?.addEventListener("click", () => {
|
|
75
|
+
const paused = pause.getAttribute("aria-pressed") === "true";
|
|
76
|
+
pause.setAttribute("aria-pressed", String(!paused));
|
|
77
|
+
if (paused) run();
|
|
78
|
+
else halt();
|
|
79
|
+
});
|
|
80
|
+
run();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function initCountdowns(root: ParentNode = document): void {
|
|
84
|
+
for (const el of root.querySelectorAll<HTMLElement>("[data-emvb-countdown]")) {
|
|
85
|
+
if (el.dataset["emvbReady"] !== undefined) continue;
|
|
86
|
+
const target = Date.parse(el.dataset["target"] ?? "");
|
|
87
|
+
if (Number.isNaN(target)) continue;
|
|
88
|
+
el.dataset["emvbReady"] = "";
|
|
89
|
+
start(el, target);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -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,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
|
+
}
|