@yamada-ui/utils 0.0.0-dev-20230606151107

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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/dist/array.d.ts +3 -0
  4. package/dist/array.js +30 -0
  5. package/dist/array.mjs +6 -0
  6. package/dist/assertion.d.ts +16 -0
  7. package/dist/assertion.js +63 -0
  8. package/dist/assertion.mjs +28 -0
  9. package/dist/calc.d.ts +17 -0
  10. package/dist/calc.js +55 -0
  11. package/dist/calc.mjs +6 -0
  12. package/dist/chunk-BZAW2D6U.mjs +6 -0
  13. package/dist/chunk-FW7XS4NH.mjs +120 -0
  14. package/dist/chunk-HUEOJZVC.mjs +403 -0
  15. package/dist/chunk-IVGIIDMV.mjs +28 -0
  16. package/dist/chunk-PF7LRFIA.mjs +51 -0
  17. package/dist/chunk-PURW64JE.mjs +6 -0
  18. package/dist/chunk-R5OUKGQ5.mjs +31 -0
  19. package/dist/chunk-SLJ4M7XC.mjs +0 -0
  20. package/dist/chunk-VYMGBE25.mjs +39 -0
  21. package/dist/color.d.ts +18 -0
  22. package/dist/color.js +183 -0
  23. package/dist/color.mjs +34 -0
  24. package/dist/dom.d.ts +33 -0
  25. package/dist/dom.js +168 -0
  26. package/dist/dom.mjs +54 -0
  27. package/dist/event.d.ts +30 -0
  28. package/dist/event.js +83 -0
  29. package/dist/event.mjs +22 -0
  30. package/dist/function.d.ts +6 -0
  31. package/dist/function.js +50 -0
  32. package/dist/function.mjs +20 -0
  33. package/dist/index.d.ts +13 -0
  34. package/dist/index.js +798 -0
  35. package/dist/index.mjs +221 -0
  36. package/dist/index.types.d.ts +14 -0
  37. package/dist/index.types.js +18 -0
  38. package/dist/index.types.mjs +1 -0
  39. package/dist/number.d.ts +8 -0
  40. package/dist/number.js +68 -0
  41. package/dist/number.mjs +16 -0
  42. package/dist/object.d.ts +18 -0
  43. package/dist/object.js +192 -0
  44. package/dist/object.mjs +40 -0
  45. package/dist/react.d.ts +44 -0
  46. package/dist/react.js +176 -0
  47. package/dist/react.mjs +46 -0
  48. package/dist/string.d.ts +3 -0
  49. package/dist/string.js +30 -0
  50. package/dist/string.mjs +6 -0
  51. package/package.json +66 -0
package/dist/color.js ADDED
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/color.ts
21
+ var color_exports = {};
22
+ __export(color_exports, {
23
+ darkenColor: () => darkenColor,
24
+ getColor: () => getColor,
25
+ isDark: () => isDark,
26
+ isLight: () => isLight,
27
+ isTone: () => isTone,
28
+ lightenColor: () => lightenColor,
29
+ randomColor: () => randomColor,
30
+ shadeColor: () => shadeColor,
31
+ tintColor: () => tintColor,
32
+ toneColor: () => toneColor,
33
+ transparentizeColor: () => transparentizeColor
34
+ });
35
+ module.exports = __toCommonJS(color_exports);
36
+ var import_color2k = require("color2k");
37
+
38
+ // src/assertion.ts
39
+ var isArray = (value) => Array.isArray(value);
40
+
41
+ // src/object.ts
42
+ var getObject = (obj, path, fallback, i) => {
43
+ const k = typeof path === "string" ? path.split(".") : [path];
44
+ for (i = 0; i < k.length; i += 1) {
45
+ if (!obj)
46
+ break;
47
+ obj = obj[k[i]];
48
+ }
49
+ return obj === void 0 ? fallback : obj;
50
+ };
51
+ var memoizeObject = (func) => {
52
+ const cache = /* @__PURE__ */ new WeakMap();
53
+ const memoizedFunc = (obj, path, fallback, i) => {
54
+ if (typeof obj === "undefined") {
55
+ return func(obj, path, fallback);
56
+ }
57
+ if (!cache.has(obj))
58
+ cache.set(obj, /* @__PURE__ */ new Map());
59
+ const map = cache.get(obj);
60
+ if (map.has(path))
61
+ return map.get(path);
62
+ const value = func(obj, path, fallback, i);
63
+ map.set(path, value);
64
+ return value;
65
+ };
66
+ return memoizedFunc;
67
+ };
68
+ var getMemoizedObject = memoizeObject(getObject);
69
+
70
+ // src/color.ts
71
+ var getColor = (color, fallback) => (theme, colorMode) => {
72
+ const hex = getMemoizedObject(
73
+ theme,
74
+ `colors.${color}`,
75
+ color
76
+ );
77
+ try {
78
+ if (isArray(hex)) {
79
+ const [lightHex, darkHex] = hex;
80
+ return (0, import_color2k.toHex)(String(colorMode !== "dark" ? lightHex : darkHex));
81
+ } else {
82
+ return (0, import_color2k.toHex)(String(hex));
83
+ }
84
+ } catch {
85
+ return fallback != null ? fallback : "#000000";
86
+ }
87
+ };
88
+ var lightenColor = (color, amount) => (theme, colorMode) => {
89
+ const raw = getColor(color)(theme, colorMode);
90
+ return (0, import_color2k.toHex)((0, import_color2k.lighten)(raw, amount / 100));
91
+ };
92
+ var darkenColor = (color, amount) => (theme, colorMode) => {
93
+ const raw = getColor(color)(theme, colorMode);
94
+ return (0, import_color2k.toHex)((0, import_color2k.darken)(raw, amount / 100));
95
+ };
96
+ var tintColor = (color, amount) => (theme, colorMode) => {
97
+ const raw = getColor(color)(theme, colorMode);
98
+ return (0, import_color2k.toHex)((0, import_color2k.mix)(raw, "#fff", amount));
99
+ };
100
+ var shadeColor = (color, amount) => (theme, colorMode) => {
101
+ const raw = getColor(color)(theme, colorMode);
102
+ return (0, import_color2k.toHex)((0, import_color2k.mix)(raw, "#000", amount / 100));
103
+ };
104
+ var transparentizeColor = (color, alpha) => (theme, colorMode) => {
105
+ const raw = getColor(color)(theme, colorMode);
106
+ return (0, import_color2k.transparentize)(raw, 1 - alpha);
107
+ };
108
+ var toneColor = (color, l) => (theme, colorMode) => {
109
+ const raw = getColor(color)(theme, colorMode);
110
+ if (l < 0 || 900 < l)
111
+ return color;
112
+ let n = (l - 500) / 10;
113
+ const isLighten = n <= 0;
114
+ if (isLighten)
115
+ n *= -1;
116
+ if (n !== 0)
117
+ n = n - 5 * (isLighten ? 1 : -1);
118
+ return (0, import_color2k.toHex)(isLighten ? (0, import_color2k.lighten)(raw, n / 100) : (0, import_color2k.mix)(raw, "#000", n / 100));
119
+ };
120
+ var randomColor = ({ string, colors } = {}) => {
121
+ const fallback = randomHex();
122
+ if (string && colors)
123
+ return randomColorFromList(string, colors);
124
+ if (string && !colors)
125
+ return randomColorFromString(string);
126
+ if (colors && !string)
127
+ return randomFromList(colors);
128
+ return fallback;
129
+ };
130
+ var randomHex = () => `#${Math.floor(Math.random() * 16777215).toString(16).padEnd(6, "0")}`;
131
+ var randomColorFromString = (str) => {
132
+ let hash = 0;
133
+ if (str.length === 0)
134
+ return hash.toString();
135
+ for (let i = 0; i < str.length; i += 1) {
136
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
137
+ hash = hash & hash;
138
+ }
139
+ let color = "#";
140
+ for (let j = 0; j < 3; j += 1) {
141
+ const value = hash >> j * 8 & 255;
142
+ color += `00${value.toString(16)}`.substr(-2);
143
+ }
144
+ return color;
145
+ };
146
+ var randomColorFromList = (str, list) => {
147
+ let index = 0;
148
+ if (str.length === 0)
149
+ return list[0];
150
+ for (let i = 0; i < str.length; i += 1) {
151
+ index = str.charCodeAt(i) + ((index << 5) - index);
152
+ index = index & index;
153
+ }
154
+ index = (index % list.length + list.length) % list.length;
155
+ return list[index];
156
+ };
157
+ var randomFromList = (list) => list[Math.floor(Math.random() * list.length)];
158
+ var getBrightness = (color) => {
159
+ const [r, g, b] = (0, import_color2k.parseToRgba)(color);
160
+ return (r * 299 + g * 587 + b * 114) / 1e3;
161
+ };
162
+ var isTone = (color) => (theme, colorMode) => {
163
+ const raw = getColor(color)(theme, colorMode);
164
+ const brightness = getBrightness(raw);
165
+ const isDark2 = brightness < 128;
166
+ return isDark2 ? "dark" : "light";
167
+ };
168
+ var isLight = (color) => (theme, colorMode) => isTone(color)(theme, colorMode) === "dark";
169
+ var isDark = (color) => (theme, colorMode) => isTone(color)(theme, colorMode) === "light";
170
+ // Annotate the CommonJS export names for ESM import in node:
171
+ 0 && (module.exports = {
172
+ darkenColor,
173
+ getColor,
174
+ isDark,
175
+ isLight,
176
+ isTone,
177
+ lightenColor,
178
+ randomColor,
179
+ shadeColor,
180
+ tintColor,
181
+ toneColor,
182
+ transparentizeColor
183
+ });
package/dist/color.mjs ADDED
@@ -0,0 +1,34 @@
1
+ import {
2
+ darkenColor,
3
+ getColor,
4
+ isDark,
5
+ isLight,
6
+ isTone,
7
+ lightenColor,
8
+ randomColor,
9
+ shadeColor,
10
+ tintColor,
11
+ toneColor,
12
+ transparentizeColor
13
+ } from "./chunk-HUEOJZVC.mjs";
14
+ import "./chunk-SLJ4M7XC.mjs";
15
+ import "./chunk-VYMGBE25.mjs";
16
+ import "./chunk-BZAW2D6U.mjs";
17
+ import "./chunk-PURW64JE.mjs";
18
+ import "./chunk-IVGIIDMV.mjs";
19
+ import "./chunk-R5OUKGQ5.mjs";
20
+ import "./chunk-FW7XS4NH.mjs";
21
+ import "./chunk-PF7LRFIA.mjs";
22
+ export {
23
+ darkenColor,
24
+ getColor,
25
+ isDark,
26
+ isLight,
27
+ isTone,
28
+ lightenColor,
29
+ randomColor,
30
+ shadeColor,
31
+ tintColor,
32
+ toneColor,
33
+ transparentizeColor
34
+ };
package/dist/dom.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import React__default from 'react';
2
+
3
+ declare const createdDom: () => boolean;
4
+ declare const getPlatform: () => string;
5
+ declare const vendor: (v: RegExp) => boolean;
6
+ declare const platform: (v: RegExp) => boolean;
7
+ declare const isMac: () => boolean;
8
+ declare const isApple: () => boolean;
9
+ declare const isSafari: () => boolean;
10
+ declare const isElement: (el: any) => el is Element;
11
+ declare const isHTMLElement: (el: any) => el is HTMLElement;
12
+ declare const isHidden: (el: HTMLElement) => boolean;
13
+ declare const isDisabled: (el: HTMLElement) => boolean;
14
+ declare const hasTabIndex: (el: HTMLElement) => boolean;
15
+ declare const isContentEditable: (el: HTMLElement) => boolean;
16
+ declare const isContains: (parent: HTMLElement | null, child: HTMLElement | null) => boolean | undefined;
17
+ declare const getEventRelatedTarget: (ev: React__default.FocusEvent | React__default.MouseEvent) => HTMLElement | null;
18
+ type Booleanish = boolean | 'true' | 'false';
19
+ declare const dataAttr: (condition: boolean | undefined) => Booleanish;
20
+ declare const ariaAttr: (condition: boolean | undefined) => boolean | undefined;
21
+ type FocusableElement = {
22
+ focus: (options?: FocusOptions) => void;
23
+ };
24
+ declare const getAllFocusable: <T extends HTMLElement>(container: T) => T[];
25
+ declare const isFocusable: (el: HTMLElement) => boolean;
26
+ declare const hasNegativeTabIndex: (el: HTMLElement) => boolean;
27
+ declare const isTabbable: (el?: HTMLElement | null) => boolean;
28
+ declare const getOwnerWindow: (node?: Element | null) => Window & typeof globalThis;
29
+ declare const getOwnerDocument: (el?: Element | null) => Document;
30
+ declare const getActiveElement: (el?: HTMLElement) => HTMLElement;
31
+ declare const isActiveElement: (el: HTMLElement) => boolean;
32
+
33
+ export { FocusableElement, ariaAttr, createdDom, dataAttr, getActiveElement, getAllFocusable, getEventRelatedTarget, getOwnerDocument, getOwnerWindow, getPlatform, hasNegativeTabIndex, hasTabIndex, isActiveElement, isApple, isContains, isContentEditable, isDisabled, isElement, isFocusable, isHTMLElement, isHidden, isMac, isSafari, isTabbable, platform, vendor };
package/dist/dom.js ADDED
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/dom.ts
21
+ var dom_exports = {};
22
+ __export(dom_exports, {
23
+ ariaAttr: () => ariaAttr,
24
+ createdDom: () => createdDom,
25
+ dataAttr: () => dataAttr,
26
+ getActiveElement: () => getActiveElement,
27
+ getAllFocusable: () => getAllFocusable,
28
+ getEventRelatedTarget: () => getEventRelatedTarget,
29
+ getOwnerDocument: () => getOwnerDocument,
30
+ getOwnerWindow: () => getOwnerWindow,
31
+ getPlatform: () => getPlatform,
32
+ hasNegativeTabIndex: () => hasNegativeTabIndex,
33
+ hasTabIndex: () => hasTabIndex,
34
+ isActiveElement: () => isActiveElement,
35
+ isApple: () => isApple,
36
+ isContains: () => isContains,
37
+ isContentEditable: () => isContentEditable,
38
+ isDisabled: () => isDisabled,
39
+ isElement: () => isElement,
40
+ isFocusable: () => isFocusable,
41
+ isHTMLElement: () => isHTMLElement,
42
+ isHidden: () => isHidden,
43
+ isMac: () => isMac,
44
+ isSafari: () => isSafari,
45
+ isTabbable: () => isTabbable,
46
+ platform: () => platform,
47
+ vendor: () => vendor
48
+ });
49
+ module.exports = __toCommonJS(dom_exports);
50
+ var createdDom = () => !!(typeof window !== "undefined" && window.document && window.document.createElement);
51
+ var getPlatform = () => {
52
+ var _a, _b;
53
+ return (_b = (_a = navigator.userAgentData) == null ? void 0 : _a.platform) != null ? _b : navigator.platform;
54
+ };
55
+ var vendor = (v) => createdDom() && v.test(navigator.vendor);
56
+ var platform = (v) => createdDom() && v.test(getPlatform());
57
+ var isMac = () => platform(/^mac/);
58
+ var isApple = () => platform(/mac|iphone|ipad|ipod/i);
59
+ var isSafari = () => isApple() && vendor(/apple/i);
60
+ var isElement = (el) => el != null && typeof el == "object" && "nodeType" in el && el.nodeType === Node.ELEMENT_NODE;
61
+ var isHTMLElement = (el) => {
62
+ var _a;
63
+ if (!isElement(el))
64
+ return false;
65
+ const win = (_a = el.ownerDocument.defaultView) != null ? _a : window;
66
+ return el instanceof win.HTMLElement;
67
+ };
68
+ var isHidden = (el) => {
69
+ if (el.parentElement && isHidden(el.parentElement))
70
+ return true;
71
+ return el.hidden;
72
+ };
73
+ var isDisabled = (el) => Boolean(el.getAttribute("disabled")) === true || Boolean(el.getAttribute("aria-disabled")) === true;
74
+ var isVisible = (el) => el.offsetWidth > 0 && el.offsetHeight > 0;
75
+ var hasTabIndex = (el) => el.hasAttribute("tabindex");
76
+ var isContentEditable = (el) => {
77
+ const value = el.getAttribute("contenteditable");
78
+ return value !== "false" && value != null;
79
+ };
80
+ var isContains = (parent, child) => {
81
+ return parent === child || (parent == null ? void 0 : parent.contains(child));
82
+ };
83
+ var getEventRelatedTarget = (ev) => {
84
+ var _a;
85
+ return (_a = ev.relatedTarget) != null ? _a : ev.currentTarget.ownerDocument.activeElement;
86
+ };
87
+ var dataAttr = (condition) => condition ? "" : void 0;
88
+ var ariaAttr = (condition) => condition ? true : void 0;
89
+ var focusableElList = [
90
+ "input:not(:disabled):not([disabled])",
91
+ "select:not(:disabled):not([disabled])",
92
+ "textarea:not(:disabled):not([disabled])",
93
+ "embed",
94
+ "iframe",
95
+ "object",
96
+ "a[href]",
97
+ "area[href]",
98
+ "button:not(:disabled):not([disabled])",
99
+ "[tabindex]",
100
+ "audio[controls]",
101
+ "video[controls]",
102
+ "*[tabindex]:not([aria-disabled])",
103
+ "*[contenteditable]"
104
+ ];
105
+ var focusableElSelector = focusableElList.join();
106
+ var getAllFocusable = (container) => {
107
+ const focusableEls = Array.from(container.querySelectorAll(focusableElSelector));
108
+ focusableEls.unshift(container);
109
+ return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
110
+ };
111
+ var isFocusable = (el) => {
112
+ if (!isHTMLElement(el) || isHidden(el) || isDisabled(el)) {
113
+ return false;
114
+ }
115
+ const { localName } = el;
116
+ const focusableTags = ["input", "select", "textarea", "button"];
117
+ if (focusableTags.indexOf(localName) >= 0)
118
+ return true;
119
+ const others = {
120
+ a: () => el.hasAttribute("href"),
121
+ audio: () => el.hasAttribute("controls"),
122
+ video: () => el.hasAttribute("controls")
123
+ };
124
+ if (localName in others)
125
+ return others[localName]();
126
+ if (isContentEditable(el))
127
+ return true;
128
+ return hasTabIndex(el);
129
+ };
130
+ var hasNegativeTabIndex = (el) => hasTabIndex(el) && el.tabIndex === -1;
131
+ var isTabbable = (el) => el ? isHTMLElement(el) && isFocusable(el) && !hasNegativeTabIndex(el) : false;
132
+ var getOwnerWindow = (node) => {
133
+ var _a, _b;
134
+ return (_b = (_a = getOwnerDocument(node)) == null ? void 0 : _a.defaultView) != null ? _b : window;
135
+ };
136
+ var getOwnerDocument = (el) => isElement(el) ? el.ownerDocument : document;
137
+ var getActiveElement = (el) => getOwnerDocument(el).activeElement;
138
+ var isActiveElement = (el) => {
139
+ return getActiveElement(el) === el;
140
+ };
141
+ // Annotate the CommonJS export names for ESM import in node:
142
+ 0 && (module.exports = {
143
+ ariaAttr,
144
+ createdDom,
145
+ dataAttr,
146
+ getActiveElement,
147
+ getAllFocusable,
148
+ getEventRelatedTarget,
149
+ getOwnerDocument,
150
+ getOwnerWindow,
151
+ getPlatform,
152
+ hasNegativeTabIndex,
153
+ hasTabIndex,
154
+ isActiveElement,
155
+ isApple,
156
+ isContains,
157
+ isContentEditable,
158
+ isDisabled,
159
+ isElement,
160
+ isFocusable,
161
+ isHTMLElement,
162
+ isHidden,
163
+ isMac,
164
+ isSafari,
165
+ isTabbable,
166
+ platform,
167
+ vendor
168
+ });
package/dist/dom.mjs ADDED
@@ -0,0 +1,54 @@
1
+ import {
2
+ ariaAttr,
3
+ createdDom,
4
+ dataAttr,
5
+ getActiveElement,
6
+ getAllFocusable,
7
+ getEventRelatedTarget,
8
+ getOwnerDocument,
9
+ getOwnerWindow,
10
+ getPlatform,
11
+ hasNegativeTabIndex,
12
+ hasTabIndex,
13
+ isActiveElement,
14
+ isApple,
15
+ isContains,
16
+ isContentEditable,
17
+ isDisabled,
18
+ isElement,
19
+ isFocusable,
20
+ isHTMLElement,
21
+ isHidden,
22
+ isMac,
23
+ isSafari,
24
+ isTabbable,
25
+ platform,
26
+ vendor
27
+ } from "./chunk-FW7XS4NH.mjs";
28
+ export {
29
+ ariaAttr,
30
+ createdDom,
31
+ dataAttr,
32
+ getActiveElement,
33
+ getAllFocusable,
34
+ getEventRelatedTarget,
35
+ getOwnerDocument,
36
+ getOwnerWindow,
37
+ getPlatform,
38
+ hasNegativeTabIndex,
39
+ hasTabIndex,
40
+ isActiveElement,
41
+ isApple,
42
+ isContains,
43
+ isContentEditable,
44
+ isDisabled,
45
+ isElement,
46
+ isFocusable,
47
+ isHTMLElement,
48
+ isHidden,
49
+ isMac,
50
+ isSafari,
51
+ isTabbable,
52
+ platform,
53
+ vendor
54
+ };
@@ -0,0 +1,30 @@
1
+ type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent;
2
+ type PointType = 'page' | 'client';
3
+ type Point = {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ type PointerEventInfo = {
8
+ point: Point;
9
+ };
10
+ type MixedEventListener = (e: AnyPointerEvent, info: PointerEventInfo) => void;
11
+ declare const isMouseEvent: (ev: any) => ev is MouseEvent;
12
+ declare const isTouchEvent: (ev: AnyPointerEvent) => ev is TouchEvent;
13
+ declare const isMultiTouchEvent: (ev: AnyPointerEvent) => boolean;
14
+ declare const getEventWindow: (ev: Event) => typeof globalThis;
15
+ declare const pointFromTouch: (e: TouchEvent, type?: PointType) => {
16
+ x: number;
17
+ y: number;
18
+ };
19
+ declare const pointFromMouse: (point: MouseEvent | PointerEvent, type?: PointType) => {
20
+ x: number;
21
+ y: number;
22
+ };
23
+ declare const getEventPoint: (ev: AnyPointerEvent, type?: PointType) => {
24
+ x: number;
25
+ y: number;
26
+ };
27
+ declare const addDomEvent: (target: EventTarget, type: string, cb: EventListener, options?: AddEventListenerOptions) => () => void;
28
+ declare const addPointerEvent: (target: EventTarget, type: string, cb: MixedEventListener, options?: AddEventListenerOptions) => () => void;
29
+
30
+ export { AnyPointerEvent, MixedEventListener, Point, PointType, PointerEventInfo, addDomEvent, addPointerEvent, getEventPoint, getEventWindow, isMouseEvent, isMultiTouchEvent, isTouchEvent, pointFromMouse, pointFromTouch };
package/dist/event.js ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/event.ts
21
+ var event_exports = {};
22
+ __export(event_exports, {
23
+ addDomEvent: () => addDomEvent,
24
+ addPointerEvent: () => addPointerEvent,
25
+ getEventPoint: () => getEventPoint,
26
+ getEventWindow: () => getEventWindow,
27
+ isMouseEvent: () => isMouseEvent,
28
+ isMultiTouchEvent: () => isMultiTouchEvent,
29
+ isTouchEvent: () => isTouchEvent,
30
+ pointFromMouse: () => pointFromMouse,
31
+ pointFromTouch: () => pointFromTouch
32
+ });
33
+ module.exports = __toCommonJS(event_exports);
34
+ var isMouseEvent = (ev) => {
35
+ const win = getEventWindow(ev);
36
+ if (typeof win.PointerEvent !== "undefined" && ev instanceof win.PointerEvent)
37
+ return !!(ev.pointerType === "mouse");
38
+ return ev instanceof win.MouseEvent;
39
+ };
40
+ var isTouchEvent = (ev) => !!ev.touches;
41
+ var isMultiTouchEvent = (ev) => isTouchEvent(ev) && ev.touches.length > 1;
42
+ var getEventWindow = (ev) => {
43
+ var _a;
44
+ return (_a = ev.view) != null ? _a : window;
45
+ };
46
+ var pointFromTouch = (e, type = "page") => {
47
+ const point = e.touches[0] || e.changedTouches[0];
48
+ return { x: point[`${type}X`], y: point[`${type}Y`] };
49
+ };
50
+ var pointFromMouse = (point, type = "page") => ({
51
+ x: point[`${type}X`],
52
+ y: point[`${type}Y`]
53
+ });
54
+ var getEventPoint = (ev, type = "page") => isTouchEvent(ev) ? pointFromTouch(ev, type) : pointFromMouse(ev, type);
55
+ var addDomEvent = (target, type, cb, options) => {
56
+ target.addEventListener(type, cb, options);
57
+ return () => {
58
+ target.removeEventListener(type, cb, options);
59
+ };
60
+ };
61
+ var filter = (cb) => (event) => {
62
+ const isMouse = isMouseEvent(event);
63
+ if (!isMouse || isMouse && event.button === 0)
64
+ cb(event);
65
+ };
66
+ var wrap = (cb, filterPrimary = false) => {
67
+ const listener = (event) => cb(event, { point: getEventPoint(event) });
68
+ const fn = filterPrimary ? filter(listener) : listener;
69
+ return fn;
70
+ };
71
+ var addPointerEvent = (target, type, cb, options) => addDomEvent(target, type, wrap(cb, type === "pointerdown"), options);
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ addDomEvent,
75
+ addPointerEvent,
76
+ getEventPoint,
77
+ getEventWindow,
78
+ isMouseEvent,
79
+ isMultiTouchEvent,
80
+ isTouchEvent,
81
+ pointFromMouse,
82
+ pointFromTouch
83
+ });
package/dist/event.mjs ADDED
@@ -0,0 +1,22 @@
1
+ import {
2
+ addDomEvent,
3
+ addPointerEvent,
4
+ getEventPoint,
5
+ getEventWindow,
6
+ isMouseEvent,
7
+ isMultiTouchEvent,
8
+ isTouchEvent,
9
+ pointFromMouse,
10
+ pointFromTouch
11
+ } from "./chunk-PF7LRFIA.mjs";
12
+ export {
13
+ addDomEvent,
14
+ addPointerEvent,
15
+ getEventPoint,
16
+ getEventWindow,
17
+ isMouseEvent,
18
+ isMultiTouchEvent,
19
+ isTouchEvent,
20
+ pointFromMouse,
21
+ pointFromTouch
22
+ };
@@ -0,0 +1,6 @@
1
+ declare const noop: () => void;
2
+ declare const runIfFunc: <T, U extends any[]>(valOrFunc: T | ((...funcArgs: U) => T), ...args: U) => T;
3
+ declare const handlerAll: <T extends (event: any) => void>(...funcs: (T | undefined)[]) => (event: (T extends (...args: infer R) => any ? R : never)[0]) => void;
4
+ declare const funcAll: <T extends (...args: any[]) => any>(...funcs: (T | undefined)[]) => (arg: (T extends (...args: infer R) => any ? R : never)[0]) => void;
5
+
6
+ export { funcAll, handlerAll, noop, runIfFunc };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/function.ts
21
+ var function_exports = {};
22
+ __export(function_exports, {
23
+ funcAll: () => funcAll,
24
+ handlerAll: () => handlerAll,
25
+ noop: () => noop,
26
+ runIfFunc: () => runIfFunc
27
+ });
28
+ module.exports = __toCommonJS(function_exports);
29
+
30
+ // src/assertion.ts
31
+ var isFunction = (value) => typeof value === "function";
32
+
33
+ // src/function.ts
34
+ var noop = () => {
35
+ };
36
+ var runIfFunc = (valOrFunc, ...args) => isFunction(valOrFunc) ? valOrFunc(...args) : valOrFunc;
37
+ var handlerAll = (...funcs) => (event) => {
38
+ funcs.some((func) => {
39
+ func == null ? void 0 : func(event);
40
+ return event == null ? void 0 : event.defaultPrevented;
41
+ });
42
+ };
43
+ var funcAll = (...funcs) => (arg) => funcs.forEach((func) => func == null ? void 0 : func(arg));
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ funcAll,
47
+ handlerAll,
48
+ noop,
49
+ runIfFunc
50
+ });
@@ -0,0 +1,20 @@
1
+ import {
2
+ funcAll,
3
+ handlerAll,
4
+ noop,
5
+ runIfFunc
6
+ } from "./chunk-HUEOJZVC.mjs";
7
+ import "./chunk-SLJ4M7XC.mjs";
8
+ import "./chunk-VYMGBE25.mjs";
9
+ import "./chunk-BZAW2D6U.mjs";
10
+ import "./chunk-PURW64JE.mjs";
11
+ import "./chunk-IVGIIDMV.mjs";
12
+ import "./chunk-R5OUKGQ5.mjs";
13
+ import "./chunk-FW7XS4NH.mjs";
14
+ import "./chunk-PF7LRFIA.mjs";
15
+ export {
16
+ funcAll,
17
+ handlerAll,
18
+ noop,
19
+ runIfFunc
20
+ };