Molkit 0.3.0
Released April 7, 2026
New Features
- Zoom to Fit: View menu item, Ctrl+Shift+0 shortcut, and status bar button to auto-fit viewport to all content
- Touch pinch-to-zoom with two-finger gesture support for tablets and touchscreens
- Atom label validation warns (non-blocking) when entering unrecognized element symbols
- Image crop aspect ratio lock with Shift+corner handle drag
- Loading spinner and auto-fit viewport for large .mkit files (>100KB)
- Snap engagement ring: green highlight on atoms when bond tool is about to snap
- Hover cursor feedback in select mode (pointer on atoms/bonds, move on annotations)
- Aromatic circle display mode now renders in animation preview and SMIL export (bonds downgrade to single, dashed circle animates with ring)
- Alt+drag resize from center for all resizable objects (shapes, annotations, images, LaTeX, state boxes)
- Double bond center position: cycling now includes a centered (symmetric) option for ring bonds via doubleBondSide value 3
- CenterMode "Use Selection" button: select atoms/annotations with marquee, click button to set as animation pivot
- Undo/redo preserves selection for objects that still exist (no longer blanket-clears all selection)
Improvements
- Label dimension cache persists across renders, only invalidating changed atoms (saves ~300ms/render on 100-atom molecules during pan/zoom)
- Crossing bond detection cached via dirty flag, skips O(B^2) recomputation on pan/zoom/selection changes
- Animation state auto-tracking deferred during drag (eliminates 4,800+ containment tests/sec), syncs once on drag end
- Atom/bond deletion uses Set instead of Array.includes (O(N) instead of O(N^2) for bulk deletions)
- SVG crossing overrides use lightweight `<use>` elements instead of deep cloneNode copies
- Pre-built element maps replace per-crossing querySelector DOM traversal
- Ghost dot bezier proximity sampling throttled to requestAnimationFrame (was 100+ Hz)
- Waypoint drag dispatches wrapped in beginBatch/endBatch
- Group selection detection cached by reference equality, skips iteration when unchanged
- Selection box setAttribute calls batched via setAttrs helper (28 call sites)
- Tab snapshots use shallow array copy for undo/redo stacks (entries are immutable, no deep clone needed)
- localStorage auto-save skips SET_UI/SET_VIEWPORT actions and only serializes dirty tabs
- Adaptive undo stack sizing scales limit by molecule complexity (5-50 entries based on entity count)
- PDF filter rasterization yields to event loop every 3 elements with progress in status bar
- Presenter timer requestAnimationFrame loop stops when paused (saves 4-10% idle CPU)
- structuredClone() used for deep cloning with JSON.parse/stringify fallback
- Pattern fills cached and reused across renders (skip DOM rebuild when params unchanged)
- renderLayerTree pre-builds group/annotation lookup maps (O(1) instead of O(N) per lookup)
- Wheel event handler throttled to one dispatch per animation frame via requestAnimationFrame
- Selection and position updates batched into single dispatch during drag (halves render count)
- 4px drag threshold prevents accidental object movement from slight mouse tremor
- Bond snap threshold is now zoom-compensated across all 4 code paths (was fixed 20px)
- Unlabeled atom hit radius increased from 3px to 6px for easier clicking
Bug Fixes
- Textbox no longer jumps position during editing (DOM and Store positions computed from single source)
- Textbox editor width now shrinks when text is deleted (20px minimum floor)
- Double-clicking a textbox to edit no longer triggers selection/drag state (300ms suppression window)
- ESC closes text editor regardless of focus (global handler before contentEditable check)
- Selection preserved when switching tools (no longer cleared on tool change)
- ESC during bond creation cleans up orphaned start atom if it has no bonds
- Paste no longer crashes when clipboard has empty atoms and annotations arrays
- Paste no longer crashes if canvas-container element is missing from DOM
- NaN guards on zoom slider, screenToCanvas, and wheel handler prevent coordinate corruption from invalid zoom
- CodeMirror module loading has 8-second timeout (prevents indefinite hang if CDN unreachable)
- Drag state cleaned up on window blur and document visibilitychange (prevents stuck drags)
- localStorage emergency mode now shows visible status bar warning before dropping inactive tab data
- Radical dot rotation in SMIL export now reads actual target atom rendering position instead of computing from atom centers (fixes dot landing at wrong position on wide labels like Cl)
- Charge glyph def IDs use Unicode code points to prevent collision between + (U+002B) and minus (U+2212) in path export mode
- Traveling electron dot preserves mk-* element classes for CSS accessibility overrides (ChemAcademy WCAG color compliance), with SMIL <set> class swap at transition midpoint
- Ghost radical dot at animation start eliminated by excluding source dot from general decoration crossfade when electron transfer is active (binary snap replaces gradual fade)
- LaTeX annotation preserves user-resized dimensions when re-editing equation or font (per-axis scale ratio applied to new MathJax output)