# Framework adapters

> Lightweight zero-dependency adapter factories and integration hooks for React, Vue 3, Svelte, Solid.js, Alpine.js, Web Components, and Angular.

Canonical documentation: https://staticcanvas.github.io/typeflow/guides/framework-adapters/


## Zero-Dependency Framework Adapters

TypeFlow utilizes factory-driven adapter functions. By accepting the host framework runtime as an injection argument (or leveraging standard browser DOM primitives), TypeFlow provides reactive hooks and directives without bloating your production bundle with framework peer dependencies.

All adapters handle automatic animation teardown, component unmounting, and signal dependency tracking.

---

## React Adapter

The React adapter provides two custom hooks: `useTypeFlow` for reactive text rendering and `useTypeFlowSequence` for multi-step sequence orchestration.

```jsx
import React, { useState } from &#39;react&#39;;
import { createTypeFlowReact, createTypeFlowSequenceReact, seq } from &#39;@staticcanvas/typeflow&#39;;

// Initialize adapter hooks by injecting React instance
const useTypeFlow = createTypeFlowReact(React);
const useTypeFlowSequence = createTypeFlowSequenceReact(React);

export function HeroTitle() {
  const [headline] = useState(&#39;TypeFlow with React Hooks&#39;);

  // Binds animation to DOM node ref
  const headlineRef = useTypeFlow(headline, {
    speed: 35,
    cursor: &#39;|&#39;,
    cursorBlink: true,
  });

  return &lt;h1 ref={headlineRef} /&gt;;
}

export function SequenceDemo() {
  useTypeFlowSequence(
    () =&gt; [
      seq.type(&#39;#seq-target&#39;, &#39;First step complete.&#39;),
      seq.pause(600),
      seq.erase(&#39;#seq-target&#39;, { eraseStyle: &#39;center&#39; }),
      seq.type(&#39;#seq-target&#39;, &#39;Second step rendered.&#39;),
    ],
    []
  );

  return &lt;div id=&#34;seq-target&#34; /&gt;;
}
```

---

## Vue 3 Adapter

The Vue 3 adapter integrates with Vue&#39;s reactivity system via getter functions, automatically updating when source refs or computed properties change.

```vue
&lt;script setup&gt;
import * as Vue from &#39;vue&#39;;
import { createTypeFlowVue, createTypeFlowSequenceVue, seq } from &#39;@staticcanvas/typeflow&#39;;

const useTypeFlow = createTypeFlowVue(Vue);
const useTypeFlowSequence = createTypeFlowSequenceVue(Vue);

const message = Vue.ref(&#39;Reactive Vue 3 Typography&#39;);
const headlineRef = useTypeFlow(() =&gt; message.value, {
  speed: 40,
  cursor: &#39;▍&#39;,
});

const runSequence = useTypeFlowSequence(() =&gt; [
  seq.type(headlineRef.value, &#39;Vue Sequence Step 1&#39;),
  seq.pause(400),
  seq.erase(headlineRef.value),
  seq.type(headlineRef.value, &#39;Vue Sequence Step 2&#39;),
]);
&lt;/script&gt;

&lt;template&gt;
  &lt;h1 ref=&#34;headlineRef&#34;&gt;&lt;/h1&gt;
  &lt;button @click=&#34;runSequence&#34;&gt;Replay Sequence&lt;/button&gt;
&lt;/template&gt;
```

---

## Svelte Adapter (Action)

The Svelte adapter implements the standard Svelte action contract (`node, params =&gt; { update, destroy }`). It works in both Svelte 4 and Svelte 5 runes.

```svelte
&lt;script&gt;
  import { createTypeFlowSvelte } from &#39;@staticcanvas/typeflow&#39;;
  const typeflow = createTypeFlowSvelte();

  let text = &#39;Reactive Svelte Action&#39;;
&lt;/script&gt;

&lt;h1 use:typeflow={{ text, config: { speed: 35, cursor: &#39;|&#39; } }}&gt;&lt;/h1&gt;
```

---

## Solid.js Adapter

The Solid.js adapter integrates directly with fine-grained signal accessors and `createEffect` tracking.

```jsx
import * as Solid from &#39;solid-js&#39;;
import { createTypeFlowSolid } from &#39;@staticcanvas/typeflow&#39;;

const useTypeFlow = createTypeFlowSolid(Solid);

export function Hero() {
  const [headline, setHeadline] = Solid.createSignal(&#39;Solid.js Reactive Typography&#39;);
  const ref = useTypeFlow(headline, {
    speed: 35,
    cursor: &#39;|&#39;,
  });

  return &lt;h1 ref={ref} /&gt;;
}
```

---

## Alpine.js Adapter (Directive)

The Alpine adapter registers a custom `x-typeflow` directive that monitors expression updates and manages animation cleanup automatically.

```html
&lt;script type=&#34;module&#34;&gt;
  import Alpine from &#39;alpinejs&#39;;
  import { createTypeFlowAlpine } from &#39;@staticcanvas/typeflow&#39;;

  createTypeFlowAlpine(Alpine);
  Alpine.start();
&lt;/script&gt;

&lt;div x-data=&#34;{ title: &#39;Alpine.js Fluid Typography&#39; }&#34;&gt;
  &lt;h1 x-typeflow=&#34;{ text: title, config: { speed: 30, cursor: &#39;|&#39; } }&#34;&gt;&lt;/h1&gt;
&lt;/div&gt;
```

---

## Web Components / Custom Element

TypeFlow provides a native autonomous custom element `&lt;type-flow&gt;` compatible with any HTML page, CMS, or framework template without bundlers.

```html
&lt;script type=&#34;module&#34;&gt;
  import { defineTypeFlowElement } from &#39;@staticcanvas/typeflow&#39;;
  defineTypeFlowElement();
&lt;/script&gt;

&lt;!-- Declarative HTML markup --&gt;
&lt;type-flow
  text=&#34;Declarative Web Component Typography&#34;
  speed=&#34;35&#34;
  direction=&#34;center&#34;
  type-style=&#34;char&#34;
  cursor=&#34;■&#34;
&gt;&lt;/type-flow&gt;
```

### Custom Element Attributes

| Attribute | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `text` | `string` | Element inner text | Source text to reveal. |
| `speed` | `number` | `40` | Milliseconds per character delay. |
| `direction` | `&#34;left&#34; \| &#34;right&#34; \| &#34;center&#34;` | `&#34;left&#34;` | Typing reveal vector. |
| `type-style` | `&#34;char&#34; \| &#34;word&#34; \| &#34;scramble&#34; \| &#34;fade-trail&#34;` | `&#34;char&#34;` | Reveal presentation style. |
| `erase-style` | `&#34;end&#34; \| &#34;start&#34; \| &#34;center&#34; \| &#34;scramble&#34;` | `&#34;end&#34;` | Erase animation style. |
| `cursor` | `string` | `&#34;\|&#34;` | Active cursor glyph. |
| `scramble-charset` | `string` | `&#34;matrix&#34;` | Preset name for decrypt animations. |
| `audio` | `&#34;mechanical&#34; \| &#34;beep&#34; \| &#34;synth&#34;` | `undefined` | Web Audio sound profile. |

---

## Astro Integration

Astro does not require a separate TypeFlow adapter. Use the browser-native ESM API inside a client island or use the native `&lt;type-flow&gt;` custom element. Keep DOM access in a client-side script; Astro&#39;s server-rendered HTML must not call `TypeFlow.type()` during SSR.

```astro
---
const text = &#39;Astro island typography&#39;;
---

&lt;h1 id=&#34;astro-headline&#34;&gt;{text}&lt;/h1&gt;

&lt;script&gt;
  import { TypeFlow } from &#39;@staticcanvas/typeflow&#39;;

  const target = document.querySelector(&#39;#astro-headline&#39;);
  if (target) TypeFlow.type(target, target.textContent ?? &#39;&#39;, { speed: 40 });
&lt;/script&gt;
```

For reusable Astro islands, place the animation in a client framework component and render it with an Astro client directive such as `client:load`. No Astro-specific runtime package is bundled or required.

---

## Angular Integration Recipe

In Angular applications, TypeFlow can be encapsulated in a reusable attribute directive:

```typescript
import { Directive, ElementRef, Input, OnChanges, OnDestroy, SimpleChanges } from &#39;@angular/core&#39;;
import { TypeFlow, TypeFlowConfig, TypeFlowController } from &#39;@staticcanvas/typeflow&#39;;

@Directive({
  selector: &#39;[appTypeFlow]&#39;,
  standalone: true,
})
export class TypeFlowDirective implements OnChanges, OnDestroy {
  @Input(&#39;appTypeFlow&#39;) text = &#39;&#39;;
  @Input() typeFlowConfig: TypeFlowConfig = {};

  private controller: TypeFlowController | null = null;

  constructor(private el: ElementRef&lt;HTMLElement&gt;) {}

  ngOnChanges(changes: SimpleChanges): void {
    if (changes[&#39;text&#39;] || changes[&#39;typeFlowConfig&#39;]) {
      this.controller?.stop();
      this.controller = TypeFlow.type(this.el.nativeElement, this.text, this.typeFlowConfig);
    }
  }

  ngOnDestroy(): void {
    this.controller?.stop();
  }
}
```

---

## Integration Compatibility Matrix

| Target Ecosystem | Integration Method | Teardown Handling | SSR Safe |
| :--- | :--- | :--- | :--- |
| **React** (v16.8&#43;) | Hook (`useTypeFlow`) | `useEffect` return callback | Yes |
| **Vue 3** | Hook (`useTypeFlow`) | `onBeforeUnmount` lifecycle | Yes |
| **Svelte** (v4 / v5) | Action (`use:typeflow`) | Action `destroy()` hook | Yes |
| **Solid.js** | Hook (`useTypeFlow`) | `onCleanup` hook | Yes |
| **Alpine.js** (v3&#43;) | Directive (`x-typeflow`) | Directive `cleanup()` hook | Yes |
| **Web Components** | Custom Element (`&lt;type-flow&gt;`) | `disconnectedCallback()` | Yes |
| **Astro** | Client-side ESM or `&lt;type-flow&gt;` | Browser lifecycle / custom-element disconnect | Yes, when client-rendered |
| **Angular** (v14&#43;) | Standalone Directive | `ngOnDestroy()` | Yes |

Angular is documented as an integration recipe rather than a built-in adapter factory. Astro likewise uses TypeFlow&#39;s framework-agnostic browser API rather than a separate Astro package.


