StringTune/Docs

Modules

Split Grammar

Detailed reference for string-split tokens, parameters, random values, and parser rules.

Type
Built-in module
Status
Stable
Scope
Element-level
Activation
string="split"

Split Grammar

StringSplit is configured through one attribute: string-split (also accepted as data-string-split). The parser is strict — it does not try to guess intent.

Attribute Format

TEXT
token[params]|token[params]|...
  • tokens are separated by |
  • each token has an optional [params] block
  • parameters inside [] are separated by ;
  • empty parts and extra whitespace are ignored

Tokens

Each token enables one level of wrappers and/or CSS variables.

TokenWrappers createdWhat it does
line.-s-lineWraps each visual line
word.-s-wordWraps each word, global ordering
word-line.-s-line + .-s-wordWraps words with per-line ordering
char.-s-charWraps each character, global ordering
char-line.-s-line + .-s-charWraps characters with per-line ordering
char-word.-s-word + .-s-charWraps characters with per-word ordering
fitnoneScales text to fill container width

A wrapper is created when any token that implies it is present:

  • .-s-line appears when line, word-line, or char-line is used
  • .-s-word appears when word, word-line, or char-word is used
  • .-s-char appears when char, char-line, or char-word is used

Alignment Parameters

Each token (except fit) accepts an alignment parameter inside []:

ParameterProduces variableValue
start--{token}-startIndex from the beginning (0, 1, 2...)
center--{token}-centerDistance from the center
end--{token}-endIndex from the end
random(min,max)--{token}-randomRandom integer in [min, max]

If no parameter is given, the default is start.

Variable naming

The CSS variable name combines the token's internal key with the alignment:

AttributeVariable
line[center]--line-center
word-line[start]--wordLine-start
char-word[end]--charWord-end
char[random(0,10)]--char-random

What the values mean

AlignmentFormula
startItem's 0-based index
endtotal - index - 1
centerDistance from the center index
random(min,max)Random integer in the inclusive range

The scope of total depends on the token:

TokenTotal is...
linetotal lines
wordtotal words across all lines
word-linewords in the current line
chartotal chars across all lines
char-wordchars in the current word
char-linechars in the current line

Combining Tokens

Use | to combine multiple levels in one attribute:

HTML
<!-- line + word + char ordering -->
string-split="line[center]|word-line[start]|char-word[end]"

This creates all three wrapper levels, each with its own alignment variable.

fit

fit is a standalone token with no parameters:

HTML
string-split="line[start]|fit"

See Fit And Rebuild for details.

Common Patterns

GoalAttribute
Reveal chars inside each wordword[start]|char-word[start]
Stagger lines then chars per lineline[start]|char-line[start]
Fit text to width with line animationline[start]|fit
Word wrappers only (no char split)word[start]
Full three-level controlline[center]|word-line[start]|char-word[end]

Edge Cases

  • Leading or trailing | is ignored
  • Whitespace around tokens is trimmed
  • A token with empty [] defaults to start
  • Unrecognized token names are skipped with a console warning
  • The parser accepts abs as a flag inside [], but it has no public effect in the current runtime