@thednp/shorty 2.0.4 → 2.0.6
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 +5 -5
- package/dist/shorty.cjs +18 -1
- package/dist/shorty.cjs.map +1 -1
- package/dist/shorty.d.ts +31 -18
- package/dist/shorty.js +18 -1
- package/dist/shorty.js.map +1 -1
- package/dist/shorty.mjs +451 -386
- package/dist/shorty.mjs.map +1 -1
- package/dts.config.ts +1 -7
- package/package.json +16 -28
- 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 +6 -4
- package/src/boolean/isFirefox.ts +2 -2
- package/src/boolean/isMobile.ts +4 -4
- package/src/boolean/support3DTransform.ts +4 -2
- package/src/boolean/supportAnimation.ts +4 -2
- package/src/boolean/supportPassive.ts +6 -6
- package/src/boolean/supportTouch.ts +3 -2
- package/src/boolean/supportTransform.ts +4 -2
- package/src/boolean/supportTransition.ts +4 -2
- 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 +9 -6
- package/src/get/getUID.ts +1 -1
- package/src/get/getWindow.ts +2 -2
- package/src/index.ts +425 -415
- 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 +8 -5
- package/src/misc/createElement.ts +6 -4
- package/src/misc/createElementNS.ts +3 -3
- package/src/misc/data.ts +4 -7
- package/src/misc/dispatchEvent.ts +2 -1
- package/src/misc/distinct.ts +2 -1
- package/src/misc/emulateAnimationEnd.ts +12 -9
- package/src/misc/emulateTransitionEnd.ts +11 -8
- package/src/misc/focus.ts +2 -1
- package/src/misc/focusTrap.ts +67 -0
- package/src/misc/getInstance.ts +1 -1
- package/src/misc/normalizeOptions.ts +16 -13
- package/src/misc/normalizeValue.ts +8 -6
- package/src/misc/setElementStyle.ts +9 -6
- package/src/misc/timer.ts +15 -8
- package/src/selectors/closest.ts +2 -2
- package/src/selectors/getCustomElements.ts +4 -5
- package/src/selectors/getElementById.ts +3 -3
- package/src/selectors/getElementsByClassName.ts +5 -5
- package/src/selectors/getElementsByTagName.ts +7 -5
- package/src/selectors/matches.ts +2 -1
- package/src/selectors/querySelector.ts +9 -6
- package/src/selectors/querySelectorAll.ts +6 -3
- 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/focusableSelector.ts +4 -0
- 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 +2 -2
- package/test/fixtures/getExampleDom.ts +12 -8
- package/test/is.test.ts +15 -11
- package/test/misc.test.ts +65 -17
- package/{vite.config.ts → vite.config.mts} +4 -8
- package/{vitest.config-ui.ts → vitest.config-ui.mts} +5 -0
- package/{vitest.config.ts → vitest.config.mts} +5 -0
package/dts.config.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
const packageJson = require("./package.json");
|
|
2
|
-
|
|
3
|
-
const getPackageName = () => {
|
|
4
|
-
return packageJson.name.includes('@') ? packageJson.name.split('/')[1] : packageJson.name;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
1
|
const config = {
|
|
8
2
|
entries: [
|
|
9
3
|
{
|
|
10
4
|
filePath: "./src/index.ts",
|
|
11
|
-
outFile: `./dist
|
|
5
|
+
outFile: `./dist/shorty.d.ts`,
|
|
12
6
|
noCheck: false,
|
|
13
7
|
output: {
|
|
14
8
|
exportReferencedTypes: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thednp/shorty",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "TypeScript shorties for the web",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/shorty.js",
|
|
@@ -32,27 +32,15 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/thednp/shorty",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^20.
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@vitest/
|
|
39
|
-
"@vitest/coverage-istanbul": "^2.1.1",
|
|
40
|
-
"@vitest/ui": "^2.1.1",
|
|
35
|
+
"@types/node": "^20.17.1",
|
|
36
|
+
"@vitest/browser": "^2.1.3",
|
|
37
|
+
"@vitest/coverage-istanbul": "^2.1.3",
|
|
38
|
+
"@vitest/ui": "^2.1.3",
|
|
41
39
|
"dts-bundle-generator": "^9.5.1",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"happy-dom": "^15.7.4",
|
|
47
|
-
"istanbul-lib-coverage": "^3.2.2",
|
|
48
|
-
"istanbul-lib-instrument": "^5.2.1",
|
|
49
|
-
"nyc": "^15.1.0",
|
|
50
|
-
"playwright": "^1.47.1",
|
|
51
|
-
"prettier": "^2.8.8",
|
|
52
|
-
"rimraf": "^5.0.10",
|
|
53
|
-
"typescript": "^5.6.2",
|
|
54
|
-
"vite": "^5.4.6",
|
|
55
|
-
"vitest": "^2.1.1"
|
|
40
|
+
"playwright": "^1.48.2",
|
|
41
|
+
"typescript": "^5.6.3",
|
|
42
|
+
"vite": "^5.4.10",
|
|
43
|
+
"vitest": "^2.1.3"
|
|
56
44
|
},
|
|
57
45
|
"engines": {
|
|
58
46
|
"node": ">=16",
|
|
@@ -60,16 +48,16 @@
|
|
|
60
48
|
},
|
|
61
49
|
"scripts": {
|
|
62
50
|
"pre-test": "pnpm clean-coverage",
|
|
63
|
-
"badges": "npx -p dependency-version-badge update-badge typescript
|
|
64
|
-
"test": "pnpm pre-test && vitest --config vitest.config.
|
|
65
|
-
"test-ui": "pnpm pre-test && vitest --config vitest.config-ui.
|
|
51
|
+
"badges": "npx -p dependency-version-badge update-badge typescript vitest vite",
|
|
52
|
+
"test": "pnpm pre-test && vitest --config vitest.config.mts",
|
|
53
|
+
"test-ui": "pnpm pre-test && vitest --config vitest.config-ui.mts",
|
|
66
54
|
"clean-coverage": "rm -rf coverage .nyc_output",
|
|
67
|
-
"format": "
|
|
55
|
+
"format": "deno fmt src",
|
|
68
56
|
"lint": "pnpm lint:ts && pnpm check:ts",
|
|
69
|
-
"lint:ts": "
|
|
70
|
-
"fix:ts": "
|
|
57
|
+
"lint:ts": "deno lint src",
|
|
58
|
+
"fix:ts": "deno lint src --fix",
|
|
71
59
|
"check:ts": "tsc -noEmit",
|
|
72
|
-
"build": "
|
|
60
|
+
"build": "vite build && pnpm dts",
|
|
73
61
|
"dts": "dts-bundle-generator --config ./dts.config.ts"
|
|
74
62
|
}
|
|
75
63
|
}
|
package/src/attr/hasAttribute.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @param att attribute name
|
|
6
6
|
* @returns the query result
|
|
7
7
|
*/
|
|
8
|
-
const hasAttribute = (element: HTMLElement, att: string): boolean =>
|
|
8
|
+
const hasAttribute = (element: HTMLElement, att: string): boolean =>
|
|
9
|
+
element.hasAttribute(att);
|
|
9
10
|
|
|
10
11
|
export default hasAttribute;
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
* @param att attribute name
|
|
7
7
|
* @returns the query result
|
|
8
8
|
*/
|
|
9
|
-
const hasAttributeNS = (
|
|
10
|
-
|
|
9
|
+
const hasAttributeNS = (
|
|
10
|
+
ns: string,
|
|
11
|
+
element: HTMLElement,
|
|
12
|
+
att: string,
|
|
13
|
+
): boolean => element.hasAttributeNS(ns, att);
|
|
11
14
|
|
|
12
15
|
export default hasAttributeNS;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @param element target element
|
|
5
5
|
* @param att attribute name
|
|
6
6
|
*/
|
|
7
|
-
const removeAttribute = (element: HTMLElement, att: string): void =>
|
|
7
|
+
const removeAttribute = (element: HTMLElement, att: string): void =>
|
|
8
|
+
element.removeAttribute(att);
|
|
8
9
|
|
|
9
10
|
export default removeAttribute;
|
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* @param element target element
|
|
6
6
|
* @param att attribute name
|
|
7
7
|
*/
|
|
8
|
-
const removeAttributeNS = (
|
|
9
|
-
|
|
8
|
+
const removeAttributeNS = (
|
|
9
|
+
ns: string,
|
|
10
|
+
element: HTMLElement,
|
|
11
|
+
att: string,
|
|
12
|
+
): void => element.removeAttributeNS(ns, att);
|
|
10
13
|
|
|
11
14
|
export default removeAttributeNS;
|
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
* @param att attribute name
|
|
7
7
|
* @param value attribute value
|
|
8
8
|
*/
|
|
9
|
-
const setAttributeNS = (
|
|
10
|
-
|
|
9
|
+
const setAttributeNS = (
|
|
10
|
+
ns: string,
|
|
11
|
+
element: HTMLElement,
|
|
12
|
+
att: string,
|
|
13
|
+
value: string,
|
|
14
|
+
): void => element.setAttributeNS(ns, att, value);
|
|
11
15
|
|
|
12
16
|
export default setAttributeNS;
|
package/src/boolean/isApple.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { NavigatorUABrand } from
|
|
2
|
-
import userAgentData from
|
|
3
|
-
import userAgent from
|
|
1
|
+
import type { NavigatorUABrand } from "../interface/navigatorUA";
|
|
2
|
+
import userAgentData from "../strings/userAgentData";
|
|
3
|
+
import userAgent from "../strings/userAgent";
|
|
4
4
|
|
|
5
5
|
const appleBrands = /(iPhone|iPod|iPad)/;
|
|
6
6
|
|
|
@@ -8,7 +8,9 @@ const appleBrands = /(iPhone|iPod|iPad)/;
|
|
|
8
8
|
* A global `boolean` for Apple browsers.
|
|
9
9
|
*/
|
|
10
10
|
const isApple: boolean = userAgentData
|
|
11
|
-
? userAgentData.brands.some((x: NavigatorUABrand) =>
|
|
11
|
+
? userAgentData.brands.some((x: NavigatorUABrand) =>
|
|
12
|
+
appleBrands.test(x.brand)
|
|
13
|
+
)
|
|
12
14
|
: /* istanbul ignore next @preserve */ appleBrands.test(userAgent);
|
|
13
15
|
|
|
14
16
|
export default isApple;
|
package/src/boolean/isFirefox.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import userAgent from
|
|
1
|
+
import userAgent from "../strings/userAgent";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A global boolean for Gecko browsers. When writing this file,
|
|
5
5
|
* Gecko was not supporting `userAgentData`.
|
|
6
6
|
*/
|
|
7
7
|
const isFirefox = userAgent
|
|
8
|
-
? userAgent.includes(
|
|
8
|
+
? userAgent.includes("Firefox")
|
|
9
9
|
: /* istanbul ignore next @preserve */ false;
|
|
10
10
|
|
|
11
11
|
export default isFirefox;
|
package/src/boolean/isMobile.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import userAgentData from
|
|
2
|
-
import userAgent from
|
|
1
|
+
import userAgentData from "../strings/userAgentData";
|
|
2
|
+
import userAgent from "../strings/userAgent";
|
|
3
3
|
|
|
4
4
|
const mobileBrands = /iPhone|iPad|iPod|Android/i;
|
|
5
5
|
let isMobileCheck = false;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// istanbul ignore else @preserve
|
|
8
8
|
if (userAgentData) {
|
|
9
|
-
isMobileCheck = userAgentData.brands.some(x => mobileBrands.test(x.brand));
|
|
9
|
+
isMobileCheck = userAgentData.brands.some((x) => mobileBrands.test(x.brand));
|
|
10
10
|
} else {
|
|
11
11
|
isMobileCheck = mobileBrands.test(userAgent);
|
|
12
12
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import documentHead from
|
|
1
|
+
import documentHead from "../blocks/documentHead";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A global `boolean` for CSS3 3D transform support.
|
|
5
5
|
*/
|
|
6
|
-
const support3DTransform = [
|
|
6
|
+
const support3DTransform = ["webkitPerspective", "perspective"].some((p) =>
|
|
7
|
+
p in documentHead.style
|
|
8
|
+
);
|
|
7
9
|
|
|
8
10
|
export default support3DTransform;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import documentHead from
|
|
1
|
+
import documentHead from "../blocks/documentHead";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A global `boolean` for CSS3 animation support.
|
|
5
5
|
*/
|
|
6
|
-
const supportAnimation = [
|
|
6
|
+
const supportAnimation = ["webkitAnimation", "animation"].some((p) =>
|
|
7
|
+
p in documentHead.style
|
|
8
|
+
);
|
|
7
9
|
|
|
8
10
|
export default supportAnimation;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import DOMContentLoadedEvent from
|
|
2
|
-
import one from
|
|
3
|
-
import noop from
|
|
1
|
+
import DOMContentLoadedEvent from "../strings/DOMContentLoadedEvent";
|
|
2
|
+
import one from "../event/one";
|
|
3
|
+
import noop from "../misc/noop";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A global `boolean` for passive events support,
|
|
@@ -11,15 +11,15 @@ import noop from '../misc/noop';
|
|
|
11
11
|
const supportPassive = (() => {
|
|
12
12
|
let result = false;
|
|
13
13
|
try {
|
|
14
|
-
const opts = Object.defineProperty({},
|
|
14
|
+
const opts = Object.defineProperty({}, "passive", {
|
|
15
15
|
get: () => {
|
|
16
16
|
result = true;
|
|
17
17
|
return result;
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
|
-
|
|
20
|
+
// istanbul ignore next @preserve
|
|
21
21
|
one(document, DOMContentLoadedEvent, noop, opts);
|
|
22
|
-
} catch (
|
|
22
|
+
} catch (_e) {
|
|
23
23
|
// throw Error('Passive events are not supported');
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A global `boolean` for touch events support.
|
|
3
3
|
*/
|
|
4
|
-
const supportTouch =
|
|
5
|
-
|
|
4
|
+
const supportTouch = "ontouchstart" in window ||
|
|
5
|
+
/* istanbul ignore next @preserve */
|
|
6
|
+
"msMaxTouchPoints" in navigator;
|
|
6
7
|
|
|
7
8
|
export default supportTouch;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import documentHead from
|
|
1
|
+
import documentHead from "../blocks/documentHead";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A global `boolean` for CSS3 transform support.
|
|
5
5
|
*/
|
|
6
|
-
const supportTransform = [
|
|
6
|
+
const supportTransform = ["webkitTransform", "transform"].some((p) =>
|
|
7
|
+
p in documentHead.style
|
|
8
|
+
);
|
|
7
9
|
|
|
8
10
|
export default supportTransform;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import documentHead from
|
|
1
|
+
import documentHead from "../blocks/documentHead";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A global `boolean` for CSS3 transition support.
|
|
5
5
|
*/
|
|
6
|
-
const supportTransition = [
|
|
6
|
+
const supportTransition = ["webkitTransition", "transition"].some((p) =>
|
|
7
|
+
p in documentHead.style
|
|
8
|
+
);
|
|
7
9
|
|
|
8
10
|
export default supportTransition;
|
package/src/event/off.ts
CHANGED
|
@@ -8,7 +8,11 @@ const off = <T extends EventTarget, L = EventListener>(
|
|
|
8
8
|
options?: AddEventListenerOptions,
|
|
9
9
|
) => {
|
|
10
10
|
const ops = options || false;
|
|
11
|
-
element.removeEventListener(
|
|
11
|
+
element.removeEventListener(
|
|
12
|
+
eventName,
|
|
13
|
+
listener as EventListenerOrEventListenerObject,
|
|
14
|
+
ops,
|
|
15
|
+
);
|
|
12
16
|
};
|
|
13
17
|
|
|
14
18
|
export default off;
|
package/src/event/on.ts
CHANGED
|
@@ -8,7 +8,11 @@ const on = <T extends EventTarget, L = EventListener>(
|
|
|
8
8
|
options?: AddEventListenerOptions,
|
|
9
9
|
) => {
|
|
10
10
|
const ops = options || false;
|
|
11
|
-
element.addEventListener(
|
|
11
|
+
element.addEventListener(
|
|
12
|
+
eventName,
|
|
13
|
+
listener as EventListenerOrEventListenerObject,
|
|
14
|
+
ops,
|
|
15
|
+
);
|
|
12
16
|
};
|
|
13
17
|
|
|
14
18
|
export default on;
|
package/src/event/one.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import on from
|
|
2
|
-
import off from
|
|
3
|
-
import { NativeEventHandler } from
|
|
1
|
+
import on from "./on";
|
|
2
|
+
import off from "./off";
|
|
3
|
+
import { NativeEventHandler } from "../interface/event";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Add an `eventListener` to an `EventTarget`
|
|
@@ -13,8 +13,8 @@ const one = <T extends EventTarget, L = EventListener>(
|
|
|
13
13
|
options?: AddEventListenerOptions,
|
|
14
14
|
) => {
|
|
15
15
|
/** Wrap the listener for easy on -> off */
|
|
16
|
-
const handlerWrapper: NativeEventHandler<T> = e => {
|
|
17
|
-
|
|
16
|
+
const handlerWrapper: NativeEventHandler<T> = (e) => {
|
|
17
|
+
// istanbul ignore else @preserve
|
|
18
18
|
if (e.target === element || e.currentTarget === element) {
|
|
19
19
|
(listener as NativeEventHandler<T>).apply(element, [e]);
|
|
20
20
|
off(element, eventName, handlerWrapper, options);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import isHTMLElement from
|
|
2
|
-
import type { BoundingClientRect } from
|
|
1
|
+
import isHTMLElement from "../is/isHTMLElement";
|
|
2
|
+
import type { BoundingClientRect } from "../interface/boundingClientRect";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the bounding client rect of a target `HTMLElement`.
|
|
@@ -14,14 +14,19 @@ const getBoundingClientRect = (
|
|
|
14
14
|
element: HTMLElement,
|
|
15
15
|
includeScale?: boolean,
|
|
16
16
|
): BoundingClientRect => {
|
|
17
|
-
const { width, height, top, right, bottom, left } = element
|
|
17
|
+
const { width, height, top, right, bottom, left } = element
|
|
18
|
+
.getBoundingClientRect();
|
|
18
19
|
let scaleX = 1;
|
|
19
20
|
let scaleY = 1;
|
|
20
21
|
|
|
21
22
|
if (includeScale && isHTMLElement(element)) {
|
|
22
23
|
const { offsetWidth, offsetHeight } = element;
|
|
23
|
-
scaleX = offsetWidth > 0
|
|
24
|
-
|
|
24
|
+
scaleX = offsetWidth > 0
|
|
25
|
+
? Math.round(width) / offsetWidth
|
|
26
|
+
: /* istanbul ignore next @preserve */ 1;
|
|
27
|
+
scaleY = offsetHeight > 0
|
|
28
|
+
? Math.round(height) / offsetHeight
|
|
29
|
+
: /* istanbul ignore next @preserve */ 1;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
return {
|
package/src/get/getDocument.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import isNode from
|
|
2
|
-
import isWindow from
|
|
3
|
-
import isDocument from
|
|
1
|
+
import isNode from "../is/isNode";
|
|
2
|
+
import isWindow from "../is/isWindow";
|
|
3
|
+
import isDocument from "../is/isDocument";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the `document` or the `#document` element.
|
|
@@ -18,7 +18,7 @@ const getDocument = (node?: Node | Document | Window): Document => {
|
|
|
18
18
|
// node instanceof Node
|
|
19
19
|
if (isNode(node)) return node.ownerDocument as Document;
|
|
20
20
|
// node is undefined | NULL
|
|
21
|
-
return
|
|
21
|
+
return globalThis.document;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export default getDocument;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import getDocument from
|
|
1
|
+
import getDocument from "./getDocument";
|
|
2
2
|
/**
|
|
3
3
|
* Returns the `document.head` or the `<head>` element.
|
|
4
4
|
*
|
|
5
5
|
* @param node the reference node
|
|
6
6
|
* @returns the `<head>` of the node's parent document
|
|
7
7
|
*/
|
|
8
|
-
const getDocumentHead = (
|
|
8
|
+
const getDocumentHead = (
|
|
9
|
+
node?: Node | Document | Window,
|
|
10
|
+
): HTMLElement & HTMLHeadElement => {
|
|
9
11
|
return getDocument(node).head;
|
|
10
12
|
};
|
|
11
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import animationDelay from
|
|
2
|
-
import animationName from
|
|
3
|
-
import getElementStyle from
|
|
1
|
+
import animationDelay from "../strings/animationDelay";
|
|
2
|
+
import animationName from "../strings/animationName";
|
|
3
|
+
import getElementStyle from "./getElementStyle";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Utility to get the computed `animationDelay`
|
|
@@ -12,9 +12,12 @@ import getElementStyle from './getElementStyle';
|
|
|
12
12
|
const getElementAnimationDelay = (element: HTMLElement): number => {
|
|
13
13
|
const propertyValue = getElementStyle(element, animationName);
|
|
14
14
|
const durationValue = getElementStyle(element, animationDelay);
|
|
15
|
-
const durationScale = durationValue.includes(
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const durationScale = durationValue.includes("ms")
|
|
16
|
+
? /* istanbul ignore next */ 1
|
|
17
|
+
: 1000;
|
|
18
|
+
const duration = propertyValue && propertyValue !== "none"
|
|
19
|
+
? parseFloat(durationValue) * durationScale
|
|
20
|
+
: 0;
|
|
18
21
|
|
|
19
22
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
20
23
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import animationDuration from
|
|
2
|
-
import animationName from
|
|
3
|
-
import getElementStyle from
|
|
1
|
+
import animationDuration from "../strings/animationDuration";
|
|
2
|
+
import animationName from "../strings/animationName";
|
|
3
|
+
import getElementStyle from "./getElementStyle";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Utility to get the computed `animationDuration`
|
|
@@ -12,9 +12,12 @@ import getElementStyle from './getElementStyle';
|
|
|
12
12
|
const getElementAnimationDuration = (element: HTMLElement): number => {
|
|
13
13
|
const propertyValue = getElementStyle(element, animationName);
|
|
14
14
|
const durationValue = getElementStyle(element, animationDuration);
|
|
15
|
-
const durationScale = durationValue.includes(
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const durationScale = durationValue.includes("ms")
|
|
16
|
+
? /* istanbul ignore next */ 1
|
|
17
|
+
: 1000;
|
|
18
|
+
const duration = propertyValue && propertyValue !== "none"
|
|
19
|
+
? parseFloat(durationValue) * durationScale
|
|
20
|
+
: 0;
|
|
18
21
|
|
|
19
22
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
20
23
|
};
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
const getElementStyle = (element: HTMLElement, property: string): string => {
|
|
15
15
|
const computedStyle = getComputedStyle(element);
|
|
16
16
|
const prop = property
|
|
17
|
-
.replace(
|
|
18
|
-
.replace(/([A-Z])/g,
|
|
17
|
+
.replace("webkit", "Webkit")
|
|
18
|
+
.replace(/([A-Z])/g, "-$1")
|
|
19
19
|
.toLowerCase();
|
|
20
20
|
|
|
21
21
|
// modern browsers only
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import transitionDelay from
|
|
2
|
-
import transitionProperty from
|
|
3
|
-
import getElementStyle from
|
|
1
|
+
import transitionDelay from "../strings/transitionDelay";
|
|
2
|
+
import transitionProperty from "../strings/transitionProperty";
|
|
3
|
+
import getElementStyle from "./getElementStyle";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Utility to get the computed `transitionDelay`
|
|
@@ -12,11 +12,12 @@ import getElementStyle from './getElementStyle';
|
|
|
12
12
|
const getElementTransitionDelay = (element: HTMLElement): number => {
|
|
13
13
|
const propertyValue = getElementStyle(element, transitionProperty);
|
|
14
14
|
const delayValue = getElementStyle(element, transitionDelay);
|
|
15
|
-
const delayScale = delayValue.includes(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const delayScale = delayValue.includes("ms")
|
|
16
|
+
? /* istanbul ignore next */ 1
|
|
17
|
+
: 1000;
|
|
18
|
+
const duration = propertyValue && propertyValue !== "none"
|
|
19
|
+
? parseFloat(delayValue) * delayScale
|
|
20
|
+
: /* istanbul ignore next */ 0;
|
|
20
21
|
|
|
21
22
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
22
23
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import transitionDuration from
|
|
2
|
-
import transitionProperty from
|
|
3
|
-
import getElementStyle from
|
|
1
|
+
import transitionDuration from "../strings/transitionDuration";
|
|
2
|
+
import transitionProperty from "../strings/transitionProperty";
|
|
3
|
+
import getElementStyle from "./getElementStyle";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Utility to get the computed `transitionDuration`
|
|
@@ -12,11 +12,12 @@ import getElementStyle from './getElementStyle';
|
|
|
12
12
|
const getElementTransitionDuration = (element: HTMLElement): number => {
|
|
13
13
|
const propertyValue = getElementStyle(element, transitionProperty);
|
|
14
14
|
const durationValue = getElementStyle(element, transitionDuration);
|
|
15
|
-
const durationScale = durationValue.includes(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const durationScale = durationValue.includes("ms")
|
|
16
|
+
? /* istanbul ignore next */ 1
|
|
17
|
+
: 1000;
|
|
18
|
+
const duration = propertyValue && propertyValue !== "none"
|
|
19
|
+
? parseFloat(durationValue) * durationScale
|
|
20
|
+
: /* istanbul ignore next */ 0;
|
|
20
21
|
|
|
21
22
|
return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
|
|
22
23
|
};
|
package/src/get/getNodeScroll.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import isWindow from
|
|
1
|
+
import isWindow from "../is/isWindow";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns an `{x,y}` object with the target
|
|
@@ -9,7 +9,9 @@ import isWindow from '../is/isWindow';
|
|
|
9
9
|
* @param element target node / element
|
|
10
10
|
* @returns the scroll tuple
|
|
11
11
|
*/
|
|
12
|
-
const getNodeScroll = (
|
|
12
|
+
const getNodeScroll = (
|
|
13
|
+
element: HTMLElement | Window,
|
|
14
|
+
): { x: number; y: number } => {
|
|
13
15
|
const isWin = isWindow(element);
|
|
14
16
|
const x = isWin ? element.scrollX : element.scrollLeft;
|
|
15
17
|
const y = isWin ? element.scrollY : element.scrollTop;
|
package/src/get/getParentNode.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import getDocumentElement from
|
|
2
|
-
import isShadowRoot from
|
|
3
|
-
import isHTMLElement from
|
|
4
|
-
import isNode from
|
|
1
|
+
import getDocumentElement from "./getDocumentElement";
|
|
2
|
+
import isShadowRoot from "../is/isShadowRoot";
|
|
3
|
+
import isHTMLElement from "../is/isHTMLElement";
|
|
4
|
+
import isNode from "../is/isNode";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns the `parentNode` also going through `ShadowRoot`.
|
|
@@ -12,7 +12,7 @@ import isNode from '../is/isNode';
|
|
|
12
12
|
* @returns {Node} the apropriate parent node
|
|
13
13
|
*/
|
|
14
14
|
const getParentNode = (node: Node): Node | ParentNode => {
|
|
15
|
-
if (node.nodeName ===
|
|
15
|
+
if (node.nodeName === "HTML") {
|
|
16
16
|
return node;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { OffsetRect } from
|
|
2
|
-
import isScaledElement from
|
|
3
|
-
import isHTMLElement from
|
|
4
|
-
import getBoundingClientRect from
|
|
1
|
+
import type { OffsetRect } from "../interface/offsetRect";
|
|
2
|
+
import isScaledElement from "../is/isScaledElement";
|
|
3
|
+
import isHTMLElement from "../is/isHTMLElement";
|
|
4
|
+
import getBoundingClientRect from "./getBoundingClientRect";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns the rect relative to a given offset parent and its scroll position.
|
|
@@ -19,10 +19,13 @@ const getRectRelativeToOffsetParent = (
|
|
|
19
19
|
scroll: { x: number; y: number },
|
|
20
20
|
): OffsetRect => {
|
|
21
21
|
const isParentAnElement = isHTMLElement(offsetParent);
|
|
22
|
-
const rect = getBoundingClientRect(
|
|
22
|
+
const rect = getBoundingClientRect(
|
|
23
|
+
element,
|
|
24
|
+
isParentAnElement && isScaledElement(offsetParent),
|
|
25
|
+
);
|
|
23
26
|
const offsets = { x: 0, y: 0 };
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
// istanbul ignore else @preserve
|
|
26
29
|
if (isParentAnElement) {
|
|
27
30
|
const offsetRect = getBoundingClientRect(offsetParent, true);
|
|
28
31
|
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
package/src/get/getUID.ts
CHANGED