nuxt-og-image 2.0.0 → 2.0.1
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.685477c5.js} +1 -1
- package/dist/client/_nuxt/{ImageLoader.51157bac.js → ImageLoader.fb4e5eb3.js} +1 -1
- package/dist/client/_nuxt/{entry.74c20cae.js → entry.0fc037e0.js} +3 -3
- package/dist/client/_nuxt/{error-404.102f7671.js → error-404.068f19dd.js} +1 -1
- package/dist/client/_nuxt/{error-500.f8617a9a.js → error-500.4d72610e.js} +1 -1
- package/dist/client/_nuxt/{index.212ef337.js → index.33389497.js} +1 -1
- package/dist/client/_nuxt/{options.fa4f11fe.js → options.e1a971ea.js} +1 -1
- package/dist/client/_nuxt/{png.eb47fcca.js → png.110ab8f5.js} +1 -1
- package/dist/client/_nuxt/{shiki.b89869e1.js → shiki.3fe159de.js} +1 -1
- package/dist/client/_nuxt/{svg.04901249.js → svg.1a58cdf3.js} +1 -1
- package/dist/client/_nuxt/{vnodes.b05f3d68.js → vnodes.42fbc6e6.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 +38 -21
- 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,8 @@ 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
|
|
240
241
|
};
|
|
241
242
|
const RuntimeCompatibility = {
|
|
242
243
|
"nitro-dev": {
|
|
@@ -255,7 +256,8 @@ const RuntimeCompatibility = {
|
|
|
255
256
|
},
|
|
256
257
|
"netlify-edge": {
|
|
257
258
|
wasm: "inline",
|
|
258
|
-
png: "resvg-wasm"
|
|
259
|
+
png: "resvg-wasm",
|
|
260
|
+
node: false
|
|
259
261
|
},
|
|
260
262
|
"vercel": {
|
|
261
263
|
// exceeds 50mb limit
|
|
@@ -265,12 +267,14 @@ const RuntimeCompatibility = {
|
|
|
265
267
|
browser: false,
|
|
266
268
|
wasm: "import",
|
|
267
269
|
wasmImportQuery: "?module",
|
|
268
|
-
png: "resvg-wasm"
|
|
270
|
+
png: "resvg-wasm",
|
|
271
|
+
node: false
|
|
269
272
|
},
|
|
270
273
|
"cloudflare-pages": {
|
|
271
274
|
browser: false,
|
|
272
275
|
wasm: "import",
|
|
273
|
-
png: "resvg-wasm"
|
|
276
|
+
png: "resvg-wasm",
|
|
277
|
+
node: false
|
|
274
278
|
},
|
|
275
279
|
"cloudflare": {
|
|
276
280
|
browser: false,
|
|
@@ -294,23 +298,28 @@ const autodetectableStaticProviders = {
|
|
|
294
298
|
function detectTarget(options = {}) {
|
|
295
299
|
return options?.static ? autodetectableStaticProviders[provider] : autodetectableProviders[provider];
|
|
296
300
|
}
|
|
297
|
-
function getNitroPreset(nuxt) {
|
|
301
|
+
function getNitroPreset(nuxt = useNuxt()) {
|
|
298
302
|
return process.env.NITRO_PRESET || nuxt.options.nitro.preset || detectTarget() || "node-server";
|
|
299
303
|
}
|
|
300
|
-
function getNitroProviderCompatibility(nuxt) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
304
|
+
function getNitroProviderCompatibility(defaults, nuxt = useNuxt()) {
|
|
305
|
+
let compatibility;
|
|
306
|
+
if (provider === "stackblitz") {
|
|
307
|
+
compatibility = RuntimeCompatibility.stackblitz;
|
|
308
|
+
} else if (nuxt.options.dev || nuxt.options._prepare || nuxt.options._generate) {
|
|
309
|
+
compatibility = {
|
|
305
310
|
wasm: "fetch",
|
|
306
311
|
browser: "universal"
|
|
307
|
-
}
|
|
312
|
+
};
|
|
313
|
+
} else {
|
|
314
|
+
const target = getNitroPreset(nuxt);
|
|
315
|
+
const lookup = RuntimeCompatibility[target];
|
|
316
|
+
if (lookup === false)
|
|
317
|
+
return false;
|
|
318
|
+
compatibility = lookup || {};
|
|
308
319
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
return false;
|
|
313
|
-
return defu(compatibility || {}, DefaultRuntimeCompatibility);
|
|
320
|
+
compatibility = defu(compatibility, defaults);
|
|
321
|
+
compatibility.inlineCss = compatibility.inlineCss || (compatibility.node ? "node" : "mock");
|
|
322
|
+
return compatibility;
|
|
314
323
|
}
|
|
315
324
|
function ensureDependencies(nuxt, dep) {
|
|
316
325
|
return Promise.all(dep.map((d) => {
|
|
@@ -358,6 +367,7 @@ const module = defineNuxtModule({
|
|
|
358
367
|
cache: true,
|
|
359
368
|
cacheTtl: 24 * 60 * 60 * 1e3
|
|
360
369
|
},
|
|
370
|
+
runtimeCompatibility: DefaultRuntimeCompatibility,
|
|
361
371
|
componentDirs: ["OgImage", "OgImageTemplate"],
|
|
362
372
|
runtimeSatori: true,
|
|
363
373
|
runtimeBrowser: nuxt.options.dev,
|
|
@@ -376,12 +386,12 @@ const module = defineNuxtModule({
|
|
|
376
386
|
return;
|
|
377
387
|
}
|
|
378
388
|
const { resolve } = createResolver(import.meta.url);
|
|
379
|
-
logger.debug("Using Nitro preset", getNitroPreset(
|
|
380
|
-
const nitroCompatibility = getNitroProviderCompatibility(
|
|
389
|
+
logger.debug("Using Nitro preset", getNitroPreset());
|
|
390
|
+
const nitroCompatibility = getNitroProviderCompatibility(config.runtimeCompatibility);
|
|
381
391
|
logger.debug("Nitro compatibility", nitroCompatibility);
|
|
382
|
-
const nitroTarget = process.env.NITRO_PRESET || nuxt.options.nitro.preset;
|
|
392
|
+
const nitroTarget = process.env.NITRO_PRESET || nuxt.options.nitro.preset || provider;
|
|
383
393
|
if (!nitroCompatibility) {
|
|
384
|
-
logger.warn(`\`nuxt-og-image\` does not support the nitro
|
|
394
|
+
logger.warn(`\`nuxt-og-image\` does not support the nitro preset \`${nitroTarget}\`. Please make an issue. `);
|
|
385
395
|
return;
|
|
386
396
|
}
|
|
387
397
|
if (!nitroCompatibility.browser && config.runtimeBrowser) {
|
|
@@ -585,6 +595,8 @@ declare module 'nitropack' {
|
|
|
585
595
|
nitroConfig.alias.bufferutil = "unenv/runtime/mock/proxy-cjs";
|
|
586
596
|
nitroConfig.alias["utf-8-validate"] = "unenv/runtime/mock/proxy-cjs";
|
|
587
597
|
}
|
|
598
|
+
if (nitroCompatibility.png === "resvg-wasm")
|
|
599
|
+
nitroConfig.alias["@resvg/resvg-js"] = "unenv/runtime/mock/proxy-cjs";
|
|
588
600
|
nitroConfig.publicAssets = nitroConfig.publicAssets || [];
|
|
589
601
|
customAssetDirs.forEach((dir) => {
|
|
590
602
|
nitroConfig.publicAssets.push({ dir, maxAge: 31536e3 });
|
|
@@ -608,6 +620,11 @@ export default function() {
|
|
|
608
620
|
export default function() {
|
|
609
621
|
return png
|
|
610
622
|
}
|
|
623
|
+
`;
|
|
624
|
+
nitroConfig.virtual["#nuxt-og-image/inline-css"] = `import inlineCss from '${providerPath}/inline-css/${nitroCompatibility.inlineCss || "mock"}'
|
|
625
|
+
export default function() {
|
|
626
|
+
return inlineCss
|
|
627
|
+
}
|
|
611
628
|
`;
|
|
612
629
|
}
|
|
613
630
|
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
|
});
|