nuxt-og-image 2.0.4 → 2.0.5

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 (51) hide show
  1. package/dist/client/200.html +2 -2
  2. package/dist/client/404.html +2 -2
  3. package/dist/client/_nuxt/{IconCSS.b4882023.js → IconCSS.c66ac96c.js} +1 -1
  4. package/dist/client/_nuxt/{ImageLoader.b68e14b5.js → ImageLoader.eea58cf7.js} +1 -1
  5. package/dist/client/_nuxt/{entry.fb0efd99.js → entry.db904b01.js} +63 -63
  6. package/dist/client/_nuxt/{error-404.644be599.js → error-404.3fd437f7.js} +1 -1
  7. package/dist/client/_nuxt/{error-500.a96819db.js → error-500.48bc2fce.js} +1 -1
  8. package/dist/client/_nuxt/{index.60e5b582.js → index.62ad0f4a.js} +1 -1
  9. package/dist/client/_nuxt/{options.727a8560.js → options.8bd8132d.js} +1 -1
  10. package/dist/client/_nuxt/{png.42d9c3d5.js → png.8fd55f17.js} +1 -1
  11. package/dist/client/_nuxt/shiki.eca11a4d.js +7 -0
  12. package/dist/client/_nuxt/{svg.c50d59f2.js → svg.6552a6ca.js} +1 -1
  13. package/dist/client/_nuxt/{vnodes.12ed942f.js → vnodes.5bb613d8.js} +1 -1
  14. package/dist/client/index.html +2 -2
  15. package/dist/module.json +1 -1
  16. package/dist/module.mjs +45 -31
  17. package/dist/runtime/browserUtil.d.ts +1 -1
  18. package/dist/runtime/components/OgImage/Cached.d.ts +1 -1
  19. package/dist/runtime/components/OgImage/Dynamic.d.ts +1 -1
  20. package/dist/runtime/components/OgImage/Screenshot.d.ts +1 -1
  21. package/dist/runtime/components/OgImage/Static.d.ts +1 -1
  22. package/dist/runtime/components/OgImage/WithoutCache.d.ts +1 -1
  23. package/dist/runtime/components/OgImage/index.d.ts +1 -1
  24. package/dist/runtime/composables/defineOgImage.d.ts +1 -1
  25. package/dist/runtime/composables/util.d.ts +1 -1
  26. package/dist/runtime/composables/util.mjs +5 -9
  27. package/dist/runtime/nitro/providers/png/resvg-node.d.ts +1 -1
  28. package/dist/runtime/nitro/providers/png/resvg-wasm.d.ts +1 -1
  29. package/dist/runtime/nitro/providers/png/svg2png.d.ts +1 -1
  30. package/dist/runtime/nitro/providers/satori/yoga-wasm.d.ts +1 -1
  31. package/dist/runtime/nitro/renderers/browser.d.ts +1 -1
  32. package/dist/runtime/nitro/renderers/satori/index.d.ts +1 -1
  33. package/dist/runtime/nitro/renderers/satori/plugins/emojis.d.ts +1 -1
  34. package/dist/runtime/nitro/renderers/satori/plugins/encoding.d.ts +1 -1
  35. package/dist/runtime/nitro/renderers/satori/plugins/flex.d.ts +1 -1
  36. package/dist/runtime/nitro/renderers/satori/plugins/imageSrc.d.ts +1 -1
  37. package/dist/runtime/nitro/renderers/satori/plugins/twClasses.d.ts +1 -1
  38. package/dist/runtime/nitro/renderers/satori/utils.d.ts +1 -1
  39. package/dist/runtime/nitro/routes/options.d.ts +1 -1
  40. package/dist/runtime/nitro/routes/options.mjs +8 -8
  41. package/dist/runtime/nitro/utils-pure.d.ts +2 -2
  42. package/dist/runtime/nitro/utils-pure.mjs +9 -3
  43. package/dist/runtime/nitro/utils.d.ts +1 -1
  44. package/dist/runtime/types.d.ts +69 -0
  45. package/dist/runtime/types.mjs +0 -0
  46. package/package.json +14 -11
  47. package/dist/client/_nuxt/shiki.4d6ce36e.js +0 -7
  48. package/dist/client/options/index.html +0 -7
  49. package/dist/client/png/index.html +0 -7
  50. package/dist/client/svg/index.html +0 -7
  51. package/dist/client/vnodes/index.html +0 -7
@@ -1,4 +1,4 @@
1
- import type { OgImageScreenshotOptions } from '../../../types';
1
+ import type { OgImageScreenshotOptions } from '../../types';
2
2
  declare const _default: import("vue").DefineComponent<OgImageScreenshotOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<OgImageScreenshotOptions>>, {
3
3
  [x: string]: any;
4
4
  [x: number]: any;
@@ -1,4 +1,4 @@
1
- import type { OgImageOptions } from '../../../types';
1
+ import type { OgImageOptions } from '../../types';
2
2
  /**
3
3
  * @deprecated Use OgImageCached instead
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { OgImageOptions } from '../../../types';
1
+ import type { OgImageOptions } from '../../types';
2
2
  declare const _default: import("vue").DefineComponent<OgImageOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<OgImageOptions>>, {
3
3
  [x: string]: any;
4
4
  }, {}>;
@@ -1,4 +1,4 @@
1
- import type { OgImageOptions } from '../../../types';
1
+ import type { OgImageOptions } from '../../types';
2
2
  declare const _default: import("vue").DefineComponent<OgImageOptions, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<OgImageOptions>>, {
3
3
  [x: string]: any;
4
4
  }, {}>;
@@ -1,4 +1,4 @@
1
- import type { OgImageOptions, OgImageScreenshotOptions } from '../../types';
1
+ import type { OgImageOptions, OgImageScreenshotOptions } from '../types';
2
2
  export declare function defineOgImageScreenshot(options?: OgImageScreenshotOptions): Promise<void>;
3
3
  /**
4
4
  * @deprecated Use `defineOgImage` or `defineOgImageCached` instead
@@ -1,2 +1,2 @@
1
- import type { OgImageOptions } from '../../types';
1
+ import type { OgImageOptions } from '../types';
2
2
  export declare function normaliseOgImageOptions(_options: OgImageOptions): any;
@@ -11,15 +11,11 @@ export function normaliseOgImageOptions(_options) {
11
11
  options.provider = "browser";
12
12
  if (options.component && componentNames) {
13
13
  const originalName = options.component;
14
- let isValid = componentNames.some((component) => component.pascalName === originalName || component.kebabName === originalName);
15
- if (!isValid) {
16
- for (const component of componentNames) {
17
- if (component.pascalName.endsWith(originalName) || component.kebabName.endsWith(originalName)) {
18
- options.component = component.pascalName;
19
- options.componentHash = component.hash;
20
- isValid = true;
21
- break;
22
- }
14
+ for (const component of componentNames) {
15
+ if (component.pascalName.endsWith(originalName) || component.kebabName.endsWith(originalName)) {
16
+ options.component = component.pascalName;
17
+ options.componentHash = component.hash;
18
+ break;
23
19
  }
24
20
  }
25
21
  }
@@ -1,4 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  import type { ResvgRenderOptions } from '@resvg/resvg-js';
3
- import type { RuntimeOgImageOptions } from '../../../../types';
3
+ import type { RuntimeOgImageOptions } from '../../../types';
4
4
  export default function (svg: string, options: ResvgRenderOptions & RuntimeOgImageOptions): Promise<Buffer>;
@@ -1,3 +1,3 @@
1
1
  import type { ResvgRenderOptions } from '@resvg/resvg-wasm';
2
- import type { RuntimeOgImageOptions } from '../../../../types';
2
+ import type { RuntimeOgImageOptions } from '../../../types';
3
3
  export default function (svg: string, options: ResvgRenderOptions & RuntimeOgImageOptions): Promise<Uint8Array>;
@@ -1,3 +1,3 @@
1
1
  import type { ConvertOptions } from 'svg2png-wasm';
2
- import type { RuntimeOgImageOptions } from '../../../../types';
2
+ import type { RuntimeOgImageOptions } from '../../../types';
3
3
  export default function (svg: string, options: ConvertOptions & RuntimeOgImageOptions): Promise<Uint8Array>;
@@ -1,3 +1,3 @@
1
1
  import type { SatoriOptions } from 'satori';
2
- import type { RuntimeOgImageOptions } from '../../../../types';
2
+ import type { RuntimeOgImageOptions } from '../../../types';
3
3
  export default function (nodes: string, options: SatoriOptions & RuntimeOgImageOptions): Promise<string>;
@@ -1,3 +1,3 @@
1
- import type { Renderer } from '../../../types';
1
+ import type { Renderer } from '../../types';
2
2
  declare const BrowserRenderer: Renderer;
3
3
  export default BrowserRenderer;
@@ -1,3 +1,3 @@
1
- import type { Renderer } from '../../../../types';
1
+ import type { Renderer } from '../../../types';
2
2
  declare const SatoriRenderer: Renderer;
3
3
  export default SatoriRenderer;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../../../../../types").SatoriTransformer | import("../../../../../types").SatoriTransformer[];
1
+ declare const _default: import("../../../../types").SatoriTransformer | import("../../../../types").SatoriTransformer[];
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../../../../../types").SatoriTransformer | import("../../../../../types").SatoriTransformer[];
1
+ declare const _default: import("../../../../types").SatoriTransformer | import("../../../../types").SatoriTransformer[];
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../../../../../types").SatoriTransformer | import("../../../../../types").SatoriTransformer[];
1
+ declare const _default: import("../../../../types").SatoriTransformer | import("../../../../types").SatoriTransformer[];
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../../../../../types").SatoriTransformer | import("../../../../../types").SatoriTransformer[];
1
+ declare const _default: import("../../../../types").SatoriTransformer | import("../../../../types").SatoriTransformer[];
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("../../../../../types").SatoriTransformer | import("../../../../../types").SatoriTransformer[];
1
+ declare const _default: import("../../../../types").SatoriTransformer | import("../../../../types").SatoriTransformer[];
2
2
  export default _default;
@@ -1,4 +1,4 @@
1
- import type { FontConfig, RuntimeOgImageOptions, SatoriTransformer, VNode } from '../../../../types';
1
+ import type { FontConfig, RuntimeOgImageOptions, SatoriTransformer, VNode } from '../../../types';
2
2
  export declare function loadFont(requestOrigin: string, font: FontConfig): Promise<any>;
3
3
  export declare function walkSatoriTree(node: VNode, plugins: (SatoriTransformer | SatoriTransformer[])[], props: RuntimeOgImageOptions): Promise<void>;
4
4
  export declare function defineSatoriTransformer(transformer: SatoriTransformer | SatoriTransformer[]): SatoriTransformer | SatoriTransformer[];
@@ -1,3 +1,3 @@
1
- import type { RuntimeOgImageOptions } from '../../../types';
1
+ import type { RuntimeOgImageOptions } from '../../types';
2
2
  declare const _default: import("h3").EventHandler<false | RuntimeOgImageOptions>;
3
3
  export default _default;
@@ -16,21 +16,21 @@ export default defineEventHandler(async (e) => {
16
16
  statusMessage: `Failed to read the path ${path} for og-image extraction. ${err.message}.`
17
17
  });
18
18
  }
19
- const extractedPayload = extractOgImageOptions(html);
20
- if (!extractedPayload) {
21
- throw createError({
22
- statusCode: 500,
23
- statusMessage: `The path ${path} is missing the og-image payload.`
24
- });
25
- }
26
19
  e.node.req.url = path;
27
20
  const oldRouteRules = e.context._nitro.routeRules;
28
21
  e.context._nitro.routeRules = void 0;
29
- const routeRules = getRouteRules(e)?.ogImage;
22
+ const routeRules = getRouteRules(e)?.ogImage || {};
30
23
  e.context._nitro.routeRules = oldRouteRules;
31
24
  e.node.req.url = e.path;
32
25
  if (routeRules === false)
33
26
  return false;
27
+ const extractedPayload = extractOgImageOptions(html, routeRules);
28
+ if (!extractedPayload) {
29
+ throw createError({
30
+ statusCode: 500,
31
+ statusMessage: `The path ${path} is missing the og-image payload.`
32
+ });
33
+ }
34
34
  const { defaults } = useRuntimeConfig()["nuxt-og-image"];
35
35
  return defu(
36
36
  extractedPayload,
@@ -1,3 +1,3 @@
1
- import type { OgImageOptions } from '../../types';
1
+ import type { OgImageOptions } from '../types';
2
2
  export declare function decodeHtml(html: string): string;
3
- export declare function extractOgImageOptions(html: string): OgImageOptions | false;
3
+ export declare function extractOgImageOptions(html: string, routeRules: OgImageOptions): OgImageOptions | false;
@@ -1,3 +1,4 @@
1
+ import { defu } from "defu";
1
2
  export function decodeHtml(html) {
2
3
  return html.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&cent;/g, "\xA2").replace(/&pound;/g, "\xA3").replace(/&yen;/g, "\xA5").replace(/&euro;/g, "\u20AC").replace(/&copy;/g, "\xA9").replace(/&reg;/g, "\xAE").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/").replace(/&#([0-9]+);/g, (full, int) => {
3
4
  return String.fromCharCode(Number.parseInt(int));
@@ -10,15 +11,20 @@ function decodeObjectHtmlEntities(obj) {
10
11
  });
11
12
  return obj;
12
13
  }
13
- export function extractOgImageOptions(html) {
14
+ export function extractOgImageOptions(html, routeRules) {
14
15
  const htmlPayload = html.match(/<script id="nuxt-og-image-options" type="application\/json">(.+?)<\/script>/)?.[1];
15
16
  if (!htmlPayload)
16
17
  return false;
17
18
  let options;
18
19
  try {
19
- options = JSON.parse(htmlPayload);
20
+ const payload = JSON.parse(htmlPayload);
21
+ Object.entries(payload).forEach(([key, value]) => {
22
+ if (!value)
23
+ delete payload[key];
24
+ });
25
+ options = defu(payload, routeRules);
20
26
  } catch (e) {
21
- options = false;
27
+ options = routeRules;
22
28
  if (process.dev)
23
29
  console.warn("Failed to parse #nuxt-og-image-options", e, options);
24
30
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Buffer } from 'node:buffer';
3
3
  import type { H3Event } from 'h3';
4
- import type { RuntimeOgImageOptions } from '../../types';
4
+ import type { RuntimeOgImageOptions } from '../types';
5
5
  export declare function wasmLoader(asyncModuleLoad: Promise<any> | Buffer | string, fallback: string): {
6
6
  load(options: RuntimeOgImageOptions): Promise<any>;
7
7
  };
@@ -0,0 +1,69 @@
1
+ /// <reference types="node" />
2
+ import type { Buffer } from 'node:buffer';
3
+ import type { html } from 'satori-html';
4
+ import type { ModuleOptions } from '../module';
5
+ export interface ScreenshotOptions {
6
+ colorScheme?: 'dark' | 'light';
7
+ selector?: string;
8
+ mask?: string;
9
+ /**
10
+ * The width of the screenshot.
11
+ *
12
+ * @default 1200
13
+ */
14
+ width: number;
15
+ /**
16
+ * The height of the screenshot.
17
+ *
18
+ * @default 630
19
+ */
20
+ height: number;
21
+ /**
22
+ * How long to wait before taking the screenshot. Useful for waiting for animations.
23
+ */
24
+ delay?: number;
25
+ }
26
+ export interface OgImageOptions extends Partial<ScreenshotOptions> {
27
+ provider?: 'browser' | 'satori';
28
+ title?: string;
29
+ description?: string;
30
+ component?: string | null;
31
+ alt?: string;
32
+ cache?: boolean;
33
+ cacheKey?: string;
34
+ cacheTtl?: number;
35
+ /**
36
+ * @deprecated Use `cache` instead
37
+ */
38
+ static?: boolean;
39
+ [key: string]: any;
40
+ }
41
+ export interface RuntimeOgImageOptions extends OgImageOptions {
42
+ path: string;
43
+ requestOrigin: string;
44
+ }
45
+ export interface FontConfig {
46
+ name: string;
47
+ weight: number;
48
+ path?: string;
49
+ }
50
+ export type InputFontConfig = (`${string}:${number}` | FontConfig);
51
+ export interface Renderer {
52
+ name: 'browser' | 'satori';
53
+ createSvg: (options: RuntimeOgImageOptions) => Promise<string>;
54
+ createPng: (options: RuntimeOgImageOptions) => Promise<Buffer>;
55
+ createVNode: (options: RuntimeOgImageOptions) => Promise<VNode>;
56
+ }
57
+ export type OgImageScreenshotOptions = Omit<OgImageOptions, 'component'>;
58
+ export interface PlaygroundServerFunctions {
59
+ openInEditor(filepath: string): void;
60
+ getConfig(): ModuleOptions;
61
+ }
62
+ export interface PlaygroundClientFunctions {
63
+ refresh(type: string): void;
64
+ }
65
+ export type VNode = ReturnType<typeof html>;
66
+ export interface SatoriTransformer {
67
+ filter: (node: VNode) => boolean;
68
+ transform: (node: VNode, props: RuntimeOgImageOptions) => Promise<void>;
69
+ }
File without changes
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "2.0.4",
5
- "packageManager": "pnpm@8.6.5",
4
+ "version": "2.0.5",
5
+ "packageManager": "pnpm@8.6.6",
6
6
  "description": "Enlightened OG Image generation for Nuxt.",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -27,7 +27,7 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@nuxt/kit": "^3.6.1",
30
+ "@nuxt/kit": "^3.6.2",
31
31
  "@resvg/resvg-js": "^2.4.1",
32
32
  "@resvg/resvg-wasm": "^2.4.1",
33
33
  "@types/fs-extra": "^11.0.1",
@@ -39,12 +39,12 @@
39
39
  "fast-glob": "^3.3.0",
40
40
  "flatted": "^3.2.7",
41
41
  "fs-extra": "^11.1.1",
42
- "globby": "^13.2.1",
42
+ "globby": "^13.2.2",
43
43
  "image-size": "^1.0.2",
44
44
  "inline-css": "^4.0.2",
45
45
  "launch-editor": "^2.6.0",
46
- "nuxt-site-config": "^0.8.1",
47
- "nuxt-site-config-kit": "^0.8.1",
46
+ "nuxt-site-config": "^1.0.3",
47
+ "nuxt-site-config-kit": "^1.0.3",
48
48
  "nypm": "^0.2.2",
49
49
  "ofetch": "^1.1.1",
50
50
  "ohash": "^1.1.2",
@@ -63,20 +63,23 @@
63
63
  "yoga-wasm-web": "^0.3.3"
64
64
  },
65
65
  "devDependencies": {
66
- "@antfu/eslint-config": "^0.39.6",
67
- "@nuxt/devtools-edge": "0.6.6-28139075.95f3dd8",
66
+ "@antfu/eslint-config": "^0.39.7",
67
+ "@nuxt/devtools-edge": "0.6.6-28142701.2977264",
68
68
  "@nuxt/module-builder": "^0.4.0",
69
- "@nuxt/test-utils": "3.6.1",
69
+ "@nuxt/test-utils": "3.6.2",
70
70
  "@nuxtjs/eslint-config-typescript": "^12.0.0",
71
71
  "@types/ws": "^8.5.5",
72
72
  "bumpp": "^9.1.1",
73
73
  "eslint": "8.44.0",
74
74
  "jest-image-snapshot": "^6.1.0",
75
- "nuxt": "^3.6.1",
75
+ "nuxt": "^3.6.2",
76
76
  "nuxt-icon": "^0.4.2",
77
77
  "playwright": "^1.35.1",
78
78
  "sass": "^1.63.6",
79
- "vitest": "^0.32.4"
79
+ "vitest": "^0.33.0"
80
+ },
81
+ "resolutions": {
82
+ "@nuxt/schema": "3.6.2"
80
83
  },
81
84
  "scripts": {
82
85
  "build": "pnpm dev:prepare && pnpm build:module && pnpm build:client",