@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,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-958: Elementor global classes as EmVB classes, without changing how a page looks.
|
|
3
|
+
*
|
|
4
|
+
* EmVB writes class rules before element rules, at the base and inside each device's media
|
|
5
|
+
* query, and a `:hover`, `:focus` or `:active` rule outranks a plain one. So on a device the
|
|
6
|
+
* winner is the last of: class desktop, element desktop, class laptop, element laptop, class
|
|
7
|
+
* tablet, element tablet, class mobile, element mobile; in a state, the element's state beats the class's, which beats both.
|
|
8
|
+
*/
|
|
9
|
+
import type { Style } from "./style.ts";
|
|
10
|
+
|
|
11
|
+
export const STATE_NAMES = ["hover", "focus", "active"] as const;
|
|
12
|
+
type StateName = (typeof STATE_NAMES)[number];
|
|
13
|
+
|
|
14
|
+
/** Desktop style, tablet and mobile overrides, and state styles, as EmVB stores them. */
|
|
15
|
+
export type Layers = { desktop: Style; laptop: Style; tablet: Style; mobile: Style } & Record<
|
|
16
|
+
StateName,
|
|
17
|
+
Style
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
const DEVICES = ["desktop", "laptop", "tablet", "mobile"] as const;
|
|
21
|
+
type Device = (typeof DEVICES)[number];
|
|
22
|
+
|
|
23
|
+
/** Values compare by content, whatever their key order. */
|
|
24
|
+
function same(a: unknown, b: unknown): boolean {
|
|
25
|
+
return stable(a) === stable(b);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function stable(value: unknown): string {
|
|
29
|
+
const sorted = (v: unknown): unknown =>
|
|
30
|
+
Array.isArray(v)
|
|
31
|
+
? v.map(sorted)
|
|
32
|
+
: typeof v === "object" && v !== null
|
|
33
|
+
? Object.fromEntries(
|
|
34
|
+
Object.keys(v)
|
|
35
|
+
.toSorted()
|
|
36
|
+
.map((k) => [k, sorted((v as Record<string, unknown>)[k])]),
|
|
37
|
+
)
|
|
38
|
+
: v;
|
|
39
|
+
return JSON.stringify(sorted(value)) ?? "undefined";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** What an element alone shows on a device: its style with the overrides down to it. */
|
|
43
|
+
function elementAt(l: Layers, device: Device): Style {
|
|
44
|
+
if (device === "desktop") return l.desktop;
|
|
45
|
+
if (device === "laptop") return { ...l.desktop, ...l.laptop };
|
|
46
|
+
if (device === "tablet") return { ...l.desktop, ...l.laptop, ...l.tablet };
|
|
47
|
+
return { ...l.desktop, ...l.laptop, ...l.tablet, ...l.mobile };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** What class rules plus element rules show on a device, in EmVB's rule order. */
|
|
51
|
+
function cascadeAt(cls: Layers, own: Layers, device: Device): Style {
|
|
52
|
+
const out: Style = { ...cls.desktop, ...own.desktop };
|
|
53
|
+
if (device === "desktop") return out;
|
|
54
|
+
Object.assign(out, cls.laptop, own.laptop);
|
|
55
|
+
if (device === "laptop") return out;
|
|
56
|
+
Object.assign(out, cls.tablet, own.tablet);
|
|
57
|
+
if (device === "tablet") return out;
|
|
58
|
+
return Object.assign(out, cls.mobile, own.mobile);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Several classes on one element as one set of layers. Undefined when two of them set the same
|
|
63
|
+
* key differently in a layer: their order on the site (the Site styles order) would decide.
|
|
64
|
+
*/
|
|
65
|
+
export function combineLayers(list: readonly Layers[]): Layers | undefined {
|
|
66
|
+
const out: Layers = {
|
|
67
|
+
desktop: {},
|
|
68
|
+
laptop: {},
|
|
69
|
+
tablet: {},
|
|
70
|
+
mobile: {},
|
|
71
|
+
hover: {},
|
|
72
|
+
focus: {},
|
|
73
|
+
active: {},
|
|
74
|
+
};
|
|
75
|
+
for (const layers of list) {
|
|
76
|
+
for (const name of [...DEVICES, ...STATE_NAMES]) {
|
|
77
|
+
for (const [key, value] of Object.entries(layers[name])) {
|
|
78
|
+
if (key in out[name] && !same(out[name][key], value)) return undefined;
|
|
79
|
+
out[name][key] = value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The fewest inline values that, over `cls`, show exactly `want` on every device and in every
|
|
88
|
+
* state. Undefined when that can't be done: a class sets something `want` doesn't have (inline
|
|
89
|
+
* styles can't unset it), or a class state value would need a different undo per device.
|
|
90
|
+
*/
|
|
91
|
+
export function inlineOver(want: Layers, cls: Layers): Layers | undefined {
|
|
92
|
+
const own: Layers = {
|
|
93
|
+
desktop: {},
|
|
94
|
+
laptop: {},
|
|
95
|
+
tablet: {},
|
|
96
|
+
mobile: {},
|
|
97
|
+
hover: {},
|
|
98
|
+
focus: {},
|
|
99
|
+
active: {},
|
|
100
|
+
};
|
|
101
|
+
for (const device of DEVICES) {
|
|
102
|
+
const target = elementAt(want, device);
|
|
103
|
+
const shown = cascadeAt(cls, own, device);
|
|
104
|
+
for (const key of new Set([...Object.keys(target), ...Object.keys(shown)])) {
|
|
105
|
+
if (same(target[key], shown[key])) continue;
|
|
106
|
+
if (target[key] === undefined) return undefined;
|
|
107
|
+
own[device][key] = target[key];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
for (const state of STATE_NAMES) {
|
|
111
|
+
for (const key of new Set([...Object.keys(want[state]), ...Object.keys(cls[state])])) {
|
|
112
|
+
if (key in want[state]) {
|
|
113
|
+
if (!(key in cls[state]) || !same(cls[state][key], want[state][key])) {
|
|
114
|
+
own[state][key] = want[state][key];
|
|
115
|
+
}
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
// The class's state value covers every device; the element must undo it with the value
|
|
119
|
+
// it shows there, which only works when that value is the same on every device.
|
|
120
|
+
const values = DEVICES.map((device) => elementAt(want, device)[key]);
|
|
121
|
+
const first = values[0];
|
|
122
|
+
if (first === undefined || values.some((v) => !same(v, first))) return undefined;
|
|
123
|
+
own[state][key] = first;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return own;
|
|
127
|
+
}
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
/** Shared state of one Elementor import (W-945): ids, globals, icons, limits and the report. */
|
|
2
|
+
import { ICON_SVG_MAX } from "../../schema/layout.ts";
|
|
3
|
+
import { sanitizeHref } from "../../sanitize/href.ts";
|
|
4
|
+
import { sanitizeMediaUrl } from "../../sanitize/media-url.ts";
|
|
5
|
+
import { isSafeSvgMarkup } from "../../sanitize/svg.ts";
|
|
6
|
+
import { emptyDesign, type DesignSystem } from "../../schema/design.ts";
|
|
7
|
+
import { newNodeId, slugify } from "../../tree-ops.ts";
|
|
8
|
+
import { validateDesign } from "../../validate.ts";
|
|
9
|
+
import type { Layers } from "./classes.ts";
|
|
10
|
+
import type { CounterItem } from "./counter-steps.ts";
|
|
11
|
+
import { type AtomicSnapshots, emptySnapshots } from "./snapshots.ts";
|
|
12
|
+
import { color, fontStack, fontWeight, isRecord, slider, str, type Settings } from "./values.ts";
|
|
13
|
+
|
|
14
|
+
export type StyleClass = NonNullable<DesignSystem["classes"]>[number];
|
|
15
|
+
|
|
16
|
+
/** W-958: an Elementor global class as the EmVB class the import adds. */
|
|
17
|
+
export type ImportedClass = { id: string; layers: Layers; cls: StyleClass };
|
|
18
|
+
|
|
19
|
+
export type NoteKind = "approximated" | "skipped" | "unmapped";
|
|
20
|
+
|
|
21
|
+
/** One line of the report. Identical notes are counted, not repeated. */
|
|
22
|
+
export type ImportNote = { kind: NoteKind; element: string; message: string; count: number };
|
|
23
|
+
|
|
24
|
+
export type GlobalTypography = {
|
|
25
|
+
fontFamily?: string;
|
|
26
|
+
fontWeight?: unknown;
|
|
27
|
+
fontSize?: unknown;
|
|
28
|
+
lineHeight?: unknown;
|
|
29
|
+
letterSpacing?: unknown;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type ImportOptions = {
|
|
33
|
+
/** The site kit's settings (Elementor's site-settings.json), for exact global colours and fonts. */
|
|
34
|
+
kit?: unknown;
|
|
35
|
+
/** Apply Elementor's default widget colours and fonts when a widget sets none (Elementor's own default). */
|
|
36
|
+
defaults?: boolean;
|
|
37
|
+
/** SVG markup for a library icon id (`fa-solid:star`), from the editor's icon sets. */
|
|
38
|
+
icon?: (id: string) => string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* W-951: the markup of an SVG file the export points to (fetched by the dialog or chosen by the
|
|
41
|
+
* person), so it becomes a recolourable icon instead of an image.
|
|
42
|
+
*/
|
|
43
|
+
svg?: (url: string) => string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* W-958: where a link to a WordPress page (by its post id) goes on this site, such as
|
|
46
|
+
* `/products`; chosen in the import dialog.
|
|
47
|
+
*/
|
|
48
|
+
pageLink?: (id: number) => string | undefined;
|
|
49
|
+
/** W-958: an old-site image's copy in the media library (its address and media id). */
|
|
50
|
+
media?: (url: string) => { url: string; id?: string } | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* W-958: point elements at their Elementor global classes as EmVB classes (returned in
|
|
53
|
+
* `classes` for the dialog to add to the site), instead of copying the classes' styles in.
|
|
54
|
+
*/
|
|
55
|
+
classes?: boolean;
|
|
56
|
+
/** Random source for node ids (tests). */
|
|
57
|
+
random?: () => number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Elementor's stock kit: what an unstyled site shows. */
|
|
61
|
+
const DEFAULT_COLORS: Record<string, string> = {
|
|
62
|
+
primary: "#6ec1e4",
|
|
63
|
+
secondary: "#54595f",
|
|
64
|
+
text: "#7a7a7a",
|
|
65
|
+
accent: "#61ce70",
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const DEFAULT_TYPOGRAPHY: Record<string, GlobalTypography> = {
|
|
69
|
+
primary: { fontFamily: "Roboto", fontWeight: "600" },
|
|
70
|
+
secondary: { fontFamily: "Roboto Slab", fontWeight: "400" },
|
|
71
|
+
text: { fontFamily: "Roboto", fontWeight: "400" },
|
|
72
|
+
accent: { fontFamily: "Roboto", fontWeight: "500" },
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** Old-site images listed for copying; an export with more lists the first ones. */
|
|
76
|
+
const MAX_IMAGES = 300;
|
|
77
|
+
|
|
78
|
+
/** Notes kept per import; the rest are counted into one line. */
|
|
79
|
+
const MAX_NOTES = 300;
|
|
80
|
+
/** Leaves room under MAX_NODES (2000) for wrappers added after the budget check. */
|
|
81
|
+
const NODE_BUDGET = 1800;
|
|
82
|
+
|
|
83
|
+
export class ImportContext {
|
|
84
|
+
readonly notes = new Map<string, ImportNote>();
|
|
85
|
+
readonly fonts = new Set<string>();
|
|
86
|
+
readonly htmlIds = new Set<string>();
|
|
87
|
+
/** Elementor 4 global classes and variables, from the export or the kit. */
|
|
88
|
+
readonly atomic: AtomicSnapshots = emptySnapshots();
|
|
89
|
+
readonly icon: ImportOptions["icon"];
|
|
90
|
+
readonly useDefaults: boolean;
|
|
91
|
+
/** W-951: SVG files the export points to whose markup wasn't given (the dialog fetches them). */
|
|
92
|
+
readonly svgFiles = new Set<string>();
|
|
93
|
+
private readonly svg: ImportOptions["svg"];
|
|
94
|
+
private readonly pageLinkOf: ImportOptions["pageLink"];
|
|
95
|
+
private readonly mediaOf: ImportOptions["media"];
|
|
96
|
+
/** W-958: Elementor class id → its EmVB class, or undefined when it can't be one. */
|
|
97
|
+
readonly imported = new Map<string, ImportedClass | undefined>();
|
|
98
|
+
readonly useClasses: boolean;
|
|
99
|
+
/** W-950: site and page CSS for emphasised and bold words inside a class (`wordRules`). */
|
|
100
|
+
wordRules = new Map<string, { color?: string; italic?: boolean; bold?: boolean }>();
|
|
101
|
+
/** W-961: classes whose `::before`/`::after` draws a CSS counter (`counterItems`). */
|
|
102
|
+
counterItems = new Map<string, CounterItem>();
|
|
103
|
+
/** W-958: images on the old site the page uses, so the dialog can copy them. */
|
|
104
|
+
readonly images = new Set<string>();
|
|
105
|
+
/** W-958: WordPress page ids the export links to, so the dialog can ask where each goes. */
|
|
106
|
+
readonly pageLinks = new Set<number>();
|
|
107
|
+
/** W-958: where the old WordPress site lives (the address before `/wp-content/`). */
|
|
108
|
+
private oldSites: URL[] = [];
|
|
109
|
+
nodes = 0;
|
|
110
|
+
elements = 0;
|
|
111
|
+
mapped = 0;
|
|
112
|
+
private readonly random: () => number;
|
|
113
|
+
private readonly colors = new Map<string, string>();
|
|
114
|
+
private readonly typography = new Map<string, GlobalTypography>();
|
|
115
|
+
private readonly kitGiven: boolean;
|
|
116
|
+
private overflow = 0;
|
|
117
|
+
|
|
118
|
+
constructor(options: ImportOptions = {}) {
|
|
119
|
+
this.random = options.random ?? Math.random;
|
|
120
|
+
this.icon = options.icon;
|
|
121
|
+
this.svg = options.svg;
|
|
122
|
+
this.pageLinkOf = options.pageLink;
|
|
123
|
+
this.mediaOf = options.media;
|
|
124
|
+
this.useClasses = options.classes === true;
|
|
125
|
+
this.useDefaults = options.defaults ?? true;
|
|
126
|
+
this.kitGiven = this.readKit(options.kit);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
id(): string {
|
|
130
|
+
this.nodes++;
|
|
131
|
+
return newNodeId(this.random);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
note(kind: NoteKind, element: string, message: string): void {
|
|
135
|
+
const key = `${kind}\u0000${element}\u0000${message}`;
|
|
136
|
+
const existing = this.notes.get(key);
|
|
137
|
+
if (existing) {
|
|
138
|
+
existing.count++;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (this.notes.size >= MAX_NOTES) {
|
|
142
|
+
this.overflow++;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this.notes.set(key, { kind, element, message, count: 1 });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Remembers an image on the old site (W-958: the dialog copies them into the media library) and
|
|
150
|
+
* notes once that the ones not copied still load from there.
|
|
151
|
+
*/
|
|
152
|
+
externalImage(url: string): void {
|
|
153
|
+
if (!/^https?:\/\//i.test(url)) return;
|
|
154
|
+
if (this.images.size < MAX_IMAGES) this.images.add(url);
|
|
155
|
+
if (this.copied(url)) return;
|
|
156
|
+
this.note(
|
|
157
|
+
"approximated",
|
|
158
|
+
"Images",
|
|
159
|
+
"Images still load from their original address (your old site). Copy them to the media library in the import dialog, or upload them before that site goes away.",
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** W-958: the media library copy of an old-site image, when the dialog made one. */
|
|
164
|
+
copied(url: string): { url: string; id?: string } | undefined {
|
|
165
|
+
const found = this.mediaOf?.(url);
|
|
166
|
+
const safe = found ? sanitizeMediaUrl(found.url) : undefined;
|
|
167
|
+
return found && safe ? { ...found, url: safe } : undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* W-951: an SVG file's markup, ready to store as an icon's `iconSvg`: anything before `<svg`
|
|
172
|
+
* (an XML declaration, comments) is dropped, and markup the SVG sanitizer refuses or that is over
|
|
173
|
+
* the icon cap is not used. Files without markup are remembered in `svgFiles`.
|
|
174
|
+
*/
|
|
175
|
+
svgMarkup(url: string): string | undefined {
|
|
176
|
+
const raw = this.svg?.(url);
|
|
177
|
+
if (raw === undefined) {
|
|
178
|
+
this.svgFiles.add(url);
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
const start = raw.search(/<svg[\s>]/i);
|
|
182
|
+
const markup = start >= 0 ? raw.slice(start).trim() : "";
|
|
183
|
+
if (markup && markup.length <= ICON_SVG_MAX && isSafeSvgMarkup(markup)) return markup;
|
|
184
|
+
this.note(
|
|
185
|
+
"skipped",
|
|
186
|
+
"SVG files",
|
|
187
|
+
"An SVG file is too large or has content EmVB doesn't allow (scripts, styles, links); it stays an image.",
|
|
188
|
+
);
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* W-958: finds the old site's address from the uploads the export points to
|
|
194
|
+
* (`https://old.example/blog/wp-content/…` → `https://old.example/blog`).
|
|
195
|
+
*/
|
|
196
|
+
findOldSite(text: string): void {
|
|
197
|
+
const found = new Map<string, URL>();
|
|
198
|
+
for (const match of text.matchAll(
|
|
199
|
+
/https?:\/\/[^"'<>\s/\\]+(?:\/[^"'<>/\\]*)*?(?=\/wp-content\/)/gi,
|
|
200
|
+
)) {
|
|
201
|
+
try {
|
|
202
|
+
const url = new URL(match[0]);
|
|
203
|
+
found.set(url.href.toLowerCase(), url);
|
|
204
|
+
} catch {
|
|
205
|
+
// Not an address: ignore it.
|
|
206
|
+
}
|
|
207
|
+
if (found.size >= 5) break;
|
|
208
|
+
}
|
|
209
|
+
this.oldSites = [...found.values()];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* An export's link, made safe. W-958: a link to a page on the old site becomes the same path on
|
|
214
|
+
* this one (`https://old.example/blog/contact/` → `/contact`), so it works once those pages are
|
|
215
|
+
* imported with the same slugs; files, admin pages and `?p=` links keep their address.
|
|
216
|
+
*/
|
|
217
|
+
href(raw: string): string | undefined {
|
|
218
|
+
const local = this.localPath(raw.trim());
|
|
219
|
+
if (local === undefined) return sanitizeHref(raw);
|
|
220
|
+
const safe = sanitizeHref(local);
|
|
221
|
+
if (safe)
|
|
222
|
+
this.note(
|
|
223
|
+
"approximated",
|
|
224
|
+
"Links",
|
|
225
|
+
"Links to pages on your old site now point to the same address on this site; import or create those pages with the same slugs.",
|
|
226
|
+
);
|
|
227
|
+
return safe;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** W-958: a WordPress page link's address here, made safe; every id is remembered. */
|
|
231
|
+
pageLink(id: number): string | undefined {
|
|
232
|
+
if (this.pageLinks.size < 100) this.pageLinks.add(id);
|
|
233
|
+
const chosen = this.pageLinkOf?.(id)?.trim();
|
|
234
|
+
return chosen ? sanitizeHref(chosen) : undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private localPath(raw: string): string | undefined {
|
|
238
|
+
if (this.oldSites.length === 0 || !/^https?:\/\//i.test(raw)) return undefined;
|
|
239
|
+
let url: URL;
|
|
240
|
+
try {
|
|
241
|
+
url = new URL(raw);
|
|
242
|
+
} catch {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
for (const site of this.oldSites) {
|
|
246
|
+
if (url.origin.toLowerCase() !== site.origin.toLowerCase()) continue;
|
|
247
|
+
const base = site.pathname.replace(/\/+$/, "").toLowerCase();
|
|
248
|
+
const path = url.pathname;
|
|
249
|
+
const lower = path.toLowerCase();
|
|
250
|
+
if (lower !== base && !lower.startsWith(`${base}/`)) continue;
|
|
251
|
+
let rest = path.slice(base.length) || "/";
|
|
252
|
+
if (/^\/(?:wp-content|wp-admin|wp-json|wp-includes)(?:\/|$)|\.php$/i.test(rest))
|
|
253
|
+
return undefined;
|
|
254
|
+
if (/[?&](?:p|page_id|post_type)=/i.test(url.search)) return undefined;
|
|
255
|
+
if (rest.length > 1) rest = rest.replace(/\/+$/, "") || "/";
|
|
256
|
+
return `${rest}${url.search}${url.hash}`;
|
|
257
|
+
}
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* W-958: the EmVB class for an Elementor global class, made once per import: named by its
|
|
263
|
+
* label, with an id from it, and only when it is a valid class (else elements stay inline).
|
|
264
|
+
*/
|
|
265
|
+
importedClass(id: string, look: () => Layers, label?: string): ImportedClass | undefined {
|
|
266
|
+
if (this.imported.has(id)) return this.imported.get(id);
|
|
267
|
+
if (this.imported.size >= 100) return undefined;
|
|
268
|
+
const layers = look();
|
|
269
|
+
const name = (label ?? "").trim().slice(0, 60) || id.slice(0, 60);
|
|
270
|
+
const taken = new Set([...this.imported.values()].map((c) => c?.id));
|
|
271
|
+
const base = slugify(name).slice(0, 34).replace(/-+$/, "") || "elementor";
|
|
272
|
+
let classId = base;
|
|
273
|
+
for (let n = 2; taken.has(classId); n++) classId = `${base}-${n}`;
|
|
274
|
+
const cls: StyleClass = { id: classId, name, style: layers.desktop };
|
|
275
|
+
const devices = {
|
|
276
|
+
...(Object.keys(layers.laptop).length > 0 ? { laptop: layers.laptop } : {}),
|
|
277
|
+
...(Object.keys(layers.tablet).length > 0 ? { tablet: layers.tablet } : {}),
|
|
278
|
+
...(Object.keys(layers.mobile).length > 0 ? { mobile: layers.mobile } : {}),
|
|
279
|
+
};
|
|
280
|
+
if (Object.keys(devices).length > 0) cls.devices = devices;
|
|
281
|
+
const states = {
|
|
282
|
+
...(Object.keys(layers.hover).length > 0 ? { hover: layers.hover } : {}),
|
|
283
|
+
...(Object.keys(layers.focus).length > 0 ? { focus: layers.focus } : {}),
|
|
284
|
+
...(Object.keys(layers.active).length > 0 ? { active: layers.active } : {}),
|
|
285
|
+
};
|
|
286
|
+
if (Object.keys(states).length > 0) cls.states = states as StyleClass["states"];
|
|
287
|
+
const valid = validateDesign({ ...emptyDesign(), classes: [cls] }).ok;
|
|
288
|
+
const made = valid ? { id: classId, layers, cls } : undefined;
|
|
289
|
+
this.imported.set(id, made);
|
|
290
|
+
if (made)
|
|
291
|
+
this.note(
|
|
292
|
+
"approximated",
|
|
293
|
+
"Classes",
|
|
294
|
+
"Elementor classes are added to your site's classes when you import. Existing classes are never changed: an identical one is reused, a different one with the same name is added as a numbered copy.",
|
|
295
|
+
);
|
|
296
|
+
return made;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
report(): ImportNote[] {
|
|
300
|
+
const list = [...this.notes.values()];
|
|
301
|
+
if (this.overflow > 0) {
|
|
302
|
+
list.push({
|
|
303
|
+
kind: "skipped",
|
|
304
|
+
element: "Report",
|
|
305
|
+
message: `${this.overflow} more notes were left out of this report.`,
|
|
306
|
+
count: 1,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return list;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
get overBudget(): boolean {
|
|
313
|
+
return this.nodes >= NODE_BUDGET;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** "globals/colors?id=primary" or a plain id → hex, from the kit or Elementor's defaults. */
|
|
317
|
+
globalColor(ref: unknown): string | undefined {
|
|
318
|
+
const id = globalId(ref, "colors");
|
|
319
|
+
if (!id) return undefined;
|
|
320
|
+
const found = this.colors.get(id) ?? DEFAULT_COLORS[id];
|
|
321
|
+
if (found && !this.kitGiven)
|
|
322
|
+
this.note(
|
|
323
|
+
"approximated",
|
|
324
|
+
"Global colours",
|
|
325
|
+
"Global colours use Elementor's default kit; add your site kit for exact colours.",
|
|
326
|
+
);
|
|
327
|
+
if (!found)
|
|
328
|
+
this.note(
|
|
329
|
+
"approximated",
|
|
330
|
+
"Global colours",
|
|
331
|
+
`Global colour "${id}" isn't in the kit; its elements keep their own colour.`,
|
|
332
|
+
);
|
|
333
|
+
return found;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
globalTypography(ref: unknown): GlobalTypography | undefined {
|
|
337
|
+
const id = globalId(ref, "typography");
|
|
338
|
+
if (!id) return undefined;
|
|
339
|
+
const found = this.typography.get(id) ?? DEFAULT_TYPOGRAPHY[id];
|
|
340
|
+
if (found && !this.kitGiven)
|
|
341
|
+
this.note(
|
|
342
|
+
"approximated",
|
|
343
|
+
"Global fonts",
|
|
344
|
+
"Global fonts use Elementor's default kit; add your site kit for exact fonts.",
|
|
345
|
+
);
|
|
346
|
+
return found;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** A font family the page uses, for the report's "load these fonts" line. */
|
|
350
|
+
useFont(family: unknown): string | undefined {
|
|
351
|
+
const stack = fontStack(family);
|
|
352
|
+
const name = str(family)?.trim();
|
|
353
|
+
if (stack && name) this.fonts.add(name);
|
|
354
|
+
return stack;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
private readKit(raw: unknown): boolean {
|
|
358
|
+
const root = isRecord(raw) && isRecord(raw["settings"]) ? raw["settings"] : raw;
|
|
359
|
+
if (!isRecord(root)) return false;
|
|
360
|
+
let any = false;
|
|
361
|
+
for (const key of ["system_colors", "custom_colors"]) {
|
|
362
|
+
const list = root[key];
|
|
363
|
+
if (!Array.isArray(list)) continue;
|
|
364
|
+
for (const entry of list.slice(0, 200)) {
|
|
365
|
+
if (!isRecord(entry)) continue;
|
|
366
|
+
const id = str(entry["_id"]);
|
|
367
|
+
const hex = color(entry["color"]);
|
|
368
|
+
if (id && hex) {
|
|
369
|
+
this.colors.set(id, hex);
|
|
370
|
+
any = true;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
for (const key of ["system_typography", "custom_typography"]) {
|
|
375
|
+
const list = root[key];
|
|
376
|
+
if (!Array.isArray(list)) continue;
|
|
377
|
+
for (const entry of list.slice(0, 200)) {
|
|
378
|
+
if (!isRecord(entry)) continue;
|
|
379
|
+
const id = str(entry["_id"]);
|
|
380
|
+
if (!id) continue;
|
|
381
|
+
this.typography.set(id, {
|
|
382
|
+
fontFamily: str(entry["typography_font_family"]),
|
|
383
|
+
fontWeight: entry["typography_font_weight"],
|
|
384
|
+
fontSize: entry["typography_font_size"],
|
|
385
|
+
lineHeight: entry["typography_line_height"],
|
|
386
|
+
letterSpacing: entry["typography_letter_spacing"],
|
|
387
|
+
});
|
|
388
|
+
any = true;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return any;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function globalId(ref: unknown, kind: "colors" | "typography"): string | undefined {
|
|
396
|
+
const raw = str(ref);
|
|
397
|
+
if (!raw) return undefined;
|
|
398
|
+
const match = new RegExp(`^globals/${kind}\\?id=([A-Za-z0-9_-]{1,64})$`).exec(raw);
|
|
399
|
+
if (match) return match[1];
|
|
400
|
+
return /^[A-Za-z0-9_-]{1,64}$/.test(raw) ? raw : undefined;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** A widget's `__globals__` reference for a setting key, if any. */
|
|
404
|
+
export function globalRef(settings: Settings, key: string): unknown {
|
|
405
|
+
const globals = settings["__globals__"];
|
|
406
|
+
return isRecord(globals) ? globals[key] : undefined;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** Typography values from a global entry, as style keys. */
|
|
410
|
+
export function typographyFromGlobal(
|
|
411
|
+
ctx: ImportContext,
|
|
412
|
+
entry: GlobalTypography,
|
|
413
|
+
): Record<string, unknown> {
|
|
414
|
+
const style: Record<string, unknown> = {};
|
|
415
|
+
const family = ctx.useFont(entry.fontFamily);
|
|
416
|
+
if (family) style["fontFamily"] = family;
|
|
417
|
+
const weight = fontWeight(entry.fontWeight);
|
|
418
|
+
if (weight !== undefined) style["fontWeight"] = weight;
|
|
419
|
+
const size = slider(entry.fontSize);
|
|
420
|
+
if (size) style["fontSize"] = size;
|
|
421
|
+
return style;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** An imported SVG file's icon id: its file name, so the editor shows where it came from. */
|
|
425
|
+
export function svgFileId(url: string): string {
|
|
426
|
+
const file = url.split(/[?#]/)[0]?.split("/").pop() ?? "";
|
|
427
|
+
const base = file.replace(/\.svg$/i, "").replace(/[^\w.-]+/g, "-") || "svg";
|
|
428
|
+
return `file:${base}`.slice(0, 64);
|
|
429
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-961: steps numbered by the site's CSS. Some Elementor sites write a numbered list as separate
|
|
3
|
+
* paragraphs and number them with a CSS counter (`.step::before{content:counter(step) "."}`, the
|
|
4
|
+
* counter reset on a parent). EmVB can't run that CSS, so the numbers were lost; consecutive
|
|
5
|
+
* siblings with such a class become one numbered List instead.
|
|
6
|
+
*/
|
|
7
|
+
import type { ListMarker } from "../../css-keywords.ts";
|
|
8
|
+
import { isRecord, str } from "./values.ts";
|
|
9
|
+
|
|
10
|
+
/** A class whose `::before`/`::after` draws a counter, and the marker that looks like it. */
|
|
11
|
+
export type CounterItem = { counter: string; marker: ListMarker };
|
|
12
|
+
|
|
13
|
+
const STYLES: Record<string, ListMarker> = {
|
|
14
|
+
decimal: "decimal",
|
|
15
|
+
"decimal-leading-zero": "decimal-leading-zero",
|
|
16
|
+
"lower-alpha": "lower-alpha",
|
|
17
|
+
"lower-latin": "lower-alpha",
|
|
18
|
+
"upper-alpha": "upper-alpha",
|
|
19
|
+
"upper-latin": "upper-alpha",
|
|
20
|
+
"lower-roman": "lower-roman",
|
|
21
|
+
"upper-roman": "upper-roman",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Class name → the counter its `::before`/`::after` draws, from site or page CSS. */
|
|
25
|
+
export function counterItems(css: string): Map<string, CounterItem> {
|
|
26
|
+
const items = new Map<string, CounterItem>();
|
|
27
|
+
const clean = css.replace(/\/\*[\s\S]*?\*\//g, "").slice(0, 200_000);
|
|
28
|
+
for (const match of clean.matchAll(/([^{}@]+)\{([^{}]*)\}/g)) {
|
|
29
|
+
const body = match[2] ?? "";
|
|
30
|
+
const drawn = /content\s*:\s*counter\(\s*([A-Za-z_][\w-]*)\s*(?:,\s*([a-z-]+)\s*)?\)/i.exec(
|
|
31
|
+
body,
|
|
32
|
+
);
|
|
33
|
+
if (!drawn) continue;
|
|
34
|
+
const marker = STYLES[(drawn[2] ?? "decimal").toLowerCase()] ?? "decimal";
|
|
35
|
+
for (const selector of (match[1] ?? "").split(",")) {
|
|
36
|
+
const found = /\.([A-Za-z_][\w-]*)::?(?:before|after)\s*$/.exec(selector.trim());
|
|
37
|
+
if (found?.[1]) items.set(found[1], { counter: drawn[1] as string, marker });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return items;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The class names an Elementor 4 element carries: global class labels and ids, local ids. */
|
|
44
|
+
function classNamesOf(
|
|
45
|
+
raw: Record<string, unknown>,
|
|
46
|
+
labels: (id: string) => string | undefined,
|
|
47
|
+
): string[] {
|
|
48
|
+
const settings = isRecord(raw["settings"]) ? raw["settings"] : {};
|
|
49
|
+
const classes = isRecord(settings["classes"]) ? settings["classes"]["value"] : undefined;
|
|
50
|
+
if (!Array.isArray(classes)) return [];
|
|
51
|
+
return classes.flatMap((id) => {
|
|
52
|
+
if (typeof id !== "string") return [];
|
|
53
|
+
const label = labels(id);
|
|
54
|
+
return label ? [id, label] : [id];
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The element's counter, when it is an Elementor 4 paragraph or heading with a counter class. */
|
|
59
|
+
export function counterOf(
|
|
60
|
+
raw: unknown,
|
|
61
|
+
items: ReadonlyMap<string, CounterItem>,
|
|
62
|
+
labels: (id: string) => string | undefined,
|
|
63
|
+
): CounterItem | undefined {
|
|
64
|
+
if (!isRecord(raw) || items.size === 0) return undefined;
|
|
65
|
+
const type = str(raw["widgetType"]) ?? str(raw["elType"]) ?? "";
|
|
66
|
+
if (type !== "e-paragraph" && type !== "e-heading") return undefined;
|
|
67
|
+
for (const name of classNamesOf(raw, labels)) {
|
|
68
|
+
const item = items.get(name);
|
|
69
|
+
if (item) return item;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|