$ show lochie/torph
torph is a dependency-free animated text and number morphing library supporting React, Vue, Svelte, and vanilla JavaScript. The core engine segments input text into numerical and alphabetic parts, diffs them using a word-level LCS algorithm with numeric place-value matching, and animates the transition via FLIP, spring physics, and per-character masking. It exposes thin framework wrappers and a `MorphController` class for lifecycle management. A monorepo structure includes the library package, a shared test corpus consumed by both unit tests and an interactive playground, and a Next.js documentation site with 25+ demos and a showcase. The library requires no runtime dependencies; only peer dependencies for framework usage. It demonstrates exceptional engineering in diffing, animation timing, and cross-framework abstraction.
The LLM identified 4 files worth highlighting for reuse:
Implements the core text diff engine: word-level LCS to find longest common subsequences, numeric place matching by decimal alignment, and cursor-aware character matching. Isolated from framework code, parameterized by segment functions, and thoroughly tested. Can be extracted for any project needing context-preserving text diffing for animation or transition purposes.
Converts spring stiffness/damping/mass into a cached `linear()` easing function with computed duration. No runtime evaluation after first call. Reusable for any physics-based animation system requiring real-time easing generation.
`MorphController` encapsulates a `TextMorph` instance with config-keyed reattachment, avoiding unnecessary teardowns when only callbacks change. Provides a clean API for imperatively controlling morphs. Could serve as a pattern for reactive controller wrappers in other animation libraries.
A curated collection of 85+ text morph test cases covering word persistence, character morphing, numbers, multiline, unicode, and stress patterns. Designed to be consumed by both vitest and the playground, ensuring implementation fidelity. Demonstrates a systematic approach to testing animation invariants.