@perkyzz/emvb 1.1.0 → 1.2.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 +1 -0
- package/package.json +10 -9
- 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/dnd/new-element.ts +46 -0
- package/src/admin/editor/editor-chrome.tsx +9 -0
- package/src/admin/editor/element-chrome.ts +22 -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 +36 -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 +3 -0
- package/src/astro/resolve-theme.ts +77 -44
- 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/EmVBLightboxRuntime.astro +8 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
- package/src/astro/widgets/alerts.ts +37 -0
- package/src/astro/widgets/carousel.ts +167 -0
- package/src/astro/widgets/index.ts +1 -0
- package/src/astro/widgets/lightbox.ts +123 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +101 -2
- package/src/core/arrange.ts +57 -1
- package/src/core/bounded-array.ts +16 -13
- package/src/core/contract.ts +4 -1
- package/src/core/elements/icon-svg.ts +135 -0
- package/src/core/elements/index.ts +33 -127
- package/src/core/elements/widgets.ts +907 -0
- package/src/core/export/runtimes.generated.ts +3 -0
- package/src/core/export/site.ts +20 -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 +394 -133
- package/src/core/issue-cap.ts +19 -0
- package/src/core/limits.ts +6 -0
- package/src/core/loop-collections.ts +33 -0
- package/src/core/proposals.ts +8 -2
- package/src/core/render/index.ts +27 -4
- 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 +395 -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/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 +27 -2
- 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
|
@@ -0,0 +1,907 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The 1.2 widgets: elements built from plain markup and CSS. Each one renders
|
|
3
|
+
* without script; the few interactive extras are opt-in runtimes.
|
|
4
|
+
*/
|
|
5
|
+
import type {
|
|
6
|
+
AlertNode,
|
|
7
|
+
IconBoxNode,
|
|
8
|
+
ImageBoxNode,
|
|
9
|
+
LayoutNode,
|
|
10
|
+
RatingNode,
|
|
11
|
+
CarouselNode,
|
|
12
|
+
CarouselSlideNode,
|
|
13
|
+
GalleryImageNode,
|
|
14
|
+
GalleryNode,
|
|
15
|
+
SocialIconsNode,
|
|
16
|
+
SocialLinkNode,
|
|
17
|
+
TestimonialNode,
|
|
18
|
+
} from "../schema/layout.ts";
|
|
19
|
+
import {
|
|
20
|
+
ALERT_VARIANTS,
|
|
21
|
+
MAX_RATING,
|
|
22
|
+
type MEDIA_BOX_POSITIONS,
|
|
23
|
+
SOCIAL_NETWORKS,
|
|
24
|
+
} from "../schema/layout.ts";
|
|
25
|
+
import { SOCIAL_ICONS } from "../icons/social.generated.ts";
|
|
26
|
+
import { sanitizeSvgMarkup } from "../sanitize/svg.ts";
|
|
27
|
+
import { sanitizeHref } from "../sanitize/href.ts";
|
|
28
|
+
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
29
|
+
import { iconGlyph } from "./icon-svg.ts";
|
|
30
|
+
import type { VNode } from "../render/vnode.ts";
|
|
31
|
+
import type { ElementDefinition } from "./definition.ts";
|
|
32
|
+
|
|
33
|
+
/** Star outline on a 24 × 24 grid. */
|
|
34
|
+
const STAR =
|
|
35
|
+
"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26";
|
|
36
|
+
|
|
37
|
+
/** A number as people write it: 4.5, 4, 0.3 (at most one decimal). */
|
|
38
|
+
const ratingNumber = (value: number) => String(Math.round(value * 10) / 10);
|
|
39
|
+
|
|
40
|
+
/** W-1023: what screen readers hear for a Rating. */
|
|
41
|
+
function ratingLabel(props: RatingNode["props"]): string {
|
|
42
|
+
const max = props.max ?? 5;
|
|
43
|
+
const value = ratingNumber(Math.min(Math.max(props.value, 0), max));
|
|
44
|
+
const template = props.label?.trim() || "Rated {value} out of {max}";
|
|
45
|
+
return template.replaceAll("{value}", value).replaceAll("{max}", String(max));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* One star filled to `fraction` (0 to 1): an empty star with the filled part over it. The filled
|
|
50
|
+
* part is the same star cut by its viewBox, so a half star needs no ids, masks or styles.
|
|
51
|
+
*/
|
|
52
|
+
function star(size: number, fraction: number): VNode {
|
|
53
|
+
const svg = (className: string, part: number, extra: Record<string, string>): VNode => ({
|
|
54
|
+
tag: "svg",
|
|
55
|
+
attrs: {
|
|
56
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
57
|
+
class: className,
|
|
58
|
+
width: String(Math.round(size * part * 100) / 100),
|
|
59
|
+
height: String(size),
|
|
60
|
+
viewBox: `0 0 ${Math.round(24 * part * 1000) / 1000} 24`,
|
|
61
|
+
fill: "currentColor",
|
|
62
|
+
"aria-hidden": "true",
|
|
63
|
+
focusable: "false",
|
|
64
|
+
...extra,
|
|
65
|
+
},
|
|
66
|
+
children: [{ tag: "polygon", attrs: { points: STAR }, children: [] }],
|
|
67
|
+
});
|
|
68
|
+
const parts: VNode[] = [svg("emvb-rating-empty", 1, { "fill-opacity": "0.25" })];
|
|
69
|
+
if (fraction > 0) parts.push(svg("emvb-rating-fill", fraction, {}));
|
|
70
|
+
return { tag: "span", attrs: { class: "emvb-rating-star" }, children: parts };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const rating: ElementDefinition<RatingNode> = {
|
|
74
|
+
baseCss:
|
|
75
|
+
".emvb-rating{display:inline-flex;gap:0.125em;line-height:0;color:inherit}.emvb-rating-star{position:relative;display:inline-block}.emvb-rating-star svg{display:block}.emvb-rating-fill{position:absolute;top:0;left:0}[dir=rtl] .emvb-rating-fill,.emvb-rating[dir=rtl] .emvb-rating-fill{left:auto;right:0;transform:scaleX(-1)}",
|
|
76
|
+
defaults: () => ({ type: "rating", props: { value: 4.5, max: 5 } }),
|
|
77
|
+
descriptor: {
|
|
78
|
+
type: "rating",
|
|
79
|
+
name: "Star rating",
|
|
80
|
+
group: "content",
|
|
81
|
+
defaultTab: "content",
|
|
82
|
+
fields: [
|
|
83
|
+
{
|
|
84
|
+
key: "value",
|
|
85
|
+
kind: "decimal",
|
|
86
|
+
label: "Rating",
|
|
87
|
+
min: 0,
|
|
88
|
+
max: 5,
|
|
89
|
+
maxProp: "max",
|
|
90
|
+
message: "Enter a number from 0 up to the number of stars, such as 4.5.",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "max",
|
|
94
|
+
kind: "int",
|
|
95
|
+
label: "Stars",
|
|
96
|
+
optional: true,
|
|
97
|
+
max: MAX_RATING,
|
|
98
|
+
message: `From 1 to ${MAX_RATING} stars.`,
|
|
99
|
+
},
|
|
100
|
+
{ key: "size", kind: "int", label: "Star size (px)", optional: true, min: 8, max: 128 },
|
|
101
|
+
{ key: "label", kind: "text", label: "Text for screen readers", optional: true },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
build: (node, attrs) => ratingStars(node.props, attrs),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** The stars of a rating as one named image (W-1023; a Testimonial's rating too, W-1022). */
|
|
108
|
+
function ratingStars(props: RatingNode["props"], attrs: Record<string, string>): VNode {
|
|
109
|
+
const max = props.max ?? 5;
|
|
110
|
+
const value = Math.min(Math.max(props.value, 0), max);
|
|
111
|
+
const size = props.size ?? 20;
|
|
112
|
+
const stars = Array.from({ length: max }, (_, i) =>
|
|
113
|
+
star(size, Math.min(Math.max(value - i, 0), 1)),
|
|
114
|
+
);
|
|
115
|
+
return {
|
|
116
|
+
tag: "div",
|
|
117
|
+
attrs: { ...attrs, role: "img", "aria-label": ratingLabel(props) },
|
|
118
|
+
children: stars,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** W-1025: the opt-in public scripts the 1.2 widgets use; a page loads only the ones it needs. */
|
|
123
|
+
export type WidgetRuntime = "alerts" | "carousel" | "lightbox";
|
|
124
|
+
|
|
125
|
+
/** The widget runtime one element needs, if any: only when it opts in. */
|
|
126
|
+
export function nodeRuntime(node: LayoutNode): WidgetRuntime | undefined {
|
|
127
|
+
if (node.type === "alert" && (node as AlertNode).props.dismissible) return "alerts";
|
|
128
|
+
if (node.type === "gallery" && (node as GalleryNode).props.lightbox) return "lightbox";
|
|
129
|
+
if (node.type === "carousel") {
|
|
130
|
+
const { arrows, dots, autoplay } = (node as CarouselNode).props;
|
|
131
|
+
if (arrows || dots || autoplay) return "carousel";
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const ALERT_LABELS: Record<AlertNode["props"]["variant"], string> = {
|
|
137
|
+
info: "Information",
|
|
138
|
+
success: "Success",
|
|
139
|
+
warning: "Warning",
|
|
140
|
+
danger: "Danger",
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/** Icon outlines on a 24 × 24 grid (stroke), one per variant. */
|
|
144
|
+
const ALERT_ICONS: Record<AlertNode["props"]["variant"], VNode[]> = {
|
|
145
|
+
info: [
|
|
146
|
+
{ tag: "circle", attrs: { cx: "12", cy: "12", r: "10" }, children: [] },
|
|
147
|
+
{ tag: "path", attrs: { d: "M12 16v-4M12 8h.01" }, children: [] },
|
|
148
|
+
],
|
|
149
|
+
success: [
|
|
150
|
+
{ tag: "circle", attrs: { cx: "12", cy: "12", r: "10" }, children: [] },
|
|
151
|
+
{ tag: "path", attrs: { d: "m9 12 2 2 4-4" }, children: [] },
|
|
152
|
+
],
|
|
153
|
+
warning: [
|
|
154
|
+
{
|
|
155
|
+
tag: "path",
|
|
156
|
+
attrs: { d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" },
|
|
157
|
+
children: [],
|
|
158
|
+
},
|
|
159
|
+
{ tag: "path", attrs: { d: "M12 9v4M12 17h.01" }, children: [] },
|
|
160
|
+
],
|
|
161
|
+
danger: [
|
|
162
|
+
{ tag: "circle", attrs: { cx: "12", cy: "12", r: "10" }, children: [] },
|
|
163
|
+
{ tag: "path", attrs: { d: "m15 9-6 6M9 9l6 6" }, children: [] },
|
|
164
|
+
],
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const strokeSvg = (className: string, size: number, children: VNode[]): VNode => ({
|
|
168
|
+
tag: "svg",
|
|
169
|
+
attrs: {
|
|
170
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
171
|
+
class: className,
|
|
172
|
+
width: String(size),
|
|
173
|
+
height: String(size),
|
|
174
|
+
viewBox: "0 0 24 24",
|
|
175
|
+
fill: "none",
|
|
176
|
+
stroke: "currentColor",
|
|
177
|
+
"stroke-width": "2",
|
|
178
|
+
"stroke-linecap": "round",
|
|
179
|
+
"stroke-linejoin": "round",
|
|
180
|
+
"aria-hidden": "true",
|
|
181
|
+
focusable: "false",
|
|
182
|
+
},
|
|
183
|
+
children,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
/** Text colour, background and border per variant; every pair is at least 7:1. */
|
|
187
|
+
const ALERT_COLORS: Record<AlertNode["props"]["variant"], [string, string, string]> = {
|
|
188
|
+
info: ["#0b3d75", "#eaf2fd", "#b6d3f5"],
|
|
189
|
+
success: ["#14532d", "#e9f7ef", "#b7e4c7"],
|
|
190
|
+
warning: ["#5c3b00", "#fff7e0", "#f5d48a"],
|
|
191
|
+
danger: ["#7f1d1d", "#fdecec", "#f5b5b5"],
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export const alert: ElementDefinition<AlertNode> = {
|
|
195
|
+
baseCss:
|
|
196
|
+
".emvb-alert{display:flex;gap:0.75em;align-items:flex-start;padding:0.875em 1em;border:1px solid;border-radius:6px}.emvb-alert[hidden]{display:none}.emvb-alert-icon{flex:none;margin-top:0.125em}.emvb-alert-body{flex:1;min-width:0}.emvb-alert-title{margin:0 0 0.25em;font-weight:600}.emvb-alert-text{margin:0;white-space:pre-line}.emvb-alert-dismiss{flex:none;display:inline-flex;margin:-0.25em -0.25em 0 0;padding:0.25em;border:0;border-radius:4px;background:none;color:inherit;cursor:pointer}.emvb-alert-dismiss:not([data-emvb-ready]){display:none}.emvb-alert-dismiss:focus-visible{outline:2px solid currentColor;outline-offset:2px}" +
|
|
197
|
+
ALERT_VARIANTS.map((variant) => {
|
|
198
|
+
const [color, background, border] = ALERT_COLORS[variant];
|
|
199
|
+
return `.emvb-alert-${variant}{color:${color};background-color:${background};border-color:${border}}`;
|
|
200
|
+
}).join(""),
|
|
201
|
+
defaults: () => ({
|
|
202
|
+
type: "alert",
|
|
203
|
+
props: { variant: "info", title: "Heads up", text: "Something your visitors should know." },
|
|
204
|
+
}),
|
|
205
|
+
descriptor: {
|
|
206
|
+
type: "alert",
|
|
207
|
+
name: "Alert",
|
|
208
|
+
group: "content",
|
|
209
|
+
defaultTab: "content",
|
|
210
|
+
fields: [
|
|
211
|
+
{
|
|
212
|
+
key: "variant",
|
|
213
|
+
kind: "select",
|
|
214
|
+
label: "Kind",
|
|
215
|
+
options: ALERT_VARIANTS.map((value) => ({ value, label: ALERT_LABELS[value] })),
|
|
216
|
+
},
|
|
217
|
+
{ key: "title", kind: "text", label: "Title", optional: true },
|
|
218
|
+
{ key: "text", kind: "textarea", label: "Text" },
|
|
219
|
+
{ key: "hideIcon", kind: "boolean", label: "Hide the icon", optional: true },
|
|
220
|
+
{ key: "dismissible", kind: "boolean", label: "Visitors can dismiss it", optional: true },
|
|
221
|
+
{
|
|
222
|
+
key: "dismissLabel",
|
|
223
|
+
kind: "text",
|
|
224
|
+
label: "Dismiss button name",
|
|
225
|
+
optional: true,
|
|
226
|
+
message: "What screen readers call the close button. Leave it empty for Dismiss.",
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
},
|
|
230
|
+
build: (node, attrs) => {
|
|
231
|
+
const { variant, title, text, hideIcon, dismissible, dismissLabel } = node.props;
|
|
232
|
+
const body: VNode[] = [];
|
|
233
|
+
if (title?.trim())
|
|
234
|
+
body.push({ tag: "p", attrs: { class: "emvb-alert-title" }, children: [title] });
|
|
235
|
+
if (text.trim()) body.push({ tag: "p", attrs: { class: "emvb-alert-text" }, children: [text] });
|
|
236
|
+
const children: (VNode | string)[] = [];
|
|
237
|
+
if (!hideIcon) children.push(strokeSvg("emvb-alert-icon", 20, ALERT_ICONS[variant]));
|
|
238
|
+
children.push({ tag: "div", attrs: { class: "emvb-alert-body" }, children: body });
|
|
239
|
+
if (dismissible) {
|
|
240
|
+
children.push({
|
|
241
|
+
tag: "button",
|
|
242
|
+
attrs: {
|
|
243
|
+
type: "button",
|
|
244
|
+
class: "emvb-alert-dismiss",
|
|
245
|
+
"data-emvb-alert-dismiss": "",
|
|
246
|
+
"aria-label": dismissLabel?.trim() || "Dismiss",
|
|
247
|
+
},
|
|
248
|
+
children: [
|
|
249
|
+
strokeSvg("emvb-alert-close", 16, [
|
|
250
|
+
{ tag: "path", attrs: { d: "M18 6 6 18M6 6l12 12" }, children: [] },
|
|
251
|
+
]),
|
|
252
|
+
],
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
tag: "div",
|
|
257
|
+
attrs: {
|
|
258
|
+
...attrs,
|
|
259
|
+
class: `${attrs["class"] ?? ""} emvb-alert-${variant}`.trim(),
|
|
260
|
+
role: "note",
|
|
261
|
+
},
|
|
262
|
+
children,
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
type MediaBoxProps = {
|
|
268
|
+
title: string;
|
|
269
|
+
titleLevel?: number | undefined;
|
|
270
|
+
text: string;
|
|
271
|
+
position?: (typeof MEDIA_BOX_POSITIONS)[number] | undefined;
|
|
272
|
+
href?: string | undefined;
|
|
273
|
+
newTab?: boolean | undefined;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* W-1020 / W-1021: the shared layout of an icon box and an image box: the media, then a heading
|
|
278
|
+
* and text. With a safe link the title is the one link, stretched over the box so the whole box
|
|
279
|
+
* is clickable while screen readers hear a single named link.
|
|
280
|
+
*/
|
|
281
|
+
function mediaBox(
|
|
282
|
+
props: MediaBoxProps,
|
|
283
|
+
attrs: Record<string, string>,
|
|
284
|
+
media: VNode | undefined,
|
|
285
|
+
): VNode {
|
|
286
|
+
const position = props.position ?? "top";
|
|
287
|
+
const safe = props.href?.trim() ? sanitizeHref(props.href) : undefined;
|
|
288
|
+
const title = props.title.trim()
|
|
289
|
+
? safe
|
|
290
|
+
? {
|
|
291
|
+
tag: "a",
|
|
292
|
+
attrs: {
|
|
293
|
+
class: "emvb-media-box-link",
|
|
294
|
+
href: safe,
|
|
295
|
+
...(props.newTab ? { target: "_blank", rel: "noopener noreferrer" } : {}),
|
|
296
|
+
},
|
|
297
|
+
children: [props.title],
|
|
298
|
+
}
|
|
299
|
+
: props.title
|
|
300
|
+
: undefined;
|
|
301
|
+
const content: VNode[] = [];
|
|
302
|
+
if (title)
|
|
303
|
+
content.push({
|
|
304
|
+
tag: `h${props.titleLevel ?? 3}`,
|
|
305
|
+
attrs: { class: "emvb-media-box-title" },
|
|
306
|
+
children: [title],
|
|
307
|
+
});
|
|
308
|
+
if (props.text.trim())
|
|
309
|
+
content.push({ tag: "p", attrs: { class: "emvb-media-box-text" }, children: [props.text] });
|
|
310
|
+
const children: VNode[] = [];
|
|
311
|
+
if (media)
|
|
312
|
+
children.push({ tag: "div", attrs: { class: "emvb-media-box-media" }, children: [media] });
|
|
313
|
+
children.push({ tag: "div", attrs: { class: "emvb-media-box-content" }, children: content });
|
|
314
|
+
return {
|
|
315
|
+
tag: "div",
|
|
316
|
+
attrs: {
|
|
317
|
+
...attrs,
|
|
318
|
+
class:
|
|
319
|
+
`${attrs["class"] ?? ""} emvb-media-box emvb-media-box-${position}${safe ? " emvb-media-box-linked" : ""}`.trim(),
|
|
320
|
+
},
|
|
321
|
+
children,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Base rules the icon box and image box share. */
|
|
326
|
+
const MEDIA_BOX_CSS =
|
|
327
|
+
'.emvb-media-box{display:flex;flex-direction:column;gap:1em;min-width:0}.emvb-media-box-left{flex-direction:row;align-items:flex-start}.emvb-media-box-right{flex-direction:row-reverse;align-items:flex-start}.emvb-media-box-media{flex:none;line-height:0}.emvb-media-box-content{flex:1;min-width:0}.emvb-media-box-title{margin:0 0 0.5em;font-size:1.25em}.emvb-media-box-text{margin:0;white-space:pre-line}.emvb-media-box-linked{position:relative}.emvb-media-box-link{color:inherit;text-decoration:none}.emvb-media-box-link::after{content:"";position:absolute;inset:0}.emvb-media-box-link:focus-visible{outline:none}.emvb-media-box-linked:has(.emvb-media-box-link:focus-visible){outline:2px solid currentColor;outline-offset:4px}';
|
|
328
|
+
|
|
329
|
+
const POSITION_OPTIONS = [
|
|
330
|
+
{ value: "top", label: "Above" },
|
|
331
|
+
{ value: "left", label: "Before the text" },
|
|
332
|
+
{ value: "right", label: "After the text" },
|
|
333
|
+
];
|
|
334
|
+
|
|
335
|
+
/** The title, text, layout and link fields of an icon box and an image box. */
|
|
336
|
+
const MEDIA_BOX_FIELDS = [
|
|
337
|
+
{ key: "title", kind: "text" as const, label: "Title" },
|
|
338
|
+
{
|
|
339
|
+
key: "titleLevel",
|
|
340
|
+
kind: "select" as const,
|
|
341
|
+
label: "Title level",
|
|
342
|
+
optional: true,
|
|
343
|
+
options: [2, 3, 4, 5, 6].map((level) => ({ value: level, label: `H${level}` })),
|
|
344
|
+
},
|
|
345
|
+
{ key: "text", kind: "textarea" as const, label: "Text" },
|
|
346
|
+
{
|
|
347
|
+
key: "position",
|
|
348
|
+
kind: "select" as const,
|
|
349
|
+
label: "Position",
|
|
350
|
+
optional: true,
|
|
351
|
+
options: POSITION_OPTIONS,
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
key: "href",
|
|
355
|
+
kind: "href" as const,
|
|
356
|
+
label: "Link",
|
|
357
|
+
optional: true,
|
|
358
|
+
message: "Use a full URL such as https://example.com or a path such as /pricing.",
|
|
359
|
+
},
|
|
360
|
+
{ key: "newTab", kind: "boolean" as const, label: "Open in a new tab", optional: true },
|
|
361
|
+
];
|
|
362
|
+
|
|
363
|
+
export const iconBox: ElementDefinition<IconBoxNode> = {
|
|
364
|
+
baseCss: `${MEDIA_BOX_CSS}.emvb-icon-box .emvb-media-box-media svg{display:block;max-width:100%}`,
|
|
365
|
+
defaults: () => ({
|
|
366
|
+
type: "icon-box",
|
|
367
|
+
props: {
|
|
368
|
+
iconId: "star",
|
|
369
|
+
title: "A clear benefit",
|
|
370
|
+
text: "One or two sentences that explain it.",
|
|
371
|
+
},
|
|
372
|
+
}),
|
|
373
|
+
descriptor: {
|
|
374
|
+
type: "icon-box",
|
|
375
|
+
name: "Icon box",
|
|
376
|
+
group: "content",
|
|
377
|
+
defaultTab: "content",
|
|
378
|
+
fields: [
|
|
379
|
+
{ key: "iconId", kind: "icon", label: "Icon" },
|
|
380
|
+
{ key: "iconSize", kind: "int", label: "Icon size (px)", optional: true, min: 8, max: 512 },
|
|
381
|
+
...MEDIA_BOX_FIELDS,
|
|
382
|
+
],
|
|
383
|
+
},
|
|
384
|
+
build: (node, attrs) =>
|
|
385
|
+
mediaBox(
|
|
386
|
+
node.props,
|
|
387
|
+
attrs,
|
|
388
|
+
iconGlyph(node.props, node.props.iconSize ?? 48, { "aria-hidden": "true" }),
|
|
389
|
+
),
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
/** W-1021: the picture of an image box, or undefined when it has no safe address. */
|
|
393
|
+
function boxImage(props: ImageBoxNode["props"]): VNode | undefined {
|
|
394
|
+
const src = props.src.trim() ? sanitizeMediaUrl(props.src.trim()) : undefined;
|
|
395
|
+
if (!src) return undefined;
|
|
396
|
+
return {
|
|
397
|
+
tag: "img",
|
|
398
|
+
attrs: {
|
|
399
|
+
src,
|
|
400
|
+
alt: props.decorative ? "" : props.alt,
|
|
401
|
+
...(props.width ? { width: String(props.width) } : {}),
|
|
402
|
+
...(props.height ? { height: String(props.height) } : {}),
|
|
403
|
+
loading: "lazy",
|
|
404
|
+
decoding: "async",
|
|
405
|
+
},
|
|
406
|
+
children: [],
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export const imageBox: ElementDefinition<ImageBoxNode> = {
|
|
411
|
+
baseCss: `${MEDIA_BOX_CSS}.emvb-image-box .emvb-media-box-media img{display:block;width:100%;height:auto}.emvb-image-box.emvb-media-box-top .emvb-media-box-media{width:100%}.emvb-image-box:is(.emvb-media-box-left,.emvb-media-box-right) .emvb-media-box-media{flex-basis:40%;max-width:40%}.emvb-image-box.emvb-image-box-small:is(.emvb-media-box-left,.emvb-media-box-right) .emvb-media-box-media{flex-basis:25%;max-width:25%}.emvb-image-box.emvb-image-box-large:is(.emvb-media-box-left,.emvb-media-box-right) .emvb-media-box-media{flex-basis:60%;max-width:60%}.emvb-image-box.emvb-image-box-full:is(.emvb-media-box-left,.emvb-media-box-right) .emvb-media-box-media{flex-basis:100%;max-width:100%}`,
|
|
412
|
+
defaults: () => ({
|
|
413
|
+
type: "image-box",
|
|
414
|
+
props: {
|
|
415
|
+
src: "",
|
|
416
|
+
alt: "Image",
|
|
417
|
+
title: "A clear benefit",
|
|
418
|
+
text: "One or two sentences that explain it.",
|
|
419
|
+
},
|
|
420
|
+
}),
|
|
421
|
+
descriptor: {
|
|
422
|
+
type: "image-box",
|
|
423
|
+
name: "Image box",
|
|
424
|
+
group: "content",
|
|
425
|
+
defaultTab: "content",
|
|
426
|
+
fields: [
|
|
427
|
+
{ key: "src", kind: "media", label: "Image" },
|
|
428
|
+
{ key: "alt", kind: "text", label: "Alt text" },
|
|
429
|
+
{ key: "decorative", kind: "boolean", label: "Decorative", optional: true },
|
|
430
|
+
{
|
|
431
|
+
key: "imageSize",
|
|
432
|
+
kind: "select",
|
|
433
|
+
label: "Image width beside the text",
|
|
434
|
+
optional: true,
|
|
435
|
+
options: [
|
|
436
|
+
{ value: "small", label: "Small (25%)" },
|
|
437
|
+
{ value: "medium", label: "Medium (40%)" },
|
|
438
|
+
{ value: "large", label: "Large (60%)" },
|
|
439
|
+
{ value: "full", label: "Full" },
|
|
440
|
+
],
|
|
441
|
+
},
|
|
442
|
+
...MEDIA_BOX_FIELDS,
|
|
443
|
+
],
|
|
444
|
+
},
|
|
445
|
+
build: (node, attrs) => {
|
|
446
|
+
const box = mediaBox(node.props, attrs, boxImage(node.props));
|
|
447
|
+
const size = node.props.imageSize;
|
|
448
|
+
if (size && size !== "medium")
|
|
449
|
+
box.attrs["class"] = `${box.attrs["class"]} emvb-image-box-${size}`;
|
|
450
|
+
return box;
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
export const testimonial: ElementDefinition<TestimonialNode> = {
|
|
455
|
+
baseCss: `${rating.baseCss}.emvb-testimonial{display:flex;flex-direction:column;gap:1em;margin:0}.emvb-testimonial-quote{margin:0;font-size:1.125em}.emvb-testimonial-quote p{margin:0;white-space:pre-line}.emvb-testimonial-caption{display:flex;align-items:center;gap:0.75em}.emvb-testimonial-photo{flex:none;width:48px;height:48px;border-radius:50%;object-fit:cover}.emvb-testimonial-who{display:flex;flex-direction:column}.emvb-testimonial-name{font-weight:600}.emvb-testimonial-role{opacity:0.8}.emvb-testimonial .emvb-rating{color:#b45309}`,
|
|
456
|
+
defaults: () => ({
|
|
457
|
+
type: "testimonial",
|
|
458
|
+
props: {
|
|
459
|
+
quote: "It changed how our team works. We ship pages in an afternoon now.",
|
|
460
|
+
name: "Sam Rivera",
|
|
461
|
+
role: "Head of Marketing",
|
|
462
|
+
},
|
|
463
|
+
}),
|
|
464
|
+
descriptor: {
|
|
465
|
+
type: "testimonial",
|
|
466
|
+
name: "Testimonial",
|
|
467
|
+
group: "content",
|
|
468
|
+
defaultTab: "content",
|
|
469
|
+
fields: [
|
|
470
|
+
{ key: "quote", kind: "textarea", label: "Quote" },
|
|
471
|
+
{ key: "name", kind: "text", label: "Name" },
|
|
472
|
+
{ key: "role", kind: "text", label: "Role or company", optional: true },
|
|
473
|
+
{ key: "src", kind: "media", label: "Photo" },
|
|
474
|
+
{
|
|
475
|
+
key: "rating",
|
|
476
|
+
kind: "decimal",
|
|
477
|
+
label: "Rating",
|
|
478
|
+
optional: true,
|
|
479
|
+
min: 0,
|
|
480
|
+
max: 5,
|
|
481
|
+
maxProp: "ratingMax",
|
|
482
|
+
message: "Enter a number from 0 up to the number of stars, or leave it empty for none.",
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
key: "ratingMax",
|
|
486
|
+
kind: "int",
|
|
487
|
+
label: "Stars",
|
|
488
|
+
optional: true,
|
|
489
|
+
max: MAX_RATING,
|
|
490
|
+
message: `From 1 to ${MAX_RATING} stars.`,
|
|
491
|
+
},
|
|
492
|
+
],
|
|
493
|
+
},
|
|
494
|
+
build: (node, attrs) => {
|
|
495
|
+
const { quote, name, role, rating: value, ratingMax } = node.props;
|
|
496
|
+
const children: VNode[] = [];
|
|
497
|
+
if (value !== undefined)
|
|
498
|
+
children.push(ratingStars({ value, max: ratingMax ?? 5 }, { class: "emvb-rating" }));
|
|
499
|
+
children.push({
|
|
500
|
+
tag: "blockquote",
|
|
501
|
+
attrs: { class: "emvb-testimonial-quote" },
|
|
502
|
+
children: [{ tag: "p", attrs: {}, children: [quote] }],
|
|
503
|
+
});
|
|
504
|
+
const src = node.props.src?.trim() ? sanitizeMediaUrl(node.props.src.trim()) : undefined;
|
|
505
|
+
const caption: VNode[] = [];
|
|
506
|
+
if (src)
|
|
507
|
+
caption.push({
|
|
508
|
+
tag: "img",
|
|
509
|
+
attrs: {
|
|
510
|
+
class: "emvb-testimonial-photo",
|
|
511
|
+
src,
|
|
512
|
+
alt: "",
|
|
513
|
+
width: "48",
|
|
514
|
+
height: "48",
|
|
515
|
+
loading: "lazy",
|
|
516
|
+
decoding: "async",
|
|
517
|
+
},
|
|
518
|
+
children: [],
|
|
519
|
+
});
|
|
520
|
+
const who: VNode[] = [];
|
|
521
|
+
if (name.trim())
|
|
522
|
+
who.push({ tag: "span", attrs: { class: "emvb-testimonial-name" }, children: [name] });
|
|
523
|
+
if (role?.trim())
|
|
524
|
+
who.push({ tag: "span", attrs: { class: "emvb-testimonial-role" }, children: [role] });
|
|
525
|
+
if (who.length > 0)
|
|
526
|
+
caption.push({ tag: "span", attrs: { class: "emvb-testimonial-who" }, children: who });
|
|
527
|
+
if (caption.length > 0)
|
|
528
|
+
children.push({
|
|
529
|
+
tag: "figcaption",
|
|
530
|
+
attrs: { class: "emvb-testimonial-caption" },
|
|
531
|
+
children: caption,
|
|
532
|
+
});
|
|
533
|
+
return { tag: "figure", attrs, children };
|
|
534
|
+
},
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
type Network = SocialLinkNode["props"]["network"];
|
|
538
|
+
|
|
539
|
+
/** W-1024: what screen readers call each network's link, unless the link has its own label. */
|
|
540
|
+
export const SOCIAL_NAMES: Record<Network, string> = {
|
|
541
|
+
facebook: "Facebook",
|
|
542
|
+
instagram: "Instagram",
|
|
543
|
+
x: "X",
|
|
544
|
+
linkedin: "LinkedIn",
|
|
545
|
+
youtube: "YouTube",
|
|
546
|
+
tiktok: "TikTok",
|
|
547
|
+
bluesky: "Bluesky",
|
|
548
|
+
mastodon: "Mastodon",
|
|
549
|
+
threads: "Threads",
|
|
550
|
+
github: "GitHub",
|
|
551
|
+
pinterest: "Pinterest",
|
|
552
|
+
whatsapp: "WhatsApp",
|
|
553
|
+
discord: "Discord",
|
|
554
|
+
twitch: "Twitch",
|
|
555
|
+
reddit: "Reddit",
|
|
556
|
+
dribbble: "Dribbble",
|
|
557
|
+
behance: "Behance",
|
|
558
|
+
telegram: "Telegram",
|
|
559
|
+
spotify: "Spotify",
|
|
560
|
+
email: "Email",
|
|
561
|
+
rss: "RSS feed",
|
|
562
|
+
website: "Website",
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
/** W-1024: each network's own colour, used when Brand colours is on. */
|
|
566
|
+
export const SOCIAL_COLORS: Record<Network, string> = {
|
|
567
|
+
facebook: "#1877f2",
|
|
568
|
+
instagram: "#e4405f",
|
|
569
|
+
x: "#000000",
|
|
570
|
+
linkedin: "#0a66c2",
|
|
571
|
+
youtube: "#ff0000",
|
|
572
|
+
tiktok: "#000000",
|
|
573
|
+
bluesky: "#1185fe",
|
|
574
|
+
mastodon: "#6364ff",
|
|
575
|
+
threads: "#000000",
|
|
576
|
+
github: "#181717",
|
|
577
|
+
pinterest: "#bd081c",
|
|
578
|
+
whatsapp: "#25d366",
|
|
579
|
+
discord: "#5865f2",
|
|
580
|
+
twitch: "#9146ff",
|
|
581
|
+
reddit: "#ff4500",
|
|
582
|
+
dribbble: "#ea4c89",
|
|
583
|
+
behance: "#1769ff",
|
|
584
|
+
telegram: "#26a5e4",
|
|
585
|
+
spotify: "#1db954",
|
|
586
|
+
email: "#555555",
|
|
587
|
+
rss: "#ee802f",
|
|
588
|
+
website: "#555555",
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
/** A preset's icon as an aria-hidden SVG one em square. */
|
|
592
|
+
function socialSvg(network: Network): VNode | undefined {
|
|
593
|
+
const icon = SOCIAL_ICONS[network];
|
|
594
|
+
const svg = sanitizeSvgMarkup(
|
|
595
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${icon.viewBox}">${icon.body}</svg>`,
|
|
596
|
+
);
|
|
597
|
+
if (!svg) return undefined;
|
|
598
|
+
return {
|
|
599
|
+
...svg,
|
|
600
|
+
attrs: {
|
|
601
|
+
...svg.attrs,
|
|
602
|
+
class: "emvb-social-svg",
|
|
603
|
+
fill: "currentColor",
|
|
604
|
+
"aria-hidden": "true",
|
|
605
|
+
focusable: "false",
|
|
606
|
+
},
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export const socialIcons: ElementDefinition<SocialIconsNode> = {
|
|
611
|
+
baseCss:
|
|
612
|
+
".emvb-social-icons{display:flex;flex-wrap:wrap;align-items:center;gap:0.5em;margin:0;padding:0;list-style:none;font-size:1.5em}.emvb-social-link{display:flex}.emvb-social-link>a,.emvb-social-link>span{display:inline-flex;align-items:center;justify-content:center;color:inherit;text-decoration:none}.emvb-social-svg{display:block;width:1em;height:1em}.emvb-social-brand.emvb-social-plain .emvb-social-link>*{color:var(--emvb-social,currentColor)}.emvb-social-icons:not(.emvb-social-plain) .emvb-social-link>*{width:2em;height:2em;background:var(--emvb-social,currentColor)}.emvb-social-icons:not(.emvb-social-plain) .emvb-social-svg{width:1.1em;height:1.1em;color:#fff}.emvb-social-circle .emvb-social-link>*{border-radius:50%}.emvb-social-rounded .emvb-social-link>*{border-radius:0.4em}.emvb-social-link>a:focus-visible{outline:2px solid currentColor;outline-offset:2px}.emvb-social-empty{opacity:0.4}" +
|
|
613
|
+
SOCIAL_NETWORKS.map(
|
|
614
|
+
(network) =>
|
|
615
|
+
`.emvb-social-brand .emvb-social-${network}{--emvb-social:${SOCIAL_COLORS[network]}}`,
|
|
616
|
+
).join(""),
|
|
617
|
+
defaults: () => ({ type: "social-icons", props: {}, children: [] }),
|
|
618
|
+
descriptor: {
|
|
619
|
+
type: "social-icons",
|
|
620
|
+
name: "Social icons",
|
|
621
|
+
group: "content",
|
|
622
|
+
defaultTab: "content",
|
|
623
|
+
fields: [
|
|
624
|
+
{
|
|
625
|
+
key: "label",
|
|
626
|
+
kind: "text",
|
|
627
|
+
label: "List name",
|
|
628
|
+
optional: true,
|
|
629
|
+
message: "What screen readers call the list. Leave it empty for Social media.",
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
key: "shape",
|
|
633
|
+
kind: "select",
|
|
634
|
+
label: "Shape",
|
|
635
|
+
optional: true,
|
|
636
|
+
options: [
|
|
637
|
+
{ value: "plain", label: "Icon only" },
|
|
638
|
+
{ value: "circle", label: "Circle" },
|
|
639
|
+
{ value: "rounded", label: "Rounded square" },
|
|
640
|
+
{ value: "square", label: "Square" },
|
|
641
|
+
],
|
|
642
|
+
},
|
|
643
|
+
{ key: "brandColors", kind: "boolean", label: "Brand colours", optional: true },
|
|
644
|
+
],
|
|
645
|
+
},
|
|
646
|
+
build: (node, attrs, children) => ({
|
|
647
|
+
tag: "ul",
|
|
648
|
+
attrs: {
|
|
649
|
+
...attrs,
|
|
650
|
+
class:
|
|
651
|
+
`${attrs["class"] ?? ""} emvb-social-${node.props.shape ?? "plain"}${node.props.brandColors ? " emvb-social-brand" : ""}`.trim(),
|
|
652
|
+
"aria-label": node.props.label?.trim() || "Social media",
|
|
653
|
+
},
|
|
654
|
+
children,
|
|
655
|
+
}),
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
export const socialLink: ElementDefinition<SocialLinkNode> = {
|
|
659
|
+
baseCss: "",
|
|
660
|
+
defaults: () => ({
|
|
661
|
+
type: "social-link",
|
|
662
|
+
props: { network: "facebook", href: "https://facebook.com/", newTab: true },
|
|
663
|
+
}),
|
|
664
|
+
descriptor: {
|
|
665
|
+
type: "social-link",
|
|
666
|
+
name: "Social link",
|
|
667
|
+
group: "content",
|
|
668
|
+
defaultTab: "content",
|
|
669
|
+
fields: [
|
|
670
|
+
{
|
|
671
|
+
key: "network",
|
|
672
|
+
kind: "select",
|
|
673
|
+
label: "Network",
|
|
674
|
+
options: SOCIAL_NETWORKS.map((value) => ({ value, label: SOCIAL_NAMES[value] })),
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
key: "href",
|
|
678
|
+
kind: "href",
|
|
679
|
+
label: "Profile address",
|
|
680
|
+
message: "Use a full URL such as https://instagram.com/yourname, or mailto: for email.",
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
key: "label",
|
|
684
|
+
kind: "text",
|
|
685
|
+
label: "Name for screen readers",
|
|
686
|
+
optional: true,
|
|
687
|
+
message: "Leave it empty to use the network's name.",
|
|
688
|
+
},
|
|
689
|
+
{ key: "newTab", kind: "boolean", label: "Open in a new tab", optional: true },
|
|
690
|
+
],
|
|
691
|
+
},
|
|
692
|
+
build: (node, attrs) => {
|
|
693
|
+
const { network, href, label, newTab } = node.props;
|
|
694
|
+
const icon = socialSvg(network);
|
|
695
|
+
const safe = href.trim() ? sanitizeHref(href) : undefined;
|
|
696
|
+
const name = label?.trim() || SOCIAL_NAMES[network];
|
|
697
|
+
const className =
|
|
698
|
+
`${attrs["class"] ?? ""} emvb-social-${network}${safe ? "" : " emvb-social-empty"}`.trim();
|
|
699
|
+
const inner: VNode = safe
|
|
700
|
+
? {
|
|
701
|
+
tag: "a",
|
|
702
|
+
attrs: {
|
|
703
|
+
href: safe,
|
|
704
|
+
"aria-label": name,
|
|
705
|
+
...(newTab ? { target: "_blank", rel: "noopener noreferrer" } : {}),
|
|
706
|
+
},
|
|
707
|
+
children: icon ? [icon] : [],
|
|
708
|
+
}
|
|
709
|
+
: { tag: "span", attrs: { "aria-hidden": "true" }, children: icon ? [icon] : [] };
|
|
710
|
+
return { tag: "li", attrs: { ...attrs, class: className }, children: [inner] };
|
|
711
|
+
},
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
export const gallery: ElementDefinition<GalleryNode> = {
|
|
715
|
+
baseCss:
|
|
716
|
+
".emvb-gallery{display:grid;gap:0.5em;margin:0;padding:0;list-style:none;grid-template-columns:repeat(var(--emvb-gallery-cols,3),minmax(0,1fr))}.emvb-gallery-image{margin:0;min-width:0}.emvb-gallery-image figure{margin:0}.emvb-gallery-image img{display:block;width:100%;height:auto}.emvb-gallery-grid .emvb-gallery-image img{aspect-ratio:1;object-fit:cover}.emvb-gallery-image figcaption{margin-top:0.25em;font-size:0.875em}.emvb-gallery-masonry{display:block;columns:var(--emvb-gallery-cols,3);column-gap:0.5em}.emvb-gallery-masonry .emvb-gallery-image{break-inside:avoid;margin-bottom:0.5em}.emvb-gallery-open{display:block;width:100%;padding:0;border:0;background:none;cursor:zoom-in}.emvb-gallery-open:focus-visible{outline:2px solid currentColor;outline-offset:2px}" +
|
|
717
|
+
[1, 2, 3, 4, 5, 6].map((n) => `.emvb-gallery-cols-${n}{--emvb-gallery-cols:${n}}`).join("") +
|
|
718
|
+
"@media (max-width:1024px){.emvb-gallery:is(.emvb-gallery-cols-3,.emvb-gallery-cols-4,.emvb-gallery-cols-5,.emvb-gallery-cols-6){--emvb-gallery-cols:2}}@media (max-width:767px){.emvb-gallery{--emvb-gallery-cols:1}}" +
|
|
719
|
+
".emvb-lightbox{max-width:min(96vw,1400px);max-height:96vh;padding:0;border:0;background:#111;color:#fff}.emvb-lightbox::backdrop{background:rgb(0 0 0/0.85)}.emvb-lightbox-figure{margin:0;display:flex;flex-direction:column;align-items:center}.emvb-lightbox img{display:block;max-width:100%;max-height:calc(96vh - 4em);object-fit:contain}.emvb-lightbox-bar{display:flex;align-items:center;gap:0.5em;width:100%;padding:0.5em}.emvb-lightbox-caption{flex:1;text-align:center}.emvb-lightbox button{min-width:2.75em;min-height:2.75em;border:0;border-radius:4px;background:rgb(255 255 255/0.15);color:#fff;font:inherit;cursor:pointer}.emvb-lightbox button:focus-visible{outline:2px solid #fff;outline-offset:2px}",
|
|
720
|
+
defaults: () => ({ type: "gallery", props: {}, children: [] }),
|
|
721
|
+
descriptor: {
|
|
722
|
+
type: "gallery",
|
|
723
|
+
name: "Gallery",
|
|
724
|
+
group: "content",
|
|
725
|
+
defaultTab: "content",
|
|
726
|
+
fields: [
|
|
727
|
+
{
|
|
728
|
+
key: "layout",
|
|
729
|
+
kind: "select",
|
|
730
|
+
label: "Layout",
|
|
731
|
+
optional: true,
|
|
732
|
+
options: [
|
|
733
|
+
{ value: "grid", label: "Grid of squares" },
|
|
734
|
+
{ value: "masonry", label: "Masonry" },
|
|
735
|
+
],
|
|
736
|
+
},
|
|
737
|
+
{ key: "columns", kind: "int", label: "Columns", optional: true, max: 6 },
|
|
738
|
+
{
|
|
739
|
+
key: "lightbox",
|
|
740
|
+
kind: "boolean",
|
|
741
|
+
label: "Open pictures large (lightbox)",
|
|
742
|
+
optional: true,
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
key: "label",
|
|
746
|
+
kind: "text",
|
|
747
|
+
label: "Gallery name",
|
|
748
|
+
optional: true,
|
|
749
|
+
message: "What screen readers call the gallery, such as Project photos.",
|
|
750
|
+
},
|
|
751
|
+
],
|
|
752
|
+
},
|
|
753
|
+
build: (node, attrs, children) => ({
|
|
754
|
+
tag: "ul",
|
|
755
|
+
attrs: {
|
|
756
|
+
...attrs,
|
|
757
|
+
class:
|
|
758
|
+
`${attrs["class"] ?? ""} emvb-gallery-${node.props.layout ?? "grid"} emvb-gallery-cols-${node.props.columns ?? 3}`.trim(),
|
|
759
|
+
...(node.props.label?.trim() ? { "aria-label": node.props.label.trim() } : {}),
|
|
760
|
+
...(node.props.lightbox ? { "data-emvb-lightbox": "" } : {}),
|
|
761
|
+
},
|
|
762
|
+
children,
|
|
763
|
+
}),
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
export const galleryImage: ElementDefinition<GalleryImageNode> = {
|
|
767
|
+
baseCss: "",
|
|
768
|
+
defaults: () => ({ type: "gallery-image", props: { src: "", alt: "Image" } }),
|
|
769
|
+
descriptor: {
|
|
770
|
+
type: "gallery-image",
|
|
771
|
+
name: "Gallery image",
|
|
772
|
+
group: "content",
|
|
773
|
+
defaultTab: "content",
|
|
774
|
+
fields: [
|
|
775
|
+
{ key: "src", kind: "media", label: "Image" },
|
|
776
|
+
{ key: "alt", kind: "text", label: "Alt text" },
|
|
777
|
+
{ key: "decorative", kind: "boolean", label: "Decorative", optional: true },
|
|
778
|
+
{ key: "caption", kind: "text", label: "Caption", optional: true },
|
|
779
|
+
],
|
|
780
|
+
},
|
|
781
|
+
build: (node, attrs) => {
|
|
782
|
+
const src = node.props.src.trim() ? sanitizeMediaUrl(node.props.src.trim()) : undefined;
|
|
783
|
+
const caption = node.props.caption?.trim();
|
|
784
|
+
const figure: VNode[] = [];
|
|
785
|
+
if (src)
|
|
786
|
+
figure.push({
|
|
787
|
+
tag: "img",
|
|
788
|
+
attrs: {
|
|
789
|
+
src,
|
|
790
|
+
alt: node.props.decorative ? "" : node.props.alt,
|
|
791
|
+
...(node.props.width ? { width: String(node.props.width) } : {}),
|
|
792
|
+
...(node.props.height ? { height: String(node.props.height) } : {}),
|
|
793
|
+
loading: "lazy",
|
|
794
|
+
decoding: "async",
|
|
795
|
+
},
|
|
796
|
+
children: [],
|
|
797
|
+
});
|
|
798
|
+
if (caption) figure.push({ tag: "figcaption", attrs: {}, children: [caption] });
|
|
799
|
+
return { tag: "li", attrs, children: [{ tag: "figure", attrs: {}, children: figure }] };
|
|
800
|
+
},
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
export const carousel: ElementDefinition<CarouselNode> = {
|
|
804
|
+
baseCss:
|
|
805
|
+
".emvb-carousel{position:relative;min-width:0}.emvb-carousel-track{display:flex;gap:var(--emvb-carousel-gap,1em);overflow-x:auto;overscroll-behavior-x:contain;scroll-snap-type:x mandatory;scrollbar-width:thin}.emvb-carousel-track:focus-visible{outline:2px solid currentColor;outline-offset:2px}.emvb-carousel-slide{flex:0 0 calc((100% - (var(--emvb-carousel-per,1) - 1) * var(--emvb-carousel-gap,1em)) / var(--emvb-carousel-per,1));min-width:0;scroll-snap-align:start;display:flex;flex-direction:column}" +
|
|
806
|
+
[1, 2, 3, 4].map((n) => `.emvb-carousel-per-${n}{--emvb-carousel-per:${n}}`).join("") +
|
|
807
|
+
"@media (max-width:1024px){.emvb-carousel:is(.emvb-carousel-per-3,.emvb-carousel-per-4){--emvb-carousel-per:2}}@media (max-width:767px){.emvb-carousel{--emvb-carousel-per:1}}@media (prefers-reduced-motion:no-preference){.emvb-carousel-track{scroll-behavior:smooth}}" +
|
|
808
|
+
'.emvb-carousel-controls{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:0.5em;margin-top:0.75em}.emvb-carousel-controls button{display:inline-flex;align-items:center;justify-content:center;min-width:2.75em;min-height:2.75em;padding:0 0.75em;border:1px solid currentColor;border-radius:999px;background:none;color:inherit;font:inherit;cursor:pointer}.emvb-carousel-controls button:disabled{opacity:0.4;cursor:default}.emvb-carousel-controls button:focus-visible{outline:2px solid currentColor;outline-offset:2px}.emvb-carousel-dots{display:flex;gap:0.25em}.emvb-carousel-dots button{min-width:2.75em;padding:0}.emvb-carousel-dots button::before{content:"";width:0.6em;height:0.6em;border-radius:50%;background:currentColor;opacity:0.35}.emvb-carousel-dots button[aria-current=true]::before{opacity:1}',
|
|
809
|
+
defaults: () => ({ type: "carousel", props: {}, children: [] }),
|
|
810
|
+
descriptor: {
|
|
811
|
+
type: "carousel",
|
|
812
|
+
name: "Carousel",
|
|
813
|
+
group: "layout",
|
|
814
|
+
defaultTab: "content",
|
|
815
|
+
fields: [
|
|
816
|
+
{
|
|
817
|
+
key: "label",
|
|
818
|
+
kind: "text",
|
|
819
|
+
label: "Carousel name",
|
|
820
|
+
optional: true,
|
|
821
|
+
message:
|
|
822
|
+
"What screen readers call it, such as Customer stories. Leave it empty for Carousel.",
|
|
823
|
+
},
|
|
824
|
+
{ key: "perView", kind: "int", label: "Slides shown at once", optional: true, max: 4 },
|
|
825
|
+
{ key: "arrows", kind: "boolean", label: "Previous and Next buttons", optional: true },
|
|
826
|
+
{ key: "dots", kind: "boolean", label: "Slide buttons (dots)", optional: true },
|
|
827
|
+
{ key: "loop", kind: "boolean", label: "Go round from the last slide", optional: true },
|
|
828
|
+
{ key: "autoplay", kind: "boolean", label: "Play automatically", optional: true },
|
|
829
|
+
{
|
|
830
|
+
key: "interval",
|
|
831
|
+
kind: "int",
|
|
832
|
+
label: "Seconds per slide",
|
|
833
|
+
optional: true,
|
|
834
|
+
min: 3,
|
|
835
|
+
max: 30,
|
|
836
|
+
message: "From 3 to 30 seconds. Leave it empty for 6.",
|
|
837
|
+
},
|
|
838
|
+
],
|
|
839
|
+
},
|
|
840
|
+
build: (node, attrs, children) => {
|
|
841
|
+
const { label, perView, arrows, dots, autoplay, interval, loop } = node.props;
|
|
842
|
+
const total = children.length;
|
|
843
|
+
// Each slide is named by its place unless it has its own name.
|
|
844
|
+
const slides = children.map((slide, i) =>
|
|
845
|
+
slide.attrs["aria-label"]
|
|
846
|
+
? slide
|
|
847
|
+
: { ...slide, attrs: { ...slide.attrs, "aria-label": `${i + 1} of ${total}` } },
|
|
848
|
+
);
|
|
849
|
+
const options: Record<string, string> = {};
|
|
850
|
+
if (arrows) options["data-emvb-arrows"] = "";
|
|
851
|
+
if (dots) options["data-emvb-dots"] = "";
|
|
852
|
+
if (autoplay) options["data-emvb-autoplay"] = String(interval ?? 6);
|
|
853
|
+
if (loop) options["data-emvb-loop"] = "";
|
|
854
|
+
return {
|
|
855
|
+
tag: "section",
|
|
856
|
+
attrs: {
|
|
857
|
+
...attrs,
|
|
858
|
+
class: `${attrs["class"] ?? ""} emvb-carousel-per-${perView ?? 1}`.trim(),
|
|
859
|
+
"aria-roledescription": "carousel",
|
|
860
|
+
"aria-label": label?.trim() || "Carousel",
|
|
861
|
+
...options,
|
|
862
|
+
},
|
|
863
|
+
children: [
|
|
864
|
+
{
|
|
865
|
+
tag: "div",
|
|
866
|
+
attrs: {
|
|
867
|
+
class: "emvb-carousel-track",
|
|
868
|
+
tabindex: "0",
|
|
869
|
+
"aria-live": autoplay ? "off" : "polite",
|
|
870
|
+
},
|
|
871
|
+
children: slides,
|
|
872
|
+
},
|
|
873
|
+
],
|
|
874
|
+
};
|
|
875
|
+
},
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
export const carouselSlide: ElementDefinition<CarouselSlideNode> = {
|
|
879
|
+
baseCss: "",
|
|
880
|
+
defaults: () => ({ type: "carousel-slide", props: {}, children: [] }),
|
|
881
|
+
descriptor: {
|
|
882
|
+
type: "carousel-slide",
|
|
883
|
+
name: "Slide",
|
|
884
|
+
group: "layout",
|
|
885
|
+
defaultTab: "content",
|
|
886
|
+
fields: [
|
|
887
|
+
{
|
|
888
|
+
key: "label",
|
|
889
|
+
kind: "text",
|
|
890
|
+
label: "Slide name",
|
|
891
|
+
optional: true,
|
|
892
|
+
message:
|
|
893
|
+
"What screen readers call this slide. Leave it empty for its place, such as 2 of 5.",
|
|
894
|
+
},
|
|
895
|
+
],
|
|
896
|
+
},
|
|
897
|
+
build: (node, attrs, children) => ({
|
|
898
|
+
tag: "div",
|
|
899
|
+
attrs: {
|
|
900
|
+
...attrs,
|
|
901
|
+
role: "group",
|
|
902
|
+
"aria-roledescription": "slide",
|
|
903
|
+
...(node.props.label?.trim() ? { "aria-label": node.props.label.trim() } : {}),
|
|
904
|
+
},
|
|
905
|
+
children,
|
|
906
|
+
}),
|
|
907
|
+
};
|