Web Components
Tegaki has a <tegaki-renderer> custom element that works in any browser, without a framework.
Installation
Section titled “Installation”npm install tegakipnpm add tegakiyarn add tegakibun add tegakiRegister the custom element once, before using it in HTML:
Using via CDN
Section titled “Using via CDN”You can use Tegaki directly from a CDN without any build tools or package manager. Add a <script> tag to any HTML page.
esm.sh (recommended)
Section titled “esm.sh (recommended)”esm.sh serves npm packages as ES modules, with their dependencies bundled:
To pin a specific version, add it to the URL:
jsDelivr
Section titled “jsDelivr”jsDelivr can serve package files directly via its ESM endpoint:
Import maps
Section titled “Import maps”For cleaner imports, use an import map to map bare specifiers to CDN URLs:
This lets you write the same import paths you’d use with a bundler, while loading from the CDN at runtime.
Loading font data manually with createBundle
Section titled “Loading font data manually with createBundle”If the pre-built font bundles don’t work in your environment, or you want to load font data from a custom URL, use createBundle to assemble a bundle from its parts:
This is also useful for loading custom font bundles generated with the studio.
Full standalone example
Section titled “Full standalone example”A complete HTML file you can save and open in a browser:
Basic example
Section titled “Basic example”The element uses Shadow DOM internally. Style the host element with font-size and color as usual; the renderer inherits them.
Text content
Section titled “Text content”You can set the text via the text attribute or as the element’s text content:
Controlled time
Section titled “Controlled time”Set the time attribute to a number to control the animation manually:
Playback attributes
Section titled “Playback attributes”Control uncontrolled playback via attributes:
Plugins
Section titled “Plugins”Glows, gradients, tapered ends and the rest are plugins. Register the factories you want once, next to the font bundle, and the element can name them in its plugins attribute:
List names split by spaces or commas for the defaults, or write a JSON array to give options, with [name, options] for each plugin that takes them:
The built-in names are glow, taper, strokeGradient, globalGradient, variation, boil and annotate, and none is registered until you register it. A plugin registered after the element is on the page is picked up then, so the order of your scripts doesn’t matter. A name that’s still unregistered once the page has loaded is warned about in the console. See Style plugins for their options.
Plugin objects, your own included, go on the plugins property. It takes names too, and when it’s set it takes precedence over the attribute:
The pressure attribute (0 to 1, default 1) sets how much the ink’s width follows the pen’s pressure. The old effects property is gone: see Migrating from effects.
Playback controls
Section titled “Playback controls”The element exposes playback methods and read-only properties:
Accessing the engine
Section titled “Accessing the engine”For advanced use cases, the underlying TegakiEngine instance is available:
CSS time mode
Section titled “CSS time mode”Use time="css" to drive the animation from CSS custom properties:
See the Rendering Animations guide for details.
Custom tag name
Section titled “Custom tag name”Custom element names must contain a hyphen per the HTML spec. The default is tegaki-renderer, but you can choose any valid name:
Attributes reference
Section titled “Attributes reference”| Attribute | Type | Description |
|---|---|---|
text |
string |
Text to render. Falls back to textContent if not set. |
font |
string |
Registered bundle name (see TegakiEngine.registerBundle). |
time |
number | "css" |
Controlled time in seconds, or "css" for CSS mode. Omit for uncontrolled. |
speed |
number |
Playback speed multiplier (default 1). |
playing |
"true" | "false" |
Whether animation is playing (default true). |
loop |
boolean attribute | Loop animation when it finishes. |
reduced-motion |
"never" | "user" | "always" |
Whether to honour reduced motion by showing the text finished (default "never"; see reducedMotion). |
pixel-ratio |
number |
Supersampling factor on top of devicePixelRatio (shortcut for quality.pixelRatio). |
segment-size |
number |
Max drawn segment length in CSS pixels (shortcut for quality.segmentSize). |
pressure |
number |
How much the ink’s width follows the pen’s pressure, 0 to 1 (default 1; see pressure). |
plugins |
string |
Registered plugins by name: "taper glow", or a JSON array with options, '["taper", ["glow", {"radius": 0.15}]]' (see Plugins). The plugins property takes precedence. |
seed |
number | "random" |
What plugins’ random choices come from: where a gradient starts, how variation changes each glyph (default 0; see seed). The element’s engine.seed is the number it drew with. |
show-overlay |
boolean attribute | Show debug text overlay. |
fallback-font |
string |
CSS font-family list for characters the bundle has no stroke data for (see fallbackFont). |
Properties reference
Section titled “Properties reference”These properties are set via JavaScript and support object values that can’t be expressed as attributes:
| Property | Type | Description |
|---|---|---|
font |
TegakiBundle | string |
Font bundle object or registered name. |
plugins |
TegakiPluginSpec[] |
Plugin objects or registered names. Takes precedence over the plugins attribute. |
timing |
TimelineConfig |
Timeline timing configuration. |
quality |
TegakiQuality |
Render-quality knobs (pixelRatio, segmentSize). |
onComplete |
() => void |
Callback when animation completes. |
engine |
TegakiEngine (read-only) |
The underlying engine instance. |
For the full options reference, see the TegakiRenderer API docs.