@lucasols/dnd-kit-utilities 0.1.3 → 0.2.1
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.
- package/dist/index.d.ts +119 -11
- package/dist/index.js +229 -7
- package/dist/index.js.map +1 -0
- package/package.json +18 -16
- package/dist/adjustment.d.ts +0 -2
- package/dist/coordinates/getEventCoordinates.d.ts +0 -5
- package/dist/coordinates/index.d.ts +0 -2
- package/dist/coordinates/types.d.ts +0 -4
- package/dist/css.d.ts +0 -25
- package/dist/dnd-kit-utilities.cjs.development.js +0 -361
- package/dist/dnd-kit-utilities.cjs.development.js.map +0 -1
- package/dist/dnd-kit-utilities.cjs.production.min.js +0 -2
- package/dist/dnd-kit-utilities.cjs.production.min.js.map +0 -1
- package/dist/dnd-kit-utilities.esm.js +0 -333
- package/dist/dnd-kit-utilities.esm.js.map +0 -1
- package/dist/event/hasViewportRelativeCoordinates.d.ts +0 -1
- package/dist/event/index.d.ts +0 -3
- package/dist/event/isKeyboardEvent.d.ts +0 -1
- package/dist/event/isTouchEvent.d.ts +0 -1
- package/dist/execution-context/canUseDOM.d.ts +0 -1
- package/dist/execution-context/getOwnerDocument.d.ts +0 -1
- package/dist/execution-context/getWindow.d.ts +0 -1
- package/dist/execution-context/index.d.ts +0 -3
- package/dist/focus/findFirstFocusableNode.d.ts +0 -1
- package/dist/focus/index.d.ts +0 -1
- package/dist/hooks/index.d.ts +0 -9
- package/dist/hooks/useCombinedRefs.d.ts +0 -1
- package/dist/hooks/useEvent.d.ts +0 -1
- package/dist/hooks/useInterval.d.ts +0 -1
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +0 -6
- package/dist/hooks/useLatestValue.d.ts +0 -2
- package/dist/hooks/useLazyMemo.d.ts +0 -1
- package/dist/hooks/useNodeRef.d.ts +0 -2
- package/dist/hooks/usePrevious.d.ts +0 -1
- package/dist/hooks/useUniqueId.d.ts +0 -1
- package/dist/type-guards/index.d.ts +0 -5
- package/dist/type-guards/isDocument.d.ts +0 -1
- package/dist/type-guards/isHTMLElement.d.ts +0 -1
- package/dist/type-guards/isNode.d.ts +0 -1
- package/dist/type-guards/isSVGElement.d.ts +0 -1
- package/dist/type-guards/isWindow.d.ts +0 -1
- package/dist/types.d.ts +0 -6
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
function useCombinedRefs() {
|
|
8
|
-
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
9
|
-
refs[_key] = arguments[_key];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return react.useMemo(() => node => {
|
|
13
|
-
refs.forEach(ref => ref(node));
|
|
14
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
15
|
-
refs);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
|
|
19
|
-
const canUseDOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
20
|
-
|
|
21
|
-
function isWindow(element) {
|
|
22
|
-
const elementString = Object.prototype.toString.call(element);
|
|
23
|
-
return elementString === '[object Window]' || // In Electron context the Window object serializes to [object global]
|
|
24
|
-
elementString === '[object global]';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function isNode(node) {
|
|
28
|
-
return 'nodeType' in node;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getWindow(target) {
|
|
32
|
-
var _target$ownerDocument, _target$ownerDocument2;
|
|
33
|
-
|
|
34
|
-
if (!target) {
|
|
35
|
-
return window;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (isWindow(target)) {
|
|
39
|
-
return target;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!isNode(target)) {
|
|
43
|
-
return window;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function isDocument(node) {
|
|
50
|
-
const {
|
|
51
|
-
Document
|
|
52
|
-
} = getWindow(node);
|
|
53
|
-
return node instanceof Document;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function isHTMLElement(node) {
|
|
57
|
-
if (isWindow(node)) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return node instanceof getWindow(node).HTMLElement;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function isSVGElement(node) {
|
|
65
|
-
return node instanceof getWindow(node).SVGElement;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getOwnerDocument(target) {
|
|
69
|
-
if (!target) {
|
|
70
|
-
return document;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (isWindow(target)) {
|
|
74
|
-
return target.document;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!isNode(target)) {
|
|
78
|
-
return document;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (isDocument(target)) {
|
|
82
|
-
return target;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (isHTMLElement(target) || isSVGElement(target)) {
|
|
86
|
-
return target.ownerDocument;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return document;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* A hook that resolves to useEffect on the server and useLayoutEffect on the client
|
|
94
|
-
* @param callback {function} Callback function that is invoked when the dependencies of the hook change
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
const useIsomorphicLayoutEffect = canUseDOM ? react.useLayoutEffect : react.useEffect;
|
|
98
|
-
|
|
99
|
-
function useEvent(handler) {
|
|
100
|
-
const handlerRef = react.useRef(handler);
|
|
101
|
-
useIsomorphicLayoutEffect(() => {
|
|
102
|
-
handlerRef.current = handler;
|
|
103
|
-
});
|
|
104
|
-
return react.useCallback(function () {
|
|
105
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
106
|
-
args[_key] = arguments[_key];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return handlerRef.current == null ? void 0 : handlerRef.current(...args);
|
|
110
|
-
}, []);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function useInterval() {
|
|
114
|
-
const intervalRef = react.useRef(null);
|
|
115
|
-
const set = react.useCallback((listener, duration) => {
|
|
116
|
-
intervalRef.current = setInterval(listener, duration);
|
|
117
|
-
}, []);
|
|
118
|
-
const clear = react.useCallback(() => {
|
|
119
|
-
if (intervalRef.current !== null) {
|
|
120
|
-
clearInterval(intervalRef.current);
|
|
121
|
-
intervalRef.current = null;
|
|
122
|
-
}
|
|
123
|
-
}, []);
|
|
124
|
-
return [set, clear];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function useLatestValue(value, dependencies) {
|
|
128
|
-
if (dependencies === void 0) {
|
|
129
|
-
dependencies = [value];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const valueRef = react.useRef(value);
|
|
133
|
-
useIsomorphicLayoutEffect(() => {
|
|
134
|
-
if (valueRef.current !== value) {
|
|
135
|
-
valueRef.current = value;
|
|
136
|
-
}
|
|
137
|
-
}, dependencies);
|
|
138
|
-
return valueRef;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function useLazyMemo(callback, dependencies) {
|
|
142
|
-
const valueRef = react.useRef();
|
|
143
|
-
return react.useMemo(() => {
|
|
144
|
-
const newValue = callback(valueRef.current);
|
|
145
|
-
valueRef.current = newValue;
|
|
146
|
-
return newValue;
|
|
147
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
148
|
-
[...dependencies]);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function useNodeRef(onChange) {
|
|
152
|
-
const onChangeHandler = useEvent(onChange);
|
|
153
|
-
const node = react.useRef(null);
|
|
154
|
-
const setNodeRef = react.useCallback(element => {
|
|
155
|
-
if (element !== node.current) {
|
|
156
|
-
onChangeHandler == null ? void 0 : onChangeHandler(element, node.current);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
node.current = element;
|
|
160
|
-
}, //eslint-disable-next-line
|
|
161
|
-
[]);
|
|
162
|
-
return [node, setNodeRef];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function usePrevious(value) {
|
|
166
|
-
const ref = react.useRef();
|
|
167
|
-
react.useEffect(() => {
|
|
168
|
-
ref.current = value;
|
|
169
|
-
}, [value]);
|
|
170
|
-
return ref.current;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
let ids = {};
|
|
174
|
-
function useUniqueId(prefix, value) {
|
|
175
|
-
return react.useMemo(() => {
|
|
176
|
-
if (value) {
|
|
177
|
-
return value;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
|
|
181
|
-
ids[prefix] = id;
|
|
182
|
-
return prefix + "-" + id;
|
|
183
|
-
}, [prefix, value]);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function createAdjustmentFn(modifier) {
|
|
187
|
-
return function (object) {
|
|
188
|
-
for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
189
|
-
adjustments[_key - 1] = arguments[_key];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return adjustments.reduce((accumulator, adjustment) => {
|
|
193
|
-
const entries = Object.entries(adjustment);
|
|
194
|
-
|
|
195
|
-
for (const [key, valueAdjustment] of entries) {
|
|
196
|
-
const value = accumulator[key];
|
|
197
|
-
|
|
198
|
-
if (value != null) {
|
|
199
|
-
accumulator[key] = value + modifier * valueAdjustment;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return accumulator;
|
|
204
|
-
}, { ...object
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const add = /*#__PURE__*/createAdjustmentFn(1);
|
|
210
|
-
const subtract = /*#__PURE__*/createAdjustmentFn(-1);
|
|
211
|
-
|
|
212
|
-
function hasViewportRelativeCoordinates(event) {
|
|
213
|
-
return 'clientX' in event && 'clientY' in event;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function isKeyboardEvent(event) {
|
|
217
|
-
if (!event) {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const {
|
|
222
|
-
KeyboardEvent
|
|
223
|
-
} = getWindow(event.target);
|
|
224
|
-
return KeyboardEvent && event instanceof KeyboardEvent;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function isTouchEvent(event) {
|
|
228
|
-
if (!event) {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const {
|
|
233
|
-
TouchEvent
|
|
234
|
-
} = getWindow(event.target);
|
|
235
|
-
return TouchEvent && event instanceof TouchEvent;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Returns the normalized x and y coordinates for mouse and touch events.
|
|
240
|
-
*/
|
|
241
|
-
|
|
242
|
-
function getEventCoordinates(event) {
|
|
243
|
-
if (isTouchEvent(event)) {
|
|
244
|
-
if (event.touches && event.touches.length) {
|
|
245
|
-
const {
|
|
246
|
-
clientX: x,
|
|
247
|
-
clientY: y
|
|
248
|
-
} = event.touches[0];
|
|
249
|
-
return {
|
|
250
|
-
x,
|
|
251
|
-
y
|
|
252
|
-
};
|
|
253
|
-
} else if (event.changedTouches && event.changedTouches.length) {
|
|
254
|
-
const {
|
|
255
|
-
clientX: x,
|
|
256
|
-
clientY: y
|
|
257
|
-
} = event.changedTouches[0];
|
|
258
|
-
return {
|
|
259
|
-
x,
|
|
260
|
-
y
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (hasViewportRelativeCoordinates(event)) {
|
|
266
|
-
return {
|
|
267
|
-
x: event.clientX,
|
|
268
|
-
y: event.clientY
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const CSS = /*#__PURE__*/Object.freeze({
|
|
276
|
-
Translate: {
|
|
277
|
-
toString(transform) {
|
|
278
|
-
if (!transform) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const {
|
|
283
|
-
x,
|
|
284
|
-
y
|
|
285
|
-
} = transform;
|
|
286
|
-
return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
},
|
|
290
|
-
Scale: {
|
|
291
|
-
toString(transform) {
|
|
292
|
-
if (!transform) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const {
|
|
297
|
-
scaleX,
|
|
298
|
-
scaleY
|
|
299
|
-
} = transform;
|
|
300
|
-
return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
},
|
|
304
|
-
Transform: {
|
|
305
|
-
toString(transform) {
|
|
306
|
-
if (!transform) {
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return [CSS.Translate.toString(transform), CSS.Scale.toString(transform)].join(' ');
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
},
|
|
314
|
-
Transition: {
|
|
315
|
-
toString(_ref) {
|
|
316
|
-
let {
|
|
317
|
-
property,
|
|
318
|
-
duration,
|
|
319
|
-
easing
|
|
320
|
-
} = _ref;
|
|
321
|
-
return property + " " + duration + "ms " + easing;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
const SELECTOR = 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';
|
|
328
|
-
function findFirstFocusableNode(element) {
|
|
329
|
-
if (element.matches(SELECTOR)) {
|
|
330
|
-
return element;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
return element.querySelector(SELECTOR);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
exports.CSS = CSS;
|
|
337
|
-
exports.add = add;
|
|
338
|
-
exports.canUseDOM = canUseDOM;
|
|
339
|
-
exports.findFirstFocusableNode = findFirstFocusableNode;
|
|
340
|
-
exports.getEventCoordinates = getEventCoordinates;
|
|
341
|
-
exports.getOwnerDocument = getOwnerDocument;
|
|
342
|
-
exports.getWindow = getWindow;
|
|
343
|
-
exports.hasViewportRelativeCoordinates = hasViewportRelativeCoordinates;
|
|
344
|
-
exports.isDocument = isDocument;
|
|
345
|
-
exports.isHTMLElement = isHTMLElement;
|
|
346
|
-
exports.isKeyboardEvent = isKeyboardEvent;
|
|
347
|
-
exports.isNode = isNode;
|
|
348
|
-
exports.isSVGElement = isSVGElement;
|
|
349
|
-
exports.isTouchEvent = isTouchEvent;
|
|
350
|
-
exports.isWindow = isWindow;
|
|
351
|
-
exports.subtract = subtract;
|
|
352
|
-
exports.useCombinedRefs = useCombinedRefs;
|
|
353
|
-
exports.useEvent = useEvent;
|
|
354
|
-
exports.useInterval = useInterval;
|
|
355
|
-
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
356
|
-
exports.useLatestValue = useLatestValue;
|
|
357
|
-
exports.useLazyMemo = useLazyMemo;
|
|
358
|
-
exports.useNodeRef = useNodeRef;
|
|
359
|
-
exports.usePrevious = usePrevious;
|
|
360
|
-
exports.useUniqueId = useUniqueId;
|
|
361
|
-
//# sourceMappingURL=dnd-kit-utilities.cjs.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dnd-kit-utilities.cjs.development.js","sources":["../src/hooks/useCombinedRefs.ts","../src/execution-context/canUseDOM.ts","../src/type-guards/isWindow.ts","../src/type-guards/isNode.ts","../src/execution-context/getWindow.ts","../src/type-guards/isDocument.ts","../src/type-guards/isHTMLElement.ts","../src/type-guards/isSVGElement.ts","../src/execution-context/getOwnerDocument.ts","../src/hooks/useIsomorphicLayoutEffect.ts","../src/hooks/useEvent.ts","../src/hooks/useInterval.ts","../src/hooks/useLatestValue.ts","../src/hooks/useLazyMemo.ts","../src/hooks/useNodeRef.ts","../src/hooks/usePrevious.ts","../src/hooks/useUniqueId.ts","../src/adjustment.ts","../src/event/hasViewportRelativeCoordinates.ts","../src/event/isKeyboardEvent.ts","../src/event/isTouchEvent.ts","../src/coordinates/getEventCoordinates.ts","../src/css.ts","../src/focus/findFirstFocusableNode.ts"],"sourcesContent":["import {useMemo} from 'react';\n\nexport function useCombinedRefs<T>(\n ...refs: ((node: T) => void)[]\n): (node: T) => void {\n return useMemo(\n () => (node: T) => {\n refs.forEach((ref) => ref(node));\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n refs\n );\n}\n","// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js\nexport const canUseDOM =\n typeof window !== 'undefined' &&\n typeof window.document !== 'undefined' &&\n typeof window.document.createElement !== 'undefined';\n","export function isWindow(element: Object): element is typeof window {\n const elementString = Object.prototype.toString.call(element);\n return (\n elementString === '[object Window]' ||\n // In Electron context the Window object serializes to [object global]\n elementString === '[object global]'\n );\n}\n","export function isNode(node: Object): node is Node {\n return 'nodeType' in node;\n}\n","import {isWindow} from '../type-guards/isWindow';\nimport {isNode} from '../type-guards/isNode';\n\nexport function getWindow(target: Event['target']): typeof window {\n if (!target) {\n return window;\n }\n\n if (isWindow(target)) {\n return target;\n }\n\n if (!isNode(target)) {\n return window;\n }\n\n return target.ownerDocument?.defaultView ?? window;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isDocument(node: Node): node is Document {\n const {Document} = getWindow(node);\n\n return node instanceof Document;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nimport {isWindow} from './isWindow';\n\nexport function isHTMLElement(node: Node | Window): node is HTMLElement {\n if (isWindow(node)) {\n return false;\n }\n\n return node instanceof getWindow(node).HTMLElement;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isSVGElement(node: Node): node is SVGElement {\n return node instanceof getWindow(node).SVGElement;\n}\n","import {\n isWindow,\n isHTMLElement,\n isDocument,\n isNode,\n isSVGElement,\n} from '../type-guards';\n\nexport function getOwnerDocument(target: Event['target']): Document {\n if (!target) {\n return document;\n }\n\n if (isWindow(target)) {\n return target.document;\n }\n\n if (!isNode(target)) {\n return document;\n }\n\n if (isDocument(target)) {\n return target;\n }\n\n if (isHTMLElement(target) || isSVGElement(target)) {\n return target.ownerDocument;\n }\n\n return document;\n}\n","import {useEffect, useLayoutEffect} from 'react';\n\nimport {canUseDOM} from '../execution-context';\n\n/**\n * A hook that resolves to useEffect on the server and useLayoutEffect on the client\n * @param callback {function} Callback function that is invoked when the dependencies of the hook change\n */\nexport const useIsomorphicLayoutEffect = canUseDOM\n ? useLayoutEffect\n : useEffect;\n","import {useCallback, useRef} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useEvent<T extends Function>(handler: T | undefined) {\n const handlerRef = useRef<T | undefined>(handler);\n\n useIsomorphicLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback(function (...args: any) {\n return handlerRef.current?.(...args);\n }, []);\n}\n","import {useCallback, useRef} from 'react';\n\nexport function useInterval() {\n const intervalRef = useRef<number | null>(null);\n\n const set = useCallback((listener: Function, duration: number) => {\n intervalRef.current = setInterval(listener, duration);\n }, []);\n\n const clear = useCallback(() => {\n if (intervalRef.current !== null) {\n clearInterval(intervalRef.current);\n intervalRef.current = null;\n }\n }, []);\n\n return [set, clear] as const;\n}\n","import {useRef} from 'react';\nimport type {DependencyList} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useLatestValue<T extends any>(\n value: T,\n dependencies: DependencyList = [value]\n) {\n const valueRef = useRef<T>(value);\n\n useIsomorphicLayoutEffect(() => {\n if (valueRef.current !== value) {\n valueRef.current = value;\n }\n }, dependencies);\n\n return valueRef;\n}\n","import {useMemo, useRef} from 'react';\n\nexport function useLazyMemo<T>(\n callback: (prevValue: T | undefined) => T,\n dependencies: any[]\n) {\n const valueRef = useRef<T>();\n\n return useMemo(\n () => {\n const newValue = callback(valueRef.current);\n valueRef.current = newValue;\n\n return newValue;\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...dependencies]\n );\n}\n","import {useRef, useCallback} from 'react';\n\nimport {useEvent} from './useEvent';\n\nexport function useNodeRef(\n onChange?: (\n newElement: HTMLElement | null,\n previousElement: HTMLElement | null\n ) => void\n) {\n const onChangeHandler = useEvent(onChange);\n const node = useRef<HTMLElement | null>(null);\n const setNodeRef = useCallback(\n (element: HTMLElement | null) => {\n if (element !== node.current) {\n onChangeHandler?.(element, node.current);\n }\n\n node.current = element;\n },\n //eslint-disable-next-line\n []\n );\n\n return [node, setNodeRef] as const;\n}\n","import {useRef, useEffect} from 'react';\n\nexport function usePrevious<T>(value: T) {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n","import {useMemo} from 'react';\n\nlet ids: Record<string, number> = {};\n\nexport function useUniqueId(prefix: string, value?: string) {\n return useMemo(() => {\n if (value) {\n return value;\n }\n\n const id = ids[prefix] == null ? 0 : ids[prefix] + 1;\n ids[prefix] = id;\n\n return `${prefix}-${id}`;\n }, [prefix, value]);\n}\n","function createAdjustmentFn(modifier: number) {\n return <T extends Record<U, number>, U extends string>(\n object: T,\n ...adjustments: Partial<T>[]\n ): T => {\n return adjustments.reduce<T>(\n (accumulator, adjustment) => {\n const entries = Object.entries(adjustment) as [U, number][];\n\n for (const [key, valueAdjustment] of entries) {\n const value = accumulator[key];\n\n if (value != null) {\n accumulator[key] = (value + modifier * valueAdjustment) as T[U];\n }\n }\n\n return accumulator;\n },\n {\n ...object,\n }\n );\n };\n}\n\nexport const add = createAdjustmentFn(1);\nexport const subtract = createAdjustmentFn(-1);\n","export function hasViewportRelativeCoordinates(\n event: Event\n): event is Event & Pick<PointerEvent, 'clientX' | 'clientY'> {\n return 'clientX' in event && 'clientY' in event;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isKeyboardEvent(\n event: Event | undefined | null\n): event is KeyboardEvent {\n if (!event) {\n return false;\n }\n\n const {KeyboardEvent} = getWindow(event.target);\n\n return KeyboardEvent && event instanceof KeyboardEvent;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isTouchEvent(\n event: Event | undefined | null\n): event is TouchEvent {\n if (!event) {\n return false;\n }\n\n const {TouchEvent} = getWindow(event.target);\n\n return TouchEvent && event instanceof TouchEvent;\n}\n","import type {Coordinates} from './types';\nimport {isTouchEvent, hasViewportRelativeCoordinates} from '../event';\n\n/**\n * Returns the normalized x and y coordinates for mouse and touch events.\n */\nexport function getEventCoordinates(event: Event): Coordinates | null {\n if (isTouchEvent(event)) {\n if (event.touches && event.touches.length) {\n const {clientX: x, clientY: y} = event.touches[0];\n\n return {\n x,\n y,\n };\n } else if (event.changedTouches && event.changedTouches.length) {\n const {clientX: x, clientY: y} = event.changedTouches[0];\n\n return {\n x,\n y,\n };\n }\n }\n\n if (hasViewportRelativeCoordinates(event)) {\n return {\n x: event.clientX,\n y: event.clientY,\n };\n }\n\n return null;\n}\n","export type Transform = {\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n};\n\nexport interface Transition {\n property: string;\n easing: string;\n duration: number;\n}\n\nexport const CSS = Object.freeze({\n Translate: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {x, y} = transform;\n\n return `translate3d(${x ? Math.round(x) : 0}px, ${\n y ? Math.round(y) : 0\n }px, 0)`;\n },\n },\n Scale: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {scaleX, scaleY} = transform;\n\n return `scaleX(${scaleX}) scaleY(${scaleY})`;\n },\n },\n Transform: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n return [\n CSS.Translate.toString(transform),\n CSS.Scale.toString(transform),\n ].join(' ');\n },\n },\n Transition: {\n toString({property, duration, easing}: Transition) {\n return `${property} ${duration}ms ${easing}`;\n },\n },\n});\n","const SELECTOR =\n 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';\n\nexport function findFirstFocusableNode(\n element: HTMLElement\n): HTMLElement | null {\n if (element.matches(SELECTOR)) {\n return element;\n }\n\n return element.querySelector(SELECTOR);\n}\n"],"names":["useCombinedRefs","refs","useMemo","node","forEach","ref","canUseDOM","window","document","createElement","isWindow","element","elementString","Object","prototype","toString","call","isNode","getWindow","target","ownerDocument","defaultView","isDocument","Document","isHTMLElement","HTMLElement","isSVGElement","SVGElement","getOwnerDocument","useIsomorphicLayoutEffect","useLayoutEffect","useEffect","useEvent","handler","handlerRef","useRef","current","useCallback","args","useInterval","intervalRef","set","listener","duration","setInterval","clear","clearInterval","useLatestValue","value","dependencies","valueRef","useLazyMemo","callback","newValue","useNodeRef","onChange","onChangeHandler","setNodeRef","usePrevious","ids","useUniqueId","prefix","id","createAdjustmentFn","modifier","object","adjustments","reduce","accumulator","adjustment","entries","key","valueAdjustment","add","subtract","hasViewportRelativeCoordinates","event","isKeyboardEvent","KeyboardEvent","isTouchEvent","TouchEvent","getEventCoordinates","touches","length","clientX","x","clientY","y","changedTouches","CSS","freeze","Translate","transform","Math","round","Scale","scaleX","scaleY","Transform","join","Transition","property","easing","SELECTOR","findFirstFocusableNode","matches","querySelector"],"mappings":";;;;;;SAEgBA;oCACXC;IAAAA;;;EAEH,OAAOC,aAAO,CAC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EAAE;IACLhF,QAAQ,CAAC6E,SAAD;MACN,IAAI,CAACA,SAAL,EAAgB;QACd;;;MAGF,MAAM;QAACI,MAAD;QAASC;UAAUL,SAAzB;MAEA,mBAAiBI,MAAjB,iBAAmCC,MAAnC;;;GAtB2B;EAyB/BC,SAAS,EAAE;IACTnF,QAAQ,CAAC6E,SAAD;MACN,IAAI,CAACA,SAAL,EAAgB;QACd;;;MAGF,OAAO,CACLH,GAAG,CAACE,SAAJ,CAAc5E,QAAd,CAAuB6E,SAAvB,CADK,EAELH,GAAG,CAACM,KAAJ,CAAUhF,QAAV,CAAmB6E,SAAnB,CAFK,EAGLO,IAHK,CAGA,GAHA,CAAP;;;GA/B2B;EAqC/BC,UAAU,EAAE;IACVrF,QAAQ;UAAC;QAACsF,QAAD;QAAW1D,QAAX;QAAqB2D;;MAC5B,OAAUD,QAAV,SAAsB1D,QAAtB,WAAoC2D,MAApC;;;;AAvC2B,CAAd,CAAZ;;ACbP,MAAMC,QAAQ,GACZ,wIADF;AAGA,SAAgBC,uBACd7F;EAEA,IAAIA,OAAO,CAAC8F,OAAR,CAAgBF,QAAhB,CAAJ,EAA+B;IAC7B,OAAO5F,OAAP;;;EAGF,OAAOA,OAAO,CAAC+F,aAAR,CAAsBH,QAAtB,CAAP;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");const t="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function n(e){const t=Object.prototype.toString.call(e);return"[object Window]"===t||"[object global]"===t}function r(e){return"nodeType"in e}function o(e){var t,o;return e?n(e)?e:r(e)&&null!=(t=null==(o=e.ownerDocument)?void 0:o.defaultView)?t:window:window}function u(e){const{Document:t}=o(e);return e instanceof t}function c(e){return!n(e)&&e instanceof o(e).HTMLElement}function s(e){return e instanceof o(e).SVGElement}const i=t?e.useLayoutEffect:e.useEffect;function a(t){const n=e.useRef(t);return i(()=>{n.current=t}),e.useCallback((function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return null==n.current?void 0:n.current(...t)}),[])}let l={};function f(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return r.reduce((t,n)=>{const r=Object.entries(n);for(const[n,o]of r){const r=t[n];null!=r&&(t[n]=r+e*o)}return t},{...t})}}const d=f(1),p=f(-1);function x(e){return"clientX"in e&&"clientY"in e}function m(e){if(!e)return!1;const{TouchEvent:t}=o(e.target);return t&&e instanceof t}const h=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[h.Translate.toString(e),h.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),b="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";exports.CSS=h,exports.add=d,exports.canUseDOM=t,exports.findFirstFocusableNode=function(e){return e.matches(b)?e:e.querySelector(b)},exports.getEventCoordinates=function(e){if(m(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return x(e)?{x:e.clientX,y:e.clientY}:null},exports.getOwnerDocument=function(e){return e?n(e)?e.document:r(e)?u(e)?e:c(e)||s(e)?e.ownerDocument:document:document:document},exports.getWindow=o,exports.hasViewportRelativeCoordinates=x,exports.isDocument=u,exports.isHTMLElement=c,exports.isKeyboardEvent=function(e){if(!e)return!1;const{KeyboardEvent:t}=o(e.target);return t&&e instanceof t},exports.isNode=r,exports.isSVGElement=s,exports.isTouchEvent=m,exports.isWindow=n,exports.subtract=p,exports.useCombinedRefs=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return e.useMemo(()=>e=>{n.forEach(t=>t(e))},n)},exports.useEvent=a,exports.useInterval=function(){const t=e.useRef(null);return[e.useCallback((e,n)=>{t.current=setInterval(e,n)},[]),e.useCallback(()=>{null!==t.current&&(clearInterval(t.current),t.current=null)},[])]},exports.useIsomorphicLayoutEffect=i,exports.useLatestValue=function(t,n){void 0===n&&(n=[t]);const r=e.useRef(t);return i(()=>{r.current!==t&&(r.current=t)},n),r},exports.useLazyMemo=function(t,n){const r=e.useRef();return e.useMemo(()=>{const e=t(r.current);return r.current=e,e},[...n])},exports.useNodeRef=function(t){const n=a(t),r=e.useRef(null),o=e.useCallback(e=>{e!==r.current&&(null==n||n(e,r.current)),r.current=e},[]);return[r,o]},exports.usePrevious=function(t){const n=e.useRef();return e.useEffect(()=>{n.current=t},[t]),n.current},exports.useUniqueId=function(t,n){return e.useMemo(()=>{if(n)return n;const e=null==l[t]?0:l[t]+1;return l[t]=e,t+"-"+e},[t,n])};
|
|
2
|
-
//# sourceMappingURL=dnd-kit-utilities.cjs.production.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dnd-kit-utilities.cjs.production.min.js","sources":["../src/execution-context/canUseDOM.ts","../src/type-guards/isWindow.ts","../src/type-guards/isNode.ts","../src/execution-context/getWindow.ts","../src/type-guards/isDocument.ts","../src/type-guards/isHTMLElement.ts","../src/type-guards/isSVGElement.ts","../src/hooks/useIsomorphicLayoutEffect.ts","../src/hooks/useEvent.ts","../src/hooks/useUniqueId.ts","../src/adjustment.ts","../src/event/hasViewportRelativeCoordinates.ts","../src/event/isTouchEvent.ts","../src/css.ts","../src/focus/findFirstFocusableNode.ts","../src/coordinates/getEventCoordinates.ts","../src/execution-context/getOwnerDocument.ts","../src/event/isKeyboardEvent.ts","../src/hooks/useCombinedRefs.ts","../src/hooks/useInterval.ts","../src/hooks/useLatestValue.ts","../src/hooks/useLazyMemo.ts","../src/hooks/useNodeRef.ts","../src/hooks/usePrevious.ts"],"sourcesContent":["// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js\nexport const canUseDOM =\n typeof window !== 'undefined' &&\n typeof window.document !== 'undefined' &&\n typeof window.document.createElement !== 'undefined';\n","export function isWindow(element: Object): element is typeof window {\n const elementString = Object.prototype.toString.call(element);\n return (\n elementString === '[object Window]' ||\n // In Electron context the Window object serializes to [object global]\n elementString === '[object global]'\n );\n}\n","export function isNode(node: Object): node is Node {\n return 'nodeType' in node;\n}\n","import {isWindow} from '../type-guards/isWindow';\nimport {isNode} from '../type-guards/isNode';\n\nexport function getWindow(target: Event['target']): typeof window {\n if (!target) {\n return window;\n }\n\n if (isWindow(target)) {\n return target;\n }\n\n if (!isNode(target)) {\n return window;\n }\n\n return target.ownerDocument?.defaultView ?? window;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isDocument(node: Node): node is Document {\n const {Document} = getWindow(node);\n\n return node instanceof Document;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nimport {isWindow} from './isWindow';\n\nexport function isHTMLElement(node: Node | Window): node is HTMLElement {\n if (isWindow(node)) {\n return false;\n }\n\n return node instanceof getWindow(node).HTMLElement;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isSVGElement(node: Node): node is SVGElement {\n return node instanceof getWindow(node).SVGElement;\n}\n","import {useEffect, useLayoutEffect} from 'react';\n\nimport {canUseDOM} from '../execution-context';\n\n/**\n * A hook that resolves to useEffect on the server and useLayoutEffect on the client\n * @param callback {function} Callback function that is invoked when the dependencies of the hook change\n */\nexport const useIsomorphicLayoutEffect = canUseDOM\n ? useLayoutEffect\n : useEffect;\n","import {useCallback, useRef} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useEvent<T extends Function>(handler: T | undefined) {\n const handlerRef = useRef<T | undefined>(handler);\n\n useIsomorphicLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback(function (...args: any) {\n return handlerRef.current?.(...args);\n }, []);\n}\n","import {useMemo} from 'react';\n\nlet ids: Record<string, number> = {};\n\nexport function useUniqueId(prefix: string, value?: string) {\n return useMemo(() => {\n if (value) {\n return value;\n }\n\n const id = ids[prefix] == null ? 0 : ids[prefix] + 1;\n ids[prefix] = id;\n\n return `${prefix}-${id}`;\n }, [prefix, value]);\n}\n","function createAdjustmentFn(modifier: number) {\n return <T extends Record<U, number>, U extends string>(\n object: T,\n ...adjustments: Partial<T>[]\n ): T => {\n return adjustments.reduce<T>(\n (accumulator, adjustment) => {\n const entries = Object.entries(adjustment) as [U, number][];\n\n for (const [key, valueAdjustment] of entries) {\n const value = accumulator[key];\n\n if (value != null) {\n accumulator[key] = (value + modifier * valueAdjustment) as T[U];\n }\n }\n\n return accumulator;\n },\n {\n ...object,\n }\n );\n };\n}\n\nexport const add = createAdjustmentFn(1);\nexport const subtract = createAdjustmentFn(-1);\n","export function hasViewportRelativeCoordinates(\n event: Event\n): event is Event & Pick<PointerEvent, 'clientX' | 'clientY'> {\n return 'clientX' in event && 'clientY' in event;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isTouchEvent(\n event: Event | undefined | null\n): event is TouchEvent {\n if (!event) {\n return false;\n }\n\n const {TouchEvent} = getWindow(event.target);\n\n return TouchEvent && event instanceof TouchEvent;\n}\n","export type Transform = {\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n};\n\nexport interface Transition {\n property: string;\n easing: string;\n duration: number;\n}\n\nexport const CSS = Object.freeze({\n Translate: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {x, y} = transform;\n\n return `translate3d(${x ? Math.round(x) : 0}px, ${\n y ? Math.round(y) : 0\n }px, 0)`;\n },\n },\n Scale: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {scaleX, scaleY} = transform;\n\n return `scaleX(${scaleX}) scaleY(${scaleY})`;\n },\n },\n Transform: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n return [\n CSS.Translate.toString(transform),\n CSS.Scale.toString(transform),\n ].join(' ');\n },\n },\n Transition: {\n toString({property, duration, easing}: Transition) {\n return `${property} ${duration}ms ${easing}`;\n },\n },\n});\n","const SELECTOR =\n 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';\n\nexport function findFirstFocusableNode(\n element: HTMLElement\n): HTMLElement | null {\n if (element.matches(SELECTOR)) {\n return element;\n }\n\n return element.querySelector(SELECTOR);\n}\n","import type {Coordinates} from './types';\nimport {isTouchEvent, hasViewportRelativeCoordinates} from '../event';\n\n/**\n * Returns the normalized x and y coordinates for mouse and touch events.\n */\nexport function getEventCoordinates(event: Event): Coordinates | null {\n if (isTouchEvent(event)) {\n if (event.touches && event.touches.length) {\n const {clientX: x, clientY: y} = event.touches[0];\n\n return {\n x,\n y,\n };\n } else if (event.changedTouches && event.changedTouches.length) {\n const {clientX: x, clientY: y} = event.changedTouches[0];\n\n return {\n x,\n y,\n };\n }\n }\n\n if (hasViewportRelativeCoordinates(event)) {\n return {\n x: event.clientX,\n y: event.clientY,\n };\n }\n\n return null;\n}\n","import {\n isWindow,\n isHTMLElement,\n isDocument,\n isNode,\n isSVGElement,\n} from '../type-guards';\n\nexport function getOwnerDocument(target: Event['target']): Document {\n if (!target) {\n return document;\n }\n\n if (isWindow(target)) {\n return target.document;\n }\n\n if (!isNode(target)) {\n return document;\n }\n\n if (isDocument(target)) {\n return target;\n }\n\n if (isHTMLElement(target) || isSVGElement(target)) {\n return target.ownerDocument;\n }\n\n return document;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isKeyboardEvent(\n event: Event | undefined | null\n): event is KeyboardEvent {\n if (!event) {\n return false;\n }\n\n const {KeyboardEvent} = getWindow(event.target);\n\n return KeyboardEvent && event instanceof KeyboardEvent;\n}\n","import {useMemo} from 'react';\n\nexport function useCombinedRefs<T>(\n ...refs: ((node: T) => void)[]\n): (node: T) => void {\n return useMemo(\n () => (node: T) => {\n refs.forEach((ref) => ref(node));\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n refs\n );\n}\n","import {useCallback, useRef} from 'react';\n\nexport function useInterval() {\n const intervalRef = useRef<number | null>(null);\n\n const set = useCallback((listener: Function, duration: number) => {\n intervalRef.current = setInterval(listener, duration);\n }, []);\n\n const clear = useCallback(() => {\n if (intervalRef.current !== null) {\n clearInterval(intervalRef.current);\n intervalRef.current = null;\n }\n }, []);\n\n return [set, clear] as const;\n}\n","import {useRef} from 'react';\nimport type {DependencyList} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useLatestValue<T extends any>(\n value: T,\n dependencies: DependencyList = [value]\n) {\n const valueRef = useRef<T>(value);\n\n useIsomorphicLayoutEffect(() => {\n if (valueRef.current !== value) {\n valueRef.current = value;\n }\n }, dependencies);\n\n return valueRef;\n}\n","import {useMemo, useRef} from 'react';\n\nexport function useLazyMemo<T>(\n callback: (prevValue: T | undefined) => T,\n dependencies: any[]\n) {\n const valueRef = useRef<T>();\n\n return useMemo(\n () => {\n const newValue = callback(valueRef.current);\n valueRef.current = newValue;\n\n return newValue;\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...dependencies]\n );\n}\n","import {useRef, useCallback} from 'react';\n\nimport {useEvent} from './useEvent';\n\nexport function useNodeRef(\n onChange?: (\n newElement: HTMLElement | null,\n previousElement: HTMLElement | null\n ) => void\n) {\n const onChangeHandler = useEvent(onChange);\n const node = useRef<HTMLElement | null>(null);\n const setNodeRef = useCallback(\n (element: HTMLElement | null) => {\n if (element !== node.current) {\n onChangeHandler?.(element, node.current);\n }\n\n node.current = element;\n },\n //eslint-disable-next-line\n []\n );\n\n return [node, setNodeRef] as const;\n}\n","import {useRef, useEffect} from 'react';\n\nexport function usePrevious<T>(value: T) {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n"],"names":["canUseDOM","window","document","createElement","isWindow","element","elementString","Object","prototype","toString","call","isNode","node","getWindow","target","ownerDocument","_target$ownerDocument2","defaultView","isDocument","Document","isHTMLElement","HTMLElement","isSVGElement","SVGElement","useIsomorphicLayoutEffect","useLayoutEffect","useEffect","useEvent","handler","handlerRef","useRef","current","useCallback","args","ids","createAdjustmentFn","modifier","object","adjustments","reduce","accumulator","adjustment","entries","key","valueAdjustment","value","add","subtract","hasViewportRelativeCoordinates","event","isTouchEvent","TouchEvent","CSS","freeze","Translate","transform","x","y","Math","round","Scale","scaleX","scaleY","Transform","join","Transition","property","duration","easing","SELECTOR","matches","querySelector","touches","length","clientX","clientY","changedTouches","KeyboardEvent","refs","useMemo","forEach","ref","intervalRef","listener","setInterval","clearInterval","dependencies","valueRef","callback","newValue","onChange","onChangeHandler","setNodeRef","prefix","id"],"mappings":"2FACA,MAAaA,EACO,oBAAXC,aACoB,IAApBA,OAAOC,eAC2B,IAAlCD,OAAOC,SAASC,uBCJTC,EAASC,GACvB,MAAMC,EAAgBC,OAAOC,UAAUC,SAASC,KAAKL,GACrD,MACoB,oBAAlBC,GAEkB,oBAAlBA,WCLYK,EAAOC,GACrB,MAAO,aAAcA,WCEPC,EAAUC,WACxB,OAAKA,EAIDV,EAASU,GACJA,EAGJH,EAAOG,sBAILA,EAAOC,sBAAPC,EAAsBC,eAHpBhB,OARAA,gBCHKiB,EAAWN,GACzB,MAAMO,SAACA,GAAYN,EAAUD,GAE7B,OAAOA,aAAgBO,WCDTC,EAAcR,GAC5B,OAAIR,EAASQ,IAINA,aAAgBC,EAAUD,GAAMS,qBCPzBC,EAAaV,GAC3B,OAAOA,aAAgBC,EAAUD,GAAMW,iBCK5BC,EAA4BxB,EACrCyB,kBACAC,qBCNYC,EAA6BC,GAC3C,MAAMC,EAAaC,SAAsBF,GAMzC,OAJAJ,EAA0B,KACxBK,EAA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