@dnd-kit/dom 0.0.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/README.md +17 -0
- package/index.cjs +1307 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +189 -0
- package/index.d.ts +189 -0
- package/index.js +1295 -0
- package/index.js.map +1 -0
- package/modifiers.cjs +120 -0
- package/modifiers.d.cts +23 -0
- package/modifiers.d.ts +23 -0
- package/modifiers.js +117 -0
- package/modifiers.js.map +1 -0
- package/package.json +92 -0
- package/plugins/debug.cjs +95 -0
- package/plugins/debug.cjs.map +1 -0
- package/plugins/debug.d.cts +8 -0
- package/plugins/debug.d.ts +8 -0
- package/plugins/debug.js +93 -0
- package/plugins/debug.js.map +1 -0
- package/sortable.cjs +531 -0
- package/sortable.cjs.map +1 -0
- package/sortable.d.cts +85 -0
- package/sortable.d.ts +85 -0
- package/sortable.js +528 -0
- package/sortable.js.map +1 -0
- package/utilities.cjs +655 -0
- package/utilities.cjs.map +1 -0
- package/utilities.d.cts +131 -0
- package/utilities.d.ts +131 -0
- package/utilities.js +626 -0
- package/utilities.js.map +1 -0
package/utilities.cjs
ADDED
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var geometry = require('@dnd-kit/geometry');
|
|
4
|
+
|
|
5
|
+
// src/utilities/bounding-rectangle/getBoundingRectangle.ts
|
|
6
|
+
function getBoundingRectangle(element) {
|
|
7
|
+
const { width, height, top, left, bottom, right } = element.getBoundingClientRect();
|
|
8
|
+
return { width, height, top, left, bottom, right };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/utilities/execution-context/canUseDOM.ts
|
|
12
|
+
var canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
13
|
+
|
|
14
|
+
// src/utilities/type-guards/isWindow.ts
|
|
15
|
+
function isWindow(element) {
|
|
16
|
+
const elementString = Object.prototype.toString.call(element);
|
|
17
|
+
return elementString === "[object Window]" || // In Electron context the Window object serializes to [object global]
|
|
18
|
+
elementString === "[object global]";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/utilities/type-guards/isNode.ts
|
|
22
|
+
function isNode(node) {
|
|
23
|
+
return "nodeType" in node;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/utilities/execution-context/getWindow.ts
|
|
27
|
+
function getWindow(target) {
|
|
28
|
+
if (!target) {
|
|
29
|
+
return window;
|
|
30
|
+
}
|
|
31
|
+
if (isWindow(target)) {
|
|
32
|
+
return target;
|
|
33
|
+
}
|
|
34
|
+
if (!isNode(target)) {
|
|
35
|
+
return window;
|
|
36
|
+
}
|
|
37
|
+
return target.ownerDocument?.defaultView ?? window;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/utilities/type-guards/isDocument.ts
|
|
41
|
+
function isDocument(node) {
|
|
42
|
+
const { Document } = getWindow(node);
|
|
43
|
+
return node instanceof Document;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/utilities/type-guards/isHTMLElement.ts
|
|
47
|
+
function isHTMLElement(node) {
|
|
48
|
+
if (isWindow(node)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return node instanceof getWindow(node).HTMLElement;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/utilities/execution-context/getDocument.ts
|
|
55
|
+
function getDocument(target) {
|
|
56
|
+
if (!target) {
|
|
57
|
+
return document;
|
|
58
|
+
}
|
|
59
|
+
if (isWindow(target)) {
|
|
60
|
+
return target.document;
|
|
61
|
+
}
|
|
62
|
+
if (!isNode(target)) {
|
|
63
|
+
return document;
|
|
64
|
+
}
|
|
65
|
+
if (isDocument(target)) {
|
|
66
|
+
return target;
|
|
67
|
+
}
|
|
68
|
+
if (isHTMLElement(target)) {
|
|
69
|
+
return target.ownerDocument;
|
|
70
|
+
}
|
|
71
|
+
return document;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/utilities/bounding-rectangle/getViewportBoundingRectangle.ts
|
|
75
|
+
function getViewportBoundingRectangle(element) {
|
|
76
|
+
const { documentElement } = getDocument(element);
|
|
77
|
+
const width = documentElement.clientWidth;
|
|
78
|
+
const height = documentElement.clientHeight;
|
|
79
|
+
return {
|
|
80
|
+
top: 0,
|
|
81
|
+
left: 0,
|
|
82
|
+
right: width,
|
|
83
|
+
bottom: height,
|
|
84
|
+
width,
|
|
85
|
+
height
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/utilities/element/cloneElement.ts
|
|
90
|
+
function cloneElement(element) {
|
|
91
|
+
const selector = "input, textarea, select, canvas, [contenteditable]";
|
|
92
|
+
const clonedElement = element.cloneNode(true);
|
|
93
|
+
const fields = Array.from(element.querySelectorAll(selector));
|
|
94
|
+
const clonedFields = Array.from(clonedElement.querySelectorAll(selector));
|
|
95
|
+
clonedFields.forEach((field, index) => {
|
|
96
|
+
const originalField = fields[index];
|
|
97
|
+
if (isField(field) && isField(originalField)) {
|
|
98
|
+
if (field.type !== "file") {
|
|
99
|
+
field.value = originalField.value;
|
|
100
|
+
}
|
|
101
|
+
if (field.type === "radio" && field.name) {
|
|
102
|
+
field.name = `Cloned__${field.name}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (field instanceof HTMLCanvasElement && originalField instanceof HTMLCanvasElement && originalField.width > 0 && originalField.height > 0) {
|
|
106
|
+
const destCtx = field.getContext("2d");
|
|
107
|
+
destCtx?.drawImage(originalField, 0, 0);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return clonedElement;
|
|
111
|
+
}
|
|
112
|
+
function isField(element) {
|
|
113
|
+
return "value" in element;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/utilities/type-guards/supportsStyle.ts
|
|
117
|
+
function supportsStyle(element) {
|
|
118
|
+
return "style" in element && element.style instanceof getWindow(element).CSSStyleDeclaration;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/utilities/element/createPlaceholder.ts
|
|
122
|
+
function createPlaceholder(element, clone = false) {
|
|
123
|
+
const placeholder = cloneElement(element);
|
|
124
|
+
if (supportsStyle(placeholder)) {
|
|
125
|
+
if (!clone) {
|
|
126
|
+
placeholder.style.setProperty("opacity", "0");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
placeholder.setAttribute("inert", "true");
|
|
130
|
+
placeholder.setAttribute("tab-index", "-1");
|
|
131
|
+
placeholder.setAttribute("aria-hidden", "true");
|
|
132
|
+
return placeholder;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/utilities/event-listeners/Listeners.ts
|
|
136
|
+
var Listeners = class {
|
|
137
|
+
constructor() {
|
|
138
|
+
this.entries = /* @__PURE__ */ new Set();
|
|
139
|
+
this.clear = () => {
|
|
140
|
+
for (const entry of this.entries) {
|
|
141
|
+
const [target, { type, listener, options }] = entry;
|
|
142
|
+
target.removeEventListener(type, listener, options);
|
|
143
|
+
}
|
|
144
|
+
this.entries.clear();
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
bind(target, input) {
|
|
148
|
+
const listeners = Array.isArray(input) ? input : [input];
|
|
149
|
+
const entries = [];
|
|
150
|
+
for (const descriptor of listeners) {
|
|
151
|
+
const { type, listener, options } = descriptor;
|
|
152
|
+
const entry = [target, descriptor];
|
|
153
|
+
target.addEventListener(type, listener, options);
|
|
154
|
+
this.entries.add(entry);
|
|
155
|
+
entries.push(entry);
|
|
156
|
+
}
|
|
157
|
+
return function cleanup() {
|
|
158
|
+
for (const [target2, { type, listener, options }] of entries) {
|
|
159
|
+
target2.removeEventListener(type, listener, options);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// src/utilities/popover/supportsPopover.ts
|
|
166
|
+
function supportsPopover(element) {
|
|
167
|
+
return "showPopover" in element && "hidePopover" in element && typeof element.showPopover === "function" && typeof element.hidePopover === "function";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/utilities/popover/showPopover.ts
|
|
171
|
+
function showPopover(element) {
|
|
172
|
+
if (supportsPopover(element) && element.isConnected) {
|
|
173
|
+
element.showPopover();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/utilities/scroll/documentScrollingElement.ts
|
|
178
|
+
function isDocumentScrollingElement(element) {
|
|
179
|
+
if (!canUseDOM || !element) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return element === getDocument(element).scrollingElement;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/utilities/scroll/getScrollPosition.ts
|
|
186
|
+
function getScrollPosition(scrollableElement) {
|
|
187
|
+
const rect = isDocumentScrollingElement(scrollableElement) ? getViewportBoundingRectangle(scrollableElement) : getBoundingRectangle(scrollableElement);
|
|
188
|
+
const dimensions = isDocumentScrollingElement(scrollableElement) ? {
|
|
189
|
+
height: window.innerHeight,
|
|
190
|
+
width: window.innerWidth
|
|
191
|
+
} : {
|
|
192
|
+
height: scrollableElement.clientHeight,
|
|
193
|
+
width: scrollableElement.clientWidth
|
|
194
|
+
};
|
|
195
|
+
const position = {
|
|
196
|
+
current: {
|
|
197
|
+
x: scrollableElement.scrollLeft,
|
|
198
|
+
y: scrollableElement.scrollTop
|
|
199
|
+
},
|
|
200
|
+
max: {
|
|
201
|
+
x: scrollableElement.scrollWidth - dimensions.width,
|
|
202
|
+
y: scrollableElement.scrollHeight - dimensions.height
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const isTop = position.current.y <= 0;
|
|
206
|
+
const isLeft = position.current.x <= 0;
|
|
207
|
+
const isBottom = position.current.y >= position.max.y;
|
|
208
|
+
const isRight = position.current.x >= position.max.x;
|
|
209
|
+
return {
|
|
210
|
+
rect,
|
|
211
|
+
position,
|
|
212
|
+
isTop,
|
|
213
|
+
isLeft,
|
|
214
|
+
isBottom,
|
|
215
|
+
isRight
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/utilities/scroll/canScroll.ts
|
|
220
|
+
function canScroll(scrollableElement, by) {
|
|
221
|
+
const { isTop, isBottom, isLeft, isRight, position } = getScrollPosition(scrollableElement);
|
|
222
|
+
const { x, y } = by ?? { x: 0, y: 0 };
|
|
223
|
+
const top = !isTop && position.current.y + y > 0;
|
|
224
|
+
const bottom = !isBottom && position.current.y + y < position.max.y;
|
|
225
|
+
const left = !isLeft && position.current.x + x > 0;
|
|
226
|
+
const right = !isRight && position.current.x + x < position.max.x;
|
|
227
|
+
return {
|
|
228
|
+
top,
|
|
229
|
+
bottom,
|
|
230
|
+
left,
|
|
231
|
+
right,
|
|
232
|
+
x: left || right,
|
|
233
|
+
y: top || bottom
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/utilities/type-guards/isSVGElement.ts
|
|
238
|
+
function isSVGElement(node) {
|
|
239
|
+
return node instanceof getWindow(node).SVGElement;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/utilities/scroll/isFixed.ts
|
|
243
|
+
function isFixed(node, computedStyle = getWindow(node).getComputedStyle(node)) {
|
|
244
|
+
return computedStyle.position === "fixed" || computedStyle.position === "sticky";
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/utilities/scroll/isScrollable.ts
|
|
248
|
+
function isScrollable(element, computedStyle = getWindow(element).getComputedStyle(
|
|
249
|
+
element
|
|
250
|
+
)) {
|
|
251
|
+
const overflowRegex = /(auto|scroll|overlay)/;
|
|
252
|
+
const properties = ["overflow", "overflowX", "overflowY"];
|
|
253
|
+
return properties.find((property) => {
|
|
254
|
+
const value = computedStyle[property];
|
|
255
|
+
return typeof value === "string" ? overflowRegex.test(value) : false;
|
|
256
|
+
}) != null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/utilities/scroll/getScrollableAncestors.ts
|
|
260
|
+
var defaultOptions = {
|
|
261
|
+
excludeElement: true
|
|
262
|
+
};
|
|
263
|
+
function getScrollableAncestors(element, options = defaultOptions) {
|
|
264
|
+
const { limit, excludeElement } = options;
|
|
265
|
+
const scrollParents = [];
|
|
266
|
+
function findScrollableAncestors(node) {
|
|
267
|
+
if (limit != null && scrollParents.length >= limit) {
|
|
268
|
+
return scrollParents;
|
|
269
|
+
}
|
|
270
|
+
if (!node) {
|
|
271
|
+
return scrollParents;
|
|
272
|
+
}
|
|
273
|
+
if (isDocument(node) && node.scrollingElement != null && !scrollParents.includes(node.scrollingElement)) {
|
|
274
|
+
scrollParents.push(node.scrollingElement);
|
|
275
|
+
return scrollParents;
|
|
276
|
+
}
|
|
277
|
+
if (!isHTMLElement(node)) {
|
|
278
|
+
if (isSVGElement(node)) {
|
|
279
|
+
return findScrollableAncestors(node.parentElement);
|
|
280
|
+
}
|
|
281
|
+
return scrollParents;
|
|
282
|
+
}
|
|
283
|
+
if (scrollParents.includes(node)) {
|
|
284
|
+
return scrollParents;
|
|
285
|
+
}
|
|
286
|
+
const { getComputedStyle } = getWindow(node);
|
|
287
|
+
const computedStyle = getComputedStyle(node);
|
|
288
|
+
if (excludeElement && node === element) ; else if (isScrollable(node, computedStyle)) {
|
|
289
|
+
scrollParents.push(node);
|
|
290
|
+
}
|
|
291
|
+
if (isFixed(node, computedStyle)) {
|
|
292
|
+
return scrollParents;
|
|
293
|
+
}
|
|
294
|
+
return findScrollableAncestors(node.parentNode);
|
|
295
|
+
}
|
|
296
|
+
if (!element) {
|
|
297
|
+
return scrollParents;
|
|
298
|
+
}
|
|
299
|
+
return findScrollableAncestors(element);
|
|
300
|
+
}
|
|
301
|
+
function getFirstScrollableAncestor(node) {
|
|
302
|
+
const [firstScrollableAncestor] = getScrollableAncestors(node, { limit: 1 });
|
|
303
|
+
return firstScrollableAncestor ?? null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/utilities/scroll/detectScrollIntent.ts
|
|
307
|
+
var ScrollDirection = /* @__PURE__ */ ((ScrollDirection2) => {
|
|
308
|
+
ScrollDirection2[ScrollDirection2["Idle"] = 0] = "Idle";
|
|
309
|
+
ScrollDirection2[ScrollDirection2["Forward"] = 1] = "Forward";
|
|
310
|
+
ScrollDirection2[ScrollDirection2["Reverse"] = -1] = "Reverse";
|
|
311
|
+
return ScrollDirection2;
|
|
312
|
+
})(ScrollDirection || {});
|
|
313
|
+
var defaultThreshold = {
|
|
314
|
+
x: 0.2,
|
|
315
|
+
y: 0.2
|
|
316
|
+
};
|
|
317
|
+
function detectScrollIntent(scrollableElement, coordinates, intent, acceleration = 25, thresholdPercentage = defaultThreshold) {
|
|
318
|
+
const {
|
|
319
|
+
rect: scrollContainerRect,
|
|
320
|
+
isTop,
|
|
321
|
+
isBottom,
|
|
322
|
+
isLeft,
|
|
323
|
+
isRight
|
|
324
|
+
} = getScrollPosition(scrollableElement);
|
|
325
|
+
const direction = {
|
|
326
|
+
x: 0 /* Idle */,
|
|
327
|
+
y: 0 /* Idle */
|
|
328
|
+
};
|
|
329
|
+
const speed = {
|
|
330
|
+
x: 0,
|
|
331
|
+
y: 0
|
|
332
|
+
};
|
|
333
|
+
const threshold = {
|
|
334
|
+
height: scrollContainerRect.height * thresholdPercentage.y,
|
|
335
|
+
width: scrollContainerRect.width * thresholdPercentage.x
|
|
336
|
+
};
|
|
337
|
+
if (!isTop && coordinates.y <= scrollContainerRect.top + threshold.height && intent?.y !== 1 /* Forward */) {
|
|
338
|
+
direction.y = -1 /* Reverse */;
|
|
339
|
+
speed.y = acceleration * Math.abs(
|
|
340
|
+
(scrollContainerRect.top + threshold.height - coordinates.y) / threshold.height
|
|
341
|
+
);
|
|
342
|
+
} else if (!isBottom && coordinates.y >= scrollContainerRect.bottom - threshold.height && intent?.y !== -1 /* Reverse */) {
|
|
343
|
+
direction.y = 1 /* Forward */;
|
|
344
|
+
speed.y = acceleration * Math.abs(
|
|
345
|
+
(scrollContainerRect.bottom - threshold.height - coordinates.y) / threshold.height
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
if (!isRight && coordinates.x >= scrollContainerRect.right - threshold.width && intent?.x !== -1 /* Reverse */) {
|
|
349
|
+
direction.x = 1 /* Forward */;
|
|
350
|
+
speed.x = acceleration * Math.abs(
|
|
351
|
+
(scrollContainerRect.right - threshold.width - coordinates.x) / threshold.width
|
|
352
|
+
);
|
|
353
|
+
} else if (!isLeft && coordinates.x <= scrollContainerRect.left + threshold.width && intent?.x !== 1 /* Forward */) {
|
|
354
|
+
direction.x = -1 /* Reverse */;
|
|
355
|
+
speed.x = acceleration * Math.abs(
|
|
356
|
+
(scrollContainerRect.left + threshold.width - coordinates.x) / threshold.width
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
direction,
|
|
361
|
+
speed
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/utilities/scroll/scrollIntoViewIfNeeded.ts
|
|
366
|
+
function supportsScrollIntoViewIfNeeded(element) {
|
|
367
|
+
return "scrollIntoViewIfNeeded" in element && typeof element.scrollIntoViewIfNeeded === "function";
|
|
368
|
+
}
|
|
369
|
+
function scrollIntoViewIfNeeded(el, centerIfNeeded = false) {
|
|
370
|
+
if (supportsScrollIntoViewIfNeeded(el)) {
|
|
371
|
+
el.scrollIntoViewIfNeeded(centerIfNeeded);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (!(el instanceof HTMLElement)) {
|
|
375
|
+
return el.scrollIntoView();
|
|
376
|
+
}
|
|
377
|
+
var [parent] = getScrollableAncestors(el, { limit: 1 });
|
|
378
|
+
if (!(parent instanceof HTMLElement)) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const parentComputedStyle = getWindow(parent).getComputedStyle(parent, null), parentBorderTopWidth = parseInt(
|
|
382
|
+
parentComputedStyle.getPropertyValue("border-top-width")
|
|
383
|
+
), parentBorderLeftWidth = parseInt(
|
|
384
|
+
parentComputedStyle.getPropertyValue("border-left-width")
|
|
385
|
+
), overTop = el.offsetTop - parent.offsetTop < parent.scrollTop, overBottom = el.offsetTop - parent.offsetTop + el.clientHeight - parentBorderTopWidth > parent.scrollTop + parent.clientHeight, overLeft = el.offsetLeft - parent.offsetLeft < parent.scrollLeft, overRight = el.offsetLeft - parent.offsetLeft + el.clientWidth - parentBorderLeftWidth > parent.scrollLeft + parent.clientWidth, alignWithTop = overTop && !overBottom;
|
|
386
|
+
if ((overTop || overBottom) && centerIfNeeded) {
|
|
387
|
+
parent.scrollTop = el.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + el.clientHeight / 2;
|
|
388
|
+
}
|
|
389
|
+
if ((overLeft || overRight) && centerIfNeeded) {
|
|
390
|
+
parent.scrollLeft = el.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + el.clientWidth / 2;
|
|
391
|
+
}
|
|
392
|
+
if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
|
|
393
|
+
el.scrollIntoView(alignWithTop);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/utilities/scheduler/scheduler.ts
|
|
398
|
+
var Scheduler = class {
|
|
399
|
+
constructor() {
|
|
400
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
401
|
+
this.flush = () => {
|
|
402
|
+
const tasks = this.tasks;
|
|
403
|
+
this.animationFrame = void 0;
|
|
404
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
405
|
+
for (const task of tasks) {
|
|
406
|
+
task();
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
schedule(task) {
|
|
411
|
+
this.tasks.add(task);
|
|
412
|
+
if (!this.animationFrame) {
|
|
413
|
+
this.animationFrame = requestAnimationFrame(this.flush);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
var scheduler = new Scheduler();
|
|
418
|
+
|
|
419
|
+
// src/utilities/transform/inverseTransform.ts
|
|
420
|
+
function inverseTransform(rect, parsedTransform, transformOrigin) {
|
|
421
|
+
const { scaleX, scaleY, x: translateX, y: translateY } = parsedTransform;
|
|
422
|
+
const x = rect.left - translateX - (1 - scaleX) * parseFloat(transformOrigin);
|
|
423
|
+
const y = rect.top - translateY - (1 - scaleY) * parseFloat(transformOrigin.slice(transformOrigin.indexOf(" ") + 1));
|
|
424
|
+
const w = scaleX ? rect.width / scaleX : rect.width;
|
|
425
|
+
const h = scaleY ? rect.height / scaleY : rect.height;
|
|
426
|
+
return {
|
|
427
|
+
width: w,
|
|
428
|
+
height: h,
|
|
429
|
+
top: y,
|
|
430
|
+
right: x + w,
|
|
431
|
+
bottom: y + h,
|
|
432
|
+
left: x
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// src/utilities/styles/Styles.ts
|
|
437
|
+
var Styles = class {
|
|
438
|
+
constructor(element) {
|
|
439
|
+
this.element = element;
|
|
440
|
+
this.initial = /* @__PURE__ */ new Map();
|
|
441
|
+
}
|
|
442
|
+
set(properties, prefix = "") {
|
|
443
|
+
const { element } = this;
|
|
444
|
+
if (!supportsStyle(element)) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
448
|
+
const property = `${prefix}${key}`;
|
|
449
|
+
if (!this.initial.has(property)) {
|
|
450
|
+
this.initial.set(property, element.style.getPropertyValue(property));
|
|
451
|
+
}
|
|
452
|
+
element.style.setProperty(
|
|
453
|
+
property,
|
|
454
|
+
typeof value === "string" ? value : `${value}px`
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
remove(properties, prefix = "") {
|
|
459
|
+
const { element } = this;
|
|
460
|
+
if (!supportsStyle(element)) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
for (const key of properties) {
|
|
464
|
+
const property = `${prefix}${key}`;
|
|
465
|
+
element.style.removeProperty(property);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
reset() {
|
|
469
|
+
const { element } = this;
|
|
470
|
+
if (!supportsStyle(element)) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
for (const [key, value] of this.initial) {
|
|
474
|
+
element.style.setProperty(key, value);
|
|
475
|
+
}
|
|
476
|
+
if (element.getAttribute("style") === "") {
|
|
477
|
+
element.removeAttribute("style");
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// src/utilities/transform/animateTransform.ts
|
|
483
|
+
function animateTransform({
|
|
484
|
+
element,
|
|
485
|
+
keyframes,
|
|
486
|
+
options,
|
|
487
|
+
onReady,
|
|
488
|
+
onFinish
|
|
489
|
+
}) {
|
|
490
|
+
const styles = new Styles(element);
|
|
491
|
+
const { transitionProperty } = getWindow(element).getComputedStyle(element);
|
|
492
|
+
const properties = transitionProperty.split(", ");
|
|
493
|
+
styles.set({
|
|
494
|
+
"transition-property": properties.length ? properties.filter(
|
|
495
|
+
(property) => !property.includes("transform") && !property.includes("translate")
|
|
496
|
+
).join(", ") : "none"
|
|
497
|
+
});
|
|
498
|
+
onReady?.();
|
|
499
|
+
element.animate(keyframes, options).finished.then(() => {
|
|
500
|
+
onFinish?.();
|
|
501
|
+
styles.reset();
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/utilities/transform/parseScale.ts
|
|
506
|
+
function parseScale(scale) {
|
|
507
|
+
if (scale === "none") {
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
const values = scale.split(" ");
|
|
511
|
+
const x = parseFloat(values[0]);
|
|
512
|
+
const y = parseFloat(values[1]);
|
|
513
|
+
if (isNaN(x) && isNaN(y)) {
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
return {
|
|
517
|
+
x: isNaN(x) ? y : x,
|
|
518
|
+
y: isNaN(y) ? x : y
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// src/utilities/transform/parseTranslate.ts
|
|
523
|
+
function parseTranslate(translate) {
|
|
524
|
+
if (translate === "none") {
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
const [x, y, z = "0"] = translate.split(" ");
|
|
528
|
+
const output = { x: parseFloat(x), y: parseFloat(y), z: parseInt(z, 10) };
|
|
529
|
+
if (isNaN(output.x) && isNaN(output.y)) {
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
return {
|
|
533
|
+
x: isNaN(output.x) ? 0 : output.x,
|
|
534
|
+
y: isNaN(output.y) ? 0 : output.y,
|
|
535
|
+
z: isNaN(output.z) ? 0 : output.z
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/utilities/transform/parseTransform.ts
|
|
540
|
+
function parseTransform(computedStyles) {
|
|
541
|
+
const { scale, transform, translate } = computedStyles;
|
|
542
|
+
const parsedScale = parseScale(scale);
|
|
543
|
+
const parsedTranslate = parseTranslate(translate);
|
|
544
|
+
if (parsedScale && parsedTranslate) {
|
|
545
|
+
return {
|
|
546
|
+
x: parsedTranslate.x,
|
|
547
|
+
y: parsedTranslate.y,
|
|
548
|
+
z: parsedTranslate.z,
|
|
549
|
+
scaleX: parsedScale.x,
|
|
550
|
+
scaleY: parsedScale.y
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
const parsedMatrix = parseTransformMatrix(transform);
|
|
554
|
+
if (!parsedMatrix && !parsedScale && !parsedTranslate) {
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
x: parsedTranslate?.x ?? parsedMatrix?.x ?? 0,
|
|
559
|
+
y: parsedTranslate?.y ?? parsedMatrix?.y ?? 0,
|
|
560
|
+
scaleX: parsedScale?.x ?? parsedMatrix?.scaleX ?? 1,
|
|
561
|
+
scaleY: parsedScale?.y ?? parsedMatrix?.scaleY ?? 1
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
function parseTransformMatrix(transform) {
|
|
565
|
+
if (transform.startsWith("matrix3d(")) {
|
|
566
|
+
const transformArray = transform.slice(9, -1).split(/, /);
|
|
567
|
+
return {
|
|
568
|
+
x: +transformArray[12],
|
|
569
|
+
y: +transformArray[13],
|
|
570
|
+
scaleX: +transformArray[0],
|
|
571
|
+
scaleY: +transformArray[5]
|
|
572
|
+
};
|
|
573
|
+
} else if (transform.startsWith("matrix(")) {
|
|
574
|
+
const transformArray = transform.slice(7, -1).split(/, /);
|
|
575
|
+
return {
|
|
576
|
+
x: +transformArray[4],
|
|
577
|
+
y: +transformArray[5],
|
|
578
|
+
scaleX: +transformArray[0],
|
|
579
|
+
scaleY: +transformArray[3]
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// src/utilities/transform/stringifyTransform.ts
|
|
586
|
+
function stringifyTransform({ x, y, z, scaleX, scaleY }) {
|
|
587
|
+
return `translate3d(${x}px, ${y}px, ${z ?? 0}) scale(${scaleX}, ${scaleY})`;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// src/utilities/shapes/DOMRectangle.ts
|
|
591
|
+
var DOMRectangle = class extends geometry.Rectangle {
|
|
592
|
+
constructor(element, ignoreTransforms = false) {
|
|
593
|
+
let { top, left, right, bottom, width, height } = getBoundingRectangle(element);
|
|
594
|
+
const computedStyles = getWindow(element).getComputedStyle(element);
|
|
595
|
+
const parsedTransform = parseTransform(computedStyles);
|
|
596
|
+
const scale = {
|
|
597
|
+
x: parsedTransform?.scaleX ?? 1,
|
|
598
|
+
y: parsedTransform?.scaleY ?? 1
|
|
599
|
+
};
|
|
600
|
+
if (parsedTransform && ignoreTransforms) {
|
|
601
|
+
const updated = inverseTransform(
|
|
602
|
+
{ top, left, right, bottom, width, height },
|
|
603
|
+
parsedTransform,
|
|
604
|
+
computedStyles.transformOrigin
|
|
605
|
+
);
|
|
606
|
+
top = updated.top;
|
|
607
|
+
left = updated.left;
|
|
608
|
+
width = updated.width;
|
|
609
|
+
height = updated.height;
|
|
610
|
+
}
|
|
611
|
+
super(left, top, width, height);
|
|
612
|
+
this.scale = scale;
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
// src/utilities/type-guards/isKeyboardEvent.ts
|
|
617
|
+
function isKeyboardEvent(event) {
|
|
618
|
+
return event instanceof KeyboardEvent;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// src/utilities/type-guards/supportsViewTransition.ts
|
|
622
|
+
function supportsViewTransition(document2) {
|
|
623
|
+
return "startViewTransition" in document2;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
exports.DOMRectangle = DOMRectangle;
|
|
627
|
+
exports.Listeners = Listeners;
|
|
628
|
+
exports.Scheduler = Scheduler;
|
|
629
|
+
exports.ScrollDirection = ScrollDirection;
|
|
630
|
+
exports.Styles = Styles;
|
|
631
|
+
exports.animateTransform = animateTransform;
|
|
632
|
+
exports.canScroll = canScroll;
|
|
633
|
+
exports.canUseDOM = canUseDOM;
|
|
634
|
+
exports.cloneElement = cloneElement;
|
|
635
|
+
exports.createPlaceholder = createPlaceholder;
|
|
636
|
+
exports.detectScrollIntent = detectScrollIntent;
|
|
637
|
+
exports.getBoundingRectangle = getBoundingRectangle;
|
|
638
|
+
exports.getDocument = getDocument;
|
|
639
|
+
exports.getFirstScrollableAncestor = getFirstScrollableAncestor;
|
|
640
|
+
exports.getScrollableAncestors = getScrollableAncestors;
|
|
641
|
+
exports.getViewportBoundingRectangle = getViewportBoundingRectangle;
|
|
642
|
+
exports.getWindow = getWindow;
|
|
643
|
+
exports.inverseTransform = inverseTransform;
|
|
644
|
+
exports.isDocumentScrollingElement = isDocumentScrollingElement;
|
|
645
|
+
exports.isKeyboardEvent = isKeyboardEvent;
|
|
646
|
+
exports.parseTransform = parseTransform;
|
|
647
|
+
exports.scheduler = scheduler;
|
|
648
|
+
exports.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded;
|
|
649
|
+
exports.showPopover = showPopover;
|
|
650
|
+
exports.stringifyTransform = stringifyTransform;
|
|
651
|
+
exports.supportsPopover = supportsPopover;
|
|
652
|
+
exports.supportsStyle = supportsStyle;
|
|
653
|
+
exports.supportsViewTransition = supportsViewTransition;
|
|
654
|
+
//# sourceMappingURL=out.js.map
|
|
655
|
+
//# sourceMappingURL=utilities.cjs.map
|