nuxt-og-image 2.0.0-beta.21 → 2.0.0-beta.22
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 +82 -15
- package/dist/client/200.html +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/IconCSS.779331aa.js +1 -0
- package/dist/client/_nuxt/{ImageLoader.97400b2b.js → ImageLoader.9ed308b0.js} +1 -1
- package/dist/client/_nuxt/{entry.7e98a020.css → entry.acc10163.css} +1 -1
- package/dist/client/_nuxt/entry.e7270163.js +5 -0
- package/dist/client/_nuxt/{error-404.7660b68a.js → error-404.dcc06a80.js} +1 -1
- package/dist/client/_nuxt/{error-500.776f22a1.js → error-500.fb40d400.js} +1 -1
- package/dist/client/_nuxt/{error-component.d4668032.js → error-component.9702a511.js} +2 -2
- package/dist/client/_nuxt/{index.77081a6c.js → index.6a247c9d.js} +1 -1
- package/dist/client/_nuxt/{options.b6164a5b.js → options.481faa9f.js} +1 -1
- package/dist/client/_nuxt/{png.b914f6c4.js → png.7e62d84b.js} +1 -1
- package/dist/client/_nuxt/{shiki.ba10b978.js → shiki.0c927d45.js} +1 -1
- package/dist/client/_nuxt/{svg.1e41877e.js → svg.81bf3f5a.js} +1 -1
- package/dist/client/_nuxt/{vnodes.a857bced.js → vnodes.096af306.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/options/index.html +2 -2
- package/dist/client/png/index.html +2 -2
- package/dist/client/svg/index.html +2 -2
- package/dist/client/vnodes/index.html +2 -2
- package/dist/module.d.ts +15 -5
- package/dist/module.json +1 -1
- package/dist/module.mjs +194 -84
- package/dist/runtime/browserUtil.mjs +5 -3
- package/dist/runtime/composables/defineOgImage.mjs +10 -7
- package/dist/runtime/nitro/middleware/og.png.mjs +43 -15
- package/dist/runtime/nitro/plugins/prerender.mjs +1 -3
- package/dist/runtime/nitro/providers/browser/lambda.d.ts +1 -1
- package/dist/runtime/nitro/providers/browser/lambda.mjs +5 -5
- package/dist/runtime/nitro/providers/browser/playwright.mjs +22 -0
- package/dist/runtime/nitro/providers/browser/universal.d.ts +1 -0
- package/dist/runtime/nitro/providers/png/resvg.d.ts +4 -0
- package/dist/runtime/nitro/providers/png/resvg.mjs +11 -0
- package/dist/runtime/nitro/providers/png/svg2png.mjs +11 -0
- package/dist/runtime/nitro/providers/satori/{webworker.mjs → yoga-wasm.mjs} +4 -5
- package/dist/runtime/nitro/renderers/browser.mjs +7 -6
- package/dist/runtime/nitro/renderers/satori/index.mjs +3 -3
- package/dist/runtime/nitro/routes/debug.d.ts +4 -0
- package/dist/runtime/nitro/routes/debug.mjs +9 -0
- package/dist/runtime/nitro/routes/options.mjs +3 -3
- package/dist/runtime/nitro/utils.d.ts +4 -3
- package/dist/runtime/nitro/utils.mjs +37 -18
- package/dist/runtime/public-assets/__nuxt_og_image__/browser-provider-not-supported.png +0 -0
- package/dist/runtime/public-assets-optional/resvg/resvg.wasm +0 -0
- package/package.json +15 -8
- package/dist/client/_nuxt/IconCSS.ecebf6a5.js +0 -1
- package/dist/client/_nuxt/entry.c8bf4454.js +0 -5
- package/dist/runtime/nitro/providers/svg2png/universal.mjs +0 -12
- /package/dist/runtime/nitro/providers/browser/{node.d.ts → playwright.d.ts} +0 -0
- /package/dist/runtime/nitro/providers/browser/{node.mjs → universal.mjs} +0 -0
- /package/dist/runtime/nitro/providers/{svg2png/universal.d.ts → png/svg2png.d.ts} +0 -0
- /package/dist/runtime/nitro/providers/satori/{node.d.ts → default.d.ts} +0 -0
- /package/dist/runtime/nitro/providers/satori/{node.mjs → default.mjs} +0 -0
- /package/dist/runtime/nitro/providers/satori/{webworker.d.ts → yoga-wasm.d.ts} +0 -0
- /package/dist/runtime/{public-assets → public-assets-optional/inter-font}/inter-latin-ext-400-normal.woff +0 -0
- /package/dist/runtime/{public-assets → public-assets-optional/inter-font}/inter-latin-ext-700-normal.woff +0 -0
- /package/dist/runtime/{public-assets → public-assets-optional/svg2png}/svg2png.wasm +0 -0
- /package/dist/runtime/{public-assets → public-assets-optional/yoga}/yoga.wasm +0 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import satori, { init } from "satori/wasm";
|
|
2
2
|
import initYoga from "yoga-wasm-web";
|
|
3
3
|
import { wasmLoader } from "../../utils.mjs";
|
|
4
|
+
const YogaLoader = wasmLoader("/* NUXT_OG_IMAGE_YOGA_WASM */", "/yoga.wasm");
|
|
4
5
|
export default async function(nodes, options) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
init(yoga);
|
|
9
|
-
}
|
|
6
|
+
const yogaWasm = await YogaLoader.load({ baseUrl: options.baseUrl });
|
|
7
|
+
const yoga = await initYoga(yogaWasm);
|
|
8
|
+
init(yoga);
|
|
10
9
|
return await satori(nodes, options);
|
|
11
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { withBase } from "ufo";
|
|
2
2
|
import { screenshot } from "../../browserUtil.mjs";
|
|
3
|
-
import
|
|
3
|
+
import loadBrowserLauncherChunk from "#nuxt-og-image/browser";
|
|
4
4
|
import { useRuntimeConfig } from "#imports";
|
|
5
5
|
export default {
|
|
6
6
|
name: "browser",
|
|
@@ -12,14 +12,15 @@ export default {
|
|
|
12
12
|
},
|
|
13
13
|
createPng: async function createPng(basePath, options) {
|
|
14
14
|
const url = new URL(basePath);
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
15
|
+
const launchBrowser = await loadBrowserLauncherChunk();
|
|
16
|
+
if (!launchBrowser) {
|
|
17
17
|
throw new Error("Failed to load browser. Is the `browserProvider` enabled?");
|
|
18
18
|
}
|
|
19
|
-
const browser = await
|
|
19
|
+
const browser = await launchBrowser();
|
|
20
|
+
let res = null;
|
|
20
21
|
if (browser) {
|
|
21
22
|
try {
|
|
22
|
-
|
|
23
|
+
res = await screenshot(browser, {
|
|
23
24
|
...options,
|
|
24
25
|
host: withBase(useRuntimeConfig().app.baseURL, url.origin),
|
|
25
26
|
path: `/api/og-image-html?path=${url.pathname}`
|
|
@@ -28,6 +29,6 @@ export default {
|
|
|
28
29
|
browser.close();
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
return
|
|
32
|
+
return res;
|
|
32
33
|
}
|
|
33
34
|
};
|
|
@@ -7,7 +7,7 @@ import twClasses from "./plugins/twClasses.mjs";
|
|
|
7
7
|
import flex from "./plugins/flex.mjs";
|
|
8
8
|
import emojis from "./plugins/emojis.mjs";
|
|
9
9
|
import encoding from "./plugins/encoding.mjs";
|
|
10
|
-
import
|
|
10
|
+
import loadPngCreator from "#nuxt-og-image/png";
|
|
11
11
|
import loadSatori from "#nuxt-og-image/satori";
|
|
12
12
|
import { useRuntimeConfig } from "#internal/nitro";
|
|
13
13
|
const satoriFonts = [];
|
|
@@ -21,8 +21,8 @@ export default {
|
|
|
21
21
|
name: "satori",
|
|
22
22
|
createPng: async function createPng(baseUrl, options) {
|
|
23
23
|
const svg = await this.createSvg(baseUrl, options);
|
|
24
|
-
const
|
|
25
|
-
return
|
|
24
|
+
const pngCreator = await loadPngCreator();
|
|
25
|
+
return pngCreator(svg, { baseUrl, ...options });
|
|
26
26
|
},
|
|
27
27
|
createVNode: async function createVNode(baseUrl, options) {
|
|
28
28
|
const url = parseURL(baseUrl);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineEventHandler, setHeader } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
export default defineEventHandler(async (e) => {
|
|
4
|
+
setHeader(e, "Content-Type", "application/json");
|
|
5
|
+
const runtimeConfig = useRuntimeConfig()["nuxt-og-image"];
|
|
6
|
+
return {
|
|
7
|
+
runtimeConfig
|
|
8
|
+
};
|
|
9
|
+
});
|
|
@@ -23,8 +23,10 @@ export default defineEventHandler(async (e) => {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
e.node.req.url = path;
|
|
26
|
+
const oldRouteRules = e.context._nitro.routeRules;
|
|
26
27
|
e.context._nitro.routeRules = void 0;
|
|
27
28
|
const routeRules = getRouteRules(e)?.ogImage;
|
|
29
|
+
e.context._nitro.routeRules = oldRouteRules;
|
|
28
30
|
e.node.req.url = e.path;
|
|
29
31
|
if (routeRules === false)
|
|
30
32
|
return false;
|
|
@@ -35,8 +37,6 @@ export default defineEventHandler(async (e) => {
|
|
|
35
37
|
// use route rules
|
|
36
38
|
...routeRules || {},
|
|
37
39
|
// use provided data
|
|
38
|
-
...extractedPayload
|
|
39
|
-
// use query data
|
|
40
|
-
...query
|
|
40
|
+
...extractedPayload
|
|
41
41
|
};
|
|
42
42
|
});
|
|
@@ -3,9 +3,10 @@ import { Buffer } from 'node:buffer';
|
|
|
3
3
|
import type { H3Event } from 'h3';
|
|
4
4
|
import type { OgImageOptions } from '../../types';
|
|
5
5
|
export * from './util-hostname';
|
|
6
|
-
export declare function wasmLoader(asyncModuleLoad: Promise<any
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export declare function wasmLoader(asyncModuleLoad: Promise<any> | Buffer | string, fallback: string): {
|
|
7
|
+
load(options: {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
}): Promise<any>;
|
|
9
10
|
};
|
|
10
11
|
export declare function fetchOptions(e: H3Event, path: string): Promise<OgImageOptions>;
|
|
11
12
|
export declare function base64ToArrayBuffer(base64: string): ArrayBuffer;
|
|
@@ -2,55 +2,74 @@ import { existsSync, promises as fsp } from "node:fs";
|
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
3
|
import { getHeaders, getQuery } from "h3";
|
|
4
4
|
import { join } from "pathe";
|
|
5
|
+
import { prefixStorage } from "unstorage";
|
|
5
6
|
import { useHostname } from "./util-hostname.mjs";
|
|
6
|
-
import { useRuntimeConfig } from "#imports";
|
|
7
|
+
import { useRuntimeConfig, useStorage } from "#imports";
|
|
7
8
|
export * from "./util-hostname.mjs";
|
|
8
|
-
export function wasmLoader(asyncModuleLoad, fallback
|
|
9
|
+
export function wasmLoader(asyncModuleLoad, fallback) {
|
|
9
10
|
let promise;
|
|
10
|
-
let
|
|
11
|
+
let wasm;
|
|
11
12
|
return {
|
|
12
|
-
|
|
13
|
-
if (loaded)
|
|
14
|
-
return true;
|
|
13
|
+
async load(options) {
|
|
15
14
|
if (typeof promise !== "undefined")
|
|
16
15
|
return promise;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
async load() {
|
|
16
|
+
if (wasm)
|
|
17
|
+
return wasm;
|
|
20
18
|
promise = promise || new Promise(async (resolve) => {
|
|
21
|
-
let wasm;
|
|
22
19
|
try {
|
|
23
20
|
wasm = await asyncModuleLoad;
|
|
24
21
|
if (typeof wasm === "string")
|
|
25
22
|
wasm = void 0;
|
|
26
23
|
} catch (e) {
|
|
27
24
|
}
|
|
28
|
-
if (!wasm)
|
|
29
|
-
wasm = await readPublicAsset(fallback);
|
|
30
25
|
if (!wasm) {
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
wasm = await readPublicAsset(fallback, "base64");
|
|
27
|
+
if (wasm)
|
|
28
|
+
wasm = Buffer.from(wasm, "base64");
|
|
29
|
+
}
|
|
30
|
+
if (!wasm) {
|
|
31
|
+
const url = new URL(options.baseUrl);
|
|
32
|
+
wasm = await (await globalThis.$fetch(fallback, { baseURL: url.origin })).arrayBuffer();
|
|
33
|
+
wasm = Buffer.from(wasm);
|
|
33
34
|
}
|
|
34
|
-
loaded = true;
|
|
35
35
|
resolve(wasm);
|
|
36
36
|
});
|
|
37
37
|
return promise;
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
export function fetchOptions(e, path) {
|
|
41
|
+
export async function fetchOptions(e, path) {
|
|
42
|
+
const { runtimeCacheStorage } = useRuntimeConfig()["nuxt-og-image"];
|
|
43
|
+
const cache = runtimeCacheStorage ? prefixStorage(useStorage(), "og-image-cache:options") : false;
|
|
44
|
+
if (cache && await cache.hasItem(path)) {
|
|
45
|
+
const cachedValue = await cache.getItem(path);
|
|
46
|
+
if (cachedValue && cachedValue.expiresAt < Date.now())
|
|
47
|
+
return cachedValue.value;
|
|
48
|
+
else
|
|
49
|
+
await cache.removeItem(path);
|
|
50
|
+
}
|
|
42
51
|
const fetchOptions2 = process.dev || process.env.prerender ? {
|
|
43
52
|
headers: getHeaders(e)
|
|
44
53
|
} : {
|
|
45
54
|
baseURL: useHostname(e)
|
|
46
55
|
};
|
|
47
|
-
|
|
56
|
+
const res = await globalThis.$fetch("/api/og-image-options", {
|
|
48
57
|
query: {
|
|
49
|
-
...getQuery(e),
|
|
50
58
|
path
|
|
51
59
|
},
|
|
52
60
|
...fetchOptions2
|
|
53
61
|
});
|
|
62
|
+
if (cache) {
|
|
63
|
+
await cache.setItem(path, {
|
|
64
|
+
value: res,
|
|
65
|
+
expiresAt: Date.now() + (res.static ? 60 * 60 * 1e3 : 5 * 1e3)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...res,
|
|
70
|
+
// use query data
|
|
71
|
+
...getQuery(e)
|
|
72
|
+
};
|
|
54
73
|
}
|
|
55
74
|
export function base64ToArrayBuffer(base64) {
|
|
56
75
|
const buffer = Buffer.from(base64, "base64");
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.22",
|
|
5
5
|
"packageManager": "pnpm@8.1.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@nuxt/kit": "3.4.2",
|
|
30
|
+
"@resvg/resvg-wasm": "^2.4.1",
|
|
30
31
|
"@types/fs-extra": "^11.0.1",
|
|
31
32
|
"birpc": "^0.2.11",
|
|
32
33
|
"chalk": "^5.2.0",
|
|
@@ -36,15 +37,17 @@
|
|
|
36
37
|
"fast-glob": "^3.2.12",
|
|
37
38
|
"flatted": "^3.2.7",
|
|
38
39
|
"fs-extra": "^11.1.1",
|
|
40
|
+
"globby": "^13.1.4",
|
|
39
41
|
"launch-editor": "^2.6.0",
|
|
42
|
+
"nypm": "^0.2.0",
|
|
40
43
|
"ofetch": "^1.0.1",
|
|
41
|
-
"ohash": "^1.1.
|
|
44
|
+
"ohash": "^1.1.2",
|
|
42
45
|
"pathe": "^1.1.0",
|
|
43
|
-
"playwright-core": "^1.
|
|
46
|
+
"playwright-core": "^1.33.0",
|
|
44
47
|
"radix3": "^1.0.1",
|
|
45
|
-
"satori": "0.
|
|
48
|
+
"satori": "0.7.2",
|
|
46
49
|
"satori-html": "^0.3.2",
|
|
47
|
-
"sirv": "^2.0.
|
|
50
|
+
"sirv": "^2.0.3",
|
|
48
51
|
"std-env": "^3.3.2",
|
|
49
52
|
"svg2png-wasm": "^1.3.4",
|
|
50
53
|
"tinyws": "^0.1.0",
|
|
@@ -55,18 +58,22 @@
|
|
|
55
58
|
},
|
|
56
59
|
"devDependencies": {
|
|
57
60
|
"@antfu/eslint-config": "^0.38.5",
|
|
58
|
-
"@nuxt/devtools-edge": "0.4.
|
|
61
|
+
"@nuxt/devtools-edge": "0.4.2-28041905.19fda12",
|
|
59
62
|
"@nuxt/module-builder": "^0.3.0",
|
|
60
63
|
"@nuxt/test-utils": "3.4.2",
|
|
61
64
|
"@nuxtjs/eslint-config-typescript": "^12.0.0",
|
|
62
65
|
"@types/ws": "^8.5.4",
|
|
63
66
|
"bumpp": "^9.1.0",
|
|
64
|
-
"eslint": "8.
|
|
67
|
+
"eslint": "8.39.0",
|
|
65
68
|
"jest-image-snapshot": "^6.1.0",
|
|
66
69
|
"nuxt": "^3.4.2",
|
|
67
|
-
"puppeteer": "^19.10.1",
|
|
68
70
|
"vitest": "^0.30.1"
|
|
69
71
|
},
|
|
72
|
+
"resolutions": {
|
|
73
|
+
"nitropack": "npm:nitropack-edge@2.4.0-28027501.1cf01bf",
|
|
74
|
+
"unstorage": "^1.5.0",
|
|
75
|
+
"unenv": "^1.4.1"
|
|
76
|
+
},
|
|
70
77
|
"scripts": {
|
|
71
78
|
"build": "pnpm dev:prepare && pnpm build:module && pnpm build:client",
|
|
72
79
|
"build:client": "nuxi generate client",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as p,b as u,e as l,f as t,o as f,h as m,i as d,u as o,j as _}from"./entry.c8bf4454.js";const x=p({__name:"IconCSS",props:{name:{type:String,required:!0},size:{type:String,default:""}},setup(i){const s=i;u(e=>({"57550bb0":o(r)}));const n=l();n?.nuxtIcon?.aliases;const c=t(()=>(n?.nuxtIcon?.aliases||{})[s.name]||s.name),r=t(()=>`url('https://api.iconify.design/${c.value.replace(":","/")}.svg')`),a=t(()=>{if(!s.size&&typeof n.nuxtIcon?.size=="boolean"&&!n.nuxtIcon?.size)return;const e=s.size||n.nuxtIcon?.size||"1em";return String(Number(e))===e?`${e}px`:e});return(e,z)=>(f(),m("span",{style:d({width:o(a),height:o(a)})},null,4))}}),g=_(x,[["__scopeId","data-v-de762dfd"]]);export{g as default};
|