CRITICAL FIX: Icon toggle now works without page refresh - Changed class name from 'show-logos' to 'show-icons' (CSS mismatch bug) - Updated localStorage key from 'cv-logos' to 'cv-icons' - Fixed toggleIcons() function in cv-functions.js HYPERSCRIPT ARCHITECTURE: - Moved 6 toggle functions from hyperscript to JavaScript (cv-functions.js) - Solves hyperscript 0.9.14 parser limitation (max 3 def statements total) - Upgraded hyperscript from 0.9.12 to 0.9.14 - Fixed operator precedence in keyboard shortcuts - Cleaned view-controls.html templates (inline → function calls) NEW FILES: - static/js/cv-functions.js - Global toggle functions (6 functions) - HYPERSCRIPT-RULES.md - Permanent architecture documentation - tests/mjs/0-zoom.test.mjs - Zoom functionality test - tests/mjs/1-toggles.test.mjs - Comprehensive toggle test with real-time verification - tests/TEST-SUMMARY.md - Test suite documentation TESTS: - Real-time DOM update verification (no refresh required) - Screenshot capture for visual regression - localStorage persistence validation - Toggle synchronization between action bar and menu BREAKING CHANGE: localStorage key changed from 'cv-logos' to 'cv-icons' Users may need to re-toggle icons preference on first load after update.
4.4 KiB
Hyperscript Development Rules
MANDATORY RULES - ALWAYS FOLLOW
Rule 1: Code Cleanliness
More than 3 lines of hyperscript → Move to function in file
- Inline hyperscript in HTML should be kept minimal (≤3 lines)
- Longer logic MUST be extracted to named functions in ._hs files
- HTML templates should be clean and readable
Rule 2: File Structure - Hyperscript 0.9.12 Limitation
Maximum 3 def statements TOTAL across ALL files
⚠️ CRITICAL: Hyperscript 0.9.12 has a parser limitation - more than 3 def statements across ALL loaded ._hs files causes:
Error: Expected 'end' but found 'def'
Solution for Global Reusable Functions: Use regular JavaScript instead
static/js/cv-functions.js- Global toggle and utility functions- toggleCVLength(), toggleIcons(), toggleTheme()
- syncPdfHover(), syncPrintHover(), highlightZoomControl()
Solution for Hyperscript-Specific Logic: Keep max 3 defs
static/hyperscript/functions._hs- ONLY hyperscript-specific utilities (printFriendly, initScrollBehavior, handleScroll)
Why JavaScript for Global Functions:
- ✅ No artificial limits
- ✅ Better performance (native JS)
- ✅ Better debugging
- ✅ Can still be called from hyperscript using
call toggleIcons(my.checked)
Rule 3: HTML Structure Cleanliness
HTML must be as clean as possible regarding hyperscript
✅ GOOD - Clean, readable:
<input type="checkbox"
id="lengthToggle"
_="on change call toggleCVLength(my.checked)">
❌ BAD - Inline logic nightmare:
<input type="checkbox"
id="lengthToggle"
_="on change
if my.checked
remove .cv-short from .cv-paper
add .cv-long to .cv-paper
set localStorage['cv-length'] to 'long'
set #lengthToggleMenu's checked to true
else
remove .cv-long from .cv-paper
add .cv-short to .cv-paper
set localStorage['cv-length'] to 'short'
set #lengthToggleMenu's checked to false
end">
File Organization
static/hyperscript/
├── functions._hs → Core utilities (3 defs max)
├── toggles._hs → Toggle functions (3 defs max)
└── hover._hs → Hover sync functions (3 defs max)
Load Order in templates/index.html:
<script type="text/hyperscript" src="/static/hyperscript/functions._hs"></script>
<script type="text/hyperscript" src="/static/hyperscript/toggles._hs"></script>
<script type="text/hyperscript" src="/static/hyperscript/hover._hs"></script>
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>
Required Functions
Core Functions (functions._hs)
printFriendly()- Handle print-friendly viewinitScrollBehavior()- Initialize scroll variableshandleScroll()- Manage scroll behavior and fixed button positioning
Toggle Functions (toggles._hs)
toggleCVLength(isLong)- Switch between short/long CVtoggleIcons(showIcons)- Show/hide iconstoggleTheme(isClean)- Switch between default/clean theme
Hover Sync Functions (hover._hs)
syncPdfHover(show)- Sync hover state across PDF buttonssyncPrintHover(show)- Sync hover state across print buttonshighlightZoomControl(show)- Highlight zoom control on hover
Why These Rules Exist
Maintainability
- Functions with descriptive names are self-documenting
- Easier to test and debug
- Changes in one place instead of scattered across templates
Performance
- Browser caches ._hs files
- Reduces HTML payload size
- Cleaner separation of concerns
Hyperscript 0.9.12 Limitation
- Parser breaks with >3
defin single file - MUST split into multiple files
- Each file: ≤3
defstatements
Common Mistakes to Avoid
❌ DON'T: Put all functions in one file if you have >3 defs ❌ DON'T: Write long inline hyperscript in HTML ❌ DON'T: Delete functions to work around the 3-def limit
✅ DO: Split functions across multiple ._hs files ✅ DO: Keep HTML clean with function calls ✅ DO: Maintain all required functions for clean architecture
Testing After Changes
- Check browser console for parse errors
- Verify all functions are defined (no "X is null" errors)
- Test all toggles work correctly
- Hard refresh browser (Ctrl+Shift+R) to clear cache
Last Updated: 2025-01-17 Hyperscript Version: 0.9.12 Status: MANDATORY - ALWAYS FOLLOW