@octane-xplat/charts 0.19.0 → 0.20.0
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 +2 -102
- package/package.json +14 -14
- package/src/Chart.macos.tsrx +248 -246
- package/src/Chart.tsrx +249 -247
- package/src/Chart.web.tsrx +236 -226
- package/src/appkit-pointer.macos.ts +91 -76
- package/src/core/axes.ts +175 -168
- package/src/core/hit.ts +197 -177
- package/src/core/marks.ts +336 -319
- package/src/core/scales.ts +128 -115
- package/src/core/scene.ts +123 -120
- package/src/core/svg.ts +52 -50
- package/src/index.macos.ts +7 -7
- package/src/index.ts +7 -7
- package/src/index.web.ts +7 -7
- package/src/props.ts +83 -83
- package/src/style-merge.ts +40 -37
- package/src/svg-image.macos.ts +21 -20
- package/types/generated/.tsrx-typegen-manifest.json +1 -7
- package/types/generated/Chart.macos.d.ts +0 -7
- package/types/generated/Chart.web.d.ts +0 -10
- package/types/generated/appkit-pointer.macos.d.ts +0 -37
- package/types/generated/index.macos.d.ts +0 -2
- package/types/generated/index.web.d.ts +0 -2
- package/types/generated/svg-image.macos.d.ts +0 -3
package/src/Chart.web.tsrx
CHANGED
|
@@ -17,247 +17,257 @@ const TIP_ESTIMATE_CHAR = 6.2
|
|
|
17
17
|
* the markup. Pointer handlers attach to the plot host so chart coords are
|
|
18
18
|
* client-minus-rect, matching the markup's coordinate space. */
|
|
19
19
|
export function Chart(props: ChartProps): JSX.Element @{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
propsRef.current = props
|
|
25
|
-
const hostRef = useRef<HTMLElement | null>(null)
|
|
20
|
+
const measure = useMeasure()
|
|
21
|
+
const [cursor, setCursor] = useState<SceneHit | null>(null)
|
|
22
|
+
const sceneRef = useRef<ChartScene | null>(null)
|
|
23
|
+
const propsRef = useRef(props)
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
const w = props.width ?? bounds?.width ?? 0
|
|
29
|
-
const h =
|
|
30
|
-
props.height ??
|
|
31
|
-
(props.aspectRatio && w > 0
|
|
32
|
-
? w / props.aspectRatio
|
|
33
|
-
: bounds?.height && bounds.height > 0
|
|
34
|
-
? bounds.height
|
|
35
|
-
: w > 0
|
|
36
|
-
? w / 1.6
|
|
37
|
-
: 0)
|
|
25
|
+
propsRef.current = props
|
|
38
26
|
|
|
39
|
-
|
|
40
|
-
() => (w > 0 && h > 0 ? computeScene(propsRef.current, w, h) : null),
|
|
41
|
-
[
|
|
42
|
-
props.type,
|
|
43
|
-
props.data,
|
|
44
|
-
props.margin,
|
|
45
|
-
props.stacked,
|
|
46
|
-
props.innerRadiusRatio,
|
|
47
|
-
props.xAxis,
|
|
48
|
-
props.yAxis,
|
|
49
|
-
w,
|
|
50
|
-
h,
|
|
51
|
-
],
|
|
52
|
-
)
|
|
27
|
+
const hostRef = useRef<HTMLElement | null>(null)
|
|
53
28
|
|
|
54
|
-
|
|
29
|
+
const bounds = measure.bounds
|
|
30
|
+
const w = props.width ?? bounds?.width ?? 0
|
|
31
|
+
const h =
|
|
32
|
+
props.height ??
|
|
33
|
+
(props.aspectRatio && w > 0
|
|
34
|
+
? w / props.aspectRatio
|
|
35
|
+
: bounds?.height && bounds.height > 0
|
|
36
|
+
? bounds.height
|
|
37
|
+
: w > 0
|
|
38
|
+
? w / 1.6
|
|
39
|
+
: 0)
|
|
55
40
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
41
|
+
const scene = useMemo(
|
|
42
|
+
() => (w > 0 && h > 0 ? computeScene(propsRef.current, w, h) : null),
|
|
43
|
+
[
|
|
44
|
+
props.type,
|
|
45
|
+
props.data,
|
|
46
|
+
props.margin,
|
|
47
|
+
props.stacked,
|
|
48
|
+
props.innerRadiusRatio,
|
|
49
|
+
props.xAxis,
|
|
50
|
+
props.yAxis,
|
|
51
|
+
w,
|
|
52
|
+
h,
|
|
53
|
+
],
|
|
54
|
+
)
|
|
62
55
|
|
|
63
|
-
|
|
64
|
-
() => sceneRef.current,
|
|
65
|
-
() => propsRef.current,
|
|
66
|
-
setCursor,
|
|
67
|
-
)
|
|
56
|
+
sceneRef.current = scene
|
|
68
57
|
|
|
69
|
-
|
|
70
|
-
const rect = el.getBoundingClientRect()
|
|
71
|
-
return { x: e.clientX - rect.left, y: e.clientY - rect.top }
|
|
72
|
-
}
|
|
58
|
+
const interactive = !!(props.onPress || props.onScrub || props.tooltip || props.crosshair)
|
|
73
59
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const p = at(e)
|
|
77
|
-
scrub('down', p.x, p.y)
|
|
78
|
-
}
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const el = hostRef.current
|
|
79
62
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
63
|
+
if (!el || !interactive) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
84
66
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
67
|
+
const scrub = createScrub(
|
|
68
|
+
() => sceneRef.current,
|
|
69
|
+
() => propsRef.current,
|
|
70
|
+
setCursor,
|
|
71
|
+
)
|
|
89
72
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Synthetic clicks carry no pointer position → tap the center.
|
|
93
|
-
const click = (e: MouseEvent) => {
|
|
94
|
-
const p =
|
|
95
|
-
e.clientX === 0 && e.clientY === 0
|
|
96
|
-
? { x: el.getBoundingClientRect().width / 2, y: el.getBoundingClientRect().height / 2 }
|
|
97
|
-
: at(e as PointerEvent)
|
|
73
|
+
const at = (e: PointerEvent) => {
|
|
74
|
+
const rect = el.getBoundingClientRect()
|
|
98
75
|
|
|
99
|
-
|
|
100
|
-
|
|
76
|
+
return { x: e.clientX - rect.left, y: e.clientY - rect.top }
|
|
77
|
+
}
|
|
101
78
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
el.addEventListener('pointerdown', down)
|
|
105
|
-
el.addEventListener('pointermove', move)
|
|
106
|
-
el.addEventListener('pointerup', up)
|
|
107
|
-
el.addEventListener('pointercancel', end)
|
|
108
|
-
el.addEventListener('pointerleave', leave)
|
|
109
|
-
el.addEventListener('click', click)
|
|
110
|
-
return () => {
|
|
111
|
-
el.removeEventListener('pointerdown', down)
|
|
112
|
-
el.removeEventListener('pointermove', move)
|
|
113
|
-
el.removeEventListener('pointerup', up)
|
|
114
|
-
el.removeEventListener('pointercancel', end)
|
|
115
|
-
el.removeEventListener('pointerleave', leave)
|
|
116
|
-
el.removeEventListener('click', click)
|
|
117
|
-
}
|
|
118
|
-
}, [interactive])
|
|
79
|
+
const down = (e: PointerEvent) => {
|
|
80
|
+
el.setPointerCapture?.(e.pointerId)
|
|
119
81
|
|
|
120
|
-
|
|
121
|
-
const plot = scene?.plot
|
|
122
|
-
const dotColor =
|
|
123
|
-
cursor && scene
|
|
124
|
-
? scene.pie
|
|
125
|
-
? scene.pie.slices.find((s) => s.series === cursor.series && s.index === cursor.index)
|
|
126
|
-
?.color
|
|
127
|
-
: scene.series[cursor.series]?.color
|
|
128
|
-
: undefined
|
|
82
|
+
const p = at(e)
|
|
129
83
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const tipLeft =
|
|
133
|
-
cursor && scene
|
|
134
|
-
? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth))
|
|
135
|
-
: 0
|
|
84
|
+
scrub('down', p.x, p.y)
|
|
85
|
+
}
|
|
136
86
|
|
|
137
|
-
|
|
87
|
+
const move = (e: PointerEvent) => {
|
|
88
|
+
const p = at(e)
|
|
138
89
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
style={{
|
|
142
|
-
display: 'flex',
|
|
143
|
-
flexWrap: 'wrap',
|
|
144
|
-
gap: 12,
|
|
145
|
-
paddingTop: position === 'bottom' ? 4 : 0,
|
|
146
|
-
paddingBottom: position === 'top' ? 4 : 0,
|
|
147
|
-
}}
|
|
148
|
-
>
|
|
149
|
-
{items.map((item) => (
|
|
150
|
-
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 4, fontSize: 11 }}>
|
|
151
|
-
<span
|
|
152
|
-
style={{
|
|
153
|
-
width: 10,
|
|
154
|
-
height: 10,
|
|
155
|
-
borderRadius: 2,
|
|
156
|
-
backgroundColor: item.color,
|
|
157
|
-
display: 'inline-block',
|
|
158
|
-
}}
|
|
159
|
-
/>
|
|
160
|
-
{item.text}
|
|
161
|
-
</span>
|
|
162
|
-
))}
|
|
163
|
-
</div>
|
|
164
|
-
)
|
|
90
|
+
scrub(e.buttons !== 0 ? 'move' : 'hover', p.x, p.y)
|
|
91
|
+
}
|
|
165
92
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
93
|
+
const up = (e: PointerEvent) => {
|
|
94
|
+
const p = at(e)
|
|
95
|
+
|
|
96
|
+
scrub('up', p.x, p.y)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// `click` (incl. el.click()/AT activation) is the web 'tap' — onPress
|
|
100
|
+
// lives on tap so a real click after pointerup doesn't double-fire.
|
|
101
|
+
// Synthetic clicks carry no pointer position → tap the center.
|
|
102
|
+
const click = (e: MouseEvent) => {
|
|
103
|
+
const p =
|
|
104
|
+
e.clientX === 0 && e.clientY === 0
|
|
105
|
+
? { x: el.getBoundingClientRect().width / 2, y: el.getBoundingClientRect().height / 2 }
|
|
106
|
+
: at(e as PointerEvent)
|
|
107
|
+
|
|
108
|
+
scrub('tap', p.x, p.y)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const end = () => scrub('cancel', 0, 0)
|
|
112
|
+
const leave = () => scrub('leave', 0, 0)
|
|
113
|
+
|
|
114
|
+
el.addEventListener('pointerdown', down)
|
|
115
|
+
el.addEventListener('pointermove', move)
|
|
116
|
+
el.addEventListener('pointerup', up)
|
|
117
|
+
el.addEventListener('pointercancel', end)
|
|
118
|
+
el.addEventListener('pointerleave', leave)
|
|
119
|
+
el.addEventListener('click', click)
|
|
120
|
+
return () => {
|
|
121
|
+
el.removeEventListener('pointerdown', down)
|
|
122
|
+
el.removeEventListener('pointermove', move)
|
|
123
|
+
el.removeEventListener('pointerup', up)
|
|
124
|
+
el.removeEventListener('pointercancel', end)
|
|
125
|
+
el.removeEventListener('pointerleave', leave)
|
|
126
|
+
el.removeEventListener('click', click)
|
|
127
|
+
}
|
|
128
|
+
}, [interactive])
|
|
129
|
+
|
|
130
|
+
const legend = props.legend === true ? 'bottom' : props.legend
|
|
131
|
+
const plot = scene?.plot
|
|
132
|
+
const dotColor =
|
|
133
|
+
cursor && scene
|
|
134
|
+
? scene.pie
|
|
135
|
+
? scene.pie.slices.find((s) => s.series === cursor.series && s.index === cursor.index)
|
|
136
|
+
?.color
|
|
137
|
+
: scene.series[cursor.series]?.color
|
|
138
|
+
: undefined
|
|
139
|
+
|
|
140
|
+
const tipText = cursor && scene ? hitLabel(scene, cursor) : null
|
|
141
|
+
const tipWidth = tipText ? tipText.length * TIP_ESTIMATE_CHAR + 14 : 0
|
|
142
|
+
const tipLeft =
|
|
143
|
+
cursor && scene
|
|
144
|
+
? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth))
|
|
145
|
+
: 0
|
|
146
|
+
|
|
147
|
+
const tipTop = cursor ? cursor.py - 30 : 0
|
|
148
|
+
|
|
149
|
+
const legendRow = (items: { color: string; text: string }[], position: 'top' | 'bottom') => (
|
|
150
|
+
<div
|
|
151
|
+
style={{
|
|
152
|
+
display: 'flex',
|
|
153
|
+
flexWrap: 'wrap',
|
|
154
|
+
gap: 12,
|
|
155
|
+
paddingTop: position === 'bottom' ? 4 : 0,
|
|
156
|
+
paddingBottom: position === 'top' ? 4 : 0,
|
|
157
|
+
}}
|
|
158
|
+
>
|
|
159
|
+
{items.map((item) => (
|
|
160
|
+
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 4, fontSize: 11 }}>
|
|
161
|
+
<span
|
|
162
|
+
style={{
|
|
163
|
+
width: 10,
|
|
164
|
+
height: 10,
|
|
165
|
+
borderRadius: 2,
|
|
166
|
+
backgroundColor: item.color,
|
|
167
|
+
display: 'inline-block',
|
|
168
|
+
}}
|
|
169
|
+
/>
|
|
170
|
+
{item.text}
|
|
171
|
+
</span>
|
|
172
|
+
))}
|
|
173
|
+
</div>
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
<div
|
|
177
|
+
id={props.id}
|
|
178
|
+
className={props.className}
|
|
179
|
+
style={{
|
|
180
|
+
display: 'flex',
|
|
181
|
+
flexDirection: 'column',
|
|
182
|
+
width: props.width,
|
|
183
|
+
height: props.height,
|
|
184
|
+
...props.style,
|
|
185
|
+
}}
|
|
186
|
+
role={props.accessibilityLabel ? 'img' : undefined}
|
|
187
|
+
aria-label={props.accessibilityLabel}
|
|
188
|
+
>
|
|
189
|
+
{legend === 'top' && scene ? legendRow(scene.legend, 'top') : null}
|
|
190
|
+
<div
|
|
191
|
+
id={props.id ? props.id + '-overlay' : undefined}
|
|
192
|
+
ref={(el: HTMLElement | null) => {
|
|
193
|
+
hostRef.current = el
|
|
194
|
+
measure.ref(el)
|
|
195
|
+
}}
|
|
196
|
+
style={{
|
|
197
|
+
position: 'relative',
|
|
198
|
+
flexGrow: 1,
|
|
199
|
+
minHeight: 0,
|
|
200
|
+
width: props.width,
|
|
201
|
+
height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : undefined),
|
|
202
|
+
}}
|
|
203
|
+
>
|
|
204
|
+
<div dangerouslySetInnerHTML={scene ? { __html: scene.markup } : undefined} />
|
|
205
|
+
<div style={{ position: 'absolute', inset: 0 }}>
|
|
206
|
+
{scene?.labels.map((l) => (
|
|
207
|
+
<div
|
|
208
|
+
style={{
|
|
209
|
+
position: 'absolute',
|
|
210
|
+
left: l.x,
|
|
211
|
+
top: l.y,
|
|
212
|
+
width: l.width,
|
|
213
|
+
fontSize: 10,
|
|
214
|
+
opacity: 0.7,
|
|
215
|
+
textAlign: l.align,
|
|
216
|
+
overflow: 'hidden',
|
|
217
|
+
whiteSpace: 'nowrap',
|
|
218
|
+
textOverflow: 'ellipsis',
|
|
219
|
+
}}
|
|
220
|
+
>
|
|
221
|
+
{l.text}
|
|
222
|
+
</div>
|
|
223
|
+
))}
|
|
224
|
+
{cursor && props.crosshair && !scene?.pie && plot ? (
|
|
225
|
+
<div
|
|
226
|
+
style={{
|
|
227
|
+
position: 'absolute',
|
|
228
|
+
left: cursor.px - 0.5,
|
|
229
|
+
top: plot.y,
|
|
230
|
+
width: 1,
|
|
231
|
+
height: plot.height,
|
|
232
|
+
backgroundColor: '#8a8a8a',
|
|
233
|
+
pointerEvents: 'none',
|
|
234
|
+
}}
|
|
235
|
+
/>
|
|
236
|
+
) : null}
|
|
237
|
+
{cursor && (props.crosshair || props.tooltip) ? (
|
|
238
|
+
<div
|
|
239
|
+
style={{
|
|
240
|
+
position: 'absolute',
|
|
241
|
+
left: cursor.px - 4,
|
|
242
|
+
top: cursor.py - 4,
|
|
243
|
+
width: 8,
|
|
244
|
+
height: 8,
|
|
245
|
+
borderRadius: 4,
|
|
246
|
+
backgroundColor: dotColor ?? '#4e79a7',
|
|
247
|
+
pointerEvents: 'none',
|
|
248
|
+
}}
|
|
249
|
+
/>
|
|
250
|
+
) : null}
|
|
251
|
+
{cursor && props.tooltip && tipText ? (
|
|
252
|
+
<div
|
|
253
|
+
style={{
|
|
254
|
+
position: 'absolute',
|
|
255
|
+
left: tipLeft,
|
|
256
|
+
top: tipTop < 0 ? cursor.py + 12 : tipTop,
|
|
257
|
+
backgroundColor: 'rgba(20,20,20,0.88)',
|
|
258
|
+
color: '#fff',
|
|
259
|
+
fontSize: 11,
|
|
260
|
+
padding: '2px 6px',
|
|
261
|
+
borderRadius: 4,
|
|
262
|
+
whiteSpace: 'nowrap',
|
|
263
|
+
pointerEvents: 'none',
|
|
264
|
+
}}
|
|
265
|
+
>
|
|
266
|
+
{tipText}
|
|
267
|
+
</div>
|
|
268
|
+
) : null}
|
|
269
|
+
</div>
|
|
270
|
+
</div>
|
|
271
|
+
{legend === 'bottom' && scene ? legendRow(scene.legend, 'bottom') : null}
|
|
272
|
+
</div>
|
|
263
273
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { ScrubPhase } from './core/hit'
|
|
2
2
|
|
|
3
3
|
export interface AppKitChartPointerBridge {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
observePointerMotion?(
|
|
5
|
+
view: unknown,
|
|
6
|
+
handlers: { move(x: number, y: number): void; exit(): void },
|
|
7
|
+
): () => void
|
|
8
|
+
locatePointer?(view: unknown): { x: number; y: number } | null
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/** Raw renderer onPan event — top-left x/y and the NSPanGestureRecognizer
|
|
12
12
|
* state (1 began / 2 changed / 3 ended / anything else cancelled). */
|
|
13
13
|
export interface AppKitPanEvent {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
x: number
|
|
15
|
+
y: number
|
|
16
|
+
deltaX: number
|
|
17
|
+
deltaY: number
|
|
18
|
+
state: number
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const finite = (x: number, y: number) => Number.isFinite(x) && Number.isFinite(y)
|
|
@@ -24,75 +24,90 @@ const finite = (x: number, y: number) => Number.isFinite(x) && Number.isFinite(y
|
|
|
24
24
|
* area motion and the current mouse event — onto the shared scrub phases,
|
|
25
25
|
* mirroring the DOM listeners in Chart.web. */
|
|
26
26
|
export function createAppKitChartPointer(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
scrub: (phase: ScrubPhase, x: number, y: number) => void,
|
|
28
|
+
size: () => { width: number; height: number },
|
|
29
|
+
bridge: () => AppKitChartPointerBridge | undefined = () =>
|
|
30
|
+
Reflect.get(globalThis, '__xplatAppKit'),
|
|
31
31
|
): {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
pan(event: { deltaX?: unknown; deltaY?: unknown; state?: unknown; x?: number; y?: number }): void
|
|
33
|
+
tap(view: unknown): void
|
|
34
|
+
observe(view: unknown): () => void
|
|
35
35
|
} {
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
pan(event: { deltaX?: unknown; deltaY?: unknown; state?: unknown; x?: number; y?: number }): void {
|
|
39
|
-
// The AppKit driver emits a superset payload carrying x/y; the shared
|
|
40
|
-
// PanGestureEvent type only declares deltaX/deltaY/state.
|
|
41
|
-
const panEvent = event as AppKitPanEvent
|
|
42
|
-
const state = Number(panEvent.state)
|
|
43
|
-
const point = finite(panEvent.x, panEvent.y)
|
|
44
|
-
? { x: panEvent.x, y: panEvent.y }
|
|
45
|
-
: null
|
|
46
|
-
if (state === 1) {
|
|
47
|
-
if (!point) {
|
|
48
|
-
return
|
|
49
|
-
}
|
|
36
|
+
let panning = false
|
|
50
37
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
tap(view: unknown): void {
|
|
67
|
-
const point = bridge()?.locatePointer?.(view)
|
|
68
|
-
if (point && finite(point.x, point.y)) {
|
|
69
|
-
scrub('tap', point.x, point.y)
|
|
70
|
-
return
|
|
71
|
-
}
|
|
38
|
+
return {
|
|
39
|
+
pan(event: {
|
|
40
|
+
deltaX?: unknown
|
|
41
|
+
deltaY?: unknown
|
|
42
|
+
state?: unknown
|
|
43
|
+
x?: number
|
|
44
|
+
y?: number
|
|
45
|
+
}): void {
|
|
46
|
+
// The AppKit driver emits a superset payload carrying x/y; the shared
|
|
47
|
+
// PanGestureEvent type only declares deltaX/deltaY/state.
|
|
48
|
+
const panEvent = event as AppKitPanEvent
|
|
49
|
+
const state = Number(panEvent.state)
|
|
50
|
+
const point = finite(panEvent.x, panEvent.y) ? { x: panEvent.x, y: panEvent.y } : null
|
|
72
51
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const observePointerMotion = bridge()?.observePointerMotion
|
|
78
|
-
if (!view || !observePointerMotion) {
|
|
79
|
-
return () => {}
|
|
80
|
-
}
|
|
52
|
+
if (state === 1) {
|
|
53
|
+
if (!point) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
81
56
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
57
|
+
// x/y includes the current delta — subtract it for the press start.
|
|
58
|
+
panning = true
|
|
59
|
+
scrub(
|
|
60
|
+
'down',
|
|
61
|
+
point.x - Number(panEvent.deltaX ?? 0),
|
|
62
|
+
point.y - Number(panEvent.deltaY ?? 0),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
scrub('move', point.x, point.y)
|
|
66
|
+
} else if (state === 2) {
|
|
67
|
+
if (panning && point) {
|
|
68
|
+
scrub('move', point.x, point.y)
|
|
69
|
+
}
|
|
70
|
+
} else if (panning) {
|
|
71
|
+
// `cancel` clears without coordinates, matching web's scrub('cancel', 0, 0).
|
|
72
|
+
const ended = state === 3 ? point : null
|
|
73
|
+
|
|
74
|
+
scrub(ended ? 'up' : 'cancel', ended?.x ?? 0, ended?.y ?? 0)
|
|
75
|
+
panning = false
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
tap(view: unknown): void {
|
|
79
|
+
const point = bridge()?.locatePointer?.(view)
|
|
80
|
+
|
|
81
|
+
if (point && finite(point.x, point.y)) {
|
|
82
|
+
scrub('tap', point.x, point.y)
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const { width, height } = size()
|
|
87
|
+
|
|
88
|
+
scrub('tap', width / 2, height / 2)
|
|
89
|
+
},
|
|
90
|
+
observe(view: unknown): () => void {
|
|
91
|
+
const observePointerMotion = bridge()?.observePointerMotion
|
|
92
|
+
|
|
93
|
+
if (!view || !observePointerMotion) {
|
|
94
|
+
return () => {}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// An AppKit exit mid-drag must not reset the scrub — the pan
|
|
98
|
+
// recognizer keeps delivering while pressed outside the view.
|
|
99
|
+
return observePointerMotion(view, {
|
|
100
|
+
move(x, y): void {
|
|
101
|
+
if (!panning) {
|
|
102
|
+
scrub('hover', x, y)
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
exit(): void {
|
|
106
|
+
if (!panning) {
|
|
107
|
+
scrub('leave', 0, 0)
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
},
|
|
112
|
+
}
|
|
98
113
|
}
|