Skip to content

Shared API ​

Import the classes below from yugioh-card. Each class takes CardOptions<TData>. Pass card fields in data.

CardClass
Yu-Gi-Oh!YugiohCard
Rush DuelRushDuelCard
Yu-Gi-Oh! Card BackYugiohBackCard
Field Center CardFieldCenterCard
Yu-Gi-Oh! Series 2YugiohSeries2Card

Constructor options ​

OptionTypeUsage
viewILeaferInputData['view']The DOM element that hosts the canvas in a browser. Optional in Node.js.
dataPartial<TData>Fields to override in the default card data.
resourcePathstringThe asset root for frames, icons, and fonts.
skiaSkiaCanvasIn Node.js, pass the object imported from skia-canvas.
readyTimeoutnumberTimeout 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 PNG Buffer in data on 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. Pass true to 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