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
@@ -0,0 +1,17 @@
1
+ function toRecord(value) {
2
+ return typeof value === "object" && value !== null ? value : void 0;
3
+ }
4
+ export function getCloudflareEnv(event) {
5
+ const runtime = event && "runtime" in event ? toRecord(event.runtime) : void 0;
6
+ const runtimeCloudflare = toRecord(runtime?.cloudflare);
7
+ const runtimeEnv = toRecord(runtimeCloudflare?.env);
8
+ if (runtimeEnv)
9
+ return runtimeEnv;
10
+ const contextCloudflare = toRecord(event?.context.cloudflare);
11
+ const contextEnv = toRecord(contextCloudflare?.env);
12
+ if (contextEnv)
13
+ return contextEnv;
14
+ const platform = toRecord(event?.context._platform);
15
+ const platformCloudflare = toRecord(platform?.cloudflare);
16
+ return toRecord(platformCloudflare?.env);
17
+ }
@@ -1,4 +1,4 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '#nuxtseo/h3';
2
2
  interface AssetsBinding {
3
3
  fetch: (request: string | Request, init?: RequestInit) => Promise<Response>;
4
4
  }
@@ -1,15 +1,18 @@
1
- import { getRequestHost } from "h3";
1
+ import { getRequestURL } from "#nuxtseo/h3";
2
+ import { getCloudflareEnv } from "./cloudflare.js";
2
3
  export function getCloudflareAssets(event) {
3
- const assets = event.context.cloudflare?.env?.ASSETS || event.context.ASSETS;
4
- return assets && typeof assets.fetch === "function" ? assets : void 0;
4
+ const assets = getCloudflareEnv(event)?.ASSETS || event.context.ASSETS;
5
+ return typeof assets === "object" && assets !== null && "fetch" in assets && typeof assets.fetch === "function" ? assets : void 0;
5
6
  }
6
7
  export async function tryCloudflareAssetsFetch(event, path, signal) {
7
8
  const assets = getCloudflareAssets(event);
8
9
  if (!assets)
9
10
  return;
10
- const origin = event.context.cloudflare?.request?.url || `https://${getRequestHost(event) || "localhost"}`;
11
+ const origin = getRequestURL(event).origin;
11
12
  const url = new URL(path, origin).href;
12
- const res = await assets.fetch(url, signal ? { signal } : void 0).catch(() => null);
13
+ const res = await assets.fetch(url, signal ? { signal } : void 0).catch(() => {
14
+ return null;
15
+ });
13
16
  if (!res || !res.ok)
14
17
  return;
15
18
  return res.arrayBuffer();
@@ -1,3 +1,2 @@
1
1
  export declare function htmlDecodeQuotes(html: string): string;
2
2
  export declare function decodeHtml(html: string): string;
3
- export declare function decodeObjectHtmlEntities(obj: Record<string, string | any>): Record<string, any>;
@@ -20,10 +20,3 @@ export function decodeHtml(html) {
20
20
  return String.fromCharCode(Number.parseInt(int));
21
21
  }).replace(RE_AMP, "&");
22
22
  }
23
- export function decodeObjectHtmlEntities(obj) {
24
- Object.entries(obj).forEach(([key, value]) => {
25
- if (typeof value === "string")
26
- obj[key] = decodeHtml(value);
27
- });
28
- return obj;
29
- }
@@ -1,2 +1,2 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '#nuxtseo/h3';
2
2
  export declare function imageEventHandler(e: H3Event): Promise<any>;
@@ -1,4 +1,4 @@
1
- import { createError, getRequestHost, H3Error, setHeader } from "h3";
1
+ import { createError, getRequestHost, H3Error, setHeader } from "#nuxtseo/h3";
2
2
  import { getSiteConfig } from "#site-config/server/composables/getSiteConfig";
3
3
  import { logger } from "../../logger.js";
4
4
  import { getBuildCachedImage, setBuildCachedImage } from "../og-image/cache/buildCache.js";
@@ -1,4 +1,4 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '#nuxtseo/h3';
2
2
  export interface FetchLocalAssetOptions {
3
3
  fetchTimeout: number;
4
4
  headers?: Record<string, string>;
@@ -1,6 +1,9 @@
1
- import type { H3Event } from 'h3';
2
- import type { NitroRouteRules } from 'nitropack';
3
1
  import type { NuxtIslandResponse } from 'nuxt/app';
4
- export { withoutQuery } from 'nuxtseo-shared/utils';
2
+ import type { H3Event } from '#nuxtseo/h3';
3
+ import type { OgImageOptions } from '../../types.js';
4
+ interface OgImageRouteRules {
5
+ ogImage?: false | OgImageOptions & Record<string, any>;
6
+ }
5
7
  export declare function fetchIsland(e: H3Event, component: string, props: Record<string, any>, timeout?: number): Promise<NuxtIslandResponse>;
6
- export declare function createNitroRouteRuleMatcher(): ((path: string) => NitroRouteRules);
8
+ export declare function createNitroRouteRuleMatcher(): ((path: string) => OgImageRouteRules);
9
+ export {};
@@ -1,13 +1,10 @@
1
- import { defu } from "defu";
2
- import { useRuntimeConfig } from "nitropack/runtime";
3
- import { createRouter as createRadixRouter, toRouteMatcher } from "radix3";
4
- import { withoutBase, withoutTrailingSlash } from "ufo";
1
+ import { createNitroRouteRuleMatcher as createRouteRuleMatcher } from "nuxtseo-shared/server";
2
+ import { fetchWithEvent, useRuntimeConfig } from "#nuxtseo/nitro";
5
3
  import { getIslandHash } from "#og-image/island-hash";
6
- export { withoutQuery } from "nuxtseo-shared/utils";
7
4
  export function fetchIsland(e, component, props, timeout) {
8
5
  const hashId = getIslandHash({ name: component, props });
9
6
  const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
10
- return e.$fetch(`/__nuxt_island/${component}_${hashId}.json`, {
7
+ return fetchWithEvent(e, `/__nuxt_island/${component}_${hashId}.json`, {
11
8
  params: {
12
9
  props: JSON.stringify(props)
13
10
  },
@@ -16,17 +13,5 @@ export function fetchIsland(e, component, props, timeout) {
16
13
  });
17
14
  }
18
15
  export function createNitroRouteRuleMatcher() {
19
- const { nitro, app } = useRuntimeConfig();
20
- const _routeRulesMatcher = toRouteMatcher(
21
- createRadixRouter({
22
- routes: Object.fromEntries(
23
- Object.entries(nitro?.routeRules || {}).map(([path, rules]) => [withoutTrailingSlash(path), rules])
24
- )
25
- })
26
- );
27
- return (path) => {
28
- return defu({}, ..._routeRulesMatcher.matchAll(
29
- withoutBase(withoutTrailingSlash(path.split("?")[0]), app.baseURL)
30
- ).reverse());
31
- };
16
+ return createRouteRuleMatcher(useRuntimeConfig());
32
17
  }
@@ -1,6 +1,2 @@
1
- import { createConsola } from "consola";
2
- export const logger = createConsola({
3
- defaults: {
4
- tag: "Nuxt OG Image"
5
- }
6
- });
1
+ import { createModuleLogger } from "nuxtseo-shared/utils";
2
+ export const logger = createModuleLogger("Nuxt OG Image");
@@ -1,4 +1,4 @@
1
- import { createError } from "h3";
1
+ import { createError } from "#nuxtseo/h3";
2
2
  import { componentNames } from "#og-image-virtual/component-names.mjs";
3
3
  const RENDERER_SUFFIXES = ["satori", "browser", "takumi"];
4
4
  const RE_RENDERER_SUFFIX_DOT = /\.?(satori|browser|takumi)$/i;
@@ -1,4 +1,4 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '#nuxtseo/h3';
2
2
  /**
3
3
  * Parse query parameters from the event path without relying on the H3 event
4
4
  * implementation. Nitro adapters can pass an H3 v1 event to bundled H3 v2
@@ -12,6 +12,3 @@ export interface Timings {
12
12
  }
13
13
  export declare function createTimings(): Timings;
14
14
  export declare const TIMING_CTX_KEY = "_ogImageTimings";
15
- export declare function getTimingsFromEvent(e: {
16
- context: Record<string, any>;
17
- }): Timings | undefined;
@@ -70,6 +70,3 @@ export function createTimings() {
70
70
  return { start, record, measure, entries, header };
71
71
  }
72
72
  export const TIMING_CTX_KEY = "_ogImageTimings";
73
- export function getTimingsFromEvent(e) {
74
- return e.context[TIMING_CTX_KEY];
75
- }
@@ -1,4 +1,4 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '#nuxtseo/h3';
2
2
  import type { OgImageOptionsInternal, OgImageRuntimeConfig } from '../types.js';
3
3
  export interface GetOgImagePathResult {
4
4
  path: string;
@@ -1,7 +1,8 @@
1
- import { useRuntimeConfig } from "nitropack/runtime";
2
1
  import { joinURL } from "ufo";
2
+ import { useRuntimeConfig } from "#nuxtseo/nitro";
3
3
  import { componentNames } from "#og-image-virtual/component-names.mjs";
4
4
  import { buildOgImageUrl } from "../shared.js";
5
+ import { getCloudflareEnv } from "./util/cloudflare.js";
5
6
  export function getOgImagePath(_pagePath, _options) {
6
7
  const baseURL = useRuntimeConfig().app.baseURL;
7
8
  const { defaults, security } = useOgImageRuntimeConfig();
@@ -20,9 +21,11 @@ export function getOgImagePath(_pagePath, _options) {
20
21
  }
21
22
  export function useOgImageRuntimeConfig(e) {
22
23
  const c = useRuntimeConfig(e);
23
- const moduleCfg = c["nuxt-og-image"] || {};
24
- const cloudflareEnv = e?.context.cloudflare?.env || e?.context?._platform?.cloudflare?.env;
25
- const overrideSecret = c.ogImage?.secret || cloudflareEnv?.NUXT_OG_IMAGE_SECRET;
24
+ const moduleCfg = c["nuxt-og-image"];
25
+ const cloudflareEnv = getCloudflareEnv(e);
26
+ const runtimeSecret = c.ogImage?.secret;
27
+ const cloudflareSecret = cloudflareEnv?.NUXT_OG_IMAGE_SECRET;
28
+ const overrideSecret = typeof runtimeSecret === "string" && runtimeSecret ? runtimeSecret : typeof cloudflareSecret === "string" ? cloudflareSecret : void 0;
26
29
  const security = overrideSecret ? { ...moduleCfg.security || {}, secret: overrideSecret } : moduleCfg.security;
27
30
  return {
28
31
  defaults: {},
@@ -1,16 +1,10 @@
1
1
  import type { ResvgRenderOptions } from '@resvg/resvg-js';
2
2
  import type { AllowedComponentProps, Component, ComponentCustomProps, VNodeProps } from '@vue/runtime-core';
3
- import type { H3Error, H3Event } from 'h3';
4
- import type { Hookable } from 'hookable';
5
- import type { NitroRuntimeHooks } from 'nitropack/types';
6
3
  import type { SatoriOptions } from 'satori';
7
4
  import type { JpegOptions, SharpOptions } from 'sharp';
8
5
  import type { MaybeRefOrGetter, Ref } from 'vue';
6
+ import type { H3Error, H3Event } from '#nuxtseo/h3';
9
7
  import type { Timings } from './server/util/timings.js';
10
- interface NitroApp {
11
- hooks: Hookable<NitroRuntimeHooks>;
12
- [key: string]: any;
13
- }
14
8
  export interface OgImageRenderEventContext {
15
9
  e: H3Event;
16
10
  extension: 'png' | 'jpeg' | 'jpg' | 'webp' | 'svg' | 'html' | 'json';
@@ -22,10 +16,19 @@ export interface OgImageRenderEventContext {
22
16
  publicStoragePath: string;
23
17
  runtimeConfig: OgImageRuntimeConfig;
24
18
  timings: Timings;
25
- _nitro: NitroApp;
19
+ _nitro: ReturnType<typeof import('#nuxtseo/nitro').useNitroApp>;
26
20
  }
27
21
  export type IconifyEmojiIconSets = 'twemoji' | 'noto' | 'fluent-emoji' | 'fluent-emoji-flat' | 'fluent-emoji-high-contrast' | 'noto-v1' | 'emojione' | 'emojione-monotone' | 'emojione-v1' | 'streamline-emojis' | 'openmoji';
28
22
  export type EmojiStrategy = 'auto' | 'local' | 'fetch';
23
+ export interface OgImageIconsData {
24
+ icons: Record<string, {
25
+ body: string;
26
+ width?: number;
27
+ height?: number;
28
+ }>;
29
+ width: number;
30
+ height: number;
31
+ }
29
32
  export interface OgImageRuntimeConfig {
30
33
  version: string;
31
34
  satoriOptions: SatoriOptions;
@@ -298,4 +301,3 @@ export interface SocialPreviewMetaData {
298
301
  export interface RouteRulesOgImage extends Partial<OgImageOptions> {
299
302
  [key: string]: any;
300
303
  }
301
- export {};