textmode.js 0.2.0-beta.5 → 0.2.1-beta.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.
- package/README.md +114 -63
- package/dist/textmode.esm.js +1141 -903
- package/dist/textmode.esm.min.js +1387 -1149
- package/dist/textmode.umd.js +20 -20
- package/dist/textmode.umd.min.js +18 -18
- package/dist/types/Textmode.d.ts +2 -6
- package/dist/types/textmode/Textmodifier.d.ts +16 -8
- package/dist/types/textmode/keyboard/KeyboardManager.d.ts +123 -0
- package/dist/types/textmode/keyboard/index.d.ts +2 -0
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +10 -6
- package/dist/types/textmode/mixins/ExportMixin.d.ts +5 -5
- package/dist/types/textmode/mixins/FontMixin.d.ts +1 -1
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +39 -0
- package/dist/types/textmode/mixins/MouseMixin.d.ts +27 -0
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +70 -39
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +6 -0
- package/dist/types/textmode/mixins/index.d.ts +4 -0
- package/dist/types/textmode/mouse/MouseManager.d.ts +130 -0
- package/dist/types/textmode/mouse/index.d.ts +2 -0
- package/package.json +8 -4
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { TextmodeCanvas } from '../Canvas';
|
|
2
|
+
import type { TextmodeGrid } from '../Grid';
|
|
3
|
+
/**
|
|
4
|
+
* Mouse coordinates in grid space
|
|
5
|
+
*/
|
|
6
|
+
export interface MousePosition {
|
|
7
|
+
/** Grid X coordinate (column), -1 if mouse is outside grid */
|
|
8
|
+
x: number;
|
|
9
|
+
/** Grid Y coordinate (row), -1 if mouse is outside grid */
|
|
10
|
+
y: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Mouse event data passed to event handlers
|
|
14
|
+
*/
|
|
15
|
+
export interface MouseEventData {
|
|
16
|
+
/** Current mouse position in grid coordinates */
|
|
17
|
+
position: MousePosition;
|
|
18
|
+
/** Previous mouse position in grid coordinates */
|
|
19
|
+
previousPosition: MousePosition;
|
|
20
|
+
/** Mouse button that triggered the event (for click events) */
|
|
21
|
+
button?: number;
|
|
22
|
+
/** Scroll delta for wheel events */
|
|
23
|
+
delta?: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
};
|
|
27
|
+
/** Original DOM event */
|
|
28
|
+
originalEvent: MouseEvent | WheelEvent;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Mouse event handler function type
|
|
32
|
+
*/
|
|
33
|
+
export type MouseEventHandler = (data: MouseEventData) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Manages all mouse interaction for a Textmodifier instance.
|
|
36
|
+
* Handles event listeners, coordinate conversion, and event dispatching.
|
|
37
|
+
*/
|
|
38
|
+
export declare class MouseManager {
|
|
39
|
+
private _canvas;
|
|
40
|
+
private _grid;
|
|
41
|
+
private _mousePosition;
|
|
42
|
+
private _previousMousePosition;
|
|
43
|
+
private _lastClientCoordinates;
|
|
44
|
+
private _mouseMoveListener;
|
|
45
|
+
private _mouseLeaveListener;
|
|
46
|
+
private _mouseDownListener;
|
|
47
|
+
private _mouseUpListener;
|
|
48
|
+
private _clickListener;
|
|
49
|
+
private _wheelListener;
|
|
50
|
+
private _areListenersSetup;
|
|
51
|
+
private _mouseClickedCallback?;
|
|
52
|
+
private _mousePressedCallback?;
|
|
53
|
+
private _mouseReleasedCallback?;
|
|
54
|
+
private _mouseMovedCallback?;
|
|
55
|
+
private _mouseScrolledCallback?;
|
|
56
|
+
constructor(canvas: TextmodeCanvas);
|
|
57
|
+
/**
|
|
58
|
+
* Update the grid reference (useful when grid changes after font loading)
|
|
59
|
+
*/
|
|
60
|
+
$initialize(grid: TextmodeGrid): void;
|
|
61
|
+
/**
|
|
62
|
+
* Setup mouse event listeners on the canvas.
|
|
63
|
+
*/
|
|
64
|
+
$setupListeners(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Remove mouse event listeners from the canvas.
|
|
67
|
+
*/
|
|
68
|
+
$cleanupListeners(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Force an immediate update of the mouse position.
|
|
71
|
+
* This is useful when grid dimensions change (font size, window resize, etc.)
|
|
72
|
+
* and we need to recalculate the mouse coordinates without waiting for a mouse event.
|
|
73
|
+
*/
|
|
74
|
+
$updatePosition(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Set a callback function that will be called when the mouse is clicked.
|
|
77
|
+
* @param callback The function to call when the mouse is clicked
|
|
78
|
+
*/
|
|
79
|
+
$setClickedCallback(callback: MouseEventHandler): void;
|
|
80
|
+
/**
|
|
81
|
+
* Set a callback function that will be called when the mouse is pressed down.
|
|
82
|
+
* @param callback The function to call when the mouse is pressed
|
|
83
|
+
*/
|
|
84
|
+
$setPressedCallback(callback: MouseEventHandler): void;
|
|
85
|
+
/**
|
|
86
|
+
* Set a callback function that will be called when the mouse is released.
|
|
87
|
+
* @param callback The function to call when the mouse is released
|
|
88
|
+
*/
|
|
89
|
+
$setReleasedCallback(callback: MouseEventHandler): void;
|
|
90
|
+
/**
|
|
91
|
+
* Set a callback function that will be called when the mouse moves.
|
|
92
|
+
* @param callback The function to call when the mouse moves
|
|
93
|
+
*/
|
|
94
|
+
$setMovedCallback(callback: MouseEventHandler): void;
|
|
95
|
+
/**
|
|
96
|
+
* Set a callback function that will be called when the mouse wheel is scrolled.
|
|
97
|
+
* @param callback The function to call when the mouse wheel is scrolled
|
|
98
|
+
*/
|
|
99
|
+
$setScrolledCallback(callback: MouseEventHandler): void;
|
|
100
|
+
/**
|
|
101
|
+
* Get the current mouse position in grid coordinates.
|
|
102
|
+
* Returns a copy to prevent external modification.
|
|
103
|
+
*/
|
|
104
|
+
$getPosition(): MousePosition;
|
|
105
|
+
/**
|
|
106
|
+
* Handle mouse moved events
|
|
107
|
+
*/
|
|
108
|
+
private _handleMouseMoved;
|
|
109
|
+
/**
|
|
110
|
+
* Handle mouse pressed events
|
|
111
|
+
*/
|
|
112
|
+
private _handleMousePressed;
|
|
113
|
+
/**
|
|
114
|
+
* Handle mouse released events
|
|
115
|
+
*/
|
|
116
|
+
private _handleMouseReleased;
|
|
117
|
+
/**
|
|
118
|
+
* Handle mouse clicked events
|
|
119
|
+
*/
|
|
120
|
+
private _handleMouseClicked;
|
|
121
|
+
/**
|
|
122
|
+
* Handle mouse scrolled events
|
|
123
|
+
*/
|
|
124
|
+
private _handleMouseScrolled;
|
|
125
|
+
/**
|
|
126
|
+
* Update mouse position based on mouse event.
|
|
127
|
+
* Converts pixel coordinates to grid coordinates.
|
|
128
|
+
*/
|
|
129
|
+
private _updateMousePosition;
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textmode.js",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.1-beta.1",
|
|
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",
|
|
7
7
|
"main": "./dist/textmode.umd.js",
|
|
@@ -55,14 +55,18 @@
|
|
|
55
55
|
"petscii",
|
|
56
56
|
"textmode",
|
|
57
57
|
"canvas",
|
|
58
|
-
"webgl"
|
|
58
|
+
"webgl",
|
|
59
|
+
"creative-coding",
|
|
60
|
+
"art",
|
|
61
|
+
"design",
|
|
62
|
+
"graphics"
|
|
59
63
|
],
|
|
60
64
|
"author": "humanbydefinition",
|
|
61
65
|
"license": "MIT",
|
|
62
66
|
"bugs": {
|
|
63
67
|
"url": "https://github.com/humanbydefinition/textmode.js/issues"
|
|
64
68
|
},
|
|
65
|
-
"homepage": "https://
|
|
69
|
+
"homepage": "https://code.textmode.art",
|
|
66
70
|
"files": [
|
|
67
71
|
"dist"
|
|
68
72
|
]
|