@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.
- package/THIRD_PARTY_NOTICES.md +3 -2
- package/package.json +11 -10
- package/src/admin/agents-api.ts +5 -1
- package/src/admin/content-api.ts +29 -0
- package/src/admin/editor/Editor.tsx +6 -1
- package/src/admin/editor/ScheduleDialog.tsx +167 -0
- package/src/admin/editor/TopBar.tsx +33 -1
- package/src/admin/editor/canvas/vnode-react.tsx +3 -0
- package/src/admin/editor/dnd/new-element.ts +106 -0
- package/src/admin/editor/editor-chrome.tsx +9 -0
- package/src/admin/editor/element-chrome.ts +50 -0
- package/src/admin/editor/panels/ElementPanel.tsx +5 -1
- package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
- package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
- package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +69 -2
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/store.ts +7 -1
- package/src/admin/editor/useEditorData.ts +4 -0
- package/src/admin/editor/useSave.ts +47 -3
- package/src/admin/export-api.ts +20 -3
- package/src/admin/menus-api.ts +113 -0
- package/src/admin/pages/ImportElementorDialog.tsx +25 -1
- package/src/astro/EmVBPage.astro +3 -0
- package/src/astro/render.ts +43 -18
- package/src/astro/request-data.ts +9 -0
- package/src/astro/resolve-theme.ts +77 -44
- package/src/astro/resolve.ts +9 -0
- package/src/astro/visitor.ts +23 -4
- package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -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/EmVBLightboxRuntime.astro +8 -0
- package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
- package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +29 -0
- package/src/astro/widgets/alerts.ts +37 -0
- package/src/astro/widgets/carousel.ts +167 -0
- package/src/astro/widgets/countdown.ts +80 -0
- package/src/astro/widgets/counter.ts +98 -0
- package/src/astro/widgets/headline.ts +90 -0
- package/src/astro/widgets/index.ts +1 -0
- package/src/astro/widgets/lightbox.ts +123 -0
- package/src/astro/widgets/map.ts +37 -0
- package/src/astro/widgets/share.ts +21 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +127 -5
- package/src/core/arrange.ts +109 -1
- package/src/core/bounded-array.ts +16 -13
- package/src/core/canvas-collections.ts +28 -0
- package/src/core/contract.ts +4 -1
- package/src/core/elements/counter-format.ts +15 -0
- package/src/core/elements/icon-svg.ts +135 -0
- package/src/core/elements/index.ts +63 -127
- package/src/core/elements/marketing.ts +1490 -0
- package/src/core/elements/widgets.ts +932 -0
- package/src/core/export/runtimes.generated.ts +8 -0
- package/src/core/export/site.ts +25 -3
- package/src/core/extensions/schema.ts +2 -1
- package/src/core/geo-trust.ts +18 -0
- package/src/core/icons/social.generated.ts +29 -0
- package/src/core/image-edit/schema.ts +2 -1
- package/src/core/import/elementor/context.ts +18 -0
- package/src/core/import/elementor/index.ts +50 -7
- package/src/core/import/elementor/widgets.ts +783 -385
- package/src/core/issue-cap.ts +19 -0
- package/src/core/limits.ts +12 -0
- package/src/core/loop-collections.ts +33 -0
- package/src/core/proposals.ts +8 -2
- package/src/core/render/index.ts +48 -5
- package/src/core/render/vnode.ts +44 -6
- package/src/core/sanitize/svg-upload.ts +276 -23
- package/src/core/sanitize/svg.ts +3 -3
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +6 -5
- package/src/core/schema/layout.ts +798 -15
- package/src/core/schema/style.ts +2 -1
- package/src/core/shadowing-ids.ts +41 -0
- package/src/core/theme/conditions.ts +2 -1
- package/src/core/theme/dynamic.ts +2 -0
- package/src/core/theme/parse-doc.ts +10 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/validate.ts +3 -2
- package/src/index.ts +23 -2
- package/src/mcp/ports.ts +18 -7
- package/src/mcp/proposals.ts +36 -11
- package/src/mcp/tools.ts +1 -1
- package/src/server/agent-settings.ts +12 -1
- package/src/server/hooks.ts +41 -6
- package/src/server/mcp-routes.ts +11 -5
- package/src/server/plugin.ts +29 -3
- package/src/server/presence.ts +5 -1
- package/src/server/proposals.ts +16 -4
- package/src/server/requests.ts +60 -11
- package/src/server/site-origin.ts +13 -0
- package/src/server/targets.ts +26 -0
package/src/astro/render.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type Layout,
|
|
10
10
|
type ThemeDynamicData,
|
|
11
11
|
} from "../core/index.ts";
|
|
12
|
+
import type { WidgetRuntime } from "../core/elements/widgets.ts";
|
|
12
13
|
import { PLUGIN_ID } from "../constants.ts";
|
|
13
14
|
|
|
14
15
|
export type RenderedPage = {
|
|
@@ -17,6 +18,11 @@ export type RenderedPage = {
|
|
|
17
18
|
needsFormsRuntime: boolean;
|
|
18
19
|
needsTabsRuntime: boolean;
|
|
19
20
|
needsMenuRuntime: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* W-1025: the opt-in widget scripts this page needs (a dismissible Alert…). `EmVBPage` loads
|
|
23
|
+
* them itself; set only when there is one.
|
|
24
|
+
*/
|
|
25
|
+
runtimes?: WidgetRuntime[];
|
|
20
26
|
/** The site's text direction when set, for the host's `<html dir>` (W-230). */
|
|
21
27
|
dir?: "ltr" | "rtl" | "auto";
|
|
22
28
|
/** W-971: the element types whose base rules `css` holds, for `sharedPartCss`. */
|
|
@@ -77,37 +83,56 @@ export function renderStored(
|
|
|
77
83
|
/** The page's language, e.g. "fr-CA", for Post Dates (W-688). */
|
|
78
84
|
lang?: string,
|
|
79
85
|
): RenderedPage {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
const empty: RenderedPage = {
|
|
87
|
+
html: "",
|
|
88
|
+
css: "",
|
|
89
|
+
needsFormsRuntime: false,
|
|
90
|
+
needsTabsRuntime: false,
|
|
91
|
+
needsMenuRuntime: false,
|
|
92
|
+
...(design.direction ? { dir: design.direction } : {}),
|
|
93
|
+
};
|
|
94
|
+
let result: ReturnType<typeof renderPage>;
|
|
95
|
+
try {
|
|
96
|
+
const { layout, problem } = inspectLayout(raw);
|
|
97
|
+
if (!layout) {
|
|
98
|
+
if (raw !== null && raw !== undefined && raw !== "") {
|
|
99
|
+
// Public renders have no plugin logger. The page id and where the layout first fails
|
|
100
|
+
// (a structural path and an issue code), never layout content or issue messages (W-182).
|
|
101
|
+
// oxlint-disable-next-line no-console
|
|
102
|
+
console.error("emvb: stored layout is unreadable", { pageId, ...problem });
|
|
103
|
+
}
|
|
104
|
+
return empty;
|
|
87
105
|
}
|
|
88
|
-
|
|
89
|
-
html: "",
|
|
90
|
-
css: "",
|
|
91
|
-
needsFormsRuntime: false,
|
|
92
|
-
needsTabsRuntime: false,
|
|
93
|
-
needsMenuRuntime: false,
|
|
94
|
-
...(design.direction ? { dir: design.direction } : {}),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime, baseTypes } =
|
|
98
|
-
renderPage(layout, design, {
|
|
106
|
+
result = renderPage(layout, design, {
|
|
99
107
|
formDefinitions,
|
|
100
108
|
dynamic,
|
|
101
109
|
scope: pageId,
|
|
102
110
|
...(partIds ? { partIds } : {}),
|
|
103
111
|
...(lang ? { lang } : {}),
|
|
104
112
|
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
// S-02: a layout that can't render leaves the page empty instead of failing the request.
|
|
115
|
+
// oxlint-disable-next-line no-console
|
|
116
|
+
console.error("emvb: stored layout failed to render", {
|
|
117
|
+
pageId,
|
|
118
|
+
error: error instanceof Error ? error.name : "unknown",
|
|
119
|
+
});
|
|
120
|
+
return empty;
|
|
121
|
+
}
|
|
122
|
+
const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime, baseTypes, runtimes } =
|
|
123
|
+
result;
|
|
124
|
+
for (const warning of result.warnings) {
|
|
125
|
+
if (warning.code !== "refused-markup") continue;
|
|
126
|
+
// oxlint-disable-next-line no-console
|
|
127
|
+
console.error("emvb: an element could not render", { pageId, nodeId: warning.nodeId });
|
|
128
|
+
}
|
|
105
129
|
return {
|
|
106
130
|
html,
|
|
107
131
|
css,
|
|
108
132
|
needsFormsRuntime,
|
|
109
133
|
needsTabsRuntime,
|
|
110
134
|
needsMenuRuntime,
|
|
135
|
+
...(runtimes.length > 0 ? { runtimes } : {}),
|
|
111
136
|
...(design.direction ? { dir: design.direction } : {}),
|
|
112
137
|
baseTypes,
|
|
113
138
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { loopCollectionAllowed } from "../core/loop-collections.ts";
|
|
2
|
+
import { someNode } from "../core/tree-ops.ts";
|
|
1
3
|
import { emdashContent, type ContentPort } from "./content-port.ts";
|
|
2
4
|
import { siteFor } from "./render-session.ts";
|
|
3
5
|
import {
|
|
@@ -17,6 +19,7 @@ type RequestData = {
|
|
|
17
19
|
site?: Record<string, string>;
|
|
18
20
|
params?: Record<string, string>;
|
|
19
21
|
origin?: string;
|
|
22
|
+
pageUrl?: string;
|
|
20
23
|
collections?: Record<string, ThemePostFields[]>;
|
|
21
24
|
abArms?: Record<string, "a" | "b">;
|
|
22
25
|
visitor?: VisitorInfo;
|
|
@@ -31,6 +34,8 @@ const ORDER_BY: Record<CollectionLoop["order"], Record<string, "asc" | "desc">>
|
|
|
31
34
|
|
|
32
35
|
/** Published entries for one collection Loop (W-308); a failing query lists nothing. */
|
|
33
36
|
async function loopEntries(loop: CollectionLoop, content: ContentPort): Promise<ThemePostFields[]> {
|
|
37
|
+
// S-11 (W-1000): a site that lists its Loop collections shows nothing from the others.
|
|
38
|
+
if (!loopCollectionAllowed(loop.collection)) return [];
|
|
34
39
|
try {
|
|
35
40
|
const result = await content.getCollection(loop.collection, {
|
|
36
41
|
status: "published",
|
|
@@ -91,6 +96,10 @@ export async function bindingDataFor(
|
|
|
91
96
|
const lists = await Promise.all(loops.map((loop) => loopEntries(loop, content)));
|
|
92
97
|
data.collections = Object.fromEntries(loops.map((loop, i) => [loop.nodeId, lists[i] ?? []]));
|
|
93
98
|
}
|
|
99
|
+
// W-1047: Share buttons share this page's address, without its query or hash.
|
|
100
|
+
if (someNode(layout.root, (node) => node.type === "share-buttons")) {
|
|
101
|
+
data.pageUrl = `${url.origin}${url.pathname}`;
|
|
102
|
+
}
|
|
94
103
|
if (layoutUsesSource(layout.root, "param")) {
|
|
95
104
|
data.params = paramsFromSearch(url.searchParams);
|
|
96
105
|
// W-307: URL-parameter links and images stay on this origin unless allowed outside.
|
|
@@ -37,6 +37,7 @@ 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
41
|
import { designFor, formsFor, layoutFor, partsFor } from "./render-session.ts";
|
|
41
42
|
import type { HostVisitor, VisitorAstro } from "./visitor.ts";
|
|
42
43
|
import { bindingDataFor } from "./request-data.ts";
|
|
@@ -98,6 +99,11 @@ export type ResolvedThemeParts = {
|
|
|
98
99
|
needsMenuRuntime: boolean;
|
|
99
100
|
/** Hosts load `EmVBFormsRuntime` only when a winning part renders a form. */
|
|
100
101
|
needsFormsRuntime: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* W-1025: the opt-in widget scripts the winning parts need; set only when there is one. Mount
|
|
104
|
+
* `<EmVBWidgetRuntimes names={theme.runtimes} />` from `@perkyzz/emvb/astro/widgets`.
|
|
105
|
+
*/
|
|
106
|
+
runtimes?: WidgetRuntime[];
|
|
101
107
|
/**
|
|
102
108
|
* True for an archive page past the last one (`/posts/page/9` with no posts there). Hosts
|
|
103
109
|
* answer 404 (W-221). Page 1 with no posts is not a 404.
|
|
@@ -411,6 +417,12 @@ async function buildDynamicForContent(
|
|
|
411
417
|
return undefined;
|
|
412
418
|
}
|
|
413
419
|
|
|
420
|
+
/** W-1025: every widget runtime the rendered parts need, once each, or nothing. */
|
|
421
|
+
function partRuntimes(rendered: readonly RenderedPage[]): { runtimes?: WidgetRuntime[] } {
|
|
422
|
+
const names = [...new Set(rendered.flatMap((page) => page.runtimes ?? []))].toSorted();
|
|
423
|
+
return names.length > 0 ? { runtimes: names } : {};
|
|
424
|
+
}
|
|
425
|
+
|
|
414
426
|
/**
|
|
415
427
|
* Resolve winning published theme parts for this request (R-062 / S7b–S7d).
|
|
416
428
|
* Returns plain HTML/CSS; popup JS is optional and only when `needsPopupsRuntime`.
|
|
@@ -441,6 +453,20 @@ export async function resolveThemeParts(
|
|
|
441
453
|
return resolveThemePartsWith(emdashContent, astro, ctx, options);
|
|
442
454
|
}
|
|
443
455
|
|
|
456
|
+
/** S-02: a part that fails to render is left out, so the rest of the site still renders. */
|
|
457
|
+
async function orSkip<T>(id: string, render: () => Promise<T | null>): Promise<T | null> {
|
|
458
|
+
try {
|
|
459
|
+
return await render();
|
|
460
|
+
} catch (error) {
|
|
461
|
+
// oxlint-disable-next-line no-console
|
|
462
|
+
console.error("emvb: theme part failed to render", {
|
|
463
|
+
partId: id,
|
|
464
|
+
error: error instanceof Error ? error.name : "unknown",
|
|
465
|
+
});
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
444
470
|
/** Same as `resolveThemeParts`, with a content port so tests can pass a fake (W-359). */
|
|
445
471
|
export async function resolveThemePartsWith(
|
|
446
472
|
port: ContentPort,
|
|
@@ -605,7 +631,9 @@ export async function resolveThemePartsWith(
|
|
|
605
631
|
|
|
606
632
|
let pastLastPage = false;
|
|
607
633
|
let archiveInfo: { title?: string; page: number; titleText?: string } | undefined;
|
|
608
|
-
const renderPart =
|
|
634
|
+
const renderPart = (winner: ThemePartCandidate | null): Promise<RenderedThemePart | null> =>
|
|
635
|
+
orSkip(winner?.id ?? "", () => renderPartOf(winner));
|
|
636
|
+
const renderPartOf = async (
|
|
609
637
|
winner: ThemePartCandidate | null,
|
|
610
638
|
): Promise<RenderedThemePart | null> => {
|
|
611
639
|
const stored = winner ? byId.get(winner.id) : undefined;
|
|
@@ -665,54 +693,58 @@ export async function resolveThemePartsWith(
|
|
|
665
693
|
|
|
666
694
|
const popups = (
|
|
667
695
|
await Promise.all(
|
|
668
|
-
popupMatches.map(
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
696
|
+
popupMatches.map((match) =>
|
|
697
|
+
orSkip(match.id, async () => {
|
|
698
|
+
const stored = byId.get(match.id);
|
|
699
|
+
if (!stored) return null;
|
|
700
|
+
const { html, css } = await renderOne(
|
|
701
|
+
stored,
|
|
702
|
+
extraTemplates.get(stored.id),
|
|
703
|
+
extraBound.get(stored.id) ?? {},
|
|
704
|
+
);
|
|
705
|
+
const popup: RenderedPopup = {
|
|
706
|
+
id: stored.id,
|
|
707
|
+
title: stored.title,
|
|
708
|
+
html: wrapPopupMarkup(stored.id, html, stored.triggers, options.labels),
|
|
709
|
+
css,
|
|
710
|
+
triggers: stored.triggers,
|
|
711
|
+
};
|
|
712
|
+
return popup;
|
|
713
|
+
}),
|
|
714
|
+
),
|
|
685
715
|
)
|
|
686
716
|
).filter((popup): popup is RenderedPopup => popup !== null);
|
|
687
717
|
|
|
688
718
|
const floats = (
|
|
689
719
|
await Promise.all(
|
|
690
|
-
floatMatches.map(
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
720
|
+
floatMatches.map((match) =>
|
|
721
|
+
orSkip(match.id, async () => {
|
|
722
|
+
const stored = byId.get(match.id);
|
|
723
|
+
if (!stored) return null;
|
|
724
|
+
const { html, css } = await renderOne(
|
|
725
|
+
stored,
|
|
726
|
+
extraTemplates.get(stored.id),
|
|
727
|
+
extraBound.get(stored.id) ?? {},
|
|
728
|
+
);
|
|
729
|
+
const layout = readLayout(stored.layout);
|
|
730
|
+
const surface = !layout || !floatHasOwnSurface(layout, design);
|
|
731
|
+
const item: RenderedFloat = {
|
|
732
|
+
id: stored.id,
|
|
733
|
+
title: stored.title,
|
|
734
|
+
html: wrapFloatMarkup(
|
|
735
|
+
stored.id,
|
|
736
|
+
stored.title,
|
|
737
|
+
html,
|
|
738
|
+
stored.float,
|
|
739
|
+
surface,
|
|
740
|
+
options.labels?.close,
|
|
741
|
+
),
|
|
742
|
+
css,
|
|
743
|
+
settings: stored.float,
|
|
744
|
+
};
|
|
745
|
+
return item;
|
|
746
|
+
}),
|
|
747
|
+
),
|
|
716
748
|
)
|
|
717
749
|
).filter((item): item is RenderedFloat => item !== null);
|
|
718
750
|
|
|
@@ -737,6 +769,7 @@ export async function resolveThemePartsWith(
|
|
|
737
769
|
needsTabsRuntime: rendered.some((page) => page.needsTabsRuntime),
|
|
738
770
|
needsMenuRuntime: rendered.some((page) => page.needsMenuRuntime),
|
|
739
771
|
needsFormsRuntime: rendered.some((page) => page.needsFormsRuntime),
|
|
772
|
+
...partRuntimes(rendered),
|
|
740
773
|
notFound: pastLastPage,
|
|
741
774
|
...(design.direction ? { dir: design.direction } : {}),
|
|
742
775
|
...(archiveInfo?.title ? { archiveTitle: archiveInfo.title } : {}),
|
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);
|
package/src/astro/visitor.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { geoTrust } from "../core/geo-trust.ts";
|
|
1
2
|
import {
|
|
2
3
|
AUDIENCE_SEGMENT,
|
|
3
4
|
abCookieName,
|
|
@@ -113,16 +114,34 @@ const COUNTRY = /^[A-Z]{2}$/;
|
|
|
113
114
|
/** XX is Cloudflare's "unknown" and T1 is Tor: neither is a country (W-514: host facts too). */
|
|
114
115
|
const isCountry = (code: string) => COUNTRY.test(code) && code !== "XX" && code !== "T1";
|
|
115
116
|
|
|
117
|
+
const onCloudflare = () => globalThis.navigator?.userAgent === "Cloudflare-Workers";
|
|
118
|
+
const onVercel = () =>
|
|
119
|
+
Boolean(
|
|
120
|
+
(globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.[
|
|
121
|
+
"VERCEL"
|
|
122
|
+
],
|
|
123
|
+
);
|
|
124
|
+
|
|
116
125
|
/**
|
|
117
|
-
* The visitor's country from the edge: Cloudflare's header or
|
|
126
|
+
* The visitor's country from the edge: `request.cf`, Cloudflare's header or Vercel's header.
|
|
118
127
|
* Not `Astro.locals.runtime.cf`: since Astro 6 the Cloudflare adapter throws when it is read.
|
|
128
|
+
* S-10 (W-999): a header counts only where that edge sets it (on Cloudflare Workers, on
|
|
129
|
+
* Vercel); elsewhere the visitor could send it. `emvb({ trustGeoHeaders: true })` trusts them
|
|
130
|
+
* behind a proxy that strips client copies; `false` trusts none.
|
|
119
131
|
*/
|
|
120
|
-
function countryOf(
|
|
132
|
+
export function countryOf(
|
|
133
|
+
astro: VisitorAstro,
|
|
134
|
+
trust: boolean | undefined = geoTrust(),
|
|
135
|
+
): string | undefined {
|
|
121
136
|
const headers = astro.request?.headers;
|
|
122
137
|
const cf = (astro.request as { cf?: { country?: unknown } } | undefined)?.cf;
|
|
123
138
|
const candidates = [
|
|
124
|
-
|
|
125
|
-
|
|
139
|
+
trust === true || (trust === undefined && onCloudflare())
|
|
140
|
+
? headers?.get("cf-ipcountry")
|
|
141
|
+
: undefined,
|
|
142
|
+
trust === true || (trust === undefined && onVercel())
|
|
143
|
+
? headers?.get("x-vercel-ip-country")
|
|
144
|
+
: undefined,
|
|
126
145
|
cf?.country,
|
|
127
146
|
];
|
|
128
147
|
for (const value of candidates) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* W-1025: the opt-in scripts of the 1.2 widgets, each mounted only when `names` asks for it.
|
|
4
|
+
* `EmVBPage` renders this for its page; for theme parts, pass `theme.runtimes`.
|
|
5
|
+
*/
|
|
6
|
+
import EmVBAlertsRuntime from "./EmVBAlertsRuntime.astro";
|
|
7
|
+
import EmVBCarouselRuntime from "./EmVBCarouselRuntime.astro";
|
|
8
|
+
import EmVBCountdownRuntime from "./EmVBCountdownRuntime.astro";
|
|
9
|
+
import EmVBCounterRuntime from "./EmVBCounterRuntime.astro";
|
|
10
|
+
import EmVBHeadlineRuntime from "./EmVBHeadlineRuntime.astro";
|
|
11
|
+
import EmVBLightboxRuntime from "./EmVBLightboxRuntime.astro";
|
|
12
|
+
import EmVBMapRuntime from "./EmVBMapRuntime.astro";
|
|
13
|
+
import EmVBShareRuntime from "./EmVBShareRuntime.astro";
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
names?: readonly string[] | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const names = new Set(Astro.props.names ?? []);
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
{names.has("alerts") && <EmVBAlertsRuntime />}
|
|
23
|
+
{names.has("lightbox") && <EmVBLightboxRuntime />}
|
|
24
|
+
{names.has("carousel") && <EmVBCarouselRuntime />}
|
|
25
|
+
{names.has("counter") && <EmVBCounterRuntime />}
|
|
26
|
+
{names.has("countdown") && <EmVBCountdownRuntime />}
|
|
27
|
+
{names.has("map") && <EmVBMapRuntime />}
|
|
28
|
+
{names.has("headline") && <EmVBHeadlineRuntime />}
|
|
29
|
+
{names.has("share") && <EmVBShareRuntime />}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1025: the opt-in Alert runtime. It shows each dismissible Alert's close button (hidden until
|
|
3
|
+
* this script runs, so a page without it never shows a button that does nothing) and hides the
|
|
4
|
+
* Alert when it is pressed, moving focus to the next thing a keyboard reaches.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const FOCUSABLE =
|
|
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
|
+
|
|
10
|
+
/** The first focusable element after `from` in the document, else the last one before it. */
|
|
11
|
+
function neighbour(from: Element): HTMLElement | null {
|
|
12
|
+
const all = [...from.ownerDocument.querySelectorAll<HTMLElement>(FOCUSABLE)].filter(
|
|
13
|
+
(el) => !from.contains(el) && !el.closest("[hidden]"),
|
|
14
|
+
);
|
|
15
|
+
const after = all.find(
|
|
16
|
+
(el) => from.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
17
|
+
);
|
|
18
|
+
return (
|
|
19
|
+
after ??
|
|
20
|
+
all.findLast((el) => from.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING) ??
|
|
21
|
+
null
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function initAlerts(root: ParentNode = document): void {
|
|
26
|
+
for (const button of root.querySelectorAll<HTMLButtonElement>("[data-emvb-alert-dismiss]")) {
|
|
27
|
+
if (button.dataset["emvbReady"] !== undefined) continue;
|
|
28
|
+
button.dataset["emvbReady"] = "";
|
|
29
|
+
button.addEventListener("click", () => {
|
|
30
|
+
const alert = button.closest<HTMLElement>(".emvb-alert");
|
|
31
|
+
if (!alert) return;
|
|
32
|
+
const next = neighbour(alert);
|
|
33
|
+
alert.hidden = true;
|
|
34
|
+
next?.focus();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|