source: imaps-frontend/node_modules/@use-gesture/core/src/config/pinchConfigResolver.ts

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import { ModifierKey } from '../types'
2import { PinchConfig, GenericOptions, InternalPinchOptions, State, Vector2 } from '../types'
3import { call, assignDefault } from '../utils/fn'
4import { V } from '../utils/maths'
5import { commonConfigResolver } from './commonConfigResolver'
6import { SUPPORT } from './support'
7
8export const pinchConfigResolver = {
9 ...commonConfigResolver,
10 device(
11 this: InternalPinchOptions,
12 _v: any,
13 _k: string,
14 { shared, pointer: { touch = false } = {} }: { shared: GenericOptions } & PinchConfig
15 ) {
16 // Only try to use gesture events when they are supported and domTarget is set
17 // as React doesn't support gesture handlers.
18 const sharedConfig = shared
19 if (sharedConfig.target && !SUPPORT.touch && SUPPORT.gesture) return 'gesture'
20 if (SUPPORT.touch && touch) return 'touch'
21 if (SUPPORT.touchscreen) {
22 if (SUPPORT.pointer) return 'pointer'
23 if (SUPPORT.touch) return 'touch'
24 }
25 // device is undefined and that's ok, we're going to use wheel to zoom.
26 },
27 bounds(_v: any, _k: string, { scaleBounds = {}, angleBounds = {} }: PinchConfig) {
28 const _scaleBounds = (state?: State) => {
29 const D = assignDefault(call(scaleBounds, state), { min: -Infinity, max: Infinity })
30 return [D.min, D.max]
31 }
32
33 const _angleBounds = (state?: State) => {
34 const A = assignDefault(call(angleBounds, state), { min: -Infinity, max: Infinity })
35 return [A.min, A.max]
36 }
37
38 if (typeof scaleBounds !== 'function' && typeof angleBounds !== 'function') return [_scaleBounds(), _angleBounds()]
39
40 return (state: State) => [_scaleBounds(state), _angleBounds(state)]
41 },
42 threshold(this: InternalPinchOptions, value: number | Vector2, _k: string, config: PinchConfig) {
43 this.lockDirection = config.axis === 'lock'
44 const threshold = V.toVector(value, this.lockDirection ? [0.1, 3] : 0)
45 return threshold
46 },
47 modifierKey(value: ModifierKey | ModifierKey[]) {
48 if (value === undefined) return 'ctrlKey'
49 return value
50 },
51 pinchOnWheel(value = true) {
52 return value
53 }
54}
Note: See TracBrowser for help on using the repository browser.