@web-canvas-ui/react 0.0.0-stage → 0.1.2

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 (98) hide show
  1. package/Canvas.tsx +142 -0
  2. package/README.md +988 -2
  3. package/__tests__/pure-logic.test.ts +153 -0
  4. package/__tests__/scene-and-node.test.ts +131 -0
  5. package/__tests__/scratch-space.test.ts +30 -0
  6. package/__tests__/textarea-caret.test.ts +96 -0
  7. package/__tests__/utils.test.ts +114 -0
  8. package/canvas-handle.ts +114 -0
  9. package/components/Button/button.ts +57 -0
  10. package/components/Button/index.ts +3 -0
  11. package/components/Button/logic.ts +11 -0
  12. package/components/CanvasView/canvasView.ts +103 -0
  13. package/components/CanvasView/index.ts +7 -0
  14. package/components/Carousel/carousel.ts +107 -0
  15. package/components/Carousel/index.ts +3 -0
  16. package/components/Carousel/logic.ts +36 -0
  17. package/components/Checkbox/checkbox.ts +14 -0
  18. package/components/Checkbox/index.ts +2 -0
  19. package/components/ChoiceGroup/choiceGroup.ts +172 -0
  20. package/components/ChoiceGroup/index.ts +3 -0
  21. package/components/ChoiceGroup/logic.ts +14 -0
  22. package/components/Circle/circle.ts +31 -0
  23. package/components/Circle/index.ts +2 -0
  24. package/components/Collapse/collapse.ts +69 -0
  25. package/components/Collapse/index.ts +3 -0
  26. package/components/Collapse/logic.ts +14 -0
  27. package/components/CustomDraw/customDraw.ts +50 -0
  28. package/components/CustomDraw/index.ts +7 -0
  29. package/components/DatePicker/datePicker.ts +70 -0
  30. package/components/DatePicker/index.ts +2 -0
  31. package/components/Dialog/dialog.ts +102 -0
  32. package/components/Dialog/index.ts +2 -0
  33. package/components/Dropdown/dropdown.ts +125 -0
  34. package/components/Dropdown/index.ts +3 -0
  35. package/components/Dropdown/logic.ts +29 -0
  36. package/components/Grid/grid.ts +15 -0
  37. package/components/Grid/index.ts +2 -0
  38. package/components/GridItem/gridItem.ts +11 -0
  39. package/components/GridItem/index.ts +2 -0
  40. package/components/Group/group.ts +8 -0
  41. package/components/Group/index.ts +2 -0
  42. package/components/Icon/icon.ts +669 -0
  43. package/components/Icon/index.ts +2 -0
  44. package/components/Image/image.ts +69 -0
  45. package/components/Image/index.ts +2 -0
  46. package/components/Input/index.ts +2 -0
  47. package/components/Input/input.ts +139 -0
  48. package/components/Progress/index.ts +2 -0
  49. package/components/Progress/progress.ts +59 -0
  50. package/components/Radio/index.ts +2 -0
  51. package/components/Radio/radio.ts +14 -0
  52. package/components/Rect/index.ts +2 -0
  53. package/components/Rect/rect.ts +35 -0
  54. package/components/Slider/index.ts +3 -0
  55. package/components/Slider/logic.ts +19 -0
  56. package/components/Slider/slider.ts +58 -0
  57. package/components/Switch/index.ts +3 -0
  58. package/components/Switch/logic.ts +8 -0
  59. package/components/Switch/switch.ts +37 -0
  60. package/components/Tabs/index.ts +3 -0
  61. package/components/Tabs/logic.ts +14 -0
  62. package/components/Tabs/tabs.ts +78 -0
  63. package/components/Text/index.ts +2 -0
  64. package/components/Text/text.ts +95 -0
  65. package/components/Textarea/index.ts +2 -0
  66. package/components/Textarea/textarea.ts +16 -0
  67. package/components/Upload/index.ts +2 -0
  68. package/components/Upload/upload.ts +66 -0
  69. package/components/draw-utils.ts +230 -0
  70. package/components/shared.ts +15 -0
  71. package/components/size.ts +20 -0
  72. package/components/types.ts +37 -0
  73. package/components.ts +98 -0
  74. package/engine/__tests__/carousel.test.ts +218 -0
  75. package/engine/__tests__/hit-test.test.ts +282 -0
  76. package/engine/__tests__/layout.test.ts +474 -0
  77. package/engine/carousel.ts +150 -0
  78. package/engine/events.ts +73 -0
  79. package/engine/hit-test.ts +321 -0
  80. package/engine/images.ts +41 -0
  81. package/engine/interaction.ts +442 -0
  82. package/engine/layout.ts +355 -0
  83. package/engine/nodes.ts +166 -0
  84. package/engine/state.ts +75 -0
  85. package/engine/text-controls.ts +122 -0
  86. package/engine/transform.ts +61 -0
  87. package/engine/vnodes.ts +204 -0
  88. package/engine.ts +162 -0
  89. package/image-assets.ts +37 -0
  90. package/index.ts +78 -0
  91. package/input-bridge.ts +285 -0
  92. package/package.json +27 -4
  93. package/renderer.ts +303 -0
  94. package/scene.ts +122 -0
  95. package/theme.css +327 -0
  96. package/theme.scss +234 -0
  97. package/types.ts +256 -0
  98. package/web-canvas-ui-react-0.1.1.tgz +0 -0
@@ -0,0 +1,218 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { SceneNode } from '../../scene';
3
+ import { advanceCarousels, changeCarousel, transitionProgress } from '../carousel';
4
+ import { EngineState } from '../state';
5
+ import type { CarouselTransition, EngineCore } from '../state';
6
+
7
+ // --- fixtures ---------------------------------------------------------------
8
+
9
+ function makeCore(scene: SceneNode): EngineCore {
10
+ // The carousel helpers only touch `scene` (traverse); text-control visibility
11
+ // is exercised with an empty overlay map, so the bridge is never called.
12
+ return { scene, inputBridge: {} } as unknown as EngineCore;
13
+ }
14
+
15
+ function carouselFixture(
16
+ carouselProps: Record<string, unknown> = {},
17
+ itemCount = 2,
18
+ ): { scene: SceneNode; carousel: SceneNode; items: SceneNode[] } {
19
+ const scene = new SceneNode('root');
20
+ const carousel = new SceneNode('carousel', { _stateKey: 'c1', ...carouselProps });
21
+ carousel.parent = scene;
22
+ scene.children.push(carousel);
23
+ const items: SceneNode[] = [];
24
+ for (let index = 0; index < itemCount; index++) {
25
+ const item = new SceneNode('carouselItem', {});
26
+ item.parent = carousel;
27
+ carousel.children.push(item);
28
+ items.push(item);
29
+ }
30
+ return { scene, carousel, items };
31
+ }
32
+
33
+ const transition = (over: Partial<CarouselTransition> = {}): CarouselTransition => ({
34
+ from: 0,
35
+ to: 1,
36
+ direction: 1,
37
+ startedAt: 0,
38
+ duration: 100,
39
+ ...over,
40
+ });
41
+
42
+ // --- transitionProgress -----------------------------------------------------
43
+
44
+ describe('transitionProgress', () => {
45
+ it('reports 1 immediately for a zero-duration transition', () => {
46
+ expect(transitionProgress(transition({ duration: 0 }), 999)).toBe(1);
47
+ });
48
+
49
+ it('clamps elapsed fraction into [0, 1]', () => {
50
+ const t = transition({ startedAt: 100, duration: 200 });
51
+ expect(transitionProgress(t, 100)).toBe(0);
52
+ expect(transitionProgress(t, 200)).toBe(0.5);
53
+ expect(transitionProgress(t, 300)).toBe(1);
54
+ expect(transitionProgress(t, 50)).toBe(0); // before start → 0
55
+ expect(transitionProgress(t, 500)).toBe(1); // after end → 1
56
+ });
57
+ });
58
+
59
+ // --- changeCarousel ---------------------------------------------------------
60
+
61
+ describe('changeCarousel', () => {
62
+ it('starts an eased transition and records the pending state', () => {
63
+ const state = new EngineState();
64
+ state.currentFrameTime = 1000;
65
+ const seen: number[] = [];
66
+ const { core, carousel } = (() => {
67
+ const f = carouselFixture({
68
+ width: 300,
69
+ _activeIndex: 0,
70
+ onChange: (i: number) => seen.push(i),
71
+ });
72
+ return { core: makeCore(f.scene), carousel: f.carousel };
73
+ })();
74
+
75
+ changeCarousel(core, state, carousel, 1);
76
+
77
+ expect(carousel.props._activeIndex).toBe(1);
78
+ expect(carousel.props._transitionProgress).toBe(0);
79
+ expect(state.carouselTransitions.has('c1')).toBe(true);
80
+ expect(state.carouselFrameTimes.get('c1')).toBe(1000);
81
+ expect(state.carouselSelections.get('c1')).toBe(1);
82
+ expect(seen).toEqual([1]);
83
+ });
84
+
85
+ it('applies an instant change when the transition duration is 0', () => {
86
+ const state = new EngineState();
87
+ const seen: number[] = [];
88
+ const { scene, carousel, items } = carouselFixture({
89
+ transitionDuration: 0,
90
+ _activeIndex: 0,
91
+ onChange: (i: number) => seen.push(i),
92
+ });
93
+ carousel.setProps({ visible: true });
94
+
95
+ changeCarousel(makeCore(scene), state, carousel, 1);
96
+
97
+ expect(carousel.props._activeIndex).toBe(1);
98
+ expect(state.carouselTransitions.has('c1')).toBe(false);
99
+ expect(items[0].props.visible).toBe(false);
100
+ expect(items[1].props.visible).toBe(true);
101
+ expect(seen).toEqual([1]);
102
+ });
103
+
104
+ it('is a no-op when the resolved index equals the current one', () => {
105
+ const state = new EngineState();
106
+ const seen: number[] = [];
107
+ const { scene, carousel } = carouselFixture({
108
+ _activeIndex: 1,
109
+ onChange: (i: number) => seen.push(i),
110
+ });
111
+
112
+ changeCarousel(makeCore(scene), state, carousel, 1);
113
+
114
+ expect(seen).toEqual([]);
115
+ expect(state.carouselTransitions.has('c1')).toBe(false);
116
+ });
117
+
118
+ it('is a no-op while a transition for the node is already running', () => {
119
+ const state = new EngineState();
120
+ state.carouselTransitions.set('c1', transition());
121
+ const seen: number[] = [];
122
+ const { scene, carousel } = carouselFixture({
123
+ _activeIndex: 0,
124
+ onChange: (i: number) => seen.push(i),
125
+ });
126
+
127
+ changeCarousel(makeCore(scene), state, carousel, 1);
128
+
129
+ expect(carousel.props._activeIndex).toBe(0);
130
+ expect(seen).toEqual([]);
131
+ });
132
+
133
+ it('is a no-op for an empty carousel', () => {
134
+ const state = new EngineState();
135
+ const seen: number[] = [];
136
+ const { scene, carousel } = carouselFixture({ onChange: (i: number) => seen.push(i) }, 0);
137
+
138
+ changeCarousel(makeCore(scene), state, carousel, 1);
139
+
140
+ expect(seen).toEqual([]);
141
+ });
142
+ });
143
+
144
+ // --- advanceCarousels -------------------------------------------------------
145
+
146
+ describe('advanceCarousels', () => {
147
+ it('seeds the frame clock then auto-advances past the interval', () => {
148
+ const state = new EngineState();
149
+ const { scene, carousel } = carouselFixture({ interval: 100, _activeIndex: 0 });
150
+ const core = makeCore(scene);
151
+
152
+ advanceCarousels(core, state, 0);
153
+ expect(state.carouselFrameTimes.get('c1')).toBe(0);
154
+ expect(carousel.props._activeIndex).toBe(0);
155
+
156
+ // interval is floored at 250ms, so 300ms elapsed triggers a change.
157
+ advanceCarousels(core, state, 300);
158
+ expect(state.currentFrameTime).toBe(300);
159
+ expect(carousel.props._activeIndex).toBe(1);
160
+ });
161
+
162
+ it('does not advance before the interval elapses', () => {
163
+ const state = new EngineState();
164
+ const { scene, carousel } = carouselFixture({ interval: 1000, _activeIndex: 0 });
165
+ const core = makeCore(scene);
166
+ advanceCarousels(core, state, 0);
167
+ advanceCarousels(core, state, 500);
168
+ expect(carousel.props._activeIndex).toBe(0);
169
+ });
170
+
171
+ it('completes an in-flight transition and clears it', () => {
172
+ const state = new EngineState();
173
+ state.carouselTransitions.set(
174
+ 'c1',
175
+ transition({ from: 0, to: 1, startedAt: 0, duration: 100 }),
176
+ );
177
+ const { scene, carousel } = carouselFixture({ _activeIndex: 1 });
178
+ carousel.setProps({ _transitionProgress: 0.4 });
179
+
180
+ advanceCarousels(makeCore(scene), state, 200);
181
+
182
+ expect(state.carouselTransitions.has('c1')).toBe(false);
183
+ expect(carousel.props._transitionProgress).toBe(1);
184
+ });
185
+
186
+ it('progresses a transition mid-flight without finishing it', () => {
187
+ const state = new EngineState();
188
+ state.carouselTransitions.set('c1', transition({ startedAt: 0, duration: 200 }));
189
+ const { scene, carousel } = carouselFixture();
190
+
191
+ advanceCarousels(makeCore(scene), state, 100);
192
+
193
+ expect(state.carouselTransitions.has('c1')).toBe(true);
194
+ expect(carousel.props._transitionProgress).toBeCloseTo(0.5);
195
+ });
196
+
197
+ it('stops the clock for non-autoplaying carousels', () => {
198
+ const state = new EngineState();
199
+ state.carouselFrameTimes.set('c1', 0);
200
+ const { scene } = carouselFixture({ autoplay: false });
201
+
202
+ advanceCarousels(makeCore(scene), state, 5000);
203
+
204
+ expect(state.carouselFrameTimes.has('c1')).toBe(false);
205
+ });
206
+
207
+ it('prunes timing bookkeeping for carousels that left the tree', () => {
208
+ const state = new EngineState();
209
+ state.carouselFrameTimes.set('gone', 1);
210
+ state.carouselTransitions.set('gone', transition());
211
+ const { scene } = carouselFixture({ interval: 100 });
212
+
213
+ advanceCarousels(makeCore(scene), state, 0);
214
+
215
+ expect(state.carouselFrameTimes.has('gone')).toBe(false);
216
+ expect(state.carouselTransitions.has('gone')).toBe(false);
217
+ });
218
+ });
@@ -0,0 +1,282 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { SceneNode } from '../../scene';
3
+ import {
4
+ canvasPoint,
5
+ findCarouselControlHit,
6
+ findGridScrollbarHit,
7
+ findHit,
8
+ isWithinClip,
9
+ localPoint,
10
+ } from '../hit-test';
11
+ import type { EngineCore } from '../state';
12
+
13
+ // --- fixtures ---------------------------------------------------------------
14
+
15
+ function makeCore(scene: SceneNode, pixelRatio = 1): EngineCore {
16
+ // hit-testing only reads `scene` and `pixelRatio` off the core.
17
+ return { scene, pixelRatio } as unknown as EngineCore;
18
+ }
19
+
20
+ function makeCanvas(width = 200, height = 200, left = 0, top = 0): HTMLCanvasElement {
21
+ return {
22
+ width,
23
+ height,
24
+ getBoundingClientRect: () => ({
25
+ width,
26
+ height,
27
+ left,
28
+ top,
29
+ right: left + width,
30
+ bottom: top + height,
31
+ }),
32
+ } as unknown as HTMLCanvasElement;
33
+ }
34
+
35
+ function link(parent: SceneNode, ...children: SceneNode[]): SceneNode {
36
+ for (const child of children) {
37
+ child.parent = parent;
38
+ parent.children.push(child);
39
+ }
40
+ return parent;
41
+ }
42
+
43
+ function root(): SceneNode {
44
+ return new SceneNode('root');
45
+ }
46
+
47
+ // --- canvasPoint ------------------------------------------------------------
48
+
49
+ describe('canvasPoint', () => {
50
+ it('maps client coordinates 1:1 when the element is unscaled', () => {
51
+ const core = makeCore(root());
52
+ expect(canvasPoint(core, makeCanvas(200, 200, 0, 0), 50, 60)).toEqual({ x: 50, y: 60 });
53
+ });
54
+
55
+ it('accounts for CSS scaling (canvas.width / rect.width)', () => {
56
+ const core = makeCore(root());
57
+ // backing store 400px shown in a 200px CSS box → each CSS px maps to 2.
58
+ const canvas = {
59
+ width: 400,
60
+ height: 400,
61
+ getBoundingClientRect: () => ({
62
+ width: 200,
63
+ height: 200,
64
+ left: 0,
65
+ top: 0,
66
+ right: 200,
67
+ bottom: 200,
68
+ }),
69
+ } as unknown as HTMLCanvasElement;
70
+ expect(canvasPoint(core, canvas, 50, 0)).toEqual({ x: 100, y: 0 });
71
+ });
72
+
73
+ it('divides by the device pixel ratio', () => {
74
+ const core = makeCore(root(), 2);
75
+ expect(canvasPoint(core, makeCanvas(200, 200, 0, 0), 80, 40)).toEqual({ x: 40, y: 20 });
76
+ });
77
+
78
+ it('offsets by the bounding-rect origin', () => {
79
+ const core = makeCore(root());
80
+ expect(canvasPoint(core, makeCanvas(200, 200, 30, 40), 80, 90)).toEqual({ x: 50, y: 50 });
81
+ });
82
+
83
+ it('returns null for a zero-sized element', () => {
84
+ const core = makeCore(root());
85
+ expect(canvasPoint(core, makeCanvas(200, 200, 0, 0), 10, 10)).not.toBeNull();
86
+ const zero = {
87
+ width: 200,
88
+ height: 200,
89
+ getBoundingClientRect: () => ({
90
+ width: 0,
91
+ height: 0,
92
+ left: 0,
93
+ top: 0,
94
+ right: 0,
95
+ bottom: 0,
96
+ }),
97
+ } as unknown as HTMLCanvasElement;
98
+ expect(canvasPoint(core, zero, 10, 10)).toBeNull();
99
+ });
100
+ });
101
+
102
+ // --- localPoint -------------------------------------------------------------
103
+
104
+ describe('localPoint', () => {
105
+ it('inverts the accumulated node transform into local space', () => {
106
+ const scene = root();
107
+ const button = new SceneNode('button', { x: 20, y: 10, width: 100, height: 40 });
108
+ link(scene, button);
109
+ const core = makeCore(scene);
110
+ expect(localPoint(core, makeCanvas(), 30, 15, button)).toEqual({ x: 10, y: 5 });
111
+ });
112
+
113
+ it('returns null when the target is not in the tree', () => {
114
+ const scene = root();
115
+ link(scene, new SceneNode('button', { x: 0, y: 0 }));
116
+ const orphan = new SceneNode('button');
117
+ const core = makeCore(scene);
118
+ expect(localPoint(core, makeCanvas(), 10, 10, orphan)).toBeNull();
119
+ });
120
+ });
121
+
122
+ // --- isWithinClip -----------------------------------------------------------
123
+
124
+ describe('isWithinClip', () => {
125
+ it('clips children to an enclosing scrollable grid', () => {
126
+ const scene = root();
127
+ const grid = new SceneNode('grid', { x: 0, y: 0, width: 100, height: 100 });
128
+ const child = new SceneNode('rect');
129
+ link(scene, grid);
130
+ link(grid, child);
131
+ const core = makeCore(scene);
132
+ expect(isWithinClip(core, makeCanvas(), 50, 50, child)).toBe(true);
133
+ expect(isWithinClip(core, makeCanvas(), 150, 150, child)).toBe(false);
134
+ });
135
+
136
+ it('is always true without grid/carousel ancestors', () => {
137
+ const scene = root();
138
+ const node = new SceneNode('rect');
139
+ link(scene, node);
140
+ const core = makeCore(scene);
141
+ expect(isWithinClip(core, makeCanvas(), 1000, 1000, node)).toBe(true);
142
+ });
143
+ });
144
+
145
+ // --- findHit ----------------------------------------------------------------
146
+
147
+ describe('findHit', () => {
148
+ it('returns the node and local coordinates for a point inside a control', () => {
149
+ const scene = root();
150
+ const button = new SceneNode('button', { x: 10, y: 10, width: 100, height: 40 });
151
+ link(scene, button);
152
+ const core = makeCore(scene);
153
+ expect(findHit(core, makeCanvas(), 20, 20)).toEqual({ node: button, x: 10, y: 10 });
154
+ });
155
+
156
+ it('misses when the point falls outside the control bounds', () => {
157
+ const scene = root();
158
+ link(scene, new SceneNode('button', { x: 10, y: 10, width: 100, height: 40 }));
159
+ const core = makeCore(scene);
160
+ expect(findHit(core, makeCanvas(), 20, 60)).toBeNull();
161
+ });
162
+
163
+ it('ignores invisible nodes', () => {
164
+ const scene = root();
165
+ link(
166
+ scene,
167
+ new SceneNode('button', { x: 0, y: 0, width: 100, height: 40, visible: false }),
168
+ );
169
+ const core = makeCore(scene);
170
+ expect(findHit(core, makeCanvas(), 10, 10)).toBeNull();
171
+ });
172
+
173
+ it('ignores non-interactive nodes such as rect', () => {
174
+ const scene = root();
175
+ link(scene, new SceneNode('rect', { x: 0, y: 0, width: 100, height: 40 }));
176
+ const core = makeCore(scene);
177
+ expect(findHit(core, makeCanvas(), 10, 10)).toBeNull();
178
+ });
179
+
180
+ it('lets an open modal dialog occlude controls outside it', () => {
181
+ const scene = root();
182
+ const button = new SceneNode('button', { x: 0, y: 0, width: 100, height: 40 });
183
+ const dialog = new SceneNode('dialog', { x: 0, y: 0, width: 200, height: 200, open: true });
184
+ link(scene, button, dialog);
185
+ const core = makeCore(scene);
186
+ // Click sits inside the (earlier) button, but the dialog is modal.
187
+ expect(findHit(core, makeCanvas(), 10, 10)?.node.type).toBe('dialog');
188
+ });
189
+ });
190
+
191
+ // --- findGridScrollbarHit ---------------------------------------------------
192
+
193
+ describe('findGridScrollbarHit', () => {
194
+ it('hits the thumb when the grid overflows', () => {
195
+ const scene = root();
196
+ const grid = new SceneNode('grid', {
197
+ x: 0,
198
+ y: 0,
199
+ width: 100,
200
+ height: 100,
201
+ _gridWidth: 100,
202
+ _gridContentHeight: 200,
203
+ _scrollTop: 0,
204
+ });
205
+ link(scene, grid);
206
+ const core = makeCore(scene);
207
+ // track occupies x∈[94,100]; thumb height 50 at scrollTop 0 → y∈[0,50].
208
+ const hit = findGridScrollbarHit(core, makeCanvas(), 97, 10);
209
+ expect(hit?.node).toBe(grid);
210
+ expect(hit?.scrollTop).toBe(0);
211
+ expect(hit?.pointerY).toBe(10);
212
+ });
213
+
214
+ it('returns null when there is nothing to scroll', () => {
215
+ const scene = root();
216
+ const grid = new SceneNode('grid', {
217
+ x: 0,
218
+ y: 0,
219
+ width: 100,
220
+ height: 100,
221
+ _gridWidth: 100,
222
+ _gridContentHeight: 100,
223
+ });
224
+ link(scene, grid);
225
+ const core = makeCore(scene);
226
+ expect(findGridScrollbarHit(core, makeCanvas(), 97, 10)).toBeNull();
227
+ });
228
+ });
229
+
230
+ // --- findCarouselControlHit -------------------------------------------------
231
+
232
+ describe('findCarouselControlHit', () => {
233
+ function carouselScene() {
234
+ const scene = root();
235
+ const carousel = new SceneNode('carousel', {
236
+ x: 0,
237
+ y: 0,
238
+ width: 300,
239
+ height: 180,
240
+ _activeIndex: 0,
241
+ });
242
+ link(scene, carousel);
243
+ link(
244
+ carousel,
245
+ new SceneNode('carouselItem'),
246
+ new SceneNode('carouselItem'),
247
+ new SceneNode('carouselItem'),
248
+ );
249
+ return { scene, carousel };
250
+ }
251
+
252
+ it('maps a left-arrow press to the previous index', () => {
253
+ const { scene, carousel } = carouselScene();
254
+ const core = makeCore(scene);
255
+ // |y - height/2| <= 20 and x <= 42 → previous (0 - 1 = -1).
256
+ expect(findCarouselControlHit(core, makeCanvas(), 10, 90)).toEqual({
257
+ node: carousel,
258
+ index: -1,
259
+ });
260
+ });
261
+
262
+ it('maps a right-arrow press to the next index', () => {
263
+ const { scene, carousel } = carouselScene();
264
+ const core = makeCore(scene);
265
+ // x >= width - 42 → next (0 + 1 = 1).
266
+ expect(findCarouselControlHit(core, makeCanvas(), 295, 90)).toEqual({
267
+ node: carousel,
268
+ index: 1,
269
+ });
270
+ });
271
+
272
+ it('returns null for a press in the carousel body', () => {
273
+ const { scene } = carouselScene();
274
+ const core = makeCore(scene);
275
+ expect(findCarouselControlHit(core, makeCanvas(), 150, 90)).toBeNull();
276
+ });
277
+
278
+ it('returns null when the scene has no carousel', () => {
279
+ const core = makeCore(root());
280
+ expect(findCarouselControlHit(core, makeCanvas(), 150, 90)).toBeNull();
281
+ });
282
+ });