textmode.js 0.3.0 → 0.3.1

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.
@@ -17,11 +17,13 @@ export interface MouseEventData {
17
17
  position: MousePosition;
18
18
  /** Previous mouse position in grid coordinates */
19
19
  previousPosition: MousePosition;
20
- /** Mouse button that triggered the event (for click events) */
20
+ /** Mouse button that triggered the event *(for click events)* */
21
21
  button?: number;
22
22
  /** Scroll delta for wheel events */
23
23
  delta?: {
24
+ /** Scroll delta in X direction */
24
25
  x: number;
26
+ /** Scroll delta in Y direction */
25
27
  y: number;
26
28
  };
27
29
  /** Original DOM event */
@@ -34,6 +36,7 @@ export type MouseEventHandler = (data: MouseEventData) => void;
34
36
  /**
35
37
  * Manages all mouse interaction for a Textmodifier instance.
36
38
  * Handles event listeners, coordinate conversion, and event dispatching.
39
+ * @ignore
37
40
  */
38
41
  export declare class MouseManager {
39
42
  private _canvas;
@@ -41,6 +44,7 @@ export declare class MouseManager {
41
44
  private _mousePosition;
42
45
  private _previousMousePosition;
43
46
  private _lastClientCoordinates;
47
+ private _suppressUntil;
44
48
  private _mouseMoveListener;
45
49
  private _mouseLeaveListener;
46
50
  private _mouseDownListener;
@@ -54,6 +58,20 @@ export declare class MouseManager {
54
58
  private _mouseMovedCallback?;
55
59
  private _mouseScrolledCallback?;
56
60
  constructor(canvas: TextmodeCanvas);
61
+ /**
62
+ * Temporarily suppress mouse event callbacks for a duration in milliseconds.
63
+ * Used to prevent synthetic mouse events from touch interactions from firing twice.
64
+ */
65
+ $suppressEventsFor(durationMs: number): void;
66
+ private _isSuppressed;
67
+ /**
68
+ * Set the CSS cursor for the textmode canvas.
69
+ * Pass a valid CSS cursor value (e.g. 'pointer', 'crosshair', 'move', 'nwse-resize', 'none').
70
+ * Call with no argument or an empty string to reset to the default cursor.
71
+ *
72
+ * Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
73
+ */
74
+ $setCursor(cursor?: string): void;
57
75
  /**
58
76
  * Update the grid reference (useful when grid changes after font loading)
59
77
  */
@@ -0,0 +1,225 @@
1
+ import type { TextmodeCanvas } from '../Canvas';
2
+ import type { TextmodeGrid } from '../Grid';
3
+ import type { MouseManager } from './MouseManager';
4
+ /**
5
+ * Touch position expressed both in grid and client coordinates
6
+ */
7
+ export interface TouchPosition {
8
+ /** Identifier provided by the browser for a touch point */
9
+ id: number;
10
+ /** Grid X coordinate (column), -1 if touch is outside grid */
11
+ x: number;
12
+ /** Grid Y coordinate (row), -1 if touch is outside grid */
13
+ y: number;
14
+ /** Client X coordinate in CSS pixels */
15
+ clientX: number;
16
+ /** Client Y coordinate in CSS pixels */
17
+ clientY: number;
18
+ /** Touch pressure (0-1) when supported */
19
+ pressure?: number;
20
+ /** Contact ellipse radius on the X axis in CSS pixels */
21
+ radiusX?: number;
22
+ /** Contact ellipse radius on the Y axis in CSS pixels */
23
+ radiusY?: number;
24
+ /** Contact ellipse angle in radians when provided */
25
+ rotationAngle?: number;
26
+ }
27
+ /**
28
+ * Touch event data.
29
+ */
30
+ export interface TouchEventData {
31
+ /** The touch point that triggered this event */
32
+ touch: TouchPosition;
33
+ /** The previous position for this touch if available */
34
+ previousTouch?: TouchPosition;
35
+ /** All active touches mapped to grid coordinates */
36
+ touches: TouchPosition[];
37
+ /** Active touches snapshot before this event */
38
+ previousTouches: TouchPosition[];
39
+ /** Touches that changed during this event */
40
+ changedTouches: TouchPosition[];
41
+ /** Milliseconds elapsed since the previous update for this touch */
42
+ deltaTime: number;
43
+ /** Original browser event */
44
+ originalEvent: TouchEvent;
45
+ }
46
+ /**
47
+ * Tap (single or double) event data
48
+ */
49
+ export interface TouchTapEventData {
50
+ /** Position of the tap */
51
+ touch: TouchPosition;
52
+ /** Number of taps recognised (1 or 2) */
53
+ taps: 1 | 2;
54
+ /** Original browser event */
55
+ originalEvent: TouchEvent;
56
+ }
57
+ /**
58
+ * Long press event data
59
+ */
60
+ export interface TouchLongPressEventData {
61
+ /** Touch position at the time the long press fired */
62
+ touch: TouchPosition;
63
+ /** Duration in milliseconds the press was held */
64
+ duration: number;
65
+ /** Original browser event */
66
+ originalEvent: TouchEvent;
67
+ }
68
+ /**
69
+ * Swipe event data reported when the finger travels a minimum distance within a time window
70
+ */
71
+ export interface TouchSwipeEventData {
72
+ /** Touch point at the end of the swipe */
73
+ touch: TouchPosition;
74
+ /** Normalised swipe direction vector */
75
+ direction: {
76
+ x: number;
77
+ y: number;
78
+ };
79
+ /** Total distance travelled in CSS pixels */
80
+ distance: number;
81
+ /** Velocity in CSS pixels per millisecond */
82
+ velocity: {
83
+ /** Velocity in X direction */
84
+ x: number;
85
+ /** Velocity in Y direction */
86
+ y: number;
87
+ };
88
+ /** Original browser event */
89
+ originalEvent: TouchEvent;
90
+ }
91
+ /**
92
+ * Pinch gesture event data describing the scaling factor between the initial and current distance
93
+ */
94
+ export interface TouchPinchEventData {
95
+ /** Touch points participating in the pinch, always two entries */
96
+ touches: [TouchPosition, TouchPosition];
97
+ /** Scale factor relative to the initial distance *(1 == unchanged)* */
98
+ scale: number;
99
+ /** Scale delta compared to the previous callback */
100
+ deltaScale: number;
101
+ /** Centre of the gesture in grid coordinates */
102
+ center: {
103
+ /** Grid X coordinate *(column)* */
104
+ x: number;
105
+ /** Grid Y coordinate *(row)* */
106
+ y: number;
107
+ };
108
+ /** Original browser event */
109
+ originalEvent: TouchEvent;
110
+ }
111
+ /**
112
+ * Rotate gesture event data describing the angle change between the initial and current segment
113
+ */
114
+ export interface TouchRotateEventData {
115
+ /** Touch points participating in the rotation, always two entries */
116
+ touches: [TouchPosition, TouchPosition];
117
+ /** Total rotation in degrees relative to the initial angle */
118
+ rotation: number;
119
+ /** Change in rotation since the previous callback */
120
+ deltaRotation: number;
121
+ /** Centre of the gesture in grid coordinates */
122
+ center: {
123
+ /** Grid X coordinate *(column)* */
124
+ x: number;
125
+ /** Grid Y coordinate *(row)* */
126
+ y: number;
127
+ };
128
+ /** Original browser event */
129
+ originalEvent: TouchEvent;
130
+ }
131
+ /** Touch event handler function type */
132
+ export type TouchEventHandler = (data: TouchEventData) => void;
133
+ /** Touch tap event handler function type */
134
+ export type TouchTapHandler = (data: TouchTapEventData) => void;
135
+ /** Touch long press event handler function type */
136
+ export type TouchLongPressHandler = (data: TouchLongPressEventData) => void;
137
+ /** Touch swipe event handler function type */
138
+ export type TouchSwipeHandler = (data: TouchSwipeEventData) => void;
139
+ /** Touch pinch event handler function type */
140
+ export type TouchPinchHandler = (data: TouchPinchEventData) => void;
141
+ /** Touch rotate event handler function type */
142
+ export type TouchRotateHandler = (data: TouchRotateEventData) => void;
143
+ /**
144
+ * Manages all touch interactions for a Textmodifier instance.
145
+ * Handles event listeners, coordinate conversion, gesture detection, and event dispatching.
146
+ * @ignore
147
+ */
148
+ export declare class TouchManager {
149
+ private readonly _canvas;
150
+ private readonly _mouseManager?;
151
+ private _grid;
152
+ private _activeTouches;
153
+ private _previousTouches;
154
+ private _touchInfo;
155
+ private _gestureBaseline;
156
+ private readonly _originalTouchAction;
157
+ private readonly _originalUserSelect;
158
+ private _touchStartListener;
159
+ private _touchMoveListener;
160
+ private _touchEndListener;
161
+ private _touchCancelListener;
162
+ private _areListenersSetup;
163
+ private _touchStartedCallback?;
164
+ private _touchMovedCallback?;
165
+ private _touchEndedCallback?;
166
+ private _touchCancelledCallback?;
167
+ private _tapCallback?;
168
+ private _doubleTapCallback?;
169
+ private _longPressCallback?;
170
+ private _swipeCallback?;
171
+ private _pinchCallback?;
172
+ private _rotateCallback?;
173
+ private readonly _tapMaxDuration;
174
+ private readonly _doubleTapMaxInterval;
175
+ private readonly _tapMovementTolerance;
176
+ private readonly _longPressDuration;
177
+ private readonly _longPressMovementTolerance;
178
+ private readonly _swipeMinDistance;
179
+ private readonly _swipeMaxDuration;
180
+ private readonly _pinchThreshold;
181
+ private readonly _rotationThreshold;
182
+ private readonly _mouseSuppressionDuration;
183
+ private _lastTapTime;
184
+ private _lastTapPosition;
185
+ constructor(canvas: TextmodeCanvas, mouseManager?: MouseManager);
186
+ /** Initialise the manager with the active grid */
187
+ $initialize(grid: TextmodeGrid): void;
188
+ /** Install touch listeners onto the canvas */
189
+ $setupListeners(): void;
190
+ /** Remove all touch listeners */
191
+ $cleanupListeners(): void;
192
+ /**
193
+ * Recalculate touch positions after grid size or offset changes.
194
+ * Uses stored client coordinates to project touches into the new grid.
195
+ */
196
+ $updatePositions(): void;
197
+ /** Retrieve a snapshot of all active touches */
198
+ $getTouches(): TouchPosition[];
199
+ $setStartedCallback(callback: TouchEventHandler): void;
200
+ $setMovedCallback(callback: TouchEventHandler): void;
201
+ $setEndedCallback(callback: TouchEventHandler): void;
202
+ $setCancelledCallback(callback: TouchEventHandler): void;
203
+ $setTapCallback(callback: TouchTapHandler): void;
204
+ $setDoubleTapCallback(callback: TouchTapHandler): void;
205
+ $setLongPressCallback(callback: TouchLongPressHandler): void;
206
+ $setSwipeCallback(callback: TouchSwipeHandler): void;
207
+ $setPinchCallback(callback: TouchPinchHandler): void;
208
+ $setRotateCallback(callback: TouchRotateHandler): void;
209
+ private _handleTouchStart;
210
+ private _handleTouchMove;
211
+ private _handleTouchEnd;
212
+ private _handleTouchCancel;
213
+ private _mapTouchList;
214
+ private _projectTouch;
215
+ private _projectClientToGrid;
216
+ private _buildTouchEventData;
217
+ private _initializeGestureBaseline;
218
+ private _updatePinchAndRotate;
219
+ private _gestureCenter;
220
+ private _evaluateTapAndSwipe;
221
+ private _detectDoubleTap;
222
+ private _cloneTouchPosition;
223
+ private _distance;
224
+ private _angle;
225
+ }
@@ -1,4 +1,12 @@
1
- export { KeyboardManager } from '../managers/KeyboardManager';
2
- export type { KeyboardEventData, KeyboardEventHandler, KeyState } from '../managers/KeyboardManager';
3
- export { MouseManager } from '../managers/MouseManager';
4
- export type { MousePosition, MouseEventData, MouseEventHandler } from '../managers/MouseManager';
1
+ /**
2
+ * Types and interfaces for keyboard event handling
3
+ */
4
+ export * as keyboard from '../managers/KeyboardManager';
5
+ /**
6
+ * Types and interfaces for mouse event handling
7
+ */
8
+ export * as mouse from '../managers/MouseManager';
9
+ /**
10
+ * Types and interfaces for touch event handling
11
+ */
12
+ export * as touch from '../managers/TouchManager';
@@ -1,4 +1,5 @@
1
1
  import type { Mixin } from './TextmodifierMixin';
2
+ import type { KeyboardEventHandler } from '../managers/KeyboardManager';
2
3
  /**
3
4
  * Capabilities provided by the KeyboardMixin
4
5
  */
@@ -61,7 +62,7 @@ export interface KeyboardCapabilities {
61
62
  * });
62
63
  * ```
63
64
  */
64
- keyPressed(callback: () => void): void;
65
+ keyPressed(callback: KeyboardEventHandler): void;
65
66
  /**
66
67
  * Set a callback function that will be called when a key is released.
67
68
  *
@@ -79,7 +80,7 @@ export interface KeyboardCapabilities {
79
80
  * });
80
81
  * ```
81
82
  */
82
- keyReleased(callback: () => void): void;
83
+ keyReleased(callback: KeyboardEventHandler): void;
83
84
  }
84
85
  /**
85
86
  * Mixin that adds keyboard interaction capabilities to Textmodifier.
@@ -1,5 +1,5 @@
1
1
  import type { Mixin } from './TextmodifierMixin';
2
- import type { MousePosition } from '../managers';
2
+ import type { MouseEventHandler, MousePosition } from '../managers/MouseManager';
3
3
  /**
4
4
  * Capabilities provided by the MouseMixin
5
5
  */
@@ -19,7 +19,7 @@ export interface MouseCapabilities {
19
19
  * });
20
20
  * ```
21
21
  */
22
- mouseClicked(callback: () => void): void;
22
+ mouseClicked(callback: MouseEventHandler): void;
23
23
  /**
24
24
  * Set a callback function that will be called when the mouse is pressed down.
25
25
  *
@@ -34,7 +34,7 @@ export interface MouseCapabilities {
34
34
  * });
35
35
  * ```
36
36
  */
37
- mousePressed(callback: () => void): void;
37
+ mousePressed(callback: MouseEventHandler): void;
38
38
  /**
39
39
  * Set a callback function that will be called when the mouse is released.
40
40
  *
@@ -49,7 +49,7 @@ export interface MouseCapabilities {
49
49
  * });
50
50
  * ```
51
51
  */
52
- mouseReleased(callback: () => void): void;
52
+ mouseReleased(callback: MouseEventHandler): void;
53
53
  /**
54
54
  * Set a callback function that will be called when the mouse moves.
55
55
  *
@@ -67,7 +67,7 @@ export interface MouseCapabilities {
67
67
  * });
68
68
  * ```
69
69
  */
70
- mouseMoved(callback: () => void): void;
70
+ mouseMoved(callback: MouseEventHandler): void;
71
71
  /**
72
72
  * Set a callback function that will be called when the mouse wheel is scrolled.
73
73
  *
@@ -83,7 +83,7 @@ export interface MouseCapabilities {
83
83
  * });
84
84
  * ```
85
85
  */
86
- mouseScrolled(callback: () => void): void;
86
+ mouseScrolled(callback: MouseEventHandler): void;
87
87
  /**
88
88
  * Get the current mouse position in grid coordinates.
89
89
  *
@@ -109,6 +109,23 @@ export interface MouseCapabilities {
109
109
  * ```
110
110
  */
111
111
  get mouse(): MousePosition;
112
+ /**
113
+ * Set the mouse cursor for the textmode canvas.
114
+ *
115
+ * Provide any valid CSS cursor value (e.g. 'default', 'pointer', 'crosshair', 'move', 'text', 'grab', 'grabbing',
116
+ * 'none', 'zoom-in', 'zoom-out', 'ns-resize', 'ew-resize', 'nwse-resize', 'nesw-resize', etc.),
117
+ * or a CSS `url(...)` cursor. Call with no argument or an empty string to reset to default.
118
+ *
119
+ * See MDN for all options: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
120
+ *
121
+ * @example
122
+ * ```javascript
123
+ * t.cursor('crosshair');
124
+ * // ... later, reset:
125
+ * t.cursor();
126
+ * ```
127
+ */
128
+ cursor(cursor?: string): void;
112
129
  }
113
130
  /**
114
131
  * Mixin that adds mouse tracking capabilities to Textmodifier.
@@ -563,6 +563,7 @@ export interface RenderingCapabilities {
563
563
  * @param r Red component (0-255)
564
564
  * @param g Green component (0-255)
565
565
  * @param b Blue component (0-255)
566
+ * @param a Alpha component (0-255, optional, defaults to 255)
566
567
  *
567
568
  * @example
568
569
  * ```javascript
@@ -578,12 +579,13 @@ export interface RenderingCapabilities {
578
579
  * });
579
580
  * ```
580
581
  */
581
- charColor(r: number, g: number, b: number): void;
582
+ charColor(r: number, g: number, b: number, a?: number): void;
582
583
  /**
583
584
  * Set the cell background color for subsequent rendering operations.
584
585
  * @param r Red component (0-255)
585
586
  * @param g Green component (0-255)
586
587
  * @param b Blue component (0-255)
588
+ * @param a Alpha component (0-255, optional, defaults to 255)
587
589
  *
588
590
  * @example
589
591
  * ```javascript
@@ -599,7 +601,7 @@ export interface RenderingCapabilities {
599
601
  * });
600
602
  * ```
601
603
  */
602
- cellColor(r: number, g: number, b: number): void;
604
+ cellColor(r: number, g: number, b: number, a: number): void;
603
605
  /**
604
606
  * Toggle horizontal flipping for subsequent character rendering.
605
607
  * @param toggle Whether to flip horizontally
@@ -7,8 +7,9 @@ import type { TextmodeCanvas } from '../Canvas';
7
7
  import type { TextmodeGrid } from '../Grid';
8
8
  import type { AnimationController } from '../AnimationController';
9
9
  import type { GLFramebuffer, Shader } from '../../rendering';
10
- import type { MouseManager } from '../managers';
11
- import type { KeyboardManager } from '../managers';
10
+ import type { MouseManager } from '../managers/MouseManager';
11
+ import type { KeyboardManager } from '../managers/KeyboardManager';
12
+ import type { TouchManager } from '../managers/TouchManager';
12
13
  /**
13
14
  * Constructor type for mixin pattern
14
15
  */
@@ -34,6 +35,8 @@ export interface TextmodifierContext {
34
35
  readonly _animationController: AnimationController;
35
36
  /** Mouse interaction manager @ignore */
36
37
  readonly _mouseManager: MouseManager;
38
+ /** Touch interaction manager @ignore */
39
+ readonly _touchManager: TouchManager;
37
40
  /** Keyboard interaction manager @ignore */
38
41
  readonly _keyboardManager: KeyboardManager;
39
42
  /** Draw shader that contains content drawn by the user @ignore */
@@ -0,0 +1,191 @@
1
+ import type { Mixin } from './TextmodifierMixin';
2
+ import type { TouchEventHandler, TouchLongPressHandler, TouchPinchHandler, TouchPosition, TouchRotateHandler, TouchSwipeHandler, TouchTapHandler } from '../managers/TouchManager';
3
+ /**
4
+ * Capabilities exposed by the TouchMixin for handling touch interaction and gestures.
5
+ */
6
+ export interface TouchCapabilities {
7
+ /**
8
+ * Set a callback function that will be called when a touch point begins.
9
+ *
10
+ * The callback receives {@link TouchEventData} containing the touch that triggered the event,
11
+ * all active touches, and the original DOM event. Use this to react when the user places one or
12
+ * more fingers on the canvas.
13
+ *
14
+ * @param callback The function to call when a touch starts.
15
+ *
16
+ * @example
17
+ * ```javascript
18
+ * t.touchStarted((data) => {
19
+ * console.log(`Touch ${data.touch.id} began at ${data.touch.x}, ${data.touch.y}`);
20
+ * });
21
+ * ```
22
+ */
23
+ touchStarted(callback: TouchEventHandler): void;
24
+ /**
25
+ * Set a callback function that will be called when a touch point moves across the canvas.
26
+ *
27
+ * The provided callback is invoked continuously while the browser reports move events. Use the
28
+ * `previousTouch` and `deltaTime` fields to derive velocity or gesture behaviour.
29
+ *
30
+ * @param callback The function to call when a touch moves.
31
+ *
32
+ * @example
33
+ * ```javascript
34
+ * t.touchMoved((data) => {
35
+ * const { touch, previousTouch } = data;
36
+ * if (previousTouch) {
37
+ * console.log(`Touch moved by ${touch.x - previousTouch.x}, ${touch.y - previousTouch.y}`);
38
+ * }
39
+ * });
40
+ * ```
41
+ */
42
+ touchMoved(callback: TouchEventHandler): void;
43
+ /**
44
+ * Set a callback function that will be called when a touch ends normally.
45
+ *
46
+ * This fires after the finger leaves the canvas surface and the browser raises a `touchend`
47
+ * event. Use it to finalise state such as drawing strokes or completing gestures.
48
+ *
49
+ * @param callback The function to call when a touch ends.
50
+ *
51
+ * @example
52
+ * ```javascript
53
+ * t.touchEnded((data) => {
54
+ * console.log(`Touch ${data.touch.id} finished at ${data.touch.x}, ${data.touch.y}`);
55
+ * });
56
+ * ```
57
+ */
58
+ touchEnded(callback: TouchEventHandler): void;
59
+ /**
60
+ * Set a callback function that will be called when a touch is cancelled by the browser.
61
+ *
62
+ * Cancellation can occur when the browser takes ownership for scrolling or if the gesture
63
+ * leaves the window. Treat this as an aborted touch and clean up any in-progress state.
64
+ *
65
+ * @param callback The function to call when a touch is cancelled.
66
+ *
67
+ * @example
68
+ * ```javascript
69
+ * t.touchCancelled((data) => {
70
+ * console.warn(`Touch ${data.touch.id} cancelled by the browser`);
71
+ * });
72
+ * ```
73
+ */
74
+ touchCancelled(callback: TouchEventHandler): void;
75
+ /**
76
+ * Register a callback for tap gestures.
77
+ *
78
+ * A tap is fired when the user quickly touches and releases the canvas without travelling far.
79
+ * Use {@link TouchTapEventData.taps} to determine whether the gesture is a single or multi tap.
80
+ *
81
+ * @param callback The function to call when a tap gesture is detected.
82
+ *
83
+ * @example
84
+ * ```javascript
85
+ * t.tap((data) => {
86
+ * console.log(`Tapped at ${data.touch.x}, ${data.touch.y}`);
87
+ * });
88
+ * ```
89
+ */
90
+ tap(callback: TouchTapHandler): void;
91
+ /**
92
+ * Register a callback for double tap gestures.
93
+ *
94
+ * Double taps reuse the same {@link TouchTapEventData} as taps with `taps` set to `2`. This
95
+ * helper lets you supply a dedicated handler when you want to treat double taps differently.
96
+ *
97
+ * @param callback The function to call when a double tap is detected.
98
+ *
99
+ * @example
100
+ * ```javascript
101
+ * t.doubleTap((data) => {
102
+ * console.log('Double tap detected', data.touch);
103
+ * });
104
+ * ```
105
+ */
106
+ doubleTap(callback: TouchTapHandler): void;
107
+ /**
108
+ * Register a callback for long press gestures.
109
+ *
110
+ * A long press is emitted when the user keeps a finger on the canvas without moving beyond the
111
+ * configured tolerance. The event includes the press duration in milliseconds.
112
+ *
113
+ * @param callback The function to call when a long press gesture is detected.
114
+ *
115
+ * @example
116
+ * ```javascript
117
+ * t.longPress((data) => {
118
+ * console.log(`Long press for ${Math.round(data.duration)}ms`);
119
+ * });
120
+ * ```
121
+ */
122
+ longPress(callback: TouchLongPressHandler): void;
123
+ /**
124
+ * Register a callback for swipe gestures.
125
+ *
126
+ * Swipes provide the dominant direction (`up`, `down`, `left`, `right`), travelled distance, and
127
+ * velocity in CSS pixels per millisecond. Useful for panning, flicks, or quick shortcuts.
128
+ *
129
+ * @param callback The function to call when a swipe gesture is detected.
130
+ *
131
+ * @example
132
+ * ```javascript
133
+ * t.swipe((data) => {
134
+ * console.log(`Swipe ${data.direction} with distance ${data.distance}`);
135
+ * });
136
+ * ```
137
+ */
138
+ swipe(callback: TouchSwipeHandler): void;
139
+ /**
140
+ * Register a callback for pinch gestures, receiving scale deltas.
141
+ *
142
+ * Pinch gestures involve two touch points. The callback receives the current scale relative to
143
+ * the initial distance and the change since the previous update, enabling zoom interactions.
144
+ *
145
+ * @param callback The function to call when a pinch gesture is detected.
146
+ *
147
+ * @example
148
+ * ```javascript
149
+ * t.pinch((data) => {
150
+ * console.log(`Pinch scale: ${data.scale.toFixed(2)}`);
151
+ * });
152
+ * ```
153
+ */
154
+ pinch(callback: TouchPinchHandler): void;
155
+ /**
156
+ * Register a callback for rotate gestures, receiving rotation deltas in degrees.
157
+ *
158
+ * Rotation callbacks provide the cumulative rotation and delta rotation since the last update,
159
+ * along with the gesture centre in grid coordinates. Ideal for dial-like interactions.
160
+ *
161
+ * @param callback The function to call when a rotation gesture is detected.
162
+ *
163
+ * @example
164
+ * ```javascript
165
+ * t.rotateGesture((data) => {
166
+ * console.log(`Rotated ${data.deltaRotation.toFixed(1)}°`);
167
+ * });
168
+ * ```
169
+ */
170
+ rotateGesture(callback: TouchRotateHandler): void;
171
+ /**
172
+ * Get the currently active touches in grid coordinates.
173
+ *
174
+ * Returns a copy of each touch, including grid position, client coordinates, and pressure when
175
+ * available. Use this inside a draw loop to react to active multi-touch scenarios.
176
+ *
177
+ * @example
178
+ * ```javascript
179
+ * t.draw(() => {
180
+ * for (const touch of t.touches) {
181
+ * t.point(touch.x, touch.y);
182
+ * }
183
+ * });
184
+ * ```
185
+ */
186
+ get touches(): TouchPosition[];
187
+ }
188
+ /**
189
+ * Mixin that wires the public touch API to the underlying TouchManager implementation.
190
+ */
191
+ export declare const TouchMixin: Mixin<TouchCapabilities>;
@@ -4,6 +4,8 @@ export { ExportMixin, type ExportCapabilities } from './ExportMixin';
4
4
  export { FontMixin, type FontCapabilities } from './FontMixin';
5
5
  export { AnimationMixin, type AnimationCapabilities } from './AnimationMixin';
6
6
  export { MouseMixin, type MouseCapabilities } from './MouseMixin';
7
+ export { TouchMixin, type TouchCapabilities } from './TouchMixin';
7
8
  export { KeyboardMixin, type KeyboardCapabilities } from './KeyboardMixin';
8
- export type { MousePosition, MouseEventData, MouseEventHandler } from '../managers';
9
- export type { KeyboardEventData, KeyboardEventHandler, KeyState } from '../managers';
9
+ export type { MousePosition, MouseEventData, MouseEventHandler } from '../managers/MouseManager';
10
+ export type { TouchEventData, TouchLongPressEventData, TouchPinchEventData, TouchPosition, TouchRotateEventData, TouchSwipeEventData, TouchTapEventData } from '../managers/TouchManager';
11
+ export type { KeyboardEventData, KeyboardEventHandler, KeyState } from '../managers/KeyboardManager';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textmode.js",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "textmode.js is a lightweight creative coding library for creating real-time ASCII art on the web.",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",