@perkyzz/emvb 1.2.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 +2 -2
- package/package.json +4 -4
- package/src/admin/editor/canvas/vnode-react.tsx +3 -0
- package/src/admin/editor/dnd/new-element.ts +60 -0
- package/src/admin/editor/element-chrome.ts +28 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +33 -0
- package/src/astro/request-data.ts +6 -0
- 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/EmVBWidgetRuntimes.astro +10 -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/map.ts +37 -0
- package/src/astro/widgets/share.ts +21 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +28 -5
- package/src/core/arrange.ts +52 -0
- package/src/core/canvas-collections.ts +28 -0
- package/src/core/elements/counter-format.ts +15 -0
- package/src/core/elements/index.ts +30 -0
- package/src/core/elements/marketing.ts +1490 -0
- package/src/core/elements/widgets.ts +28 -3
- package/src/core/export/runtimes.generated.ts +5 -0
- package/src/core/export/site.ts +5 -0
- package/src/core/import/elementor/widgets.ts +418 -281
- package/src/core/limits.ts +6 -0
- package/src/core/render/index.ts +21 -1
- package/src/core/render/vnode.ts +1 -1
- package/src/core/schema/layout.ts +420 -17
- package/src/core/theme/dynamic.ts +2 -0
- package/src/server/plugin.ts +2 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1041: the opt-in Map runtime. It shows each Map's "Show the map" button (hidden by CSS until
|
|
3
|
+
* this script marks the Map ready) and, only when it is pressed, replaces it with the map in an
|
|
4
|
+
* iframe, so nothing is fetched from the map service before the visitor asks.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const ALLOWED = /^https:\/\/www\.(?:openstreetmap\.org\/export\/embed\.html|google\.com\/maps)\?/;
|
|
8
|
+
|
|
9
|
+
function load(frame: HTMLElement): void {
|
|
10
|
+
const src = frame.dataset["src"] ?? "";
|
|
11
|
+
if (!ALLOWED.test(src)) return;
|
|
12
|
+
// oxlint-disable-next-line react/iframe-missing-sandbox -- set just below, before it loads
|
|
13
|
+
const iframe = frame.ownerDocument.createElement("iframe");
|
|
14
|
+
// Map pages need their own scripts; they stay in their own origin and may open links.
|
|
15
|
+
iframe.setAttribute(
|
|
16
|
+
"sandbox",
|
|
17
|
+
"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox",
|
|
18
|
+
);
|
|
19
|
+
iframe.src = src;
|
|
20
|
+
iframe.title = frame.dataset["title"] || "Map";
|
|
21
|
+
iframe.height = frame.dataset["height"] || "360";
|
|
22
|
+
iframe.loading = "lazy";
|
|
23
|
+
iframe.referrerPolicy = "no-referrer-when-downgrade";
|
|
24
|
+
frame.replaceChildren(iframe);
|
|
25
|
+
iframe.focus();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function initMaps(root: ParentNode = document): void {
|
|
29
|
+
for (const map of root.querySelectorAll<HTMLElement>("[data-emvb-map]")) {
|
|
30
|
+
if (map.dataset["emvbReady"] !== undefined) continue;
|
|
31
|
+
const frame = map.querySelector<HTMLElement>(".emvb-map-frame");
|
|
32
|
+
const button = frame?.querySelector<HTMLButtonElement>(".emvb-map-load");
|
|
33
|
+
if (!frame || !button) continue;
|
|
34
|
+
map.dataset["emvbReady"] = "";
|
|
35
|
+
button.addEventListener("click", () => load(frame));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1047: the opt-in Share runtime. Where the browser has its own share sheet
|
|
3
|
+
* (`navigator.share`), it shows each Share buttons element's Share button (hidden by CSS until
|
|
4
|
+
* then) and opens the sheet for this page when it is pressed. Elsewhere nothing changes: the
|
|
5
|
+
* plain share links stay.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function initShare(root: ParentNode = document): void {
|
|
9
|
+
const nav = globalThis.navigator as Navigator | undefined;
|
|
10
|
+
if (typeof nav?.share !== "function") return;
|
|
11
|
+
for (const list of root.querySelectorAll<HTMLElement>("[data-emvb-share-list]")) {
|
|
12
|
+
if (list.dataset["emvbReady"] !== undefined) continue;
|
|
13
|
+
list.dataset["emvbReady"] = "";
|
|
14
|
+
const button = list.querySelector<HTMLButtonElement>("[data-emvb-share]");
|
|
15
|
+
button?.addEventListener("click", () => {
|
|
16
|
+
const doc = list.ownerDocument;
|
|
17
|
+
// A visitor closing the sheet rejects the promise; there is nothing to report.
|
|
18
|
+
nav.share({ title: doc.title, url: doc.location.href.split("#")[0] }).catch(() => {});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/constants.ts
CHANGED
package/src/core/a11y/audit.ts
CHANGED
|
@@ -45,7 +45,8 @@ export type A11yIssue = {
|
|
|
45
45
|
| "empty-heading"
|
|
46
46
|
| "landmark-name"
|
|
47
47
|
| "motion"
|
|
48
|
-
| "empty-alert"
|
|
48
|
+
| "empty-alert"
|
|
49
|
+
| "counter-title";
|
|
49
50
|
severity: "error" | "warning";
|
|
50
51
|
message: string;
|
|
51
52
|
/** The one-click fix, when there is a safe one. */
|
|
@@ -150,7 +151,8 @@ function px(value: unknown, design?: DesignSystem): number | undefined {
|
|
|
150
151
|
const HEADING_PX = [32, 24, 18.72, 16, 13.28, 10.72];
|
|
151
152
|
|
|
152
153
|
const headingLevel = (node: LayoutNode): number | undefined => {
|
|
153
|
-
|
|
154
|
+
// W-1046: an Animated headline is a heading too.
|
|
155
|
+
if (node.type !== "heading" && node.type !== "headline") return undefined;
|
|
154
156
|
const level = (node.props as { level?: unknown }).level;
|
|
155
157
|
return typeof level === "number" && level >= 1 && level <= 6 ? level : 2;
|
|
156
158
|
};
|
|
@@ -309,7 +311,8 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
309
311
|
} else if (
|
|
310
312
|
// W-1021: an image box's picture needs real alt text as an Image does, once it has one.
|
|
311
313
|
(node.type === "image" ||
|
|
312
|
-
((node.type === "image-box" || node.type === "gallery-image"
|
|
314
|
+
((node.type === "image-box" || node.type === "gallery-image" || node.type === "hotspots") &&
|
|
315
|
+
spoken(props["src"]))) &&
|
|
313
316
|
props["decorative"] !== true
|
|
314
317
|
) {
|
|
315
318
|
const alt = typeof props["alt"] === "string" ? spoken(props["alt"]) : "";
|
|
@@ -558,6 +561,26 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
558
561
|
message: "This alert has no title or text, so it shows an empty box and says nothing.",
|
|
559
562
|
});
|
|
560
563
|
}
|
|
564
|
+
// W-1039: a bar without a title is a meter screen readers can't name.
|
|
565
|
+
if (node.type === "progress" && !spoken(props["label"]) && !node.bind) {
|
|
566
|
+
add({
|
|
567
|
+
nodeId: node.id,
|
|
568
|
+
rule: "control-name",
|
|
569
|
+
severity: "warning",
|
|
570
|
+
message:
|
|
571
|
+
'This progress bar has no title, so screen readers can\'t say what it measures. Add a title such as "Design".',
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
// W-1038: a Counter's number alone ("1,200+") doesn't say what was counted.
|
|
575
|
+
if (node.type === "counter" && !spoken(props["title"]) && !node.bind) {
|
|
576
|
+
add({
|
|
577
|
+
nodeId: node.id,
|
|
578
|
+
rule: "counter-title",
|
|
579
|
+
severity: "warning",
|
|
580
|
+
message:
|
|
581
|
+
'This counter has no title, so its number doesn\'t say what it counts. Add a title such as "Happy clients".',
|
|
582
|
+
});
|
|
583
|
+
}
|
|
561
584
|
// W-419: an empty heading still shows up in screen readers' heading list, with nothing to say.
|
|
562
585
|
if (node.type === "heading" && !spoken(props["text"]) && !node.bind) {
|
|
563
586
|
add({
|
|
@@ -567,7 +590,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
567
590
|
message: "This heading is empty; screen readers list it as a heading with no words.",
|
|
568
591
|
});
|
|
569
592
|
}
|
|
570
|
-
if (node.type === "heading") {
|
|
593
|
+
if (node.type === "heading" || node.type === "headline") {
|
|
571
594
|
const level = typeof props["level"] === "number" ? props["level"] : 2;
|
|
572
595
|
if (level === 1) {
|
|
573
596
|
h1s = h1s.map((count, i) => count + (shownOn[i] ? 1 : 0));
|
|
@@ -743,7 +766,7 @@ export function applyAllA11yFixes(layout: Layout, issues: A11yIssue[]): Layout {
|
|
|
743
766
|
const levels = new Map<string, number>();
|
|
744
767
|
let last = 0;
|
|
745
768
|
const walk = (node: LayoutNode) => {
|
|
746
|
-
if (node.type === "heading") {
|
|
769
|
+
if (node.type === "heading" || node.type === "headline") {
|
|
747
770
|
const own = typeof node.props["level"] === "number" ? node.props["level"] : 2;
|
|
748
771
|
const level = order.has(node.id) ? Math.min(own, Math.max(2, last + 1)) : own;
|
|
749
772
|
if (level !== own) levels.set(node.id, level);
|
package/src/core/arrange.ts
CHANGED
|
@@ -3,6 +3,9 @@ import {
|
|
|
3
3
|
MAX_DEPTH,
|
|
4
4
|
MAX_GALLERY_IMAGES,
|
|
5
5
|
MAX_NODES,
|
|
6
|
+
MAX_HOTSPOTS,
|
|
7
|
+
MAX_PRICE_ITEMS,
|
|
8
|
+
MAX_SHARE_LINKS,
|
|
6
9
|
MAX_SOCIAL_LINKS,
|
|
7
10
|
MAX_TABS,
|
|
8
11
|
} from "./limits.ts";
|
|
@@ -80,6 +83,15 @@ export const REASONS = {
|
|
|
80
83
|
slideOutsideCarousel: "Slides can only go inside a Carousel.",
|
|
81
84
|
onlySlides: "A carousel can only hold slides.",
|
|
82
85
|
tooManySlides: `A carousel can hold up to ${MAX_CAROUSEL_SLIDES} slides.`,
|
|
86
|
+
itemOutsidePriceList: "Price list items can only go inside a Price list.",
|
|
87
|
+
onlyPriceItems: "A price list can only hold price list items.",
|
|
88
|
+
tooManyPriceItems: `A price list can hold up to ${MAX_PRICE_ITEMS} items.`,
|
|
89
|
+
shareOutsideButtons: "Share links can only go inside Share buttons.",
|
|
90
|
+
onlyShareLinks: "Share buttons can only hold share links.",
|
|
91
|
+
tooManyShareLinks: `Share buttons can hold up to ${MAX_SHARE_LINKS} links.`,
|
|
92
|
+
hotspotOutsidePicture: "Hotspots can only go inside a Hotspots picture.",
|
|
93
|
+
onlyHotspots: "A Hotspots picture can only hold hotspots.",
|
|
94
|
+
tooManyHotspots: `A Hotspots picture can hold up to ${MAX_HOTSPOTS} markers.`,
|
|
83
95
|
emptyOutsideLoop: "An Empty state can only go inside a Loop.",
|
|
84
96
|
} as const;
|
|
85
97
|
|
|
@@ -175,6 +187,22 @@ export function parentChildRefusal(
|
|
|
175
187
|
return REASONS.slideOutsideCarousel;
|
|
176
188
|
}
|
|
177
189
|
if (parent.type === "carousel" && child.type !== "carousel-slide") return REASONS.onlySlides;
|
|
190
|
+
if (child.type === "price-list-item" && parent.type !== "price-list") {
|
|
191
|
+
return REASONS.itemOutsidePriceList;
|
|
192
|
+
}
|
|
193
|
+
if (parent.type === "price-list" && child.type !== "price-list-item") {
|
|
194
|
+
return REASONS.onlyPriceItems;
|
|
195
|
+
}
|
|
196
|
+
if (child.type === "share-link" && parent.type !== "share-buttons") {
|
|
197
|
+
return REASONS.shareOutsideButtons;
|
|
198
|
+
}
|
|
199
|
+
if (parent.type === "share-buttons" && child.type !== "share-link") {
|
|
200
|
+
return REASONS.onlyShareLinks;
|
|
201
|
+
}
|
|
202
|
+
if (child.type === "hotspot" && parent.type !== "hotspots") {
|
|
203
|
+
return REASONS.hotspotOutsidePicture;
|
|
204
|
+
}
|
|
205
|
+
if (parent.type === "hotspots" && child.type !== "hotspot") return REASONS.onlyHotspots;
|
|
178
206
|
if (isFormNode(child) && inForm) return REASONS.nestedForm;
|
|
179
207
|
if (isFormFieldType(child.type) && !inForm) return REASONS.fieldOutsideForm;
|
|
180
208
|
return undefined;
|
|
@@ -215,6 +243,30 @@ const DROP_RULES: [breaks: (drop: Drop) => boolean, reason: string][] = [
|
|
|
215
243
|
nodeChildren(into.node).length >= MAX_CAROUSEL_SLIDES,
|
|
216
244
|
REASONS.tooManySlides,
|
|
217
245
|
],
|
|
246
|
+
// W-1043: a full Price list takes no new item; moving within it is fine.
|
|
247
|
+
[
|
|
248
|
+
({ node, into }) =>
|
|
249
|
+
into.node.type === "price-list" &&
|
|
250
|
+
!nodeChildren(into.node).some((child) => child.id === node.id) &&
|
|
251
|
+
nodeChildren(into.node).length >= MAX_PRICE_ITEMS,
|
|
252
|
+
REASONS.tooManyPriceItems,
|
|
253
|
+
],
|
|
254
|
+
// W-1047: a full Share buttons takes no new link; moving within it is fine.
|
|
255
|
+
[
|
|
256
|
+
({ node, into }) =>
|
|
257
|
+
into.node.type === "share-buttons" &&
|
|
258
|
+
!nodeChildren(into.node).some((child) => child.id === node.id) &&
|
|
259
|
+
nodeChildren(into.node).length >= MAX_SHARE_LINKS,
|
|
260
|
+
REASONS.tooManyShareLinks,
|
|
261
|
+
],
|
|
262
|
+
// W-1048: a full Hotspots picture takes no new marker; moving within it is fine.
|
|
263
|
+
[
|
|
264
|
+
({ node, into }) =>
|
|
265
|
+
into.node.type === "hotspots" &&
|
|
266
|
+
!nodeChildren(into.node).some((child) => child.id === node.id) &&
|
|
267
|
+
nodeChildren(into.node).length >= MAX_HOTSPOTS,
|
|
268
|
+
REASONS.tooManyHotspots,
|
|
269
|
+
],
|
|
218
270
|
[({ node, into }) => into.depth + height(node) > MAX_DEPTH, REASONS.tooDeep],
|
|
219
271
|
[
|
|
220
272
|
({ node, layout, isNew }) => isNew && size(layout.root) + size(node) > MAX_NODES,
|
|
@@ -18,3 +18,31 @@ export function canvasCollectionSlugs(input: unknown): string[] {
|
|
|
18
18
|
}
|
|
19
19
|
return out;
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* W-1036 (S-08, render side): the running site's list, set when the plugin starts and read when
|
|
24
|
+
* `resolveEmVBPage` renders a host collection. Kept on globalThis like core/geo-trust.ts. Unset
|
|
25
|
+
* (the plugin never started in this process, as in unit tests) means "unknown", never "unlisted".
|
|
26
|
+
*/
|
|
27
|
+
const KEY = Symbol.for("emvb.canvasCollections");
|
|
28
|
+
const WARNED = Symbol.for("emvb.canvasCollectionsWarned");
|
|
29
|
+
|
|
30
|
+
type Holder = { [KEY]?: readonly string[]; [WARNED]?: Set<string> };
|
|
31
|
+
|
|
32
|
+
export function setCanvasCollections(input: unknown): void {
|
|
33
|
+
(globalThis as Holder)[KEY] = canvasCollectionSlugs(input);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* True the first time a layout from `collection` renders while the site's `canvasCollections`
|
|
38
|
+
* leaves it out: the caller logs one warning per collection and process (1.3; 2.0 refuses).
|
|
39
|
+
*/
|
|
40
|
+
export function unlistedCanvasCollectionFirstSeen(collection: string): boolean {
|
|
41
|
+
const holder = globalThis as Holder;
|
|
42
|
+
const listed = holder[KEY];
|
|
43
|
+
if (listed === undefined || listed.includes(collection) || OWN.has(collection)) return false;
|
|
44
|
+
const warned = (holder[WARNED] ??= new Set());
|
|
45
|
+
if (warned.has(collection)) return false;
|
|
46
|
+
warned.add(collection);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1038: how a Counter writes its number. Shared by the renderer and the opt-in counter runtime,
|
|
3
|
+
* so the count-up ends on exactly the text the page was rendered with.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** `value` with `decimals` digits after a "." and `separator` between thousands. */
|
|
7
|
+
export function formatCounter(value: number, decimals = 0, separator = ""): string {
|
|
8
|
+
const fixed = Math.abs(value).toFixed(decimals);
|
|
9
|
+
const [whole = "0", fraction] = fixed.split(".");
|
|
10
|
+
const grouped = separator ? whole.replace(/\B(?=(\d{3})+(?!\d))/g, separator) : whole;
|
|
11
|
+
// With "." between thousands, the decimal mark is ",", as people write it.
|
|
12
|
+
const mark = separator === "." ? "," : ".";
|
|
13
|
+
const sign = value < 0 && Number(fixed) !== 0 ? "-" : "";
|
|
14
|
+
return `${sign}${grouped}${fraction === undefined ? "" : `${mark}${fraction}`}`;
|
|
15
|
+
}
|
|
@@ -39,6 +39,22 @@ import type { ElementDefinition } from "./definition.ts";
|
|
|
39
39
|
import { ICON_STROKE_WIDTHS, iconGlyph } from "./icon-svg.ts";
|
|
40
40
|
export { iconHasAdjustableStroke, iconHasOwnColors } from "./icon-svg.ts";
|
|
41
41
|
import { menu, menuItem } from "./menu.ts";
|
|
42
|
+
import {
|
|
43
|
+
countdown,
|
|
44
|
+
counter,
|
|
45
|
+
cta,
|
|
46
|
+
flipBox,
|
|
47
|
+
headline,
|
|
48
|
+
map,
|
|
49
|
+
priceList,
|
|
50
|
+
priceListItem,
|
|
51
|
+
priceTable,
|
|
52
|
+
hotspot,
|
|
53
|
+
hotspots,
|
|
54
|
+
progress,
|
|
55
|
+
shareButtons,
|
|
56
|
+
shareLink,
|
|
57
|
+
} from "./marketing.ts";
|
|
42
58
|
import {
|
|
43
59
|
alert,
|
|
44
60
|
carousel,
|
|
@@ -1124,6 +1140,20 @@ export const ELEMENTS = {
|
|
|
1124
1140
|
"gallery-image": galleryImage,
|
|
1125
1141
|
carousel,
|
|
1126
1142
|
"carousel-slide": carouselSlide,
|
|
1143
|
+
counter,
|
|
1144
|
+
progress,
|
|
1145
|
+
countdown,
|
|
1146
|
+
map,
|
|
1147
|
+
"price-table": priceTable,
|
|
1148
|
+
"price-list": priceList,
|
|
1149
|
+
"price-list-item": priceListItem,
|
|
1150
|
+
cta,
|
|
1151
|
+
"flip-box": flipBox,
|
|
1152
|
+
headline,
|
|
1153
|
+
"share-buttons": shareButtons,
|
|
1154
|
+
"share-link": shareLink,
|
|
1155
|
+
hotspots,
|
|
1156
|
+
hotspot,
|
|
1127
1157
|
container,
|
|
1128
1158
|
"layout-section": layoutSection,
|
|
1129
1159
|
spacer,
|