diff --git a/examples/cf-page-build/package.json b/examples/cf-page-build/package.json index ab4f050..d0c6891 100644 --- a/examples/cf-page-build/package.json +++ b/examples/cf-page-build/package.json @@ -26,7 +26,7 @@ }, "type": "module", "dependencies": { - "@resvg/resvg-js": "^2.4.1", + "@resvg/resvg-wasm": "^2.4.1", "satori": "^0.10.1" } } diff --git a/examples/cf-page-build/pnpm-lock.yaml b/examples/cf-page-build/pnpm-lock.yaml index 7dafcc6..84a07d9 100644 --- a/examples/cf-page-build/pnpm-lock.yaml +++ b/examples/cf-page-build/pnpm-lock.yaml @@ -3,7 +3,7 @@ lockfileVersion: 5.4 specifiers: '@ethercorps/sveltekit-og': link:../../package '@playwright/test': ^1.31.2 - '@resvg/resvg-js': ^2.4.1 + '@resvg/resvg-wasm': ^2.4.1 '@sveltejs/adapter-cloudflare': ^2.3.0 '@sveltejs/adapter-static': ^2.0.2 '@sveltejs/kit': ^1.12.0 @@ -17,7 +17,7 @@ specifiers: vite: ^4.2.0 dependencies: - '@resvg/resvg-js': 2.4.1 + '@resvg/resvg-wasm': 2.4.1 satori: 0.10.1 devDependencies: @@ -533,130 +533,9 @@ packages: resolution: {integrity: sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==} dev: true - /@resvg/resvg-js-android-arm-eabi/2.4.1: - resolution: {integrity: sha512-AA6f7hS0FAPpvQMhBCf6f1oD1LdlqNXKCxAAPpKh6tR11kqV0YIB9zOlIYgITM14mq2YooLFl6XIbbvmY+jwUw==} + /@resvg/resvg-wasm/2.4.1: + resolution: {integrity: sha512-yi6R0HyHtsoWTRA06Col4WoDs7SvlXU3DLMNP2bdAgs7HK18dTEVl1weXgxRzi8gwLteGUbIg29zulxIB3GSdg==} engines: {node: '>= 10'} - cpu: [arm] - os: [android] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-android-arm64/2.4.1: - resolution: {integrity: sha512-/QleoRdPfsEuH9jUjilYcDtKK/BkmWcK+1LXM8L2nsnf/CI8EnFyv7ZzCj4xAIvZGAy9dTYr/5NZBcTwxG2HQg==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [android] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-darwin-arm64/2.4.1: - resolution: {integrity: sha512-U1oMNhea+kAXgiEXgzo7EbFGCD1Edq5aSlQoe6LMly6UjHzgx2W3N5kEXCwU/CgN5FiQhZr7PlSJSlcr7mdhfg==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [darwin] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-darwin-x64/2.4.1: - resolution: {integrity: sha512-avyVh6DpebBfHHtTQTZYSr6NG1Ur6TEilk1+H0n7V+g4F7x7WPOo8zL00ZhQCeRQ5H4f8WXNWIEKL8fwqcOkYw==} - engines: {node: '>= 10'} - cpu: [x64] - os: [darwin] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-linux-arm-gnueabihf/2.4.1: - resolution: {integrity: sha512-isY/mdKoBWH4VB5v621co+8l101jxxYjuTkwOLsbW+5RK9EbLciPlCB02M99ThAHzI2MYxIUjXNmNgOW8btXvw==} - engines: {node: '>= 10'} - cpu: [arm] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-linux-arm64-gnu/2.4.1: - resolution: {integrity: sha512-uY5voSCrFI8TH95vIYBm5blpkOtltLxLRODyhKJhGfskOI7XkRw5/t1u0sWAGYD8rRSNX+CA+np86otKjubrNg==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-linux-arm64-musl/2.4.1: - resolution: {integrity: sha512-6mT0+JBCsermKMdi/O2mMk3m7SqOjwi9TKAwSngRZ/nQoL3Z0Z5zV+572ztgbWr0GODB422uD8e9R9zzz38dRQ==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-linux-x64-gnu/2.4.1: - resolution: {integrity: sha512-60KnrscLj6VGhkYOJEmmzPlqqfcw1keDh6U+vMcNDjPhV3B5vRSkpP/D/a8sfokyeh4VEacPSYkWGezvzS2/mg==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-linux-x64-musl/2.4.1: - resolution: {integrity: sha512-0AMyZSICC1D7ge115cOZQW8Pcad6PjWuZkBFF3FJuSxC6Dgok0MQnLTs2MfMdKBlAcwO9dXsf3bv9tJZj8pATA==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-win32-arm64-msvc/2.4.1: - resolution: {integrity: sha512-76XDFOFSa3d0QotmcNyChh2xHwk+JTFiEQBVxMlHpHMeq7hNrQJ1IpE1zcHSQvrckvkdfLboKRrlGB86B10Qjw==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [win32] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-win32-ia32-msvc/2.4.1: - resolution: {integrity: sha512-odyVFGrEWZIzzJ89KdaFtiYWaIJh9hJRW/frcEcG3agJ464VXkN/2oEVF5ulD+5mpGlug9qJg7htzHcKxDN8sg==} - engines: {node: '>= 10'} - cpu: [ia32] - os: [win32] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js-win32-x64-msvc/2.4.1: - resolution: {integrity: sha512-vY4kTLH2S3bP+puU5x7hlAxHv+ulFgcK6Zn3efKSr0M0KnZ9A3qeAjZteIpkowEFfUeMPNg2dvvoFRJA9zqxSw==} - engines: {node: '>= 10'} - cpu: [x64] - os: [win32] - requiresBuild: true - dev: false - optional: true - - /@resvg/resvg-js/2.4.1: - resolution: {integrity: sha512-wTOf1zerZX8qYcMmLZw3czR4paI4hXqPjShNwJRh5DeHxvgffUS5KM7XwxtbIheUW6LVYT5fhT2AJiP6mU7U4A==} - engines: {node: '>= 10'} - optionalDependencies: - '@resvg/resvg-js-android-arm-eabi': 2.4.1 - '@resvg/resvg-js-android-arm64': 2.4.1 - '@resvg/resvg-js-darwin-arm64': 2.4.1 - '@resvg/resvg-js-darwin-x64': 2.4.1 - '@resvg/resvg-js-linux-arm-gnueabihf': 2.4.1 - '@resvg/resvg-js-linux-arm64-gnu': 2.4.1 - '@resvg/resvg-js-linux-arm64-musl': 2.4.1 - '@resvg/resvg-js-linux-x64-gnu': 2.4.1 - '@resvg/resvg-js-linux-x64-musl': 2.4.1 - '@resvg/resvg-js-win32-arm64-msvc': 2.4.1 - '@resvg/resvg-js-win32-ia32-msvc': 2.4.1 - '@resvg/resvg-js-win32-x64-msvc': 2.4.1 dev: false /@shuding/opentype.js/1.4.0-beta.0: diff --git a/examples/cf-page-build/svelte.config.js b/examples/cf-page-build/svelte.config.js index cef7e5d..d4caeba 100644 --- a/examples/cf-page-build/svelte.config.js +++ b/examples/cf-page-build/svelte.config.js @@ -3,7 +3,10 @@ import adapter from '@sveltejs/adapter-cloudflare'; /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { - adapter: adapter() + adapter: adapter(), + prerender: { + crawl: true + } } }; diff --git a/src/lib/index.ts b/src/lib/index.ts index 87f6a63..850db58 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -2,14 +2,6 @@ import satori, { type SatoriOptions } from 'satori'; import type { SvelteComponent } from 'svelte'; import toReactElement from './toReactElement'; import {Resvg as wasmSvg, initWasm, type ResvgRenderOptions} from "@resvg/resvg-wasm" -import {readFileSync} from "fs" -import { dirname } from "path" -import { fileURLToPath } from 'url'; - -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); - - const fontFile = await fetch('https://sveltekit-og.ethercorps.io/noto-sans.ttf'); const fontData: ArrayBuffer = await fontFile.arrayBuffer(); @@ -19,11 +11,9 @@ const initReSvg = async () => { const indexWasmRes = await fetch('https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm'); const buffer = await indexWasmRes.arrayBuffer(); await initWasm(buffer); - // await initWasm( readFileSync( __dirname + "/resvg.wasm" )); initialized = true; }; - const ImageResponse = async (htmlTemplate: string, optionsByUser: ImageResponseOptions) => { const options = Object.assign({ width: 1200, height: 630, debug: !1 }, optionsByUser); const svg = await satori(toReactElement(htmlTemplate), {