nuxt-og-image 1.1.1 → 1.2.0

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/README.md CHANGED
@@ -39,6 +39,7 @@ Enlightened OG Image generation for Nuxt 3.
39
39
  - 🤖 Browser provider: Supporting painless, complex templates
40
40
  - ✨ Prerendering enabled for static images
41
41
  - 📸 Feeling lazy? Just generate screenshots with options for hiding elements, waiting for animations, and more
42
+ - ⚙️ Edge / WASM compatible
42
43
 
43
44
  ## Install
44
45
 
@@ -94,16 +95,14 @@ For this guide, you will create your Satori OG image using the default component
94
95
 
95
96
  Within your `pages/index.vue`, use `defineOgImageStatic` or `OgImageStatic` to define your `og:image` component.
96
97
 
97
- Make sure you have defined some metadata for your page with `useHead` as props will be inferred from it.
98
+ Make sure you have defined some metadata as props will be inferred from it.
98
99
 
99
100
  ```vue
100
101
  <script lang="ts" setup>
101
102
  // 1. make sure you have some meta
102
- useHead({
103
+ useSeoMeta({
103
104
  title: 'Home',
104
- meta: [
105
- { name: 'description', content: 'My awesome home page.' },
106
- ],
105
+ description: 'My awesome home page.',
107
106
  })
108
107
  // 2a. Use the Composition API
109
108
  defineOgImageStatic()
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "bridge": false
6
6
  },
7
7
  "configKey": "ogImage",
8
- "version": "1.1.1"
8
+ "version": "1.2.0"
9
9
  }
package/dist/module.mjs CHANGED
@@ -10,6 +10,7 @@ import { resolve, relative } from 'pathe';
10
10
  import { tinyws } from 'tinyws';
11
11
  import sirv from 'sirv';
12
12
  import { copy } from 'fs-extra';
13
+ import { provider } from 'std-env';
13
14
  import { createBirpcGroup } from 'birpc';
14
15
  import { stringify, parse } from 'flatted';
15
16
 
@@ -219,7 +220,7 @@ const module = defineNuxtModule({
219
220
  return resolve(`../dist/${p}`);
220
221
  };
221
222
  nuxt.options.experimental.componentIslands = true;
222
- const isEdge = (process.env.NITRO_PRESET || "").includes("edge");
223
+ const isEdge = provider === "stackblitz" || (process.env.NITRO_PRESET || "").includes("edge");
223
224
  addTemplate({
224
225
  filename: "nuxt-og-image.d.ts",
225
226
  getContents: () => {
@@ -295,7 +296,11 @@ export {}
295
296
  });
296
297
  nitroConfig.publicAssets = nitroConfig.publicAssets || [];
297
298
  nitroConfig.publicAssets.push({ dir: fontDir, maxAge: 31536e3 });
298
- nitroConfig.virtual["#nuxt-og-image/browser"] = `export { createBrowser } from '${runtimeDir}/nitro/browsers/${isEdge ? "lambda" : "default"}'`;
299
+ if (isEdge && config.experimentalNitroBrowser)
300
+ nitroConfig.virtual["#nuxt-og-image/browser"] = `export { createBrowser } from '${runtimeDir}/nitro/browsers/${isEdge ? "lambda" : "default"}'`;
301
+ else
302
+ nitroConfig.virtual["#nuxt-og-image/browser"] = `export { createBrowser } from '${runtimeDir}/nitro/browsers/default'`;
303
+ nitroConfig.virtual["#nuxt-og-image/resvg"] = `import resvg from '${runtimeDir}/nitro/resvg/${isEdge ? "wasm" : "node"}'; export { resvg }`;
299
304
  nitroConfig.virtual["#nuxt-og-image/provider"] = `
300
305
  import satori from '${runtimeDir}/nitro/providers/satori'
301
306
  import browser from '${runtimeDir}/nitro/providers/browser'
@@ -1,7 +1,6 @@
1
1
  import { html as convertHtmlToSatori } from "satori-html";
2
2
  import satori from "satori";
3
3
  import { parseURL } from "ufo";
4
- import { Resvg } from "@resvg/resvg-js";
5
4
  import twemoji from "twemoji";
6
5
  import { loadFont, walkSatoriTree } from "./utils.mjs";
7
6
  import imageSrc from "./plugins/imageSrc.mjs";
@@ -9,13 +8,12 @@ import twClasses from "./plugins/twClasses.mjs";
9
8
  import flex from "./plugins/flex.mjs";
10
9
  import emojis from "./plugins/emojis.mjs";
11
10
  import { fonts, satoriOptions } from "#nuxt-og-image/config";
11
+ import { resvg } from "#nuxt-og-image/resvg";
12
12
  export default {
13
13
  name: "satori",
14
14
  createPng: async function createPng(baseUrl, options) {
15
15
  const svg = await this.createSvg(baseUrl, options);
16
- const resvg = new Resvg(svg, {});
17
- const pngData = resvg.render();
18
- return pngData.asPng();
16
+ return resvg(svg, options);
19
17
  },
20
18
  createVNode: async function createVNode(baseUrl, options) {
21
19
  const url = parseURL(baseUrl);
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import type { ResvgRenderOptions } from '@resvg/resvg-js';
3
+ export default function (svg: string, options: ResvgRenderOptions): Promise<Buffer>;
@@ -0,0 +1,6 @@
1
+ import { Resvg } from "@resvg/resvg-js";
2
+ export default async function(svg, options) {
3
+ const resvg = new Resvg(svg, options);
4
+ const pngData = resvg.render();
5
+ return pngData.asPng();
6
+ }
@@ -0,0 +1,2 @@
1
+ import type { ResvgRenderOptions } from '@resvg/resvg-wasm';
2
+ export default function (svg: string, options: ResvgRenderOptions): Promise<false | Uint8Array>;
@@ -0,0 +1,31 @@
1
+ import { Resvg, initWasm } from "@resvg/resvg-wasm";
2
+ import { resolvePath } from "mlly";
3
+ import { dirname, join } from "pathe";
4
+ import { $fetch } from "ofetch";
5
+ let wasm = null;
6
+ async function useResvgWasm() {
7
+ if (wasm)
8
+ return wasm;
9
+ try {
10
+ const path = join(
11
+ dirname(await resolvePath("@resvg/resvg-wasm")),
12
+ "index_bg.wasm"
13
+ );
14
+ const fs = await import("node:fs/promises");
15
+ wasm = await fs.readFile(path);
16
+ } catch (e) {
17
+ wasm = await $fetch("https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm", {
18
+ responseType: "arrayBuffer"
19
+ });
20
+ }
21
+ return wasm;
22
+ }
23
+ export default async function(svg, options) {
24
+ const resvgWasm = await useResvgWasm();
25
+ if (!resvgWasm)
26
+ return false;
27
+ await initWasm(resvgWasm);
28
+ const resvg = new Resvg(svg, options);
29
+ const pngData = resvg.render();
30
+ return pngData.asPng();
31
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "1.1.1",
4
+ "version": "1.2.0",
5
5
  "packageManager": "pnpm@7.8.0",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -28,6 +28,7 @@
28
28
  "dependencies": {
29
29
  "@nuxt/kit": "3.1.0",
30
30
  "@resvg/resvg-js": "^2.2.0",
31
+ "@resvg/resvg-wasm": "^2.2.0",
31
32
  "@types/fs-extra": "^11.0.1",
32
33
  "birpc": "^0.2.3",
33
34
  "chalk": "^5.2.0",
@@ -45,6 +46,7 @@
45
46
  "satori": "^0.1.1",
46
47
  "satori-html": "^0.3.2",
47
48
  "sirv": "^2.0.2",
49
+ "std-env": "^3.3.1",
48
50
  "tinyws": "^0.1.0",
49
51
  "twemoji": "^14.0.2",
50
52
  "ufo": "^1.0.1"