@perkyzz/emvb 1.2.0 → 1.4.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 +2 -2
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/package.json +4 -4
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +22 -2
- 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 +5 -0
- package/src/admin/editor/co-design.ts +36 -1
- 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 +76 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +34 -0
- package/src/admin/editor/feature-css.ts +22 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.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 +18 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +33 -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/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 +25 -2
- package/src/admin/extension-outputs.ts +179 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +22 -188
- 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/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 +19 -4
- package/src/astro/request-data.ts +6 -0
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/resolve.ts +9 -0
- package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
- package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
- package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
- package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +22 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +91 -0
- package/src/astro/widgets/counter.ts +98 -0
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +99 -0
- package/src/astro/widgets/map.ts +37 -0
- package/src/astro/widgets/share.ts +21 -0
- 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 +177 -6
- package/src/core/arrange.ts +71 -1
- package/src/core/canvas-collections.ts +28 -0
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +35 -1
- package/src/core/elements/counter-format.ts +15 -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 +54 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/marketing.ts +1490 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +40 -5
- package/src/core/export/runtimes.generated.ts +10 -3
- package/src/core/export/site.ts +55 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +17 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +66 -21
- 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 +13 -4
- package/src/core/import/elementor/index.ts +32 -21
- package/src/core/import/elementor/widgets.ts +532 -293
- 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 +45 -0
- package/src/core/limits.ts +6 -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 +172 -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 +534 -22
- 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 +11 -6
- 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/extension-build.ts +331 -0
- package/src/index.ts +25 -3
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +29 -1
- package/src/mcp/tools.ts +40 -1
- package/src/mcp/write.ts +41 -1
- package/src/server/extension-routes.ts +73 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +11 -1
|
@@ -59,6 +59,23 @@ export type ExtensionField = Pick<
|
|
|
59
59
|
"key" | "kind" | "label" | "options" | "message" | "optional" | "max" | "min"
|
|
60
60
|
>;
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* W-1086: a node an extension's render() returns. Built-in node fields, plus `extClasses`: class
|
|
64
|
+
* names from the extension's own `classes.allow` list. Names not on the list are dropped. This is
|
|
65
|
+
* render output only; it is never stored in a layout.
|
|
66
|
+
*/
|
|
67
|
+
export type ExtensionOutputNode = LayoutNode & { extClasses?: readonly string[] };
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* W-1086: the static class allowlist an extension declares. Every name starts with `prefix`
|
|
71
|
+
* (lowercase letters, digits and hyphens, ending in `-`, never `emvb…`), so extension classes
|
|
72
|
+
* can't clash with EmVB's `emvb-*` classes or a site's own design classes.
|
|
73
|
+
*/
|
|
74
|
+
export type ExtensionClasses = {
|
|
75
|
+
prefix: string;
|
|
76
|
+
allow: readonly string[];
|
|
77
|
+
};
|
|
78
|
+
|
|
62
79
|
/** Context passed to an element render function (read-only source values). */
|
|
63
80
|
export type ExtensionRenderContext = {
|
|
64
81
|
/** Resolved values from this extension's sources, keyed by source name then field. */
|
|
@@ -80,7 +97,7 @@ export type ExtensionElement = {
|
|
|
80
97
|
render: (
|
|
81
98
|
props: Record<string, unknown>,
|
|
82
99
|
ctx: ExtensionRenderContext,
|
|
83
|
-
) =>
|
|
100
|
+
) => ExtensionOutputNode | readonly ExtensionOutputNode[];
|
|
84
101
|
};
|
|
85
102
|
|
|
86
103
|
/**
|
|
@@ -118,6 +135,32 @@ export type EmVBExtension = {
|
|
|
118
135
|
elements?: readonly ExtensionElement[];
|
|
119
136
|
panels?: readonly ExtensionPanel[];
|
|
120
137
|
sources?: readonly ExtensionSource[];
|
|
138
|
+
/**
|
|
139
|
+
* W-1086: the module that exports this extension, as `import.meta.url`. EmVB bundles it into
|
|
140
|
+
* the site's server build (Cloudflare Workers and production builds included), and resolves
|
|
141
|
+
* `css` and `runtime` against it at build time.
|
|
142
|
+
*/
|
|
143
|
+
module?: string;
|
|
144
|
+
/** W-1086: class names render() may put on its nodes through `extClasses`. */
|
|
145
|
+
classes?: ExtensionClasses;
|
|
146
|
+
/**
|
|
147
|
+
* W-1086: a stylesheet in the extension's own package, relative to `module` (`"./hello.css"`).
|
|
148
|
+
* Read once at build time; written on pages (and in the editor canvas) that render one of the
|
|
149
|
+
* extension's elements.
|
|
150
|
+
*/
|
|
151
|
+
css?: string;
|
|
152
|
+
/**
|
|
153
|
+
* W-1086: a self-contained browser script in the extension's own package, relative to
|
|
154
|
+
* `module` (`"./runtime.js"`): no `import` or `export`. Read once at build time; loaded only on
|
|
155
|
+
* public pages that render one of the extension's elements, never in the admin.
|
|
156
|
+
*/
|
|
157
|
+
runtime?: string;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** W-1086: the file contents EmVB read at build time for `css` and `runtime`. */
|
|
161
|
+
export type ExtensionAssets = {
|
|
162
|
+
css?: string;
|
|
163
|
+
runtime?: string;
|
|
121
164
|
};
|
|
122
165
|
|
|
123
166
|
/**
|
|
@@ -156,4 +199,8 @@ export type ExtensionManifest = {
|
|
|
156
199
|
elements: readonly ExtensionElementManifest[];
|
|
157
200
|
panels: readonly ExtensionPanelManifest[];
|
|
158
201
|
sources: readonly ExtensionSourceManifest[];
|
|
202
|
+
/** W-1086: the checked class allowlist; absent when the extension declares none. */
|
|
203
|
+
classes?: ExtensionClasses;
|
|
204
|
+
/** W-1086: stylesheet and runtime text read at build time; absent when there are none. */
|
|
205
|
+
assets?: ExtensionAssets;
|
|
159
206
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1072: custom font files. EmDash's media library (1.4 and 1.5) refuses `font/woff2` uploads
|
|
3
|
+
* (its default upload allowlist has images, video, audio and PDF only), so EmVB keeps font files
|
|
4
|
+
* in its own plugin storage and serves them from a public route with a long cache.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The largest font file EmVB stores: 1 MiB. Base64 in a plugin storage row, that stays under
|
|
9
|
+
* Cloudflare D1's 2 MB row limit. A Latin WOFF2 is usually 15 to 150 KB.
|
|
10
|
+
*/
|
|
11
|
+
export const FONT_MAX_BYTES = 1024 * 1024;
|
|
12
|
+
|
|
13
|
+
/** The most font files a site keeps (uploads and Google downloads together). */
|
|
14
|
+
export const FONT_FILE_LIMIT = 300;
|
|
15
|
+
|
|
16
|
+
/** A stored font file's id: the first 16 hex digits of the SHA-256 of its bytes. */
|
|
17
|
+
export const FONT_ID = /^[0-9a-f]{16}$/;
|
|
18
|
+
|
|
19
|
+
/** The public URL a stored font file is served from (the plugin id is `emvb`). */
|
|
20
|
+
export const fontFileUrl = (id: string) => `/_emdash/api/plugins/emvb/font?id=${id}`;
|
|
21
|
+
|
|
22
|
+
const WOFF2_HEADER_BYTES = 48;
|
|
23
|
+
/** sfnt flavours: TrueType (0x00010000), CFF (`OTTO`) and collections (`ttcf`). */
|
|
24
|
+
const FLAVORS = new Set([0x00010000, 0x4f54544f, 0x74746366]);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A real WOFF2 file: the `wOF2` signature, a known sfnt flavour, and a header length that matches
|
|
28
|
+
* the file. Anything else (a renamed TTF, an HTML error page, a truncated download) is refused.
|
|
29
|
+
*/
|
|
30
|
+
export function isWoff2(bytes: Uint8Array): boolean {
|
|
31
|
+
if (bytes.byteLength < WOFF2_HEADER_BYTES) return false;
|
|
32
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
33
|
+
return (
|
|
34
|
+
view.getUint32(0) === 0x774f4632 &&
|
|
35
|
+
FLAVORS.has(view.getUint32(4)) &&
|
|
36
|
+
view.getUint32(8) === bytes.byteLength
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Why a font file is refused, or undefined when it can be stored. */
|
|
41
|
+
export function fontFileProblem(bytes: Uint8Array): string | undefined {
|
|
42
|
+
if (bytes.byteLength > FONT_MAX_BYTES) {
|
|
43
|
+
return `This font is ${Math.ceil(bytes.byteLength / 1024)} KB. Use a WOFF2 file up to ${FONT_MAX_BYTES / 1024} KB.`;
|
|
44
|
+
}
|
|
45
|
+
if (!isWoff2(bytes)) return "This isn't a WOFF2 font file. Convert the font to WOFF2 first.";
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The id a font file is stored under (content-addressed, so the same file is stored once). */
|
|
50
|
+
export async function fontFileId(bytes: Uint8Array): Promise<string> {
|
|
51
|
+
const digest = await crypto.subtle.digest("SHA-256", new Uint8Array(bytes));
|
|
52
|
+
return [...new Uint8Array(digest).slice(0, 8)]
|
|
53
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
54
|
+
.join("");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const CHUNK = 0x8000;
|
|
58
|
+
|
|
59
|
+
export function bytesToBase64(bytes: Uint8Array): string {
|
|
60
|
+
let binary = "";
|
|
61
|
+
for (let i = 0; i < bytes.byteLength; i += CHUNK) {
|
|
62
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
|
|
63
|
+
}
|
|
64
|
+
return btoa(binary);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The bytes of a base64 string, or undefined when it isn't base64. */
|
|
68
|
+
export function base64ToBytes(text: string): Uint8Array | undefined {
|
|
69
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(text) || text.length % 4 !== 0) return undefined;
|
|
70
|
+
const binary = atob(text);
|
|
71
|
+
const bytes = new Uint8Array(binary.length);
|
|
72
|
+
for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
|
|
73
|
+
return bytes;
|
|
74
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1072: Google fonts, self-hosted. The server asks Google's CSS API for one family, weight and
|
|
3
|
+
* style, downloads the WOFF2 files it lists and stores them like uploads, so public pages only
|
|
4
|
+
* load the site's own URLs. Google Fonts are under the SIL Open Font License (a few under Apache
|
|
5
|
+
* 2.0 or the Ubuntu Font Licence), which allow self-hosting.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const GOOGLE_CSS_HOST = "fonts.googleapis.com";
|
|
9
|
+
export const GOOGLE_FILE_HOST = "fonts.gstatic.com";
|
|
10
|
+
|
|
11
|
+
/** Google family names: Latin letters, digits and single spaces ("Open Sans", "Noto Sans JP"). */
|
|
12
|
+
export const GOOGLE_FAMILY = /^[A-Za-z0-9](?:[A-Za-z0-9]| (?=[A-Za-z0-9])){0,59}$/;
|
|
13
|
+
|
|
14
|
+
/** Subset labels as the CSS API writes them in its comments ("latin-ext", "[12]"). */
|
|
15
|
+
export const GOOGLE_SUBSET = /^(?:[a-z0-9-]{1,30}|\[\d{1,3}\])$/;
|
|
16
|
+
|
|
17
|
+
/** The subsets a new import downloads unless the editor picks others. */
|
|
18
|
+
export const DEFAULT_GOOGLE_SUBSETS = ["latin", "latin-ext"] as const;
|
|
19
|
+
|
|
20
|
+
/** The most files one weight and style may bring (one per subset). */
|
|
21
|
+
export const GOOGLE_FILES_PER_FACE = 12;
|
|
22
|
+
|
|
23
|
+
export const GOOGLE_WEIGHTS = [100, 200, 300, 400, 500, 600, 700, 800, 900] as const;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A modern browser's User-Agent: the CSS API picks the file format from it, and only answers
|
|
27
|
+
* WOFF2 to browsers it knows support it.
|
|
28
|
+
*/
|
|
29
|
+
export const GOOGLE_USER_AGENT =
|
|
30
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
|
|
31
|
+
|
|
32
|
+
/** The CSS API URL for one family, weight and style. */
|
|
33
|
+
export function googleCssUrl(family: string, weight: number, style: "normal" | "italic"): string {
|
|
34
|
+
const name = family.replace(/ /g, "+");
|
|
35
|
+
const axes = style === "italic" ? `ital,wght@1,${weight}` : `wght@${weight}`;
|
|
36
|
+
return `https://${GOOGLE_CSS_HOST}/css2?family=${name}:${axes}&display=swap`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type GoogleFace = {
|
|
40
|
+
style: "normal" | "italic";
|
|
41
|
+
weight: number;
|
|
42
|
+
/** A fonts.gstatic.com HTTPS URL. */
|
|
43
|
+
url: string;
|
|
44
|
+
unicodeRange?: string;
|
|
45
|
+
/** The subset label from the comment before the rule, when there is one. */
|
|
46
|
+
subset?: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** A font file URL on fonts.gstatic.com over HTTPS, with no credentials or port, or undefined. */
|
|
50
|
+
export function googleFileUrl(raw: string): string | undefined {
|
|
51
|
+
let url: URL;
|
|
52
|
+
try {
|
|
53
|
+
url = new URL(raw);
|
|
54
|
+
} catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
if (url.protocol !== "https:" || url.hostname !== GOOGLE_FILE_HOST) return undefined;
|
|
58
|
+
if (url.port || url.username || url.password) return undefined;
|
|
59
|
+
return url.href;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const UNICODE_RANGE_VALUE =
|
|
63
|
+
/^U\+[0-9A-Fa-f?]{1,6}(?:-[0-9A-Fa-f]{1,6})?(?:, ?U\+[0-9A-Fa-f?]{1,6}(?:-[0-9A-Fa-f]{1,6})?)*$/;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The WOFF2 faces in a CSS API answer. Rules that don't read as expected (another format, another
|
|
67
|
+
* host, a weight range) are skipped, never guessed at.
|
|
68
|
+
*/
|
|
69
|
+
export function parseGoogleFontCss(css: string): GoogleFace[] {
|
|
70
|
+
const faces: GoogleFace[] = [];
|
|
71
|
+
const rule = /(?:\/\*\s*([^*]{1,40}?)\s*\*\/\s*)?@font-face\s*\{([^{}]{1,2000})\}/g;
|
|
72
|
+
for (const match of css.matchAll(rule)) {
|
|
73
|
+
const label = match[1]?.trim();
|
|
74
|
+
const body = match[2] ?? "";
|
|
75
|
+
const style = /(?:^|;)\s*font-style:\s*(normal|italic)\s*(?:;|$)/.exec(body)?.[1];
|
|
76
|
+
const weight = /(?:^|;)\s*font-weight:\s*(\d{1,4})\s*(?:;|$)/.exec(body)?.[1];
|
|
77
|
+
const src =
|
|
78
|
+
/(?:^|;)\s*src:\s*url\(([^()\s'"]{1,500})\)\s*format\(['"]woff2['"]\)\s*(?:;|$)/.exec(
|
|
79
|
+
body,
|
|
80
|
+
)?.[1];
|
|
81
|
+
const range = /(?:^|;)\s*unicode-range:\s*([^;]{1,1000}?)\s*(?:;|$)/.exec(body)?.[1];
|
|
82
|
+
if (!style || !weight || !src) continue;
|
|
83
|
+
const url = googleFileUrl(src);
|
|
84
|
+
const n = Number(weight);
|
|
85
|
+
if (!url || n < 1 || n > 1000) continue;
|
|
86
|
+
if (range !== undefined && !UNICODE_RANGE_VALUE.test(range)) continue;
|
|
87
|
+
faces.push({
|
|
88
|
+
style: style === "italic" ? "italic" : "normal",
|
|
89
|
+
weight: n,
|
|
90
|
+
url,
|
|
91
|
+
...(range !== undefined ? { unicodeRange: range } : {}),
|
|
92
|
+
...(label && GOOGLE_SUBSET.test(label) ? { subset: label } : {}),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return faces;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The faces of one import: the requested weight and style, in the chosen subsets. A rule without
|
|
100
|
+
* a subset label is kept (an answer with a single file has none).
|
|
101
|
+
*/
|
|
102
|
+
export function pickGoogleFaces(
|
|
103
|
+
faces: readonly GoogleFace[],
|
|
104
|
+
wanted: { weight: number; style: "normal" | "italic"; subsets: readonly string[] },
|
|
105
|
+
): GoogleFace[] {
|
|
106
|
+
return faces.filter(
|
|
107
|
+
(face) =>
|
|
108
|
+
face.weight === wanted.weight &&
|
|
109
|
+
face.style === wanted.style &&
|
|
110
|
+
(face.subset === undefined || wanted.subsets.includes(face.subset)),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A minimal byte string that passes the WOFF2 header check (tests only). */
|
|
2
|
+
export function fakeWoff2(size = 64, fill = 0): Uint8Array {
|
|
3
|
+
const bytes = new Uint8Array(size).fill(fill);
|
|
4
|
+
const view = new DataView(bytes.buffer);
|
|
5
|
+
view.setUint32(0, 0x774f4632);
|
|
6
|
+
view.setUint32(4, 0x00010000);
|
|
7
|
+
view.setUint32(8, size);
|
|
8
|
+
return bytes;
|
|
9
|
+
}
|
|
@@ -87,6 +87,8 @@ const DEFAULT_TYPOGRAPHY: Record<string, GlobalTypography> = {
|
|
|
87
87
|
|
|
88
88
|
/** Old-site images listed for copying; an export with more lists the first ones. */
|
|
89
89
|
const MAX_IMAGES = 300;
|
|
90
|
+
/** The longest old-site address (`https://old.example/blog`) looked for before `/wp-content/`. */
|
|
91
|
+
const MAX_SITE_URL = 512;
|
|
90
92
|
|
|
91
93
|
/** Notes kept per import; the rest are counted into one line. */
|
|
92
94
|
const MAX_NOTES = 300;
|
|
@@ -213,16 +215,23 @@ export class ImportContext {
|
|
|
213
215
|
*/
|
|
214
216
|
findOldSite(text: string): void {
|
|
215
217
|
const found = new Map<string, URL>();
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
218
|
+
// W-1074: only the text just before each `/wp-content/` is searched, so input full of
|
|
219
|
+
// addresses that never reach one (`http://http://…`) reads in linear time, not quadratic.
|
|
220
|
+
const marker = "/wp-content/";
|
|
221
|
+
let at = 0;
|
|
222
|
+
for (let hits = 0; hits < 200 && found.size < 5; hits++) {
|
|
223
|
+
const hit = text.indexOf(marker, at);
|
|
224
|
+
if (hit === -1) break;
|
|
225
|
+
at = hit + marker.length;
|
|
226
|
+
const window = text.slice(Math.max(0, hit - MAX_SITE_URL), hit + marker.length);
|
|
227
|
+
const match = /https?:\/\/[^"'<>\s/\\]+(?:\/[^"'<>/\\]*)*?(?=\/wp-content\/$)/i.exec(window);
|
|
228
|
+
if (!match) continue;
|
|
219
229
|
try {
|
|
220
230
|
const url = new URL(match[0]);
|
|
221
231
|
found.set(url.href.toLowerCase(), url);
|
|
222
232
|
} catch {
|
|
223
233
|
// Not an address: ignore it.
|
|
224
234
|
}
|
|
225
|
-
if (found.size >= 5) break;
|
|
226
235
|
}
|
|
227
236
|
this.oldSites = [...found.values()];
|
|
228
237
|
}
|
|
@@ -911,32 +911,43 @@ export function importElementor(input: unknown, options: ImportOptions = {}): El
|
|
|
911
911
|
});
|
|
912
912
|
if (pageStyle.devices) root["devices"] = pageStyle.devices;
|
|
913
913
|
if (options.media) pointAtCopies(root, ctx);
|
|
914
|
+
const checked = validImport(root, ctx);
|
|
915
|
+
if (!checked.ok) return checked;
|
|
916
|
+
const partType = source.type ? PART_TYPES[source.type] : undefined;
|
|
917
|
+
return {
|
|
918
|
+
ok: true,
|
|
919
|
+
layout: checked.layout,
|
|
920
|
+
...(source.title ? { title: source.title } : {}),
|
|
921
|
+
...(partType ? { partType } : {}),
|
|
922
|
+
elements: ctx.elements,
|
|
923
|
+
mapped: ctx.mapped,
|
|
924
|
+
notes: ctx.report(),
|
|
925
|
+
fonts: [...ctx.fonts].toSorted(),
|
|
926
|
+
svgFiles: [...ctx.svgFiles],
|
|
927
|
+
pageLinks: [...ctx.pageLinks].toSorted((a, b) => a - b),
|
|
928
|
+
menus: [...ctx.menus].toSorted(),
|
|
929
|
+
images: [...ctx.images],
|
|
930
|
+
classes: usedClasses(checked.layout, ctx).map((cls) =>
|
|
931
|
+
options.media ? (pointAtCopies(structuredClone(cls), ctx) as StyleClass) : cls,
|
|
932
|
+
),
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* The imported tree as a layout EmVB accepts: whatever validation or the nesting rules refuse is
|
|
938
|
+
* pruned (and noted) until it passes. Shared with the HTML import (W-1074).
|
|
939
|
+
*/
|
|
940
|
+
export function validImport(
|
|
941
|
+
root: N,
|
|
942
|
+
ctx: ImportContext,
|
|
943
|
+
): { ok: true; layout: Layout } | { ok: false; error: string } {
|
|
914
944
|
const candidate: Record<string, unknown> = { schemaVersion: LAYOUT_SCHEMA_VERSION, root };
|
|
915
945
|
const tried = new Set<string>();
|
|
916
946
|
for (let attempt = 0; attempt < 500; attempt++) {
|
|
917
947
|
const checked = validateLayout(candidate);
|
|
918
948
|
// The save hook also refuses misplaced elements (a field outside a form, …): prune those too.
|
|
919
949
|
const misplaced = checked.ok ? nestingIssues(checked.layout, 1)[0] : undefined;
|
|
920
|
-
if (checked.ok && !misplaced) {
|
|
921
|
-
const partType = source.type ? PART_TYPES[source.type] : undefined;
|
|
922
|
-
return {
|
|
923
|
-
ok: true,
|
|
924
|
-
layout: checked.layout,
|
|
925
|
-
...(source.title ? { title: source.title } : {}),
|
|
926
|
-
...(partType ? { partType } : {}),
|
|
927
|
-
elements: ctx.elements,
|
|
928
|
-
mapped: ctx.mapped,
|
|
929
|
-
notes: ctx.report(),
|
|
930
|
-
fonts: [...ctx.fonts].toSorted(),
|
|
931
|
-
svgFiles: [...ctx.svgFiles],
|
|
932
|
-
pageLinks: [...ctx.pageLinks].toSorted((a, b) => a - b),
|
|
933
|
-
menus: [...ctx.menus].toSorted(),
|
|
934
|
-
images: [...ctx.images],
|
|
935
|
-
classes: usedClasses(checked.layout, ctx).map((cls) =>
|
|
936
|
-
options.media ? (pointAtCopies(structuredClone(cls), ctx) as StyleClass) : cls,
|
|
937
|
-
),
|
|
938
|
-
};
|
|
939
|
-
}
|
|
950
|
+
if (checked.ok && !misplaced) return { ok: true, layout: checked.layout };
|
|
940
951
|
const issue = checked.ok ? misplaced : checked.issues[0];
|
|
941
952
|
if (!issue || !prune(root, issue, ctx, tried)) {
|
|
942
953
|
return {
|
|
@@ -952,7 +963,7 @@ export function importElementor(input: unknown, options: ImportOptions = {}): El
|
|
|
952
963
|
* W-958: points every use of an old-site image at its media library copy: image sources (which
|
|
953
964
|
* also get the library id), backgrounds and any other stored address equal to it.
|
|
954
965
|
*/
|
|
955
|
-
function pointAtCopies(value: unknown, ctx: ImportContext): unknown {
|
|
966
|
+
export function pointAtCopies(value: unknown, ctx: ImportContext): unknown {
|
|
956
967
|
if (typeof value === "string")
|
|
957
968
|
return /^https?:\/\//i.test(value) ? (ctx.copied(value)?.url ?? value) : value;
|
|
958
969
|
if (Array.isArray(value)) {
|