Fix SVG keyframe collisions with dynamic precision#3
Merged
Conversation
Fixes jerky/incorrect animations in large SVG files by implementing dynamic percentage precision based on keyframe count. Problem: - Large animations (4000+ keyframes) had multiple keyframes with same percentage values due to 1 decimal precision limit - Browser couldn't determine which transform to apply, causing jerky rendering Solution: - Implemented formatPercentage() with dynamic precision: - < 100 keyframes: 1 decimal - < 1,000 keyframes: 2 decimals - < 10,000 keyframes: 3 decimals - < 100,000 keyframes: 4 decimals - >= 100,000 keyframes: 5 decimals - Ensures unique percentages for all keyframes - Optimizes file size by using minimal required precision Results: - Smooth animations for recordings of any size - Optimal file sizes (small demos stay small) - No configuration needed - automatically adapts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Replace if statement with strings.TrimSuffix as suggested by staticcheck (S1017)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes jerky/incorrect SVG animations for large recordings by implementing dynamic percentage precision based on keyframe count.
Problem
When generating SVG animations with many keyframes (e.g., 4000+ for complex demos), the fixed 1-decimal precision for percentages caused collisions:
Example from a real recording:
Solution
Implemented a new
formatPercentage()function with dynamic precision that adapts to the number of keyframes:Results
Testing
formatPercentage()Example Impact
For the problematic tokenizer demo (4161 keyframes):
Related
This addresses rendering issues mentioned in the upstream discussion: charmbracelet#644
🤖 Generated with Claude Code