@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,17 +0,0 @@
1
- import isNode from "./isNode";
2
-
3
- /**
4
- * Check if a target element is a `<table>`, `<td>` or `<th>`.
5
- * This specific check is important for determining
6
- * the `offsetParent` of a given element.
7
- *
8
- * @param element the target element
9
- * @returns the query result
10
- */
11
- const isTableElement = (
12
- element?: unknown,
13
- ): element is HTMLTableElement | HTMLTableCellElement =>
14
- (isNode(element) && ["TABLE", "TD", "TH"].includes(element.nodeName)) ||
15
- false;
16
-
17
- export default isTableElement;
@@ -1,11 +0,0 @@
1
- import isObject from "./isObject";
2
-
3
- /**
4
- * Checks if an element is a `WeakMap`.
5
- *
6
- * @param obj the target object
7
- * @returns the query result
8
- */
9
- const isWeakMap = (obj?: unknown): obj is WeakMap<WeakKey, unknown> =>
10
- (isObject(obj) && obj.constructor.name === "WeakMap") || false;
11
- export default isWeakMap;
@@ -1,13 +0,0 @@
1
- import isObject from "./isObject";
2
-
3
- /**
4
- * Check if a target object is `Window`.
5
- * => equivalent to `object instanceof Window`
6
- *
7
- * @param obj the target object
8
- * @returns the query result
9
- */
10
- const isWindow = (obj?: unknown): obj is Window =>
11
- (isObject(obj) && obj.constructor.name === "Window") || false;
12
-
13
- export default isWindow;
@@ -1,11 +0,0 @@
1
- /**
2
- * Shortie for `Array.from()` static method.
3
- * The utility should also work with any typed arrays
4
- * like Float64Array or Int32Array.
5
- *
6
- * @param arr array-like iterable object
7
- * @returns a new array from iterable object
8
- */
9
- const ArrayFrom = <T>(arr: ArrayLike<T> | Iterable<T>): T[] => Array.from(arr);
10
-
11
- export default ArrayFrom;
@@ -1,11 +0,0 @@
1
- /**
2
- * Shortcut for `Float32Array.from()` static method.
3
- *
4
- * @param arr array-like iterable object
5
- * @returns a new Float32Array
6
- */
7
- const Float32ArrayFrom = (
8
- arr: ArrayLike<number> | Iterable<number>,
9
- ): Float32Array => Float32Array.from(Array.from(arr));
10
-
11
- export default Float32ArrayFrom;
@@ -1,11 +0,0 @@
1
- /**
2
- * Shortcut for `Float64Array.from()` static method.
3
- *
4
- * @param arr array-like iterable object
5
- * @returns a new Float64Array
6
- */
7
- const Float64ArrayFrom = (
8
- arr: ArrayLike<number> | Iterable<number>,
9
- ): Float64Array => Float64Array.from(Array.from(arr));
10
-
11
- export default Float64ArrayFrom;
@@ -1,54 +0,0 @@
1
- /**
2
- * Overloads for Object.assign.
3
- *
4
- * @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/object-assign/index.d.ts
5
- */
6
- declare function ObjectAssignTyped<T, U>(target: T, source: U): T & U;
7
- declare function ObjectAssignTyped<T, U, V>(
8
- target: T,
9
- source1: U,
10
- source2: V,
11
- ): T & U & V;
12
- declare function ObjectAssignTyped<T, U, V, W>(
13
- target: T,
14
- source1: U,
15
- source2: V,
16
- source3: W,
17
- ): T & U & V & W;
18
- declare function ObjectAssignTyped<T, U, V, W, Q>(
19
- target: T,
20
- source1: U,
21
- source2: V,
22
- source3: W,
23
- source4: Q,
24
- ): T & U & V & W & Q;
25
- declare function ObjectAssignTyped<T, U, V, W, Q, R>(
26
- target: T,
27
- source1: U,
28
- source2: V,
29
- source3: W,
30
- source4: Q,
31
- source5: R,
32
- ): T & U & V & W & Q & R;
33
- declare function ObjectAssignTyped(
34
- target: unknown,
35
- ...sources: unknown[]
36
- ): unknown;
37
-
38
- /**
39
- * Shortcut for `Object.assign()` static method.
40
- *
41
- * @param obj a target object
42
- * @param source source object(s)
43
- * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
44
- */
45
- const ObjectAssign: typeof ObjectAssignTyped = <
46
- A extends Record<string, unknown>,
47
- B,
48
- >(
49
- obj: A,
50
- ...source: B[]
51
- ): B extends Record<string, unknown>[] ? unknown : A & B =>
52
- Object.assign(obj, ...source);
53
-
54
- export default ObjectAssign;
@@ -1,11 +0,0 @@
1
- /**
2
- * Shortcut for `Object.entries()` static method.
3
- *
4
- * @param obj a target object
5
- * @returns the entries of an object in an array format [key, value][]
6
- * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
7
- */
8
- const ObjectEntries = <O extends Record<keyof O, unknown>>(obj: O) =>
9
- Object.entries(obj) as [keyof O, O[keyof O]][];
10
-
11
- export default ObjectEntries;
@@ -1,11 +0,0 @@
1
- /**
2
- * Shortcut for `Object.fromEntries()` static method.
3
- *
4
- * @param entries a target entries object
5
- * @returns a new Object created from the specified entries in array format [key, value][]
6
- * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
7
- */
8
- const ObjectFromEntries = <K extends string, V>(entries: [K, V][]) =>
9
- Object.fromEntries(entries) as Record<K, V>;
10
-
11
- export default ObjectFromEntries;
@@ -1,18 +0,0 @@
1
- import isObject from "../is/isObject";
2
-
3
- /**
4
- * A shortcut to `Object.hasOwn()` static method to work
5
- * with regular `Object` elements.
6
- *
7
- * @see https://fettblog.eu/typescript-hasownproperty/
8
- * @param obj the target object
9
- * @param prop the property to check
10
- * @returns the query result
11
- */
12
- const ObjectHasOwn = <T extends object, K extends PropertyKey>(
13
- obj: T,
14
- prop: K,
15
- ): obj is T & Record<K, unknown> =>
16
- isObject(obj) && (Object.hasOwn(obj, prop) || prop in obj);
17
-
18
- export default ObjectHasOwn;
@@ -1,11 +0,0 @@
1
- /**
2
- * Shortcut for `Object.keys()` static method.
3
- *
4
- * @param obj a target object
5
- * @returns an array with object keys
6
- * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
7
- */
8
- const ObjectKeys = <O extends Record<keyof O, unknown>>(obj: O) =>
9
- Object.keys(obj) as (keyof O)[];
10
-
11
- export default ObjectKeys;
@@ -1,12 +0,0 @@
1
- /**
2
- * Shortcut for `Object.values()` static method.
3
- *
4
- * @param obj a target object
5
- * @returns an array with the object values
6
- * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
7
- */
8
- const ObjectValues = <O extends Record<string, unknown>>(
9
- obj: O,
10
- ): O[keyof O][] => Object.values(obj) as O[keyof O][];
11
-
12
- export default ObjectValues;
@@ -1,31 +0,0 @@
1
- import type { OriginalEvent } from "../interface/originalEvent";
2
- import isObject from "../is/isObject";
3
- import ObjectAssign from "./ObjectAssign";
4
-
5
- /**
6
- * Returns a namespaced `CustomEvent` specific to each component.
7
- *
8
- * @param eventType Event.type
9
- * @param config Event.options | Event.properties
10
- * @returns a new namespaced event
11
- */
12
- const createCustomEvent = <
13
- O extends unknown & Record<string, unknown>,
14
- T extends OriginalEvent,
15
- >(
16
- eventType: string,
17
- config?: O,
18
- ): T => {
19
- const OriginalCustomEvent = new CustomEvent<O>(eventType, {
20
- cancelable: true,
21
- bubbles: true,
22
- }) as T;
23
-
24
- // istanbul ignore else @preserve
25
- if (isObject(config)) {
26
- ObjectAssign(OriginalCustomEvent, config);
27
- }
28
- return OriginalCustomEvent;
29
- };
30
-
31
- export default createCustomEvent;
@@ -1,36 +0,0 @@
1
- import isString from "../is/isString";
2
- import getDocument from "../get/getDocument";
3
- import ObjectAssign from "./ObjectAssign";
4
-
5
- /**
6
- * Shortie for `document.createElement` method
7
- * which allows you to create a new `HTMLElement` for a given `tagName`
8
- * or based on an object with specific non-readonly attributes with string values:
9
- * `id`, `className`, `textContent`, `style`, etc.
10
- *
11
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
12
- *
13
- * @param param `tagName` or object
14
- * @return a new `HTMLElement`
15
- */
16
- const createElement = <T extends HTMLElement>(
17
- param?: string | Partial<T>,
18
- ): T | undefined => {
19
- if (!param) return undefined;
20
-
21
- if (isString(param)) {
22
- return getDocument().createElement(param) as T;
23
- }
24
-
25
- const { tagName } = param;
26
- const newElement = createElement(tagName as string);
27
-
28
- if (!newElement) return undefined;
29
-
30
- const attr = { ...(param as Record<string, unknown>) };
31
- delete attr.tagName;
32
-
33
- return ObjectAssign(newElement, attr) as unknown as T;
34
- };
35
-
36
- export default createElement;
@@ -1,40 +0,0 @@
1
- import getDocument from "../get/getDocument";
2
- import ObjectAssign from "./ObjectAssign";
3
- import isString from "../is/isString";
4
-
5
- /**
6
- * Shortie for `document.createElementNS` method
7
- * which allows you to create a new `HTMLElement` for a given `tagName`
8
- * or based on an object with specific non-readonly attributes with string values:
9
- * `id`, `className`, `textContent`, `style`, etc.
10
- * Note: some elements resulted from this function call may not be compatible with
11
- * some attributes.
12
- *
13
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS
14
- *
15
- * @param ns `namespaceURI` to associate with the new `HTMLElement`
16
- * @param param `tagName` or object
17
- * @return a new `HTMLElement`
18
- */
19
- const createElementNS = <T extends Element = HTMLElement>(
20
- ns: string,
21
- param?: string | Partial<T>,
22
- ): T | undefined => {
23
- if (!ns || !param) return undefined;
24
-
25
- if (isString(param)) {
26
- return getDocument().createElementNS(ns, param) as T;
27
- }
28
-
29
- const { tagName } = param;
30
- const newElement = createElementNS(ns, tagName);
31
-
32
- if (!newElement) return undefined;
33
-
34
- const attr = { ...(param as Record<string, unknown>) };
35
- delete attr.tagName;
36
-
37
- return ObjectAssign(newElement, attr) as unknown as T;
38
- };
39
-
40
- export default createElementNS;
package/src/misc/data.ts DELETED
@@ -1,80 +0,0 @@
1
- import isHTMLElement from "../is/isHTMLElement";
2
-
3
- const componentData = new Map<string, Map<HTMLElement, unknown>>();
4
-
5
- /**
6
- * An interface for web components background data.
7
- *
8
- * @see https://github.com/thednp/bootstrap.native/blob/master/src/components/base-component.js
9
- */
10
- const Data = {
11
- data: componentData,
12
- /**
13
- * Sets web components data.
14
- *
15
- * @param element target element
16
- * @param component the component's name or a unique key
17
- * @param instance the component instance
18
- */
19
- set: <T>(element: HTMLElement, component: string, instance: T): void => {
20
- if (!isHTMLElement(element)) return;
21
-
22
- // istanbul ignore else @preserve
23
- if (!componentData.has(component)) {
24
- componentData.set(component, new Map<HTMLElement, T>());
25
- }
26
-
27
- const instanceMap = componentData.get(component) as Map<HTMLElement, T>;
28
- // not undefined, but defined right above
29
- instanceMap.set(element, instance);
30
- },
31
-
32
- /**
33
- * Returns all instances for specified component.
34
- *
35
- * @param component the component's name or a unique key
36
- * @returns all the component instances
37
- */
38
- getAllFor: <T>(component: string): Map<HTMLElement, T> | null => {
39
- const instanceMap = componentData.get(component) as Map<HTMLElement, T>;
40
-
41
- return instanceMap || null;
42
- },
43
-
44
- /**
45
- * Returns the instance associated with the target.
46
- *
47
- * @param element target element
48
- * @param component the component's name or a unique key
49
- * @returns the instance
50
- */
51
- get: <T>(element: HTMLElement, component: string): T | null => {
52
- if (!isHTMLElement(element) || !component) return null;
53
- const instanceMap = Data.getAllFor<T>(component);
54
-
55
- const instance = element && instanceMap && instanceMap.get(element);
56
-
57
- return instance || null;
58
- },
59
-
60
- /**
61
- * Removes web components data.
62
- *
63
- * @param element target element
64
- * @param component the component's name or a unique key
65
- */
66
- remove: <T>(element: HTMLElement, component: string): void => {
67
- const instanceMap = Data.getAllFor<T>(component);
68
-
69
- if (!instanceMap || !isHTMLElement(element)) return;
70
-
71
- instanceMap.delete(element);
72
-
73
- // istanbul ignore else @preserve
74
- if (instanceMap.size === 0) {
75
- componentData.delete(component);
76
- }
77
- },
78
- };
79
-
80
- export default Data;
@@ -1,10 +0,0 @@
1
- /**
2
- * Shortcut for the `Element.dispatchEvent(Event)` method.
3
- *
4
- * @param element is the target
5
- * @param event is the `Event` object
6
- */
7
- const dispatchEvent = (element: EventTarget, event: Event): boolean =>
8
- element.dispatchEvent(event);
9
-
10
- export default dispatchEvent;
@@ -1,19 +0,0 @@
1
- /**
2
- * JavaScript `Array` distinct.
3
- *
4
- * @see https://codeburst.io/javascript-array-distinct-5edc93501dc4
5
- *
6
- * @example
7
- * ```
8
- * [0,1,1,2].filter(distinct)
9
- * // => [0,1,2]
10
- * ```
11
- * @param value array item value
12
- * @param index array item index
13
- * @param arr a clone of the target array
14
- * @returns the query result
15
- */
16
- const distinct = <T>(value: T, index: number, arr: T[]): boolean =>
17
- arr.indexOf(value) === index;
18
-
19
- export default distinct;
@@ -1,43 +0,0 @@
1
- import animationEndEvent from "../strings/animationEndEvent";
2
- import getElementAnimationDelay from "../get/getElementAnimationDelay";
3
- import getElementAnimationDuration from "../get/getElementAnimationDuration";
4
- import dispatchEvent from "./dispatchEvent";
5
-
6
- /**
7
- * Utility to make sure callbacks are consistently
8
- * called when animation ends.
9
- *
10
- * @param element target
11
- * @param handler `animationend` callback
12
- */
13
- const emulateAnimationEnd = (
14
- element: HTMLElement,
15
- handler: EventListener,
16
- ): void => {
17
- let called = 0;
18
- const endEvent = new Event(animationEndEvent);
19
- const duration = getElementAnimationDuration(element);
20
- const delay = getElementAnimationDelay(element);
21
-
22
- if (duration) {
23
- // Wrap the handler in on -> off callback
24
- const animationEndWrapper = (e: Event): void => {
25
- // istanbul ignore else @preserve
26
- if (e.target === element) {
27
- handler.apply(element, [e]);
28
- element.removeEventListener(animationEndEvent, animationEndWrapper);
29
- called = 1;
30
- }
31
- };
32
- element.addEventListener(animationEndEvent, animationEndWrapper);
33
- setTimeout(() => {
34
- // istanbul ignore next @preserve
35
- if (!called) dispatchEvent(element, endEvent);
36
- }, duration + delay + 17);
37
- } else {
38
- // istanbul ignore next @preserve
39
- handler.apply(element, [endEvent]);
40
- }
41
- };
42
-
43
- export default emulateAnimationEnd;
@@ -1,42 +0,0 @@
1
- import transitionEndEvent from "../strings/transitionEndEvent";
2
- import getElementTransitionDelay from "../get/getElementTransitionDelay";
3
- import getElementTransitionDuration from "../get/getElementTransitionDuration";
4
- import dispatchEvent from "./dispatchEvent";
5
-
6
- /**
7
- * Utility to make sure callbacks are consistently
8
- * called when transition ends.
9
- *
10
- * @param element event target
11
- * @param handler `transitionend` callback
12
- */
13
- const emulateTransitionEnd = (
14
- element: HTMLElement,
15
- handler: EventListener,
16
- ): void => {
17
- let called = 0;
18
- const endEvent = new Event(transitionEndEvent);
19
- const duration = getElementTransitionDuration(element);
20
- const delay = getElementTransitionDelay(element);
21
-
22
- if (duration) {
23
- // Wrap the handler in on -> off callback
24
- const transitionEndWrapper = (e: Event): void => {
25
- // istanbul ignore else @preserve
26
- if (e.target === element) {
27
- handler.apply(element, [e]);
28
- element.removeEventListener(transitionEndEvent, transitionEndWrapper);
29
- called = 1;
30
- }
31
- };
32
- element.addEventListener(transitionEndEvent, transitionEndWrapper);
33
- setTimeout(() => {
34
- // istanbul ignore next @preserve
35
- if (!called) dispatchEvent(element, endEvent);
36
- }, duration + delay + 17);
37
- } else {
38
- handler.apply(element, [endEvent]);
39
- }
40
- };
41
-
42
- export default emulateTransitionEnd;
package/src/misc/focus.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Shortie for `HTMLElement.focus()` method.
3
- *
4
- * @param element is the target
5
- * @param options allows to pass additional options such as `preventScroll: boolean`
6
- */
7
- const focus = (element: HTMLOrSVGElement, options?: FocusOptions): void =>
8
- element.focus(options);
9
-
10
- export default focus;
@@ -1,67 +0,0 @@
1
- import ariaHidden from "../strings/ariaHidden";
2
- import focusableSelector from "../strings/focusableSelector";
3
- import querySelectorAll from "../selectors/querySelectorAll";
4
- import getAttribute from "../attr/getAttribute";
5
- import hasAttribute from "../attr/hasAttribute";
6
- import off from "../event/off";
7
- import on from "../event/on";
8
- import getDocument from "../get/getDocument";
9
- import { KeyboardEvent } from "../interface/event";
10
-
11
- const focusTrapMap = new Map<HTMLElement, boolean>();
12
-
13
- export type FocusableElement =
14
- | HTMLAnchorElement
15
- | HTMLButtonElement
16
- | HTMLInputElement
17
- | HTMLTextAreaElement
18
- | HTMLDataListElement
19
- | HTMLDetailsElement
20
- | HTMLSelectElement;
21
-
22
- function handleKeyboardNavigation<T extends HTMLElement & EventTarget>(
23
- this: T,
24
- event: KeyboardEvent<T>,
25
- ) {
26
- const { shiftKey, code } = event;
27
- const doc = getDocument(this);
28
- const focusableElements = [
29
- ...querySelectorAll<FocusableElement>(focusableSelector, this),
30
- ].filter(
31
- (el) => !hasAttribute(el, "disabled") && !getAttribute(el, ariaHidden),
32
- );
33
-
34
- if (!focusableElements.length) return;
35
- const firstFocusable = focusableElements[0];
36
- const lastFocusable = focusableElements[focusableElements.length - 1];
37
-
38
- // istanbul ignore else @preserve
39
- if (code === "Tab") {
40
- if (shiftKey && doc.activeElement === firstFocusable) {
41
- lastFocusable.focus();
42
- event.preventDefault();
43
- } else if (!shiftKey && doc.activeElement === lastFocusable) {
44
- firstFocusable.focus();
45
- event.preventDefault();
46
- }
47
- }
48
- }
49
-
50
- /**
51
- * Utility to check if a designated element is affected by focus trap;
52
- * @param target
53
- */
54
- export const hasFocusTrap = (target: HTMLElement) =>
55
- focusTrapMap.has(target) === true;
56
-
57
- /**
58
- * Utility to toggle focus trap inside a designated target element;
59
- * @param target
60
- */
61
- export const toggleFocusTrap = (target: HTMLElement) => {
62
- const isCurrentlyTrapped = hasFocusTrap(target);
63
- const action = !isCurrentlyTrapped ? on : off;
64
- action(target, "keydown", handleKeyboardNavigation);
65
- if (isCurrentlyTrapped) focusTrapMap.delete(target);
66
- else focusTrapMap.set(target, true);
67
- };
@@ -1,9 +0,0 @@
1
- import Data from "./data";
2
-
3
- /**
4
- * An alias for `Data.get()`.
5
- */
6
- const getInstance = <T>(target: HTMLElement, component: string): T | null =>
7
- Data.get(target, component);
8
-
9
- export default getInstance;
package/src/misc/noop.ts DELETED
@@ -1,6 +0,0 @@
1
- /** A generic function with empty body. */
2
- const noop = () => {
3
- // this is a noop
4
- };
5
-
6
- export default noop;
@@ -1,58 +0,0 @@
1
- import getAttribute from "../attr/getAttribute";
2
- import normalizeValue from "./normalizeValue";
3
- import ObjectEntries from "./ObjectEntries";
4
- import toLowerCase from "./toLowerCase";
5
- // import { optionValues } from '../types';
6
-
7
- /**
8
- * Utility to normalize component options.
9
- *
10
- * @param element target
11
- * @param defaultOps component default options
12
- * @param inputOps component instance options
13
- * @param ns component namespace
14
- * @return normalized component options object
15
- */
16
- const normalizeOptions = <T extends { [key: string]: unknown }>(
17
- element: HTMLElement,
18
- defaultOps: T,
19
- inputOps: Partial<T>,
20
- ns?: string,
21
- ): T => {
22
- const INPUT = { ...inputOps } as T;
23
- const data = { ...element.dataset };
24
- const normalOps = { ...defaultOps };
25
- const dataOps: Partial<T> = {};
26
- const title = "title";
27
-
28
- ObjectEntries(data).forEach(([k, v]) => {
29
- const key: keyof T = ns && typeof k === "string" && k.includes(ns)
30
- ? k.replace(ns, "").replace(
31
- /[A-Z]/g,
32
- (match: string) => toLowerCase(match),
33
- )
34
- : /* istanbul ignore next @preserve */ k;
35
-
36
- dataOps[key] = normalizeValue(v) as T[keyof T];
37
- });
38
-
39
- ObjectEntries(INPUT).forEach(([k, v]) => {
40
- INPUT[k] = normalizeValue(v) as T[keyof T];
41
- });
42
-
43
- ObjectEntries(defaultOps).forEach(([k, v]) => {
44
- // istanbul ignore else @preserve
45
- if (k in INPUT) {
46
- normalOps[k] = INPUT[k] as T[keyof T];
47
- } else if (k in dataOps) {
48
- normalOps[k] = dataOps[k] as T[keyof T];
49
- } else {
50
- normalOps[k] =
51
- (k === title ? getAttribute(element, title) : v) as T[keyof T];
52
- }
53
- });
54
-
55
- return normalOps;
56
- };
57
-
58
- export default normalizeOptions;