@thednp/shorty 2.0.0-alpha4 → 2.0.0-alpha5
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 +6 -2
- package/dist/shorty.cjs +1 -1
- package/dist/shorty.cjs.map +1 -1
- package/dist/shorty.d.ts +57 -51
- package/dist/shorty.js +1 -1
- package/dist/shorty.js.map +1 -1
- package/dist/shorty.mjs +160 -162
- package/dist/shorty.mjs.map +1 -1
- package/package.json +10 -4
- 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 +6 -1
- 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 +2 -1
- package/src/get/getElementTransitionDuration.ts +2 -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 +10 -2
- package/src/interface/originalEvent.ts +2 -1
- package/src/is/isCanvas.ts +2 -2
- package/src/is/isCustomElement.ts +2 -2
- package/src/is/isDocument.ts +2 -1
- package/src/is/isElement.ts +3 -2
- package/src/is/isElementsArray.ts +2 -1
- package/src/is/isFunction.ts +2 -1
- package/src/is/isHTMLCollection.ts +1 -1
- package/src/is/isHTMLElement.ts +3 -1
- package/src/is/isHTMLImageElement.ts +2 -1
- package/src/is/isJSON.ts +1 -1
- package/src/is/isMap.ts +2 -1
- package/src/is/isMedia.ts +5 -2
- package/src/is/isNode.ts +2 -2
- package/src/is/isNodeList.ts +2 -1
- package/src/is/isNumber.ts +1 -1
- package/src/is/isObject.ts +1 -1
- package/src/is/isRTL.ts +1 -0
- package/src/is/isSVGElement.ts +1 -1
- package/src/is/isScaledElement.ts +5 -2
- package/src/is/isShadowRoot.ts +1 -1
- package/src/is/isString.ts +1 -1
- package/src/is/isTableElement.ts +3 -1
- package/src/is/isWeakMap.ts +2 -1
- package/src/is/isWindow.ts +2 -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 +10 -7
- package/src/misc/createElementNS.ts +9 -5
- package/src/misc/data.ts +31 -16
- package/src/misc/distinct.ts +1 -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 +2 -2
- package/src/strings/mouseHoverEvents.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thednp/shorty",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.0alpha5",
|
|
4
4
|
"description": "TypeScript shorties for the web",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/shorty.js",
|
|
@@ -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",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
57
|
+
"@typescript-eslint/parser": "^5.35.1",
|
|
55
58
|
"cypress": "^10.6.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,7 +5,12 @@ 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 */
|
|
@@ -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,8 @@ 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' ? parseFloat(delayValue) * delayScale : 0;
|
|
17
18
|
|
|
18
19
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
19
20
|
};
|
|
@@ -13,7 +13,8 @@ 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' ? parseFloat(durationValue) * durationScale : 0;
|
|
17
18
|
|
|
18
19
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
19
20
|
};
|
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';
|
|
@@ -172,7 +177,7 @@ import ObjectAssign from './misc/ObjectAssign';
|
|
|
172
177
|
import ObjectEntries from './misc/ObjectEntries';
|
|
173
178
|
import ObjectKeys from './misc/ObjectKeys';
|
|
174
179
|
import ObjectValues from './misc/ObjectValues';
|
|
175
|
-
import
|
|
180
|
+
import createCustomEvent from './misc/createCustomEvent';
|
|
176
181
|
import passiveHandler from './misc/passiveHandler';
|
|
177
182
|
import reflow from './misc/reflow';
|
|
178
183
|
import setElementStyle from './misc/setElementStyle';
|
|
@@ -361,12 +366,16 @@ const SHORTY = {
|
|
|
361
366
|
on,
|
|
362
367
|
off,
|
|
363
368
|
one,
|
|
369
|
+
documentBody,
|
|
370
|
+
documentElement,
|
|
371
|
+
documentHead,
|
|
364
372
|
dispatchEvent,
|
|
365
373
|
distinct,
|
|
366
374
|
Data,
|
|
367
375
|
getInstance,
|
|
368
376
|
createElement,
|
|
369
377
|
createElementNS,
|
|
378
|
+
createCustomEvent,
|
|
370
379
|
toUpperCase,
|
|
371
380
|
toLowerCase,
|
|
372
381
|
Timer,
|
|
@@ -429,7 +438,6 @@ const SHORTY = {
|
|
|
429
438
|
ObjectEntries,
|
|
430
439
|
ObjectKeys,
|
|
431
440
|
ObjectValues,
|
|
432
|
-
OriginalEvent,
|
|
433
441
|
getBoundingClientRect,
|
|
434
442
|
getDocument,
|
|
435
443
|
getDocumentBody,
|
package/src/is/isCanvas.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @returns the query result
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const isCanvas = (element?:
|
|
9
|
-
(element && element.
|
|
8
|
+
const isCanvas = (element?: Node): element is HTMLCanvasElement =>
|
|
9
|
+
(element && element.nodeName === 'CANVAS') || false;
|
|
10
10
|
|
|
11
11
|
export default isCanvas;
|
|
@@ -6,7 +6,7 @@ import { CustomElement } from '../interface/customElement';
|
|
|
6
6
|
* @param element the target object
|
|
7
7
|
* @returns the query result
|
|
8
8
|
*/
|
|
9
|
-
const isCustomElement = <T extends CustomElement>(element?:
|
|
10
|
-
(element && !!element.shadowRoot) || false;
|
|
9
|
+
const isCustomElement = <T extends CustomElement>(element?: T | Node): element is T =>
|
|
10
|
+
(element && !!(element as CustomElement).shadowRoot) || false;
|
|
11
11
|
|
|
12
12
|
export default isCustomElement;
|
package/src/is/isDocument.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if an object is a `Document`.
|
|
3
|
+
*
|
|
3
4
|
* @see https://dom.spec.whatwg.org/#node
|
|
4
5
|
*
|
|
5
6
|
* @param obj the target object
|
|
6
7
|
* @returns the query result
|
|
7
8
|
*/
|
|
8
|
-
const isDocument = (obj?:
|
|
9
|
+
const isDocument = (obj?: Node | Document): obj is Document => (obj && obj.nodeType === 9) || false;
|
|
9
10
|
|
|
10
11
|
export default isDocument;
|
package/src/is/isElement.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if an object is an `Element`.
|
|
3
|
+
*
|
|
3
4
|
* @see https://dom.spec.whatwg.org/#node
|
|
4
5
|
*
|
|
5
6
|
* ```
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
* @param element the target object
|
|
19
20
|
* @returns the query result
|
|
20
21
|
*/
|
|
21
|
-
const isElement = (element?:
|
|
22
|
-
(element && [1, 2, 3, 4, 5, 6, 7, 8].some(
|
|
22
|
+
const isElement = (element?: Element | Node): element is Element =>
|
|
23
|
+
(element && [1, 2, 3, 4, 5, 6, 7, 8].some(x => element.nodeType === x)) || false;
|
|
23
24
|
|
|
24
25
|
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?: any): obj is HTMLElement[] =>
|
|
10
|
+
const isElementsArray = (obj?: any): 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 =
|
|
7
|
+
const isFunction = <T extends (...arg0: any[]) => any>(fn?: T): fn is T =>
|
|
8
|
+
typeof fn === 'function' || false;
|
|
8
9
|
|
|
9
10
|
export default isFunction;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param obj the target object
|
|
5
5
|
* @returns the query result
|
|
6
6
|
*/
|
|
7
|
-
const isHTMLCollection = (obj?:
|
|
7
|
+
const isHTMLCollection = (obj?: HTMLCollection): obj is HTMLCollection =>
|
|
8
8
|
(obj && obj.constructor.name === 'HTMLCollection') || false;
|
|
9
9
|
|
|
10
10
|
export default isHTMLCollection;
|
package/src/is/isHTMLElement.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if an element is an `HTMLElement`.
|
|
3
|
+
*
|
|
3
4
|
* @see https://dom.spec.whatwg.org/#node
|
|
4
5
|
*
|
|
5
6
|
* @param element the target object
|
|
6
7
|
* @returns the query result
|
|
7
8
|
*/
|
|
8
|
-
const isHTMLElement = (element?:
|
|
9
|
+
const isHTMLElement = (element?: HTMLElement | Node): element is HTMLElement =>
|
|
10
|
+
(element && element.nodeType === 1) || false;
|
|
9
11
|
export default isHTMLElement;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Check if a target element is an `<img>`.
|
|
3
|
+
*
|
|
3
4
|
* @param element the target element
|
|
4
5
|
* @returns the query result
|
|
5
6
|
*/
|
|
6
|
-
const isHTMLImageElement = (element?:
|
|
7
|
+
const isHTMLImageElement = (element?: HTMLImageElement): element is HTMLImageElement =>
|
|
7
8
|
(element && element.tagName === 'IMG') || false;
|
|
8
9
|
|
|
9
10
|
export default isHTMLImageElement;
|
package/src/is/isJSON.ts
CHANGED
package/src/is/isMap.ts
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
* @param obj the target object
|
|
5
5
|
* @returns the query result
|
|
6
6
|
*/
|
|
7
|
-
const isMap =
|
|
7
|
+
const isMap = <T extends Map<any, any>>(obj?: T): obj is T =>
|
|
8
|
+
(obj && obj.constructor.name === 'Map') || false;
|
|
8
9
|
export default isMap;
|
package/src/is/isMedia.ts
CHANGED
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
* `<img>`, `<video>` or `<canvas>`.
|
|
4
4
|
*
|
|
5
5
|
* *Tooltip* / *Popover* works different with media elements.
|
|
6
|
+
*
|
|
6
7
|
* @param element the target element
|
|
7
8
|
* @returns the query result
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
|
-
const isMedia = (
|
|
11
|
+
const isMedia = (
|
|
12
|
+
element?: SVGElement | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement,
|
|
13
|
+
): element is SVGElement | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement =>
|
|
11
14
|
(element &&
|
|
12
15
|
element.nodeType === 1 &&
|
|
13
|
-
['SVG', 'Image', 'Video', 'Canvas'].some(
|
|
16
|
+
['SVG', 'Image', 'Video', 'Canvas'].some(s => element.constructor.name.includes(s))) ||
|
|
14
17
|
false;
|
|
15
18
|
|
|
16
19
|
export default isMedia;
|
package/src/is/isNode.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @returns the query result
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const isNode = (node?:
|
|
9
|
-
(node && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].some(
|
|
8
|
+
const isNode = (node?: Node): node is Node =>
|
|
9
|
+
(node && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].some(x => node.nodeType === x)) || false;
|
|
10
10
|
|
|
11
11
|
export default isNode;
|
package/src/is/isNodeList.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @param obj the target object
|
|
6
6
|
* @returns the query result
|
|
7
7
|
*/
|
|
8
|
-
const isNodeList = (obj?:
|
|
8
|
+
const isNodeList = (obj?: NodeList): obj is NodeList =>
|
|
9
|
+
(obj && obj.constructor.name === 'NodeList') || false;
|
|
9
10
|
|
|
10
11
|
export default isNodeList;
|
package/src/is/isNumber.ts
CHANGED