nuxt-og-image 5.1.10 → 5.1.12
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/dist/client/200.html +1 -0
- package/dist/client/404.html +1 -0
- package/dist/client/_nuxt/B8PEiB0p.js +1 -0
- package/dist/client/_nuxt/CD9VIl4i.js +4062 -0
- package/dist/client/_nuxt/CI_lqgv7.js +1 -0
- package/dist/client/_nuxt/CVO1_9PV.js +1 -0
- package/dist/client/_nuxt/Cp-IABpG.js +1 -0
- package/dist/client/_nuxt/D0r3Knsf.js +1 -0
- package/dist/client/_nuxt/Dz8kdfgF.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -0
- package/dist/client/_nuxt/builds/meta/71b0f7ea-9aae-4c28-bbd9-8eea71b82dfb.json +1 -0
- package/dist/client/_nuxt/entry.DNM8P-MU.css +1 -0
- package/dist/client/_nuxt/error-404.C2mGI6Vt.css +1 -0
- package/dist/client/_nuxt/error-500.ClHbVBiL.css +1 -0
- package/dist/client/_nuxt/l5rcX3cq.js +8 -0
- package/dist/client/index.html +1 -0
- package/dist/content.cjs +22 -0
- package/dist/content.d.cts +46 -0
- package/dist/content.d.mts +46 -0
- package/dist/content.d.ts +46 -0
- package/dist/content.mjs +18 -0
- package/dist/module.cjs +1027 -0
- package/dist/module.d.cts +109 -0
- package/dist/module.d.mts +109 -0
- package/dist/module.d.ts +109 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +1007 -0
- package/dist/runtime/app/components/OgImage/OgImage.d.ts +3 -0
- package/dist/runtime/app/components/OgImage/OgImage.js +10 -0
- package/dist/runtime/app/components/OgImage/OgImageScreenshot.d.ts +3 -0
- package/dist/runtime/app/components/OgImage/OgImageScreenshot.js +10 -0
- package/dist/runtime/app/components/Templates/Community/BrandedLogo.d.vue.ts +13 -0
- package/dist/runtime/app/components/Templates/Community/BrandedLogo.vue +22 -0
- package/dist/runtime/app/components/Templates/Community/BrandedLogo.vue.d.ts +13 -0
- package/dist/runtime/app/components/Templates/Community/Frame.d.vue.ts +21 -0
- package/dist/runtime/app/components/Templates/Community/Frame.vue +58 -0
- package/dist/runtime/app/components/Templates/Community/Frame.vue.d.ts +21 -0
- package/dist/runtime/app/components/Templates/Community/Nuxt.d.vue.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/Nuxt.vue +179 -0
- package/dist/runtime/app/components/Templates/Community/Nuxt.vue.d.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/NuxtSeo.d.vue.ts +15 -0
- package/dist/runtime/app/components/Templates/Community/NuxtSeo.vue +103 -0
- package/dist/runtime/app/components/Templates/Community/NuxtSeo.vue.d.ts +15 -0
- package/dist/runtime/app/components/Templates/Community/Pergel.d.vue.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/Pergel.vue +98 -0
- package/dist/runtime/app/components/Templates/Community/Pergel.vue.d.ts +12 -0
- package/dist/runtime/app/components/Templates/Community/SimpleBlog.d.vue.ts +9 -0
- package/dist/runtime/app/components/Templates/Community/SimpleBlog.vue +27 -0
- package/dist/runtime/app/components/Templates/Community/SimpleBlog.vue.d.ts +9 -0
- package/dist/runtime/app/components/Templates/Community/UnJs.d.vue.ts +21 -0
- package/dist/runtime/app/components/Templates/Community/UnJs.vue +99 -0
- package/dist/runtime/app/components/Templates/Community/UnJs.vue.d.ts +21 -0
- package/dist/runtime/app/components/Templates/Community/Wave.d.vue.ts +11 -0
- package/dist/runtime/app/components/Templates/Community/Wave.vue +28 -0
- package/dist/runtime/app/components/Templates/Community/Wave.vue.d.ts +11 -0
- package/dist/runtime/app/components/Templates/Community/WithEmoji.d.vue.ts +13 -0
- package/dist/runtime/app/components/Templates/Community/WithEmoji.vue +21 -0
- package/dist/runtime/app/components/Templates/Community/WithEmoji.vue.d.ts +13 -0
- package/dist/runtime/app/composables/defineOgImage.d.ts +2 -0
- package/dist/runtime/app/composables/defineOgImage.js +43 -0
- package/dist/runtime/app/composables/defineOgImageComponent.d.ts +3 -0
- package/dist/runtime/app/composables/defineOgImageComponent.js +8 -0
- package/dist/runtime/app/composables/defineOgImageScreenshot.d.ts +2 -0
- package/dist/runtime/app/composables/defineOgImageScreenshot.js +14 -0
- package/dist/runtime/app/composables/mock.d.ts +5 -0
- package/dist/runtime/app/composables/mock.js +20 -0
- package/dist/runtime/app/plugins/__zero-runtime/og-image-canonical-urls.server.d.ts +2 -0
- package/dist/runtime/app/plugins/__zero-runtime/og-image-canonical-urls.server.js +9 -0
- package/dist/runtime/app/plugins/__zero-runtime/route-rule-og-image.server.d.ts +2 -0
- package/dist/runtime/app/plugins/__zero-runtime/route-rule-og-image.server.js +9 -0
- package/dist/runtime/app/plugins/og-image-canonical-urls.server.d.ts +2 -0
- package/dist/runtime/app/plugins/og-image-canonical-urls.server.js +7 -0
- package/dist/runtime/app/plugins/route-rule-og-image.server.d.ts +2 -0
- package/dist/runtime/app/plugins/route-rule-og-image.server.js +7 -0
- package/dist/runtime/app/utils/plugins.d.ts +3 -0
- package/dist/runtime/app/utils/plugins.js +92 -0
- package/dist/runtime/app/utils.d.ts +7 -0
- package/dist/runtime/app/utils.js +94 -0
- package/dist/runtime/assets/Inter-normal-400.ttf.base64 +1 -0
- package/dist/runtime/assets/Inter-normal-700.ttf.base64 +1 -0
- package/dist/runtime/logger.d.ts +2 -0
- package/dist/runtime/logger.js +8 -0
- package/dist/runtime/mock/empty.d.ts +2 -0
- package/dist/runtime/mock/empty.js +2 -0
- package/dist/runtime/mock/proxy-cjs.d.ts +2 -0
- package/dist/runtime/mock/proxy-cjs.js +2 -0
- package/dist/runtime/server/og-image/bindings/chromium/chrome-launcher.d.ts +2 -0
- package/dist/runtime/server/og-image/bindings/chromium/chrome-launcher.js +9 -0
- package/dist/runtime/server/og-image/bindings/chromium/on-demand.d.ts +2 -0
- package/dist/runtime/server/og-image/bindings/chromium/on-demand.js +40 -0
- package/dist/runtime/server/og-image/bindings/chromium/playwright.d.ts +2 -0
- package/dist/runtime/server/og-image/bindings/chromium/playwright.js +6 -0
- package/dist/runtime/server/og-image/bindings/css-inline/node.d.ts +8 -0
- package/dist/runtime/server/og-image/bindings/css-inline/node.js +7 -0
- package/dist/runtime/server/og-image/bindings/css-inline/wasm-fs.d.ts +7 -0
- package/dist/runtime/server/og-image/bindings/css-inline/wasm-fs.js +8 -0
- package/dist/runtime/server/og-image/bindings/css-inline/wasm.d.ts +7 -0
- package/dist/runtime/server/og-image/bindings/css-inline/wasm.js +7 -0
- package/dist/runtime/server/og-image/bindings/resvg/node.d.ts +6 -0
- package/dist/runtime/server/og-image/bindings/resvg/node.js +5 -0
- package/dist/runtime/server/og-image/bindings/resvg/wasm-fs.d.ts +40 -0
- package/dist/runtime/server/og-image/bindings/resvg/wasm-fs.js +6 -0
- package/dist/runtime/server/og-image/bindings/resvg/wasm.d.ts +40 -0
- package/dist/runtime/server/og-image/bindings/resvg/wasm.js +5 -0
- package/dist/runtime/server/og-image/bindings/satori/node.d.ts +6 -0
- package/dist/runtime/server/og-image/bindings/satori/node.js +5 -0
- package/dist/runtime/server/og-image/bindings/satori/wasm-fs.d.ts +6 -0
- package/dist/runtime/server/og-image/bindings/satori/wasm-fs.js +13 -0
- package/dist/runtime/server/og-image/bindings/satori/wasm.d.ts +6 -0
- package/dist/runtime/server/og-image/bindings/satori/wasm.js +13 -0
- package/dist/runtime/server/og-image/bindings/sharp/node.d.ts +2 -0
- package/dist/runtime/server/og-image/bindings/sharp/node.js +2 -0
- package/dist/runtime/server/og-image/cache/lru.d.ts +9 -0
- package/dist/runtime/server/og-image/cache/lru.js +15 -0
- package/dist/runtime/server/og-image/cache/mock.d.ts +9 -0
- package/dist/runtime/server/og-image/cache/mock.js +9 -0
- package/dist/runtime/server/og-image/chromium/renderer.d.ts +3 -0
- package/dist/runtime/server/og-image/chromium/renderer.js +24 -0
- package/dist/runtime/server/og-image/chromium/screenshot.d.ts +4 -0
- package/dist/runtime/server/og-image/chromium/screenshot.js +54 -0
- package/dist/runtime/server/og-image/context.d.ts +5 -0
- package/dist/runtime/server/og-image/context.js +283 -0
- package/dist/runtime/server/og-image/instances.d.ts +2 -0
- package/dist/runtime/server/og-image/instances.js +10 -0
- package/dist/runtime/server/og-image/satori/font.d.ts +3 -0
- package/dist/runtime/server/og-image/satori/font.js +40 -0
- package/dist/runtime/server/og-image/satori/instances.d.ts +41 -0
- package/dist/runtime/server/og-image/satori/instances.js +23 -0
- package/dist/runtime/server/og-image/satori/plugins/classes.d.ts +2 -0
- package/dist/runtime/server/og-image/satori/plugins/classes.js +17 -0
- package/dist/runtime/server/og-image/satori/plugins/emojis.d.ts +2 -0
- package/dist/runtime/server/og-image/satori/plugins/emojis.js +28 -0
- package/dist/runtime/server/og-image/satori/plugins/encoding.d.ts +2 -0
- package/dist/runtime/server/og-image/satori/plugins/encoding.js +17 -0
- package/dist/runtime/server/og-image/satori/plugins/flex.d.ts +2 -0
- package/dist/runtime/server/og-image/satori/plugins/flex.js +60 -0
- package/dist/runtime/server/og-image/satori/plugins/imageSrc.d.ts +2 -0
- package/dist/runtime/server/og-image/satori/plugins/imageSrc.js +107 -0
- package/dist/runtime/server/og-image/satori/plugins/nuxt-icon.d.ts +2 -0
- package/dist/runtime/server/og-image/satori/plugins/nuxt-icon.js +20 -0
- package/dist/runtime/server/og-image/satori/plugins/unocss.d.ts +2 -0
- package/dist/runtime/server/og-image/satori/plugins/unocss.js +55 -0
- package/dist/runtime/server/og-image/satori/renderer.d.ts +4 -0
- package/dist/runtime/server/og-image/satori/renderer.js +123 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis.d.ts +3 -0
- package/dist/runtime/server/og-image/satori/transforms/emojis.js +3595 -0
- package/dist/runtime/server/og-image/satori/transforms/inlineCss.d.ts +3 -0
- package/dist/runtime/server/og-image/satori/transforms/inlineCss.js +51 -0
- package/dist/runtime/server/og-image/satori/utils.d.ts +3 -0
- package/dist/runtime/server/og-image/satori/utils.js +24 -0
- package/dist/runtime/server/og-image/satori/vnodes.d.ts +2 -0
- package/dist/runtime/server/og-image/satori/vnodes.js +40 -0
- package/dist/runtime/server/og-image/templates/html.d.ts +2 -0
- package/dist/runtime/server/og-image/templates/html.js +112 -0
- package/dist/runtime/server/plugins/__zero-runtime/nuxt-content-v2.d.ts +2 -0
- package/dist/runtime/server/plugins/__zero-runtime/nuxt-content-v2.js +9 -0
- package/dist/runtime/server/plugins/nuxt-content-v2.d.ts +2 -0
- package/dist/runtime/server/plugins/nuxt-content-v2.js +5 -0
- package/dist/runtime/server/plugins/prerender.d.ts +2 -0
- package/dist/runtime/server/plugins/prerender.js +38 -0
- package/dist/runtime/server/routes/__zero-runtime/font.d.ts +2 -0
- package/dist/runtime/server/routes/__zero-runtime/font.js +8 -0
- package/dist/runtime/server/routes/__zero-runtime/image.d.ts +2 -0
- package/dist/runtime/server/routes/__zero-runtime/image.js +8 -0
- package/dist/runtime/server/routes/debug.json.d.ts +7 -0
- package/dist/runtime/server/routes/debug.json.js +15 -0
- package/dist/runtime/server/routes/font.d.ts +2 -0
- package/dist/runtime/server/routes/font.js +3 -0
- package/dist/runtime/server/routes/image.d.ts +2 -0
- package/dist/runtime/server/routes/image.js +3 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/util/cache.d.ts +10 -0
- package/dist/runtime/server/util/cache.js +74 -0
- package/dist/runtime/server/util/encoding.d.ts +3 -0
- package/dist/runtime/server/util/encoding.js +15 -0
- package/dist/runtime/server/util/eventHandlers.d.ts +3 -0
- package/dist/runtime/server/util/eventHandlers.js +156 -0
- package/dist/runtime/server/util/kit.d.ts +6 -0
- package/dist/runtime/server/util/kit.js +32 -0
- package/dist/runtime/server/util/logger.d.ts +1 -0
- package/dist/runtime/server/util/logger.js +6 -0
- package/dist/runtime/server/util/options.d.ts +2 -0
- package/dist/runtime/server/util/options.js +18 -0
- package/dist/runtime/server/util/plugins.d.ts +2 -0
- package/dist/runtime/server/util/plugins.js +56 -0
- package/dist/runtime/server/util/wasm.d.ts +2 -0
- package/dist/runtime/server/util/wasm.js +16 -0
- package/dist/runtime/server/utils.d.ts +4 -0
- package/dist/runtime/server/utils.js +20 -0
- package/dist/runtime/shared.d.ts +15 -0
- package/dist/runtime/shared.js +132 -0
- package/dist/runtime/types.d.ts +187 -0
- package/dist/runtime/types.js +0 -0
- package/dist/types.d.mts +9 -0
- package/package.json +32 -32
package/dist/module.cjs
ADDED
|
@@ -0,0 +1,1027 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const promises = require('node:fs/promises');
|
|
5
|
+
const kit = require('@nuxt/kit');
|
|
6
|
+
const defu = require('defu');
|
|
7
|
+
const kit$1 = require('nuxt-site-config/kit');
|
|
8
|
+
const ohash = require('ohash');
|
|
9
|
+
const pathe = require('pathe');
|
|
10
|
+
const pkgTypes = require('pkg-types');
|
|
11
|
+
const stdEnv = require('std-env');
|
|
12
|
+
const ufo = require('ufo');
|
|
13
|
+
const unstorage = require('unstorage');
|
|
14
|
+
const fsDriver = require('unstorage/drivers/fs');
|
|
15
|
+
const node_crypto = require('node:crypto');
|
|
16
|
+
const nypm = require('nypm');
|
|
17
|
+
const chromeLauncher = require('chrome-launcher');
|
|
18
|
+
const ofetch = require('ofetch');
|
|
19
|
+
const node_path = require('node:path');
|
|
20
|
+
const devtoolsKit = require('@nuxt/devtools-kit');
|
|
21
|
+
const node_url = require('node:url');
|
|
22
|
+
const MagicString = require('magic-string');
|
|
23
|
+
const stripLiteral = require('strip-literal');
|
|
24
|
+
const unplugin = require('unplugin');
|
|
25
|
+
const logger_js = require('../dist/runtime/logger.js');
|
|
26
|
+
|
|
27
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
28
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
29
|
+
|
|
30
|
+
function _interopNamespaceCompat(e) {
|
|
31
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
32
|
+
const n = Object.create(null);
|
|
33
|
+
if (e) {
|
|
34
|
+
for (const k in e) {
|
|
35
|
+
n[k] = e[k];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
n.default = e;
|
|
39
|
+
return n;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
|
|
43
|
+
const fsDriver__default = /*#__PURE__*/_interopDefaultCompat(fsDriver);
|
|
44
|
+
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
45
|
+
|
|
46
|
+
const isUndefinedOrTruthy = (v) => typeof v === "undefined" || v !== false;
|
|
47
|
+
function checkLocalChrome() {
|
|
48
|
+
if (stdEnv.isCI)
|
|
49
|
+
return false;
|
|
50
|
+
let hasChromeLocally = false;
|
|
51
|
+
try {
|
|
52
|
+
hasChromeLocally = !!chromeLauncher.Launcher.getFirstInstallation();
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
return hasChromeLocally;
|
|
56
|
+
}
|
|
57
|
+
async function hasResolvableDependency(dep) {
|
|
58
|
+
return await kit.resolvePath(dep, { fallbackToOriginal: true }).catch(() => null).then((r) => r && r !== dep);
|
|
59
|
+
}
|
|
60
|
+
async function downloadFont(font, storage, mirror) {
|
|
61
|
+
const { name, weight, style } = font;
|
|
62
|
+
const key = `${name}-${style}-${weight}.ttf.base64`;
|
|
63
|
+
if (await storage.hasItem(key))
|
|
64
|
+
return { success: true };
|
|
65
|
+
const host = typeof mirror === "undefined" ? "fonts.googleapis.com" : mirror === true ? "fonts.font.im" : mirror;
|
|
66
|
+
const cssUrl = `https://${host}/css2?family=${name}:${style === "ital" ? `ital,wght@1,${weight}` : `wght@${weight}`}`;
|
|
67
|
+
const css = await ofetch.$fetch(cssUrl, {
|
|
68
|
+
timeout: 10 * 1e3,
|
|
69
|
+
// 10 second timeout
|
|
70
|
+
headers: {
|
|
71
|
+
// Make sure it returns TTF.
|
|
72
|
+
"User-Agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
|
|
73
|
+
}
|
|
74
|
+
}).catch((err) => {
|
|
75
|
+
return { error: err };
|
|
76
|
+
});
|
|
77
|
+
if (!css || typeof css !== "string")
|
|
78
|
+
return { success: false, error: css?.error || new Error(`Failed to fetch CSS from ${cssUrl}`), host };
|
|
79
|
+
const ttfResource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/);
|
|
80
|
+
if (ttfResource?.[1]) {
|
|
81
|
+
const buf = await ofetch.$fetch(ttfResource[1], { responseType: "arrayBuffer" }).catch((err) => {
|
|
82
|
+
return { error: err };
|
|
83
|
+
});
|
|
84
|
+
if (buf && "error" in buf)
|
|
85
|
+
return { success: false, error: buf.error, host, fontUrl: ttfResource[1] };
|
|
86
|
+
const base64Font = Buffer.from(buf).toString("base64");
|
|
87
|
+
await storage.setItem(key, base64Font);
|
|
88
|
+
return { success: true };
|
|
89
|
+
}
|
|
90
|
+
return { success: false, error: new Error("No TTF resource found in CSS response"), host };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const autodetectableProviders = {
|
|
94
|
+
azure_static: "azure",
|
|
95
|
+
cloudflare_pages: "cloudflare-pages",
|
|
96
|
+
netlify: "netlify",
|
|
97
|
+
stormkit: "stormkit",
|
|
98
|
+
vercel: "vercel",
|
|
99
|
+
cleavr: "cleavr",
|
|
100
|
+
stackblitz: "stackblitz"
|
|
101
|
+
};
|
|
102
|
+
const autodetectableStaticProviders = {
|
|
103
|
+
netlify: "netlify-static",
|
|
104
|
+
vercel: "vercel-static"
|
|
105
|
+
};
|
|
106
|
+
const NodeRuntime = {
|
|
107
|
+
// node-server runtime
|
|
108
|
+
"chromium": "on-demand",
|
|
109
|
+
// this gets changed build start
|
|
110
|
+
"css-inline": "node",
|
|
111
|
+
"resvg": "node",
|
|
112
|
+
"satori": "node",
|
|
113
|
+
"sharp": "node"
|
|
114
|
+
// will be disabled if they're missing the dependency
|
|
115
|
+
};
|
|
116
|
+
const cloudflare = {
|
|
117
|
+
"chromium": false,
|
|
118
|
+
"css-inline": false,
|
|
119
|
+
"resvg": "wasm",
|
|
120
|
+
"satori": "node",
|
|
121
|
+
"sharp": false,
|
|
122
|
+
"wasm": {
|
|
123
|
+
esmImport: true,
|
|
124
|
+
lazy: true
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const awsLambda = {
|
|
128
|
+
"chromium": false,
|
|
129
|
+
"css-inline": "wasm",
|
|
130
|
+
"resvg": "node",
|
|
131
|
+
"satori": "node",
|
|
132
|
+
"sharp": false
|
|
133
|
+
// 0.33.x has issues
|
|
134
|
+
};
|
|
135
|
+
const WebContainer = {
|
|
136
|
+
"chromium": false,
|
|
137
|
+
"css-inline": "wasm-fs",
|
|
138
|
+
"resvg": "wasm-fs",
|
|
139
|
+
"satori": "wasm-fs",
|
|
140
|
+
"sharp": false
|
|
141
|
+
};
|
|
142
|
+
const RuntimeCompatibility = {
|
|
143
|
+
"nitro-dev": NodeRuntime,
|
|
144
|
+
"nitro-prerender": NodeRuntime,
|
|
145
|
+
"node-server": NodeRuntime,
|
|
146
|
+
"stackblitz": WebContainer,
|
|
147
|
+
"codesandbox": WebContainer,
|
|
148
|
+
"aws-lambda": awsLambda,
|
|
149
|
+
"netlify": awsLambda,
|
|
150
|
+
"netlify-edge": {
|
|
151
|
+
"chromium": false,
|
|
152
|
+
"css-inline": "wasm",
|
|
153
|
+
"resvg": "wasm",
|
|
154
|
+
"satori": "node",
|
|
155
|
+
"sharp": false,
|
|
156
|
+
"wasm": {
|
|
157
|
+
// @ts-expect-error untyped
|
|
158
|
+
rollup: {
|
|
159
|
+
targetEnv: "auto-inline",
|
|
160
|
+
sync: ["@resvg/resvg-wasm/index_bg.wasm"]
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"firebase": awsLambda,
|
|
165
|
+
"vercel": awsLambda,
|
|
166
|
+
"vercel-edge": {
|
|
167
|
+
"chromium": false,
|
|
168
|
+
"css-inline": false,
|
|
169
|
+
// size constraint (2mb is max)
|
|
170
|
+
"resvg": "wasm",
|
|
171
|
+
"satori": "node",
|
|
172
|
+
"sharp": false,
|
|
173
|
+
"wasm": {
|
|
174
|
+
// lowers workers kb size
|
|
175
|
+
esmImport: true,
|
|
176
|
+
lazy: true
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
"cloudflare-pages": cloudflare,
|
|
180
|
+
"cloudflare": cloudflare,
|
|
181
|
+
"cloudflare-module": cloudflare
|
|
182
|
+
};
|
|
183
|
+
function detectTarget(options = {}) {
|
|
184
|
+
return options?.static ? autodetectableStaticProviders[stdEnv.provider] : autodetectableProviders[stdEnv.provider];
|
|
185
|
+
}
|
|
186
|
+
function resolveNitroPreset(nitroConfig) {
|
|
187
|
+
if (stdEnv.provider === "stackblitz" || stdEnv.provider === "codesandbox")
|
|
188
|
+
return stdEnv.provider;
|
|
189
|
+
const nuxt = kit.useNuxt();
|
|
190
|
+
if (nuxt.options.dev)
|
|
191
|
+
return "nitro-dev";
|
|
192
|
+
if (nuxt.options._generate || nuxt.options.nitro.static)
|
|
193
|
+
return "nitro-prerender";
|
|
194
|
+
let preset;
|
|
195
|
+
if (nitroConfig && nitroConfig?.preset)
|
|
196
|
+
preset = nitroConfig.preset;
|
|
197
|
+
if (!preset)
|
|
198
|
+
preset = stdEnv.env.NITRO_PRESET || stdEnv.env.SERVER_PRESET || detectTarget() || "node-server";
|
|
199
|
+
return preset.replace("_", "-");
|
|
200
|
+
}
|
|
201
|
+
function getPresetNitroPresetCompatibility(target) {
|
|
202
|
+
let compatibility = RuntimeCompatibility[target];
|
|
203
|
+
if (!compatibility)
|
|
204
|
+
compatibility = RuntimeCompatibility["nitro-dev"];
|
|
205
|
+
return compatibility;
|
|
206
|
+
}
|
|
207
|
+
async function applyNitroPresetCompatibility(nitroConfig, options) {
|
|
208
|
+
const target = resolveNitroPreset(nitroConfig);
|
|
209
|
+
const compatibility = getPresetNitroPresetCompatibility(target);
|
|
210
|
+
const hasCssInlineNode = await hasResolvableDependency("@css-inline/css-inline");
|
|
211
|
+
const hasCssInlineWasm = await hasResolvableDependency("@css-inline/css-inline-wasm");
|
|
212
|
+
const { resolve } = options;
|
|
213
|
+
const satoriEnabled = typeof options.compatibility?.satori !== "undefined" ? !!options.compatibility.satori : !!compatibility.satori;
|
|
214
|
+
const chromiumEnabled = typeof options.compatibility?.chromium !== "undefined" ? !!options.compatibility.chromium : !!compatibility.chromium;
|
|
215
|
+
const emptyMock = await resolve.resolvePath("./runtime/mock/empty");
|
|
216
|
+
nitroConfig.alias["#og-image/renderers/satori"] = satoriEnabled ? await resolve.resolvePath("./runtime/server/og-image/satori/renderer") : emptyMock;
|
|
217
|
+
nitroConfig.alias["#og-image/renderers/chromium"] = chromiumEnabled ? await resolve.resolvePath("./runtime/server/og-image/chromium/renderer") : emptyMock;
|
|
218
|
+
const resolvedCompatibility = {};
|
|
219
|
+
async function applyBinding(key) {
|
|
220
|
+
let binding = options.compatibility?.[key];
|
|
221
|
+
if (typeof binding === "undefined")
|
|
222
|
+
binding = compatibility[key];
|
|
223
|
+
if (key === "chromium" && binding === "node")
|
|
224
|
+
binding = "playwright";
|
|
225
|
+
if (key === "css-inline" && typeof binding === "string") {
|
|
226
|
+
if (binding === "node" && !hasCssInlineNode || ["wasm", "wasm-fs"].includes(binding) && !hasCssInlineWasm) {
|
|
227
|
+
binding = false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
resolvedCompatibility[key] = binding;
|
|
231
|
+
return {
|
|
232
|
+
[`#og-image/bindings/${key}`]: binding === false ? emptyMock : await resolve.resolvePath(`./runtime/server/og-image/bindings/${key}/${binding}`)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
nitroConfig.alias = defu.defu(
|
|
236
|
+
await applyBinding("chromium"),
|
|
237
|
+
await applyBinding("satori"),
|
|
238
|
+
await applyBinding("resvg"),
|
|
239
|
+
await applyBinding("sharp"),
|
|
240
|
+
await applyBinding("css-inline"),
|
|
241
|
+
nitroConfig.alias || {}
|
|
242
|
+
);
|
|
243
|
+
if (Object.values(compatibility).includes("wasm")) {
|
|
244
|
+
nitroConfig.experimental = nitroConfig.experimental || {};
|
|
245
|
+
nitroConfig.experimental.wasm = true;
|
|
246
|
+
}
|
|
247
|
+
nitroConfig.rollupConfig = nitroConfig.rollupConfig || {};
|
|
248
|
+
nitroConfig.wasm = defu.defu(compatibility.wasm, nitroConfig.wasm);
|
|
249
|
+
nitroConfig.virtual["#og-image/compatibility"] = () => `export default ${JSON.stringify(resolvedCompatibility)}`;
|
|
250
|
+
kit.addTemplate({
|
|
251
|
+
filename: "nuxt-og-image/compatibility.mjs",
|
|
252
|
+
getContents() {
|
|
253
|
+
return `export default ${JSON.stringify(resolvedCompatibility)}`;
|
|
254
|
+
},
|
|
255
|
+
options: { mode: "server" }
|
|
256
|
+
});
|
|
257
|
+
return resolvedCompatibility;
|
|
258
|
+
}
|
|
259
|
+
function ensureDependencies(dep, nuxt = kit.useNuxt()) {
|
|
260
|
+
return Promise.all(dep.map((d) => {
|
|
261
|
+
return nypm.ensureDependencyInstalled(d, {
|
|
262
|
+
cwd: nuxt.options.rootDir,
|
|
263
|
+
dev: true
|
|
264
|
+
});
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function setupBuildHandler(config, resolve, nuxt = kit.useNuxt()) {
|
|
269
|
+
nuxt.options.nitro.storage = nuxt.options.nitro.storage || {};
|
|
270
|
+
if (typeof config.runtimeCacheStorage === "object")
|
|
271
|
+
nuxt.options.nitro.storage["og-image"] = config.runtimeCacheStorage;
|
|
272
|
+
const proxyCjs = await resolve.resolvePath("./runtime/mock/proxy-cjs");
|
|
273
|
+
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
274
|
+
await applyNitroPresetCompatibility(nitroConfig, { compatibility: config.compatibility?.runtime, resolve });
|
|
275
|
+
nitroConfig.alias.electron = proxyCjs;
|
|
276
|
+
nitroConfig.alias.bufferutil = proxyCjs;
|
|
277
|
+
nitroConfig.alias["utf-8-validate"] = proxyCjs;
|
|
278
|
+
nitroConfig.alias.queue = proxyCjs;
|
|
279
|
+
nitroConfig.alias["chromium-bidi"] = proxyCjs;
|
|
280
|
+
});
|
|
281
|
+
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
282
|
+
const target = resolveNitroPreset(nitro.options);
|
|
283
|
+
const isCloudflarePagesOrModule = target === "cloudflare-pages" || target === "cloudflare-module";
|
|
284
|
+
if (isCloudflarePagesOrModule) {
|
|
285
|
+
nitro.options.cloudflare = nitro.options.cloudflare || {};
|
|
286
|
+
nitro.options.cloudflare.pages = nitro.options.cloudflare.pages || {};
|
|
287
|
+
nitro.options.cloudflare.pages.routes = nitro.options.cloudflare.pages.routes || { exclude: [] };
|
|
288
|
+
nitro.options.cloudflare.pages.routes.exclude = nitro.options.cloudflare.pages.routes.exclude || [];
|
|
289
|
+
nitro.options.cloudflare.pages.routes.exclude.push("/__og-image__/static/*");
|
|
290
|
+
}
|
|
291
|
+
nitro.hooks.hook("compiled", async (_nitro) => {
|
|
292
|
+
const compatibility = getPresetNitroPresetCompatibility(target);
|
|
293
|
+
if (compatibility.wasm?.esmImport !== true)
|
|
294
|
+
return;
|
|
295
|
+
const configuredEntry = nitro.options.rollupConfig?.output.entryFileNames;
|
|
296
|
+
const serverEntry = resolve.resolve(_nitro.options.output.serverDir, typeof configuredEntry === "string" ? configuredEntry : "index.mjs");
|
|
297
|
+
const wasmEntries = [serverEntry];
|
|
298
|
+
if (isCloudflarePagesOrModule) {
|
|
299
|
+
wasmEntries.push(resolve.resolve(pathe.dirname(serverEntry), "./chunks/wasm.mjs"));
|
|
300
|
+
wasmEntries.push(resolve.resolve(pathe.dirname(serverEntry), "./chunks/_/wasm.mjs"));
|
|
301
|
+
wasmEntries.push(resolve.resolve(pathe.dirname(serverEntry), "./chunks/index_bg.mjs"));
|
|
302
|
+
}
|
|
303
|
+
const resvgHash = await resolveFilePathSha1("@resvg/resvg-wasm/index_bg.wasm");
|
|
304
|
+
const yogaHash = await resolveFilePathSha1("yoga-wasm-web/dist/yoga.wasm");
|
|
305
|
+
const cssInlineHash = await resolveFilePathSha1("@css-inline/css-inline-wasm/index_bg.wasm");
|
|
306
|
+
for (const entry of wasmEntries) {
|
|
307
|
+
if (!fs.existsSync(entry))
|
|
308
|
+
continue;
|
|
309
|
+
const contents = await promises.readFile(serverEntry, "utf-8");
|
|
310
|
+
const postfix = target === "vercel-edge" ? "?module" : "";
|
|
311
|
+
const path = isCloudflarePagesOrModule ? `../wasm/` : `./wasm/`;
|
|
312
|
+
await promises.writeFile(serverEntry, contents.replaceAll('"@resvg/resvg-wasm/index_bg.wasm?module"', `"${path}index_bg-${resvgHash}.wasm${postfix}"`).replaceAll('"@css-inline/css-inline-wasm/index_bg.wasm?module"', `"${path}index_bg-${cssInlineHash}.wasm${postfix}"`).replaceAll('"yoga-wasm-web/dist/yoga.wasm?module"', `"${path}yoga-${yogaHash}.wasm${postfix}"`), { encoding: "utf-8" });
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
async function resolveFilePathSha1(path) {
|
|
318
|
+
const _path = await kit.resolvePath(path);
|
|
319
|
+
return sha1(fs.existsSync(_path) ? await promises.readFile(_path) : Buffer.from(path));
|
|
320
|
+
}
|
|
321
|
+
function sha1(source) {
|
|
322
|
+
return node_crypto.createHash("sha1").update(source).digest("hex").slice(0, 16);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function setupDevHandler(options, resolve, nuxt = kit.useNuxt()) {
|
|
326
|
+
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
327
|
+
await applyNitroPresetCompatibility(nitroConfig, { compatibility: options.compatibility?.dev, resolve });
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const DEVTOOLS_UI_ROUTE = "/__nuxt-og-image";
|
|
332
|
+
const DEVTOOLS_UI_LOCAL_PORT = 3030;
|
|
333
|
+
function setupDevToolsUI(options, resolve, nuxt = kit.useNuxt()) {
|
|
334
|
+
const clientPath = resolve("./client");
|
|
335
|
+
const isProductionBuild = fs.existsSync(clientPath);
|
|
336
|
+
if (isProductionBuild) {
|
|
337
|
+
nuxt.hook("vite:serverCreated", async (server) => {
|
|
338
|
+
const sirv = await import('sirv').then((r) => r.default || r);
|
|
339
|
+
server.middlewares.use(
|
|
340
|
+
DEVTOOLS_UI_ROUTE,
|
|
341
|
+
sirv(clientPath, { dev: true, single: true })
|
|
342
|
+
);
|
|
343
|
+
});
|
|
344
|
+
} else {
|
|
345
|
+
nuxt.hook("vite:extendConfig", (config) => {
|
|
346
|
+
config.server = config.server || {};
|
|
347
|
+
config.server.proxy = config.server.proxy || {};
|
|
348
|
+
config.server.proxy[DEVTOOLS_UI_ROUTE] = {
|
|
349
|
+
target: `http://localhost:${DEVTOOLS_UI_LOCAL_PORT}${DEVTOOLS_UI_ROUTE}`,
|
|
350
|
+
changeOrigin: true,
|
|
351
|
+
followRedirects: true,
|
|
352
|
+
rewrite: (path) => path.replace(DEVTOOLS_UI_ROUTE, "")
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
const useNitro = new Promise((resolve2) => {
|
|
357
|
+
nuxt.hooks.hook("nitro:init", resolve2);
|
|
358
|
+
});
|
|
359
|
+
devtoolsKit.onDevToolsInitialized(async () => {
|
|
360
|
+
const rpc = devtoolsKit.extendServerRpc("nuxt-og-image", {
|
|
361
|
+
async ejectCommunityTemplate(path) {
|
|
362
|
+
const [dirName, componentName] = path.split("/");
|
|
363
|
+
const dir = resolve(nuxt.options.rootDir, "components", dirName || "");
|
|
364
|
+
if (!fs.existsSync(dir)) {
|
|
365
|
+
fs.mkdirSync(dir);
|
|
366
|
+
}
|
|
367
|
+
const newPath = resolve(dir, componentName || "");
|
|
368
|
+
const templatePath = resolve(`./runtime/app/components/Templates/Community/${componentName}`);
|
|
369
|
+
const template = (await promises.readFile(templatePath, "utf-8")).replace("{{ title }}", `{{ title }} - Ejected!`);
|
|
370
|
+
await promises.writeFile(newPath, template, { encoding: "utf-8" });
|
|
371
|
+
await kit.updateTemplates({ filter: (t) => t.filename.includes("nuxt-og-image/components.mjs") });
|
|
372
|
+
const nitro = await useNitro;
|
|
373
|
+
await nitro.hooks.callHook("rollup:reload");
|
|
374
|
+
return newPath;
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
nuxt.hook("builder:watch", (e, path) => {
|
|
378
|
+
path = node_path.relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, path));
|
|
379
|
+
if ((e === "change" || e.includes("link")) && (path.startsWith("pages") || path.startsWith("content"))) {
|
|
380
|
+
rpc.broadcast.refreshRouteData(path).catch(() => {
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
if (options.componentDirs.some((dir) => path.includes(dir))) {
|
|
384
|
+
if (e === "change") {
|
|
385
|
+
rpc.broadcast.refresh().catch(() => {
|
|
386
|
+
});
|
|
387
|
+
} else {
|
|
388
|
+
rpc.broadcast.refreshGlobalData().catch(() => {
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
nuxt.hook("devtools:customTabs", (tabs) => {
|
|
395
|
+
tabs.push({
|
|
396
|
+
// unique identifier
|
|
397
|
+
name: "nuxt-og-image",
|
|
398
|
+
// title to display in the tab
|
|
399
|
+
title: "OG Image",
|
|
400
|
+
// any icon from Iconify, or a URL to an image
|
|
401
|
+
icon: "carbon:image-search",
|
|
402
|
+
// iframe view
|
|
403
|
+
view: {
|
|
404
|
+
type: "iframe",
|
|
405
|
+
src: DEVTOOLS_UI_ROUTE
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function setupGenerateHandler(options, resolve, nuxt = kit.useNuxt()) {
|
|
412
|
+
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
413
|
+
await applyNitroPresetCompatibility(nitroConfig, {
|
|
414
|
+
compatibility: {
|
|
415
|
+
"chromium": false,
|
|
416
|
+
"satori": false,
|
|
417
|
+
"css-inline": false,
|
|
418
|
+
"resvg": false,
|
|
419
|
+
"sharp": false
|
|
420
|
+
},
|
|
421
|
+
resolve
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function setupPrerenderHandler(options, resolve, nuxt = kit.useNuxt()) {
|
|
427
|
+
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
428
|
+
nitro.hooks.hook("prerender:config", async (nitroConfig) => {
|
|
429
|
+
await applyNitroPresetCompatibility(nitroConfig, { compatibility: options.compatibility?.prerender, resolve });
|
|
430
|
+
nitroConfig.wasm = nitroConfig.wasm || {};
|
|
431
|
+
nitroConfig.wasm.esmImport = false;
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function isVue(id, opts = {}) {
|
|
437
|
+
const { search } = ufo.parseURL(decodeURIComponent(node_url.pathToFileURL(id).href));
|
|
438
|
+
if (id.endsWith(".vue") && !search) {
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
if (!search) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
const query = ufo.parseQuery(search);
|
|
445
|
+
if (query.nuxt_component) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
if (query.macro && (search === "?macro=true" || !opts.type || opts.type.includes("script"))) {
|
|
449
|
+
return true;
|
|
450
|
+
}
|
|
451
|
+
const type = "setup" in query ? "script" : query.type;
|
|
452
|
+
if (!("vue" in query) || opts.type && !opts.type.includes(type)) {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
const JS_RE = /\.(?:[cm]?j|t)sx?$/;
|
|
458
|
+
function isJS(id) {
|
|
459
|
+
const { pathname } = ufo.parseURL(decodeURIComponent(node_url.pathToFileURL(id).href));
|
|
460
|
+
return JS_RE.test(pathname);
|
|
461
|
+
}
|
|
462
|
+
const TreeShakeComposablesPlugin = unplugin.createUnplugin(() => {
|
|
463
|
+
const composableNames = [
|
|
464
|
+
"defineOgImage",
|
|
465
|
+
"defineOgImageComponent",
|
|
466
|
+
"defineOgImageScreenshot"
|
|
467
|
+
];
|
|
468
|
+
const regexp = `(^\\s*)(${composableNames.join("|")})(?=\\((?!\\) \\{))`;
|
|
469
|
+
const COMPOSABLE_RE = new RegExp(regexp, "m");
|
|
470
|
+
const COMPOSABLE_RE_GLOBAL = new RegExp(regexp, "gm");
|
|
471
|
+
return {
|
|
472
|
+
name: "nuxt-og-image:zero-runtime:transform",
|
|
473
|
+
enforce: "pre",
|
|
474
|
+
transformInclude(id) {
|
|
475
|
+
return isVue(id, { type: ["script"] }) || isJS(id);
|
|
476
|
+
},
|
|
477
|
+
transform(code, id) {
|
|
478
|
+
const s = new MagicString__default(code);
|
|
479
|
+
if (id.endsWith("components.islands.mjs")) ; else {
|
|
480
|
+
const strippedCode = stripLiteral.stripLiteral(code);
|
|
481
|
+
if (!COMPOSABLE_RE.test(code)) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
for (const match of strippedCode.matchAll(COMPOSABLE_RE_GLOBAL)) {
|
|
485
|
+
s.overwrite(match.index, match.index + match[0].length, `${match[1]} import.meta.prerender && ${match[2]}`);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (s.hasChanged()) {
|
|
489
|
+
return {
|
|
490
|
+
code: s.toString(),
|
|
491
|
+
map: s.generateMap({ hires: true })
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
async function getNuxtModuleOptions(module, nuxt = kit.useNuxt()) {
|
|
499
|
+
const moduleMeta = ({ name: module } ) || {};
|
|
500
|
+
const { nuxtModule } = await kit.loadNuxtModuleInstance(module, nuxt);
|
|
501
|
+
let moduleEntry;
|
|
502
|
+
for (const m of nuxt.options.modules) {
|
|
503
|
+
if (Array.isArray(m) && m.length >= 2) {
|
|
504
|
+
const _module = m[0];
|
|
505
|
+
const _moduleEntryName = typeof _module === "string" ? _module : (await _module.getMeta?.())?.name || "";
|
|
506
|
+
if (_moduleEntryName === moduleMeta.name)
|
|
507
|
+
moduleEntry = m;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
let inlineOptions = {};
|
|
511
|
+
if (moduleEntry)
|
|
512
|
+
inlineOptions = moduleEntry[1];
|
|
513
|
+
if (nuxtModule.getOptions)
|
|
514
|
+
return nuxtModule.getOptions(inlineOptions, nuxt);
|
|
515
|
+
return inlineOptions;
|
|
516
|
+
}
|
|
517
|
+
function isNuxtGenerate(nuxt = kit.useNuxt()) {
|
|
518
|
+
return nuxt.options._generate || nuxt.options.nitro.static || nuxt.options.nitro.preset === "static";
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function normaliseFontInput(fonts) {
|
|
522
|
+
return fonts.map((f) => {
|
|
523
|
+
if (typeof f === "string") {
|
|
524
|
+
const vals = f.split(":");
|
|
525
|
+
const includesStyle = vals.length === 3;
|
|
526
|
+
let name, weight, style;
|
|
527
|
+
if (includesStyle) {
|
|
528
|
+
name = vals[0];
|
|
529
|
+
style = vals[1];
|
|
530
|
+
weight = vals[2];
|
|
531
|
+
} else {
|
|
532
|
+
name = vals[0];
|
|
533
|
+
weight = vals[1];
|
|
534
|
+
}
|
|
535
|
+
return {
|
|
536
|
+
cacheKey: f,
|
|
537
|
+
name,
|
|
538
|
+
weight: weight || 400,
|
|
539
|
+
style: style || "normal",
|
|
540
|
+
path: void 0
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
return {
|
|
544
|
+
cacheKey: f.key || `${f.name}:${f.style}:${f.weight}`,
|
|
545
|
+
style: "normal",
|
|
546
|
+
weight: 400,
|
|
547
|
+
...f
|
|
548
|
+
};
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
const IS_MODULE_DEVELOPMENT = undefined.endsWith(".ts");
|
|
553
|
+
function isProviderEnabledForEnv(provider, nuxt, config) {
|
|
554
|
+
return nuxt.options.dev && config.compatibility?.dev?.[provider] !== false || !nuxt.options.dev && (config.compatibility?.runtime?.[provider] !== false || config.compatibility?.prerender?.[provider] !== false);
|
|
555
|
+
}
|
|
556
|
+
const defaultComponentDirs = ["OgImage", "og-image", "OgImageTemplate"];
|
|
557
|
+
const module$1 = kit.defineNuxtModule({
|
|
558
|
+
meta: {
|
|
559
|
+
name: "nuxt-og-image",
|
|
560
|
+
compatibility: {
|
|
561
|
+
nuxt: ">=3.16.0"
|
|
562
|
+
},
|
|
563
|
+
configKey: "ogImage"
|
|
564
|
+
},
|
|
565
|
+
defaults() {
|
|
566
|
+
return {
|
|
567
|
+
enabled: true,
|
|
568
|
+
defaults: {
|
|
569
|
+
emojis: "noto",
|
|
570
|
+
renderer: "satori",
|
|
571
|
+
component: "NuxtSeo",
|
|
572
|
+
extension: "png",
|
|
573
|
+
width: 1200,
|
|
574
|
+
height: 600,
|
|
575
|
+
// default is to cache the image for 3 day (72 hours)
|
|
576
|
+
cacheMaxAgeSeconds: 60 * 60 * 24 * 3
|
|
577
|
+
},
|
|
578
|
+
componentDirs: defaultComponentDirs,
|
|
579
|
+
fonts: [],
|
|
580
|
+
runtimeCacheStorage: true,
|
|
581
|
+
debug: stdEnv.isDevelopment
|
|
582
|
+
};
|
|
583
|
+
},
|
|
584
|
+
async setup(config, nuxt) {
|
|
585
|
+
const resolver = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
|
|
586
|
+
const { resolve } = resolver;
|
|
587
|
+
const { version } = await pkgTypes.readPackageJSON(resolve("../package.json"));
|
|
588
|
+
const userAppPkgJson = await pkgTypes.readPackageJSON(nuxt.options.rootDir).catch(() => ({ dependencies: {}, devDependencies: {} }));
|
|
589
|
+
logger_js.logger.level = config.debug || nuxt.options.debug ? 4 : 3;
|
|
590
|
+
if (config.enabled === false) {
|
|
591
|
+
logger_js.logger.debug("The module is disabled, skipping setup.");
|
|
592
|
+
["defineOgImage", "defineOgImageComponent", "defineOgImageScreenshot"].forEach((name) => {
|
|
593
|
+
kit.addImports({ name, from: resolve(`./runtime/app/composables/mock`) });
|
|
594
|
+
});
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (config.enabled && !nuxt.options.ssr) {
|
|
598
|
+
logger_js.logger.warn("Nuxt OG Image is enabled but SSR is disabled.\n\nYou should enable SSR (`ssr: true`) or disable the module (`ogImage: { enabled: false }`).");
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
nuxt.options.alias["#og-image"] = resolve("./runtime");
|
|
602
|
+
nuxt.options.alias["#og-image-cache"] = resolve("./runtime/server/og-image/cache/lru");
|
|
603
|
+
nuxt.options.alias["#nuxt-og-image-utils"] = resolve("./runtime/shared");
|
|
604
|
+
const preset = resolveNitroPreset(nuxt.options.nitro);
|
|
605
|
+
const targetCompatibility = getPresetNitroPresetCompatibility(preset);
|
|
606
|
+
if (config.zeroRuntime) {
|
|
607
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
608
|
+
runtime: {
|
|
609
|
+
chromium: false,
|
|
610
|
+
// should already be false
|
|
611
|
+
satori: false
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
if (!nuxt.options.dev) {
|
|
615
|
+
kit.addBuildPlugin(TreeShakeComposablesPlugin, { server: true, client: true, build: true });
|
|
616
|
+
nuxt.options.alias["#og-image-cache"] = resolve("./runtime/server/og-image/cache/mock");
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
const basePath = config.zeroRuntime ? "./runtime/server/routes/__zero-runtime" : "./runtime/server/routes";
|
|
620
|
+
let publicDirAbs = nuxt.options.dir.public;
|
|
621
|
+
if (!pathe.isAbsolute(publicDirAbs)) {
|
|
622
|
+
publicDirAbs = (publicDirAbs in nuxt.options.alias ? nuxt.options.alias[publicDirAbs] : resolve(nuxt.options.rootDir, publicDirAbs)) || "";
|
|
623
|
+
}
|
|
624
|
+
if (isProviderEnabledForEnv("satori", nuxt, config)) {
|
|
625
|
+
let attemptSharpUsage = false;
|
|
626
|
+
if (isProviderEnabledForEnv("sharp", nuxt, config)) {
|
|
627
|
+
const userConfiguredExtension = config.defaults.extension;
|
|
628
|
+
const hasConfiguredJpegs = userConfiguredExtension && ["jpeg", "jpg"].includes(userConfiguredExtension);
|
|
629
|
+
const allDeps = {
|
|
630
|
+
...userAppPkgJson.dependencies || {},
|
|
631
|
+
...userAppPkgJson.devDependencies || {}
|
|
632
|
+
};
|
|
633
|
+
const hasExplicitSharpDependency = !!config.sharpOptions || "sharp" in allDeps || hasConfiguredJpegs && config.defaults.renderer !== "chromium";
|
|
634
|
+
if (hasExplicitSharpDependency) {
|
|
635
|
+
if (!targetCompatibility.sharp) {
|
|
636
|
+
logger_js.logger.warn(`Rendering JPEGs requires sharp which does not work with ${preset}. Images will be rendered as PNG at runtime.`);
|
|
637
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
638
|
+
runtime: { sharp: false }
|
|
639
|
+
});
|
|
640
|
+
} else {
|
|
641
|
+
await import('sharp').catch(() => {
|
|
642
|
+
}).then(() => {
|
|
643
|
+
attemptSharpUsage = true;
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
} else if (hasConfiguredJpegs && config.defaults.renderer !== "chromium") {
|
|
647
|
+
logger_js.logger.warn("You have enabled `JPEG` images. These require the `sharp` dependency which is missing, installing it for you.");
|
|
648
|
+
await ensureDependencies(["sharp"]);
|
|
649
|
+
logger_js.logger.warn("Support for `sharp` is limited so check the compatibility guide.");
|
|
650
|
+
attemptSharpUsage = true;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (!attemptSharpUsage) {
|
|
654
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
655
|
+
runtime: { sharp: false },
|
|
656
|
+
dev: { sharp: false },
|
|
657
|
+
prerender: { sharp: false }
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
if (isProviderEnabledForEnv("resvg", nuxt, config)) {
|
|
661
|
+
await import('@resvg/resvg-js').catch(() => {
|
|
662
|
+
logger_js.logger.warn("ReSVG is missing dependencies for environment. Falling back to WASM version, this may slow down PNG rendering.");
|
|
663
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
664
|
+
dev: { resvg: "wasm-fs" },
|
|
665
|
+
prerender: { resvg: "wasm-fs" }
|
|
666
|
+
});
|
|
667
|
+
if (targetCompatibility.resvg === "node") {
|
|
668
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
669
|
+
runtime: { resvg: "wasm" }
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
if (!config.fonts.length) {
|
|
675
|
+
config.fonts = [
|
|
676
|
+
{
|
|
677
|
+
name: "Inter",
|
|
678
|
+
weight: 400,
|
|
679
|
+
path: resolve("./runtime/assets/Inter-normal-400.ttf.base64"),
|
|
680
|
+
absolutePath: true
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
name: "Inter",
|
|
684
|
+
weight: 700,
|
|
685
|
+
path: resolve("./runtime/assets/Inter-normal-700.ttf.base64"),
|
|
686
|
+
absolutePath: true
|
|
687
|
+
}
|
|
688
|
+
];
|
|
689
|
+
}
|
|
690
|
+
const serverFontsDir = resolve(nuxt.options.buildDir, "cache", `nuxt-og-image`, "_fonts");
|
|
691
|
+
const fontStorage = unstorage.createStorage({
|
|
692
|
+
driver: fsDriver__default({
|
|
693
|
+
base: serverFontsDir
|
|
694
|
+
})
|
|
695
|
+
});
|
|
696
|
+
config.fonts = (await Promise.all(normaliseFontInput(config.fonts).map(async (f) => {
|
|
697
|
+
const fontKey = `${f.name}:${f.style}:${f.weight}`;
|
|
698
|
+
const fontFileBase = fontKey.replaceAll(":", "-");
|
|
699
|
+
if (!f.key && !f.path) {
|
|
700
|
+
if (preset === "stackblitz") {
|
|
701
|
+
logger_js.logger.warn(`The ${fontKey} font was skipped because remote fonts are not available in StackBlitz, please use a local font.`);
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
const result = await downloadFont(f, fontStorage, config.googleFontMirror);
|
|
705
|
+
if (result.success) {
|
|
706
|
+
f.key = `nuxt-og-image:fonts:${fontFileBase}.ttf.base64`;
|
|
707
|
+
} else {
|
|
708
|
+
const mirrorMsg = config.googleFontMirror ? `using mirror host \`${result.host}\`` : "Consider setting `googleFontMirror: true` if you are in China or behind a firewall.";
|
|
709
|
+
logger_js.logger.warn(`Failed to download font ${fontKey} ${mirrorMsg}`);
|
|
710
|
+
if (result.error)
|
|
711
|
+
logger_js.logger.warn(` Error: ${result.error.message || result.error}`);
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
} else if (f.path) {
|
|
715
|
+
const extension = pathe.basename(f.path.replace(".base64", "")).split(".").pop();
|
|
716
|
+
if (!["woff", "ttf", "otf"].includes(extension)) {
|
|
717
|
+
logger_js.logger.warn(`The ${fontKey} font was skipped because the file extension ${extension} is not supported. Only woff, ttf and otf are supported.`);
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
if (!f.absolutePath)
|
|
721
|
+
f.path = resolve(publicDirAbs, ufo.withoutLeadingSlash(f.path));
|
|
722
|
+
if (!fs.existsSync(f.path)) {
|
|
723
|
+
logger_js.logger.warn(`The ${fontKey} font was skipped because the file does not exist at path ${f.path}.`);
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
const fontData = await promises.readFile(f.path, f.path.endsWith(".base64") ? "utf-8" : "base64");
|
|
727
|
+
f.key = `nuxt-og-image:fonts:${fontFileBase}.${extension}.base64`;
|
|
728
|
+
await fontStorage.setItem(`${fontFileBase}.${extension}.base64`, fontData);
|
|
729
|
+
delete f.path;
|
|
730
|
+
delete f.absolutePath;
|
|
731
|
+
}
|
|
732
|
+
return f;
|
|
733
|
+
}))).filter(Boolean);
|
|
734
|
+
const fontKeys = config.fonts.map((f) => f.key?.split(":").pop());
|
|
735
|
+
const fontStorageKeys = await fontStorage.getKeys();
|
|
736
|
+
await Promise.all(fontStorageKeys.filter((key) => !fontKeys.includes(key)).map(async (key) => {
|
|
737
|
+
logger_js.logger.info(`Nuxt OG Image removing outdated cached font file \`${key}\``);
|
|
738
|
+
await fontStorage.removeItem(key);
|
|
739
|
+
}));
|
|
740
|
+
if (!config.zeroRuntime) {
|
|
741
|
+
nuxt.options.nitro.serverAssets = nuxt.options.nitro.serverAssets || [];
|
|
742
|
+
nuxt.options.nitro.serverAssets.push({ baseName: "nuxt-og-image:fonts", dir: serverFontsDir });
|
|
743
|
+
}
|
|
744
|
+
kit.addServerHandler({
|
|
745
|
+
lazy: true,
|
|
746
|
+
route: "/__og-image__/font/**",
|
|
747
|
+
handler: resolve(`${basePath}/font`)
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
if (isProviderEnabledForEnv("chromium", nuxt, config)) {
|
|
751
|
+
const hasChromeLocally = checkLocalChrome();
|
|
752
|
+
const hasPlaywrightDependency = await hasResolvableDependency("playwright");
|
|
753
|
+
const chromeCompatibilityFlags = {
|
|
754
|
+
prerender: config.compatibility?.prerender?.chromium,
|
|
755
|
+
dev: config.compatibility?.dev?.chromium,
|
|
756
|
+
runtime: config.compatibility?.runtime?.chromium
|
|
757
|
+
};
|
|
758
|
+
const chromiumBinding = {
|
|
759
|
+
dev: null,
|
|
760
|
+
prerender: null,
|
|
761
|
+
runtime: null
|
|
762
|
+
};
|
|
763
|
+
if (nuxt.options.dev) {
|
|
764
|
+
if (isUndefinedOrTruthy(chromeCompatibilityFlags.dev))
|
|
765
|
+
chromiumBinding.dev = hasChromeLocally ? "chrome-launcher" : hasPlaywrightDependency ? "playwright" : "on-demand";
|
|
766
|
+
} else {
|
|
767
|
+
if (isUndefinedOrTruthy(chromeCompatibilityFlags.prerender))
|
|
768
|
+
chromiumBinding.prerender = hasChromeLocally ? "chrome-launcher" : hasPlaywrightDependency ? "playwright" : "on-demand";
|
|
769
|
+
if (isUndefinedOrTruthy(chromeCompatibilityFlags.runtime))
|
|
770
|
+
chromiumBinding.runtime = hasPlaywrightDependency ? "playwright" : null;
|
|
771
|
+
}
|
|
772
|
+
config.compatibility = defu.defu(config.compatibility, {
|
|
773
|
+
runtime: { chromium: chromiumBinding.runtime },
|
|
774
|
+
dev: { chromium: chromiumBinding.dev },
|
|
775
|
+
prerender: { chromium: chromiumBinding.prerender }
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
await kit$1.installNuxtSiteConfig();
|
|
779
|
+
const usingNuxtContent = kit.hasNuxtModule("@nuxt/content");
|
|
780
|
+
const isNuxtContentV3 = usingNuxtContent && await kit.hasNuxtModuleCompatibility("@nuxt/content", "^3");
|
|
781
|
+
const isNuxtContentV2 = usingNuxtContent && await kit.hasNuxtModuleCompatibility("@nuxt/content", "^2");
|
|
782
|
+
if (isNuxtContentV3) {
|
|
783
|
+
if (typeof config.strictNuxtContentPaths !== "undefined") {
|
|
784
|
+
logger_js.logger.warn("The `strictNuxtContentPaths` option is deprecated and has no effect in Nuxt Content v3.");
|
|
785
|
+
}
|
|
786
|
+
} else if (isNuxtContentV2) {
|
|
787
|
+
kit.addServerPlugin(resolve("./runtime/server/plugins/nuxt-content-v2"));
|
|
788
|
+
}
|
|
789
|
+
nuxt.options.experimental.componentIslands ||= true;
|
|
790
|
+
if (config.debug || nuxt.options.dev) {
|
|
791
|
+
kit.addServerHandler({
|
|
792
|
+
lazy: true,
|
|
793
|
+
route: "/__og-image__/debug.json",
|
|
794
|
+
handler: resolve("./runtime/server/routes/debug.json")
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
kit.addServerHandler({
|
|
798
|
+
lazy: true,
|
|
799
|
+
route: "/__og-image__/image/**",
|
|
800
|
+
handler: resolve(`${basePath}/image`)
|
|
801
|
+
});
|
|
802
|
+
kit.addServerHandler({
|
|
803
|
+
lazy: true,
|
|
804
|
+
route: "/__og-image__/static/**",
|
|
805
|
+
handler: resolve(`${basePath}/image`)
|
|
806
|
+
});
|
|
807
|
+
if (!nuxt.options.dev) {
|
|
808
|
+
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"] = [];
|
|
809
|
+
}
|
|
810
|
+
[
|
|
811
|
+
"defineOgImage",
|
|
812
|
+
"defineOgImageComponent",
|
|
813
|
+
{ name: "defineOgImageScreenshot", enabled: isProviderEnabledForEnv("chromium", nuxt, config) }
|
|
814
|
+
].forEach((name) => {
|
|
815
|
+
if (typeof name === "object") {
|
|
816
|
+
if (!name.enabled) {
|
|
817
|
+
kit.addImports({ name: name.name, from: resolve(`./runtime/app/composables/mock`) });
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
name = name.name;
|
|
821
|
+
}
|
|
822
|
+
kit.addImports({
|
|
823
|
+
name,
|
|
824
|
+
from: resolve(`./runtime/app/composables/${name}`)
|
|
825
|
+
});
|
|
826
|
+
if (!nuxt.options.dev) {
|
|
827
|
+
nuxt.options.optimization.treeShake.composables.client = nuxt.options.optimization.treeShake.composables.client || {};
|
|
828
|
+
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"] = nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"] || [];
|
|
829
|
+
nuxt.options.optimization.treeShake.composables.client["nuxt-og-image"].push(name);
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
if (!config.zeroRuntime || nuxt.options.dev) {
|
|
833
|
+
kit.addComponentsDir({
|
|
834
|
+
path: resolve("./runtime/app/components/Templates/Community"),
|
|
835
|
+
island: true,
|
|
836
|
+
watch: IS_MODULE_DEVELOPMENT
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
[
|
|
840
|
+
// new
|
|
841
|
+
"OgImage",
|
|
842
|
+
"OgImageScreenshot"
|
|
843
|
+
].forEach((name) => {
|
|
844
|
+
kit.addComponent({
|
|
845
|
+
name,
|
|
846
|
+
filePath: resolve(`./runtime/app/components/OgImage/${name}`),
|
|
847
|
+
...config.componentOptions
|
|
848
|
+
});
|
|
849
|
+
});
|
|
850
|
+
const basePluginPath = `./runtime/app/plugins${config.zeroRuntime ? "/__zero-runtime" : ""}`;
|
|
851
|
+
kit.addPlugin({ mode: "server", src: resolve(`${basePluginPath}/route-rule-og-image.server`) });
|
|
852
|
+
kit.addPlugin({ mode: "server", src: resolve(`${basePluginPath}/og-image-canonical-urls.server`) });
|
|
853
|
+
for (const componentDir of config.componentDirs) {
|
|
854
|
+
const path = resolve(nuxt.options.srcDir, "components", componentDir);
|
|
855
|
+
if (fs.existsSync(path)) {
|
|
856
|
+
kit.addComponentsDir({
|
|
857
|
+
path,
|
|
858
|
+
island: true,
|
|
859
|
+
watch: IS_MODULE_DEVELOPMENT
|
|
860
|
+
});
|
|
861
|
+
} else if (!defaultComponentDirs.includes(componentDir)) {
|
|
862
|
+
logger_js.logger.warn(`The configured component directory \`./${pathe.relative(nuxt.options.rootDir, path)}\` does not exist. Skipping.`);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
const ogImageComponentCtx = { components: [] };
|
|
866
|
+
nuxt.hook("components:extend", (components) => {
|
|
867
|
+
ogImageComponentCtx.components = [];
|
|
868
|
+
components.forEach((component) => {
|
|
869
|
+
let valid = false;
|
|
870
|
+
config.componentDirs.forEach((dir) => {
|
|
871
|
+
if (component.pascalName.startsWith(dir) || component.kebabName.startsWith(dir) || component.shortPath.includes(`/${dir}/`)) {
|
|
872
|
+
valid = true;
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
if (component.filePath.includes(resolve("./runtime/app/components/Templates")))
|
|
876
|
+
valid = true;
|
|
877
|
+
if (valid && fs__namespace.existsSync(component.filePath)) {
|
|
878
|
+
component.island = true;
|
|
879
|
+
component.mode = "server";
|
|
880
|
+
let category = "app";
|
|
881
|
+
if (component.filePath.includes(resolve("./runtime/app/components/Templates/Community")))
|
|
882
|
+
category = "community";
|
|
883
|
+
const componentFile = fs__namespace.readFileSync(component.filePath, "utf-8");
|
|
884
|
+
const credits = componentFile.split("\n").find((line) => line.startsWith(" * @credits"))?.replace("* @credits", "").trim();
|
|
885
|
+
ogImageComponentCtx.components.push({
|
|
886
|
+
// purge cache when component changes
|
|
887
|
+
hash: ohash.hash(componentFile).replaceAll("_", "-"),
|
|
888
|
+
pascalName: component.pascalName,
|
|
889
|
+
kebabName: component.kebabName,
|
|
890
|
+
path: component.filePath,
|
|
891
|
+
category,
|
|
892
|
+
credits
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
nuxt.hooks.hook("nuxt-og-image:components", ogImageComponentCtx);
|
|
897
|
+
});
|
|
898
|
+
kit.addTemplate({
|
|
899
|
+
filename: "nuxt-og-image/components.mjs",
|
|
900
|
+
getContents() {
|
|
901
|
+
return `export const componentNames = ${JSON.stringify(ogImageComponentCtx.components)}`;
|
|
902
|
+
},
|
|
903
|
+
options: { mode: "server" }
|
|
904
|
+
});
|
|
905
|
+
nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {};
|
|
906
|
+
nuxt.options.nitro.virtual["#og-image-virtual/component-names.mjs"] = () => {
|
|
907
|
+
return `export const componentNames = ${JSON.stringify(ogImageComponentCtx.components)}`;
|
|
908
|
+
};
|
|
909
|
+
let unoCssConfig = {};
|
|
910
|
+
nuxt.hook("tailwindcss:config", (tailwindConfig) => {
|
|
911
|
+
unoCssConfig = defu.defu(tailwindConfig.theme?.extend, { ...tailwindConfig.theme, extend: void 0 });
|
|
912
|
+
});
|
|
913
|
+
nuxt.hook("unocss:config", (_unoCssConfig) => {
|
|
914
|
+
unoCssConfig = { ..._unoCssConfig.theme };
|
|
915
|
+
});
|
|
916
|
+
nuxt.options.nitro.virtual["#og-image-virtual/unocss-config.mjs"] = () => {
|
|
917
|
+
return `export const theme = ${JSON.stringify(unoCssConfig)}`;
|
|
918
|
+
};
|
|
919
|
+
kit.addTypeTemplate({
|
|
920
|
+
filename: "module/nuxt-og-image.d.ts",
|
|
921
|
+
getContents: (data) => {
|
|
922
|
+
const typesPath = pathe.relative(resolve(data.nuxt.options.rootDir, data.nuxt.options.buildDir, "module"), resolve("runtime/types"));
|
|
923
|
+
const componentImports = ogImageComponentCtx.components.map((component) => {
|
|
924
|
+
const relativeComponentPath = pathe.relative(resolve(nuxt.options.rootDir, nuxt.options.buildDir, "module"), component.path);
|
|
925
|
+
const name = config.componentDirs.sort((a, b) => b.length - a.length).reduce((name2, dir) => {
|
|
926
|
+
return name2.replace(new RegExp(`^${dir}`), "");
|
|
927
|
+
}, component.pascalName);
|
|
928
|
+
return ` '${name}': typeof import('${relativeComponentPath}')['default']`;
|
|
929
|
+
}).join("\n");
|
|
930
|
+
const types = `interface NitroRouteRules {
|
|
931
|
+
ogImage?: false | import('${typesPath}').OgImageOptions & Record<string, any>
|
|
932
|
+
}
|
|
933
|
+
interface NitroRouteConfig {
|
|
934
|
+
ogImage?: false | import('${typesPath}').OgImageOptions & Record<string, any>
|
|
935
|
+
}
|
|
936
|
+
interface NitroRuntimeHooks {
|
|
937
|
+
'nuxt-og-image:context': (ctx: import('${typesPath}').OgImageRenderEventContext) => void | Promise<void>
|
|
938
|
+
'nuxt-og-image:satori:vnodes': (vnodes: import('${typesPath}').VNode, ctx: import('${typesPath}').OgImageRenderEventContext) => void | Promise<void>
|
|
939
|
+
}`;
|
|
940
|
+
return `
|
|
941
|
+
declare module 'nitropack' {
|
|
942
|
+
${types}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
declare module 'nitropack/types' {
|
|
946
|
+
${types}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
declare module '#og-image/components' {
|
|
950
|
+
export interface OgImageComponents {
|
|
951
|
+
${componentImports}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
declare module '#og-image/unocss-config' {
|
|
955
|
+
export type theme = any
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
export {}
|
|
959
|
+
`;
|
|
960
|
+
}
|
|
961
|
+
}, {
|
|
962
|
+
nitro: true,
|
|
963
|
+
nuxt: true
|
|
964
|
+
});
|
|
965
|
+
const cacheEnabled = typeof config.runtimeCacheStorage !== "undefined" && config.runtimeCacheStorage !== false;
|
|
966
|
+
const runtimeCacheStorage = typeof config.runtimeCacheStorage === "boolean" ? "default" : config.runtimeCacheStorage.driver;
|
|
967
|
+
let baseCacheKey = runtimeCacheStorage === "default" ? `/cache/nuxt-og-image/${version}` : `/nuxt-og-image/${version}`;
|
|
968
|
+
if (!cacheEnabled)
|
|
969
|
+
baseCacheKey = false;
|
|
970
|
+
if (!nuxt.options.dev && config.runtimeCacheStorage && typeof config.runtimeCacheStorage === "object") {
|
|
971
|
+
nuxt.options.nitro.storage = nuxt.options.nitro.storage || {};
|
|
972
|
+
nuxt.options.nitro.storage["nuxt-og-image"] = config.runtimeCacheStorage;
|
|
973
|
+
}
|
|
974
|
+
nuxt.hooks.hook("modules:done", async () => {
|
|
975
|
+
const normalisedFonts = normaliseFontInput(config.fonts);
|
|
976
|
+
if (!isNuxtGenerate() && nuxt.options.build) {
|
|
977
|
+
nuxt.options.nitro = nuxt.options.nitro || {};
|
|
978
|
+
nuxt.options.nitro.prerender = nuxt.options.nitro.prerender || {};
|
|
979
|
+
nuxt.options.nitro.prerender.routes = nuxt.options.nitro.prerender.routes || [];
|
|
980
|
+
}
|
|
981
|
+
const hasColorModeModule = kit.hasNuxtModule("@nuxtjs/color-mode");
|
|
982
|
+
const colorModeOptions = hasColorModeModule ? await getNuxtModuleOptions("@nuxtjs/color-mode") : {};
|
|
983
|
+
let colorPreference = colorModeOptions.preference;
|
|
984
|
+
if (!colorPreference || colorPreference === "system")
|
|
985
|
+
colorPreference = colorModeOptions.fallback;
|
|
986
|
+
if (!colorPreference || colorPreference === "system")
|
|
987
|
+
colorPreference = "light";
|
|
988
|
+
const runtimeConfig = {
|
|
989
|
+
version,
|
|
990
|
+
// binding options
|
|
991
|
+
satoriOptions: config.satoriOptions || {},
|
|
992
|
+
resvgOptions: config.resvgOptions || {},
|
|
993
|
+
sharpOptions: config.sharpOptions === true ? {} : config.sharpOptions || {},
|
|
994
|
+
publicStoragePath: `root${publicDirAbs.replace(nuxt.options.rootDir, "").replaceAll("/", ":")}`,
|
|
995
|
+
defaults: config.defaults,
|
|
996
|
+
debug: config.debug,
|
|
997
|
+
// avoid adding credentials
|
|
998
|
+
baseCacheKey,
|
|
999
|
+
// convert the fonts to uniform type to fix ts issue
|
|
1000
|
+
fonts: normalisedFonts,
|
|
1001
|
+
hasNuxtIcon: kit.hasNuxtModule("nuxt-icon") || kit.hasNuxtModule("@nuxt/icon"),
|
|
1002
|
+
colorPreference,
|
|
1003
|
+
strictNuxtContentPaths: config.strictNuxtContentPaths,
|
|
1004
|
+
// @ts-expect-error runtime type
|
|
1005
|
+
isNuxtContentDocumentDriven: config.strictNuxtContentPaths || !!nuxt.options.content?.documentDriven
|
|
1006
|
+
};
|
|
1007
|
+
if (nuxt.options.dev) {
|
|
1008
|
+
runtimeConfig.componentDirs = config.componentDirs;
|
|
1009
|
+
}
|
|
1010
|
+
nuxt.hooks.callHook("nuxt-og-image:runtime-config", runtimeConfig);
|
|
1011
|
+
nuxt.options.runtimeConfig["nuxt-og-image"] = runtimeConfig;
|
|
1012
|
+
});
|
|
1013
|
+
if (nuxt.options.dev) {
|
|
1014
|
+
setupDevHandler(config, resolver);
|
|
1015
|
+
setupDevToolsUI(config, resolve);
|
|
1016
|
+
} else if (isNuxtGenerate()) {
|
|
1017
|
+
setupGenerateHandler(config, resolver);
|
|
1018
|
+
} else if (nuxt.options.build) {
|
|
1019
|
+
await setupBuildHandler(config, resolver);
|
|
1020
|
+
}
|
|
1021
|
+
if (nuxt.options.build)
|
|
1022
|
+
kit.addServerPlugin(resolve("./runtime/server/plugins/prerender"));
|
|
1023
|
+
setupPrerenderHandler(config, resolver);
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
module.exports = module$1;
|