@yamada-ui/utils 2.0.0-dev-20240531201720 → 2.0.0-dev-20250626073729

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 (171) hide show
  1. package/README.md +7 -13
  2. package/dist/cjs/_virtual/rolldown_runtime.cjs +30 -0
  3. package/dist/cjs/array.cjs +14 -0
  4. package/dist/cjs/array.cjs.map +1 -0
  5. package/dist/cjs/assertion.cjs +73 -0
  6. package/dist/cjs/assertion.cjs.map +1 -0
  7. package/dist/cjs/calc.cjs +39 -0
  8. package/dist/cjs/calc.cjs.map +1 -0
  9. package/dist/cjs/color.cjs +247 -0
  10. package/dist/cjs/color.cjs.map +1 -0
  11. package/dist/cjs/dom.cjs +378 -0
  12. package/dist/cjs/dom.cjs.map +1 -0
  13. package/dist/cjs/event.cjs +92 -0
  14. package/dist/cjs/event.cjs.map +1 -0
  15. package/dist/cjs/function.cjs +27 -0
  16. package/dist/cjs/function.cjs.map +1 -0
  17. package/dist/cjs/i18n.cjs +46 -0
  18. package/dist/cjs/i18n.cjs.map +1 -0
  19. package/dist/cjs/index.cjs +148 -0
  20. package/dist/cjs/index.types.cjs +0 -0
  21. package/dist/cjs/module.cjs +9 -0
  22. package/dist/cjs/module.cjs.map +1 -0
  23. package/dist/cjs/number.cjs +46 -0
  24. package/dist/cjs/number.cjs.map +1 -0
  25. package/dist/cjs/object.cjs +120 -0
  26. package/dist/cjs/object.cjs.map +1 -0
  27. package/dist/cjs/string.cjs +95 -0
  28. package/dist/cjs/string.cjs.map +1 -0
  29. package/dist/esm/array.js +13 -0
  30. package/dist/esm/array.js.map +1 -0
  31. package/dist/esm/assertion.js +56 -0
  32. package/dist/esm/assertion.js.map +1 -0
  33. package/dist/esm/calc.js +38 -0
  34. package/dist/esm/calc.js.map +1 -0
  35. package/dist/esm/color.js +232 -0
  36. package/dist/esm/color.js.map +1 -0
  37. package/dist/esm/dom.js +325 -0
  38. package/dist/esm/dom.js.map +1 -0
  39. package/dist/esm/event.js +83 -0
  40. package/dist/esm/event.js.map +1 -0
  41. package/dist/esm/function.js +24 -0
  42. package/dist/esm/function.js.map +1 -0
  43. package/dist/esm/i18n.js +45 -0
  44. package/dist/esm/i18n.js.map +1 -0
  45. package/dist/esm/index.js +14 -0
  46. package/dist/esm/index.types.js +0 -0
  47. package/dist/esm/module.js +8 -0
  48. package/dist/esm/module.js.map +1 -0
  49. package/dist/esm/number.js +39 -0
  50. package/dist/esm/number.js.map +1 -0
  51. package/dist/esm/object.js +108 -0
  52. package/dist/esm/object.js.map +1 -0
  53. package/dist/esm/string.js +86 -0
  54. package/dist/esm/string.js.map +1 -0
  55. package/dist/types/array.d.ts +6 -0
  56. package/dist/types/assertion.d.ts +23 -0
  57. package/dist/types/calc.d.ts +25 -0
  58. package/dist/types/color.d.ts +20 -0
  59. package/dist/types/dom.d.ts +61 -0
  60. package/dist/types/event.d.ts +21 -0
  61. package/dist/types/function.d.ts +8 -0
  62. package/dist/types/i18n.d.ts +5 -0
  63. package/dist/types/index.d.ts +14 -0
  64. package/dist/types/index.types.d.ts +15 -0
  65. package/dist/types/module.d.ts +5 -0
  66. package/dist/types/number.d.ts +11 -0
  67. package/dist/types/object.d.ts +36 -0
  68. package/dist/types/string.d.ts +16 -0
  69. package/package.json +26 -27
  70. package/dist/array.d.mts +0 -3
  71. package/dist/array.d.ts +0 -3
  72. package/dist/array.js +0 -31
  73. package/dist/array.js.map +0 -1
  74. package/dist/array.mjs +0 -7
  75. package/dist/array.mjs.map +0 -1
  76. package/dist/assertion.d.mts +0 -17
  77. package/dist/assertion.d.ts +0 -17
  78. package/dist/assertion.js +0 -67
  79. package/dist/assertion.js.map +0 -1
  80. package/dist/assertion.mjs +0 -31
  81. package/dist/assertion.mjs.map +0 -1
  82. package/dist/calc.d.mts +0 -18
  83. package/dist/calc.d.ts +0 -18
  84. package/dist/calc.js +0 -57
  85. package/dist/calc.js.map +0 -1
  86. package/dist/calc.mjs +0 -7
  87. package/dist/calc.mjs.map +0 -1
  88. package/dist/chunk-5OUUTZYQ.mjs +0 -7
  89. package/dist/chunk-5OUUTZYQ.mjs.map +0 -1
  90. package/dist/chunk-A74F6ICI.mjs +0 -52
  91. package/dist/chunk-A74F6ICI.mjs.map +0 -1
  92. package/dist/chunk-L56KWSQO.mjs +0 -33
  93. package/dist/chunk-L56KWSQO.mjs.map +0 -1
  94. package/dist/chunk-L76GM3GN.mjs +0 -50
  95. package/dist/chunk-L76GM3GN.mjs.map +0 -1
  96. package/dist/chunk-P52P4NMT.mjs +0 -41
  97. package/dist/chunk-P52P4NMT.mjs.map +0 -1
  98. package/dist/chunk-P5JCSYB3.mjs +0 -31
  99. package/dist/chunk-P5JCSYB3.mjs.map +0 -1
  100. package/dist/chunk-PZXEZGEL.mjs +0 -811
  101. package/dist/chunk-PZXEZGEL.mjs.map +0 -1
  102. package/dist/chunk-RSDBT4DI.mjs +0 -1
  103. package/dist/chunk-RSDBT4DI.mjs.map +0 -1
  104. package/dist/chunk-WV6P7ZCI.mjs +0 -7
  105. package/dist/chunk-WV6P7ZCI.mjs.map +0 -1
  106. package/dist/color.d.mts +0 -33
  107. package/dist/color.d.ts +0 -33
  108. package/dist/color.js +0 -374
  109. package/dist/color.js.map +0 -1
  110. package/dist/color.mjs +0 -61
  111. package/dist/color.mjs.map +0 -1
  112. package/dist/dom.d.mts +0 -34
  113. package/dist/dom.d.ts +0 -34
  114. package/dist/dom.js +0 -196
  115. package/dist/dom.js.map +0 -1
  116. package/dist/dom.mjs +0 -65
  117. package/dist/dom.mjs.map +0 -1
  118. package/dist/event.d.mts +0 -30
  119. package/dist/event.d.ts +0 -30
  120. package/dist/event.js +0 -84
  121. package/dist/event.js.map +0 -1
  122. package/dist/event.mjs +0 -23
  123. package/dist/event.mjs.map +0 -1
  124. package/dist/function.d.mts +0 -6
  125. package/dist/function.d.ts +0 -6
  126. package/dist/function.js +0 -51
  127. package/dist/function.js.map +0 -1
  128. package/dist/function.mjs +0 -21
  129. package/dist/function.mjs.map +0 -1
  130. package/dist/index.d.mts +0 -14
  131. package/dist/index.d.ts +0 -14
  132. package/dist/index.js +0 -1162
  133. package/dist/index.js.map +0 -1
  134. package/dist/index.mjs +0 -270
  135. package/dist/index.mjs.map +0 -1
  136. package/dist/index.types.d.mts +0 -12
  137. package/dist/index.types.d.ts +0 -12
  138. package/dist/index.types.js +0 -19
  139. package/dist/index.types.js.map +0 -1
  140. package/dist/index.types.mjs +0 -2
  141. package/dist/index.types.mjs.map +0 -1
  142. package/dist/module.d.mts +0 -3
  143. package/dist/module.d.ts +0 -3
  144. package/dist/module.js +0 -31
  145. package/dist/module.js.map +0 -1
  146. package/dist/module.mjs +0 -7
  147. package/dist/module.mjs.map +0 -1
  148. package/dist/number.d.mts +0 -9
  149. package/dist/number.d.ts +0 -9
  150. package/dist/number.js +0 -71
  151. package/dist/number.js.map +0 -1
  152. package/dist/number.mjs +0 -19
  153. package/dist/number.mjs.map +0 -1
  154. package/dist/object.d.mts +0 -18
  155. package/dist/object.d.ts +0 -18
  156. package/dist/object.js +0 -220
  157. package/dist/object.js.map +0 -1
  158. package/dist/object.mjs +0 -41
  159. package/dist/object.mjs.map +0 -1
  160. package/dist/react.d.mts +0 -105
  161. package/dist/react.d.ts +0 -105
  162. package/dist/react.js +0 -258
  163. package/dist/react.js.map +0 -1
  164. package/dist/react.mjs +0 -55
  165. package/dist/react.mjs.map +0 -1
  166. package/dist/string.d.mts +0 -8
  167. package/dist/string.d.ts +0 -8
  168. package/dist/string.js +0 -77
  169. package/dist/string.js.map +0 -1
  170. package/dist/string.mjs +0 -13
  171. package/dist/string.mjs.map +0 -1
@@ -0,0 +1,21 @@
1
+ //#region src/event.d.ts
2
+ type AnyPointerEvent = MouseEvent | PointerEvent | TouchEvent;
3
+ interface Point {
4
+ x: number;
5
+ y: number;
6
+ }
7
+ declare function isMouseEvent(ev: any): ev is MouseEvent;
8
+ declare function isTouchEvent(ev: AnyPointerEvent): ev is TouchEvent;
9
+ declare function isMultiTouchEvent(ev: AnyPointerEvent): boolean;
10
+ declare function getEventWindow(ev: Event): typeof globalThis;
11
+ declare function pointFromTouch(e: TouchEvent, type?: "client" | "page"): Point;
12
+ declare function pointFromMouse(point: MouseEvent | PointerEvent, type?: "client" | "page"): Point;
13
+ declare function getEventPoint(ev: AnyPointerEvent, type?: "client" | "page"): Point;
14
+ interface EventMap extends DocumentEventMap, GlobalEventHandlersEventMap, WindowEventMap, FontFaceSetEventMap {}
15
+ type EventType = keyof EventMap;
16
+ declare function addDomEvent<Y extends EventType>(target: EventTarget, type: Y, cb: (ev: EventMap[Y]) => void, options?: AddEventListenerOptions | boolean): () => void;
17
+ declare function focusTrap(el: HTMLElement | null, onFocus?: (elToFocus: HTMLElement) => void): () => void;
18
+ declare function focusTransfer(el: HTMLElement | null, target?: HTMLElement | null, onFocus?: (elToFocus: HTMLElement) => void): () => void;
19
+ //#endregion
20
+ export { AnyPointerEvent, EventMap, EventType, Point, addDomEvent, focusTransfer, focusTrap, getEventPoint, getEventWindow, isMouseEvent, isMultiTouchEvent, isTouchEvent, pointFromMouse, pointFromTouch };
21
+ //# sourceMappingURL=event.d.ts.map
@@ -0,0 +1,8 @@
1
+ //#region src/function.d.ts
2
+ declare const noop: () => void;
3
+ declare function runIfFn<T, U extends any[]>(valOrFunc: ((...funcArgs: U) => T) | T, ...args: U): T;
4
+ declare function handlerAll<T extends (event: any, ...args: any[]) => void>(...funcs: (null | 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;
5
+ declare function fnAll<T extends (...args: any[]) => any>(...funcs: (null | T | undefined)[]): (...args: T extends ((...args: infer R) => any) ? R : never) => void;
6
+ //#endregion
7
+ export { fnAll, handlerAll, noop, runIfFn };
8
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1,5 @@
1
+ //#region src/i18n.d.ts
2
+ declare function isRtl(_locale: string): boolean;
3
+ //#endregion
4
+ export { isRtl };
5
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1,14 @@
1
+ import { filterEmpty, toArray } from "./array.js";
2
+ import { AnyString, Booleanish, Dict, Length, Merge, Path, Primitive, Value } from "./index.types.js";
3
+ import { cast, is, isArray, isBoolean, isBooleanish, isEmpty, isEmptyObject, isFunction, isNotNumber, isNull, isNumber, isNumeric, isObject, isRegExp, isString, isUndefined, isUnit } from "./assertion.js";
4
+ import { Operand, calc } from "./calc.js";
5
+ import { COLOR_SCHEMES, ColorFormat, DEFAULT_COLOR_SCHEMES, SEMANTIC_COLOR_SCHEMES, TONES, alphaToHex, calcFormat, convertColor, getAlpha, hslaTo, hsvTo, parseToHsla, parseToHsv, parseToRgba, rgbaTo, sameColor } from "./color.js";
6
+ import { ariaAttr, contains, createdDom, dataAttr, getActiveElement, getDocument, getDocumentElement, getFirstFocusableElement, getFirstTabbableElement, getFocusableElements, getLastTabbableElement, getNextTabbableElement, getNodeName, getParentNode, getPlatform, getPx, getTabIndex, getTabbableElementEdges, getTabbableElements, getUserAgent, getWindow, isActiveElement, isAndroid, isApple, isChrome, isDisabledElement, isDocument, isEditableElement, isFirefox, isFocusableElement, isFrame, isHTMLElement, isHiddenElement, isIPad, isIPhone, isInputElement, isIos, isMac, isNode, isSafari, isShadowRoot, isTabbableElement, isTouchDevice, isVisibleElement, isVisualViewport, isWebKit, isWindow, platform, scrollLock, setAttribute, setStyle, userAgent, uuid, vendor } from "./dom.js";
7
+ import { AnyPointerEvent, EventMap, EventType, Point, addDomEvent, focusTransfer, focusTrap, getEventPoint, getEventWindow, isMouseEvent, isMultiTouchEvent, isTouchEvent, pointFromMouse, pointFromTouch } from "./event.js";
8
+ import { fnAll, handlerAll, noop, runIfFn } from "./function.js";
9
+ import { isRtl } from "./i18n.js";
10
+ import { interopDefault } from "./module.js";
11
+ import { clampNumber, countDecimal, percentToValue, roundNumberToStep, toNumber, toPrecision, valueToPercent } from "./number.js";
12
+ import { FlattenObjectOptions, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, memoizeObject, merge, mergeOptions, objectKeys, omitObject, pickObject, replaceObject, splitObject, wrapWithKey } from "./object.js";
13
+ import { antonym, bem, cx, escape, isSize, toCamelCase, toKebabCase, toPascalCase, toTitleCase, transformSize } from "./string.js";
14
+ export { AnyPointerEvent, AnyString, Booleanish, COLOR_SCHEMES, ColorFormat, DEFAULT_COLOR_SCHEMES, Dict, EventMap, EventType, FlattenObjectOptions, Length, Merge, Operand, Path, Point, Primitive, SEMANTIC_COLOR_SCHEMES, TONES, Value, addDomEvent, alphaToHex, antonym, ariaAttr, bem, calc, calcFormat, cast, clampNumber, contains, convertColor, countDecimal, createdDom, cx, dataAttr, escape, filterEmpty, filterObject, filterUndefined, flattenObject, fnAll, focusTransfer, focusTrap, getActiveElement, getAlpha, getDocument, getDocumentElement, getEventPoint, getEventWindow, getFirstFocusableElement, getFirstTabbableElement, getFocusableElements, getLastTabbableElement, getMemoizedObject, getNextTabbableElement, getNodeName, getObject, getParentNode, getPlatform, getPx, getTabIndex, getTabbableElementEdges, getTabbableElements, getUserAgent, getWindow, handlerAll, hslaTo, hsvTo, interopDefault, is, isActiveElement, isAndroid, isApple, isArray, isBoolean, isBooleanish, isChrome, isDisabledElement, isDocument, isEditableElement, isEmpty, isEmptyObject, isFirefox, isFocusableElement, isFrame, isFunction, isHTMLElement, isHiddenElement, isIPad, isIPhone, isInputElement, isIos, isMac, isMouseEvent, isMultiTouchEvent, isNode, isNotNumber, isNull, isNumber, isNumeric, isObject, isRegExp, isRtl, isSafari, isShadowRoot, isSize, isString, isTabbableElement, isTouchDevice, isTouchEvent, isUndefined, isUnit, isVisibleElement, isVisualViewport, isWebKit, isWindow, memoizeObject, merge, mergeOptions, noop, objectKeys, omitObject, parseToHsla, parseToHsv, parseToRgba, percentToValue, pickObject, platform, pointFromMouse, pointFromTouch, replaceObject, rgbaTo, roundNumberToStep, runIfFn, sameColor, scrollLock, setAttribute, setStyle, splitObject, toArray, toCamelCase, toKebabCase, toNumber, toPascalCase, toPrecision, toTitleCase, transformSize, userAgent, uuid, valueToPercent, vendor, wrapWithKey };
@@ -0,0 +1,15 @@
1
+ //#region src/index.types.d.ts
2
+ type Primitive = bigint | boolean | null | number | string | symbol | undefined;
3
+ type PathImpl<Y extends number | string | symbol, M> = Y extends number | string ? M extends Primitive ? `${Y}` : `${Y}.${Path<M>}` : ``;
4
+ type Path<Y> = Y extends any[] ? `${number}` : { [M in keyof Y]-?: PathImpl<M, Y[M]> }[keyof Y];
5
+ type Value<Y extends Dict, M extends string> = M extends `${infer D}.${infer H}` ? Value<Y[D], H> : Y[M];
6
+ interface Dict<Y = any> {
7
+ [key: string]: Y;
8
+ }
9
+ type AnyString = string & {};
10
+ type Booleanish<Y> = Y extends "false" | "true" ? boolean : Y;
11
+ type Length<T extends any[]> = T["length"];
12
+ type Merge<Y, M> = M & Omit<Y, keyof M>;
13
+ //#endregion
14
+ export { AnyString, Booleanish, Dict, Length, Merge, Path, Primitive, Value };
15
+ //# sourceMappingURL=index.types.d.ts.map
@@ -0,0 +1,5 @@
1
+ //#region src/module.d.ts
2
+ declare function interopDefault<T>(module: T): T;
3
+ //#endregion
4
+ export { interopDefault };
5
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1,11 @@
1
+ //#region src/number.d.ts
2
+ declare function toNumber(n: any): number;
3
+ declare function toPrecision(n: number, precision?: number): string;
4
+ declare function countDecimal(n: number): number;
5
+ declare function roundNumberToStep(n: number, from: number, step: number): string;
6
+ declare function valueToPercent(n: number, min: number, max: number): number;
7
+ declare function percentToValue(n: number, min: number, max: number): number;
8
+ declare function clampNumber(n: number, min: number, max: number): number;
9
+ //#endregion
10
+ export { clampNumber, countDecimal, percentToValue, roundNumberToStep, toNumber, toPrecision, valueToPercent };
11
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1,36 @@
1
+ import { Dict } from "./index.types.js";
2
+
3
+ //#region src/object.d.ts
4
+ declare function omitObject<Y extends Dict, M extends keyof Y>(obj: Y, keys: M[] | readonly M[]): Omit<Y, M>;
5
+ declare function pickObject<Y extends Dict, M extends keyof Y>(obj: Y, keys: M[] | readonly M[]): { [D in M]: Y[D] };
6
+ declare function splitObject<Y extends Dict, M extends keyof Y>(obj: Y, funcOrKeys?: M[] | readonly M[]): [{ [D in M]: Y[D] }, Omit<Y, M>];
7
+ declare function splitObject<Y extends Dict, M extends Dict>(obj: Dict, funcOrKeys?: (key: string) => boolean): [Y, M];
8
+ declare function filterObject<Y extends Dict, M extends Dict>(obj: Y, func: (key: keyof Y, value: Y[keyof Y], obj: Y) => boolean): M;
9
+ declare function filterUndefined<Y extends Dict>(obj: Y): Y;
10
+ interface mergeOptions {
11
+ debug?: boolean;
12
+ mergeArray?: boolean;
13
+ shouldProcess?: (value: any) => boolean;
14
+ }
15
+ declare function merge<Y extends Dict>(target: any, source: any, options?: mergeOptions): Y;
16
+ interface FlattenObjectOptions {
17
+ maxDepth?: number;
18
+ separator?: string;
19
+ shouldProcess?: (value: any) => boolean;
20
+ }
21
+ declare function flattenObject<Y extends Dict>(obj: any, {
22
+ maxDepth,
23
+ separator,
24
+ shouldProcess
25
+ }?: FlattenObjectOptions): Y;
26
+ declare function objectKeys<Y extends object>(obj: Y): (keyof Y)[];
27
+ declare function replaceObject<Y = any>(objOrArray: Y, callBack: (value: any) => any): Y;
28
+ declare function getObject(obj: Dict | undefined, path: number | string, fallback?: any): any;
29
+ declare function memoizeObject(func: typeof getObject): <Y>(obj: Dict, path: number | string, fallback?: any) => Y;
30
+ declare const getMemoizedObject: <Y>(obj: Dict, path: number | string, fallback?: any) => Y;
31
+ declare function wrapWithKey<T>(obj: T, key?: string): T | {
32
+ [key]: T;
33
+ };
34
+ //#endregion
35
+ export { FlattenObjectOptions, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, memoizeObject, merge, mergeOptions, objectKeys, omitObject, pickObject, replaceObject, splitObject, wrapWithKey };
36
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { AnyString } from "./index.types.js";
2
+
3
+ //#region src/string.d.ts
4
+ declare function cx(...classNames: (string | undefined)[]): string;
5
+ declare function escape(value: string, replaceValue?: string): string;
6
+ declare function antonym(value: string): string;
7
+ declare function isSize(value: any): boolean;
8
+ declare function transformSize<Y = string>(token: string | undefined, value: number, omitTokens?: null | string[]): undefined | Y;
9
+ declare function toCamelCase(value: AnyString): string;
10
+ declare function toPascalCase(value: AnyString): string;
11
+ declare function toKebabCase(value: AnyString): string;
12
+ declare function toTitleCase(value: AnyString): string;
13
+ declare function bem(block: string, element?: string, modifier?: string): string;
14
+ //#endregion
15
+ export { antonym, bem, cx, escape, isSize, toCamelCase, toKebabCase, toPascalCase, toTitleCase, transformSize };
16
+ //# sourceMappingURL=string.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@yamada-ui/utils",
3
- "version": "2.0.0-dev-20240531201720",
4
- "description": "Yamada UI utils",
3
+ "type": "module",
4
+ "version": "2.0.0-dev-20250626073729",
5
+ "description": "The utilities for Yamada UI projects",
5
6
  "keywords": [
6
7
  "utils",
7
8
  "utilities",
@@ -11,7 +12,7 @@
11
12
  ],
12
13
  "author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
13
14
  "license": "MIT",
14
- "main": "dist/index.js",
15
+ "main": "dist/esm/index.js",
15
16
  "files": [
16
17
  "dist"
17
18
  ],
@@ -22,47 +23,45 @@
22
23
  "homepage": "https://yamada-ui.com",
23
24
  "repository": {
24
25
  "type": "git",
25
- "url": "git+https://github.com/yamada-ui/yamada-ui",
26
+ "url": "https://github.com/yamada-ui/yamada-ui",
26
27
  "directory": "packages/utils"
27
28
  },
28
29
  "bugs": {
29
30
  "url": "https://github.com/yamada-ui/yamada-ui/issues"
30
31
  },
31
32
  "dependencies": {
32
- "color2k": "^2.0.2"
33
+ "color2k": "^2.0.3"
33
34
  },
34
35
  "devDependencies": {
35
36
  "clean-package": "2.2.0",
36
- "react": "^18.0.0"
37
+ "react": "^19.1.0"
37
38
  },
38
39
  "peerDependencies": {
39
- "react": ">=18"
40
+ "react": ">=19"
40
41
  },
41
- "clean-package": "../../clean-package.config.json",
42
- "tsup": {
43
- "clean": true,
44
- "target": "es2019",
45
- "format": [
46
- "cjs",
47
- "esm"
48
- ],
49
- "sourcemap": true
50
- },
51
- "module": "dist/index.mjs",
52
- "types": "dist/index.d.ts",
42
+ "clean-package": "./clean-package.config.json",
43
+ "types": "dist/types/index.d.ts",
53
44
  "exports": {
54
45
  ".": {
55
- "types": "./dist/index.d.ts",
56
- "import": "./dist/index.mjs",
57
- "require": "./dist/index.js"
46
+ "source": "./src/index.ts",
47
+ "import": {
48
+ "types": "./dist/types/index.d.ts",
49
+ "default": "./dist/esm/index.js"
50
+ },
51
+ "require": {
52
+ "types": "./dist/types/index.d.ts",
53
+ "default": "./dist/cjs/index.cjs"
54
+ }
58
55
  },
59
56
  "./package.json": "./package.json"
60
57
  },
61
58
  "scripts": {
62
- "dev": "pnpm build:fast -- --watch",
63
- "build": "tsup src --dts",
64
- "build:fast": "tsup src",
65
- "clean": "rimraf dist .turbo",
66
- "typecheck": "tsc --noEmit"
59
+ "clean": "rimraf dist .turbo .eslintcache",
60
+ "build": "tsdown",
61
+ "test": "vitest",
62
+ "test:dev": "vitest --watch --ui",
63
+ "typecheck": "tsc --noEmit",
64
+ "lint": "eslint . --max-warnings=0 --cache",
65
+ "format": "prettier . --ignore-path ../../.prettierignore --check --cache"
67
66
  }
68
67
  }
package/dist/array.d.mts DELETED
@@ -1,3 +0,0 @@
1
- declare const filterEmpty: <T extends any[]>(array: T) => any[];
2
-
3
- export { filterEmpty };
package/dist/array.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare const filterEmpty: <T extends any[]>(array: T) => any[];
2
-
3
- export { filterEmpty };
package/dist/array.js DELETED
@@ -1,31 +0,0 @@
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/array.ts
21
- var array_exports = {};
22
- __export(array_exports, {
23
- filterEmpty: () => filterEmpty
24
- });
25
- module.exports = __toCommonJS(array_exports);
26
- var filterEmpty = (array) => array.filter((value) => value != null);
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- filterEmpty
30
- });
31
- //# sourceMappingURL=array.js.map
package/dist/array.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/array.ts"],"sourcesContent":["export const filterEmpty = <T extends any[]>(array: T) =>\n array.filter((value) => value != null)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,cAAc,CAAkB,UAC3C,MAAM,OAAO,CAAC,UAAU,SAAS,IAAI;","names":[]}
package/dist/array.mjs DELETED
@@ -1,7 +0,0 @@
1
- import {
2
- filterEmpty
3
- } from "./chunk-WV6P7ZCI.mjs";
4
- export {
5
- filterEmpty
6
- };
7
- //# sourceMappingURL=array.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,17 +0,0 @@
1
- import { Dict } from './index.types.mjs';
2
-
3
- declare const isNumber: (value: any) => value is number;
4
- declare const isNotNumber: (value: any) => boolean;
5
- declare const isNumeric: (value: any) => boolean;
6
- declare const isString: (value: any) => value is string;
7
- declare const isBoolean: (value: any) => value is boolean;
8
- declare const isUndefined: (value: any) => value is undefined;
9
- declare const isNull: (value: any) => value is null;
10
- declare const isObject: <T extends Dict>(value: any) => value is T;
11
- declare const isArray: <T extends any[]>(value: any) => value is T;
12
- declare const isEmpty: (value: any) => boolean;
13
- declare const isFunction: <T extends Function = Function>(value: any) => value is T;
14
- declare const isUnit: (value: any) => boolean;
15
- declare const cast: <T>(value: any) => T;
16
-
17
- export { cast, isArray, isBoolean, isEmpty, isFunction, isNotNumber, isNull, isNumber, isNumeric, isObject, isString, isUndefined, isUnit };
@@ -1,17 +0,0 @@
1
- import { Dict } from './index.types.js';
2
-
3
- declare const isNumber: (value: any) => value is number;
4
- declare const isNotNumber: (value: any) => boolean;
5
- declare const isNumeric: (value: any) => boolean;
6
- declare const isString: (value: any) => value is string;
7
- declare const isBoolean: (value: any) => value is boolean;
8
- declare const isUndefined: (value: any) => value is undefined;
9
- declare const isNull: (value: any) => value is null;
10
- declare const isObject: <T extends Dict>(value: any) => value is T;
11
- declare const isArray: <T extends any[]>(value: any) => value is T;
12
- declare const isEmpty: (value: any) => boolean;
13
- declare const isFunction: <T extends Function = Function>(value: any) => value is T;
14
- declare const isUnit: (value: any) => boolean;
15
- declare const cast: <T>(value: any) => T;
16
-
17
- export { cast, isArray, isBoolean, isEmpty, isFunction, isNotNumber, isNull, isNumber, isNumeric, isObject, isString, isUndefined, isUnit };
package/dist/assertion.js DELETED
@@ -1,67 +0,0 @@
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/assertion.ts
21
- var assertion_exports = {};
22
- __export(assertion_exports, {
23
- cast: () => cast,
24
- isArray: () => isArray,
25
- isBoolean: () => isBoolean,
26
- isEmpty: () => isEmpty,
27
- isFunction: () => isFunction,
28
- isNotNumber: () => isNotNumber,
29
- isNull: () => isNull,
30
- isNumber: () => isNumber,
31
- isNumeric: () => isNumeric,
32
- isObject: () => isObject,
33
- isString: () => isString,
34
- isUndefined: () => isUndefined,
35
- isUnit: () => isUnit
36
- });
37
- module.exports = __toCommonJS(assertion_exports);
38
- var isNumber = (value) => typeof value === "number";
39
- var isNotNumber = (value) => typeof value !== "number" || Number.isNaN(value) || !Number.isFinite(value);
40
- var isNumeric = (value) => value != null && parseFloat(value.toString()) - parseFloat(value.toString()) + 1 >= 0;
41
- var isString = (value) => Object.prototype.toString.call(value) === "[object String]";
42
- var isBoolean = (value) => typeof value === "boolean";
43
- var isUndefined = (value) => typeof value === "undefined" && value === void 0;
44
- var isNull = (value) => value === null;
45
- var isObject = (value) => value !== null && (typeof value === "object" || typeof value === "function") && !isArray(value);
46
- var isArray = (value) => Array.isArray(value);
47
- var isEmpty = (value) => !isArray(value) || !value.length || value.every((v) => v == null);
48
- var isFunction = (value) => typeof value === "function";
49
- var isUnit = (value) => /[0-9].*[px|rem|em|%|vw|vh]$/.test(value);
50
- var cast = (value) => value;
51
- // Annotate the CommonJS export names for ESM import in node:
52
- 0 && (module.exports = {
53
- cast,
54
- isArray,
55
- isBoolean,
56
- isEmpty,
57
- isFunction,
58
- isNotNumber,
59
- isNull,
60
- isNumber,
61
- isNumeric,
62
- isObject,
63
- isString,
64
- isUndefined,
65
- isUnit
66
- });
67
- //# sourceMappingURL=assertion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/assertion.ts"],"sourcesContent":["import type { Dict } from \".\"\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 value != null &&\n parseFloat(value.toString()) - parseFloat(value.toString()) + 1 >= 0\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].*[px|rem|em|%|vw|vh]$/.test(value)\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;AAEO,IAAM,WAAW,CAAC,UACvB,OAAO,UAAU;AAEZ,IAAM,cAAc,CAAC,UAC1B,OAAO,UAAU,YAAY,OAAO,MAAM,KAAK,KAAK,CAAC,OAAO,SAAS,KAAK;AAErE,IAAM,YAAY,CAAC,UACxB,SAAS,QACT,WAAW,MAAM,SAAS,CAAC,IAAI,WAAW,MAAM,SAAS,CAAC,IAAI,KAAK;AAE9D,IAAM,WAAW,CAAC,UACvB,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM;AAErC,IAAM,YAAY,CAAC,UACxB,OAAO,UAAU;AAEZ,IAAM,cAAc,CAAC,UAC1B,OAAO,UAAU,eAAe,UAAU;AAErC,IAAM,SAAS,CAAC,UAA8B,UAAU;AAExD,IAAM,WAAW,CAAiB,UACvC,UAAU,SACT,OAAO,UAAU,YAAY,OAAO,UAAU,eAC/C,CAAC,QAAQ,KAAK;AAET,IAAM,UAAU,CAAkB,UACvC,MAAM,QAAQ,KAAK;AAEd,IAAM,UAAU,CAAC,UACtB,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,UAAU,MAAM,MAAM,CAAC,MAAM,KAAK,IAAI;AAE3D,IAAM,aAAa,CACxB,UACe,OAAO,UAAU;AAE3B,IAAM,SAAS,CAAC,UACrB,8BAA8B,KAAK,KAAK;AAEnC,IAAM,OAAO,CAAI,UAAe;","names":[]}
@@ -1,31 +0,0 @@
1
- import {
2
- cast,
3
- isArray,
4
- isBoolean,
5
- isEmpty,
6
- isFunction,
7
- isNotNumber,
8
- isNull,
9
- isNumber,
10
- isNumeric,
11
- isObject,
12
- isString,
13
- isUndefined,
14
- isUnit
15
- } from "./chunk-P5JCSYB3.mjs";
16
- export {
17
- cast,
18
- isArray,
19
- isBoolean,
20
- isEmpty,
21
- isFunction,
22
- isNotNumber,
23
- isNull,
24
- isNumber,
25
- isNumeric,
26
- isObject,
27
- isString,
28
- isUndefined,
29
- isUnit
30
- };
31
- //# sourceMappingURL=assertion.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/calc.d.mts DELETED
@@ -1,18 +0,0 @@
1
- type Operand = string | number;
2
- type Calc = {
3
- add: (...args: Operand[]) => Calc;
4
- subtract: (...args: Operand[]) => Calc;
5
- multiply: (...args: Operand[]) => Calc;
6
- divide: (...args: Operand[]) => Calc;
7
- negate: () => Calc;
8
- toString: () => string;
9
- };
10
- declare const calc: ((x: Operand) => Calc) & {
11
- add: (...args: Operand[]) => string;
12
- subtract: (...args: Operand[]) => string;
13
- multiply: (...args: Operand[]) => string;
14
- divide: (...args: Operand[]) => string;
15
- negate: (value: Operand) => string;
16
- };
17
-
18
- export { type Operand, calc };
package/dist/calc.d.ts DELETED
@@ -1,18 +0,0 @@
1
- type Operand = string | number;
2
- type Calc = {
3
- add: (...args: Operand[]) => Calc;
4
- subtract: (...args: Operand[]) => Calc;
5
- multiply: (...args: Operand[]) => Calc;
6
- divide: (...args: Operand[]) => Calc;
7
- negate: () => Calc;
8
- toString: () => string;
9
- };
10
- declare const calc: ((x: Operand) => Calc) & {
11
- add: (...args: Operand[]) => string;
12
- subtract: (...args: Operand[]) => string;
13
- multiply: (...args: Operand[]) => string;
14
- divide: (...args: Operand[]) => string;
15
- negate: (value: Operand) => string;
16
- };
17
-
18
- export { type Operand, calc };
package/dist/calc.js DELETED
@@ -1,57 +0,0 @@
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/calc.ts
21
- var calc_exports = {};
22
- __export(calc_exports, {
23
- calc: () => calc
24
- });
25
- module.exports = __toCommonJS(calc_exports);
26
- var toExpression = (operator, ...args) => args.join(` ${operator} `).replace(/calc/g, "");
27
- var add = (...args) => `calc(${toExpression("+", ...args)})`;
28
- var subtract = (...args) => `calc(${toExpression("-", ...args)})`;
29
- var multiply = (...args) => `calc(${toExpression("*", ...args)})`;
30
- var divide = (...args) => `calc(${toExpression("/", ...args)})`;
31
- var negate = (value) => {
32
- if (value != null && !isNaN(parseFloat(value.toString())))
33
- return String(value).startsWith("-") ? String(value).slice(1) : `-${value}`;
34
- return multiply(value, -1);
35
- };
36
- var calc = Object.assign(
37
- (x) => ({
38
- add: (...args) => calc(add(x, ...args)),
39
- subtract: (...args) => calc(subtract(x, ...args)),
40
- multiply: (...args) => calc(multiply(x, ...args)),
41
- divide: (...args) => calc(divide(x, ...args)),
42
- negate: () => calc(negate(x)),
43
- toString: () => x.toString()
44
- }),
45
- {
46
- add,
47
- subtract,
48
- multiply,
49
- divide,
50
- negate
51
- }
52
- );
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- calc
56
- });
57
- //# sourceMappingURL=calc.js.map
package/dist/calc.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/calc.ts"],"sourcesContent":["type Operator = \"+\" | \"-\" | \"*\" | \"/\"\n\nexport type Operand = string | number\n\nconst toExpression = (operator: Operator, ...args: Operand[]) =>\n args.join(` ${operator} `).replace(/calc/g, \"\")\n\nconst add = (...args: Operand[]) => `calc(${toExpression(\"+\", ...args)})`\n\nconst subtract = (...args: Operand[]) => `calc(${toExpression(\"-\", ...args)})`\n\nconst multiply = (...args: Operand[]) => `calc(${toExpression(\"*\", ...args)})`\n\nconst divide = (...args: Operand[]) => `calc(${toExpression(\"/\", ...args)})`\n\nconst negate = (value: Operand) => {\n if (value != null && !isNaN(parseFloat(value.toString())))\n return String(value).startsWith(\"-\") ? String(value).slice(1) : `-${value}`\n\n return multiply(value, -1)\n}\n\ntype Calc = {\n add: (...args: Operand[]) => Calc\n subtract: (...args: Operand[]) => Calc\n multiply: (...args: Operand[]) => Calc\n divide: (...args: Operand[]) => Calc\n negate: () => Calc\n toString: () => string\n}\n\nexport const calc = Object.assign(\n (x: Operand): Calc => ({\n add: (...args) => calc(add(x, ...args)),\n subtract: (...args) => calc(subtract(x, ...args)),\n multiply: (...args) => calc(multiply(x, ...args)),\n divide: (...args) => calc(divide(x, ...args)),\n negate: () => calc(negate(x)),\n toString: () => x.toString(),\n }),\n {\n add,\n subtract,\n multiply,\n divide,\n negate,\n },\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,IAAM,eAAe,CAAC,aAAuB,SAC3C,KAAK,KAAK,IAAI,QAAQ,GAAG,EAAE,QAAQ,SAAS,EAAE;AAEhD,IAAM,MAAM,IAAI,SAAoB,QAAQ,aAAa,KAAK,GAAG,IAAI,CAAC;AAEtE,IAAM,WAAW,IAAI,SAAoB,QAAQ,aAAa,KAAK,GAAG,IAAI,CAAC;AAE3E,IAAM,WAAW,IAAI,SAAoB,QAAQ,aAAa,KAAK,GAAG,IAAI,CAAC;AAE3E,IAAM,SAAS,IAAI,SAAoB,QAAQ,aAAa,KAAK,GAAG,IAAI,CAAC;AAEzE,IAAM,SAAS,CAAC,UAAmB;AACjC,MAAI,SAAS,QAAQ,CAAC,MAAM,WAAW,MAAM,SAAS,CAAC,CAAC;AACtD,WAAO,OAAO,KAAK,EAAE,WAAW,GAAG,IAAI,OAAO,KAAK,EAAE,MAAM,CAAC,IAAI,IAAI,KAAK;AAE3E,SAAO,SAAS,OAAO,EAAE;AAC3B;AAWO,IAAM,OAAO,OAAO;AAAA,EACzB,CAAC,OAAsB;AAAA,IACrB,KAAK,IAAI,SAAS,KAAK,IAAI,GAAG,GAAG,IAAI,CAAC;AAAA,IACtC,UAAU,IAAI,SAAS,KAAK,SAAS,GAAG,GAAG,IAAI,CAAC;AAAA,IAChD,UAAU,IAAI,SAAS,KAAK,SAAS,GAAG,GAAG,IAAI,CAAC;AAAA,IAChD,QAAQ,IAAI,SAAS,KAAK,OAAO,GAAG,GAAG,IAAI,CAAC;AAAA,IAC5C,QAAQ,MAAM,KAAK,OAAO,CAAC,CAAC;AAAA,IAC5B,UAAU,MAAM,EAAE,SAAS;AAAA,EAC7B;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
package/dist/calc.mjs DELETED
@@ -1,7 +0,0 @@
1
- import {
2
- calc
3
- } from "./chunk-L56KWSQO.mjs";
4
- export {
5
- calc
6
- };
7
- //# sourceMappingURL=calc.mjs.map
package/dist/calc.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,7 +0,0 @@
1
- // src/module.ts
2
- var interopDefault = (module) => module.default || module;
3
-
4
- export {
5
- interopDefault
6
- };
7
- //# sourceMappingURL=chunk-5OUUTZYQ.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/module.ts"],"sourcesContent":["export const interopDefault = <T extends unknown>(module: T): T =>\n (module as { default: T }).default || module\n"],"mappings":";AAAO,IAAM,iBAAiB,CAAoB,WAC/C,OAA0B,WAAW;","names":[]}
@@ -1,52 +0,0 @@
1
- // src/event.ts
2
- var isMouseEvent = (ev) => {
3
- const win = getEventWindow(ev);
4
- if (typeof win.PointerEvent !== "undefined" && ev instanceof win.PointerEvent)
5
- return !!(ev.pointerType === "mouse");
6
- return ev instanceof win.MouseEvent;
7
- };
8
- var isTouchEvent = (ev) => !!ev.touches;
9
- var isMultiTouchEvent = (ev) => isTouchEvent(ev) && ev.touches.length > 1;
10
- var getEventWindow = (ev) => {
11
- var _a;
12
- return (_a = ev.view) != null ? _a : window;
13
- };
14
- var pointFromTouch = (e, type = "page") => {
15
- const point = e.touches[0] || e.changedTouches[0];
16
- return { x: point[`${type}X`], y: point[`${type}Y`] };
17
- };
18
- var pointFromMouse = (point, type = "page") => ({
19
- x: point[`${type}X`],
20
- y: point[`${type}Y`]
21
- });
22
- var getEventPoint = (ev, type = "page") => isTouchEvent(ev) ? pointFromTouch(ev, type) : pointFromMouse(ev, type);
23
- var addDomEvent = (target, type, cb, options) => {
24
- target.addEventListener(type, cb, options);
25
- return () => {
26
- target.removeEventListener(type, cb, options);
27
- };
28
- };
29
- var filter = (cb) => (ev) => {
30
- const isMouse = isMouseEvent(ev);
31
- if (!isMouse || isMouse && ev.button === 0)
32
- cb(ev);
33
- };
34
- var wrap = (cb, filterPrimary = false) => {
35
- const listener = (ev) => cb(ev, { point: getEventPoint(ev) });
36
- const fn = filterPrimary ? filter(listener) : listener;
37
- return fn;
38
- };
39
- var addPointerEvent = (target, type, cb, options) => addDomEvent(target, type, wrap(cb, type === "pointerdown"), options);
40
-
41
- export {
42
- isMouseEvent,
43
- isTouchEvent,
44
- isMultiTouchEvent,
45
- getEventWindow,
46
- pointFromTouch,
47
- pointFromMouse,
48
- getEventPoint,
49
- addDomEvent,
50
- addPointerEvent
51
- };
52
- //# sourceMappingURL=chunk-A74F6ICI.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/event.ts"],"sourcesContent":["export type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent\n\nexport type PointType = \"page\" | \"client\"\n\nexport type Point = {\n x: number\n y: number\n}\n\nexport type PointerEventInfo = {\n point: Point\n}\n\nexport type MixedEventListener = (\n e: AnyPointerEvent,\n info: PointerEventInfo,\n) => void\n\nexport const 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 const isTouchEvent = (ev: AnyPointerEvent): ev is TouchEvent =>\n !!(ev as TouchEvent).touches\n\nexport const isMultiTouchEvent = (ev: AnyPointerEvent) =>\n isTouchEvent(ev) && ev.touches.length > 1\n\nexport const getEventWindow = (ev: Event): typeof globalThis =>\n ((ev as UIEvent).view ?? window) as unknown as typeof globalThis\n\nexport const 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 const pointFromMouse = (\n point: MouseEvent | PointerEvent,\n type: PointType = \"page\",\n) => ({\n x: point[`${type}X`],\n y: point[`${type}Y`],\n})\n\nexport const getEventPoint = (ev: AnyPointerEvent, type: PointType = \"page\") =>\n isTouchEvent(ev) ? pointFromTouch(ev, type) : pointFromMouse(ev, type)\n\nexport const 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\nconst filter =\n (cb: EventListener): EventListener =>\n (ev: Event) => {\n const isMouse = isMouseEvent(ev)\n\n if (!isMouse || (isMouse && ev.button === 0)) cb(ev)\n }\n\nconst wrap = (cb: MixedEventListener, filterPrimary = false): EventListener => {\n const listener = (ev: any) => cb(ev, { point: getEventPoint(ev) })\n\n const fn = filterPrimary ? filter(listener) : listener\n\n return fn as EventListener\n}\n\nexport const addPointerEvent = (\n target: EventTarget,\n type: string,\n cb: MixedEventListener,\n options?: AddEventListenerOptions,\n) => addDomEvent(target, type, wrap(cb, type === \"pointerdown\"), options)\n"],"mappings":";AAkBO,IAAM,eAAe,CAAC,OAA8B;AACzD,QAAM,MAAM,eAAe,EAAE;AAE7B,MAAI,OAAO,IAAI,iBAAiB,eAAe,cAAc,IAAI;AAC/D,WAAO,CAAC,EAAE,GAAG,gBAAgB;AAE/B,SAAO,cAAc,IAAI;AAC3B;AAEO,IAAM,eAAe,CAAC,OAC3B,CAAC,CAAE,GAAkB;AAEhB,IAAM,oBAAoB,CAAC,OAChC,aAAa,EAAE,KAAK,GAAG,QAAQ,SAAS;AAEnC,IAAM,iBAAiB,CAAC,OAA8B;AAjC7D;AAkCI,kBAAe,SAAf,YAAuB;AAAA;AAEpB,IAAM,iBAAiB,CAAC,GAAe,OAAkB,WAAW;AACzE,QAAM,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;AAEhD,SAAO,EAAE,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG,GAAG,MAAM,GAAG,IAAI,GAAG,EAAE;AACtD;AAEO,IAAM,iBAAiB,CAC5B,OACA,OAAkB,YACd;AAAA,EACJ,GAAG,MAAM,GAAG,IAAI,GAAG;AAAA,EACnB,GAAG,MAAM,GAAG,IAAI,GAAG;AACrB;AAEO,IAAM,gBAAgB,CAAC,IAAqB,OAAkB,WACnE,aAAa,EAAE,IAAI,eAAe,IAAI,IAAI,IAAI,eAAe,IAAI,IAAI;AAEhE,IAAM,cAAc,CACzB,QACA,MACA,IACA,YACG;AACH,SAAO,iBAAiB,MAAM,IAAI,OAAO;AAEzC,SAAO,MAAM;AACX,WAAO,oBAAoB,MAAM,IAAI,OAAO;AAAA,EAC9C;AACF;AAEA,IAAM,SACJ,CAAC,OACD,CAAC,OAAc;AACb,QAAM,UAAU,aAAa,EAAE;AAE/B,MAAI,CAAC,WAAY,WAAW,GAAG,WAAW;AAAI,OAAG,EAAE;AACrD;AAEF,IAAM,OAAO,CAAC,IAAwB,gBAAgB,UAAyB;AAC7E,QAAM,WAAW,CAAC,OAAY,GAAG,IAAI,EAAE,OAAO,cAAc,EAAE,EAAE,CAAC;AAEjE,QAAM,KAAK,gBAAgB,OAAO,QAAQ,IAAI;AAE9C,SAAO;AACT;AAEO,IAAM,kBAAkB,CAC7B,QACA,MACA,IACA,YACG,YAAY,QAAQ,MAAM,KAAK,IAAI,SAAS,aAAa,GAAG,OAAO;","names":[]}