1+ "use strict" ;
2+
3+ function _typeof ( obj ) { "@babel/helpers - typeof" ; if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
4+
5+ Object . defineProperty ( exports , "__esModule" , {
6+ value : true
7+ } ) ;
8+ exports . matchesSelector = matchesSelector ;
9+ exports . matchesSelectorAndParentsTo = matchesSelectorAndParentsTo ;
10+ exports . addEvent = addEvent ;
11+ exports . removeEvent = removeEvent ;
12+ exports . outerHeight = outerHeight ;
13+ exports . outerWidth = outerWidth ;
14+ exports . innerHeight = innerHeight ;
15+ exports . innerWidth = innerWidth ;
16+ exports . offsetXYFromParent = offsetXYFromParent ;
17+ exports . createCSSTransform = createCSSTransform ;
18+ exports . createSVGTransform = createSVGTransform ;
19+ exports . getTranslation = getTranslation ;
20+ exports . getTouch = getTouch ;
21+ exports . getTouchIdentifier = getTouchIdentifier ;
22+ exports . addUserSelectStyles = addUserSelectStyles ;
23+ exports . removeUserSelectStyles = removeUserSelectStyles ;
24+ exports . styleHacks = styleHacks ;
25+ exports . addClassName = addClassName ;
26+ exports . removeClassName = removeClassName ;
27+
28+ var _shims = require ( "./shims" ) ;
29+
30+ var _getPrefix = _interopRequireWildcard ( require ( "./getPrefix" ) ) ;
31+
32+ function _getRequireWildcardCache ( ) { if ( typeof WeakMap !== "function" ) return null ; var cache = new WeakMap ( ) ; _getRequireWildcardCache = function _getRequireWildcardCache ( ) { return cache ; } ; return cache ; }
33+
34+ function _interopRequireWildcard ( obj ) { if ( obj && obj . __esModule ) { return obj ; } if ( obj === null || _typeof ( obj ) !== "object" && typeof obj !== "function" ) { return { default : obj } ; } var cache = _getRequireWildcardCache ( ) ; if ( cache && cache . has ( obj ) ) { return cache . get ( obj ) ; } var newObj = { } ; var hasPropertyDescriptor = Object . defineProperty && Object . getOwnPropertyDescriptor ; for ( var key in obj ) { if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) { var desc = hasPropertyDescriptor ? Object . getOwnPropertyDescriptor ( obj , key ) : null ; if ( desc && ( desc . get || desc . set ) ) { Object . defineProperty ( newObj , key , desc ) ; } else { newObj [ key ] = obj [ key ] ; } } } newObj . default = obj ; if ( cache ) { cache . set ( obj , newObj ) ; } return newObj ; }
35+
36+ function ownKeys ( object , enumerableOnly ) { var keys = Object . keys ( object ) ; if ( Object . getOwnPropertySymbols ) { var symbols = Object . getOwnPropertySymbols ( object ) ; if ( enumerableOnly ) symbols = symbols . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ; } ) ; keys . push . apply ( keys , symbols ) ; } return keys ; }
37+
38+ function _objectSpread ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] != null ? arguments [ i ] : { } ; if ( i % 2 ) { ownKeys ( Object ( source ) , true ) . forEach ( function ( key ) { _defineProperty ( target , key , source [ key ] ) ; } ) ; } else if ( Object . getOwnPropertyDescriptors ) { Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) ; } else { ownKeys ( Object ( source ) ) . forEach ( function ( key ) { Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ; } ) ; } } return target ; }
39+
40+ function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
41+
42+ var matchesSelectorFunc = '' ;
43+
44+ function matchesSelector ( el
45+ /*: Node*/
46+ , selector
47+ /*: string*/
48+ )
49+ /*: boolean*/
50+ {
51+ if ( ! matchesSelectorFunc ) {
52+ matchesSelectorFunc = ( 0 , _shims . findInArray ) ( [ 'matches' , 'webkitMatchesSelector' , 'mozMatchesSelector' , 'msMatchesSelector' , 'oMatchesSelector' ] , function ( method ) {
53+ // $FlowIgnore: Doesn't think elements are indexable
54+ return ( 0 , _shims . isFunction ) ( el [ method ] ) ;
55+ } ) ;
56+ } // Might not be found entirely (not an Element?) - in that case, bail
57+ // $FlowIgnore: Doesn't think elements are indexable
58+
59+
60+ if ( ! ( 0 , _shims . isFunction ) ( el [ matchesSelectorFunc ] ) ) return false ; // $FlowIgnore: Doesn't think elements are indexable
61+
62+ return el [ matchesSelectorFunc ] ( selector ) ;
63+ } // Works up the tree to the draggable itself attempting to match selector.
64+
65+
66+ function matchesSelectorAndParentsTo ( el
67+ /*: Node*/
68+ , selector
69+ /*: string*/
70+ , baseNode
71+ /*: Node*/
72+ )
73+ /*: boolean*/
74+ {
75+ var node = el ;
76+
77+ do {
78+ if ( matchesSelector ( node , selector ) ) return true ;
79+ if ( node === baseNode ) return false ;
80+ node = node . parentNode ;
81+ } while ( node ) ;
82+
83+ return false ;
84+ }
85+
86+ function addEvent ( el
87+ /*: ?Node*/
88+ , event
89+ /*: string*/
90+ , handler
91+ /*: Function*/
92+ )
93+ /*: void*/
94+ {
95+ if ( ! el ) {
96+ return ;
97+ }
98+
99+ if ( el . attachEvent ) {
100+ el . attachEvent ( 'on' + event , handler ) ;
101+ } else if ( el . addEventListener ) {
102+ el . addEventListener ( event , handler , true ) ;
103+ } else {
104+ // $FlowIgnore: Doesn't think elements are indexable
105+ el [ 'on' + event ] = handler ;
106+ }
107+ }
108+
109+ function removeEvent ( el
110+ /*: ?Node*/
111+ , event
112+ /*: string*/
113+ , handler
114+ /*: Function*/
115+ )
116+ /*: void*/
117+ {
118+ if ( ! el ) {
119+ return ;
120+ }
121+
122+ if ( el . detachEvent ) {
123+ el . detachEvent ( 'on' + event , handler ) ;
124+ } else if ( el . removeEventListener ) {
125+ el . removeEventListener ( event , handler , true ) ;
126+ } else {
127+ // $FlowIgnore: Doesn't think elements are indexable
128+ el [ 'on' + event ] = null ;
129+ }
130+ }
131+
132+ function outerHeight ( node
133+ /*: HTMLElement*/
134+ )
135+ /*: number*/
136+ {
137+ // This is deliberately excluding margin for our calculations, since we are using
138+ // offsetTop which is including margin. See getBoundPosition
139+ var height = node . clientHeight ;
140+ var computedStyle = node . ownerDocument . defaultView . getComputedStyle ( node ) ;
141+ height += ( 0 , _shims . int ) ( computedStyle . borderTopWidth ) ;
142+ height += ( 0 , _shims . int ) ( computedStyle . borderBottomWidth ) ;
143+ return height ;
144+ }
145+
146+ function outerWidth ( node
147+ /*: HTMLElement*/
148+ )
149+ /*: number*/
150+ {
151+ // This is deliberately excluding margin for our calculations, since we are using
152+ // offsetLeft which is including margin. See getBoundPosition
153+ var width = node . clientWidth ;
154+ var computedStyle = node . ownerDocument . defaultView . getComputedStyle ( node ) ;
155+ width += ( 0 , _shims . int ) ( computedStyle . borderLeftWidth ) ;
156+ width += ( 0 , _shims . int ) ( computedStyle . borderRightWidth ) ;
157+ return width ;
158+ }
159+
160+ function innerHeight ( node
161+ /*: HTMLElement*/
162+ )
163+ /*: number*/
164+ {
165+ var height = node . clientHeight ;
166+ var computedStyle = node . ownerDocument . defaultView . getComputedStyle ( node ) ;
167+ height -= ( 0 , _shims . int ) ( computedStyle . paddingTop ) ;
168+ height -= ( 0 , _shims . int ) ( computedStyle . paddingBottom ) ;
169+ return height ;
170+ }
171+
172+ function innerWidth ( node
173+ /*: HTMLElement*/
174+ )
175+ /*: number*/
176+ {
177+ var width = node . clientWidth ;
178+ var computedStyle = node . ownerDocument . defaultView . getComputedStyle ( node ) ;
179+ width -= ( 0 , _shims . int ) ( computedStyle . paddingLeft ) ;
180+ width -= ( 0 , _shims . int ) ( computedStyle . paddingRight ) ;
181+ return width ;
182+ } // Get from offsetParent
183+
184+
185+ function offsetXYFromParent ( evt
186+ /*: {clientX: number, clientY: number}*/
187+ , offsetParent
188+ /*: HTMLElement*/
189+ , scale
190+ /*: number*/
191+ )
192+ /*: ControlPosition*/
193+ {
194+ var isBody = offsetParent === offsetParent . ownerDocument . body ;
195+ var offsetParentRect = isBody ? {
196+ left : 0 ,
197+ top : 0
198+ } : offsetParent . getBoundingClientRect ( ) ;
199+ var x = ( evt . clientX + offsetParent . scrollLeft - offsetParentRect . left ) / scale ;
200+ var y = ( evt . clientY + offsetParent . scrollTop - offsetParentRect . top ) / scale ;
201+ return {
202+ x : x ,
203+ y : y
204+ } ;
205+ }
206+
207+ function createCSSTransform ( controlPos
208+ /*: ControlPosition*/
209+ , positionOffset
210+ /*: PositionOffsetControlPosition*/
211+ )
212+ /*: Object*/
213+ {
214+ var translation = getTranslation ( controlPos , positionOffset , 'px' ) ;
215+ return _defineProperty ( { } , ( 0 , _getPrefix . browserPrefixToKey ) ( 'transform' , _getPrefix . default ) , translation ) ;
216+ }
217+
218+ function createSVGTransform ( controlPos
219+ /*: ControlPosition*/
220+ , positionOffset
221+ /*: PositionOffsetControlPosition*/
222+ )
223+ /*: string*/
224+ {
225+ var translation = getTranslation ( controlPos , positionOffset , '' ) ;
226+ return translation ;
227+ }
228+
229+ function getTranslation ( _ref2 , positionOffset
230+ /*: PositionOffsetControlPosition*/
231+ , unitSuffix
232+ /*: string*/
233+ )
234+ /*: string*/
235+ {
236+ var x = _ref2 . x ,
237+ y = _ref2 . y ;
238+ var translation = "translate(" . concat ( x ) . concat ( unitSuffix , "," ) . concat ( y ) . concat ( unitSuffix , ")" ) ;
239+
240+ if ( positionOffset ) {
241+ var defaultX = "" . concat ( typeof positionOffset . x === 'string' ? positionOffset . x : positionOffset . x + unitSuffix ) ;
242+ var defaultY = "" . concat ( typeof positionOffset . y === 'string' ? positionOffset . y : positionOffset . y + unitSuffix ) ;
243+ translation = "translate(" . concat ( defaultX , ", " ) . concat ( defaultY , ")" ) + translation ;
244+ }
245+
246+ return translation ;
247+ }
248+
249+ function getTouch ( e
250+ /*: MouseTouchEvent*/
251+ , identifier
252+ /*: number*/
253+ )
254+ /*: ?{clientX: number, clientY: number}*/
255+ {
256+ return e . targetTouches && ( 0 , _shims . findInArray ) ( e . targetTouches , function ( t ) {
257+ return identifier === t . identifier ;
258+ } ) || e . changedTouches && ( 0 , _shims . findInArray ) ( e . changedTouches , function ( t ) {
259+ return identifier === t . identifier ;
260+ } ) ;
261+ }
262+
263+ function getTouchIdentifier ( e
264+ /*: MouseTouchEvent*/
265+ )
266+ /*: ?number*/
267+ {
268+ if ( e . targetTouches && e . targetTouches [ 0 ] ) return e . targetTouches [ 0 ] . identifier ;
269+ if ( e . changedTouches && e . changedTouches [ 0 ] ) return e . changedTouches [ 0 ] . identifier ;
270+ } // User-select Hacks:
271+ //
272+ // Useful for preventing blue highlights all over everything when dragging.
273+ // Note we're passing `document` b/c we could be iframed
274+
275+
276+ function addUserSelectStyles ( doc
277+ /*: ?Document*/
278+ ) {
279+ if ( ! doc ) return ;
280+ var styleEl = doc . getElementById ( 'react-draggable-style-el' ) ;
281+
282+ if ( ! styleEl ) {
283+ styleEl = doc . createElement ( 'style' ) ;
284+ styleEl . type = 'text/css' ;
285+ styleEl . id = 'react-draggable-style-el' ;
286+ styleEl . innerHTML = '.react-draggable-transparent-selection *::-moz-selection {all: inherit;}\n' ;
287+ styleEl . innerHTML += '.react-draggable-transparent-selection *::selection {all: inherit;}\n' ;
288+ doc . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( styleEl ) ;
289+ }
290+
291+ if ( doc . body ) addClassName ( doc . body , 'react-draggable-transparent-selection' ) ;
292+ }
293+
294+ function removeUserSelectStyles ( doc
295+ /*: ?Document*/
296+ ) {
297+ try {
298+ if ( doc && doc . body ) removeClassName ( doc . body , 'react-draggable-transparent-selection' ) ; // $FlowIgnore: IE
299+
300+ if ( doc . selection ) {
301+ // $FlowIgnore: IE
302+ doc . selection . empty ( ) ;
303+ } else {
304+ window . getSelection ( ) . removeAllRanges ( ) ; // remove selection caused by scroll
305+ }
306+ } catch ( e ) { // probably IE
307+ }
308+ }
309+
310+ function styleHacks ( )
311+ /*: Object*/
312+ {
313+ var childStyle
314+ /*: Object*/
315+ = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
316+ // Workaround IE pointer events; see #51
317+ // https://github.com/mzabriskie/react-draggable/issues/51#issuecomment-103488278
318+ return _objectSpread ( {
319+ touchAction : 'none'
320+ } , childStyle ) ;
321+ }
322+
323+ function addClassName ( el
324+ /*: HTMLElement*/
325+ , className
326+ /*: string*/
327+ ) {
328+ if ( el . classList ) {
329+ el . classList . add ( className ) ;
330+ } else {
331+ if ( ! el . className . match ( new RegExp ( "(?:^|\\s)" . concat ( className , "(?!\\S)" ) ) ) ) {
332+ el . className += " " . concat ( className ) ;
333+ }
334+ }
335+ }
336+
337+ function removeClassName ( el
338+ /*: HTMLElement*/
339+ , className
340+ /*: string*/
341+ ) {
342+ if ( el . classList ) {
343+ el . classList . remove ( className ) ;
344+ } else {
345+ el . className = el . className . replace ( new RegExp ( "(?:^|\\s)" . concat ( className , "(?!\\S)" ) , 'g' ) , '' ) ;
346+ }
347+ }
0 commit comments