nuxt-og-image 6.7.4 → 6.7.6

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 (80) hide show
  1. package/dist/chunks/tw4.cjs +2 -2
  2. package/dist/chunks/tw4.mjs +2 -2
  3. package/dist/chunks/uno.cjs +20 -5
  4. package/dist/chunks/uno.mjs +19 -5
  5. package/dist/cli.cjs +8 -2
  6. package/dist/cli.mjs +8 -2
  7. package/dist/devtools/lib/og-image/rpc.ts +4 -1
  8. package/dist/module.cjs +2 -2
  9. package/dist/module.json +2 -2
  10. package/dist/module.mjs +2 -2
  11. package/dist/runtime/app/plugins/og-image-canonical-urls.server.d.ts +2 -1
  12. package/dist/runtime/app/plugins/og-image-canonical-urls.server.js +3 -1
  13. package/dist/runtime/app/plugins/route-rule-og-image.server.d.ts +2 -1
  14. package/dist/runtime/app/plugins/route-rule-og-image.server.js +3 -1
  15. package/dist/runtime/app/utils/plugins.js +4 -10
  16. package/dist/runtime/logger.js +2 -6
  17. package/dist/runtime/pure.d.ts +0 -1
  18. package/dist/runtime/pure.js +0 -5
  19. package/dist/runtime/server/og-image/bindings/browser/chrome-launcher.d.ts +1 -1
  20. package/dist/runtime/server/og-image/bindings/browser/cloudflare.d.ts +1 -2
  21. package/dist/runtime/server/og-image/bindings/browser/cloudflare.js +2 -9
  22. package/dist/runtime/server/og-image/bindings/browser/on-demand.d.ts +1 -1
  23. package/dist/runtime/server/og-image/bindings/browser/playwright.d.ts +1 -1
  24. package/dist/runtime/server/og-image/bindings/font-assets/cloudflare.d.ts +1 -1
  25. package/dist/runtime/server/og-image/bindings/font-assets/cloudflare.js +1 -1
  26. package/dist/runtime/server/og-image/bindings/font-assets/dev-prerender.d.ts +1 -1
  27. package/dist/runtime/server/og-image/bindings/font-assets/dev-prerender.js +27 -13
  28. package/dist/runtime/server/og-image/bindings/font-assets/external-url.js +3 -1
  29. package/dist/runtime/server/og-image/bindings/font-assets/node.d.ts +1 -1
  30. package/dist/runtime/server/og-image/bindings/font-assets/node.js +4 -2
  31. package/dist/runtime/server/og-image/bindings/resvg/node-dev.js +18 -64
  32. package/dist/runtime/server/og-image/bindings/takumi/node-dev.js +26 -83
  33. package/dist/runtime/server/og-image/bindings/worker-queue.d.ts +34 -0
  34. package/dist/runtime/server/og-image/bindings/worker-queue.js +150 -0
  35. package/dist/runtime/server/og-image/browser/renderer.js +1 -1
  36. package/dist/runtime/server/og-image/context.d.ts +1 -1
  37. package/dist/runtime/server/og-image/context.js +2 -3
  38. package/dist/runtime/server/og-image/core/plugins/imageSrc.js +1 -1
  39. package/dist/runtime/server/og-image/core/transforms/emojis/local.d.ts +2 -17
  40. package/dist/runtime/server/og-image/core/transforms/emojis/local.js +1 -1
  41. package/dist/runtime/server/og-image/devtools.d.ts +1 -1
  42. package/dist/runtime/server/og-image/devtools.js +1 -1
  43. package/dist/runtime/server/og-image/fonts.d.ts +1 -1
  44. package/dist/runtime/server/og-image/fonts.js +3 -1
  45. package/dist/runtime/server/og-image/templates/html.js +1 -1
  46. package/dist/runtime/server/plugins/prerender.d.ts +1 -1
  47. package/dist/runtime/server/plugins/prerender.js +2 -2
  48. package/dist/runtime/server/routes/__zero-runtime/image.d.ts +1 -1
  49. package/dist/runtime/server/routes/__zero-runtime/image.js +1 -1
  50. package/dist/runtime/server/routes/debug.json.d.ts +1 -10
  51. package/dist/runtime/server/routes/debug.json.js +1 -1
  52. package/dist/runtime/server/routes/image.d.ts +1 -1
  53. package/dist/runtime/server/routes/image.js +1 -1
  54. package/dist/runtime/server/routes/resolve.d.ts +1 -1
  55. package/dist/runtime/server/routes/resolve.js +1 -1
  56. package/dist/runtime/server/util/cache.d.ts +1 -6
  57. package/dist/runtime/server/util/cache.js +2 -2
  58. package/dist/runtime/server/util/cloudflare.d.ts +3 -0
  59. package/dist/runtime/server/util/cloudflare.js +17 -0
  60. package/dist/runtime/server/util/cloudflareAssets.d.ts +1 -1
  61. package/dist/runtime/server/util/cloudflareAssets.js +8 -5
  62. package/dist/runtime/server/util/encoding.d.ts +0 -1
  63. package/dist/runtime/server/util/encoding.js +0 -7
  64. package/dist/runtime/server/util/eventHandlers.d.ts +1 -1
  65. package/dist/runtime/server/util/eventHandlers.js +1 -1
  66. package/dist/runtime/server/util/fetchLocalAsset.d.ts +1 -1
  67. package/dist/runtime/server/util/kit.d.ts +7 -4
  68. package/dist/runtime/server/util/kit.js +4 -19
  69. package/dist/runtime/server/util/logger.js +2 -6
  70. package/dist/runtime/server/util/options.js +1 -1
  71. package/dist/runtime/server/util/query.d.ts +1 -1
  72. package/dist/runtime/server/util/timings.d.ts +0 -3
  73. package/dist/runtime/server/util/timings.js +0 -3
  74. package/dist/runtime/server/utils.d.ts +1 -1
  75. package/dist/runtime/server/utils.js +7 -4
  76. package/dist/runtime/types.d.ts +11 -9
  77. package/dist/shared/{nuxt-og-image.Bv8VSGTj.mjs → nuxt-og-image.BIbfn5xQ.mjs} +146 -108
  78. package/dist/shared/{nuxt-og-image.BRBtdkUp.cjs → nuxt-og-image.CdpC3njh.cjs} +148 -107
  79. package/package.json +57 -48
  80. package/types/virtual.d.ts +15 -0
@@ -4,17 +4,17 @@ const promises = require('node:fs/promises');
4
4
  const node_url = require('node:url');
5
5
  const exsolve = require('exsolve');
6
6
  const pathe = require('pathe');
7
- const module$1 = require('../shared/nuxt-og-image.BRBtdkUp.cjs');
7
+ const module$1 = require('../shared/nuxt-og-image.CdpC3njh.cjs');
8
8
  require('node:crypto');
9
9
  require('node:fs');
10
10
  require('@nuxt/kit');
11
11
  require('defu');
12
12
  require('fnv1a-64');
13
13
  require('nuxt-site-config/kit');
14
+ require('nuxtseo-shared/kit');
14
15
  require('pkg-types');
15
16
  require('std-env');
16
17
  require('oxc-walker');
17
- require('nuxtseo-shared/kit');
18
18
  require('../../dist/runtime/logger.js');
19
19
  require('chrome-launcher');
20
20
  require('nypm');
@@ -2,17 +2,17 @@ import { readFile } from 'node:fs/promises';
2
2
  import { pathToFileURL } from 'node:url';
3
3
  import { resolveModulePath } from 'exsolve';
4
4
  import { dirname, join } from 'pathe';
5
- import { e as extractVariantBaseClasses, r as resolveVariantPrefixes, h as resolveExtractedVars, i as resolveVarsDeep, s as simplifyCss, p as postProcessStyles, l as loadLightningCss, a as extractCssVars, c as extractUniversalVars, d as extractPerClassVars, g as extractVarsFromCss, f as extractClassStyles } from '../shared/nuxt-og-image.Bv8VSGTj.mjs';
5
+ import { e as extractVariantBaseClasses, r as resolveVariantPrefixes, h as resolveExtractedVars, l as resolveVarsDeep, s as simplifyCss, p as postProcessStyles, m as loadLightningCss, a as extractCssVars, c as extractUniversalVars, d as extractPerClassVars, g as extractVarsFromCss, f as extractClassStyles } from '../shared/nuxt-og-image.BIbfn5xQ.mjs';
6
6
  import 'node:crypto';
7
7
  import 'node:fs';
8
8
  import '@nuxt/kit';
9
9
  import 'defu';
10
10
  import 'fnv1a-64';
11
11
  import 'nuxt-site-config/kit';
12
+ import 'nuxtseo-shared/kit';
12
13
  import 'pkg-types';
13
14
  import 'std-env';
14
15
  import 'oxc-walker';
15
- import 'nuxtseo-shared/kit';
16
16
  import '../../dist/runtime/logger.js';
17
17
  import 'chrome-launcher';
18
18
  import 'nypm';
@@ -3,18 +3,18 @@
3
3
  const promises = require('node:fs/promises');
4
4
  const defu = require('defu');
5
5
  const logger_js = require('../../dist/runtime/logger.js');
6
- const module$1 = require('../shared/nuxt-og-image.BRBtdkUp.cjs');
6
+ const module$1 = require('../shared/nuxt-og-image.CdpC3njh.cjs');
7
7
  require('node:crypto');
8
8
  require('node:fs');
9
9
  require('node:url');
10
10
  require('@nuxt/kit');
11
11
  require('fnv1a-64');
12
12
  require('nuxt-site-config/kit');
13
+ require('nuxtseo-shared/kit');
13
14
  require('pathe');
14
15
  require('pkg-types');
15
16
  require('std-env');
16
17
  require('oxc-walker');
17
- require('nuxtseo-shared/kit');
18
18
  require('chrome-launcher');
19
19
  require('nypm');
20
20
  require('nuxtseo-shared/devtools');
@@ -42,6 +42,8 @@ const RE_HEIGHT_ATTR = /\bheight=['"](\d+)['"]/;
42
42
  const RE_SVG_BODY = /<svg[^>]*>([\s\S]*)<\/svg>/;
43
43
  let unoConfig = null;
44
44
  let rootDir = null;
45
+ let unocssCorePath;
46
+ let unocssConfigPath;
45
47
  let generator = null;
46
48
  let pendingGenerator = null;
47
49
  let cachedExtracted = null;
@@ -60,6 +62,15 @@ function clearUnoCache() {
60
62
  pendingGenerator = null;
61
63
  cachedExtracted = null;
62
64
  }
65
+ function setUnoModulePaths(options) {
66
+ const nextCorePath = options?.unocssCorePath;
67
+ const nextConfigPath = options?.unocssConfigPath;
68
+ if (nextCorePath === unocssCorePath && nextConfigPath === unocssConfigPath)
69
+ return;
70
+ unocssCorePath = nextCorePath;
71
+ unocssConfigPath = nextConfigPath;
72
+ clearUnoCache();
73
+ }
63
74
  async function getGenerator() {
64
75
  if (generator)
65
76
  return generator;
@@ -68,17 +79,18 @@ async function getGenerator() {
68
79
  pendingGenerator = (async () => {
69
80
  let loadedConfig;
70
81
  try {
71
- const { loadConfig } = await import('@unocss/config');
82
+ const { loadConfig } = await module$1.importOptionalPeer("@unocss/config", unocssConfigPath, "UnoCSS class extraction with OG images");
72
83
  const result = await loadConfig(rootDir || process.cwd());
73
84
  loadedConfig = result.config;
74
85
  } catch (e) {
75
- logger_js.logger.warn("[og-image UnoCSS] Failed to load uno.config.ts:", e.message);
86
+ if (!unoConfig)
87
+ logger_js.logger.warn("[og-image UnoCSS] Failed to load uno.config.ts:", e.message);
76
88
  }
77
89
  const finalConfig = loadedConfig ? defu.defu(unoConfig || {}, loadedConfig) : unoConfig;
78
90
  if (!finalConfig) {
79
91
  throw new Error("UnoCSS config not found. Ensure uno.config.ts exists or @unocss/nuxt is loaded.");
80
92
  }
81
- const { createGenerator } = await import('@unocss/core');
93
+ const { createGenerator } = await module$1.importOptionalPeer("@unocss/core", unocssCorePath, "UnoCSS class extraction with OG images");
82
94
  generator = await createGenerator(finalConfig);
83
95
  return generator;
84
96
  })();
@@ -116,6 +128,7 @@ function resolveUserVars(extracted, rootAttrs) {
116
128
  return module$1.resolveExtractedVars(extracted, rootAttrs);
117
129
  }
118
130
  function createUnoProvider(options) {
131
+ setUnoModulePaths(options);
119
132
  return {
120
133
  name: "unocss",
121
134
  async resolveClassesToStyles(classes, context, rootAttrs) {
@@ -227,6 +240,8 @@ function createUnoProvider(options) {
227
240
  };
228
241
  }
229
242
 
243
+ exports.importResolvedModule = module$1.importResolvedModule;
244
+ exports.resolveOptionalModulePath = module$1.resolveOptionalModulePath;
230
245
  exports.clearUnoCache = clearUnoCache;
231
246
  exports.clearUnoUserVarsCache = clearUnoUserVarsCache;
232
247
  exports.createUnoProvider = createUnoProvider;
@@ -1,18 +1,19 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { defu } from 'defu';
3
3
  import { logger } from '../../dist/runtime/logger.js';
4
- import { e as extractVariantBaseClasses, s as simplifyCss, a as extractCssVars, b as extractPropertyInitialValues, c as extractUniversalVars, d as extractPerClassVars, f as extractClassStyles, p as postProcessStyles, r as resolveVariantPrefixes, g as extractVarsFromCss, h as resolveExtractedVars } from '../shared/nuxt-og-image.Bv8VSGTj.mjs';
4
+ import { e as extractVariantBaseClasses, s as simplifyCss, a as extractCssVars, b as extractPropertyInitialValues, c as extractUniversalVars, d as extractPerClassVars, f as extractClassStyles, p as postProcessStyles, r as resolveVariantPrefixes, i as importOptionalPeer, g as extractVarsFromCss, h as resolveExtractedVars } from '../shared/nuxt-og-image.BIbfn5xQ.mjs';
5
+ export { j as importResolvedModule, k as resolveOptionalModulePath } from '../shared/nuxt-og-image.BIbfn5xQ.mjs';
5
6
  import 'node:crypto';
6
7
  import 'node:fs';
7
8
  import 'node:url';
8
9
  import '@nuxt/kit';
9
10
  import 'fnv1a-64';
10
11
  import 'nuxt-site-config/kit';
12
+ import 'nuxtseo-shared/kit';
11
13
  import 'pathe';
12
14
  import 'pkg-types';
13
15
  import 'std-env';
14
16
  import 'oxc-walker';
15
- import 'nuxtseo-shared/kit';
16
17
  import 'chrome-launcher';
17
18
  import 'nypm';
18
19
  import 'nuxtseo-shared/devtools';
@@ -40,6 +41,8 @@ const RE_HEIGHT_ATTR = /\bheight=['"](\d+)['"]/;
40
41
  const RE_SVG_BODY = /<svg[^>]*>([\s\S]*)<\/svg>/;
41
42
  let unoConfig = null;
42
43
  let rootDir = null;
44
+ let unocssCorePath;
45
+ let unocssConfigPath;
43
46
  let generator = null;
44
47
  let pendingGenerator = null;
45
48
  let cachedExtracted = null;
@@ -58,6 +61,15 @@ function clearUnoCache() {
58
61
  pendingGenerator = null;
59
62
  cachedExtracted = null;
60
63
  }
64
+ function setUnoModulePaths(options) {
65
+ const nextCorePath = options?.unocssCorePath;
66
+ const nextConfigPath = options?.unocssConfigPath;
67
+ if (nextCorePath === unocssCorePath && nextConfigPath === unocssConfigPath)
68
+ return;
69
+ unocssCorePath = nextCorePath;
70
+ unocssConfigPath = nextConfigPath;
71
+ clearUnoCache();
72
+ }
61
73
  async function getGenerator() {
62
74
  if (generator)
63
75
  return generator;
@@ -66,17 +78,18 @@ async function getGenerator() {
66
78
  pendingGenerator = (async () => {
67
79
  let loadedConfig;
68
80
  try {
69
- const { loadConfig } = await import('@unocss/config');
81
+ const { loadConfig } = await importOptionalPeer("@unocss/config", unocssConfigPath, "UnoCSS class extraction with OG images");
70
82
  const result = await loadConfig(rootDir || process.cwd());
71
83
  loadedConfig = result.config;
72
84
  } catch (e) {
73
- logger.warn("[og-image UnoCSS] Failed to load uno.config.ts:", e.message);
85
+ if (!unoConfig)
86
+ logger.warn("[og-image UnoCSS] Failed to load uno.config.ts:", e.message);
74
87
  }
75
88
  const finalConfig = loadedConfig ? defu(unoConfig || {}, loadedConfig) : unoConfig;
76
89
  if (!finalConfig) {
77
90
  throw new Error("UnoCSS config not found. Ensure uno.config.ts exists or @unocss/nuxt is loaded.");
78
91
  }
79
- const { createGenerator } = await import('@unocss/core');
92
+ const { createGenerator } = await importOptionalPeer("@unocss/core", unocssCorePath, "UnoCSS class extraction with OG images");
80
93
  generator = await createGenerator(finalConfig);
81
94
  return generator;
82
95
  })();
@@ -114,6 +127,7 @@ function resolveUserVars(extracted, rootAttrs) {
114
127
  return resolveExtractedVars(extracted, rootAttrs);
115
128
  }
116
129
  function createUnoProvider(options) {
130
+ setUnoModulePaths(options);
117
131
  return {
118
132
  name: "unocss",
119
133
  async resolveClassesToStyles(classes, context, rootAttrs) {
package/dist/cli.cjs CHANGED
@@ -364,7 +364,10 @@ async function checkNuxtConfig(rootDir) {
364
364
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
365
365
  hasNuxtFontsInPkg = !!(pkg.dependencies?.["@nuxt/fonts"] || pkg.devDependencies?.["@nuxt/fonts"]);
366
366
  }
367
- const config = await kit.loadNuxtConfig({ cwd: rootDir }).catch(() => null);
367
+ const config = await kit.loadNuxtConfig({ cwd: rootDir }).catch((error) => {
368
+ p__namespace.log.warn(`Could not inspect Nuxt config: ${error.message}`);
369
+ return null;
370
+ });
368
371
  if (!config)
369
372
  return { hasDeprecatedFonts: false, hasNuxtFonts: hasNuxtFontsInPkg, hasDefaultsComponent: false, defaultComponentName: null, nitroPreset: null, deprecatedConfigKeys: [] };
370
373
  const ogImageConfig = config.ogImage;
@@ -545,7 +548,10 @@ function migrateV6Components(componentsToRename, defaultRenderer, dryRun) {
545
548
  }
546
549
  }
547
550
  async function detectDeploymentTarget(rootDir) {
548
- const config = await kit.loadNuxtConfig({ cwd: rootDir }).catch(() => null);
551
+ const config = await kit.loadNuxtConfig({ cwd: rootDir }).catch((error) => {
552
+ p__namespace.log.warn(`Could not detect deployment target: ${error.message}`);
553
+ return null;
554
+ });
549
555
  return config?.nitro?.preset || null;
550
556
  }
551
557
  async function installRendererDeps(renderers, isEdge) {
package/dist/cli.mjs CHANGED
@@ -347,7 +347,10 @@ async function checkNuxtConfig(rootDir) {
347
347
  const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
348
348
  hasNuxtFontsInPkg = !!(pkg.dependencies?.["@nuxt/fonts"] || pkg.devDependencies?.["@nuxt/fonts"]);
349
349
  }
350
- const config = await loadNuxtConfig({ cwd: rootDir }).catch(() => null);
350
+ const config = await loadNuxtConfig({ cwd: rootDir }).catch((error) => {
351
+ p.log.warn(`Could not inspect Nuxt config: ${error.message}`);
352
+ return null;
353
+ });
351
354
  if (!config)
352
355
  return { hasDeprecatedFonts: false, hasNuxtFonts: hasNuxtFontsInPkg, hasDefaultsComponent: false, defaultComponentName: null, nitroPreset: null, deprecatedConfigKeys: [] };
353
356
  const ogImageConfig = config.ogImage;
@@ -528,7 +531,10 @@ function migrateV6Components(componentsToRename, defaultRenderer, dryRun) {
528
531
  }
529
532
  }
530
533
  async function detectDeploymentTarget(rootDir) {
531
- const config = await loadNuxtConfig({ cwd: rootDir }).catch(() => null);
534
+ const config = await loadNuxtConfig({ cwd: rootDir }).catch((error) => {
535
+ p.log.warn(`Could not detect deployment target: ${error.message}`);
536
+ return null;
537
+ });
532
538
  return config?.nitro?.preset || null;
533
539
  }
534
540
  async function installRendererDeps(renderers, isEdge) {
@@ -17,7 +17,10 @@ export const isFallbackMode = computed(() => connectionState.value === 'fallback
17
17
  // Fallback fetch for localhost:3000
18
18
  async function tryFallbackConnection() {
19
19
  const fallbackUrl = 'http://localhost:3000'
20
- const res = await fetch(`${fallbackUrl}/_og/debug.json`).catch(() => null)
20
+ const res = await fetch(`${fallbackUrl}/_og/debug.json`).catch(() => {
21
+ // An unreachable fallback host means the devtools connection has failed.
22
+ return null
23
+ })
21
24
  if (res?.ok) {
22
25
  appFetch.value = ((url: string, opts?: any) => fetch(`${fallbackUrl}${url}`, opts).then(r => r.json())) as any
23
26
  base.value = '/'
package/dist/module.cjs CHANGED
@@ -8,11 +8,11 @@ require('@nuxt/kit');
8
8
  require('defu');
9
9
  require('fnv1a-64');
10
10
  require('nuxt-site-config/kit');
11
+ require('nuxtseo-shared/kit');
11
12
  require('pathe');
12
13
  require('pkg-types');
13
14
  require('std-env');
14
- const module$1 = require('./shared/nuxt-og-image.BRBtdkUp.cjs');
15
- require('nuxtseo-shared/kit');
15
+ const module$1 = require('./shared/nuxt-og-image.CdpC3njh.cjs');
16
16
  require('../dist/runtime/logger.js');
17
17
  require('oxc-walker');
18
18
  require('chrome-launcher');
package/dist/module.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "nuxt": ">=3.16.0"
5
5
  },
6
6
  "configKey": "ogImage",
7
- "version": "6.7.4",
7
+ "version": "6.7.6",
8
8
  "builder": {
9
- "@nuxt/module-builder": "1.0.2",
9
+ "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
11
11
  }
12
12
  }
package/dist/module.mjs CHANGED
@@ -6,11 +6,11 @@ import '@nuxt/kit';
6
6
  import 'defu';
7
7
  import 'fnv1a-64';
8
8
  import 'nuxt-site-config/kit';
9
+ import 'nuxtseo-shared/kit';
9
10
  import 'pathe';
10
11
  import 'pkg-types';
11
12
  import 'std-env';
12
- export { m as default } from './shared/nuxt-og-image.Bv8VSGTj.mjs';
13
- import 'nuxtseo-shared/kit';
13
+ export { n as default } from './shared/nuxt-og-image.BIbfn5xQ.mjs';
14
14
  import '../dist/runtime/logger.js';
15
15
  import 'oxc-walker';
16
16
  import 'chrome-launcher';
@@ -1 +1,2 @@
1
- export { ogImageCanonicalUrls as default } from '../utils/plugins.js';
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -1 +1,3 @@
1
- export { ogImageCanonicalUrls as default } from "../utils/plugins.js";
1
+ import { defineNuxtPlugin } from "#app";
2
+ import { ogImageCanonicalUrls } from "../utils/plugins.js";
3
+ export default defineNuxtPlugin((nuxtApp) => ogImageCanonicalUrls(nuxtApp));
@@ -1 +1,2 @@
1
- export { routeRuleOgImage as default } from '../utils/plugins.js';
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -1 +1,3 @@
1
- export { routeRuleOgImage as default } from "../utils/plugins.js";
1
+ import { defineNuxtPlugin } from "#app";
2
+ import { routeRuleOgImage } from "../utils/plugins.js";
3
+ export default defineNuxtPlugin((nuxtApp) => routeRuleOgImage(nuxtApp));
@@ -1,7 +1,7 @@
1
1
  import { TemplateParamsPlugin } from "@unhead/vue/plugins";
2
2
  import { defu } from "defu";
3
- import { createRouter as createRadixRouter, toRouteMatcher } from "radix3";
4
- import { parseURL, withoutBase } from "ufo";
3
+ import { createNitroRouteRuleMatcher } from "nuxtseo-shared/server";
4
+ import { parseURL } from "ufo";
5
5
  import { toValue } from "vue";
6
6
  import { defineNuxtPlugin, useRequestEvent } from "#app";
7
7
  import { withSiteUrl } from "#site-config/app/composables";
@@ -60,14 +60,8 @@ export const routeRuleOgImage = defineNuxtPlugin((nuxtApp) => {
60
60
  const path = parseURL(e?.path || "").pathname;
61
61
  if (isInternalRoute(path))
62
62
  return;
63
- const _routeRulesMatcher = toRouteMatcher(
64
- createRadixRouter({ routes: ssrContext?.runtimeConfig?.nitro?.routeRules })
65
- );
66
- const matchedRules = _routeRulesMatcher.matchAll(
67
- withoutBase(path.split("?")?.[0] || "", ssrContext?.runtimeConfig?.app.baseURL || "")
68
- ).reverse();
69
- const combinedRules = defu({}, ...matchedRules);
70
- let routeRules = combinedRules?.ogImage;
63
+ const matchRouteRules = createNitroRouteRuleMatcher(ssrContext?.runtimeConfig || {});
64
+ let routeRules = matchRouteRules(path).ogImage;
71
65
  if (typeof routeRules === "undefined")
72
66
  return;
73
67
  if (routeRules === false) {
@@ -1,8 +1,4 @@
1
- import { createConsola } from "consola";
2
1
  import { colorize } from "consola/utils";
3
- export const logger = createConsola({
4
- defaults: {
5
- tag: "@nuxtjs/og-image"
6
- }
7
- });
2
+ import { createModuleLogger } from "nuxtseo-shared/utils";
3
+ export const logger = createModuleLogger("@nuxtjs/og-image");
8
4
  export const gray = (s) => colorize("gray", s);
@@ -3,4 +3,3 @@ export declare function extractSocialPreviewTags(html: string): [Record<string,
3
3
  export declare function detectBase64MimeType(data: string): string;
4
4
  export declare function toBase64Image(data: string | ArrayBuffer): string;
5
5
  export declare function withoutQuery(path: string): string | undefined;
6
- export declare function getExtension(path: string): string;
@@ -65,8 +65,3 @@ export function toBase64Image(data) {
65
65
  export function withoutQuery(path) {
66
66
  return path.split("?")[0];
67
67
  }
68
- export function getExtension(path) {
69
- path = withoutQuery(path);
70
- const lastSegment = path.split("/").pop() || path;
71
- return lastSegment.split(".").pop() || lastSegment;
72
- }
@@ -1,3 +1,3 @@
1
- import type { H3Event } from 'h3';
2
1
  import type { Browser } from 'playwright-core';
2
+ import type { H3Event } from '#nuxtseo/h3';
3
3
  export declare function createBrowser(_event?: H3Event): Promise<Browser | void>;
@@ -1,4 +1,4 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '#nuxtseo/h3';
2
2
  interface Browser {
3
3
  connected: boolean;
4
4
  newPage: () => Promise<any>;
@@ -6,5 +6,4 @@ interface Browser {
6
6
  on: (event: string, handler: () => void) => void;
7
7
  }
8
8
  export declare function createBrowser(event?: H3Event): Promise<Browser>;
9
- export declare function disposeBrowser(): Promise<void>;
10
9
  export {};
@@ -1,3 +1,4 @@
1
+ import { getCloudflareEnv } from "../../../util/cloudflare.js";
1
2
  import { withTimeout } from "../../../util/withTimeout.js";
2
3
  import { useOgImageRuntimeConfig } from "../../../utils.js";
3
4
  let puppeteer;
@@ -20,7 +21,7 @@ export async function createBrowser(event) {
20
21
  "[Nuxt OG Image] Browser binding name not configured. Set `ogImage.browser.binding` in nuxt.config."
21
22
  );
22
23
  }
23
- const binding = event?.context?.cloudflare?.env?.[bindingName];
24
+ const binding = getCloudflareEnv(event)?.[bindingName];
24
25
  if (!binding) {
25
26
  throw new Error(
26
27
  `[Nuxt OG Image] Cloudflare browser binding "${bindingName}" not found. Ensure it's configured in wrangler.toml and the request has cloudflare context.`
@@ -45,11 +46,3 @@ export async function createBrowser(event) {
45
46
  browserPromise = null;
46
47
  return browser;
47
48
  }
48
- export async function disposeBrowser() {
49
- if (browser) {
50
- await browser.close().catch((err) => {
51
- void err;
52
- });
53
- browser = null;
54
- }
55
- }
@@ -1,3 +1,3 @@
1
- import type { H3Event } from 'h3';
2
1
  import type { Browser } from 'playwright-core';
2
+ import type { H3Event } from '#nuxtseo/h3';
3
3
  export declare function createBrowser(_event?: H3Event): Promise<Browser | void>;
@@ -1,3 +1,3 @@
1
- import type { H3Event } from 'h3';
2
1
  import type { Browser } from 'playwright-core';
2
+ import type { H3Event } from '#nuxtseo/h3';
3
3
  export declare function createBrowser(_event?: H3Event): Promise<Browser | void>;
@@ -1,3 +1,3 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '#nuxtseo/h3';
2
2
  import type { FontConfig } from '../../../../types.js';
3
3
  export declare function resolve(event: H3Event, font: FontConfig): Promise<Buffer<ArrayBufferLike>>;
@@ -1,5 +1,5 @@
1
- import { useRuntimeConfig } from "nitropack/runtime";
2
1
  import { withBase } from "ufo";
2
+ import { useRuntimeConfig } from "#nuxtseo/nitro";
3
3
  import { getSiteConfig } from "#site-config/server/composables";
4
4
  import { getCloudflareAssets } from "../../../util/cloudflareAssets.js";
5
5
  import { fetchLocalAsset } from "../../../util/fetchLocalAsset.js";
@@ -1,3 +1,3 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '#nuxtseo/h3';
2
2
  import type { FontConfig } from '../../../../types.js';
3
3
  export declare function resolve(event: H3Event, font: FontConfig): Promise<Buffer>;
@@ -1,8 +1,8 @@
1
1
  import { readFile } from "node:fs/promises";
2
- import { getRequestURL } from "h3";
3
- import { useRuntimeConfig } from "nitropack/runtime";
4
2
  import { join } from "pathe";
5
3
  import { withBase } from "ufo";
4
+ import { getRequestURL } from "#nuxtseo/h3";
5
+ import { useRuntimeConfig } from "#nuxtseo/nitro";
6
6
  import { buildDir, rootDir } from "#og-image-virtual/build-dir.mjs";
7
7
  import { getSiteConfig } from "#site-config/server/composables";
8
8
  import { getFetchTimeout } from "../../../util/fetchTimeout.js";
@@ -10,11 +10,23 @@ import { fetchWithRedirectValidation } from "../../../util/ssrf.js";
10
10
  import { useOgImageRuntimeConfig } from "../../../utils.js";
11
11
  import { fetchSpecialFontUrl, isDataFontUrl, isExternalFontUrl } from "./external-url.js";
12
12
  let fontUrlMapping;
13
+ async function readOptionalFile(path) {
14
+ return readFile(path).catch((error) => {
15
+ if (error.code === "ENOENT")
16
+ return null;
17
+ throw error;
18
+ });
19
+ }
20
+ async function fetchOptionalFont(url, timeout) {
21
+ return fetch(url, { signal: AbortSignal.timeout(timeout) }).catch(() => {
22
+ return null;
23
+ });
24
+ }
13
25
  async function loadFontUrlMapping() {
14
26
  if (fontUrlMapping)
15
27
  return fontUrlMapping;
16
- const content = await readFile(join(buildDir, "cache", "og-image", "font-urls.json"), "utf-8").catch(() => null);
17
- fontUrlMapping = content ? JSON.parse(content) : {};
28
+ const content = await readOptionalFile(join(buildDir, "cache", "og-image", "font-urls.json"));
29
+ fontUrlMapping = content ? JSON.parse(content.toString("utf-8")) : {};
18
30
  return fontUrlMapping;
19
31
  }
20
32
  export async function resolve(event, font) {
@@ -22,7 +34,7 @@ export async function resolve(event, font) {
22
34
  const runtimeConfig = useOgImageRuntimeConfig();
23
35
  const timeout = getFetchTimeout(runtimeConfig);
24
36
  if (font.absolutePath) {
25
- const data = await readFile(font.absolutePath).catch(() => null);
37
+ const data = await readOptionalFile(font.absolutePath);
26
38
  if (data?.length)
27
39
  return data;
28
40
  }
@@ -31,31 +43,31 @@ export async function resolve(event, font) {
31
43
  if (import.meta.prerender) {
32
44
  if (path.startsWith("/_og-static-fonts/")) {
33
45
  const filename2 = path.slice("/_og-static-fonts/".length);
34
- const cached = await readFile(join(buildDir, "cache", "og-image", "fonts-ttf", filename2)).catch(() => null) || await readFile(join(rootDir, ".output", "public", "_og-static-fonts", filename2)).catch(() => null);
46
+ const cached = await readOptionalFile(join(buildDir, "cache", "og-image", "fonts-ttf", filename2)) || await readOptionalFile(join(rootDir, ".output", "public", "_og-static-fonts", filename2));
35
47
  if (cached?.length)
36
48
  return cached;
37
49
  }
38
50
  if (path.startsWith("/_fonts/")) {
39
51
  const filename2 = path.slice("/_fonts/".length);
40
- const cached = await readFile(join(rootDir, ".output", "public", "_fonts", filename2)).catch(() => null);
52
+ const cached = await readOptionalFile(join(rootDir, ".output", "public", "_fonts", filename2));
41
53
  if (cached?.length)
42
54
  return cached;
43
55
  const mapping = await loadFontUrlMapping();
44
56
  if (mapping[filename2]) {
45
- const res = await fetch(mapping[filename2], { signal: AbortSignal.timeout(timeout) }).catch(() => null);
57
+ const res = await fetchOptionalFont(mapping[filename2], timeout);
46
58
  if (res?.ok)
47
59
  return Buffer.from(await res.arrayBuffer());
48
60
  }
49
61
  throw new Error(`Font ${filename2} not found in mapping or cache`);
50
62
  }
51
63
  const filename = path.slice(1);
52
- const data = await readFile(join(rootDir, "public", filename)).catch(() => null) || await readFile(join(rootDir, ".output", "public", filename)).catch(() => null);
64
+ const data = await readOptionalFile(join(rootDir, "public", filename)) || await readOptionalFile(join(rootDir, ".output", "public", filename));
53
65
  if (data?.length)
54
66
  return data;
55
67
  }
56
68
  if (path.startsWith("/_og-static-fonts/")) {
57
69
  const filename = path.slice("/_og-static-fonts/".length);
58
- const cached = await readFile(join(buildDir, "cache", "og-image", "fonts-ttf", filename)).catch(() => null);
70
+ const cached = await readOptionalFile(join(buildDir, "cache", "og-image", "fonts-ttf", filename));
59
71
  if (cached?.length)
60
72
  return cached;
61
73
  }
@@ -63,14 +75,14 @@ export async function resolve(event, font) {
63
75
  const filename = path.slice("/_fonts/".length);
64
76
  const mapping = await loadFontUrlMapping();
65
77
  if (mapping[filename]) {
66
- const res = await fetch(mapping[filename], { signal: AbortSignal.timeout(timeout) }).catch(() => null);
78
+ const res = await fetchOptionalFont(mapping[filename], timeout);
67
79
  if (res?.ok)
68
80
  return Buffer.from(await res.arrayBuffer());
69
81
  }
70
82
  }
71
83
  if (import.meta.dev) {
72
84
  const filename = path.slice(1);
73
- const data = await readFile(join(rootDir, "public", filename)).catch(() => null);
85
+ const data = await readOptionalFile(join(rootDir, "public", filename));
74
86
  if (data?.length)
75
87
  return data;
76
88
  }
@@ -79,7 +91,9 @@ export async function resolve(event, font) {
79
91
  const reqUrl = getRequestURL(event);
80
92
  const origin = `${reqUrl.protocol}//${reqUrl.host}`;
81
93
  const target = new URL(withBase(path, app.baseURL), origin);
82
- const ab = await fetchWithRedirectValidation(target.href, { timeout, trustedHost: target.host }).catch(() => null);
94
+ const ab = await fetchWithRedirectValidation(target.href, { timeout, trustedHost: target.host }).catch(() => {
95
+ return null;
96
+ });
83
97
  if (ab) {
84
98
  return Buffer.from(ab);
85
99
  }
@@ -32,7 +32,9 @@ export function resolveSameOriginFontUrl(path, siteUrl) {
32
32
  }
33
33
  export async function fetchSpecialFontUrl(path, siteUrl, timeout) {
34
34
  if (isDataFontUrl(path)) {
35
- const res = await fetch(path.trimStart(), { signal: AbortSignal.timeout(timeout) }).catch(() => null);
35
+ const res = await fetch(path.trimStart(), { signal: AbortSignal.timeout(timeout) }).catch(() => {
36
+ return null;
37
+ });
36
38
  if (res?.ok)
37
39
  return Buffer.from(await res.arrayBuffer());
38
40
  throw new Error("[Nuxt OG Image] Invalid data: font URL.");
@@ -1,3 +1,3 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '#nuxtseo/h3';
2
2
  import type { FontConfig } from '../../../../types.js';
3
3
  export declare function resolve(event: H3Event, font: FontConfig): Promise<Buffer<ArrayBufferLike>>;
@@ -1,5 +1,5 @@
1
- import { useRuntimeConfig } from "nitropack/runtime";
2
1
  import { withBase } from "ufo";
2
+ import { useRuntimeConfig } from "#nuxtseo/nitro";
3
3
  import { getNitroOrigin, getSiteConfig } from "#site-config/server/composables";
4
4
  import { getFetchTimeout } from "../../../util/fetchTimeout.js";
5
5
  import { fetchWithRedirectValidation } from "../../../util/ssrf.js";
@@ -15,7 +15,9 @@ export async function resolve(event, font) {
15
15
  if (path && (isDataFontUrl(path) || isExternalFontUrl(path)))
16
16
  return fetchSpecialFontUrl(path, getSiteConfig(event).url, timeout);
17
17
  const target = new URL(fullPath, origin);
18
- const ab = await fetchWithRedirectValidation(target.href, { timeout, trustedHost: target.host }).catch(() => null);
18
+ const ab = await fetchWithRedirectValidation(target.href, { timeout, trustedHost: target.host }).catch(() => {
19
+ return null;
20
+ });
19
21
  if (ab) {
20
22
  return Buffer.from(ab);
21
23
  }