@perkyzz/emvb 1.3.0 → 1.4.1
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/package.json +2 -2
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/content-item.ts +3 -0
- package/src/admin/copy-rich-text.ts +99 -9
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +28 -3
- 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 +2 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/collection-previews.ts +7 -8
- 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 +16 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +6 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
- package/src/admin/editor/extensions-context.tsx +16 -1
- package/src/admin/editor/feature-css.ts +27 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
- package/src/admin/editor/panels/ElementPanel.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 +33 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
- package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -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/loop-context.ts +34 -3
- 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 +27 -2
- package/src/admin/extension-outputs.ts +236 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/import-forms.ts +133 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +53 -187
- package/src/admin/pages/ImportForms.tsx +71 -0
- 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/admin/setup/plan.ts +2 -0
- package/src/admin/ui.ts +7 -0
- package/src/admin/widgets/ConvertToRichText.tsx +3 -2
- 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 +25 -4
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/resolve.ts +2 -0
- package/src/astro/theme-posts.ts +17 -23
- package/src/astro/visitor.ts +14 -5
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +18 -7
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +14 -5
- 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 +150 -2
- package/src/core/arrange.ts +19 -1
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +41 -2
- package/src/core/css/trace.ts +8 -0
- package/src/core/data/bindings.ts +7 -4
- package/src/core/elements/dynamic-elements.ts +1 -1
- package/src/core/elements/element-nouns.ts +48 -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 +24 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +13 -3
- package/src/core/export/runtimes.generated.ts +7 -5
- package/src/core/export/site.ts +53 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +19 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/placeholder.ts +7 -2
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +115 -36
- 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 +42 -4
- package/src/core/import/elementor/index.ts +55 -23
- package/src/core/import/elementor/widgets.ts +242 -20
- 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 +54 -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 +165 -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 +118 -6
- 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 +9 -6
- package/src/core/theme/media-value.ts +88 -0
- 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/core/visitor-cookie.ts +91 -0
- package/src/extension-build.ts +331 -0
- package/src/index.ts +53 -4
- package/src/mcp/agent-defaults.ts +40 -0
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/extensions.ts +138 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +84 -20
- package/src/mcp/tools.ts +42 -3
- package/src/mcp/write.ts +124 -9
- package/src/server/extension-routes.ts +110 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +15 -0
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
* `resolveThemeParts().needsPopupsRuntime` is true (R-031).
|
|
4
4
|
*
|
|
5
5
|
* Triggers: page_load, delay, scroll, click, exit_intent, inactivity (W-081).
|
|
6
|
-
* Advanced
|
|
7
|
-
*
|
|
6
|
+
* Advanced: showTimes (localStorage), devices (viewport width), URL query rules and show dates
|
|
7
|
+
* (W-1081). Gap vs Elementor (deferred): A/B.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
clampScrollPercent,
|
|
12
12
|
matchesPopupDevices,
|
|
13
|
+
matchesUrlParams,
|
|
13
14
|
type PopupDevice,
|
|
14
15
|
TRIGGER_LIMITS,
|
|
16
|
+
type UrlParamRule,
|
|
17
|
+
withinShowDates,
|
|
15
18
|
withinShowTimes,
|
|
16
19
|
} from "../../core/theme/popup-rules.ts";
|
|
17
20
|
|
|
@@ -26,6 +29,9 @@ type OpenTrigger =
|
|
|
26
29
|
type Advanced = {
|
|
27
30
|
showTimes?: number | null;
|
|
28
31
|
devices?: PopupDevice[] | null;
|
|
32
|
+
urlParams?: UrlParamRule[] | null;
|
|
33
|
+
from?: string | null;
|
|
34
|
+
until?: string | null;
|
|
29
35
|
};
|
|
30
36
|
|
|
31
37
|
type TriggersDoc = {
|
|
@@ -85,6 +91,9 @@ function isValidSelector(selector: string): boolean {
|
|
|
85
91
|
function canOpen(config: PopupConfig, byClick: boolean): boolean {
|
|
86
92
|
const advanced = config.triggers.advanced;
|
|
87
93
|
if (!matchesPopupDevices(advanced, window.innerWidth)) return false;
|
|
94
|
+
// W-1081: where and when the popup runs at all, so a click is held to them too.
|
|
95
|
+
if (!matchesUrlParams(advanced, window.location.search)) return false;
|
|
96
|
+
if (!withinShowDates(advanced, Date.now())) return false;
|
|
88
97
|
if (!byClick && !withinShowTimes(advanced, timesShown(config.id))) return false;
|
|
89
98
|
return true;
|
|
90
99
|
}
|
|
@@ -93,6 +102,8 @@ type Controller = {
|
|
|
93
102
|
root: HTMLElement;
|
|
94
103
|
dialog: HTMLElement;
|
|
95
104
|
lastFocus: HTMLElement | null;
|
|
105
|
+
/** Click trigger selectors: the controls they match say they open this dialog. */
|
|
106
|
+
openers: string[];
|
|
96
107
|
open: () => void;
|
|
97
108
|
close: () => void;
|
|
98
109
|
opened: boolean;
|
|
@@ -127,6 +138,32 @@ function unlockScroll(): void {
|
|
|
127
138
|
if (!anyPopupOpen()) document.documentElement.style.overflow = savedOverflow;
|
|
128
139
|
}
|
|
129
140
|
|
|
141
|
+
const CONTROL = 'a[href], button, summary, input, [role="button"]';
|
|
142
|
+
|
|
143
|
+
/** The controls a click trigger's selector names: the matches, or the controls inside a match. */
|
|
144
|
+
function openerControls(selector: string): HTMLElement[] {
|
|
145
|
+
const out = new Set<HTMLElement>();
|
|
146
|
+
for (const match of document.querySelectorAll<HTMLElement>(selector)) {
|
|
147
|
+
if (match.matches(CONTROL)) out.add(match);
|
|
148
|
+
else for (const inner of match.querySelectorAll<HTMLElement>(CONTROL)) out.add(inner);
|
|
149
|
+
}
|
|
150
|
+
return [...out];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* W-1071: a control that opens a popup or panel says so (aria-haspopup="dialog") and whether it
|
|
155
|
+
* is open (aria-expanded), kept in step as the dialog opens and closes.
|
|
156
|
+
*/
|
|
157
|
+
function markOpeners(ctrl: Controller): void {
|
|
158
|
+
const expanded = String(ctrl.opened);
|
|
159
|
+
for (const selector of ctrl.openers) {
|
|
160
|
+
for (const control of openerControls(selector)) {
|
|
161
|
+
control.setAttribute("aria-haspopup", "dialog");
|
|
162
|
+
control.setAttribute("aria-expanded", expanded);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
130
167
|
function createController(root: HTMLElement): Controller | null {
|
|
131
168
|
const dialog = root.querySelector<HTMLElement>(".emvb-popup__dialog");
|
|
132
169
|
if (!dialog) return null;
|
|
@@ -134,6 +171,7 @@ function createController(root: HTMLElement): Controller | null {
|
|
|
134
171
|
root,
|
|
135
172
|
dialog,
|
|
136
173
|
lastFocus: null,
|
|
174
|
+
openers: [],
|
|
137
175
|
opened: false,
|
|
138
176
|
open() {
|
|
139
177
|
ctrl.lastFocus = document.activeElement as HTMLElement | null;
|
|
@@ -141,12 +179,14 @@ function createController(root: HTMLElement): Controller | null {
|
|
|
141
179
|
lockScroll();
|
|
142
180
|
root.hidden = false;
|
|
143
181
|
ctrl.opened = true;
|
|
182
|
+
markOpeners(ctrl);
|
|
144
183
|
dialog.focus({ preventScroll: true });
|
|
145
184
|
},
|
|
146
185
|
close() {
|
|
147
186
|
if (!ctrl.opened) return;
|
|
148
187
|
root.hidden = true;
|
|
149
188
|
ctrl.opened = false;
|
|
189
|
+
markOpeners(ctrl);
|
|
150
190
|
unlockScroll();
|
|
151
191
|
const prev = ctrl.lastFocus;
|
|
152
192
|
if (prev && typeof prev.focus === "function") prev.focus({ preventScroll: true });
|
|
@@ -317,6 +357,11 @@ function registerTrigger(ctrl: Controller, config: PopupConfig, trigger: OpenTri
|
|
|
317
357
|
const arm = (ARM as Record<string, Arm<OpenTrigger["type"]> | undefined>)[trigger.type];
|
|
318
358
|
const byClick = trigger.type === "click";
|
|
319
359
|
arm?.(() => openOnce(ctrl, config, byClick), trigger as never);
|
|
360
|
+
const selector = byClick ? String(trigger.selector ?? "").trim() : "";
|
|
361
|
+
if (selector && isValidSelector(selector)) {
|
|
362
|
+
ctrl.openers.push(selector);
|
|
363
|
+
markOpeners(ctrl);
|
|
364
|
+
}
|
|
320
365
|
}
|
|
321
366
|
|
|
322
367
|
/**
|
package/src/astro/render.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type Layout,
|
|
10
10
|
type ThemeDynamicData,
|
|
11
11
|
} from "../core/index.ts";
|
|
12
|
-
import type {
|
|
12
|
+
import type { PageRuntime } from "../core/elements/widgets.ts";
|
|
13
13
|
import { PLUGIN_ID } from "../constants.ts";
|
|
14
14
|
|
|
15
15
|
export type RenderedPage = {
|
|
@@ -22,11 +22,16 @@ export type RenderedPage = {
|
|
|
22
22
|
* W-1025: the opt-in widget scripts this page needs (a dismissible Alert…). `EmVBPage` loads
|
|
23
23
|
* them itself; set only when there is one.
|
|
24
24
|
*/
|
|
25
|
-
runtimes?:
|
|
25
|
+
runtimes?: PageRuntime[];
|
|
26
26
|
/** The site's text direction when set, for the host's `<html dir>` (W-230). */
|
|
27
27
|
dir?: "ltr" | "rtl" | "auto";
|
|
28
28
|
/** W-971: the element types whose base rules `css` holds, for `sharedPartCss`. */
|
|
29
29
|
baseTypes?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* W-1086: the extensions whose elements rendered. Their stylesheets are not in `css`:
|
|
32
|
+
* `EmVBPage` and the theme parts' `css` write each once per response.
|
|
33
|
+
*/
|
|
34
|
+
extensions?: string[];
|
|
30
35
|
};
|
|
31
36
|
|
|
32
37
|
/** The design document through the in-process public route (no HTTP round trip, D-013). */
|
|
@@ -82,6 +87,11 @@ export function renderStored(
|
|
|
82
87
|
partIds = false,
|
|
83
88
|
/** The page's language, e.g. "fr-CA", for Post Dates (W-688). */
|
|
84
89
|
lang?: string,
|
|
90
|
+
/**
|
|
91
|
+
* W-1088 (#37): a draft preview shows the placeholder for an extension element that can't
|
|
92
|
+
* render; visitors get nothing in its place.
|
|
93
|
+
*/
|
|
94
|
+
extensionPlaceholders = false,
|
|
85
95
|
): RenderedPage {
|
|
86
96
|
const empty: RenderedPage = {
|
|
87
97
|
html: "",
|
|
@@ -109,6 +119,8 @@ export function renderStored(
|
|
|
109
119
|
scope: pageId,
|
|
110
120
|
...(partIds ? { partIds } : {}),
|
|
111
121
|
...(lang ? { lang } : {}),
|
|
122
|
+
...(extensionPlaceholders ? { extensionPlaceholders } : {}),
|
|
123
|
+
separateExtensionCss: true,
|
|
112
124
|
});
|
|
113
125
|
} catch (error) {
|
|
114
126
|
// S-02: a layout that can't render leaves the page empty instead of failing the request.
|
|
@@ -119,8 +131,16 @@ export function renderStored(
|
|
|
119
131
|
});
|
|
120
132
|
return empty;
|
|
121
133
|
}
|
|
122
|
-
const {
|
|
123
|
-
|
|
134
|
+
const {
|
|
135
|
+
html,
|
|
136
|
+
css,
|
|
137
|
+
needsFormsRuntime,
|
|
138
|
+
needsTabsRuntime,
|
|
139
|
+
needsMenuRuntime,
|
|
140
|
+
baseTypes,
|
|
141
|
+
runtimes,
|
|
142
|
+
extensions,
|
|
143
|
+
} = result;
|
|
124
144
|
for (const warning of result.warnings) {
|
|
125
145
|
if (warning.code !== "refused-markup") continue;
|
|
126
146
|
// oxlint-disable-next-line no-console
|
|
@@ -133,6 +153,7 @@ export function renderStored(
|
|
|
133
153
|
needsTabsRuntime,
|
|
134
154
|
needsMenuRuntime,
|
|
135
155
|
...(runtimes.length > 0 ? { runtimes } : {}),
|
|
156
|
+
...(extensions.length > 0 ? { extensions } : {}),
|
|
136
157
|
...(design.direction ? { dir: design.direction } : {}),
|
|
137
158
|
baseTypes,
|
|
138
159
|
};
|
|
@@ -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
|
@@ -202,6 +202,8 @@ export async function resolveEmVBPageWith(
|
|
|
202
202
|
Object.keys(dynamic).length > 0 ? dynamic : undefined,
|
|
203
203
|
false,
|
|
204
204
|
options.lang ?? found.fallbackLocale ?? locale,
|
|
205
|
+
// W-1088 (#37): a draft preview (editors) keeps the missing-extension note.
|
|
206
|
+
Boolean(found.isPreview),
|
|
205
207
|
),
|
|
206
208
|
entry,
|
|
207
209
|
collection: hosted ? (options.collection as string) : PAGES_COLLECTION,
|
package/src/astro/theme-posts.ts
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
clipText,
|
|
3
|
+
entryImageValue,
|
|
4
|
+
loopPermalink,
|
|
5
|
+
mediaUrlOf,
|
|
6
|
+
type ThemePostFields,
|
|
7
|
+
} from "../core/index.ts";
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
alt?: unknown;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/** Pull a sanitized-ready image URL + alt from an EmDash media / image field value. */
|
|
9
|
+
/**
|
|
10
|
+
* Pull a sanitized-ready image URL + alt from an EmDash media / image field value. W-1090 (#32):
|
|
11
|
+
* a local upload picked in EmDash's admin has no `src`, only its storage key.
|
|
12
|
+
*/
|
|
11
13
|
export function mediaFieldsFrom(value: unknown): {
|
|
12
14
|
featuredImageUrl?: string;
|
|
13
15
|
featuredImageAlt?: string;
|
|
14
16
|
} {
|
|
15
17
|
if (!value || typeof value !== "object") return {};
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
for (const candidate of candidates) {
|
|
20
|
-
if (typeof candidate === "string" && candidate.trim()) {
|
|
21
|
-
featuredImageUrl = candidate.trim();
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const featuredImageAlt =
|
|
26
|
-
typeof media.alt === "string" && media.alt.trim() ? media.alt.trim() : undefined;
|
|
27
|
-
return { featuredImageUrl, featuredImageAlt };
|
|
18
|
+
const alt = (value as { alt?: unknown }).alt;
|
|
19
|
+
const featuredImageAlt = typeof alt === "string" && alt.trim() ? alt.trim() : undefined;
|
|
20
|
+
return { featuredImageUrl: mediaUrlOf(value), featuredImageAlt };
|
|
28
21
|
}
|
|
29
22
|
|
|
30
23
|
/**
|
|
@@ -46,7 +39,7 @@ export function themePostFromEntry(
|
|
|
46
39
|
permalinkPrefix?: string;
|
|
47
40
|
/** W-330: a Loop's link pattern, e.g. `/team/{slug}`. */
|
|
48
41
|
permalinkPattern?: string;
|
|
49
|
-
/** W-330: the field with the entry's image, instead of
|
|
42
|
+
/** W-330: the field with the entry's image, instead of the automatic one (W-1090). */
|
|
50
43
|
imageField?: string;
|
|
51
44
|
/** W-330: the field with the entry's excerpt, instead of `excerpt`. */
|
|
52
45
|
excerptField?: string;
|
|
@@ -67,7 +60,8 @@ export function themePostFromEntry(
|
|
|
67
60
|
const permalink = options.permalinkPattern
|
|
68
61
|
? loopPermalink(options.permalinkPattern, { slug: slug || id, id: id || slug })
|
|
69
62
|
: `${prefix.replace(/\/$/, "")}/${slug || id}`;
|
|
70
|
-
|
|
63
|
+
// W-1090 (#32): unset reads featured_image, else the entry's first image field.
|
|
64
|
+
const media = mediaFieldsFrom(entryImageValue(data, options.imageField));
|
|
71
65
|
// W-303: EmDash's own publish date is `data.publishedAt`, a `Date`; a custom field may be text.
|
|
72
66
|
const publishedAt = ["published_at", "publishedAt", "date"]
|
|
73
67
|
.map((key) => entryTimestamp(data[key]))
|
package/src/astro/visitor.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { geoTrust } from "../core/geo-trust.ts";
|
|
2
|
+
import { visitorCookie, visitorCookieAllowed } from "../core/visitor-cookie.ts";
|
|
2
3
|
import {
|
|
3
4
|
AUDIENCE_SEGMENT,
|
|
4
5
|
abCookieName,
|
|
@@ -190,7 +191,8 @@ export function hostVisitorFacts(host: HostVisitor | undefined): Partial<Visitor
|
|
|
190
191
|
|
|
191
192
|
/**
|
|
192
193
|
* What the server knows about this visitor, for visitor-aware elements (W-313): country from
|
|
193
|
-
* the edge, device from the User-Agent, new or returning from a first-party cookie
|
|
194
|
+
* the edge, device from the User-Agent, new or returning from a first-party cookie (when
|
|
195
|
+
* `emvb({ visitorCookie })` allows it, W-1092), and the time.
|
|
194
196
|
* Facts the host passes (W-329) win over detected ones. Only read when the layout has a rule.
|
|
195
197
|
*/
|
|
196
198
|
export function visitorFor(
|
|
@@ -205,13 +207,20 @@ export function visitorFor(
|
|
|
205
207
|
if (country) visitor.country = country;
|
|
206
208
|
const device = deviceFromUserAgent(headers?.get("user-agent"), headers?.get("sec-ch-ua-mobile"));
|
|
207
209
|
if (device) visitor.device = device;
|
|
210
|
+
// W-1092 (#34): only a new/returning rule reads or sets the cookie, and only when
|
|
211
|
+
// `emvb({ visitorCookie })` allows it for this request. Otherwise everyone counts as new.
|
|
208
212
|
if (astro.cookies && layoutUsesVisitorRule(layout)) {
|
|
209
|
-
|
|
210
|
-
|
|
213
|
+
const cookieAllowed = visitorCookieAllowed(visitorCookie(), (name) =>
|
|
214
|
+
requestCookie(astro, name),
|
|
215
|
+
);
|
|
216
|
+
const seen = requestCookie(astro, SEEN_COOKIE);
|
|
217
|
+
visitor.returning = cookieAllowed && seen === "1";
|
|
218
|
+
if (cookieAllowed ? !visitor.returning : seen !== undefined) {
|
|
211
219
|
try {
|
|
212
|
-
|
|
220
|
+
// Without consent (or in "never" mode) a cookie left from before is cleared.
|
|
221
|
+
astro.cookies.set(SEEN_COOKIE, cookieAllowed ? "1" : "", {
|
|
213
222
|
path: "/",
|
|
214
|
-
maxAge: SEEN_DAYS * 86_400,
|
|
223
|
+
maxAge: cookieAllowed ? SEEN_DAYS * 86_400 : 0,
|
|
215
224
|
sameSite: "lax",
|
|
216
225
|
httpOnly: true,
|
|
217
226
|
secure: astro.url.protocol === "https:",
|
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
+
}
|