@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
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { pluginResponse, PluginRouteError, type PluginRoute, type RouteContext } from "emdash";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
base64ToBytes,
|
|
5
|
+
bytesToBase64,
|
|
6
|
+
DEFAULT_GOOGLE_SUBSETS,
|
|
7
|
+
FONT_FILE_LIMIT,
|
|
8
|
+
FONT_ID,
|
|
9
|
+
FONT_MAX_BYTES,
|
|
10
|
+
fontFileId,
|
|
11
|
+
fontFileProblem,
|
|
12
|
+
fontFileUrl,
|
|
13
|
+
GOOGLE_CSS_HOST,
|
|
14
|
+
GOOGLE_FAMILY,
|
|
15
|
+
GOOGLE_FILE_HOST,
|
|
16
|
+
GOOGLE_FILES_PER_FACE,
|
|
17
|
+
GOOGLE_SUBSET,
|
|
18
|
+
GOOGLE_USER_AGENT,
|
|
19
|
+
googleCssUrl,
|
|
20
|
+
parseGoogleFontCss,
|
|
21
|
+
pickGoogleFaces,
|
|
22
|
+
type FontFace,
|
|
23
|
+
} from "../core/index.ts";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Custom fonts (W-1072). EmDash's media library refuses `font/woff2` on 1.4 and 1.5, so font
|
|
27
|
+
* files live in EmVB's plugin storage (as W-239 keeps uploaded SVG icons) and the public `font`
|
|
28
|
+
* route serves them with their real type and a year-long immutable cache: a file's id is the hash
|
|
29
|
+
* of its bytes, so a URL never changes what it serves.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export type StoredFont = {
|
|
33
|
+
name: string;
|
|
34
|
+
size: number;
|
|
35
|
+
/** The WOFF2 file, base64. */
|
|
36
|
+
data: string;
|
|
37
|
+
uploadedAt: string;
|
|
38
|
+
source: "upload" | "google";
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type FontStore = {
|
|
42
|
+
get(id: string): Promise<StoredFont | null>;
|
|
43
|
+
put(id: string, data: StoredFont): Promise<void>;
|
|
44
|
+
exists(id: string): Promise<boolean>;
|
|
45
|
+
count(): Promise<number>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const store = (ctx: RouteContext<unknown>) => ctx.storage["fonts"] as unknown as FontStore;
|
|
49
|
+
|
|
50
|
+
/** A file name as a label: no folder, control characters or direction marks, at most 80. */
|
|
51
|
+
const fileLabel = (name: string) =>
|
|
52
|
+
Array.from(name.replace(/^.*[\\/]/, ""), (ch) => (ch.charCodeAt(0) < 32 ? " " : ch))
|
|
53
|
+
.join("")
|
|
54
|
+
.replace(/[\u007F-\u009F---]/g, "")
|
|
55
|
+
.trim()
|
|
56
|
+
.slice(0, 80) || "Font";
|
|
57
|
+
|
|
58
|
+
/** Stores a checked font file once (content-addressed) and answers its id and URL. */
|
|
59
|
+
async function storeFontFile(
|
|
60
|
+
files: FontStore,
|
|
61
|
+
bytes: Uint8Array,
|
|
62
|
+
meta: { name: string; source: StoredFont["source"] },
|
|
63
|
+
): Promise<{ id: string; url: string; duplicate: boolean }> {
|
|
64
|
+
const problem = fontFileProblem(bytes);
|
|
65
|
+
if (problem) throw new PluginRouteError("INVALID_FONT", problem, 422);
|
|
66
|
+
const id = await fontFileId(bytes);
|
|
67
|
+
if (await files.exists(id)) return { id, url: fontFileUrl(id), duplicate: true };
|
|
68
|
+
if ((await files.count()) >= FONT_FILE_LIMIT) {
|
|
69
|
+
throw new PluginRouteError(
|
|
70
|
+
"FONTS_FULL",
|
|
71
|
+
`This site keeps up to ${FONT_FILE_LIMIT} font files.`,
|
|
72
|
+
409,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
await files.put(id, {
|
|
76
|
+
name: fileLabel(meta.name),
|
|
77
|
+
size: bytes.byteLength,
|
|
78
|
+
data: bytesToBase64(bytes),
|
|
79
|
+
uploadedAt: new Date().toISOString(),
|
|
80
|
+
source: meta.source,
|
|
81
|
+
});
|
|
82
|
+
return { id, url: fontFileUrl(id), duplicate: false };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const missing = () => new PluginRouteError("NOT_FOUND", "No such font.", 404);
|
|
86
|
+
|
|
87
|
+
/** Anyone: one stored font file, as `font/woff2`, cached for a year. */
|
|
88
|
+
export const fontRoute: PluginRoute = {
|
|
89
|
+
public: true,
|
|
90
|
+
methods: ["GET", "HEAD"],
|
|
91
|
+
response: "raw",
|
|
92
|
+
cacheControl: "public, max-age=31536000, immutable",
|
|
93
|
+
handler: async (ctx) => {
|
|
94
|
+
const id = (ctx.input as { id?: unknown } | undefined)?.id;
|
|
95
|
+
if (typeof id !== "string" || !FONT_ID.test(id)) throw missing();
|
|
96
|
+
const row = await store(ctx).get(id);
|
|
97
|
+
const bytes = typeof row?.data === "string" ? base64ToBytes(row.data) : undefined;
|
|
98
|
+
// A row written past the upload route is served only if it is still a real WOFF2.
|
|
99
|
+
if (!bytes || fontFileProblem(bytes)) throw missing();
|
|
100
|
+
return pluginResponse({
|
|
101
|
+
status: 200,
|
|
102
|
+
headers: { "content-type": "font/woff2", etag: `"${id}"` },
|
|
103
|
+
body: { kind: "bytes", value: bytes },
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const UploadInput = z.object({
|
|
109
|
+
name: z.string().max(255),
|
|
110
|
+
data: z
|
|
111
|
+
.string()
|
|
112
|
+
.min(1)
|
|
113
|
+
.max(Math.ceil(FONT_MAX_BYTES / 3) * 4),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/** Editors and above: stores an uploaded WOFF2 after checking it again on the server. */
|
|
117
|
+
export const fontUploadRoute: PluginRoute<z.infer<typeof UploadInput>> = {
|
|
118
|
+
permission: "content:edit_any",
|
|
119
|
+
input: UploadInput,
|
|
120
|
+
// The default JSON limit is 1 MiB; a 1 MiB font is about 1.4 MB as base64.
|
|
121
|
+
request: { body: "json", maxBytes: 1_600_000 },
|
|
122
|
+
handler: async (ctx) => {
|
|
123
|
+
const bytes = base64ToBytes(ctx.input.data);
|
|
124
|
+
if (!bytes) throw new PluginRouteError("INVALID_FONT", "The file didn't arrive whole.", 422);
|
|
125
|
+
const file = await storeFontFile(store(ctx), bytes, {
|
|
126
|
+
name: ctx.input.name,
|
|
127
|
+
source: "upload",
|
|
128
|
+
});
|
|
129
|
+
return { file };
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const GoogleInput = z.object({
|
|
134
|
+
family: z.string().regex(GOOGLE_FAMILY, "Type a Google Fonts family name, such as Open Sans"),
|
|
135
|
+
weight: z.number().int().min(100).max(900).multipleOf(100),
|
|
136
|
+
style: z.enum(["normal", "italic"]),
|
|
137
|
+
subsets: z.array(z.string().regex(GOOGLE_SUBSET)).min(1).max(12).optional(),
|
|
138
|
+
});
|
|
139
|
+
type GoogleInput = z.infer<typeof GoogleInput>;
|
|
140
|
+
|
|
141
|
+
type Fetch = (url: string, init: RequestInit) => Promise<Response>;
|
|
142
|
+
|
|
143
|
+
const CSS_MAX_BYTES = 256 * 1024;
|
|
144
|
+
const TIMEOUT_MS = 20_000;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* GET from Google's two font hosts only. Redirects are not followed (a redirect could leave
|
|
148
|
+
* those hosts), and the body is read up to `maxBytes`.
|
|
149
|
+
*/
|
|
150
|
+
async function googleGet(fetcher: Fetch, url: string, maxBytes: number): Promise<Response> {
|
|
151
|
+
const host = new URL(url).hostname;
|
|
152
|
+
if (host !== GOOGLE_CSS_HOST && host !== GOOGLE_FILE_HOST) {
|
|
153
|
+
throw new PluginRouteError("GOOGLE_FONTS", "Fonts are only downloaded from Google.", 502);
|
|
154
|
+
}
|
|
155
|
+
let response: Response;
|
|
156
|
+
try {
|
|
157
|
+
response = await fetcher(url, {
|
|
158
|
+
method: "GET",
|
|
159
|
+
redirect: "manual",
|
|
160
|
+
headers: { "user-agent": GOOGLE_USER_AGENT, accept: "text/css,font/woff2,*/*;q=0.1" },
|
|
161
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
// PluginRouteError's fourth argument is sent to the client, so the cause is set apart.
|
|
165
|
+
const failed = new PluginRouteError(
|
|
166
|
+
"GOOGLE_FONTS",
|
|
167
|
+
"Couldn't reach Google Fonts. Try again.",
|
|
168
|
+
502,
|
|
169
|
+
);
|
|
170
|
+
failed.cause = error;
|
|
171
|
+
throw failed;
|
|
172
|
+
}
|
|
173
|
+
const declared = Number(response.headers.get("content-length"));
|
|
174
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
175
|
+
await response.body?.cancel();
|
|
176
|
+
throw new PluginRouteError("GOOGLE_FONTS", "Google Fonts sent a file that is too large.", 502);
|
|
177
|
+
}
|
|
178
|
+
return response;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The body, refused once it passes `maxBytes` (a missing or wrong Content-Length can't help). */
|
|
182
|
+
async function readCapped(response: Response, maxBytes: number): Promise<Uint8Array> {
|
|
183
|
+
const reader = response.body?.getReader();
|
|
184
|
+
if (!reader) return new Uint8Array();
|
|
185
|
+
const chunks: Uint8Array[] = [];
|
|
186
|
+
let size = 0;
|
|
187
|
+
for (;;) {
|
|
188
|
+
// oxlint-disable-next-line no-await-in-loop -- a stream is read one chunk after another
|
|
189
|
+
const { done, value } = await reader.read();
|
|
190
|
+
if (done) break;
|
|
191
|
+
size += value.byteLength;
|
|
192
|
+
if (size > maxBytes) {
|
|
193
|
+
void reader.cancel().catch(() => undefined);
|
|
194
|
+
throw new PluginRouteError(
|
|
195
|
+
"GOOGLE_FONTS",
|
|
196
|
+
"Google Fonts sent a file that is too large.",
|
|
197
|
+
502,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
chunks.push(value);
|
|
201
|
+
}
|
|
202
|
+
const out = new Uint8Array(size);
|
|
203
|
+
let at = 0;
|
|
204
|
+
for (const chunk of chunks) {
|
|
205
|
+
out.set(chunk, at);
|
|
206
|
+
at += chunk.byteLength;
|
|
207
|
+
}
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Downloads one WOFF2 file from fonts.gstatic.com and stores it; answers its site URL. */
|
|
212
|
+
async function downloadGoogleFile(
|
|
213
|
+
deps: { fetch: Fetch; files: FontStore },
|
|
214
|
+
url: string,
|
|
215
|
+
name: string,
|
|
216
|
+
): Promise<string> {
|
|
217
|
+
const response = await googleGet(deps.fetch, url, FONT_MAX_BYTES);
|
|
218
|
+
if (response.status !== 200) {
|
|
219
|
+
await response.body?.cancel();
|
|
220
|
+
throw new PluginRouteError("GOOGLE_FONTS", "Google Fonts didn't send a font file.", 502);
|
|
221
|
+
}
|
|
222
|
+
const bytes = await readCapped(response, FONT_MAX_BYTES);
|
|
223
|
+
return (await storeFontFile(deps.files, bytes, { name, source: "google" })).url;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Downloads one family, weight and style from Google Fonts and stores its WOFF2 files like
|
|
228
|
+
* uploads. Answers the faces, pointing at the site's own font route.
|
|
229
|
+
*/
|
|
230
|
+
export async function importGoogleFace(
|
|
231
|
+
input: GoogleInput,
|
|
232
|
+
deps: { fetch: Fetch; files: FontStore },
|
|
233
|
+
): Promise<{ family: string; faces: FontFace[] }> {
|
|
234
|
+
const cssResponse = await googleGet(
|
|
235
|
+
deps.fetch,
|
|
236
|
+
googleCssUrl(input.family, input.weight, input.style),
|
|
237
|
+
CSS_MAX_BYTES,
|
|
238
|
+
);
|
|
239
|
+
if (cssResponse.status === 400 || cssResponse.status === 404) {
|
|
240
|
+
await cssResponse.body?.cancel();
|
|
241
|
+
throw new PluginRouteError(
|
|
242
|
+
"GOOGLE_FONT_UNKNOWN",
|
|
243
|
+
`Google Fonts has no "${input.family}" in weight ${input.weight}${input.style === "italic" ? " italic" : ""}.`,
|
|
244
|
+
404,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
const type = cssResponse.headers.get("content-type") ?? "";
|
|
248
|
+
if (cssResponse.status !== 200 || !type.toLowerCase().startsWith("text/css")) {
|
|
249
|
+
await cssResponse.body?.cancel();
|
|
250
|
+
throw new PluginRouteError("GOOGLE_FONTS", "Google Fonts didn't answer. Try again.", 502);
|
|
251
|
+
}
|
|
252
|
+
const css = new TextDecoder().decode(await readCapped(cssResponse, CSS_MAX_BYTES));
|
|
253
|
+
const picked = pickGoogleFaces(parseGoogleFontCss(css), {
|
|
254
|
+
weight: input.weight,
|
|
255
|
+
style: input.style,
|
|
256
|
+
subsets: input.subsets ?? DEFAULT_GOOGLE_SUBSETS,
|
|
257
|
+
});
|
|
258
|
+
if (picked.length === 0) {
|
|
259
|
+
throw new PluginRouteError(
|
|
260
|
+
"GOOGLE_FONT_UNKNOWN",
|
|
261
|
+
`Google Fonts has no WOFF2 file of "${input.family}" for these subsets.`,
|
|
262
|
+
404,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (picked.length > GOOGLE_FILES_PER_FACE) {
|
|
266
|
+
throw new PluginRouteError(
|
|
267
|
+
"GOOGLE_FONTS",
|
|
268
|
+
`"${input.family}" comes in ${picked.length} files per weight. Pick fewer subsets.`,
|
|
269
|
+
422,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
const stored = new Map<string, string>();
|
|
273
|
+
const faces: FontFace[] = [];
|
|
274
|
+
for (const face of picked) {
|
|
275
|
+
let src = stored.get(face.url);
|
|
276
|
+
if (!src) {
|
|
277
|
+
const name = `${input.family} ${input.weight}${input.style === "italic" ? " italic" : ""}${face.subset ? ` ${face.subset}` : ""}.woff2`;
|
|
278
|
+
// oxlint-disable-next-line no-await-in-loop -- one download at a time keeps memory low
|
|
279
|
+
src = await downloadGoogleFile(deps, face.url, name);
|
|
280
|
+
stored.set(face.url, src);
|
|
281
|
+
}
|
|
282
|
+
faces.push({
|
|
283
|
+
weight: face.weight,
|
|
284
|
+
style: face.style,
|
|
285
|
+
src,
|
|
286
|
+
...(face.unicodeRange ? { unicodeRange: face.unicodeRange } : {}),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return { family: input.family, faces };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Editors and above: self-hosts one weight and style of a Google font. */
|
|
293
|
+
export const fontGoogleRoute: PluginRoute<GoogleInput> = {
|
|
294
|
+
permission: "content:edit_any",
|
|
295
|
+
input: GoogleInput,
|
|
296
|
+
handler: async (ctx) =>
|
|
297
|
+
importGoogleFace(ctx.input, {
|
|
298
|
+
fetch: (url, init) => globalThis.fetch(url, init),
|
|
299
|
+
files: store(ctx),
|
|
300
|
+
}),
|
|
301
|
+
};
|
package/src/server/plugin.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
savedSectionsRoute,
|
|
26
26
|
} from "./saved-sections.ts";
|
|
27
27
|
import { iconDeleteRoute, iconRenameRoute, iconUploadRoute, iconsRoute } from "./icon-routes.ts";
|
|
28
|
+
import { fontGoogleRoute, fontRoute, fontUploadRoute } from "./font-routes.ts";
|
|
28
29
|
import { beforeSave } from "./hooks.ts";
|
|
29
30
|
import {
|
|
30
31
|
agentsRoute,
|
|
@@ -33,8 +34,9 @@ import {
|
|
|
33
34
|
pageAgentVersionsRoute,
|
|
34
35
|
} from "./agent-settings.ts";
|
|
35
36
|
import { canvasStyleUrls } from "../core/canvas-styles.ts";
|
|
36
|
-
import { canvasCollectionSlugs } from "../core/canvas-collections.ts";
|
|
37
|
+
import { canvasCollectionSlugs, setCanvasCollections } from "../core/canvas-collections.ts";
|
|
37
38
|
import { manifestsFromOptions } from "../core/extensions/index.ts";
|
|
39
|
+
import { extensionRenderRoute } from "./extension-routes.ts";
|
|
38
40
|
import { TOOLS } from "../mcp/tools.ts";
|
|
39
41
|
import { mcpRoutes, mcpToolConfig } from "./mcp-routes.ts";
|
|
40
42
|
|
|
@@ -55,6 +57,7 @@ export function createPlugin(
|
|
|
55
57
|
) {
|
|
56
58
|
setGeoTrust(options.trustGeoHeaders);
|
|
57
59
|
setLoopCollections(options.loopCollections);
|
|
60
|
+
setCanvasCollections(options.canvasCollections);
|
|
58
61
|
const canvasStyles = canvasStyleUrls(options.canvasStyles);
|
|
59
62
|
const canvasCollections = canvasCollectionSlugs(options.canvasCollections);
|
|
60
63
|
const extensions = manifestsFromOptions(options.extensions);
|
|
@@ -79,6 +82,8 @@ export function createPlugin(
|
|
|
79
82
|
storage: {
|
|
80
83
|
design: { indexes: [] },
|
|
81
84
|
icons: { indexes: ["uploadedAt"] },
|
|
85
|
+
// W-1072: custom font files (EmDash's media library refuses font/woff2).
|
|
86
|
+
fonts: { indexes: ["uploadedAt"] },
|
|
82
87
|
// D-057: agent changes and the site styles history.
|
|
83
88
|
agentlog: { indexes: ["at", "pageId"] },
|
|
84
89
|
designhistory: { indexes: ["at"] },
|
|
@@ -132,6 +137,7 @@ export function createPlugin(
|
|
|
132
137
|
extensions,
|
|
133
138
|
}),
|
|
134
139
|
},
|
|
140
|
+
"editor/extensions/render": extensionRenderRoute,
|
|
135
141
|
design: designRoute,
|
|
136
142
|
"design/draft": designDraftRoute,
|
|
137
143
|
"design/save": designSaveRoute,
|
|
@@ -154,6 +160,10 @@ export function createPlugin(
|
|
|
154
160
|
"icons/upload": iconUploadRoute,
|
|
155
161
|
"icons/rename": iconRenameRoute,
|
|
156
162
|
"icons/delete": iconDeleteRoute,
|
|
163
|
+
// W-1072: custom fonts. `font` is public: pages load the files from it.
|
|
164
|
+
font: fontRoute,
|
|
165
|
+
"fonts/upload": fontUploadRoute,
|
|
166
|
+
"fonts/google": fontGoogleRoute,
|
|
157
167
|
// W-463: the Agents tab (admins only).
|
|
158
168
|
agents: agentsRoute,
|
|
159
169
|
"agents/save": agentsSaveRoute,
|