@perkyzz/emvb 1.3.0 → 1.4.1
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 +2 -2
- package/package.json +2 -2
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/content-item.ts +3 -0
- package/src/admin/copy-rich-text.ts +99 -9
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +28 -3
- package/src/admin/editor/Timeline.tsx +1 -8
- package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
- package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
- package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
- package/src/admin/editor/canvas/vnode-react.tsx +2 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/collection-previews.ts +7 -8
- package/src/admin/editor/dnd/dragged-source.ts +22 -0
- package/src/admin/editor/dnd/layer-drop.ts +141 -0
- package/src/admin/editor/dnd/new-element.ts +16 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +6 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
- package/src/admin/editor/extensions-context.tsx +16 -1
- package/src/admin/editor/feature-css.ts +27 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
- package/src/admin/editor/panels/ElementPanel.tsx +2 -2
- package/src/admin/editor/panels/FontFaces.tsx +342 -0
- package/src/admin/editor/panels/LayersPanel.tsx +56 -6
- package/src/admin/editor/panels/LeftPanel.tsx +153 -29
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
- package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
- package/src/admin/editor/panels/TokenScales.tsx +2 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
- package/src/admin/editor/panels/VariableSection.tsx +111 -7
- package/src/admin/editor/panels/color-space.ts +71 -6
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +33 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
- package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
- package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
- package/src/admin/editor/panels/settings/loop-context.ts +34 -3
- package/src/admin/editor/panels/settings/style-sections.ts +19 -2
- package/src/admin/editor/panels/url-rules.ts +43 -0
- package/src/admin/editor/panels/use-layers-drop.ts +232 -0
- package/src/admin/editor/store.ts +4 -2
- package/src/admin/editor/useExtensions.ts +3 -1
- package/src/admin/editor/useNodeActions.ts +74 -1
- package/src/admin/editor/useSave.ts +116 -85
- package/src/admin/export-api.ts +27 -2
- package/src/admin/extension-outputs.ts +236 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/import-forms.ts +133 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +53 -187
- package/src/admin/pages/ImportForms.tsx +71 -0
- package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
- package/src/admin/pages/ImportImageCopies.tsx +167 -0
- package/src/admin/pages/ImportReport.tsx +63 -0
- package/src/admin/pages/NewPageDialog.tsx +54 -32
- package/src/admin/pages/PageList.tsx +9 -0
- package/src/admin/pages/ThemePartList.tsx +9 -0
- package/src/admin/setup/plan.ts +2 -0
- package/src/admin/ui.ts +7 -0
- package/src/admin/widgets/ConvertToRichText.tsx +3 -2
- package/src/astro/EmVBPage.astro +5 -2
- package/src/astro/extension-styles.ts +35 -0
- package/src/astro/forms/EmVBFormsClient.astro +3 -0
- package/src/astro/forms/enhance.ts +107 -0
- package/src/astro/popups/runtime.ts +47 -2
- package/src/astro/render.ts +25 -4
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/resolve.ts +2 -0
- package/src/astro/theme-posts.ts +17 -23
- package/src/astro/visitor.ts +14 -5
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +18 -7
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +14 -5
- package/src/astro/widgets/sticky.ts +87 -0
- package/src/astro/widgets/theme.ts +52 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +150 -2
- package/src/core/arrange.ts +19 -1
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +41 -2
- package/src/core/css/trace.ts +8 -0
- package/src/core/data/bindings.ts +7 -4
- package/src/core/elements/dynamic-elements.ts +1 -1
- package/src/core/elements/element-nouns.ts +48 -0
- package/src/core/elements/form-elements.ts +119 -9
- package/src/core/elements/icon-svg.ts +14 -0
- package/src/core/elements/index.ts +24 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +13 -3
- package/src/core/export/runtimes.generated.ts +7 -5
- package/src/core/export/site.ts +53 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +19 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/placeholder.ts +7 -2
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +115 -36
- package/src/core/extensions/safe-nodes.ts +67 -11
- package/src/core/extensions/types.ts +48 -1
- package/src/core/fonts/files.ts +74 -0
- package/src/core/fonts/google.ts +112 -0
- package/src/core/fonts/test-font.ts +9 -0
- package/src/core/import/elementor/context.ts +42 -4
- package/src/core/import/elementor/index.ts +55 -23
- package/src/core/import/elementor/widgets.ts +242 -20
- package/src/core/import/html/blocks.ts +602 -0
- package/src/core/import/html/index.ts +155 -0
- package/src/core/import/html/map.ts +958 -0
- package/src/core/import/html/parse.ts +430 -0
- package/src/core/index.ts +54 -0
- package/src/core/migrate/v18.ts +3 -0
- package/src/core/public-attributes.ts +17 -0
- package/src/core/render/extras.ts +31 -7
- package/src/core/render/form.ts +103 -10
- package/src/core/render/index.ts +165 -16
- package/src/core/render/section.ts +31 -1
- package/src/core/render/spacer-basis.ts +102 -0
- package/src/core/render/theme-boot.ts +16 -0
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +68 -3
- package/src/core/sanitize/motion.ts +12 -0
- package/src/core/schema/design.ts +40 -0
- package/src/core/schema/layout.ts +118 -6
- package/src/core/schema/style.ts +28 -0
- package/src/core/templates/index.ts +218 -0
- package/src/core/templates/pages.ts +29 -0
- package/src/core/templates/sections.ts +794 -0
- package/src/core/templates/types.ts +9 -0
- package/src/core/theme/dynamic.ts +9 -6
- package/src/core/theme/media-value.ts +88 -0
- package/src/core/theme/popup-markup.ts +21 -2
- package/src/core/theme/popup-rules.ts +36 -0
- package/src/core/theme/triggers.ts +64 -5
- package/src/core/translatable.ts +5 -2
- package/src/core/visitor-cookie.ts +91 -0
- package/src/extension-build.ts +331 -0
- package/src/index.ts +53 -4
- package/src/mcp/agent-defaults.ts +40 -0
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/extensions.ts +138 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +84 -20
- package/src/mcp/tools.ts +42 -3
- package/src/mcp/write.ts +124 -9
- package/src/server/extension-routes.ts +110 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +15 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1074: a small, tolerant HTML reader for the WordPress and HTML import. It turns pasted or
|
|
3
|
+
* uploaded markup into a neutral tree of elements, text and WordPress block delimiters
|
|
4
|
+
* (`<!-- wp:paragraph {"align":"center"} -->`) that `importHtml` maps onto EmVB elements.
|
|
5
|
+
*
|
|
6
|
+
* Why a reader in core and not the browser's DOMParser: core stays free of the DOM (it runs in
|
|
7
|
+
* the admin, on the server and in `bun test` alike), the same input always gives the same tree,
|
|
8
|
+
* Gutenberg's block comments come out as structure instead of comment nodes, and nothing here
|
|
9
|
+
* ever loads, runs or renders the input. The tree only carries tag names, attribute strings and
|
|
10
|
+
* text; the mapper decides what of it becomes plain EmVB props.
|
|
11
|
+
*
|
|
12
|
+
* It follows the parts of HTML's tree building that matter for content (void elements, implied
|
|
13
|
+
* ends of `p`, `li`, `dt`/`dd`, table rows and cells, raw-text elements) and ignores stray end
|
|
14
|
+
* tags. Everything is bounded: nodes read, nesting depth and attribute sizes.
|
|
15
|
+
*/
|
|
16
|
+
import { decodeEntities } from "../elementor/html.ts";
|
|
17
|
+
|
|
18
|
+
export type HtmlElement = {
|
|
19
|
+
kind: "element";
|
|
20
|
+
tag: string;
|
|
21
|
+
attrs: Readonly<Record<string, string>>;
|
|
22
|
+
children: HtmlNode[];
|
|
23
|
+
};
|
|
24
|
+
export type HtmlText = { kind: "text"; text: string };
|
|
25
|
+
/** A WordPress block: `name` is namespaced (`core/paragraph`), `attrs` its JSON attributes. */
|
|
26
|
+
export type WpBlock = {
|
|
27
|
+
kind: "block";
|
|
28
|
+
name: string;
|
|
29
|
+
attrs: Readonly<Record<string, unknown>>;
|
|
30
|
+
children: HtmlNode[];
|
|
31
|
+
};
|
|
32
|
+
export type HtmlNode = HtmlElement | HtmlText | WpBlock;
|
|
33
|
+
|
|
34
|
+
export type ParsedHtml = {
|
|
35
|
+
nodes: HtmlNode[];
|
|
36
|
+
/** The document's `<title>`, when it has one. */
|
|
37
|
+
title?: string;
|
|
38
|
+
/** WordPress block delimiters were found (Gutenberg post content). */
|
|
39
|
+
blocks: boolean;
|
|
40
|
+
/** What the reader dropped on its own: scripts, styles, inline SVG… */
|
|
41
|
+
dropped: string[];
|
|
42
|
+
/** Nesting deeper than the reader keeps was flattened. */
|
|
43
|
+
flattened: boolean;
|
|
44
|
+
/** The input had more nodes than the reader keeps; the rest was left out. */
|
|
45
|
+
cut: boolean;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Parse nodes kept per import (elements and text runs). */
|
|
49
|
+
export const MAX_PARSE_NODES = 20_000;
|
|
50
|
+
/** Element nesting kept; deeper elements add their content to the deepest kept one. */
|
|
51
|
+
export const MAX_PARSE_DEPTH = 48;
|
|
52
|
+
const MAX_ATTRS = 64;
|
|
53
|
+
const MAX_ATTR_VALUE = 8192;
|
|
54
|
+
const MAX_BLOCK_ATTRS = 65_536;
|
|
55
|
+
|
|
56
|
+
const VOID = new Set([
|
|
57
|
+
"area",
|
|
58
|
+
"base",
|
|
59
|
+
"br",
|
|
60
|
+
"col",
|
|
61
|
+
"embed",
|
|
62
|
+
"hr",
|
|
63
|
+
"img",
|
|
64
|
+
"input",
|
|
65
|
+
"link",
|
|
66
|
+
"meta",
|
|
67
|
+
"param",
|
|
68
|
+
"source",
|
|
69
|
+
"track",
|
|
70
|
+
"wbr",
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
/** Elements whose content is not markup: skipped whole. */
|
|
74
|
+
const RAW_TEXT = new Set([
|
|
75
|
+
"script",
|
|
76
|
+
"style",
|
|
77
|
+
"textarea",
|
|
78
|
+
"title",
|
|
79
|
+
"noscript",
|
|
80
|
+
"template",
|
|
81
|
+
"svg",
|
|
82
|
+
"math",
|
|
83
|
+
"iframe",
|
|
84
|
+
"xmp",
|
|
85
|
+
"noembed",
|
|
86
|
+
"noframes",
|
|
87
|
+
"plaintext",
|
|
88
|
+
"object",
|
|
89
|
+
"canvas",
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
const DROPPED_NAME: Record<string, string> = {
|
|
93
|
+
script: "scripts",
|
|
94
|
+
style: "styles",
|
|
95
|
+
svg: "inline SVG drawings",
|
|
96
|
+
math: "MathML formulas",
|
|
97
|
+
noscript: "noscript fallbacks",
|
|
98
|
+
template: "templates",
|
|
99
|
+
textarea: "form fields",
|
|
100
|
+
object: "embedded objects",
|
|
101
|
+
canvas: "canvas drawings",
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Opening one of these ends an open `p` (HTML's "close a p element"). */
|
|
105
|
+
const CLOSES_P = new Set([
|
|
106
|
+
"address",
|
|
107
|
+
"article",
|
|
108
|
+
"aside",
|
|
109
|
+
"blockquote",
|
|
110
|
+
"details",
|
|
111
|
+
"div",
|
|
112
|
+
"dl",
|
|
113
|
+
"fieldset",
|
|
114
|
+
"figcaption",
|
|
115
|
+
"figure",
|
|
116
|
+
"footer",
|
|
117
|
+
"form",
|
|
118
|
+
"h1",
|
|
119
|
+
"h2",
|
|
120
|
+
"h3",
|
|
121
|
+
"h4",
|
|
122
|
+
"h5",
|
|
123
|
+
"h6",
|
|
124
|
+
"header",
|
|
125
|
+
"hr",
|
|
126
|
+
"main",
|
|
127
|
+
"menu",
|
|
128
|
+
"nav",
|
|
129
|
+
"ol",
|
|
130
|
+
"p",
|
|
131
|
+
"pre",
|
|
132
|
+
"section",
|
|
133
|
+
"summary",
|
|
134
|
+
"table",
|
|
135
|
+
"ul",
|
|
136
|
+
]);
|
|
137
|
+
|
|
138
|
+
const HEADINGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Implied ends: opening `tag` closes the nearest open element in `closes`, unless one of `stop`
|
|
142
|
+
* comes first (from the innermost element outwards).
|
|
143
|
+
*/
|
|
144
|
+
const IMPLIED: Record<string, { closes: ReadonlySet<string>; stop: ReadonlySet<string> }> = {
|
|
145
|
+
li: { closes: new Set(["li"]), stop: new Set(["ul", "ol", "menu", "table", "td", "th"]) },
|
|
146
|
+
dt: { closes: new Set(["dt", "dd"]), stop: new Set(["dl", "table", "td", "th"]) },
|
|
147
|
+
dd: { closes: new Set(["dt", "dd"]), stop: new Set(["dl", "table", "td", "th"]) },
|
|
148
|
+
tr: { closes: new Set(["tr"]), stop: new Set(["table", "thead", "tbody", "tfoot"]) },
|
|
149
|
+
td: { closes: new Set(["td", "th"]), stop: new Set(["tr", "table"]) },
|
|
150
|
+
th: { closes: new Set(["td", "th"]), stop: new Set(["tr", "table"]) },
|
|
151
|
+
thead: { closes: new Set(["thead", "tbody", "tfoot"]), stop: new Set(["table"]) },
|
|
152
|
+
tbody: { closes: new Set(["thead", "tbody", "tfoot"]), stop: new Set(["table"]) },
|
|
153
|
+
tfoot: { closes: new Set(["thead", "tbody", "tfoot"]), stop: new Set(["table"]) },
|
|
154
|
+
a: { closes: new Set(["a"]), stop: new Set(["td", "th", "table", "button"]) },
|
|
155
|
+
option: { closes: new Set(["option"]), stop: new Set(["select", "datalist"]) },
|
|
156
|
+
};
|
|
157
|
+
const P_SCOPE = new Set(["button", "table", "td", "th", "caption", "template", "object"]);
|
|
158
|
+
|
|
159
|
+
/** Entities HTML knows that the shared decoder doesn't, used to hide a URL's scheme. */
|
|
160
|
+
const EXTRA_ENTITIES: Record<string, string> = {
|
|
161
|
+
colon: ":",
|
|
162
|
+
tab: "\t",
|
|
163
|
+
newline: "\n",
|
|
164
|
+
sol: "/",
|
|
165
|
+
bsol: "\\",
|
|
166
|
+
lpar: "(",
|
|
167
|
+
rpar: ")",
|
|
168
|
+
period: ".",
|
|
169
|
+
comma: ",",
|
|
170
|
+
excl: "!",
|
|
171
|
+
quest: "?",
|
|
172
|
+
num: "#",
|
|
173
|
+
equals: "=",
|
|
174
|
+
plus: "+",
|
|
175
|
+
commat: "@",
|
|
176
|
+
percnt: "%",
|
|
177
|
+
lowbar: "_",
|
|
178
|
+
semi: ";",
|
|
179
|
+
ast: "*",
|
|
180
|
+
dollar: "$",
|
|
181
|
+
grave: "`",
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Text and attribute values as a browser reads them: named and numeric references, including
|
|
186
|
+
* numeric ones without their `;` (`javascript:`), so a hidden scheme is seen by the
|
|
187
|
+
* sanitizers and refused.
|
|
188
|
+
*/
|
|
189
|
+
export function decodeHtml(text: string): string {
|
|
190
|
+
if (!text.includes("&")) return text;
|
|
191
|
+
const named = text.replace(/&([a-z]{2,8});/gi, (whole, name: string) => {
|
|
192
|
+
const extra = EXTRA_ENTITIES[name.toLowerCase()];
|
|
193
|
+
return extra ?? whole;
|
|
194
|
+
});
|
|
195
|
+
const numeric = named
|
|
196
|
+
.replace(/&#(\d{1,7})(?![\d;])/g, "&#$1;")
|
|
197
|
+
.replace(/&#x([0-9a-f]{1,6})(?![0-9a-f;])/gi, "&#x$1;");
|
|
198
|
+
return decodeEntities(numeric);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const ATTR = /([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
202
|
+
|
|
203
|
+
function readAttrs(source: string): Record<string, string> {
|
|
204
|
+
const out: Record<string, string> = {};
|
|
205
|
+
let count = 0;
|
|
206
|
+
for (const m of source.matchAll(ATTR)) {
|
|
207
|
+
const name = (m[1] ?? "").toLowerCase();
|
|
208
|
+
if (!name || name in out) continue;
|
|
209
|
+
if (++count > MAX_ATTRS) break;
|
|
210
|
+
const raw = m[2] ?? m[3] ?? m[4] ?? "";
|
|
211
|
+
// A value too long to be a sensible address or caption (a data: image, say) is left out.
|
|
212
|
+
out[name] = raw.length > MAX_ATTR_VALUE ? "" : decodeHtml(raw);
|
|
213
|
+
}
|
|
214
|
+
return out;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const BLOCK_COMMENT =
|
|
218
|
+
/^\s*(\/)?wp:([a-z][a-z0-9_-]*\/)?([a-z][a-z0-9_-]*)\s+(\{[\s\S]*\}\s+)?(\/)?$/;
|
|
219
|
+
|
|
220
|
+
type Open = HtmlElement | WpBlock;
|
|
221
|
+
|
|
222
|
+
/** Reads `input` into a tree. Never throws; malformed markup gives a best-effort tree. */
|
|
223
|
+
export function parseHtml(input: string): ParsedHtml {
|
|
224
|
+
const html = input;
|
|
225
|
+
const lower = html.toLowerCase();
|
|
226
|
+
const len = html.length;
|
|
227
|
+
const root: WpBlock = { kind: "block", name: "#root", attrs: {}, children: [] };
|
|
228
|
+
const stack: Open[] = [root];
|
|
229
|
+
const dropped = new Set<string>();
|
|
230
|
+
let title: string | undefined;
|
|
231
|
+
let blocks = false;
|
|
232
|
+
let flattened = false;
|
|
233
|
+
let cut = false;
|
|
234
|
+
let count = 0;
|
|
235
|
+
|
|
236
|
+
const top = () => stack[stack.length - 1] as Open;
|
|
237
|
+
const elementDepth = () => stack.length - 1;
|
|
238
|
+
const budget = () => {
|
|
239
|
+
if (count >= MAX_PARSE_NODES) {
|
|
240
|
+
cut = true;
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
count++;
|
|
244
|
+
return true;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const addText = (raw: string) => {
|
|
248
|
+
if (!raw) return;
|
|
249
|
+
const text = decodeHtml(raw);
|
|
250
|
+
const kids = top().children;
|
|
251
|
+
const last = kids[kids.length - 1];
|
|
252
|
+
if (last?.kind === "text") {
|
|
253
|
+
last.text += text;
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (!budget()) return;
|
|
257
|
+
kids.push({ kind: "text", text });
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/** Closes the nearest open `names` element above any `stop` element; true when one closed. */
|
|
261
|
+
const closeNearest = (names: ReadonlySet<string>, stop: ReadonlySet<string>): boolean => {
|
|
262
|
+
for (let i = stack.length - 1; i > 0; i--) {
|
|
263
|
+
const open = stack[i] as Open;
|
|
264
|
+
if (open.kind === "block") return false;
|
|
265
|
+
if (names.has(open.tag)) {
|
|
266
|
+
stack.length = i;
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
if (stop.has(open.tag)) return false;
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const openElement = (tag: string, attrs: Record<string, string>, isVoid: boolean) => {
|
|
275
|
+
if (CLOSES_P.has(tag)) closeNearest(new Set(["p"]), P_SCOPE);
|
|
276
|
+
if (HEADINGS.has(tag)) {
|
|
277
|
+
const current = top();
|
|
278
|
+
if (current.kind === "element" && HEADINGS.has(current.tag)) stack.pop();
|
|
279
|
+
}
|
|
280
|
+
const implied = IMPLIED[tag];
|
|
281
|
+
if (implied) closeNearest(implied.closes, implied.stop);
|
|
282
|
+
if (!budget()) return;
|
|
283
|
+
const element: HtmlElement = { kind: "element", tag, attrs, children: [] };
|
|
284
|
+
top().children.push(element);
|
|
285
|
+
if (isVoid) return;
|
|
286
|
+
if (elementDepth() >= MAX_PARSE_DEPTH) {
|
|
287
|
+
// Too deep: its content goes into the deepest kept element.
|
|
288
|
+
flattened = true;
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
stack.push(element);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const closeElement = (tag: string) => {
|
|
295
|
+
for (let i = stack.length - 1; i > 0; i--) {
|
|
296
|
+
const open = stack[i] as Open;
|
|
297
|
+
if (open.kind === "block") return;
|
|
298
|
+
if (open.tag === tag) {
|
|
299
|
+
stack.length = i;
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const blockComment = (body: string) => {
|
|
306
|
+
const m = BLOCK_COMMENT.exec(body);
|
|
307
|
+
if (!m) return;
|
|
308
|
+
blocks = true;
|
|
309
|
+
const name = `${m[2] ?? "core/"}${m[3] ?? ""}`;
|
|
310
|
+
if (m[1]) {
|
|
311
|
+
for (let i = stack.length - 1; i > 0; i--) {
|
|
312
|
+
const open = stack[i] as Open;
|
|
313
|
+
if (open.kind === "block" && open.name === name) {
|
|
314
|
+
stack.length = i;
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
let attrs: Record<string, unknown> = {};
|
|
321
|
+
const json = m[4]?.trim();
|
|
322
|
+
if (json && json.length <= MAX_BLOCK_ATTRS) {
|
|
323
|
+
try {
|
|
324
|
+
const parsed = JSON.parse(json) as unknown;
|
|
325
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed))
|
|
326
|
+
attrs = parsed as Record<string, unknown>;
|
|
327
|
+
} catch {
|
|
328
|
+
// Unreadable attributes: the block keeps its content and default settings.
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (!budget()) return;
|
|
332
|
+
const block: WpBlock = { kind: "block", name, attrs, children: [] };
|
|
333
|
+
top().children.push(block);
|
|
334
|
+
if (m[5]) return;
|
|
335
|
+
if (stack.length - 1 >= MAX_PARSE_DEPTH) {
|
|
336
|
+
flattened = true;
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
stack.push(block);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const TAG_NAME = /[a-zA-Z][a-zA-Z0-9-]*/y;
|
|
343
|
+
let i = 0;
|
|
344
|
+
while (i < len) {
|
|
345
|
+
if (count >= MAX_PARSE_NODES) {
|
|
346
|
+
cut = true;
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
const lt = html.indexOf("<", i);
|
|
350
|
+
if (lt === -1) {
|
|
351
|
+
addText(html.slice(i));
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
if (lt > i) addText(html.slice(i, lt));
|
|
355
|
+
i = lt;
|
|
356
|
+
if (html.startsWith("<!--", i)) {
|
|
357
|
+
const end = html.indexOf("-->", i + 4);
|
|
358
|
+
blockComment(html.slice(i + 4, end === -1 ? len : end));
|
|
359
|
+
i = end === -1 ? len : end + 3;
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const next = html[i + 1];
|
|
363
|
+
if (next === "!" || next === "?") {
|
|
364
|
+
// Doctype, CDATA, processing instructions: nothing to keep.
|
|
365
|
+
const end = html.indexOf(">", i);
|
|
366
|
+
i = end === -1 ? len : end + 1;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
const closing = next === "/";
|
|
370
|
+
const nameAt = closing ? i + 2 : i + 1;
|
|
371
|
+
TAG_NAME.lastIndex = nameAt;
|
|
372
|
+
const nameMatch = TAG_NAME.exec(html);
|
|
373
|
+
if (!nameMatch) {
|
|
374
|
+
addText("<");
|
|
375
|
+
i++;
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
const tag = nameMatch[0].toLowerCase();
|
|
379
|
+
let j = nameAt + nameMatch[0].length;
|
|
380
|
+
let quote = "";
|
|
381
|
+
while (j < len) {
|
|
382
|
+
const c = html[j];
|
|
383
|
+
if (quote) {
|
|
384
|
+
if (c === quote) quote = "";
|
|
385
|
+
} else if (c === '"' || c === "'") quote = c;
|
|
386
|
+
else if (c === ">") break;
|
|
387
|
+
j++;
|
|
388
|
+
}
|
|
389
|
+
// A tag that never ends is dropped, as browsers do at the end of the input.
|
|
390
|
+
if (j >= len) break;
|
|
391
|
+
const attrSource = html.slice(nameAt + nameMatch[0].length, j);
|
|
392
|
+
i = j + 1;
|
|
393
|
+
if (closing) {
|
|
394
|
+
if (tag === "br") openElement("br", {}, true);
|
|
395
|
+
else if (tag === "p" && !closeNearest(new Set(["p"]), P_SCOPE)) {
|
|
396
|
+
// `</p>` with no open p: nothing to close.
|
|
397
|
+
} else closeElement(tag);
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (RAW_TEXT.has(tag)) {
|
|
401
|
+
const end = lower.indexOf(`</${tag}`, i);
|
|
402
|
+
const content = html.slice(i, end === -1 ? len : end);
|
|
403
|
+
const close = end === -1 ? -1 : html.indexOf(">", end);
|
|
404
|
+
i = close === -1 ? len : close + 1;
|
|
405
|
+
if (tag === "title") {
|
|
406
|
+
if (title === undefined) title = decodeHtml(content);
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
if (tag === "iframe") {
|
|
410
|
+
// Kept as an element (no content): video embeds become Video elements.
|
|
411
|
+
openElement("iframe", readAttrs(attrSource), true);
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
const name = DROPPED_NAME[tag];
|
|
415
|
+
if (name) dropped.add(name);
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
// As in HTML, a trailing slash on a non-void element (`<div/>`) doesn't close it.
|
|
419
|
+
openElement(tag, readAttrs(attrSource), VOID.has(tag));
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return {
|
|
423
|
+
nodes: root.children,
|
|
424
|
+
...(title?.trim() ? { title: title.replace(/\s+/g, " ").trim().slice(0, 200) } : {}),
|
|
425
|
+
blocks,
|
|
426
|
+
dropped: [...dropped],
|
|
427
|
+
flattened,
|
|
428
|
+
cut,
|
|
429
|
+
};
|
|
430
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -146,9 +146,35 @@ export {
|
|
|
146
146
|
ColorVariable,
|
|
147
147
|
emptyDesign,
|
|
148
148
|
FontVariable,
|
|
149
|
+
FONT_FAMILY_NAME,
|
|
149
150
|
LengthVariable,
|
|
150
151
|
type DefaultStyleTag,
|
|
152
|
+
type FontFace,
|
|
151
153
|
} from "./schema/design.ts";
|
|
154
|
+
export { fontFaceRules } from "./css/font-face.ts";
|
|
155
|
+
export {
|
|
156
|
+
base64ToBytes,
|
|
157
|
+
bytesToBase64,
|
|
158
|
+
FONT_FILE_LIMIT,
|
|
159
|
+
FONT_ID,
|
|
160
|
+
FONT_MAX_BYTES,
|
|
161
|
+
fontFileId,
|
|
162
|
+
fontFileProblem,
|
|
163
|
+
fontFileUrl,
|
|
164
|
+
} from "./fonts/files.ts";
|
|
165
|
+
export {
|
|
166
|
+
DEFAULT_GOOGLE_SUBSETS,
|
|
167
|
+
GOOGLE_CSS_HOST,
|
|
168
|
+
GOOGLE_FAMILY,
|
|
169
|
+
GOOGLE_FILE_HOST,
|
|
170
|
+
GOOGLE_FILES_PER_FACE,
|
|
171
|
+
GOOGLE_SUBSET,
|
|
172
|
+
GOOGLE_USER_AGENT,
|
|
173
|
+
GOOGLE_WEIGHTS,
|
|
174
|
+
googleCssUrl,
|
|
175
|
+
parseGoogleFontCss,
|
|
176
|
+
pickGoogleFaces,
|
|
177
|
+
} from "./fonts/google.ts";
|
|
152
178
|
export {
|
|
153
179
|
MAX_VARIABLES,
|
|
154
180
|
variableListFull,
|
|
@@ -373,6 +399,7 @@ export {
|
|
|
373
399
|
export {
|
|
374
400
|
TRIGGERS_SCHEMA_VERSION,
|
|
375
401
|
MAX_POPUP_TRIGGERS,
|
|
402
|
+
PANEL_SIZES,
|
|
376
403
|
defaultTriggers,
|
|
377
404
|
validateTriggers,
|
|
378
405
|
isSafeClickSelector,
|
|
@@ -399,6 +426,9 @@ export {
|
|
|
399
426
|
DEVICE_PREVIEW_PX,
|
|
400
427
|
matchesPopupDevices,
|
|
401
428
|
withinShowTimes,
|
|
429
|
+
MAX_URL_PARAM_RULES,
|
|
430
|
+
URL_PARAM_NAME,
|
|
431
|
+
type UrlParamRule,
|
|
402
432
|
type PopupDevice,
|
|
403
433
|
} from "./theme/popup-rules.ts";
|
|
404
434
|
|
|
@@ -448,6 +478,13 @@ export {
|
|
|
448
478
|
type ArchivePagination,
|
|
449
479
|
type PaginationItem,
|
|
450
480
|
} from "./theme/pagination.ts";
|
|
481
|
+
export {
|
|
482
|
+
DEFAULT_IMAGE_FIELD,
|
|
483
|
+
automaticImageField,
|
|
484
|
+
entryImageValue,
|
|
485
|
+
imageFieldsOf,
|
|
486
|
+
mediaUrlOf,
|
|
487
|
+
} from "./theme/media-value.ts";
|
|
451
488
|
|
|
452
489
|
export { layoutHasMenuDropdown, layoutHasTabs } from "./tabs/presence.ts";
|
|
453
490
|
export {
|
|
@@ -541,6 +578,18 @@ export {
|
|
|
541
578
|
type RecipeId,
|
|
542
579
|
type RecipeTokens,
|
|
543
580
|
} from "./recipes/index.ts";
|
|
581
|
+
export {
|
|
582
|
+
PAGE_TEMPLATES,
|
|
583
|
+
SECTION_TEMPLATES,
|
|
584
|
+
TEMPLATE_FALLBACKS,
|
|
585
|
+
pageTemplate,
|
|
586
|
+
resolveTemplateNode,
|
|
587
|
+
sectionTemplate,
|
|
588
|
+
templatePageLayout,
|
|
589
|
+
templateSectionNode,
|
|
590
|
+
type PageTemplate,
|
|
591
|
+
type SectionTemplate,
|
|
592
|
+
} from "./templates/index.ts";
|
|
544
593
|
export {
|
|
545
594
|
decodeSharedPage,
|
|
546
595
|
encodeSharedPage,
|
|
@@ -586,11 +635,14 @@ export {
|
|
|
586
635
|
export { portableTextToLayout } from "./portable-text.ts";
|
|
587
636
|
export {
|
|
588
637
|
type ElementorImport,
|
|
638
|
+
type ImportedForm,
|
|
639
|
+
type ImportedFormField,
|
|
589
640
|
type ImportNote,
|
|
590
641
|
type ImportOptions,
|
|
591
642
|
importElementor,
|
|
592
643
|
MAX_IMPORT_CHARS,
|
|
593
644
|
} from "./import/elementor/index.ts";
|
|
645
|
+
export { type HtmlImport, importHtml, MAX_HTML_IMPORT_CHARS } from "./import/html/index.ts";
|
|
594
646
|
|
|
595
647
|
export {
|
|
596
648
|
EXTENSION_API_VERSION,
|
|
@@ -617,6 +669,8 @@ export {
|
|
|
617
669
|
extensionPlaceholderLabel,
|
|
618
670
|
extensionPlaceholderVNode,
|
|
619
671
|
normalizeExtension,
|
|
672
|
+
extensionOutputKey,
|
|
673
|
+
rememberExtensionManifests,
|
|
620
674
|
type EmVBExtension,
|
|
621
675
|
type ExtensionManifest,
|
|
622
676
|
type ExtensionElement,
|
package/src/core/migrate/v18.ts
CHANGED
|
@@ -13,6 +13,8 @@ const MOTION_PARTS = {
|
|
|
13
13
|
icon: "iconAnimation",
|
|
14
14
|
// W-938: added in 1.0; the flat key exists only inside EmVB (style rows, CSS).
|
|
15
15
|
loop: "loopMotion",
|
|
16
|
+
// W-1070: added in 1.4.
|
|
17
|
+
sticky: "stickyMotion",
|
|
16
18
|
} as const;
|
|
17
19
|
export type MotionPart = keyof typeof MOTION_PARTS;
|
|
18
20
|
export type FlatMotionKey = (typeof MOTION_PARTS)[MotionPart];
|
|
@@ -23,6 +25,7 @@ const PART_OF: Readonly<Record<string, MotionPart>> = {
|
|
|
23
25
|
transition: "transition",
|
|
24
26
|
iconAnimation: "icon",
|
|
25
27
|
loopMotion: "loop",
|
|
28
|
+
stickyMotion: "sticky",
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
export const FLAT_MOTION_KEYS: readonly FlatMotionKey[] = Object.values(MOTION_PARTS);
|
|
@@ -12,6 +12,23 @@ export const PUBLIC_DATA_ATTRIBUTES: readonly string[] = [
|
|
|
12
12
|
"data-emvb-float",
|
|
13
13
|
"data-emvb-float-dismiss",
|
|
14
14
|
"data-emvb-float-edge",
|
|
15
|
+
// W-1083: the widget and site hooks their opt-in runtimes read (1.2 to 1.4), and an empty Menu.
|
|
16
|
+
"data-emvb-menu-empty",
|
|
17
|
+
"data-emvb-alert-dismiss",
|
|
18
|
+
"data-emvb-lightbox",
|
|
19
|
+
"data-emvb-arrows",
|
|
20
|
+
"data-emvb-dots",
|
|
21
|
+
"data-emvb-autoplay",
|
|
22
|
+
"data-emvb-loop",
|
|
23
|
+
"data-emvb-counter",
|
|
24
|
+
"data-emvb-countdown",
|
|
25
|
+
"data-emvb-map",
|
|
26
|
+
"data-emvb-rotate",
|
|
27
|
+
"data-emvb-share-list",
|
|
28
|
+
"data-emvb-share",
|
|
29
|
+
"data-emvb-theme-toggle",
|
|
30
|
+
"data-emvb-sticky-hide",
|
|
31
|
+
"data-emvb-ext",
|
|
15
32
|
];
|
|
16
33
|
|
|
17
34
|
/**
|
|
@@ -70,10 +70,35 @@ const ALWAYS_INTERACTIVE = new Set([
|
|
|
70
70
|
"submit",
|
|
71
71
|
"pagination",
|
|
72
72
|
"toc",
|
|
73
|
+
// W-1073, W-1067: a search box and button; a toggle button.
|
|
74
|
+
"search-form",
|
|
75
|
+
"theme-toggle",
|
|
76
|
+
// A pause button; a map link and load button; network links; marker buttons.
|
|
77
|
+
"countdown",
|
|
78
|
+
"map",
|
|
79
|
+
"social-icons",
|
|
80
|
+
"social-link",
|
|
81
|
+
"share-buttons",
|
|
82
|
+
"share-link",
|
|
83
|
+
"hotspots",
|
|
84
|
+
"hotspot",
|
|
73
85
|
// Post content can hold links of its own.
|
|
74
86
|
"post-content",
|
|
75
87
|
]);
|
|
76
88
|
|
|
89
|
+
/** Elements that render a link only once this prop holds an address. */
|
|
90
|
+
const LINK_PROP: Record<string, string> = {
|
|
91
|
+
heading: "href",
|
|
92
|
+
icon: "href",
|
|
93
|
+
image: "href",
|
|
94
|
+
"icon-box": "href",
|
|
95
|
+
"image-box": "href",
|
|
96
|
+
cta: "href",
|
|
97
|
+
"flip-box": "href",
|
|
98
|
+
"price-list-item": "href",
|
|
99
|
+
"price-table": "buttonHref",
|
|
100
|
+
};
|
|
101
|
+
|
|
77
102
|
function containsInteractive(node: LayoutNode): boolean {
|
|
78
103
|
if (ALWAYS_INTERACTIVE.has(node.type)) return true;
|
|
79
104
|
const props = node.props as { partId?: unknown };
|
|
@@ -83,15 +108,14 @@ function containsInteractive(node: LayoutNode): boolean {
|
|
|
83
108
|
if (node.type === "loop" && typeof props.partId === "string" && props.partId.trim()) {
|
|
84
109
|
return true;
|
|
85
110
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
node.
|
|
89
|
-
node.type === "icon" ||
|
|
90
|
-
node.type === "image"
|
|
91
|
-
) {
|
|
92
|
-
const href = (node.props as { href?: unknown }).href;
|
|
111
|
+
const linkKey = LINK_PROP[node.type] ?? (BOX.has(node.type) ? "href" : undefined);
|
|
112
|
+
if (linkKey) {
|
|
113
|
+
const href = (node.props as Record<string, unknown>)[linkKey];
|
|
93
114
|
if (typeof href === "string" && href.trim()) return true;
|
|
94
115
|
}
|
|
116
|
+
if (node.type === "alert" && (node.props as { dismissible?: unknown }).dismissible === true) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
95
119
|
return childrenOf(node).some(containsInteractive);
|
|
96
120
|
}
|
|
97
121
|
|