nuxt-og-image 5.1.10 → 5.1.11

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