Socket
Socket
Sign inDemoInstall

@use-gesture/core

Package Overview
Dependencies
0
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 10.0.0-beta.2 to 10.0.0-beta.3

2

dist/declarations/src/imports.d.ts

@@ -10,3 +10,3 @@ import { ResolverMap } from './config/resolver';

export declare const ConfigResolverMap: Map<GestureKey, ResolverMap>;
export declare function registerEngine<Key extends GestureKey>(action: Key, Engine: EngineClass<Key>): void;
export declare function registerEngine<Key extends GestureKey>(action: Key, Engine: EngineClass<Key>, resolver: ResolverMap): void;
export declare function parseMergedHandlers(mergedHandlers: GestureHandlers, mergedConfig: UserGestureConfig): {

@@ -13,0 +13,0 @@ handlers: {};

export { Controller } from './Controller';
export { DragEngine } from './engines/DragEngine';
export { dragConfigResolver } from './config/dragConfigResolver';
export { PinchEngine } from './engines/PinchEngine';
export { pinchConfigResolver } from './config/pinchConfigResolver';
export { WheelEngine } from './engines/WheelEngine';
export { wheelConfigResolver } from './config/wheelConfigResolver';
export { ScrollEngine } from './engines/ScrollEngine';
export { scrollConfigResolver } from './config/scrollConfigResolver';
export { MoveEngine } from './engines/MoveEngine';
export { moveConfigResolver } from './config/moveConfigResolver';
export { HoverEngine } from './engines/HoverEngine';
export { hoverConfigResolver } from './config/hoverConfigResolver';
export { registerEngine, parseMergedHandlers } from './imports';
export * from './types';

@@ -60,4 +60,5 @@ 'use strict';

const ConfigResolverMap = new Map();
function registerEngine(action, Engine) {
function registerEngine(action, Engine, resolver) {
EngineMap.set(action, Engine);
ConfigResolverMap.set(action, resolver);
}

@@ -852,2 +853,21 @@ const RE_NOT_NATIVE = /^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;

function selectAxis([dx, dy]) {
const d = Math.abs(dx) - Math.abs(dy);
if (d > 0) return 'x';
if (d < 0) return 'y';
return undefined;
}
function restrictVectorToAxis(v, axis) {
switch (axis) {
case 'x':
v[1] = 0;
break;
case 'y':
v[0] = 0;
break;
}
}
class CoordinatesEngine extends Engine {

@@ -865,12 +885,7 @@ reset() {

computeOffset() {
const state = this.state;
state.offset = V.add(state.lastOffset, state.movement);
this.state.offset = V.add(this.state.lastOffset, this.state.movement);
}
computeMovement() {
const {
offset,
lastOffset
} = this.state;
this.state.movement = V.sub(offset, lastOffset);
this.state.movement = V.sub(this.state.offset, this.state.lastOffset);
this.state.xy = this.state.values;

@@ -880,26 +895,9 @@ }

intent(v) {
const state = this.state;
this.state.axis = this.state.axis || selectAxis(v);
this.state._blocked = (this.config.lockDirection || !!this.config.axis) && !this.state.axis || !!this.config.axis && this.config.axis !== this.state.axis;
if (this.state._blocked) return;
if (!state.axis) {
const axisMovementDifference = Math.abs(v[0]) - Math.abs(v[1]);
if (axisMovementDifference < 0) state.axis = 'y';else if (axisMovementDifference > 0) state.axis = 'x';
if (this.config.axis || this.config.lockDirection) {
restrictVectorToAxis(v, this.state.axis);
}
const axis = state.axis;
if (this.config.lockDirection) {
if (axis) {
state._blocked = false;
if (axis === 'x') v[1] = 0;else if (axis === 'y') v[0] = 0;
} else {
state._blocked = false;
}
} else if (this.config.axis) {
if (!!axis && axis === this.config.axis) {
state._blocked = false;
if (axis === 'x') v[1] = 0;else if (axis === 'y') v[0] = 0;
} else {
state._blocked = true;
}
}
}

@@ -998,110 +996,2 @@

const DEFAULT_DRAG_DELAY = 180;
const DEFAULT_SWIPE_VELOCITY = 0.5;
const DEFAULT_SWIPE_DISTANCE = 50;
const DEFAULT_SWIPE_DURATION = 250;
const dragConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, {
pointerLock(_v, _k, {
pointer: {
lock = false,
touch = false
} = {}
}) {
this.useTouch = SUPPORT.touch && touch;
return SUPPORT.pointerLock && lock;
},
device(_v, _k, config) {
if (config.shared.r3f) return 'pointer';
if (this.useTouch) return 'touch';
if (this.pointerLock) return 'mouse';
if (SUPPORT.pointer) return 'pointer';
if (SUPPORT.touch) return 'touch';
return 'mouse';
},
preventScroll(value = false) {
return value && SUPPORT.touch;
},
pointerCapture(_v, _k, {
pointer: {
capture = true
} = {}
}) {
return !this.pointerLock && this.device === 'pointer' && capture;
},
threshold(value, _k, {
filterTaps = false,
axis = undefined
}) {
const threshold = V.toVector(value, filterTaps ? 3 : axis ? 1 : 0);
this.filterTaps = filterTaps;
return threshold;
},
swipe({
velocity = DEFAULT_SWIPE_VELOCITY,
distance = DEFAULT_SWIPE_DISTANCE,
duration = DEFAULT_SWIPE_DURATION
} = {}) {
return {
velocity: this.transform(V.toVector(velocity)),
distance: this.transform(V.toVector(distance)),
duration
};
},
delay(value = 0) {
switch (value) {
case true:
return DEFAULT_DRAG_DELAY;
case false:
return 0;
default:
return value;
}
}
});
if (process.env.NODE_ENV === 'development') {
Object.assign(dragConfigResolver, {
useTouch(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`useTouch\` option has been renamed to \`pointer.touch\`. Use it as in \`{ pointer: { touch: true } }\`.`;
}
},
experimental_preventWindowScrollY(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`experimental_preventWindowScrollY\` option has been renamed to \`preventScroll\`.`;
}
},
swipeVelocity(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeVelocity\` option has been renamed to \`swipe.velocity\`. Use it as in \`{ swipe: { velocity: 0.5 } }\`.`;
}
},
swipeDistance(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeDistance\` option has been renamed to \`swipe.distance\`. Use it as in \`{ swipe: { distance: 50 } }\`.`;
}
},
swipeDuration(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeDuration\` option has been renamed to \`swipe.duration\`. Use it as in \`{ swipe: { duration: 250 } }\`.`;
}
}
});
}
ConfigResolverMap.set('drag', dragConfigResolver);
const DISPLACEMENT = 10;

@@ -1424,53 +1314,70 @@ const KEYS_DELTA_MAP = {

const pinchConfigResolver = _objectSpread2(_objectSpread2({}, commonConfigResolver), {}, {
useTouch(_v, _k, {
const DEFAULT_DRAG_DELAY = 180;
const DEFAULT_SWIPE_VELOCITY = 0.5;
const DEFAULT_SWIPE_DISTANCE = 50;
const DEFAULT_SWIPE_DURATION = 250;
const dragConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, {
pointerLock(_v, _k, {
pointer: {
lock = false,
touch = false
} = {}
}) {
return SUPPORT.touch && touch;
this.useTouch = SUPPORT.touch && touch;
return SUPPORT.pointerLock && lock;
},
device(_v, _k, config) {
const sharedConfig = config.shared;
if (sharedConfig.target && !SUPPORT.touch && SUPPORT.gesture) return 'gesture';
if (sharedConfig.r3f) return 'pointer';
if (config.shared.r3f) return 'pointer';
if (this.useTouch) return 'touch';
if (SUPPORT.touch && SUPPORT.pointer) return 'pointer';
if (this.pointerLock) return 'mouse';
if (SUPPORT.pointer) return 'pointer';
if (SUPPORT.touch) return 'touch';
return 'mouse';
},
useRad(_v, _k, config) {
return config.angleUnit === 'rad' || config.angleUnit == null && config.shared.r3f;
preventScroll(value = false) {
return value && SUPPORT.touch;
},
bounds(_v, _k, {
scaleBounds = {},
angleBounds = {}
pointerCapture(_v, _k, {
pointer: {
capture = true
} = {}
}) {
const _scaleBounds = state => {
const D = assignDefault(call(scaleBounds, state), {
min: -Infinity,
max: Infinity
});
return [D.min, D.max];
};
return !this.pointerLock && this.device === 'pointer' && capture;
},
const _angleBounds = state => {
const A = assignDefault(call(angleBounds, state), {
min: -Infinity,
max: Infinity
});
return [A.min, A.max];
threshold(value, _k, {
filterTaps = false,
axis = undefined
}) {
const threshold = V.toVector(value, filterTaps ? 3 : axis ? 1 : 0);
this.filterTaps = filterTaps;
return threshold;
},
swipe({
velocity = DEFAULT_SWIPE_VELOCITY,
distance = DEFAULT_SWIPE_DISTANCE,
duration = DEFAULT_SWIPE_DURATION
} = {}) {
return {
velocity: this.transform(V.toVector(velocity)),
distance: this.transform(V.toVector(distance)),
duration
};
if (typeof scaleBounds !== 'function' && typeof angleBounds !== 'function') return [_scaleBounds(), _angleBounds()];
return state => [_scaleBounds(state), _angleBounds(state)];
},
threshold(value, _k, config) {
this.lockDirection = config.axis === 'lock';
const angleRatio = this.useRad ? Math.PI / 180 : 1;
const threshold = V.toVector(value, this.lockDirection ? [0.1, 3 * angleRatio] : 0);
return threshold;
delay(value = 0) {
switch (value) {
case true:
return DEFAULT_DRAG_DELAY;
case false:
return 0;
default:
return value;
}
}

@@ -1480,3 +1387,37 @@

ConfigResolverMap.set('pinch', pinchConfigResolver);
if (process.env.NODE_ENV === 'development') {
Object.assign(dragConfigResolver, {
useTouch(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`useTouch\` option has been renamed to \`pointer.touch\`. Use it as in \`{ pointer: { touch: true } }\`.`;
}
},
experimental_preventWindowScrollY(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`experimental_preventWindowScrollY\` option has been renamed to \`preventScroll\`.`;
}
},
swipeVelocity(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeVelocity\` option has been renamed to \`swipe.velocity\`. Use it as in \`{ swipe: { velocity: 0.5 } }\`.`;
}
},
swipeDistance(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeDistance\` option has been renamed to \`swipe.distance\`. Use it as in \`{ swipe: { distance: 50 } }\`.`;
}
},
swipeDuration(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeDuration\` option has been renamed to \`swipe.duration\`. Use it as in \`{ swipe: { duration: 250 } }\`.`;
}
}
});
}
const SCALE_ANGLE_RATIO_INTENT_DEG = 30;

@@ -1737,5 +1678,57 @@ const SCALE_ANGLE_RATIO_INTENT_RAD = SCALE_ANGLE_RATIO_INTENT_DEG / 180 * Math.PI;

const wheelConfigResolver = coordinatesConfigResolver;
const pinchConfigResolver = _objectSpread2(_objectSpread2({}, commonConfigResolver), {}, {
useTouch(_v, _k, {
pointer: {
touch = false
} = {}
}) {
return SUPPORT.touch && touch;
},
ConfigResolverMap.set('wheel', wheelConfigResolver);
device(_v, _k, config) {
const sharedConfig = config.shared;
if (sharedConfig.target && !SUPPORT.touch && SUPPORT.gesture) return 'gesture';
if (sharedConfig.r3f) return 'pointer';
if (this.useTouch) return 'touch';
if (SUPPORT.touch && SUPPORT.pointer) return 'pointer';
if (SUPPORT.touch) return 'touch';
},
useRad(_v, _k, config) {
return config.angleUnit === 'rad' || config.angleUnit == null && config.shared.r3f;
},
bounds(_v, _k, {
scaleBounds = {},
angleBounds = {}
}) {
const _scaleBounds = state => {
const D = assignDefault(call(scaleBounds, state), {
min: -Infinity,
max: Infinity
});
return [D.min, D.max];
};
const _angleBounds = state => {
const A = assignDefault(call(angleBounds, state), {
min: -Infinity,
max: Infinity
});
return [A.min, A.max];
};
if (typeof scaleBounds !== 'function' && typeof angleBounds !== 'function') return [_scaleBounds(), _angleBounds()];
return state => [_scaleBounds(state), _angleBounds(state)];
},
threshold(value, _k, config) {
this.lockDirection = config.axis === 'lock';
const angleRatio = this.useRad ? Math.PI / 180 : 1;
const threshold = V.toVector(value, this.lockDirection ? [0.1, 3 * angleRatio] : 0);
return threshold;
}
});
class WheelEngine extends CoordinatesEngine {

@@ -1776,5 +1769,4 @@ constructor(...args) {

const scrollConfigResolver = coordinatesConfigResolver;
const wheelConfigResolver = coordinatesConfigResolver;
ConfigResolverMap.set('scroll', scrollConfigResolver);
class ScrollEngine extends CoordinatesEngine {

@@ -1817,5 +1809,4 @@ constructor(...args) {

const moveConfigResolver = coordinatesConfigResolver;
const scrollConfigResolver = coordinatesConfigResolver;
ConfigResolverMap.set('move', moveConfigResolver);
class MoveEngine extends CoordinatesEngine {

@@ -1867,5 +1858,4 @@ constructor(...args) {

const hoverConfigResolver = coordinatesConfigResolver;
const moveConfigResolver = coordinatesConfigResolver;
ConfigResolverMap.set('hover', hoverConfigResolver);
class HoverEngine extends CoordinatesEngine {

@@ -1904,2 +1894,4 @@ constructor(...args) {

const hoverConfigResolver = coordinatesConfigResolver;
exports.Controller = Controller;

@@ -1912,3 +1904,9 @@ exports.DragEngine = DragEngine;

exports.WheelEngine = WheelEngine;
exports.dragConfigResolver = dragConfigResolver;
exports.hoverConfigResolver = hoverConfigResolver;
exports.moveConfigResolver = moveConfigResolver;
exports.parseMergedHandlers = parseMergedHandlers;
exports.pinchConfigResolver = pinchConfigResolver;
exports.registerEngine = registerEngine;
exports.scrollConfigResolver = scrollConfigResolver;
exports.wheelConfigResolver = wheelConfigResolver;

@@ -60,4 +60,5 @@ 'use strict';

const ConfigResolverMap = new Map();
function registerEngine(action, Engine) {
function registerEngine(action, Engine, resolver) {
EngineMap.set(action, Engine);
ConfigResolverMap.set(action, resolver);
}

@@ -852,2 +853,21 @@ const RE_NOT_NATIVE = /^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;

function selectAxis([dx, dy]) {
const d = Math.abs(dx) - Math.abs(dy);
if (d > 0) return 'x';
if (d < 0) return 'y';
return undefined;
}
function restrictVectorToAxis(v, axis) {
switch (axis) {
case 'x':
v[1] = 0;
break;
case 'y':
v[0] = 0;
break;
}
}
class CoordinatesEngine extends Engine {

@@ -865,12 +885,7 @@ reset() {

computeOffset() {
const state = this.state;
state.offset = V.add(state.lastOffset, state.movement);
this.state.offset = V.add(this.state.lastOffset, this.state.movement);
}
computeMovement() {
const {
offset,
lastOffset
} = this.state;
this.state.movement = V.sub(offset, lastOffset);
this.state.movement = V.sub(this.state.offset, this.state.lastOffset);
this.state.xy = this.state.values;

@@ -880,26 +895,9 @@ }

intent(v) {
const state = this.state;
this.state.axis = this.state.axis || selectAxis(v);
this.state._blocked = (this.config.lockDirection || !!this.config.axis) && !this.state.axis || !!this.config.axis && this.config.axis !== this.state.axis;
if (this.state._blocked) return;
if (!state.axis) {
const axisMovementDifference = Math.abs(v[0]) - Math.abs(v[1]);
if (axisMovementDifference < 0) state.axis = 'y';else if (axisMovementDifference > 0) state.axis = 'x';
if (this.config.axis || this.config.lockDirection) {
restrictVectorToAxis(v, this.state.axis);
}
const axis = state.axis;
if (this.config.lockDirection) {
if (axis) {
state._blocked = false;
if (axis === 'x') v[1] = 0;else if (axis === 'y') v[0] = 0;
} else {
state._blocked = false;
}
} else if (this.config.axis) {
if (!!axis && axis === this.config.axis) {
state._blocked = false;
if (axis === 'x') v[1] = 0;else if (axis === 'y') v[0] = 0;
} else {
state._blocked = true;
}
}
}

@@ -975,75 +973,2 @@

const DEFAULT_DRAG_DELAY = 180;
const DEFAULT_SWIPE_VELOCITY = 0.5;
const DEFAULT_SWIPE_DISTANCE = 50;
const DEFAULT_SWIPE_DURATION = 250;
const dragConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, {
pointerLock(_v, _k, {
pointer: {
lock = false,
touch = false
} = {}
}) {
this.useTouch = SUPPORT.touch && touch;
return SUPPORT.pointerLock && lock;
},
device(_v, _k, config) {
if (config.shared.r3f) return 'pointer';
if (this.useTouch) return 'touch';
if (this.pointerLock) return 'mouse';
if (SUPPORT.pointer) return 'pointer';
if (SUPPORT.touch) return 'touch';
return 'mouse';
},
preventScroll(value = false) {
return value && SUPPORT.touch;
},
pointerCapture(_v, _k, {
pointer: {
capture = true
} = {}
}) {
return !this.pointerLock && this.device === 'pointer' && capture;
},
threshold(value, _k, {
filterTaps = false,
axis = undefined
}) {
const threshold = V.toVector(value, filterTaps ? 3 : axis ? 1 : 0);
this.filterTaps = filterTaps;
return threshold;
},
swipe({
velocity = DEFAULT_SWIPE_VELOCITY,
distance = DEFAULT_SWIPE_DISTANCE,
duration = DEFAULT_SWIPE_DURATION
} = {}) {
return {
velocity: this.transform(V.toVector(velocity)),
distance: this.transform(V.toVector(distance)),
duration
};
},
delay(value = 0) {
switch (value) {
case true:
return DEFAULT_DRAG_DELAY;
case false:
return 0;
default:
return value;
}
}
});
ConfigResolverMap.set('drag', dragConfigResolver);
const DISPLACEMENT = 10;

@@ -1344,53 +1269,70 @@ const KEYS_DELTA_MAP = {

const pinchConfigResolver = _objectSpread2(_objectSpread2({}, commonConfigResolver), {}, {
useTouch(_v, _k, {
const DEFAULT_DRAG_DELAY = 180;
const DEFAULT_SWIPE_VELOCITY = 0.5;
const DEFAULT_SWIPE_DISTANCE = 50;
const DEFAULT_SWIPE_DURATION = 250;
const dragConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, {
pointerLock(_v, _k, {
pointer: {
lock = false,
touch = false
} = {}
}) {
return SUPPORT.touch && touch;
this.useTouch = SUPPORT.touch && touch;
return SUPPORT.pointerLock && lock;
},
device(_v, _k, config) {
const sharedConfig = config.shared;
if (sharedConfig.target && !SUPPORT.touch && SUPPORT.gesture) return 'gesture';
if (sharedConfig.r3f) return 'pointer';
if (config.shared.r3f) return 'pointer';
if (this.useTouch) return 'touch';
if (SUPPORT.touch && SUPPORT.pointer) return 'pointer';
if (this.pointerLock) return 'mouse';
if (SUPPORT.pointer) return 'pointer';
if (SUPPORT.touch) return 'touch';
return 'mouse';
},
useRad(_v, _k, config) {
return config.angleUnit === 'rad' || config.angleUnit == null && config.shared.r3f;
preventScroll(value = false) {
return value && SUPPORT.touch;
},
bounds(_v, _k, {
scaleBounds = {},
angleBounds = {}
pointerCapture(_v, _k, {
pointer: {
capture = true
} = {}
}) {
const _scaleBounds = state => {
const D = assignDefault(call(scaleBounds, state), {
min: -Infinity,
max: Infinity
});
return [D.min, D.max];
};
return !this.pointerLock && this.device === 'pointer' && capture;
},
const _angleBounds = state => {
const A = assignDefault(call(angleBounds, state), {
min: -Infinity,
max: Infinity
});
return [A.min, A.max];
threshold(value, _k, {
filterTaps = false,
axis = undefined
}) {
const threshold = V.toVector(value, filterTaps ? 3 : axis ? 1 : 0);
this.filterTaps = filterTaps;
return threshold;
},
swipe({
velocity = DEFAULT_SWIPE_VELOCITY,
distance = DEFAULT_SWIPE_DISTANCE,
duration = DEFAULT_SWIPE_DURATION
} = {}) {
return {
velocity: this.transform(V.toVector(velocity)),
distance: this.transform(V.toVector(distance)),
duration
};
if (typeof scaleBounds !== 'function' && typeof angleBounds !== 'function') return [_scaleBounds(), _angleBounds()];
return state => [_scaleBounds(state), _angleBounds(state)];
},
threshold(value, _k, config) {
this.lockDirection = config.axis === 'lock';
const angleRatio = this.useRad ? Math.PI / 180 : 1;
const threshold = V.toVector(value, this.lockDirection ? [0.1, 3 * angleRatio] : 0);
return threshold;
delay(value = 0) {
switch (value) {
case true:
return DEFAULT_DRAG_DELAY;
case false:
return 0;
default:
return value;
}
}

@@ -1400,3 +1342,2 @@

ConfigResolverMap.set('pinch', pinchConfigResolver);
const SCALE_ANGLE_RATIO_INTENT_DEG = 30;

@@ -1655,5 +1596,57 @@ const SCALE_ANGLE_RATIO_INTENT_RAD = SCALE_ANGLE_RATIO_INTENT_DEG / 180 * Math.PI;

const wheelConfigResolver = coordinatesConfigResolver;
const pinchConfigResolver = _objectSpread2(_objectSpread2({}, commonConfigResolver), {}, {
useTouch(_v, _k, {
pointer: {
touch = false
} = {}
}) {
return SUPPORT.touch && touch;
},
ConfigResolverMap.set('wheel', wheelConfigResolver);
device(_v, _k, config) {
const sharedConfig = config.shared;
if (sharedConfig.target && !SUPPORT.touch && SUPPORT.gesture) return 'gesture';
if (sharedConfig.r3f) return 'pointer';
if (this.useTouch) return 'touch';
if (SUPPORT.touch && SUPPORT.pointer) return 'pointer';
if (SUPPORT.touch) return 'touch';
},
useRad(_v, _k, config) {
return config.angleUnit === 'rad' || config.angleUnit == null && config.shared.r3f;
},
bounds(_v, _k, {
scaleBounds = {},
angleBounds = {}
}) {
const _scaleBounds = state => {
const D = assignDefault(call(scaleBounds, state), {
min: -Infinity,
max: Infinity
});
return [D.min, D.max];
};
const _angleBounds = state => {
const A = assignDefault(call(angleBounds, state), {
min: -Infinity,
max: Infinity
});
return [A.min, A.max];
};
if (typeof scaleBounds !== 'function' && typeof angleBounds !== 'function') return [_scaleBounds(), _angleBounds()];
return state => [_scaleBounds(state), _angleBounds(state)];
},
threshold(value, _k, config) {
this.lockDirection = config.axis === 'lock';
const angleRatio = this.useRad ? Math.PI / 180 : 1;
const threshold = V.toVector(value, this.lockDirection ? [0.1, 3 * angleRatio] : 0);
return threshold;
}
});
class WheelEngine extends CoordinatesEngine {

@@ -1694,5 +1687,4 @@ constructor(...args) {

const scrollConfigResolver = coordinatesConfigResolver;
const wheelConfigResolver = coordinatesConfigResolver;
ConfigResolverMap.set('scroll', scrollConfigResolver);
class ScrollEngine extends CoordinatesEngine {

@@ -1735,5 +1727,4 @@ constructor(...args) {

const moveConfigResolver = coordinatesConfigResolver;
const scrollConfigResolver = coordinatesConfigResolver;
ConfigResolverMap.set('move', moveConfigResolver);
class MoveEngine extends CoordinatesEngine {

@@ -1785,5 +1776,4 @@ constructor(...args) {

const hoverConfigResolver = coordinatesConfigResolver;
const moveConfigResolver = coordinatesConfigResolver;
ConfigResolverMap.set('hover', hoverConfigResolver);
class HoverEngine extends CoordinatesEngine {

@@ -1822,2 +1812,4 @@ constructor(...args) {

const hoverConfigResolver = coordinatesConfigResolver;
exports.Controller = Controller;

@@ -1830,3 +1822,9 @@ exports.DragEngine = DragEngine;

exports.WheelEngine = WheelEngine;
exports.dragConfigResolver = dragConfigResolver;
exports.hoverConfigResolver = hoverConfigResolver;
exports.moveConfigResolver = moveConfigResolver;
exports.parseMergedHandlers = parseMergedHandlers;
exports.pinchConfigResolver = pinchConfigResolver;
exports.registerEngine = registerEngine;
exports.scrollConfigResolver = scrollConfigResolver;
exports.wheelConfigResolver = wheelConfigResolver;

@@ -56,4 +56,5 @@ function _defineProperty(obj, key, value) {

const ConfigResolverMap = new Map();
function registerEngine(action, Engine) {
function registerEngine(action, Engine, resolver) {
EngineMap.set(action, Engine);
ConfigResolverMap.set(action, resolver);
}

@@ -848,2 +849,21 @@ const RE_NOT_NATIVE = /^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;

function selectAxis([dx, dy]) {
const d = Math.abs(dx) - Math.abs(dy);
if (d > 0) return 'x';
if (d < 0) return 'y';
return undefined;
}
function restrictVectorToAxis(v, axis) {
switch (axis) {
case 'x':
v[1] = 0;
break;
case 'y':
v[0] = 0;
break;
}
}
class CoordinatesEngine extends Engine {

@@ -861,12 +881,7 @@ reset() {

computeOffset() {
const state = this.state;
state.offset = V.add(state.lastOffset, state.movement);
this.state.offset = V.add(this.state.lastOffset, this.state.movement);
}
computeMovement() {
const {
offset,
lastOffset
} = this.state;
this.state.movement = V.sub(offset, lastOffset);
this.state.movement = V.sub(this.state.offset, this.state.lastOffset);
this.state.xy = this.state.values;

@@ -876,26 +891,9 @@ }

intent(v) {
const state = this.state;
this.state.axis = this.state.axis || selectAxis(v);
this.state._blocked = (this.config.lockDirection || !!this.config.axis) && !this.state.axis || !!this.config.axis && this.config.axis !== this.state.axis;
if (this.state._blocked) return;
if (!state.axis) {
const axisMovementDifference = Math.abs(v[0]) - Math.abs(v[1]);
if (axisMovementDifference < 0) state.axis = 'y';else if (axisMovementDifference > 0) state.axis = 'x';
if (this.config.axis || this.config.lockDirection) {
restrictVectorToAxis(v, this.state.axis);
}
const axis = state.axis;
if (this.config.lockDirection) {
if (axis) {
state._blocked = false;
if (axis === 'x') v[1] = 0;else if (axis === 'y') v[0] = 0;
} else {
state._blocked = false;
}
} else if (this.config.axis) {
if (!!axis && axis === this.config.axis) {
state._blocked = false;
if (axis === 'x') v[1] = 0;else if (axis === 'y') v[0] = 0;
} else {
state._blocked = true;
}
}
}

@@ -994,110 +992,2 @@

const DEFAULT_DRAG_DELAY = 180;
const DEFAULT_SWIPE_VELOCITY = 0.5;
const DEFAULT_SWIPE_DISTANCE = 50;
const DEFAULT_SWIPE_DURATION = 250;
const dragConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, {
pointerLock(_v, _k, {
pointer: {
lock = false,
touch = false
} = {}
}) {
this.useTouch = SUPPORT.touch && touch;
return SUPPORT.pointerLock && lock;
},
device(_v, _k, config) {
if (config.shared.r3f) return 'pointer';
if (this.useTouch) return 'touch';
if (this.pointerLock) return 'mouse';
if (SUPPORT.pointer) return 'pointer';
if (SUPPORT.touch) return 'touch';
return 'mouse';
},
preventScroll(value = false) {
return value && SUPPORT.touch;
},
pointerCapture(_v, _k, {
pointer: {
capture = true
} = {}
}) {
return !this.pointerLock && this.device === 'pointer' && capture;
},
threshold(value, _k, {
filterTaps = false,
axis = undefined
}) {
const threshold = V.toVector(value, filterTaps ? 3 : axis ? 1 : 0);
this.filterTaps = filterTaps;
return threshold;
},
swipe({
velocity = DEFAULT_SWIPE_VELOCITY,
distance = DEFAULT_SWIPE_DISTANCE,
duration = DEFAULT_SWIPE_DURATION
} = {}) {
return {
velocity: this.transform(V.toVector(velocity)),
distance: this.transform(V.toVector(distance)),
duration
};
},
delay(value = 0) {
switch (value) {
case true:
return DEFAULT_DRAG_DELAY;
case false:
return 0;
default:
return value;
}
}
});
if (process.env.NODE_ENV === 'development') {
Object.assign(dragConfigResolver, {
useTouch(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`useTouch\` option has been renamed to \`pointer.touch\`. Use it as in \`{ pointer: { touch: true } }\`.`;
}
},
experimental_preventWindowScrollY(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`experimental_preventWindowScrollY\` option has been renamed to \`preventScroll\`.`;
}
},
swipeVelocity(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeVelocity\` option has been renamed to \`swipe.velocity\`. Use it as in \`{ swipe: { velocity: 0.5 } }\`.`;
}
},
swipeDistance(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeDistance\` option has been renamed to \`swipe.distance\`. Use it as in \`{ swipe: { distance: 50 } }\`.`;
}
},
swipeDuration(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeDuration\` option has been renamed to \`swipe.duration\`. Use it as in \`{ swipe: { duration: 250 } }\`.`;
}
}
});
}
ConfigResolverMap.set('drag', dragConfigResolver);
const DISPLACEMENT = 10;

@@ -1420,53 +1310,70 @@ const KEYS_DELTA_MAP = {

const pinchConfigResolver = _objectSpread2(_objectSpread2({}, commonConfigResolver), {}, {
useTouch(_v, _k, {
const DEFAULT_DRAG_DELAY = 180;
const DEFAULT_SWIPE_VELOCITY = 0.5;
const DEFAULT_SWIPE_DISTANCE = 50;
const DEFAULT_SWIPE_DURATION = 250;
const dragConfigResolver = _objectSpread2(_objectSpread2({}, coordinatesConfigResolver), {}, {
pointerLock(_v, _k, {
pointer: {
lock = false,
touch = false
} = {}
}) {
return SUPPORT.touch && touch;
this.useTouch = SUPPORT.touch && touch;
return SUPPORT.pointerLock && lock;
},
device(_v, _k, config) {
const sharedConfig = config.shared;
if (sharedConfig.target && !SUPPORT.touch && SUPPORT.gesture) return 'gesture';
if (sharedConfig.r3f) return 'pointer';
if (config.shared.r3f) return 'pointer';
if (this.useTouch) return 'touch';
if (SUPPORT.touch && SUPPORT.pointer) return 'pointer';
if (this.pointerLock) return 'mouse';
if (SUPPORT.pointer) return 'pointer';
if (SUPPORT.touch) return 'touch';
return 'mouse';
},
useRad(_v, _k, config) {
return config.angleUnit === 'rad' || config.angleUnit == null && config.shared.r3f;
preventScroll(value = false) {
return value && SUPPORT.touch;
},
bounds(_v, _k, {
scaleBounds = {},
angleBounds = {}
pointerCapture(_v, _k, {
pointer: {
capture = true
} = {}
}) {
const _scaleBounds = state => {
const D = assignDefault(call(scaleBounds, state), {
min: -Infinity,
max: Infinity
});
return [D.min, D.max];
};
return !this.pointerLock && this.device === 'pointer' && capture;
},
const _angleBounds = state => {
const A = assignDefault(call(angleBounds, state), {
min: -Infinity,
max: Infinity
});
return [A.min, A.max];
threshold(value, _k, {
filterTaps = false,
axis = undefined
}) {
const threshold = V.toVector(value, filterTaps ? 3 : axis ? 1 : 0);
this.filterTaps = filterTaps;
return threshold;
},
swipe({
velocity = DEFAULT_SWIPE_VELOCITY,
distance = DEFAULT_SWIPE_DISTANCE,
duration = DEFAULT_SWIPE_DURATION
} = {}) {
return {
velocity: this.transform(V.toVector(velocity)),
distance: this.transform(V.toVector(distance)),
duration
};
if (typeof scaleBounds !== 'function' && typeof angleBounds !== 'function') return [_scaleBounds(), _angleBounds()];
return state => [_scaleBounds(state), _angleBounds(state)];
},
threshold(value, _k, config) {
this.lockDirection = config.axis === 'lock';
const angleRatio = this.useRad ? Math.PI / 180 : 1;
const threshold = V.toVector(value, this.lockDirection ? [0.1, 3 * angleRatio] : 0);
return threshold;
delay(value = 0) {
switch (value) {
case true:
return DEFAULT_DRAG_DELAY;
case false:
return 0;
default:
return value;
}
}

@@ -1476,3 +1383,37 @@

ConfigResolverMap.set('pinch', pinchConfigResolver);
if (process.env.NODE_ENV === 'development') {
Object.assign(dragConfigResolver, {
useTouch(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`useTouch\` option has been renamed to \`pointer.touch\`. Use it as in \`{ pointer: { touch: true } }\`.`;
}
},
experimental_preventWindowScrollY(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`experimental_preventWindowScrollY\` option has been renamed to \`preventScroll\`.`;
}
},
swipeVelocity(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeVelocity\` option has been renamed to \`swipe.velocity\`. Use it as in \`{ swipe: { velocity: 0.5 } }\`.`;
}
},
swipeDistance(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeDistance\` option has been renamed to \`swipe.distance\`. Use it as in \`{ swipe: { distance: 50 } }\`.`;
}
},
swipeDuration(value) {
if (value !== undefined) {
throw `[@use-gesture]: \`swipeDuration\` option has been renamed to \`swipe.duration\`. Use it as in \`{ swipe: { duration: 250 } }\`.`;
}
}
});
}
const SCALE_ANGLE_RATIO_INTENT_DEG = 30;

@@ -1733,5 +1674,57 @@ const SCALE_ANGLE_RATIO_INTENT_RAD = SCALE_ANGLE_RATIO_INTENT_DEG / 180 * Math.PI;

const wheelConfigResolver = coordinatesConfigResolver;
const pinchConfigResolver = _objectSpread2(_objectSpread2({}, commonConfigResolver), {}, {
useTouch(_v, _k, {
pointer: {
touch = false
} = {}
}) {
return SUPPORT.touch && touch;
},
ConfigResolverMap.set('wheel', wheelConfigResolver);
device(_v, _k, config) {
const sharedConfig = config.shared;
if (sharedConfig.target && !SUPPORT.touch && SUPPORT.gesture) return 'gesture';
if (sharedConfig.r3f) return 'pointer';
if (this.useTouch) return 'touch';
if (SUPPORT.touch && SUPPORT.pointer) return 'pointer';
if (SUPPORT.touch) return 'touch';
},
useRad(_v, _k, config) {
return config.angleUnit === 'rad' || config.angleUnit == null && config.shared.r3f;
},
bounds(_v, _k, {
scaleBounds = {},
angleBounds = {}
}) {
const _scaleBounds = state => {
const D = assignDefault(call(scaleBounds, state), {
min: -Infinity,
max: Infinity
});
return [D.min, D.max];
};
const _angleBounds = state => {
const A = assignDefault(call(angleBounds, state), {
min: -Infinity,
max: Infinity
});
return [A.min, A.max];
};
if (typeof scaleBounds !== 'function' && typeof angleBounds !== 'function') return [_scaleBounds(), _angleBounds()];
return state => [_scaleBounds(state), _angleBounds(state)];
},
threshold(value, _k, config) {
this.lockDirection = config.axis === 'lock';
const angleRatio = this.useRad ? Math.PI / 180 : 1;
const threshold = V.toVector(value, this.lockDirection ? [0.1, 3 * angleRatio] : 0);
return threshold;
}
});
class WheelEngine extends CoordinatesEngine {

@@ -1772,5 +1765,4 @@ constructor(...args) {

const scrollConfigResolver = coordinatesConfigResolver;
const wheelConfigResolver = coordinatesConfigResolver;
ConfigResolverMap.set('scroll', scrollConfigResolver);
class ScrollEngine extends CoordinatesEngine {

@@ -1813,5 +1805,4 @@ constructor(...args) {

const moveConfigResolver = coordinatesConfigResolver;
const scrollConfigResolver = coordinatesConfigResolver;
ConfigResolverMap.set('move', moveConfigResolver);
class MoveEngine extends CoordinatesEngine {

@@ -1863,5 +1854,4 @@ constructor(...args) {

const hoverConfigResolver = coordinatesConfigResolver;
const moveConfigResolver = coordinatesConfigResolver;
ConfigResolverMap.set('hover', hoverConfigResolver);
class HoverEngine extends CoordinatesEngine {

@@ -1900,2 +1890,4 @@ constructor(...args) {

export { Controller, DragEngine, HoverEngine, MoveEngine, PinchEngine, ScrollEngine, WheelEngine, parseMergedHandlers, registerEngine };
const hoverConfigResolver = coordinatesConfigResolver;
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.2",
"version": "10.0.0-beta.3",
"description": "Core engine for receiving gestures",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -5,2 +5,20 @@ import { Engine } from './Engine'

function selectAxis([dx, dy]: Vector2) {
const d = Math.abs(dx) - Math.abs(dy)
if (d > 0) return 'x'
if (d < 0) return 'y'
return undefined
}
function restrictVectorToAxis(v: Vector2, axis?: 'x' | 'y') {
switch (axis) {
case 'x':
v[1] = 0
break // [ x, 0 ]
case 'y':
v[0] = 0
break // [ 0, y ]
}
}
export abstract class CoordinatesEngine<Key extends CoordinatesKey> extends Engine<Key> {

@@ -18,9 +36,7 @@ reset() {

computeOffset() {
const state = this.state
state.offset = V.add(state.lastOffset, state.movement)
this.state.offset = V.add(this.state.lastOffset, this.state.movement)
}
computeMovement() {
const { offset, lastOffset } = this.state
this.state.movement = V.sub(offset, lastOffset)
this.state.movement = V.sub(this.state.offset, this.state.lastOffset)
// let's take profit from this function to set `values` alias to `xy`

@@ -31,30 +47,17 @@ this.state.xy = this.state.values

intent(v: Vector2) {
const state = this.state
this.state.axis = this.state.axis || selectAxis(v)
if (!state.axis) {
const axisMovementDifference = Math.abs(v[0]) - Math.abs(v[1])
if (axisMovementDifference < 0) state.axis = 'y'
else if (axisMovementDifference > 0) state.axis = 'x'
}
// We block the movement if either:
// - config.lockDirection or config.axis was set but axis isn't detected yet
// - config.axis was set but is different than detected axis
this.state._blocked =
((this.config.lockDirection || !!this.config.axis) && !this.state.axis) ||
(!!this.config.axis && this.config.axis !== this.state.axis)
const axis = state.axis
if (this.state._blocked) return
if (this.config.lockDirection) {
if (axis) {
state._blocked = false
if (axis === 'x') v[1] = 0
else if (axis === 'y') v[0] = 0
} else {
state._blocked = false
}
} else if (this.config.axis) {
if (!!axis && axis === this.config.axis) {
state._blocked = false
if (axis === 'x') v[1] = 0
else if (axis === 'y') v[0] = 0
} else {
state._blocked = true
}
if (this.config.axis || this.config.lockDirection) {
restrictVectorToAxis(v, this.state.axis)
}
}
}
import { CoordinatesEngine } from './CoordinatesEngine'
import { ConfigResolverMap } from '../imports'
import { dragConfigResolver } from '../config/dragConfigResolver'
import { coordinatesConfigResolver } from '../config/coordinatesConfigResolver'

@@ -9,4 +7,2 @@ import { Pointer } from '../utils/events'

ConfigResolverMap.set('drag', dragConfigResolver)
const DISPLACEMENT = 10

@@ -13,0 +9,0 @@

@@ -1,3 +0,1 @@

import { ConfigResolverMap } from '../imports'
import { hoverConfigResolver } from '../config/hoverConfigResolver'
import { CoordinatesEngine } from './CoordinatesEngine'

@@ -7,4 +5,2 @@ import { Pointer } from '../utils/events'

ConfigResolverMap.set('hover', hoverConfigResolver)
export class HoverEngine extends CoordinatesEngine<'hover'> {

@@ -11,0 +7,0 @@ ingKey = 'hovering' as const

@@ -1,3 +0,1 @@

import { ConfigResolverMap } from '../imports'
import { moveConfigResolver } from '../config/moveConfigResolver'
import { CoordinatesEngine } from './CoordinatesEngine'

@@ -7,4 +5,2 @@ import { Pointer } from '../utils/events'

ConfigResolverMap.set('move', moveConfigResolver)
export class MoveEngine extends CoordinatesEngine<'move'> {

@@ -11,0 +7,0 @@ ingKey = 'moving' as const

import { Engine } from './Engine'
import { ConfigResolverMap } from '../imports'
import { pinchConfigResolver } from '../config/pinchConfigResolver'
import { Touches, Wheel, distanceAngle } from '../utils/events'

@@ -8,4 +6,2 @@ import { V } from '../utils/maths'

ConfigResolverMap.set('pinch', pinchConfigResolver)
const SCALE_ANGLE_RATIO_INTENT_DEG = 30

@@ -12,0 +8,0 @@ const SCALE_ANGLE_RATIO_INTENT_RAD = (SCALE_ANGLE_RATIO_INTENT_DEG / 180) * Math.PI

@@ -1,3 +0,1 @@

import { ConfigResolverMap } from '../imports'
import { scrollConfigResolver } from '../config/scrollConfigResolver'
import { CoordinatesEngine } from './CoordinatesEngine'

@@ -7,4 +5,2 @@ import { Scroll } from '../utils/events'

ConfigResolverMap.set('scroll', scrollConfigResolver)
export class ScrollEngine extends CoordinatesEngine<'scroll'> {

@@ -11,0 +7,0 @@ ingKey = 'scrolling' as const

@@ -1,3 +0,1 @@

import { ConfigResolverMap } from '../imports'
import { wheelConfigResolver } from '../config/wheelConfigResolver'
import { CoordinatesEngine } from './CoordinatesEngine'

@@ -7,4 +5,2 @@ import { Wheel } from '../utils/events'

ConfigResolverMap.set('wheel', wheelConfigResolver)
export interface WheelEngine extends CoordinatesEngine<'wheel'> {

@@ -11,0 +7,0 @@ wheel(this: WheelEngine, event: WheelEvent): void

@@ -13,4 +13,5 @@ import { ResolverMap } from './config/resolver'

export function registerEngine<Key extends GestureKey>(action: Key, Engine: EngineClass<Key>) {
export function registerEngine<Key extends GestureKey>(action: Key, Engine: EngineClass<Key>, resolver: ResolverMap) {
EngineMap.set(action, Engine)
ConfigResolverMap.set(action, resolver)
}

@@ -17,0 +18,0 @@

export { Controller } from './Controller'
export { DragEngine } from './engines/DragEngine'
export { dragConfigResolver } from './config/dragConfigResolver'
export { PinchEngine } from './engines/PinchEngine'
export { pinchConfigResolver } from './config/pinchConfigResolver'
export { WheelEngine } from './engines/WheelEngine'
export { wheelConfigResolver } from './config/wheelConfigResolver'
export { ScrollEngine } from './engines/ScrollEngine'
export { scrollConfigResolver } from './config/scrollConfigResolver'
export { MoveEngine } from './engines/MoveEngine'
export { moveConfigResolver } from './config/moveConfigResolver'
export { HoverEngine } from './engines/HoverEngine'
export { hoverConfigResolver } from './config/hoverConfigResolver'
export { registerEngine, parseMergedHandlers } from './imports'
export * from './types'
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc