@thednp/shorty 1.0.3 → 2.0.0-alpha10

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 (353) hide show
  1. package/.eslintrc.cjs +224 -0
  2. package/.lgtm.yml +9 -0
  3. package/.prettierrc.json +15 -0
  4. package/README.md +195 -198
  5. package/cypress/e2e/att.cy.ts +46 -0
  6. package/cypress/e2e/boolean.cy.ts +44 -0
  7. package/cypress/e2e/class.cy.ts +28 -0
  8. package/cypress/e2e/event.cy.ts +51 -0
  9. package/cypress/e2e/get.cy.ts +168 -0
  10. package/cypress/e2e/is.cy.ts +233 -0
  11. package/cypress/e2e/misc.cy.ts +331 -0
  12. package/cypress/e2e/selectors.cy.ts +85 -0
  13. package/cypress/fixtures/custom-elem.js +18 -0
  14. package/cypress/plugins/esbuild-istanbul.ts +50 -0
  15. package/cypress/plugins/tsCompile.ts +34 -0
  16. package/cypress/support/commands.ts +37 -0
  17. package/cypress/support/e2e.ts +21 -0
  18. package/cypress/support/index.js +22 -0
  19. package/cypress/test.html +63 -0
  20. package/cypress.config.ts +30 -0
  21. package/dist/shorty.cjs +2 -0
  22. package/dist/shorty.cjs.map +1 -0
  23. package/dist/shorty.d.ts +1502 -0
  24. package/dist/shorty.js +2 -2628
  25. package/dist/shorty.js.map +1 -0
  26. package/dist/shorty.mjs +552 -0
  27. package/dist/shorty.mjs.map +1 -0
  28. package/dts.config.ts +22 -0
  29. package/package.json +33 -38
  30. package/src/attr/getAttribute.ts +11 -0
  31. package/src/attr/getAttributeNS.ts +12 -0
  32. package/src/attr/hasAttribute.ts +10 -0
  33. package/src/attr/hasAttributeNS.ts +12 -0
  34. package/src/attr/removeAttribute.ts +9 -0
  35. package/src/attr/removeAttributeNS.ts +11 -0
  36. package/src/attr/setAttribute.ts +11 -0
  37. package/src/attr/setAttributeNS.ts +12 -0
  38. package/src/blocks/{documentBody.js → documentBody.ts} +0 -0
  39. package/src/blocks/{documentElement.js → documentElement.ts} +0 -0
  40. package/src/blocks/{documentHead.js → documentHead.ts} +0 -0
  41. package/src/boolean/isApple.ts +14 -0
  42. package/src/boolean/{isFirefox.js → isFirefox.ts} +2 -3
  43. package/src/boolean/{isMobile.js → isMobile.ts} +1 -2
  44. package/src/boolean/support3DTransform.ts +8 -0
  45. package/src/boolean/supportAnimation.ts +8 -0
  46. package/src/boolean/{supportPassive.js → supportPassive.ts} +3 -3
  47. package/src/boolean/supportTouch.ts +7 -0
  48. package/src/boolean/supportTransform.ts +8 -0
  49. package/src/boolean/supportTransition.ts +8 -0
  50. package/src/class/addClass.ts +11 -0
  51. package/src/class/hasClass.ts +11 -0
  52. package/src/class/removeClass.ts +11 -0
  53. package/src/event/off.ts +14 -0
  54. package/src/event/on.ts +14 -0
  55. package/src/event/one.ts +25 -0
  56. package/src/get/{getBoundingClientRect.js → getBoundingClientRect.ts} +14 -12
  57. package/src/get/{getDocument.js → getDocument.ts} +11 -7
  58. package/src/get/getDocumentBody.ts +13 -0
  59. package/src/get/getDocumentElement.ts +13 -0
  60. package/src/get/getDocumentHead.ts +12 -0
  61. package/src/get/{getElementAnimationDelay.js → getElementAnimationDelay.ts} +10 -9
  62. package/src/get/{getElementAnimationDuration.js → getElementAnimationDuration.ts} +10 -8
  63. package/src/get/getElementStyle.ts +25 -0
  64. package/src/get/{getElementTransitionDelay.js → getElementTransitionDelay.ts} +12 -8
  65. package/src/get/{getElementTransitionDuration.js → getElementTransitionDuration.ts} +12 -8
  66. package/src/get/{getNodeScroll.js → getNodeScroll.ts} +9 -5
  67. package/src/get/{getParentNode.js → getParentNode.ts} +11 -6
  68. package/src/get/{getRectRelativeToOffsetParent.js → getRectRelativeToOffsetParent.ts} +15 -7
  69. package/src/get/getUID.ts +42 -0
  70. package/src/get/{getWindow.js → getWindow.ts} +9 -6
  71. package/src/{index.js → index.ts} +37 -43
  72. package/src/interface/boundingClientRect.d.ts +10 -0
  73. package/src/interface/css4Declaration.d.ts +4 -0
  74. package/src/interface/customElement.d.ts +8 -0
  75. package/src/interface/navigatorUA.d.ts +15 -0
  76. package/src/interface/offsetRect.d.ts +6 -0
  77. package/src/interface/originalEvent.d.ts +4 -0
  78. package/src/is/isArray.ts +9 -0
  79. package/src/is/isCanvas.ts +13 -0
  80. package/src/is/isCustomElement.ts +13 -0
  81. package/src/is/isDocument.ts +13 -0
  82. package/src/is/{isElement.js → isElement.ts} +10 -5
  83. package/src/is/{isElementInScrollRange.js → isElementInScrollRange.ts} +4 -4
  84. package/src/is/{isElementInViewport.js → isElementInViewport.ts} +6 -12
  85. package/src/is/isElementsArray.ts +13 -0
  86. package/src/is/isFunction.ts +10 -0
  87. package/src/is/isHTMLCollection.ts +12 -0
  88. package/src/is/isHTMLElement.ts +13 -0
  89. package/src/is/isHTMLImageElement.ts +12 -0
  90. package/src/is/isJSON.ts +20 -0
  91. package/src/is/isMap.ts +11 -0
  92. package/src/is/isMedia.ts +20 -0
  93. package/src/is/isNode.ts +17 -0
  94. package/src/is/isNodeList.ts +13 -0
  95. package/src/is/isNumber.ts +9 -0
  96. package/src/is/isObject.ts +10 -0
  97. package/src/is/isRTL.ts +11 -0
  98. package/src/is/isSVGElement.ts +13 -0
  99. package/src/is/{isScaledElement.js → isScaledElement.ts} +9 -7
  100. package/src/is/isShadowRoot.ts +12 -0
  101. package/src/is/isString.ts +9 -0
  102. package/src/is/isTableElement.ts +14 -0
  103. package/src/is/isWeakMap.ts +11 -0
  104. package/src/is/isWindow.ts +13 -0
  105. package/src/misc/ArrayFrom.ts +11 -0
  106. package/src/misc/Float32ArrayFrom.ts +10 -0
  107. package/src/misc/Float64ArrayFrom.ts +10 -0
  108. package/src/misc/ObjectAssign.ts +43 -0
  109. package/src/misc/ObjectEntries.ts +11 -0
  110. package/src/misc/ObjectHasOwn.ts +17 -0
  111. package/src/misc/ObjectKeys.ts +10 -0
  112. package/src/misc/ObjectValues.ts +11 -0
  113. package/src/misc/createCustomEvent.ts +28 -0
  114. package/src/misc/createElement.ts +40 -0
  115. package/src/misc/createElementNS.ts +45 -0
  116. package/src/misc/data.ts +82 -0
  117. package/src/misc/dispatchEvent.ts +9 -0
  118. package/src/misc/distinct.ts +18 -0
  119. package/src/misc/{emulateAnimationEnd.js → emulateAnimationEnd.ts} +8 -9
  120. package/src/misc/{emulateTransitionEnd.js → emulateTransitionEnd.ts} +8 -9
  121. package/src/misc/focus.ts +9 -0
  122. package/src/misc/getInstance.ts +9 -0
  123. package/src/misc/{noop.js → noop.ts} +4 -1
  124. package/src/misc/normalizeOptions.ts +55 -0
  125. package/src/misc/normalizeValue.ts +30 -0
  126. package/src/misc/{passiveHandler.js → passiveHandler.ts} +1 -2
  127. package/src/misc/reflow.ts +9 -0
  128. package/src/misc/setElementStyle.ts +23 -0
  129. package/src/misc/timer.ts +84 -0
  130. package/src/misc/toLowerCase.ts +9 -0
  131. package/src/misc/toUpperCase.ts +9 -0
  132. package/src/selectors/closest.ts +20 -0
  133. package/src/selectors/{getCustomElements.js → getCustomElements.ts} +8 -4
  134. package/src/selectors/getElementById.ts +16 -0
  135. package/src/selectors/getElementsByClassName.ts +22 -0
  136. package/src/selectors/getElementsByTagName.ts +20 -0
  137. package/src/selectors/matches.ts +10 -0
  138. package/src/selectors/querySelector.ts +22 -0
  139. package/src/selectors/{querySelectorAll.js → querySelectorAll.ts} +7 -5
  140. package/src/strings/{DOMContentLoadedEvent.js → DOMContentLoadedEvent.ts} +0 -1
  141. package/src/strings/{DOMMouseScrollEvent.js → DOMMouseScrollEvent.ts} +0 -1
  142. package/src/strings/{abortEvent.js → abortEvent.ts} +0 -1
  143. package/src/strings/{addEventListener.js → addEventListener.ts} +0 -1
  144. package/src/strings/{animationDelay.js → animationDelay.ts} +0 -1
  145. package/src/strings/{animationDuration.js → animationDuration.ts} +0 -1
  146. package/src/strings/{animationEndEvent.js → animationEndEvent.ts} +0 -1
  147. package/src/strings/{animationName.js → animationName.ts} +0 -1
  148. package/src/strings/{ariaChecked.js → ariaChecked.ts} +0 -1
  149. package/src/strings/{ariaDescribedBy.js → ariaDescribedBy.ts} +0 -1
  150. package/src/strings/{ariaDescription.js → ariaDescription.ts} +0 -1
  151. package/src/strings/{ariaExpanded.js → ariaExpanded.ts} +0 -1
  152. package/src/strings/{ariaHasPopup.js → ariaHasPopup.ts} +0 -1
  153. package/src/strings/{ariaHidden.js → ariaHidden.ts} +0 -1
  154. package/src/strings/{ariaLabel.js → ariaLabel.ts} +0 -1
  155. package/src/strings/{ariaLabelledBy.js → ariaLabelledBy.ts} +0 -1
  156. package/src/strings/{ariaModal.js → ariaModal.ts} +0 -1
  157. package/src/strings/{ariaPressed.js → ariaPressed.ts} +0 -1
  158. package/src/strings/{ariaSelected.js → ariaSelected.ts} +0 -1
  159. package/src/strings/{ariaValueMax.js → ariaValueMax.ts} +0 -1
  160. package/src/strings/{ariaValueMin.js → ariaValueMin.ts} +0 -1
  161. package/src/strings/{ariaValueNow.js → ariaValueNow.ts} +0 -1
  162. package/src/strings/{ariaValueText.js → ariaValueText.ts} +0 -1
  163. package/src/strings/{beforeunloadEvent.js → beforeunloadEvent.ts} +0 -1
  164. package/src/strings/{bezierEasings.js → bezierEasings.ts} +0 -1
  165. package/src/strings/{blurEvent.js → blurEvent.ts} +0 -1
  166. package/src/strings/{changeEvent.js → changeEvent.ts} +0 -1
  167. package/src/strings/{contextmenuEvent.js → contextmenuEvent.ts} +0 -1
  168. package/src/strings/dragEvent.ts +5 -0
  169. package/src/strings/dragendEvent.ts +5 -0
  170. package/src/strings/dragenterEvent.ts +5 -0
  171. package/src/strings/dragleaveEvent.ts +5 -0
  172. package/src/strings/dragoverEvent.ts +5 -0
  173. package/src/strings/dragstartEvent.ts +5 -0
  174. package/src/strings/{errorEvent.js → errorEvent.ts} +0 -1
  175. package/src/strings/{focusEvent.js → focusEvent.ts} +0 -1
  176. package/src/strings/{focusEvents.js → focusEvents.ts} +0 -1
  177. package/src/strings/{focusinEvent.js → focusinEvent.ts} +0 -1
  178. package/src/strings/{focusoutEvent.js → focusoutEvent.ts} +0 -1
  179. package/src/strings/{gesturechangeEvent.js → gesturechangeEvent.ts} +0 -1
  180. package/src/strings/{gestureendEvent.js → gestureendEvent.ts} +0 -1
  181. package/src/strings/{gesturestartEvent.js → gesturestartEvent.ts} +0 -1
  182. package/src/strings/{keyAlt.js → keyAlt.ts} +1 -1
  183. package/src/strings/{keyArrowDown.js → keyArrowDown.ts} +1 -1
  184. package/src/strings/{keyArrowLeft.js → keyArrowLeft.ts} +1 -1
  185. package/src/strings/{keyArrowRight.js → keyArrowRight.ts} +1 -1
  186. package/src/strings/{keyArrowUp.js → keyArrowUp.ts} +1 -1
  187. package/src/strings/{keyBackspace.js → keyBackspace.ts} +1 -1
  188. package/src/strings/{keyCapsLock.js → keyCapsLock.ts} +1 -1
  189. package/src/strings/{keyControl.js → keyControl.ts} +1 -1
  190. package/src/strings/{keyDelete.js → keyDelete.ts} +1 -1
  191. package/src/strings/{keyEnter.js → keyEnter.ts} +1 -1
  192. package/src/strings/{keyEscape.js → keyEscape.ts} +1 -1
  193. package/src/strings/{keyInsert.js → keyInsert.ts} +1 -1
  194. package/src/strings/{keyMeta.js → keyMeta.ts} +1 -1
  195. package/src/strings/{keyPause.js → keyPause.ts} +1 -1
  196. package/src/strings/{keyScrollLock.js → keyScrollLock.ts} +1 -1
  197. package/src/strings/{keyShift.js → keyShift.ts} +1 -1
  198. package/src/strings/{keySpace.js → keySpace.ts} +1 -1
  199. package/src/strings/{keyTab.js → keyTab.ts} +1 -1
  200. package/src/strings/{keyboardEventKeys.js → keyboardEventKeys.ts} +0 -1
  201. package/src/strings/{keydownEvent.js → keydownEvent.ts} +0 -1
  202. package/src/strings/{keypressEvent.js → keypressEvent.ts} +0 -1
  203. package/src/strings/{keyupEvent.js → keyupEvent.ts} +0 -1
  204. package/src/strings/{loadEvent.js → loadEvent.ts} +0 -1
  205. package/src/strings/{loadstartEvent.js → loadstartEvent.ts} +0 -1
  206. package/src/strings/{mouseClickEvents.js → mouseClickEvents.ts} +0 -1
  207. package/src/strings/mouseHoverEvents.ts +8 -0
  208. package/src/strings/{mouseSwipeEvents.js → mouseSwipeEvents.ts} +4 -2
  209. package/src/strings/{mouseclickEvent.js → mouseclickEvent.ts} +0 -1
  210. package/src/strings/{mousedblclickEvent.js → mousedblclickEvent.ts} +0 -1
  211. package/src/strings/{mousedownEvent.js → mousedownEvent.ts} +0 -1
  212. package/src/strings/{mouseenterEvent.js → mouseenterEvent.ts} +0 -1
  213. package/src/strings/{mousehoverEvent.js → mousehoverEvent.ts} +0 -1
  214. package/src/strings/{mouseinEvent.js → mouseinEvent.ts} +0 -1
  215. package/src/strings/{mouseleaveEvent.js → mouseleaveEvent.ts} +0 -1
  216. package/src/strings/{mousemoveEvent.js → mousemoveEvent.ts} +0 -1
  217. package/src/strings/{mouseoutEvent.js → mouseoutEvent.ts} +0 -1
  218. package/src/strings/{mouseoverEvent.js → mouseoverEvent.ts} +0 -1
  219. package/src/strings/{mouseupEvent.js → mouseupEvent.ts} +0 -1
  220. package/src/strings/{mousewheelEvent.js → mousewheelEvent.ts} +0 -1
  221. package/src/strings/{moveEvent.js → moveEvent.ts} +0 -1
  222. package/src/strings/{nativeEvents.js → nativeEvents.ts} +0 -0
  223. package/src/strings/{offsetHeight.js → offsetHeight.ts} +0 -1
  224. package/src/strings/{offsetWidth.js → offsetWidth.ts} +0 -1
  225. package/src/strings/{orientationchangeEvent.js → orientationchangeEvent.ts} +0 -1
  226. package/src/strings/{pointercancelEvent.js → pointercancelEvent.ts} +0 -1
  227. package/src/strings/{pointerdownEvent.js → pointerdownEvent.ts} +0 -1
  228. package/src/strings/{pointerleaveEvent.js → pointerleaveEvent.ts} +0 -1
  229. package/src/strings/{pointermoveEvent.js → pointermoveEvent.ts} +0 -1
  230. package/src/strings/{pointerupEvent.js → pointerupEvent.ts} +0 -1
  231. package/src/strings/{readystatechangeEvent.js → readystatechangeEvent.ts} +0 -1
  232. package/src/strings/{removeEventListener.js → removeEventListener.ts} +0 -1
  233. package/src/strings/{resetEvent.js → resetEvent.ts} +0 -1
  234. package/src/strings/{resizeEvent.js → resizeEvent.ts} +0 -1
  235. package/src/strings/{scrollEvent.js → scrollEvent.ts} +0 -1
  236. package/src/strings/{scrollHeight.js → scrollHeight.ts} +0 -1
  237. package/src/strings/{scrollWidth.js → scrollWidth.ts} +0 -1
  238. package/src/strings/{selectEvent.js → selectEvent.ts} +0 -1
  239. package/src/strings/{selectendEvent.js → selectendEvent.ts} +0 -1
  240. package/src/strings/{selectstartEvent.js → selectstartEvent.ts} +0 -1
  241. package/src/strings/{submitEvent.js → submitEvent.ts} +0 -1
  242. package/src/strings/tabindex.ts +5 -0
  243. package/src/strings/touchEvents.ts +10 -0
  244. package/src/strings/{touchcancelEvent.js → touchcancelEvent.ts} +0 -1
  245. package/src/strings/{touchendEvent.js → touchendEvent.ts} +0 -1
  246. package/src/strings/{touchmoveEvent.js → touchmoveEvent.ts} +0 -1
  247. package/src/strings/{touchstartEvent.js → touchstartEvent.ts} +0 -1
  248. package/src/strings/{transitionDelay.js → transitionDelay.ts} +0 -1
  249. package/src/strings/{transitionDuration.js → transitionDuration.ts} +0 -1
  250. package/src/strings/{transitionEndEvent.js → transitionEndEvent.ts} +0 -1
  251. package/src/strings/{transitionProperty.js → transitionProperty.ts} +0 -2
  252. package/src/strings/{unloadEvent.js → unloadEvent.ts} +0 -1
  253. package/src/strings/{userAgent.js → userAgent.ts} +0 -0
  254. package/src/strings/userAgentData.ts +9 -0
  255. package/tsconfig.json +30 -0
  256. package/vite.config.ts +30 -0
  257. package/dist/shorty.esm.js +0 -2599
  258. package/dist/shorty.esm.min.js +0 -2
  259. package/dist/shorty.min.js +0 -2
  260. package/src/attr/getAttribute.js +0 -9
  261. package/src/attr/getAttributeNS.js +0 -10
  262. package/src/attr/hasAttribute.js +0 -9
  263. package/src/attr/hasAttributeNS.js +0 -10
  264. package/src/attr/removeAttribute.js +0 -9
  265. package/src/attr/removeAttributeNS.js +0 -10
  266. package/src/attr/setAttribute.js +0 -10
  267. package/src/attr/setAttributeNS.js +0 -11
  268. package/src/boolean/isApple.js +0 -13
  269. package/src/boolean/support3DTransform.js +0 -9
  270. package/src/boolean/supportAnimation.js +0 -9
  271. package/src/boolean/supportTouch.js +0 -7
  272. package/src/boolean/supportTransform.js +0 -9
  273. package/src/boolean/supportTransition.js +0 -9
  274. package/src/class/addClass.js +0 -10
  275. package/src/class/hasClass.js +0 -10
  276. package/src/class/removeClass.js +0 -10
  277. package/src/event/off.js +0 -9
  278. package/src/event/on.js +0 -9
  279. package/src/event/one.js +0 -23
  280. package/src/get/getDocumentBody.js +0 -10
  281. package/src/get/getDocumentElement.js +0 -11
  282. package/src/get/getDocumentHead.js +0 -10
  283. package/src/get/getElementAnimationDelayLegacy.js +0 -21
  284. package/src/get/getElementAnimationDurationLegacy.js +0 -21
  285. package/src/get/getElementStyle.js +0 -20
  286. package/src/get/getElementTransitionDelayLegacy.js +0 -21
  287. package/src/get/getElementTransitionDurationLegacy.js +0 -21
  288. package/src/get/getUID.js +0 -34
  289. package/src/is/isArray.js +0 -8
  290. package/src/is/isCustomElement.js +0 -8
  291. package/src/is/isDocument.js +0 -10
  292. package/src/is/isElementsArray.js +0 -12
  293. package/src/is/isFunction.js +0 -8
  294. package/src/is/isHTMLCollection.js +0 -8
  295. package/src/is/isHTMLElement.js +0 -9
  296. package/src/is/isHTMLImageElement.js +0 -8
  297. package/src/is/isMedia.js +0 -14
  298. package/src/is/isNode.js +0 -9
  299. package/src/is/isNodeList.js +0 -9
  300. package/src/is/isNumber.js +0 -8
  301. package/src/is/isObject.js +0 -8
  302. package/src/is/isRTL.js +0 -9
  303. package/src/is/isSVGElement.js +0 -11
  304. package/src/is/isShadowRoot.js +0 -9
  305. package/src/is/isString.js +0 -8
  306. package/src/is/isTableElement.js +0 -11
  307. package/src/is/isWindow.js +0 -9
  308. package/src/misc/ArrayFrom.js +0 -8
  309. package/src/misc/Float32ArrayFrom.js +0 -7
  310. package/src/misc/Float64ArrayFrom.js +0 -7
  311. package/src/misc/ObjectAssign.js +0 -7
  312. package/src/misc/ObjectEntries.js +0 -7
  313. package/src/misc/ObjectKeys.js +0 -7
  314. package/src/misc/ObjectValues.js +0 -7
  315. package/src/misc/OriginalEvent.js +0 -20
  316. package/src/misc/createElement.js +0 -27
  317. package/src/misc/createElementNS.js +0 -30
  318. package/src/misc/data.js +0 -78
  319. package/src/misc/dispatchEvent.js +0 -8
  320. package/src/misc/distinct.js +0 -10
  321. package/src/misc/emulateAnimationEndLegacy.js +0 -41
  322. package/src/misc/emulateTransitionEndLegacy.js +0 -41
  323. package/src/misc/focus.js +0 -7
  324. package/src/misc/normalizeOptions.js +0 -49
  325. package/src/misc/normalizeValue.js +0 -34
  326. package/src/misc/passiveHandlerLegacy.js +0 -10
  327. package/src/misc/reflow.js +0 -8
  328. package/src/misc/setElementStyle.js +0 -19
  329. package/src/misc/timer.js +0 -75
  330. package/src/misc/toLowerCase.js +0 -8
  331. package/src/misc/toUpperCase.js +0 -8
  332. package/src/misc/version.js +0 -8
  333. package/src/selectors/closest.js +0 -16
  334. package/src/selectors/getElementById.js +0 -14
  335. package/src/selectors/getElementsByClassName.js +0 -15
  336. package/src/selectors/getElementsByTagName.js +0 -15
  337. package/src/selectors/matches.js +0 -10
  338. package/src/selectors/matchesLegacy.js +0 -23
  339. package/src/selectors/querySelector.js +0 -19
  340. package/src/strings/animationDelayLegacy.js +0 -9
  341. package/src/strings/animationDurationLegacy.js +0 -9
  342. package/src/strings/animationEndEventLegacy.js +0 -9
  343. package/src/strings/animationNameLegacy.js +0 -9
  344. package/src/strings/mouseHoverEvents.js +0 -7
  345. package/src/strings/touchEvents.js +0 -8
  346. package/src/strings/transitionDelayLegacy.js +0 -9
  347. package/src/strings/transitionDurationLegacy.js +0 -9
  348. package/src/strings/transitionEndEventLegacy.js +0 -9
  349. package/src/strings/transitionPropertyLegacy.js +0 -12
  350. package/src/strings/userAgentData.js +0 -7
  351. package/types/index.d.ts +0 -257
  352. package/types/module/shorty.ts +0 -248
  353. package/types/shorty.d.ts +0 -2316
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A global `boolean` for touch events support.
3
+ */
4
+ const supportTouch =
5
+ 'ontouchstart' in window || /* istanbul ignore next */ 'msMaxTouchPoints' in navigator;
6
+
7
+ export default supportTouch;
@@ -0,0 +1,8 @@
1
+ import documentHead from '../blocks/documentHead';
2
+
3
+ /**
4
+ * A global `boolean` for CSS3 transform support.
5
+ */
6
+ const supportTransform = ['webkitTransform', 'transform'].some(p => p in documentHead.style);
7
+
8
+ export default supportTransform;
@@ -0,0 +1,8 @@
1
+ import documentHead from '../blocks/documentHead';
2
+
3
+ /**
4
+ * A global `boolean` for CSS3 transition support.
5
+ */
6
+ const supportTransition = ['webkitTransition', 'transition'].some(p => p in documentHead.style);
7
+
8
+ export default supportTransition;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Add one or more CSS classes to `HTMLElement.classList`.
3
+ *
4
+ * @param element target
5
+ * @param classNAME to add
6
+ */
7
+ const addClass = (element: HTMLElement, ...classNAME: string[]): void => {
8
+ element.classList.add(...classNAME);
9
+ };
10
+
11
+ export default addClass;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Check class in `HTMLElement.classList`.
3
+ *
4
+ * @param element target
5
+ * @param classNAME to check
6
+ */
7
+ const hasClass = (element: HTMLElement, classNAME: string): boolean => {
8
+ return element.classList.contains(classNAME);
9
+ };
10
+
11
+ export default hasClass;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Remove one or more classes from `HTMLElement.classList`.
3
+ *
4
+ * @param element target
5
+ * @param classNAME to remove
6
+ */
7
+ const removeClass = (element: HTMLElement, ...classNAME: string[]): void => {
8
+ element.classList.remove(...classNAME);
9
+ };
10
+
11
+ export default removeClass;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Remove eventListener from an `EventTarget` object.
3
+ */
4
+ const off = (
5
+ element: EventTarget,
6
+ eventName: string,
7
+ listener: EventListener,
8
+ options?: AddEventListenerOptions,
9
+ ) => {
10
+ const ops = options || false;
11
+ element.removeEventListener(eventName, listener, ops);
12
+ };
13
+
14
+ export default off;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Add eventListener to an `EventTarget` object.
3
+ */
4
+ const on = (
5
+ element: EventTarget,
6
+ eventName: string,
7
+ listener: EventListener,
8
+ options?: AddEventListenerOptions,
9
+ ) => {
10
+ const ops = options || false;
11
+ element.addEventListener(eventName, listener, ops);
12
+ };
13
+
14
+ export default on;
@@ -0,0 +1,25 @@
1
+ import on from './on';
2
+ import off from './off';
3
+
4
+ /**
5
+ * Add an `eventListener` to an `EventTarget`
6
+ * element and remove it once callback is called.
7
+ */
8
+ const one = (
9
+ element: EventTarget,
10
+ eventName: string,
11
+ listener: EventListener,
12
+ options?: AddEventListenerOptions,
13
+ ) => {
14
+ /** Wrap the listener for easy on -> off */
15
+ const handlerWrapper = (e: Event): void => {
16
+ /* istanbul ignore else */
17
+ if (e.target === element || e.currentTarget === element) {
18
+ listener.apply(element, [e]);
19
+ off(element, eventName, handlerWrapper, options);
20
+ }
21
+ };
22
+ on(element, eventName, handlerWrapper, options);
23
+ };
24
+
25
+ export default one;
@@ -1,27 +1,27 @@
1
1
  import isHTMLElement from '../is/isHTMLElement';
2
+ import type { BoundingClientRect } from '../interface/boundingClientRect';
2
3
 
3
4
  /**
4
5
  * Returns the bounding client rect of a target `HTMLElement`.
5
6
  *
6
7
  * @see https://github.com/floating-ui/floating-ui
7
8
  *
8
- * @param {HTMLElement} element event.target
9
- * @param {boolean=} includeScale when *true*, the target scale is also computed
10
- * @returns {SHORTY.BoundingClientRect} the bounding client rect object
9
+ * @param element event.target
10
+ * @param includeScale when *true*, the target scale is also computed
11
+ * @returns the bounding client rect object
11
12
  */
12
- export default function getBoundingClientRect(element, includeScale) {
13
- const {
14
- width, height, top, right, bottom, left,
15
- } = element.getBoundingClientRect();
13
+ const getBoundingClientRect = (
14
+ element: HTMLElement,
15
+ includeScale?: boolean,
16
+ ): BoundingClientRect => {
17
+ const { width, height, top, right, bottom, left } = element.getBoundingClientRect();
16
18
  let scaleX = 1;
17
19
  let scaleY = 1;
18
20
 
19
21
  if (includeScale && isHTMLElement(element)) {
20
22
  const { offsetWidth, offsetHeight } = element;
21
- scaleX = offsetWidth > 0 ? Math.round(width) / offsetWidth
22
- : /* istanbul ignore next */1;
23
- scaleY = offsetHeight > 0 ? Math.round(height) / offsetHeight
24
- : /* istanbul ignore next */1;
23
+ scaleX = offsetWidth > 0 ? Math.round(width) / offsetWidth : /* istanbul ignore next */ 1;
24
+ scaleY = offsetHeight > 0 ? Math.round(height) / offsetHeight : /* istanbul ignore next */ 1;
25
25
  }
26
26
 
27
27
  return {
@@ -34,4 +34,6 @@ export default function getBoundingClientRect(element, includeScale) {
34
34
  x: left / scaleX,
35
35
  y: top / scaleY,
36
36
  };
37
- }
37
+ };
38
+
39
+ export default getBoundingClientRect;
@@ -4,17 +4,21 @@ import isDocument from '../is/isDocument';
4
4
 
5
5
  /**
6
6
  * Returns the `document` or the `#document` element.
7
+ *
7
8
  * @see https://github.com/floating-ui/floating-ui
8
- * @param {(Node | Window)=} node
9
- * @returns {Document}
9
+ *
10
+ * @param node the reference node
11
+ * @returns the parent document of the given node
10
12
  */
11
- export default function getDocument(node) {
13
+ const getDocument = (node?: Node | Document | Window): Document => {
14
+ // node instanceof Window
15
+ if (isWindow(node)) return node.document;
12
16
  // node instanceof Document
13
17
  if (isDocument(node)) return node;
14
18
  // node instanceof Node
15
- if (isNode(node)) return node.ownerDocument;
16
- // node instanceof Window
17
- if (isWindow(node)) return node.document;
19
+ if (isNode(node)) return node.ownerDocument as Document;
18
20
  // node is undefined | NULL
19
21
  return window.document;
20
- }
22
+ };
23
+
24
+ export default getDocument;
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,12 @@
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 = (node?: Node | Document | Window): HTMLElement & HTMLHeadElement => {
9
+ return getDocument(node).head;
10
+ };
11
+
12
+ export default getDocumentHead;
@@ -6,16 +6,17 @@ import getElementStyle from './getElementStyle';
6
6
  * Utility to get the computed `animationDelay`
7
7
  * from Element in miliseconds.
8
8
  *
9
- * @param {HTMLElement} element target
10
- * @return {number} the value in miliseconds
9
+ * @param element target
10
+ * @return the `animationDelay` value in miliseconds
11
11
  */
12
- export default function getElementAnimationDelay(element) {
12
+ const getElementAnimationDelay = (element: HTMLElement): number => {
13
13
  const propertyValue = getElementStyle(element, animationName);
14
14
  const durationValue = getElementStyle(element, animationDelay);
15
- const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */1 : 1000;
16
- const duration = propertyValue && propertyValue !== 'none'
17
- ? parseFloat(durationValue) * durationScale : 0;
15
+ const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
+ const duration =
17
+ propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
18
18
 
19
- /* istanbul ignore next */
20
- return !Number.isNaN(duration) ? duration : 0;
21
- }
19
+ return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
20
+ };
21
+
22
+ export default getElementAnimationDelay;
@@ -6,15 +6,17 @@ import getElementStyle from './getElementStyle';
6
6
  * Utility to get the computed `animationDuration`
7
7
  * from `HTMLElement` in miliseconds.
8
8
  *
9
- * @param {HTMLElement} element target
10
- * @return {number} the value in miliseconds
9
+ * @param element target
10
+ * @return the `animationDuration` value in miliseconds
11
11
  */
12
- export default function getElementAnimationDuration(element) {
12
+ const getElementAnimationDuration = (element: HTMLElement): number => {
13
13
  const propertyValue = getElementStyle(element, animationName);
14
14
  const durationValue = getElementStyle(element, animationDuration);
15
- const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */1 : 1000;
16
- const duration = propertyValue && propertyValue !== 'none'
17
- ? parseFloat(durationValue) * durationScale : 0;
15
+ const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
+ const duration =
17
+ propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
18
18
 
19
- return !Number.isNaN(duration) ? duration : /* istanbul ignore next */0;
20
- }
19
+ return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
20
+ };
21
+
22
+ export default getElementAnimationDuration;
@@ -0,0 +1,25 @@
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;
@@ -6,15 +6,19 @@ import getElementStyle from './getElementStyle';
6
6
  * Utility to get the computed `transitionDelay`
7
7
  * from Element in miliseconds.
8
8
  *
9
- * @param {HTMLElement} element target
10
- * @return {number} the value in miliseconds
9
+ * @param element target
10
+ * @return the `transitionDelay` value in miliseconds
11
11
  */
12
- export default function getElementTransitionDelay(element) {
12
+ const getElementTransitionDelay = (element: HTMLElement): number => {
13
13
  const propertyValue = getElementStyle(element, transitionProperty);
14
14
  const delayValue = getElementStyle(element, transitionDelay);
15
- const delayScale = delayValue.includes('ms') ? /* istanbul ignore next */1 : 1000;
16
- const duration = propertyValue && propertyValue !== 'none'
17
- ? parseFloat(delayValue) * delayScale : 0;
15
+ const delayScale = delayValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
+ const duration =
17
+ propertyValue && propertyValue !== 'none'
18
+ ? parseFloat(delayValue) * delayScale
19
+ : /* istanbul ignore next */ 0;
18
20
 
19
- return !Number.isNaN(duration) ? duration : /* istanbul ignore next */0;
20
- }
21
+ return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
22
+ };
23
+
24
+ export default getElementTransitionDelay;
@@ -6,15 +6,19 @@ import getElementStyle from './getElementStyle';
6
6
  * Utility to get the computed `transitionDuration`
7
7
  * from Element in miliseconds.
8
8
  *
9
- * @param {HTMLElement} element target
10
- * @return {number} the value in miliseconds
9
+ * @param element target
10
+ * @return the `transitionDuration` value in miliseconds
11
11
  */
12
- export default function getElementTransitionDuration(element) {
12
+ const getElementTransitionDuration = (element: HTMLElement): number => {
13
13
  const propertyValue = getElementStyle(element, transitionProperty);
14
14
  const durationValue = getElementStyle(element, transitionDuration);
15
- const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */1 : 1000;
16
- const duration = propertyValue && propertyValue !== 'none'
17
- ? parseFloat(durationValue) * durationScale : 0;
15
+ const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
+ const duration =
17
+ propertyValue && propertyValue !== 'none'
18
+ ? parseFloat(durationValue) * durationScale
19
+ : /* istanbul ignore next */ 0;
18
20
 
19
- return !Number.isNaN(duration) ? duration : /* istanbul ignore next */0;
20
- }
21
+ return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
22
+ };
23
+
24
+ export default getElementTransitionDuration;
@@ -1,16 +1,20 @@
1
+ import isWindow from '../is/isWindow';
2
+
1
3
  /**
2
4
  * Returns an `{x,y}` object with the target
3
5
  * `HTMLElement` / `Node` scroll position.
4
6
  *
5
7
  * @see https://github.com/floating-ui/floating-ui
6
8
  *
7
- * @param {HTMLElement | Window} element target node / element
8
- * @returns {{x: number, y: number}} the scroll tuple
9
+ * @param element target node / element
10
+ * @returns the scroll tuple
9
11
  */
10
- export default function getNodeScroll(element) {
11
- const isWin = 'scrollX' in element;
12
+ const getNodeScroll = (element: HTMLElement | Window): { x: number; y: number } => {
13
+ const isWin = isWindow(element);
12
14
  const x = isWin ? element.scrollX : element.scrollLeft;
13
15
  const y = isWin ? element.scrollY : element.scrollTop;
14
16
 
15
17
  return { x, y };
16
- }
18
+ };
19
+
20
+ export default getNodeScroll;
@@ -1,23 +1,28 @@
1
1
  import getDocumentElement from './getDocumentElement';
2
2
  import isShadowRoot from '../is/isShadowRoot';
3
+ import isHTMLElement from '../is/isHTMLElement';
4
+ import isNode from '../is/isNode';
3
5
 
4
6
  /**
5
7
  * Returns the `parentNode` also going through `ShadowRoot`.
8
+ *
6
9
  * @see https://github.com/floating-ui/floating-ui
7
10
  *
8
11
  * @param {Node} node the target node
9
12
  * @returns {Node} the apropriate parent node
10
13
  */
11
- export default function getParentNode(node) {
14
+ const getParentNode = (node: Node): Node | ParentNode => {
12
15
  if (node.nodeName === 'HTML') {
13
16
  return node;
14
17
  }
15
18
 
16
19
  // this is a quicker (but less type safe) way to save quite some bytes from the bundle
17
20
  return (
18
- node.assignedSlot // step into the shadow DOM of the parent of a slotted node
19
- || node.parentNode // DOM Element detected
20
- || (isShadowRoot(node) && node.host) // ShadowRoot detected
21
- || getDocumentElement(node) // fallback
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>
22
25
  );
23
- }
26
+ };
27
+
28
+ export default getParentNode;
@@ -1,17 +1,23 @@
1
+ import type { OffsetRect } from '../interface/offsetRect';
1
2
  import isScaledElement from '../is/isScaledElement';
2
3
  import isHTMLElement from '../is/isHTMLElement';
3
4
  import getBoundingClientRect from './getBoundingClientRect';
4
5
 
5
6
  /**
6
- * Returns the rect relative to an offset parent.
7
+ * Returns the rect relative to a given offset parent and its scroll position.
8
+ *
7
9
  * @see https://github.com/floating-ui/floating-ui
8
10
  *
9
- * @param {HTMLElement} element target
10
- * @param {ParentNode | Window} offsetParent the container / offset parent
11
- * @param {{x: number, y: number}} scroll the offsetParent scroll position
12
- * @returns {SHORTY.OffsetRect}
11
+ * @param element target
12
+ * @param offsetParent the container / offset parent
13
+ * @param scroll the offsetParent scroll position
14
+ * @returns a DOMRect like object
13
15
  */
14
- export default function getRectRelativeToOffsetParent(element, offsetParent, scroll) {
16
+ const getRectRelativeToOffsetParent = (
17
+ element: HTMLElement,
18
+ offsetParent: HTMLElement,
19
+ scroll: { x: number; y: number },
20
+ ): OffsetRect => {
15
21
  const isParentAnElement = isHTMLElement(offsetParent);
16
22
  const rect = getBoundingClientRect(element, isParentAnElement && isScaledElement(offsetParent));
17
23
  const offsets = { x: 0, y: 0 };
@@ -29,4 +35,6 @@ export default function getRectRelativeToOffsetParent(element, offsetParent, scr
29
35
  width: rect.width,
30
36
  height: rect.height,
31
37
  };
32
- }
38
+ };
39
+
40
+ export default getRectRelativeToOffsetParent;
@@ -0,0 +1,42 @@
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;
@@ -3,18 +3,21 @@ import isNode from '../is/isNode';
3
3
 
4
4
  /**
5
5
  * Returns the `Window` object of a target node.
6
+ *
6
7
  * @see https://github.com/floating-ui/floating-ui
7
8
  *
8
- * @param {(Node | Window)=} node target node
9
- * @returns {Window} the `Window` object
9
+ * @param node target node
10
+ * @returns the `Window` object
10
11
  */
11
- export default function getWindow(node) {
12
+ const getWindow = (node?: Node): Window => {
12
13
  // node is undefined | NULL
13
14
  if (!node) return window;
14
15
  // node instanceof Document
15
- if (isDocument(node)) return node.defaultView;
16
+ if (isDocument(node)) return node.defaultView as Window;
16
17
  // node instanceof Node
17
- if (isNode(node)) return node.ownerDocument.defaultView;
18
+ if (isNode(node)) return node?.ownerDocument?.defaultView as Window;
18
19
  // node is instanceof Window
19
20
  return node;
20
- }
21
+ };
22
+
23
+ export default getWindow;