Skip to content

createScrambler()

Signature

function createScrambler(options: CreateScramblerOptions): ScrambleInstance

When to Use

Use createScrambler() when you need scramble text output without direct DOM mutation — for example:

  • Rendering to a <canvas>
  • Driving React/Vue state manually
  • Server-side text generation
  • Custom animation pipelines

Parameters

options

Extends ScrambleOptions with:

ParameterTypeDescription
textstringRequired. The target text to reveal.
fromTextstringThe source text to transition from. Default: ''
onFrame(text: string, progress: number) => voidCalled every frame with the current text.

All other options from Options are supported (chars, from, duration, etc.).

Example

import { createScrambler } from '@scrambl/core'
const scrambler = createScrambler({
text: 'Loading complete',
fromText: 'Please wait...',
chars: 'blocks',
duration: 1000,
onFrame: (text, progress) => {
myCanvas.clear()
myCanvas.drawText(text, 100, 200)
},
onComplete: () => {
console.log('Animation finished')
},
})