nuxt-og-image 1.4.8 → 1.4.10
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
CHANGED
|
@@ -34,6 +34,7 @@ Enlightened OG Image generation for Nuxt 3.
|
|
|
34
34
|
## Demos
|
|
35
35
|
|
|
36
36
|
- [Vercel Edge Demo](https://nuxt-og-image-playground.vercel.app/)
|
|
37
|
+
- [StackBlitz - Minimal Example](https://stackblitz.com/edit/nuxt-starter-pxs3wk?file=pages/index.vue)
|
|
37
38
|
- [StackBlitz - Alpine Theme](https://stackblitz.com/edit/github-hgunsf?file=package.json) (visit `/__og_image__`)
|
|
38
39
|
|
|
39
40
|
## Features
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -339,38 +339,48 @@ export {}
|
|
|
339
339
|
nitroConfig.externals = defu(nitroConfig.externals || {}, {
|
|
340
340
|
inline: [runtimeDir]
|
|
341
341
|
});
|
|
342
|
+
if (config.experimentalRuntimeBrowser) {
|
|
343
|
+
nitroConfig.alias = nitroConfig.alias || {};
|
|
344
|
+
nitroConfig.alias.electron = "unenv/runtime/mock/proxy-cjs";
|
|
345
|
+
nitroConfig.alias.bufferutil = "unenv/runtime/mock/proxy-cjs";
|
|
346
|
+
nitroConfig.alias["utf-8-validate"] = "unenv/runtime/mock/proxy-cjs";
|
|
347
|
+
}
|
|
342
348
|
nitroConfig.publicAssets = nitroConfig.publicAssets || [];
|
|
343
349
|
nitroConfig.publicAssets.push({ dir: moduleAssetDir, maxAge: 31536e3 });
|
|
344
350
|
const providerPath = `${runtimeDir}/nitro/providers`;
|
|
345
351
|
if (config.browserProvider) {
|
|
346
|
-
nitroConfig.virtual["#nuxt-og-image/browser"] = config.experimentalRuntimeBrowser ? `
|
|
347
|
-
|
|
352
|
+
nitroConfig.virtual["#nuxt-og-image/browser"] = nuxt.options.dev || config.experimentalRuntimeBrowser ? `
|
|
353
|
+
import node from '${providerPath}/browser/node'
|
|
354
|
+
|
|
355
|
+
export default async function() {
|
|
356
|
+
return node
|
|
348
357
|
}
|
|
349
358
|
` : `export default async function() {
|
|
350
|
-
return (
|
|
359
|
+
return () => {}
|
|
351
360
|
}
|
|
352
361
|
`;
|
|
353
362
|
}
|
|
354
363
|
if (config.satoriProvider) {
|
|
355
|
-
nitroConfig.virtual["#nuxt-og-image/satori"] = isWebWorkerEnv ?
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return await import('${providerPath}/svg2png/universal').then(m => m.default)
|
|
364
|
+
nitroConfig.virtual["#nuxt-og-image/satori"] = `import webworker from '${providerPath}/satori/${isWebWorkerEnv ? "webworker" : "node"}'
|
|
365
|
+
export default async function() {
|
|
366
|
+
return webworker
|
|
367
|
+
}`;
|
|
368
|
+
nitroConfig.virtual["#nuxt-og-image/svg2png"] = `
|
|
369
|
+
import svg2png from '${providerPath}/svg2png/universal'
|
|
370
|
+
export default async function() {
|
|
371
|
+
return svg2png
|
|
364
372
|
}`;
|
|
365
373
|
}
|
|
366
374
|
nitroConfig.virtual["#nuxt-og-image/provider"] = `
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
375
|
+
import satori from '${relative(nuxt.options.rootDir, resolve("./runtime/nitro/renderers/satori"))}'
|
|
376
|
+
import browser from '${relative(nuxt.options.rootDir, resolve("./runtime/nitro/renderers/browser"))}'
|
|
377
|
+
|
|
378
|
+
export async function useProvider(provider) {
|
|
379
|
+
if (provider === 'satori')
|
|
380
|
+
return satori
|
|
381
|
+
if (provider === 'browser')
|
|
382
|
+
return browser
|
|
383
|
+
}
|
|
374
384
|
`;
|
|
375
385
|
});
|
|
376
386
|
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
@@ -10,6 +10,12 @@ import { fonts, satoriOptions } from "#nuxt-og-image/config";
|
|
|
10
10
|
import loadSvg2png from "#nuxt-og-image/svg2png";
|
|
11
11
|
import loadSatori from "#nuxt-og-image/satori";
|
|
12
12
|
const satoriFonts = [];
|
|
13
|
+
let fontLoadPromise = null;
|
|
14
|
+
function loadFonts(fonts2) {
|
|
15
|
+
if (fontLoadPromise)
|
|
16
|
+
return fontLoadPromise;
|
|
17
|
+
return fontLoadPromise = Promise.all(fonts2.map((font) => loadFont(font)));
|
|
18
|
+
}
|
|
13
19
|
export default {
|
|
14
20
|
name: "satori",
|
|
15
21
|
createPng: async function createPng(baseUrl, options) {
|
|
@@ -39,10 +45,8 @@ export default {
|
|
|
39
45
|
},
|
|
40
46
|
createSvg: async function createSvg(baseUrl, options) {
|
|
41
47
|
const vnodes = await this.createVNode(baseUrl, options);
|
|
42
|
-
if (!satoriFonts.length)
|
|
43
|
-
|
|
44
|
-
satoriFonts.push(await loadFont(new URL(baseUrl), font));
|
|
45
|
-
}
|
|
48
|
+
if (!satoriFonts.length)
|
|
49
|
+
satoriFonts.push(...await loadFonts(fonts));
|
|
46
50
|
const satori = await loadSatori();
|
|
47
51
|
return await satori(vnodes, {
|
|
48
52
|
...satoriOptions,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ParsedURL } from 'ufo';
|
|
2
2
|
import type { SatoriTransformer, VNode } from '../../../../types';
|
|
3
|
-
export declare function loadFont(
|
|
3
|
+
export declare function loadFont(font: string): Promise<any>;
|
|
4
4
|
export declare function walkSatoriTree(url: ParsedURL, node: VNode, plugins: SatoriTransformer[]): Promise<void>;
|
|
5
5
|
export declare function defineSatoriTransformer(transformer: (url: ParsedURL) => SatoriTransformer): (url: ParsedURL) => SatoriTransformer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { base64ToArrayBuffer, readPublicAsset } from "../../utils.mjs";
|
|
2
2
|
import { useStorage } from "#internal/nitro";
|
|
3
3
|
const cachedFonts = {};
|
|
4
|
-
export async function loadFont(
|
|
4
|
+
export async function loadFont(font) {
|
|
5
5
|
if (cachedFonts[font])
|
|
6
6
|
return cachedFonts[font];
|
|
7
7
|
let data;
|
|
@@ -14,7 +14,7 @@ export async function loadFont(url, font) {
|
|
|
14
14
|
if (name === "Inter" && ["400", "700"].includes(weight)) {
|
|
15
15
|
const data2 = await readPublicAsset(`/inter-latin-ext-${weight}-normal.woff`);
|
|
16
16
|
if (data2)
|
|
17
|
-
return cachedFonts[font] = { name:
|
|
17
|
+
return cachedFonts[font] = { name, weight: Number(weight), data: data2, style: "normal" };
|
|
18
18
|
}
|
|
19
19
|
if (!data) {
|
|
20
20
|
const fontUrl = await globalThis.$fetch("/api/og-image-font", {
|
|
@@ -25,7 +25,7 @@ export async function loadFont(url, font) {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
await useStorage().setItem(storageKey, Buffer.from(data).toString("base64"));
|
|
28
|
-
return cachedFonts[font] = { name, weight, data, style: "normal" };
|
|
28
|
+
return cachedFonts[font] = { name, weight: Number(weight), data, style: "normal" };
|
|
29
29
|
}
|
|
30
30
|
export async function walkSatoriTree(url, node, plugins) {
|
|
31
31
|
if (!node.props?.children)
|