@yamada-ui/utils 1.5.0 → 1.5.1-dev-20240917064938
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/dist/array.d.mts +1 -1
- package/dist/array.d.ts +1 -1
- package/dist/array.js +3 -1
- package/dist/array.js.map +1 -1
- package/dist/array.mjs +1 -1
- package/dist/assertion.d.mts +14 -14
- package/dist/assertion.d.ts +14 -14
- package/dist/assertion.js +44 -16
- package/dist/assertion.js.map +1 -1
- package/dist/assertion.mjs +1 -1
- package/dist/calc.d.mts +12 -7
- package/dist/calc.d.ts +12 -7
- package/dist/calc.js +17 -7
- package/dist/calc.js.map +1 -1
- package/dist/calc.mjs +1 -1
- package/dist/{chunk-ZFE4ZWCP.mjs → chunk-2AWPBKLQ.mjs} +68 -47
- package/dist/chunk-2AWPBKLQ.mjs.map +1 -0
- package/dist/chunk-5EG6NSMV.mjs +9 -0
- package/dist/chunk-5EG6NSMV.mjs.map +1 -0
- package/dist/{chunk-I5E5UXSE.mjs → chunk-7XL7BPER.mjs} +52 -44
- package/dist/chunk-7XL7BPER.mjs.map +1 -0
- package/dist/{chunk-KT4SLZO6.mjs → chunk-7XRVZGET.mjs} +18 -12
- package/dist/chunk-7XRVZGET.mjs.map +1 -0
- package/dist/{chunk-S35WPDIT.mjs → chunk-AF6MSVQN.mjs} +75 -41
- package/dist/chunk-AF6MSVQN.mjs.map +1 -0
- package/dist/chunk-APJY76CK.mjs +9 -0
- package/dist/chunk-APJY76CK.mjs.map +1 -0
- package/dist/{chunk-L56KWSQO.mjs → chunk-OM7WYVSS.mjs} +18 -8
- package/dist/chunk-OM7WYVSS.mjs.map +1 -0
- package/dist/chunk-QTCZ2LU5.mjs +65 -0
- package/dist/chunk-QTCZ2LU5.mjs.map +1 -0
- package/dist/chunk-RCW53QOG.mjs +31 -0
- package/dist/chunk-RCW53QOG.mjs.map +1 -0
- package/dist/chunk-TJ7CW2M5.mjs +365 -0
- package/dist/chunk-TJ7CW2M5.mjs.map +1 -0
- package/dist/{chunk-2AQWXBLU.mjs → chunk-WU6FTFUV.mjs} +15 -7
- package/dist/chunk-WU6FTFUV.mjs.map +1 -0
- package/dist/chunk-Z4AGSEWZ.mjs +63 -0
- package/dist/chunk-Z4AGSEWZ.mjs.map +1 -0
- package/dist/color.d.mts +24 -24
- package/dist/color.d.ts +24 -24
- package/dist/color.js +212 -158
- package/dist/color.js.map +1 -1
- package/dist/color.mjs +3 -3
- package/dist/dom.d.mts +29 -29
- package/dist/dom.d.ts +29 -29
- package/dist/dom.js +79 -41
- package/dist/dom.js.map +1 -1
- package/dist/dom.mjs +2 -2
- package/dist/event.d.mts +13 -13
- package/dist/event.d.ts +13 -13
- package/dist/event.js +37 -23
- package/dist/event.js.map +1 -1
- package/dist/event.mjs +1 -1
- package/dist/function.d.mts +3 -3
- package/dist/function.d.ts +3 -3
- package/dist/function.js +19 -9
- package/dist/function.js.map +1 -1
- package/dist/function.mjs +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +531 -346
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -12
- package/dist/index.types.d.mts +8 -4
- package/dist/index.types.d.ts +8 -4
- package/dist/index.types.js.map +1 -1
- package/dist/module.d.mts +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.js +3 -1
- package/dist/module.js.map +1 -1
- package/dist/module.mjs +1 -1
- package/dist/number.d.mts +7 -7
- package/dist/number.d.ts +7 -7
- package/dist/number.js +17 -11
- package/dist/number.js.map +1 -1
- package/dist/number.mjs +1 -1
- package/dist/object.d.mts +19 -15
- package/dist/object.d.ts +19 -15
- package/dist/object.js +65 -47
- package/dist/object.js.map +1 -1
- package/dist/object.mjs +2 -2
- package/dist/react.d.mts +25 -35
- package/dist/react.d.ts +25 -35
- package/dist/react.js +78 -49
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +2 -2
- package/dist/string.d.mts +5 -5
- package/dist/string.d.ts +5 -5
- package/dist/string.js +14 -6
- package/dist/string.js.map +1 -1
- package/dist/string.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-2AQWXBLU.mjs.map +0 -1
- package/dist/chunk-5OUUTZYQ.mjs +0 -7
- package/dist/chunk-5OUUTZYQ.mjs.map +0 -1
- package/dist/chunk-I5E5UXSE.mjs.map +0 -1
- package/dist/chunk-KT4SLZO6.mjs.map +0 -1
- package/dist/chunk-L56KWSQO.mjs.map +0 -1
- package/dist/chunk-MMZ4T26E.mjs +0 -51
- package/dist/chunk-MMZ4T26E.mjs.map +0 -1
- package/dist/chunk-NBL5H4TH.mjs +0 -35
- package/dist/chunk-NBL5H4TH.mjs.map +0 -1
- package/dist/chunk-S35WPDIT.mjs.map +0 -1
- package/dist/chunk-VRHGQ632.mjs +0 -23
- package/dist/chunk-VRHGQ632.mjs.map +0 -1
- package/dist/chunk-WV6P7ZCI.mjs +0 -7
- package/dist/chunk-WV6P7ZCI.mjs.map +0 -1
- package/dist/chunk-ZFE4ZWCP.mjs.map +0 -1
- package/dist/chunk-ZMR5WZIP.mjs +0 -321
- package/dist/chunk-ZMR5WZIP.mjs.map +0 -1
package/dist/dom.d.mts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
|
|
3
|
-
declare
|
|
4
|
-
declare
|
|
5
|
-
declare
|
|
6
|
-
declare
|
|
7
|
-
declare
|
|
8
|
-
declare
|
|
9
|
-
declare
|
|
10
|
-
declare
|
|
11
|
-
declare
|
|
12
|
-
declare
|
|
13
|
-
declare
|
|
14
|
-
declare
|
|
15
|
-
declare
|
|
16
|
-
declare
|
|
17
|
-
declare
|
|
18
|
-
declare
|
|
3
|
+
declare function createdDom(): boolean;
|
|
4
|
+
declare function getPlatform(): string;
|
|
5
|
+
declare function vendor(v: RegExp): boolean;
|
|
6
|
+
declare function platform(v: RegExp): boolean;
|
|
7
|
+
declare function isMac(): boolean;
|
|
8
|
+
declare function isApple(): boolean;
|
|
9
|
+
declare function isSafari(): boolean;
|
|
10
|
+
declare function isElement(el: any): el is Element;
|
|
11
|
+
declare function isHTMLElement(el: any): el is HTMLElement;
|
|
12
|
+
declare function isHidden(el: HTMLElement): boolean;
|
|
13
|
+
declare function isDisabled(el: HTMLElement): boolean;
|
|
14
|
+
declare function hasTabIndex(el: HTMLElement): boolean;
|
|
15
|
+
declare function isContentEditable(el: HTMLElement): boolean;
|
|
16
|
+
declare function isContains(parent: HTMLElement | null, child: HTMLElement | null): boolean | undefined;
|
|
17
|
+
declare function getPx(value: string | number | undefined): number;
|
|
18
|
+
declare function getEventRelatedTarget(ev: React__default.FocusEvent | React__default.MouseEvent): HTMLElement | null;
|
|
19
19
|
type Booleanish = boolean | "true" | "false";
|
|
20
|
-
declare
|
|
21
|
-
declare
|
|
22
|
-
|
|
20
|
+
declare function dataAttr(condition: boolean | undefined): Booleanish;
|
|
21
|
+
declare function ariaAttr(condition: boolean | undefined): boolean | undefined;
|
|
22
|
+
interface FocusableElement {
|
|
23
23
|
focus: (options?: FocusOptions) => void;
|
|
24
|
-
}
|
|
25
|
-
declare
|
|
26
|
-
declare
|
|
27
|
-
declare
|
|
28
|
-
declare
|
|
29
|
-
declare
|
|
30
|
-
declare
|
|
31
|
-
declare
|
|
32
|
-
declare
|
|
33
|
-
declare
|
|
24
|
+
}
|
|
25
|
+
declare function getAllFocusable<T extends HTMLElement>(container: T): T[];
|
|
26
|
+
declare function isFocusable(el: HTMLElement): boolean;
|
|
27
|
+
declare function hasNegativeTabIndex(el: HTMLElement): boolean;
|
|
28
|
+
declare function isTabbable(el?: HTMLElement | null): boolean;
|
|
29
|
+
declare function isTouchDevice(): boolean;
|
|
30
|
+
declare function getOwnerWindow(node?: Element | null): Window & typeof globalThis;
|
|
31
|
+
declare function getOwnerDocument(el?: Element | null): Document;
|
|
32
|
+
declare function getActiveElement(el?: HTMLElement): HTMLElement;
|
|
33
|
+
declare function isActiveElement(el: HTMLElement): boolean;
|
|
34
34
|
|
|
35
35
|
export { type FocusableElement, ariaAttr, createdDom, dataAttr, getActiveElement, getAllFocusable, getEventRelatedTarget, getOwnerDocument, getOwnerWindow, getPlatform, getPx, hasNegativeTabIndex, hasTabIndex, isActiveElement, isApple, isContains, isContentEditable, isDisabled, isElement, isFocusable, isHTMLElement, isHidden, isMac, isSafari, isTabbable, isTouchDevice, platform, vendor };
|
package/dist/dom.d.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
|
|
3
|
-
declare
|
|
4
|
-
declare
|
|
5
|
-
declare
|
|
6
|
-
declare
|
|
7
|
-
declare
|
|
8
|
-
declare
|
|
9
|
-
declare
|
|
10
|
-
declare
|
|
11
|
-
declare
|
|
12
|
-
declare
|
|
13
|
-
declare
|
|
14
|
-
declare
|
|
15
|
-
declare
|
|
16
|
-
declare
|
|
17
|
-
declare
|
|
18
|
-
declare
|
|
3
|
+
declare function createdDom(): boolean;
|
|
4
|
+
declare function getPlatform(): string;
|
|
5
|
+
declare function vendor(v: RegExp): boolean;
|
|
6
|
+
declare function platform(v: RegExp): boolean;
|
|
7
|
+
declare function isMac(): boolean;
|
|
8
|
+
declare function isApple(): boolean;
|
|
9
|
+
declare function isSafari(): boolean;
|
|
10
|
+
declare function isElement(el: any): el is Element;
|
|
11
|
+
declare function isHTMLElement(el: any): el is HTMLElement;
|
|
12
|
+
declare function isHidden(el: HTMLElement): boolean;
|
|
13
|
+
declare function isDisabled(el: HTMLElement): boolean;
|
|
14
|
+
declare function hasTabIndex(el: HTMLElement): boolean;
|
|
15
|
+
declare function isContentEditable(el: HTMLElement): boolean;
|
|
16
|
+
declare function isContains(parent: HTMLElement | null, child: HTMLElement | null): boolean | undefined;
|
|
17
|
+
declare function getPx(value: string | number | undefined): number;
|
|
18
|
+
declare function getEventRelatedTarget(ev: React__default.FocusEvent | React__default.MouseEvent): HTMLElement | null;
|
|
19
19
|
type Booleanish = boolean | "true" | "false";
|
|
20
|
-
declare
|
|
21
|
-
declare
|
|
22
|
-
|
|
20
|
+
declare function dataAttr(condition: boolean | undefined): Booleanish;
|
|
21
|
+
declare function ariaAttr(condition: boolean | undefined): boolean | undefined;
|
|
22
|
+
interface FocusableElement {
|
|
23
23
|
focus: (options?: FocusOptions) => void;
|
|
24
|
-
}
|
|
25
|
-
declare
|
|
26
|
-
declare
|
|
27
|
-
declare
|
|
28
|
-
declare
|
|
29
|
-
declare
|
|
30
|
-
declare
|
|
31
|
-
declare
|
|
32
|
-
declare
|
|
33
|
-
declare
|
|
24
|
+
}
|
|
25
|
+
declare function getAllFocusable<T extends HTMLElement>(container: T): T[];
|
|
26
|
+
declare function isFocusable(el: HTMLElement): boolean;
|
|
27
|
+
declare function hasNegativeTabIndex(el: HTMLElement): boolean;
|
|
28
|
+
declare function isTabbable(el?: HTMLElement | null): boolean;
|
|
29
|
+
declare function isTouchDevice(): boolean;
|
|
30
|
+
declare function getOwnerWindow(node?: Element | null): Window & typeof globalThis;
|
|
31
|
+
declare function getOwnerDocument(el?: Element | null): Document;
|
|
32
|
+
declare function getActiveElement(el?: HTMLElement): HTMLElement;
|
|
33
|
+
declare function isActiveElement(el: HTMLElement): boolean;
|
|
34
34
|
|
|
35
35
|
export { type FocusableElement, ariaAttr, createdDom, dataAttr, getActiveElement, getAllFocusable, getEventRelatedTarget, getOwnerDocument, getOwnerWindow, getPlatform, getPx, hasNegativeTabIndex, hasTabIndex, isActiveElement, isApple, isContains, isContentEditable, isDisabled, isElement, isFocusable, isHTMLElement, isHidden, isMac, isSafari, isTabbable, isTouchDevice, platform, vendor };
|
package/dist/dom.js
CHANGED
|
@@ -51,42 +51,66 @@ __export(dom_exports, {
|
|
|
51
51
|
module.exports = __toCommonJS(dom_exports);
|
|
52
52
|
|
|
53
53
|
// src/assertion.ts
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
function isNumber(value) {
|
|
55
|
+
return typeof value === "number";
|
|
56
|
+
}
|
|
57
|
+
function isUndefined(value) {
|
|
58
|
+
return typeof value === "undefined" && value === void 0;
|
|
59
|
+
}
|
|
56
60
|
|
|
57
61
|
// src/dom.ts
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
function createdDom() {
|
|
63
|
+
return !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
64
|
+
}
|
|
65
|
+
function getPlatform() {
|
|
60
66
|
var _a, _b;
|
|
61
67
|
return (_b = (_a = navigator.userAgentData) == null ? void 0 : _a.platform) != null ? _b : navigator.platform;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
}
|
|
69
|
+
function vendor(v) {
|
|
70
|
+
return createdDom() && v.test(navigator.vendor);
|
|
71
|
+
}
|
|
72
|
+
function platform(v) {
|
|
73
|
+
return createdDom() && v.test(getPlatform());
|
|
74
|
+
}
|
|
75
|
+
function isMac() {
|
|
76
|
+
return platform(/^mac/i);
|
|
77
|
+
}
|
|
78
|
+
function isApple() {
|
|
79
|
+
return platform(/mac|iphone|ipad|ipod/i);
|
|
80
|
+
}
|
|
81
|
+
function isSafari() {
|
|
82
|
+
return isApple() && vendor(/apple/i);
|
|
83
|
+
}
|
|
84
|
+
function isElement(el) {
|
|
85
|
+
return el != null && typeof el == "object" && "nodeType" in el && el.nodeType === Node.ELEMENT_NODE;
|
|
86
|
+
}
|
|
87
|
+
function isHTMLElement(el) {
|
|
70
88
|
var _a;
|
|
71
89
|
if (!isElement(el)) return false;
|
|
72
90
|
const win = (_a = el.ownerDocument.defaultView) != null ? _a : window;
|
|
73
91
|
return el instanceof win.HTMLElement;
|
|
74
|
-
}
|
|
75
|
-
|
|
92
|
+
}
|
|
93
|
+
function isHidden(el) {
|
|
76
94
|
if (el.parentElement && isHidden(el.parentElement)) return true;
|
|
77
95
|
return el.hidden;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
}
|
|
97
|
+
function isDisabled(el) {
|
|
98
|
+
return Boolean(el.getAttribute("disabled")) === true || Boolean(el.getAttribute("data-disabled")) === true || Boolean(el.getAttribute("aria-disabled")) === true;
|
|
99
|
+
}
|
|
100
|
+
function isVisible(el) {
|
|
101
|
+
return el.offsetWidth > 0 && el.offsetHeight > 0;
|
|
102
|
+
}
|
|
103
|
+
function hasTabIndex(el) {
|
|
104
|
+
return el.hasAttribute("tabindex");
|
|
105
|
+
}
|
|
106
|
+
function isContentEditable(el) {
|
|
83
107
|
const value = el.getAttribute("contenteditable");
|
|
84
108
|
return value !== "false" && value != null;
|
|
85
|
-
}
|
|
86
|
-
|
|
109
|
+
}
|
|
110
|
+
function isContains(parent, child) {
|
|
87
111
|
return parent === child || (parent == null ? void 0 : parent.contains(child));
|
|
88
|
-
}
|
|
89
|
-
|
|
112
|
+
}
|
|
113
|
+
function getPx(value) {
|
|
90
114
|
if (isNumber(value)) return value;
|
|
91
115
|
if (isUndefined(value)) return 0;
|
|
92
116
|
if (value.includes("px")) return parseFloat(value);
|
|
@@ -98,13 +122,17 @@ var getPx = (value) => {
|
|
|
98
122
|
if (!isNaN(computedFontSize)) fontSize = computedFontSize;
|
|
99
123
|
}
|
|
100
124
|
return parseFloat(value) * fontSize;
|
|
101
|
-
}
|
|
102
|
-
|
|
125
|
+
}
|
|
126
|
+
function getEventRelatedTarget(ev) {
|
|
103
127
|
var _a;
|
|
104
128
|
return (_a = ev.relatedTarget) != null ? _a : ev.currentTarget.ownerDocument.activeElement;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
129
|
+
}
|
|
130
|
+
function dataAttr(condition) {
|
|
131
|
+
return condition ? "" : void 0;
|
|
132
|
+
}
|
|
133
|
+
function ariaAttr(condition) {
|
|
134
|
+
return condition ? true : void 0;
|
|
135
|
+
}
|
|
108
136
|
var focusableElList = [
|
|
109
137
|
"input:not(:disabled):not([disabled])",
|
|
110
138
|
"select:not(:disabled):not([disabled])",
|
|
@@ -122,14 +150,14 @@ var focusableElList = [
|
|
|
122
150
|
"*[contenteditable]"
|
|
123
151
|
];
|
|
124
152
|
var focusableElSelector = focusableElList.join();
|
|
125
|
-
|
|
153
|
+
function getAllFocusable(container) {
|
|
126
154
|
const focusableEls = Array.from(
|
|
127
155
|
container.querySelectorAll(focusableElSelector)
|
|
128
156
|
);
|
|
129
157
|
focusableEls.unshift(container);
|
|
130
158
|
return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
|
|
131
|
-
}
|
|
132
|
-
|
|
159
|
+
}
|
|
160
|
+
function isFocusable(el) {
|
|
133
161
|
if (!isHTMLElement(el) || isHidden(el) || isDisabled(el)) {
|
|
134
162
|
return false;
|
|
135
163
|
}
|
|
@@ -144,19 +172,29 @@ var isFocusable = (el) => {
|
|
|
144
172
|
if (localName in others) return others[localName]();
|
|
145
173
|
if (isContentEditable(el)) return true;
|
|
146
174
|
return hasTabIndex(el);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
175
|
+
}
|
|
176
|
+
function hasNegativeTabIndex(el) {
|
|
177
|
+
return hasTabIndex(el) && el.tabIndex === -1;
|
|
178
|
+
}
|
|
179
|
+
function isTabbable(el) {
|
|
180
|
+
return el ? isHTMLElement(el) && isFocusable(el) && !hasNegativeTabIndex(el) : false;
|
|
181
|
+
}
|
|
182
|
+
function isTouchDevice() {
|
|
183
|
+
return "ontouchstart" in window;
|
|
184
|
+
}
|
|
185
|
+
function getOwnerWindow(node) {
|
|
152
186
|
var _a, _b;
|
|
153
187
|
return (_b = (_a = getOwnerDocument(node)) == null ? void 0 : _a.defaultView) != null ? _b : window;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
188
|
+
}
|
|
189
|
+
function getOwnerDocument(el) {
|
|
190
|
+
return isElement(el) ? el.ownerDocument : document;
|
|
191
|
+
}
|
|
192
|
+
function getActiveElement(el) {
|
|
193
|
+
return getOwnerDocument(el).activeElement;
|
|
194
|
+
}
|
|
195
|
+
function isActiveElement(el) {
|
|
158
196
|
return getActiveElement(el) === el;
|
|
159
|
-
}
|
|
197
|
+
}
|
|
160
198
|
// Annotate the CommonJS export names for ESM import in node:
|
|
161
199
|
0 && (module.exports = {
|
|
162
200
|
ariaAttr,
|
package/dist/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dom.ts","../src/assertion.ts"],"sourcesContent":["import type React from \"react\"\nimport { isNumber, isUndefined } from \"./assertion\"\n\nexport const createdDom = (): boolean =>\n !!(\n typeof window !== \"undefined\" &&\n window.document &&\n window.document.createElement\n )\n\nexport const getPlatform = (): string =>\n (navigator as any).userAgentData?.platform ?? navigator.platform\n\nexport const vendor = (v: RegExp): boolean =>\n createdDom() && v.test(navigator.vendor)\nexport const platform = (v: RegExp): boolean =>\n createdDom() && v.test(getPlatform())\n\nexport const isMac = (): boolean => platform(/^mac/i)\nexport const isApple = (): boolean => platform(/mac|iphone|ipad|ipod/i)\nexport const isSafari = (): boolean => isApple() && vendor(/apple/i)\n\nexport const isElement = (el: any): el is Element =>\n el != null &&\n typeof el == \"object\" &&\n \"nodeType\" in el &&\n el.nodeType === Node.ELEMENT_NODE\n\nexport const isHTMLElement = (el: any): el is HTMLElement => {\n if (!isElement(el)) return false\n\n const win = el.ownerDocument.defaultView ?? window\n\n return el instanceof win.HTMLElement\n}\n\nexport const isHidden = (el: HTMLElement): boolean => {\n if (el.parentElement && isHidden(el.parentElement)) return true\n\n return el.hidden\n}\n\nexport const isDisabled = (el: HTMLElement): boolean =>\n Boolean(el.getAttribute(\"disabled\")) === true ||\n Boolean(el.getAttribute(\"data-disabled\")) === true ||\n Boolean(el.getAttribute(\"aria-disabled\")) === true\n\nconst isVisible = (el: HTMLElement) => el.offsetWidth > 0 && el.offsetHeight > 0\n\nexport const hasTabIndex = (el: HTMLElement): boolean =>\n el.hasAttribute(\"tabindex\")\n\nexport const isContentEditable = (el: HTMLElement): boolean => {\n const value = el.getAttribute(\"contenteditable\")\n\n return value !== \"false\" && value != null\n}\n\nexport const isContains = (\n parent: HTMLElement | null,\n child: HTMLElement | null,\n): boolean | undefined => {\n return parent === child || parent?.contains(child)\n}\n\nexport const getPx = (value: string | number | undefined): number => {\n if (isNumber(value)) return value\n\n if (isUndefined(value)) return 0\n\n if (value.includes(\"px\")) return parseFloat(value)\n\n const isBrowser = createdDom()\n let fontSize = 16\n\n if (isBrowser) {\n const style = window.getComputedStyle(document.documentElement)\n\n const computedFontSize = parseFloat(style.fontSize)\n\n if (!isNaN(computedFontSize)) fontSize = computedFontSize\n }\n\n return parseFloat(value) * fontSize\n}\n\nexport const getEventRelatedTarget = (\n ev: React.FocusEvent | React.MouseEvent,\n) =>\n (ev.relatedTarget ??\n ev.currentTarget.ownerDocument.activeElement) as HTMLElement | null\n\ntype Booleanish = boolean | \"true\" | \"false\"\n\nexport const dataAttr = (condition: boolean | undefined) =>\n (condition ? \"\" : undefined) as Booleanish\n\nexport const ariaAttr = (\n condition: boolean | undefined,\n): boolean | undefined => (condition ? true : undefined)\n\nexport type FocusableElement = {\n focus: (options?: FocusOptions) => void\n}\n\nconst focusableElList = [\n \"input:not(:disabled):not([disabled])\",\n \"select:not(:disabled):not([disabled])\",\n \"textarea:not(:disabled):not([disabled])\",\n \"embed\",\n \"iframe\",\n \"object\",\n \"a[href]\",\n \"area[href]\",\n \"button:not(:disabled):not([disabled])\",\n \"[tabindex]\",\n \"audio[controls]\",\n \"video[controls]\",\n \"*[tabindex]:not([aria-disabled])\",\n \"*[contenteditable]\",\n]\n\nconst focusableElSelector: string = focusableElList.join()\n\nexport const getAllFocusable = <T extends HTMLElement>(container: T): T[] => {\n const focusableEls: T[] = Array.from(\n container.querySelectorAll<T>(focusableElSelector),\n )\n\n focusableEls.unshift(container)\n\n return focusableEls.filter((el) => isFocusable(el) && isVisible(el))\n}\n\nexport const isFocusable = (el: HTMLElement): boolean => {\n if (!isHTMLElement(el) || isHidden(el) || isDisabled(el)) {\n return false\n }\n\n const { localName } = el\n const focusableTags = [\"input\", \"select\", \"textarea\", \"button\"]\n\n if (focusableTags.indexOf(localName) >= 0) return true\n\n const others = {\n a: () => el.hasAttribute(\"href\"),\n audio: () => el.hasAttribute(\"controls\"),\n video: () => el.hasAttribute(\"controls\"),\n }\n\n if (localName in others) return others[localName as keyof typeof others]()\n\n if (isContentEditable(el)) return true\n\n return hasTabIndex(el)\n}\n\nexport const hasNegativeTabIndex = (el: HTMLElement): boolean =>\n hasTabIndex(el) && el.tabIndex === -1\n\nexport const isTabbable = (el?: HTMLElement | null): boolean =>\n el ? isHTMLElement(el) && isFocusable(el) && !hasNegativeTabIndex(el) : false\n\nexport const isTouchDevice = () => \"ontouchstart\" in window\n\nexport const getOwnerWindow = (\n node?: Element | null,\n): Window & typeof globalThis => getOwnerDocument(node)?.defaultView ?? window\n\nexport const getOwnerDocument = (el?: Element | null): Document =>\n isElement(el) ? el.ownerDocument : document\n\nexport const getActiveElement = (el?: HTMLElement): HTMLElement =>\n getOwnerDocument(el).activeElement as HTMLElement\n\nexport const isActiveElement = (el: HTMLElement) => {\n return getActiveElement(el) === el\n}\n","import type { Dict } from \"./index.types\"\n\nexport const is = (x: any, y: any) =>\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y)\n\nexport const isNumber = (value: any): value is number =>\n typeof value === \"number\"\n\nexport const isNotNumber = (value: any): boolean =>\n typeof value !== \"number\" || Number.isNaN(value) || !Number.isFinite(value)\n\nexport const isNumeric = (value: any): boolean =>\n !isNaN(parseFloat(String(value))) &&\n isFinite(Number(value)) &&\n /^-?\\d*\\.?\\d+$/.test(String(value))\n\nexport const isString = (value: any): value is string =>\n Object.prototype.toString.call(value) === \"[object String]\"\n\nexport const isBoolean = (value: any): value is boolean =>\n typeof value === \"boolean\"\n\nexport const isUndefined = (value: any): value is undefined =>\n typeof value === \"undefined\" && value === undefined\n\nexport const isNull = (value: any): value is null => value === null\n\nexport const isObject = <T extends Dict>(value: any): value is T =>\n value !== null &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n !isArray(value)\n\nexport const isArray = <T extends any[]>(value: any): value is T =>\n Array.isArray(value)\n\nexport const isEmpty = (value: any): boolean =>\n !isArray(value) || !value.length || value.every((v) => v == null)\n\nexport const isFunction = <T extends Function = Function>(\n value: any,\n): value is T => typeof value === \"function\"\n\nexport const isUnit = (value: any): boolean =>\n /[0-9].*(em|rem|ex|rex|cap|rcap|ch|rch|ic|ric|lh|rlh|vw|svw|lvw|dvw|vh|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax|cm|mm|Q|in|pc|pt|px|%|cqw|cqh|cqi|cqb|cqmin|cqmax)$/.test(\n value,\n )\n\nexport const cast = <T>(value: any) => value as T\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,WAAW,CAAC,UACvB,OAAO,UAAU;AAgBZ,IAAM,cAAc,CAAC,UAC1B,OAAO,UAAU,eAAe,UAAU;;;ADpBrC,IAAM,aAAa,MACxB,CAAC,EACC,OAAO,WAAW,eAClB,OAAO,YACP,OAAO,SAAS;AAGb,IAAM,cAAc,MAAW;AAVtC;AAWG,+BAAkB,kBAAlB,mBAAiC,aAAjC,YAA6C,UAAU;AAAA;AAEnD,IAAM,SAAS,CAAC,MACrB,WAAW,KAAK,EAAE,KAAK,UAAU,MAAM;AAClC,IAAM,WAAW,CAAC,MACvB,WAAW,KAAK,EAAE,KAAK,YAAY,CAAC;AAE/B,IAAM,QAAQ,MAAe,SAAS,OAAO;AAC7C,IAAM,UAAU,MAAe,SAAS,uBAAuB;AAC/D,IAAM,WAAW,MAAe,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,IAAM,aAAa,CAAC,OACzB,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,KAAK,CAAC,oBAAoB,EAAE,IAAI;AAEnE,IAAM,gBAAgB,MAAM,kBAAkB;AAE9C,IAAM,iBAAiB,CAC5B,SAC4B;AAvK9B;AAuKiC,sCAAiB,IAAI,MAArB,mBAAwB,gBAAxB,YAAuC;AAAA;AAEjE,IAAM,mBAAmB,CAAC,OAC/B,UAAU,EAAE,IAAI,GAAG,gBAAgB;AAE9B,IAAM,mBAAmB,CAAC,OAC/B,iBAAiB,EAAE,EAAE;AAEhB,IAAM,kBAAkB,CAAC,OAAoB;AAClD,SAAO,iBAAiB,EAAE,MAAM;AAClC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/dom.ts","../src/assertion.ts"],"sourcesContent":["import type React from \"react\"\nimport { isNumber, isUndefined } from \"./assertion\"\n\nexport function createdDom(): boolean {\n return !!(\n typeof window !== \"undefined\" &&\n window.document &&\n window.document.createElement\n )\n}\n\nexport function getPlatform(): string {\n return (navigator as any).userAgentData?.platform ?? navigator.platform\n}\n\nexport function vendor(v: RegExp): boolean {\n return createdDom() && v.test(navigator.vendor)\n}\n\nexport function platform(v: RegExp): boolean {\n return createdDom() && v.test(getPlatform())\n}\n\nexport function isMac(): boolean {\n return platform(/^mac/i)\n}\n\nexport function isApple(): boolean {\n return platform(/mac|iphone|ipad|ipod/i)\n}\n\nexport function isSafari(): boolean {\n return isApple() && vendor(/apple/i)\n}\n\nexport function isElement(el: any): el is Element {\n return (\n el != null &&\n typeof el == \"object\" &&\n \"nodeType\" in el &&\n el.nodeType === Node.ELEMENT_NODE\n )\n}\n\nexport function isHTMLElement(el: any): el is HTMLElement {\n if (!isElement(el)) return false\n\n const win = el.ownerDocument.defaultView ?? window\n\n return el instanceof win.HTMLElement\n}\n\nexport function isHidden(el: HTMLElement): boolean {\n if (el.parentElement && isHidden(el.parentElement)) return true\n\n return el.hidden\n}\n\nexport function isDisabled(el: HTMLElement): boolean {\n return (\n Boolean(el.getAttribute(\"disabled\")) === true ||\n Boolean(el.getAttribute(\"data-disabled\")) === true ||\n Boolean(el.getAttribute(\"aria-disabled\")) === true\n )\n}\n\nfunction isVisible(el: HTMLElement) {\n return el.offsetWidth > 0 && el.offsetHeight > 0\n}\n\nexport function hasTabIndex(el: HTMLElement): boolean {\n return el.hasAttribute(\"tabindex\")\n}\n\nexport function isContentEditable(el: HTMLElement): boolean {\n const value = el.getAttribute(\"contenteditable\")\n\n return value !== \"false\" && value != null\n}\n\nexport function isContains(\n parent: HTMLElement | null,\n child: HTMLElement | null,\n): boolean | undefined {\n return parent === child || parent?.contains(child)\n}\n\nexport function getPx(value: string | number | undefined): number {\n if (isNumber(value)) return value\n\n if (isUndefined(value)) return 0\n\n if (value.includes(\"px\")) return parseFloat(value)\n\n const isBrowser = createdDom()\n let fontSize = 16\n\n if (isBrowser) {\n const style = window.getComputedStyle(document.documentElement)\n\n const computedFontSize = parseFloat(style.fontSize)\n\n if (!isNaN(computedFontSize)) fontSize = computedFontSize\n }\n\n return parseFloat(value) * fontSize\n}\n\nexport function getEventRelatedTarget(ev: React.FocusEvent | React.MouseEvent) {\n return (ev.relatedTarget ??\n ev.currentTarget.ownerDocument.activeElement) as HTMLElement | null\n}\n\ntype Booleanish = boolean | \"true\" | \"false\"\n\nexport function dataAttr(condition: boolean | undefined) {\n return (condition ? \"\" : undefined) as Booleanish\n}\n\nexport function ariaAttr(condition: boolean | undefined): boolean | undefined {\n return condition ? true : undefined\n}\n\nexport interface FocusableElement {\n focus: (options?: FocusOptions) => void\n}\n\nconst focusableElList = [\n \"input:not(:disabled):not([disabled])\",\n \"select:not(:disabled):not([disabled])\",\n \"textarea:not(:disabled):not([disabled])\",\n \"embed\",\n \"iframe\",\n \"object\",\n \"a[href]\",\n \"area[href]\",\n \"button:not(:disabled):not([disabled])\",\n \"[tabindex]\",\n \"audio[controls]\",\n \"video[controls]\",\n \"*[tabindex]:not([aria-disabled])\",\n \"*[contenteditable]\",\n]\n\nconst focusableElSelector: string = focusableElList.join()\n\nexport function getAllFocusable<T extends HTMLElement>(container: T): T[] {\n const focusableEls: T[] = Array.from(\n container.querySelectorAll<T>(focusableElSelector),\n )\n\n focusableEls.unshift(container)\n\n return focusableEls.filter((el) => isFocusable(el) && isVisible(el))\n}\n\nexport function isFocusable(el: HTMLElement): boolean {\n if (!isHTMLElement(el) || isHidden(el) || isDisabled(el)) {\n return false\n }\n\n const { localName } = el\n const focusableTags = [\"input\", \"select\", \"textarea\", \"button\"]\n\n if (focusableTags.indexOf(localName) >= 0) return true\n\n const others = {\n a: () => el.hasAttribute(\"href\"),\n audio: () => el.hasAttribute(\"controls\"),\n video: () => el.hasAttribute(\"controls\"),\n }\n\n if (localName in others) return others[localName as keyof typeof others]()\n\n if (isContentEditable(el)) return true\n\n return hasTabIndex(el)\n}\n\nexport function hasNegativeTabIndex(el: HTMLElement): boolean {\n return hasTabIndex(el) && el.tabIndex === -1\n}\n\nexport function isTabbable(el?: HTMLElement | null): boolean {\n return el\n ? isHTMLElement(el) && isFocusable(el) && !hasNegativeTabIndex(el)\n : false\n}\n\nexport function isTouchDevice(): boolean {\n return \"ontouchstart\" in window\n}\n\nexport function getOwnerWindow(\n node?: Element | null,\n): Window & typeof globalThis {\n return getOwnerDocument(node)?.defaultView ?? window\n}\n\nexport function getOwnerDocument(el?: Element | null): Document {\n return isElement(el) ? el.ownerDocument : document\n}\n\nexport function getActiveElement(el?: HTMLElement): HTMLElement {\n return getOwnerDocument(el).activeElement as HTMLElement\n}\n\nexport function isActiveElement(el: HTMLElement): boolean {\n return getActiveElement(el) === el\n}\n","import type { Dict } from \"./index.types\"\n\nexport function is(x: any, y: any) {\n return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y)\n}\n\nexport function isNumber(value: any): value is number {\n return typeof value === \"number\"\n}\n\nexport function isNotNumber(value: any): boolean {\n return (\n typeof value !== \"number\" || Number.isNaN(value) || !Number.isFinite(value)\n )\n}\n\nexport function isNumeric(value: any): boolean {\n return (\n !isNaN(parseFloat(String(value))) &&\n isFinite(Number(value)) &&\n /^-?\\d*\\.?\\d+$/.test(String(value))\n )\n}\n\nexport function isString(value: any): value is string {\n return Object.prototype.toString.call(value) === \"[object String]\"\n}\n\nexport function isBoolean(value: any): value is boolean {\n return typeof value === \"boolean\"\n}\n\nexport function isUndefined(value: any): value is undefined {\n return typeof value === \"undefined\" && value === undefined\n}\n\nexport function isNull(value: any): value is null {\n return value === null\n}\n\nexport function isObject<T extends Dict>(value: any): value is T {\n return (\n value !== null &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n !isArray(value)\n )\n}\n\nexport function isArray<T extends any[]>(value: any): value is T {\n return Array.isArray(value)\n}\n\nexport function isEmpty(value: any): boolean {\n return !isArray(value) || !value.length || value.every((v) => v == null)\n}\n\nexport function isFunction<T extends Function = Function>(\n value: any,\n): value is T {\n return typeof value === \"function\"\n}\n\nexport function isUnit(value: any): boolean {\n return /[0-9].*(em|rem|ex|rex|cap|rcap|ch|rch|ic|ric|lh|rlh|vw|svw|lvw|dvw|vh|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax|cm|mm|Q|in|pc|pt|px|%|cqw|cqh|cqi|cqb|cqmin|cqmax)$/.test(\n value,\n )\n}\n\nexport function cast<T>(value: any) {\n return value as T\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,SAAS,SAAS,OAA6B;AACpD,SAAO,OAAO,UAAU;AAC1B;AAwBO,SAAS,YAAY,OAAgC;AAC1D,SAAO,OAAO,UAAU,eAAe,UAAU;AACnD;;;AD/BO,SAAS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AACxD,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,UAAU,IAAI;AACtB,QAAM,gBAAgB,CAAC,SAAS,UAAU,YAAY,QAAQ;AAE9D,MAAI,cAAc,QAAQ,SAAS,KAAK,EAAG,QAAO;AAElD,QAAM,SAAS;AAAA,IACb,GAAG,MAAM,GAAG,aAAa,MAAM;AAAA,IAC/B,OAAO,MAAM,GAAG,aAAa,UAAU;AAAA,IACvC,OAAO,MAAM,GAAG,aAAa,UAAU;AAAA,EACzC;AAEA,MAAI,aAAa,OAAQ,QAAO,OAAO,SAAgC,EAAE;AAEzE,MAAI,kBAAkB,EAAE,EAAG,QAAO;AAElC,SAAO,YAAY,EAAE;AACvB;AAEO,SAAS,oBAAoB,IAA0B;AAC5D,SAAO,YAAY,EAAE,KAAK,GAAG,aAAa;AAC5C;AAEO,SAAS,WAAW,IAAkC;AAC3D,SAAO,KACH,cAAc,EAAE,KAAK,YAAY,EAAE,KAAK,CAAC,oBAAoB,EAAE,IAC/D;AACN;AAEO,SAAS,gBAAyB;AACvC,SAAO,kBAAkB;AAC3B;AAEO,SAAS,eACd,MAC4B;AAnM9B;AAoME,UAAO,4BAAiB,IAAI,MAArB,mBAAwB,gBAAxB,YAAuC;AAChD;AAEO,SAAS,iBAAiB,IAA+B;AAC9D,SAAO,UAAU,EAAE,IAAI,GAAG,gBAAgB;AAC5C;AAEO,SAAS,iBAAiB,IAA+B;AAC9D,SAAO,iBAAiB,EAAE,EAAE;AAC9B;AAEO,SAAS,gBAAgB,IAA0B;AACxD,SAAO,iBAAiB,EAAE,MAAM;AAClC;","names":[]}
|
package/dist/dom.mjs
CHANGED
package/dist/event.d.mts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent;
|
|
2
2
|
type PointType = "page" | "client";
|
|
3
|
-
|
|
3
|
+
interface Point {
|
|
4
4
|
x: number;
|
|
5
5
|
y: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
6
|
+
}
|
|
7
|
+
interface PointerEventInfo {
|
|
8
8
|
point: Point;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
type MixedEventListener = (e: AnyPointerEvent, info: PointerEventInfo) => void;
|
|
11
|
-
declare
|
|
12
|
-
declare
|
|
13
|
-
declare
|
|
14
|
-
declare
|
|
15
|
-
declare
|
|
11
|
+
declare function isMouseEvent(ev: any): ev is MouseEvent;
|
|
12
|
+
declare function isTouchEvent(ev: AnyPointerEvent): ev is TouchEvent;
|
|
13
|
+
declare function isMultiTouchEvent(ev: AnyPointerEvent): boolean;
|
|
14
|
+
declare function getEventWindow(ev: Event): typeof globalThis;
|
|
15
|
+
declare function pointFromTouch(e: TouchEvent, type?: PointType): {
|
|
16
16
|
x: number;
|
|
17
17
|
y: number;
|
|
18
18
|
};
|
|
19
|
-
declare
|
|
19
|
+
declare function pointFromMouse(point: MouseEvent | PointerEvent, type?: PointType): {
|
|
20
20
|
x: number;
|
|
21
21
|
y: number;
|
|
22
22
|
};
|
|
23
|
-
declare
|
|
23
|
+
declare function getEventPoint(ev: AnyPointerEvent, type?: PointType): {
|
|
24
24
|
x: number;
|
|
25
25
|
y: number;
|
|
26
26
|
};
|
|
27
|
-
declare
|
|
28
|
-
declare
|
|
27
|
+
declare function addDomEvent(target: EventTarget, type: string, cb: EventListener, options?: AddEventListenerOptions): () => void;
|
|
28
|
+
declare function addPointerEvent(target: EventTarget, type: string, cb: MixedEventListener, options?: AddEventListenerOptions): () => void;
|
|
29
29
|
|
|
30
30
|
export { type AnyPointerEvent, type MixedEventListener, type Point, type PointType, type PointerEventInfo, addDomEvent, addPointerEvent, getEventPoint, getEventWindow, isMouseEvent, isMultiTouchEvent, isTouchEvent, pointFromMouse, pointFromTouch };
|
package/dist/event.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent;
|
|
2
2
|
type PointType = "page" | "client";
|
|
3
|
-
|
|
3
|
+
interface Point {
|
|
4
4
|
x: number;
|
|
5
5
|
y: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
6
|
+
}
|
|
7
|
+
interface PointerEventInfo {
|
|
8
8
|
point: Point;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
type MixedEventListener = (e: AnyPointerEvent, info: PointerEventInfo) => void;
|
|
11
|
-
declare
|
|
12
|
-
declare
|
|
13
|
-
declare
|
|
14
|
-
declare
|
|
15
|
-
declare
|
|
11
|
+
declare function isMouseEvent(ev: any): ev is MouseEvent;
|
|
12
|
+
declare function isTouchEvent(ev: AnyPointerEvent): ev is TouchEvent;
|
|
13
|
+
declare function isMultiTouchEvent(ev: AnyPointerEvent): boolean;
|
|
14
|
+
declare function getEventWindow(ev: Event): typeof globalThis;
|
|
15
|
+
declare function pointFromTouch(e: TouchEvent, type?: PointType): {
|
|
16
16
|
x: number;
|
|
17
17
|
y: number;
|
|
18
18
|
};
|
|
19
|
-
declare
|
|
19
|
+
declare function pointFromMouse(point: MouseEvent | PointerEvent, type?: PointType): {
|
|
20
20
|
x: number;
|
|
21
21
|
y: number;
|
|
22
22
|
};
|
|
23
|
-
declare
|
|
23
|
+
declare function getEventPoint(ev: AnyPointerEvent, type?: PointType): {
|
|
24
24
|
x: number;
|
|
25
25
|
y: number;
|
|
26
26
|
};
|
|
27
|
-
declare
|
|
28
|
-
declare
|
|
27
|
+
declare function addDomEvent(target: EventTarget, type: string, cb: EventListener, options?: AddEventListenerOptions): () => void;
|
|
28
|
+
declare function addPointerEvent(target: EventTarget, type: string, cb: MixedEventListener, options?: AddEventListenerOptions): () => void;
|
|
29
29
|
|
|
30
30
|
export { type AnyPointerEvent, type MixedEventListener, type Point, type PointType, type PointerEventInfo, addDomEvent, addPointerEvent, getEventPoint, getEventWindow, isMouseEvent, isMultiTouchEvent, isTouchEvent, pointFromMouse, pointFromTouch };
|
package/dist/event.js
CHANGED
|
@@ -31,43 +31,57 @@ __export(event_exports, {
|
|
|
31
31
|
pointFromTouch: () => pointFromTouch
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(event_exports);
|
|
34
|
-
|
|
34
|
+
function isMouseEvent(ev) {
|
|
35
35
|
const win = getEventWindow(ev);
|
|
36
36
|
if (typeof win.PointerEvent !== "undefined" && ev instanceof win.PointerEvent)
|
|
37
37
|
return !!(ev.pointerType === "mouse");
|
|
38
38
|
return ev instanceof win.MouseEvent;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
}
|
|
40
|
+
function isTouchEvent(ev) {
|
|
41
|
+
return !!ev.touches;
|
|
42
|
+
}
|
|
43
|
+
function isMultiTouchEvent(ev) {
|
|
44
|
+
return isTouchEvent(ev) && ev.touches.length > 1;
|
|
45
|
+
}
|
|
46
|
+
function getEventWindow(ev) {
|
|
43
47
|
var _a;
|
|
44
48
|
return (_a = ev.view) != null ? _a : window;
|
|
45
|
-
}
|
|
46
|
-
|
|
49
|
+
}
|
|
50
|
+
function pointFromTouch(e, type = "page") {
|
|
47
51
|
const point = e.touches[0] || e.changedTouches[0];
|
|
48
52
|
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
}
|
|
54
|
+
function pointFromMouse(point, type = "page") {
|
|
55
|
+
return {
|
|
56
|
+
x: point[`${type}X`],
|
|
57
|
+
y: point[`${type}Y`]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function getEventPoint(ev, type = "page") {
|
|
61
|
+
return isTouchEvent(ev) ? pointFromTouch(ev, type) : pointFromMouse(ev, type);
|
|
62
|
+
}
|
|
63
|
+
function addDomEvent(target, type, cb, options) {
|
|
56
64
|
target.addEventListener(type, cb, options);
|
|
57
65
|
return () => {
|
|
58
66
|
target.removeEventListener(type, cb, options);
|
|
59
67
|
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
}
|
|
69
|
+
function filter(cb) {
|
|
70
|
+
return function(ev) {
|
|
71
|
+
const isMouse = isMouseEvent(ev);
|
|
72
|
+
if (!isMouse || isMouse && ev.button === 0) cb(ev);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function wrap(cb, filterPrimary = false) {
|
|
76
|
+
function listener(ev) {
|
|
77
|
+
return cb(ev, { point: getEventPoint(ev) });
|
|
78
|
+
}
|
|
67
79
|
const fn = filterPrimary ? filter(listener) : listener;
|
|
68
80
|
return fn;
|
|
69
|
-
}
|
|
70
|
-
|
|
81
|
+
}
|
|
82
|
+
function addPointerEvent(target, type, cb, options) {
|
|
83
|
+
return addDomEvent(target, type, wrap(cb, type === "pointerdown"), options);
|
|
84
|
+
}
|
|
71
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
72
86
|
0 && (module.exports = {
|
|
73
87
|
addDomEvent,
|
package/dist/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/event.ts"],"sourcesContent":["export type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent\n\nexport type PointType = \"page\" | \"client\"\n\nexport
|
|
1
|
+
{"version":3,"sources":["../src/event.ts"],"sourcesContent":["export type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent\n\nexport type PointType = \"page\" | \"client\"\n\nexport interface Point {\n x: number\n y: number\n}\n\nexport interface PointerEventInfo {\n point: Point\n}\n\nexport type MixedEventListener = (\n e: AnyPointerEvent,\n info: PointerEventInfo,\n) => void\n\nexport function isMouseEvent(ev: any): ev is MouseEvent {\n const win = getEventWindow(ev)\n\n if (typeof win.PointerEvent !== \"undefined\" && ev instanceof win.PointerEvent)\n return !!(ev.pointerType === \"mouse\")\n\n return ev instanceof win.MouseEvent\n}\n\nexport function isTouchEvent(ev: AnyPointerEvent): ev is TouchEvent {\n return !!(ev as TouchEvent).touches\n}\n\nexport function isMultiTouchEvent(ev: AnyPointerEvent) {\n return isTouchEvent(ev) && ev.touches.length > 1\n}\n\nexport function getEventWindow(ev: Event): typeof globalThis {\n return ((ev as UIEvent).view ?? window) as unknown as typeof globalThis\n}\n\nexport function pointFromTouch(e: TouchEvent, type: PointType = \"page\") {\n const point = e.touches[0] || e.changedTouches[0]\n\n return { x: point[`${type}X`], y: point[`${type}Y`] }\n}\n\nexport function pointFromMouse(\n point: MouseEvent | PointerEvent,\n type: PointType = \"page\",\n) {\n return {\n x: point[`${type}X`],\n y: point[`${type}Y`],\n }\n}\n\nexport function getEventPoint(ev: AnyPointerEvent, type: PointType = \"page\") {\n return isTouchEvent(ev) ? pointFromTouch(ev, type) : pointFromMouse(ev, type)\n}\n\nexport function addDomEvent(\n target: EventTarget,\n type: string,\n cb: EventListener,\n options?: AddEventListenerOptions,\n) {\n target.addEventListener(type, cb, options)\n\n return () => {\n target.removeEventListener(type, cb, options)\n }\n}\n\nfunction filter(cb: EventListener): EventListener {\n return function (ev: Event) {\n const isMouse = isMouseEvent(ev)\n\n if (!isMouse || (isMouse && ev.button === 0)) cb(ev)\n }\n}\n\nfunction wrap(cb: MixedEventListener, filterPrimary = false): EventListener {\n function listener(ev: any) {\n return cb(ev, { point: getEventPoint(ev) })\n }\n\n const fn = filterPrimary ? filter(listener) : listener\n\n return fn as EventListener\n}\n\nexport function addPointerEvent(\n target: EventTarget,\n type: string,\n cb: MixedEventListener,\n options?: AddEventListenerOptions,\n) {\n return addDomEvent(target, type, wrap(cb, type === \"pointerdown\"), options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,aAAa,IAA2B;AACtD,QAAM,MAAM,eAAe,EAAE;AAE7B,MAAI,OAAO,IAAI,iBAAiB,eAAe,cAAc,IAAI;AAC/D,WAAO,CAAC,EAAE,GAA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AACT;AAEO,SAAS,gBACd,QACA,MACA,IACA,SACA;AACA,SAAO,YAAY,QAAQ,MAAM,KAAK,IAAI,SAAS,aAAa,GAAG,OAAO;AAC5E;","names":[]}
|
package/dist/event.mjs
CHANGED
package/dist/function.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare const noop: () => void;
|
|
2
|
-
declare
|
|
3
|
-
declare
|
|
4
|
-
declare
|
|
2
|
+
declare function runIfFunc<T, U extends any[]>(valOrFunc: T | ((...funcArgs: U) => T), ...args: U): T;
|
|
3
|
+
declare function handlerAll<T extends (event: any, ...args: any[]) => void>(...funcs: (T | undefined)[]): (event: T extends (event: infer R, ...args: any[]) => any ? R : never, ...args: T extends (event: any, ...args: infer R) => any ? R : never) => void;
|
|
4
|
+
declare function funcAll<T extends (...args: any[]) => any>(...funcs: (T | undefined)[]): (...args: T extends (...args: infer R) => any ? R : never) => void;
|
|
5
5
|
|
|
6
6
|
export { funcAll, handlerAll, noop, runIfFunc };
|
package/dist/function.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare const noop: () => void;
|
|
2
|
-
declare
|
|
3
|
-
declare
|
|
4
|
-
declare
|
|
2
|
+
declare function runIfFunc<T, U extends any[]>(valOrFunc: T | ((...funcArgs: U) => T), ...args: U): T;
|
|
3
|
+
declare function handlerAll<T extends (event: any, ...args: any[]) => void>(...funcs: (T | undefined)[]): (event: T extends (event: infer R, ...args: any[]) => any ? R : never, ...args: T extends (event: any, ...args: infer R) => any ? R : never) => void;
|
|
4
|
+
declare function funcAll<T extends (...args: any[]) => any>(...funcs: (T | undefined)[]): (...args: T extends (...args: infer R) => any ? R : never) => void;
|
|
5
5
|
|
|
6
6
|
export { funcAll, handlerAll, noop, runIfFunc };
|