@thednp/shorty 1.0.0

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 (234) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +340 -0
  3. package/dist/shorty.esm.js +2540 -0
  4. package/dist/shorty.esm.min.js +2 -0
  5. package/dist/shorty.js +2563 -0
  6. package/dist/shorty.min.js +2 -0
  7. package/package.json +59 -0
  8. package/src/attr/getAttribute.js +9 -0
  9. package/src/attr/getAttributeNS.js +10 -0
  10. package/src/attr/hasAttribute.js +9 -0
  11. package/src/attr/hasAttributeNS.js +10 -0
  12. package/src/attr/removeAttribute.js +9 -0
  13. package/src/attr/removeAttributeNS.js +10 -0
  14. package/src/attr/setAttribute.js +10 -0
  15. package/src/attr/setAttributeNS.js +11 -0
  16. package/src/blocks/documentBody.js +5 -0
  17. package/src/blocks/documentElement.js +5 -0
  18. package/src/blocks/documentHead.js +5 -0
  19. package/src/boolean/isApple.js +13 -0
  20. package/src/boolean/isFirefox.js +9 -0
  21. package/src/boolean/isMobile.js +20 -0
  22. package/src/boolean/support3DTransform.js +8 -0
  23. package/src/boolean/supportAnimation.js +8 -0
  24. package/src/boolean/supportPassive.js +28 -0
  25. package/src/boolean/supportTouch.js +6 -0
  26. package/src/boolean/supportTransform.js +8 -0
  27. package/src/boolean/supportTransition.js +8 -0
  28. package/src/class/addClass.js +10 -0
  29. package/src/class/hasClass.js +10 -0
  30. package/src/class/removeClass.js +10 -0
  31. package/src/event/off.js +13 -0
  32. package/src/event/on.js +13 -0
  33. package/src/event/one.js +26 -0
  34. package/src/get/getBoundingClientRect.js +33 -0
  35. package/src/get/getDocument.js +11 -0
  36. package/src/get/getDocumentBody.js +10 -0
  37. package/src/get/getDocumentElement.js +11 -0
  38. package/src/get/getDocumentHead.js +10 -0
  39. package/src/get/getElementAnimationDelay.js +21 -0
  40. package/src/get/getElementAnimationDelayLegacy.js +21 -0
  41. package/src/get/getElementAnimationDuration.js +20 -0
  42. package/src/get/getElementAnimationDurationLegacy.js +21 -0
  43. package/src/get/getElementStyle.js +18 -0
  44. package/src/get/getElementTransitionDelay.js +21 -0
  45. package/src/get/getElementTransitionDelayLegacy.js +21 -0
  46. package/src/get/getElementTransitionDuration.js +20 -0
  47. package/src/get/getElementTransitionDurationLegacy.js +21 -0
  48. package/src/get/getNodeScroll.js +16 -0
  49. package/src/get/getParentNode.js +24 -0
  50. package/src/get/getRectRelativeToOffsetParent.js +30 -0
  51. package/src/get/getUID.js +34 -0
  52. package/src/get/getWindow.js +20 -0
  53. package/src/index.js +475 -0
  54. package/src/is/isArray.js +9 -0
  55. package/src/is/isCustomElement.js +8 -0
  56. package/src/is/isDocument.js +9 -0
  57. package/src/is/isElement.js +9 -0
  58. package/src/is/isElementInScrollRange.js +18 -0
  59. package/src/is/isElementInViewport.js +22 -0
  60. package/src/is/isElementsArray.js +10 -0
  61. package/src/is/isFunction.js +9 -0
  62. package/src/is/isHTMLCollection.js +8 -0
  63. package/src/is/isHTMLElement.js +8 -0
  64. package/src/is/isHTMLImageElement.js +8 -0
  65. package/src/is/isMedia.js +12 -0
  66. package/src/is/isNode.js +8 -0
  67. package/src/is/isNodeList.js +8 -0
  68. package/src/is/isRTL.js +9 -0
  69. package/src/is/isSVGElement.js +8 -0
  70. package/src/is/isScaledElement.js +15 -0
  71. package/src/is/isShadowRoot.js +12 -0
  72. package/src/is/isString.js +8 -0
  73. package/src/is/isTableElement.js +7 -0
  74. package/src/is/isWindow.js +9 -0
  75. package/src/misc/ArrayFrom.js +8 -0
  76. package/src/misc/Float32ArrayFrom.js +7 -0
  77. package/src/misc/Float64ArrayFrom.js +7 -0
  78. package/src/misc/ObjectAssign.js +7 -0
  79. package/src/misc/ObjectKeys.js +7 -0
  80. package/src/misc/ObjectValues.js +7 -0
  81. package/src/misc/OriginalEvent.js +18 -0
  82. package/src/misc/createElement.js +25 -0
  83. package/src/misc/createElementNS.js +26 -0
  84. package/src/misc/data.js +78 -0
  85. package/src/misc/dispatchEvent.js +8 -0
  86. package/src/misc/distinct.js +10 -0
  87. package/src/misc/emulateAnimationEnd.js +37 -0
  88. package/src/misc/emulateAnimationEndLegacy.js +38 -0
  89. package/src/misc/emulateTransitionEnd.js +37 -0
  90. package/src/misc/emulateTransitionEndLegacy.js +38 -0
  91. package/src/misc/focus.js +8 -0
  92. package/src/misc/noop.js +3 -0
  93. package/src/misc/normalizeOptions.js +49 -0
  94. package/src/misc/normalizeValue.js +32 -0
  95. package/src/misc/passiveHandler.js +7 -0
  96. package/src/misc/passiveHandlerLegacy.js +9 -0
  97. package/src/misc/reflow.js +9 -0
  98. package/src/misc/setElementStyle.js +10 -0
  99. package/src/misc/timer.js +78 -0
  100. package/src/misc/toLowerCase.js +8 -0
  101. package/src/misc/toUpperCase.js +8 -0
  102. package/src/misc/tryWrapper.js +11 -0
  103. package/src/misc/version.js +9 -0
  104. package/src/selectors/closest.js +16 -0
  105. package/src/selectors/documentAll.js +8 -0
  106. package/src/selectors/elementNodes.js +5 -0
  107. package/src/selectors/getCustomElements.js +18 -0
  108. package/src/selectors/getElementById.js +11 -0
  109. package/src/selectors/getElementsByClassName.js +15 -0
  110. package/src/selectors/getElementsByTagName.js +15 -0
  111. package/src/selectors/matches.js +10 -0
  112. package/src/selectors/matchesLegacy.js +23 -0
  113. package/src/selectors/parentNodes.js +5 -0
  114. package/src/selectors/querySelector.js +15 -0
  115. package/src/selectors/querySelectorAll.js +14 -0
  116. package/src/strings/DOMContentLoadedEvent.js +6 -0
  117. package/src/strings/DOMMouseScrollEvent.js +6 -0
  118. package/src/strings/abortEvent.js +6 -0
  119. package/src/strings/addEventListener.js +6 -0
  120. package/src/strings/animationDelay.js +6 -0
  121. package/src/strings/animationDelayLegacy.js +8 -0
  122. package/src/strings/animationDuration.js +6 -0
  123. package/src/strings/animationDurationLegacy.js +8 -0
  124. package/src/strings/animationEndEvent.js +6 -0
  125. package/src/strings/animationEndEventLegacy.js +8 -0
  126. package/src/strings/animationName.js +6 -0
  127. package/src/strings/animationNameLegacy.js +8 -0
  128. package/src/strings/ariaChecked.js +6 -0
  129. package/src/strings/ariaDescribedBy.js +6 -0
  130. package/src/strings/ariaDescription.js +6 -0
  131. package/src/strings/ariaExpanded.js +6 -0
  132. package/src/strings/ariaHasPopup.js +6 -0
  133. package/src/strings/ariaHidden.js +6 -0
  134. package/src/strings/ariaLabel.js +6 -0
  135. package/src/strings/ariaLabelledBy.js +6 -0
  136. package/src/strings/ariaModal.js +6 -0
  137. package/src/strings/ariaPressed.js +6 -0
  138. package/src/strings/ariaSelected.js +6 -0
  139. package/src/strings/ariaValueMax.js +6 -0
  140. package/src/strings/ariaValueMin.js +6 -0
  141. package/src/strings/ariaValueNow.js +6 -0
  142. package/src/strings/ariaValueText.js +6 -0
  143. package/src/strings/beforeunloadEvent.js +6 -0
  144. package/src/strings/bezierEasings.js +33 -0
  145. package/src/strings/blurEvent.js +6 -0
  146. package/src/strings/changeEvent.js +6 -0
  147. package/src/strings/contextmenuEvent.js +6 -0
  148. package/src/strings/errorEvent.js +6 -0
  149. package/src/strings/focusEvent.js +6 -0
  150. package/src/strings/focusEvents.js +6 -0
  151. package/src/strings/focusinEvent.js +6 -0
  152. package/src/strings/focusoutEvent.js +6 -0
  153. package/src/strings/gesturechangeEvent.js +6 -0
  154. package/src/strings/gestureendEvent.js +6 -0
  155. package/src/strings/gesturestartEvent.js +6 -0
  156. package/src/strings/keyAlt.js +7 -0
  157. package/src/strings/keyArrowDown.js +7 -0
  158. package/src/strings/keyArrowLeft.js +7 -0
  159. package/src/strings/keyArrowRight.js +7 -0
  160. package/src/strings/keyArrowUp.js +7 -0
  161. package/src/strings/keyBackspace.js +7 -0
  162. package/src/strings/keyCapsLock.js +7 -0
  163. package/src/strings/keyControl.js +7 -0
  164. package/src/strings/keyDelete.js +7 -0
  165. package/src/strings/keyEnter.js +7 -0
  166. package/src/strings/keyEscape.js +7 -0
  167. package/src/strings/keyInsert.js +7 -0
  168. package/src/strings/keyMeta.js +7 -0
  169. package/src/strings/keyPause.js +7 -0
  170. package/src/strings/keyScrollLock.js +7 -0
  171. package/src/strings/keyShift.js +7 -0
  172. package/src/strings/keySpace.js +7 -0
  173. package/src/strings/keyTab.js +7 -0
  174. package/src/strings/keyboardEventKeys.js +27 -0
  175. package/src/strings/keydownEvent.js +6 -0
  176. package/src/strings/keypressEvent.js +6 -0
  177. package/src/strings/keyupEvent.js +6 -0
  178. package/src/strings/loadEvent.js +6 -0
  179. package/src/strings/loadstartEvent.js +6 -0
  180. package/src/strings/mouseClickEvents.js +6 -0
  181. package/src/strings/mouseHoverEvents.js +6 -0
  182. package/src/strings/mouseSwipeEvents.js +8 -0
  183. package/src/strings/mouseclickEvent.js +6 -0
  184. package/src/strings/mousedblclickEvent.js +6 -0
  185. package/src/strings/mousedownEvent.js +6 -0
  186. package/src/strings/mouseenterEvent.js +6 -0
  187. package/src/strings/mousehoverEvent.js +6 -0
  188. package/src/strings/mouseinEvent.js +6 -0
  189. package/src/strings/mouseleaveEvent.js +6 -0
  190. package/src/strings/mousemoveEvent.js +6 -0
  191. package/src/strings/mouseoutEvent.js +6 -0
  192. package/src/strings/mouseoverEvent.js +6 -0
  193. package/src/strings/mouseupEvent.js +6 -0
  194. package/src/strings/mousewheelEvent.js +6 -0
  195. package/src/strings/moveEvent.js +6 -0
  196. package/src/strings/nativeEvents.js +108 -0
  197. package/src/strings/offsetHeight.js +6 -0
  198. package/src/strings/offsetWidth.js +6 -0
  199. package/src/strings/orientationchangeEvent.js +6 -0
  200. package/src/strings/pointercancelEvent.js +6 -0
  201. package/src/strings/pointerdownEvent.js +6 -0
  202. package/src/strings/pointerleaveEvent.js +6 -0
  203. package/src/strings/pointermoveEvent.js +6 -0
  204. package/src/strings/pointerupEvent.js +6 -0
  205. package/src/strings/readystatechangeEvent.js +6 -0
  206. package/src/strings/removeEventListener.js +6 -0
  207. package/src/strings/resetEvent.js +6 -0
  208. package/src/strings/resizeEvent.js +6 -0
  209. package/src/strings/scrollEvent.js +6 -0
  210. package/src/strings/scrollHeight.js +6 -0
  211. package/src/strings/scrollWidth.js +6 -0
  212. package/src/strings/selectEvent.js +6 -0
  213. package/src/strings/selectendEvent.js +6 -0
  214. package/src/strings/selectstartEvent.js +6 -0
  215. package/src/strings/submitEvent.js +6 -0
  216. package/src/strings/touchEvents.js +8 -0
  217. package/src/strings/touchcancelEvent.js +6 -0
  218. package/src/strings/touchendEvent.js +6 -0
  219. package/src/strings/touchmoveEvent.js +6 -0
  220. package/src/strings/touchstartEvent.js +6 -0
  221. package/src/strings/transitionDelay.js +6 -0
  222. package/src/strings/transitionDelayLegacy.js +8 -0
  223. package/src/strings/transitionDuration.js +6 -0
  224. package/src/strings/transitionDurationLegacy.js +8 -0
  225. package/src/strings/transitionEndEvent.js +6 -0
  226. package/src/strings/transitionEndEventLegacy.js +8 -0
  227. package/src/strings/transitionProperty.js +7 -0
  228. package/src/strings/transitionPropertyLegacy.js +12 -0
  229. package/src/strings/unloadEvent.js +6 -0
  230. package/src/strings/userAgent.js +7 -0
  231. package/src/strings/userAgentData.js +8 -0
  232. package/types/index.d.ts +252 -0
  233. package/types/module/shorty.ts +249 -0
  234. package/types/shorty.d.ts +2317 -0
@@ -0,0 +1,2 @@
1
+ // Shorty v1.0.0 | dnp_theme © 2022 | MIT-License
2
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SHORTY=t()}(this,(function(){"use strict";var e={DOMContentLoaded:"DOMContentLoaded",DOMMouseScroll:"DOMMouseScroll",abort:"abort",beforeunload:"beforeunload",blur:"blur",change:"change",click:"click",contextmenu:"contextmenu",dblclick:"dblclick",error:"error",focus:"focus",focusin:"focusin",focusout:"focusout",gesturechange:"gesturechange",gestureend:"gestureend",gesturestart:"gesturestart",hover:"hover",keydown:"keydown",keypress:"keypress",keyup:"keyup",load:"load",mousedown:"mousedown",mousemove:"mousemove",mousein:"mousein",mouseout:"mouseout",mouseenter:"mouseenter",mouseleave:"mouseleave",mouseover:"mouseover",mouseup:"mouseup",mousewheel:"mousewheel",move:"move",orientationchange:"orientationchange",pointercancel:"pointercancel",pointerdown:"pointerdown",pointerleave:"pointerleave",pointermove:"pointermove",pointerup:"pointerup",readystatechange:"readystatechange",reset:"reset",resize:"resize",scroll:"scroll",select:"select",selectend:"selectend",selectstart:"selectstart",submit:"submit",touchcancel:"touchcancel",touchend:"touchend",touchmove:"touchmove",touchstart:"touchstart",unload:"unload"},t="onmouseleave"in document?["mouseenter","mouseleave"]:["mouseover","mouseout"],n=document.head,i="webkitAnimation"in n.style?"webkitAnimationDuration":"animationDuration",r="webkitAnimation"in n.style?"webkitAnimationDelay":"animationDelay",o="webkitAnimation"in n.style?"webkitAnimationName":"animationName",a="webkitAnimation"in n.style?"webkitAnimationEnd":"animationend",u="webkitTransition"in n.style?"webkitTransitionDuration":"transitionDuration",s="webkitTransition"in n.style?"webkitTransitionDelay":"transitionDelay",c="webkitTransition"in n.style?"webkitTransitionEnd":"transitionend",l="webkitTransition"in n.style?"webkitTransitionProperty":"transitionProperty",m=navigator.userAgentData,d=navigator.userAgent,f=/iPhone|iPad|iPod|Android/i,v=m?m.brands.some((function(e){return f.test(e.brand)})):f.test(d),g=/(iPhone|iPod|iPad)/,p=m?m.brands.some((function(e){return g.test(e.brand)})):g.test(d),E=!!d&&d.includes("Firefox"),b="webkitPerspective"in n.style||"perspective"in n.style;function y(e,t,n,i){var r=i||!1;e.addEventListener(t,n,r)}function h(e,t,n,i){var r=i||!1;e.removeEventListener(t,n,r)}function w(e,t,n,i){var r=function(o){o.target===e&&(n.apply(e,[o]),h(e,t,r,i))};y(e,t,r,i)}var A=function(){var e=!1;try{var t=Object.defineProperty({},"passive",{get:function(){return e=!0}});w(document,"DOMContentLoaded",(function(){}),t)}catch(e){throw Error("Passive events are not supported")}return e}(),k="webkitTransform"in n.style||"transform"in n.style,L="ontouchstart"in window||"msMaxTouchPoints"in navigator,D="webkitAnimation"in n.style||"animation"in n.style,N="webkitTransition"in n.style||"transition"in n.style,T=function(e,t){return e.getAttribute(t)};function S(e){return e instanceof HTMLElement?e.ownerDocument:e instanceof Window?e.document:window.document}function M(e,t){var n="querySelector",i=t&&t[n]?t:S();return e[n]?e:i[n](e)}var O=new Map,C={set:function(e,t,n){var i=M(e);i&&(O.has(t)||O.set(t,new Map),O.get(t).set(i,n))},getAllFor:function(e){return O.get(e)||null},get:function(e,t){var n=M(e),i=C.getAllFor(t);return n&&i&&i.get(n)||null},remove:function(e,t){var n=M(e),i=O.get(t);i&&n&&(i.delete(n),0===i.size&&O.delete(t))}},z=function(e,t){return Object.assign(e,t)};function H(e,t){var n=getComputedStyle(e);return t in n?n[t]:""}function x(e){var t=H(e,"animationName"),n=H(e,"animationDelay"),i=n.includes("ms")?1:1e3,r=t&&"none"!==t?parseFloat(n)*i:0;return Number.isNaN(r)?0:r}function I(e){var t=H(e,"animationName"),n=H(e,"animationDuration"),i=n.includes("ms")?1:1e3,r=t&&"none"!==t?parseFloat(n)*i:0;return Number.isNaN(r)?0:r}function P(e){var t=H(e,o),n=H(e,r),i=n.includes("ms")?1:1e3,a=D&&t&&"none"!==t?parseFloat(n)*i:0;return Number.isNaN(a)?0:a}function B(e){var t=H(e,o),n=H(e,i),r=n.includes("ms")?1:1e3,a=D&&t&&"none"!==t?parseFloat(n)*r:0;return Number.isNaN(a)?0:a}function F(e){var t=H(e,"transitionProperty"),n=H(e,"transitionDelay"),i=n.includes("ms")?1:1e3,r=t&&"none"!==t?parseFloat(n)*i:0;return Number.isNaN(r)?0:r}function R(e){var t=H(e,"transitionProperty"),n=H(e,"transitionDuration"),i=n.includes("ms")?1:1e3,r=t&&"none"!==t?parseFloat(n)*i:0;return Number.isNaN(r)?0:r}function V(e){var t=H(e,l),n=H(e,s),i=n.includes("ms")?1:1e3,r=N&&t&&"none"!==t?parseFloat(n)*i:0;return Number.isNaN(r)?0:r}function W(e){var t=H(e,l),n=H(e,u),i=n.includes("ms")?1:1e3,r=N&&t&&"none"!==t?parseFloat(n)*i:0;return Number.isNaN(r)?0:r}function j(e){return"true"===e||"false"!==e&&(Number.isNaN(+e)?""===e||"null"===e?null:e:+e)}var Q=function(e){return Object.keys(e)},U=function(e){return e.toLowerCase()};var q=!!A&&{passive:!0},G=new Map,K={set:function(e,t,n,i){var r=M(e);r&&(i&&i.length?(G.has(r)||G.set(r,new Map),G.get(r).set(i,setTimeout(t,n))):G.set(r,setTimeout(t,n)))},get:function(e,t){var n=M(e);if(!n)return null;var i=G.get(n);return t&&t.length&&i&&i.get?i.get(t)||null:i||null},clear:function(e,t){var n=M(e);if(n)if(t&&t.length){var i=G.get(n);i&&i.get&&(clearTimeout(i.get(t)),i.delete(t),0===i.size&&G.delete(n))}else clearTimeout(G.get(n)),G.delete(n)}};function X(e,t){var n=e.getBoundingClientRect(),i=n.width,r=n.height,o=n.top,a=n.right,u=n.bottom,s=n.left,c=1,l=1;if(t&&e instanceof HTMLElement){var m=e.offsetWidth,d=e.offsetHeight;c=m>0&&Math.round(i)/m||1,l=d>0&&Math.round(r)/d||1}return{width:i/c,height:r/l,top:o/l,right:a/c,bottom:u/l,left:s/c,x:s/c,y:o/l}}function Y(e){return S(e).documentElement}function Z(e){if(null==e)return window;if(!(e instanceof Window)){var t=e.ownerDocument;return t&&t.defaultView||window}return e}var J=function(e){return e instanceof Z(e).ShadowRoot||e instanceof ShadowRoot};function $(e){var t=X(e),n=t.width,i=t.height,r=e.offsetWidth,o=e.offsetHeight;return Math.round(n)!==r||Math.round(i)!==o}var _=0,ee=0,te=new Map;var ne=function(e){return e&&!!e.shadowRoot};function ie(e,t){var n="getElementsByTagName";return(t&&t[n]?t:S())[n](e)}var re=ie("*"),oe=[Element,HTMLElement],ae=[Document,Element,HTMLElement];var ue=Element.prototype,se=ue.matches||ue.matchesSelector||ue.webkitMatchesSelector||ue.mozMatchesSelector||ue.msMatchesSelector||ue.oMatchesSelector||function(){return!1};return{ariaChecked:"aria-checked",ariaDescription:"aria-description",ariaDescribedBy:"aria-describedby",ariaExpanded:"aria-expanded",ariaHidden:"aria-hidden",ariaHasPopup:"aria-haspopup",ariaLabel:"aria-label",ariaLabelledBy:"aria-labelledby",ariaModal:"aria-modal",ariaPressed:"aria-pressed",ariaSelected:"aria-selected",ariaValueMin:"aria-valuemin",ariaValueMax:"aria-valuemax",ariaValueNow:"aria-valuenow",ariaValueText:"aria-valuetext",nativeEvents:e,abortEvent:"abort",blurEvent:"blur",moveEvent:"move",changeEvent:"change",errorEvent:"error",resetEvent:"reset",resizeEvent:"resize",scrollEvent:"scroll",submitEvent:"submit",loadEvent:"load",loadstartEvent:"loadstart",unloadEvent:"unload",readystatechangeEvent:"readystatechange",beforeunloadEvent:"beforeunload",orientationchangeEvent:"orientationchange",contextmenuEvent:"contextmenu",DOMContentLoadedEvent:"DOMContentLoaded",DOMMouseScrollEvent:"DOMMouseScroll",selectEvent:"select",selectendEvent:"selectend",selectstartEvent:"selectstart",mouseClickEvents:{down:"mousedown",up:"mouseup"},mouseclickEvent:"click",mousedblclickEvent:"dblclick",mousedownEvent:"mousedown",mouseupEvent:"mouseup",mousehoverEvent:"hover",mouseHoverEvents:t,mouseenterEvent:"mouseenter",mouseleaveEvent:"mouseleave",mouseinEvent:"mousein",mouseoutEvent:"mouseout",mouseoverEvent:"mouseover",mousemoveEvent:"mousemove",mousewheelEvent:"mousewheel",mouseSwipeEvents:{start:"mousedown",end:"mouseup",move:"mousemove",cancel:"mouseleave"},touchEvents:{start:"touchstart",end:"touchend",move:"touchmove",cancel:"touchcancel"},touchstartEvent:"touchstart",touchmoveEvent:"touchmove",touchcancelEvent:"touchcancel",touchendEvent:"touchend",pointercancelEvent:"pointercancel",pointerdownEvent:"pointerdown",pointerleaveEvent:"pointerleave",pointermoveEvent:"pointermove",pointerupEvent:"pointerup",focusEvents:{in:"focusin",out:"focusout"},focusEvent:"focus",focusinEvent:"focusin",focusoutEvent:"focusout",gesturechangeEvent:"gesturechange",gestureendEvent:"gestureend",gesturestartEvent:"gesturestart",bezierEasings:{linear:"linear",easingSinusoidalIn:"cubic-bezier(0.47,0,0.745,0.715)",easingSinusoidalOut:"cubic-bezier(0.39,0.575,0.565,1)",easingSinusoidalInOut:"cubic-bezier(0.445,0.05,0.55,0.95)",easingQuadraticIn:"cubic-bezier(0.550,0.085,0.680,0.530)",easingQuadraticOut:"cubic-bezier(0.250,0.460,0.450,0.940)",easingQuadraticInOut:"cubic-bezier(0.455,0.030,0.515,0.955)",easingCubicIn:"cubic-bezier(0.55,0.055,0.675,0.19)",easingCubicOut:"cubic-bezier(0.215,0.61,0.355,1)",easingCubicInOut:"cubic-bezier(0.645,0.045,0.355,1)",easingQuarticIn:"cubic-bezier(0.895,0.03,0.685,0.22)",easingQuarticOut:"cubic-bezier(0.165,0.84,0.44,1)",easingQuarticInOut:"cubic-bezier(0.77,0,0.175,1)",easingQuinticIn:"cubic-bezier(0.755,0.05,0.855,0.06)",easingQuinticOut:"cubic-bezier(0.23,1,0.32,1)",easingQuinticInOut:"cubic-bezier(0.86,0,0.07,1)",easingExponentialIn:"cubic-bezier(0.95,0.05,0.795,0.035)",easingExponentialOut:"cubic-bezier(0.19,1,0.22,1)",easingExponentialInOut:"cubic-bezier(1,0,0,1)",easingCircularIn:"cubic-bezier(0.6,0.04,0.98,0.335)",easingCircularOut:"cubic-bezier(0.075,0.82,0.165,1)",easingCircularInOut:"cubic-bezier(0.785,0.135,0.15,0.86)",easingBackIn:"cubic-bezier(0.6,-0.28,0.735,0.045)",easingBackOut:"cubic-bezier(0.175,0.885,0.32,1.275)",easingBackInOut:"cubic-bezier(0.68,-0.55,0.265,1.55)"},animationDuration:"animationDuration",animationDurationLegacy:i,animationDelay:"animationDelay",animationDelayLegacy:r,animationName:"animationName",animationNameLegacy:o,animationEndEvent:"animationend",animationEndEventLegacy:a,transitionDuration:"transitionDuration",transitionDurationLegacy:u,transitionDelay:"transitionDelay",transitionDelayLegacy:s,transitionEndEvent:"transitionend",transitionEndEventLegacy:c,transitionProperty:"transitionProperty",transitionPropertyLegacy:l,isMobile:v,isApple:p,isFirefox:E,support3DTransform:b,supportPassive:A,supportTransform:k,supportTouch:L,supportAnimation:D,supportTransition:N,addEventListener:"addEventListener",removeEventListener:"removeEventListener",keyboardEventKeys:{Backspace:"Backspace",Tab:"Tab",Enter:"Enter",Shift:"Shift",Control:"Control",Alt:"Alt",Pause:"Pause",CapsLock:"CapsLock",Escape:"Escape",Scape:"Space",ArrowLeft:"ArrowLeft",ArrowUp:"ArrowUp",ArrowRight:"ArrowRight",ArrowDown:"ArrowDown",Insert:"Insert",Delete:"Delete",Meta:"Meta",ContextMenu:"ContextMenu",ScrollLock:"ScrollLock"},keydownEvent:"keydown",keypressEvent:"keypress",keyupEvent:"keyup",keyAlt:"Alt",keyArrowDown:"ArrowDown",keyArrowLeft:"ArrowLeft",keyArrowRight:"ArrowRight",keyArrowUp:"ArrowUp",keyBackspace:"Backspace",keyCapsLock:"CapsLock",keyControl:"Control",keyDelete:"Delete",keyEnter:"Enter",keyEscape:"Escape",keyInsert:"Insert",keyMeta:"Meta",keyPause:"Pause",keyScrollLock:"ScrollLock",keyShift:"Shift",keySpace:"Space",keyTab:"Tab",offsetHeight:"offsetHeight",offsetWidth:"offsetWidth",scrollHeight:"scrollHeight",scrollWidth:"scrollWidth",userAgentData:m,userAgent:d,addClass:function(e,t){e.classList.add(t)},removeClass:function(e,t){e.classList.remove(t)},hasClass:function(e,t){return e.classList.contains(t)},on:y,off:h,one:w,dispatchEvent:function(e,t){return e.dispatchEvent(t)},distinct:function(e,t,n){return n.indexOf(e)===t},Data:C,getInstance:function(e,t){return C.get(e,t)},createElement:function e(t){if("string"==typeof t)return S().createElement(t);var n=t.tagName,i=Object.assign({},t),r=e(n);return delete i.tagName,z(r,i),r},createElementNS:function e(t,n){if("string"==typeof n)return S().createElementNS(t,n);var i=n.tagName,r=Object.assign({},n),o=e(t,i);return delete r.tagName,z(o,r),o},toUpperCase:function(e){return e.toUpperCase()},toLowerCase:U,Timer:K,emulateAnimationEnd:function(e,t){var n=0,i=new Event("animationend"),r=I(e),o=x(e);if(r){var a=function(i){i.target===e&&(t.apply(e,[i]),e.removeEventListener("animationend",a),n=1)};e.addEventListener("animationend",a),setTimeout((function(){n||e.dispatchEvent(i)}),r+o+17)}else t.apply(e,[i])},emulateAnimationEndLegacy:function(e,t){var n=0,i=new Event(a),r=B(e),o=P(e);if(D&&r){var u=function(i){i.target===e&&(t.apply(e,[i]),e.removeEventListener(a,u),n=1)};e.addEventListener(a,u),setTimeout((function(){n||e.dispatchEvent(i)}),r+o+17)}else t.apply(e,[i])},emulateTransitionEnd:function(e,t){var n=0,i=new Event("transitionend"),r=R(e),o=F(e);if(r){var a=function(i){i.target===e&&(t.apply(e,[i]),e.removeEventListener("transitionend",a),n=1)};e.addEventListener("transitionend",a),setTimeout((function(){n||e.dispatchEvent(i)}),r+o+17)}else t.apply(e,[i])},emulateTransitionEndLegacy:function(e,t){var n=0,i=new Event(c),r=W(e),o=V(e);if(N&&r){var a=function(i){i.target===e&&(t.apply(e,[i]),e.removeEventListener(c,a),n=1)};e.addEventListener(c,a),setTimeout((function(){n||e.dispatchEvent(i)}),r+o+17)}else t.apply(e,[i])},isElementInScrollRange:function(e){var t=X(e),n=t.top,i=t.bottom;return n<=Y(e).clientHeight&&i>=0},isElementInViewport:function(e){var t=X(e,!0),n=t.top,i=t.left,r=t.bottom,o=t.right,a=Y(e),u=a.clientWidth,s=a.clientHeight;return n>=0&&i>=0&&r<=s&&o<=u},passiveHandler:{passive:!0},passiveHandlerLegacy:q,getElementAnimationDuration:I,getElementAnimationDurationLegacy:B,getElementAnimationDelay:x,getElementAnimationDelayLegacy:P,getElementTransitionDuration:R,getElementTransitionDurationLegacy:W,getElementTransitionDelay:F,getElementTransitionDelayLegacy:V,getNodeScroll:function(e){var t="scrollX"in e;return{x:t?e.scrollX:e.scrollLeft,y:t?e.scrollY:e.scrollTop}},getParentNode:function(e){return"HTML"===e.nodeName?e:e.assignedSlot||e.parentNode||(J(e)?e.host:null)||Y(e)},getRectRelativeToOffsetParent:function(e,t,n){var i=t instanceof HTMLElement,r=X(e,i&&$(t)),o={x:0,y:0};if(i){var a=X(t,!0);o.x=a.x+t.clientLeft,o.y=a.y+t.clientTop}return{x:r.left+n.x-o.x,y:r.top+n.y-o.y,width:r.width,height:r.height}},getWindow:Z,isArray:function(e){return Array.isArray(e)},isString:function(e){return"string"==typeof e},isCustomElement:ne,isElement:function(e){return e instanceof Element},isNode:function(e){return e instanceof Node},isHTMLElement:function(e){return e instanceof HTMLElement},isHTMLImageElement:function(e){return e instanceof HTMLImageElement},isSVGElement:function(e){return e instanceof SVGElement},isNodeList:function(e){return e instanceof NodeList},isHTMLCollection:function(e){return e instanceof HTMLCollection},isScaledElement:$,isTableElement:function(e){return["TABLE","TD","TH"].includes(e.tagName)},isShadowRoot:J,isDocument:function(e){return e instanceof Document},isElementsArray:function(e){return Array.isArray(e)&&e.every((function(e){return[HTMLElement,Element].some((function(t){return e instanceof t}))}))},isWindow:function(e){return e instanceof Window},isMedia:function(e){return e&&[SVGElement,HTMLImageElement,HTMLVideoElement].some((function(t){return e instanceof t}))},isRTL:function(e){return"rtl"===Y(e).dir},elementNodes:oe,parentNodes:ae,closest:function e(t,n){return t?t.closest(n)||e(t.getRootNode().host,n):null},documentAll:re,querySelector:M,getCustomElements:function(e){var t=e&&ae.some((function(t){return e instanceof t}))?ie("*",e):re;return[].concat(t).filter(ne)},getElementById:function(e){return S().getElementById(e)},querySelectorAll:function(e,t){return(t&&t.querySelectorAll?t:S()).querySelectorAll(e)},getElementsByClassName:function(e,t){var n="getElementsByClassName";return(t&&t[n]?t:S())[n](e)},getElementsByTagName:ie,matches:function(e,t){return e.matches(t)},matchesLegacy:function(e,t){return se.call(e,t)},normalizeValue:j,normalizeOptions:function(e,t,n,i){var r=Object.assign({},e.dataset),o={},a={};return Q(r).forEach((function(e){var t=i&&e.includes(i)?e.replace(i,"").replace(/[A-Z]/,(function(e){return U(e)})):e;a[t]=j(r[e])})),Q(n).forEach((function(e){n[e]=j(n[e])})),Q(t).forEach((function(i){o[i]=i in n?n[i]:i in a?a[i]:"title"===i?T(e,"title"):t[i]})),o},tryWrapper:function(e,t){try{e()}catch(e){throw TypeError(t+" "+e)}},reflow:function(e){return e.offsetHeight},noop:function(){},focus:function(e){return e.focus()},getUID:function e(t,n){var i=n?_:ee;if(n){var r=e(t),o=te.get(r)||new Map;te.has(r)||te.set(r,o),o.has(n)?i=o.get(n):(o.set(n,i),_+=1)}else{var a=t.id||t;te.has(a)?i=te.get(a):(te.set(a,i),ee+=1)}return i},ArrayFrom:function(e){return Array.from(e)},Float32ArrayFrom:function(e){return Float32Array.from(Array.from(e))},Float64ArrayFrom:function(e){return Float64Array.from(Array.from(e))},ObjectAssign:z,ObjectKeys:Q,ObjectValues:function(e){return Object.values(e)},OriginalEvent:function(e,t){var n=new CustomEvent(e,{cancelable:!0,bubbles:!0});return t instanceof Object&&z(n,t),n},getBoundingClientRect:X,getDocument:S,getDocumentBody:function(e){return S(e).body},getDocumentElement:Y,getDocumentHead:function(e){return S(e).head},getElementStyle:H,setElementStyle:function(e,t){z(e.style,t)},hasAttribute:function(e,t){return e.hasAttribute(t)},hasAttributeNS:function(e,t,n){return t.hasAttributeNS(e,n)},getAttribute:T,getAttributeNS:function(e,t,n){return t.getAttributeNS(e,n)},setAttribute:function(e,t,n){return e.setAttribute(t,n)},setAttributeNS:function(e,t,n,i){return t.setAttributeNS(e,n,i)},removeAttribute:function(e,t){return e.removeAttribute(t)},removeAttributeNS:function(e,t,n){return t.removeAttributeNS(e,n)},Version:"1.0.0"}}));
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@thednp/shorty",
3
+ "version": "1.0.0",
4
+ "description": "JavaScript shorties.",
5
+ "main": "dist/shorty.min.js",
6
+ "module": "dist/shorty.esm.js",
7
+ "jsnext": "src/index.js",
8
+ "types": "types/index.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "src",
12
+ "types"
13
+ ],
14
+ "scripts": {
15
+ "test": "echo \"Error: no test specified\" && exit 1",
16
+ "fix:js": "eslint src/ --config .eslintrc --fix",
17
+ "lint:js": "eslint src/ --config .eslintrc",
18
+ "build:ts": "tsc -d",
19
+ "build": "npm run lint:js && npm-run-all --parallel umd umdmin esm esmmin",
20
+ "umd": "rollup --environment FORMAT:umd,MIN:false -c",
21
+ "umdmin": "rollup --environment FORMAT:umd,MIN:true -c",
22
+ "esm": "rollup --environment FORMAT:esm,MIN:false -c",
23
+ "esmmin": "rollup --environment FORMAT:esm,MIN:true -c"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "registry": "https://registry.npmjs.org/"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/thednp/shorty.git"
32
+ },
33
+ "keywords": [
34
+ "shorty",
35
+ "javascript",
36
+ "vanilla",
37
+ "native"
38
+ ],
39
+ "author": "dnp_theme",
40
+ "license": "MIT",
41
+ "bugs": {
42
+ "url": "https://github.com/thednp/shorty/issues"
43
+ },
44
+ "homepage": "https://github.com/thednp/shorty",
45
+ "devDependencies": {
46
+ "@rollup/plugin-buble": "^0.21.3",
47
+ "@rollup/plugin-json": "^4.1.0",
48
+ "@rollup/plugin-node-resolve": "^7.1.0",
49
+ "@rollup/plugin-typescript": "^8.3.0",
50
+ "eslint": "^7.22.0",
51
+ "eslint-config-airbnb-base": "^14.2.1",
52
+ "eslint-plugin-import": "^2.22.1",
53
+ "eslint-plugin-vue": "^7.7.0",
54
+ "npm-run-all": "^4.1.5",
55
+ "rollup": "^2.38.5",
56
+ "rollup-plugin-terser": "^5.3.1",
57
+ "typescript": "^4.5.2"
58
+ }
59
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shortcut for `HTMLElement.getAttribute()` method.
3
+ * @param {HTMLElement | Element} element target element
4
+ * @param {string} attribute attribute name
5
+ * @returns {string?} attribute value
6
+ */
7
+ const getAttribute = (element, attribute) => element.getAttribute(attribute);
8
+
9
+ export default getAttribute;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shortcut for `HTMLElement.getAttributeNS()` method.
3
+ * @param {string} ns attribute namespace
4
+ * @param {HTMLElement | Element} element target element
5
+ * @param {string} attribute attribute name
6
+ * @returns {string?} attribute value
7
+ */
8
+ const getAttributeNS = (ns, element, attribute) => element.getAttributeNS(ns, attribute);
9
+
10
+ export default getAttributeNS;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shortcut for `HTMLElement.hasAttribute()` method.
3
+ * @param {HTMLElement | Element} element target element
4
+ * @param {string} attribute attribute name
5
+ * @returns {boolean} the query result
6
+ */
7
+ const hasAttribute = (element, attribute) => element.hasAttribute(attribute);
8
+
9
+ export default hasAttribute;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shortcut for `HTMLElement.hasAttributeNS()` method.
3
+ * @param {string} ns attribute namespace
4
+ * @param {HTMLElement | Element} element target element
5
+ * @param {string} att attribute name
6
+ * @returns {boolean} the query result
7
+ */
8
+ const hasAttributeNS = (ns, element, att) => element.hasAttributeNS(ns, att);
9
+
10
+ export default hasAttributeNS;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shortcut for `HTMLElement.removeAttribute()` method.
3
+ * @param {HTMLElement | Element} element target element
4
+ * @param {string} attribute attribute name
5
+ * @returns {void}
6
+ */
7
+ const removeAttribute = (element, attribute) => element.removeAttribute(attribute);
8
+
9
+ export default removeAttribute;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shortcut for `HTMLElement.removeAttributeNS()` method.
3
+ * @param {string} ns attribute namespace
4
+ * @param {HTMLElement | Element} element target element
5
+ * @param {string} att attribute name
6
+ * @returns {void}
7
+ */
8
+ const removeAttributeNS = (ns, element, att) => element.removeAttributeNS(ns, att);
9
+
10
+ export default removeAttributeNS;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shortcut for `HTMLElement.setAttribute()` method.
3
+ * @param {HTMLElement | Element} element target element
4
+ * @param {string} attribute attribute name
5
+ * @param {string} value attribute value
6
+ * @returns {void}
7
+ */
8
+ const setAttribute = (element, attribute, value) => element.setAttribute(attribute, value);
9
+
10
+ export default setAttribute;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Shortcut for `SVGElement.setAttributeNS()` method.
3
+ * @param {string} ns attribute namespace
4
+ * @param {HTMLElement | Element} element target element
5
+ * @param {string} att attribute name
6
+ * @param {string} value attribute value
7
+ * @returns {void}
8
+ */
9
+ const setAttributeNS = (ns, element, att, value) => element.setAttributeNS(ns, att, value);
10
+
11
+ export default setAttributeNS;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A global namespace for `document.body`.
3
+ */
4
+ const { body: documentBody } = document;
5
+ export default documentBody;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A global namespace for `document.documentElement` or the `<HTML>`.
3
+ */
4
+ const { documentElement } = document;
5
+ export default documentElement;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A global namespace for `document.head`.
3
+ */
4
+ const { head: documentHead } = document;
5
+ export default documentHead;
@@ -0,0 +1,13 @@
1
+ import userAgentData from '../strings/userAgentData';
2
+ import userAgent from '../strings/userAgent';
3
+
4
+ const appleBrands = /(iPhone|iPod|iPad)/;
5
+
6
+ /**
7
+ * A global `boolean` for Apple browsers.
8
+ * @type {boolean}
9
+ */
10
+ const isApple = !userAgentData ? appleBrands.test(userAgent)
11
+ : userAgentData.brands.some((/** @type {Record<string, any>} */x) => appleBrands.test(x.brand));
12
+
13
+ export default isApple;
@@ -0,0 +1,9 @@
1
+ import userAgent from '../strings/userAgent';
2
+
3
+ /**
4
+ * A global boolean for Gecko browsers. When writing this file,
5
+ * Gecko was not supporting `userAgentData`.
6
+ * @type {boolean}
7
+ */
8
+ const isFirefox = userAgent ? userAgent.includes('Firefox') : false;
9
+ export default isFirefox;
@@ -0,0 +1,20 @@
1
+ import userAgentData from '../strings/userAgentData';
2
+ import userAgent from '../strings/userAgent';
3
+
4
+ const mobileBrands = /iPhone|iPad|iPod|Android/i;
5
+ let isMobileCheck = false;
6
+
7
+ if (userAgentData) {
8
+ isMobileCheck = userAgentData.brands
9
+ .some((/** @type {Record<String, any>} */x) => mobileBrands.test(x.brand));
10
+ } else {
11
+ isMobileCheck = mobileBrands.test(userAgent);
12
+ }
13
+
14
+ /**
15
+ * A global `boolean` for mobile detection.
16
+ * @type {boolean}
17
+ */
18
+ const isMobile = isMobileCheck;
19
+
20
+ export default isMobile;
@@ -0,0 +1,8 @@
1
+ import documentHead from '../blocks/documentHead';
2
+
3
+ /**
4
+ * A global `boolean` for CSS3 3D transform support.
5
+ * @type {boolean}
6
+ */
7
+ const support3DTransform = 'webkitPerspective' in documentHead.style || 'perspective' in documentHead.style;
8
+ export default support3DTransform;
@@ -0,0 +1,8 @@
1
+ import documentHead from '../blocks/documentHead';
2
+
3
+ /**
4
+ * A global `boolean` for CSS3 animation support.
5
+ * @type {boolean}
6
+ */
7
+ const supportAnimation = 'webkitAnimation' in documentHead.style || 'animation' in documentHead.style;
8
+ export default supportAnimation;
@@ -0,0 +1,28 @@
1
+ import DOMContentLoadedEvent from '../strings/DOMContentLoadedEvent';
2
+ import one from '../event/one';
3
+
4
+ /**
5
+ * A global `boolean` for passive events support,
6
+ * in general event options are not suited for scroll prevention.
7
+ *
8
+ * @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
9
+ * @type {boolean}
10
+ */
11
+ const supportPassive = (() => {
12
+ let result = false;
13
+ try {
14
+ const opts = Object.defineProperty({}, 'passive', {
15
+ get() {
16
+ result = true;
17
+ return result;
18
+ },
19
+ });
20
+ one(document, DOMContentLoadedEvent, () => {}, opts);
21
+ } catch (e) {
22
+ throw Error('Passive events are not supported');
23
+ }
24
+
25
+ return result;
26
+ })();
27
+
28
+ export default supportPassive;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A global `boolean` for touch events support.
3
+ * @type {boolean}
4
+ */
5
+ const supportTouch = 'ontouchstart' in window || 'msMaxTouchPoints' in navigator;
6
+ export default supportTouch;
@@ -0,0 +1,8 @@
1
+ import documentHead from '../blocks/documentHead';
2
+
3
+ /**
4
+ * A global `boolean` for CSS3 transform support.
5
+ * @type {boolean}
6
+ */
7
+ const supportTransform = 'webkitTransform' in documentHead.style || 'transform' in documentHead.style;
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
+ * @type {boolean}
6
+ */
7
+ const supportTransition = 'webkitTransition' in documentHead.style || 'transition' in documentHead.style;
8
+ export default supportTransition;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Add class to `HTMLElement.classList`.
3
+ *
4
+ * @param {HTMLElement | Element} element target
5
+ * @param {string} classNAME to add
6
+ * @returns {void}
7
+ */
8
+ export default function addClass(element, classNAME) {
9
+ element.classList.add(classNAME);
10
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Check class in `HTMLElement.classList`.
3
+ *
4
+ * @param {HTMLElement | Element} element target
5
+ * @param {string} classNAME to check
6
+ * @returns {boolean}
7
+ */
8
+ export default function hasClass(element, classNAME) {
9
+ return element.classList.contains(classNAME);
10
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Remove class from `HTMLElement.classList`.
3
+ *
4
+ * @param {HTMLElement | Element} element target
5
+ * @param {string} classNAME to remove
6
+ * @returns {void}
7
+ */
8
+ export default function removeClass(element, classNAME) {
9
+ element.classList.remove(classNAME);
10
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Remove eventListener from an `Element` | `HTMLElement` | `Document` | `Window` target.
3
+ *
4
+ * @param {HTMLElement | Element | Document | Window} element event.target
5
+ * @param {string} eventName event.type
6
+ * @param {EventListener} listener callback
7
+ * @param {(EventListenerOptions | boolean)=} options other event options
8
+ * @returns {void}
9
+ */
10
+ export default function off(element, eventName, listener, options) {
11
+ const ops = options || false;
12
+ element.removeEventListener(eventName, listener, ops);
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Add eventListener to an `Element` | `HTMLElement` | `Document` target.
3
+ *
4
+ * @param {HTMLElement | Element | Document | Window} element event.target
5
+ * @param {string} eventName event.type
6
+ * @param {EventListener} listener callback
7
+ * @param {(EventListenerOptions | boolean)=} options other event options
8
+ * @returns {void}
9
+ */
10
+ export default function on(element, eventName, listener, options) {
11
+ const ops = options || false;
12
+ element.addEventListener(eventName, listener, ops);
13
+ }
@@ -0,0 +1,26 @@
1
+ import on from './on';
2
+ import off from './off';
3
+
4
+ /**
5
+ * Add an `eventListener` to an `Element` | `HTMLElement` | `Document` | `Window`
6
+ * target and remove it once callback is called.
7
+ *
8
+ * @param {HTMLElement | Element | Document | Window} element event.target
9
+ * @param {string} eventName event.type
10
+ * @param {EventListener} listener callback
11
+ * @param {(EventListenerOptions | boolean)=} options other event options
12
+ * @returns {void}
13
+ */
14
+ export default function one(element, eventName, listener, options) {
15
+ /**
16
+ * Wrap the listener for easy on -> off
17
+ * @type {EventListener}
18
+ */
19
+ const handlerWrapper = (e) => {
20
+ if (e.target === element) {
21
+ listener.apply(element, [e]);
22
+ off(element, eventName, handlerWrapper, options);
23
+ }
24
+ };
25
+ on(element, eventName, handlerWrapper, options);
26
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Returns the bounding client rect of a target `HTMLElement`.
3
+ *
4
+ * @see https://github.com/floating-ui/floating-ui
5
+ *
6
+ * @param {HTMLElement | Element} element event.target
7
+ * @param {boolean=} includeScale when *true*, the target scale is also computed
8
+ * @returns {SHORTER.BoundingClientRect} the bounding client rect object
9
+ */
10
+ export default function getBoundingClientRect(element, includeScale) {
11
+ const {
12
+ width, height, top, right, bottom, left,
13
+ } = element.getBoundingClientRect();
14
+ let scaleX = 1;
15
+ let scaleY = 1;
16
+
17
+ if (includeScale && element instanceof HTMLElement) {
18
+ const { offsetWidth, offsetHeight } = element;
19
+ scaleX = offsetWidth > 0 ? Math.round(width) / offsetWidth || 1 : 1;
20
+ scaleY = offsetHeight > 0 ? Math.round(height) / offsetHeight || 1 : 1;
21
+ }
22
+
23
+ return {
24
+ width: width / scaleX,
25
+ height: height / scaleY,
26
+ top: top / scaleY,
27
+ right: right / scaleX,
28
+ bottom: bottom / scaleY,
29
+ left: left / scaleX,
30
+ x: left / scaleX,
31
+ y: top / scaleY,
32
+ };
33
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns the `document` or the `#document` element.
3
+ * @see https://github.com/floating-ui/floating-ui
4
+ * @param {(Node | HTMLElement | Element | globalThis)=} node
5
+ * @returns {Document}
6
+ */
7
+ export default function getDocument(node) {
8
+ if (node instanceof HTMLElement) return node.ownerDocument;
9
+ if (node instanceof Window) return node.document;
10
+ return window.document;
11
+ }
@@ -0,0 +1,10 @@
1
+ import getDocument from './getDocument';
2
+ /**
3
+ * Returns the `document.body` or the `<body>` element.
4
+ *
5
+ * @param {(Node | HTMLElement | Element | globalThis)=} node
6
+ * @returns {HTMLElement | HTMLBodyElement}
7
+ */
8
+ export default function getDocumentBody(node) {
9
+ return getDocument(node).body;
10
+ }
@@ -0,0 +1,11 @@
1
+ import getDocument from './getDocument';
2
+
3
+ /**
4
+ * Returns the `document.documentElement` or the `<html>` element.
5
+ *
6
+ * @param {(Node | HTMLElement | Element | globalThis)=} node
7
+ * @returns {HTMLElement | HTMLHtmlElement}
8
+ */
9
+ export default function getDocumentElement(node) {
10
+ return getDocument(node).documentElement;
11
+ }
@@ -0,0 +1,10 @@
1
+ import getDocument from './getDocument';
2
+ /**
3
+ * Returns the `document.head` or the `<head>` element.
4
+ *
5
+ * @param {(Node | HTMLElement | Element | globalThis)=} node
6
+ * @returns {HTMLElement | HTMLHeadElement}
7
+ */
8
+ export default function getDocumentHead(node) {
9
+ return getDocument(node).head;
10
+ }
@@ -0,0 +1,21 @@
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 {HTMLElement | Element} element target
10
+ * @return {number} the value in miliseconds
11
+ */
12
+ export default function getElementAnimationDelay(element) {
13
+ const propertyValue = getElementStyle(element, animationName);
14
+ const durationValue = getElementStyle(element, animationDelay);
15
+
16
+ const durationScale = durationValue.includes('ms') ? 1 : 1000;
17
+ const duration = propertyValue && propertyValue !== 'none'
18
+ ? parseFloat(durationValue) * durationScale : 0;
19
+
20
+ return !Number.isNaN(duration) ? duration : 0;
21
+ }
@@ -0,0 +1,21 @@
1
+ import supportAnimation from '../boolean/supportAnimation';
2
+ import animationDelay from '../strings/animationDelayLegacy';
3
+ import animationName from '../strings/animationNameLegacy';
4
+ import getElementStyle from './getElementStyle';
5
+
6
+ /**
7
+ * Utility to get the computed `animationDelay`
8
+ * from Element in miliseconds.
9
+ *
10
+ * @param {HTMLElement | Element} element target
11
+ * @return {number} the value in miliseconds
12
+ */
13
+ export default function getElementAnimationDelay(element) {
14
+ const propertyValue = getElementStyle(element, animationName);
15
+ const durationValue = getElementStyle(element, animationDelay);
16
+ const durationScale = durationValue.includes('ms') ? 1 : 1000;
17
+ const duration = supportAnimation && propertyValue && propertyValue !== 'none'
18
+ ? parseFloat(durationValue) * durationScale : 0;
19
+
20
+ return !Number.isNaN(duration) ? duration : 0;
21
+ }
@@ -0,0 +1,20 @@
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 {HTMLElement | Element} element target
10
+ * @return {number} the value in miliseconds
11
+ */
12
+ export default function getElementAnimationDuration(element) {
13
+ const propertyValue = getElementStyle(element, animationName);
14
+ const durationValue = getElementStyle(element, animationDuration);
15
+ const durationScale = durationValue.includes('ms') ? 1 : 1000;
16
+ const duration = propertyValue && propertyValue !== 'none'
17
+ ? parseFloat(durationValue) * durationScale : 0;
18
+
19
+ return !Number.isNaN(duration) ? duration : 0;
20
+ }
@@ -0,0 +1,21 @@
1
+ import supportAnimation from '../boolean/supportAnimation';
2
+ import animationDuration from '../strings/animationDurationLegacy';
3
+ import animationName from '../strings/animationNameLegacy';
4
+ import getElementStyle from './getElementStyle';
5
+
6
+ /**
7
+ * Utility to get the computed `animationDuration`
8
+ * from `HTMLElement` in miliseconds.
9
+ *
10
+ * @param {HTMLElement | Element} element target
11
+ * @return {number} the value in miliseconds
12
+ */
13
+ export default function getElementAnimationDuration(element) {
14
+ const propertyValue = getElementStyle(element, animationName);
15
+ const durationValue = getElementStyle(element, animationDuration);
16
+ const durationScale = durationValue.includes('ms') ? 1 : 1000;
17
+ const duration = supportAnimation && propertyValue && propertyValue !== 'none'
18
+ ? parseFloat(durationValue) * durationScale : 0;
19
+
20
+ return !Number.isNaN(duration) ? duration : 0;
21
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Shortcut for `window.getComputedStyle(element).propertyName`
3
+ * static method.
4
+ *
5
+ * * If `element` parameter is not an `HTMLElement`, `getComputedStyle`
6
+ * throws a `ReferenceError`.
7
+ *
8
+ * @param {HTMLElement | Element} element target
9
+ * @param {string} property the css property
10
+ * @return {string} the css property value
11
+ */
12
+ export default function getElementStyle(element, property) {
13
+ const computedStyle = getComputedStyle(element);
14
+
15
+ // @ts-ignore -- must use camelcase strings,
16
+ // or non-camelcase strings with `getPropertyValue`
17
+ return property in computedStyle ? computedStyle[property] : '';
18
+ }