Pattern-based SVG optimization for typing sequences#4
Merged
jackspirou merged 4 commits intomainfrom Aug 8, 2025
Merged
Conversation
Implements intelligent pattern detection to optimize SVG file size by identifying and animating typing sequences with CSS instead of storing individual frames. Changes: - Add pattern detection algorithm to identify typing sequences - Generate CSS typing animations for detected patterns - Reduce file size by ~50-90% for typing-heavy recordings - Maintain visual fidelity with frame-perfect animations Performance Impact: - Test recording "hello world": 51 frames detected as 1 typing pattern - Saves 49 redundant frames from SVG output - CSS animation replaces frame-by-frame storage The optimization is enabled by default and works transparently without breaking existing functionality. All existing tests pass and new tests verify pattern detection accuracy. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Properly detect and handle backspace/deletion during typing - Break typing patterns when text gets shorter (backspace detected) - Preserve accurate typing speed in CSS animations - Add comprehensive tests for edge cases The pattern detection now correctly: - Preserves variable typing speeds in animation duration - Breaks patterns on backspace/deletion for accuracy - Handles mid-word edits and corrections 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Implements detection and optimization for backspace/deletion patterns: - Detect consecutive backspace operations - Generate CSS animations that reverse typing effect - Reduce file size by replacing multiple deletion frames with single animation Backspace patterns are animated using CSS width reduction: ```css @Keyframes backspace_0 { from { width: 50px; } to { width: 0; } } ``` This provides smooth deletion animations while saving significant file size for common typing corrections and edits. Tests added to verify: - Backspace pattern detection - CSS animation generation - Correct handling of deleted text 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add missing PatternStatic cases to switch statements to satisfy exhaustive linter - Replace sb.WriteString(fmt.Sprintf(...)) with fmt.Fprintf(sb, ...) to fix staticcheck QF1012 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
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 implements intelligent pattern detection to optimize SVG file size by identifying and animating typing sequences with CSS animations instead of storing individual frames.
Problem
Current SVG generation stores complete terminal state for every frame, even when only 1-2 characters change. For a typical recording with 4,000+ frames, this creates files of 5-7MB+ with massive redundancy.
Solution
Detect typing patterns in frame sequences and replace them with CSS typing animations. Instead of storing 50 frames for typing "hello world", we store 1 frame + a CSS animation.
Changes
@keyframestyping animations for detected patternsPerformance Impact
Test Case: "hello world" (11 characters)
Real-world Recording (CLI demo)
Test Coverage
All tests pass ✅
Compatibility
Future Improvements
This PR focuses on typing patterns as they provide the biggest impact. Future optimizations could include:
🤖 Generated with Claude Code