@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.
Files changed (258) hide show
  1. package/README.md +54 -26
  2. package/dist/shorty.cjs +1 -1
  3. package/dist/shorty.cjs.map +1 -1
  4. package/dist/shorty.d.ts +235 -138
  5. package/dist/shorty.js +1 -1
  6. package/dist/shorty.js.map +1 -1
  7. package/dist/shorty.mjs +536 -600
  8. package/dist/shorty.mjs.map +1 -1
  9. package/package.json +9 -8
  10. package/.eslintrc.cjs +0 -224
  11. package/.lgtm.yml +0 -8
  12. package/.prettierrc.json +0 -15
  13. package/src/attr/getAttribute.ts +0 -11
  14. package/src/attr/getAttributeNS.ts +0 -12
  15. package/src/attr/hasAttribute.ts +0 -11
  16. package/src/attr/hasAttributeNS.ts +0 -15
  17. package/src/attr/removeAttribute.ts +0 -10
  18. package/src/attr/removeAttributeNS.ts +0 -14
  19. package/src/attr/setAttribute.ts +0 -11
  20. package/src/attr/setAttributeNS.ts +0 -16
  21. package/src/blocks/documentBody.ts +0 -5
  22. package/src/blocks/documentElement.ts +0 -5
  23. package/src/blocks/documentHead.ts +0 -5
  24. package/src/boolean/isApple.ts +0 -15
  25. package/src/boolean/isFirefox.ts +0 -9
  26. package/src/boolean/isMobile.ts +0 -14
  27. package/src/boolean/support3DTransform.ts +0 -7
  28. package/src/boolean/supportAnimation.ts +0 -7
  29. package/src/boolean/supportPassive.ts +0 -29
  30. package/src/boolean/supportTouch.ts +0 -9
  31. package/src/boolean/supportTransform.ts +0 -7
  32. package/src/boolean/supportTransition.ts +0 -7
  33. package/src/class/addClass.ts +0 -11
  34. package/src/class/hasClass.ts +0 -11
  35. package/src/class/removeClass.ts +0 -11
  36. package/src/event/off.ts +0 -18
  37. package/src/event/on.ts +0 -18
  38. package/src/event/one.ts +0 -26
  39. package/src/get/getBoundingClientRect.ts +0 -44
  40. package/src/get/getDocument.ts +0 -24
  41. package/src/get/getDocumentBody.ts +0 -13
  42. package/src/get/getDocumentElement.ts +0 -13
  43. package/src/get/getDocumentHead.ts +0 -14
  44. package/src/get/getElementAnimationDelay.ts +0 -25
  45. package/src/get/getElementAnimationDuration.ts +0 -25
  46. package/src/get/getElementStyle.ts +0 -25
  47. package/src/get/getElementTransitionDelay.ts +0 -25
  48. package/src/get/getElementTransitionDuration.ts +0 -25
  49. package/src/get/getNodeScroll.ts +0 -22
  50. package/src/get/getParentNode.ts +0 -28
  51. package/src/get/getRectRelativeToOffsetParent.ts +0 -43
  52. package/src/get/getUID.ts +0 -42
  53. package/src/get/getWindow.ts +0 -23
  54. package/src/index.ts +0 -571
  55. package/src/interface/boundingClientRect.d.ts +0 -10
  56. package/src/interface/css4Declaration.d.ts +0 -4
  57. package/src/interface/customElement.d.ts +0 -8
  58. package/src/interface/event.d.ts +0 -255
  59. package/src/interface/fn.ts +0 -1
  60. package/src/interface/navigatorUA.d.ts +0 -15
  61. package/src/interface/offsetRect.d.ts +0 -6
  62. package/src/interface/originalEvent.d.ts +0 -4
  63. package/src/is/isArray.ts +0 -10
  64. package/src/is/isCanvas.ts +0 -13
  65. package/src/is/isCustomElement.ts +0 -15
  66. package/src/is/isDocument.ts +0 -14
  67. package/src/is/isElement.ts +0 -28
  68. package/src/is/isElementInScrollRange.ts +0 -20
  69. package/src/is/isElementInViewport.ts +0 -21
  70. package/src/is/isElementsArray.ts +0 -13
  71. package/src/is/isFunction.ts +0 -12
  72. package/src/is/isHTMLCollection.ts +0 -12
  73. package/src/is/isHTMLElement.ts +0 -13
  74. package/src/is/isHTMLImageElement.ts +0 -12
  75. package/src/is/isJSON.ts +0 -20
  76. package/src/is/isMap.ts +0 -11
  77. package/src/is/isMedia.ts +0 -26
  78. package/src/is/isNode.ts +0 -19
  79. package/src/is/isNodeList.ts +0 -13
  80. package/src/is/isNumber.ts +0 -10
  81. package/src/is/isObject.ts +0 -10
  82. package/src/is/isRTL.ts +0 -11
  83. package/src/is/isSVGElement.ts +0 -13
  84. package/src/is/isScaledElement.ts +0 -20
  85. package/src/is/isShadowRoot.ts +0 -12
  86. package/src/is/isString.ts +0 -10
  87. package/src/is/isTableElement.ts +0 -17
  88. package/src/is/isWeakMap.ts +0 -11
  89. package/src/is/isWindow.ts +0 -13
  90. package/src/misc/ArrayFrom.ts +0 -11
  91. package/src/misc/Float32ArrayFrom.ts +0 -11
  92. package/src/misc/Float64ArrayFrom.ts +0 -11
  93. package/src/misc/ObjectAssign.ts +0 -54
  94. package/src/misc/ObjectEntries.ts +0 -11
  95. package/src/misc/ObjectFromEntries.ts +0 -11
  96. package/src/misc/ObjectHasOwn.ts +0 -18
  97. package/src/misc/ObjectKeys.ts +0 -11
  98. package/src/misc/ObjectValues.ts +0 -12
  99. package/src/misc/createCustomEvent.ts +0 -31
  100. package/src/misc/createElement.ts +0 -36
  101. package/src/misc/createElementNS.ts +0 -40
  102. package/src/misc/data.ts +0 -80
  103. package/src/misc/dispatchEvent.ts +0 -10
  104. package/src/misc/distinct.ts +0 -19
  105. package/src/misc/emulateAnimationEnd.ts +0 -43
  106. package/src/misc/emulateTransitionEnd.ts +0 -42
  107. package/src/misc/focus.ts +0 -10
  108. package/src/misc/focusTrap.ts +0 -67
  109. package/src/misc/getInstance.ts +0 -9
  110. package/src/misc/noop.ts +0 -6
  111. package/src/misc/normalizeOptions.ts +0 -58
  112. package/src/misc/normalizeValue.ts +0 -32
  113. package/src/misc/passiveHandler.ts +0 -6
  114. package/src/misc/reflow.ts +0 -9
  115. package/src/misc/setElementStyle.ts +0 -26
  116. package/src/misc/timer.ts +0 -91
  117. package/src/misc/toLowerCase.ts +0 -9
  118. package/src/misc/toUpperCase.ts +0 -9
  119. package/src/selectors/closest.ts +0 -23
  120. package/src/selectors/getCustomElements.ts +0 -19
  121. package/src/selectors/getElementById.ts +0 -16
  122. package/src/selectors/getElementsByClassName.ts +0 -22
  123. package/src/selectors/getElementsByTagName.ts +0 -22
  124. package/src/selectors/matches.ts +0 -11
  125. package/src/selectors/querySelector.ts +0 -25
  126. package/src/selectors/querySelectorAll.ts +0 -19
  127. package/src/strings/DOMContentLoadedEvent.ts +0 -5
  128. package/src/strings/DOMMouseScrollEvent.ts +0 -5
  129. package/src/strings/abortEvent.ts +0 -5
  130. package/src/strings/addEventListener.ts +0 -5
  131. package/src/strings/animationDelay.ts +0 -5
  132. package/src/strings/animationDuration.ts +0 -5
  133. package/src/strings/animationEndEvent.ts +0 -5
  134. package/src/strings/animationName.ts +0 -5
  135. package/src/strings/ariaChecked.ts +0 -5
  136. package/src/strings/ariaDescribedBy.ts +0 -5
  137. package/src/strings/ariaDescription.ts +0 -5
  138. package/src/strings/ariaExpanded.ts +0 -5
  139. package/src/strings/ariaHasPopup.ts +0 -5
  140. package/src/strings/ariaHidden.ts +0 -5
  141. package/src/strings/ariaLabel.ts +0 -5
  142. package/src/strings/ariaLabelledBy.ts +0 -5
  143. package/src/strings/ariaModal.ts +0 -5
  144. package/src/strings/ariaPressed.ts +0 -5
  145. package/src/strings/ariaSelected.ts +0 -5
  146. package/src/strings/ariaValueMax.ts +0 -5
  147. package/src/strings/ariaValueMin.ts +0 -5
  148. package/src/strings/ariaValueNow.ts +0 -5
  149. package/src/strings/ariaValueText.ts +0 -5
  150. package/src/strings/beforeunloadEvent.ts +0 -5
  151. package/src/strings/bezierEasings.ts +0 -32
  152. package/src/strings/blurEvent.ts +0 -5
  153. package/src/strings/changeEvent.ts +0 -5
  154. package/src/strings/contextmenuEvent.ts +0 -5
  155. package/src/strings/dragEvent.ts +0 -5
  156. package/src/strings/dragendEvent.ts +0 -5
  157. package/src/strings/dragenterEvent.ts +0 -5
  158. package/src/strings/dragleaveEvent.ts +0 -5
  159. package/src/strings/dragoverEvent.ts +0 -5
  160. package/src/strings/dragstartEvent.ts +0 -5
  161. package/src/strings/errorEvent.ts +0 -5
  162. package/src/strings/focusEvent.ts +0 -5
  163. package/src/strings/focusEvents.ts +0 -5
  164. package/src/strings/focusableSelector.ts +0 -4
  165. package/src/strings/focusinEvent.ts +0 -5
  166. package/src/strings/focusoutEvent.ts +0 -5
  167. package/src/strings/gesturechangeEvent.ts +0 -5
  168. package/src/strings/gestureendEvent.ts +0 -5
  169. package/src/strings/gesturestartEvent.ts +0 -5
  170. package/src/strings/keyAlt.ts +0 -7
  171. package/src/strings/keyArrowDown.ts +0 -7
  172. package/src/strings/keyArrowLeft.ts +0 -7
  173. package/src/strings/keyArrowRight.ts +0 -7
  174. package/src/strings/keyArrowUp.ts +0 -7
  175. package/src/strings/keyBackspace.ts +0 -7
  176. package/src/strings/keyCapsLock.ts +0 -7
  177. package/src/strings/keyControl.ts +0 -7
  178. package/src/strings/keyDelete.ts +0 -7
  179. package/src/strings/keyEnter.ts +0 -7
  180. package/src/strings/keyEscape.ts +0 -7
  181. package/src/strings/keyInsert.ts +0 -7
  182. package/src/strings/keyMeta.ts +0 -7
  183. package/src/strings/keyNumpadEnter.ts +0 -7
  184. package/src/strings/keyPause.ts +0 -7
  185. package/src/strings/keyScrollLock.ts +0 -7
  186. package/src/strings/keyShift.ts +0 -7
  187. package/src/strings/keySpace.ts +0 -7
  188. package/src/strings/keyTab.ts +0 -7
  189. package/src/strings/keyboardEventKeys.ts +0 -26
  190. package/src/strings/keydownEvent.ts +0 -5
  191. package/src/strings/keypressEvent.ts +0 -5
  192. package/src/strings/keyupEvent.ts +0 -5
  193. package/src/strings/loadEvent.ts +0 -5
  194. package/src/strings/loadstartEvent.ts +0 -5
  195. package/src/strings/mouseClickEvents.ts +0 -5
  196. package/src/strings/mouseHoverEvents.ts +0 -7
  197. package/src/strings/mouseSwipeEvents.ts +0 -10
  198. package/src/strings/mouseclickEvent.ts +0 -5
  199. package/src/strings/mousedblclickEvent.ts +0 -5
  200. package/src/strings/mousedownEvent.ts +0 -5
  201. package/src/strings/mouseenterEvent.ts +0 -5
  202. package/src/strings/mousehoverEvent.ts +0 -5
  203. package/src/strings/mouseinEvent.ts +0 -5
  204. package/src/strings/mouseleaveEvent.ts +0 -5
  205. package/src/strings/mousemoveEvent.ts +0 -5
  206. package/src/strings/mouseoutEvent.ts +0 -5
  207. package/src/strings/mouseoverEvent.ts +0 -5
  208. package/src/strings/mouseupEvent.ts +0 -5
  209. package/src/strings/mousewheelEvent.ts +0 -5
  210. package/src/strings/moveEvent.ts +0 -5
  211. package/src/strings/nativeEvents.ts +0 -108
  212. package/src/strings/offsetHeight.ts +0 -5
  213. package/src/strings/offsetWidth.ts +0 -5
  214. package/src/strings/orientationchangeEvent.ts +0 -5
  215. package/src/strings/pointercancelEvent.ts +0 -5
  216. package/src/strings/pointerdownEvent.ts +0 -5
  217. package/src/strings/pointerleaveEvent.ts +0 -5
  218. package/src/strings/pointermoveEvent.ts +0 -5
  219. package/src/strings/pointerupEvent.ts +0 -5
  220. package/src/strings/readystatechangeEvent.ts +0 -5
  221. package/src/strings/removeEventListener.ts +0 -5
  222. package/src/strings/resetEvent.ts +0 -5
  223. package/src/strings/resizeEvent.ts +0 -5
  224. package/src/strings/scrollEvent.ts +0 -5
  225. package/src/strings/scrollHeight.ts +0 -5
  226. package/src/strings/scrollWidth.ts +0 -5
  227. package/src/strings/selectEvent.ts +0 -5
  228. package/src/strings/selectendEvent.ts +0 -5
  229. package/src/strings/selectstartEvent.ts +0 -5
  230. package/src/strings/submitEvent.ts +0 -5
  231. package/src/strings/tabindex.ts +0 -5
  232. package/src/strings/touchEvents.ts +0 -10
  233. package/src/strings/touchcancelEvent.ts +0 -5
  234. package/src/strings/touchendEvent.ts +0 -5
  235. package/src/strings/touchmoveEvent.ts +0 -5
  236. package/src/strings/touchstartEvent.ts +0 -5
  237. package/src/strings/transitionDelay.ts +0 -5
  238. package/src/strings/transitionDuration.ts +0 -5
  239. package/src/strings/transitionEndEvent.ts +0 -5
  240. package/src/strings/transitionProperty.ts +0 -5
  241. package/src/strings/unloadEvent.ts +0 -5
  242. package/src/strings/userAgent.ts +0 -7
  243. package/src/strings/userAgentData.ts +0 -8
  244. package/test/att.test.ts +0 -43
  245. package/test/boolean.test.ts +0 -30
  246. package/test/class.test.ts +0 -26
  247. package/test/event.test.ts +0 -39
  248. package/test/fixtures/custom-elem.js +0 -18
  249. package/test/fixtures/getExampleDom.ts +0 -52
  250. package/test/fixtures/style.css +0 -18
  251. package/test/get.test.ts +0 -150
  252. package/test/is.test.ts +0 -240
  253. package/test/misc.test.ts +0 -400
  254. package/test/selectors.test.ts +0 -90
  255. package/tsconfig.json +0 -36
  256. package/vite.config.mts +0 -45
  257. package/vitest.config-ui.mts +0 -26
  258. 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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;