@yamada-ui/utils 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/array.js +1 -0
- package/dist/array.js.map +1 -0
- package/dist/array.mjs +2 -1
- package/dist/array.mjs.map +1 -0
- package/dist/assertion.js +1 -0
- package/dist/assertion.js.map +1 -0
- package/dist/assertion.mjs +2 -1
- package/dist/assertion.mjs.map +1 -0
- package/dist/calc.js +1 -0
- package/dist/calc.js.map +1 -0
- package/dist/calc.mjs +2 -1
- package/dist/calc.mjs.map +1 -0
- package/dist/chunk-5OUUTZYQ.mjs +7 -0
- package/dist/chunk-5OUUTZYQ.mjs.map +1 -0
- package/dist/{chunk-BU4LEFZY.mjs → chunk-6DMBHPNQ.mjs} +1 -0
- package/dist/chunk-6DMBHPNQ.mjs.map +1 -0
- package/dist/{chunk-G7Q2EDJF.mjs → chunk-A74F6ICI.mjs} +1 -0
- package/dist/chunk-A74F6ICI.mjs.map +1 -0
- package/dist/{chunk-H5VMEQNO.mjs → chunk-GC3WZLP7.mjs} +1 -0
- package/dist/chunk-GC3WZLP7.mjs.map +1 -0
- package/dist/{chunk-RJN7NAQE.mjs → chunk-OHIZZWZU.mjs} +11 -5
- package/dist/chunk-OHIZZWZU.mjs.map +1 -0
- package/dist/chunk-RSDBT4DI.mjs +1 -0
- package/dist/chunk-RSDBT4DI.mjs.map +1 -0
- package/dist/{chunk-BZAW2D6U.mjs → chunk-TX5GWD7K.mjs} +1 -0
- package/dist/chunk-TX5GWD7K.mjs.map +1 -0
- package/dist/{chunk-VYMGBE25.mjs → chunk-WDMW4NT7.mjs} +1 -0
- package/dist/chunk-WDMW4NT7.mjs.map +1 -0
- package/dist/{chunk-PURW64JE.mjs → chunk-WV6P7ZCI.mjs} +1 -0
- package/dist/chunk-WV6P7ZCI.mjs.map +1 -0
- package/dist/{chunk-R5OUKGQ5.mjs → chunk-ZFYLQH3G.mjs} +1 -0
- package/dist/chunk-ZFYLQH3G.mjs.map +1 -0
- package/dist/color.d.mts +4 -3
- package/dist/color.d.ts +4 -3
- package/dist/color.js +9 -4
- package/dist/color.js.map +1 -0
- package/dist/color.mjs +13 -9
- package/dist/color.mjs.map +1 -0
- package/dist/dom.js +1 -0
- package/dist/dom.js.map +1 -0
- package/dist/dom.mjs +2 -1
- package/dist/dom.mjs.map +1 -0
- package/dist/event.js +1 -0
- package/dist/event.js.map +1 -0
- package/dist/event.mjs +2 -1
- package/dist/event.mjs.map +1 -0
- package/dist/function.js +1 -0
- package/dist/function.js.map +1 -0
- package/dist/function.mjs +11 -9
- package/dist/function.mjs.map +1 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +17 -4
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +18 -9
- package/dist/index.mjs.map +1 -0
- package/dist/index.types.js +1 -0
- package/dist/index.types.js.map +1 -0
- package/dist/index.types.mjs +2 -1
- package/dist/index.types.mjs.map +1 -0
- package/dist/module.d.mts +3 -0
- package/dist/module.d.ts +3 -0
- package/dist/module.js +31 -0
- package/dist/module.js.map +1 -0
- package/dist/module.mjs +7 -0
- package/dist/module.mjs.map +1 -0
- package/dist/number.js +1 -0
- package/dist/number.js.map +1 -0
- package/dist/number.mjs +2 -1
- package/dist/number.mjs.map +1 -0
- package/dist/object.js +1 -0
- package/dist/object.js.map +1 -0
- package/dist/object.mjs +11 -9
- package/dist/object.mjs.map +1 -0
- package/dist/react.d.mts +2 -1
- package/dist/react.d.ts +2 -1
- package/dist/react.js +4 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +13 -9
- package/dist/react.mjs.map +1 -0
- package/dist/string.js +1 -0
- package/dist/string.js.map +1 -0
- package/dist/string.mjs +2 -1
- package/dist/string.mjs.map +1 -0
- package/package.json +3 -2
- package/dist/chunk-SLJ4M7XC.mjs +0 -0
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ $ npm install @yamada-ui/utils
|
|
|
24
24
|
|
|
25
25
|
Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](https://github.com/hirotomoyamada/yamada-ui/blob/main/CONTRIBUTING.md) to assist you.
|
|
26
26
|
|
|
27
|
-
##
|
|
27
|
+
## License
|
|
28
28
|
|
|
29
29
|
This package is licensed under the terms of the
|
|
30
30
|
|
package/dist/array.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
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
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/assertion.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
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 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;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,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":[]}
|
package/dist/assertion.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
isString,
|
|
12
12
|
isUndefined,
|
|
13
13
|
isUnit
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-6DMBHPNQ.mjs";
|
|
15
15
|
export {
|
|
16
16
|
cast,
|
|
17
17
|
isArray,
|
|
@@ -26,3 +26,4 @@ export {
|
|
|
26
26
|
isUndefined,
|
|
27
27
|
isUnit
|
|
28
28
|
};
|
|
29
|
+
//# sourceMappingURL=assertion.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/calc.js
CHANGED
package/dist/calc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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}\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 }),\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;AAUO,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,EAC9B;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/calc.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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 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":";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,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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dom.ts"],"sourcesContent":["import type React from \"react\"\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/)\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(\"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 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 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"],"mappings":";AAEO,IAAM,aAAa,MACxB,CAAC,EACC,OAAO,WAAW,eAClB,OAAO,YACP,OAAO,SAAS;AAGb,IAAM,cAAc,MAAW;AATtC;AAUG,+BAAkB,kBAAlB,mBAAiC,aAAjC,YAA6C,UAAU;AAAA;AAEnD,IAAM,SAAS,CAAC,MACrB,WAAW,KAAK,EAAE,KAAK,UAAU,MAAM;AAClC,IAAM,WAAW,CA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iBAAiB,EAAE,EAAE;AAEhB,IAAM,kBAAkB,CAAC,OAAoB;AAClD,SAAO,iBAAiB,EAAE,MAAM;AAClC;","names":[]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
isNumber,
|
|
5
5
|
isObject,
|
|
6
6
|
isString
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-6DMBHPNQ.mjs";
|
|
8
8
|
|
|
9
9
|
// src/function.ts
|
|
10
10
|
var noop = () => {
|
|
@@ -170,6 +170,7 @@ var useAsyncRetry = (func, deps = []) => {
|
|
|
170
170
|
}, [...deps, stateLoading]);
|
|
171
171
|
return { ...state, retry };
|
|
172
172
|
};
|
|
173
|
+
var createId = (prefix) => `${prefix}-${(/* @__PURE__ */ new Date()).getTime()}`;
|
|
173
174
|
|
|
174
175
|
// src/color.ts
|
|
175
176
|
import {
|
|
@@ -180,7 +181,6 @@ import {
|
|
|
180
181
|
darken,
|
|
181
182
|
lighten
|
|
182
183
|
} from "color2k";
|
|
183
|
-
var coef = 0.75;
|
|
184
184
|
var hues = [
|
|
185
185
|
50,
|
|
186
186
|
100,
|
|
@@ -195,6 +195,7 @@ var hues = [
|
|
|
195
195
|
950
|
|
196
196
|
];
|
|
197
197
|
var isGray = (colorScheme) => colorScheme === "gray" || colorScheme === "neutral";
|
|
198
|
+
var isAccessible = (colorScheme) => colorScheme === "yellow" || colorScheme === "cyan" || colorScheme === "lime";
|
|
198
199
|
var getColor = (color, fallback) => (theme = {}, colorMode) => {
|
|
199
200
|
var _a, _b, _c;
|
|
200
201
|
const [token, hue] = color.split(".");
|
|
@@ -224,7 +225,7 @@ var darkenColor = (color, amount) => (theme, colorMode) => {
|
|
|
224
225
|
};
|
|
225
226
|
var tintColor = (color, amount) => (theme, colorMode) => {
|
|
226
227
|
const raw = getColor(color, color)(theme, colorMode);
|
|
227
|
-
return toHex(mix(raw, "#fff", amount));
|
|
228
|
+
return toHex(mix(raw, "#fff", amount / 100));
|
|
228
229
|
};
|
|
229
230
|
var shadeColor = (color, amount) => (theme, colorMode) => {
|
|
230
231
|
const raw = getColor(color, color)(theme, colorMode);
|
|
@@ -234,18 +235,20 @@ var transparentizeColor = (color, alpha) => (theme, colorMode) => {
|
|
|
234
235
|
const raw = getColor(color, color)(theme, colorMode);
|
|
235
236
|
return transparentize(raw, 1 - alpha);
|
|
236
237
|
};
|
|
237
|
-
var toneColor = (color, hue) => (theme, colorMode) => {
|
|
238
|
+
var toneColor = (color, hue, lCoef = 0.94, dCoef = 0.86) => (theme, colorMode) => {
|
|
238
239
|
if (hue < 50 || 950 < hue)
|
|
239
240
|
return color;
|
|
240
241
|
let raw = color;
|
|
241
242
|
if (theme && colorMode)
|
|
242
243
|
getColor(color, color)(theme, colorMode);
|
|
244
|
+
const coef = hue < 500 ? lCoef : dCoef;
|
|
243
245
|
const amount = (500 - hue) * 1e-3 * coef;
|
|
244
246
|
return toHex(lighten(raw, amount));
|
|
245
247
|
};
|
|
246
|
-
var toneColors = (color) => {
|
|
248
|
+
var toneColors = (color, lCoef = 0.94, dCoef = 0.86) => {
|
|
247
249
|
const colors = {};
|
|
248
250
|
hues.forEach((hue) => {
|
|
251
|
+
const coef = hue < 500 ? lCoef : dCoef;
|
|
249
252
|
const amount = (500 - hue) * 1e-3 * coef;
|
|
250
253
|
colors[hue] = toHex(lighten(color, amount));
|
|
251
254
|
});
|
|
@@ -481,8 +484,10 @@ export {
|
|
|
481
484
|
useAsync,
|
|
482
485
|
useAsyncFunc,
|
|
483
486
|
useAsyncRetry,
|
|
487
|
+
createId,
|
|
484
488
|
hues,
|
|
485
489
|
isGray,
|
|
490
|
+
isAccessible,
|
|
486
491
|
getColor,
|
|
487
492
|
lightenColor,
|
|
488
493
|
darkenColor,
|
|
@@ -496,3 +501,4 @@ export {
|
|
|
496
501
|
isLight,
|
|
497
502
|
isDark
|
|
498
503
|
};
|
|
504
|
+
//# sourceMappingURL=chunk-OHIZZWZU.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/function.ts","../src/react.tsx","../src/color.ts","../src/object.ts"],"sourcesContent":["import { isFunction } from \".\"\n\nexport const noop = () => {}\n\nexport const runIfFunc = <T, U extends Array<any>>(\n valOrFunc: T | ((...funcArgs: U) => T),\n ...args: U\n): T => (isFunction(valOrFunc) ? valOrFunc(...args) : valOrFunc)\n\nexport const handlerAll =\n <T extends (event: any) => void>(...funcs: (T | undefined)[]) =>\n (event: (T extends (...args: infer R) => any ? R : never)[0]) => {\n funcs.some((func) => {\n func?.(event)\n\n return event?.defaultPrevented\n })\n }\n\nexport const funcAll =\n <T extends (...args: any[]) => any>(...funcs: (T | undefined)[]) =>\n (arg: (T extends (...args: infer R) => any ? R : never)[0]) =>\n funcs.forEach((func) => func?.(arg))\n","import * as React from \"react\"\nimport { isNumber, isString } from \".\"\n\ntype DOMElement = Element & HTMLOrSVGElement\n\ntype DataAttributes = {\n [dataAttr: string]: any\n}\n\nexport type DOMAttributes<Y = DOMElement> = React.AriaAttributes &\n React.DOMAttributes<Y> &\n DataAttributes & {\n id?: string\n role?: React.AriaRole\n tabIndex?: number\n style?: React.CSSProperties\n }\n\ntype Merge<Y, M> = M extends Record<string, unknown> ? Y : Omit<Y, keyof M> & M\n\nexport type PropGetter<Y = Record<string, unknown>, M = DOMAttributes> = (\n props?: Merge<DOMAttributes, Y>,\n ref?: React.Ref<any>,\n) => M & React.RefAttributes<any>\n\nexport type RequiredPropGetter<\n Y = Record<string, unknown>,\n M = DOMAttributes,\n> = (\n props: Merge<DOMAttributes, Y>,\n ref?: React.Ref<any>,\n) => M & React.RefAttributes<any>\n\nexport type MaybeRenderProp<Y> =\n | React.ReactNode\n | ((props: Y) => React.ReactNode)\n\ntype Options = {\n strict?: boolean\n errorMessage?: string\n name?: string\n}\n\ntype CreateContextReturn<T> = [React.Provider<T>, () => T, React.Context<T>]\n\nexport const createContext = <ContextType extends any = any>({\n strict = true,\n errorMessage = \"useContext: `context` is undefined. Seems you forgot to wrap component within the Provider\",\n name,\n}: Options = {}) => {\n const Context = React.createContext<ContextType | undefined>(undefined)\n\n Context.displayName = name\n\n const useContext = () => {\n const context = React.useContext(Context)\n\n if (!context && strict) {\n const error = new Error(errorMessage)\n error.name = \"ContextError\"\n Error.captureStackTrace?.(error, useContext)\n throw error\n }\n\n return context\n }\n\n return [\n Context.Provider,\n useContext,\n Context,\n ] as CreateContextReturn<ContextType>\n}\n\nexport const useSafeLayoutEffect = Boolean(globalThis?.document)\n ? React.useLayoutEffect\n : React.useEffect\n\nexport const useUnmountEffect = (callback: () => void) =>\n // eslint-disable-next-line react-hooks/exhaustive-deps\n React.useEffect(() => () => callback(), [])\n\nexport const useIsMounted = () => {\n const isMounted = React.useRef(false)\n\n useSafeLayoutEffect(() => {\n isMounted.current = true\n\n return () => {\n isMounted.current = false\n }\n }, [])\n\n return isMounted\n}\n\nexport const getValidChildren = (\n children: React.ReactNode,\n): React.ReactElement[] =>\n React.Children.toArray(children).filter((child) =>\n React.isValidElement(child),\n ) as React.ReactElement[]\n\nexport const isValidElement = (child: any): child is React.ReactNode =>\n React.isValidElement(child) || isString(child) || isNumber(child)\n\nexport const findChildren = (\n children: React.ReactElement<\n any,\n string | React.JSXElementConstructor<any>\n >[],\n ...types: React.JSXElementConstructor<any>[]\n): [React.ReactElement | undefined, ...React.ReactElement[]] =>\n (children.find((child) => types.some((type) => child.type === type))\n ? children.sort((a, b) =>\n types.some((type) => a.type === type)\n ? -1\n : types.some((type) => b.type === type)\n ? 1\n : 0,\n )\n : [undefined, ...children]) as [\n React.ReactElement | undefined,\n ...React.ReactElement[],\n ]\n\nexport const includesChildren = (\n children: React.ReactElement<\n any,\n string | React.JSXElementConstructor<any>\n >[],\n ...types: React.JSXElementConstructor<any>[]\n): boolean =>\n children.some((child) => {\n if (types.some((type) => child.type === type)) return true\n\n const children = getValidChildren(child.props.children)\n\n return children.length ? includesChildren(children, ...types) : false\n })\n\nexport const omitChildren = (\n children: React.ReactElement<\n any,\n string | React.JSXElementConstructor<any>\n >[],\n ...types: React.JSXElementConstructor<any>[]\n): React.ReactElement[] =>\n children.filter((child) => types.every((type) => child.type !== type))\n\nexport const pickChildren = (\n children: React.ReactElement<\n any,\n string | React.JSXElementConstructor<any>\n >[],\n ...types: React.JSXElementConstructor<any>[]\n): React.ReactElement[] =>\n children.filter((child) => types.every((type) => child.type === type))\n\nexport const cx = (...classNames: (string | undefined)[]) =>\n classNames.filter(Boolean).join(\" \")\n\ntype ReactRef<T> = React.Ref<T> | React.MutableRefObject<T>\n\nexport const isRefObject = (val: any): val is { current: any } =>\n \"current\" in val\n\nexport const assignRef = <T extends any = any>(\n ref: ReactRef<T> | undefined,\n value: T,\n) => {\n if (ref == null) return\n\n if (typeof ref === \"function\") {\n ref(value)\n\n return\n }\n\n try {\n // @ts-ignore\n ref.current = value\n } catch (error) {\n throw new Error(`Cannot assign value '${value}' to ref '${ref}'`)\n }\n}\n\nexport const mergeRefs =\n <T extends any = any>(...refs: (ReactRef<T> | null | undefined)[]) =>\n (node: T | null) => {\n refs.forEach((ref) => {\n assignRef(ref, node)\n })\n }\n\nexport const useMergeRefs = <T extends any = any>(\n ...refs: (ReactRef<T> | undefined)[]\n) => React.useMemo(() => mergeRefs(...refs), [refs])\n\nexport const useCallbackRef = <T extends (...args: any[]) => any>(\n callback: T | undefined,\n deps: React.DependencyList = [],\n) => {\n const callbackRef = React.useRef(callback)\n\n React.useEffect(() => {\n callbackRef.current = callback\n })\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return React.useCallback(\n ((...args) => callbackRef.current?.(...args)) as T,\n deps,\n )\n}\n\nexport const useUpdateEffect = (\n callback: React.EffectCallback,\n deps: React.DependencyList,\n) => {\n const renderCycleRef = React.useRef(false)\n const effectCycleRef = React.useRef(false)\n\n React.useEffect(() => {\n const mounted = renderCycleRef.current\n const run = mounted && effectCycleRef.current\n\n if (run) return callback()\n\n effectCycleRef.current = true\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps)\n\n React.useEffect(() => {\n renderCycleRef.current = true\n\n return () => {\n renderCycleRef.current = false\n }\n }, [])\n}\n\nexport type FunctionReturningPromise = (...args: any[]) => Promise<any>\n\nexport const useAsync = <T extends FunctionReturningPromise>(\n func: T,\n deps: React.DependencyList = [],\n) => {\n const [state, callback] = useAsyncFunc(func, deps, { loading: true })\n\n React.useEffect(() => {\n callback()\n }, [callback])\n\n return state\n}\n\nexport type AsyncState<T> =\n | {\n loading: boolean\n error?: undefined\n value?: undefined\n }\n | {\n loading: true\n error?: Error | undefined\n value?: T\n }\n | {\n loading: false\n error: Error\n value?: undefined\n }\n | {\n loading: false\n error?: undefined\n value: T\n }\n\nexport type PromiseType<P extends Promise<any>> = P extends Promise<infer T>\n ? T\n : never\n\ntype StateFromFunctionReturningPromise<T extends FunctionReturningPromise> =\n AsyncState<PromiseType<ReturnType<T>>>\n\nexport type AsyncFnReturn<\n T extends FunctionReturningPromise = FunctionReturningPromise,\n> = [StateFromFunctionReturningPromise<T>, T]\n\nexport const useAsyncFunc = <T extends FunctionReturningPromise>(\n func: T,\n deps: React.DependencyList = [],\n initialState: StateFromFunctionReturningPromise<T> = { loading: false },\n): AsyncFnReturn<T> => {\n const lastCallId = React.useRef(0)\n const isMounted = useIsMounted()\n const [state, setState] =\n React.useState<StateFromFunctionReturningPromise<T>>(initialState)\n\n const callback = React.useCallback(\n (...args: Parameters<T>): ReturnType<T> => {\n const callId = ++lastCallId.current\n\n if (!state.loading)\n setState((prevState) => ({ ...prevState, loading: true }))\n\n return func(...args).then(\n (value) => {\n if (isMounted.current && callId === lastCallId.current)\n setState({ value, loading: false })\n\n return value\n },\n (error) => {\n if (isMounted.current && callId === lastCallId.current)\n setState({ error, loading: false })\n\n return error\n },\n ) as ReturnType<T>\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n deps,\n )\n\n return [state, callback as unknown as T]\n}\n\nexport type AsyncStateRetry<T> = AsyncState<T> & {\n retry(): void\n}\n\nexport const useAsyncRetry = <T,>(\n func: () => Promise<T>,\n deps: React.DependencyList = [],\n) => {\n const [attempt, setAttempt] = React.useState<number>(0)\n const state = useAsync(func, [...deps, attempt])\n\n const stateLoading = state.loading\n\n const retry = React.useCallback(() => {\n if (stateLoading) return\n\n setAttempt((currentAttempt) => currentAttempt + 1)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [...deps, stateLoading])\n\n return { ...state, retry }\n}\n\nexport const createId = (prefix: string) => `${prefix}-${new Date().getTime()}`\n","import {\n toHex,\n parseToRgba,\n transparentize,\n mix,\n darken,\n lighten,\n} from \"color2k\"\nimport type { Dict } from \".\"\nimport { getMemoizedObject as get, isArray } from \".\"\n\ntype ColorMode = \"light\" | \"dark\"\n\nexport const hues = [\n 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950,\n] as const\n\nexport const isGray = (colorScheme: string) =>\n colorScheme === \"gray\" || colorScheme === \"neutral\"\n\nexport const isAccessible = (colorScheme: string) =>\n colorScheme === \"yellow\" || colorScheme === \"cyan\" || colorScheme === \"lime\"\n\nexport const getColor =\n (color: string, fallback?: string) =>\n (theme: Dict = {}, colorMode?: ColorMode) => {\n const [token, hue] = color.split(\".\")\n\n const [, relatedToken] =\n Object.entries<string>(theme.semantics?.colorSchemes ?? {}).find(\n ([semanticToken]) => token === semanticToken,\n ) ?? []\n\n if (relatedToken) color = `${relatedToken}.${hue}`\n\n const hex = get<\n string | number | [string | number, string | number] | undefined\n >(theme, `colors.${color}`, color)\n\n try {\n if (isArray(hex)) {\n return toHex(String(colorMode !== \"dark\" ? hex[0] : hex[1]))\n } else {\n return toHex(String(hex))\n }\n } catch {\n return fallback ?? \"#000000\"\n }\n }\n\nexport const lightenColor =\n (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return toHex(lighten(raw, amount / 100))\n }\n\nexport const darkenColor =\n (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return toHex(darken(raw, amount / 100))\n }\n\nexport const tintColor =\n (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return toHex(mix(raw, \"#fff\", amount / 100))\n }\n\nexport const shadeColor =\n (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return toHex(mix(raw, \"#000\", amount / 100))\n }\n\nexport const transparentizeColor =\n (color: string, alpha: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return transparentize(raw, 1 - alpha)\n }\n\nexport const toneColor =\n (\n color: string,\n hue: (typeof hues)[number],\n lCoef: number = 0.94,\n dCoef: number = 0.86,\n ) =>\n (theme?: Dict, colorMode?: ColorMode) => {\n if (hue < 50 || 950 < hue) return color\n\n let raw = color\n\n if (theme && colorMode) getColor(color, color)(theme, colorMode)\n\n const coef = hue < 500 ? lCoef : dCoef\n const amount = (500 - hue) * 0.001 * coef\n\n return toHex(lighten(raw, amount))\n }\n\nexport const toneColors = (\n color: string,\n lCoef: number = 0.94,\n dCoef: number = 0.86,\n) => {\n const colors: Record<string, string> = {}\n\n hues.forEach((hue) => {\n const coef = hue < 500 ? lCoef : dCoef\n\n const amount = (500 - hue) * 0.001 * coef\n\n colors[hue] = toHex(lighten(color, amount))\n })\n\n return colors\n}\n\nexport const randomColor = ({\n string,\n colors,\n}: { string?: string; colors?: string[] } = {}) => {\n const fallback = randomHex()\n\n if (string && colors) return randomColorFromList(string, colors)\n\n if (string && !colors) return randomColorFromString(string)\n\n if (colors && !string) return randomFromList(colors)\n\n return fallback\n}\n\nconst randomHex = () =>\n `#${Math.floor(Math.random() * 0xffffff)\n .toString(16)\n .padEnd(6, \"0\")}`\n\nconst randomColorFromString = (str: string) => {\n let hash = 0\n\n if (str.length === 0) return hash.toString()\n\n for (let i = 0; i < str.length; i += 1) {\n hash = str.charCodeAt(i) + ((hash << 5) - hash)\n hash = hash & hash\n }\n\n let color = \"#\"\n\n for (let j = 0; j < 3; j += 1) {\n const value = (hash >> (j * 8)) & 255\n\n color += `00${value.toString(16)}`.substr(-2)\n }\n\n return color\n}\n\nconst randomColorFromList = (str: string, list: string[]) => {\n let index = 0\n\n if (str.length === 0) return list[0]\n\n for (let i = 0; i < str.length; i += 1) {\n index = str.charCodeAt(i) + ((index << 5) - index)\n\n index = index & index\n }\n\n index = ((index % list.length) + list.length) % list.length\n\n return list[index]\n}\n\nconst randomFromList = (list: string[]) =>\n list[Math.floor(Math.random() * list.length)]\n\nconst getBrightness = (color: string) => {\n const [r, g, b] = parseToRgba(color)\n\n return (r * 299 + g * 587 + b * 114) / 1000\n}\n\nexport const isTone =\n (color: string) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = theme ? getColor(color)(theme, colorMode) : color\n\n const brightness = getBrightness(raw)\n\n const isDark = brightness < 128\n\n return isDark ? \"dark\" : \"light\"\n }\n\nexport const isLight =\n (color: string) => (theme?: Dict, colorMode?: ColorMode) =>\n isTone(color)(theme, colorMode) === \"dark\"\n\nexport const isDark =\n (color: string) => (theme?: Dict, colorMode?: ColorMode) =>\n isTone(color)(theme, colorMode) === \"light\"\n","import type { Dict } from \".\"\nimport { isObject, isArray, isFunction } from \".\"\n\nexport const omitObject = <T extends Dict, K extends keyof T>(\n obj: T,\n keys: K[],\n): Omit<T, K> => {\n const result: Dict = {}\n\n Object.keys(obj).forEach((key) => {\n if (keys.includes(key as K)) return\n\n result[key] = obj[key]\n })\n\n return result as Omit<T, K>\n}\n\nexport const pickObject = <T extends Dict, K extends keyof T>(\n obj: T,\n keys: K[],\n): { [P in K]: T[P] } => {\n const result = {} as { [P in K]: T[P] }\n\n keys.forEach((key) => {\n if (key in obj) result[key] = obj[key]\n })\n\n return result\n}\n\nexport const splitObject = <T extends Dict, K extends keyof T>(\n obj: T,\n keys: K[],\n) => {\n const picked: Dict = {}\n const omitted: Dict = {}\n\n for (const [key, value] of Object.entries(obj)) {\n if (keys.includes(key as T[K])) {\n picked[key] = value\n } else {\n omitted[key] = value\n }\n }\n\n return [picked, omitted] as [{ [P in K]: T[P] }, Omit<T, K>]\n}\n\nexport const filterObject = <T extends Dict, K extends Dict>(\n obj: T,\n func: (key: keyof T, value: T[keyof T], obj: T) => boolean,\n): K => {\n const result: Dict = {}\n\n Object.entries(obj).forEach(([key, value]) => {\n const shouldPass = func(key, value, obj)\n\n if (shouldPass) result[key] = value\n })\n\n return result as K\n}\n\nexport const filterUndefined = <T extends Dict>(obj: T): T =>\n filterObject(obj, (_, val) => val !== null && val !== undefined)\n\nexport const merge = <T extends Dict>(\n target: any,\n source: any,\n mergeArray: boolean = false,\n): T => {\n let result = Object.assign({}, target)\n\n if (isObject(source)) {\n if (isObject(target)) {\n for (const [sourceKey, sourceValue] of Object.entries(source)) {\n const targetValue = target[sourceKey]\n\n if (mergeArray && isArray(sourceValue) && isArray(targetValue)) {\n result[sourceKey] = targetValue.concat(...sourceValue)\n } else if (\n !isFunction(sourceValue) &&\n isObject(sourceValue) &&\n target.hasOwnProperty(sourceKey)\n ) {\n result[sourceKey] = merge(targetValue, sourceValue, mergeArray)\n } else {\n Object.assign(result, { [sourceKey]: sourceValue })\n }\n }\n } else {\n result = source\n }\n }\n\n return result as T\n}\n\nexport const flattenObject = <T extends Dict>(\n obj: any,\n maxDepth: number = Infinity,\n omitKeys: string[] = [],\n): T => {\n if ((!isObject(obj) && !isArray(obj)) || !maxDepth) return obj\n\n return Object.entries(obj).reduce((result, [key, value]) => {\n if (\n isObject(value) &&\n !Object.keys(value).some((key) => omitKeys.includes(key))\n ) {\n Object.entries(flattenObject(value, maxDepth - 1, omitKeys)).forEach(\n ([childKey, childValue]) => {\n result[`${key}.${childKey}`] = childValue\n },\n )\n } else {\n result[key] = value\n }\n\n return result\n }, {} as any) as T\n}\n\nexport const objectFromEntries = <T extends Dict>(entries: any[][]): T =>\n entries.reduce((result, [key, value]) => {\n result[key] = value\n\n return result\n }, {} as any) as T\n\nexport const keysFormObject = <T extends Dict>(obj: T): (keyof T)[] =>\n Object.keys(obj)\n\nexport const replaceObject = <T extends any>(\n objOrArray: T,\n callBack: (value: any) => any,\n): T => {\n if (isArray(objOrArray)) {\n return objOrArray.map(callBack) as T\n } else if (isObject(objOrArray)) {\n return Object.entries(objOrArray).reduce((obj, [key, value]) => {\n obj[key] = callBack(value)\n\n return obj\n }, {} as Dict) as T\n } else {\n return callBack(objOrArray)\n }\n}\n\nexport const getObject = (\n obj: Dict,\n path: string | number,\n fallback?: any,\n i?: number,\n) => {\n const k = typeof path === \"string\" ? path.split(\".\") : [path]\n\n for (i = 0; i < k.length; i += 1) {\n if (!obj) break\n\n obj = obj[k[i]]\n }\n\n return obj === undefined ? fallback : obj\n}\n\nexport const memoizeObject = (func: typeof getObject) => {\n const cache = new WeakMap()\n\n const memoizedFunc = <T extends unknown = any>(\n obj: Dict,\n path: string | number,\n fallback?: any,\n i?: number,\n ): T => {\n if (typeof obj === \"undefined\") return func(obj, path, fallback)\n\n if (!cache.has(obj)) cache.set(obj, new Map())\n\n const map = cache.get(obj)\n\n if (map.has(path)) return map.get(path)\n\n const value = func(obj, path, fallback, i)\n\n map.set(path, value)\n\n return value as T\n }\n\n return memoizedFunc\n}\n\nexport const getMemoizedObject = memoizeObject(getObject)\n\nexport const assignAfter = (target: Record<string, any>, ...sources: any[]) => {\n if (target == null)\n throw new TypeError(\"Cannot convert undefined or null to object\")\n\n const result: Record<string, unknown> = { ...target }\n\n for (const nextSource of sources) {\n if (nextSource == null) continue\n\n for (const nextKey in nextSource) {\n if (!Object.prototype.hasOwnProperty.call(nextSource, nextKey)) continue\n\n if (nextKey in result) delete result[nextKey]\n\n result[nextKey] = nextSource[nextKey]\n }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;AAEO,IAAM,OAAO,MAAM;AAAC;AAEpB,IAAM,YAAY,CACvB,cACG,SACI,WAAW,SAAS,IAAI,UAAU,GAAG,IAAI,IAAI;AAE/C,IAAM,aACX,IAAoC,UAC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,MAAM,UAAU,CAAC;AAEzC,QAAI,IAAI,MAAM,KAAK;AAEnB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB,cAAc,SAAS;AAEjD,IAAM,cAAc,CAAC,WAAgC,YAAmB;AAC7E,MAAI,UAAU;AACZ,UAAM,IAAI,UAAU,4CAA4C;AAElE,QAAM,SAAkC,EAAE,GAAG,OAAO;AAEpD,aAAW,cAAc,SAAS;AAChC,QAAI,cAAc;AAAM;AAExB,eAAW,WAAW,YAAY;AAChC,UAAI,CAAC,OAAO,UAAU,eAAe,KAAK,YAAY,OAAO;AAAG;AAEhE,UAAI,WAAW;AAAQ,eAAO,OAAO,OAAO;AAE5C,aAAO,OAAO,IAAI,WAAW,OAAO;AAAA,IACtC;AAAA,EACF;AAEA,SAAO;AACT;","names":["createContext","useContext","isValidElement","children","isDark","key"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-RSDBT4DI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/string.ts"],"sourcesContent":["export const escape = (value: string, replaceValue: string = \"\"): string =>\n value.replace(/\\s+/g, replaceValue)\n"],"mappings":";AAAO,IAAM,SAAS,CAAC,OAAe,eAAuB,OAC3D,MAAM,QAAQ,QAAQ,YAAY;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/number.ts"],"sourcesContent":["const toNumber = (n: any): number => {\n const num = parseFloat(n)\n\n return typeof num !== \"number\" || Number.isNaN(num) ? 0 : num\n}\n\nexport const toPrecision = (n: number, precision?: number): string => {\n n = toNumber(n)\n\n const scale = 10 ** (precision ?? 10)\n\n n = Math.round(n * scale) / scale\n\n return precision ? n.toFixed(precision) : n.toString()\n}\n\nexport const countDecimal = (n: number): number => {\n if (!Number.isFinite(n)) return 0\n\n let e = 1\n let p = 0\n\n while (Math.round(n * e) / e !== n) {\n e *= 10\n p += 1\n }\n\n return p\n}\n\nexport const roundNumberToStep = (n: number, from: number, step: number) => {\n const nextValue = Math.round((n - from) / step) * step + from\n\n const precision = countDecimal(step)\n\n return toPrecision(nextValue, precision)\n}\n\nexport const valueToPercent = (n: number, min: number, max: number): number =>\n ((n - min) * 100) / (max - min)\n\nexport const percentToValue = (n: number, min: number, max: number) =>\n (max - min) * n + min\n\nexport const clampNumber = (n: number, min: number, max: number): number =>\n Math.min(Math.max(n, min), max)\n"],"mappings":";AAAA,IAAM,WAAW,CAAC,MAAmB;AACnC,QAAM,MAAM,WAAW,CAAC;AAExB,SAAO,OAAO,QAAQ,YAAY,OAAO,MAAM,GAAG,IAAI,IAAI;AAC5D;AAEO,IAAM,cAAc,CAAC,GAAW,cAA+B;AACpE,MAAI,SAAS,CAAC;AAEd,QAAM,QAAQ,OAAO,gCAAa;AAElC,MAAI,KAAK,MAAM,IAAI,KAAK,IAAI;AAE5B,SAAO,YAAY,EAAE,QAAQ,SAAS,IAAI,EAAE,SAAS;AACvD;AAEO,IAAM,eAAe,CAAC,MAAsB;AACjD,MAAI,CAAC,OAAO,SAAS,CAAC;AAAG,WAAO;AAEhC,MAAI,IAAI;AACR,MAAI,IAAI;AAER,SAAO,KAAK,MAAM,IAAI,CAAC,IAAI,MAAM,GAAG;AAClC,SAAK;AACL,SAAK;AAAA,EACP;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB,CAAC,GAAW,MAAc,SAAiB;AAC1E,QAAM,YAAY,KAAK,OAAO,IAAI,QAAQ,IAAI,IAAI,OAAO;AAEzD,QAAM,YAAY,aAAa,IAAI;AAEnC,SAAO,YAAY,WAAW,SAAS;AACzC;AAEO,IAAM,iBAAiB,CAAC,GAAW,KAAa,SACnD,IAAI,OAAO,OAAQ,MAAM;AAEtB,IAAM,iBAAiB,CAAC,GAAW,KAAa,SACpD,MAAM,OAAO,IAAI;AAEb,IAAM,cAAc,CAAC,GAAW,KAAa,QAClD,KAAK,IAAI,KAAK,IAAI,GAAG,GAAG,GAAG,GAAG;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/array.ts"],"sourcesContent":["export const filterEmpty = <T extends any[]>(array: T) =>\n array.filter((value) => value != null)\n"],"mappings":";AAAO,IAAM,cAAc,CAAkB,UAC3C,MAAM,OAAO,CAAC,UAAU,SAAS,IAAI;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
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}\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 }),\n {\n add,\n subtract,\n multiply,\n divide,\n negate,\n },\n)\n"],"mappings":";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;AAUO,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,EAC9B;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/color.d.mts
CHANGED
|
@@ -3,14 +3,15 @@ import { Dict } from './index.types.mjs';
|
|
|
3
3
|
type ColorMode = "light" | "dark";
|
|
4
4
|
declare const hues: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
5
5
|
declare const isGray: (colorScheme: string) => boolean;
|
|
6
|
+
declare const isAccessible: (colorScheme: string) => boolean;
|
|
6
7
|
declare const getColor: (color: string, fallback?: string) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
7
8
|
declare const lightenColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
8
9
|
declare const darkenColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
9
10
|
declare const tintColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
10
11
|
declare const shadeColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
11
12
|
declare const transparentizeColor: (color: string, alpha: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
12
|
-
declare const toneColor: (color: string, hue: (typeof hues)[number]) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
13
|
-
declare const toneColors: (color: string) => Record<string, string>;
|
|
13
|
+
declare const toneColor: (color: string, hue: (typeof hues)[number], lCoef?: number, dCoef?: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
14
|
+
declare const toneColors: (color: string, lCoef?: number, dCoef?: number) => Record<string, string>;
|
|
14
15
|
declare const randomColor: ({ string, colors, }?: {
|
|
15
16
|
string?: string | undefined;
|
|
16
17
|
colors?: string[] | undefined;
|
|
@@ -19,4 +20,4 @@ declare const isTone: (color: string) => (theme?: Dict, colorMode?: ColorMode) =
|
|
|
19
20
|
declare const isLight: (color: string) => (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
20
21
|
declare const isDark: (color: string) => (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
21
22
|
|
|
22
|
-
export { darkenColor, getColor, hues, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, toneColors, transparentizeColor };
|
|
23
|
+
export { darkenColor, getColor, hues, isAccessible, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, toneColors, transparentizeColor };
|
package/dist/color.d.ts
CHANGED
|
@@ -3,14 +3,15 @@ import { Dict } from './index.types.js';
|
|
|
3
3
|
type ColorMode = "light" | "dark";
|
|
4
4
|
declare const hues: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
5
5
|
declare const isGray: (colorScheme: string) => boolean;
|
|
6
|
+
declare const isAccessible: (colorScheme: string) => boolean;
|
|
6
7
|
declare const getColor: (color: string, fallback?: string) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
7
8
|
declare const lightenColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
8
9
|
declare const darkenColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
9
10
|
declare const tintColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
10
11
|
declare const shadeColor: (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
11
12
|
declare const transparentizeColor: (color: string, alpha: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
12
|
-
declare const toneColor: (color: string, hue: (typeof hues)[number]) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
13
|
-
declare const toneColors: (color: string) => Record<string, string>;
|
|
13
|
+
declare const toneColor: (color: string, hue: (typeof hues)[number], lCoef?: number, dCoef?: number) => (theme?: Dict, colorMode?: ColorMode) => string;
|
|
14
|
+
declare const toneColors: (color: string, lCoef?: number, dCoef?: number) => Record<string, string>;
|
|
14
15
|
declare const randomColor: ({ string, colors, }?: {
|
|
15
16
|
string?: string | undefined;
|
|
16
17
|
colors?: string[] | undefined;
|
|
@@ -19,4 +20,4 @@ declare const isTone: (color: string) => (theme?: Dict, colorMode?: ColorMode) =
|
|
|
19
20
|
declare const isLight: (color: string) => (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
20
21
|
declare const isDark: (color: string) => (theme?: Dict, colorMode?: ColorMode) => boolean;
|
|
21
22
|
|
|
22
|
-
export { darkenColor, getColor, hues, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, toneColors, transparentizeColor };
|
|
23
|
+
export { darkenColor, getColor, hues, isAccessible, isDark, isGray, isLight, isTone, lightenColor, randomColor, shadeColor, tintColor, toneColor, toneColors, transparentizeColor };
|
package/dist/color.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(color_exports, {
|
|
|
23
23
|
darkenColor: () => darkenColor,
|
|
24
24
|
getColor: () => getColor,
|
|
25
25
|
hues: () => hues,
|
|
26
|
+
isAccessible: () => isAccessible,
|
|
26
27
|
isDark: () => isDark,
|
|
27
28
|
isGray: () => isGray,
|
|
28
29
|
isLight: () => isLight,
|
|
@@ -70,7 +71,6 @@ var memoizeObject = (func) => {
|
|
|
70
71
|
var getMemoizedObject = memoizeObject(getObject);
|
|
71
72
|
|
|
72
73
|
// src/color.ts
|
|
73
|
-
var coef = 0.75;
|
|
74
74
|
var hues = [
|
|
75
75
|
50,
|
|
76
76
|
100,
|
|
@@ -85,6 +85,7 @@ var hues = [
|
|
|
85
85
|
950
|
|
86
86
|
];
|
|
87
87
|
var isGray = (colorScheme) => colorScheme === "gray" || colorScheme === "neutral";
|
|
88
|
+
var isAccessible = (colorScheme) => colorScheme === "yellow" || colorScheme === "cyan" || colorScheme === "lime";
|
|
88
89
|
var getColor = (color, fallback) => (theme = {}, colorMode) => {
|
|
89
90
|
var _a, _b, _c;
|
|
90
91
|
const [token, hue] = color.split(".");
|
|
@@ -114,7 +115,7 @@ var darkenColor = (color, amount) => (theme, colorMode) => {
|
|
|
114
115
|
};
|
|
115
116
|
var tintColor = (color, amount) => (theme, colorMode) => {
|
|
116
117
|
const raw = getColor(color, color)(theme, colorMode);
|
|
117
|
-
return (0, import_color2k.toHex)((0, import_color2k.mix)(raw, "#fff", amount));
|
|
118
|
+
return (0, import_color2k.toHex)((0, import_color2k.mix)(raw, "#fff", amount / 100));
|
|
118
119
|
};
|
|
119
120
|
var shadeColor = (color, amount) => (theme, colorMode) => {
|
|
120
121
|
const raw = getColor(color, color)(theme, colorMode);
|
|
@@ -124,18 +125,20 @@ var transparentizeColor = (color, alpha) => (theme, colorMode) => {
|
|
|
124
125
|
const raw = getColor(color, color)(theme, colorMode);
|
|
125
126
|
return (0, import_color2k.transparentize)(raw, 1 - alpha);
|
|
126
127
|
};
|
|
127
|
-
var toneColor = (color, hue) => (theme, colorMode) => {
|
|
128
|
+
var toneColor = (color, hue, lCoef = 0.94, dCoef = 0.86) => (theme, colorMode) => {
|
|
128
129
|
if (hue < 50 || 950 < hue)
|
|
129
130
|
return color;
|
|
130
131
|
let raw = color;
|
|
131
132
|
if (theme && colorMode)
|
|
132
133
|
getColor(color, color)(theme, colorMode);
|
|
134
|
+
const coef = hue < 500 ? lCoef : dCoef;
|
|
133
135
|
const amount = (500 - hue) * 1e-3 * coef;
|
|
134
136
|
return (0, import_color2k.toHex)((0, import_color2k.lighten)(raw, amount));
|
|
135
137
|
};
|
|
136
|
-
var toneColors = (color) => {
|
|
138
|
+
var toneColors = (color, lCoef = 0.94, dCoef = 0.86) => {
|
|
137
139
|
const colors = {};
|
|
138
140
|
hues.forEach((hue) => {
|
|
141
|
+
const coef = hue < 500 ? lCoef : dCoef;
|
|
139
142
|
const amount = (500 - hue) * 1e-3 * coef;
|
|
140
143
|
colors[hue] = (0, import_color2k.toHex)((0, import_color2k.lighten)(color, amount));
|
|
141
144
|
});
|
|
@@ -199,6 +202,7 @@ var isDark = (color) => (theme, colorMode) => isTone(color)(theme, colorMode) ==
|
|
|
199
202
|
darkenColor,
|
|
200
203
|
getColor,
|
|
201
204
|
hues,
|
|
205
|
+
isAccessible,
|
|
202
206
|
isDark,
|
|
203
207
|
isGray,
|
|
204
208
|
isLight,
|
|
@@ -211,3 +215,4 @@ var isDark = (color) => (theme, colorMode) => isTone(color)(theme, colorMode) ==
|
|
|
211
215
|
toneColors,
|
|
212
216
|
transparentizeColor
|
|
213
217
|
});
|
|
218
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/color.ts","../src/assertion.ts","../src/object.ts"],"sourcesContent":["import {\n toHex,\n parseToRgba,\n transparentize,\n mix,\n darken,\n lighten,\n} from \"color2k\"\nimport type { Dict } from \".\"\nimport { getMemoizedObject as get, isArray } from \".\"\n\ntype ColorMode = \"light\" | \"dark\"\n\nexport const hues = [\n 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950,\n] as const\n\nexport const isGray = (colorScheme: string) =>\n colorScheme === \"gray\" || colorScheme === \"neutral\"\n\nexport const isAccessible = (colorScheme: string) =>\n colorScheme === \"yellow\" || colorScheme === \"cyan\" || colorScheme === \"lime\"\n\nexport const getColor =\n (color: string, fallback?: string) =>\n (theme: Dict = {}, colorMode?: ColorMode) => {\n const [token, hue] = color.split(\".\")\n\n const [, relatedToken] =\n Object.entries<string>(theme.semantics?.colorSchemes ?? {}).find(\n ([semanticToken]) => token === semanticToken,\n ) ?? []\n\n if (relatedToken) color = `${relatedToken}.${hue}`\n\n const hex = get<\n string | number | [string | number, string | number] | undefined\n >(theme, `colors.${color}`, color)\n\n try {\n if (isArray(hex)) {\n return toHex(String(colorMode !== \"dark\" ? hex[0] : hex[1]))\n } else {\n return toHex(String(hex))\n }\n } catch {\n return fallback ?? \"#000000\"\n }\n }\n\nexport const lightenColor =\n (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return toHex(lighten(raw, amount / 100))\n }\n\nexport const darkenColor =\n (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return toHex(darken(raw, amount / 100))\n }\n\nexport const tintColor =\n (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return toHex(mix(raw, \"#fff\", amount / 100))\n }\n\nexport const shadeColor =\n (color: string, amount: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return toHex(mix(raw, \"#000\", amount / 100))\n }\n\nexport const transparentizeColor =\n (color: string, alpha: number) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = getColor(color, color)(theme, colorMode)\n\n return transparentize(raw, 1 - alpha)\n }\n\nexport const toneColor =\n (\n color: string,\n hue: (typeof hues)[number],\n lCoef: number = 0.94,\n dCoef: number = 0.86,\n ) =>\n (theme?: Dict, colorMode?: ColorMode) => {\n if (hue < 50 || 950 < hue) return color\n\n let raw = color\n\n if (theme && colorMode) getColor(color, color)(theme, colorMode)\n\n const coef = hue < 500 ? lCoef : dCoef\n const amount = (500 - hue) * 0.001 * coef\n\n return toHex(lighten(raw, amount))\n }\n\nexport const toneColors = (\n color: string,\n lCoef: number = 0.94,\n dCoef: number = 0.86,\n) => {\n const colors: Record<string, string> = {}\n\n hues.forEach((hue) => {\n const coef = hue < 500 ? lCoef : dCoef\n\n const amount = (500 - hue) * 0.001 * coef\n\n colors[hue] = toHex(lighten(color, amount))\n })\n\n return colors\n}\n\nexport const randomColor = ({\n string,\n colors,\n}: { string?: string; colors?: string[] } = {}) => {\n const fallback = randomHex()\n\n if (string && colors) return randomColorFromList(string, colors)\n\n if (string && !colors) return randomColorFromString(string)\n\n if (colors && !string) return randomFromList(colors)\n\n return fallback\n}\n\nconst randomHex = () =>\n `#${Math.floor(Math.random() * 0xffffff)\n .toString(16)\n .padEnd(6, \"0\")}`\n\nconst randomColorFromString = (str: string) => {\n let hash = 0\n\n if (str.length === 0) return hash.toString()\n\n for (let i = 0; i < str.length; i += 1) {\n hash = str.charCodeAt(i) + ((hash << 5) - hash)\n hash = hash & hash\n }\n\n let color = \"#\"\n\n for (let j = 0; j < 3; j += 1) {\n const value = (hash >> (j * 8)) & 255\n\n color += `00${value.toString(16)}`.substr(-2)\n }\n\n return color\n}\n\nconst randomColorFromList = (str: string, list: string[]) => {\n let index = 0\n\n if (str.length === 0) return list[0]\n\n for (let i = 0; i < str.length; i += 1) {\n index = str.charCodeAt(i) + ((index << 5) - index)\n\n index = index & index\n }\n\n index = ((index % list.length) + list.length) % list.length\n\n return list[index]\n}\n\nconst randomFromList = (list: string[]) =>\n list[Math.floor(Math.random() * list.length)]\n\nconst getBrightness = (color: string) => {\n const [r, g, b] = parseToRgba(color)\n\n return (r * 299 + g * 587 + b * 114) / 1000\n}\n\nexport const isTone =\n (color: string) => (theme?: Dict, colorMode?: ColorMode) => {\n const raw = theme ? getColor(color)(theme, colorMode) : color\n\n const brightness = getBrightness(raw)\n\n const isDark = brightness < 128\n\n return isDark ? \"dark\" : \"light\"\n }\n\nexport const isLight =\n (color: string) => (theme?: Dict, colorMode?: ColorMode) =>\n isTone(color)(theme, colorMode) === \"dark\"\n\nexport const isDark =\n (color: string) => (theme?: Dict, colorMode?: ColorMode) =>\n isTone(color)(theme, colorMode) === \"light\"\n","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 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","import type { Dict } from \".\"\nimport { isObject, isArray, isFunction } from \".\"\n\nexport const omitObject = <T extends Dict, K extends keyof T>(\n obj: T,\n keys: K[],\n): Omit<T, K> => {\n const result: Dict = {}\n\n Object.keys(obj).forEach((key) => {\n if (keys.includes(key as K)) return\n\n result[key] = obj[key]\n })\n\n return result as Omit<T, K>\n}\n\nexport const pickObject = <T extends Dict, K extends keyof T>(\n obj: T,\n keys: K[],\n): { [P in K]: T[P] } => {\n const result = {} as { [P in K]: T[P] }\n\n keys.forEach((key) => {\n if (key in obj) result[key] = obj[key]\n })\n\n return result\n}\n\nexport const splitObject = <T extends Dict, K extends keyof T>(\n obj: T,\n keys: K[],\n) => {\n const picked: Dict = {}\n const omitted: Dict = {}\n\n for (const [key, value] of Object.entries(obj)) {\n if (keys.includes(key as T[K])) {\n picked[key] = value\n } else {\n omitted[key] = value\n }\n }\n\n return [picked, omitted] as [{ [P in K]: T[P] }, Omit<T, K>]\n}\n\nexport const filterObject = <T extends Dict, K extends Dict>(\n obj: T,\n func: (key: keyof T, value: T[keyof T], obj: T) => boolean,\n): K => {\n const result: Dict = {}\n\n Object.entries(obj).forEach(([key, value]) => {\n const shouldPass = func(key, value, obj)\n\n if (shouldPass) result[key] = value\n })\n\n return result as K\n}\n\nexport const filterUndefined = <T extends Dict>(obj: T): T =>\n filterObject(obj, (_, val) => val !== null && val !== undefined)\n\nexport const merge = <T extends Dict>(\n target: any,\n source: any,\n mergeArray: boolean = false,\n): T => {\n let result = Object.assign({}, target)\n\n if (isObject(source)) {\n if (isObject(target)) {\n for (const [sourceKey, sourceValue] of Object.entries(source)) {\n const targetValue = target[sourceKey]\n\n if (mergeArray && isArray(sourceValue) && isArray(targetValue)) {\n result[sourceKey] = targetValue.concat(...sourceValue)\n } else if (\n !isFunction(sourceValue) &&\n isObject(sourceValue) &&\n target.hasOwnProperty(sourceKey)\n ) {\n result[sourceKey] = merge(targetValue, sourceValue, mergeArray)\n } else {\n Object.assign(result, { [sourceKey]: sourceValue })\n }\n }\n } else {\n result = source\n }\n }\n\n return result as T\n}\n\nexport const flattenObject = <T extends Dict>(\n obj: any,\n maxDepth: number = Infinity,\n omitKeys: string[] = [],\n): T => {\n if ((!isObject(obj) && !isArray(obj)) || !maxDepth) return obj\n\n return Object.entries(obj).reduce((result, [key, value]) => {\n if (\n isObject(value) &&\n !Object.keys(value).some((key) => omitKeys.includes(key))\n ) {\n Object.entries(flattenObject(value, maxDepth - 1, omitKeys)).forEach(\n ([childKey, childValue]) => {\n result[`${key}.${childKey}`] = childValue\n },\n )\n } else {\n result[key] = value\n }\n\n return result\n }, {} as any) as T\n}\n\nexport const objectFromEntries = <T extends Dict>(entries: any[][]): T =>\n entries.reduce((result, [key, value]) => {\n result[key] = value\n\n return result\n }, {} as any) as T\n\nexport const keysFormObject = <T extends Dict>(obj: T): (keyof T)[] =>\n Object.keys(obj)\n\nexport const replaceObject = <T extends any>(\n objOrArray: T,\n callBack: (value: any) => any,\n): T => {\n if (isArray(objOrArray)) {\n return objOrArray.map(callBack) as T\n } else if (isObject(objOrArray)) {\n return Object.entries(objOrArray).reduce((obj, [key, value]) => {\n obj[key] = callBack(value)\n\n return obj\n }, {} as Dict) as T\n } else {\n return callBack(objOrArray)\n }\n}\n\nexport const getObject = (\n obj: Dict,\n path: string | number,\n fallback?: any,\n i?: number,\n) => {\n const k = typeof path === \"string\" ? path.split(\".\") : [path]\n\n for (i = 0; i < k.length; i += 1) {\n if (!obj) break\n\n obj = obj[k[i]]\n }\n\n return obj === undefined ? fallback : obj\n}\n\nexport const memoizeObject = (func: typeof getObject) => {\n const cache = new WeakMap()\n\n const memoizedFunc = <T extends unknown = any>(\n obj: Dict,\n path: string | number,\n fallback?: any,\n i?: number,\n ): T => {\n if (typeof obj === \"undefined\") return func(obj, path, fallback)\n\n if (!cache.has(obj)) cache.set(obj, new Map())\n\n const map = cache.get(obj)\n\n if (map.has(path)) return map.get(path)\n\n const value = func(obj, path, fallback, i)\n\n map.set(path, value)\n\n return value as T\n }\n\n return memoizedFunc\n}\n\nexport const getMemoizedObject = memoizeObject(getObject)\n\nexport const assignAfter = (target: Record<string, any>, ...sources: any[]) => {\n if (target == null)\n throw new TypeError(\"Cannot convert undefined or null to object\")\n\n const result: Record<string, unknown> = { ...target }\n\n for (const nextSource of sources) {\n if (nextSource == null) continue\n\n for (const nextKey in nextSource) {\n if (!Object.prototype.hasOwnProperty.call(nextSource, nextKey)) continue\n\n if (nextKey in result) delete result[nextKey]\n\n result[nextKey] = nextSource[nextKey]\n }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAOO;;;ACkBA,IAAM,UAAU,CAAkB,UACvC,MAAM,QAAQ,KAAK;;;AC6Hd,IAAM,YAAY,CACvB,KACA,MACA,UACA,MACG;AACH,QAAM,IAAI,OAAO,SAAS,WAAW,KAAK,MAAM,GAAG,IAAI,CAAC,IAAI;AAE5D,OAAK,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK,GAAG;AAChC,QAAI,CAAC;AAAK;AAEV,UAAM,IAAI,EAAE,CAAC,CAAC;AAAA,EAChB;AAEA,SAAO,QAAQ,SAAY,WAAW;AACxC;AAEO,IAAM,gBAAgB,CAAC,SAA2B;AACvD,QAAM,QAAQ,oBAAI,QAAQ;AAE1B,QAAM,eAAe,CACnB,KACA,MACA,UACA,MACM;AACN,QAAI,OAAO,QAAQ;AAAa,aAAO,KAAK,KAAK,MAAM,QAAQ;AAE/D,QAAI,CAAC,MAAM,IAAI,GAAG;AAAG,YAAM,IAAI,KAAK,oBAAI,IAAI,CAAC;AAE7C,UAAM,MAAM,MAAM,IAAI,GAAG;AAEzB,QAAI,IAAI,IAAI,IAAI;AAAG,aAAO,IAAI,IAAI,IAAI;AAEtC,UAAM,QAAQ,KAAK,KAAK,MAAM,UAAU,CAAC;AAEzC,QAAI,IAAI,MAAM,KAAK;AAEnB,WAAO;AAAA,EACT;AAEA,SAAO;AACT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UAAkB;AACvC,QAAM,CAAC,GAAG,GAAG,CAAC,QAAI,4BAAY,KAAK;AAEnC,UAAQ,IAAI,MAAM,IAAI,MAAM,IAAI,OAAO;AACzC;AAEO,IAAM,SACX,CAAC,UAAkB,CAAC,OAAc,cAA0B;AAC1D,QAAM,MAAM,QAAQ,SAAS,KAAK,EAAE,OAAO,SAAS,IAAI;AAExD,QAAM,aAAa,cAAc,GAAG;AAEpC,QAAMA,UAAS,aAAa;AAE5B,SAAOA,UAAS,SAAS;AAC3B;AAEK,IAAM,UACX,CAAC,UAAkB,CAAC,OAAc,cAChC,OAAO,KAAK,EAAE,OAAO,SAAS,MAAM;AAEjC,IAAM,SACX,CAAC,UAAkB,CAAC,OAAc,cAChC,OAAO,KAAK,EAAE,OAAO,SAAS,MAAM;","names":["isDark"]}
|
package/dist/color.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
darkenColor,
|
|
3
3
|
getColor,
|
|
4
4
|
hues,
|
|
5
|
+
isAccessible,
|
|
5
6
|
isDark,
|
|
6
7
|
isGray,
|
|
7
8
|
isLight,
|
|
@@ -13,19 +14,21 @@ import {
|
|
|
13
14
|
toneColor,
|
|
14
15
|
toneColors,
|
|
15
16
|
transparentizeColor
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
20
|
-
import "./chunk-
|
|
21
|
-
import "./chunk-
|
|
22
|
-
import "./chunk-
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
17
|
+
} from "./chunk-OHIZZWZU.mjs";
|
|
18
|
+
import "./chunk-RSDBT4DI.mjs";
|
|
19
|
+
import "./chunk-5OUUTZYQ.mjs";
|
|
20
|
+
import "./chunk-WDMW4NT7.mjs";
|
|
21
|
+
import "./chunk-TX5GWD7K.mjs";
|
|
22
|
+
import "./chunk-WV6P7ZCI.mjs";
|
|
23
|
+
import "./chunk-6DMBHPNQ.mjs";
|
|
24
|
+
import "./chunk-ZFYLQH3G.mjs";
|
|
25
|
+
import "./chunk-GC3WZLP7.mjs";
|
|
26
|
+
import "./chunk-A74F6ICI.mjs";
|
|
25
27
|
export {
|
|
26
28
|
darkenColor,
|
|
27
29
|
getColor,
|
|
28
30
|
hues,
|
|
31
|
+
isAccessible,
|
|
29
32
|
isDark,
|
|
30
33
|
isGray,
|
|
31
34
|
isLight,
|
|
@@ -38,3 +41,4 @@ export {
|
|
|
38
41
|
toneColors,
|
|
39
42
|
transparentizeColor
|
|
40
43
|
};
|
|
44
|
+
//# sourceMappingURL=color.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/dom.js
CHANGED
package/dist/dom.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dom.ts"],"sourcesContent":["import type React from \"react\"\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/)\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(\"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 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 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"],"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;AAEO,IAAM,aAAa,MACxB,CAAC,EACC,OAAO,WAAW,eAClB,OAAO,YACP,OAAO,SAAS;AAGb,IAAM,cAAc,MAAW;AATtC;AAUG,+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,MAAM;AAC5C,IAAM,UAAU,MAAe,SAAS,uBAAuB;AAC/D,IAAM,WAAW,M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