/**
 * 向量类型
 */ export type TVector = [ number , number ] ; /**
 * 向量范围
 */ export type TVectorRange = [ number , number , number , number ] ; param vector1 param vector2 returns export const addVector = ( vector1 , vector2 ) : TVector => { const x = vector1 [ 0 ] + vector2 [ 0 ] ; const y = vector1 [ 1 ] + vector2 [ 1 ] ; return [ x , y ] ; } ; param vector1 param vector2 returns export const diffVector = ( vector1 , vector2 ) : TVector => { const x = vector2 [ 0 ] - vector1 [ 0 ] ; const y = vector2 [ 1 ] - vector1 [ 1 ] ; return [ x , y ] ; } ; param vector param range returns export const formatVector = ( vector , range ) : TVector => { let x = vector [ 0 ] ; let y = vector [ 1 ] ; x = Math . max ( x , range [ 2 ] ) ; x = Math . min ( x , range [ 3 ] ) ; y = Math . max ( y , range [ 0 ] ) ; y = Math . min ( y , range [ 1 ] ) ; return [ x , y ] ; } ; param transform param vector returns export const setTranslatePosition = ( transform , vector ) : string => { return `translate3d(${ vector [ 0 ] }px, ${ vector [ 1 ] }px, 0px) ${ transform . replace ( "none" , "" ) }` ; } ; export const getPosition = ( e ) : TVector => { if ( e instanceof MouseEvent ) { return [ e . pageX , e . pageY ] ; } const touch = e . touches [ 0 ] ; return [ touch . pageX , touch . pageY ] ; } ; export const isMobile = ( ) => /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i . test ( navigator . userAgent ) ;