@hypen-space/web 0.4.36 → 0.4.37
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/dist/canvas/accessibility.js +174 -174
- package/dist/canvas/accessibility.js.map +1 -10
- package/dist/canvas/events.js +264 -360
- package/dist/canvas/events.js.map +1 -11
- package/dist/canvas/index.js +11 -47
- package/dist/canvas/index.js.map +1 -9
- package/dist/canvas/input.js +178 -289
- package/dist/canvas/input.js.map +1 -11
- package/dist/canvas/layout.js +349 -547
- package/dist/canvas/layout.js.map +1 -12
- package/dist/canvas/paint.js +1122 -1146
- package/dist/canvas/paint.js.map +1 -12
- package/dist/canvas/renderer.js +352 -2259
- package/dist/canvas/renderer.js.map +1 -17
- package/dist/canvas/text.js +129 -264
- package/dist/canvas/text.js.map +1 -11
- package/dist/canvas/types.js +7 -2
- package/dist/canvas/types.js.map +1 -9
- package/dist/canvas/utils.js +158 -161
- package/dist/canvas/utils.js.map +1 -10
- package/dist/client.js +19 -45
- package/dist/client.js.map +1 -9
- package/dist/dom/applicators/advanced-layout.js +105 -138
- package/dist/dom/applicators/advanced-layout.js.map +1 -10
- package/dist/dom/applicators/background.js +36 -76
- package/dist/dom/applicators/background.js.map +1 -10
- package/dist/dom/applicators/border.js +82 -106
- package/dist/dom/applicators/border.js.map +1 -10
- package/dist/dom/applicators/color.js +17 -58
- package/dist/dom/applicators/color.js.map +1 -10
- package/dist/dom/applicators/display.js +39 -79
- package/dist/dom/applicators/display.js.map +1 -10
- package/dist/dom/applicators/effects.js +121 -147
- package/dist/dom/applicators/effects.js.map +1 -10
- package/dist/dom/applicators/events.js +413 -450
- package/dist/dom/applicators/events.js.map +1 -11
- package/dist/dom/applicators/font.js +119 -140
- package/dist/dom/applicators/font.js.map +1 -10
- package/dist/dom/applicators/index.js +386 -1770
- package/dist/dom/applicators/index.js.map +1 -26
- package/dist/dom/applicators/layout.js +143 -149
- package/dist/dom/applicators/layout.js.map +1 -10
- package/dist/dom/applicators/margin.js +64 -105
- package/dist/dom/applicators/margin.js.map +1 -10
- package/dist/dom/applicators/padding.js +64 -105
- package/dist/dom/applicators/padding.js.map +1 -10
- package/dist/dom/applicators/size.js +169 -172
- package/dist/dom/applicators/size.js.map +1 -10
- package/dist/dom/applicators/transform.js +73 -114
- package/dist/dom/applicators/transform.js.map +1 -10
- package/dist/dom/applicators/transition.js +47 -88
- package/dist/dom/applicators/transition.js.map +1 -10
- package/dist/dom/applicators/types.js +7 -2
- package/dist/dom/applicators/types.js.map +1 -9
- package/dist/dom/applicators/typography.js +68 -109
- package/dist/dom/applicators/typography.js.map +1 -10
- package/dist/dom/canvas/index.js +49 -83
- package/dist/dom/canvas/index.js.map +1 -10
- package/dist/dom/components/app.js +16 -63
- package/dist/dom/components/app.js.map +1 -10
- package/dist/dom/components/audio.js +31 -76
- package/dist/dom/components/audio.js.map +1 -10
- package/dist/dom/components/avatar.js +41 -87
- package/dist/dom/components/avatar.js.map +1 -10
- package/dist/dom/components/badge.js +35 -83
- package/dist/dom/components/badge.js.map +1 -10
- package/dist/dom/components/button.js +26 -69
- package/dist/dom/components/button.js.map +1 -10
- package/dist/dom/components/card.js +13 -63
- package/dist/dom/components/card.js.map +1 -10
- package/dist/dom/components/center.js +21 -65
- package/dist/dom/components/center.js.map +1 -10
- package/dist/dom/components/checkbox.js +37 -82
- package/dist/dom/components/checkbox.js.map +1 -10
- package/dist/dom/components/column.js +16 -62
- package/dist/dom/components/column.js.map +1 -10
- package/dist/dom/components/container.js +11 -59
- package/dist/dom/components/container.js.map +1 -10
- package/dist/dom/components/divider.js +27 -73
- package/dist/dom/components/divider.js.map +1 -10
- package/dist/dom/components/grid.js +41 -80
- package/dist/dom/components/grid.js.map +1 -10
- package/dist/dom/components/heading.js +28 -74
- package/dist/dom/components/heading.js.map +1 -10
- package/dist/dom/components/hypenapp.js +291 -288
- package/dist/dom/components/hypenapp.js.map +1 -10
- package/dist/dom/components/image.js +18 -67
- package/dist/dom/components/image.js.map +1 -10
- package/dist/dom/components/index.js +109 -1427
- package/dist/dom/components/index.js.map +1 -42
- package/dist/dom/components/input.js +19 -69
- package/dist/dom/components/input.js.map +1 -10
- package/dist/dom/components/link.js +23 -70
- package/dist/dom/components/link.js.map +1 -10
- package/dist/dom/components/list.js +26 -72
- package/dist/dom/components/list.js.map +1 -10
- package/dist/dom/components/paragraph.js +14 -63
- package/dist/dom/components/paragraph.js.map +1 -10
- package/dist/dom/components/progressbar.js +38 -85
- package/dist/dom/components/progressbar.js.map +1 -10
- package/dist/dom/components/route.js +27 -73
- package/dist/dom/components/route.js.map +1 -10
- package/dist/dom/components/router.js +15 -62
- package/dist/dom/components/router.js.map +1 -10
- package/dist/dom/components/row.js +25 -70
- package/dist/dom/components/row.js.map +1 -10
- package/dist/dom/components/select.js +42 -85
- package/dist/dom/components/select.js.map +1 -10
- package/dist/dom/components/slider.js +31 -76
- package/dist/dom/components/slider.js.map +1 -10
- package/dist/dom/components/spacer.js +10 -60
- package/dist/dom/components/spacer.js.map +1 -10
- package/dist/dom/components/spinner.js +41 -88
- package/dist/dom/components/spinner.js.map +1 -10
- package/dist/dom/components/stack.js +19 -67
- package/dist/dom/components/stack.js.map +1 -10
- package/dist/dom/components/switch.js +50 -93
- package/dist/dom/components/switch.js.map +1 -10
- package/dist/dom/components/text.js +24 -69
- package/dist/dom/components/text.js.map +1 -10
- package/dist/dom/components/textarea.js +35 -79
- package/dist/dom/components/textarea.js.map +1 -10
- package/dist/dom/components/video.js +35 -79
- package/dist/dom/components/video.js.map +1 -10
- package/dist/dom/debug.js +159 -160
- package/dist/dom/debug.js.map +1 -10
- package/dist/dom/element-data.js +181 -143
- package/dist/dom/element-data.js.map +1 -10
- package/dist/dom/events.js +133 -142
- package/dist/dom/events.js.map +1 -10
- package/dist/dom/index.js +11 -48
- package/dist/dom/index.js.map +1 -9
- package/dist/dom/renderer.js +311 -3596
- package/dist/dom/renderer.js.map +1 -62
- package/dist/hypen.js +385 -3880
- package/dist/hypen.js.map +1 -63
- package/dist/index.js +36 -53
- package/dist/index.js.map +1 -9
- package/package.json +2 -2
package/dist/canvas/events.js
CHANGED
|
@@ -1,378 +1,282 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var __export = (target, all) => {
|
|
30
|
-
for (var name in all)
|
|
31
|
-
__defProp(target, name, {
|
|
32
|
-
get: all[name],
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
set: __exportSetter.bind(all, name)
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
39
|
-
|
|
40
|
-
// src/canvas/utils.ts
|
|
41
|
-
function parseSpacing(value) {
|
|
42
|
-
if (typeof value === "number") {
|
|
43
|
-
return { top: value, right: value, bottom: value, left: value };
|
|
44
|
-
}
|
|
45
|
-
if (typeof value === "string") {
|
|
46
|
-
const parts = value.split(/\s+/).map((v) => parseFloat(v) || 0);
|
|
47
|
-
if (parts.length === 1) {
|
|
48
|
-
return { top: parts[0], right: parts[0], bottom: parts[0], left: parts[0] };
|
|
1
|
+
/**
|
|
2
|
+
* Event System
|
|
3
|
+
*
|
|
4
|
+
* Hit testing and event handling for canvas nodes
|
|
5
|
+
*/
|
|
6
|
+
import { isPointInRoundedRect, getAbsoluteBounds } from "./utils.js";
|
|
7
|
+
/**
|
|
8
|
+
* Canvas Event Manager
|
|
9
|
+
*/
|
|
10
|
+
export class CanvasEventManager {
|
|
11
|
+
canvas;
|
|
12
|
+
engine;
|
|
13
|
+
rootNode = null;
|
|
14
|
+
hoveredNode = null;
|
|
15
|
+
focusedNode = null;
|
|
16
|
+
mouseDownNode = null;
|
|
17
|
+
// Bound handler references for cleanup
|
|
18
|
+
boundOnMouseMove;
|
|
19
|
+
boundOnMouseDown;
|
|
20
|
+
boundOnMouseUp;
|
|
21
|
+
boundOnClick;
|
|
22
|
+
boundOnDoubleClick;
|
|
23
|
+
boundOnKeyDown;
|
|
24
|
+
boundOnKeyUp;
|
|
25
|
+
constructor(canvas, engine) {
|
|
26
|
+
this.canvas = canvas;
|
|
27
|
+
this.engine = engine;
|
|
28
|
+
this.setupEventListeners();
|
|
49
29
|
}
|
|
50
|
-
|
|
51
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Set the root node for hit testing
|
|
32
|
+
*/
|
|
33
|
+
setRootNode(node) {
|
|
34
|
+
this.rootNode = node;
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Setup canvas event listeners
|
|
38
|
+
*/
|
|
39
|
+
setupEventListeners() {
|
|
40
|
+
this.boundOnMouseMove = this.onMouseMove.bind(this);
|
|
41
|
+
this.boundOnMouseDown = this.onMouseDown.bind(this);
|
|
42
|
+
this.boundOnMouseUp = this.onMouseUp.bind(this);
|
|
43
|
+
this.boundOnClick = this.onClick.bind(this);
|
|
44
|
+
this.boundOnDoubleClick = this.onDoubleClick.bind(this);
|
|
45
|
+
this.boundOnKeyDown = this.onKeyDown.bind(this);
|
|
46
|
+
this.boundOnKeyUp = this.onKeyUp.bind(this);
|
|
47
|
+
this.canvas.addEventListener("mousemove", this.boundOnMouseMove);
|
|
48
|
+
this.canvas.addEventListener("mousedown", this.boundOnMouseDown);
|
|
49
|
+
this.canvas.addEventListener("mouseup", this.boundOnMouseUp);
|
|
50
|
+
this.canvas.addEventListener("click", this.boundOnClick);
|
|
51
|
+
this.canvas.addEventListener("dblclick", this.boundOnDoubleClick);
|
|
52
|
+
this.canvas.addEventListener("keydown", this.boundOnKeyDown);
|
|
53
|
+
this.canvas.addEventListener("keyup", this.boundOnKeyUp);
|
|
55
54
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
function isPointInRect(point, rect) {
|
|
79
|
-
return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
|
|
80
|
-
}
|
|
81
|
-
function isPointInRoundedRect(point, rect, radius) {
|
|
82
|
-
const { x, y, width, height } = rect;
|
|
83
|
-
if (!isPointInRect(point, rect))
|
|
84
|
-
return false;
|
|
85
|
-
if (radius <= 0)
|
|
86
|
-
return true;
|
|
87
|
-
const px = point.x;
|
|
88
|
-
const py = point.y;
|
|
89
|
-
if (px < x + radius && py < y + radius) {
|
|
90
|
-
return Math.pow(px - (x + radius), 2) + Math.pow(py - (y + radius), 2) <= Math.pow(radius, 2);
|
|
91
|
-
}
|
|
92
|
-
if (px > x + width - radius && py < y + radius) {
|
|
93
|
-
return Math.pow(px - (x + width - radius), 2) + Math.pow(py - (y + radius), 2) <= Math.pow(radius, 2);
|
|
94
|
-
}
|
|
95
|
-
if (px < x + radius && py > y + height - radius) {
|
|
96
|
-
return Math.pow(px - (x + radius), 2) + Math.pow(py - (y + height - radius), 2) <= Math.pow(radius, 2);
|
|
97
|
-
}
|
|
98
|
-
if (px > x + width - radius && py > y + height - radius) {
|
|
99
|
-
return Math.pow(px - (x + width - radius), 2) + Math.pow(py - (y + height - radius), 2) <= Math.pow(radius, 2);
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
function mergeRects(rects) {
|
|
104
|
-
if (rects.length === 0)
|
|
105
|
-
return null;
|
|
106
|
-
if (rects.length === 1)
|
|
107
|
-
return rects[0];
|
|
108
|
-
let minX = Infinity;
|
|
109
|
-
let minY = Infinity;
|
|
110
|
-
let maxX = -Infinity;
|
|
111
|
-
let maxY = -Infinity;
|
|
112
|
-
for (const rect of rects) {
|
|
113
|
-
minX = Math.min(minX, rect.x);
|
|
114
|
-
minY = Math.min(minY, rect.y);
|
|
115
|
-
maxX = Math.max(maxX, rect.x + rect.width);
|
|
116
|
-
maxY = Math.max(maxY, rect.y + rect.height);
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
x: minX,
|
|
120
|
-
y: minY,
|
|
121
|
-
width: maxX - minX,
|
|
122
|
-
height: maxY - minY
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function createFontString(fontSize, fontWeight, fontFamily) {
|
|
126
|
-
return `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
127
|
-
}
|
|
128
|
-
function walkTree(node, callback) {
|
|
129
|
-
callback(node);
|
|
130
|
-
for (const child of node.children) {
|
|
131
|
-
walkTree(child, callback);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function findNodeById(root, id) {
|
|
135
|
-
if (root.id === id)
|
|
136
|
-
return root;
|
|
137
|
-
for (const child of root.children) {
|
|
138
|
-
const found = findNodeById(child, id);
|
|
139
|
-
if (found)
|
|
140
|
-
return found;
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
function getAbsoluteBounds(node) {
|
|
145
|
-
if (!node.layout)
|
|
146
|
-
return null;
|
|
147
|
-
let x = node.layout.x;
|
|
148
|
-
let y = node.layout.y;
|
|
149
|
-
let current = node.parent;
|
|
150
|
-
while (current && current.layout) {
|
|
151
|
-
x += current.layout.contentX;
|
|
152
|
-
y += current.layout.contentY;
|
|
153
|
-
current = current.parent;
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
x,
|
|
157
|
-
y,
|
|
158
|
-
width: node.layout.width,
|
|
159
|
-
height: node.layout.height
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// src/canvas/events.ts
|
|
164
|
-
class CanvasEventManager {
|
|
165
|
-
canvas;
|
|
166
|
-
engine;
|
|
167
|
-
rootNode = null;
|
|
168
|
-
hoveredNode = null;
|
|
169
|
-
focusedNode = null;
|
|
170
|
-
mouseDownNode = null;
|
|
171
|
-
boundOnMouseMove;
|
|
172
|
-
boundOnMouseDown;
|
|
173
|
-
boundOnMouseUp;
|
|
174
|
-
boundOnClick;
|
|
175
|
-
boundOnDoubleClick;
|
|
176
|
-
boundOnKeyDown;
|
|
177
|
-
boundOnKeyUp;
|
|
178
|
-
constructor(canvas, engine) {
|
|
179
|
-
this.canvas = canvas;
|
|
180
|
-
this.engine = engine;
|
|
181
|
-
this.setupEventListeners();
|
|
182
|
-
}
|
|
183
|
-
setRootNode(node) {
|
|
184
|
-
this.rootNode = node;
|
|
185
|
-
}
|
|
186
|
-
setupEventListeners() {
|
|
187
|
-
this.boundOnMouseMove = this.onMouseMove.bind(this);
|
|
188
|
-
this.boundOnMouseDown = this.onMouseDown.bind(this);
|
|
189
|
-
this.boundOnMouseUp = this.onMouseUp.bind(this);
|
|
190
|
-
this.boundOnClick = this.onClick.bind(this);
|
|
191
|
-
this.boundOnDoubleClick = this.onDoubleClick.bind(this);
|
|
192
|
-
this.boundOnKeyDown = this.onKeyDown.bind(this);
|
|
193
|
-
this.boundOnKeyUp = this.onKeyUp.bind(this);
|
|
194
|
-
this.canvas.addEventListener("mousemove", this.boundOnMouseMove);
|
|
195
|
-
this.canvas.addEventListener("mousedown", this.boundOnMouseDown);
|
|
196
|
-
this.canvas.addEventListener("mouseup", this.boundOnMouseUp);
|
|
197
|
-
this.canvas.addEventListener("click", this.boundOnClick);
|
|
198
|
-
this.canvas.addEventListener("dblclick", this.boundOnDoubleClick);
|
|
199
|
-
this.canvas.addEventListener("keydown", this.boundOnKeyDown);
|
|
200
|
-
this.canvas.addEventListener("keyup", this.boundOnKeyUp);
|
|
201
|
-
}
|
|
202
|
-
getCanvasCoordinates(e) {
|
|
203
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
204
|
-
const scaleX = this.canvas.width / rect.width;
|
|
205
|
-
const scaleY = this.canvas.height / rect.height;
|
|
206
|
-
return {
|
|
207
|
-
x: (e.clientX - rect.left) * scaleX,
|
|
208
|
-
y: (e.clientY - rect.top) * scaleY
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
hitTest(point) {
|
|
212
|
-
if (!this.rootNode)
|
|
213
|
-
return null;
|
|
214
|
-
return this.hitTestNode(this.rootNode, point);
|
|
215
|
-
}
|
|
216
|
-
hitTestNode(node, point) {
|
|
217
|
-
if (!node.visible || !node.layout)
|
|
218
|
-
return null;
|
|
219
|
-
const bounds = getAbsoluteBounds(node);
|
|
220
|
-
if (!bounds)
|
|
221
|
-
return null;
|
|
222
|
-
for (let i = node.children.length - 1;i >= 0; i--) {
|
|
223
|
-
const child = node.children[i];
|
|
224
|
-
const hit = this.hitTestNode(child, point);
|
|
225
|
-
if (hit)
|
|
226
|
-
return hit;
|
|
55
|
+
/**
|
|
56
|
+
* Get canvas coordinates from mouse event
|
|
57
|
+
*/
|
|
58
|
+
getCanvasCoordinates(e) {
|
|
59
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
60
|
+
const scaleX = this.canvas.width / rect.width;
|
|
61
|
+
const scaleY = this.canvas.height / rect.height;
|
|
62
|
+
return {
|
|
63
|
+
x: (e.clientX - rect.left) * scaleX,
|
|
64
|
+
y: (e.clientY - rect.top) * scaleY,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Find node at canvas coordinates
|
|
69
|
+
*/
|
|
70
|
+
hitTest(point) {
|
|
71
|
+
if (!this.rootNode)
|
|
72
|
+
return null;
|
|
73
|
+
return this.hitTestNode(this.rootNode, point);
|
|
227
74
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Recursively test node and children
|
|
77
|
+
*/
|
|
78
|
+
hitTestNode(node, point) {
|
|
79
|
+
if (!node.visible || !node.layout)
|
|
80
|
+
return null;
|
|
81
|
+
const bounds = getAbsoluteBounds(node);
|
|
82
|
+
if (!bounds)
|
|
83
|
+
return null;
|
|
84
|
+
// Test children first (front to back)
|
|
85
|
+
for (let i = node.children.length - 1; i >= 0; i--) {
|
|
86
|
+
const child = node.children[i];
|
|
87
|
+
const hit = this.hitTestNode(child, point);
|
|
88
|
+
if (hit)
|
|
89
|
+
return hit;
|
|
90
|
+
}
|
|
91
|
+
// Test this node
|
|
92
|
+
const radius = node.layout.border.radius;
|
|
93
|
+
if (isPointInRoundedRect(point, bounds, radius)) {
|
|
94
|
+
return node;
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
231
97
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this.hoveredNode
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Handle mouse move
|
|
100
|
+
*/
|
|
101
|
+
onMouseMove(e) {
|
|
102
|
+
const point = this.getCanvasCoordinates(e);
|
|
103
|
+
const node = this.hitTest(point);
|
|
104
|
+
// Update hover state
|
|
105
|
+
if (node !== this.hoveredNode) {
|
|
106
|
+
// Leave old node
|
|
107
|
+
if (this.hoveredNode) {
|
|
108
|
+
this.hoveredNode.hovered = false;
|
|
109
|
+
this.dispatchNodeEvent(this.hoveredNode, "mouseleave", {});
|
|
110
|
+
}
|
|
111
|
+
// Enter new node
|
|
112
|
+
this.hoveredNode = node;
|
|
113
|
+
if (node) {
|
|
114
|
+
node.hovered = true;
|
|
115
|
+
this.dispatchNodeEvent(node, "mouseenter", {});
|
|
116
|
+
}
|
|
117
|
+
// Update cursor
|
|
118
|
+
this.updateCursor(node);
|
|
119
|
+
// Request redraw for hover effects
|
|
120
|
+
this.requestRedraw();
|
|
121
|
+
}
|
|
249
122
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Handle mouse down
|
|
125
|
+
*/
|
|
126
|
+
onMouseDown(e) {
|
|
127
|
+
const point = this.getCanvasCoordinates(e);
|
|
128
|
+
const node = this.hitTest(point);
|
|
129
|
+
this.mouseDownNode = node;
|
|
130
|
+
if (node && node.clickable) {
|
|
131
|
+
this.dispatchNodeEvent(node, "mousedown", {
|
|
132
|
+
button: e.button,
|
|
133
|
+
clientX: e.clientX,
|
|
134
|
+
clientY: e.clientY,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// Update focus
|
|
138
|
+
if (node && node.focusable) {
|
|
139
|
+
this.setFocus(node);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.setFocus(null);
|
|
143
|
+
}
|
|
261
144
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Handle mouse up
|
|
147
|
+
*/
|
|
148
|
+
onMouseUp(e) {
|
|
149
|
+
const point = this.getCanvasCoordinates(e);
|
|
150
|
+
const node = this.hitTest(point);
|
|
151
|
+
if (node && node.clickable) {
|
|
152
|
+
this.dispatchNodeEvent(node, "mouseup", {
|
|
153
|
+
button: e.button,
|
|
154
|
+
clientX: e.clientX,
|
|
155
|
+
clientY: e.clientY,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
this.mouseDownNode = null;
|
|
266
159
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Handle click
|
|
162
|
+
*/
|
|
163
|
+
onClick(e) {
|
|
164
|
+
const point = this.getCanvasCoordinates(e);
|
|
165
|
+
const node = this.hitTest(point);
|
|
166
|
+
if (node && node.clickable && node === this.mouseDownNode) {
|
|
167
|
+
this.dispatchNodeEvent(node, "click", {
|
|
168
|
+
button: e.button,
|
|
169
|
+
clientX: e.clientX,
|
|
170
|
+
clientY: e.clientY,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
277
173
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Handle double click
|
|
176
|
+
*/
|
|
177
|
+
onDoubleClick(e) {
|
|
178
|
+
const point = this.getCanvasCoordinates(e);
|
|
179
|
+
const node = this.hitTest(point);
|
|
180
|
+
if (node && node.clickable) {
|
|
181
|
+
this.dispatchNodeEvent(node, "dblclick", {
|
|
182
|
+
button: e.button,
|
|
183
|
+
clientX: e.clientX,
|
|
184
|
+
clientY: e.clientY,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
289
187
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Handle keyboard events
|
|
190
|
+
*/
|
|
191
|
+
onKeyDown(e) {
|
|
192
|
+
if (this.focusedNode) {
|
|
193
|
+
this.dispatchNodeEvent(this.focusedNode, "keydown", {
|
|
194
|
+
key: e.key,
|
|
195
|
+
code: e.code,
|
|
196
|
+
ctrlKey: e.ctrlKey,
|
|
197
|
+
shiftKey: e.shiftKey,
|
|
198
|
+
altKey: e.altKey,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
300
201
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
202
|
+
onKeyUp(e) {
|
|
203
|
+
if (this.focusedNode) {
|
|
204
|
+
this.dispatchNodeEvent(this.focusedNode, "keyup", {
|
|
205
|
+
key: e.key,
|
|
206
|
+
code: e.code,
|
|
207
|
+
ctrlKey: e.ctrlKey,
|
|
208
|
+
shiftKey: e.shiftKey,
|
|
209
|
+
altKey: e.altKey,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
311
212
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
213
|
+
/**
|
|
214
|
+
* Set focused node
|
|
215
|
+
*/
|
|
216
|
+
setFocus(node) {
|
|
217
|
+
if (node === this.focusedNode)
|
|
218
|
+
return;
|
|
219
|
+
if (this.focusedNode) {
|
|
220
|
+
this.focusedNode.focused = false;
|
|
221
|
+
this.dispatchNodeEvent(this.focusedNode, "blur", {});
|
|
222
|
+
}
|
|
223
|
+
this.focusedNode = node;
|
|
224
|
+
if (node) {
|
|
225
|
+
node.focused = true;
|
|
226
|
+
this.dispatchNodeEvent(node, "focus", {});
|
|
227
|
+
}
|
|
228
|
+
this.requestRedraw();
|
|
322
229
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
230
|
+
/**
|
|
231
|
+
* Update cursor based on node
|
|
232
|
+
*/
|
|
233
|
+
updateCursor(node) {
|
|
234
|
+
if (!node) {
|
|
235
|
+
this.canvas.style.cursor = "default";
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const cursor = node.props.cursor || (node.clickable ? "pointer" : "default");
|
|
239
|
+
this.canvas.style.cursor = cursor;
|
|
330
240
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Dispatch event to engine
|
|
243
|
+
*/
|
|
244
|
+
dispatchNodeEvent(node, eventType, data) {
|
|
245
|
+
// Check if node has action handler for this event
|
|
246
|
+
const actionName = node.props[`on${eventType}`] || node.props[eventType];
|
|
247
|
+
if (actionName && typeof actionName === "string") {
|
|
248
|
+
// Dispatch to engine
|
|
249
|
+
this.engine.dispatchAction(actionName, {
|
|
250
|
+
type: eventType,
|
|
251
|
+
nodeId: node.id,
|
|
252
|
+
timestamp: Date.now(),
|
|
253
|
+
...data,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
335
256
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Request redraw from renderer
|
|
259
|
+
*/
|
|
260
|
+
requestRedraw() {
|
|
261
|
+
// This will be called via a callback set by the renderer
|
|
262
|
+
// For now, dispatch a custom event
|
|
263
|
+
this.canvas.dispatchEvent(new CustomEvent("hypen:redraw"));
|
|
342
264
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Cleanup
|
|
267
|
+
*/
|
|
268
|
+
destroy() {
|
|
269
|
+
this.canvas.removeEventListener("mousemove", this.boundOnMouseMove);
|
|
270
|
+
this.canvas.removeEventListener("mousedown", this.boundOnMouseDown);
|
|
271
|
+
this.canvas.removeEventListener("mouseup", this.boundOnMouseUp);
|
|
272
|
+
this.canvas.removeEventListener("click", this.boundOnClick);
|
|
273
|
+
this.canvas.removeEventListener("dblclick", this.boundOnDoubleClick);
|
|
274
|
+
this.canvas.removeEventListener("keydown", this.boundOnKeyDown);
|
|
275
|
+
this.canvas.removeEventListener("keyup", this.boundOnKeyUp);
|
|
276
|
+
this.rootNode = null;
|
|
277
|
+
this.hoveredNode = null;
|
|
278
|
+
this.focusedNode = null;
|
|
279
|
+
this.mouseDownNode = null;
|
|
355
280
|
}
|
|
356
|
-
}
|
|
357
|
-
requestRedraw() {
|
|
358
|
-
this.canvas.dispatchEvent(new CustomEvent("hypen:redraw"));
|
|
359
|
-
}
|
|
360
|
-
destroy() {
|
|
361
|
-
this.canvas.removeEventListener("mousemove", this.boundOnMouseMove);
|
|
362
|
-
this.canvas.removeEventListener("mousedown", this.boundOnMouseDown);
|
|
363
|
-
this.canvas.removeEventListener("mouseup", this.boundOnMouseUp);
|
|
364
|
-
this.canvas.removeEventListener("click", this.boundOnClick);
|
|
365
|
-
this.canvas.removeEventListener("dblclick", this.boundOnDoubleClick);
|
|
366
|
-
this.canvas.removeEventListener("keydown", this.boundOnKeyDown);
|
|
367
|
-
this.canvas.removeEventListener("keyup", this.boundOnKeyUp);
|
|
368
|
-
this.rootNode = null;
|
|
369
|
-
this.hoveredNode = null;
|
|
370
|
-
this.focusedNode = null;
|
|
371
|
-
this.mouseDownNode = null;
|
|
372
|
-
}
|
|
373
281
|
}
|
|
374
|
-
|
|
375
|
-
CanvasEventManager
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
//# debugId=69654AED1A0C380A64756E2164756E21
|
|
282
|
+
//# sourceMappingURL=events.js.map
|