Shared API
Import the classes below from yugioh-card. Each class takes CardOptions<TData>. Pass card fields in data.
| Card | Class |
|---|---|
| Yu-Gi-Oh! | YugiohCard |
| Rush Duel | RushDuelCard |
| Yu-Gi-Oh! Card Back | YugiohBackCard |
| Field Center Card | FieldCenterCard |
| Yu-Gi-Oh! Series 2 | YugiohSeries2Card |
Constructor options
| Option | Type | Usage |
|---|---|---|
view | ILeaferInputData['view'] | The DOM element that hosts the canvas in a browser. Optional in Node.js. |
data | Partial<TData> | Fields to override in the default card data. |
resourcePath | string | The asset root for frames, icons, and fonts. |
skia | SkiaCanvas | In Node.js, pass the object imported from skia-canvas. |
readyTimeout | number | Timeout for each readiness cycle, in milliseconds. Defaults to 30000. |
Updates and readiness
card.setData(patch) merges the fields you supply and skips values of undefined. Pass '' to explicitly clear text or artwork. The browser can preview a card with fallback fonts while the fonts load.
await card.ready waits for the current card's required fonts, images, final layout, and a draw. Read it again after each call to setData(). The promise rejects on required asset errors or a timeout. After handling an error, you can start another update to retry.
Export and cleanup with Leafer
card.leafer is the Leafer instance that renders the card. It provides both export() and destroy().
- Call
card.leafer.export()to export the card. In Node.js, pass'png'and{ screenshot: true, blob: true }to receive a PNGBufferindataon success. See LeaferJS for all file types and options. Browser download example · Leafer export API - Call
card.leafer.destroy(true)when unmounting a component or finishing a script. Passtrueto destroy the instance synchronously. Leafer destroy API
Terminology
The field descriptions draw on the official TCG, OCG, and Rush Duel databases. Field names and enum values are shared across locales. English TCG · Simplified Chinese OCG · Japanese OCG · Rush Duel