@perkyzz/emvb 0.9.0 → 1.1.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 +10 -1
- package/package.json +2 -2
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +10 -6
- package/src/admin/copy-rich-text.ts +119 -0
- package/src/admin/dialog-tab-wrap.ts +78 -0
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +311 -250
- package/src/admin/editor/Timeline.tsx +8 -3
- package/src/admin/editor/TopBar.tsx +29 -7
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
- package/src/admin/editor/canvas/canvas-scale.ts +3 -3
- 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 +48 -4
- package/src/admin/editor/editor-chrome.tsx +8 -6
- package/src/admin/editor/editor-commands.ts +15 -4
- package/src/admin/editor/editor-css.ts +2 -1
- 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/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 +68 -20
- 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 +72 -15
- 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 +183 -10
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
- 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 +120 -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 +68 -4
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +52 -10
- package/src/admin/editor/panels/style-target.ts +22 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +14 -4
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +18 -7
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/export-api.ts +221 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +9 -26
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ExportDialog.tsx +395 -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 +82 -3
- package/src/admin/pages/ThemePartList.tsx +52 -2
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +50 -4
- package/src/admin/widgets/CanvasField.tsx +8 -0
- package/src/admin/widgets/ConvertToRichText.tsx +136 -0
- package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
- package/src/admin/widgets/convert-body.ts +73 -2
- package/src/astro/content-port.ts +14 -1
- package/src/astro/render.ts +6 -6
- package/src/astro/resolve-theme.ts +25 -8
- package/src/astro/resolve.ts +89 -2
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +45 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +305 -0
- package/src/core/css/generate.ts +151 -20
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +47 -13
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +28 -9
- package/src/core/design/devices.ts +89 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +31 -5
- package/src/core/elements/dynamic-elements.ts +3 -3
- package/src/core/elements/index.ts +73 -9
- package/src/core/export/runtimes.generated.ts +9 -0
- package/src/core/export/site.ts +562 -0
- package/src/core/export/zip.ts +95 -0
- 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 +26 -1
- package/src/core/import/elementor/atomic.ts +1608 -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 +967 -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 +429 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +96 -0
- package/src/core/json-schema.ts +114 -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 +42 -24
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/public-attributes.ts +30 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +222 -23
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +151 -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 +4 -3
- package/src/core/schema/layout.ts +92 -16
- package/src/core/schema/style.ts +296 -112
- package/src/core/search-text.ts +70 -0
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +2 -0
- package/src/core/theme/popup-rules.ts +33 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +24 -0
- 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 -10
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +5 -1
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +35 -2
- 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,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-950: inline formatting kept from Elementor HTML. While a paragraph is read, every character
|
|
3
|
+
* of its raw text carries the formatting around it (bold, italic, colour, link); this turns that
|
|
4
|
+
* into marks over the cleaned text, following `cleanText` step by step so ranges line up.
|
|
5
|
+
*/
|
|
6
|
+
import { MAX_TEXT_MARKS, type TextMark } from "../../schema/layout.ts";
|
|
7
|
+
|
|
8
|
+
export type Fmt = { bold?: true; italic?: true; color?: string; href?: string };
|
|
9
|
+
|
|
10
|
+
// oxlint-disable-next-line no-control-regex -- the control characters cleanText drops
|
|
11
|
+
const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f]/;
|
|
12
|
+
|
|
13
|
+
type Ch = { c: string; f: Fmt | undefined };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Marks for `raw` (with one format per UTF-16 unit in `fmts`) once cleaned like `cleanText`.
|
|
17
|
+
* Empty when the cleaned text isn't `expected`: then nothing can be misplaced.
|
|
18
|
+
*/
|
|
19
|
+
export function marksFromChars(
|
|
20
|
+
raw: string,
|
|
21
|
+
fmts: readonly (Fmt | undefined)[],
|
|
22
|
+
keepBreaks: boolean,
|
|
23
|
+
expected: string,
|
|
24
|
+
): TextMark[] {
|
|
25
|
+
let chars: Ch[] = [];
|
|
26
|
+
for (let i = 0; i < raw.length; i++) {
|
|
27
|
+
const c = raw[i] === "\t" ? " " : (raw[i] as string);
|
|
28
|
+
if (!CONTROL.test(c)) chars.push({ c, f: fmts[i] });
|
|
29
|
+
}
|
|
30
|
+
// [ \u00a0]+ → one space
|
|
31
|
+
chars = chars.reduce<Ch[]>((out, ch) => {
|
|
32
|
+
const space = ch.c === " " || ch.c === "\u00a0";
|
|
33
|
+
if (space && out.at(-1)?.c === " ") return out;
|
|
34
|
+
out.push(space ? { c: " ", f: ch.f } : ch);
|
|
35
|
+
return out;
|
|
36
|
+
}, []);
|
|
37
|
+
// " ?\n ?" → "\n"
|
|
38
|
+
chars = chars.filter(
|
|
39
|
+
(ch, i) => !(ch.c === " " && (chars[i - 1]?.c === "\n" || chars[i + 1]?.c === "\n")),
|
|
40
|
+
);
|
|
41
|
+
// \n{3,} → \n\n
|
|
42
|
+
chars = chars.filter(
|
|
43
|
+
(ch, i) => !(ch.c === "\n" && chars[i - 1]?.c === "\n" && chars[i - 2]?.c === "\n"),
|
|
44
|
+
);
|
|
45
|
+
// trim
|
|
46
|
+
while (chars.length > 0 && /\s/.test(chars[0]?.c ?? "")) chars.shift();
|
|
47
|
+
while (chars.length > 0 && /\s/.test(chars.at(-1)?.c ?? "")) chars.pop();
|
|
48
|
+
if (!keepBreaks) {
|
|
49
|
+
// \n+ → one space
|
|
50
|
+
chars = chars.flatMap((ch, i) =>
|
|
51
|
+
ch.c !== "\n" ? [ch] : chars[i - 1]?.c === "\n" ? [] : [{ c: " ", f: ch.f }],
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
if (chars.map((ch) => ch.c).join("") !== expected) return [];
|
|
55
|
+
const marks: TextMark[] = [];
|
|
56
|
+
let at = 0;
|
|
57
|
+
while (at < chars.length) {
|
|
58
|
+
const f = chars[at]?.f;
|
|
59
|
+
const key = JSON.stringify(f ?? {});
|
|
60
|
+
let end = at + 1;
|
|
61
|
+
while (end < chars.length && JSON.stringify(chars[end]?.f ?? {}) === key) end++;
|
|
62
|
+
if (f && (f.bold || f.italic || f.color || f.href)) {
|
|
63
|
+
if (marks.length >= MAX_TEXT_MARKS) break;
|
|
64
|
+
marks.push({ start: at, end, ...f });
|
|
65
|
+
}
|
|
66
|
+
at = end;
|
|
67
|
+
}
|
|
68
|
+
return marks;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The formatting a stack of open tags gives (inner tags win for colour). */
|
|
72
|
+
export function combine(stack: readonly Fmt[], href: string | undefined): Fmt | undefined {
|
|
73
|
+
const out: Fmt = {};
|
|
74
|
+
for (const f of stack) {
|
|
75
|
+
if (f.bold) out.bold = true;
|
|
76
|
+
if (f.italic) out.italic = true;
|
|
77
|
+
if (f.color) out.color = f.color;
|
|
78
|
+
}
|
|
79
|
+
if (href) out.href = href;
|
|
80
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
81
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Elementor 4 global classes and variables, as a template export carries them (W-945). */
|
|
2
|
+
import { isRecord, type Settings, str } from "./values.ts";
|
|
3
|
+
|
|
4
|
+
export type Value = { $$type?: string; value?: unknown };
|
|
5
|
+
export type ClassVariant = {
|
|
6
|
+
meta?: { breakpoint?: string | null; state?: string | null };
|
|
7
|
+
props?: Settings;
|
|
8
|
+
custom_css?: unknown;
|
|
9
|
+
};
|
|
10
|
+
export type ClassDef = { id?: string; label?: string; variants?: ClassVariant[] };
|
|
11
|
+
|
|
12
|
+
/** The global classes and variables a template export carries. */
|
|
13
|
+
export type AtomicSnapshots = {
|
|
14
|
+
classes: Map<string, ClassDef>;
|
|
15
|
+
/** Position in Elementor's class order: a lower index wins over a higher one. */
|
|
16
|
+
rank: Map<string, number>;
|
|
17
|
+
variables: Map<string, { type: string; value: unknown }>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const emptySnapshots = (): AtomicSnapshots => ({
|
|
21
|
+
classes: new Map(),
|
|
22
|
+
rank: new Map(),
|
|
23
|
+
variables: new Map(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/** Reads `global_classes: { items, order }` and `global_variables: { data }` into `into`. */
|
|
27
|
+
export function readSnapshots(source: Settings, into: AtomicSnapshots): void {
|
|
28
|
+
const classes = isRecord(source["global_classes"]) ? source["global_classes"] : undefined;
|
|
29
|
+
const items = classes && isRecord(classes["items"]) ? classes["items"] : undefined;
|
|
30
|
+
if (items) {
|
|
31
|
+
for (const [id, def] of Object.entries(items).slice(0, 5000)) {
|
|
32
|
+
if (isRecord(def) && !into.classes.has(id)) into.classes.set(id, def as ClassDef);
|
|
33
|
+
}
|
|
34
|
+
const order = Array.isArray(classes?.["order"]) ? (classes["order"] as unknown[]) : [];
|
|
35
|
+
order.forEach((id, i) => {
|
|
36
|
+
if (typeof id === "string" && !into.rank.has(id)) into.rank.set(id, i);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const variables = isRecord(source["global_variables"]) ? source["global_variables"] : undefined;
|
|
40
|
+
const data = variables && isRecord(variables["data"]) ? variables["data"] : undefined;
|
|
41
|
+
if (data) {
|
|
42
|
+
for (const [id, def] of Object.entries(data).slice(0, 5000)) {
|
|
43
|
+
if (!isRecord(def) || into.variables.has(id)) continue;
|
|
44
|
+
const raw = isRecord(def["value"]) ? def["value"]["value"] : def["value"];
|
|
45
|
+
into.variables.set(id, { type: str(def["type"]) ?? "", value: raw });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elementor settings → EmVB `style` and `devices` (W-945). Elementor stores a responsive value
|
|
3
|
+
* as `key`, `key_tablet` and `key_mobile`; each reader runs once per device with a getter that
|
|
4
|
+
* adds the suffix, and the tablet and mobile results keep only what changed.
|
|
5
|
+
*/
|
|
6
|
+
import { ALIGN_ITEMS, BORDER_STYLES, JUSTIFY_CONTENT } from "../../css-keywords.ts";
|
|
7
|
+
import { globalRef, type ImportContext, typographyFromGlobal } from "./context.ts";
|
|
8
|
+
import {
|
|
9
|
+
backgroundPosition,
|
|
10
|
+
backgroundUrl,
|
|
11
|
+
changedKeys,
|
|
12
|
+
color,
|
|
13
|
+
dimensions,
|
|
14
|
+
flexValue,
|
|
15
|
+
fontWeight,
|
|
16
|
+
isEmptyStyle,
|
|
17
|
+
isRecord,
|
|
18
|
+
num,
|
|
19
|
+
putRadius,
|
|
20
|
+
putSides,
|
|
21
|
+
type Settings,
|
|
22
|
+
slider,
|
|
23
|
+
str,
|
|
24
|
+
textAlign,
|
|
25
|
+
} from "./values.ts";
|
|
26
|
+
|
|
27
|
+
export type Style = Record<string, unknown>;
|
|
28
|
+
export type Device = "" | "_widescreen" | "_laptop" | "_tablet" | "_mobile";
|
|
29
|
+
|
|
30
|
+
/** Reads one device's style from a widget's settings. */
|
|
31
|
+
export type Reader = (s: Settings, d: Device, ctx: ImportContext, el: string) => Style;
|
|
32
|
+
|
|
33
|
+
/** Style for desktop plus tablet/mobile overrides, from several readers. */
|
|
34
|
+
export function deviceStyles(
|
|
35
|
+
s: Settings,
|
|
36
|
+
ctx: ImportContext,
|
|
37
|
+
el: string,
|
|
38
|
+
readers: readonly Reader[],
|
|
39
|
+
): { style?: Style; devices?: { laptop?: Style; tablet?: Style; mobile?: Style } } {
|
|
40
|
+
const read = (d: Device) => Object.assign({}, ...readers.map((r) => r(s, d, ctx, el))) as Style;
|
|
41
|
+
const desktop = read("");
|
|
42
|
+
// W-959: Elementor's widescreen values (`key_widescreen`), on Desktop's, in `style.wide`.
|
|
43
|
+
const wide = changedKeys(desktop, read("_widescreen"));
|
|
44
|
+
// W-956: Elementor's laptop values (`key_laptop`), between desktop and tablet.
|
|
45
|
+
const laptop = changedKeys(desktop, read("_laptop"));
|
|
46
|
+
const tablet = changedKeys({ ...desktop, ...laptop }, read("_tablet"));
|
|
47
|
+
const mobile = changedKeys({ ...desktop, ...laptop, ...tablet }, read("_mobile"));
|
|
48
|
+
const devices: { laptop?: Style; tablet?: Style; mobile?: Style } = {};
|
|
49
|
+
if (!isEmptyStyle(laptop)) devices.laptop = laptop;
|
|
50
|
+
if (!isEmptyStyle(tablet)) devices.tablet = tablet;
|
|
51
|
+
if (!isEmptyStyle(mobile)) devices.mobile = mobile;
|
|
52
|
+
if (!isEmptyStyle(wide)) desktop["wide"] = wide;
|
|
53
|
+
return {
|
|
54
|
+
...(isEmptyStyle(desktop) ? {} : { style: desktop }),
|
|
55
|
+
...(Object.keys(devices).length > 0 ? { devices } : {}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Tablet/mobile values only exist under the suffixed key; desktop-only keys skip other devices. */
|
|
60
|
+
const at = (s: Settings, key: string, d: Device) => s[`${key}${d}`];
|
|
61
|
+
|
|
62
|
+
/** A colour setting: the `__globals__` reference wins, as in Elementor. Desktop only. */
|
|
63
|
+
export function colorAt(
|
|
64
|
+
s: Settings,
|
|
65
|
+
key: string,
|
|
66
|
+
ctx: ImportContext,
|
|
67
|
+
d: Device = "",
|
|
68
|
+
): string | undefined {
|
|
69
|
+
if (d !== "") return color(at(s, key, d));
|
|
70
|
+
const ref = globalRef(s, key);
|
|
71
|
+
if (ref !== undefined && ref !== "") return ctx.globalColor(ref) ?? color(s[key]);
|
|
72
|
+
return color(s[key]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Padding, margin, background, border, radius, shadow and size of a box. `p` is "" or "_". */
|
|
76
|
+
export function boxReader(p: "" | "_"): Reader {
|
|
77
|
+
return (s, d, ctx, el) => {
|
|
78
|
+
const style: Style = {};
|
|
79
|
+
putSides(style, "padding", at(s, `${p}padding`, d));
|
|
80
|
+
putSides(style, "margin", at(s, `${p}margin`, d), true);
|
|
81
|
+
Object.assign(style, background(s, `${p}background_`, d, ctx, el));
|
|
82
|
+
const borderType = str(s[`${p}border_border`]);
|
|
83
|
+
if (borderType && borderType !== "none" && borderType !== "") {
|
|
84
|
+
if (d === "") {
|
|
85
|
+
style["borderStyle"] = (BORDER_STYLES as readonly string[]).includes(borderType)
|
|
86
|
+
? borderType
|
|
87
|
+
: "solid";
|
|
88
|
+
if (!(BORDER_STYLES as readonly string[]).includes(borderType)) {
|
|
89
|
+
ctx.note("approximated", el, `Border style "${borderType}" is shown as solid.`);
|
|
90
|
+
}
|
|
91
|
+
const borderColor = colorAt(s, `${p}border_color`, ctx);
|
|
92
|
+
if (borderColor) style["borderColor"] = borderColor;
|
|
93
|
+
}
|
|
94
|
+
const widths = dimensions(at(s, `${p}border_width`, d));
|
|
95
|
+
const values = Object.values(widths);
|
|
96
|
+
if (values.length === 4 && sameLength(values)) {
|
|
97
|
+
style["borderWidth"] = values[0];
|
|
98
|
+
} else {
|
|
99
|
+
putSides(style, "border", at(s, `${p}border_width`, d));
|
|
100
|
+
for (const side of ["Top", "Right", "Bottom", "Left"]) {
|
|
101
|
+
const value = style[`border${side}`];
|
|
102
|
+
if (value) {
|
|
103
|
+
delete style[`border${side}`];
|
|
104
|
+
style[`border${side}Width`] = value;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
putRadius(style, at(s, `${p}border_radius`, d));
|
|
110
|
+
if (d === "" && s[`${p}box_shadow_box_shadow_type`] === "yes") {
|
|
111
|
+
const shadow = s[`${p}box_shadow_box_shadow`];
|
|
112
|
+
if (isRecord(shadow)) {
|
|
113
|
+
const value = {
|
|
114
|
+
x: clamp(num(shadow["horizontal"]) ?? 0, -1000, 1000),
|
|
115
|
+
y: clamp(num(shadow["vertical"]) ?? 0, -1000, 1000),
|
|
116
|
+
blur: clamp(num(shadow["blur"]) ?? 10, 0, 1000),
|
|
117
|
+
spread: clamp(num(shadow["spread"]) ?? 0, -1000, 1000),
|
|
118
|
+
...(color(shadow["color"]) ? { color: color(shadow["color"]) } : {}),
|
|
119
|
+
...(str(s[`${p}box_shadow_box_shadow_position`]) === "inset" ? { inset: true } : {}),
|
|
120
|
+
};
|
|
121
|
+
style["boxShadow"] = value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const zIndex = num(at(s, `${p}z_index`, d));
|
|
125
|
+
if (zIndex !== undefined && Number.isInteger(zIndex) && Math.abs(zIndex) <= 9999)
|
|
126
|
+
style["zIndex"] = zIndex;
|
|
127
|
+
if (d === "" && (str(s[`${p}position`]) === "absolute" || str(s[`${p}position`]) === "fixed")) {
|
|
128
|
+
ctx.note(
|
|
129
|
+
"approximated",
|
|
130
|
+
el,
|
|
131
|
+
"Absolute or fixed positioning was left out; the element sits in the flow.",
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return style;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** All four lengths are equal (one shorthand value will do). */
|
|
139
|
+
const sameLength = (values: readonly { value: number; unit: string }[]) =>
|
|
140
|
+
values.every((v) => v.value === values[0]?.value && v.unit === values[0]?.unit);
|
|
141
|
+
|
|
142
|
+
const clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));
|
|
143
|
+
|
|
144
|
+
/** Elementor's two-colour gradient settings under prefix `k` (`background_`, `background_overlay_`). */
|
|
145
|
+
function gradientOf(s: Settings, k: string, ctx: ImportContext): Style | undefined {
|
|
146
|
+
const a = colorAt(s, `${k}color`, ctx);
|
|
147
|
+
const b = colorAt(s, `${k}color_b`, ctx);
|
|
148
|
+
if (!a || !b) return undefined;
|
|
149
|
+
const sizeOf = (key: string, fallback: number) =>
|
|
150
|
+
num(isRecord(s[key]) ? (s[key] as Settings)["size"] : undefined) ?? fallback;
|
|
151
|
+
const stopA = clamp(Math.round(sizeOf(`${k}color_stop`, 0)), 0, 100);
|
|
152
|
+
const stopB = clamp(Math.round(sizeOf(`${k}color_b_stop`, 100)), 0, 100);
|
|
153
|
+
const radial = str(s[`${k}gradient_type`]) === "radial";
|
|
154
|
+
const angle = sizeOf(`${k}gradient_angle`, 180);
|
|
155
|
+
return {
|
|
156
|
+
type: radial ? "radial" : "linear",
|
|
157
|
+
...(radial
|
|
158
|
+
? { position: backgroundPosition(s[`${k}gradient_position`]) ?? "center" }
|
|
159
|
+
: { angle: clamp(Math.round(((angle % 360) + 360) % 360), 0, 360) }),
|
|
160
|
+
stops: [
|
|
161
|
+
{ color: a, at: stopA },
|
|
162
|
+
{ color: b, at: Math.max(stopA, stopB) },
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** `background_*` (or `_background_*`): classic colour and image, gradient, overlay. */
|
|
168
|
+
function background(s: Settings, k: string, d: Device, ctx: ImportContext, el: string): Style {
|
|
169
|
+
const style: Style = {};
|
|
170
|
+
const kind = str(s[`${k}background`]);
|
|
171
|
+
if (kind === "classic") {
|
|
172
|
+
const fill = colorAt(s, `${k}color`, ctx, d);
|
|
173
|
+
if (fill) style["backgroundColor"] = fill;
|
|
174
|
+
const url = backgroundUrl(at(s, `${k}image`, d));
|
|
175
|
+
if (url) {
|
|
176
|
+
ctx.externalImage(url);
|
|
177
|
+
style["backgroundImage"] = url;
|
|
178
|
+
const size = str(at(s, `${k}size`, d));
|
|
179
|
+
if (size === "cover" || size === "contain" || size === "auto") style["backgroundSize"] = size;
|
|
180
|
+
else if (d === "") style["backgroundSize"] = "auto";
|
|
181
|
+
const position = backgroundPosition(at(s, `${k}position`, d));
|
|
182
|
+
if (position) style["backgroundPosition"] = position;
|
|
183
|
+
const repeat = str(at(s, `${k}repeat`, d));
|
|
184
|
+
if (
|
|
185
|
+
repeat === "no-repeat" ||
|
|
186
|
+
repeat === "repeat" ||
|
|
187
|
+
repeat === "repeat-x" ||
|
|
188
|
+
repeat === "repeat-y"
|
|
189
|
+
) {
|
|
190
|
+
style["backgroundRepeat"] = repeat;
|
|
191
|
+
}
|
|
192
|
+
if (d === "" && str(s[`${k}attachment`]) === "fixed") {
|
|
193
|
+
ctx.note(
|
|
194
|
+
"approximated",
|
|
195
|
+
el,
|
|
196
|
+
"Fixed (parallax) background attachment scrolls with the page.",
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
} else if (kind === "gradient" && d === "") {
|
|
201
|
+
const gradient = gradientOf(s, k, ctx);
|
|
202
|
+
if (gradient) style["gradient"] = gradient;
|
|
203
|
+
} else if (kind === "video" && d === "") {
|
|
204
|
+
const link = str(s[`${k}video_link`])?.trim();
|
|
205
|
+
if (link && /^https?:\/\/[^\s()"'`\\]+\.(?:mp4|webm|ogg)(?:\?[^\s()"'`\\]*)?$/i.test(link)) {
|
|
206
|
+
style["backgroundVideo"] = link;
|
|
207
|
+
} else {
|
|
208
|
+
ctx.note(
|
|
209
|
+
"approximated",
|
|
210
|
+
el,
|
|
211
|
+
"A YouTube or Vimeo background video was left out (EmVB plays video files only).",
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
const fallback = backgroundUrl(s[`${k}video_fallback`]);
|
|
215
|
+
if (fallback) style["backgroundImage"] = fallback;
|
|
216
|
+
} else if (kind === "slideshow" && d === "") {
|
|
217
|
+
const slides = s[`${k}slideshow_gallery`];
|
|
218
|
+
const first = Array.isArray(slides) ? backgroundUrl(slides[0]) : undefined;
|
|
219
|
+
if (first) style["backgroundImage"] = first;
|
|
220
|
+
ctx.note("approximated", el, "A background slideshow shows its first image only.");
|
|
221
|
+
}
|
|
222
|
+
if (d === "") {
|
|
223
|
+
// `background_` → `background_overlay_`, `_background_` → `_background_overlay_`.
|
|
224
|
+
const ok = `${k}overlay_`;
|
|
225
|
+
const overlayKind = str(s[`${ok}background`]);
|
|
226
|
+
if (overlayKind === "classic") {
|
|
227
|
+
const overlay = colorAt(s, `${ok}color`, ctx);
|
|
228
|
+
const opacity = s[`${ok}opacity`];
|
|
229
|
+
const amount = num(isRecord(opacity) ? opacity["size"] : opacity);
|
|
230
|
+
if (overlay) style["overlay"] = { color: overlay, opacity: clamp(amount ?? 0.5, 0, 1) };
|
|
231
|
+
} else if (overlayKind === "gradient") {
|
|
232
|
+
// W-949: EmVB overlays can be gradients.
|
|
233
|
+
const gradient = gradientOf(s, ok, ctx);
|
|
234
|
+
const opacity = s[`${ok}opacity`];
|
|
235
|
+
const amount = num(isRecord(opacity) ? opacity["size"] : opacity);
|
|
236
|
+
if (gradient) {
|
|
237
|
+
style["overlay"] = {
|
|
238
|
+
gradient,
|
|
239
|
+
...(amount !== undefined && amount < 1 ? { opacity: clamp(amount, 0, 1) } : {}),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return style;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Typography under `p` (`typography`, `title_typography`, ...). Elementor applies it only when
|
|
249
|
+
* `${p}_typography` is "custom" or a global; `fallback` is the widget's default global (stock
|
|
250
|
+
* Elementor) when `ctx.useDefaults`.
|
|
251
|
+
*/
|
|
252
|
+
export function typographyReader(p: string, fallback?: string): Reader {
|
|
253
|
+
return (s, d, ctx: ImportContext) => {
|
|
254
|
+
const style: Style = {};
|
|
255
|
+
const ref = globalRef(s, `${p}_typography`);
|
|
256
|
+
if (d === "") {
|
|
257
|
+
const global =
|
|
258
|
+
ref !== undefined && ref !== ""
|
|
259
|
+
? ctx.globalTypography(ref)
|
|
260
|
+
: str(s[`${p}_typography`]) !== "custom" && fallback && ctx.useDefaults
|
|
261
|
+
? ctx.globalTypography(fallback)
|
|
262
|
+
: undefined;
|
|
263
|
+
if (global) Object.assign(style, typographyFromGlobal(ctx, global));
|
|
264
|
+
}
|
|
265
|
+
if (str(s[`${p}_typography`]) !== "custom") return style;
|
|
266
|
+
if (d === "") {
|
|
267
|
+
const family = ctx.useFont(s[`${p}_font_family`]);
|
|
268
|
+
if (family) style["fontFamily"] = family;
|
|
269
|
+
const weight = fontWeight(s[`${p}_font_weight`]);
|
|
270
|
+
if (weight !== undefined) style["fontWeight"] = weight;
|
|
271
|
+
const transform = str(s[`${p}_text_transform`]);
|
|
272
|
+
if (
|
|
273
|
+
transform === "uppercase" ||
|
|
274
|
+
transform === "lowercase" ||
|
|
275
|
+
transform === "capitalize" ||
|
|
276
|
+
transform === "none"
|
|
277
|
+
) {
|
|
278
|
+
style["textTransform"] = transform;
|
|
279
|
+
}
|
|
280
|
+
const decoration = str(s[`${p}_text_decoration`]);
|
|
281
|
+
if (
|
|
282
|
+
decoration === "underline" ||
|
|
283
|
+
decoration === "overline" ||
|
|
284
|
+
decoration === "line-through" ||
|
|
285
|
+
decoration === "none"
|
|
286
|
+
) {
|
|
287
|
+
style["textDecoration"] = decoration;
|
|
288
|
+
}
|
|
289
|
+
const fontStyle = str(s[`${p}_font_style`]);
|
|
290
|
+
if (fontStyle === "italic" || fontStyle === "oblique") style["fontStyle"] = "italic";
|
|
291
|
+
else if (fontStyle === "normal") style["fontStyle"] = "normal";
|
|
292
|
+
}
|
|
293
|
+
const size = slider(at(s, `${p}_font_size`, d));
|
|
294
|
+
if (size) style["fontSize"] = size;
|
|
295
|
+
const lineHeight = at(s, `${p}_line_height`, d);
|
|
296
|
+
const lh = slider(lineHeight);
|
|
297
|
+
if (lh) {
|
|
298
|
+
const unit = isRecord(lineHeight) ? str(lineHeight["unit"]) : undefined;
|
|
299
|
+
style["lineHeight"] =
|
|
300
|
+
unit === "em" || unit === "" || unit === undefined ? Math.min(lh.value, 100) : lh;
|
|
301
|
+
}
|
|
302
|
+
const spacing = slider(at(s, `${p}_letter_spacing`, d), { negative: true });
|
|
303
|
+
if (spacing) style["letterSpacing"] = spacing;
|
|
304
|
+
return style;
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** Text colour from `key` (or the widget's default global) and alignment from `alignKey`. */
|
|
309
|
+
export function textReader(colorKey: string, fallback?: string, alignKey = "align"): Reader {
|
|
310
|
+
return (s, d, ctx) => {
|
|
311
|
+
const style: Style = {};
|
|
312
|
+
const fill =
|
|
313
|
+
colorAt(s, colorKey, ctx, d) ??
|
|
314
|
+
(d === "" && fallback && ctx.useDefaults && !s[colorKey]
|
|
315
|
+
? ctx.globalColor(fallback)
|
|
316
|
+
: undefined);
|
|
317
|
+
if (fill) style["color"] = fill;
|
|
318
|
+
const align = textAlign(at(s, alignKey, d));
|
|
319
|
+
if (align) style["textAlign"] = align;
|
|
320
|
+
return style;
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Flex settings of a container (`flex_direction`, `flex_gap`, ...), with Elementor's defaults. */
|
|
325
|
+
export const flexReader: Reader = (s, d) => {
|
|
326
|
+
const style: Style = {};
|
|
327
|
+
const direction = str(at(s, "flex_direction", d));
|
|
328
|
+
if (
|
|
329
|
+
direction === "row" ||
|
|
330
|
+
direction === "column" ||
|
|
331
|
+
direction === "row-reverse" ||
|
|
332
|
+
direction === "column-reverse"
|
|
333
|
+
) {
|
|
334
|
+
style["flexDirection"] = direction;
|
|
335
|
+
} else if (d === "") {
|
|
336
|
+
style["flexDirection"] = "column";
|
|
337
|
+
}
|
|
338
|
+
const justify = flexValue(at(s, "flex_justify_content", d), JUSTIFY_CONTENT);
|
|
339
|
+
if (justify) style["justifyContent"] = justify;
|
|
340
|
+
const align = flexValue(at(s, "flex_align_items", d), ALIGN_ITEMS);
|
|
341
|
+
if (align) style["alignItems"] = align;
|
|
342
|
+
const wrap = str(at(s, "flex_wrap", d));
|
|
343
|
+
if (wrap === "wrap" || wrap === "nowrap" || wrap === "wrap-reverse") style["flexWrap"] = wrap;
|
|
344
|
+
const gapValue = at(s, "flex_gap", d);
|
|
345
|
+
const gap = isRecord(gapValue)
|
|
346
|
+
? slider({ size: gapValue["column"] ?? gapValue["size"], unit: gapValue["unit"] })
|
|
347
|
+
: undefined;
|
|
348
|
+
if (gap) style["gap"] = gap;
|
|
349
|
+
else if (d === "") style["gap"] = { value: 20, unit: "px" };
|
|
350
|
+
const minHeight = slider(at(s, "min_height", d));
|
|
351
|
+
if (minHeight) style["minHeight"] = minHeight;
|
|
352
|
+
return style;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
/** Width of a child box: containers' `width`, widgets' `_element_width` (+ custom width). */
|
|
356
|
+
export const widthReader =
|
|
357
|
+
(key: "width" | "_element_custom_width"): Reader =>
|
|
358
|
+
(s, d) => {
|
|
359
|
+
const style: Style = {};
|
|
360
|
+
if (key === "_element_custom_width") {
|
|
361
|
+
const mode = str(at(s, "_element_width", d));
|
|
362
|
+
if (mode === "auto") style["width"] = "auto";
|
|
363
|
+
else if (mode === "initial") {
|
|
364
|
+
const width = slider(at(s, key, d));
|
|
365
|
+
if (width) style["width"] = width;
|
|
366
|
+
}
|
|
367
|
+
return style;
|
|
368
|
+
}
|
|
369
|
+
const width = slider(at(s, key, d));
|
|
370
|
+
if (width) style["width"] = width;
|
|
371
|
+
return style;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const ENTRANCES: Record<string, string> = {
|
|
375
|
+
fadeIn: "fade",
|
|
376
|
+
fadeInUp: "fade-up",
|
|
377
|
+
fadeInDown: "fade-down",
|
|
378
|
+
slideInUp: "slide-up",
|
|
379
|
+
slideInDown: "slide-down",
|
|
380
|
+
zoomIn: "scale",
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
/** `_animation` / `animation` → an on-view entrance. */
|
|
384
|
+
export function entrance(s: Settings, ctx: ImportContext, el: string): Style | undefined {
|
|
385
|
+
const name = str(s["_animation"]) ?? str(s["animation"]);
|
|
386
|
+
if (!name || name === "none") return undefined;
|
|
387
|
+
let type = ENTRANCES[name];
|
|
388
|
+
if (!type) {
|
|
389
|
+
type = "fade";
|
|
390
|
+
ctx.note("approximated", el, `Entrance animation "${name}" is shown as a fade.`);
|
|
391
|
+
}
|
|
392
|
+
const speed = str(s["animation_duration"]);
|
|
393
|
+
const duration = speed === "slow" ? 2000 : speed === "fast" ? 750 : 1250;
|
|
394
|
+
const delayRaw = num(s["_animation_delay"] ?? s["animation_delay"]);
|
|
395
|
+
const delay = delayRaw !== undefined ? clamp(Math.round(delayRaw), 0, 2000) : undefined;
|
|
396
|
+
return { type, duration, trigger: "view", ...(delay ? { delay } : {}) };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* `hide_desktop` / `hide_laptop` / `hide_tablet` / `hide_mobile` → `hiddenOn`. W-956: a site
|
|
401
|
+
* without Elementor's laptop breakpoint (no `hide_laptop` setting) hides "desktop" from 1025 px,
|
|
402
|
+
* laptops included.
|
|
403
|
+
*/
|
|
404
|
+
/**
|
|
405
|
+
* W-959: `hide_widescreen` when the site has Elementor's widescreen breakpoint and it hides or
|
|
406
|
+
* shows unlike Desktop (`style.wide.hidden`); undefined when Wide screen follows Desktop.
|
|
407
|
+
*/
|
|
408
|
+
export function wideHidden(s: Settings): boolean | undefined {
|
|
409
|
+
if (!("hide_widescreen" in s)) return undefined;
|
|
410
|
+
const wide = !!str(s["hide_widescreen"]);
|
|
411
|
+
return wide === !!str(s["hide_desktop"]) ? undefined : wide;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** Two styles one after the other; their Wide screen records merge too (W-959). */
|
|
415
|
+
export function mergeStyles(a: Style | undefined, b: Style | undefined): Style {
|
|
416
|
+
const out: Style = { ...a, ...b };
|
|
417
|
+
if (isRecord(a?.["wide"]) && isRecord(b?.["wide"])) out["wide"] = { ...a["wide"], ...b["wide"] };
|
|
418
|
+
return out;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function hiddenOn(s: Settings): ("desktop" | "laptop" | "tablet" | "mobile")[] | undefined {
|
|
422
|
+
const out: ("desktop" | "laptop" | "tablet" | "mobile")[] = [];
|
|
423
|
+
const laptopActive = "hide_laptop" in s;
|
|
424
|
+
if (str(s["hide_desktop"])) out.push("desktop");
|
|
425
|
+
if (laptopActive ? str(s["hide_laptop"]) : str(s["hide_desktop"])) out.push("laptop");
|
|
426
|
+
if (str(s["hide_tablet"])) out.push("tablet");
|
|
427
|
+
if (str(s["hide_mobile"])) out.push("mobile");
|
|
428
|
+
return out.length > 0 ? out : undefined;
|
|
429
|
+
}
|