@marsio/vue-draggable 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.draggableCoreProps = exports.draggableCoreDefaultProps = exports.defaultDraggableEventHandler = exports.default = void 0;
7
+ var _vue = require("vue");
8
+ var _vueTypes = _interopRequireDefault(require("vue-types"));
9
+ var _get = _interopRequireDefault(require("lodash/get"));
10
+ var _domFns = require("./utils/domFns");
11
+ var _positionFns = require("./utils/positionFns");
12
+ var _shims = require("./utils/shims");
13
+ var _log = _interopRequireDefault(require("./utils/log"));
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ // Simple abstraction for dragging events names.
16
+ const eventsFor = {
17
+ touch: {
18
+ start: 'touchstart',
19
+ move: 'touchmove',
20
+ stop: 'touchend'
21
+ },
22
+ mouse: {
23
+ start: 'mousedown',
24
+ move: 'mousemove',
25
+ stop: 'mouseup'
26
+ }
27
+ };
28
+ const defaultDraggableEventHandler = (e, data) => true;
29
+ exports.defaultDraggableEventHandler = defaultDraggableEventHandler;
30
+ const funcVoid = function () {};
31
+
32
+ // Default to mouse events.
33
+ let dragEventFor = eventsFor.mouse;
34
+ const draggableCoreDefaultProps = exports.draggableCoreDefaultProps = {
35
+ allowAnyClick: _vueTypes.default.bool.def(false),
36
+ disabled: _vueTypes.default.bool.def(false),
37
+ enableUserSelectHack: _vueTypes.default.bool.def(true),
38
+ startFn: _vueTypes.default.func.def(defaultDraggableEventHandler).def(funcVoid),
39
+ dragFn: _vueTypes.default.func.def(defaultDraggableEventHandler).def(funcVoid),
40
+ stopFn: _vueTypes.default.func.def(defaultDraggableEventHandler).def(funcVoid),
41
+ scale: _vueTypes.default.number.def(1)
42
+ };
43
+ const draggableCoreProps = exports.draggableCoreProps = {
44
+ ...draggableCoreDefaultProps,
45
+ cancel: _vueTypes.default.string,
46
+ offsetParent: _vueTypes.default.custom(_shims.prop_is_not_node, 'Draggable\'s offsetParent must be a DOM Node.'),
47
+ grid: _vueTypes.default.arrayOf(_vueTypes.default.number),
48
+ handle: _vueTypes.default.string,
49
+ nodeRef: _vueTypes.default.object.def(null)
50
+ };
51
+ const componentName = 'DraggableCore';
52
+ var _default = exports.default = (0, _vue.defineComponent)({
53
+ compatConfig: {
54
+ MODE: 3
55
+ },
56
+ name: componentName,
57
+ inheritAttrs: false,
58
+ props: {
59
+ ...draggableCoreProps
60
+ // style: dontSetMe('style', componentName),
61
+ // class: dontSetMe('class', componentName),
62
+ // transform: dontSetMe('transform', componentName),
63
+ },
64
+ setup(props, _ref) {
65
+ let {
66
+ slots,
67
+ emit
68
+ } = _ref;
69
+ const rootElement = (0, _vue.ref)(null);
70
+ const displayName = 'DraggableCore';
71
+ const state = (0, _vue.reactive)({
72
+ dragging: false,
73
+ // Used while dragging to determine deltas.
74
+ lastX: NaN,
75
+ lastY: NaN,
76
+ touchIdentifier: null,
77
+ mounted: false
78
+ });
79
+ const findDOMNode = () => {
80
+ return (0, _get.default)(props, 'nodeRef.value') || rootElement.value;
81
+ };
82
+ const handleDrag = e => {
83
+ // Get the current drag point from the event. This is used as the offset.
84
+ const position = (0, _positionFns.getControlPosition)(e, {
85
+ props,
86
+ findDOMNode
87
+ }, state.touchIdentifier);
88
+ if (position == null) return;
89
+ let {
90
+ x,
91
+ y
92
+ } = position;
93
+
94
+ // Snap to grid if prop has been provided
95
+ if (Array.isArray(props.grid)) {
96
+ let deltaX = x - state.lastX,
97
+ deltaY = y - state.lastY;
98
+ [deltaX, deltaY] = (0, _positionFns.snapToGrid)(props.grid, deltaX, deltaY);
99
+ if (!deltaX && !deltaY) return; // skip useless drag
100
+ x = state.lastX + deltaX, y = state.lastY + deltaY;
101
+ }
102
+ const coreEvent = (0, _positionFns.createCoreData)({
103
+ props,
104
+ findDOMNode,
105
+ state
106
+ }, x, y);
107
+ (0, _log.default)('DraggableCore: handleDrag: %j', coreEvent);
108
+
109
+ // Call event handler. If it returns explicit false, trigger end.
110
+ const shouldUpdate = props.dragFn?.(e, coreEvent);
111
+ if (shouldUpdate === false || state.mounted === false) {
112
+ try {
113
+ handleDragStop(new MouseEvent('mouseup'));
114
+ } catch (err) {
115
+ // Old browsers
116
+ const event = document.createEvent('MouseEvents');
117
+ event.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
118
+ handleDragStop(event);
119
+ }
120
+ return;
121
+ }
122
+ state.lastX = x;
123
+ state.lastY = y;
124
+ };
125
+ const handleDragStop = e => {
126
+ if (!state.dragging) return;
127
+ const position = (0, _positionFns.getControlPosition)(e, {
128
+ props,
129
+ findDOMNode
130
+ }, state.touchIdentifier);
131
+ if (position == null) return;
132
+ let {
133
+ x,
134
+ y
135
+ } = position;
136
+
137
+ // Snap to grid if prop has been provided
138
+ if (Array.isArray(props.grid)) {
139
+ let deltaX = x - state.lastX || 0;
140
+ let deltaY = y - state.lastY || 0;
141
+ [deltaX, deltaY] = (0, _positionFns.snapToGrid)(props.grid, deltaX, deltaY);
142
+ x = state.lastX + deltaX, y = state.lastY + deltaY;
143
+ }
144
+ const coreEvent = (0, _positionFns.createCoreData)({
145
+ props,
146
+ findDOMNode,
147
+ state
148
+ }, x, y);
149
+
150
+ // Call event handler
151
+ const shouldContinue = props.stopFn?.(e, coreEvent);
152
+ if (shouldContinue === false || state.mounted === false) return false;
153
+ const thisNode = findDOMNode();
154
+ if (thisNode) {
155
+ // Remove user-select hack
156
+ if (props.enableUserSelectHack) (0, _domFns.removeUserSelectStyles)(thisNode.ownerDocument);
157
+ }
158
+ (0, _log.default)('DraggableCore: handleDragStop: %j', coreEvent);
159
+
160
+ // Reset the el.
161
+ state.dragging = false;
162
+ state.lastX = NaN;
163
+ state.lastY = NaN;
164
+ if (thisNode) {
165
+ // Remove event handlers
166
+ (0, _log.default)('DraggableCore: Removing handlers');
167
+ (0, _domFns.removeEvent)(thisNode.ownerDocument, dragEventFor.move, handleDrag);
168
+ (0, _domFns.removeEvent)(thisNode.ownerDocument, dragEventFor.stop, handleDragStop);
169
+ }
170
+ };
171
+ const handleDragStart = e => {
172
+ // Make it possible to attach event handlers on top of this one.
173
+ emit('mousedown', e);
174
+
175
+ // Only accept left-clicks.
176
+ if (!props.allowAnyClick && typeof e.button === 'number' && e.button !== 0) return false;
177
+
178
+ // Get nodes. Be sure to grab relative document (could be iframed)
179
+ const thisNode = findDOMNode();
180
+ if (!(0, _get.default)(thisNode, 'ownerDocument.body')) {
181
+ throw new Error('<DraggableCore> not mounted on DragStart!');
182
+ }
183
+ const {
184
+ ownerDocument
185
+ } = thisNode;
186
+
187
+ // Short circuit if handle or cancel prop was provided and selector doesn't match.
188
+ if (props.disabled || !(e.target instanceof ownerDocument.defaultView.Node) || props.handle && !(0, _domFns.matchesSelectorAndParentsTo)(e.target, props.handle, thisNode) || props.cancel && (0, _domFns.matchesSelectorAndParentsTo)(e.target, props.cancel, thisNode)) {
189
+ return;
190
+ }
191
+
192
+ // Prevent scrolling on mobile devices, like ipad/iphone.
193
+ // Important that this is after handle/cancel.
194
+ if (e.type === 'touchstart') e.preventDefault();
195
+
196
+ // Set touch identifier in component state if this is a touch event. This allows us to
197
+ // distinguish between individual touches on multitouch screens by identifying which
198
+ // touchpoint was set to this element.
199
+ const touchIdentifier = (0, _domFns.getTouchIdentifier)(e);
200
+ state.touchIdentifier = touchIdentifier;
201
+ // Get the current drag point from the event. This is used as the offset.
202
+ const position = (0, _positionFns.getControlPosition)(e, {
203
+ props,
204
+ findDOMNode
205
+ }, touchIdentifier);
206
+ if (position == null) return;
207
+ const {
208
+ x,
209
+ y
210
+ } = position;
211
+
212
+ // Create an event object with all the data parents need to make a decision here.
213
+ const coreEvent = (0, _positionFns.createCoreData)({
214
+ props,
215
+ findDOMNode,
216
+ state
217
+ }, x, y);
218
+ (0, _log.default)('DraggableCore: handleDragStart: %j', coreEvent);
219
+
220
+ // Call event handler. If it returns explicit false, cancel.
221
+ (0, _log.default)('calling', props.startFn);
222
+ const shouldUpdate = props.startFn(e, coreEvent);
223
+ if (shouldUpdate === false || state.mounted === false) return;
224
+
225
+ // Add a style to the body to disable user-select. This prevents text from
226
+ // being selected all over the page.
227
+ if (props.enableUserSelectHack) (0, _domFns.addUserSelectStyles)(ownerDocument);
228
+
229
+ // Initiate dragging. Set the current x and y as offsets
230
+ // so we know how much we've moved during the drag. This allows us
231
+ // to drag elements around even if they have been moved, without issue.
232
+ state.dragging = true;
233
+ state.lastX = x;
234
+ state.lastY = y;
235
+
236
+ // Add events to the document directly so we catch when the user's mouse/touch moves outside of
237
+ // this element. We use different events depending on whether or not we have detected that this
238
+ // is a touch-capable device.
239
+ (0, _domFns.addEvent)(ownerDocument, dragEventFor.move, handleDrag);
240
+ (0, _domFns.addEvent)(ownerDocument, dragEventFor.stop, handleDragStop);
241
+ };
242
+ const onMousedown = e => {
243
+ dragEventFor = eventsFor.mouse; // on touchscreen laptops we could switch back to mouse
244
+ return handleDragStart(e);
245
+ };
246
+
247
+ // const onMoueDown = (e: MouseTouchEvent) => {
248
+ // dragEventFor = eventsFor.mouse // on touchscreen laptops we could switch back to mouse
249
+ // return handleDragStart(e)
250
+ // }
251
+
252
+ const onMouseup = e => {
253
+ dragEventFor = eventsFor.mouse;
254
+ return handleDragStop(e);
255
+ };
256
+ const onTouchStart = e => {
257
+ // We're on a touch device now, so change the event handlers
258
+ dragEventFor = eventsFor.touch;
259
+ return handleDragStart(e);
260
+ };
261
+ const onTouchend = e => {
262
+ // We're on a touch device now, so change the event handlers
263
+ dragEventFor = eventsFor.touch;
264
+ return handleDragStop(e);
265
+ };
266
+ (0, _vue.onMounted)(() => {
267
+ state.mounted = true;
268
+ const thisNode = findDOMNode();
269
+ if (thisNode) {
270
+ (0, _domFns.addEvent)(thisNode, eventsFor.touch.start, onTouchStart, {
271
+ passive: false
272
+ });
273
+ }
274
+ });
275
+ (0, _vue.onUnmounted)(() => {
276
+ state.mounted = false;
277
+ // Remove any leftover event handlers. Remove both touch and mouse handlers in case
278
+ // some browser quirk caused a touch event to fire during a mouse move, or vice versa.
279
+ const thisNode = findDOMNode();
280
+ if (thisNode) {
281
+ const {
282
+ ownerDocument
283
+ } = thisNode;
284
+ (0, _domFns.removeEvent)(ownerDocument, eventsFor.mouse.move, handleDrag);
285
+ (0, _domFns.removeEvent)(ownerDocument, eventsFor.touch.move, handleDrag);
286
+ (0, _domFns.removeEvent)(ownerDocument, eventsFor.mouse.stop, handleDragStop);
287
+ (0, _domFns.removeEvent)(ownerDocument, eventsFor.touch.stop, handleDragStop);
288
+ (0, _domFns.removeEvent)(thisNode, eventsFor.touch.start, onTouchStart, {
289
+ passive: false
290
+ });
291
+ if (props.enableUserSelectHack) (0, _domFns.removeUserSelectStyles)(ownerDocument);
292
+ }
293
+ });
294
+ return () => {
295
+ const slotContent = (0, _vue.renderSlot)(slots, 'default');
296
+ let children = slotContent.children;
297
+ if (!Array.isArray(children)) {
298
+ children = []; // 如果不是数组,则使用空数组
299
+ }
300
+ const child = (0, _get.default)(children, '0.children[0]');
301
+ const clonedChildren = (0, _vue.isVNode)(child) ? (0, _vue.cloneVNode)(child, {
302
+ onMousedown,
303
+ onMouseup,
304
+ onTouchend,
305
+ ref: rootElement
306
+ }) : child;
307
+ return clonedChildren;
308
+ };
309
+ }
310
+ });
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ const {
4
+ default: Draggable,
5
+ DraggableCore
6
+ } = require('./Draggable');
7
+ module.exports = Draggable;
8
+ module.exports.default = Draggable;
9
+ module.exports.DraggableCore = DraggableCore;
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addClassName = addClassName;
7
+ exports.addEvent = addEvent;
8
+ exports.addUserSelectStyles = addUserSelectStyles;
9
+ exports.createCSSTransform = createCSSTransform;
10
+ exports.createSVGTransform = createSVGTransform;
11
+ exports.getTouch = getTouch;
12
+ exports.getTouchIdentifier = getTouchIdentifier;
13
+ exports.getTranslation = getTranslation;
14
+ exports.innerHeight = innerHeight;
15
+ exports.innerWidth = innerWidth;
16
+ exports.matchesSelector = matchesSelector;
17
+ exports.matchesSelectorAndParentsTo = matchesSelectorAndParentsTo;
18
+ exports.offsetXYFromParent = offsetXYFromParent;
19
+ exports.outerHeight = outerHeight;
20
+ exports.outerWidth = outerWidth;
21
+ exports.removeClassName = removeClassName;
22
+ exports.removeEvent = removeEvent;
23
+ exports.removeUserSelectStyles = removeUserSelectStyles;
24
+ var _getPrefix = _interopRequireWildcard(require("./getPrefix"));
25
+ var _shims = require("./shims");
26
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
27
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
28
+ let matchesSelectorFunc = '';
29
+ function matchesSelector(el, selector) {
30
+ if (!matchesSelectorFunc) {
31
+ matchesSelectorFunc = (0, _shims.findInArray)(['matches', 'webkitMatchesSelector', 'mozMatchesSelector', 'msMatchesSelector', 'oMatchesSelector'], function (method) {
32
+ return (0, _shims.isFunction)(el[method]);
33
+ });
34
+ }
35
+
36
+ // Might not be found entirely (not an Element?) - in that case, bail
37
+ if (!(0, _shims.isFunction)(el[matchesSelectorFunc])) return false;
38
+ return el[matchesSelectorFunc](selector);
39
+ }
40
+
41
+ // Works up the tree to the draggable itself attempting to match selector.
42
+ function matchesSelectorAndParentsTo(el, selector, baseNode) {
43
+ let node = el;
44
+ do {
45
+ if (matchesSelector(node, selector)) return true;
46
+ if (node === baseNode) return false;
47
+ node = node.parentNode;
48
+ } while (node);
49
+ return false;
50
+ }
51
+ function addEvent(el, event, handler, inputOptions) {
52
+ if (!el) return;
53
+ const options = {
54
+ capture: true,
55
+ ...inputOptions
56
+ };
57
+ if (el.addEventListener) {
58
+ el.addEventListener(event, handler, options);
59
+ } else if (el.attachEvent) {
60
+ el.attachEvent(`on${event}`, handler);
61
+ } else {
62
+ el[`on${event}`] = handler;
63
+ }
64
+ }
65
+ function removeEvent(el, event, handler, inputOptions) {
66
+ if (!el) return;
67
+ const options = {
68
+ capture: true,
69
+ ...inputOptions
70
+ };
71
+ if (el.removeEventListener) {
72
+ el.removeEventListener(event, handler, options);
73
+ } else if (el.detachEvent) {
74
+ el.detachEvent('on' + event, handler);
75
+ } else {
76
+ el[`on${event}`] = null;
77
+ }
78
+ }
79
+ function outerHeight(node) {
80
+ // This is deliberately excluding margin for our calculations, since we are using
81
+ // offsetTop which is including margin. See getBoundPosition
82
+ let height = node.clientHeight;
83
+ const computedStyle = node.ownerDocument.defaultView?.getComputedStyle(node);
84
+ height += (0, _shims.int)(computedStyle.borderTopWidth);
85
+ height += (0, _shims.int)(computedStyle.borderBottomWidth);
86
+ return height;
87
+ }
88
+ function outerWidth(node) {
89
+ // This is deliberately excluding margin for our calculations, since we are using
90
+ // offsetLeft which is including margin. See getBoundPosition
91
+ let width = node.clientWidth;
92
+ const computedStyle = node.ownerDocument?.defaultView?.getComputedStyle(node);
93
+ width += (0, _shims.int)(computedStyle.borderLeftWidth);
94
+ width += (0, _shims.int)(computedStyle.borderRightWidth);
95
+ return width;
96
+ }
97
+ function innerHeight(node) {
98
+ let height = node.clientHeight;
99
+ const computedStyle = node.ownerDocument?.defaultView?.getComputedStyle(node);
100
+ height -= (0, _shims.int)(computedStyle.paddingTop);
101
+ height -= (0, _shims.int)(computedStyle.paddingBottom);
102
+ return height;
103
+ }
104
+ function innerWidth(node) {
105
+ let width = node.clientWidth;
106
+ const computedStyle = node.ownerDocument?.defaultView?.getComputedStyle(node);
107
+ width -= (0, _shims.int)(computedStyle.paddingLeft);
108
+ width -= (0, _shims.int)(computedStyle.paddingRight);
109
+ return width;
110
+ }
111
+
112
+ // Get from offsetParent
113
+ function offsetXYFromParent(evt, offsetParent, scale) {
114
+ const isBody = offsetParent === offsetParent.ownerDocument.body;
115
+ const offsetParentRect = isBody ? {
116
+ left: 0,
117
+ top: 0
118
+ } : offsetParent.getBoundingClientRect();
119
+ const x = (evt.clientX + offsetParent.scrollLeft - offsetParentRect.left) / scale;
120
+ const y = (evt.clientY + offsetParent.scrollTop - offsetParentRect.top) / scale;
121
+ return {
122
+ x,
123
+ y
124
+ };
125
+ }
126
+ function createCSSTransform(controlPos, positionOffset) {
127
+ const translation = getTranslation(controlPos, positionOffset, 'px');
128
+ return {
129
+ [(0, _getPrefix.browserPrefixToKey)('transform', _getPrefix.default)]: translation
130
+ };
131
+ }
132
+ function createSVGTransform(controlPos, positionOffset) {
133
+ const translation = getTranslation(controlPos, positionOffset, '');
134
+ return translation;
135
+ }
136
+ function getTranslation(_ref, positionOffset, unitSuffix) {
137
+ let {
138
+ x,
139
+ y
140
+ } = _ref;
141
+ let translation = `translate(${x}${unitSuffix},${y}${unitSuffix})`;
142
+ if (positionOffset) {
143
+ const defaultX = `${typeof positionOffset.x === 'string' ? positionOffset.x : positionOffset.x + unitSuffix}`;
144
+ const defaultY = `${typeof positionOffset.y === 'string' ? positionOffset.y : positionOffset.y + unitSuffix}`;
145
+ translation = `translate(${defaultX}, ${defaultY})` + translation;
146
+ }
147
+ return translation;
148
+ }
149
+ function getTouch(e, identifier) {
150
+ return e.targetTouches && (0, _shims.findInArray)(e.targetTouches, t => identifier === t.identifier) || e.changedTouches && (0, _shims.findInArray)(e.changedTouches, t => identifier === t.identifier);
151
+ }
152
+ function getTouchIdentifier(e) {
153
+ if (e.targetTouches && e.targetTouches[0]) return e.targetTouches[0].identifier;
154
+ if (e.changedTouches && e.changedTouches[0]) return e.changedTouches[0].identifier;
155
+ return;
156
+ }
157
+
158
+ // User-select Hacks:
159
+ //
160
+ // Useful for preventing blue highlights all over everything when dragging.
161
+
162
+ // Note we're passing `document` b/c we could be iframed
163
+ function addUserSelectStyles(doc) {
164
+ if (!doc) return;
165
+ let styleEl = doc.getElementById('vue-draggable-style-el');
166
+ if (!styleEl) {
167
+ styleEl = doc.createElement('style');
168
+ styleEl.type = 'text/css';
169
+ styleEl.id = 'vue-draggable-style-el';
170
+ styleEl.innerHTML = '.vue-draggable-transparent-selection *::-moz-selection {all: inherit;}\n';
171
+ styleEl.innerHTML += '.vue-draggable-transparent-selection *::selection {all: inherit;}\n';
172
+ doc.getElementsByTagName('head')[0].appendChild(styleEl);
173
+ }
174
+ if (doc.body) addClassName(doc.body, 'vue-draggable-transparent-selection');
175
+ }
176
+ function removeUserSelectStyles(doc) {
177
+ if (!doc) return;
178
+ try {
179
+ if (doc.body) removeClassName(doc.body, 'vue-draggable-transparent-selection');
180
+ if (doc.selection) {
181
+ doc.selection.empty();
182
+ } else {
183
+ // Remove selection caused by scroll, unless it's a focused input
184
+ // (we use doc.defaultView in case we're in an iframe)
185
+ const selection = (doc.defaultView || window).getSelection();
186
+ if (selection && selection.type !== 'Caret') {
187
+ selection.removeAllRanges();
188
+ }
189
+ }
190
+ } catch (e) {
191
+ // probably IE
192
+ }
193
+ }
194
+ function addClassName(el, className) {
195
+ if (el.classList) {
196
+ el.classList.add(className);
197
+ } else {
198
+ if (!el.className.match(new RegExp(`(?:^|\\s)${className}(?!\\S)`))) {
199
+ el.className += ` ${className}`;
200
+ }
201
+ }
202
+ }
203
+ function removeClassName(el, className) {
204
+ if (el.classList) {
205
+ el.classList.remove(className);
206
+ } else {
207
+ el.className = el.className.replace(new RegExp(`(?:^|\\s)${className}(?!\\S)`, 'g'), '');
208
+ }
209
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.browserPrefixToKey = browserPrefixToKey;
7
+ exports.browserPrefixToStyle = browserPrefixToStyle;
8
+ exports.default = void 0;
9
+ exports.getPrefix = getPrefix;
10
+ const prefixes = ['Moz', 'Webkit', 'O', 'ms'];
11
+ function getPrefix() {
12
+ let prop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'transform';
13
+ // Checking specifically for 'window.document' is for pseudo-browser server-side
14
+ // environments that define 'window' as the global context.
15
+ if (typeof window === 'undefined' || typeof window.document === 'undefined') return '';
16
+ const style = window.document.documentElement.style;
17
+ if (prop in style) return '';
18
+ for (let i = 0; i < prefixes.length; i++) {
19
+ if (browserPrefixToKey(prop, prefixes[i]) in style) return prefixes[i];
20
+ }
21
+ return '';
22
+ }
23
+ function browserPrefixToKey(prop, prefix) {
24
+ return prefix ? `${prefix}${kebabToTitleCase(prop)}` : prop;
25
+ }
26
+ function browserPrefixToStyle(prop, prefix) {
27
+ return prefix ? `-${prefix.toLowerCase()}-${prop}` : prop;
28
+ }
29
+ function kebabToTitleCase(str) {
30
+ let out = '';
31
+ let shouldCapitalize = true;
32
+ for (let i = 0; i < str.length; i++) {
33
+ if (shouldCapitalize) {
34
+ out += str[i].toUpperCase();
35
+ shouldCapitalize = false;
36
+ } else if (str[i] === '-') {
37
+ shouldCapitalize = true;
38
+ } else {
39
+ out += str[i];
40
+ }
41
+ }
42
+ return out;
43
+ }
44
+
45
+ // Default export is the prefix itself, like 'Moz', 'Webkit', etc
46
+ // Note that you may have to re-test for certain things; for instance, Chrome 50
47
+ // can handle unprefixed `transform`, but not unprefixed `user-select`
48
+ var _default = exports.default = getPrefix();
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = log;
7
+ function log() {
8
+ // if (process.env.DRAGGABLE_DEBUG) console.log(...args);
9
+ }