@thednp/shorty 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/shorty.cjs +1 -17
- package/dist/shorty.cjs.map +1 -1
- package/dist/shorty.d.ts +2033 -1719
- package/dist/shorty.js +1 -17
- package/dist/shorty.js.map +1 -1
- package/dist/shorty.mjs +514 -516
- package/dist/shorty.mjs.map +1 -1
- package/package.json +13 -24
- package/src/attr/hasAttribute.ts +2 -1
- package/src/attr/hasAttributeNS.ts +5 -2
- package/src/attr/removeAttribute.ts +2 -1
- package/src/attr/removeAttributeNS.ts +5 -2
- package/src/attr/setAttributeNS.ts +6 -2
- package/src/boolean/isApple.ts +11 -10
- package/src/boolean/isFirefox.ts +3 -5
- package/src/boolean/isMobile.ts +9 -14
- package/src/boolean/support3DTransform.ts +2 -3
- package/src/boolean/supportAnimation.ts +2 -3
- package/src/boolean/supportPassive.ts +7 -7
- package/src/boolean/supportTouch.ts +4 -2
- package/src/boolean/supportTransform.ts +2 -3
- package/src/boolean/supportTransition.ts +2 -3
- package/src/event/off.ts +5 -1
- package/src/event/on.ts +5 -1
- package/src/event/one.ts +5 -5
- package/src/get/getBoundingClientRect.ts +10 -5
- package/src/get/getDocument.ts +4 -4
- package/src/get/getDocumentBody.ts +1 -1
- package/src/get/getDocumentElement.ts +1 -1
- package/src/get/getDocumentHead.ts +4 -2
- package/src/get/getElementAnimationDelay.ts +9 -6
- package/src/get/getElementAnimationDuration.ts +9 -6
- package/src/get/getElementStyle.ts +2 -2
- package/src/get/getElementTransitionDelay.ts +9 -8
- package/src/get/getElementTransitionDuration.ts +9 -8
- package/src/get/getNodeScroll.ts +4 -2
- package/src/get/getParentNode.ts +5 -5
- package/src/get/getRectRelativeToOffsetParent.ts +8 -5
- package/src/get/getUID.ts +1 -1
- package/src/get/getWindow.ts +2 -2
- package/src/index.ts +482 -440
- package/src/interface/event.d.ts +49 -41
- package/src/interface/fn.ts +1 -0
- package/src/interface/originalEvent.d.ts +1 -1
- package/src/is/isArray.ts +2 -1
- package/src/is/isCanvas.ts +2 -2
- package/src/is/isCustomElement.ts +5 -3
- package/src/is/isDocument.ts +3 -2
- package/src/is/isElement.ts +3 -2
- package/src/is/isElementInScrollRange.ts +3 -3
- package/src/is/isElementInViewport.ts +5 -4
- package/src/is/isElementsArray.ts +2 -2
- package/src/is/isFunction.ts +4 -2
- package/src/is/isHTMLCollection.ts +2 -2
- package/src/is/isHTMLElement.ts +1 -1
- package/src/is/isHTMLImageElement.ts +2 -2
- package/src/is/isJSON.ts +2 -2
- package/src/is/isMap.ts +3 -3
- package/src/is/isMedia.ts +9 -3
- package/src/is/isNode.ts +5 -3
- package/src/is/isNodeList.ts +2 -2
- package/src/is/isNumber.ts +2 -1
- package/src/is/isObject.ts +1 -1
- package/src/is/isRTL.ts +2 -2
- package/src/is/isSVGElement.ts +2 -2
- package/src/is/isScaledElement.ts +4 -3
- package/src/is/isShadowRoot.ts +2 -2
- package/src/is/isString.ts +2 -1
- package/src/is/isTableElement.ts +6 -3
- package/src/is/isWeakMap.ts +3 -3
- package/src/is/isWindow.ts +2 -2
- package/src/misc/Float32ArrayFrom.ts +3 -2
- package/src/misc/Float64ArrayFrom.ts +3 -2
- package/src/misc/ObjectAssign.ts +15 -4
- package/src/misc/ObjectEntries.ts +1 -1
- package/src/misc/ObjectHasOwn.ts +3 -2
- package/src/misc/ObjectKeys.ts +2 -1
- package/src/misc/ObjectValues.ts +3 -2
- package/src/misc/createCustomEvent.ts +7 -4
- package/src/misc/createElement.ts +6 -4
- package/src/misc/createElementNS.ts +3 -3
- package/src/misc/data.ts +2 -2
- package/src/misc/dispatchEvent.ts +2 -1
- package/src/misc/distinct.ts +2 -1
- package/src/misc/emulateAnimationEnd.ts +8 -5
- package/src/misc/emulateTransitionEnd.ts +8 -5
- package/src/misc/focus.ts +2 -1
- package/src/misc/focusTrap.ts +17 -14
- package/src/misc/getInstance.ts +1 -1
- package/src/misc/normalizeOptions.ts +15 -12
- package/src/misc/normalizeValue.ts +8 -6
- package/src/misc/setElementStyle.ts +9 -6
- package/src/misc/timer.ts +12 -5
- package/src/selectors/closest.ts +2 -2
- package/src/selectors/getCustomElements.ts +3 -3
- package/src/selectors/getElementById.ts +1 -1
- package/src/selectors/getElementsByClassName.ts +9 -4
- package/src/selectors/getElementsByTagName.ts +9 -4
- package/src/selectors/matches.ts +2 -1
- package/src/selectors/querySelector.ts +3 -3
- package/src/selectors/querySelectorAll.ts +2 -2
- package/src/strings/DOMContentLoadedEvent.ts +1 -1
- package/src/strings/DOMMouseScrollEvent.ts +1 -1
- package/src/strings/abortEvent.ts +1 -1
- package/src/strings/addEventListener.ts +1 -1
- package/src/strings/animationDelay.ts +1 -1
- package/src/strings/animationDuration.ts +1 -1
- package/src/strings/animationEndEvent.ts +1 -1
- package/src/strings/animationName.ts +1 -1
- package/src/strings/ariaChecked.ts +1 -1
- package/src/strings/ariaDescribedBy.ts +1 -1
- package/src/strings/ariaDescription.ts +1 -1
- package/src/strings/ariaExpanded.ts +1 -1
- package/src/strings/ariaHasPopup.ts +1 -1
- package/src/strings/ariaHidden.ts +1 -1
- package/src/strings/ariaLabel.ts +1 -1
- package/src/strings/ariaLabelledBy.ts +1 -1
- package/src/strings/ariaModal.ts +1 -1
- package/src/strings/ariaPressed.ts +1 -1
- package/src/strings/ariaSelected.ts +1 -1
- package/src/strings/ariaValueMax.ts +1 -1
- package/src/strings/ariaValueMin.ts +1 -1
- package/src/strings/ariaValueNow.ts +1 -1
- package/src/strings/ariaValueText.ts +1 -1
- package/src/strings/beforeunloadEvent.ts +1 -1
- package/src/strings/bezierEasings.ts +25 -25
- package/src/strings/blurEvent.ts +1 -1
- package/src/strings/changeEvent.ts +1 -1
- package/src/strings/contextmenuEvent.ts +1 -1
- package/src/strings/dragEvent.ts +1 -1
- package/src/strings/dragendEvent.ts +1 -1
- package/src/strings/dragenterEvent.ts +1 -1
- package/src/strings/dragleaveEvent.ts +1 -1
- package/src/strings/dragoverEvent.ts +1 -1
- package/src/strings/dragstartEvent.ts +1 -1
- package/src/strings/errorEvent.ts +1 -1
- package/src/strings/focusEvent.ts +1 -1
- package/src/strings/focusEvents.ts +1 -1
- package/src/strings/focusinEvent.ts +1 -1
- package/src/strings/focusoutEvent.ts +1 -1
- package/src/strings/gesturechangeEvent.ts +1 -1
- package/src/strings/gestureendEvent.ts +1 -1
- package/src/strings/gesturestartEvent.ts +1 -1
- package/src/strings/keyAlt.ts +1 -1
- package/src/strings/keyArrowDown.ts +1 -1
- package/src/strings/keyArrowLeft.ts +1 -1
- package/src/strings/keyArrowRight.ts +1 -1
- package/src/strings/keyArrowUp.ts +1 -1
- package/src/strings/keyBackspace.ts +1 -1
- package/src/strings/keyCapsLock.ts +1 -1
- package/src/strings/keyControl.ts +1 -1
- package/src/strings/keyDelete.ts +1 -1
- package/src/strings/keyEnter.ts +1 -1
- package/src/strings/keyEscape.ts +1 -1
- package/src/strings/keyInsert.ts +1 -1
- package/src/strings/keyMeta.ts +1 -1
- package/src/strings/keyNumpadEnter.ts +1 -1
- package/src/strings/keyPause.ts +1 -1
- package/src/strings/keyScrollLock.ts +1 -1
- package/src/strings/keyShift.ts +1 -1
- package/src/strings/keySpace.ts +1 -1
- package/src/strings/keyTab.ts +1 -1
- package/src/strings/keyboardEventKeys.ts +19 -19
- package/src/strings/keydownEvent.ts +1 -1
- package/src/strings/keypressEvent.ts +1 -1
- package/src/strings/keyupEvent.ts +1 -1
- package/src/strings/loadEvent.ts +1 -1
- package/src/strings/loadstartEvent.ts +1 -1
- package/src/strings/mouseClickEvents.ts +1 -1
- package/src/strings/mouseHoverEvents.ts +3 -4
- package/src/strings/mouseSwipeEvents.ts +4 -4
- package/src/strings/mouseclickEvent.ts +1 -1
- package/src/strings/mousedblclickEvent.ts +1 -1
- package/src/strings/mousedownEvent.ts +1 -1
- package/src/strings/mouseenterEvent.ts +1 -1
- package/src/strings/mousehoverEvent.ts +1 -1
- package/src/strings/mouseinEvent.ts +1 -1
- package/src/strings/mouseleaveEvent.ts +1 -1
- package/src/strings/mousemoveEvent.ts +1 -1
- package/src/strings/mouseoutEvent.ts +1 -1
- package/src/strings/mouseoverEvent.ts +1 -1
- package/src/strings/mouseupEvent.ts +1 -1
- package/src/strings/mousewheelEvent.ts +1 -1
- package/src/strings/moveEvent.ts +1 -1
- package/src/strings/nativeEvents.ts +50 -50
- package/src/strings/offsetHeight.ts +1 -1
- package/src/strings/offsetWidth.ts +1 -1
- package/src/strings/orientationchangeEvent.ts +1 -1
- package/src/strings/pointercancelEvent.ts +1 -1
- package/src/strings/pointerdownEvent.ts +1 -1
- package/src/strings/pointerleaveEvent.ts +1 -1
- package/src/strings/pointermoveEvent.ts +1 -1
- package/src/strings/pointerupEvent.ts +1 -1
- package/src/strings/readystatechangeEvent.ts +1 -1
- package/src/strings/removeEventListener.ts +1 -1
- package/src/strings/resetEvent.ts +1 -1
- package/src/strings/resizeEvent.ts +1 -1
- package/src/strings/scrollEvent.ts +1 -1
- package/src/strings/scrollHeight.ts +1 -1
- package/src/strings/scrollWidth.ts +1 -1
- package/src/strings/selectEvent.ts +1 -1
- package/src/strings/selectendEvent.ts +1 -1
- package/src/strings/selectstartEvent.ts +1 -1
- package/src/strings/submitEvent.ts +1 -1
- package/src/strings/tabindex.ts +1 -1
- package/src/strings/touchEvents.ts +4 -4
- package/src/strings/touchcancelEvent.ts +1 -1
- package/src/strings/touchendEvent.ts +1 -1
- package/src/strings/touchmoveEvent.ts +1 -1
- package/src/strings/touchstartEvent.ts +1 -1
- package/src/strings/transitionDelay.ts +1 -1
- package/src/strings/transitionDuration.ts +1 -1
- package/src/strings/transitionEndEvent.ts +1 -1
- package/src/strings/transitionProperty.ts +1 -1
- package/src/strings/unloadEvent.ts +1 -1
- package/src/strings/userAgentData.ts +3 -4
- package/test/boolean.test.ts +9 -9
- package/tsconfig.json +2 -1
- package/vite.config.mts +20 -0
- package/vitest.config-ui.mts +5 -0
- package/vitest.config.mts +5 -0
- package/dts.config.ts +0 -16
package/src/misc/ObjectKeys.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @returns an array with object keys
|
|
6
6
|
* @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
|
|
7
7
|
*/
|
|
8
|
-
const ObjectKeys = <O extends Record<
|
|
8
|
+
const ObjectKeys = <O extends Record<keyof O, unknown>>(obj: O) =>
|
|
9
|
+
Object.keys(obj) as (keyof O)[];
|
|
9
10
|
|
|
10
11
|
export default ObjectKeys;
|
package/src/misc/ObjectValues.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* @returns an array with the object values
|
|
6
6
|
* @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
|
|
7
7
|
*/
|
|
8
|
-
const ObjectValues = <O extends Record<string, unknown>>(
|
|
9
|
-
|
|
8
|
+
const ObjectValues = <O extends Record<string, unknown>>(
|
|
9
|
+
obj: O,
|
|
10
|
+
): O[keyof O][] => Object.values(obj) as O[keyof O][];
|
|
10
11
|
|
|
11
12
|
export default ObjectValues;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { OriginalEvent } from
|
|
2
|
-
import isObject from
|
|
3
|
-
import ObjectAssign from
|
|
1
|
+
import type { OriginalEvent } from "../interface/originalEvent";
|
|
2
|
+
import isObject from "../is/isObject";
|
|
3
|
+
import ObjectAssign from "./ObjectAssign";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns a namespaced `CustomEvent` specific to each component.
|
|
@@ -9,7 +9,10 @@ import ObjectAssign from './ObjectAssign';
|
|
|
9
9
|
* @param config Event.options | Event.properties
|
|
10
10
|
* @returns a new namespaced event
|
|
11
11
|
*/
|
|
12
|
-
const createCustomEvent = <
|
|
12
|
+
const createCustomEvent = <
|
|
13
|
+
O extends unknown & Record<string, unknown>,
|
|
14
|
+
T extends OriginalEvent,
|
|
15
|
+
>(
|
|
13
16
|
eventType: string,
|
|
14
17
|
config?: O,
|
|
15
18
|
): T => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import isString from
|
|
2
|
-
import getDocument from
|
|
3
|
-
import ObjectAssign from
|
|
1
|
+
import isString from "../is/isString";
|
|
2
|
+
import getDocument from "../get/getDocument";
|
|
3
|
+
import ObjectAssign from "./ObjectAssign";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Shortie for `document.createElement` method
|
|
@@ -13,7 +13,9 @@ import ObjectAssign from './ObjectAssign';
|
|
|
13
13
|
* @param param `tagName` or object
|
|
14
14
|
* @return a new `HTMLElement`
|
|
15
15
|
*/
|
|
16
|
-
const createElement = <T extends HTMLElement>(
|
|
16
|
+
const createElement = <T extends HTMLElement>(
|
|
17
|
+
param?: string | Partial<T>,
|
|
18
|
+
): T | undefined => {
|
|
17
19
|
if (!param) return undefined;
|
|
18
20
|
|
|
19
21
|
if (isString(param)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import getDocument from
|
|
2
|
-
import ObjectAssign from
|
|
3
|
-
import isString from
|
|
1
|
+
import getDocument from "../get/getDocument";
|
|
2
|
+
import ObjectAssign from "./ObjectAssign";
|
|
3
|
+
import isString from "../is/isString";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Shortie for `document.createElementNS` method
|
package/src/misc/data.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import isHTMLElement from
|
|
1
|
+
import isHTMLElement from "../is/isHTMLElement";
|
|
2
2
|
|
|
3
|
-
const componentData = new Map<string, Map<HTMLElement,
|
|
3
|
+
const componentData = new Map<string, Map<HTMLElement, unknown>>();
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* An interface for web components background data.
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @param element is the target
|
|
5
5
|
* @param event is the `Event` object
|
|
6
6
|
*/
|
|
7
|
-
const dispatchEvent = (element: EventTarget, event: Event): boolean =>
|
|
7
|
+
const dispatchEvent = (element: EventTarget, event: Event): boolean =>
|
|
8
|
+
element.dispatchEvent(event);
|
|
8
9
|
|
|
9
10
|
export default dispatchEvent;
|
package/src/misc/distinct.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* @param arr a clone of the target array
|
|
14
14
|
* @returns the query result
|
|
15
15
|
*/
|
|
16
|
-
const distinct = <T>(value: T, index: number, arr: T[]): boolean =>
|
|
16
|
+
const distinct = <T>(value: T, index: number, arr: T[]): boolean =>
|
|
17
|
+
arr.indexOf(value) === index;
|
|
17
18
|
|
|
18
19
|
export default distinct;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import animationEndEvent from
|
|
2
|
-
import getElementAnimationDelay from
|
|
3
|
-
import getElementAnimationDuration from
|
|
4
|
-
import dispatchEvent from
|
|
1
|
+
import animationEndEvent from "../strings/animationEndEvent";
|
|
2
|
+
import getElementAnimationDelay from "../get/getElementAnimationDelay";
|
|
3
|
+
import getElementAnimationDuration from "../get/getElementAnimationDuration";
|
|
4
|
+
import dispatchEvent from "./dispatchEvent";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Utility to make sure callbacks are consistently
|
|
@@ -10,7 +10,10 @@ import dispatchEvent from './dispatchEvent';
|
|
|
10
10
|
* @param element target
|
|
11
11
|
* @param handler `animationend` callback
|
|
12
12
|
*/
|
|
13
|
-
const emulateAnimationEnd = (
|
|
13
|
+
const emulateAnimationEnd = (
|
|
14
|
+
element: HTMLElement,
|
|
15
|
+
handler: EventListener,
|
|
16
|
+
): void => {
|
|
14
17
|
let called = 0;
|
|
15
18
|
const endEvent = new Event(animationEndEvent);
|
|
16
19
|
const duration = getElementAnimationDuration(element);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import transitionEndEvent from
|
|
2
|
-
import getElementTransitionDelay from
|
|
3
|
-
import getElementTransitionDuration from
|
|
4
|
-
import dispatchEvent from
|
|
1
|
+
import transitionEndEvent from "../strings/transitionEndEvent";
|
|
2
|
+
import getElementTransitionDelay from "../get/getElementTransitionDelay";
|
|
3
|
+
import getElementTransitionDuration from "../get/getElementTransitionDuration";
|
|
4
|
+
import dispatchEvent from "./dispatchEvent";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Utility to make sure callbacks are consistently
|
|
@@ -10,7 +10,10 @@ import dispatchEvent from './dispatchEvent';
|
|
|
10
10
|
* @param element event target
|
|
11
11
|
* @param handler `transitionend` callback
|
|
12
12
|
*/
|
|
13
|
-
const emulateTransitionEnd = (
|
|
13
|
+
const emulateTransitionEnd = (
|
|
14
|
+
element: HTMLElement,
|
|
15
|
+
handler: EventListener,
|
|
16
|
+
): void => {
|
|
14
17
|
let called = 0;
|
|
15
18
|
const endEvent = new Event(transitionEndEvent);
|
|
16
19
|
const duration = getElementTransitionDuration(element);
|
package/src/misc/focus.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @param element is the target
|
|
5
5
|
* @param options allows to pass additional options such as `preventScroll: boolean`
|
|
6
6
|
*/
|
|
7
|
-
const focus = (element: HTMLOrSVGElement, options?: FocusOptions): void =>
|
|
7
|
+
const focus = (element: HTMLOrSVGElement, options?: FocusOptions): void =>
|
|
8
|
+
element.focus(options);
|
|
8
9
|
|
|
9
10
|
export default focus;
|
package/src/misc/focusTrap.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import ariaHidden from
|
|
2
|
-
import focusableSelector from
|
|
3
|
-
import querySelectorAll from
|
|
4
|
-
import getAttribute from
|
|
5
|
-
import hasAttribute from
|
|
6
|
-
import off from
|
|
7
|
-
import on from
|
|
8
|
-
import getDocument from
|
|
9
|
-
import { KeyboardEvent } from
|
|
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
10
|
|
|
11
11
|
const focusTrapMap = new Map<HTMLElement, boolean>();
|
|
12
12
|
|
|
@@ -25,8 +25,10 @@ function handleKeyboardNavigation<T extends HTMLElement & EventTarget>(
|
|
|
25
25
|
) {
|
|
26
26
|
const { shiftKey, code } = event;
|
|
27
27
|
const doc = getDocument(this);
|
|
28
|
-
const focusableElements = [
|
|
29
|
-
|
|
28
|
+
const focusableElements = [
|
|
29
|
+
...querySelectorAll<FocusableElement>(focusableSelector, this),
|
|
30
|
+
].filter(
|
|
31
|
+
(el) => !hasAttribute(el, "disabled") && !getAttribute(el, ariaHidden),
|
|
30
32
|
);
|
|
31
33
|
|
|
32
34
|
if (!focusableElements.length) return;
|
|
@@ -34,7 +36,7 @@ function handleKeyboardNavigation<T extends HTMLElement & EventTarget>(
|
|
|
34
36
|
const lastFocusable = focusableElements[focusableElements.length - 1];
|
|
35
37
|
|
|
36
38
|
// istanbul ignore else @preserve
|
|
37
|
-
if (code ===
|
|
39
|
+
if (code === "Tab") {
|
|
38
40
|
if (shiftKey && doc.activeElement === firstFocusable) {
|
|
39
41
|
lastFocusable.focus();
|
|
40
42
|
event.preventDefault();
|
|
@@ -49,7 +51,8 @@ function handleKeyboardNavigation<T extends HTMLElement & EventTarget>(
|
|
|
49
51
|
* Utility to check if a designated element is affected by focus trap;
|
|
50
52
|
* @param target
|
|
51
53
|
*/
|
|
52
|
-
export const hasFocusTrap = (target: HTMLElement) =>
|
|
54
|
+
export const hasFocusTrap = (target: HTMLElement) =>
|
|
55
|
+
focusTrapMap.has(target) === true;
|
|
53
56
|
|
|
54
57
|
/**
|
|
55
58
|
* Utility to toggle focus trap inside a designated target element;
|
|
@@ -58,7 +61,7 @@ export const hasFocusTrap = (target: HTMLElement) => focusTrapMap.has(target) ==
|
|
|
58
61
|
export const toggleFocusTrap = (target: HTMLElement) => {
|
|
59
62
|
const isCurrentlyTrapped = hasFocusTrap(target);
|
|
60
63
|
const action = !isCurrentlyTrapped ? on : off;
|
|
61
|
-
action(target,
|
|
64
|
+
action(target, "keydown", handleKeyboardNavigation);
|
|
62
65
|
if (isCurrentlyTrapped) focusTrapMap.delete(target);
|
|
63
66
|
else focusTrapMap.set(target, true);
|
|
64
67
|
};
|
package/src/misc/getInstance.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import getAttribute from
|
|
2
|
-
import normalizeValue from
|
|
3
|
-
import ObjectEntries from
|
|
4
|
-
import toLowerCase from
|
|
1
|
+
import getAttribute from "../attr/getAttribute";
|
|
2
|
+
import normalizeValue from "./normalizeValue";
|
|
3
|
+
import ObjectEntries from "./ObjectEntries";
|
|
4
|
+
import toLowerCase from "./toLowerCase";
|
|
5
5
|
// import { optionValues } from '../types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -13,23 +13,25 @@ import toLowerCase from './toLowerCase';
|
|
|
13
13
|
* @param ns component namespace
|
|
14
14
|
* @return normalized component options object
|
|
15
15
|
*/
|
|
16
|
-
const normalizeOptions = <T extends { [key: string]:
|
|
16
|
+
const normalizeOptions = <T extends { [key: string]: unknown }>(
|
|
17
17
|
element: HTMLElement,
|
|
18
18
|
defaultOps: T,
|
|
19
19
|
inputOps: Partial<T>,
|
|
20
20
|
ns?: string,
|
|
21
21
|
): T => {
|
|
22
|
-
const INPUT = { ...inputOps };
|
|
22
|
+
const INPUT = { ...inputOps } as T;
|
|
23
23
|
const data = { ...element.dataset };
|
|
24
24
|
const normalOps = { ...defaultOps };
|
|
25
25
|
const dataOps: Partial<T> = {};
|
|
26
|
-
const title =
|
|
26
|
+
const title = "title";
|
|
27
27
|
|
|
28
28
|
ObjectEntries(data).forEach(([k, v]) => {
|
|
29
|
-
const key: keyof T =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
:
|
|
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;
|
|
33
35
|
|
|
34
36
|
dataOps[key] = normalizeValue(v) as T[keyof T];
|
|
35
37
|
});
|
|
@@ -45,7 +47,8 @@ const normalizeOptions = <T extends { [key: string]: any }>(
|
|
|
45
47
|
} else if (k in dataOps) {
|
|
46
48
|
normalOps[k] = dataOps[k] as T[keyof T];
|
|
47
49
|
} else {
|
|
48
|
-
normalOps[k] =
|
|
50
|
+
normalOps[k] =
|
|
51
|
+
(k === title ? getAttribute(element, title) : v) as T[keyof T];
|
|
49
52
|
}
|
|
50
53
|
});
|
|
51
54
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { Fn } from "../interface/fn";
|
|
2
|
+
|
|
3
|
+
type NormalValue = boolean | number | string | Fn | null;
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Utility to normalize component options
|
|
@@ -6,20 +8,20 @@ type NormalValue = boolean | number | string | ((...args: any[]) => any) | null;
|
|
|
6
8
|
* @param value the input value
|
|
7
9
|
* @return the normalized value
|
|
8
10
|
*/
|
|
9
|
-
const normalizeValue = (value?:
|
|
10
|
-
if ([
|
|
11
|
+
const normalizeValue = (value?: unknown): NormalValue => {
|
|
12
|
+
if (["true", true].includes(value as boolean)) {
|
|
11
13
|
return true;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
if ([
|
|
16
|
+
if (["false", false].includes(value as boolean)) {
|
|
15
17
|
return false;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
if ([
|
|
20
|
+
if (["null", "", null, undefined].includes(value as string | undefined)) {
|
|
19
21
|
return null;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
if (value !==
|
|
24
|
+
if (value !== "" && !Number.isNaN(+(value as string))) {
|
|
23
25
|
return +(value as string);
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import ObjectAssign from
|
|
2
|
-
import ObjectEntries from
|
|
3
|
-
import isString from
|
|
4
|
-
import type { CSS4Declaration } from
|
|
1
|
+
import ObjectAssign from "./ObjectAssign";
|
|
2
|
+
import ObjectEntries from "./ObjectEntries";
|
|
3
|
+
import isString from "../is/isString";
|
|
4
|
+
import type { CSS4Declaration } from "../interface/css4Declaration";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Shortcut for multiple uses of `HTMLElement.style.propertyName` method.
|
|
@@ -9,9 +9,12 @@ import type { CSS4Declaration } from '../interface/css4Declaration';
|
|
|
9
9
|
* @param element target element
|
|
10
10
|
* @param styles attribute value
|
|
11
11
|
*/
|
|
12
|
-
const setElementStyle = (
|
|
12
|
+
const setElementStyle = (
|
|
13
|
+
element: HTMLElement,
|
|
14
|
+
styles: Partial<CSS4Declaration>,
|
|
15
|
+
): void => {
|
|
13
16
|
ObjectEntries(styles).forEach(([key, value]) => {
|
|
14
|
-
if (value && isString(key as string) && (key as string).includes(
|
|
17
|
+
if (value && isString(key as string) && (key as string).includes("--")) {
|
|
15
18
|
element.style.setProperty(key as string, value);
|
|
16
19
|
} else {
|
|
17
20
|
const propObject: Partial<CSS4Declaration> = {};
|
package/src/misc/timer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import isMap from
|
|
2
|
-
import isHTMLElement from
|
|
3
|
-
import isNumber from
|
|
1
|
+
import isMap from "../is/isMap";
|
|
2
|
+
import isHTMLElement from "../is/isHTMLElement";
|
|
3
|
+
import isNumber from "../is/isNumber";
|
|
4
4
|
|
|
5
5
|
type KeyMap = Map<string, number>;
|
|
6
6
|
type TimeMap = Map<HTMLElement, number | KeyMap>;
|
|
@@ -20,7 +20,12 @@ const Timer = {
|
|
|
20
20
|
* @param delay the execution delay
|
|
21
21
|
* @param key a unique key
|
|
22
22
|
*/
|
|
23
|
-
set: (
|
|
23
|
+
set: (
|
|
24
|
+
element: HTMLElement,
|
|
25
|
+
callback: TimerHandler,
|
|
26
|
+
delay: number,
|
|
27
|
+
key?: string,
|
|
28
|
+
): void => {
|
|
24
29
|
if (!isHTMLElement(element)) return;
|
|
25
30
|
|
|
26
31
|
// istanbul ignore else @preserve
|
|
@@ -49,7 +54,9 @@ const Timer = {
|
|
|
49
54
|
const keyTimers = TimeCache.get(element);
|
|
50
55
|
|
|
51
56
|
if (key && keyTimers && isMap(keyTimers as KeyMap)) {
|
|
52
|
-
return (keyTimers as KeyMap).get(key) ||
|
|
57
|
+
return (keyTimers as KeyMap).get(key) ||
|
|
58
|
+
/* istanbul ignore next @preserve */
|
|
59
|
+
null;
|
|
53
60
|
} else if (isNumber(keyTimers as number)) {
|
|
54
61
|
return keyTimers as number;
|
|
55
62
|
}
|
package/src/selectors/closest.ts
CHANGED
|
@@ -15,8 +15,8 @@ const closest = <T extends Element = HTMLElement>(
|
|
|
15
15
|
): HTMLElement | null => {
|
|
16
16
|
return element
|
|
17
17
|
? element.closest(selector) ||
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// break out of `ShadowRoot`
|
|
19
|
+
closest((element.getRootNode() as ShadowRoot).host, selector)
|
|
20
20
|
: null;
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import isCustomElement from
|
|
2
|
-
import getElementsByTagName from
|
|
1
|
+
import isCustomElement from "../is/isCustomElement";
|
|
2
|
+
import getElementsByTagName from "./getElementsByTagName";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns an `Array` of `Node` elements that are registered as
|
|
@@ -11,7 +11,7 @@ import getElementsByTagName from './getElementsByTagName';
|
|
|
11
11
|
* @returns the query result
|
|
12
12
|
*/
|
|
13
13
|
const getCustomElements = (parent?: ParentNode) => {
|
|
14
|
-
const collection = getElementsByTagName(
|
|
14
|
+
const collection = getElementsByTagName("*", parent);
|
|
15
15
|
|
|
16
16
|
return [...collection].filter(isCustomElement);
|
|
17
17
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import getDocument from
|
|
2
|
-
import isNode from
|
|
1
|
+
import getDocument from "../get/getDocument";
|
|
2
|
+
import isNode from "../is/isNode";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Shortcut for `HTMLElement.getElementsByClassName` method. Some `Node` elements
|
|
@@ -9,9 +9,14 @@ import isNode from '../is/isNode';
|
|
|
9
9
|
* @param parent optional Element to look into
|
|
10
10
|
* @return the 'HTMLCollection'
|
|
11
11
|
*/
|
|
12
|
-
const getElementsByClassName = <T extends HTMLElement>(
|
|
12
|
+
const getElementsByClassName = <T extends HTMLElement>(
|
|
13
|
+
selector: string,
|
|
14
|
+
parent?: ParentNode,
|
|
15
|
+
) => {
|
|
13
16
|
const lookUp = parent && isNode(parent) ? parent : getDocument();
|
|
14
|
-
return (lookUp as HTMLElement | Document).getElementsByClassName(
|
|
17
|
+
return (lookUp as HTMLElement | Document).getElementsByClassName(
|
|
18
|
+
selector,
|
|
19
|
+
) as HTMLCollectionOf<T>;
|
|
15
20
|
};
|
|
16
21
|
|
|
17
22
|
export default getElementsByClassName;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import getDocument from
|
|
2
|
-
import isNode from
|
|
1
|
+
import getDocument from "../get/getDocument";
|
|
2
|
+
import isNode from "../is/isNode";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Shortcut for `HTMLElement.getElementsByTagName` method. Some `Node` elements
|
|
@@ -9,9 +9,14 @@ import isNode from '../is/isNode';
|
|
|
9
9
|
* @param parent optional Element to look into
|
|
10
10
|
* @return the 'HTMLCollection'
|
|
11
11
|
*/
|
|
12
|
-
const getElementsByTagName = <T extends HTMLElement>(
|
|
12
|
+
const getElementsByTagName = <T extends HTMLElement>(
|
|
13
|
+
selector: string,
|
|
14
|
+
parent?: ParentNode,
|
|
15
|
+
) => {
|
|
13
16
|
const lookUp = isNode(parent) ? parent : getDocument();
|
|
14
|
-
return (lookUp as Document).getElementsByTagName(
|
|
17
|
+
return (lookUp as Document).getElementsByTagName(
|
|
18
|
+
selector,
|
|
19
|
+
) as HTMLCollectionOf<T>;
|
|
15
20
|
};
|
|
16
21
|
|
|
17
22
|
export default getElementsByTagName;
|
package/src/selectors/matches.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @param selector the selector to match
|
|
6
6
|
* @returns the query result
|
|
7
7
|
*/
|
|
8
|
-
const matches = (target: Element, selector: string): boolean =>
|
|
8
|
+
const matches = (target: Element, selector: string): boolean =>
|
|
9
|
+
target.matches(selector);
|
|
9
10
|
|
|
10
11
|
export default matches;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import getDocument from
|
|
2
|
-
import isNode from
|
|
3
|
-
import isHTMLElement from
|
|
1
|
+
import getDocument from "../get/getDocument";
|
|
2
|
+
import isNode from "../is/isNode";
|
|
3
|
+
import isHTMLElement from "../is/isHTMLElement";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Utility to check if target is typeof `HTMLElement`, `Element`, `Node`
|
package/src/strings/ariaLabel.ts
CHANGED