nuxt-og-image 2.0.0 → 2.0.2
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 +1 -1
- package/dist/client/200.html +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/{IconCSS.48ffa50d.js → IconCSS.512a16f2.js} +1 -1
- package/dist/client/_nuxt/{ImageLoader.51157bac.js → ImageLoader.8121dffe.js} +1 -1
- package/dist/client/_nuxt/{entry.74c20cae.js → entry.57977e72.js} +3 -3
- package/dist/client/_nuxt/{error-404.102f7671.js → error-404.d4738c97.js} +1 -1
- package/dist/client/_nuxt/{error-500.f8617a9a.js → error-500.c8697c1e.js} +1 -1
- package/dist/client/_nuxt/{index.212ef337.js → index.3ba5d172.js} +1 -1
- package/dist/client/_nuxt/{options.fa4f11fe.js → options.a04aa904.js} +1 -1
- package/dist/client/_nuxt/{png.eb47fcca.js → png.f0a539e0.js} +1 -1
- package/dist/client/_nuxt/{shiki.b89869e1.js → shiki.f6c35446.js} +1 -1
- package/dist/client/_nuxt/{svg.04901249.js → svg.3a9a21ca.js} +1 -1
- package/dist/client/_nuxt/{vnodes.b05f3d68.js → vnodes.9adf2dbf.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 +16 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +44 -29
- package/dist/runtime/nitro/providers/inline-css/mock.d.ts +5 -0
- package/dist/runtime/nitro/providers/inline-css/mock.mjs +3 -0
- package/dist/runtime/nitro/providers/inline-css/node.d.ts +5 -0
- package/dist/runtime/nitro/providers/inline-css/node.mjs +11 -0
- package/dist/runtime/nitro/routes/html.mjs +30 -28
- package/package.json +1 -1
package/dist/module.mjs
CHANGED
|
@@ -11,12 +11,12 @@ import sirv from 'sirv';
|
|
|
11
11
|
import { pathExists, copy, mkdirp } from 'fs-extra';
|
|
12
12
|
import { globby } from 'globby';
|
|
13
13
|
import { installNuxtSiteConfig, updateSiteConfig, requireSiteConfig } from 'nuxt-site-config-kit';
|
|
14
|
+
import { provider } from 'std-env';
|
|
14
15
|
import playwrightCore from 'playwright-core';
|
|
15
16
|
import { existsSync } from 'node:fs';
|
|
16
17
|
import { createBirpcGroup } from 'birpc';
|
|
17
18
|
import { stringify, parse } from 'flatted';
|
|
18
19
|
import { addDependency } from 'nypm';
|
|
19
|
-
import { provider } from 'std-env';
|
|
20
20
|
|
|
21
21
|
async function createBrowser() {
|
|
22
22
|
if (process.dev || process.env.prerender) {
|
|
@@ -236,7 +236,14 @@ const DefaultRuntimeCompatibility = {
|
|
|
236
236
|
browser: "playwright",
|
|
237
237
|
satori: "default",
|
|
238
238
|
wasm: "fetch",
|
|
239
|
-
png: "resvg-node"
|
|
239
|
+
png: "resvg-node",
|
|
240
|
+
node: true
|
|
241
|
+
};
|
|
242
|
+
const cloudflare = {
|
|
243
|
+
browser: false,
|
|
244
|
+
wasm: "import",
|
|
245
|
+
png: "resvg-wasm",
|
|
246
|
+
node: false
|
|
240
247
|
};
|
|
241
248
|
const RuntimeCompatibility = {
|
|
242
249
|
"nitro-dev": {
|
|
@@ -255,7 +262,8 @@ const RuntimeCompatibility = {
|
|
|
255
262
|
},
|
|
256
263
|
"netlify-edge": {
|
|
257
264
|
wasm: "inline",
|
|
258
|
-
png: "resvg-wasm"
|
|
265
|
+
png: "resvg-wasm",
|
|
266
|
+
node: false
|
|
259
267
|
},
|
|
260
268
|
"vercel": {
|
|
261
269
|
// exceeds 50mb limit
|
|
@@ -265,17 +273,11 @@ const RuntimeCompatibility = {
|
|
|
265
273
|
browser: false,
|
|
266
274
|
wasm: "import",
|
|
267
275
|
wasmImportQuery: "?module",
|
|
268
|
-
png: "resvg-wasm"
|
|
269
|
-
|
|
270
|
-
"cloudflare-pages": {
|
|
271
|
-
browser: false,
|
|
272
|
-
wasm: "import",
|
|
273
|
-
png: "resvg-wasm"
|
|
276
|
+
png: "resvg-wasm",
|
|
277
|
+
node: false
|
|
274
278
|
},
|
|
275
|
-
"cloudflare":
|
|
276
|
-
|
|
277
|
-
wasm: "import"
|
|
278
|
-
}
|
|
279
|
+
"cloudflare-pages": cloudflare,
|
|
280
|
+
"cloudflare": cloudflare
|
|
279
281
|
};
|
|
280
282
|
|
|
281
283
|
const autodetectableProviders = {
|
|
@@ -294,23 +296,28 @@ const autodetectableStaticProviders = {
|
|
|
294
296
|
function detectTarget(options = {}) {
|
|
295
297
|
return options?.static ? autodetectableStaticProviders[provider] : autodetectableProviders[provider];
|
|
296
298
|
}
|
|
297
|
-
function getNitroPreset(nuxt) {
|
|
299
|
+
function getNitroPreset(nuxt = useNuxt()) {
|
|
298
300
|
return process.env.NITRO_PRESET || nuxt.options.nitro.preset || detectTarget() || "node-server";
|
|
299
301
|
}
|
|
300
|
-
function getNitroProviderCompatibility(nuxt) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
302
|
+
function getNitroProviderCompatibility(defaults, nuxt = useNuxt()) {
|
|
303
|
+
let compatibility;
|
|
304
|
+
if (provider === "stackblitz") {
|
|
305
|
+
compatibility = RuntimeCompatibility.stackblitz;
|
|
306
|
+
} else if (nuxt.options.dev || nuxt.options._prepare || nuxt.options._generate) {
|
|
307
|
+
compatibility = {
|
|
305
308
|
wasm: "fetch",
|
|
306
309
|
browser: "universal"
|
|
307
|
-
}
|
|
310
|
+
};
|
|
311
|
+
} else {
|
|
312
|
+
const target = getNitroPreset(nuxt);
|
|
313
|
+
const lookup = RuntimeCompatibility[target];
|
|
314
|
+
if (lookup === false)
|
|
315
|
+
return false;
|
|
316
|
+
compatibility = lookup || {};
|
|
308
317
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
return false;
|
|
313
|
-
return defu(compatibility || {}, DefaultRuntimeCompatibility);
|
|
318
|
+
compatibility = defu(compatibility, defaults);
|
|
319
|
+
compatibility.inlineCss = compatibility.inlineCss || (compatibility.node ? "node" : "mock");
|
|
320
|
+
return compatibility;
|
|
314
321
|
}
|
|
315
322
|
function ensureDependencies(nuxt, dep) {
|
|
316
323
|
return Promise.all(dep.map((d) => {
|
|
@@ -358,6 +365,7 @@ const module = defineNuxtModule({
|
|
|
358
365
|
cache: true,
|
|
359
366
|
cacheTtl: 24 * 60 * 60 * 1e3
|
|
360
367
|
},
|
|
368
|
+
runtimeCompatibility: DefaultRuntimeCompatibility,
|
|
361
369
|
componentDirs: ["OgImage", "OgImageTemplate"],
|
|
362
370
|
runtimeSatori: true,
|
|
363
371
|
runtimeBrowser: nuxt.options.dev,
|
|
@@ -376,12 +384,12 @@ const module = defineNuxtModule({
|
|
|
376
384
|
return;
|
|
377
385
|
}
|
|
378
386
|
const { resolve } = createResolver(import.meta.url);
|
|
379
|
-
logger.debug("Using Nitro preset", getNitroPreset(
|
|
380
|
-
const nitroCompatibility = getNitroProviderCompatibility(
|
|
387
|
+
logger.debug("Using Nitro preset", getNitroPreset());
|
|
388
|
+
const nitroCompatibility = getNitroProviderCompatibility(config.runtimeCompatibility);
|
|
381
389
|
logger.debug("Nitro compatibility", nitroCompatibility);
|
|
382
|
-
const nitroTarget = process.env.NITRO_PRESET || nuxt.options.nitro.preset;
|
|
390
|
+
const nitroTarget = process.env.NITRO_PRESET || nuxt.options.nitro.preset || provider;
|
|
383
391
|
if (!nitroCompatibility) {
|
|
384
|
-
logger.warn(`\`nuxt-og-image\` does not support the nitro
|
|
392
|
+
logger.warn(`\`nuxt-og-image\` does not support the nitro preset \`${nitroTarget}\`. Please make an issue. `);
|
|
385
393
|
return;
|
|
386
394
|
}
|
|
387
395
|
if (!nitroCompatibility.browser && config.runtimeBrowser) {
|
|
@@ -585,6 +593,8 @@ declare module 'nitropack' {
|
|
|
585
593
|
nitroConfig.alias.bufferutil = "unenv/runtime/mock/proxy-cjs";
|
|
586
594
|
nitroConfig.alias["utf-8-validate"] = "unenv/runtime/mock/proxy-cjs";
|
|
587
595
|
}
|
|
596
|
+
if (nitroCompatibility.png === "resvg-wasm")
|
|
597
|
+
nitroConfig.alias["@resvg/resvg-js"] = "unenv/runtime/mock/proxy-cjs";
|
|
588
598
|
nitroConfig.publicAssets = nitroConfig.publicAssets || [];
|
|
589
599
|
customAssetDirs.forEach((dir) => {
|
|
590
600
|
nitroConfig.publicAssets.push({ dir, maxAge: 31536e3 });
|
|
@@ -608,6 +618,11 @@ export default function() {
|
|
|
608
618
|
export default function() {
|
|
609
619
|
return png
|
|
610
620
|
}
|
|
621
|
+
`;
|
|
622
|
+
nitroConfig.virtual["#nuxt-og-image/inline-css"] = `import inlineCss from '${providerPath}/inline-css/${nitroCompatibility.inlineCss || "mock"}'
|
|
623
|
+
export default function() {
|
|
624
|
+
return inlineCss
|
|
625
|
+
}
|
|
611
626
|
`;
|
|
612
627
|
}
|
|
613
628
|
nitroConfig.virtual["#nuxt-og-image/provider"] = `
|
|
@@ -7,12 +7,14 @@ import twemoji from "twemoji";
|
|
|
7
7
|
import { defu } from "defu";
|
|
8
8
|
import { fetchOptions } from "../utils.mjs";
|
|
9
9
|
import { useNitroOrigin, useRuntimeConfig } from "#imports";
|
|
10
|
+
import loadInlineCSS from "#nuxt-og-image/inline-css";
|
|
10
11
|
export default defineEventHandler(async (e) => {
|
|
11
12
|
const { fonts, satoriOptions } = useRuntimeConfig()["nuxt-og-image"];
|
|
12
13
|
const query = getQuery(e);
|
|
13
14
|
const path = withBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
14
15
|
const scale = query.scale;
|
|
15
16
|
const mode = query.mode || "light";
|
|
17
|
+
const nitroOrigin = useNitroOrigin(e);
|
|
16
18
|
let queryOptions;
|
|
17
19
|
if (query.options) {
|
|
18
20
|
try {
|
|
@@ -25,7 +27,7 @@ export default defineEventHandler(async (e) => {
|
|
|
25
27
|
options = defu(queryOptions, options);
|
|
26
28
|
if (options.provider === "browser" && !options.component) {
|
|
27
29
|
const pathWithoutBase = path.replace(new RegExp(`^${useRuntimeConfig().app.baseURL}`), "");
|
|
28
|
-
return sendRedirect(e, withBase(pathWithoutBase,
|
|
30
|
+
return sendRedirect(e, withBase(pathWithoutBase, nitroOrigin));
|
|
29
31
|
}
|
|
30
32
|
if (!options.component) {
|
|
31
33
|
throw createError({
|
|
@@ -127,39 +129,39 @@ img.emoji {
|
|
|
127
129
|
<head>${headChunk.headTags}</head>
|
|
128
130
|
<body ${headChunk.bodyAttrs}>${headChunk.bodyTagsOpen}<div style="position: relative; display: flex; margin: 0 auto; width: ${options.width}px; height: ${options.height}px; overflow: hidden;">${html}</div>${headChunk.bodyTags}</body>
|
|
129
131
|
</html>`;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
132
|
+
const inlineCss = loadInlineCSS();
|
|
133
|
+
if (!inlineCss.__mock) {
|
|
134
|
+
let hasInlineStyles = false;
|
|
135
|
+
const stylesheets = htmlTemplate.match(/<link rel="stylesheet" href=".*?">/g);
|
|
136
|
+
if (stylesheets) {
|
|
137
|
+
for (const stylesheet of stylesheets) {
|
|
138
|
+
if (!stylesheet.includes(`${options.component.replace("OgImageTemplate", "").replace("OgImage", "")}.vue`)) {
|
|
139
|
+
htmlTemplate = htmlTemplate.replace(stylesheet, "");
|
|
140
|
+
} else {
|
|
141
|
+
const href = stylesheet.match(/href="(.*?)"/)[1];
|
|
142
|
+
try {
|
|
143
|
+
let css = await (await $fetch(href, {
|
|
144
|
+
baseURL: nitroOrigin
|
|
145
|
+
})).text();
|
|
146
|
+
if (css.includes("const __vite__css =")) {
|
|
147
|
+
css = css.match(/const __vite__css = "(.*)"/)[1].replace(/\\n/g, "\n");
|
|
148
|
+
}
|
|
149
|
+
css = css.replace(/\/\*# sourceMappingURL=.*?\*\//g, "").replaceAll("! important", "").replaceAll("!important");
|
|
150
|
+
htmlTemplate = htmlTemplate.replace(stylesheet, `<style>${css}</style>`);
|
|
151
|
+
hasInlineStyles = true;
|
|
152
|
+
} catch {
|
|
144
153
|
}
|
|
145
|
-
htmlTemplate = htmlTemplate.replace(stylesheet, `<style>${css.replace(/\/\/# sourceMappingURL=.*/, "")}</style>`);
|
|
146
|
-
hasInlineStyles = true;
|
|
147
|
-
} catch {
|
|
148
154
|
}
|
|
149
155
|
}
|
|
150
156
|
}
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
157
|
if (hasInlineStyles) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
});
|
|
158
|
+
try {
|
|
159
|
+
htmlTemplate = await inlineCss(htmlTemplate, {
|
|
160
|
+
url: nitroOrigin
|
|
161
|
+
});
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
161
164
|
}
|
|
162
|
-
} catch {
|
|
163
165
|
}
|
|
164
166
|
return htmlTemplate;
|
|
165
167
|
});
|