@hypen-space/web 0.4.35 → 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.
Files changed (139) hide show
  1. package/dist/canvas/accessibility.js +174 -174
  2. package/dist/canvas/accessibility.js.map +1 -10
  3. package/dist/canvas/events.js +264 -360
  4. package/dist/canvas/events.js.map +1 -11
  5. package/dist/canvas/index.js +11 -47
  6. package/dist/canvas/index.js.map +1 -9
  7. package/dist/canvas/input.js +178 -289
  8. package/dist/canvas/input.js.map +1 -11
  9. package/dist/canvas/layout.js +349 -547
  10. package/dist/canvas/layout.js.map +1 -12
  11. package/dist/canvas/paint.js +1122 -1146
  12. package/dist/canvas/paint.js.map +1 -12
  13. package/dist/canvas/renderer.js +352 -2259
  14. package/dist/canvas/renderer.js.map +1 -17
  15. package/dist/canvas/text.js +129 -264
  16. package/dist/canvas/text.js.map +1 -11
  17. package/dist/canvas/types.js +7 -2
  18. package/dist/canvas/types.js.map +1 -9
  19. package/dist/canvas/utils.js +158 -161
  20. package/dist/canvas/utils.js.map +1 -10
  21. package/dist/client.js +19 -45
  22. package/dist/client.js.map +1 -9
  23. package/dist/dom/applicators/advanced-layout.js +105 -138
  24. package/dist/dom/applicators/advanced-layout.js.map +1 -10
  25. package/dist/dom/applicators/background.js +36 -76
  26. package/dist/dom/applicators/background.js.map +1 -10
  27. package/dist/dom/applicators/border.js +82 -106
  28. package/dist/dom/applicators/border.js.map +1 -10
  29. package/dist/dom/applicators/color.js +17 -58
  30. package/dist/dom/applicators/color.js.map +1 -10
  31. package/dist/dom/applicators/display.js +39 -79
  32. package/dist/dom/applicators/display.js.map +1 -10
  33. package/dist/dom/applicators/effects.js +121 -147
  34. package/dist/dom/applicators/effects.js.map +1 -10
  35. package/dist/dom/applicators/events.js +413 -450
  36. package/dist/dom/applicators/events.js.map +1 -11
  37. package/dist/dom/applicators/font.js +119 -140
  38. package/dist/dom/applicators/font.js.map +1 -10
  39. package/dist/dom/applicators/index.js +386 -1770
  40. package/dist/dom/applicators/index.js.map +1 -26
  41. package/dist/dom/applicators/layout.js +143 -149
  42. package/dist/dom/applicators/layout.js.map +1 -10
  43. package/dist/dom/applicators/margin.js +64 -105
  44. package/dist/dom/applicators/margin.js.map +1 -10
  45. package/dist/dom/applicators/padding.js +64 -105
  46. package/dist/dom/applicators/padding.js.map +1 -10
  47. package/dist/dom/applicators/size.js +169 -172
  48. package/dist/dom/applicators/size.js.map +1 -10
  49. package/dist/dom/applicators/transform.js +73 -114
  50. package/dist/dom/applicators/transform.js.map +1 -10
  51. package/dist/dom/applicators/transition.js +47 -88
  52. package/dist/dom/applicators/transition.js.map +1 -10
  53. package/dist/dom/applicators/types.js +7 -2
  54. package/dist/dom/applicators/types.js.map +1 -9
  55. package/dist/dom/applicators/typography.js +68 -109
  56. package/dist/dom/applicators/typography.js.map +1 -10
  57. package/dist/dom/canvas/index.js +49 -83
  58. package/dist/dom/canvas/index.js.map +1 -10
  59. package/dist/dom/components/app.js +16 -63
  60. package/dist/dom/components/app.js.map +1 -10
  61. package/dist/dom/components/audio.js +31 -76
  62. package/dist/dom/components/audio.js.map +1 -10
  63. package/dist/dom/components/avatar.js +41 -87
  64. package/dist/dom/components/avatar.js.map +1 -10
  65. package/dist/dom/components/badge.js +35 -83
  66. package/dist/dom/components/badge.js.map +1 -10
  67. package/dist/dom/components/button.js +26 -69
  68. package/dist/dom/components/button.js.map +1 -10
  69. package/dist/dom/components/card.js +13 -63
  70. package/dist/dom/components/card.js.map +1 -10
  71. package/dist/dom/components/center.js +21 -65
  72. package/dist/dom/components/center.js.map +1 -10
  73. package/dist/dom/components/checkbox.js +37 -82
  74. package/dist/dom/components/checkbox.js.map +1 -10
  75. package/dist/dom/components/column.js +16 -62
  76. package/dist/dom/components/column.js.map +1 -10
  77. package/dist/dom/components/container.js +11 -59
  78. package/dist/dom/components/container.js.map +1 -10
  79. package/dist/dom/components/divider.js +27 -73
  80. package/dist/dom/components/divider.js.map +1 -10
  81. package/dist/dom/components/grid.js +41 -80
  82. package/dist/dom/components/grid.js.map +1 -10
  83. package/dist/dom/components/heading.js +28 -74
  84. package/dist/dom/components/heading.js.map +1 -10
  85. package/dist/dom/components/hypenapp.js +291 -288
  86. package/dist/dom/components/hypenapp.js.map +1 -10
  87. package/dist/dom/components/image.js +18 -67
  88. package/dist/dom/components/image.js.map +1 -10
  89. package/dist/dom/components/index.js +109 -1427
  90. package/dist/dom/components/index.js.map +1 -42
  91. package/dist/dom/components/input.js +19 -69
  92. package/dist/dom/components/input.js.map +1 -10
  93. package/dist/dom/components/link.js +23 -70
  94. package/dist/dom/components/link.js.map +1 -10
  95. package/dist/dom/components/list.js +26 -72
  96. package/dist/dom/components/list.js.map +1 -10
  97. package/dist/dom/components/paragraph.js +14 -63
  98. package/dist/dom/components/paragraph.js.map +1 -10
  99. package/dist/dom/components/progressbar.js +38 -85
  100. package/dist/dom/components/progressbar.js.map +1 -10
  101. package/dist/dom/components/route.js +27 -73
  102. package/dist/dom/components/route.js.map +1 -10
  103. package/dist/dom/components/router.js +15 -62
  104. package/dist/dom/components/router.js.map +1 -10
  105. package/dist/dom/components/row.js +25 -70
  106. package/dist/dom/components/row.js.map +1 -10
  107. package/dist/dom/components/select.js +42 -85
  108. package/dist/dom/components/select.js.map +1 -10
  109. package/dist/dom/components/slider.js +31 -76
  110. package/dist/dom/components/slider.js.map +1 -10
  111. package/dist/dom/components/spacer.js +10 -60
  112. package/dist/dom/components/spacer.js.map +1 -10
  113. package/dist/dom/components/spinner.js +41 -88
  114. package/dist/dom/components/spinner.js.map +1 -10
  115. package/dist/dom/components/stack.js +19 -67
  116. package/dist/dom/components/stack.js.map +1 -10
  117. package/dist/dom/components/switch.js +50 -93
  118. package/dist/dom/components/switch.js.map +1 -10
  119. package/dist/dom/components/text.js +24 -69
  120. package/dist/dom/components/text.js.map +1 -10
  121. package/dist/dom/components/textarea.js +35 -79
  122. package/dist/dom/components/textarea.js.map +1 -10
  123. package/dist/dom/components/video.js +35 -79
  124. package/dist/dom/components/video.js.map +1 -10
  125. package/dist/dom/debug.js +159 -160
  126. package/dist/dom/debug.js.map +1 -10
  127. package/dist/dom/element-data.js +181 -143
  128. package/dist/dom/element-data.js.map +1 -10
  129. package/dist/dom/events.js +133 -142
  130. package/dist/dom/events.js.map +1 -10
  131. package/dist/dom/index.js +11 -48
  132. package/dist/dom/index.js.map +1 -9
  133. package/dist/dom/renderer.js +311 -3596
  134. package/dist/dom/renderer.js.map +1 -62
  135. package/dist/hypen.js +385 -3880
  136. package/dist/hypen.js.map +1 -63
  137. package/dist/index.js +36 -53
  138. package/dist/index.js.map +1 -9
  139. package/package.json +2 -2
@@ -1,378 +1,282 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- function __accessProp(key) {
6
- return this[key];
7
- }
8
- var __toCommonJS = (from) => {
9
- var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
- if (entry)
11
- return entry;
12
- entry = __defProp({}, "__esModule", { value: true });
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (var key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(entry, key))
16
- __defProp(entry, key, {
17
- get: __accessProp.bind(from, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
20
- }
21
- __moduleCache.set(from, entry);
22
- return entry;
23
- };
24
- var __moduleCache;
25
- var __returnValue = (v) => v;
26
- function __exportSetter(name, newValue) {
27
- this[name] = __returnValue.bind(null, newValue);
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
- if (parts.length === 2) {
51
- return { top: parts[0], right: parts[1], bottom: parts[0], left: parts[1] };
30
+ /**
31
+ * Set the root node for hit testing
32
+ */
33
+ setRootNode(node) {
34
+ this.rootNode = node;
52
35
  }
53
- if (parts.length === 4) {
54
- return { top: parts[0], right: parts[1], bottom: parts[2], left: parts[3] };
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
- if (typeof value === "object" && value !== null) {
58
- return {
59
- top: parseFloat(value.top) || 0,
60
- right: parseFloat(value.right) || 0,
61
- bottom: parseFloat(value.bottom) || 0,
62
- left: parseFloat(value.left) || 0
63
- };
64
- }
65
- return { top: 0, right: 0, bottom: 0, left: 0 };
66
- }
67
- function parseSize(value) {
68
- if (typeof value === "number")
69
- return value;
70
- if (typeof value === "string") {
71
- if (value === "auto")
72
- return null;
73
- const num = parseFloat(value);
74
- return isNaN(num) ? null : num;
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
- const radius = node.layout.border.radius;
229
- if (isPointInRoundedRect(point, bounds, radius)) {
230
- return node;
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
- return null;
233
- }
234
- onMouseMove(e) {
235
- const point = this.getCanvasCoordinates(e);
236
- const node = this.hitTest(point);
237
- if (node !== this.hoveredNode) {
238
- if (this.hoveredNode) {
239
- this.hoveredNode.hovered = false;
240
- this.dispatchNodeEvent(this.hoveredNode, "mouseleave", {});
241
- }
242
- this.hoveredNode = node;
243
- if (node) {
244
- node.hovered = true;
245
- this.dispatchNodeEvent(node, "mouseenter", {});
246
- }
247
- this.updateCursor(node);
248
- this.requestRedraw();
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
- onMouseDown(e) {
252
- const point = this.getCanvasCoordinates(e);
253
- const node = this.hitTest(point);
254
- this.mouseDownNode = node;
255
- if (node && node.clickable) {
256
- this.dispatchNodeEvent(node, "mousedown", {
257
- button: e.button,
258
- clientX: e.clientX,
259
- clientY: e.clientY
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
- if (node && node.focusable) {
263
- this.setFocus(node);
264
- } else {
265
- this.setFocus(null);
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
- onMouseUp(e) {
269
- const point = this.getCanvasCoordinates(e);
270
- const node = this.hitTest(point);
271
- if (node && node.clickable) {
272
- this.dispatchNodeEvent(node, "mouseup", {
273
- button: e.button,
274
- clientX: e.clientX,
275
- clientY: e.clientY
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
- this.mouseDownNode = null;
279
- }
280
- onClick(e) {
281
- const point = this.getCanvasCoordinates(e);
282
- const node = this.hitTest(point);
283
- if (node && node.clickable && node === this.mouseDownNode) {
284
- this.dispatchNodeEvent(node, "click", {
285
- button: e.button,
286
- clientX: e.clientX,
287
- clientY: e.clientY
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
- onDoubleClick(e) {
292
- const point = this.getCanvasCoordinates(e);
293
- const node = this.hitTest(point);
294
- if (node && node.clickable) {
295
- this.dispatchNodeEvent(node, "dblclick", {
296
- button: e.button,
297
- clientX: e.clientX,
298
- clientY: e.clientY
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
- onKeyDown(e) {
303
- if (this.focusedNode) {
304
- this.dispatchNodeEvent(this.focusedNode, "keydown", {
305
- key: e.key,
306
- code: e.code,
307
- ctrlKey: e.ctrlKey,
308
- shiftKey: e.shiftKey,
309
- altKey: e.altKey
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
- onKeyUp(e) {
314
- if (this.focusedNode) {
315
- this.dispatchNodeEvent(this.focusedNode, "keyup", {
316
- key: e.key,
317
- code: e.code,
318
- ctrlKey: e.ctrlKey,
319
- shiftKey: e.shiftKey,
320
- altKey: e.altKey
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
- setFocus(node) {
325
- if (node === this.focusedNode)
326
- return;
327
- if (this.focusedNode) {
328
- this.focusedNode.focused = false;
329
- this.dispatchNodeEvent(this.focusedNode, "blur", {});
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
- this.focusedNode = node;
332
- if (node) {
333
- node.focused = true;
334
- this.dispatchNodeEvent(node, "focus", {});
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
- this.requestRedraw();
337
- }
338
- updateCursor(node) {
339
- if (!node) {
340
- this.canvas.style.cursor = "default";
341
- return;
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
- const cursor = node.props.cursor || (node.clickable ? "pointer" : "default");
344
- this.canvas.style.cursor = cursor;
345
- }
346
- dispatchNodeEvent(node, eventType, data) {
347
- const actionName = node.props[`on${eventType}`] || node.props[eventType];
348
- if (actionName && typeof actionName === "string") {
349
- this.engine.dispatchAction(actionName, {
350
- type: eventType,
351
- nodeId: node.id,
352
- timestamp: Date.now(),
353
- ...data
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
- export {
375
- CanvasEventManager
376
- };
377
-
378
- //# debugId=69654AED1A0C380A64756E2164756E21
282
+ //# sourceMappingURL=events.js.map