<TextMorph />

Text continuity for interfaces on the web.

Plugin reference

Every type here is exported from torph. The guide explains how they fit together.

TorphPlugin

FieldWhat it is
nameRequired, unique, with no NULL characters. It namespaces the plugin's ids.
keyThe plugin's options as a string. The morph is rebuilt when it changes.
animateHooks for kinds the plugin doesn't own, by kind: "text" for plain text, or another plugin's kind. slot and ink on "text" mask plain text.
kindsHooks for kinds the plugin's own segments carry, with slot and ink.
decorateHooks that run alongside whatever moves a box, by kind or "*".
runsclaim(run, side), with optional enter and exit, to move a run of replaced text as one shape.
claim(word, ctx)Whether this plugin cuts up word. The first plugin to claim a word gets it.
segment(word, ctx)Cuts a claimed word into segments.
whole(value, ctx)Cuts the whole value, in place of the word-by-word match. null leaves it to the match.
touches(value)Whether a value could hold a word this plugin claims. Lets torph skip work.
token(word)A token to match words by: words with the same token pair up in order.
affinity(from, to)How alike two words are, 0 to 1, or null to use letter similarity.
fold(char)A key letters match by: (c) => c.toLowerCase() ignores case.
maxShiftHow far, in characters, a word moves and stays the same word.
lettersDraws plain text a box per letter, not per word.
lingerHow long leaving text keeps its place, in durations, before it goes.
tween(from, to, ctx)Values to morph through, each { value, at } with at in ms. The last should be to.
boxes(value)Keeps value in boxes at rest, not plain text.
easeThe morph's easing when the component doesn't set one.
read(root, style, change)Runs once per morph before anything changes. Its result is ctx.state.
idleThe state for a morph where read was skipped.
prepare(root, state)Writes that change layout, before torph measures.
teardown(root)Undoes prepare when the instance is destroyed.
cssStyles for the plugin's boxes, added once.

Motion hooks

enter, persist and exit each get (box, ctx) and return what to wait on: an array of Animations, a promise, or nothing.

ctx fieldWhat it is
animate(element, keyframes, options)element.animate, resumed from where an interrupted morph left element.
delta{ x, y } from the box's new place back to where it was drawn.
fromWhere the box was when this morph interrupted it, { tx, ty, opacity }.
moverFromThe same, for the inner box of a slot.
moverA slot's inner box, or the box itself.
line{ height, clear }: the line's height, and how far a slot's mover travels to be hidden.
duration, easeThe morph's timing.
indexThe box's place in reading order among the boxes on its side.
arriving, leavingHow many boxes arrive and leave.
wasWhat a staying box read before. Its text can change.
replacesThe leaving box an arriving one takes the place of.
replacedByThe arriving box that takes a leaving one's place.
kindThe box's kind, "text" for plain text.
stateWhat read returned.
signalAborts when a later morph interrupts this one.
runSet on a decoration when the box moves as part of a run.

Run hooks

runs.enter and runs.exit get (boxes, ctx):

ctx fieldWhat it is
rectsEach box's rect on screen.
fromWhere each box was when interrupted.
animate, line, state, duration, ease, signalAs for motion hooks.

Cutting contexts

FieldInWhat it is
localeallThe component's locale.
id(base?)segment, wholeMints an id. Pass a base for one derived from it, or nothing for a fresh one.
previoussegmentThe old word this one was paired with, as segments. Absent for a new word.
previouswholeThe whole old value, as segments.
split()segmentprevious cut to one segment per letter.
cursorsegmentThe caret's place in the word, when the value has one claimed word.

Segment

FieldWhat it is
idUnique within the value. Reuse a previous id to keep its box.
stringThe text.
kindPicks the segment's hooks from a plugin's kinds. Absent for plain text.