Skip to content

SealCanvas

SealCanvas is the primary React component for rendering a seal. It combines a preset template with user-provided values and renders the result on a Konva canvas.

Import

tsx
import { SealCanvas, type SealCanvasProps, type SealCanvasRef } from '@luohuax/seal-kit'

Props

PropTypeDescription
presetPresetNameBuilt-in template: mitomein, dateStamp, kakuin, tenkoku.
textstring | string[]Seal text. String characters are arranged vertically; array items are rows.
colorstringInk color.
fontFamilystringFont family name. Must be registered or available in GOOGLE_FONT_MAP.
sizenumber | { width: number; height: number }Render canvas size.
shape"circle" | "square"Outer seal shape.
border"single" | "double" | "none"Border style.
borderThicknessnumberBorder thickness in pixels.
cornerRadiusnumberRadius for rounded square seals.
textDirection"horizontal" | "vertical"Text direction.
invertbooleanWhite text on colored background.
bleedbooleanInk bleed texture effect.
previewScalenumberOn-screen preview scale.
singleFieldAutoGridbooleanAuto-compute grid layout for single-field seals such as kakuin.
dateStamp{ year?, month?, day?, topText?, bottomText? }Data for the date stamp preset.

Ref Methods

Use useRef<SealCanvasRef>() to access export methods.

MethodSignatureDescription
exportPng(options?: { width?, height?, transparent? }) => Promise<string>Exports the seal as a PNG data URL.

Example

tsx
import { useRef } from 'react'
import { SealCanvas, type SealCanvasRef } from '@luohuax/seal-kit'

function App() {
  const ref = useRef<SealCanvasRef>(null)

  return (
    <div>
      <SealCanvas
        ref={ref}
        preset="mitomein"
        text="山田太郎"
        color="#cc0000"
        size={200}
      />
      <button onClick={async () => {
        const url = await ref.current?.exportPng({ width: 1024 })
        console.log(url)
      }}>
        Export
      </button>
    </div>
  )
}

Notes

  • preset provides all defaults. Any prop you pass overrides the preset value.
  • Fonts must be loaded before they render correctly. See Fonts.

Released under the MIT License.