@use-gesture/core
Advanced tools
Comparing version 10.0.0-beta.6 to 10.0.0-beta.7
export declare const hoverConfigResolver: { | ||
mouseOnly: (value?: boolean) => boolean; | ||
axis(this: import("..").InternalCoordinatesOptions<import("..").CoordinatesKey>, _v: any, _k: string, { axis }: import("..").CoordinatesConfig<import("..").CoordinatesKey>): "x" | "y" | undefined; | ||
@@ -3,0 +4,0 @@ bounds(value?: import("..").DragBounds | ((state: import("..").State) => import("..").DragBounds)): HTMLElement | [import("..").Vector2, import("..").Vector2] | (() => EventTarget | null); |
export declare const moveConfigResolver: { | ||
mouseOnly: (value?: boolean) => boolean; | ||
axis(this: import("..").InternalCoordinatesOptions<import("..").CoordinatesKey>, _v: any, _k: string, { axis }: import("..").CoordinatesConfig<import("..").CoordinatesKey>): "x" | "y" | undefined; | ||
@@ -3,0 +4,0 @@ bounds(value?: import("..").DragBounds | ((state: import("..").State) => import("..").DragBounds)): HTMLElement | [import("..").Vector2, import("..").Vector2] | (() => EventTarget | null); |
@@ -105,2 +105,10 @@ /// <reference types="react" /> | ||
export declare type DragBounds = Bounds | HTMLElement | React.RefObject<HTMLElement>; | ||
declare type MoveAndHoverMouseOnly = { | ||
/** | ||
* If false, onMove or onHover handlers will also fire on touch devices. | ||
*/ | ||
mouseOnly?: boolean; | ||
}; | ||
export declare type MoveConfig = CoordinatesConfig<'move'> & MoveAndHoverMouseOnly; | ||
export declare type HoverConfig = MoveAndHoverMouseOnly; | ||
export declare type DragConfig = CoordinatesConfig<'drag'> & { | ||
@@ -168,4 +176,4 @@ /** | ||
export declare type UserScrollConfig = GenericOptions & CoordinatesConfig<'scroll'>; | ||
export declare type UserMoveConfig = GenericOptions & CoordinatesConfig<'move'>; | ||
export declare type UserHoverConfig = GenericOptions; | ||
export declare type UserMoveConfig = GenericOptions & MoveConfig; | ||
export declare type UserHoverConfig = GenericOptions & HoverConfig; | ||
export declare type UserGestureConfig = GenericOptions & { | ||
@@ -175,7 +183,8 @@ drag?: DragConfig; | ||
scroll?: CoordinatesConfig<'scroll'>; | ||
move?: CoordinatesConfig<'move'>; | ||
move?: MoveConfig; | ||
pinch?: PinchConfig; | ||
hover?: { | ||
enabled?: boolean; | ||
}; | ||
} & HoverConfig; | ||
}; | ||
export {}; |
@@ -46,2 +46,5 @@ import { GestureKey, CoordinatesKey } from './config'; | ||
}; | ||
declare type MoveAndHoverMouseOnly = { | ||
mouseOnly: boolean; | ||
}; | ||
export declare type InternalConfig = { | ||
@@ -52,5 +55,6 @@ shared: InternalGenericOptions; | ||
scroll?: InternalCoordinatesOptions<'scroll'>; | ||
move?: InternalCoordinatesOptions<'move'>; | ||
move?: InternalCoordinatesOptions<'move'> & MoveAndHoverMouseOnly; | ||
hover?: InternalCoordinatesOptions<'hover'> & MoveAndHoverMouseOnly; | ||
pinch?: InternalPinchOptions; | ||
hover?: InternalCoordinatesOptions<'hover'>; | ||
}; | ||
export {}; |
@@ -5,2 +5,4 @@ 'use strict'; | ||
var maths = require('./maths-125ca19a.cjs.dev.js'); | ||
function _defineProperty(obj, key, value) { | ||
@@ -605,47 +607,2 @@ if (key in obj) { | ||
function clamp(v, min, max) { | ||
return Math.max(min, Math.min(v, max)); | ||
} | ||
const V = { | ||
toVector(v, fallback) { | ||
if (v === undefined) v = fallback; | ||
return Array.isArray(v) ? v : [v, v]; | ||
}, | ||
add(v1, v2) { | ||
return [v1[0] + v2[0], v1[1] + v2[1]]; | ||
}, | ||
sub(v1, v2) { | ||
return [v1[0] - v2[0], v1[1] - v2[1]]; | ||
}, | ||
addTo(v1, v2) { | ||
v1[0] += v2[0]; | ||
v1[1] += v2[1]; | ||
}, | ||
subTo(v1, v2) { | ||
v1[0] -= v2[0]; | ||
v1[1] -= v2[1]; | ||
} | ||
}; | ||
function rubberband(distance, dimension, constant) { | ||
if (dimension === 0 || Math.abs(dimension) === Infinity) return Math.pow(distance, constant * 5); | ||
return distance * dimension * constant / (dimension + constant * distance); | ||
} | ||
function rubberbandIfOutOfBounds(position, min, max, constant = 0.15) { | ||
if (constant === 0) return clamp(position, min, max); | ||
if (position < min) return -rubberband(min - position, max - min, constant) + min; | ||
if (position > max) return +rubberband(position - max, max - min, constant) + max; | ||
return position; | ||
} | ||
function computeRubberband(bounds, [Vx, Vy], [Rx, Ry]) { | ||
const [[X0, X1], [Y0, Y1]] = bounds; | ||
return [rubberbandIfOutOfBounds(Vx, X0, X1, Rx), rubberbandIfOutOfBounds(Vy, Y0, Y1, Ry)]; | ||
} | ||
class Engine { | ||
@@ -716,3 +673,3 @@ constructor(ctrl, args, key) { | ||
state._delta = [0, 0]; | ||
state._threshold = V.sub(transform(threshold), transform([0, 0])).map(Math.abs); | ||
state._threshold = maths.V.sub(transform(threshold), transform([0, 0])).map(Math.abs); | ||
state._bounds = [[-Infinity, Infinity], [-Infinity, Infinity]]; | ||
@@ -760,3 +717,3 @@ state.axis = undefined; | ||
Object.assign(shared, getEventDetails(event)); | ||
shared.down = shared.pressed = shared.buttons > 0 || shared.touches > 0; | ||
shared.down = shared.pressed = shared.buttons % 2 === 1 || shared.touches > 0; | ||
dt = event.timeStamp - state.timeStamp; | ||
@@ -770,3 +727,3 @@ state.timeStamp = event.timeStamp; | ||
V.addTo(state._distance, _absoluteDelta); | ||
maths.V.addTo(state._distance, _absoluteDelta); | ||
} | ||
@@ -803,5 +760,5 @@ | ||
if (!state.last) { | ||
state.delta = V.sub(movement, previousMovement); | ||
state.delta = maths.V.sub(movement, previousMovement); | ||
const absoluteDelta = state.delta.map(Math.abs); | ||
V.addTo(state.distance, absoluteDelta); | ||
maths.V.addTo(state.distance, absoluteDelta); | ||
state.direction = state.delta.map(Math.sign); | ||
@@ -817,3 +774,3 @@ | ||
const rubberband = state._active ? config.rubberband || [0, 0] : [0, 0]; | ||
state.offset = computeRubberband(state._bounds, state.offset, rubberband); | ||
state.offset = maths.computeRubberband(state._bounds, state.offset, rubberband); | ||
this.computeMovement(); | ||
@@ -870,7 +827,7 @@ } | ||
computeOffset() { | ||
this.state.offset = V.add(this.state.lastOffset, this.state.movement); | ||
this.state.offset = maths.V.add(this.state.lastOffset, this.state.movement); | ||
} | ||
computeMovement() { | ||
this.state.movement = V.sub(this.state.offset, this.state.lastOffset); | ||
this.state.movement = maths.V.sub(this.state.offset, this.state.lastOffset); | ||
this.state.xy = this.state.values; | ||
@@ -910,3 +867,3 @@ } | ||
default: | ||
return V.toVector(value); | ||
return maths.V.toVector(value); | ||
} | ||
@@ -917,3 +874,3 @@ }, | ||
if (typeof value === 'function') return value; | ||
if (value != null) return V.toVector(value); | ||
if (value != null) return maths.V.toVector(value); | ||
}, | ||
@@ -1050,2 +1007,3 @@ | ||
pointerDown(event) { | ||
if (event.buttons != null && event.buttons % 2 !== 1) return; | ||
this.ctrl.setEventIds(event); | ||
@@ -1096,7 +1054,7 @@ | ||
} else { | ||
state._delta = V.sub(values, state.values); | ||
state._delta = maths.V.sub(values, state.values); | ||
state.values = values; | ||
} | ||
V.addTo(state._movement, state._delta); | ||
maths.V.addTo(state._movement, state._delta); | ||
this.compute(event); | ||
@@ -1244,3 +1202,3 @@ | ||
state._keyboardActive = true; | ||
V.addTo(state._movement, state._delta); | ||
maths.V.addTo(state._movement, state._delta); | ||
this.compute(event); | ||
@@ -1266,2 +1224,3 @@ this.emit(); | ||
bindFunction(device, 'end', this.pointerUp.bind(this)); | ||
bindFunction(device, 'cancel', this.pointerUp.bind(this)); | ||
} | ||
@@ -1324,3 +1283,3 @@ | ||
}) { | ||
const threshold = V.toVector(value, filterTaps ? 3 : axis ? 1 : 0); | ||
const threshold = maths.V.toVector(value, filterTaps ? 3 : axis ? 1 : 0); | ||
this.filterTaps = filterTaps; | ||
@@ -1336,4 +1295,4 @@ return threshold; | ||
return { | ||
velocity: this.transform(V.toVector(velocity)), | ||
distance: this.transform(V.toVector(distance)), | ||
velocity: this.transform(maths.V.toVector(velocity)), | ||
distance: this.transform(maths.V.toVector(distance)), | ||
duration | ||
@@ -1475,2 +1434,3 @@ }; | ||
pointerStart(event) { | ||
if (event.buttons != null && event.buttons % 2 !== 1) return; | ||
this.ctrl.setEventIds(event); | ||
@@ -1588,3 +1548,3 @@ event.target.setPointerCapture(event.pointerId); | ||
state._movement = [event.scale - 1, event.rotation]; | ||
state._delta = V.sub(state._movement, _previousMovement); | ||
state._delta = maths.V.sub(state._movement, _previousMovement); | ||
this.compute(event); | ||
@@ -1627,3 +1587,3 @@ this.emit(); | ||
state._delta = [-wheelValues(event)[1] / PINCH_WHEEL_RATIO, 0]; | ||
V.addTo(state._movement, state._delta); | ||
maths.V.addTo(state._movement, state._delta); | ||
this.state.origin = [event.clientX, event.clientY]; | ||
@@ -1700,3 +1660,3 @@ this.compute(event); | ||
this.lockDirection = config.axis === 'lock'; | ||
const threshold = V.toVector(value, this.lockDirection ? [0.1, 3] : 0); | ||
const threshold = maths.V.toVector(value, this.lockDirection ? [0.1, 3] : 0); | ||
return threshold; | ||
@@ -1724,3 +1684,3 @@ } | ||
state._delta = wheelValues(event); | ||
V.addTo(this.state._movement, state._delta); | ||
maths.V.addTo(this.state._movement, state._delta); | ||
this.compute(event); | ||
@@ -1762,4 +1722,4 @@ this.emit(); | ||
const values = scrollValues(event); | ||
state._delta = V.sub(values, state.values); | ||
V.addTo(state._movement, state._delta); | ||
state._delta = maths.V.sub(values, state.values); | ||
maths.V.addTo(state._movement, state._delta); | ||
state.values = values; | ||
@@ -1793,2 +1753,3 @@ this.compute(event); | ||
move(event) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return; | ||
if (!this.state._active) this.moveStart(event);else this.moveChange(event); | ||
@@ -1811,4 +1772,4 @@ this.timeoutStore.add('moveEnd', this.moveEnd.bind(this)); | ||
const state = this.state; | ||
state._delta = V.sub(values, state.values); | ||
V.addTo(state._movement, state._delta); | ||
state._delta = maths.V.sub(values, state.values); | ||
maths.V.addTo(state._movement, state._delta); | ||
state.values = values; | ||
@@ -1827,4 +1788,4 @@ this.compute(event); | ||
bind(bindFunction) { | ||
bindFunction('mouse', 'change', this.move.bind(this)); | ||
bindFunction('mouse', 'leave', this.moveEnd.bind(this)); | ||
bindFunction('pointer', 'change', this.move.bind(this)); | ||
bindFunction('pointer', 'leave', this.moveEnd.bind(this)); | ||
} | ||
@@ -1834,3 +1795,5 @@ | ||
const moveConfigResolver = coordinatesConfigResolver; | ||
const moveConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, { | ||
mouseOnly: (value = true) => value | ||
}); | ||
@@ -1845,2 +1808,3 @@ class HoverEngine extends CoordinatesEngine { | ||
enter(event) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return; | ||
this.start(event); | ||
@@ -1853,2 +1817,3 @@ this.state.values = pointerValues(event); | ||
leave(event) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return; | ||
const state = this.state; | ||
@@ -1858,3 +1823,3 @@ if (!state._active) return; | ||
const values = pointerValues(event); | ||
state._movement = state._delta = V.sub(values, state.values); | ||
state._movement = state._delta = maths.V.sub(values, state.values); | ||
state.values = values; | ||
@@ -1867,4 +1832,4 @@ this.compute(event); | ||
bind(bindFunction) { | ||
bindFunction('mouse', 'enter', this.enter.bind(this)); | ||
bindFunction('mouse', 'leave', this.leave.bind(this)); | ||
bindFunction('pointer', 'enter', this.enter.bind(this)); | ||
bindFunction('pointer', 'leave', this.leave.bind(this)); | ||
} | ||
@@ -1874,3 +1839,5 @@ | ||
const hoverConfigResolver = coordinatesConfigResolver; | ||
const hoverConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, { | ||
mouseOnly: (value = true) => value | ||
}); | ||
@@ -1877,0 +1844,0 @@ exports.Controller = Controller; |
@@ -5,2 +5,4 @@ 'use strict'; | ||
var maths = require('./maths-a42ecce1.cjs.prod.js'); | ||
function _defineProperty(obj, key, value) { | ||
@@ -605,47 +607,2 @@ if (key in obj) { | ||
function clamp(v, min, max) { | ||
return Math.max(min, Math.min(v, max)); | ||
} | ||
const V = { | ||
toVector(v, fallback) { | ||
if (v === undefined) v = fallback; | ||
return Array.isArray(v) ? v : [v, v]; | ||
}, | ||
add(v1, v2) { | ||
return [v1[0] + v2[0], v1[1] + v2[1]]; | ||
}, | ||
sub(v1, v2) { | ||
return [v1[0] - v2[0], v1[1] - v2[1]]; | ||
}, | ||
addTo(v1, v2) { | ||
v1[0] += v2[0]; | ||
v1[1] += v2[1]; | ||
}, | ||
subTo(v1, v2) { | ||
v1[0] -= v2[0]; | ||
v1[1] -= v2[1]; | ||
} | ||
}; | ||
function rubberband(distance, dimension, constant) { | ||
if (dimension === 0 || Math.abs(dimension) === Infinity) return Math.pow(distance, constant * 5); | ||
return distance * dimension * constant / (dimension + constant * distance); | ||
} | ||
function rubberbandIfOutOfBounds(position, min, max, constant = 0.15) { | ||
if (constant === 0) return clamp(position, min, max); | ||
if (position < min) return -rubberband(min - position, max - min, constant) + min; | ||
if (position > max) return +rubberband(position - max, max - min, constant) + max; | ||
return position; | ||
} | ||
function computeRubberband(bounds, [Vx, Vy], [Rx, Ry]) { | ||
const [[X0, X1], [Y0, Y1]] = bounds; | ||
return [rubberbandIfOutOfBounds(Vx, X0, X1, Rx), rubberbandIfOutOfBounds(Vy, Y0, Y1, Ry)]; | ||
} | ||
class Engine { | ||
@@ -716,3 +673,3 @@ constructor(ctrl, args, key) { | ||
state._delta = [0, 0]; | ||
state._threshold = V.sub(transform(threshold), transform([0, 0])).map(Math.abs); | ||
state._threshold = maths.V.sub(transform(threshold), transform([0, 0])).map(Math.abs); | ||
state._bounds = [[-Infinity, Infinity], [-Infinity, Infinity]]; | ||
@@ -760,3 +717,3 @@ state.axis = undefined; | ||
Object.assign(shared, getEventDetails(event)); | ||
shared.down = shared.pressed = shared.buttons > 0 || shared.touches > 0; | ||
shared.down = shared.pressed = shared.buttons % 2 === 1 || shared.touches > 0; | ||
dt = event.timeStamp - state.timeStamp; | ||
@@ -770,3 +727,3 @@ state.timeStamp = event.timeStamp; | ||
V.addTo(state._distance, _absoluteDelta); | ||
maths.V.addTo(state._distance, _absoluteDelta); | ||
} | ||
@@ -803,5 +760,5 @@ | ||
if (!state.last) { | ||
state.delta = V.sub(movement, previousMovement); | ||
state.delta = maths.V.sub(movement, previousMovement); | ||
const absoluteDelta = state.delta.map(Math.abs); | ||
V.addTo(state.distance, absoluteDelta); | ||
maths.V.addTo(state.distance, absoluteDelta); | ||
state.direction = state.delta.map(Math.sign); | ||
@@ -817,3 +774,3 @@ | ||
const rubberband = state._active ? config.rubberband || [0, 0] : [0, 0]; | ||
state.offset = computeRubberband(state._bounds, state.offset, rubberband); | ||
state.offset = maths.computeRubberband(state._bounds, state.offset, rubberband); | ||
this.computeMovement(); | ||
@@ -870,7 +827,7 @@ } | ||
computeOffset() { | ||
this.state.offset = V.add(this.state.lastOffset, this.state.movement); | ||
this.state.offset = maths.V.add(this.state.lastOffset, this.state.movement); | ||
} | ||
computeMovement() { | ||
this.state.movement = V.sub(this.state.offset, this.state.lastOffset); | ||
this.state.movement = maths.V.sub(this.state.offset, this.state.lastOffset); | ||
this.state.xy = this.state.values; | ||
@@ -910,3 +867,3 @@ } | ||
default: | ||
return V.toVector(value); | ||
return maths.V.toVector(value); | ||
} | ||
@@ -917,3 +874,3 @@ }, | ||
if (typeof value === 'function') return value; | ||
if (value != null) return V.toVector(value); | ||
if (value != null) return maths.V.toVector(value); | ||
}, | ||
@@ -1027,2 +984,3 @@ | ||
pointerDown(event) { | ||
if (event.buttons != null && event.buttons % 2 !== 1) return; | ||
this.ctrl.setEventIds(event); | ||
@@ -1073,7 +1031,7 @@ | ||
} else { | ||
state._delta = V.sub(values, state.values); | ||
state._delta = maths.V.sub(values, state.values); | ||
state.values = values; | ||
} | ||
V.addTo(state._movement, state._delta); | ||
maths.V.addTo(state._movement, state._delta); | ||
this.compute(event); | ||
@@ -1205,3 +1163,3 @@ | ||
state._keyboardActive = true; | ||
V.addTo(state._movement, state._delta); | ||
maths.V.addTo(state._movement, state._delta); | ||
this.compute(event); | ||
@@ -1227,2 +1185,3 @@ this.emit(); | ||
bindFunction(device, 'end', this.pointerUp.bind(this)); | ||
bindFunction(device, 'cancel', this.pointerUp.bind(this)); | ||
} | ||
@@ -1285,3 +1244,3 @@ | ||
}) { | ||
const threshold = V.toVector(value, filterTaps ? 3 : axis ? 1 : 0); | ||
const threshold = maths.V.toVector(value, filterTaps ? 3 : axis ? 1 : 0); | ||
this.filterTaps = filterTaps; | ||
@@ -1297,4 +1256,4 @@ return threshold; | ||
return { | ||
velocity: this.transform(V.toVector(velocity)), | ||
distance: this.transform(V.toVector(distance)), | ||
velocity: this.transform(maths.V.toVector(velocity)), | ||
distance: this.transform(maths.V.toVector(distance)), | ||
duration | ||
@@ -1401,2 +1360,3 @@ }; | ||
pointerStart(event) { | ||
if (event.buttons != null && event.buttons % 2 !== 1) return; | ||
this.ctrl.setEventIds(event); | ||
@@ -1514,3 +1474,3 @@ event.target.setPointerCapture(event.pointerId); | ||
state._movement = [event.scale - 1, event.rotation]; | ||
state._delta = V.sub(state._movement, _previousMovement); | ||
state._delta = maths.V.sub(state._movement, _previousMovement); | ||
this.compute(event); | ||
@@ -1549,3 +1509,3 @@ this.emit(); | ||
state._delta = [-wheelValues(event)[1] / PINCH_WHEEL_RATIO, 0]; | ||
V.addTo(state._movement, state._delta); | ||
maths.V.addTo(state._movement, state._delta); | ||
this.state.origin = [event.clientX, event.clientY]; | ||
@@ -1622,3 +1582,3 @@ this.compute(event); | ||
this.lockDirection = config.axis === 'lock'; | ||
const threshold = V.toVector(value, this.lockDirection ? [0.1, 3] : 0); | ||
const threshold = maths.V.toVector(value, this.lockDirection ? [0.1, 3] : 0); | ||
return threshold; | ||
@@ -1646,3 +1606,3 @@ } | ||
state._delta = wheelValues(event); | ||
V.addTo(this.state._movement, state._delta); | ||
maths.V.addTo(this.state._movement, state._delta); | ||
this.compute(event); | ||
@@ -1684,4 +1644,4 @@ this.emit(); | ||
const values = scrollValues(event); | ||
state._delta = V.sub(values, state.values); | ||
V.addTo(state._movement, state._delta); | ||
state._delta = maths.V.sub(values, state.values); | ||
maths.V.addTo(state._movement, state._delta); | ||
state.values = values; | ||
@@ -1715,2 +1675,3 @@ this.compute(event); | ||
move(event) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return; | ||
if (!this.state._active) this.moveStart(event);else this.moveChange(event); | ||
@@ -1733,4 +1694,4 @@ this.timeoutStore.add('moveEnd', this.moveEnd.bind(this)); | ||
const state = this.state; | ||
state._delta = V.sub(values, state.values); | ||
V.addTo(state._movement, state._delta); | ||
state._delta = maths.V.sub(values, state.values); | ||
maths.V.addTo(state._movement, state._delta); | ||
state.values = values; | ||
@@ -1749,4 +1710,4 @@ this.compute(event); | ||
bind(bindFunction) { | ||
bindFunction('mouse', 'change', this.move.bind(this)); | ||
bindFunction('mouse', 'leave', this.moveEnd.bind(this)); | ||
bindFunction('pointer', 'change', this.move.bind(this)); | ||
bindFunction('pointer', 'leave', this.moveEnd.bind(this)); | ||
} | ||
@@ -1756,3 +1717,5 @@ | ||
const moveConfigResolver = coordinatesConfigResolver; | ||
const moveConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, { | ||
mouseOnly: (value = true) => value | ||
}); | ||
@@ -1767,2 +1730,3 @@ class HoverEngine extends CoordinatesEngine { | ||
enter(event) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return; | ||
this.start(event); | ||
@@ -1775,2 +1739,3 @@ this.state.values = pointerValues(event); | ||
leave(event) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return; | ||
const state = this.state; | ||
@@ -1780,3 +1745,3 @@ if (!state._active) return; | ||
const values = pointerValues(event); | ||
state._movement = state._delta = V.sub(values, state.values); | ||
state._movement = state._delta = maths.V.sub(values, state.values); | ||
state.values = values; | ||
@@ -1789,4 +1754,4 @@ this.compute(event); | ||
bind(bindFunction) { | ||
bindFunction('mouse', 'enter', this.enter.bind(this)); | ||
bindFunction('mouse', 'leave', this.leave.bind(this)); | ||
bindFunction('pointer', 'enter', this.enter.bind(this)); | ||
bindFunction('pointer', 'leave', this.leave.bind(this)); | ||
} | ||
@@ -1796,3 +1761,5 @@ | ||
const hoverConfigResolver = coordinatesConfigResolver; | ||
const hoverConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, { | ||
mouseOnly: (value = true) => value | ||
}); | ||
@@ -1799,0 +1766,0 @@ exports.Controller = Controller; |
@@ -0,1 +1,3 @@ | ||
import { V, c as computeRubberband } from './maths-b2a210f4.esm.js'; | ||
function _defineProperty(obj, key, value) { | ||
@@ -600,47 +602,2 @@ if (key in obj) { | ||
function clamp(v, min, max) { | ||
return Math.max(min, Math.min(v, max)); | ||
} | ||
const V = { | ||
toVector(v, fallback) { | ||
if (v === undefined) v = fallback; | ||
return Array.isArray(v) ? v : [v, v]; | ||
}, | ||
add(v1, v2) { | ||
return [v1[0] + v2[0], v1[1] + v2[1]]; | ||
}, | ||
sub(v1, v2) { | ||
return [v1[0] - v2[0], v1[1] - v2[1]]; | ||
}, | ||
addTo(v1, v2) { | ||
v1[0] += v2[0]; | ||
v1[1] += v2[1]; | ||
}, | ||
subTo(v1, v2) { | ||
v1[0] -= v2[0]; | ||
v1[1] -= v2[1]; | ||
} | ||
}; | ||
function rubberband(distance, dimension, constant) { | ||
if (dimension === 0 || Math.abs(dimension) === Infinity) return Math.pow(distance, constant * 5); | ||
return distance * dimension * constant / (dimension + constant * distance); | ||
} | ||
function rubberbandIfOutOfBounds(position, min, max, constant = 0.15) { | ||
if (constant === 0) return clamp(position, min, max); | ||
if (position < min) return -rubberband(min - position, max - min, constant) + min; | ||
if (position > max) return +rubberband(position - max, max - min, constant) + max; | ||
return position; | ||
} | ||
function computeRubberband(bounds, [Vx, Vy], [Rx, Ry]) { | ||
const [[X0, X1], [Y0, Y1]] = bounds; | ||
return [rubberbandIfOutOfBounds(Vx, X0, X1, Rx), rubberbandIfOutOfBounds(Vy, Y0, Y1, Ry)]; | ||
} | ||
class Engine { | ||
@@ -754,3 +711,3 @@ constructor(ctrl, args, key) { | ||
Object.assign(shared, getEventDetails(event)); | ||
shared.down = shared.pressed = shared.buttons > 0 || shared.touches > 0; | ||
shared.down = shared.pressed = shared.buttons % 2 === 1 || shared.touches > 0; | ||
dt = event.timeStamp - state.timeStamp; | ||
@@ -1038,2 +995,3 @@ state.timeStamp = event.timeStamp; | ||
pointerDown(event) { | ||
if (event.buttons != null && event.buttons % 2 !== 1) return; | ||
this.ctrl.setEventIds(event); | ||
@@ -1252,2 +1210,3 @@ | ||
bindFunction(device, 'end', this.pointerUp.bind(this)); | ||
bindFunction(device, 'cancel', this.pointerUp.bind(this)); | ||
} | ||
@@ -1459,2 +1418,3 @@ | ||
pointerStart(event) { | ||
if (event.buttons != null && event.buttons % 2 !== 1) return; | ||
this.ctrl.setEventIds(event); | ||
@@ -1772,2 +1732,3 @@ event.target.setPointerCapture(event.pointerId); | ||
move(event) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return; | ||
if (!this.state._active) this.moveStart(event);else this.moveChange(event); | ||
@@ -1805,4 +1766,4 @@ this.timeoutStore.add('moveEnd', this.moveEnd.bind(this)); | ||
bind(bindFunction) { | ||
bindFunction('mouse', 'change', this.move.bind(this)); | ||
bindFunction('mouse', 'leave', this.moveEnd.bind(this)); | ||
bindFunction('pointer', 'change', this.move.bind(this)); | ||
bindFunction('pointer', 'leave', this.moveEnd.bind(this)); | ||
} | ||
@@ -1812,3 +1773,5 @@ | ||
const moveConfigResolver = coordinatesConfigResolver; | ||
const moveConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, { | ||
mouseOnly: (value = true) => value | ||
}); | ||
@@ -1823,2 +1786,3 @@ class HoverEngine extends CoordinatesEngine { | ||
enter(event) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return; | ||
this.start(event); | ||
@@ -1831,2 +1795,3 @@ this.state.values = pointerValues(event); | ||
leave(event) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return; | ||
const state = this.state; | ||
@@ -1844,4 +1809,4 @@ if (!state._active) return; | ||
bind(bindFunction) { | ||
bindFunction('mouse', 'enter', this.enter.bind(this)); | ||
bindFunction('mouse', 'leave', this.leave.bind(this)); | ||
bindFunction('pointer', 'enter', this.enter.bind(this)); | ||
bindFunction('pointer', 'leave', this.leave.bind(this)); | ||
} | ||
@@ -1851,4 +1816,6 @@ | ||
const hoverConfigResolver = coordinatesConfigResolver; | ||
const hoverConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, { | ||
mouseOnly: (value = true) => value | ||
}); | ||
export { Controller, DragEngine, HoverEngine, MoveEngine, PinchEngine, ScrollEngine, WheelEngine, dragConfigResolver, hoverConfigResolver, moveConfigResolver, parseMergedHandlers, pinchConfigResolver, registerEngine, scrollConfigResolver, wheelConfigResolver }; |
{ | ||
"name": "@use-gesture/core", | ||
"version": "10.0.0-beta.6", | ||
"version": "10.0.0-beta.7", | ||
"description": "Core engine for receiving gestures", | ||
@@ -9,2 +9,8 @@ "license": "MIT", | ||
"sideEffects": false, | ||
"preconstruct": { | ||
"entrypoints": [ | ||
"./index.ts", | ||
"./utils.ts" | ||
] | ||
}, | ||
"repository": { | ||
@@ -11,0 +17,0 @@ "type": "git", |
import { coordinatesConfigResolver } from './coordinatesConfigResolver' | ||
export const hoverConfigResolver = coordinatesConfigResolver | ||
export const hoverConfigResolver = { | ||
...coordinatesConfigResolver, | ||
mouseOnly: (value = true) => value | ||
} |
import { coordinatesConfigResolver } from './coordinatesConfigResolver' | ||
export const moveConfigResolver = coordinatesConfigResolver | ||
export const moveConfigResolver = { | ||
...coordinatesConfigResolver, | ||
mouseOnly: (value = true) => value | ||
} |
@@ -75,2 +75,3 @@ import { CoordinatesEngine } from './CoordinatesEngine' | ||
pointerDown(event: PointerEvent) { | ||
if (event.buttons != null && event.buttons % 2 !== 1) return | ||
this.ctrl.setEventIds(event) | ||
@@ -305,2 +306,3 @@ // We need to capture all pointer ids so that we can keep track of them when | ||
bindFunction(device, 'end', this.pointerUp.bind(this)) | ||
bindFunction(device, 'cancel', this.pointerUp.bind(this)) | ||
} | ||
@@ -307,0 +309,0 @@ bindFunction('key', 'down', this.keyDown.bind(this)) |
@@ -188,3 +188,3 @@ import { Controller } from '../Controller' | ||
Object.assign(shared, getEventDetails(event)) | ||
shared.down = shared.pressed = shared.buttons > 0 || shared.touches > 0 | ||
shared.down = shared.pressed = shared.buttons % 2 === 1 || shared.touches > 0 | ||
@@ -191,0 +191,0 @@ // sets time stamps |
@@ -9,2 +9,3 @@ import { CoordinatesEngine } from './CoordinatesEngine' | ||
enter(event: PointerEvent) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return | ||
this.start(event) | ||
@@ -18,2 +19,3 @@ this.state.values = pointerValues(event) | ||
leave(event: PointerEvent) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return | ||
const state = this.state | ||
@@ -32,5 +34,5 @@ if (!state._active) return | ||
bind(bindFunction: any) { | ||
bindFunction('mouse', 'enter', this.enter.bind(this)) | ||
bindFunction('mouse', 'leave', this.leave.bind(this)) | ||
bindFunction('pointer', 'enter', this.enter.bind(this)) | ||
bindFunction('pointer', 'leave', this.leave.bind(this)) | ||
} | ||
} |
@@ -9,2 +9,3 @@ import { CoordinatesEngine } from './CoordinatesEngine' | ||
move(event: PointerEvent) { | ||
if (this.config.mouseOnly && event.pointerType !== 'mouse') return | ||
if (!this.state._active) this.moveStart(event) | ||
@@ -44,5 +45,5 @@ else this.moveChange(event) | ||
bind(bindFunction: any) { | ||
bindFunction('mouse', 'change', this.move.bind(this)) | ||
bindFunction('mouse', 'leave', this.moveEnd.bind(this)) | ||
bindFunction('pointer', 'change', this.move.bind(this)) | ||
bindFunction('pointer', 'leave', this.moveEnd.bind(this)) | ||
} | ||
} |
@@ -90,2 +90,3 @@ import { Engine } from './Engine' | ||
pointerStart(event: PointerEvent) { | ||
if (event.buttons != null && event.buttons % 2 !== 1) return | ||
this.ctrl.setEventIds(event) | ||
@@ -92,0 +93,0 @@ ;(event.target as HTMLElement).setPointerCapture(event.pointerId) |
@@ -110,2 +110,13 @@ import { State } from './state' | ||
type MoveAndHoverMouseOnly = { | ||
/** | ||
* If false, onMove or onHover handlers will also fire on touch devices. | ||
*/ | ||
mouseOnly?: boolean | ||
} | ||
export type MoveConfig = CoordinatesConfig<'move'> & MoveAndHoverMouseOnly | ||
export type HoverConfig = MoveAndHoverMouseOnly | ||
export type DragConfig = CoordinatesConfig<'drag'> & { | ||
@@ -174,4 +185,4 @@ /** | ||
export type UserScrollConfig = GenericOptions & CoordinatesConfig<'scroll'> | ||
export type UserMoveConfig = GenericOptions & CoordinatesConfig<'move'> | ||
export type UserHoverConfig = GenericOptions | ||
export type UserMoveConfig = GenericOptions & MoveConfig | ||
export type UserHoverConfig = GenericOptions & HoverConfig | ||
@@ -182,5 +193,5 @@ export type UserGestureConfig = GenericOptions & { | ||
scroll?: CoordinatesConfig<'scroll'> | ||
move?: CoordinatesConfig<'move'> | ||
move?: MoveConfig | ||
pinch?: PinchConfig | ||
hover?: { enabled?: boolean } | ||
hover?: { enabled?: boolean } & HoverConfig | ||
} |
@@ -52,2 +52,6 @@ import { GestureKey, CoordinatesKey } from './config' | ||
type MoveAndHoverMouseOnly = { | ||
mouseOnly: boolean | ||
} | ||
export type InternalConfig = { | ||
@@ -58,5 +62,5 @@ shared: InternalGenericOptions | ||
scroll?: InternalCoordinatesOptions<'scroll'> | ||
move?: InternalCoordinatesOptions<'move'> | ||
move?: InternalCoordinatesOptions<'move'> & MoveAndHoverMouseOnly | ||
hover?: InternalCoordinatesOptions<'hover'> & MoveAndHoverMouseOnly | ||
pinch?: InternalPinchOptions | ||
hover?: InternalCoordinatesOptions<'hover'> | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
264192
83
7938
12