@thednp/shorty 2.0.7 → 2.0.8
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 +54 -26
- package/dist/shorty.cjs +1 -1
- package/dist/shorty.cjs.map +1 -1
- package/dist/shorty.d.ts +235 -138
- package/dist/shorty.js +1 -1
- package/dist/shorty.js.map +1 -1
- package/dist/shorty.mjs +536 -600
- package/dist/shorty.mjs.map +1 -1
- package/package.json +9 -8
- package/.eslintrc.cjs +0 -224
- package/.lgtm.yml +0 -8
- package/.prettierrc.json +0 -15
- package/src/attr/getAttribute.ts +0 -11
- package/src/attr/getAttributeNS.ts +0 -12
- package/src/attr/hasAttribute.ts +0 -11
- package/src/attr/hasAttributeNS.ts +0 -15
- package/src/attr/removeAttribute.ts +0 -10
- package/src/attr/removeAttributeNS.ts +0 -14
- package/src/attr/setAttribute.ts +0 -11
- package/src/attr/setAttributeNS.ts +0 -16
- package/src/blocks/documentBody.ts +0 -5
- package/src/blocks/documentElement.ts +0 -5
- package/src/blocks/documentHead.ts +0 -5
- package/src/boolean/isApple.ts +0 -15
- package/src/boolean/isFirefox.ts +0 -9
- package/src/boolean/isMobile.ts +0 -14
- package/src/boolean/support3DTransform.ts +0 -7
- package/src/boolean/supportAnimation.ts +0 -7
- package/src/boolean/supportPassive.ts +0 -29
- package/src/boolean/supportTouch.ts +0 -9
- package/src/boolean/supportTransform.ts +0 -7
- package/src/boolean/supportTransition.ts +0 -7
- package/src/class/addClass.ts +0 -11
- package/src/class/hasClass.ts +0 -11
- package/src/class/removeClass.ts +0 -11
- package/src/event/off.ts +0 -18
- package/src/event/on.ts +0 -18
- package/src/event/one.ts +0 -26
- package/src/get/getBoundingClientRect.ts +0 -44
- package/src/get/getDocument.ts +0 -24
- package/src/get/getDocumentBody.ts +0 -13
- package/src/get/getDocumentElement.ts +0 -13
- package/src/get/getDocumentHead.ts +0 -14
- package/src/get/getElementAnimationDelay.ts +0 -25
- package/src/get/getElementAnimationDuration.ts +0 -25
- package/src/get/getElementStyle.ts +0 -25
- package/src/get/getElementTransitionDelay.ts +0 -25
- package/src/get/getElementTransitionDuration.ts +0 -25
- package/src/get/getNodeScroll.ts +0 -22
- package/src/get/getParentNode.ts +0 -28
- package/src/get/getRectRelativeToOffsetParent.ts +0 -43
- package/src/get/getUID.ts +0 -42
- package/src/get/getWindow.ts +0 -23
- package/src/index.ts +0 -571
- package/src/interface/boundingClientRect.d.ts +0 -10
- package/src/interface/css4Declaration.d.ts +0 -4
- package/src/interface/customElement.d.ts +0 -8
- package/src/interface/event.d.ts +0 -255
- package/src/interface/fn.ts +0 -1
- package/src/interface/navigatorUA.d.ts +0 -15
- package/src/interface/offsetRect.d.ts +0 -6
- package/src/interface/originalEvent.d.ts +0 -4
- package/src/is/isArray.ts +0 -10
- package/src/is/isCanvas.ts +0 -13
- package/src/is/isCustomElement.ts +0 -15
- package/src/is/isDocument.ts +0 -14
- package/src/is/isElement.ts +0 -28
- package/src/is/isElementInScrollRange.ts +0 -20
- package/src/is/isElementInViewport.ts +0 -21
- package/src/is/isElementsArray.ts +0 -13
- package/src/is/isFunction.ts +0 -12
- package/src/is/isHTMLCollection.ts +0 -12
- package/src/is/isHTMLElement.ts +0 -13
- package/src/is/isHTMLImageElement.ts +0 -12
- package/src/is/isJSON.ts +0 -20
- package/src/is/isMap.ts +0 -11
- package/src/is/isMedia.ts +0 -26
- package/src/is/isNode.ts +0 -19
- package/src/is/isNodeList.ts +0 -13
- package/src/is/isNumber.ts +0 -10
- package/src/is/isObject.ts +0 -10
- package/src/is/isRTL.ts +0 -11
- package/src/is/isSVGElement.ts +0 -13
- package/src/is/isScaledElement.ts +0 -20
- package/src/is/isShadowRoot.ts +0 -12
- package/src/is/isString.ts +0 -10
- package/src/is/isTableElement.ts +0 -17
- package/src/is/isWeakMap.ts +0 -11
- package/src/is/isWindow.ts +0 -13
- package/src/misc/ArrayFrom.ts +0 -11
- package/src/misc/Float32ArrayFrom.ts +0 -11
- package/src/misc/Float64ArrayFrom.ts +0 -11
- package/src/misc/ObjectAssign.ts +0 -54
- package/src/misc/ObjectEntries.ts +0 -11
- package/src/misc/ObjectFromEntries.ts +0 -11
- package/src/misc/ObjectHasOwn.ts +0 -18
- package/src/misc/ObjectKeys.ts +0 -11
- package/src/misc/ObjectValues.ts +0 -12
- package/src/misc/createCustomEvent.ts +0 -31
- package/src/misc/createElement.ts +0 -36
- package/src/misc/createElementNS.ts +0 -40
- package/src/misc/data.ts +0 -80
- package/src/misc/dispatchEvent.ts +0 -10
- package/src/misc/distinct.ts +0 -19
- package/src/misc/emulateAnimationEnd.ts +0 -43
- package/src/misc/emulateTransitionEnd.ts +0 -42
- package/src/misc/focus.ts +0 -10
- package/src/misc/focusTrap.ts +0 -67
- package/src/misc/getInstance.ts +0 -9
- package/src/misc/noop.ts +0 -6
- package/src/misc/normalizeOptions.ts +0 -58
- package/src/misc/normalizeValue.ts +0 -32
- package/src/misc/passiveHandler.ts +0 -6
- package/src/misc/reflow.ts +0 -9
- package/src/misc/setElementStyle.ts +0 -26
- package/src/misc/timer.ts +0 -91
- package/src/misc/toLowerCase.ts +0 -9
- package/src/misc/toUpperCase.ts +0 -9
- package/src/selectors/closest.ts +0 -23
- package/src/selectors/getCustomElements.ts +0 -19
- package/src/selectors/getElementById.ts +0 -16
- package/src/selectors/getElementsByClassName.ts +0 -22
- package/src/selectors/getElementsByTagName.ts +0 -22
- package/src/selectors/matches.ts +0 -11
- package/src/selectors/querySelector.ts +0 -25
- package/src/selectors/querySelectorAll.ts +0 -19
- package/src/strings/DOMContentLoadedEvent.ts +0 -5
- package/src/strings/DOMMouseScrollEvent.ts +0 -5
- package/src/strings/abortEvent.ts +0 -5
- package/src/strings/addEventListener.ts +0 -5
- package/src/strings/animationDelay.ts +0 -5
- package/src/strings/animationDuration.ts +0 -5
- package/src/strings/animationEndEvent.ts +0 -5
- package/src/strings/animationName.ts +0 -5
- package/src/strings/ariaChecked.ts +0 -5
- package/src/strings/ariaDescribedBy.ts +0 -5
- package/src/strings/ariaDescription.ts +0 -5
- package/src/strings/ariaExpanded.ts +0 -5
- package/src/strings/ariaHasPopup.ts +0 -5
- package/src/strings/ariaHidden.ts +0 -5
- package/src/strings/ariaLabel.ts +0 -5
- package/src/strings/ariaLabelledBy.ts +0 -5
- package/src/strings/ariaModal.ts +0 -5
- package/src/strings/ariaPressed.ts +0 -5
- package/src/strings/ariaSelected.ts +0 -5
- package/src/strings/ariaValueMax.ts +0 -5
- package/src/strings/ariaValueMin.ts +0 -5
- package/src/strings/ariaValueNow.ts +0 -5
- package/src/strings/ariaValueText.ts +0 -5
- package/src/strings/beforeunloadEvent.ts +0 -5
- package/src/strings/bezierEasings.ts +0 -32
- package/src/strings/blurEvent.ts +0 -5
- package/src/strings/changeEvent.ts +0 -5
- package/src/strings/contextmenuEvent.ts +0 -5
- package/src/strings/dragEvent.ts +0 -5
- package/src/strings/dragendEvent.ts +0 -5
- package/src/strings/dragenterEvent.ts +0 -5
- package/src/strings/dragleaveEvent.ts +0 -5
- package/src/strings/dragoverEvent.ts +0 -5
- package/src/strings/dragstartEvent.ts +0 -5
- package/src/strings/errorEvent.ts +0 -5
- package/src/strings/focusEvent.ts +0 -5
- package/src/strings/focusEvents.ts +0 -5
- package/src/strings/focusableSelector.ts +0 -4
- package/src/strings/focusinEvent.ts +0 -5
- package/src/strings/focusoutEvent.ts +0 -5
- package/src/strings/gesturechangeEvent.ts +0 -5
- package/src/strings/gestureendEvent.ts +0 -5
- package/src/strings/gesturestartEvent.ts +0 -5
- package/src/strings/keyAlt.ts +0 -7
- package/src/strings/keyArrowDown.ts +0 -7
- package/src/strings/keyArrowLeft.ts +0 -7
- package/src/strings/keyArrowRight.ts +0 -7
- package/src/strings/keyArrowUp.ts +0 -7
- package/src/strings/keyBackspace.ts +0 -7
- package/src/strings/keyCapsLock.ts +0 -7
- package/src/strings/keyControl.ts +0 -7
- package/src/strings/keyDelete.ts +0 -7
- package/src/strings/keyEnter.ts +0 -7
- package/src/strings/keyEscape.ts +0 -7
- package/src/strings/keyInsert.ts +0 -7
- package/src/strings/keyMeta.ts +0 -7
- package/src/strings/keyNumpadEnter.ts +0 -7
- package/src/strings/keyPause.ts +0 -7
- package/src/strings/keyScrollLock.ts +0 -7
- package/src/strings/keyShift.ts +0 -7
- package/src/strings/keySpace.ts +0 -7
- package/src/strings/keyTab.ts +0 -7
- package/src/strings/keyboardEventKeys.ts +0 -26
- package/src/strings/keydownEvent.ts +0 -5
- package/src/strings/keypressEvent.ts +0 -5
- package/src/strings/keyupEvent.ts +0 -5
- package/src/strings/loadEvent.ts +0 -5
- package/src/strings/loadstartEvent.ts +0 -5
- package/src/strings/mouseClickEvents.ts +0 -5
- package/src/strings/mouseHoverEvents.ts +0 -7
- package/src/strings/mouseSwipeEvents.ts +0 -10
- package/src/strings/mouseclickEvent.ts +0 -5
- package/src/strings/mousedblclickEvent.ts +0 -5
- package/src/strings/mousedownEvent.ts +0 -5
- package/src/strings/mouseenterEvent.ts +0 -5
- package/src/strings/mousehoverEvent.ts +0 -5
- package/src/strings/mouseinEvent.ts +0 -5
- package/src/strings/mouseleaveEvent.ts +0 -5
- package/src/strings/mousemoveEvent.ts +0 -5
- package/src/strings/mouseoutEvent.ts +0 -5
- package/src/strings/mouseoverEvent.ts +0 -5
- package/src/strings/mouseupEvent.ts +0 -5
- package/src/strings/mousewheelEvent.ts +0 -5
- package/src/strings/moveEvent.ts +0 -5
- package/src/strings/nativeEvents.ts +0 -108
- package/src/strings/offsetHeight.ts +0 -5
- package/src/strings/offsetWidth.ts +0 -5
- package/src/strings/orientationchangeEvent.ts +0 -5
- package/src/strings/pointercancelEvent.ts +0 -5
- package/src/strings/pointerdownEvent.ts +0 -5
- package/src/strings/pointerleaveEvent.ts +0 -5
- package/src/strings/pointermoveEvent.ts +0 -5
- package/src/strings/pointerupEvent.ts +0 -5
- package/src/strings/readystatechangeEvent.ts +0 -5
- package/src/strings/removeEventListener.ts +0 -5
- package/src/strings/resetEvent.ts +0 -5
- package/src/strings/resizeEvent.ts +0 -5
- package/src/strings/scrollEvent.ts +0 -5
- package/src/strings/scrollHeight.ts +0 -5
- package/src/strings/scrollWidth.ts +0 -5
- package/src/strings/selectEvent.ts +0 -5
- package/src/strings/selectendEvent.ts +0 -5
- package/src/strings/selectstartEvent.ts +0 -5
- package/src/strings/submitEvent.ts +0 -5
- package/src/strings/tabindex.ts +0 -5
- package/src/strings/touchEvents.ts +0 -10
- package/src/strings/touchcancelEvent.ts +0 -5
- package/src/strings/touchendEvent.ts +0 -5
- package/src/strings/touchmoveEvent.ts +0 -5
- package/src/strings/touchstartEvent.ts +0 -5
- package/src/strings/transitionDelay.ts +0 -5
- package/src/strings/transitionDuration.ts +0 -5
- package/src/strings/transitionEndEvent.ts +0 -5
- package/src/strings/transitionProperty.ts +0 -5
- package/src/strings/unloadEvent.ts +0 -5
- package/src/strings/userAgent.ts +0 -7
- package/src/strings/userAgentData.ts +0 -8
- package/test/att.test.ts +0 -43
- package/test/boolean.test.ts +0 -30
- package/test/class.test.ts +0 -26
- package/test/event.test.ts +0 -39
- package/test/fixtures/custom-elem.js +0 -18
- package/test/fixtures/getExampleDom.ts +0 -52
- package/test/fixtures/style.css +0 -18
- package/test/get.test.ts +0 -150
- package/test/is.test.ts +0 -240
- package/test/misc.test.ts +0 -400
- package/test/selectors.test.ts +0 -90
- package/tsconfig.json +0 -36
- package/vite.config.mts +0 -45
- package/vitest.config-ui.mts +0 -26
- package/vitest.config.mts +0 -25
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import isHTMLElement from "../is/isHTMLElement";
|
|
2
|
-
import type { BoundingClientRect } from "../interface/boundingClientRect";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns the bounding client rect of a target `HTMLElement`.
|
|
6
|
-
*
|
|
7
|
-
* @see https://github.com/floating-ui/floating-ui
|
|
8
|
-
*
|
|
9
|
-
* @param element event.target
|
|
10
|
-
* @param includeScale when *true*, the target scale is also computed
|
|
11
|
-
* @returns the bounding client rect object
|
|
12
|
-
*/
|
|
13
|
-
const getBoundingClientRect = (
|
|
14
|
-
element: HTMLElement,
|
|
15
|
-
includeScale?: boolean,
|
|
16
|
-
): BoundingClientRect => {
|
|
17
|
-
const { width, height, top, right, bottom, left } = element
|
|
18
|
-
.getBoundingClientRect();
|
|
19
|
-
let scaleX = 1;
|
|
20
|
-
let scaleY = 1;
|
|
21
|
-
|
|
22
|
-
if (includeScale && isHTMLElement(element)) {
|
|
23
|
-
const { offsetWidth, offsetHeight } = element;
|
|
24
|
-
scaleX = offsetWidth > 0
|
|
25
|
-
? Math.round(width) / offsetWidth
|
|
26
|
-
: /* istanbul ignore next @preserve */ 1;
|
|
27
|
-
scaleY = offsetHeight > 0
|
|
28
|
-
? Math.round(height) / offsetHeight
|
|
29
|
-
: /* istanbul ignore next @preserve */ 1;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
width: width / scaleX,
|
|
34
|
-
height: height / scaleY,
|
|
35
|
-
top: top / scaleY,
|
|
36
|
-
right: right / scaleX,
|
|
37
|
-
bottom: bottom / scaleY,
|
|
38
|
-
left: left / scaleX,
|
|
39
|
-
x: left / scaleX,
|
|
40
|
-
y: top / scaleY,
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export default getBoundingClientRect;
|
package/src/get/getDocument.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import isNode from "../is/isNode";
|
|
2
|
-
import isWindow from "../is/isWindow";
|
|
3
|
-
import isDocument from "../is/isDocument";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the `document` or the `#document` element.
|
|
7
|
-
*
|
|
8
|
-
* @see https://github.com/floating-ui/floating-ui
|
|
9
|
-
*
|
|
10
|
-
* @param node the reference node
|
|
11
|
-
* @returns the parent document of the given node
|
|
12
|
-
*/
|
|
13
|
-
const getDocument = (node?: Node | Document | Window): Document => {
|
|
14
|
-
// node instanceof Window
|
|
15
|
-
if (isWindow(node)) return node.document;
|
|
16
|
-
// node instanceof Document
|
|
17
|
-
if (isDocument(node)) return node;
|
|
18
|
-
// node instanceof Node
|
|
19
|
-
if (isNode(node)) return node.ownerDocument as Document;
|
|
20
|
-
// node is undefined | NULL
|
|
21
|
-
return globalThis.document;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default getDocument;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import getDocument from "./getDocument";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns the `document.body` or the `<body>` element.
|
|
5
|
-
*
|
|
6
|
-
* @param node the reference node
|
|
7
|
-
* @returns the parent `<body>` of the specified node
|
|
8
|
-
*/
|
|
9
|
-
const getDocumentBody = (node?: Node | Document | Window): HTMLElement => {
|
|
10
|
-
return getDocument(node).body;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default getDocumentBody;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import getDocument from "./getDocument";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns the `document.documentElement` or the `<HTML>` element.
|
|
5
|
-
*
|
|
6
|
-
* @param node the reference node
|
|
7
|
-
* @returns the parent `<HTML>` of the node's parent document
|
|
8
|
-
*/
|
|
9
|
-
const getDocumentElement = (node?: Node | Document | Window): HTMLElement => {
|
|
10
|
-
return getDocument(node).documentElement;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default getDocumentElement;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import getDocument from "./getDocument";
|
|
2
|
-
/**
|
|
3
|
-
* Returns the `document.head` or the `<head>` element.
|
|
4
|
-
*
|
|
5
|
-
* @param node the reference node
|
|
6
|
-
* @returns the `<head>` of the node's parent document
|
|
7
|
-
*/
|
|
8
|
-
const getDocumentHead = (
|
|
9
|
-
node?: Node | Document | Window,
|
|
10
|
-
): HTMLElement & HTMLHeadElement => {
|
|
11
|
-
return getDocument(node).head;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default getDocumentHead;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import animationDelay from "../strings/animationDelay";
|
|
2
|
-
import animationName from "../strings/animationName";
|
|
3
|
-
import getElementStyle from "./getElementStyle";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Utility to get the computed `animationDelay`
|
|
7
|
-
* from Element in miliseconds.
|
|
8
|
-
*
|
|
9
|
-
* @param element target
|
|
10
|
-
* @return the `animationDelay` value in miliseconds
|
|
11
|
-
*/
|
|
12
|
-
const getElementAnimationDelay = (element: HTMLElement): number => {
|
|
13
|
-
const propertyValue = getElementStyle(element, animationName);
|
|
14
|
-
const durationValue = getElementStyle(element, animationDelay);
|
|
15
|
-
const durationScale = durationValue.includes("ms")
|
|
16
|
-
? /* istanbul ignore next */ 1
|
|
17
|
-
: 1000;
|
|
18
|
-
const duration = propertyValue && propertyValue !== "none"
|
|
19
|
-
? parseFloat(durationValue) * durationScale
|
|
20
|
-
: 0;
|
|
21
|
-
|
|
22
|
-
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default getElementAnimationDelay;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import animationDuration from "../strings/animationDuration";
|
|
2
|
-
import animationName from "../strings/animationName";
|
|
3
|
-
import getElementStyle from "./getElementStyle";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Utility to get the computed `animationDuration`
|
|
7
|
-
* from `HTMLElement` in miliseconds.
|
|
8
|
-
*
|
|
9
|
-
* @param element target
|
|
10
|
-
* @return the `animationDuration` value in miliseconds
|
|
11
|
-
*/
|
|
12
|
-
const getElementAnimationDuration = (element: HTMLElement): number => {
|
|
13
|
-
const propertyValue = getElementStyle(element, animationName);
|
|
14
|
-
const durationValue = getElementStyle(element, animationDuration);
|
|
15
|
-
const durationScale = durationValue.includes("ms")
|
|
16
|
-
? /* istanbul ignore next */ 1
|
|
17
|
-
: 1000;
|
|
18
|
-
const duration = propertyValue && propertyValue !== "none"
|
|
19
|
-
? parseFloat(durationValue) * durationScale
|
|
20
|
-
: 0;
|
|
21
|
-
|
|
22
|
-
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default getElementAnimationDuration;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// import CSS4Declaration from "../interface/css4Declaration";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shortcut for `window.getComputedStyle(element).propertyName`
|
|
5
|
-
* static method.
|
|
6
|
-
*
|
|
7
|
-
* * If `element` parameter is not an `HTMLElement`, `getComputedStyle`
|
|
8
|
-
* throws a `ReferenceError`.
|
|
9
|
-
*
|
|
10
|
-
* @param element target
|
|
11
|
-
* @param property the css property
|
|
12
|
-
* @return the css property value
|
|
13
|
-
*/
|
|
14
|
-
const getElementStyle = (element: HTMLElement, property: string): string => {
|
|
15
|
-
const computedStyle = getComputedStyle(element);
|
|
16
|
-
const prop = property
|
|
17
|
-
.replace("webkit", "Webkit")
|
|
18
|
-
.replace(/([A-Z])/g, "-$1")
|
|
19
|
-
.toLowerCase();
|
|
20
|
-
|
|
21
|
-
// modern browsers only
|
|
22
|
-
return computedStyle.getPropertyValue(prop);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default getElementStyle;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import transitionDelay from "../strings/transitionDelay";
|
|
2
|
-
import transitionProperty from "../strings/transitionProperty";
|
|
3
|
-
import getElementStyle from "./getElementStyle";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Utility to get the computed `transitionDelay`
|
|
7
|
-
* from Element in miliseconds.
|
|
8
|
-
*
|
|
9
|
-
* @param element target
|
|
10
|
-
* @return the `transitionDelay` value in miliseconds
|
|
11
|
-
*/
|
|
12
|
-
const getElementTransitionDelay = (element: HTMLElement): number => {
|
|
13
|
-
const propertyValue = getElementStyle(element, transitionProperty);
|
|
14
|
-
const delayValue = getElementStyle(element, transitionDelay);
|
|
15
|
-
const delayScale = delayValue.includes("ms")
|
|
16
|
-
? /* istanbul ignore next */ 1
|
|
17
|
-
: 1000;
|
|
18
|
-
const duration = propertyValue && propertyValue !== "none"
|
|
19
|
-
? parseFloat(delayValue) * delayScale
|
|
20
|
-
: /* istanbul ignore next */ 0;
|
|
21
|
-
|
|
22
|
-
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default getElementTransitionDelay;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import transitionDuration from "../strings/transitionDuration";
|
|
2
|
-
import transitionProperty from "../strings/transitionProperty";
|
|
3
|
-
import getElementStyle from "./getElementStyle";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Utility to get the computed `transitionDuration`
|
|
7
|
-
* from Element in miliseconds.
|
|
8
|
-
*
|
|
9
|
-
* @param element target
|
|
10
|
-
* @return the `transitionDuration` value in miliseconds
|
|
11
|
-
*/
|
|
12
|
-
const getElementTransitionDuration = (element: HTMLElement): number => {
|
|
13
|
-
const propertyValue = getElementStyle(element, transitionProperty);
|
|
14
|
-
const durationValue = getElementStyle(element, transitionDuration);
|
|
15
|
-
const durationScale = durationValue.includes("ms")
|
|
16
|
-
? /* istanbul ignore next */ 1
|
|
17
|
-
: 1000;
|
|
18
|
-
const duration = propertyValue && propertyValue !== "none"
|
|
19
|
-
? parseFloat(durationValue) * durationScale
|
|
20
|
-
: /* istanbul ignore next */ 0;
|
|
21
|
-
|
|
22
|
-
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default getElementTransitionDuration;
|
package/src/get/getNodeScroll.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import isWindow from "../is/isWindow";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns an `{x,y}` object with the target
|
|
5
|
-
* `HTMLElement` / `Node` scroll position.
|
|
6
|
-
*
|
|
7
|
-
* @see https://github.com/floating-ui/floating-ui
|
|
8
|
-
*
|
|
9
|
-
* @param element target node / element
|
|
10
|
-
* @returns the scroll tuple
|
|
11
|
-
*/
|
|
12
|
-
const getNodeScroll = (
|
|
13
|
-
element: HTMLElement | Window,
|
|
14
|
-
): { x: number; y: number } => {
|
|
15
|
-
const isWin = isWindow(element);
|
|
16
|
-
const x = isWin ? element.scrollX : element.scrollLeft;
|
|
17
|
-
const y = isWin ? element.scrollY : element.scrollTop;
|
|
18
|
-
|
|
19
|
-
return { x, y };
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default getNodeScroll;
|
package/src/get/getParentNode.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import getDocumentElement from "./getDocumentElement";
|
|
2
|
-
import isShadowRoot from "../is/isShadowRoot";
|
|
3
|
-
import isHTMLElement from "../is/isHTMLElement";
|
|
4
|
-
import isNode from "../is/isNode";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns the `parentNode` also going through `ShadowRoot`.
|
|
8
|
-
*
|
|
9
|
-
* @see https://github.com/floating-ui/floating-ui
|
|
10
|
-
*
|
|
11
|
-
* @param {Node} node the target node
|
|
12
|
-
* @returns {Node} the apropriate parent node
|
|
13
|
-
*/
|
|
14
|
-
const getParentNode = (node: Node): Node | ParentNode => {
|
|
15
|
-
if (node.nodeName === "HTML") {
|
|
16
|
-
return node;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// this is a quicker (but less type safe) way to save quite some bytes from the bundle
|
|
20
|
-
return (
|
|
21
|
-
(isHTMLElement(node) && node.assignedSlot) || // step into the shadow DOM of the parent of a slotted node
|
|
22
|
-
(isNode(node) && node.parentNode) || // DOM Element detected
|
|
23
|
-
(isShadowRoot(node) && node.host) || // ShadowRoot detected
|
|
24
|
-
getDocumentElement(node) // fallback to <HTML>
|
|
25
|
-
);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default getParentNode;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { OffsetRect } from "../interface/offsetRect";
|
|
2
|
-
import isScaledElement from "../is/isScaledElement";
|
|
3
|
-
import isHTMLElement from "../is/isHTMLElement";
|
|
4
|
-
import getBoundingClientRect from "./getBoundingClientRect";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns the rect relative to a given offset parent and its scroll position.
|
|
8
|
-
*
|
|
9
|
-
* @see https://github.com/floating-ui/floating-ui
|
|
10
|
-
*
|
|
11
|
-
* @param element target
|
|
12
|
-
* @param offsetParent the container / offset parent
|
|
13
|
-
* @param scroll the offsetParent scroll position
|
|
14
|
-
* @returns a DOMRect like object
|
|
15
|
-
*/
|
|
16
|
-
const getRectRelativeToOffsetParent = (
|
|
17
|
-
element: HTMLElement,
|
|
18
|
-
offsetParent: HTMLElement,
|
|
19
|
-
scroll: { x: number; y: number },
|
|
20
|
-
): OffsetRect => {
|
|
21
|
-
const isParentAnElement = isHTMLElement(offsetParent);
|
|
22
|
-
const rect = getBoundingClientRect(
|
|
23
|
-
element,
|
|
24
|
-
isParentAnElement && isScaledElement(offsetParent),
|
|
25
|
-
);
|
|
26
|
-
const offsets = { x: 0, y: 0 };
|
|
27
|
-
|
|
28
|
-
// istanbul ignore else @preserve
|
|
29
|
-
if (isParentAnElement) {
|
|
30
|
-
const offsetRect = getBoundingClientRect(offsetParent, true);
|
|
31
|
-
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
32
|
-
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
x: rect.left + scroll.x - offsets.x,
|
|
37
|
-
y: rect.top + scroll.y - offsets.y,
|
|
38
|
-
width: rect.width,
|
|
39
|
-
height: rect.height,
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default getRectRelativeToOffsetParent;
|
package/src/get/getUID.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import isMap from "../is/isMap";
|
|
2
|
-
|
|
3
|
-
let elementUID = 0;
|
|
4
|
-
let elementMapUID = 0;
|
|
5
|
-
|
|
6
|
-
type KeyIdMap = Map<string | number, number>;
|
|
7
|
-
type IDMap = Map<number | string | HTMLElement, number | KeyIdMap>;
|
|
8
|
-
|
|
9
|
-
const elementIDMap: IDMap = new Map();
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Returns a unique identifier for popover, tooltip, scrollspy.
|
|
13
|
-
*
|
|
14
|
-
* @param element target element
|
|
15
|
-
* @param key optional identifier key
|
|
16
|
-
* @returns an existing or new unique ID
|
|
17
|
-
*/
|
|
18
|
-
const getUID = (element: HTMLElement, key?: string): number => {
|
|
19
|
-
let result = key ? elementUID : elementMapUID;
|
|
20
|
-
|
|
21
|
-
if (key) {
|
|
22
|
-
const elID = getUID(element);
|
|
23
|
-
const elMap = elementIDMap.get(elID) || (new Map() as KeyIdMap);
|
|
24
|
-
if (!elementIDMap.has(elID)) {
|
|
25
|
-
elementIDMap.set(elID, elMap);
|
|
26
|
-
}
|
|
27
|
-
if (isMap(elMap as KeyIdMap) && !(elMap as KeyIdMap).has(key)) {
|
|
28
|
-
(elMap as KeyIdMap).set(key, result);
|
|
29
|
-
elementUID += 1;
|
|
30
|
-
} else result = (elMap as KeyIdMap).get(key) as number;
|
|
31
|
-
} else {
|
|
32
|
-
const elkey = element.id || element;
|
|
33
|
-
|
|
34
|
-
if (!elementIDMap.has(elkey)) {
|
|
35
|
-
elementIDMap.set(elkey, result);
|
|
36
|
-
elementMapUID += 1;
|
|
37
|
-
} else result = elementIDMap.get(elkey) as number;
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default getUID;
|
package/src/get/getWindow.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import isDocument from "../is/isDocument";
|
|
2
|
-
import isNode from "../is/isNode";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns the `Window` object of a target node.
|
|
6
|
-
*
|
|
7
|
-
* @see https://github.com/floating-ui/floating-ui
|
|
8
|
-
*
|
|
9
|
-
* @param node target node
|
|
10
|
-
* @returns the `Window` object
|
|
11
|
-
*/
|
|
12
|
-
const getWindow = (node?: Node): Window => {
|
|
13
|
-
// node is undefined | NULL
|
|
14
|
-
if (!node) return window;
|
|
15
|
-
// node instanceof Document
|
|
16
|
-
if (isDocument(node)) return node.defaultView as Window;
|
|
17
|
-
// node instanceof Node
|
|
18
|
-
if (isNode(node)) return node?.ownerDocument?.defaultView as Window;
|
|
19
|
-
// node is instanceof Window
|
|
20
|
-
return node;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default getWindow;
|