@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,949 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elementor import (W-945, D-069): Elementor JSON (`_elementor_data`, a template export or one
|
|
3
|
+
* copied element) → an EmVB layout and a report. Pure and synchronous; the editor passes its
|
|
4
|
+
* icon sets in. The result is always a layout EmVB accepts: anything that fails validation is
|
|
5
|
+
* pruned (and reported) instead of failing the import.
|
|
6
|
+
*/
|
|
7
|
+
import { LAYOUT_SCHEMA_VERSION, type Layout, type LayoutNode } from "../../schema/layout.ts";
|
|
8
|
+
import { nodeChildren } from "../../tree-ops.ts";
|
|
9
|
+
import type { ThemePartType } from "../../theme/part-types.ts";
|
|
10
|
+
import { nestingIssues } from "../../nesting.ts";
|
|
11
|
+
import { validateLayout } from "../../validate.ts";
|
|
12
|
+
import { atomicElement } from "./atomic.ts";
|
|
13
|
+
import { readSnapshots } from "./snapshots.ts";
|
|
14
|
+
import { customCss, wordRules } from "./css.ts";
|
|
15
|
+
import { type CounterItem, counterItems, counterOf } from "./counter-steps.ts";
|
|
16
|
+
import { ImportContext, type ImportNote, type ImportOptions, type StyleClass } from "./context.ts";
|
|
17
|
+
import {
|
|
18
|
+
boxReader,
|
|
19
|
+
deviceStyles,
|
|
20
|
+
entrance,
|
|
21
|
+
flexReader,
|
|
22
|
+
hiddenOn,
|
|
23
|
+
type Style,
|
|
24
|
+
widthReader,
|
|
25
|
+
} from "./style.ts";
|
|
26
|
+
import { isRecord, num, type Settings, slider, str } from "./values.ts";
|
|
27
|
+
import {
|
|
28
|
+
box,
|
|
29
|
+
dynamicTag,
|
|
30
|
+
type Env,
|
|
31
|
+
genericWidget,
|
|
32
|
+
href,
|
|
33
|
+
type N,
|
|
34
|
+
node,
|
|
35
|
+
unwrap,
|
|
36
|
+
WIDGETS,
|
|
37
|
+
} from "./widgets.ts";
|
|
38
|
+
|
|
39
|
+
export type { ImportNote, ImportOptions } from "./context.ts";
|
|
40
|
+
|
|
41
|
+
/** Pasted or uploaded JSON larger than this is refused before parsing. */
|
|
42
|
+
export const MAX_IMPORT_CHARS = 8 * 1024 * 1024;
|
|
43
|
+
/** Elementor elements read per import; the rest is reported as left out. */
|
|
44
|
+
export const MAX_IMPORT_ELEMENTS = 5000;
|
|
45
|
+
/** Elementor nesting deeper than this is left out (EmVB allows 24 levels; wrappers add some). */
|
|
46
|
+
const MAX_WALK_DEPTH = 16;
|
|
47
|
+
|
|
48
|
+
export type ElementorImport =
|
|
49
|
+
| {
|
|
50
|
+
ok: true;
|
|
51
|
+
layout: Layout;
|
|
52
|
+
/** The template's title, when the export has one. */
|
|
53
|
+
title?: string;
|
|
54
|
+
/** The theme-part type an Elementor theme-builder template maps to. */
|
|
55
|
+
partType?: ThemePartType;
|
|
56
|
+
/** Elementor elements read, and how many produced EmVB elements. */
|
|
57
|
+
elements: number;
|
|
58
|
+
mapped: number;
|
|
59
|
+
notes: ImportNote[];
|
|
60
|
+
/** Font families the page uses; the site must load them. */
|
|
61
|
+
fonts: string[];
|
|
62
|
+
/**
|
|
63
|
+
* W-951: SVG files the export points to whose markup wasn't given; with it (`svg` option)
|
|
64
|
+
* they import as recolourable icons, without it as images.
|
|
65
|
+
*/
|
|
66
|
+
svgFiles: string[];
|
|
67
|
+
/** W-958: WordPress page ids the page links to (their address comes from `pageLink`). */
|
|
68
|
+
pageLinks: number[];
|
|
69
|
+
/** W-958: images on the old site the page uses (`media` gives their library copies). */
|
|
70
|
+
images: string[];
|
|
71
|
+
/** W-958: with `classes`, the EmVB classes the page's elements point at, to add to the site. */
|
|
72
|
+
classes: StyleClass[];
|
|
73
|
+
}
|
|
74
|
+
| { ok: false; error: string };
|
|
75
|
+
|
|
76
|
+
const PART_TYPES: Record<string, ThemePartType> = {
|
|
77
|
+
header: "header",
|
|
78
|
+
footer: "footer",
|
|
79
|
+
popup: "popup",
|
|
80
|
+
single: "single_post",
|
|
81
|
+
"single-post": "single_post",
|
|
82
|
+
"single-page": "single_page",
|
|
83
|
+
archive: "archive",
|
|
84
|
+
"search-results": "search_results",
|
|
85
|
+
"error-404": "error_404",
|
|
86
|
+
"loop-item": "loop_item",
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
type Source = {
|
|
90
|
+
elements: unknown[];
|
|
91
|
+
title?: string;
|
|
92
|
+
type?: string;
|
|
93
|
+
pageSettings?: Settings;
|
|
94
|
+
/** The export's own record: Elementor 4 exports carry `global_classes` and `global_variables`. */
|
|
95
|
+
record?: Settings;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** Finds the Elementor elements in what the person pasted or uploaded. */
|
|
99
|
+
function readSource(input: unknown): Source | { error: string } {
|
|
100
|
+
let value = input;
|
|
101
|
+
if (typeof value === "string") {
|
|
102
|
+
if (value.length > MAX_IMPORT_CHARS)
|
|
103
|
+
return { error: "This file is larger than 8 MB. Export one page or template at a time." };
|
|
104
|
+
const text = value.trim();
|
|
105
|
+
if (text.startsWith("<"))
|
|
106
|
+
return {
|
|
107
|
+
error:
|
|
108
|
+
"This looks like a WordPress XML export. Export the page from Elementor as a template (JSON) instead.",
|
|
109
|
+
};
|
|
110
|
+
try {
|
|
111
|
+
value = JSON.parse(text) as unknown;
|
|
112
|
+
} catch {
|
|
113
|
+
return {
|
|
114
|
+
error:
|
|
115
|
+
"This isn't valid JSON. Paste an Elementor template export or the page's _elementor_data.",
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (let unwrapDepth = 0; unwrapDepth < 3; unwrapDepth++) {
|
|
120
|
+
if (Array.isArray(value)) return { elements: value };
|
|
121
|
+
if (!isRecord(value)) break;
|
|
122
|
+
if (
|
|
123
|
+
isRecord(value["settings"]) &&
|
|
124
|
+
("system_colors" in value["settings"] || "custom_colors" in value["settings"])
|
|
125
|
+
) {
|
|
126
|
+
return {
|
|
127
|
+
error:
|
|
128
|
+
"This is a site kit (site-settings.json). Add it under Site kit, and paste a page or template here.",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (Array.isArray(value["content"])) {
|
|
132
|
+
return {
|
|
133
|
+
elements: value["content"],
|
|
134
|
+
record: value,
|
|
135
|
+
...titleOf(value["title"]),
|
|
136
|
+
...(str(value["type"]) ? { type: str(value["type"]) } : {}),
|
|
137
|
+
...(isRecord(value["page_settings"]) ? { pageSettings: value["page_settings"] } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (typeof value["elType"] === "string") return { elements: [value] };
|
|
141
|
+
if (Array.isArray(value["elements"]) && value["type"] === "elementor")
|
|
142
|
+
return { elements: value["elements"] };
|
|
143
|
+
const nested = value["_elementor_data"] ?? value["content"];
|
|
144
|
+
if (typeof nested === "string" && nested.length <= MAX_IMPORT_CHARS) {
|
|
145
|
+
try {
|
|
146
|
+
value = JSON.parse(nested) as unknown;
|
|
147
|
+
continue;
|
|
148
|
+
} catch {
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (Array.isArray(nested)) return { elements: nested };
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
error:
|
|
157
|
+
"No Elementor content was found. Paste an Elementor template export (.json) or the page's _elementor_data.",
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const titleOf = (value: unknown): { title?: string } => {
|
|
162
|
+
const title = str(value)?.trim().slice(0, 200);
|
|
163
|
+
return title ? { title } : {};
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const ACRONYMS = new Set(["html", "css", "cta", "toc", "wp", "faq"]);
|
|
167
|
+
|
|
168
|
+
const label = (type: string) =>
|
|
169
|
+
type
|
|
170
|
+
.replace(/^e-/, "")
|
|
171
|
+
.split(/[-_]+/)
|
|
172
|
+
.filter(Boolean)
|
|
173
|
+
.map((w) => (ACRONYMS.has(w) ? w.toUpperCase() : w.charAt(0).toUpperCase() + w.slice(1)))
|
|
174
|
+
.join(" ")
|
|
175
|
+
.slice(0, 60) || "Element";
|
|
176
|
+
|
|
177
|
+
const isValidHtmlId = (id: string) => /^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(id);
|
|
178
|
+
|
|
179
|
+
class Walker {
|
|
180
|
+
constructor(readonly ctx: ImportContext) {}
|
|
181
|
+
|
|
182
|
+
readonly walk = (elements: unknown, env: Env): N[] => {
|
|
183
|
+
const list = Array.isArray(elements) ? elements : [];
|
|
184
|
+
const out: N[] = [];
|
|
185
|
+
const labels = (id: string) => this.ctx.atomic.classes.get(id)?.label;
|
|
186
|
+
for (let i = 0; i < list.length; i++) {
|
|
187
|
+
// W-961: consecutive paragraphs numbered by a CSS counter become one numbered List.
|
|
188
|
+
const item = counterOf(list[i], this.ctx.counterItems, labels);
|
|
189
|
+
if (item) {
|
|
190
|
+
let end = i;
|
|
191
|
+
while (
|
|
192
|
+
end + 1 < list.length &&
|
|
193
|
+
counterOf(list[end + 1], this.ctx.counterItems, labels)?.counter === item.counter
|
|
194
|
+
)
|
|
195
|
+
end++;
|
|
196
|
+
out.push(...this.counterList(list.slice(i, end + 1), item, env));
|
|
197
|
+
i = end;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
out.push(...this.element(list[i], env));
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/** W-961: the steps as one numbered List with the first step's style, or as they were. */
|
|
206
|
+
private counterList(run: readonly unknown[], item: CounterItem, env: Env): N[] {
|
|
207
|
+
const parts = run.flatMap((raw) => this.element(raw, env));
|
|
208
|
+
const texts = parts.map((part) =>
|
|
209
|
+
isRecord(part["props"]) ? part["props"]["text"] : undefined,
|
|
210
|
+
);
|
|
211
|
+
if (parts.length === 0 || parts.length > 200 || !texts.every((t) => typeof t === "string"))
|
|
212
|
+
return parts;
|
|
213
|
+
const first = parts[0] as N;
|
|
214
|
+
const list = node(this.ctx, "list", {
|
|
215
|
+
items: texts as string[],
|
|
216
|
+
ordered: true,
|
|
217
|
+
...(item.marker === "decimal" ? {} : { marker: item.marker }),
|
|
218
|
+
});
|
|
219
|
+
for (const key of ["style", "devices", "states", "hiddenOn", "classes"] as const) {
|
|
220
|
+
if (first[key] !== undefined) list[key] = first[key];
|
|
221
|
+
}
|
|
222
|
+
list["editorLabel"] = "Numbered steps";
|
|
223
|
+
this.ctx.note(
|
|
224
|
+
"approximated",
|
|
225
|
+
"Numbered steps",
|
|
226
|
+
"Paragraphs numbered by your site's CSS (a counter) became one numbered List; check its spacing.",
|
|
227
|
+
);
|
|
228
|
+
return [list];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
element(raw: unknown, env: Env): N[] {
|
|
232
|
+
const ctx = this.ctx;
|
|
233
|
+
if (!isRecord(raw)) return [];
|
|
234
|
+
ctx.elements++;
|
|
235
|
+
if (ctx.elements > MAX_IMPORT_ELEMENTS || ctx.overBudget) {
|
|
236
|
+
ctx.note(
|
|
237
|
+
"skipped",
|
|
238
|
+
"Page",
|
|
239
|
+
"The page is larger than EmVB imports at once; the rest was left out. Import its sections separately.",
|
|
240
|
+
);
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
if (env.depth > MAX_WALK_DEPTH) {
|
|
244
|
+
ctx.note("skipped", "Page", "Elements nested deeper than EmVB allows were left out.");
|
|
245
|
+
return [];
|
|
246
|
+
}
|
|
247
|
+
const s = isRecord(raw["settings"]) ? raw["settings"] : {};
|
|
248
|
+
const elType = str(raw["elType"]) ?? "";
|
|
249
|
+
let nodes: N[];
|
|
250
|
+
let name: string;
|
|
251
|
+
const atomicType = elType === "widget" ? (str(raw["widgetType"]) ?? "") : elType;
|
|
252
|
+
const atomic = atomicType.startsWith("e-")
|
|
253
|
+
? atomicElement(raw, ctx, ctx.atomic, env)
|
|
254
|
+
: undefined;
|
|
255
|
+
if (atomic) {
|
|
256
|
+
if (atomic.length === 0) return [];
|
|
257
|
+
ctx.mapped++;
|
|
258
|
+
return atomic;
|
|
259
|
+
}
|
|
260
|
+
if (elType === "widget") {
|
|
261
|
+
const type = str(raw["widgetType"]) ?? "";
|
|
262
|
+
name = label(type);
|
|
263
|
+
nodes = this.widget(type, s, raw, env, name);
|
|
264
|
+
} else if (elType === "section") {
|
|
265
|
+
name = "Section";
|
|
266
|
+
nodes = this.section(raw, s, env);
|
|
267
|
+
} else if (elType === "column") {
|
|
268
|
+
name = "Column";
|
|
269
|
+
nodes = this.column(raw, s, env, 10);
|
|
270
|
+
} else if (elType === "container") {
|
|
271
|
+
name = "Container";
|
|
272
|
+
nodes = this.container(raw, s, env);
|
|
273
|
+
} else if (elType.startsWith("e-")) {
|
|
274
|
+
name = label(elType);
|
|
275
|
+
nodes = this.widget(elType, s, raw, env, name);
|
|
276
|
+
} else {
|
|
277
|
+
name = label(elType || "element");
|
|
278
|
+
ctx.note(
|
|
279
|
+
"unmapped",
|
|
280
|
+
name,
|
|
281
|
+
`Element type "${elType.slice(0, 40)}" isn't known; its children were kept.`,
|
|
282
|
+
);
|
|
283
|
+
nodes = this.walk(raw["elements"], env);
|
|
284
|
+
}
|
|
285
|
+
if (nodes.length === 0) return [];
|
|
286
|
+
ctx.mapped++;
|
|
287
|
+
const widget = elType === "widget" || elType.startsWith("e-");
|
|
288
|
+
return this.common(nodes, s, name, widget);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Motion, visibility, id, classes and custom CSS: shared by every element type. */
|
|
292
|
+
private common(nodes: N[], s: Settings, name: string, isWidget: boolean): N[] {
|
|
293
|
+
const ctx = this.ctx;
|
|
294
|
+
let [target] = nodes;
|
|
295
|
+
if (isWidget) {
|
|
296
|
+
const adv = deviceStyles(s, ctx, name, [
|
|
297
|
+
boxReader("_"),
|
|
298
|
+
widthReader("_element_custom_width"),
|
|
299
|
+
]);
|
|
300
|
+
const own = (nodes.length === 1 ? (target?.["style"] as Style | undefined) : undefined) ?? {};
|
|
301
|
+
const overlaps = adv.style ? Object.keys(adv.style).some((key) => key in own) : false;
|
|
302
|
+
const single = nodes.length === 1 && !overlaps && !(adv.devices && target?.["devices"]);
|
|
303
|
+
if (single && target) {
|
|
304
|
+
if (adv.style) target["style"] = { ...own, ...adv.style };
|
|
305
|
+
if (adv.devices) target["devices"] = adv.devices;
|
|
306
|
+
} else if (adv.style || adv.devices || nodes.length > 1) {
|
|
307
|
+
target = box(ctx, nodes, adv.style ?? {});
|
|
308
|
+
if (adv.devices) target["devices"] = adv.devices;
|
|
309
|
+
nodes = [target];
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (nodes.length !== 1 || !target) return nodes;
|
|
313
|
+
const motion = entrance(s, ctx, name);
|
|
314
|
+
if (motion) {
|
|
315
|
+
const style = { ...(target["style"] as Style | undefined) };
|
|
316
|
+
style["motion"] = { ...(style["motion"] as Style | undefined), entrance: motion };
|
|
317
|
+
target["style"] = style;
|
|
318
|
+
}
|
|
319
|
+
const hidden = hiddenOn(s);
|
|
320
|
+
if (hidden) target["hiddenOn"] = hidden;
|
|
321
|
+
const id = str(s["_element_id"]) ?? str(s["css_id"]);
|
|
322
|
+
if (id) {
|
|
323
|
+
if (isValidHtmlId(id) && !ctx.htmlIds.has(id) && !target["htmlId"]) {
|
|
324
|
+
ctx.htmlIds.add(id);
|
|
325
|
+
target["htmlId"] = id;
|
|
326
|
+
} else {
|
|
327
|
+
ctx.note(
|
|
328
|
+
"skipped",
|
|
329
|
+
name,
|
|
330
|
+
`The CSS id "${id.slice(0, 40)}" was left out (not a valid or unique id).`,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (str(s["_css_classes"]) || str(s["css_classes"])) {
|
|
335
|
+
ctx.note(
|
|
336
|
+
"skipped",
|
|
337
|
+
"CSS classes",
|
|
338
|
+
"Elementor CSS classes weren't imported; EmVB classes are made in the editor.",
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
const css = str(s["custom_css"]);
|
|
342
|
+
if (css?.trim()) {
|
|
343
|
+
const style = { ...(target["style"] as Style | undefined), ...customCss(css, ctx, name) };
|
|
344
|
+
if (Object.keys(style).length > 0) target["style"] = style;
|
|
345
|
+
}
|
|
346
|
+
if (
|
|
347
|
+
str(s["hover_animation"]) ||
|
|
348
|
+
str(s["_hover_animation"]) ||
|
|
349
|
+
str(s["button_hover_animation"])
|
|
350
|
+
) {
|
|
351
|
+
ctx.note("approximated", name, "Hover animations aren't imported.");
|
|
352
|
+
}
|
|
353
|
+
// W-954: Elementor 3 flex child settings (`_flex_size`, `_flex_align_self`, `_flex_order`).
|
|
354
|
+
const flexItem = v3FlexItem(s);
|
|
355
|
+
if (flexItem) target["style"] = { ...(target["style"] as Style | undefined), ...flexItem };
|
|
356
|
+
// W-953: Elementor 3 transforms (`_transform_*_effect`, and `_hover` for the hover state).
|
|
357
|
+
const transform = v3Transform(s, "");
|
|
358
|
+
const hoverTransform = v3Transform(s, "_hover");
|
|
359
|
+
if (transform) target["style"] = { ...(target["style"] as Style | undefined), transform };
|
|
360
|
+
if (hoverTransform) {
|
|
361
|
+
const states = { ...(target["states"] as Record<string, Style> | undefined) };
|
|
362
|
+
states["hover"] = { ...states["hover"], transform: hoverTransform };
|
|
363
|
+
target["states"] = states;
|
|
364
|
+
}
|
|
365
|
+
if (s["motion_fx_motion_fx_scrolling"] === "yes" || s["motion_fx_motion_fx_mouse"] === "yes") {
|
|
366
|
+
ctx.note(
|
|
367
|
+
"approximated",
|
|
368
|
+
name,
|
|
369
|
+
"Scrolling and mouse motion effects weren't imported; add scroll motion in the editor.",
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
if (s["sticky"] && s["sticky"] !== "")
|
|
373
|
+
ctx.note("approximated", name, "Sticky positioning wasn't imported.");
|
|
374
|
+
return nodes;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
private widget(type: string, s: Settings, raw: Settings, env: Env, name: string): N[] {
|
|
378
|
+
const ctx = this.ctx;
|
|
379
|
+
const map = WIDGETS[type];
|
|
380
|
+
if (type.startsWith("wp-widget-")) {
|
|
381
|
+
ctx.note("skipped", name, "WordPress widgets weren't imported.");
|
|
382
|
+
return [];
|
|
383
|
+
}
|
|
384
|
+
const nodes = map ? map(s, ctx, name, env, raw) : genericWidget(type, unwrapAll(s), ctx, name);
|
|
385
|
+
const dynamic = s["__dynamic__"];
|
|
386
|
+
if (isRecord(dynamic)) {
|
|
387
|
+
for (const key of Object.keys(dynamic).slice(0, 50)) {
|
|
388
|
+
const tag = dynamicTag(s, key);
|
|
389
|
+
const handled =
|
|
390
|
+
(key === "title" &&
|
|
391
|
+
(tag === "post-title" || tag === "archive-title" || tag === "page-title") &&
|
|
392
|
+
type === "heading") ||
|
|
393
|
+
(key === "image" && tag === "post-featured-image" && type === "image");
|
|
394
|
+
if (!handled && tag)
|
|
395
|
+
ctx.note("approximated", name, `Dynamic tag "${tag}" kept its fixed fallback value.`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return nodes;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Legacy Section → a full-width band with a row of columns, `content_width` wide when boxed. */
|
|
402
|
+
private section(raw: Settings, s: Settings, env: Env): N[] {
|
|
403
|
+
const ctx = this.ctx;
|
|
404
|
+
const GAPS: Record<string, number> = {
|
|
405
|
+
no: 0,
|
|
406
|
+
narrow: 5,
|
|
407
|
+
default: 10,
|
|
408
|
+
extended: 15,
|
|
409
|
+
wide: 20,
|
|
410
|
+
wider: 30,
|
|
411
|
+
};
|
|
412
|
+
const gapSetting = str(s["gap"]) ?? "default";
|
|
413
|
+
const gap =
|
|
414
|
+
gapSetting === "custom"
|
|
415
|
+
? (slider(s["gap_columns_custom"])?.value ?? 10)
|
|
416
|
+
: (GAPS[gapSetting] ?? 10);
|
|
417
|
+
const boxed = str(s["layout"]) !== "full_width";
|
|
418
|
+
const width = slider(s["content_width"]) ?? { value: 1140, unit: "px" as const };
|
|
419
|
+
const columns = (Array.isArray(raw["elements"]) ? raw["elements"] : []).flatMap((c) =>
|
|
420
|
+
isRecord(c) && c["elType"] === "column"
|
|
421
|
+
? this.counted(
|
|
422
|
+
c,
|
|
423
|
+
() =>
|
|
424
|
+
this.column(
|
|
425
|
+
c,
|
|
426
|
+
isRecord(c["settings"]) ? c["settings"] : {},
|
|
427
|
+
{ ...env, parentRow: true, depth: env.depth + 2 },
|
|
428
|
+
gap,
|
|
429
|
+
),
|
|
430
|
+
env,
|
|
431
|
+
)
|
|
432
|
+
: this.element(c, { ...env, parentRow: true, depth: env.depth + 2 }),
|
|
433
|
+
);
|
|
434
|
+
const positions: Record<string, string> = {
|
|
435
|
+
top: "flex-start",
|
|
436
|
+
middle: "center",
|
|
437
|
+
bottom: "flex-end",
|
|
438
|
+
};
|
|
439
|
+
const rowStyle: Style = {
|
|
440
|
+
flexDirection: "row",
|
|
441
|
+
gap: { value: 0, unit: "px" },
|
|
442
|
+
width: { value: 100, unit: "%" },
|
|
443
|
+
alignItems: positions[str(s["content_position"]) ?? ""] ?? "stretch",
|
|
444
|
+
...(boxed ? { maxWidth: width, marginLeft: "auto", marginRight: "auto" } : {}),
|
|
445
|
+
};
|
|
446
|
+
const row = box(ctx, columns, rowStyle);
|
|
447
|
+
row["devices"] = {
|
|
448
|
+
mobile: {
|
|
449
|
+
flexDirection:
|
|
450
|
+
str(s["reverse_order_mobile"]) === "reverse-mobile" ? "column-reverse" : "column",
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
const ds = deviceStyles(s, ctx, "Section", [
|
|
454
|
+
boxReader(""),
|
|
455
|
+
(x, d) => {
|
|
456
|
+
const out: Style = {};
|
|
457
|
+
const height = str(x[`height${d}`]);
|
|
458
|
+
if (height === "full") out["minHeight"] = { value: 100, unit: "vh" };
|
|
459
|
+
else if (height === "min-height") {
|
|
460
|
+
const min = slider(x[`custom_height${d}`]);
|
|
461
|
+
if (min) out["minHeight"] = min;
|
|
462
|
+
}
|
|
463
|
+
return out;
|
|
464
|
+
},
|
|
465
|
+
]);
|
|
466
|
+
const style: Style = { gap: { value: 0, unit: "px" }, ...ds.style };
|
|
467
|
+
if (style["minHeight"])
|
|
468
|
+
style["justifyContent"] = positions[str(s["column_position"]) ?? "middle"] ?? "center";
|
|
469
|
+
const tag = str(s["html_tag"]);
|
|
470
|
+
const outer = node(
|
|
471
|
+
ctx,
|
|
472
|
+
"container",
|
|
473
|
+
tag && ["section", "header", "footer", "main", "article", "aside", "nav", "div"].includes(tag)
|
|
474
|
+
? { tag }
|
|
475
|
+
: { tag: "section" },
|
|
476
|
+
{
|
|
477
|
+
style,
|
|
478
|
+
children: [row],
|
|
479
|
+
editorLabel: "Section",
|
|
480
|
+
},
|
|
481
|
+
);
|
|
482
|
+
if (ds.devices) outer["devices"] = ds.devices;
|
|
483
|
+
return [outer];
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Runs `build` as one counted element (for columns built directly by their section). */
|
|
487
|
+
private counted(c: Settings, build: () => N[], env: Env): N[] {
|
|
488
|
+
void env;
|
|
489
|
+
this.ctx.elements++;
|
|
490
|
+
const nodes = build();
|
|
491
|
+
if (nodes.length > 0) this.ctx.mapped++;
|
|
492
|
+
return this.common(nodes, isRecord(c["settings"]) ? c["settings"] : {}, "Column", false);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** Legacy Column: its width in %, its widgets in a column with 20px between them. */
|
|
496
|
+
private column(raw: Settings, s: Settings, env: Env, gap: number): N[] {
|
|
497
|
+
const ctx = this.ctx;
|
|
498
|
+
const size = num(s["_inline_size"]) ?? num(s["_column_size"]) ?? 100;
|
|
499
|
+
const children = this.walk(raw["elements"], { ...env, parentRow: false, depth: env.depth + 1 });
|
|
500
|
+
const positions: Record<string, string> = {
|
|
501
|
+
top: "flex-start",
|
|
502
|
+
center: "center",
|
|
503
|
+
bottom: "flex-end",
|
|
504
|
+
};
|
|
505
|
+
const ds = deviceStyles(s, ctx, "Column", [
|
|
506
|
+
boxReader(""),
|
|
507
|
+
(x, d) => {
|
|
508
|
+
const out: Style = {};
|
|
509
|
+
const inline = num(x[`_inline_size${d}`]);
|
|
510
|
+
if (d === "") out["width"] = { value: Math.min(100, Math.max(1, size)), unit: "%" };
|
|
511
|
+
else if (inline !== undefined)
|
|
512
|
+
out["width"] = { value: Math.min(100, Math.max(1, inline)), unit: "%" };
|
|
513
|
+
else if (d === "_mobile") out["width"] = { value: 100, unit: "%" };
|
|
514
|
+
return out;
|
|
515
|
+
},
|
|
516
|
+
]);
|
|
517
|
+
const style: Style = { gap: { value: 20, unit: "px" }, ...ds.style };
|
|
518
|
+
if (!["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"].some((k) => k in style)) {
|
|
519
|
+
for (const side of ["Top", "Right", "Bottom", "Left"])
|
|
520
|
+
style[`padding${side}`] = { value: gap, unit: "px" };
|
|
521
|
+
}
|
|
522
|
+
const position = positions[str(s["content_position"]) ?? ""];
|
|
523
|
+
if (position) style["justifyContent"] = position;
|
|
524
|
+
const n = node(ctx, "container", {}, { style, children, editorLabel: "Column" });
|
|
525
|
+
if (ds.devices) n["devices"] = ds.devices;
|
|
526
|
+
return [n];
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Flexbox or Grid Container; a boxed one is a full-width box around a centred inner box. */
|
|
530
|
+
private container(raw: Settings, s: Settings, env: Env): N[] {
|
|
531
|
+
const ctx = this.ctx;
|
|
532
|
+
const grid = str(s["container_type"]) === "grid";
|
|
533
|
+
const boxed = (str(s["content_width"]) ?? "boxed") === "boxed";
|
|
534
|
+
const outerDs = deviceStyles(s, ctx, "Container", [boxReader(""), widthReader("width")]);
|
|
535
|
+
const layoutDs = grid
|
|
536
|
+
? deviceStyles(s, ctx, "Container", [gridReader])
|
|
537
|
+
: deviceStyles(s, ctx, "Container", [flexReader]);
|
|
538
|
+
const outerStyle: Style = { ...outerDs.style };
|
|
539
|
+
if (
|
|
540
|
+
!["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"].some((k) => k in outerStyle)
|
|
541
|
+
) {
|
|
542
|
+
for (const side of ["Top", "Right", "Bottom", "Left"])
|
|
543
|
+
outerStyle[`padding${side}`] = { value: 10, unit: "px" };
|
|
544
|
+
}
|
|
545
|
+
if (env.parentRow && !("width" in outerStyle)) outerStyle["width"] = { value: 100, unit: "%" };
|
|
546
|
+
const innerStyle: Style = { ...layoutDs.style };
|
|
547
|
+
const row =
|
|
548
|
+
!grid &&
|
|
549
|
+
(innerStyle["flexDirection"] === "row" || innerStyle["flexDirection"] === "row-reverse");
|
|
550
|
+
const children = this.walk(raw["elements"], {
|
|
551
|
+
...env,
|
|
552
|
+
parentRow: row,
|
|
553
|
+
depth: env.depth + (boxed ? 2 : 1),
|
|
554
|
+
});
|
|
555
|
+
const tag = str(s["html_tag"]);
|
|
556
|
+
const props: Record<string, unknown> = {
|
|
557
|
+
...(tag &&
|
|
558
|
+
["section", "header", "footer", "main", "article", "aside", "nav", "div"].includes(tag)
|
|
559
|
+
? { tag }
|
|
560
|
+
: {}),
|
|
561
|
+
...(str(s["html_tag"]) === "a" ? href(s["link"], ctx) : {}),
|
|
562
|
+
};
|
|
563
|
+
if (tag && !props["tag"] && tag !== "a")
|
|
564
|
+
ctx.note("approximated", "Container", `HTML tag "${tag.slice(0, 20)}" is shown as a div.`);
|
|
565
|
+
const columns = grid ? gridColumns(s) : undefined;
|
|
566
|
+
const layoutDevices = layoutDs.devices;
|
|
567
|
+
|
|
568
|
+
if (!boxed) {
|
|
569
|
+
const style = { ...outerStyle, ...innerStyle };
|
|
570
|
+
const n = grid
|
|
571
|
+
? node(
|
|
572
|
+
ctx,
|
|
573
|
+
"grid",
|
|
574
|
+
{ ...gridProps(columns), ...(props["href"] ? { href: props["href"] } : {}) },
|
|
575
|
+
{ style, children },
|
|
576
|
+
)
|
|
577
|
+
: node(ctx, "container", props, { style, children });
|
|
578
|
+
const devices = mergeDevices(outerDs.devices, layoutDevices);
|
|
579
|
+
if (devices) n["devices"] = devices;
|
|
580
|
+
return [n];
|
|
581
|
+
}
|
|
582
|
+
const boxedWidth = slider(s["boxed_width"]) ?? { value: 1140, unit: "px" as const };
|
|
583
|
+
const minHeight = innerStyle["minHeight"];
|
|
584
|
+
delete innerStyle["minHeight"];
|
|
585
|
+
const inner = grid
|
|
586
|
+
? node(ctx, "grid", gridProps(columns), {
|
|
587
|
+
style: {
|
|
588
|
+
...innerStyle,
|
|
589
|
+
width: { value: 100, unit: "%" },
|
|
590
|
+
maxWidth: boxedWidth,
|
|
591
|
+
marginLeft: "auto",
|
|
592
|
+
marginRight: "auto",
|
|
593
|
+
},
|
|
594
|
+
children,
|
|
595
|
+
})
|
|
596
|
+
: node(
|
|
597
|
+
ctx,
|
|
598
|
+
"container",
|
|
599
|
+
{},
|
|
600
|
+
{
|
|
601
|
+
style: {
|
|
602
|
+
...innerStyle,
|
|
603
|
+
width: { value: 100, unit: "%" },
|
|
604
|
+
maxWidth: boxedWidth,
|
|
605
|
+
marginLeft: "auto",
|
|
606
|
+
marginRight: "auto",
|
|
607
|
+
},
|
|
608
|
+
children,
|
|
609
|
+
},
|
|
610
|
+
);
|
|
611
|
+
// Min height belongs to the outer box on every device, as on desktop.
|
|
612
|
+
const outerDevices = { ...outerDs.devices };
|
|
613
|
+
const innerDevices: { tablet?: Style; mobile?: Style } = {};
|
|
614
|
+
for (const key of ["tablet", "mobile"] as const) {
|
|
615
|
+
const layout = layoutDevices?.[key];
|
|
616
|
+
if (!layout) continue;
|
|
617
|
+
const { minHeight: deviceMin, ...rest } = layout;
|
|
618
|
+
if (deviceMin !== undefined)
|
|
619
|
+
outerDevices[key] = { ...outerDevices[key], minHeight: deviceMin };
|
|
620
|
+
if (Object.keys(rest).length > 0) innerDevices[key] = rest;
|
|
621
|
+
}
|
|
622
|
+
if (Object.keys(innerDevices).length > 0) inner["devices"] = innerDevices;
|
|
623
|
+
const outer = node(ctx, "container", props, {
|
|
624
|
+
style: {
|
|
625
|
+
...outerStyle,
|
|
626
|
+
gap: { value: 0, unit: "px" },
|
|
627
|
+
...(minHeight ? { minHeight } : {}),
|
|
628
|
+
// The inner box sits where the container's content would: centred when Elementor centres it.
|
|
629
|
+
...(minHeight ? { justifyContent: verticalOf(innerStyle, grid) } : {}),
|
|
630
|
+
},
|
|
631
|
+
children: [inner],
|
|
632
|
+
});
|
|
633
|
+
if (Object.keys(outerDevices).length > 0) outer["devices"] = outerDevices;
|
|
634
|
+
return [outer];
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** Grid props: three columns and one on phones unless the container says otherwise. */
|
|
639
|
+
const gridProps = (cols: Record<string, number> | undefined): Record<string, unknown> => ({
|
|
640
|
+
columns: cols?.["d"] ?? 3,
|
|
641
|
+
...(cols?.["t"] ? { columnsTablet: cols["t"] } : {}),
|
|
642
|
+
...(cols?.["m"] ? { columnsMobile: cols["m"] } : { columnsMobile: 1 }),
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
/** Elementor 3 flex child settings → EmVB flex item keys. */
|
|
646
|
+
function v3FlexItem(s: Settings): Style | undefined {
|
|
647
|
+
const out: Style = {};
|
|
648
|
+
const sizeMode = str(s["_flex_size"]);
|
|
649
|
+
if (sizeMode === "grow") out["flexGrow"] = 1;
|
|
650
|
+
else if (sizeMode === "shrink") out["flexShrink"] = 1;
|
|
651
|
+
else if (sizeMode === "none") {
|
|
652
|
+
out["flexGrow"] = 0;
|
|
653
|
+
out["flexShrink"] = 0;
|
|
654
|
+
} else if (sizeMode === "custom") {
|
|
655
|
+
const grow = num(s["_flex_grow"]);
|
|
656
|
+
const shrink = num(s["_flex_shrink"]);
|
|
657
|
+
if (grow !== undefined && grow >= 0 && grow <= 100) out["flexGrow"] = grow;
|
|
658
|
+
if (shrink !== undefined && shrink >= 0 && shrink <= 100) out["flexShrink"] = shrink;
|
|
659
|
+
}
|
|
660
|
+
const align = str(s["_flex_align_self"]);
|
|
661
|
+
const alignMap: Record<string, string> = {
|
|
662
|
+
"flex-start": "flex-start",
|
|
663
|
+
start: "flex-start",
|
|
664
|
+
center: "center",
|
|
665
|
+
"flex-end": "flex-end",
|
|
666
|
+
end: "flex-end",
|
|
667
|
+
stretch: "stretch",
|
|
668
|
+
};
|
|
669
|
+
if (align && alignMap[align]) out["alignSelf"] = alignMap[align];
|
|
670
|
+
const order = str(s["_flex_order"]);
|
|
671
|
+
if (order === "start") out["order"] = -99;
|
|
672
|
+
else if (order === "end") out["order"] = 99;
|
|
673
|
+
else if (order === "custom") {
|
|
674
|
+
const n = num(s["_flex_order_custom"]);
|
|
675
|
+
if (n !== undefined && Number.isInteger(n)) out["order"] = Math.min(99, Math.max(-99, n));
|
|
676
|
+
}
|
|
677
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/** Elementor 3 transform settings (`_transform_translateX_effect` …) for a state suffix. */
|
|
681
|
+
function v3Transform(s: Settings, state: "" | "_hover"): Record<string, number> | undefined {
|
|
682
|
+
const sizeOf = (key: string) => {
|
|
683
|
+
const value = s[`_transform_${key}_effect${state}`];
|
|
684
|
+
return num(isRecord(value) ? value["size"] : value);
|
|
685
|
+
};
|
|
686
|
+
const out: Record<string, number> = {};
|
|
687
|
+
const x = sizeOf("translateX");
|
|
688
|
+
const y = sizeOf("translateY");
|
|
689
|
+
const scale = sizeOf("scale");
|
|
690
|
+
const rotate = sizeOf("rotateZ");
|
|
691
|
+
if (x !== undefined && x !== 0) out["x"] = Math.round(Math.min(2000, Math.max(-2000, x)));
|
|
692
|
+
if (y !== undefined && y !== 0) out["y"] = Math.round(Math.min(2000, Math.max(-2000, y)));
|
|
693
|
+
if (scale !== undefined && scale !== 1)
|
|
694
|
+
out["scale"] = Math.round(Math.min(4, Math.max(0.1, scale)) * 100);
|
|
695
|
+
if (rotate !== undefined && rotate !== 0)
|
|
696
|
+
out["rotate"] = Math.round(Math.min(360, Math.max(-360, rotate)));
|
|
697
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function verticalOf(style: Style, grid: boolean): string {
|
|
701
|
+
if (grid) return "flex-start";
|
|
702
|
+
const column = style["flexDirection"] === "column" || style["flexDirection"] === "column-reverse";
|
|
703
|
+
const value = column ? style["justifyContent"] : style["alignItems"];
|
|
704
|
+
return value === "center" || value === "flex-end" ? (value as string) : "flex-start";
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/** Grid gaps and minimum height per device (column counts are props, see gridColumns). */
|
|
708
|
+
const gridReader = (s: Settings, d: "" | "_laptop" | "_tablet" | "_mobile"): Style => {
|
|
709
|
+
const style: Style = {};
|
|
710
|
+
const gaps = s[`grid_gaps${d}`];
|
|
711
|
+
const gap = isRecord(gaps)
|
|
712
|
+
? slider({ size: gaps["column"] ?? gaps["size"], unit: gaps["unit"] })
|
|
713
|
+
: undefined;
|
|
714
|
+
if (gap) style["gap"] = gap;
|
|
715
|
+
else if (d === "") style["gap"] = { value: 20, unit: "px" };
|
|
716
|
+
const min = slider(s[`min_height${d}`]);
|
|
717
|
+
if (min) style["minHeight"] = min;
|
|
718
|
+
return style;
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
function mergeDevices(
|
|
722
|
+
a?: { laptop?: Style; tablet?: Style; mobile?: Style },
|
|
723
|
+
b?: { laptop?: Style; tablet?: Style; mobile?: Style },
|
|
724
|
+
) {
|
|
725
|
+
if (!a && !b) return undefined;
|
|
726
|
+
const out: { laptop?: Style; tablet?: Style; mobile?: Style } = {};
|
|
727
|
+
for (const key of ["laptop", "tablet", "mobile"] as const) {
|
|
728
|
+
const merged = { ...a?.[key], ...b?.[key] };
|
|
729
|
+
if (Object.keys(merged).length > 0) out[key] = merged;
|
|
730
|
+
}
|
|
731
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/** Grid column counts per device (`d`, `t`, `m`). */
|
|
735
|
+
function gridColumns(s: Settings): Record<string, number> {
|
|
736
|
+
const out: Record<string, number> = {};
|
|
737
|
+
for (const [d, k] of [
|
|
738
|
+
["", "d"],
|
|
739
|
+
["_tablet", "t"],
|
|
740
|
+
["_mobile", "m"],
|
|
741
|
+
] as const) {
|
|
742
|
+
const cols = s[`grid_columns_grid${d}`];
|
|
743
|
+
const count = num(isRecord(cols) ? cols["size"] : cols);
|
|
744
|
+
if (count !== undefined) out[k] = Math.min(12, Math.max(1, Math.round(count)));
|
|
745
|
+
}
|
|
746
|
+
return out;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
function unwrapAll(s: Settings): Settings {
|
|
750
|
+
const out: Settings = {};
|
|
751
|
+
for (const [key, value] of Object.entries(s)) out[key] = unwrap(value);
|
|
752
|
+
return out;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// ---------------------------------------------------------------------------------------------
|
|
756
|
+
// Validation: prune what EmVB refuses, never fail the import for one bad value
|
|
757
|
+
|
|
758
|
+
type Found = { node: N; parent?: N; rest: string[] };
|
|
759
|
+
|
|
760
|
+
function locate(root: N, path: string): Found | undefined {
|
|
761
|
+
if (!path.startsWith("root")) return undefined;
|
|
762
|
+
const tokens = path
|
|
763
|
+
.slice(4)
|
|
764
|
+
.split(/\.|\[|\]/)
|
|
765
|
+
.filter(Boolean);
|
|
766
|
+
let current: N = root;
|
|
767
|
+
let parent: N | undefined;
|
|
768
|
+
let i = 0;
|
|
769
|
+
while (i < tokens.length && tokens[i] === "children") {
|
|
770
|
+
const kids = current["children"];
|
|
771
|
+
const index = Number(tokens[i + 1]);
|
|
772
|
+
if (!Array.isArray(kids) || !Number.isInteger(index) || !kids[index]) break;
|
|
773
|
+
parent = current;
|
|
774
|
+
current = kids[index] as N;
|
|
775
|
+
i += 2;
|
|
776
|
+
}
|
|
777
|
+
return { node: current, ...(parent ? { parent } : {}), rest: tokens.slice(i) };
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function prune(
|
|
781
|
+
root: N,
|
|
782
|
+
issue: { path: string; code: string; message: string },
|
|
783
|
+
ctx: ImportContext,
|
|
784
|
+
tried: Set<string>,
|
|
785
|
+
): boolean {
|
|
786
|
+
if (issue.code === "too_large" || issue.code === "too_many_nodes") {
|
|
787
|
+
const kids = root["children"] as N[];
|
|
788
|
+
if (kids.length <= 1) return false;
|
|
789
|
+
kids.pop();
|
|
790
|
+
ctx.note(
|
|
791
|
+
"skipped",
|
|
792
|
+
"Page",
|
|
793
|
+
"The page was larger than EmVB allows; its last sections were left out. Import them separately.",
|
|
794
|
+
);
|
|
795
|
+
return true;
|
|
796
|
+
}
|
|
797
|
+
const found = locate(root, issue.path);
|
|
798
|
+
if (!found) return false;
|
|
799
|
+
const { node: target, parent, rest } = found;
|
|
800
|
+
const [head, k1, k2] = rest;
|
|
801
|
+
if (
|
|
802
|
+
head === "style" ||
|
|
803
|
+
head === "states" ||
|
|
804
|
+
head === "devices" ||
|
|
805
|
+
head === "htmlId" ||
|
|
806
|
+
head === "query" ||
|
|
807
|
+
head === "hiddenOn"
|
|
808
|
+
) {
|
|
809
|
+
const holder = target[head];
|
|
810
|
+
if (head === "style" && k1 && isRecord(holder)) delete holder[k1];
|
|
811
|
+
else if (
|
|
812
|
+
(head === "states" || head === "devices") &&
|
|
813
|
+
k1 &&
|
|
814
|
+
k2 &&
|
|
815
|
+
isRecord(holder) &&
|
|
816
|
+
isRecord(holder[k1])
|
|
817
|
+
)
|
|
818
|
+
delete (holder[k1] as Settings)[k2];
|
|
819
|
+
else delete target[head];
|
|
820
|
+
ctx.note("approximated", "Styles", "Some style values EmVB can't use were left out.");
|
|
821
|
+
return true;
|
|
822
|
+
}
|
|
823
|
+
if (head === "props" && k1 && !tried.has(`${target.id}.${k1}`)) {
|
|
824
|
+
tried.add(`${target.id}.${k1}`);
|
|
825
|
+
delete target.props[k1];
|
|
826
|
+
return true;
|
|
827
|
+
}
|
|
828
|
+
if (!parent) return false;
|
|
829
|
+
const kids = parent["children"] as N[];
|
|
830
|
+
parent["children"] = kids.filter((kid) => kid !== target);
|
|
831
|
+
ctx.note(
|
|
832
|
+
"skipped",
|
|
833
|
+
"Elements",
|
|
834
|
+
`An element EmVB couldn't use was left out (${issue.message.slice(0, 120)}).`,
|
|
835
|
+
);
|
|
836
|
+
return true;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/** Elementor JSON → an EmVB layout and an import report. */
|
|
840
|
+
export function importElementor(input: unknown, options: ImportOptions = {}): ElementorImport {
|
|
841
|
+
const source = readSource(input);
|
|
842
|
+
if ("error" in source) return { ok: false, error: source.error };
|
|
843
|
+
if (source.elements.length === 0) return { ok: false, error: "This export has no elements." };
|
|
844
|
+
const ctx = new ImportContext(options);
|
|
845
|
+
if (source.record) readSnapshots(source.record, ctx.atomic);
|
|
846
|
+
if (isRecord(options.kit)) readSnapshots(options.kit, ctx.atomic);
|
|
847
|
+
ctx.findOldSite(JSON.stringify([source.elements, source.pageSettings ?? {}]));
|
|
848
|
+
{
|
|
849
|
+
const kitCustom =
|
|
850
|
+
isRecord(options.kit) && isRecord(options.kit["settings"])
|
|
851
|
+
? str(options.kit["settings"]["custom_css"])
|
|
852
|
+
: undefined;
|
|
853
|
+
const pageCustom = source.pageSettings ? str(source.pageSettings["custom_css"]) : undefined;
|
|
854
|
+
ctx.wordRules = wordRules(`${kitCustom ?? ""}\n${pageCustom ?? ""}`);
|
|
855
|
+
ctx.counterItems = counterItems(`${kitCustom ?? ""}\n${pageCustom ?? ""}`);
|
|
856
|
+
}
|
|
857
|
+
const walker = new Walker(ctx);
|
|
858
|
+
const children = walker.walk(source.elements, { parentRow: false, depth: 1, walk: walker.walk });
|
|
859
|
+
if (children.length === 0)
|
|
860
|
+
return {
|
|
861
|
+
ok: false,
|
|
862
|
+
error:
|
|
863
|
+
"Nothing in this export could be imported. See the report for what was left out." +
|
|
864
|
+
(ctx.report()[0] ? ` (${ctx.report()[0]?.message})` : ""),
|
|
865
|
+
};
|
|
866
|
+
const page = source.pageSettings ?? {};
|
|
867
|
+
const pageStyle = deviceStyles(page, ctx, "Page", [boxReader("")]);
|
|
868
|
+
const pageCss = str(page["custom_css"]);
|
|
869
|
+
// The kit's custom CSS sets site-wide text defaults on `body` (font, colour): the page root
|
|
870
|
+
// takes them, below the page's own settings.
|
|
871
|
+
const kitSettings =
|
|
872
|
+
isRecord(options.kit) && isRecord(options.kit["settings"])
|
|
873
|
+
? options.kit["settings"]
|
|
874
|
+
: undefined;
|
|
875
|
+
const kitCss = kitSettings ? str(kitSettings["custom_css"]) : undefined;
|
|
876
|
+
const kitStyle = kitCss ? customCss(kitCss, ctx, "Site kit") : {};
|
|
877
|
+
const root = box(ctx, children, {
|
|
878
|
+
flexDirection: "column",
|
|
879
|
+
...kitStyle,
|
|
880
|
+
...pageStyle.style,
|
|
881
|
+
...(pageCss ? customCss(pageCss, ctx, "Page") : {}),
|
|
882
|
+
});
|
|
883
|
+
if (pageStyle.devices) root["devices"] = pageStyle.devices;
|
|
884
|
+
if (options.media) useCopies(root, ctx);
|
|
885
|
+
const candidate: Record<string, unknown> = { schemaVersion: LAYOUT_SCHEMA_VERSION, root };
|
|
886
|
+
const tried = new Set<string>();
|
|
887
|
+
for (let attempt = 0; attempt < 500; attempt++) {
|
|
888
|
+
const checked = validateLayout(candidate);
|
|
889
|
+
// The save hook also refuses misplaced elements (a field outside a form, …): prune those too.
|
|
890
|
+
const misplaced = checked.ok ? nestingIssues(checked.layout, 1)[0] : undefined;
|
|
891
|
+
if (checked.ok && !misplaced) {
|
|
892
|
+
const partType = source.type ? PART_TYPES[source.type] : undefined;
|
|
893
|
+
return {
|
|
894
|
+
ok: true,
|
|
895
|
+
layout: checked.layout,
|
|
896
|
+
...(source.title ? { title: source.title } : {}),
|
|
897
|
+
...(partType ? { partType } : {}),
|
|
898
|
+
elements: ctx.elements,
|
|
899
|
+
mapped: ctx.mapped,
|
|
900
|
+
notes: ctx.report(),
|
|
901
|
+
fonts: [...ctx.fonts].toSorted(),
|
|
902
|
+
svgFiles: [...ctx.svgFiles],
|
|
903
|
+
pageLinks: [...ctx.pageLinks].toSorted((a, b) => a - b),
|
|
904
|
+
images: [...ctx.images],
|
|
905
|
+
classes: usedClasses(checked.layout, ctx).map((cls) =>
|
|
906
|
+
options.media ? (useCopies(structuredClone(cls), ctx) as StyleClass) : cls,
|
|
907
|
+
),
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
const issue = checked.ok ? misplaced : checked.issues[0];
|
|
911
|
+
if (!issue || !prune(root, issue, ctx, tried)) {
|
|
912
|
+
return {
|
|
913
|
+
ok: false,
|
|
914
|
+
error: `The imported page couldn't be made valid: ${issue?.message ?? "unknown problem"}`,
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
return { ok: false, error: "The imported page couldn't be made valid." };
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* W-958: points every use of an old-site image at its media library copy: image sources (which
|
|
923
|
+
* also get the library id), backgrounds and any other stored address equal to it.
|
|
924
|
+
*/
|
|
925
|
+
function useCopies(value: unknown, ctx: ImportContext): unknown {
|
|
926
|
+
if (typeof value === "string")
|
|
927
|
+
return /^https?:\/\//i.test(value) ? (ctx.copied(value)?.url ?? value) : value;
|
|
928
|
+
if (Array.isArray(value)) {
|
|
929
|
+
for (let i = 0; i < value.length; i++) value[i] = useCopies(value[i], ctx);
|
|
930
|
+
return value;
|
|
931
|
+
}
|
|
932
|
+
if (!isRecord(value)) return value;
|
|
933
|
+
const props = value["type"] === "image" && isRecord(value["props"]) ? value["props"] : undefined;
|
|
934
|
+
const copy = props && typeof props["src"] === "string" ? ctx.copied(props["src"]) : undefined;
|
|
935
|
+
for (const [key, inner] of Object.entries(value)) value[key] = useCopies(inner, ctx);
|
|
936
|
+
if (props && copy?.id) props["mediaId"] = copy.id;
|
|
937
|
+
return value;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/** W-958: the imported classes still used once the page is valid (pruning can drop elements). */
|
|
941
|
+
function usedClasses(layout: Layout, ctx: ImportContext): StyleClass[] {
|
|
942
|
+
const used = new Set<string>();
|
|
943
|
+
const visit = (item: LayoutNode) => {
|
|
944
|
+
for (const id of item.classes ?? []) used.add(id);
|
|
945
|
+
nodeChildren(item).forEach(visit);
|
|
946
|
+
};
|
|
947
|
+
visit(layout.root);
|
|
948
|
+
return [...ctx.imported.values()].flatMap((c) => (c && used.has(c.id) ? [c.cls] : []));
|
|
949
|
+
}
|