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
package/dist/module.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ResvgRenderOptions } from '@resvg/resvg-wasm';
|
|
2
|
-
export default function (svg: string, options: ResvgRenderOptions): Promise<
|
|
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
|
|
5
|
+
let initialisedWasm = false;
|
|
6
6
|
async function useResvgWasm() {
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
22
|
+
if (wasm) {
|
|
23
|
+
await initWasm(wasm);
|
|
24
|
+
initialisedWasm = true;
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
export default async function(svg, options) {
|
|
24
|
-
|
|
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
|
|
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="
|
|
25
|
+
<iframe src="/__nuxt_og_image__/client/?&path=${basePath}"></iframe>`;
|
|
26
26
|
});
|