@perkyzz/emvb 0.8.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +4 -4
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +325 -239
- package/src/admin/editor/FieldPreview.tsx +164 -0
- package/src/admin/editor/Timeline.tsx +2 -1
- package/src/admin/editor/TopBar.tsx +36 -3
- package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
- package/src/admin/editor/canvas/canvas-scale.ts +2 -2
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +26 -4
- package/src/admin/editor/editor-chrome.tsx +3 -3
- package/src/admin/editor/editor-commands.ts +8 -3
- package/src/admin/editor/editor-css.ts +3 -0
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/host.ts +6 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +53 -15
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +76 -20
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +104 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +113 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +55 -2
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +51 -10
- package/src/admin/editor/panels/style-target.ts +9 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/store.ts +6 -2
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +4 -4
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +15 -6
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/index.tsx +5 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/media-api.ts +27 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +11 -28
- package/src/admin/pages/CollectionsPage.tsx +215 -0
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +15 -1
- package/src/admin/pages/ThemePartList.tsx +15 -1
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/setup/host-collections.ts +100 -0
- package/src/admin/ui.ts +39 -2
- package/src/admin/widgets/CanvasField.tsx +202 -0
- package/src/admin/widgets/convert-body.ts +54 -0
- package/src/admin/widgets/field-fetcher.ts +79 -0
- package/src/astro/content-port.ts +14 -1
- package/src/astro/index.ts +2 -0
- package/src/astro/page-count.ts +77 -0
- package/src/astro/resolve-theme.ts +58 -3
- package/src/astro/resolve.ts +128 -5
- package/src/astro/responsive-images.ts +99 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +44 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/canvas-collections.ts +20 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +285 -0
- package/src/core/css/generate.ts +89 -20
- package/src/core/css/trace.ts +18 -9
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +4 -5
- package/src/core/design/devices.ts +13 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +17 -4
- package/src/core/elements/dynamic-elements.ts +19 -4
- package/src/core/elements/index.ts +73 -9
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +1 -1
- package/src/core/import/elementor/atomic.ts +1595 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +949 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +409 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +84 -0
- package/src/core/json-schema.ts +107 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +5 -5
- package/src/core/portable-text.ts +127 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +140 -20
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/pagination.ts +20 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +125 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +2 -1
- package/src/core/schema/layout.ts +87 -14
- package/src/core/schema/style.ts +251 -114
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/pagination.ts +9 -0
- package/src/core/theme/popup-rules.ts +17 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +35 -1
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -9
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +21 -2
- package/src/server/hooks.ts +81 -0
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +53 -5
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
|
@@ -0,0 +1,1897 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elementor widgets → EmVB elements (W-945). Core Elementor widgets map to their EmVB
|
|
3
|
+
* counterparts with Elementor's own defaults; Pro, theme-builder and third-party widgets are
|
|
4
|
+
* best-effort and say what they left out. Every text is plain text and every URL goes through
|
|
5
|
+
* EmVB's sanitizers before it lands in a node.
|
|
6
|
+
*/
|
|
7
|
+
import { MAX_TABS, MAX_TEXT_LENGTH } from "../../limits.ts";
|
|
8
|
+
import { FIELD_NAME_PATTERN, ICON_SVG_MAX } from "../../schema/layout.ts";
|
|
9
|
+
import { sanitizeHref } from "../../sanitize/href.ts";
|
|
10
|
+
import { sanitizeMediaUrl } from "../../sanitize/media-url.ts";
|
|
11
|
+
import { type ImportContext, svgFileId } from "./context.ts";
|
|
12
|
+
import {
|
|
13
|
+
type Block,
|
|
14
|
+
cleanText,
|
|
15
|
+
decodeEntities,
|
|
16
|
+
embedVideoUrl,
|
|
17
|
+
htmlToBlocks,
|
|
18
|
+
inlineMarks,
|
|
19
|
+
splitLong,
|
|
20
|
+
stripControl,
|
|
21
|
+
} from "./html.ts";
|
|
22
|
+
import {
|
|
23
|
+
boxReader,
|
|
24
|
+
colorAt,
|
|
25
|
+
deviceStyles,
|
|
26
|
+
type Reader,
|
|
27
|
+
type Style,
|
|
28
|
+
textReader,
|
|
29
|
+
typographyReader,
|
|
30
|
+
} from "./style.ts";
|
|
31
|
+
import {
|
|
32
|
+
altFromUrl,
|
|
33
|
+
color,
|
|
34
|
+
image,
|
|
35
|
+
isRecord,
|
|
36
|
+
link,
|
|
37
|
+
num,
|
|
38
|
+
type Settings,
|
|
39
|
+
slider,
|
|
40
|
+
str,
|
|
41
|
+
textAlign,
|
|
42
|
+
} from "./values.ts";
|
|
43
|
+
|
|
44
|
+
/** A layout node under construction; the whole tree is validated at the end. */
|
|
45
|
+
export type N = {
|
|
46
|
+
id: string;
|
|
47
|
+
type: string;
|
|
48
|
+
props: Record<string, unknown>;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type Env = {
|
|
53
|
+
/** The parent lays its children out in a row (alignment by auto margins needs a column). */
|
|
54
|
+
parentRow: boolean;
|
|
55
|
+
depth: number;
|
|
56
|
+
/** Maps child Elementor elements (nested widgets), as the structure walker does. */
|
|
57
|
+
walk: (elements: unknown, env: Env) => N[];
|
|
58
|
+
/** Inside an Elementor 4 form: its labels by input id, so fields take their label. */
|
|
59
|
+
form?: { labels: Map<string, string>; byField?: Map<Record<string, unknown>, string> };
|
|
60
|
+
/** Inside a grid: its column counts, for children that span every column. */
|
|
61
|
+
grid?: { desktop: number; tablet?: number; mobile?: number };
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
type Widget = (s: Settings, ctx: ImportContext, el: string, env: Env, raw: Settings) => N[];
|
|
65
|
+
|
|
66
|
+
export const node = (
|
|
67
|
+
ctx: ImportContext,
|
|
68
|
+
type: string,
|
|
69
|
+
props: Record<string, unknown>,
|
|
70
|
+
extra: Record<string, unknown> = {},
|
|
71
|
+
): N => ({ id: ctx.id(), type, props, ...extra });
|
|
72
|
+
|
|
73
|
+
export const box = (
|
|
74
|
+
ctx: ImportContext,
|
|
75
|
+
children: N[],
|
|
76
|
+
style: Style = {},
|
|
77
|
+
extra: Record<string, unknown> = {},
|
|
78
|
+
): N =>
|
|
79
|
+
node(
|
|
80
|
+
ctx,
|
|
81
|
+
"container",
|
|
82
|
+
{},
|
|
83
|
+
{ style: { gap: { value: 0, unit: "px" }, ...style }, children, ...extra },
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
/** Merges a device-style result into a node. */
|
|
87
|
+
function styled(n: N, ds: { style?: Style; devices?: Record<string, Style> }): N {
|
|
88
|
+
if (ds.style) n["style"] = { ...(n["style"] as Style | undefined), ...ds.style };
|
|
89
|
+
if (ds.devices) n["devices"] = ds.devices;
|
|
90
|
+
return n;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Inline HTML in a title → plain text (and whether markup was dropped). */
|
|
94
|
+
function plain(value: unknown): { text: string; hadMarkup: boolean } {
|
|
95
|
+
const raw = str(value) ?? "";
|
|
96
|
+
const hadMarkup = /<[a-z/!]/i.test(raw);
|
|
97
|
+
const text = cleanText(decodeEntities(raw.replace(/<br\s*\/?>/gi, " ").replace(/<[^>]*>/g, "")));
|
|
98
|
+
return { text, hadMarkup };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const short = (text: string, max = MAX_TEXT_LENGTH) => text.slice(0, max);
|
|
102
|
+
|
|
103
|
+
export function href(value: unknown, ctx: ImportContext): { href?: string; newTab?: boolean } {
|
|
104
|
+
const l = link(value);
|
|
105
|
+
if (!l) return {};
|
|
106
|
+
const safe = ctx.href(l.url);
|
|
107
|
+
return safe ? { href: safe, ...(l.newTab ? { newTab: true } : {}) } : {};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const safeSrc = (url: string) => sanitizeMediaUrl(url.trim());
|
|
111
|
+
|
|
112
|
+
/** Elementor's "{name}" of a dynamic tag on `key`, if the setting is dynamic. */
|
|
113
|
+
export function dynamicTag(s: Settings, key: string): string | undefined {
|
|
114
|
+
const dynamic = s["__dynamic__"];
|
|
115
|
+
const raw = isRecord(dynamic) ? str(dynamic[key]) : undefined;
|
|
116
|
+
return raw ? /name="([a-z0-9_-]{1,64})"/i.exec(raw)?.[1] : undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Text blocks → EmVB nodes. Images without alt get one from the file name (noted). */
|
|
120
|
+
function blockNodes(blocks: readonly Block[], ctx: ImportContext, el: string): N[] {
|
|
121
|
+
const out: N[] = [];
|
|
122
|
+
for (const block of blocks) {
|
|
123
|
+
if (ctx.overBudget) break;
|
|
124
|
+
switch (block.kind) {
|
|
125
|
+
case "heading":
|
|
126
|
+
out.push(
|
|
127
|
+
node(ctx, "heading", {
|
|
128
|
+
text: block.text,
|
|
129
|
+
level: block.level,
|
|
130
|
+
...(block.href ? { href: block.href } : {}),
|
|
131
|
+
...(block.marks ? { marks: block.marks } : {}),
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
break;
|
|
135
|
+
case "text":
|
|
136
|
+
out.push(
|
|
137
|
+
node(ctx, "text", { text: block.text, ...(block.marks ? { marks: block.marks } : {}) }),
|
|
138
|
+
);
|
|
139
|
+
break;
|
|
140
|
+
case "link":
|
|
141
|
+
out.push(node(ctx, "link", { text: block.text, href: block.href }));
|
|
142
|
+
break;
|
|
143
|
+
case "list":
|
|
144
|
+
out.push(
|
|
145
|
+
node(ctx, "list", {
|
|
146
|
+
items: block.items,
|
|
147
|
+
...(block.ordered ? { ordered: true } : {}),
|
|
148
|
+
...(block.start ? { start: block.start } : {}),
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
break;
|
|
152
|
+
case "image": {
|
|
153
|
+
const alt = block.alt || altFromUrl(block.src);
|
|
154
|
+
if (!block.alt)
|
|
155
|
+
ctx.note(
|
|
156
|
+
"approximated",
|
|
157
|
+
el,
|
|
158
|
+
"Images without alt text got one from their file name; check it.",
|
|
159
|
+
);
|
|
160
|
+
ctx.externalImage(block.src);
|
|
161
|
+
out.push(
|
|
162
|
+
node(
|
|
163
|
+
ctx,
|
|
164
|
+
"image",
|
|
165
|
+
{ src: block.src, alt },
|
|
166
|
+
{ style: { maxWidth: { value: 100, unit: "%" } } },
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case "divider":
|
|
172
|
+
out.push(node(ctx, "divider", {}));
|
|
173
|
+
break;
|
|
174
|
+
case "video":
|
|
175
|
+
out.push(node(ctx, "video", { url: block.url, title: "Video" }));
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** HTML content → nodes, noting what was flattened or dropped. */
|
|
183
|
+
function htmlNodes(value: unknown, ctx: ImportContext, el: string): N[] {
|
|
184
|
+
const result = htmlToBlocks(str(value) ?? "", (url) => ctx.href(url), safeSrc);
|
|
185
|
+
if (result.flattened)
|
|
186
|
+
ctx.note(
|
|
187
|
+
"approximated",
|
|
188
|
+
el,
|
|
189
|
+
"Inline formatting (bold, italic, coloured or linked words) became plain text.",
|
|
190
|
+
);
|
|
191
|
+
for (const what of result.dropped) ctx.note("skipped", el, `Left out: ${what}.`);
|
|
192
|
+
return blockNodes(result.blocks, ctx, el);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Several nodes as one: a single node stays itself, more go in a column. */
|
|
196
|
+
function one(ctx: ImportContext, nodes: N[], gap: Style["gap"] = { value: 0, unit: "px" }): N[] {
|
|
197
|
+
if (nodes.length <= 1) return nodes;
|
|
198
|
+
return [box(ctx, nodes, { gap })];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const FA_PREFIX: Record<string, string> = {
|
|
202
|
+
fas: "fa-solid",
|
|
203
|
+
fa: "fa-solid",
|
|
204
|
+
"fa-solid": "fa-solid",
|
|
205
|
+
far: "fa-regular",
|
|
206
|
+
"fa-regular": "fa-regular",
|
|
207
|
+
fab: "fa-brands",
|
|
208
|
+
"fa-brands": "fa-brands",
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/** Font Awesome 4/5 names Elementor still stores → Font Awesome 7 names. */
|
|
212
|
+
const FA_RENAMED: Record<string, string> = {
|
|
213
|
+
times: "xmark",
|
|
214
|
+
close: "xmark",
|
|
215
|
+
"check-circle": "circle-check",
|
|
216
|
+
"times-circle": "circle-xmark",
|
|
217
|
+
"info-circle": "circle-info",
|
|
218
|
+
"question-circle": "circle-question",
|
|
219
|
+
"exclamation-circle": "circle-exclamation",
|
|
220
|
+
"exclamation-triangle": "triangle-exclamation",
|
|
221
|
+
"play-circle": "circle-play",
|
|
222
|
+
"user-circle": "circle-user",
|
|
223
|
+
"arrow-circle-right": "circle-arrow-right",
|
|
224
|
+
"chevron-circle-right": "circle-chevron-right",
|
|
225
|
+
"phone-alt": "phone",
|
|
226
|
+
"phone-square": "square-phone",
|
|
227
|
+
"map-marker": "location-pin",
|
|
228
|
+
"map-marker-alt": "location-dot",
|
|
229
|
+
"external-link-alt": "up-right-from-square",
|
|
230
|
+
"external-link": "arrow-up-right-from-square",
|
|
231
|
+
search: "magnifying-glass",
|
|
232
|
+
home: "house",
|
|
233
|
+
"shopping-cart": "cart-shopping",
|
|
234
|
+
"shopping-bag": "bag-shopping",
|
|
235
|
+
"calendar-alt": "calendar-days",
|
|
236
|
+
"mobile-alt": "mobile-screen-button",
|
|
237
|
+
mobile: "mobile-screen",
|
|
238
|
+
cog: "gear",
|
|
239
|
+
cogs: "gears",
|
|
240
|
+
"envelope-open": "envelope-open",
|
|
241
|
+
"long-arrow-alt-right": "right-long",
|
|
242
|
+
"long-arrow-right": "arrow-right-long",
|
|
243
|
+
"angle-double-right": "angles-right",
|
|
244
|
+
"quote-left": "quote-left",
|
|
245
|
+
"star-half-alt": "star-half-stroke",
|
|
246
|
+
"facebook-square": "square-facebook",
|
|
247
|
+
"twitter-square": "square-twitter",
|
|
248
|
+
"linkedin-in": "linkedin-in",
|
|
249
|
+
"youtube-square": "square-youtube",
|
|
250
|
+
"instagram-square": "square-instagram",
|
|
251
|
+
"pinterest-square": "square-pinterest",
|
|
252
|
+
"whatsapp-square": "square-whatsapp",
|
|
253
|
+
"check-square": "square-check",
|
|
254
|
+
edit: "pen-to-square",
|
|
255
|
+
"trash-alt": "trash-can",
|
|
256
|
+
"sign-out-alt": "right-from-bracket",
|
|
257
|
+
"sign-in-alt": "right-to-bracket",
|
|
258
|
+
"paper-plane": "paper-plane",
|
|
259
|
+
"file-alt": "file-lines",
|
|
260
|
+
"clock-o": "clock",
|
|
261
|
+
"heart-o": "heart",
|
|
262
|
+
"star-o": "star",
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
/** An Elementor icon setting → an EmVB icon id and its SVG from the editor's icon sets. */
|
|
266
|
+
function iconOf(
|
|
267
|
+
value: unknown,
|
|
268
|
+
ctx: ImportContext,
|
|
269
|
+
el: string,
|
|
270
|
+
): { iconId: string; iconSvg: string; name: string } | undefined {
|
|
271
|
+
let classes: string | undefined;
|
|
272
|
+
let library: string | undefined;
|
|
273
|
+
if (isRecord(value)) {
|
|
274
|
+
library = str(value["library"]);
|
|
275
|
+
if (library === "svg") {
|
|
276
|
+
// W-951: the file's markup (fetched or added in the dialog) makes it a recolourable icon.
|
|
277
|
+
const file = isRecord(value["value"]) ? str(value["value"]["url"]) : undefined;
|
|
278
|
+
const url = file ? sanitizeMediaUrl(file) : undefined;
|
|
279
|
+
const markup = url ? ctx.svgMarkup(url) : undefined;
|
|
280
|
+
if (url && markup) return { iconId: svgFileId(url), iconSvg: markup, name: altFromUrl(url) };
|
|
281
|
+
ctx.note(
|
|
282
|
+
"skipped",
|
|
283
|
+
el,
|
|
284
|
+
url
|
|
285
|
+
? "Uploaded SVG icons that couldn't be read are left out; add the .svg files in the import dialog, or pick them again in the editor."
|
|
286
|
+
: "Uploaded SVG icons aren't in the export file; pick them again in the editor.",
|
|
287
|
+
);
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
classes = str(value["value"]);
|
|
291
|
+
} else {
|
|
292
|
+
classes = str(value);
|
|
293
|
+
}
|
|
294
|
+
if (!classes?.trim()) return undefined;
|
|
295
|
+
const tokens = classes.trim().split(/\s+/);
|
|
296
|
+
if (tokens.some((t) => t.startsWith("eicon"))) {
|
|
297
|
+
ctx.note(
|
|
298
|
+
"skipped",
|
|
299
|
+
el,
|
|
300
|
+
"Elementor's own icons (eicons) have no EmVB match; pick a similar icon in the editor.",
|
|
301
|
+
);
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
let prefix = FA_PREFIX[library ?? ""] ?? undefined;
|
|
305
|
+
let name: string | undefined;
|
|
306
|
+
for (const token of tokens) {
|
|
307
|
+
if (FA_PREFIX[token]) prefix ??= FA_PREFIX[token];
|
|
308
|
+
else if (/^fa-[a-z0-9-]+$/.test(token)) name = token.slice(3);
|
|
309
|
+
}
|
|
310
|
+
if (!name) return undefined;
|
|
311
|
+
prefix ??= "fa-solid";
|
|
312
|
+
const candidates = [...new Set([FA_RENAMED[name] ?? name, name])];
|
|
313
|
+
for (const candidate of candidates) {
|
|
314
|
+
for (const p of prefix === "fa-regular" ? [prefix, "fa-solid"] : [prefix]) {
|
|
315
|
+
const id = `${p}:${candidate}`;
|
|
316
|
+
const svg = ctx.icon?.(id);
|
|
317
|
+
if (svg && svg.length <= ICON_SVG_MAX) return { iconId: id, iconSvg: svg, name: candidate };
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
ctx.note(
|
|
321
|
+
"skipped",
|
|
322
|
+
el,
|
|
323
|
+
`Icon "${name}" wasn't found in EmVB's Font Awesome set; pick it again in the editor.`,
|
|
324
|
+
);
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const humanize = (name: string) => {
|
|
329
|
+
const words = name
|
|
330
|
+
.replace(/-(?:alt|square|f|in|o)$/g, "")
|
|
331
|
+
.replace(/[-_]+/g, " ")
|
|
332
|
+
.trim();
|
|
333
|
+
return words ? words.charAt(0).toUpperCase() + words.slice(1) : "Icon";
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/** Left/center/right of a block widget in a column, by auto margins (Elementor's text-align). */
|
|
337
|
+
function align(
|
|
338
|
+
n: N,
|
|
339
|
+
value: unknown,
|
|
340
|
+
env: Env,
|
|
341
|
+
fallback?: "left" | "center" | "right" | "justify",
|
|
342
|
+
): N {
|
|
343
|
+
const where = textAlign(value) ?? fallback;
|
|
344
|
+
if (!where || env.parentRow) return n;
|
|
345
|
+
const style = { ...(n["style"] as Style | undefined) };
|
|
346
|
+
if (where === "justify") {
|
|
347
|
+
style["width"] = { value: 100, unit: "%" };
|
|
348
|
+
} else {
|
|
349
|
+
if (where !== "left" && style["marginLeft"] === undefined) style["marginLeft"] = "auto";
|
|
350
|
+
if (where !== "right" && style["marginRight"] === undefined) style["marginRight"] = "auto";
|
|
351
|
+
}
|
|
352
|
+
n["style"] = style;
|
|
353
|
+
return n;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Image widget-like settings → an image node (or nothing, noted). */
|
|
357
|
+
function imageNode(
|
|
358
|
+
ctx: ImportContext,
|
|
359
|
+
el: string,
|
|
360
|
+
value: unknown,
|
|
361
|
+
extra: Record<string, unknown> = {},
|
|
362
|
+
): N | undefined {
|
|
363
|
+
const img = image(value);
|
|
364
|
+
if (!img) {
|
|
365
|
+
if (isRecord(value) && str(value["url"]))
|
|
366
|
+
ctx.note("skipped", el, "An image with an unsupported address was left out.");
|
|
367
|
+
return undefined;
|
|
368
|
+
}
|
|
369
|
+
if (!img.alt)
|
|
370
|
+
ctx.note("approximated", el, "Images without alt text got one from their file name; check it.");
|
|
371
|
+
ctx.externalImage(img.url);
|
|
372
|
+
return node(ctx, "image", { src: img.url, alt: img.alt ?? altFromUrl(img.url), ...extra });
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// ---------------------------------------------------------------------------------------------
|
|
376
|
+
// Core widgets
|
|
377
|
+
|
|
378
|
+
const SIZES: Record<string, number> = { small: 15, medium: 19, large: 29, xl: 39, xxl: 59 };
|
|
379
|
+
|
|
380
|
+
const heading: Widget = (s, ctx, el) => {
|
|
381
|
+
const tag = str(s["header_size"]) ?? "h2";
|
|
382
|
+
const level = /^h([1-6])$/.exec(tag)?.[1];
|
|
383
|
+
const ds = deviceStyles(s, ctx, el, [
|
|
384
|
+
typographyReader("typography", "primary"),
|
|
385
|
+
textReader("title_color", "primary"),
|
|
386
|
+
]);
|
|
387
|
+
const sized = SIZES[str(s["size"]) ?? ""];
|
|
388
|
+
if (sized && !(ds.style && "fontSize" in ds.style))
|
|
389
|
+
ds.style = { ...ds.style, fontSize: { value: sized, unit: "px" } };
|
|
390
|
+
const dynamic = dynamicTag(s, "title");
|
|
391
|
+
if (dynamic === "post-title" || dynamic === "archive-title" || dynamic === "page-title") {
|
|
392
|
+
return [styled(node(ctx, "post-title", level ? { level: Number(level) } : {}), ds)];
|
|
393
|
+
}
|
|
394
|
+
const { text, hadMarkup } = plain(s["title"]);
|
|
395
|
+
if (!text) return [];
|
|
396
|
+
const linkProps = href(s["link"], ctx);
|
|
397
|
+
// W-950: bold, italic, coloured and linked words stay formatted.
|
|
398
|
+
const marks = hadMarkup ? inlineMarks(str(s["title"]) ?? "", (url) => ctx.href(url), text) : [];
|
|
399
|
+
if (hadMarkup && marks.length === 0)
|
|
400
|
+
ctx.note("approximated", el, "Formatting inside a heading became plain text.");
|
|
401
|
+
if (level)
|
|
402
|
+
return splitLong(text).map((part) =>
|
|
403
|
+
styled(
|
|
404
|
+
node(ctx, "heading", {
|
|
405
|
+
text: part,
|
|
406
|
+
level: Number(level),
|
|
407
|
+
...linkProps,
|
|
408
|
+
...(marks.length > 0 ? { marks } : {}),
|
|
409
|
+
}),
|
|
410
|
+
ds,
|
|
411
|
+
),
|
|
412
|
+
);
|
|
413
|
+
if (linkProps.href) return [styled(node(ctx, "link", { text: short(text), ...linkProps }), ds)];
|
|
414
|
+
return splitLong(text).map((part) =>
|
|
415
|
+
styled(node(ctx, "text", { text: part, tag: tag === "div" ? "div" : "p" }), ds),
|
|
416
|
+
);
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const textEditor: Widget = (s, ctx, el) => {
|
|
420
|
+
const ds = deviceStyles(s, ctx, el, [
|
|
421
|
+
typographyReader("typography", "text"),
|
|
422
|
+
textReader("text_color", "text"),
|
|
423
|
+
]);
|
|
424
|
+
if (str(s["drop_cap"]) === "yes") ctx.note("approximated", el, "Drop caps aren't shown.");
|
|
425
|
+
if ((num(s["text_columns"]) ?? 1) > 1)
|
|
426
|
+
ctx.note("approximated", el, "Text columns are shown as one column.");
|
|
427
|
+
const nodes = htmlNodes(s["editor"], ctx, el);
|
|
428
|
+
if (nodes.length === 0) return [];
|
|
429
|
+
const [only] = nodes;
|
|
430
|
+
if (nodes.length === 1 && only) return [styled(only, ds)];
|
|
431
|
+
return [styled(box(ctx, nodes, { gap: { value: 0.9, unit: "rem" } }), ds)];
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const imageWidget: Widget = (s, ctx, el, env) => {
|
|
435
|
+
const dynamic = dynamicTag(s, "image");
|
|
436
|
+
const caption =
|
|
437
|
+
str(s["caption_source"]) === "custom" ? plain(s["caption"]).text.slice(0, 500) : undefined;
|
|
438
|
+
if (str(s["caption_source"]) === "attachment")
|
|
439
|
+
ctx.note(
|
|
440
|
+
"approximated",
|
|
441
|
+
el,
|
|
442
|
+
"Media-library captions aren't in the export; add the caption in the editor.",
|
|
443
|
+
);
|
|
444
|
+
const linkTo = str(s["link_to"]);
|
|
445
|
+
const img = image(s["image"]);
|
|
446
|
+
const linkProps =
|
|
447
|
+
linkTo === "custom" ? href(s["link"], ctx) : linkTo === "file" && img ? { href: img.url } : {};
|
|
448
|
+
const style: Style = { maxWidth: { value: 100, unit: "%" } };
|
|
449
|
+
const ds = deviceStyles(s, ctx, el, [
|
|
450
|
+
(x, d) => {
|
|
451
|
+
const out: Style = {};
|
|
452
|
+
const width = slider(x[`width${d}`]);
|
|
453
|
+
if (width) out["width"] = width;
|
|
454
|
+
const max = slider(x[`space${d}`]);
|
|
455
|
+
if (max) out["maxWidth"] = max;
|
|
456
|
+
const height = slider(x[`height${d}`]);
|
|
457
|
+
if (height) out["height"] = height;
|
|
458
|
+
const fit = str(x[`object-fit${d}`]);
|
|
459
|
+
if (fit === "cover" || fit === "contain" || fit === "fill") out["objectFit"] = fit;
|
|
460
|
+
return out;
|
|
461
|
+
},
|
|
462
|
+
(x, d, c) => {
|
|
463
|
+
const out: Style = {};
|
|
464
|
+
const radius = x[`image_border_radius${d}`];
|
|
465
|
+
if (radius) Object.assign(out, boxReader("")({ border_radius: radius }, "", c, el));
|
|
466
|
+
const opacity = isRecord(x[`opacity${d}`])
|
|
467
|
+
? num((x[`opacity${d}`] as Settings)["size"])
|
|
468
|
+
: undefined;
|
|
469
|
+
if (opacity !== undefined && opacity >= 0 && opacity <= 1) out["opacity"] = opacity;
|
|
470
|
+
return out;
|
|
471
|
+
},
|
|
472
|
+
]);
|
|
473
|
+
if (dynamic === "post-featured-image") {
|
|
474
|
+
return [align(styled(node(ctx, "post-image", {}, { style }), ds), s["align"], env, "center")];
|
|
475
|
+
}
|
|
476
|
+
const n = imageNode(ctx, el, s["image"], { ...(caption ? { caption } : {}), ...linkProps });
|
|
477
|
+
if (!n) return [];
|
|
478
|
+
n["style"] = style;
|
|
479
|
+
if (str(s["hover_animation"])) ctx.note("approximated", el, "Hover animations aren't imported.");
|
|
480
|
+
return [align(styled(n, ds), s["align"], env, "center")];
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
const SMALL_BUTTON = { pad: [12, 24] as [number, number], font: 15 };
|
|
484
|
+
const BUTTON_SIZES: Record<string, { pad: [number, number]; font: number }> = {
|
|
485
|
+
xs: { pad: [10, 20], font: 13 },
|
|
486
|
+
sm: { pad: [12, 24], font: 15 },
|
|
487
|
+
md: { pad: [15, 30], font: 16 },
|
|
488
|
+
lg: { pad: [20, 40], font: 18 },
|
|
489
|
+
xl: { pad: [25, 50], font: 20 },
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
/** A button with Elementor's look: accent background, white text, 3px corners. */
|
|
493
|
+
function buttonNode(
|
|
494
|
+
s: Settings,
|
|
495
|
+
ctx: ImportContext,
|
|
496
|
+
el: string,
|
|
497
|
+
keys: { text: string; link: string; icon?: string } = {
|
|
498
|
+
text: "text",
|
|
499
|
+
link: "link",
|
|
500
|
+
icon: "selected_icon",
|
|
501
|
+
},
|
|
502
|
+
): N | undefined {
|
|
503
|
+
const text = short(plain(s[keys.text]).text);
|
|
504
|
+
if (!text) return undefined;
|
|
505
|
+
const size = BUTTON_SIZES[str(s["size"]) ?? "sm"] ?? SMALL_BUTTON;
|
|
506
|
+
const base: Style = {
|
|
507
|
+
paddingTop: { value: size.pad[0], unit: "px" },
|
|
508
|
+
paddingBottom: { value: size.pad[0], unit: "px" },
|
|
509
|
+
paddingLeft: { value: size.pad[1], unit: "px" },
|
|
510
|
+
paddingRight: { value: size.pad[1], unit: "px" },
|
|
511
|
+
fontSize: { value: size.font, unit: "px" },
|
|
512
|
+
lineHeight: 1,
|
|
513
|
+
borderRadius: { value: 3, unit: "px" },
|
|
514
|
+
borderStyle: "none",
|
|
515
|
+
color: "#ffffff",
|
|
516
|
+
};
|
|
517
|
+
if (ctx.useDefaults) {
|
|
518
|
+
const accent = ctx.globalColor("accent");
|
|
519
|
+
if (accent) base["backgroundColor"] = accent;
|
|
520
|
+
}
|
|
521
|
+
const textColor: Reader = (x, d, c) => {
|
|
522
|
+
const out: Style = {};
|
|
523
|
+
const fill = colorAt(x, "button_text_color", c, d);
|
|
524
|
+
if (fill) out["color"] = fill;
|
|
525
|
+
const bg = colorAt(x, "background_color", c, d) ?? colorAt(x, "button_background_color", c, d);
|
|
526
|
+
if (bg) out["backgroundColor"] = bg;
|
|
527
|
+
const pad: Style = {};
|
|
528
|
+
for (const [k, v] of Object.entries(
|
|
529
|
+
boxReader("")({ padding: x[`text_padding${d}`] }, "", c, el),
|
|
530
|
+
))
|
|
531
|
+
pad[k] = v;
|
|
532
|
+
return { ...out, ...pad };
|
|
533
|
+
};
|
|
534
|
+
const ds = deviceStyles(s, ctx, el, [
|
|
535
|
+
typographyReader("typography", "accent"),
|
|
536
|
+
(x, d, c) => {
|
|
537
|
+
// Border, radius and shadow of the button itself (its padding is `text_padding`).
|
|
538
|
+
const out = boxReader("")(
|
|
539
|
+
{ ...x, padding: undefined, margin: undefined, background_background: undefined },
|
|
540
|
+
d,
|
|
541
|
+
c,
|
|
542
|
+
el,
|
|
543
|
+
);
|
|
544
|
+
return out;
|
|
545
|
+
},
|
|
546
|
+
textColor,
|
|
547
|
+
]);
|
|
548
|
+
const n = node(
|
|
549
|
+
ctx,
|
|
550
|
+
"button",
|
|
551
|
+
{ text, ...href(s[keys.link], ctx) },
|
|
552
|
+
{ style: { ...base, ...ds.style } },
|
|
553
|
+
);
|
|
554
|
+
if (ds.devices) n["devices"] = ds.devices;
|
|
555
|
+
const hover: Style = {};
|
|
556
|
+
const hoverText = colorAt(s, "hover_color", ctx);
|
|
557
|
+
if (hoverText) hover["color"] = hoverText;
|
|
558
|
+
const hoverBg = colorAt(s, "button_background_hover_color", ctx);
|
|
559
|
+
if (hoverBg) hover["backgroundColor"] = hoverBg;
|
|
560
|
+
const hoverBorder = colorAt(s, "button_hover_border_color", ctx);
|
|
561
|
+
if (hoverBorder) hover["borderColor"] = hoverBorder;
|
|
562
|
+
if (Object.keys(hover).length > 0) n["states"] = { hover };
|
|
563
|
+
const icon = keys.icon ? iconOf(s[keys.icon] ?? s["icon"], ctx, el) : undefined;
|
|
564
|
+
if (icon) {
|
|
565
|
+
const props = n.props;
|
|
566
|
+
props["iconId"] = icon.iconId;
|
|
567
|
+
props["iconSvg"] = icon.iconSvg;
|
|
568
|
+
const position = str(s["icon_align"]);
|
|
569
|
+
props["iconPosition"] = position === "right" || position === "row-reverse" ? "after" : "before";
|
|
570
|
+
const gap = slider(s["icon_indent"]);
|
|
571
|
+
if (gap && gap.unit === "px")
|
|
572
|
+
props["iconGap"] = Math.min(64, Math.max(0, Math.round(gap.value)));
|
|
573
|
+
}
|
|
574
|
+
return n;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const button: Widget = (s, ctx, el, env) => {
|
|
578
|
+
const n = buttonNode(s, ctx, el);
|
|
579
|
+
return n ? [align(n, s["align"], env, "left")] : [];
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
const spacer: Widget = (s, ctx) => {
|
|
583
|
+
const height = slider(s["space"]) ?? { value: 50, unit: "px" as const };
|
|
584
|
+
const n = node(ctx, "spacer", { height });
|
|
585
|
+
const tablet = slider(s["space_tablet"]);
|
|
586
|
+
const mobile = slider(s["space_mobile"]);
|
|
587
|
+
if (tablet || mobile) {
|
|
588
|
+
n["devices"] = {
|
|
589
|
+
...(tablet ? { tablet: { height: tablet } } : {}),
|
|
590
|
+
...(mobile ? { mobile: { height: mobile } } : {}),
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
return [n];
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
const divider: Widget = (s, ctx, el, env) => {
|
|
597
|
+
const style: Style = {};
|
|
598
|
+
const kind = str(s["style"]) ?? "solid";
|
|
599
|
+
if (kind === "dashed" || kind === "dotted" || kind === "solid") style["borderStyle"] = kind;
|
|
600
|
+
else {
|
|
601
|
+
style["borderStyle"] = "solid";
|
|
602
|
+
ctx.note("approximated", el, `Divider pattern "${kind}" is shown as a solid line.`);
|
|
603
|
+
}
|
|
604
|
+
style["borderTopWidth"] = slider(s["weight"]) ?? { value: 1, unit: "px" };
|
|
605
|
+
const fill =
|
|
606
|
+
colorAt(s, "color", ctx) ?? (ctx.useDefaults ? ctx.globalColor("secondary") : undefined);
|
|
607
|
+
if (fill) style["color"] = fill;
|
|
608
|
+
const width = slider(s["width"]);
|
|
609
|
+
if (width) style["width"] = width;
|
|
610
|
+
const gap = slider(s["gap"]) ?? { value: 15, unit: "px" as const };
|
|
611
|
+
style["marginTop"] = gap;
|
|
612
|
+
style["marginBottom"] = gap;
|
|
613
|
+
if (str(s["look"]) && str(s["look"]) !== "line")
|
|
614
|
+
ctx.note("approximated", el, "A divider's text or icon was left out.");
|
|
615
|
+
return [align(node(ctx, "divider", {}, { style }), s["align"], env, "left")];
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
/** An Icon widget's icon, with Elementor's stacked/framed looks. */
|
|
619
|
+
function iconNode(
|
|
620
|
+
s: Settings,
|
|
621
|
+
ctx: ImportContext,
|
|
622
|
+
el: string,
|
|
623
|
+
key = "selected_icon",
|
|
624
|
+
fallbackColor = "primary",
|
|
625
|
+
): N | undefined {
|
|
626
|
+
const icon = iconOf(s[key] ?? s["icon"], ctx, el);
|
|
627
|
+
if (!icon) return undefined;
|
|
628
|
+
const size = slider(s["size"]);
|
|
629
|
+
const pxSize = size && size.unit === "px" ? Math.round(size.value) : 50;
|
|
630
|
+
const linkProps = href(s["link"], ctx);
|
|
631
|
+
const fill =
|
|
632
|
+
colorAt(s, "primary_color", ctx) ??
|
|
633
|
+
(ctx.useDefaults ? ctx.globalColor(fallbackColor) : undefined);
|
|
634
|
+
const style: Style = {};
|
|
635
|
+
const view = str(s["view"]);
|
|
636
|
+
if (view === "stacked") {
|
|
637
|
+
if (fill) style["backgroundColor"] = fill;
|
|
638
|
+
style["color"] = colorAt(s, "secondary_color", ctx) ?? "#ffffff";
|
|
639
|
+
} else if (fill) {
|
|
640
|
+
style["color"] = fill;
|
|
641
|
+
}
|
|
642
|
+
if (view === "framed") {
|
|
643
|
+
style["borderStyle"] = "solid";
|
|
644
|
+
style["borderWidth"] = { value: 3, unit: "px" };
|
|
645
|
+
if (fill) style["borderColor"] = fill;
|
|
646
|
+
}
|
|
647
|
+
if (view === "stacked" || view === "framed") {
|
|
648
|
+
const pad = slider(s["icon_padding"]) ?? { value: 0.5, unit: "em" as const };
|
|
649
|
+
for (const side of ["Top", "Right", "Bottom", "Left"]) style[`padding${side}`] = pad;
|
|
650
|
+
style["borderRadius"] =
|
|
651
|
+
str(s["shape"]) === "square" ? { value: 0, unit: "px" } : { value: 50, unit: "%" };
|
|
652
|
+
}
|
|
653
|
+
return node(
|
|
654
|
+
ctx,
|
|
655
|
+
"icon",
|
|
656
|
+
{
|
|
657
|
+
iconId: icon.iconId,
|
|
658
|
+
iconSvg: icon.iconSvg,
|
|
659
|
+
size: Math.min(512, Math.max(1, pxSize)),
|
|
660
|
+
...(linkProps.href ? { ...linkProps, title: humanize(icon.name) } : { decorative: true }),
|
|
661
|
+
},
|
|
662
|
+
{ style },
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const iconWidget: Widget = (s, ctx, el, env) => {
|
|
667
|
+
const n = iconNode(s, ctx, el);
|
|
668
|
+
return n ? [align(n, s["align"], env, "center")] : [];
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
/** Icon Box / Image Box: media, then a title and a description. */
|
|
672
|
+
function mediaBox(media: N | undefined, s: Settings, ctx: ImportContext, el: string): N[] {
|
|
673
|
+
const titleTag = str(s["title_size"]) ?? "h3";
|
|
674
|
+
const level = Number(/^h([1-6])$/.exec(titleTag)?.[1] ?? 3);
|
|
675
|
+
const title = plain(s["title_text"]).text;
|
|
676
|
+
const description = plain(s["description_text"]).text;
|
|
677
|
+
const linkProps = href(s["link"], ctx);
|
|
678
|
+
const children: N[] = [];
|
|
679
|
+
if (title) {
|
|
680
|
+
children.push(
|
|
681
|
+
styled(
|
|
682
|
+
node(ctx, "heading", { text: short(title), level, ...linkProps }),
|
|
683
|
+
deviceStyles(s, ctx, el, [
|
|
684
|
+
typographyReader("title_typography", "primary"),
|
|
685
|
+
textReader("title_color", "primary", "text_align"),
|
|
686
|
+
]),
|
|
687
|
+
),
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
if (description) {
|
|
691
|
+
children.push(
|
|
692
|
+
styled(
|
|
693
|
+
node(ctx, "text", { text: short(description) }),
|
|
694
|
+
deviceStyles(s, ctx, el, [
|
|
695
|
+
typographyReader("description_typography", "text"),
|
|
696
|
+
textReader("description_color", "text", "text_align"),
|
|
697
|
+
]),
|
|
698
|
+
),
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
const position = str(s["position"]) ?? "top";
|
|
702
|
+
const side = position === "left" || position === "right";
|
|
703
|
+
const content = box(ctx, children, { gap: { value: 10, unit: "px" } });
|
|
704
|
+
const parts = media ? (position === "right" ? [content, media] : [media, content]) : [content];
|
|
705
|
+
const where = textAlign(s["text_align"]) ?? (side ? "left" : "center");
|
|
706
|
+
return [
|
|
707
|
+
box(ctx, parts, {
|
|
708
|
+
flexDirection: side ? "row" : "column",
|
|
709
|
+
gap: { value: 15, unit: "px" },
|
|
710
|
+
alignItems: side
|
|
711
|
+
? "flex-start"
|
|
712
|
+
: where === "left"
|
|
713
|
+
? "flex-start"
|
|
714
|
+
: where === "right"
|
|
715
|
+
? "flex-end"
|
|
716
|
+
: "center",
|
|
717
|
+
textAlign: where,
|
|
718
|
+
}),
|
|
719
|
+
];
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
const iconBox: Widget = (s, ctx, el) => mediaBox(iconNode(s, ctx, el), s, ctx, el);
|
|
723
|
+
|
|
724
|
+
const imageBox: Widget = (s, ctx, el) => {
|
|
725
|
+
const img = imageNode(ctx, el, s["image"]);
|
|
726
|
+
if (img) {
|
|
727
|
+
const width = slider(s["image_size"]);
|
|
728
|
+
img["style"] = {
|
|
729
|
+
width: width ? { value: width.value, unit: "%" } : { value: 30, unit: "%" },
|
|
730
|
+
maxWidth: { value: 100, unit: "%" },
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
return mediaBox(img, s, ctx, el);
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
const iconList: Widget = (s, ctx, el) => {
|
|
737
|
+
const items = Array.isArray(s["icon_list"]) ? s["icon_list"].slice(0, 200) : [];
|
|
738
|
+
const inline = str(s["view"]) === "inline";
|
|
739
|
+
const textStyle = deviceStyles(s, ctx, el, [
|
|
740
|
+
typographyReader("icon_typography", "text"),
|
|
741
|
+
textReader("text_color", "secondary"),
|
|
742
|
+
]);
|
|
743
|
+
const iconColor =
|
|
744
|
+
colorAt(s, "icon_color", ctx) ?? (ctx.useDefaults ? ctx.globalColor("primary") : undefined);
|
|
745
|
+
const iconSize = slider(s["icon_size"]);
|
|
746
|
+
const rows: N[] = [];
|
|
747
|
+
for (const raw of items) {
|
|
748
|
+
if (!isRecord(raw) || ctx.overBudget) continue;
|
|
749
|
+
const text = short(plain(raw["text"]).text);
|
|
750
|
+
if (!text) continue;
|
|
751
|
+
const linkProps = href(raw["link"], ctx);
|
|
752
|
+
const label = linkProps.href
|
|
753
|
+
? node(ctx, "link", { text, ...linkProps })
|
|
754
|
+
: node(ctx, "text", { text });
|
|
755
|
+
styled(label, textStyle);
|
|
756
|
+
const icon = iconOf(raw["selected_icon"] ?? raw["icon"], ctx, el);
|
|
757
|
+
const parts: N[] = [];
|
|
758
|
+
if (icon) {
|
|
759
|
+
parts.push(
|
|
760
|
+
node(
|
|
761
|
+
ctx,
|
|
762
|
+
"icon",
|
|
763
|
+
{
|
|
764
|
+
iconId: icon.iconId,
|
|
765
|
+
iconSvg: icon.iconSvg,
|
|
766
|
+
decorative: true,
|
|
767
|
+
size: iconSize && iconSize.unit === "px" ? Math.round(iconSize.value) : 14,
|
|
768
|
+
},
|
|
769
|
+
iconColor ? { style: { color: iconColor } } : {},
|
|
770
|
+
),
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
parts.push(label);
|
|
774
|
+
rows.push(
|
|
775
|
+
parts.length === 1
|
|
776
|
+
? label
|
|
777
|
+
: box(ctx, parts, {
|
|
778
|
+
flexDirection: "row",
|
|
779
|
+
alignItems: "center",
|
|
780
|
+
gap: { value: 5, unit: "px" },
|
|
781
|
+
}),
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
if (rows.length === 0) return [];
|
|
785
|
+
const space = slider(s["space_between"]);
|
|
786
|
+
return [
|
|
787
|
+
box(ctx, rows, {
|
|
788
|
+
flexDirection: inline ? "row" : "column",
|
|
789
|
+
...(inline ? { flexWrap: "wrap" } : {}),
|
|
790
|
+
gap: space ?? { value: inline ? 16 : 8, unit: "px" },
|
|
791
|
+
}),
|
|
792
|
+
];
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
const video: Widget = (s, ctx, el) => {
|
|
796
|
+
const type = str(s["video_type"]) ?? "youtube";
|
|
797
|
+
let url: string | undefined;
|
|
798
|
+
if (type === "youtube") url = str(s["youtube_url"]);
|
|
799
|
+
else if (type === "vimeo") url = str(s["vimeo_url"]);
|
|
800
|
+
else if (type === "hosted")
|
|
801
|
+
url = link(s["insert_url"] === "yes" ? s["external_url"] : s["hosted_url"])?.url;
|
|
802
|
+
else {
|
|
803
|
+
ctx.note("skipped", el, `${type} videos aren't supported; use YouTube, Vimeo or a video file.`);
|
|
804
|
+
return [];
|
|
805
|
+
}
|
|
806
|
+
const embedded = url ? (embedVideoUrl(url) ?? url) : undefined;
|
|
807
|
+
const safe = embedded ? sanitizeHref(embedded) : undefined;
|
|
808
|
+
if (!safe) return [];
|
|
809
|
+
return [node(ctx, "video", { url: safe, title: "Video" })];
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
const counter: Widget = (s, ctx, el) => {
|
|
813
|
+
const end = num(s["ending_number"]) ?? 100;
|
|
814
|
+
const separator =
|
|
815
|
+
str(s["thousand_separator"]) !== "" && s["thousand_separator"] !== undefined
|
|
816
|
+
? (str(s["thousand_separator_char"]) ?? ",")
|
|
817
|
+
: "";
|
|
818
|
+
const digits = String(Math.trunc(Math.abs(end))).replace(
|
|
819
|
+
/\B(?=(\d{3})+(?!\d))/g,
|
|
820
|
+
separator === "space" ? " " : separator,
|
|
821
|
+
);
|
|
822
|
+
const number = `${plain(s["prefix"]).text}${end < 0 ? "-" : ""}${digits}${plain(s["suffix"]).text}`;
|
|
823
|
+
ctx.note("approximated", el, "Counters show their final number, without the counting animation.");
|
|
824
|
+
const children = [
|
|
825
|
+
styled(
|
|
826
|
+
node(
|
|
827
|
+
ctx,
|
|
828
|
+
"text",
|
|
829
|
+
{ text: short(number), tag: "div" },
|
|
830
|
+
{ style: { fontSize: { value: 69, unit: "px" }, fontWeight: 600, lineHeight: 1 } },
|
|
831
|
+
),
|
|
832
|
+
deviceStyles(s, ctx, el, [
|
|
833
|
+
typographyReader("typography_number", "primary"),
|
|
834
|
+
textReader("number_color", "primary"),
|
|
835
|
+
]),
|
|
836
|
+
),
|
|
837
|
+
];
|
|
838
|
+
const title = plain(s["title"]).text;
|
|
839
|
+
if (title) {
|
|
840
|
+
children.push(
|
|
841
|
+
styled(
|
|
842
|
+
node(
|
|
843
|
+
ctx,
|
|
844
|
+
"text",
|
|
845
|
+
{ text: short(title), tag: "div" },
|
|
846
|
+
{ style: { fontSize: { value: 19, unit: "px" } } },
|
|
847
|
+
),
|
|
848
|
+
deviceStyles(s, ctx, el, [
|
|
849
|
+
typographyReader("typography_title", "secondary"),
|
|
850
|
+
textReader("title_color", "secondary"),
|
|
851
|
+
]),
|
|
852
|
+
),
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
return [
|
|
856
|
+
box(ctx, children, {
|
|
857
|
+
alignItems: "center",
|
|
858
|
+
textAlign: "center",
|
|
859
|
+
gap: { value: 5, unit: "px" },
|
|
860
|
+
}),
|
|
861
|
+
];
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
const progress: Widget = (s, ctx, el) => {
|
|
865
|
+
const percent = Math.min(
|
|
866
|
+
100,
|
|
867
|
+
Math.max(
|
|
868
|
+
0,
|
|
869
|
+
Math.round(num(isRecord(s["percent"]) ? s["percent"]["size"] : s["percent"]) ?? 50),
|
|
870
|
+
),
|
|
871
|
+
);
|
|
872
|
+
const bar =
|
|
873
|
+
colorAt(s, "bar_color", ctx) ??
|
|
874
|
+
(ctx.useDefaults ? ctx.globalColor("primary") : undefined) ??
|
|
875
|
+
"#6ec1e4";
|
|
876
|
+
const children: N[] = [];
|
|
877
|
+
const title = plain(s["title"]).text;
|
|
878
|
+
if (title) children.push(node(ctx, "text", { text: short(title), tag: "div" }));
|
|
879
|
+
const inner = plain(s["inner_text"]).text;
|
|
880
|
+
const fill = box(
|
|
881
|
+
ctx,
|
|
882
|
+
inner
|
|
883
|
+
? [
|
|
884
|
+
node(
|
|
885
|
+
ctx,
|
|
886
|
+
"text",
|
|
887
|
+
{ text: short(inner), tag: "div" },
|
|
888
|
+
{
|
|
889
|
+
style: {
|
|
890
|
+
color: "#ffffff",
|
|
891
|
+
paddingLeft: { value: 15, unit: "px" },
|
|
892
|
+
lineHeight: { value: 30, unit: "px" },
|
|
893
|
+
},
|
|
894
|
+
},
|
|
895
|
+
),
|
|
896
|
+
]
|
|
897
|
+
: [],
|
|
898
|
+
{
|
|
899
|
+
width: { value: percent, unit: "%" },
|
|
900
|
+
minHeight: { value: 30, unit: "px" },
|
|
901
|
+
backgroundColor: bar,
|
|
902
|
+
justifyContent: "center",
|
|
903
|
+
},
|
|
904
|
+
);
|
|
905
|
+
children.push(
|
|
906
|
+
box(ctx, [fill], {
|
|
907
|
+
backgroundColor: colorAt(s, "bar_bg_color", ctx) ?? "#eeeeee",
|
|
908
|
+
minHeight: { value: 30, unit: "px" },
|
|
909
|
+
}),
|
|
910
|
+
);
|
|
911
|
+
ctx.note("approximated", el, "Progress bars are shown filled, without their animation.");
|
|
912
|
+
return [box(ctx, children, { gap: { value: 8, unit: "px" } })];
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
const testimonial: Widget = (s, ctx, el) => {
|
|
916
|
+
const children: N[] = [];
|
|
917
|
+
const content = plain(s["testimonial_content"]).text;
|
|
918
|
+
if (content) {
|
|
919
|
+
children.push(
|
|
920
|
+
styled(
|
|
921
|
+
node(
|
|
922
|
+
ctx,
|
|
923
|
+
"text",
|
|
924
|
+
{ text: short(content) },
|
|
925
|
+
{ style: { fontSize: { value: 1.3, unit: "em" } } },
|
|
926
|
+
),
|
|
927
|
+
deviceStyles(s, ctx, el, [
|
|
928
|
+
typographyReader("content_typography", "text"),
|
|
929
|
+
textReader("content_content_color", "text"),
|
|
930
|
+
]),
|
|
931
|
+
),
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
const img = imageNode(ctx, el, s["testimonial_image"]);
|
|
935
|
+
if (img) {
|
|
936
|
+
img["style"] = {
|
|
937
|
+
width: { value: 60, unit: "px" },
|
|
938
|
+
height: { value: 60, unit: "px" },
|
|
939
|
+
borderRadius: { value: 50, unit: "%" },
|
|
940
|
+
objectFit: "cover",
|
|
941
|
+
};
|
|
942
|
+
children.push(img);
|
|
943
|
+
}
|
|
944
|
+
const name = plain(s["testimonial_name"]).text;
|
|
945
|
+
if (name)
|
|
946
|
+
children.push(
|
|
947
|
+
styled(
|
|
948
|
+
node(ctx, "text", { text: short(name), tag: "div" }, { style: { fontWeight: "bold" } }),
|
|
949
|
+
deviceStyles(s, ctx, el, [textReader("name_text_color", "primary")]),
|
|
950
|
+
),
|
|
951
|
+
);
|
|
952
|
+
const job = plain(s["testimonial_job"]).text;
|
|
953
|
+
if (job)
|
|
954
|
+
children.push(
|
|
955
|
+
styled(
|
|
956
|
+
node(ctx, "text", { text: short(job), tag: "div" }),
|
|
957
|
+
deviceStyles(s, ctx, el, [textReader("job_text_color", "secondary")]),
|
|
958
|
+
),
|
|
959
|
+
);
|
|
960
|
+
if (children.length === 0) return [];
|
|
961
|
+
const where = textAlign(s["testimonial_alignment"]) ?? "center";
|
|
962
|
+
return [
|
|
963
|
+
box(ctx, children, {
|
|
964
|
+
gap: { value: 15, unit: "px" },
|
|
965
|
+
textAlign: where,
|
|
966
|
+
alignItems: where === "left" ? "flex-start" : where === "right" ? "flex-end" : "center",
|
|
967
|
+
}),
|
|
968
|
+
];
|
|
969
|
+
};
|
|
970
|
+
|
|
971
|
+
const starRating: Widget = (s, ctx, el) => {
|
|
972
|
+
const scale = Math.min(10, Math.max(1, Math.round(num(s["rating_scale"]) ?? 5)));
|
|
973
|
+
const rating = Math.min(
|
|
974
|
+
scale,
|
|
975
|
+
Math.max(0, num(isRecord(s["rating"]) ? s["rating"]["size"] : s["rating"]) ?? scale),
|
|
976
|
+
);
|
|
977
|
+
const full = Math.round(rating);
|
|
978
|
+
const stars = `${"★".repeat(full)}${"☆".repeat(scale - full)}`;
|
|
979
|
+
const title = plain(s["title"]).text;
|
|
980
|
+
ctx.note("approximated", el, "Star ratings are shown as star characters.");
|
|
981
|
+
return [
|
|
982
|
+
node(
|
|
983
|
+
ctx,
|
|
984
|
+
"text",
|
|
985
|
+
{ text: short(`${title ? `${title} ` : ""}${stars} (${rating}/${scale})`) },
|
|
986
|
+
{
|
|
987
|
+
style: { color: colorAt(s, "stars_color", ctx) ?? "#f0ad4e" },
|
|
988
|
+
},
|
|
989
|
+
),
|
|
990
|
+
];
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
const INFO_ALERT: [string, string, string] = ["#d9edf7", "#bcdff1", "#31708f"];
|
|
994
|
+
const ALERTS: Record<string, [string, string, string]> = {
|
|
995
|
+
info: ["#d9edf7", "#bcdff1", "#31708f"],
|
|
996
|
+
success: ["#dff0d8", "#cae6be", "#3c763d"],
|
|
997
|
+
warning: ["#fcf8e3", "#f9f0c3", "#8a6d3b"],
|
|
998
|
+
danger: ["#f2dede", "#e8c4c4", "#a94442"],
|
|
999
|
+
};
|
|
1000
|
+
|
|
1001
|
+
const alert: Widget = (s, ctx, el) => {
|
|
1002
|
+
const [bg, border, ink] = ALERTS[str(s["alert_type"]) ?? "info"] ?? INFO_ALERT;
|
|
1003
|
+
const children: N[] = [];
|
|
1004
|
+
const title = plain(s["alert_title"]).text;
|
|
1005
|
+
if (title)
|
|
1006
|
+
children.push(
|
|
1007
|
+
node(ctx, "text", { text: short(title), tag: "div" }, { style: { fontWeight: "bold" } }),
|
|
1008
|
+
);
|
|
1009
|
+
const description = plain(s["alert_description"]).text;
|
|
1010
|
+
if (description) children.push(node(ctx, "text", { text: short(description) }));
|
|
1011
|
+
if (children.length === 0) return [];
|
|
1012
|
+
if (str(s["show_dismiss"]) === "show") ctx.note("approximated", el, "Alerts can't be dismissed.");
|
|
1013
|
+
return [
|
|
1014
|
+
box(ctx, children, {
|
|
1015
|
+
gap: { value: 5, unit: "px" },
|
|
1016
|
+
backgroundColor: colorAt(s, "background", ctx) ?? bg,
|
|
1017
|
+
borderStyle: "solid",
|
|
1018
|
+
borderLeftWidth: { value: 5, unit: "px" },
|
|
1019
|
+
borderColor: colorAt(s, "border_color", ctx) ?? border,
|
|
1020
|
+
color: colorAt(s, "title_color", ctx) ?? ink,
|
|
1021
|
+
paddingTop: { value: 15, unit: "px" },
|
|
1022
|
+
paddingBottom: { value: 15, unit: "px" },
|
|
1023
|
+
paddingLeft: { value: 15, unit: "px" },
|
|
1024
|
+
paddingRight: { value: 15, unit: "px" },
|
|
1025
|
+
}),
|
|
1026
|
+
];
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
const html: Widget = (s, ctx, el) => {
|
|
1030
|
+
const nodes = htmlNodes(s["html"], ctx, el);
|
|
1031
|
+
ctx.note(
|
|
1032
|
+
"approximated",
|
|
1033
|
+
el,
|
|
1034
|
+
"Custom HTML became plain EmVB elements; scripts, styles and markup were left out.",
|
|
1035
|
+
);
|
|
1036
|
+
return one(ctx, nodes, { value: 16, unit: "px" });
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
const menuAnchor: Widget = (s, ctx, el) => {
|
|
1040
|
+
const anchor = str(s["anchor"])?.trim().replace(/\s+/g, "-") ?? "";
|
|
1041
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(anchor)) {
|
|
1042
|
+
if (anchor)
|
|
1043
|
+
ctx.note(
|
|
1044
|
+
"skipped",
|
|
1045
|
+
el,
|
|
1046
|
+
`Anchor "${anchor.slice(0, 40)}" isn't a valid id; add it in the editor.`,
|
|
1047
|
+
);
|
|
1048
|
+
return [];
|
|
1049
|
+
}
|
|
1050
|
+
if (ctx.htmlIds.has(anchor)) return [];
|
|
1051
|
+
ctx.htmlIds.add(anchor);
|
|
1052
|
+
return [box(ctx, [], {}, { htmlId: anchor, editorLabel: `Anchor ${anchor}`.slice(0, 80) })];
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1055
|
+
const googleMaps: Widget = (s, ctx, el) => {
|
|
1056
|
+
const address = plain(s["address"]).text;
|
|
1057
|
+
ctx.note("approximated", el, "Google Maps embeds became a link to the map.");
|
|
1058
|
+
if (!address) return [];
|
|
1059
|
+
return [
|
|
1060
|
+
node(ctx, "link", {
|
|
1061
|
+
text: short(`View map: ${address}`),
|
|
1062
|
+
href: `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(address.slice(0, 500))}`,
|
|
1063
|
+
newTab: true,
|
|
1064
|
+
}),
|
|
1065
|
+
];
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
/** Galleries and carousels → a grid of images. */
|
|
1069
|
+
function gallery(
|
|
1070
|
+
list: unknown,
|
|
1071
|
+
columns: number,
|
|
1072
|
+
ctx: ImportContext,
|
|
1073
|
+
el: string,
|
|
1074
|
+
imageKey?: string,
|
|
1075
|
+
): N[] {
|
|
1076
|
+
const items = Array.isArray(list) ? list.slice(0, 100) : [];
|
|
1077
|
+
const images: N[] = [];
|
|
1078
|
+
for (const item of items) {
|
|
1079
|
+
if (ctx.overBudget) break;
|
|
1080
|
+
const value = imageKey && isRecord(item) ? item[imageKey] : item;
|
|
1081
|
+
const n = imageNode(ctx, el, value);
|
|
1082
|
+
if (n) {
|
|
1083
|
+
n["style"] = { width: { value: 100, unit: "%" }, height: "auto", objectFit: "cover" };
|
|
1084
|
+
images.push(n);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
if (images.length === 0) return [];
|
|
1088
|
+
return [
|
|
1089
|
+
node(
|
|
1090
|
+
ctx,
|
|
1091
|
+
"grid",
|
|
1092
|
+
{ columns: Math.min(12, Math.max(1, Math.round(columns))) },
|
|
1093
|
+
{
|
|
1094
|
+
style: { gap: { value: 10, unit: "px" } },
|
|
1095
|
+
children: images,
|
|
1096
|
+
},
|
|
1097
|
+
),
|
|
1098
|
+
];
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
const imageGallery: Widget = (s, ctx, el) =>
|
|
1102
|
+
gallery(s["wp_gallery"], num(s["gallery_columns"]) ?? 4, ctx, el);
|
|
1103
|
+
const proGallery: Widget = (s, ctx, el) => gallery(s["gallery"], num(s["columns"]) ?? 4, ctx, el);
|
|
1104
|
+
const imageCarousel: Widget = (s, ctx, el) => {
|
|
1105
|
+
ctx.note("approximated", el, "Carousels are shown as a grid of their slides.");
|
|
1106
|
+
return gallery(s["carousel"], num(s["slides_to_show"]) ?? 3, ctx, el);
|
|
1107
|
+
};
|
|
1108
|
+
const mediaCarousel: Widget = (s, ctx, el) => {
|
|
1109
|
+
ctx.note("approximated", el, "Carousels are shown as a grid of their slides.");
|
|
1110
|
+
return gallery(s["slides"], num(s["slides_per_view"]) ?? 3, ctx, el, "image");
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
const BRANDS: Record<string, string> = {
|
|
1114
|
+
facebook: "#3b5998",
|
|
1115
|
+
"facebook-f": "#3b5998",
|
|
1116
|
+
twitter: "#1da1f2",
|
|
1117
|
+
"x-twitter": "#000000",
|
|
1118
|
+
instagram: "#262626",
|
|
1119
|
+
youtube: "#cd201f",
|
|
1120
|
+
linkedin: "#0077b5",
|
|
1121
|
+
"linkedin-in": "#0077b5",
|
|
1122
|
+
pinterest: "#bd081c",
|
|
1123
|
+
"pinterest-p": "#bd081c",
|
|
1124
|
+
tiktok: "#000000",
|
|
1125
|
+
whatsapp: "#25d366",
|
|
1126
|
+
github: "#333333",
|
|
1127
|
+
dribbble: "#ea4c89",
|
|
1128
|
+
behance: "#1769ff",
|
|
1129
|
+
vimeo: "#1ab7ea",
|
|
1130
|
+
"vimeo-v": "#1ab7ea",
|
|
1131
|
+
telegram: "#2ca5e0",
|
|
1132
|
+
reddit: "#ff4500",
|
|
1133
|
+
snapchat: "#fffc00",
|
|
1134
|
+
spotify: "#2ebd59",
|
|
1135
|
+
discord: "#5865f2",
|
|
1136
|
+
threads: "#000000",
|
|
1137
|
+
"square-x-twitter": "#000000",
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
const socialIcons: Widget = (s, ctx, el) => {
|
|
1141
|
+
const items = Array.isArray(s["social_icon_list"]) ? s["social_icon_list"].slice(0, 50) : [];
|
|
1142
|
+
const size = slider(s["icon_size"]);
|
|
1143
|
+
const px = size && size.unit === "px" ? Math.round(size.value) : 25;
|
|
1144
|
+
const shape = str(s["shape"]) ?? "rounded";
|
|
1145
|
+
const custom = str(s["icon_color"]) === "custom";
|
|
1146
|
+
const icons: N[] = [];
|
|
1147
|
+
for (const raw of items) {
|
|
1148
|
+
if (!isRecord(raw) || ctx.overBudget) continue;
|
|
1149
|
+
const icon = iconOf(raw["social_icon"] ?? raw["social"], ctx, el);
|
|
1150
|
+
if (!icon) continue;
|
|
1151
|
+
const linkProps = href(raw["link"], ctx);
|
|
1152
|
+
const pad = slider(s["icon_padding"]) ?? { value: 0.5, unit: "em" as const };
|
|
1153
|
+
const brand = icon.name.replace(/^square-/, "");
|
|
1154
|
+
icons.push(
|
|
1155
|
+
node(
|
|
1156
|
+
ctx,
|
|
1157
|
+
"icon",
|
|
1158
|
+
{
|
|
1159
|
+
iconId: icon.iconId,
|
|
1160
|
+
iconSvg: icon.iconSvg,
|
|
1161
|
+
size: px,
|
|
1162
|
+
title: humanize(brand),
|
|
1163
|
+
...linkProps,
|
|
1164
|
+
...(linkProps.href ? {} : { decorative: true }),
|
|
1165
|
+
},
|
|
1166
|
+
{
|
|
1167
|
+
style: {
|
|
1168
|
+
color: (custom ? colorAt(s, "icon_secondary_color", ctx) : undefined) ?? "#ffffff",
|
|
1169
|
+
backgroundColor:
|
|
1170
|
+
(custom ? colorAt(s, "icon_primary_color", ctx) : undefined) ??
|
|
1171
|
+
BRANDS[icon.name] ??
|
|
1172
|
+
BRANDS[brand] ??
|
|
1173
|
+
"#69727d",
|
|
1174
|
+
paddingTop: pad,
|
|
1175
|
+
paddingRight: pad,
|
|
1176
|
+
paddingBottom: pad,
|
|
1177
|
+
paddingLeft: pad,
|
|
1178
|
+
borderRadius:
|
|
1179
|
+
shape === "circle"
|
|
1180
|
+
? { value: 50, unit: "%" }
|
|
1181
|
+
: shape === "square"
|
|
1182
|
+
? { value: 0, unit: "px" }
|
|
1183
|
+
: { value: 10, unit: "%" },
|
|
1184
|
+
},
|
|
1185
|
+
},
|
|
1186
|
+
),
|
|
1187
|
+
);
|
|
1188
|
+
}
|
|
1189
|
+
if (icons.length === 0) return [];
|
|
1190
|
+
const where = textAlign(s["align"]) ?? "center";
|
|
1191
|
+
return [
|
|
1192
|
+
box(ctx, icons, {
|
|
1193
|
+
flexDirection: "row",
|
|
1194
|
+
flexWrap: "wrap",
|
|
1195
|
+
gap: slider(s["icon_spacing"]) ?? { value: 5, unit: "px" },
|
|
1196
|
+
justifyContent: where === "left" ? "flex-start" : where === "right" ? "flex-end" : "center",
|
|
1197
|
+
}),
|
|
1198
|
+
];
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
/** Classic Tabs / Accordion / Toggle: `tabs: [{ tab_title, tab_content }]`. */
|
|
1202
|
+
function tabItems(s: Settings): { title: string; content: unknown }[] {
|
|
1203
|
+
const list = Array.isArray(s["tabs"]) ? s["tabs"] : [];
|
|
1204
|
+
return list
|
|
1205
|
+
.filter(isRecord)
|
|
1206
|
+
.map((t) => ({ title: plain(t["tab_title"]).text, content: t["tab_content"] }))
|
|
1207
|
+
.filter((t) => t.title);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
const tabs: Widget = (s, ctx, el) => {
|
|
1211
|
+
const items = tabItems(s);
|
|
1212
|
+
if (items.length === 0) return [];
|
|
1213
|
+
if (items.length > MAX_TABS) ctx.note("skipped", el, `Only the first ${MAX_TABS} tabs are kept.`);
|
|
1214
|
+
const panels = items
|
|
1215
|
+
.slice(0, MAX_TABS)
|
|
1216
|
+
.map((t) =>
|
|
1217
|
+
node(
|
|
1218
|
+
ctx,
|
|
1219
|
+
"tab-panel",
|
|
1220
|
+
{ label: short(t.title) },
|
|
1221
|
+
{ children: htmlNodes(t.content, ctx, el) },
|
|
1222
|
+
),
|
|
1223
|
+
);
|
|
1224
|
+
return [node(ctx, "tabs", {}, { children: panels })];
|
|
1225
|
+
};
|
|
1226
|
+
|
|
1227
|
+
const accordion =
|
|
1228
|
+
(firstOpen: boolean): Widget =>
|
|
1229
|
+
(s, ctx, el) => {
|
|
1230
|
+
const items = tabItems(s).slice(0, 100);
|
|
1231
|
+
if (items.length === 0) return [];
|
|
1232
|
+
const children = items.map((t, i) =>
|
|
1233
|
+
node(
|
|
1234
|
+
ctx,
|
|
1235
|
+
"accordion-item",
|
|
1236
|
+
{ summary: t.title.slice(0, 200), ...(firstOpen && i === 0 ? { open: true } : {}) },
|
|
1237
|
+
{ children: htmlNodes(t.content, ctx, el) },
|
|
1238
|
+
),
|
|
1239
|
+
);
|
|
1240
|
+
return [node(ctx, "accordion", {}, { children })];
|
|
1241
|
+
};
|
|
1242
|
+
|
|
1243
|
+
/** Nested Tabs / Nested Accordion: titles in settings, one child container per item. */
|
|
1244
|
+
const nestedTabs: Widget = (s, ctx, el, env, raw) => {
|
|
1245
|
+
const titles = (Array.isArray(s["tabs"]) ? s["tabs"] : [])
|
|
1246
|
+
.filter(isRecord)
|
|
1247
|
+
.map((t) => plain(t["tab_title"]).text || "Tab");
|
|
1248
|
+
const kids = Array.isArray(raw["elements"]) ? raw["elements"] : [];
|
|
1249
|
+
if (titles.length > MAX_TABS)
|
|
1250
|
+
ctx.note("skipped", el, `Only the first ${MAX_TABS} tabs are kept.`);
|
|
1251
|
+
const panels = titles
|
|
1252
|
+
.slice(0, MAX_TABS)
|
|
1253
|
+
.map((title, i) =>
|
|
1254
|
+
node(
|
|
1255
|
+
ctx,
|
|
1256
|
+
"tab-panel",
|
|
1257
|
+
{ label: short(title) },
|
|
1258
|
+
{ children: env.walk([kids[i]], { ...env, parentRow: false, depth: env.depth + 2 }) },
|
|
1259
|
+
),
|
|
1260
|
+
);
|
|
1261
|
+
return panels.length > 0 ? [node(ctx, "tabs", {}, { children: panels })] : [];
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
const nestedAccordion: Widget = (s, ctx, _el, env, raw) => {
|
|
1265
|
+
const titles = (Array.isArray(s["items"]) ? s["items"] : [])
|
|
1266
|
+
.filter(isRecord)
|
|
1267
|
+
.map((t) => plain(t["item_title"]).text || "Item");
|
|
1268
|
+
const kids = Array.isArray(raw["elements"]) ? raw["elements"] : [];
|
|
1269
|
+
const items = titles
|
|
1270
|
+
.slice(0, 100)
|
|
1271
|
+
.map((title, i) =>
|
|
1272
|
+
node(
|
|
1273
|
+
ctx,
|
|
1274
|
+
"accordion-item",
|
|
1275
|
+
{ summary: title.slice(0, 200) },
|
|
1276
|
+
{ children: env.walk([kids[i]], { ...env, parentRow: false, depth: env.depth + 2 }) },
|
|
1277
|
+
),
|
|
1278
|
+
);
|
|
1279
|
+
return items.length > 0 ? [node(ctx, "accordion", {}, { children: items })] : [];
|
|
1280
|
+
};
|
|
1281
|
+
|
|
1282
|
+
// ---------------------------------------------------------------------------------------------
|
|
1283
|
+
// Pro and theme-builder widgets (best effort)
|
|
1284
|
+
|
|
1285
|
+
const FIELD_TYPES: Record<string, string> = {
|
|
1286
|
+
text: "text-input",
|
|
1287
|
+
email: "text-input",
|
|
1288
|
+
url: "text-input",
|
|
1289
|
+
tel: "text-input",
|
|
1290
|
+
number: "text-input",
|
|
1291
|
+
date: "text-input",
|
|
1292
|
+
time: "text-input",
|
|
1293
|
+
password: "text-input",
|
|
1294
|
+
textarea: "textarea",
|
|
1295
|
+
select: "select",
|
|
1296
|
+
radio: "radio",
|
|
1297
|
+
checkbox: "checkbox",
|
|
1298
|
+
acceptance: "checkbox",
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
const form: Widget = (s, ctx, el) => {
|
|
1302
|
+
const fields = Array.isArray(s["form_fields"]) ? s["form_fields"].slice(0, 100) : [];
|
|
1303
|
+
const children: N[] = [];
|
|
1304
|
+
const names = new Set<string>();
|
|
1305
|
+
fields.forEach((raw, i) => {
|
|
1306
|
+
if (!isRecord(raw)) return;
|
|
1307
|
+
const type = str(raw["field_type"]) ?? "text";
|
|
1308
|
+
const nodeType = FIELD_TYPES[type];
|
|
1309
|
+
if (!nodeType) {
|
|
1310
|
+
ctx.note("skipped", el, `Form field type "${type}" was left out.`);
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
let name = str(raw["custom_id"]) ?? "";
|
|
1314
|
+
if (!FIELD_NAME_PATTERN.test(name) || name.length > 80 || names.has(name))
|
|
1315
|
+
name = `field_${i + 1}`;
|
|
1316
|
+
names.add(name);
|
|
1317
|
+
const label =
|
|
1318
|
+
plain(raw["field_label"]).text.slice(0, 200) ||
|
|
1319
|
+
(type === "acceptance" ? plain(raw["acceptance_text"]).text.slice(0, 200) : "");
|
|
1320
|
+
const placeholder = plain(raw["placeholder"]).text.slice(0, 200);
|
|
1321
|
+
children.push(
|
|
1322
|
+
node(ctx, nodeType, {
|
|
1323
|
+
field: name,
|
|
1324
|
+
...(label ? { label } : {}),
|
|
1325
|
+
...(placeholder && nodeType !== "checkbox" ? { placeholder } : {}),
|
|
1326
|
+
}),
|
|
1327
|
+
);
|
|
1328
|
+
});
|
|
1329
|
+
const label = plain(s["button_text"]).text.slice(0, 80) || "Send";
|
|
1330
|
+
children.push(node(ctx, "submit", { label }));
|
|
1331
|
+
ctx.note(
|
|
1332
|
+
"approximated",
|
|
1333
|
+
el,
|
|
1334
|
+
"Connect each imported form to a form in the forms plugin; field options and email actions weren't imported.",
|
|
1335
|
+
);
|
|
1336
|
+
return [
|
|
1337
|
+
node(ctx, "form", { formId: "" }, { style: { gap: { value: 10, unit: "px" } }, children }),
|
|
1338
|
+
];
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
const navMenu: Widget = (s, ctx, el) => {
|
|
1342
|
+
ctx.note(
|
|
1343
|
+
"approximated",
|
|
1344
|
+
el,
|
|
1345
|
+
`The WordPress menu${str(s["menu"]) ? ` "${(str(s["menu"]) ?? "").slice(0, 40)}"` : ""} isn't in the export; add its links to the Menu in the editor.`,
|
|
1346
|
+
);
|
|
1347
|
+
const vertical = str(s["layout"]) === "vertical" || str(s["layout"]) === "dropdown";
|
|
1348
|
+
return [node(ctx, "menu", { direction: vertical ? "column" : "row" }, { children: [] })];
|
|
1349
|
+
};
|
|
1350
|
+
|
|
1351
|
+
const megaMenu: Widget = (s, ctx, _el, env, raw) => {
|
|
1352
|
+
const items = (Array.isArray(s["menu_items"]) ? s["menu_items"] : [])
|
|
1353
|
+
.filter(isRecord)
|
|
1354
|
+
.slice(0, 50);
|
|
1355
|
+
const kids = Array.isArray(raw["elements"]) ? raw["elements"] : [];
|
|
1356
|
+
const children = items.map((item, i) => {
|
|
1357
|
+
const text = plain(item["item_title"]).text || "Item";
|
|
1358
|
+
const panel =
|
|
1359
|
+
str(item["item_dropdown_content"]) === "yes"
|
|
1360
|
+
? env.walk([kids[i]], { ...env, parentRow: false, depth: env.depth + 2 })
|
|
1361
|
+
: [];
|
|
1362
|
+
return node(
|
|
1363
|
+
ctx,
|
|
1364
|
+
"menu-item",
|
|
1365
|
+
{ text: short(text), ...href(item["item_link"], ctx) },
|
|
1366
|
+
{ children: panel },
|
|
1367
|
+
);
|
|
1368
|
+
});
|
|
1369
|
+
return [node(ctx, "menu", { direction: "row" }, { children })];
|
|
1370
|
+
};
|
|
1371
|
+
|
|
1372
|
+
const callToAction: Widget = (s, ctx, el) => {
|
|
1373
|
+
const children: N[] = [];
|
|
1374
|
+
const style: Style = {
|
|
1375
|
+
gap: { value: 15, unit: "px" },
|
|
1376
|
+
paddingTop: { value: 35, unit: "px" },
|
|
1377
|
+
paddingBottom: { value: 35, unit: "px" },
|
|
1378
|
+
paddingLeft: { value: 35, unit: "px" },
|
|
1379
|
+
paddingRight: { value: 35, unit: "px" },
|
|
1380
|
+
alignItems: "center",
|
|
1381
|
+
textAlign: "center",
|
|
1382
|
+
};
|
|
1383
|
+
const bg = image(s["bg_image"]);
|
|
1384
|
+
if (bg && !/[()\\\s"'`]/.test(bg.url)) {
|
|
1385
|
+
style["backgroundImage"] = bg.url;
|
|
1386
|
+
style["backgroundSize"] = "cover";
|
|
1387
|
+
style["backgroundPosition"] = "center";
|
|
1388
|
+
}
|
|
1389
|
+
const fill = colorAt(s, "background_color", ctx);
|
|
1390
|
+
if (fill) style["backgroundColor"] = fill;
|
|
1391
|
+
const title = plain(s["title"]).text;
|
|
1392
|
+
const level = Number(/^h([1-6])$/.exec(str(s["title_tag"]) ?? "h2")?.[1] ?? 2);
|
|
1393
|
+
if (title) children.push(node(ctx, "heading", { text: short(title), level }));
|
|
1394
|
+
const description = plain(s["description"]).text;
|
|
1395
|
+
if (description) children.push(node(ctx, "text", { text: short(description) }));
|
|
1396
|
+
const btn = buttonNode(s, ctx, el, { text: "button", link: "link", icon: "selected_icon" });
|
|
1397
|
+
if (btn) children.push(btn);
|
|
1398
|
+
ctx.note(
|
|
1399
|
+
"approximated",
|
|
1400
|
+
el,
|
|
1401
|
+
"Call to Action boxes keep their text, image and button, not their hover effects.",
|
|
1402
|
+
);
|
|
1403
|
+
return children.length > 0 ? [box(ctx, children, style)] : [];
|
|
1404
|
+
};
|
|
1405
|
+
|
|
1406
|
+
const priceTable: Widget = (s, ctx, el) => {
|
|
1407
|
+
const children: N[] = [];
|
|
1408
|
+
const headingText = plain(s["heading"]).text;
|
|
1409
|
+
if (headingText)
|
|
1410
|
+
children.push(
|
|
1411
|
+
node(ctx, "heading", {
|
|
1412
|
+
text: short(headingText),
|
|
1413
|
+
level: Number(/^h([1-6])$/.exec(str(s["heading_tag"]) ?? "h3")?.[1] ?? 3),
|
|
1414
|
+
}),
|
|
1415
|
+
);
|
|
1416
|
+
const sub = plain(s["sub_heading"]).text;
|
|
1417
|
+
if (sub) children.push(node(ctx, "text", { text: short(sub) }));
|
|
1418
|
+
const symbols: Record<string, string> = {
|
|
1419
|
+
dollar: "$",
|
|
1420
|
+
euro: "€",
|
|
1421
|
+
pound: "£",
|
|
1422
|
+
yen: "¥",
|
|
1423
|
+
rupee: "₹",
|
|
1424
|
+
franc: "₣",
|
|
1425
|
+
real: "R$",
|
|
1426
|
+
baht: "฿",
|
|
1427
|
+
krona: "kr",
|
|
1428
|
+
lira: "₺",
|
|
1429
|
+
peseta: "₧",
|
|
1430
|
+
peso: "₱",
|
|
1431
|
+
shekel: "₪",
|
|
1432
|
+
won: "₩",
|
|
1433
|
+
guilder: "ƒ",
|
|
1434
|
+
};
|
|
1435
|
+
const currency =
|
|
1436
|
+
str(s["currency_symbol"]) === "custom"
|
|
1437
|
+
? plain(s["currency_symbol_custom"]).text
|
|
1438
|
+
: (symbols[str(s["currency_symbol"]) ?? "dollar"] ?? "");
|
|
1439
|
+
const price = plain(s["price"]).text;
|
|
1440
|
+
if (price) {
|
|
1441
|
+
const period = plain(s["period"]).text;
|
|
1442
|
+
children.push(
|
|
1443
|
+
node(
|
|
1444
|
+
ctx,
|
|
1445
|
+
"text",
|
|
1446
|
+
{ text: short(`${currency}${price}${period ? ` / ${period}` : ""}`), tag: "div" },
|
|
1447
|
+
{ style: { fontSize: { value: 2.5, unit: "em" }, fontWeight: 600 } },
|
|
1448
|
+
),
|
|
1449
|
+
);
|
|
1450
|
+
}
|
|
1451
|
+
const features = (Array.isArray(s["features_list"]) ? s["features_list"] : [])
|
|
1452
|
+
.filter(isRecord)
|
|
1453
|
+
.map((f) => short(plain(f["item_text"]).text))
|
|
1454
|
+
.filter(Boolean)
|
|
1455
|
+
.slice(0, 200);
|
|
1456
|
+
if (features.length > 0) children.push(node(ctx, "list", { items: features }));
|
|
1457
|
+
const btn = buttonNode(s, ctx, el, { text: "button_text", link: "link" });
|
|
1458
|
+
if (btn) children.push(btn);
|
|
1459
|
+
const footer = plain(s["footer_additional_info"]).text;
|
|
1460
|
+
if (footer) children.push(node(ctx, "text", { text: short(footer) }));
|
|
1461
|
+
ctx.note(
|
|
1462
|
+
"approximated",
|
|
1463
|
+
el,
|
|
1464
|
+
"Price tables keep their content in EmVB's default look; ribbons are left out.",
|
|
1465
|
+
);
|
|
1466
|
+
return children.length > 0
|
|
1467
|
+
? [
|
|
1468
|
+
box(ctx, children, {
|
|
1469
|
+
gap: { value: 12, unit: "px" },
|
|
1470
|
+
alignItems: "center",
|
|
1471
|
+
textAlign: "center",
|
|
1472
|
+
}),
|
|
1473
|
+
]
|
|
1474
|
+
: [];
|
|
1475
|
+
};
|
|
1476
|
+
|
|
1477
|
+
const flipBox: Widget = (s, ctx, el) => {
|
|
1478
|
+
const side = (suffix: "a" | "b") => {
|
|
1479
|
+
const parts: N[] = [];
|
|
1480
|
+
const title = plain(s[`title_text_${suffix}`]).text;
|
|
1481
|
+
if (title) parts.push(node(ctx, "heading", { text: short(title), level: 3 }));
|
|
1482
|
+
const text = plain(s[`description_text_${suffix}`]).text;
|
|
1483
|
+
if (text) parts.push(node(ctx, "text", { text: short(text) }));
|
|
1484
|
+
const fill = colorAt(s, `background_color_${suffix}`, ctx);
|
|
1485
|
+
return parts.length > 0
|
|
1486
|
+
? box(ctx, parts, {
|
|
1487
|
+
gap: { value: 10, unit: "px" },
|
|
1488
|
+
alignItems: "center",
|
|
1489
|
+
textAlign: "center",
|
|
1490
|
+
...(fill ? { backgroundColor: fill } : {}),
|
|
1491
|
+
paddingTop: { value: 35, unit: "px" },
|
|
1492
|
+
paddingBottom: { value: 35, unit: "px" },
|
|
1493
|
+
paddingLeft: { value: 35, unit: "px" },
|
|
1494
|
+
paddingRight: { value: 35, unit: "px" },
|
|
1495
|
+
})
|
|
1496
|
+
: undefined;
|
|
1497
|
+
};
|
|
1498
|
+
const front = side("a");
|
|
1499
|
+
const back = side("b");
|
|
1500
|
+
const btn = buttonNode(s, ctx, el, { text: "button_text", link: "link" });
|
|
1501
|
+
if (back && btn) (back["children"] as N[]).push(btn);
|
|
1502
|
+
ctx.note(
|
|
1503
|
+
"approximated",
|
|
1504
|
+
el,
|
|
1505
|
+
"Flip boxes show their back side below the front, without the flip.",
|
|
1506
|
+
);
|
|
1507
|
+
return [front, back].filter((n): n is N => n !== undefined);
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
const blockquote: Widget = (s, ctx) => {
|
|
1511
|
+
const content = plain(s["blockquote_content"]).text;
|
|
1512
|
+
if (!content) return [];
|
|
1513
|
+
const author = plain(s["author_name"]).text;
|
|
1514
|
+
return [
|
|
1515
|
+
box(
|
|
1516
|
+
ctx,
|
|
1517
|
+
[
|
|
1518
|
+
node(
|
|
1519
|
+
ctx,
|
|
1520
|
+
"text",
|
|
1521
|
+
{ text: short(content) },
|
|
1522
|
+
{ style: { fontSize: { value: 1.2, unit: "em" } } },
|
|
1523
|
+
),
|
|
1524
|
+
...(author ? [node(ctx, "text", { text: short(`— ${author}`) })] : []),
|
|
1525
|
+
],
|
|
1526
|
+
{
|
|
1527
|
+
gap: { value: 8, unit: "px" },
|
|
1528
|
+
borderStyle: "solid",
|
|
1529
|
+
borderLeftWidth: { value: 4, unit: "px" },
|
|
1530
|
+
paddingLeft: { value: 20, unit: "px" },
|
|
1531
|
+
},
|
|
1532
|
+
),
|
|
1533
|
+
];
|
|
1534
|
+
};
|
|
1535
|
+
|
|
1536
|
+
const animatedHeadline: Widget = (s, ctx, el) => {
|
|
1537
|
+
const rotating = (str(s["rotating_text"]) ?? "").split("\n")[0] ?? "";
|
|
1538
|
+
const middle =
|
|
1539
|
+
str(s["headline_style"]) === "rotate" ? rotating : (str(s["highlighted_text"]) ?? "");
|
|
1540
|
+
const text = cleanText(
|
|
1541
|
+
[plain(s["before_text"]).text, plain(middle).text, plain(s["after_text"]).text]
|
|
1542
|
+
.filter(Boolean)
|
|
1543
|
+
.join(" "),
|
|
1544
|
+
);
|
|
1545
|
+
if (!text) return [];
|
|
1546
|
+
ctx.note(
|
|
1547
|
+
"approximated",
|
|
1548
|
+
el,
|
|
1549
|
+
"Animated headlines are shown without their animation (rotating headlines show their first word).",
|
|
1550
|
+
);
|
|
1551
|
+
const level = Number(/^h([1-6])$/.exec(str(s["tag"]) ?? "h3")?.[1] ?? 3);
|
|
1552
|
+
return [
|
|
1553
|
+
styled(
|
|
1554
|
+
node(ctx, "heading", { text: short(text), level, ...href(s["link"], ctx) }),
|
|
1555
|
+
deviceStyles(s, ctx, el, [
|
|
1556
|
+
typographyReader("title_typography", "primary"),
|
|
1557
|
+
textReader("title_color", "secondary", "alignment"),
|
|
1558
|
+
]),
|
|
1559
|
+
),
|
|
1560
|
+
];
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
const toc: Widget = (s, ctx) => {
|
|
1564
|
+
const title = plain(s["title"]).text.slice(0, 80);
|
|
1565
|
+
return [node(ctx, "toc", title ? { title } : {})];
|
|
1566
|
+
};
|
|
1567
|
+
|
|
1568
|
+
const postTitle: Widget = (s, ctx, el) => {
|
|
1569
|
+
const level = /^h([1-6])$/.exec(str(s["header_size"]) ?? "h1")?.[1];
|
|
1570
|
+
return [
|
|
1571
|
+
styled(
|
|
1572
|
+
node(ctx, "post-title", level ? { level: Number(level) } : {}),
|
|
1573
|
+
deviceStyles(s, ctx, el, [
|
|
1574
|
+
typographyReader("typography", "primary"),
|
|
1575
|
+
textReader("title_color", "primary"),
|
|
1576
|
+
]),
|
|
1577
|
+
),
|
|
1578
|
+
];
|
|
1579
|
+
};
|
|
1580
|
+
|
|
1581
|
+
const postInfo: Widget = (s, ctx, el) => {
|
|
1582
|
+
const items = (Array.isArray(s["icon_list"]) ? s["icon_list"] : []).filter(isRecord);
|
|
1583
|
+
const parts: N[] = [];
|
|
1584
|
+
for (const item of items) {
|
|
1585
|
+
const type = str(item["type"]);
|
|
1586
|
+
if (type === "author") parts.push(node(ctx, "post-author", {}));
|
|
1587
|
+
else if (type === "date") parts.push(node(ctx, "post-date", {}));
|
|
1588
|
+
else if (type) ctx.note("skipped", el, `Post info "${type}" was left out.`);
|
|
1589
|
+
}
|
|
1590
|
+
if (parts.length === 0) return [];
|
|
1591
|
+
return [
|
|
1592
|
+
box(ctx, parts, {
|
|
1593
|
+
flexDirection: str(s["view"]) === "traditional" ? "column" : "row",
|
|
1594
|
+
gap: { value: 12, unit: "px" },
|
|
1595
|
+
}),
|
|
1596
|
+
];
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
const siteLogo: Widget = (s, ctx, el, env) => {
|
|
1600
|
+
const n = imageNode(ctx, el, s["custom_image"] ?? s["image"]);
|
|
1601
|
+
if (!n) {
|
|
1602
|
+
ctx.note(
|
|
1603
|
+
"skipped",
|
|
1604
|
+
el,
|
|
1605
|
+
"The site logo comes from WordPress settings; add your logo as an image.",
|
|
1606
|
+
);
|
|
1607
|
+
return [];
|
|
1608
|
+
}
|
|
1609
|
+
n["style"] = { maxWidth: { value: 100, unit: "%" } };
|
|
1610
|
+
return [align(n, s["align"], env, "center")];
|
|
1611
|
+
};
|
|
1612
|
+
|
|
1613
|
+
const slides: Widget = (s, ctx, el) => {
|
|
1614
|
+
const list = (Array.isArray(s["slides"]) ? s["slides"] : []).filter(isRecord).slice(0, 20);
|
|
1615
|
+
const height = slider(s["slides_height"]) ?? { value: 400, unit: "px" as const };
|
|
1616
|
+
const out: N[] = [];
|
|
1617
|
+
for (const slide of list) {
|
|
1618
|
+
const parts: N[] = [];
|
|
1619
|
+
const title = plain(slide["heading"]).text;
|
|
1620
|
+
if (title) parts.push(node(ctx, "heading", { text: short(title), level: 2 }));
|
|
1621
|
+
const text = plain(slide["description"]).text;
|
|
1622
|
+
if (text) parts.push(node(ctx, "text", { text: short(text) }));
|
|
1623
|
+
const btn = buttonNode(slide, ctx, el, { text: "button_text", link: "link" });
|
|
1624
|
+
if (btn) parts.push(btn);
|
|
1625
|
+
const style: Style = {
|
|
1626
|
+
minHeight: height,
|
|
1627
|
+
justifyContent: "center",
|
|
1628
|
+
alignItems: "center",
|
|
1629
|
+
textAlign: "center",
|
|
1630
|
+
gap: { value: 15, unit: "px" },
|
|
1631
|
+
color: "#ffffff",
|
|
1632
|
+
};
|
|
1633
|
+
const fill = color(slide["background_color"]);
|
|
1634
|
+
if (fill) style["backgroundColor"] = fill;
|
|
1635
|
+
const bg = image(slide["background_image"]);
|
|
1636
|
+
if (bg && !/[()\\\s"'`]/.test(bg.url)) {
|
|
1637
|
+
style["backgroundImage"] = bg.url;
|
|
1638
|
+
style["backgroundSize"] = "cover";
|
|
1639
|
+
}
|
|
1640
|
+
out.push(box(ctx, parts, style));
|
|
1641
|
+
}
|
|
1642
|
+
if (out.length > 0) ctx.note("approximated", el, "Slides are shown stacked, one after another.");
|
|
1643
|
+
return out;
|
|
1644
|
+
};
|
|
1645
|
+
|
|
1646
|
+
const testimonialCarousel: Widget = (s, ctx, el, env, raw) => {
|
|
1647
|
+
const list = (Array.isArray(s["slides"]) ? s["slides"] : []).filter(isRecord).slice(0, 30);
|
|
1648
|
+
const out = list.flatMap((slide) =>
|
|
1649
|
+
testimonial(
|
|
1650
|
+
{
|
|
1651
|
+
testimonial_content: slide["content"],
|
|
1652
|
+
testimonial_name: slide["name"],
|
|
1653
|
+
testimonial_job: slide["title"],
|
|
1654
|
+
testimonial_image: slide["image"],
|
|
1655
|
+
},
|
|
1656
|
+
ctx,
|
|
1657
|
+
el,
|
|
1658
|
+
env,
|
|
1659
|
+
raw,
|
|
1660
|
+
),
|
|
1661
|
+
);
|
|
1662
|
+
if (out.length > 0)
|
|
1663
|
+
ctx.note("approximated", el, "Carousels are shown as a grid of their slides.");
|
|
1664
|
+
return out.length > 0
|
|
1665
|
+
? [
|
|
1666
|
+
node(
|
|
1667
|
+
ctx,
|
|
1668
|
+
"grid",
|
|
1669
|
+
{ columns: Math.min(12, Math.max(1, num(s["slides_per_view"]) ?? 3)) },
|
|
1670
|
+
{ style: { gap: { value: 20, unit: "px" } }, children: out },
|
|
1671
|
+
),
|
|
1672
|
+
]
|
|
1673
|
+
: [];
|
|
1674
|
+
};
|
|
1675
|
+
|
|
1676
|
+
const codeHighlight: Widget = (s, ctx, el) => {
|
|
1677
|
+
const code = str(s["code"]) ?? "";
|
|
1678
|
+
if (!code.trim()) return [];
|
|
1679
|
+
ctx.note("approximated", el, "Code blocks became plain monospace text, without highlighting.");
|
|
1680
|
+
return splitLong(
|
|
1681
|
+
stripControl(code.replace(/\r\n?/g, "\n").replace(/\t/g, " ")),
|
|
1682
|
+
MAX_TEXT_LENGTH,
|
|
1683
|
+
).map((part) =>
|
|
1684
|
+
node(
|
|
1685
|
+
ctx,
|
|
1686
|
+
"text",
|
|
1687
|
+
{ text: part, tag: "div" },
|
|
1688
|
+
{ style: { fontFamily: "ui-monospace, monospace" } },
|
|
1689
|
+
),
|
|
1690
|
+
);
|
|
1691
|
+
};
|
|
1692
|
+
|
|
1693
|
+
const audio: Widget = (s, ctx, el) => {
|
|
1694
|
+
const linkProps = href(s["link"], ctx);
|
|
1695
|
+
ctx.note("approximated", el, "Audio players became a link.");
|
|
1696
|
+
return linkProps.href ? [node(ctx, "link", { text: "Listen", ...linkProps })] : [];
|
|
1697
|
+
};
|
|
1698
|
+
|
|
1699
|
+
const textPath: Widget = (s, ctx, el) => {
|
|
1700
|
+
const text = plain(s["text"]).text;
|
|
1701
|
+
ctx.note("approximated", el, "Text on a path is shown as straight text.");
|
|
1702
|
+
return text ? [node(ctx, "text", { text: short(text) })] : [];
|
|
1703
|
+
};
|
|
1704
|
+
|
|
1705
|
+
const skip =
|
|
1706
|
+
(message: string, kind: "skipped" | "unmapped" = "skipped"): Widget =>
|
|
1707
|
+
(_s, ctx, el) => {
|
|
1708
|
+
ctx.note(kind, el, message);
|
|
1709
|
+
return [];
|
|
1710
|
+
};
|
|
1711
|
+
|
|
1712
|
+
const LOOPS = "Post lists and loops weren't imported; rebuild them with EmVB's Loop element.";
|
|
1713
|
+
|
|
1714
|
+
export const WIDGETS: Record<string, Widget> = {
|
|
1715
|
+
heading,
|
|
1716
|
+
"text-editor": textEditor,
|
|
1717
|
+
image: imageWidget,
|
|
1718
|
+
button,
|
|
1719
|
+
spacer,
|
|
1720
|
+
divider,
|
|
1721
|
+
icon: iconWidget,
|
|
1722
|
+
"icon-box": iconBox,
|
|
1723
|
+
"image-box": imageBox,
|
|
1724
|
+
"icon-list": iconList,
|
|
1725
|
+
video,
|
|
1726
|
+
counter,
|
|
1727
|
+
progress,
|
|
1728
|
+
testimonial,
|
|
1729
|
+
"star-rating": starRating,
|
|
1730
|
+
alert,
|
|
1731
|
+
html,
|
|
1732
|
+
"menu-anchor": menuAnchor,
|
|
1733
|
+
google_maps: googleMaps,
|
|
1734
|
+
"image-gallery": imageGallery,
|
|
1735
|
+
gallery: proGallery,
|
|
1736
|
+
"image-carousel": imageCarousel,
|
|
1737
|
+
"media-carousel": mediaCarousel,
|
|
1738
|
+
"social-icons": socialIcons,
|
|
1739
|
+
tabs,
|
|
1740
|
+
accordion: accordion(true),
|
|
1741
|
+
toggle: accordion(false),
|
|
1742
|
+
"nested-tabs": nestedTabs,
|
|
1743
|
+
"nested-accordion": nestedAccordion,
|
|
1744
|
+
form,
|
|
1745
|
+
"nav-menu": navMenu,
|
|
1746
|
+
"mega-menu": megaMenu,
|
|
1747
|
+
"call-to-action": callToAction,
|
|
1748
|
+
"price-table": priceTable,
|
|
1749
|
+
"flip-box": flipBox,
|
|
1750
|
+
blockquote,
|
|
1751
|
+
"animated-headline": animatedHeadline,
|
|
1752
|
+
"table-of-contents": toc,
|
|
1753
|
+
"theme-post-title": postTitle,
|
|
1754
|
+
"theme-page-title": postTitle,
|
|
1755
|
+
"theme-archive-title": postTitle,
|
|
1756
|
+
"theme-post-excerpt": (_s, ctx) => [node(ctx, "post-excerpt", {})],
|
|
1757
|
+
"theme-post-content": (_s, ctx) => [node(ctx, "post-content", {})],
|
|
1758
|
+
"theme-post-featured-image": (s, ctx, _el, env) => [
|
|
1759
|
+
align(
|
|
1760
|
+
node(ctx, "post-image", {}, { style: { maxWidth: { value: 100, unit: "%" } } }),
|
|
1761
|
+
s["align"],
|
|
1762
|
+
env,
|
|
1763
|
+
"center",
|
|
1764
|
+
),
|
|
1765
|
+
],
|
|
1766
|
+
"post-info": postInfo,
|
|
1767
|
+
"theme-site-logo": siteLogo,
|
|
1768
|
+
slides,
|
|
1769
|
+
"testimonial-carousel": testimonialCarousel,
|
|
1770
|
+
reviews: testimonialCarousel,
|
|
1771
|
+
"code-highlight": codeHighlight,
|
|
1772
|
+
audio,
|
|
1773
|
+
"text-path": textPath,
|
|
1774
|
+
shortcode: (s, ctx, el) => {
|
|
1775
|
+
ctx.note(
|
|
1776
|
+
"skipped",
|
|
1777
|
+
el,
|
|
1778
|
+
`The shortcode ${plain(s["shortcode"]).text.slice(0, 60) || ""} needs WordPress and was left out.`.replace(
|
|
1779
|
+
" ",
|
|
1780
|
+
" ",
|
|
1781
|
+
),
|
|
1782
|
+
);
|
|
1783
|
+
return [];
|
|
1784
|
+
},
|
|
1785
|
+
"theme-site-title": skip("The site title comes from WordPress settings; add it as a Heading."),
|
|
1786
|
+
"read-more": skip("WordPress's Read More tag has no EmVB equivalent."),
|
|
1787
|
+
sidebar: skip("WordPress sidebars weren't imported."),
|
|
1788
|
+
countdown: skip("Countdown timers weren't imported."),
|
|
1789
|
+
"share-buttons": skip("Share buttons weren't imported; add Icon links instead."),
|
|
1790
|
+
"search-form": skip("Search forms weren't imported."),
|
|
1791
|
+
login: skip("Login forms weren't imported."),
|
|
1792
|
+
lottie: skip("Lottie animations weren't imported."),
|
|
1793
|
+
hotspot: skip("Hotspots weren't imported."),
|
|
1794
|
+
"paypal-button": skip("PayPal buttons weren't imported."),
|
|
1795
|
+
"progress-tracker": skip("Reading progress bars weren't imported."),
|
|
1796
|
+
posts: skip(LOOPS),
|
|
1797
|
+
"archive-posts": skip(LOOPS),
|
|
1798
|
+
"loop-grid": skip(LOOPS),
|
|
1799
|
+
"loop-carousel": skip(LOOPS),
|
|
1800
|
+
portfolio: skip(LOOPS),
|
|
1801
|
+
"post-navigation": skip("Post navigation wasn't imported."),
|
|
1802
|
+
"post-comments": skip("Comments weren't imported."),
|
|
1803
|
+
"author-box": skip("Author boxes weren't imported; use Post author."),
|
|
1804
|
+
};
|
|
1805
|
+
|
|
1806
|
+
// ---------------------------------------------------------------------------------------------
|
|
1807
|
+
// Third-party widgets: rebuilt from their text, images and buttons
|
|
1808
|
+
|
|
1809
|
+
/** Elementor 4 stores `{ $$type, value }`; unwraps to the plain value. */
|
|
1810
|
+
export function unwrap(value: unknown, depth = 0): unknown {
|
|
1811
|
+
if (depth > 6) return undefined;
|
|
1812
|
+
if (isRecord(value) && "$$type" in value) return unwrap(value["value"], depth + 1);
|
|
1813
|
+
return value;
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
const TITLE_KEY = /(^|_)(title|heading|headline|title_text|main_title)$/;
|
|
1817
|
+
const TEXT_KEY =
|
|
1818
|
+
/(^|_)(description|content|text|editor|desc|paragraph|sub_?title|subheading|excerpt)$/;
|
|
1819
|
+
const IMAGE_KEY = /(^|_)(image|img|photo|picture|logo|thumbnail)$/;
|
|
1820
|
+
const BUTTON_TEXT_KEY = /(^|_)(btn|button)(_text|_label)?$/;
|
|
1821
|
+
const SETTING_NOISE =
|
|
1822
|
+
/(color|typography|_size|align|_width|_height|padding|margin|border|shadow|_position|_icon|animation|css|_id$|_class|^_)/;
|
|
1823
|
+
|
|
1824
|
+
export function genericWidget(type: string, s: Settings, ctx: ImportContext, el: string): N[] {
|
|
1825
|
+
const out: N[] = [];
|
|
1826
|
+
let title: string | undefined;
|
|
1827
|
+
let buttonText: string | undefined;
|
|
1828
|
+
let buttonLink: unknown;
|
|
1829
|
+
const level = Number(
|
|
1830
|
+
/^h([1-6])$/.exec(str(unwrap(s["tag"])) ?? str(unwrap(s["header_size"])) ?? "")?.[1] ?? 2,
|
|
1831
|
+
);
|
|
1832
|
+
for (const [key, rawValue] of Object.entries(s).slice(0, 300)) {
|
|
1833
|
+
if (ctx.overBudget) break;
|
|
1834
|
+
const value = unwrap(rawValue);
|
|
1835
|
+
if (SETTING_NOISE.test(key) && !IMAGE_KEY.test(key)) continue;
|
|
1836
|
+
if (IMAGE_KEY.test(key) && isRecord(value)) {
|
|
1837
|
+
const src = unwrap(
|
|
1838
|
+
isRecord(value["src"])
|
|
1839
|
+
? ((value["src"] as Settings)["value"] ?? value["src"])
|
|
1840
|
+
: value["url"],
|
|
1841
|
+
);
|
|
1842
|
+
const url = isRecord(src) ? unwrap(src["url"]) : src;
|
|
1843
|
+
const n = imageNode(ctx, el, { url: str(url), alt: str(unwrap(value["alt"])) });
|
|
1844
|
+
if (n) {
|
|
1845
|
+
n["style"] = { maxWidth: { value: 100, unit: "%" } };
|
|
1846
|
+
out.push(n);
|
|
1847
|
+
}
|
|
1848
|
+
continue;
|
|
1849
|
+
}
|
|
1850
|
+
if (typeof value !== "string" || !value.trim()) continue;
|
|
1851
|
+
if (BUTTON_TEXT_KEY.test(key)) {
|
|
1852
|
+
buttonText ??= value;
|
|
1853
|
+
continue;
|
|
1854
|
+
}
|
|
1855
|
+
if (/(^|_)(link|url|btn_link|button_link)$/.test(key)) {
|
|
1856
|
+
buttonLink ??= value;
|
|
1857
|
+
continue;
|
|
1858
|
+
}
|
|
1859
|
+
if (!title && TITLE_KEY.test(key)) {
|
|
1860
|
+
title = plain(value).text;
|
|
1861
|
+
if (title) out.push(node(ctx, "heading", { text: short(title), level }));
|
|
1862
|
+
continue;
|
|
1863
|
+
}
|
|
1864
|
+
if (TEXT_KEY.test(key)) out.push(...htmlNodes(value, ctx, el));
|
|
1865
|
+
}
|
|
1866
|
+
if (!buttonLink) {
|
|
1867
|
+
for (const [key, rawValue] of Object.entries(s)) {
|
|
1868
|
+
if (/(^|_)link$/.test(key) && isRecord(unwrap(rawValue))) {
|
|
1869
|
+
const value = unwrap(rawValue) as Settings;
|
|
1870
|
+
const dest = unwrap(value["destination"]);
|
|
1871
|
+
buttonLink = isRecord(dest) ? unwrap(dest["value"]) : (str(dest) ?? value["url"]);
|
|
1872
|
+
break;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
if (buttonText) {
|
|
1877
|
+
const btn = buttonNode({ text: buttonText, link: link(buttonLink) ?? buttonLink }, ctx, el, {
|
|
1878
|
+
text: "text",
|
|
1879
|
+
link: "link",
|
|
1880
|
+
});
|
|
1881
|
+
if (btn) out.push(btn);
|
|
1882
|
+
}
|
|
1883
|
+
if (out.length === 0) {
|
|
1884
|
+
ctx.note(
|
|
1885
|
+
"unmapped",
|
|
1886
|
+
el,
|
|
1887
|
+
`Widget "${type}" has no EmVB match and no text to keep; it was left out.`,
|
|
1888
|
+
);
|
|
1889
|
+
return [];
|
|
1890
|
+
}
|
|
1891
|
+
ctx.note(
|
|
1892
|
+
"unmapped",
|
|
1893
|
+
el,
|
|
1894
|
+
`Widget "${type}" isn't known to EmVB; its text, images and buttons were kept in a plain layout.`,
|
|
1895
|
+
);
|
|
1896
|
+
return one(ctx, out, { value: 12, unit: "px" });
|
|
1897
|
+
}
|