nuxt-og-image 1.2.1 → 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.1"
8
+ "version": "1.2.2"
9
9
  }
@@ -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();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "1.2.1",
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",