@motion-core/motion-gpu 0.6.0 → 0.7.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 +35 -2
- package/dist/core/pointer.d.ts +96 -0
- package/dist/core/pointer.d.ts.map +1 -0
- package/dist/core/pointer.js +71 -0
- package/dist/core/pointer.js.map +1 -0
- package/dist/react/advanced.js +2 -1
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -1
- package/dist/react/use-pointer.d.ts +94 -0
- package/dist/react/use-pointer.d.ts.map +1 -0
- package/dist/react/use-pointer.js +285 -0
- package/dist/react/use-pointer.js.map +1 -0
- package/dist/svelte/advanced.js +2 -1
- package/dist/svelte/index.d.ts +2 -0
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +2 -1
- package/dist/svelte/use-pointer.d.ts +94 -0
- package/dist/svelte/use-pointer.d.ts.map +1 -0
- package/dist/svelte/use-pointer.js +292 -0
- package/dist/svelte/use-pointer.js.map +1 -0
- package/package.json +1 -1
- package/src/lib/core/pointer.ts +177 -0
- package/src/lib/react/index.ts +10 -0
- package/src/lib/react/use-pointer.ts +515 -0
- package/src/lib/svelte/index.ts +10 -0
- package/src/lib/svelte/use-pointer.ts +507 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { createCurrentWritable } from "../core/current-value.js";
|
|
2
|
+
import { createInitialPointerState, getPointerCoordinates, getPointerNowSeconds, normalizePointerKind, resolvePointerFrameRequestMode } from "../core/pointer.js";
|
|
3
|
+
import { useMotionGPU } from "./motiongpu-context.js";
|
|
4
|
+
import { onMount } from "svelte";
|
|
5
|
+
//#region src/lib/svelte/use-pointer.ts
|
|
6
|
+
/**
|
|
7
|
+
* Normalizes click button configuration with a primary-button fallback.
|
|
8
|
+
*/
|
|
9
|
+
function normalizeClickButtons(buttons) {
|
|
10
|
+
const source = buttons && buttons.length > 0 ? buttons : [0];
|
|
11
|
+
return new Set(source);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolves a valid click duration threshold in milliseconds.
|
|
15
|
+
*/
|
|
16
|
+
function resolveClickMaxDurationMs(value) {
|
|
17
|
+
if (typeof value !== "number" || Number.isNaN(value) || value <= 0) return 350;
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a valid click travel threshold in pixels.
|
|
22
|
+
*/
|
|
23
|
+
function resolveClickMaxMovePx(value) {
|
|
24
|
+
if (typeof value !== "number" || Number.isNaN(value) || value < 0) return 8;
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Tracks normalized pointer coordinates and click/tap snapshots for the active `FragCanvas`.
|
|
29
|
+
*/
|
|
30
|
+
function usePointer(options = {}) {
|
|
31
|
+
const motiongpu = useMotionGPU();
|
|
32
|
+
const pointerState = createCurrentWritable(createInitialPointerState());
|
|
33
|
+
const lastClick = createCurrentWritable(null);
|
|
34
|
+
const enabled = options.enabled ?? true;
|
|
35
|
+
const requestFrameMode = options.requestFrame ?? "auto";
|
|
36
|
+
const capturePointer = options.capturePointer ?? true;
|
|
37
|
+
const trackOutside = options.trackWhilePressedOutsideCanvas ?? true;
|
|
38
|
+
const clickEnabled = options.clickEnabled ?? true;
|
|
39
|
+
const clickMaxDurationMs = resolveClickMaxDurationMs(options.clickMaxDurationMs);
|
|
40
|
+
const clickMaxMovePx = resolveClickMaxMovePx(options.clickMaxMovePx);
|
|
41
|
+
const clickButtons = normalizeClickButtons(options.clickButtons);
|
|
42
|
+
let activePointerId = null;
|
|
43
|
+
let downSnapshot = null;
|
|
44
|
+
let clickCounter = 0;
|
|
45
|
+
let previousPx = null;
|
|
46
|
+
let previousUv = null;
|
|
47
|
+
let previousTimeSeconds = 0;
|
|
48
|
+
const requestFrame = () => {
|
|
49
|
+
const mode = resolvePointerFrameRequestMode(requestFrameMode, motiongpu.renderMode.current);
|
|
50
|
+
if (mode === "invalidate") {
|
|
51
|
+
motiongpu.invalidate();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (mode === "advance") motiongpu.advance();
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Commits a full pointer state snapshot with computed delta and velocity vectors.
|
|
58
|
+
*/
|
|
59
|
+
const updatePointerState = (input) => {
|
|
60
|
+
const nowSeconds = getPointerNowSeconds();
|
|
61
|
+
const dt = previousTimeSeconds > 0 ? Math.max(nowSeconds - previousTimeSeconds, 1e-6) : 0;
|
|
62
|
+
const deltaPx = input.resetDelta || !previousPx ? [0, 0] : [input.point.px[0] - previousPx[0], input.point.px[1] - previousPx[1]];
|
|
63
|
+
const deltaUv = input.resetDelta || !previousUv ? [0, 0] : [input.point.uv[0] - previousUv[0], input.point.uv[1] - previousUv[1]];
|
|
64
|
+
const velocityPx = dt > 0 ? [deltaPx[0] / dt, deltaPx[1] / dt] : [0, 0];
|
|
65
|
+
const velocityUv = dt > 0 ? [deltaUv[0] / dt, deltaUv[1] / dt] : [0, 0];
|
|
66
|
+
const nextState = {
|
|
67
|
+
px: input.point.px,
|
|
68
|
+
uv: input.point.uv,
|
|
69
|
+
ndc: input.point.ndc,
|
|
70
|
+
inside: input.inside,
|
|
71
|
+
pressed: input.pressed,
|
|
72
|
+
dragging: input.dragging,
|
|
73
|
+
pointerType: input.pointerType,
|
|
74
|
+
pointerId: input.pointerId,
|
|
75
|
+
button: input.button,
|
|
76
|
+
buttons: input.buttons,
|
|
77
|
+
time: nowSeconds,
|
|
78
|
+
downPx: input.downPx,
|
|
79
|
+
downUv: input.downUv,
|
|
80
|
+
deltaPx,
|
|
81
|
+
deltaUv,
|
|
82
|
+
velocityPx,
|
|
83
|
+
velocityUv
|
|
84
|
+
};
|
|
85
|
+
pointerState.set(nextState);
|
|
86
|
+
previousPx = input.point.px;
|
|
87
|
+
previousUv = input.point.uv;
|
|
88
|
+
previousTimeSeconds = nowSeconds;
|
|
89
|
+
requestFrame();
|
|
90
|
+
return nextState;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Updates only the `inside` flag while keeping the latest pointer coordinates.
|
|
94
|
+
*/
|
|
95
|
+
const updateInsideState = (inside) => {
|
|
96
|
+
const nextState = {
|
|
97
|
+
...pointerState.current,
|
|
98
|
+
inside,
|
|
99
|
+
time: getPointerNowSeconds(),
|
|
100
|
+
deltaPx: [0, 0],
|
|
101
|
+
deltaUv: [0, 0],
|
|
102
|
+
velocityPx: [0, 0],
|
|
103
|
+
velocityUv: [0, 0]
|
|
104
|
+
};
|
|
105
|
+
pointerState.set(nextState);
|
|
106
|
+
requestFrame();
|
|
107
|
+
return nextState;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Checks whether an event belongs to the active tracked pointer.
|
|
111
|
+
*/
|
|
112
|
+
const isTrackedPointer = (event) => activePointerId === null || event.pointerId === activePointerId;
|
|
113
|
+
onMount(() => {
|
|
114
|
+
if (!enabled) return;
|
|
115
|
+
const canvas = motiongpu.canvas;
|
|
116
|
+
if (!canvas) return;
|
|
117
|
+
const handlePointerDown = (event) => {
|
|
118
|
+
const point = getPointerCoordinates(event.clientX, event.clientY, canvas.getBoundingClientRect());
|
|
119
|
+
const pointerType = normalizePointerKind(event.pointerType);
|
|
120
|
+
activePointerId = event.pointerId;
|
|
121
|
+
downSnapshot = {
|
|
122
|
+
pointerId: event.pointerId,
|
|
123
|
+
pointerType,
|
|
124
|
+
button: event.button,
|
|
125
|
+
timeMs: getPointerNowSeconds() * 1e3,
|
|
126
|
+
px: point.px,
|
|
127
|
+
uv: point.uv,
|
|
128
|
+
inside: point.inside
|
|
129
|
+
};
|
|
130
|
+
if (capturePointer) try {
|
|
131
|
+
canvas.setPointerCapture(event.pointerId);
|
|
132
|
+
} catch {}
|
|
133
|
+
const nextState = updatePointerState({
|
|
134
|
+
point,
|
|
135
|
+
inside: point.inside,
|
|
136
|
+
pressed: true,
|
|
137
|
+
dragging: false,
|
|
138
|
+
pointerType,
|
|
139
|
+
pointerId: event.pointerId,
|
|
140
|
+
button: event.button,
|
|
141
|
+
buttons: event.buttons,
|
|
142
|
+
downPx: point.px,
|
|
143
|
+
downUv: point.uv,
|
|
144
|
+
resetDelta: true
|
|
145
|
+
});
|
|
146
|
+
options.onDown?.(nextState, event);
|
|
147
|
+
};
|
|
148
|
+
const handleMove = (event) => {
|
|
149
|
+
if (!isTrackedPointer(event)) return;
|
|
150
|
+
const point = getPointerCoordinates(event.clientX, event.clientY, canvas.getBoundingClientRect());
|
|
151
|
+
const pressed = activePointerId !== null && event.pointerId === activePointerId;
|
|
152
|
+
const downPx = pressed ? downSnapshot?.px ?? point.px : null;
|
|
153
|
+
const downUv = pressed ? downSnapshot?.uv ?? point.uv : null;
|
|
154
|
+
let dragging = false;
|
|
155
|
+
if (pressed && downPx) {
|
|
156
|
+
const dx = point.px[0] - downPx[0];
|
|
157
|
+
const dy = point.px[1] - downPx[1];
|
|
158
|
+
dragging = Math.hypot(dx, dy) > 0;
|
|
159
|
+
}
|
|
160
|
+
const nextState = updatePointerState({
|
|
161
|
+
point,
|
|
162
|
+
inside: point.inside,
|
|
163
|
+
pressed,
|
|
164
|
+
dragging,
|
|
165
|
+
pointerType: normalizePointerKind(event.pointerType),
|
|
166
|
+
pointerId: event.pointerId,
|
|
167
|
+
button: pressed ? downSnapshot?.button ?? event.button : null,
|
|
168
|
+
buttons: event.buttons,
|
|
169
|
+
downPx,
|
|
170
|
+
downUv
|
|
171
|
+
});
|
|
172
|
+
options.onMove?.(nextState, event);
|
|
173
|
+
};
|
|
174
|
+
const handleWindowMove = (event) => {
|
|
175
|
+
if (!trackOutside || activePointerId === null || event.pointerId !== activePointerId) return;
|
|
176
|
+
const point = getPointerCoordinates(event.clientX, event.clientY, canvas.getBoundingClientRect());
|
|
177
|
+
if (point.inside) return;
|
|
178
|
+
const downPx = downSnapshot?.px ?? point.px;
|
|
179
|
+
const downUv = downSnapshot?.uv ?? point.uv;
|
|
180
|
+
const dx = point.px[0] - downPx[0];
|
|
181
|
+
const dy = point.px[1] - downPx[1];
|
|
182
|
+
const nextState = updatePointerState({
|
|
183
|
+
point,
|
|
184
|
+
inside: false,
|
|
185
|
+
pressed: true,
|
|
186
|
+
dragging: Math.hypot(dx, dy) > 0,
|
|
187
|
+
pointerType: downSnapshot?.pointerType ?? normalizePointerKind(event.pointerType),
|
|
188
|
+
pointerId: event.pointerId,
|
|
189
|
+
button: downSnapshot?.button ?? event.button,
|
|
190
|
+
buttons: event.buttons,
|
|
191
|
+
downPx,
|
|
192
|
+
downUv
|
|
193
|
+
});
|
|
194
|
+
options.onMove?.(nextState, event);
|
|
195
|
+
};
|
|
196
|
+
const releasePointer = (event, emitClick) => {
|
|
197
|
+
if (activePointerId === null || event.pointerId !== activePointerId) return;
|
|
198
|
+
const point = getPointerCoordinates(event.clientX, event.clientY, canvas.getBoundingClientRect());
|
|
199
|
+
const pointerType = downSnapshot?.pointerType ?? normalizePointerKind(event.pointerType);
|
|
200
|
+
const previous = downSnapshot;
|
|
201
|
+
const nextState = updatePointerState({
|
|
202
|
+
point,
|
|
203
|
+
inside: point.inside,
|
|
204
|
+
pressed: false,
|
|
205
|
+
dragging: false,
|
|
206
|
+
pointerType,
|
|
207
|
+
pointerId: null,
|
|
208
|
+
button: null,
|
|
209
|
+
buttons: event.buttons,
|
|
210
|
+
downPx: null,
|
|
211
|
+
downUv: null
|
|
212
|
+
});
|
|
213
|
+
options.onUp?.(nextState, event);
|
|
214
|
+
if (capturePointer && canvas.hasPointerCapture(event.pointerId)) try {
|
|
215
|
+
canvas.releasePointerCapture(event.pointerId);
|
|
216
|
+
} catch {}
|
|
217
|
+
if (emitClick && clickEnabled && previous && clickButtons.has(previous.button)) {
|
|
218
|
+
const durationMs = getPointerNowSeconds() * 1e3 - previous.timeMs;
|
|
219
|
+
const dx = point.px[0] - previous.px[0];
|
|
220
|
+
const dy = point.px[1] - previous.px[1];
|
|
221
|
+
const moveDistance = Math.hypot(dx, dy);
|
|
222
|
+
if (previous.inside && point.inside && durationMs <= clickMaxDurationMs && moveDistance <= clickMaxMovePx) {
|
|
223
|
+
clickCounter += 1;
|
|
224
|
+
const click = {
|
|
225
|
+
id: clickCounter,
|
|
226
|
+
time: getPointerNowSeconds(),
|
|
227
|
+
pointerType,
|
|
228
|
+
pointerId: event.pointerId,
|
|
229
|
+
button: previous.button,
|
|
230
|
+
modifiers: {
|
|
231
|
+
alt: event.altKey,
|
|
232
|
+
ctrl: event.ctrlKey,
|
|
233
|
+
shift: event.shiftKey,
|
|
234
|
+
meta: event.metaKey
|
|
235
|
+
},
|
|
236
|
+
px: point.px,
|
|
237
|
+
uv: point.uv,
|
|
238
|
+
ndc: point.ndc
|
|
239
|
+
};
|
|
240
|
+
lastClick.set(click);
|
|
241
|
+
options.onClick?.(click, nextState, event);
|
|
242
|
+
requestFrame();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
activePointerId = null;
|
|
246
|
+
downSnapshot = null;
|
|
247
|
+
};
|
|
248
|
+
const handlePointerUp = (event) => {
|
|
249
|
+
releasePointer(event, true);
|
|
250
|
+
};
|
|
251
|
+
const handlePointerCancel = (event) => {
|
|
252
|
+
releasePointer(event, false);
|
|
253
|
+
};
|
|
254
|
+
const handlePointerLeave = () => {
|
|
255
|
+
if (activePointerId !== null) return;
|
|
256
|
+
updateInsideState(false);
|
|
257
|
+
};
|
|
258
|
+
canvas.addEventListener("pointerdown", handlePointerDown);
|
|
259
|
+
canvas.addEventListener("pointermove", handleMove);
|
|
260
|
+
canvas.addEventListener("pointerup", handlePointerUp);
|
|
261
|
+
canvas.addEventListener("pointercancel", handlePointerCancel);
|
|
262
|
+
canvas.addEventListener("pointerleave", handlePointerLeave);
|
|
263
|
+
if (trackOutside) {
|
|
264
|
+
window.addEventListener("pointermove", handleWindowMove);
|
|
265
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
266
|
+
window.addEventListener("pointercancel", handlePointerCancel);
|
|
267
|
+
}
|
|
268
|
+
return () => {
|
|
269
|
+
canvas.removeEventListener("pointerdown", handlePointerDown);
|
|
270
|
+
canvas.removeEventListener("pointermove", handleMove);
|
|
271
|
+
canvas.removeEventListener("pointerup", handlePointerUp);
|
|
272
|
+
canvas.removeEventListener("pointercancel", handlePointerCancel);
|
|
273
|
+
canvas.removeEventListener("pointerleave", handlePointerLeave);
|
|
274
|
+
if (trackOutside) {
|
|
275
|
+
window.removeEventListener("pointermove", handleWindowMove);
|
|
276
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
277
|
+
window.removeEventListener("pointercancel", handlePointerCancel);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
return {
|
|
282
|
+
state: pointerState,
|
|
283
|
+
lastClick,
|
|
284
|
+
resetClick: () => {
|
|
285
|
+
lastClick.set(null);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
//#endregion
|
|
290
|
+
export { usePointer };
|
|
291
|
+
|
|
292
|
+
//# sourceMappingURL=use-pointer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-pointer.js","names":[],"sources":["../../src/lib/svelte/use-pointer.ts"],"sourcesContent":["import { onMount } from 'svelte';\nimport {\n\tcreateCurrentWritable as currentWritable,\n\ttype CurrentReadable\n} from '../core/current-value.js';\nimport {\n\tcreateInitialPointerState,\n\tgetPointerCoordinates,\n\tgetPointerNowSeconds,\n\tnormalizePointerKind,\n\tresolvePointerFrameRequestMode,\n\ttype PointerClick,\n\ttype PointerFrameRequestMode,\n\ttype PointerState,\n\ttype PointerVec2\n} from '../core/pointer.js';\nimport { useMotionGPU } from './motiongpu-context.js';\n\nexport type {\n\tPointerClick,\n\tPointerFrameRequestMode,\n\tPointerKind,\n\tPointerPoint,\n\tPointerState\n} from '../core/pointer.js';\n\n/**\n * Configuration for pointer input handling in `usePointer`.\n */\nexport interface UsePointerOptions {\n\t/**\n\t * Enables pointer listeners.\n\t *\n\t * @default true\n\t */\n\tenabled?: boolean;\n\t/**\n\t * Frame wake-up strategy for pointer-driven state changes.\n\t *\n\t * @default 'auto'\n\t */\n\trequestFrame?: PointerFrameRequestMode;\n\t/**\n\t * Requests pointer capture on pointer down.\n\t *\n\t * @default true\n\t */\n\tcapturePointer?: boolean;\n\t/**\n\t * Tracks pointer move/up outside canvas while pointer is pressed.\n\t *\n\t * @default true\n\t */\n\ttrackWhilePressedOutsideCanvas?: boolean;\n\t/**\n\t * Enables click/tap synthesis on pointer up.\n\t *\n\t * @default true\n\t */\n\tclickEnabled?: boolean;\n\t/**\n\t * Maximum press duration to consider pointer up a click (milliseconds).\n\t *\n\t * @default 350\n\t */\n\tclickMaxDurationMs?: number;\n\t/**\n\t * Maximum pointer travel from down to up to consider pointer up a click (pixels).\n\t *\n\t * @default 8\n\t */\n\tclickMaxMovePx?: number;\n\t/**\n\t * Allowed pointer buttons for click synthesis.\n\t *\n\t * @default [0]\n\t */\n\tclickButtons?: number[];\n\t/**\n\t * Called after pointer move state update.\n\t */\n\tonMove?: (state: PointerState, event: PointerEvent) => void;\n\t/**\n\t * Called after pointer down state update.\n\t */\n\tonDown?: (state: PointerState, event: PointerEvent) => void;\n\t/**\n\t * Called after pointer up/cancel state update.\n\t */\n\tonUp?: (state: PointerState, event: PointerEvent) => void;\n\t/**\n\t * Called when click/tap is synthesized.\n\t */\n\tonClick?: (click: PointerClick, state: PointerState, event: PointerEvent) => void;\n}\n\n/**\n * Reactive state returned by `usePointer`.\n */\nexport interface UsePointerResult {\n\t/**\n\t * Current pointer state.\n\t */\n\tstate: CurrentReadable<PointerState>;\n\t/**\n\t * Last synthesized click/tap event.\n\t */\n\tlastClick: CurrentReadable<PointerClick | null>;\n\t/**\n\t * Clears last click snapshot.\n\t */\n\tresetClick: () => void;\n}\n\ninterface PointerDownSnapshot {\n\tbutton: number;\n\tinside: boolean;\n\tpointerId: number;\n\tpointerType: 'mouse' | 'pen' | 'touch';\n\tpx: PointerVec2;\n\ttimeMs: number;\n\tuv: PointerVec2;\n}\n\n/**\n * Normalizes click button configuration with a primary-button fallback.\n */\nfunction normalizeClickButtons(buttons: number[] | undefined): Set<number> {\n\tconst source = buttons && buttons.length > 0 ? buttons : [0];\n\treturn new Set(source);\n}\n\n/**\n * Resolves a valid click duration threshold in milliseconds.\n */\nfunction resolveClickMaxDurationMs(value: number | undefined): number {\n\tif (typeof value !== 'number' || Number.isNaN(value) || value <= 0) {\n\t\treturn 350;\n\t}\n\n\treturn value;\n}\n\n/**\n * Resolves a valid click travel threshold in pixels.\n */\nfunction resolveClickMaxMovePx(value: number | undefined): number {\n\tif (typeof value !== 'number' || Number.isNaN(value) || value < 0) {\n\t\treturn 8;\n\t}\n\n\treturn value;\n}\n\n/**\n * Tracks normalized pointer coordinates and click/tap snapshots for the active `FragCanvas`.\n */\nexport function usePointer(options: UsePointerOptions = {}): UsePointerResult {\n\tconst motiongpu = useMotionGPU();\n\tconst pointerState = currentWritable<PointerState>(createInitialPointerState());\n\tconst lastClick = currentWritable<PointerClick | null>(null);\n\tconst enabled = options.enabled ?? true;\n\tconst requestFrameMode = options.requestFrame ?? 'auto';\n\tconst capturePointer = options.capturePointer ?? true;\n\tconst trackOutside = options.trackWhilePressedOutsideCanvas ?? true;\n\tconst clickEnabled = options.clickEnabled ?? true;\n\tconst clickMaxDurationMs = resolveClickMaxDurationMs(options.clickMaxDurationMs);\n\tconst clickMaxMovePx = resolveClickMaxMovePx(options.clickMaxMovePx);\n\tconst clickButtons = normalizeClickButtons(options.clickButtons);\n\tlet activePointerId: number | null = null;\n\tlet downSnapshot: PointerDownSnapshot | null = null;\n\tlet clickCounter = 0;\n\tlet previousPx: PointerVec2 | null = null;\n\tlet previousUv: PointerVec2 | null = null;\n\tlet previousTimeSeconds = 0;\n\n\tconst requestFrame = (): void => {\n\t\tconst mode = resolvePointerFrameRequestMode(requestFrameMode, motiongpu.renderMode.current);\n\t\tif (mode === 'invalidate') {\n\t\t\tmotiongpu.invalidate();\n\t\t\treturn;\n\t\t}\n\t\tif (mode === 'advance') {\n\t\t\tmotiongpu.advance();\n\t\t}\n\t};\n\n\t/**\n\t * Commits a full pointer state snapshot with computed delta and velocity vectors.\n\t */\n\tconst updatePointerState = (input: {\n\t\tbutton: number | null;\n\t\tbuttons: number;\n\t\tdownPx: PointerVec2 | null;\n\t\tdownUv: PointerVec2 | null;\n\t\tdragging: boolean;\n\t\tinside: boolean;\n\t\tpointerId: number | null;\n\t\tpointerType: 'mouse' | 'pen' | 'touch' | null;\n\t\tpressed: boolean;\n\t\tpoint: {\n\t\t\tndc: PointerVec2;\n\t\t\tpx: PointerVec2;\n\t\t\tuv: PointerVec2;\n\t\t};\n\t\tresetDelta?: boolean;\n\t}): PointerState => {\n\t\tconst nowSeconds = getPointerNowSeconds();\n\t\tconst dt = previousTimeSeconds > 0 ? Math.max(nowSeconds - previousTimeSeconds, 1e-6) : 0;\n\t\tconst deltaPx: PointerVec2 =\n\t\t\tinput.resetDelta || !previousPx\n\t\t\t\t? [0, 0]\n\t\t\t\t: [input.point.px[0] - previousPx[0], input.point.px[1] - previousPx[1]];\n\t\tconst deltaUv: PointerVec2 =\n\t\t\tinput.resetDelta || !previousUv\n\t\t\t\t? [0, 0]\n\t\t\t\t: [input.point.uv[0] - previousUv[0], input.point.uv[1] - previousUv[1]];\n\t\tconst velocityPx: PointerVec2 = dt > 0 ? [deltaPx[0] / dt, deltaPx[1] / dt] : [0, 0];\n\t\tconst velocityUv: PointerVec2 = dt > 0 ? [deltaUv[0] / dt, deltaUv[1] / dt] : [0, 0];\n\t\tconst nextState: PointerState = {\n\t\t\tpx: input.point.px,\n\t\t\tuv: input.point.uv,\n\t\t\tndc: input.point.ndc,\n\t\t\tinside: input.inside,\n\t\t\tpressed: input.pressed,\n\t\t\tdragging: input.dragging,\n\t\t\tpointerType: input.pointerType,\n\t\t\tpointerId: input.pointerId,\n\t\t\tbutton: input.button,\n\t\t\tbuttons: input.buttons,\n\t\t\ttime: nowSeconds,\n\t\t\tdownPx: input.downPx,\n\t\t\tdownUv: input.downUv,\n\t\t\tdeltaPx,\n\t\t\tdeltaUv,\n\t\t\tvelocityPx,\n\t\t\tvelocityUv\n\t\t};\n\t\tpointerState.set(nextState);\n\t\tpreviousPx = input.point.px;\n\t\tpreviousUv = input.point.uv;\n\t\tpreviousTimeSeconds = nowSeconds;\n\t\trequestFrame();\n\t\treturn nextState;\n\t};\n\n\t/**\n\t * Updates only the `inside` flag while keeping the latest pointer coordinates.\n\t */\n\tconst updateInsideState = (inside: boolean): PointerState => {\n\t\tconst current = pointerState.current;\n\t\tconst nextState: PointerState = {\n\t\t\t...current,\n\t\t\tinside,\n\t\t\ttime: getPointerNowSeconds(),\n\t\t\tdeltaPx: [0, 0],\n\t\t\tdeltaUv: [0, 0],\n\t\t\tvelocityPx: [0, 0],\n\t\t\tvelocityUv: [0, 0]\n\t\t};\n\t\tpointerState.set(nextState);\n\t\trequestFrame();\n\t\treturn nextState;\n\t};\n\n\t/**\n\t * Checks whether an event belongs to the active tracked pointer.\n\t */\n\tconst isTrackedPointer = (event: PointerEvent): boolean =>\n\t\tactivePointerId === null || event.pointerId === activePointerId;\n\n\tonMount(() => {\n\t\tif (!enabled) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst canvas = motiongpu.canvas;\n\t\tif (!canvas) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst handlePointerDown = (event: PointerEvent): void => {\n\t\t\tconst point = getPointerCoordinates(\n\t\t\t\tevent.clientX,\n\t\t\t\tevent.clientY,\n\t\t\t\tcanvas.getBoundingClientRect()\n\t\t\t);\n\t\t\tconst pointerType = normalizePointerKind(event.pointerType);\n\t\t\tactivePointerId = event.pointerId;\n\t\t\tdownSnapshot = {\n\t\t\t\tpointerId: event.pointerId,\n\t\t\t\tpointerType,\n\t\t\t\tbutton: event.button,\n\t\t\t\ttimeMs: getPointerNowSeconds() * 1000,\n\t\t\t\tpx: point.px,\n\t\t\t\tuv: point.uv,\n\t\t\t\tinside: point.inside\n\t\t\t};\n\t\t\tif (capturePointer) {\n\t\t\t\ttry {\n\t\t\t\t\tcanvas.setPointerCapture(event.pointerId);\n\t\t\t\t} catch {\n\t\t\t\t\t// Browser rejected capture (e.g. unsupported pointer state).\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst nextState = updatePointerState({\n\t\t\t\tpoint,\n\t\t\t\tinside: point.inside,\n\t\t\t\tpressed: true,\n\t\t\t\tdragging: false,\n\t\t\t\tpointerType,\n\t\t\t\tpointerId: event.pointerId,\n\t\t\t\tbutton: event.button,\n\t\t\t\tbuttons: event.buttons,\n\t\t\t\tdownPx: point.px,\n\t\t\t\tdownUv: point.uv,\n\t\t\t\tresetDelta: true\n\t\t\t});\n\t\t\toptions.onDown?.(nextState, event);\n\t\t};\n\n\t\tconst handleMove = (event: PointerEvent): void => {\n\t\t\tif (!isTrackedPointer(event)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst point = getPointerCoordinates(\n\t\t\t\tevent.clientX,\n\t\t\t\tevent.clientY,\n\t\t\t\tcanvas.getBoundingClientRect()\n\t\t\t);\n\t\t\tconst pressed = activePointerId !== null && event.pointerId === activePointerId;\n\t\t\tconst downPx = pressed ? (downSnapshot?.px ?? point.px) : null;\n\t\t\tconst downUv = pressed ? (downSnapshot?.uv ?? point.uv) : null;\n\t\t\tlet dragging = false;\n\t\t\tif (pressed && downPx) {\n\t\t\t\tconst dx = point.px[0] - downPx[0];\n\t\t\t\tconst dy = point.px[1] - downPx[1];\n\t\t\t\tdragging = Math.hypot(dx, dy) > 0;\n\t\t\t}\n\t\t\tconst nextState = updatePointerState({\n\t\t\t\tpoint,\n\t\t\t\tinside: point.inside,\n\t\t\t\tpressed,\n\t\t\t\tdragging,\n\t\t\t\tpointerType: normalizePointerKind(event.pointerType),\n\t\t\t\tpointerId: event.pointerId,\n\t\t\t\tbutton: pressed ? (downSnapshot?.button ?? event.button) : null,\n\t\t\t\tbuttons: event.buttons,\n\t\t\t\tdownPx,\n\t\t\t\tdownUv\n\t\t\t});\n\t\t\toptions.onMove?.(nextState, event);\n\t\t};\n\n\t\tconst handleWindowMove = (event: PointerEvent): void => {\n\t\t\tif (!trackOutside || activePointerId === null || event.pointerId !== activePointerId) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst point = getPointerCoordinates(\n\t\t\t\tevent.clientX,\n\t\t\t\tevent.clientY,\n\t\t\t\tcanvas.getBoundingClientRect()\n\t\t\t);\n\t\t\tif (point.inside) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst downPx = downSnapshot?.px ?? point.px;\n\t\t\tconst downUv = downSnapshot?.uv ?? point.uv;\n\t\t\tconst dx = point.px[0] - downPx[0];\n\t\t\tconst dy = point.px[1] - downPx[1];\n\t\t\tconst nextState = updatePointerState({\n\t\t\t\tpoint,\n\t\t\t\tinside: false,\n\t\t\t\tpressed: true,\n\t\t\t\tdragging: Math.hypot(dx, dy) > 0,\n\t\t\t\tpointerType: downSnapshot?.pointerType ?? normalizePointerKind(event.pointerType),\n\t\t\t\tpointerId: event.pointerId,\n\t\t\t\tbutton: downSnapshot?.button ?? event.button,\n\t\t\t\tbuttons: event.buttons,\n\t\t\t\tdownPx,\n\t\t\t\tdownUv\n\t\t\t});\n\t\t\toptions.onMove?.(nextState, event);\n\t\t};\n\n\t\tconst releasePointer = (event: PointerEvent, emitClick: boolean): void => {\n\t\t\tif (activePointerId === null || event.pointerId !== activePointerId) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst point = getPointerCoordinates(\n\t\t\t\tevent.clientX,\n\t\t\t\tevent.clientY,\n\t\t\t\tcanvas.getBoundingClientRect()\n\t\t\t);\n\t\t\tconst pointerType = downSnapshot?.pointerType ?? normalizePointerKind(event.pointerType);\n\t\t\tconst previous = downSnapshot;\n\t\t\tconst nextState = updatePointerState({\n\t\t\t\tpoint,\n\t\t\t\tinside: point.inside,\n\t\t\t\tpressed: false,\n\t\t\t\tdragging: false,\n\t\t\t\tpointerType,\n\t\t\t\tpointerId: null,\n\t\t\t\tbutton: null,\n\t\t\t\tbuttons: event.buttons,\n\t\t\t\tdownPx: null,\n\t\t\t\tdownUv: null\n\t\t\t});\n\t\t\toptions.onUp?.(nextState, event);\n\n\t\t\tif (capturePointer && canvas.hasPointerCapture(event.pointerId)) {\n\t\t\t\ttry {\n\t\t\t\t\tcanvas.releasePointerCapture(event.pointerId);\n\t\t\t\t} catch {\n\t\t\t\t\t// Browser rejected release for this pointer id.\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (emitClick && clickEnabled && previous && clickButtons.has(previous.button)) {\n\t\t\t\tconst durationMs = getPointerNowSeconds() * 1000 - previous.timeMs;\n\t\t\t\tconst dx = point.px[0] - previous.px[0];\n\t\t\t\tconst dy = point.px[1] - previous.px[1];\n\t\t\t\tconst moveDistance = Math.hypot(dx, dy);\n\t\t\t\tif (\n\t\t\t\t\tprevious.inside &&\n\t\t\t\t\tpoint.inside &&\n\t\t\t\t\tdurationMs <= clickMaxDurationMs &&\n\t\t\t\t\tmoveDistance <= clickMaxMovePx\n\t\t\t\t) {\n\t\t\t\t\tclickCounter += 1;\n\t\t\t\t\tconst click: PointerClick = {\n\t\t\t\t\t\tid: clickCounter,\n\t\t\t\t\t\ttime: getPointerNowSeconds(),\n\t\t\t\t\t\tpointerType,\n\t\t\t\t\t\tpointerId: event.pointerId,\n\t\t\t\t\t\tbutton: previous.button,\n\t\t\t\t\t\tmodifiers: {\n\t\t\t\t\t\t\talt: event.altKey,\n\t\t\t\t\t\t\tctrl: event.ctrlKey,\n\t\t\t\t\t\t\tshift: event.shiftKey,\n\t\t\t\t\t\t\tmeta: event.metaKey\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpx: point.px,\n\t\t\t\t\t\tuv: point.uv,\n\t\t\t\t\t\tndc: point.ndc\n\t\t\t\t\t};\n\t\t\t\t\tlastClick.set(click);\n\t\t\t\t\toptions.onClick?.(click, nextState, event);\n\t\t\t\t\trequestFrame();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tactivePointerId = null;\n\t\t\tdownSnapshot = null;\n\t\t};\n\n\t\tconst handlePointerUp = (event: PointerEvent): void => {\n\t\t\treleasePointer(event, true);\n\t\t};\n\n\t\tconst handlePointerCancel = (event: PointerEvent): void => {\n\t\t\treleasePointer(event, false);\n\t\t};\n\n\t\tconst handlePointerLeave = (): void => {\n\t\t\tif (activePointerId !== null) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tupdateInsideState(false);\n\t\t};\n\n\t\tcanvas.addEventListener('pointerdown', handlePointerDown);\n\t\tcanvas.addEventListener('pointermove', handleMove);\n\t\tcanvas.addEventListener('pointerup', handlePointerUp);\n\t\tcanvas.addEventListener('pointercancel', handlePointerCancel);\n\t\tcanvas.addEventListener('pointerleave', handlePointerLeave);\n\t\tif (trackOutside) {\n\t\t\twindow.addEventListener('pointermove', handleWindowMove);\n\t\t\twindow.addEventListener('pointerup', handlePointerUp);\n\t\t\twindow.addEventListener('pointercancel', handlePointerCancel);\n\t\t}\n\n\t\treturn () => {\n\t\t\tcanvas.removeEventListener('pointerdown', handlePointerDown);\n\t\t\tcanvas.removeEventListener('pointermove', handleMove);\n\t\t\tcanvas.removeEventListener('pointerup', handlePointerUp);\n\t\t\tcanvas.removeEventListener('pointercancel', handlePointerCancel);\n\t\t\tcanvas.removeEventListener('pointerleave', handlePointerLeave);\n\t\t\tif (trackOutside) {\n\t\t\t\twindow.removeEventListener('pointermove', handleWindowMove);\n\t\t\t\twindow.removeEventListener('pointerup', handlePointerUp);\n\t\t\t\twindow.removeEventListener('pointercancel', handlePointerCancel);\n\t\t\t}\n\t\t};\n\t});\n\n\treturn {\n\t\tstate: pointerState,\n\t\tlastClick,\n\t\tresetClick: () => {\n\t\t\tlastClick.set(null);\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;;AA+HA,SAAS,sBAAsB,SAA4C;CAC1E,MAAM,SAAS,WAAW,QAAQ,SAAS,IAAI,UAAU,CAAC,EAAE;AAC5D,QAAO,IAAI,IAAI,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,aAAa,gBAAgB;AACxD,WAAO,oBAAoB,iBAAiB,oBAAoB;;;GAGjE;AAEF,QAAO;EACN,OAAO;EACP;EACA,kBAAkB;AACjB,aAAU,IAAI,KAAK;;EAEpB"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { RenderMode } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pointer kind normalized from DOM `PointerEvent.pointerType`.
|
|
5
|
+
*/
|
|
6
|
+
export type PointerKind = 'mouse' | 'pen' | 'touch';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 2D tuple used by pointer coordinate payloads.
|
|
10
|
+
*/
|
|
11
|
+
export type PointerVec2 = [number, number];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Normalized pointer coordinates exposed to runtime hooks.
|
|
15
|
+
*/
|
|
16
|
+
export interface PointerPoint {
|
|
17
|
+
/**
|
|
18
|
+
* CSS pixel coordinates relative to canvas top-left corner.
|
|
19
|
+
*/
|
|
20
|
+
px: PointerVec2;
|
|
21
|
+
/**
|
|
22
|
+
* UV coordinates in shader-friendly orientation (`y` grows upward).
|
|
23
|
+
*/
|
|
24
|
+
uv: PointerVec2;
|
|
25
|
+
/**
|
|
26
|
+
* Normalized device coordinates (`-1..1`, `y` grows upward).
|
|
27
|
+
*/
|
|
28
|
+
ndc: PointerVec2;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Mutable pointer state snapshot exposed by `usePointer`.
|
|
33
|
+
*/
|
|
34
|
+
export interface PointerState extends PointerPoint {
|
|
35
|
+
inside: boolean;
|
|
36
|
+
pressed: boolean;
|
|
37
|
+
dragging: boolean;
|
|
38
|
+
pointerType: PointerKind | null;
|
|
39
|
+
pointerId: number | null;
|
|
40
|
+
button: number | null;
|
|
41
|
+
buttons: number;
|
|
42
|
+
time: number;
|
|
43
|
+
downPx: PointerVec2 | null;
|
|
44
|
+
downUv: PointerVec2 | null;
|
|
45
|
+
deltaPx: PointerVec2;
|
|
46
|
+
deltaUv: PointerVec2;
|
|
47
|
+
velocityPx: PointerVec2;
|
|
48
|
+
velocityUv: PointerVec2;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Modifier key snapshot attached to pointer click events.
|
|
53
|
+
*/
|
|
54
|
+
export interface PointerModifiers {
|
|
55
|
+
alt: boolean;
|
|
56
|
+
ctrl: boolean;
|
|
57
|
+
shift: boolean;
|
|
58
|
+
meta: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Click/tap payload produced by `usePointer`.
|
|
63
|
+
*/
|
|
64
|
+
export interface PointerClick extends PointerPoint {
|
|
65
|
+
id: number;
|
|
66
|
+
time: number;
|
|
67
|
+
pointerType: PointerKind;
|
|
68
|
+
pointerId: number;
|
|
69
|
+
button: number;
|
|
70
|
+
modifiers: PointerModifiers;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Frame wake-up strategy for pointer-driven interactions.
|
|
75
|
+
*/
|
|
76
|
+
export type PointerFrameRequestMode = 'advance' | 'auto' | 'invalidate' | 'none';
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Returns a monotonic timestamp in seconds.
|
|
80
|
+
*/
|
|
81
|
+
export function getPointerNowSeconds(): number {
|
|
82
|
+
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
|
|
83
|
+
return performance.now() / 1000;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return Date.now() / 1000;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates the initial pointer state snapshot.
|
|
91
|
+
*/
|
|
92
|
+
export function createInitialPointerState(): PointerState {
|
|
93
|
+
return {
|
|
94
|
+
px: [0, 0],
|
|
95
|
+
uv: [0, 0],
|
|
96
|
+
ndc: [-1, -1],
|
|
97
|
+
inside: false,
|
|
98
|
+
pressed: false,
|
|
99
|
+
dragging: false,
|
|
100
|
+
pointerType: null,
|
|
101
|
+
pointerId: null,
|
|
102
|
+
button: null,
|
|
103
|
+
buttons: 0,
|
|
104
|
+
time: getPointerNowSeconds(),
|
|
105
|
+
downPx: null,
|
|
106
|
+
downUv: null,
|
|
107
|
+
deltaPx: [0, 0],
|
|
108
|
+
deltaUv: [0, 0],
|
|
109
|
+
velocityPx: [0, 0],
|
|
110
|
+
velocityUv: [0, 0]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Normalized coordinate payload for a pointer position against a canvas rect.
|
|
116
|
+
*/
|
|
117
|
+
export interface PointerCoordinates extends PointerPoint {
|
|
118
|
+
inside: boolean;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Converts client coordinates to canvas-relative pointer coordinates.
|
|
123
|
+
*/
|
|
124
|
+
export function getPointerCoordinates(
|
|
125
|
+
clientX: number,
|
|
126
|
+
clientY: number,
|
|
127
|
+
rect: Pick<DOMRectReadOnly, 'height' | 'left' | 'top' | 'width'>
|
|
128
|
+
): PointerCoordinates {
|
|
129
|
+
const width = Math.max(rect.width, 1);
|
|
130
|
+
const height = Math.max(rect.height, 1);
|
|
131
|
+
const nx = (clientX - rect.left) / width;
|
|
132
|
+
const ny = (clientY - rect.top) / height;
|
|
133
|
+
const pxX = clientX - rect.left;
|
|
134
|
+
const pxY = clientY - rect.top;
|
|
135
|
+
const uvX = nx;
|
|
136
|
+
const uvY = 1 - ny;
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
px: [pxX, pxY],
|
|
140
|
+
uv: [uvX, uvY],
|
|
141
|
+
ndc: [nx * 2 - 1, uvY * 2 - 1],
|
|
142
|
+
inside: nx >= 0 && nx <= 1 && ny >= 0 && ny <= 1
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Resolves frame wake-up strategy for pointer-driven updates.
|
|
148
|
+
*/
|
|
149
|
+
export function resolvePointerFrameRequestMode(
|
|
150
|
+
mode: PointerFrameRequestMode,
|
|
151
|
+
renderMode: RenderMode
|
|
152
|
+
): Exclude<PointerFrameRequestMode, 'auto'> {
|
|
153
|
+
if (mode !== 'auto') {
|
|
154
|
+
return mode;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (renderMode === 'manual') {
|
|
158
|
+
return 'advance';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (renderMode === 'on-demand') {
|
|
162
|
+
return 'invalidate';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return 'none';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Normalizes unknown pointer kind values to the public `PointerKind`.
|
|
170
|
+
*/
|
|
171
|
+
export function normalizePointerKind(pointerType: string): PointerKind {
|
|
172
|
+
if (pointerType === 'mouse' || pointerType === 'pen' || pointerType === 'touch') {
|
|
173
|
+
return pointerType;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return 'mouse';
|
|
177
|
+
}
|
package/src/lib/react/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export {
|
|
|
12
12
|
} from '../passes/index.js';
|
|
13
13
|
export { useMotionGPU } from './motiongpu-context.js';
|
|
14
14
|
export { useFrame } from './frame-context.js';
|
|
15
|
+
export { usePointer } from './use-pointer.js';
|
|
15
16
|
export { useTexture } from './use-texture.js';
|
|
16
17
|
export type {
|
|
17
18
|
FrameInvalidationToken,
|
|
@@ -56,6 +57,15 @@ export type {
|
|
|
56
57
|
} from '../core/material.js';
|
|
57
58
|
export type { MotionGPUContext } from './motiongpu-context.js';
|
|
58
59
|
export type { UseFrameOptions, UseFrameResult } from './frame-context.js';
|
|
60
|
+
export type {
|
|
61
|
+
PointerClick,
|
|
62
|
+
PointerFrameRequestMode,
|
|
63
|
+
PointerKind,
|
|
64
|
+
PointerPoint,
|
|
65
|
+
PointerState,
|
|
66
|
+
UsePointerOptions,
|
|
67
|
+
UsePointerResult
|
|
68
|
+
} from './use-pointer.js';
|
|
59
69
|
export type { TextureUrlInput, UseTextureResult } from './use-texture.js';
|
|
60
70
|
export type {
|
|
61
71
|
StorageBufferAccess,
|