Skip to content

V3#11

Draft
tol-is wants to merge 14 commits intomainfrom
v3
Draft

V3#11
tol-is wants to merge 14 commits intomainfrom
v3

Conversation

@tol-is
Copy link
Copy Markdown
Owner

@tol-is tol-is commented Mar 23, 2026

No description provided.

tol-is added 14 commits March 17, 2026 21:57
The animate function was recreated every render and used as a useEffect
dependency, causing the effect to re-fire on every render. This
constantly cancelled and re-requested animation frames.

Fix: use a frameRef pattern where the rAF loop always calls through a
ref that holds the latest closure. This eliminates the [animate]
dependency and consolidates three separate useEffects into one clean
effect that only re-runs when text changes. Speed and other prop changes
are picked up automatically via the fresh closure in frameRef.current.

Made-with: Cursor
- Replace useRef<any> with useRef<HTMLElement> for DOM node ref
- Replace Function type with () => void for callback props
- Simplify RangeOrCharCodes type to [number, number] | number[]
- Fix duplicate number in setIfNotIgnored value param type
- Replace all var declarations in for loops with let

Made-with: Cursor
- Replace innerHTML with textContent for DOM updates. The output is
  always plain text so textContent is both safer (no XSS) and faster
  (no HTML parsing).
- Cache prefersReducedMotion in state and subscribe to media query
  changes via addEventListener, so the hook reacts dynamically when
  the user toggles their OS reduced-motion preference.

Made-with: Cursor
TSDX has been unmaintained since 2021 and pins old versions of Rollup,
Jest, and TypeScript.

- Replace tsdx with tsup (esbuild-based, outputs CJS + ESM + DTS)
- Replace tsdx test with vitest as the test runner
- Add tsup.config.ts and vitest.config.ts
- Update package.json scripts, output paths, and size-limit paths
- Update playground import from dist to src for dev workflow
- Install @testing-library/react + @testing-library/dom for future tests

Made-with: Cursor
- TypeScript 4.9.3 -> 5.9.3
- @types/react 18.0.26 -> 19.x
- @types/react-dom 18.0.9 -> 19.x
- size-limit 4.8.0 -> 11.x
- @size-limit/preset-small-lib 4.8.0 -> 11.x
- concurrently 7.6.0 -> 9.x
- Remove tslib (no longer needed with tsup)

Made-with: Cursor
- Bump version to 3.0.0
- Add exports field with proper CJS/ESM type resolution
- Add sideEffects: false for tree-shaking
- Update engines to node >= 18
- Update peerDependencies to react/react-dom >= 17 (drop React 16)
- Update tsconfig: remove stale types include, use react-jsx transform,
  add dom.iterable lib, set es2018 target

Made-with: Cursor
useScramble now accepts a generic type parameter for the DOM ref:

  const { ref } = useScramble<HTMLParagraphElement>({ text: "hello" })

Defaults to HTMLElement for backwards compatibility.

Made-with: Cursor
New optional `delay` prop (milliseconds) to postpone the animation
start. Applies to both initial mount animation and manual replay().
Defaults to 0 (no delay) for backwards compatibility.

Timers are properly cleaned up on unmount and text changes.

Made-with: Cursor
New optional `direction` prop controls the order characters resolve:

- 'ltr' (default): left to right, same as previous behavior
- 'rtl': right to left, characters resolve from end to start
- 'random': characters resolve in a shuffled random order

Internally, a resolveOrderRef maps the cursor position to actual
character indices, and enteredRef tracks which positions have been
entered. This replaces the old position-based comparisons in draw(),
seedForward(), stepForward(), and onOverdrive().

Made-with: Cursor
Replace the no-op placeholder test with 11 meaningful tests:
- renders without crashing
- resolves to target text
- fires onAnimationEnd / onAnimationStart callbacks
- playOnMount: false shows text immediately
- speed: 0 pauses animation
- fires onAnimationFrame during animation
- replay restarts animation
- handles empty text
- handles text change (rerender)
- respects ignore characters

Also adds test/setup.ts to mock window.matchMedia for jsdom.

Made-with: Cursor
Run on push to main/v3 and on PRs to main:
- Type check (tsc --noEmit)
- Test (vitest)
- Build (tsup)
- Size limit check

Tests across Node 18, 20, and 22.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant