nuxt-og-image 1.2.0 → 1.2.2

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.
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "bridge": false
6
6
  },
7
7
  "configKey": "ogImage",
8
- "version": "1.2.0"
8
+ "version": "1.2.2"
9
9
  }
package/dist/module.mjs CHANGED
@@ -241,6 +241,7 @@ export {}
241
241
  });
242
242
  ["html", "options", "svg", "vnode", "og.png"].forEach((type) => {
243
243
  addServerHandler({
244
+ lazy: true,
244
245
  handler: resolve(`./runtime/nitro/routes/__og_image__/${type}`)
245
246
  });
246
247
  });
@@ -1,2 +1,2 @@
1
1
  import type { ResvgRenderOptions } from '@resvg/resvg-wasm';
2
- export default function (svg: string, options: ResvgRenderOptions): Promise<false | Uint8Array>;
2
+ export default function (svg: string, options: ResvgRenderOptions): Promise<Uint8Array>;
@@ -2,10 +2,11 @@ import { Resvg, initWasm } from "@resvg/resvg-wasm";
2
2
  import { resolvePath } from "mlly";
3
3
  import { dirname, join } from "pathe";
4
4
  import { $fetch } from "ofetch";
5
- let wasm = null;
5
+ let initialisedWasm = false;
6
6
  async function useResvgWasm() {
7
- if (wasm)
8
- return wasm;
7
+ let wasm = null;
8
+ if (initialisedWasm)
9
+ return;
9
10
  try {
10
11
  const path = join(
11
12
  dirname(await resolvePath("@resvg/resvg-wasm")),
@@ -18,13 +19,13 @@ async function useResvgWasm() {
18
19
  responseType: "arrayBuffer"
19
20
  });
20
21
  }
21
- return wasm;
22
+ if (wasm) {
23
+ await initWasm(wasm);
24
+ initialisedWasm = true;
25
+ }
22
26
  }
23
27
  export default async function(svg, options) {
24
- const resvgWasm = await useResvgWasm();
25
- if (!resvgWasm)
26
- return false;
27
- await initWasm(resvgWasm);
28
+ await useResvgWasm();
28
29
  const resvg = new Resvg(svg, options);
29
30
  const pngData = resvg.render();
30
31
  return pngData.asPng();
@@ -1,6 +1,6 @@
1
1
  import { defineEventHandler } from "h3";
2
2
  import { parseURL, withoutTrailingSlash } from "ufo";
3
- import { fetchOptions, useHostname } from "../../utils.mjs";
3
+ import { fetchOptions } from "../../utils.mjs";
4
4
  export default defineEventHandler(async (e) => {
5
5
  const path = parseURL(e.path).pathname;
6
6
  if (!path.endsWith("/__og_image__"))
@@ -22,5 +22,5 @@ export default defineEventHandler(async (e) => {
22
22
  }
23
23
  </style>
24
24
  <title>OG Image Playground</title>
25
- <iframe src="${useHostname(e)}/__nuxt_og_image__/client/?&path=${withoutTrailingSlash(path.replace("__og_image__", ""))}"></iframe>`;
25
+ <iframe src="/__nuxt_og_image__/client/?&path=${basePath}"></iframe>`;
26
26
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "packageManager": "pnpm@7.8.0",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",