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