Astro
Tegaki provides a native Astro component that renders full HTML at build time and hydrates on the client. No JavaScript framework required — text is visible even before hydration.
Installation
Section titled “Installation”npm install tegaki
pnpm add tegaki
yarn add tegaki
bun add tegaki
Basic example
Section titled “Basic example”Font registration
Section titled “Font registration”When using the same font across multiple components on a page, you can register the bundle once and reference it by name. This avoids duplicating the font data in the HTML output.
Register the bundle
Section titled “Register the bundle”Use the bundle prop on a dedicated instance — it serializes the font data into a <script type="application/json"> tag and registers it on the client. Once registered, reference the font by its family name (the fullFamily field of the bundle, e.g. "Caveat"):
Preload the font
Section titled “Preload the font”Add loadFont to inject an @font-face rule so the browser starts downloading the font file immediately:
Effects
Section titled “Effects”How it works
Section titled “How it works”- Build time — The Astro component calls
TegakiEngine.renderElements()to produce the full HTML (canvas fallback text, overlay, sentinel). Text is visible in the initial HTML even without JavaScript. - Bundle serialization — Because font glyph data lives in server memory during SSR, it must be embedded into the HTML to reach the browser. When
font={bundle}is passed as an object, the component automatically serializes the bundle into a<script type="application/json">tag. If the same font is used across multiple renderers on the same page, use thebundleprop once to serialize it and reference by name afterward — this avoids duplicating the bundle data in the HTML output. - Client hydration — A module script reads any serialized bundle tags and registers them, then finds all
[data-tegaki-options]elements, creates aTegakiEnginewithadopt: true(reusing existing DOM), and starts the animation. - Dynamic elements — A
MutationObserverwatches for elements added after initial load (e.g., from View Transitions or client-side routing) and hydrates them automatically.
The Astro component accepts all TegakiEngineOptions plus:
| Prop | Type | Description |
|---|---|---|
bundle | boolean | Register the font bundle for client-side lookup by name |
loadFont | boolean | Inject @font-face CSS for early font loading |
class | string | CSS class on the container |