Package Exports #
The @staticcanvas/typeflow package provides ESM, CommonJS, and UMD distributions.
| Export Path | Format | Target | Description |
|---|---|---|---|
@staticcanvas/typeflow |
ESM / CJS / UMD | dist/typeflow.mjs |
Core typewriter engine and sequence helpers. |
@staticcanvas/typeflow/metrics |
ESM / CJS / UMD | dist/typeflow-metrics.mjs |
Real-time floating performance HUD and diagnostic badge. |
@staticcanvas/typeflow/debug |
ESM / CJS / UMD | dist/typeflow-debug.mjs |
Diagnostic tracing and @staticcanvas/logcad integration. |
@staticcanvas/typeflow/webaudio |
ESM / CJS / UMD | dist/typeflow-webaudio.mjs |
Zero-asset procedural Web Audio synthesizer. |
@staticcanvas/typeflow/parallel |
ESM / CJS / UMD | dist/typeflow-parallel.mjs |
Explicit opt-in parallel step orchestration with bounded concurrency. |
@staticcanvas/typeflow/keystroke |
ESM / CJS / UMD | dist/typeflow-keystroke.mjs |
Human typing dynamics, finger travel, and typo simulation. |
@staticcanvas/typeflow/extchars |
ESM / CJS / UMD | dist/typeflow-extchars.mjs |
Extended Unicode glyph sets for decrypt scramble reveals. |
@staticcanvas/typeflow/caret |
ESM / CJS / UMD | dist/typeflow-caret.mjs |
Persistent, editable cursor bound to an element’s text. |
jsr:@staticcanvas/typeflow |
ESM | src/typeflow.js |
JSR package distribution for Deno and Node. |
TypeFlowConfig Options
#
export interface TypeFlowConfig {
speed?: number;
delay?: number;
speedVariance?: number;
naturalCadence?: boolean;
granularity?: "grapheme" | "word";
direction?: "left" | "right" | "center";
typeStyle?: "char" | "word" | "scramble" | "fade-trail" | "word-fade" | "float-in-top" | "float-in-bottom" | "float-in-left" | "float-in-right" | "zoom-in-space";
wordOrder?: "left-to-right" | "right-to-left" | "random";
wordLayout?: "opacity" | "placeholder";
wordFadeDuration?: number;
wordStagger?: number;
wordSeed?: string | number;
wordMotionDistance?: number;
wordMotionDepth?: number;
wordMotionScale?: number;
wordMotionPerspective?: number;
wordMotionEasing?: string;
trailFade?: number | boolean;
trailMinOpacity?: number;
cursor?: string;
cursorBlink?: boolean;
html?: boolean;
mode?: "replace" | "append";
scrambleCharset?: "matrix" | "ascii" | "ascii-extended" | "blocks" | "binary" | "hex" | "braille" | "runic" | "cyber";
scrambleGlyphs?: string;
scrambleRounds?: number;
scrambleColor?: string;
scrambleGradient?: string;
audio?: "mechanical" | "beep" | "synth" | boolean | (() => void);
allowedTags?: string[];
allowedAttributes?: Record<string, string[]>;
sanitizer?: (html: string) => string;
respectReducedMotion?: boolean;
ariaLive?: "off" | "polite" | "assertive";
eraseStyle?: "end" | "start" | "center" | "scramble" | "fade-trail" | "instant" | "fade" | "word-fade" | "float-in-top" | "float-in-bottom" | "float-in-left" | "float-in-right" | "zoom-in-space";
duration?: number;
preserveBaseline?: boolean;
onStart?: () => void;
onComplete?: (text: string) => void;
onInterrupt?: () => void;
}
Options Breakdown #
| Property | Type | Default | Description |
|---|---|---|---|
speed |
number |
50 (type) / 25 (erase) |
Milliseconds per character / word delay. |
delay |
number |
0 |
Initial delay in ms before animation initiates. |
speedVariance |
number |
0 |
Random jitter (+/- ms) added per unit for natural typing cadence. |
naturalCadence |
boolean |
false |
Adds natural micro-pauses at punctuation (. , ! ?) and word breaks. |
granularity |
"grapheme" | "word" |
"grapheme" |
Unit segmentation mode using Intl.Segmenter. |
direction |
"left" | "right" | "center" |
"left" |
Typing reveal direction (LTR, RTL, center-outward). |
typeStyle |
"char" | "word" | "scramble" | "fade-trail" | "word-fade" | "float-in-top" | "float-in-bottom" | "float-in-left" | "float-in-right" | "zoom-in-space" |
"char" |
Typing reveal presentation style. word-fade and the float-in-*/zoom-in-space spatial styles lay out the final text before transitioning each word. |
wordOrder |
"left-to-right" | "right-to-left" | "random" |
"left-to-right" |
Reveal or erase order for word-fade and the spatial word-motion styles; it does not change bidi direction. |
wordLayout |
"opacity" | "placeholder" |
"opacity" |
Stable-layout strategy shared by word-fade and the spatial word-motion styles. Placeholder mode also hides unrevealed words with visibility. |
wordFadeDuration |
number |
280 |
Opacity/transform transition duration for each word in milliseconds. |
wordStagger |
number |
Current speed |
Delay between consecutive word transitions in milliseconds. |
wordSeed |
string | number |
undefined |
Optional deterministic seed when wordOrder is "random". |
wordMotionDistance |
number |
24 |
Translate distance in pixels for float-in-* styles. |
wordMotionDepth |
number |
160 |
translateZ depth in pixels for zoom-in-space. |
wordMotionScale |
number |
0.82 |
Starting scale (0-1) for zoom-in-space. |
wordMotionPerspective |
number |
600 |
CSS perspective in pixels applied to the target element while zoom-in-space runs. |
wordMotionEasing |
string |
"ease" |
CSS timing function for float-in-*/zoom-in-space transitions. |
trailFade |
number | boolean |
undefined |
Length of trailing fade gradient in characters. |
trailMinOpacity |
number |
0.18 |
Lowest opacity used by characters in a trailing fade. |
scrambleCharset |
"matrix" | "ascii" | ... |
undefined |
Built-in scramble glyph charset preset name. |
scrambleGlyphs |
string |
"!<>-_\\/[]{}—=+*^?#________" |
Character pool used during scramble reveals. |
scrambleRounds |
number |
2 |
Number of glyph iterations per unit. |
scrambleColor |
string |
undefined |
CSS color applied to the active scramble glyph. |
scrambleGradient |
string |
undefined |
CSS gradient applied to the active scramble glyph; overrides scrambleColor. |
audio |
"mechanical" | "beep" | "synth" | boolean | fn |
undefined |
Procedural Web Audio synthesized keystrokes or custom sound callback. |
cursor |
string |
"|" |
Cursor glyph string. Set to "" to omit cursor. |
cursorBlink |
boolean |
true |
Enables post-completion cursor blinking effect. |
html |
boolean |
false |
When true, parses input string as structured HTML markup. |
mode |
"replace" | "append" |
"replace" |
"replace" clears element first; "append" preserves initial child nodes. |
allowedTags |
string[] |
['b', 'strong', 'i', 'em', 'mark', 'span', 'small', 'sub', 'sup', 'u', 'br', 'a', 'code', 'ul', 'ol', 'li'] |
Allowed HTML tags for sanitization. |
allowedAttributes |
Record<string, string[]> |
Defaults for a, span, mark |
Map of tag names to allowed attribute arrays. |
sanitizer |
(html: string) => string |
undefined |
Custom HTML sanitization function. |
respectReducedMotion |
boolean |
true |
Skips animation if user OS has prefers-reduced-motion: reduce. |
ariaLive |
"off" | "polite" | "assertive" |
undefined |
Updates the element aria-live attribute during typing. |
eraseStyle |
"end" | "start" | "center" | "scramble" | "fade-trail" | "instant" | "fade" | "word-fade" | "float-in-top" | "float-in-bottom" | "float-in-left" | "float-in-right" | "zoom-in-space" |
"end" |
Erasing animation method. |
duration |
number |
250 |
Fade duration in ms when eraseStyle: 'fade'. |
preserveBaseline |
boolean |
true |
Retains initial prefix when erasing an append mode element. |
onStart |
() => void |
undefined |
Callback invoked right before the first character renders. |
onComplete |
(text: string) => void |
undefined |
Callback invoked upon animation completion. |
onInterrupt |
() => void |
undefined |
Callback invoked when .stop() is triggered early. |
TypeFlowController
#
Returned by TypeFlow.type(), TypeFlow.erase(), TypeFlow.morph(), TypeFlow.stagger(), TypeFlow.sequence(), and TypeFlow.rotate().
| Property / Method | Type | Description |
|---|---|---|
stop() |
() => void |
Cancels running timers and halts animation immediately without promise rejection. |
promise |
Promise<TypeFlowResult> |
Resolves with { completed: boolean, text: string }. |
Core Engine Methods #
TypeFlow.type(target, text, config?)
#
Types text or sanitized HTML into the element.
const controller = TypeFlow.type('#msg', 'Hello <strong>World</strong>', {
html: true,
direction: 'center',
audio: 'mechanical'
});
TypeFlow.erase(target, config?)
#
Erases text from the target using the specified eraseStyle.
TypeFlow.erase('#msg', { eraseStyle: 'fade-trail', speed: 20 });
TypeFlow.morph(target, nextText, config?)
#
Computes the longest common prefix between existing text and nextText, erases only the changed suffix, and types the new text.
await TypeFlow.type('#status', 'Connection: Pending');
await TypeFlow.morph('#status', 'Connection: Established');
TypeFlow.stream(target, config?)
#
Creates a streaming chunk consumer for real-time LLM token ingestion.
const stream = TypeFlow.stream('#output', { speed: 15 });
stream.push('Processing ');
stream.push('query results...');
TypeFlow.stagger(targets, texts?, config?)
#
Staggers typing across multiple DOM elements simultaneously with offset delays.
TypeFlow.stagger('.terminal-line', [
'npm install @staticcanvas/typeflow',
'npm run build',
'Ready.'
], { stagger: 200, speed: 25 });
TypeFlow.preset(name, overrides?)
#
Returns a pre-configured options object for common styles ('cyberpunk', 'terminal', 'writer', 'matrix', 'blocks', 'subtle').
TypeFlow.type('#terminal', 'INITIALIZING MATRIX', TypeFlow.preset('cyberpunk'));
TypeFlow.fit(target, candidates)
#
Measures candidate phrases and locks the container’s inline dimensions to eliminate Cumulative Layout Shift (CLS).
TypeFlow.fit('#rotating', ['Short', 'A much longer rotating phrase']);
TypeFlow.sequence(steps, seqConfig?)
#
Orchestrates sequential typing, erasing, pausing, and arbitrary function callbacks.
import { TypeFlow, seq } from '@staticcanvas/typeflow';
TypeFlow.sequence([
seq.visible('#output'),
seq.type('#output', 'Step 1 complete.'),
seq.pause(500),
seq.call(() => console.log('Milestone')),
seq.erase('#output', { eraseStyle: 'center' }),
seq.type('#output', 'Step 2 starting...')
], { repeat: 1 });
TypeFlow.parallel(steps, options?) — experimental
#
This API is opt-in and experimental. Its shape may change before it is promoted to the stable API.
Runs ordinary seq steps concurrently while preserving input order in the
result array. concurrency bounds active children. With all-settled (the
default), every step runs; with fail-fast, the first error or interrupted
child stops active siblings. The controller promise always resolves, including
errors as { status: 'rejected', reason } entries. Calling stop() propagates
to active children and pending waits. A later operation on a repeated target
interrupts the earlier operation, following the normal TypeFlow target rule.
import { TypeFlow, seq } from '@staticcanvas/typeflow';
import { installParallel } from '@staticcanvas/typeflow/parallel';
// Explicit opt-in: this adds parallel() only for callers importing the extension.
installParallel(TypeFlow, seq);
const group = TypeFlow.parallel([
seq.type('#status-a', 'Connected', { delay: 100 }),
seq.erase('#status-b', { eraseStyle: 'fade' }),
seq.parallel([
seq.type('#nested-a', 'Nested A'),
seq.type('#nested-b', 'Nested B')
], { concurrency: 1 })
], { concurrency: 2, settlement: 'all-settled' });
const { completed, results } = await group.promise;
TypeFlow.rotate(target, words, config?)
#
Cyclically types and erases an array of strings.
TypeFlow.rotate('#rotating', ['Fast', 'Lightweight', 'Reliable'], {
holdDuration: 1200,
pauseBetween: 200,
repeat: Infinity
});
TypeFlow.watch(container, selector, callback)
#
Observes DOM subtree mutations and automatically invokes a callback whenever matching elements are injected.
const watcher = TypeFlow.watch('#feed', '.item-title', (el) => {
const text = el.textContent;
el.textContent = '';
TypeFlow.type(el, text, { speed: 20 });
});
// Clean up
watcher.disconnect();
Companion Extensions API #
TypeFlowMetrics (@staticcanvas/typeflow/metrics)
#
import { TypeFlowMetrics } from '@staticcanvas/typeflow/metrics';
TypeFlowMetrics.mount({ position: 'bottom-right', detailed: false });
const stats = TypeFlowMetrics.getStats();
TypeFlowMetrics.unmount();
TypeFlowDebug (@staticcanvas/typeflow/debug)
#
import { TypeFlowDebug } from '@staticcanvas/typeflow/debug';
TypeFlowDebug.enable({ logcad: true, console: true });
TypeFlowDebug.trace(controller, 'Target Label');
const jsonLog = TypeFlowDebug.exportLog();
TypeFlowWebAudio (@staticcanvas/typeflow/webaudio)
#
import { TypeFlowWebAudio, createKeystrokeAudio } from '@staticcanvas/typeflow/webaudio';
TypeFlowWebAudio.play('mechanical-blue', { pan: 0.1 });
const audioCallback = createKeystrokeAudio('teletype');
const controller = TypeFlow.type('#target', 'Scoped audio', { audio: audioCallback });
controller.stop(); // also stops and disconnects this callback's active voices
TypeFlowKeystroke (@staticcanvas/typeflow/keystroke)
#
import { TypeFlowKeystroke, calculateKeyDistance } from '@staticcanvas/typeflow/keystroke';
const dist = calculateKeyDistance('q', 'p');
const actions = TypeFlowKeystroke.humanize('Typo injection text', { errorRate: 0.05 });
TypeFlowExtChars (@staticcanvas/typeflow/extchars)
#
import { TypeFlowExtChars, getExtendedCharset } from '@staticcanvas/typeflow/extchars';
const runes = getExtendedCharset('runic');
const custom = TypeFlowExtChars.combineCharsets('hieroglyphs', 'coptic');