zoooom 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Luke Steuber
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # zoooom
2
+
3
+ <div align="center">
4
+
5
+ ![enhance](https://media.tenor.com/atZ7_JeUlugAAAAM/enhance-supertroopers.gif)
6
+
7
+ *"Enhance."*
8
+
9
+ </div>
10
+
11
+ ---
12
+
13
+ You know the scene. Someone squints at a blurry surveillance photo, says "enhance," and suddenly it's crystal clear at 4000x zoom. Every cop show. Every sci-fi movie. Every time, you think: that's not how images work.
14
+
15
+ **Except now it is.**
16
+
17
+ `zoooom` is a zero-dependency pan/zoom engine for images. Mouse, touch, trackpad, keyboard, and — because why not — a virtual joystick. Drop it on any image and let people *enhance* to their heart's content.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install zoooom
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```js
28
+ import Zoooom from 'zoooom';
29
+
30
+ const viewer = new Zoooom('#photo', { src: 'evidence.jpg' });
31
+ viewer.enhance(); // you know you want to
32
+ ```
33
+
34
+ That's it. Two lines. You now have:
35
+ - Mouse drag to pan
36
+ - Scroll wheel / trackpad pinch to zoom (toward your cursor, not the center like an animal)
37
+ - Touch: single-finger pan, two-finger pinch
38
+ - Keyboard: arrows to pan, `+`/`-` to zoom, `R` to reset
39
+ - A loading spinner that fades out when the image is ready
40
+ - Momentum on release (that satisfying drift)
41
+ - Auto-calculated max zoom from the image's actual resolution
42
+
43
+ ## Script Tag
44
+
45
+ No bundler? No problem.
46
+
47
+ ```html
48
+ <div id="viewer" style="width: 100%; height: 100vh;"></div>
49
+ <script src="https://unpkg.com/zoooom/dist/zoooom.iife.global.js"></script>
50
+ <script>
51
+ new Zoooom('#viewer', { src: 'satellite.jpg' });
52
+ </script>
53
+ ```
54
+
55
+ ## What Makes This Different
56
+
57
+ Most image zoom libraries are either:
58
+ 1. jQuery plugins from 2014 that zoom to center (not cursor position)
59
+ 2. React/Vue wrappers that bring 200KB of framework along
60
+ 3. Overkill map engines that want tile servers
61
+
62
+ `zoooom` is none of those. It's the interaction engine extracted from an accessibility-first image viewer I built to display 165 high-resolution infographics. Battle-tested with mouse, touch, trackpad, keyboard, and even joystick input across Chrome, Firefox, Safari, and mobile.
63
+
64
+ **Zero dependencies. ~25KB core (before gzip). Works with any image.**
65
+
66
+ The zoom-toward-cursor math is correct (not the naive "scale from center" that most libs do). Trackpad detection distinguishes precision scrolling from mouse wheel clicks. Safari gesture events are handled. Pinch-to-zoom tracks the actual pinch center, not the image center.
67
+
68
+ ## Options
69
+
70
+ ```js
71
+ new Zoooom('#container', {
72
+ src: 'photo.jpg', // required
73
+ alt: 'A satellite image', // default: 'Image'
74
+ minScale: 0.8, // how far you can zoom out
75
+ maxScale: 'auto', // 'auto' = calculated from natural image dimensions
76
+ zoomFactor: 1.5, // multiplier per zoom step
77
+ velocityDamping: 0.85, // momentum friction (0 = ice rink, 1 = brick wall)
78
+ trackpadSensitivity: 0.002, // fine-tuning for continuous trackpad zoom
79
+ mouse: true, // enable mouse input
80
+ touch: true, // enable touch input
81
+ wheel: true, // enable wheel/trackpad
82
+ keyboard: true, // enable keyboard nav
83
+ loading: true, // show loading spinner
84
+ injectStyles: true, // auto-inject CSS (disable for BYO styles)
85
+ respectReducedMotion: true, // honor prefers-reduced-motion
86
+ onLoad: () => {}, // fires when image is ready
87
+ onZoom: (scale) => {}, // fires on zoom change
88
+ onPan: (x, y) => {}, // fires on pan
89
+ });
90
+ ```
91
+
92
+ ## API
93
+
94
+ ```js
95
+ const viewer = new Zoooom('#el', { src: 'img.jpg' });
96
+
97
+ viewer.zoomIn(); // zoom in by zoomFactor
98
+ viewer.zoomOut(); // zoom out
99
+ viewer.enhance(); // same as zoomIn(), but funnier
100
+ viewer.zoomTo(3); // set specific scale
101
+ viewer.zoomToPoint(2, x, y); // zoom toward a point
102
+ viewer.panTo(100, -50); // set position directly
103
+ viewer.panBy(10, 0); // relative pan
104
+ viewer.reset(); // back to scale=1, centered
105
+ viewer.center(); // center without changing zoom
106
+ viewer.load('new.jpg'); // load a different image
107
+ viewer.destroy(); // clean up everything
108
+
109
+ // Read state
110
+ viewer.scale; // current zoom level
111
+ viewer.translateX; // current X offset
112
+ viewer.translateY; // current Y offset
113
+ viewer.isLoaded; // whether image is ready
114
+
115
+ // Events
116
+ viewer.on('load', () => {});
117
+ viewer.on('zoom', (scale) => {});
118
+ viewer.on('pan', (x, y) => {});
119
+ viewer.on('reset', () => {});
120
+ viewer.on('destroy', () => {});
121
+ viewer.off('zoom', handler);
122
+ ```
123
+
124
+ ## Joystick Plugin
125
+
126
+ For when arrow keys aren't enough and you want that drone-camera-operator feeling:
127
+
128
+ ```js
129
+ import Zoooom from 'zoooom';
130
+ import { ZoooomJoystick } from 'zoooom/joystick';
131
+
132
+ const viewer = new Zoooom('#container', { src: 'map.jpg' });
133
+ const joystick = new ZoooomJoystick(viewer);
134
+ ```
135
+
136
+ The joystick gives you:
137
+ - A virtual disc for 8-directional panning (hover or drag)
138
+ - Split-circle center for zoom in/out
139
+ - Dwell-to-activate (hover 100ms, then move to pan)
140
+ - Direction arrows showing which way you're going
141
+ - Screen reader ARIA support (announces direction + speed)
142
+ - Compass toggle button to show/hide
143
+
144
+ ```js
145
+ // Joystick options
146
+ new ZoooomJoystick(viewer, {
147
+ radius: 60, // panning zone radius (px)
148
+ deadzone: 0.1, // center deadzone (fraction)
149
+ maxSpeed: 10, // max pan speed (px/frame)
150
+ showToggle: true, // show the toggle button
151
+ dwellTimeout: 100, // ms before dwell activates
152
+ });
153
+
154
+ joystick.show(); // show programmatically
155
+ joystick.hide(); // hide
156
+ joystick.destroy(); // remove from DOM
157
+ ```
158
+
159
+ Script tag (full bundle with joystick included):
160
+
161
+ ```html
162
+ <script src="https://unpkg.com/zoooom/dist/zoooom-full.iife.global.js"></script>
163
+ <script>
164
+ const viewer = new Zoooom('#container', { src: 'photo.jpg' });
165
+ const joystick = new ZoooomJoystick(viewer);
166
+ </script>
167
+ ```
168
+
169
+ ## CSS Customization
170
+
171
+ Styles are auto-injected. Override with CSS variables:
172
+
173
+ ```css
174
+ [data-zoooom] {
175
+ --zoooom-bg: #1a1a1a;
176
+ --zoooom-spinner-color: #ff6b6b;
177
+ --zoooom-spinner-track: rgba(255, 255, 255, 0.2);
178
+ --zoooom-spinner-size: 48px;
179
+ --zoooom-loading-bg: rgba(0, 0, 0, 0.9);
180
+ --zoooom-loading-radius: 12px;
181
+ --zoooom-cursor: crosshair;
182
+ --zoooom-cursor-active: move;
183
+ }
184
+ ```
185
+
186
+ Or disable auto-injection and bring your own:
187
+
188
+ ```js
189
+ new Zoooom('#el', { src: 'img.jpg', injectStyles: false });
190
+ ```
191
+
192
+ ```html
193
+ <link rel="stylesheet" href="node_modules/zoooom/dist/zoooom.css">
194
+ ```
195
+
196
+ ## Accessibility
197
+
198
+ - Full keyboard navigation (arrows, +/-, R, Tab)
199
+ - `prefers-reduced-motion` respected — no transitions, no momentum, instant show
200
+ - ARIA labels on all interactive elements
201
+ - Joystick announces direction and speed to screen readers
202
+ - Container is focusable and has `role="application"` with usage hints
203
+ - Minimum 44px touch targets
204
+
205
+ ## Browser Support
206
+
207
+ ES2020+: Chrome 80+, Firefox 74+, Safari 14+, Edge 80+.
208
+
209
+ ## The Name
210
+
211
+ Four o's because three felt restrained and five was too many.
212
+
213
+ ## License
214
+
215
+ MIT
@@ -0,0 +1,128 @@
1
+ /** Configuration options for the Zoooom viewer */
2
+ interface ZoooomOptions {
3
+ /** Image URL to display (required) */
4
+ src: string;
5
+ /** Alt text for the image */
6
+ alt?: string;
7
+ /** Minimum zoom scale (default: 0.8) */
8
+ minScale?: number;
9
+ /** Maximum zoom scale — 'auto' calculates from natural dimensions (default: 'auto') */
10
+ maxScale?: number | 'auto';
11
+ /** Multiplier beyond native resolution for max zoom (default: 2) */
12
+ overscaleFactor?: number;
13
+ /** Zoom multiplier per discrete step (default: 1.5) */
14
+ zoomFactor?: number;
15
+ /** Keyboard pan distance in pixels (default: 50) */
16
+ panStep?: number;
17
+ /** Momentum friction coefficient, 0-1 (default: 0.85) */
18
+ velocityDamping?: number;
19
+ /** Sensitivity for continuous trackpad zoom (default: 0.002) */
20
+ trackpadSensitivity?: number;
21
+ /** Enable mouse drag/wheel (default: true) */
22
+ mouse?: boolean;
23
+ /** Enable touch pan/pinch (default: true) */
24
+ touch?: boolean;
25
+ /** Enable wheel/trackpad zoom (default: true) */
26
+ wheel?: boolean;
27
+ /** Enable keyboard navigation (default: true) */
28
+ keyboard?: boolean;
29
+ /** Show loading spinner — true for default, string for custom HTML, false to disable */
30
+ loading?: boolean | string;
31
+ /** Auto-inject bundled CSS (default: true) */
32
+ injectStyles?: boolean;
33
+ /** Honor prefers-reduced-motion (default: true) */
34
+ respectReducedMotion?: boolean;
35
+ onLoad?: () => void;
36
+ onError?: (error: Error) => void;
37
+ onZoom?: (scale: number) => void;
38
+ onPan?: (x: number, y: number) => void;
39
+ }
40
+ /** Internal mutable state for the viewer */
41
+ interface ZoooomState {
42
+ scale: number;
43
+ translateX: number;
44
+ translateY: number;
45
+ velocityX: number;
46
+ velocityY: number;
47
+ maxScale: number;
48
+ isDragging: boolean;
49
+ isAnimating: boolean;
50
+ isLoaded: boolean;
51
+ startX: number;
52
+ startY: number;
53
+ initialDistance: number;
54
+ initialScale: number;
55
+ initialTranslateX: number;
56
+ initialTranslateY: number;
57
+ pinchCenter: {
58
+ x: number;
59
+ y: number;
60
+ };
61
+ wheelTimeout: ReturnType<typeof setTimeout> | null;
62
+ reducedMotion: boolean;
63
+ }
64
+ /** Event types emitted by Zoooom */
65
+ type ZoooomEvent = 'load' | 'error' | 'zoom' | 'pan' | 'reset' | 'destroy';
66
+ /** Event handler function */
67
+ type ZoooomEventHandler = (...args: unknown[]) => void;
68
+ /** DOM elements managed by the viewer */
69
+ interface ZoooomElements {
70
+ container: HTMLElement;
71
+ image: HTMLImageElement;
72
+ loadingOverlay: HTMLElement | null;
73
+ }
74
+ /** Joystick plugin options */
75
+ interface JoystickOptions {
76
+ /** Panning zone radius in pixels (default: 60) */
77
+ radius?: number;
78
+ /** Center deadzone as fraction 0-1 (default: 0.1) */
79
+ deadzone?: number;
80
+ /** Max panning speed in px/frame (default: 10) */
81
+ maxSpeed?: number;
82
+ /** Position of the joystick (default: 'bottom-center') */
83
+ position?: 'bottom-center' | 'bottom-left' | 'bottom-right';
84
+ /** Show compass toggle button (default: true) */
85
+ showToggle?: boolean;
86
+ /** Milliseconds before dwell activates panning (default: 100) */
87
+ dwellTimeout?: number;
88
+ }
89
+
90
+ declare class Zoooom {
91
+ private state;
92
+ private elements;
93
+ private options;
94
+ private cleanups;
95
+ private listeners;
96
+ private resizeHandler;
97
+ constructor(container: string | HTMLElement, options: ZoooomOptions);
98
+ get scale(): number;
99
+ get translateX(): number;
100
+ get translateY(): number;
101
+ get isLoaded(): boolean;
102
+ zoomIn(): void;
103
+ zoomOut(): void;
104
+ /** "Enhance." */
105
+ enhance(): void;
106
+ zoomTo(scale: number): void;
107
+ zoomToPoint(scale: number, x: number, y: number): void;
108
+ panTo(x: number, y: number): void;
109
+ panBy(dx: number, dy: number): void;
110
+ reset(): void;
111
+ center(): void;
112
+ load(src: string, alt?: string): void;
113
+ /**
114
+ * Apply velocity directly (used by joystick plugin).
115
+ * Sets velocity and lets the rAF loop handle movement.
116
+ */
117
+ applyVelocity(vx: number, vy: number): void;
118
+ /** Get the internal state (for plugin access) */
119
+ getState(): Readonly<ZoooomState>;
120
+ /** Get the managed elements (for plugin access) */
121
+ getElements(): Readonly<ZoooomElements>;
122
+ on(event: ZoooomEvent, handler: ZoooomEventHandler): void;
123
+ off(event: ZoooomEvent, handler: ZoooomEventHandler): void;
124
+ emit(event: string, ...args: unknown[]): void;
125
+ destroy(): void;
126
+ }
127
+
128
+ export { type JoystickOptions as J, Zoooom as Z, type ZoooomEvent as a, type ZoooomEventHandler as b, type ZoooomOptions as c };
@@ -0,0 +1,128 @@
1
+ /** Configuration options for the Zoooom viewer */
2
+ interface ZoooomOptions {
3
+ /** Image URL to display (required) */
4
+ src: string;
5
+ /** Alt text for the image */
6
+ alt?: string;
7
+ /** Minimum zoom scale (default: 0.8) */
8
+ minScale?: number;
9
+ /** Maximum zoom scale — 'auto' calculates from natural dimensions (default: 'auto') */
10
+ maxScale?: number | 'auto';
11
+ /** Multiplier beyond native resolution for max zoom (default: 2) */
12
+ overscaleFactor?: number;
13
+ /** Zoom multiplier per discrete step (default: 1.5) */
14
+ zoomFactor?: number;
15
+ /** Keyboard pan distance in pixels (default: 50) */
16
+ panStep?: number;
17
+ /** Momentum friction coefficient, 0-1 (default: 0.85) */
18
+ velocityDamping?: number;
19
+ /** Sensitivity for continuous trackpad zoom (default: 0.002) */
20
+ trackpadSensitivity?: number;
21
+ /** Enable mouse drag/wheel (default: true) */
22
+ mouse?: boolean;
23
+ /** Enable touch pan/pinch (default: true) */
24
+ touch?: boolean;
25
+ /** Enable wheel/trackpad zoom (default: true) */
26
+ wheel?: boolean;
27
+ /** Enable keyboard navigation (default: true) */
28
+ keyboard?: boolean;
29
+ /** Show loading spinner — true for default, string for custom HTML, false to disable */
30
+ loading?: boolean | string;
31
+ /** Auto-inject bundled CSS (default: true) */
32
+ injectStyles?: boolean;
33
+ /** Honor prefers-reduced-motion (default: true) */
34
+ respectReducedMotion?: boolean;
35
+ onLoad?: () => void;
36
+ onError?: (error: Error) => void;
37
+ onZoom?: (scale: number) => void;
38
+ onPan?: (x: number, y: number) => void;
39
+ }
40
+ /** Internal mutable state for the viewer */
41
+ interface ZoooomState {
42
+ scale: number;
43
+ translateX: number;
44
+ translateY: number;
45
+ velocityX: number;
46
+ velocityY: number;
47
+ maxScale: number;
48
+ isDragging: boolean;
49
+ isAnimating: boolean;
50
+ isLoaded: boolean;
51
+ startX: number;
52
+ startY: number;
53
+ initialDistance: number;
54
+ initialScale: number;
55
+ initialTranslateX: number;
56
+ initialTranslateY: number;
57
+ pinchCenter: {
58
+ x: number;
59
+ y: number;
60
+ };
61
+ wheelTimeout: ReturnType<typeof setTimeout> | null;
62
+ reducedMotion: boolean;
63
+ }
64
+ /** Event types emitted by Zoooom */
65
+ type ZoooomEvent = 'load' | 'error' | 'zoom' | 'pan' | 'reset' | 'destroy';
66
+ /** Event handler function */
67
+ type ZoooomEventHandler = (...args: unknown[]) => void;
68
+ /** DOM elements managed by the viewer */
69
+ interface ZoooomElements {
70
+ container: HTMLElement;
71
+ image: HTMLImageElement;
72
+ loadingOverlay: HTMLElement | null;
73
+ }
74
+ /** Joystick plugin options */
75
+ interface JoystickOptions {
76
+ /** Panning zone radius in pixels (default: 60) */
77
+ radius?: number;
78
+ /** Center deadzone as fraction 0-1 (default: 0.1) */
79
+ deadzone?: number;
80
+ /** Max panning speed in px/frame (default: 10) */
81
+ maxSpeed?: number;
82
+ /** Position of the joystick (default: 'bottom-center') */
83
+ position?: 'bottom-center' | 'bottom-left' | 'bottom-right';
84
+ /** Show compass toggle button (default: true) */
85
+ showToggle?: boolean;
86
+ /** Milliseconds before dwell activates panning (default: 100) */
87
+ dwellTimeout?: number;
88
+ }
89
+
90
+ declare class Zoooom {
91
+ private state;
92
+ private elements;
93
+ private options;
94
+ private cleanups;
95
+ private listeners;
96
+ private resizeHandler;
97
+ constructor(container: string | HTMLElement, options: ZoooomOptions);
98
+ get scale(): number;
99
+ get translateX(): number;
100
+ get translateY(): number;
101
+ get isLoaded(): boolean;
102
+ zoomIn(): void;
103
+ zoomOut(): void;
104
+ /** "Enhance." */
105
+ enhance(): void;
106
+ zoomTo(scale: number): void;
107
+ zoomToPoint(scale: number, x: number, y: number): void;
108
+ panTo(x: number, y: number): void;
109
+ panBy(dx: number, dy: number): void;
110
+ reset(): void;
111
+ center(): void;
112
+ load(src: string, alt?: string): void;
113
+ /**
114
+ * Apply velocity directly (used by joystick plugin).
115
+ * Sets velocity and lets the rAF loop handle movement.
116
+ */
117
+ applyVelocity(vx: number, vy: number): void;
118
+ /** Get the internal state (for plugin access) */
119
+ getState(): Readonly<ZoooomState>;
120
+ /** Get the managed elements (for plugin access) */
121
+ getElements(): Readonly<ZoooomElements>;
122
+ on(event: ZoooomEvent, handler: ZoooomEventHandler): void;
123
+ off(event: ZoooomEvent, handler: ZoooomEventHandler): void;
124
+ emit(event: string, ...args: unknown[]): void;
125
+ destroy(): void;
126
+ }
127
+
128
+ export { type JoystickOptions as J, Zoooom as Z, type ZoooomEvent as a, type ZoooomEventHandler as b, type ZoooomOptions as c };