Skip to content

Commit 48a4e7f

Browse files
committed
fix: align capture timing and pointer event defaults
1 parent a7fb025 commit 48a4e7f

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/motion/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ export class Motion {
5353
const changed = pointer.touch(target, point)
5454

5555
this.#dispatchTouch('touchstart', target, changed, gesture)
56-
57-
if (pointer.implicitCapture)
58-
pointer.capture(target)
5956
}
6057

6158
touchmove(pointer, point, gesture = { scale: 1, rotation: 0 }) {

src/motions/glide/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class GlideMotion extends Motion {
5656

5757
try {
5858
this.touchstart(pointer, point)
59+
pointer.capture(target)
5960

6061
for (let i = 1; i < points.length; i++) {
6162
await this.delay(points[i].createdAt - points[i - 1].createdAt)
@@ -82,4 +83,3 @@ export class GlideMotion extends Motion {
8283
}
8384
}
8485
}
85-

src/pointer/index.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ const prefixLen = (a, b) => {
1717
return i
1818
}
1919

20+
const eventDefaults = type => ({
21+
pointerover: { bubbles: true, cancelable: true, composed: true },
22+
pointerenter: { bubbles: false, cancelable: false, composed: false },
23+
pointerdown: { bubbles: true, cancelable: true, composed: true },
24+
pointermove: { bubbles: true, cancelable: true, composed: true },
25+
pointerup: { bubbles: true, cancelable: true, composed: true },
26+
pointerout: { bubbles: true, cancelable: true, composed: true },
27+
pointerleave: { bubbles: false, cancelable: false, composed: false },
28+
pointercancel: { bubbles: true, cancelable: true, composed: true },
29+
gotpointercapture: { bubbles: true, cancelable: false, composed: true },
30+
lostpointercapture: { bubbles: true, cancelable: false, composed: true },
31+
})[type] ?? { bubbles: true, cancelable: true, composed: true }
32+
2033
export class Pointer {
2134
static id = () => {
2235
const { crypto } = globalThis
@@ -136,11 +149,11 @@ export class Pointer {
136149
release(target) {
137150
if (!this.#captureTarget) return
138151

152+
this.#captureTarget = null
153+
139154
this.#dispatch('lostpointercapture', target, this.#lastPoint ?? null, {
140155
bubbles: true,
141156
})
142-
143-
this.#captureTarget = null
144157
}
145158

146159
touch(target, point) { return null }
@@ -195,6 +208,8 @@ export class Pointer {
195208
if (typeof Event !== 'function')
196209
throw new Error('PointerEvent is not available in this environment')
197210

211+
const defaults = eventDefaults(type)
212+
198213
const base = {
199214
pointerId: this.#id,
200215
pointerType: this.type,
@@ -216,13 +231,16 @@ export class Pointer {
216231
const props = this.props(i, total)
217232

218233
const movement =
219-
type === 'pointermove' && this.type === 'mouse'
234+
type === 'pointermove'
220235
? this.#movement(point)
221236
: {}
222237

223-
const init = { ...base, ...coords, ...props, ...movement, ...extra }
238+
const init = { ...defaults, ...base, ...coords, ...props, ...movement, ...extra }
224239

225240
target.dispatchEvent(new Event(type, init))
241+
242+
if (point)
243+
this.#lastPoint = point
226244
}
227245

228246
#movement(point) {

0 commit comments

Comments
 (0)