Skip to content

Commit 0b8ac2e

Browse files
committed
fix: import wasm module from takumi-js/wasm to match version
Amp-Thread-ID: https://ampcode.com/threads/T-019d71fd-cc3e-72de-83b9-fb27e70af98a
1 parent 0b5981d commit 0b8ac2e

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

src/worker.tsx

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createStartHandler, defaultStreamHandler } from '@tanstack/react-start/server'
22
import { ImageResponse } from 'takumi-js/response'
3-
import { initSync, Renderer } from 'takumi-js/wasm'
4-
import wasmModule from '@takumi-rs/wasm/takumi_wasm_bg.wasm'
3+
import wasmModule, { initSync, Renderer } from 'takumi-js/wasm'
54
import * as Config from './lib/Config'
65
import { OgCard } from './lib/Og'
76
// @ts-expect-error bytes import
@@ -11,20 +10,14 @@ import cmunbxData from '../public/fonts/cmunbx-clean.ttf?bytes'
1110
// @ts-expect-error bytes import
1211
import cmunslData from '../public/fonts/cmunsl-clean.ttf?bytes'
1312

14-
let renderer: Renderer | null = null
15-
function getRenderer() {
16-
if (!renderer) {
17-
initSync(wasmModule)
18-
renderer = new Renderer({
19-
fonts: [
20-
{ name: 'CMU Serif', data: cmunrmData, weight: 400, style: 'normal' },
21-
{ name: 'CMU Serif', data: cmunbxData, weight: 700, style: 'normal' },
22-
{ name: 'CMU Serif', data: cmunslData, weight: 400, style: 'italic' },
23-
],
24-
})
25-
}
26-
return renderer
27-
}
13+
initSync(wasmModule)
14+
const renderer = new Renderer({
15+
fonts: [
16+
{ name: 'CMU Serif', data: cmunrmData, weight: 400, style: 'normal' },
17+
{ name: 'CMU Serif', data: cmunbxData, weight: 700, style: 'normal' },
18+
{ name: 'CMU Serif', data: cmunslData, weight: 400, style: 'italic' },
19+
],
20+
})
2821

2922
const handler = createStartHandler(defaultStreamHandler)
3023

@@ -50,7 +43,7 @@ export default {
5043
{
5144
width: 1200,
5245
height: 630,
53-
renderer: getRenderer(),
46+
renderer,
5447
headers: {
5548
'Cache-Control': 'public, max-age=3600, s-maxage=86400, stale-while-revalidate=604800',
5649
},

0 commit comments

Comments
 (0)