@thednp/shorty 2.0.0-alpha4 → 2.0.0-alpha6
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 +8 -3
- package/dist/shorty.cjs +1 -1
- package/dist/shorty.cjs.map +1 -1
- package/dist/shorty.d.ts +59 -53
- package/dist/shorty.js +1 -1
- package/dist/shorty.js.map +1 -1
- package/dist/shorty.mjs +305 -306
- package/dist/shorty.mjs.map +1 -1
- package/package.json +12 -6
- package/src/attr/getAttribute.ts +3 -1
- package/src/attr/getAttributeNS.ts +3 -1
- package/src/attr/hasAttribute.ts +1 -0
- package/src/attr/hasAttributeNS.ts +3 -1
- package/src/attr/removeAttribute.ts +1 -0
- package/src/attr/removeAttributeNS.ts +3 -1
- package/src/attr/setAttribute.ts +3 -1
- package/src/attr/setAttributeNS.ts +1 -0
- package/src/boolean/isMobile.ts +1 -1
- package/src/boolean/support3DTransform.ts +1 -1
- package/src/boolean/supportAnimation.ts +1 -1
- package/src/boolean/supportPassive.ts +1 -1
- package/src/boolean/supportTouch.ts +2 -1
- package/src/boolean/supportTransform.ts +1 -1
- package/src/boolean/supportTransition.ts +1 -1
- package/src/event/off.ts +5 -3
- package/src/event/on.ts +5 -3
- package/src/event/one.ts +7 -2
- package/src/get/getBoundingClientRect.ts +5 -1
- package/src/get/getDocument.ts +4 -3
- package/src/get/getDocumentBody.ts +1 -1
- package/src/get/getElementAnimationDelay.ts +2 -1
- package/src/get/getElementAnimationDuration.ts +2 -1
- package/src/get/getElementTransitionDelay.ts +4 -1
- package/src/get/getElementTransitionDuration.ts +4 -1
- package/src/get/getParentNode.ts +2 -1
- package/src/get/getRectRelativeToOffsetParent.ts +1 -0
- package/src/get/getUID.ts +2 -2
- package/src/get/getWindow.ts +1 -0
- package/src/index.ts +12 -2
- package/src/interface/customElement.ts +1 -1
- package/src/interface/originalEvent.ts +2 -1
- package/src/is/isArray.ts +1 -1
- package/src/is/isCanvas.ts +4 -2
- package/src/is/isCustomElement.ts +3 -2
- package/src/is/isDocument.ts +4 -1
- package/src/is/isElement.ts +5 -2
- package/src/is/isElementsArray.ts +2 -1
- package/src/is/isFunction.ts +2 -1
- package/src/is/isHTMLCollection.ts +4 -2
- package/src/is/isHTMLElement.ts +5 -1
- package/src/is/isHTMLImageElement.ts +5 -2
- package/src/is/isJSON.ts +1 -1
- package/src/is/isMap.ts +4 -1
- package/src/is/isMedia.ts +8 -4
- package/src/is/isNode.ts +9 -3
- package/src/is/isNodeList.ts +4 -1
- package/src/is/isNumber.ts +1 -1
- package/src/is/isObject.ts +2 -1
- package/src/is/isRTL.ts +1 -0
- package/src/is/isSVGElement.ts +4 -2
- package/src/is/isScaledElement.ts +5 -2
- package/src/is/isShadowRoot.ts +4 -2
- package/src/is/isString.ts +1 -1
- package/src/is/isTableElement.ts +4 -2
- package/src/is/isWeakMap.ts +4 -1
- package/src/is/isWindow.ts +4 -1
- package/src/misc/Float32ArrayFrom.ts +1 -0
- package/src/misc/Float64ArrayFrom.ts +1 -0
- package/src/misc/ObjectAssign.ts +35 -3
- package/src/misc/ObjectEntries.ts +3 -1
- package/src/misc/ObjectKeys.ts +2 -1
- package/src/misc/ObjectValues.ts +3 -1
- package/src/misc/{OriginalEvent.ts → createCustomEvent.ts} +9 -5
- package/src/misc/createElement.ts +7 -6
- package/src/misc/createElementNS.ts +9 -5
- package/src/misc/data.ts +22 -15
- package/src/misc/distinct.ts +1 -0
- package/src/misc/hasOwn.ts +17 -0
- package/src/misc/normalizeValue.ts +9 -7
- package/src/misc/setElementStyle.ts +3 -2
- package/src/misc/timer.ts +16 -13
- package/src/selectors/getCustomElements.ts +1 -0
- package/src/selectors/getElementsByClassName.ts +7 -2
- package/src/selectors/getElementsByTagName.ts +4 -1
- package/src/selectors/querySelector.ts +5 -4
- package/src/strings/mouseHoverEvents.ts +3 -1
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thednp/shorty",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.0alpha6",
|
|
4
4
|
"description": "TypeScript shorties for the web",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/shorty.js",
|
|
7
7
|
"types": "./dist/shorty.d.ts",
|
|
8
8
|
"module": "./dist/shorty.mjs",
|
|
9
|
-
"exports": {
|
|
9
|
+
"*exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"import": "./dist/shorty.mjs",
|
|
12
12
|
"require": "./dist/shorty.cjs",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"cypress": "npm run pre-test && npx cypress open",
|
|
26
26
|
"coverage:report": "nyc report --reporter=lcov --reporter=json --reporter=text --reporter=json-summary",
|
|
27
27
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
28
|
-
"lint:ts": "
|
|
28
|
+
"lint:ts": "eslint -c .eslintrc.js --ext .ts src",
|
|
29
|
+
"fix:ts": "eslint -c .eslintrc.js --ext .ts src --fix",
|
|
29
30
|
"build": "npm run clean && tsc && vite build && dts-bundle-generator --config ./dts.config.ts"
|
|
30
31
|
},
|
|
31
32
|
"publishConfig": {
|
|
@@ -52,17 +53,22 @@
|
|
|
52
53
|
"@cypress/code-coverage": "^3.10.0",
|
|
53
54
|
"@testing-library/cypress": "^8.0.3",
|
|
54
55
|
"@types/istanbul-lib-instrument": "^1.7.4",
|
|
55
|
-
"
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
57
|
+
"@typescript-eslint/parser": "^5.35.1",
|
|
58
|
+
"cypress": "^11.2.0",
|
|
56
59
|
"dts-bundle-generator": "^6.12.0",
|
|
57
60
|
"esbuild": "^0.14.30",
|
|
61
|
+
"eslint": "^8.23.0",
|
|
62
|
+
"eslint-plugin-jsdoc": "^39.3.6",
|
|
63
|
+
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
64
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
58
65
|
"istanbul-lib-coverage": "^3.2.0",
|
|
59
66
|
"istanbul-lib-instrument": "^5.2.0",
|
|
67
|
+
"ncp": "^2.0.0",
|
|
60
68
|
"npm-run-all": "^4.1.5",
|
|
61
69
|
"nyc": "^15.1.0",
|
|
62
70
|
"prettier": "^2.7.1",
|
|
63
71
|
"rimraf": "^3.0.2",
|
|
64
|
-
"tslint": "^6.1.3",
|
|
65
|
-
"tslint-config-prettier": "^1.18.0",
|
|
66
72
|
"typescript": "^4.7.4",
|
|
67
73
|
"vite": "^3.0.9"
|
|
68
74
|
}
|
package/src/attr/getAttribute.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shortcut for `HTMLElement.getAttribute()` method.
|
|
3
|
+
*
|
|
3
4
|
* @param element target element
|
|
4
5
|
* @param att attribute name
|
|
5
6
|
* @returns attribute value
|
|
6
7
|
*/
|
|
7
|
-
const getAttribute = (element: HTMLElement, att: string): string | null =>
|
|
8
|
+
const getAttribute = (element: HTMLElement, att: string): string | null =>
|
|
9
|
+
element.getAttribute(att);
|
|
8
10
|
|
|
9
11
|
export default getAttribute;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shortcut for `HTMLElement.getAttributeNS()` method.
|
|
3
|
+
*
|
|
3
4
|
* @param ns attribute namespace
|
|
4
5
|
* @param element target element
|
|
5
6
|
* @param att attribute name
|
|
6
7
|
* @returns attribute value
|
|
7
8
|
*/
|
|
8
|
-
const getAttributeNS = (ns: string, element: HTMLElement, att: string) =>
|
|
9
|
+
const getAttributeNS = (ns: string, element: HTMLElement, att: string) =>
|
|
10
|
+
element.getAttributeNS(ns, att);
|
|
9
11
|
|
|
10
12
|
export default getAttributeNS;
|
package/src/attr/hasAttribute.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shortcut for `HTMLElement.hasAttributeNS()` method.
|
|
3
|
+
*
|
|
3
4
|
* @param ns attribute namespace
|
|
4
5
|
* @param element target element
|
|
5
6
|
* @param att attribute name
|
|
6
7
|
* @returns the query result
|
|
7
8
|
*/
|
|
8
|
-
const hasAttributeNS = (ns: string, element: HTMLElement, att: string): boolean =>
|
|
9
|
+
const hasAttributeNS = (ns: string, element: HTMLElement, att: string): boolean =>
|
|
10
|
+
element.hasAttributeNS(ns, att);
|
|
9
11
|
|
|
10
12
|
export default hasAttributeNS;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shortcut for `HTMLElement.removeAttributeNS()` method.
|
|
3
|
+
*
|
|
3
4
|
* @param ns attribute namespace
|
|
4
5
|
* @param element target element
|
|
5
6
|
* @param att attribute name
|
|
6
7
|
*/
|
|
7
|
-
const removeAttributeNS = (ns: string, element: HTMLElement, att: string): void =>
|
|
8
|
+
const removeAttributeNS = (ns: string, element: HTMLElement, att: string): void =>
|
|
9
|
+
element.removeAttributeNS(ns, att);
|
|
8
10
|
|
|
9
11
|
export default removeAttributeNS;
|
package/src/attr/setAttribute.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shortcut for `HTMLElement.setAttribute()` method.
|
|
3
|
+
*
|
|
3
4
|
* @param element target element
|
|
4
5
|
* @param att attribute name
|
|
5
6
|
* @param value attribute value
|
|
6
7
|
*/
|
|
7
|
-
const setAttribute = (element: HTMLElement, att: string, value: string) =>
|
|
8
|
+
const setAttribute = (element: HTMLElement, att: string, value: string) =>
|
|
9
|
+
element.setAttribute(att, value);
|
|
8
10
|
|
|
9
11
|
export default setAttribute;
|
package/src/boolean/isMobile.ts
CHANGED
|
@@ -6,7 +6,7 @@ let isMobileCheck = false;
|
|
|
6
6
|
|
|
7
7
|
/* istanbul ignore else */
|
|
8
8
|
if (userAgentData) {
|
|
9
|
-
isMobileCheck = userAgentData.brands.some(
|
|
9
|
+
isMobileCheck = userAgentData.brands.some(x => mobileBrands.test(x.brand));
|
|
10
10
|
} else {
|
|
11
11
|
isMobileCheck = mobileBrands.test(userAgent);
|
|
12
12
|
}
|
|
@@ -3,6 +3,6 @@ import documentHead from '../blocks/documentHead';
|
|
|
3
3
|
/**
|
|
4
4
|
* A global `boolean` for CSS3 3D transform support.
|
|
5
5
|
*/
|
|
6
|
-
const support3DTransform = ['webkitPerspective', 'perspective'].some(
|
|
6
|
+
const support3DTransform = ['webkitPerspective', 'perspective'].some(p => p in documentHead.style);
|
|
7
7
|
|
|
8
8
|
export default support3DTransform;
|
|
@@ -3,6 +3,6 @@ import documentHead from '../blocks/documentHead';
|
|
|
3
3
|
/**
|
|
4
4
|
* A global `boolean` for CSS3 animation support.
|
|
5
5
|
*/
|
|
6
|
-
const supportAnimation = ['webkitAnimation', 'animation'].some(
|
|
6
|
+
const supportAnimation = ['webkitAnimation', 'animation'].some(p => p in documentHead.style);
|
|
7
7
|
|
|
8
8
|
export default supportAnimation;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A global `boolean` for touch events support.
|
|
3
3
|
*/
|
|
4
|
-
const supportTouch =
|
|
4
|
+
const supportTouch =
|
|
5
|
+
'ontouchstart' in window || /* istanbul ignore next */ 'msMaxTouchPoints' in navigator;
|
|
5
6
|
|
|
6
7
|
export default supportTouch;
|
|
@@ -3,6 +3,6 @@ import documentHead from '../blocks/documentHead';
|
|
|
3
3
|
/**
|
|
4
4
|
* A global `boolean` for CSS3 transform support.
|
|
5
5
|
*/
|
|
6
|
-
const supportTransform = ['webkitTransform', 'transform'].some(
|
|
6
|
+
const supportTransform = ['webkitTransform', 'transform'].some(p => p in documentHead.style);
|
|
7
7
|
|
|
8
8
|
export default supportTransform;
|
|
@@ -3,6 +3,6 @@ import documentHead from '../blocks/documentHead';
|
|
|
3
3
|
/**
|
|
4
4
|
* A global `boolean` for CSS3 transition support.
|
|
5
5
|
*/
|
|
6
|
-
const supportTransition = ['webkitTransition', 'transition'].some(
|
|
6
|
+
const supportTransition = ['webkitTransition', 'transition'].some(p => p in documentHead.style);
|
|
7
7
|
|
|
8
8
|
export default supportTransition;
|
package/src/event/off.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Remove eventListener from an `EventTarget` object.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
const off = (
|
|
5
5
|
element: EventTarget,
|
|
6
6
|
eventName: string,
|
|
7
7
|
listener: EventListener,
|
|
8
8
|
options?: AddEventListenerOptions,
|
|
9
|
-
) {
|
|
9
|
+
) => {
|
|
10
10
|
const ops = options || false;
|
|
11
11
|
element.removeEventListener(eventName, listener, ops);
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default off;
|
package/src/event/on.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Add eventListener to an `EventTarget` object.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
const on = (
|
|
5
5
|
element: EventTarget,
|
|
6
6
|
eventName: string,
|
|
7
7
|
listener: EventListener,
|
|
8
8
|
options?: AddEventListenerOptions,
|
|
9
|
-
) {
|
|
9
|
+
) => {
|
|
10
10
|
const ops = options || false;
|
|
11
11
|
element.addEventListener(eventName, listener, ops);
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default on;
|
package/src/event/one.ts
CHANGED
|
@@ -5,11 +5,16 @@ import off from './off';
|
|
|
5
5
|
* Add an `eventListener` to an `EventTarget`
|
|
6
6
|
* element and remove it once callback is called.
|
|
7
7
|
*/
|
|
8
|
-
const one = (
|
|
8
|
+
const one = (
|
|
9
|
+
element: EventTarget,
|
|
10
|
+
eventName: string,
|
|
11
|
+
listener: EventListener,
|
|
12
|
+
options?: AddEventListenerOptions,
|
|
13
|
+
) => {
|
|
9
14
|
/** Wrap the listener for easy on -> off */
|
|
10
15
|
const handlerWrapper = (e: Event): void => {
|
|
11
16
|
/* istanbul ignore else */
|
|
12
|
-
if (e.target === element) {
|
|
17
|
+
if (e.target === element || e.currentTarget === element) {
|
|
13
18
|
listener.apply(element, [e]);
|
|
14
19
|
off(element, eventName, handlerWrapper, options);
|
|
15
20
|
}
|
|
@@ -3,13 +3,17 @@ import { BoundingClientRect } from '../interface/boundingClientRect';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the bounding client rect of a target `HTMLElement`.
|
|
6
|
+
*
|
|
6
7
|
* @see https://github.com/floating-ui/floating-ui
|
|
7
8
|
*
|
|
8
9
|
* @param element event.target
|
|
9
10
|
* @param includeScale when *true*, the target scale is also computed
|
|
10
11
|
* @returns the bounding client rect object
|
|
11
12
|
*/
|
|
12
|
-
const getBoundingClientRect = (
|
|
13
|
+
const getBoundingClientRect = (
|
|
14
|
+
element: HTMLElement,
|
|
15
|
+
includeScale?: boolean,
|
|
16
|
+
): BoundingClientRect => {
|
|
13
17
|
const { width, height, top, right, bottom, left } = element.getBoundingClientRect();
|
|
14
18
|
let scaleX = 1;
|
|
15
19
|
let scaleY = 1;
|
package/src/get/getDocument.ts
CHANGED
|
@@ -4,18 +4,19 @@ import isDocument from '../is/isDocument';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the `document` or the `#document` element.
|
|
7
|
+
*
|
|
7
8
|
* @see https://github.com/floating-ui/floating-ui
|
|
8
9
|
*
|
|
9
10
|
* @param node the reference node
|
|
10
11
|
* @returns the parent document of the given node
|
|
11
12
|
*/
|
|
12
|
-
const getDocument = (node?:
|
|
13
|
+
const getDocument = (node?: Node | Document | Window): Document => {
|
|
14
|
+
// node instanceof Window
|
|
15
|
+
if (isWindow(node)) return node.document;
|
|
13
16
|
// node instanceof Document
|
|
14
17
|
if (isDocument(node)) return node;
|
|
15
18
|
// node instanceof Node
|
|
16
19
|
if (isNode(node)) return node.ownerDocument as Document;
|
|
17
|
-
// node instanceof Window
|
|
18
|
-
if (isWindow(node)) return node.document;
|
|
19
20
|
// node is undefined | NULL
|
|
20
21
|
return window.document;
|
|
21
22
|
};
|
|
@@ -6,7 +6,7 @@ import getDocument from './getDocument';
|
|
|
6
6
|
* @param node the reference node
|
|
7
7
|
* @returns the parent `<body>` of the specified node
|
|
8
8
|
*/
|
|
9
|
-
const getDocumentBody = (node?:
|
|
9
|
+
const getDocumentBody = (node?: Node): HTMLElement => {
|
|
10
10
|
return getDocument(node).body;
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -13,7 +13,8 @@ const getElementAnimationDelay = (element: HTMLElement): number => {
|
|
|
13
13
|
const propertyValue = getElementStyle(element, animationName);
|
|
14
14
|
const durationValue = getElementStyle(element, animationDelay);
|
|
15
15
|
const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
|
|
16
|
-
const duration =
|
|
16
|
+
const duration =
|
|
17
|
+
propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
|
|
17
18
|
|
|
18
19
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
19
20
|
};
|
|
@@ -13,7 +13,8 @@ const getElementAnimationDuration = (element: HTMLElement): number => {
|
|
|
13
13
|
const propertyValue = getElementStyle(element, animationName);
|
|
14
14
|
const durationValue = getElementStyle(element, animationDuration);
|
|
15
15
|
const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
|
|
16
|
-
const duration =
|
|
16
|
+
const duration =
|
|
17
|
+
propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
|
|
17
18
|
|
|
18
19
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
19
20
|
};
|
|
@@ -13,7 +13,10 @@ const getElementTransitionDelay = (element: HTMLElement): number => {
|
|
|
13
13
|
const propertyValue = getElementStyle(element, transitionProperty);
|
|
14
14
|
const delayValue = getElementStyle(element, transitionDelay);
|
|
15
15
|
const delayScale = delayValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
|
|
16
|
-
const duration =
|
|
16
|
+
const duration =
|
|
17
|
+
propertyValue && propertyValue !== 'none'
|
|
18
|
+
? parseFloat(delayValue) * delayScale
|
|
19
|
+
: /* istanbul ignore next */ 0;
|
|
17
20
|
|
|
18
21
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
19
22
|
};
|
|
@@ -13,7 +13,10 @@ const getElementTransitionDuration = (element: HTMLElement): number => {
|
|
|
13
13
|
const propertyValue = getElementStyle(element, transitionProperty);
|
|
14
14
|
const durationValue = getElementStyle(element, transitionDuration);
|
|
15
15
|
const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
|
|
16
|
-
const duration =
|
|
16
|
+
const duration =
|
|
17
|
+
propertyValue && propertyValue !== 'none'
|
|
18
|
+
? parseFloat(durationValue) * durationScale
|
|
19
|
+
: /* istanbul ignore next */ 0;
|
|
17
20
|
|
|
18
21
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
19
22
|
};
|
package/src/get/getParentNode.ts
CHANGED
|
@@ -5,12 +5,13 @@ import isNode from '../is/isNode';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns the `parentNode` also going through `ShadowRoot`.
|
|
8
|
+
*
|
|
8
9
|
* @see https://github.com/floating-ui/floating-ui
|
|
9
10
|
*
|
|
10
11
|
* @param {Node} node the target node
|
|
11
12
|
* @returns {Node} the apropriate parent node
|
|
12
13
|
*/
|
|
13
|
-
const getParentNode = (node: Node): Node => {
|
|
14
|
+
const getParentNode = (node: Node): Node | ParentNode => {
|
|
14
15
|
if (node.nodeName === 'HTML') {
|
|
15
16
|
return node;
|
|
16
17
|
}
|
package/src/get/getUID.ts
CHANGED
|
@@ -24,8 +24,8 @@ const getUID = (element: HTMLElement, key?: string): number => {
|
|
|
24
24
|
if (!elementIDMap.has(elID)) {
|
|
25
25
|
elementIDMap.set(elID, elMap);
|
|
26
26
|
}
|
|
27
|
-
if (isMap(elMap) && !elMap.has(key)) {
|
|
28
|
-
elMap.set(key, result);
|
|
27
|
+
if (isMap(elMap as KeyIdMap) && !(elMap as KeyIdMap).has(key)) {
|
|
28
|
+
(elMap as KeyIdMap).set(key, result);
|
|
29
29
|
elementUID += 1;
|
|
30
30
|
} else result = (elMap as KeyIdMap).get(key) as number;
|
|
31
31
|
} else {
|
package/src/get/getWindow.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -153,6 +153,11 @@ import on from './event/on';
|
|
|
153
153
|
import off from './event/off';
|
|
154
154
|
import one from './event/one';
|
|
155
155
|
|
|
156
|
+
// blocks
|
|
157
|
+
import documentBody from './blocks/documentBody';
|
|
158
|
+
import documentElement from './blocks/documentElement';
|
|
159
|
+
import documentHead from './blocks/documentHead';
|
|
160
|
+
|
|
156
161
|
// misc
|
|
157
162
|
import ArrayFrom from './misc/ArrayFrom';
|
|
158
163
|
import Data, { getInstance } from './misc/data';
|
|
@@ -166,13 +171,14 @@ import Float32ArrayFrom from './misc/Float32ArrayFrom';
|
|
|
166
171
|
import Float64ArrayFrom from './misc/Float64ArrayFrom';
|
|
167
172
|
import focus from './misc/focus';
|
|
168
173
|
import noop from './misc/noop';
|
|
174
|
+
import hasOwn from './misc/hasOwn';
|
|
169
175
|
import normalizeOptions from './misc/normalizeOptions';
|
|
170
176
|
import normalizeValue from './misc/normalizeValue';
|
|
171
177
|
import ObjectAssign from './misc/ObjectAssign';
|
|
172
178
|
import ObjectEntries from './misc/ObjectEntries';
|
|
173
179
|
import ObjectKeys from './misc/ObjectKeys';
|
|
174
180
|
import ObjectValues from './misc/ObjectValues';
|
|
175
|
-
import
|
|
181
|
+
import createCustomEvent from './misc/createCustomEvent';
|
|
176
182
|
import passiveHandler from './misc/passiveHandler';
|
|
177
183
|
import reflow from './misc/reflow';
|
|
178
184
|
import setElementStyle from './misc/setElementStyle';
|
|
@@ -361,12 +367,16 @@ const SHORTY = {
|
|
|
361
367
|
on,
|
|
362
368
|
off,
|
|
363
369
|
one,
|
|
370
|
+
documentBody,
|
|
371
|
+
documentElement,
|
|
372
|
+
documentHead,
|
|
364
373
|
dispatchEvent,
|
|
365
374
|
distinct,
|
|
366
375
|
Data,
|
|
367
376
|
getInstance,
|
|
368
377
|
createElement,
|
|
369
378
|
createElementNS,
|
|
379
|
+
createCustomEvent,
|
|
370
380
|
toUpperCase,
|
|
371
381
|
toLowerCase,
|
|
372
382
|
Timer,
|
|
@@ -416,6 +426,7 @@ const SHORTY = {
|
|
|
416
426
|
getElementsByClassName,
|
|
417
427
|
getElementsByTagName,
|
|
418
428
|
matches,
|
|
429
|
+
hasOwn,
|
|
419
430
|
normalizeValue,
|
|
420
431
|
normalizeOptions,
|
|
421
432
|
reflow,
|
|
@@ -429,7 +440,6 @@ const SHORTY = {
|
|
|
429
440
|
ObjectEntries,
|
|
430
441
|
ObjectKeys,
|
|
431
442
|
ObjectValues,
|
|
432
|
-
OriginalEvent,
|
|
433
443
|
getBoundingClientRect,
|
|
434
444
|
getDocument,
|
|
435
445
|
getDocumentBody,
|
package/src/is/isArray.ts
CHANGED
package/src/is/isCanvas.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import isNode from './isNode';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Checks if an element is an `HTMLCanvasElement` or `<canvas>`.
|
|
3
5
|
*
|
|
@@ -5,7 +7,7 @@
|
|
|
5
7
|
* @returns the query result
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
|
-
const isCanvas = (element?:
|
|
9
|
-
(element && element.
|
|
10
|
+
const isCanvas = (element?: unknown): element is HTMLCanvasElement =>
|
|
11
|
+
(isNode(element) && element.nodeName === 'CANVAS') || false;
|
|
10
12
|
|
|
11
13
|
export default isCanvas;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import isHTMLElement from './isHTMLElement';
|
|
1
2
|
import { CustomElement } from '../interface/customElement';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -6,7 +7,7 @@ import { CustomElement } from '../interface/customElement';
|
|
|
6
7
|
* @param element the target object
|
|
7
8
|
* @returns the query result
|
|
8
9
|
*/
|
|
9
|
-
const isCustomElement = <T extends CustomElement>(element?:
|
|
10
|
-
(element && !!element.shadowRoot) || false;
|
|
10
|
+
const isCustomElement = <T extends CustomElement>(element?: unknown): element is T =>
|
|
11
|
+
(isHTMLElement(element) && !!(element as T).shadowRoot) || false;
|
|
11
12
|
|
|
12
13
|
export default isCustomElement;
|
package/src/is/isDocument.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import isNode from './isNode';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Checks if an object is a `Document`.
|
|
5
|
+
*
|
|
3
6
|
* @see https://dom.spec.whatwg.org/#node
|
|
4
7
|
*
|
|
5
8
|
* @param obj the target object
|
|
6
9
|
* @returns the query result
|
|
7
10
|
*/
|
|
8
|
-
const isDocument = (obj?:
|
|
11
|
+
const isDocument = (obj?: unknown): obj is Document => (isNode(obj) && obj.nodeType === 9) || false;
|
|
9
12
|
|
|
10
13
|
export default isDocument;
|
package/src/is/isElement.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import isNode from './isNode';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Checks if an object is an `Element`.
|
|
5
|
+
*
|
|
3
6
|
* @see https://dom.spec.whatwg.org/#node
|
|
4
7
|
*
|
|
5
8
|
* ```
|
|
@@ -18,7 +21,7 @@
|
|
|
18
21
|
* @param element the target object
|
|
19
22
|
* @returns the query result
|
|
20
23
|
*/
|
|
21
|
-
const isElement = (element?:
|
|
22
|
-
(element && [1, 2, 3, 4, 5, 6, 7, 8].some(
|
|
24
|
+
const isElement = (element?: unknown): element is Element =>
|
|
25
|
+
(isNode(element) && [1, 2, 3, 4, 5, 6, 7, 8].some(x => element.nodeType === x)) || false;
|
|
23
26
|
|
|
24
27
|
export default isElement;
|
|
@@ -7,6 +7,7 @@ import isArray from './isArray';
|
|
|
7
7
|
* @param obj the target object
|
|
8
8
|
* @returns the query result
|
|
9
9
|
*/
|
|
10
|
-
const isElementsArray = (obj?:
|
|
10
|
+
const isElementsArray = (obj?: unknown): obj is HTMLElement[] =>
|
|
11
|
+
(isArray(obj) && obj.every(isHTMLElement)) || false;
|
|
11
12
|
|
|
12
13
|
export default isElementsArray;
|
package/src/is/isFunction.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @param fn the target object
|
|
5
5
|
* @returns the query result
|
|
6
6
|
*/
|
|
7
|
-
const isFunction = (fn?:
|
|
7
|
+
const isFunction = (fn?: unknown): fn is (...arg0: any[]) => any =>
|
|
8
|
+
typeof fn === 'function' || false;
|
|
8
9
|
|
|
9
10
|
export default isFunction;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import isObject from './isObject';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Checks if an object is an `HTMLCollection`.
|
|
3
5
|
*
|
|
4
6
|
* @param obj the target object
|
|
5
7
|
* @returns the query result
|
|
6
8
|
*/
|
|
7
|
-
const isHTMLCollection = (obj?:
|
|
8
|
-
(obj && obj.constructor.name === 'HTMLCollection') || false;
|
|
9
|
+
const isHTMLCollection = (obj?: unknown): obj is HTMLCollection =>
|
|
10
|
+
(isObject(obj) && obj.constructor.name === 'HTMLCollection') || false;
|
|
9
11
|
|
|
10
12
|
export default isHTMLCollection;
|
package/src/is/isHTMLElement.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import isNode from './isNode';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Checks if an element is an `HTMLElement`.
|
|
5
|
+
*
|
|
3
6
|
* @see https://dom.spec.whatwg.org/#node
|
|
4
7
|
*
|
|
5
8
|
* @param element the target object
|
|
6
9
|
* @returns the query result
|
|
7
10
|
*/
|
|
8
|
-
const isHTMLElement = (element?:
|
|
11
|
+
const isHTMLElement = (element?: unknown): element is HTMLElement =>
|
|
12
|
+
(isNode(element) && element.nodeType === 1) || false;
|
|
9
13
|
export default isHTMLElement;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import isHTMLElement from './isHTMLElement';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Check if a target element is an `<img>`.
|
|
5
|
+
*
|
|
3
6
|
* @param element the target element
|
|
4
7
|
* @returns the query result
|
|
5
8
|
*/
|
|
6
|
-
const isHTMLImageElement = (element?:
|
|
7
|
-
(element && element.tagName === 'IMG') || false;
|
|
9
|
+
const isHTMLImageElement = (element?: unknown): element is HTMLImageElement =>
|
|
10
|
+
(isHTMLElement(element) && element.tagName === 'IMG') || false;
|
|
8
11
|
|
|
9
12
|
export default isHTMLImageElement;
|