@yamada-ui/react 2.2.4-dev-20260706063021 → 2.2.4-dev-20260714083000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/date-picker/use-date-picker.cjs.map +1 -1
- package/dist/cjs/components/fieldset/fieldset.style.cjs.map +1 -1
- package/dist/cjs/components/icon/icons/index.cjs +3 -0
- package/dist/cjs/components/icon/icons/index.cjs.map +1 -1
- package/dist/cjs/components/icon/icons/paper-bag-icon.cjs +14 -0
- package/dist/cjs/components/icon/icons/paper-bag-icon.cjs.map +1 -0
- package/dist/cjs/components/icon/index.cjs +2 -0
- package/dist/cjs/components/slider/use-slider.cjs.map +1 -1
- package/dist/cjs/core/components/create-component.cjs.map +1 -1
- package/dist/cjs/core/components/use-component-style.cjs.map +1 -1
- package/dist/cjs/hooks/use-focus/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +3 -0
- package/dist/cjs/utils/store.cjs.map +1 -1
- package/dist/esm/components/date-picker/use-date-picker.js.map +1 -1
- package/dist/esm/components/fieldset/fieldset.style.js.map +1 -1
- package/dist/esm/components/icon/icons/index.js +3 -1
- package/dist/esm/components/icon/icons/index.js.map +1 -1
- package/dist/esm/components/icon/icons/paper-bag-icon.js +14 -0
- package/dist/esm/components/icon/icons/paper-bag-icon.js.map +1 -0
- package/dist/esm/components/icon/index.js +2 -1
- package/dist/esm/components/slider/use-slider.js.map +1 -1
- package/dist/esm/core/components/create-component.js.map +1 -1
- package/dist/esm/core/components/use-component-style.js.map +1 -1
- package/dist/esm/hooks/use-focus/index.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/utils/store.js.map +1 -1
- package/dist/types/components/chart/polar-chart.style.d.ts +1 -1
- package/dist/types/components/icon/icons/index.d.ts +3 -2
- package/dist/types/components/icon/icons/index.types.d.ts +1 -1
- package/dist/types/components/icon/icons/paper-bag-icon.d.ts +13 -0
- package/dist/types/components/icon/index.d.ts +2 -1
- package/dist/types/index.d.ts +3 -2
- package/package.json +9 -9
|
@@ -1136,6 +1136,7 @@ const require_panel_top_open_icon = require("./icons/panel-top-open-icon.cjs");
|
|
|
1136
1136
|
const require_panels_left_bottom_icon = require("./icons/panels-left-bottom-icon.cjs");
|
|
1137
1137
|
const require_panels_right_bottom_icon = require("./icons/panels-right-bottom-icon.cjs");
|
|
1138
1138
|
const require_panels_top_left_icon = require("./icons/panels-top-left-icon.cjs");
|
|
1139
|
+
const require_paper_bag_icon = require("./icons/paper-bag-icon.cjs");
|
|
1139
1140
|
const require_paperclip_icon = require("./icons/paperclip-icon.cjs");
|
|
1140
1141
|
const require_parasol_icon = require("./icons/parasol-icon.cjs");
|
|
1141
1142
|
const require_parentheses_icon = require("./icons/parentheses-icon.cjs");
|
|
@@ -2885,6 +2886,7 @@ exports.PanelTopOpenIcon = require_panel_top_open_icon.PanelTopOpenIcon;
|
|
|
2885
2886
|
exports.PanelsLeftBottomIcon = require_panels_left_bottom_icon.PanelsLeftBottomIcon;
|
|
2886
2887
|
exports.PanelsRightBottomIcon = require_panels_right_bottom_icon.PanelsRightBottomIcon;
|
|
2887
2888
|
exports.PanelsTopLeftIcon = require_panels_top_left_icon.PanelsTopLeftIcon;
|
|
2889
|
+
exports.PaperBagIcon = require_paper_bag_icon.PaperBagIcon;
|
|
2888
2890
|
exports.PaperclipIcon = require_paperclip_icon.PaperclipIcon;
|
|
2889
2891
|
exports.ParasolIcon = require_parasol_icon.ParasolIcon;
|
|
2890
2892
|
exports.ParenthesesIcon = require_parentheses_icon.ParenthesesIcon;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-slider.cjs","names":["useFieldProps","useControllableState","useI18n","usePanEvent","mergeProps","visuallyHiddenAttributes","mergeRefs"],"sources":["../../../../src/components/slider/use-slider.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent } from \"react\"\nimport type {\n HTMLProps,\n HTMLRefAttributes,\n Orientation,\n PropGetter,\n RequiredPropGetter,\n} from \"../../core\"\nimport type { Point } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useRef } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { usePanEvent } from \"../../hooks/use-pan-event\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n clampNumber,\n cx,\n dataAttr,\n handlerAll,\n isArray,\n isNumber,\n mergeRefs,\n percentToValue,\n roundNumberToStep,\n runKeyAction,\n valueToPercent,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nexport interface UseSliderProps<Y extends [number, number] | number = number>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * The minimum distance between slider thumbs.\n * Useful for preventing the thumbs from being too close together.\n *\n * @default 0\n */\n betweenThumbs?: number\n /**\n * The initial value of the slider.\n */\n defaultValue?: Y\n /**\n * The base `id` to use for the slider.\n */\n id?: string\n /**\n * The maximum allowed value of the slider. Cannot be less than min.\n *\n * @default 100\n */\n max?: number\n /**\n * The minimum allowed value of the slider. Cannot be greater than max.\n *\n * @default 0\n */\n min?: number\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The orientation of the slider.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 1\n */\n step?: number\n /**\n * The value of the slider.\n */\n value?: Y\n /**\n * This is used to format the value so that screen readers\n * can speak out a more human-friendly value.\n *\n * It is used to set the `aria-valuetext` property of the input.\n */\n getAriaValueText?: (value: number, index: number) => string | undefined\n /**\n * Function called whenever the slider value changes.\n */\n onChange?: (value: Y) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: Y) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: Y) => void\n}\n\nexport const useSlider = <Y extends [number, number] | number = number>(\n props: UseSliderProps<Y> = {},\n) => {\n const {\n props: {\n id,\n ref,\n name,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-valuetext\": ariaValueText,\n betweenThumbs = 0,\n defaultValue = 0 as Y,\n disabled,\n getAriaValueText,\n max = 100,\n min = 0,\n orientation = \"horizontal\",\n readOnly,\n required,\n step = 1,\n value: valueProp,\n onChange: onChangeProp,\n onChangeEnd,\n onChangeStart,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const { t } = useI18n(\"slider\")\n const currentIndex = useRef(0)\n const interactive = !(disabled || readOnly)\n const [_, getPanEventProps] = usePanEvent<HTMLDivElement>({\n onEnd: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n if (range) {\n const start = currentIndex.current === 0\n const oppositeIndex = currentIndex.current === 0 ? 1 : 0\n const oppositeValue = value[oppositeIndex]\n\n onChangeEnd?.(\n (start ? [panValue, oppositeValue] : [oppositeValue, panValue]) as Y,\n )\n } else {\n onChangeEnd?.(panValue as Y)\n }\n },\n onMove: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n onChange(currentIndex.current, panValue)\n },\n onStart: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n if (range) {\n const distances = value.map((value) => Math.abs(value - panValue))\n const closest = Math.min(...distances)\n const index = distances.indexOf(closest)\n\n currentIndex.current = index\n\n const start = index === 0\n const oppositeIndex = index === 0 ? 1 : 0\n const oppositeValue = value[oppositeIndex]\n\n onChangeStart?.(\n (start ? [panValue, oppositeValue] : [oppositeValue, panValue]) as Y,\n )\n } else {\n currentIndex.current = 0\n\n onChangeStart?.(value as Y)\n }\n\n onChange(currentIndex.current, panValue)\n },\n })\n const range = !isNumber(value)\n const percent = (\n range\n ? value.map((value) => valueToPercent(value, min, max))\n : valueToPercent(value, min, max)\n ) as Y extends number ? number : number[]\n const tenStep = (max - min) / 10\n const oneStep = step || (max - min) / 100\n\n if (max < min) console.warn(\"Do not assign a number less than 'min' to 'max'\")\n\n const getMinMax = useCallback(\n (index: number) => {\n const start = index === 0\n const oppositeIndex = index === 0 ? 1 : 0\n const oppositeValue = range ? value[oppositeIndex] : value\n\n return {\n max: range ? (start ? oppositeValue - betweenThumbs : max) : max,\n min: range ? (start ? min : oppositeValue + betweenThumbs) : min,\n }\n },\n [betweenThumbs, max, min, range, value],\n )\n\n const getPanValue = useCallback(\n ({ x, y }: Point, { bottom, height, left, width }: DOMRect) => {\n const diff = orientation === \"horizontal\" ? x - left : bottom - y\n const length = orientation === \"horizontal\" ? width : height\n const percent = diff / length\n\n let nextValue = percentToValue(percent, min, max)\n\n nextValue = parseFloat(roundNumberToStep(nextValue, min, step))\n nextValue = clampNumber(nextValue, min, max)\n\n return nextValue\n },\n [orientation, min, max, step],\n )\n\n const onChange = useCallback(\n (index: number, value: number) => {\n if (!interactive) return\n\n const { max, min } = getMinMax(index)\n\n value = parseFloat(roundNumberToStep(value, min, oneStep))\n value = clampNumber(value, min, max)\n\n setValue((prev) => {\n if (isArray(prev)) {\n const next = [...prev]\n\n next[index] = value\n\n return next as Y\n } else {\n return value as Y\n }\n })\n },\n [getMinMax, interactive, oneStep, setValue],\n )\n\n const stepUp = useCallback(\n (index: number, step = oneStep) =>\n range\n ? onChange(index, value[index]! + step)\n : onChange(index, value + step),\n [oneStep, range, onChange, value],\n )\n\n const stepDown = useCallback(\n (index: number, step = oneStep) =>\n range\n ? onChange(index, value[index]! - step)\n : onChange(index, value - step),\n [oneStep, range, onChange, value],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLDivElement>) => {\n const { max, min } = getMinMax(index)\n\n runKeyAction(ev, {\n ArrowDown: () => stepDown(index),\n ArrowLeft: () => stepDown(index),\n ArrowRight: () => stepUp(index),\n ArrowUp: () => stepUp(index),\n End: () => onChange(index, max),\n Home: () => onChange(index, min),\n PageDown: () => stepDown(index, tenStep),\n PageUp: () => stepUp(index, tenStep),\n })\n },\n [getMinMax, onChange, stepDown, stepUp, tenStep],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => {\n const computedProps: HTMLProps = mergeProps(\n dataProps,\n { \"data-orientation\": orientation },\n rest,\n props,\n { onBlur: eventProps.onBlur, onFocus: eventProps.onFocus },\n )()\n\n computedProps.style ??= {}\n\n if (isArray(percent)) {\n computedProps.style[\"--range-start\"] = `${Math.abs(percent[0]!)}%`\n computedProps.style[\"--range-end\"] = `${Math.abs(percent[1]!)}%`\n } else {\n computedProps.style[\"--range-start\"] = \"0%\"\n computedProps.style[\"--range-end\"] = `${Math.abs(percent)}%`\n }\n\n return computedProps\n },\n [dataProps, eventProps, orientation, percent, rest],\n )\n\n const getInputProps: PropGetter<\"input\", { index?: number }> = useCallback(\n ({ index = 0, ...props } = {}) => ({\n ...visuallyHiddenAttributes,\n ...dataProps,\n ...ariaProps,\n id,\n type: \"hidden\",\n name,\n disabled,\n readOnly,\n required,\n value: range ? value[index]! : value,\n ...props,\n ref: index === 0 ? mergeRefs(props.ref, ref) : props.ref,\n }),\n [\n dataProps,\n ariaProps,\n id,\n name,\n disabled,\n readOnly,\n required,\n range,\n value,\n ref,\n ],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props) =>\n getPanEventProps({\n ...dataProps,\n \"data-orientation\": orientation,\n ...props,\n }),\n [dataProps, getPanEventProps, orientation],\n )\n\n const getRangeProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n \"data-orientation\": orientation,\n \"data-range\": dataAttr(range),\n ...props,\n }),\n [dataProps, orientation, range],\n )\n\n const getMarkProps: RequiredPropGetter<\"div\", { value: number }> =\n useCallback(\n ({ style, value: valueProp, ...props }) => {\n const between = range\n ? value[0] < valueProp && valueProp < value[1]\n : valueProp < value\n const percent = valueToPercent(valueProp, min, max)\n\n return {\n ...dataProps,\n \"aria-hidden\": true,\n \"data-between\": dataAttr(between),\n \"data-orientation\": orientation,\n role: \"presentation\",\n ...props,\n style: { ...style, \"--mark-position\": `${percent}%` },\n }\n },\n [dataProps, max, min, orientation, range, value],\n )\n\n const getThumbProps: PropGetter<\"div\", { index?: number }> = useCallback(\n ({ index = 0, ...rest } = {}) => {\n const { max, min } = getMinMax(index)\n\n const props: HTMLProps = {\n ...dataProps,\n ...ariaProps,\n \"aria-label\": t(\"Slider thumb\"),\n \"aria-orientation\": orientation,\n \"aria-valuemax\": max,\n \"aria-valuemin\": min,\n role: \"slider\",\n tabIndex: interactive ? 0 : -1,\n ...rest,\n \"aria-labelledby\": cx(rest[\"aria-labelledby\"], ariaLabelledBy),\n onKeyDown: handlerAll(rest.onKeyDown, onKeyDown(index)),\n }\n\n if (range) {\n const currentValue = value[index]!\n\n props[\"data-start\"] = dataAttr(index === 0)\n props[\"data-end\"] = dataAttr(index === 1)\n props[\"aria-valuenow\"] = currentValue\n props[\"aria-valuetext\"] =\n ariaValueText ??\n getAriaValueText?.(currentValue, index) ??\n currentValue.toString()\n } else {\n props[\"data-end\"] = dataAttr(index === 0)\n props[\"aria-valuenow\"] = value\n props[\"aria-valuetext\"] =\n ariaValueText ?? getAriaValueText?.(value, index) ?? value.toString()\n }\n\n return props\n },\n [\n t,\n ariaLabelledBy,\n ariaProps,\n ariaValueText,\n dataProps,\n getAriaValueText,\n getMinMax,\n interactive,\n onKeyDown,\n orientation,\n range,\n value,\n ],\n )\n\n return {\n percent,\n range,\n setValue,\n stepDown,\n stepUp,\n value,\n getInputProps,\n getMarkProps,\n getRangeProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n onChange,\n }\n}\n\nexport type UseSliderReturn = ReturnType<typeof useSlider>\n"],"mappings":";;;;;;;;;;;AA2GA,MAAa,aACX,QAA2B,CAAC,MACzB;CACH,MAAM,EACJ,OAAO,EACL,IACA,KACA,MACA,mBAAmB,gBACnB,kBAAkB,eAClB,gBAAgB,GAChB,eAAe,G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zB,MAAM,oBACJ,iBAAiB,mBAAmB,OAAO,KAAK,KAAK,MAAM,SAAS;GACxE;GAEA,OAAO;EACT,GACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAcY;EACZ;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"use-slider.cjs","names":["useFieldProps","useControllableState","useI18n","usePanEvent","mergeProps","visuallyHiddenAttributes","mergeRefs"],"sources":["../../../../src/components/slider/use-slider.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent } from \"react\"\nimport type {\n HTMLProps,\n HTMLRefAttributes,\n Orientation,\n PropGetter,\n RequiredPropGetter,\n} from \"../../core\"\nimport type { Point } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useRef } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { usePanEvent } from \"../../hooks/use-pan-event\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n clampNumber,\n cx,\n dataAttr,\n handlerAll,\n isArray,\n isNumber,\n mergeRefs,\n percentToValue,\n roundNumberToStep,\n runKeyAction,\n valueToPercent,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nexport interface UseSliderProps<Y extends [number, number] | number = number>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * The minimum distance between slider thumbs.\n * Useful for preventing the thumbs from being too close together.\n *\n * @default 0\n */\n betweenThumbs?: number\n /**\n * The initial value of the slider.\n */\n defaultValue?: Y\n /**\n * The base `id` to use for the slider.\n */\n id?: string\n /**\n * The maximum allowed value of the slider. Cannot be less than min.\n *\n * @default 100\n */\n max?: number\n /**\n * The minimum allowed value of the slider. Cannot be greater than max.\n *\n * @default 0\n */\n min?: number\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The orientation of the slider.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 1\n */\n step?: number\n /**\n * The value of the slider.\n */\n value?: Y\n /**\n * This is used to format the value so that screen readers\n * can speak out a more human-friendly value.\n *\n * It is used to set the `aria-valuetext` property of the input.\n */\n getAriaValueText?: (value: number, index: number) => string | undefined\n /**\n * Function called whenever the slider value changes.\n */\n onChange?: (value: Y) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: Y) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: Y) => void\n}\n\nexport const useSlider = <Y extends [number, number] | number = number>(\n props: UseSliderProps<Y> = {},\n) => {\n const {\n props: {\n id,\n ref,\n name,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-valuetext\": ariaValueText,\n betweenThumbs = 0,\n defaultValue = 0 as Y,\n disabled,\n getAriaValueText,\n max = 100,\n min = 0,\n orientation = \"horizontal\",\n readOnly,\n required,\n step = 1,\n value: valueProp,\n onChange: onChangeProp,\n onChangeEnd,\n onChangeStart,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const { t } = useI18n(\"slider\")\n const currentIndex = useRef(0)\n const interactive = !(disabled || readOnly)\n const [_, getPanEventProps] = usePanEvent<HTMLDivElement>({\n onEnd: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n if (range) {\n const start = currentIndex.current === 0\n const oppositeIndex = currentIndex.current === 0 ? 1 : 0\n const oppositeValue = value[oppositeIndex]\n\n onChangeEnd?.(\n (start ? [panValue, oppositeValue] : [oppositeValue, panValue]) as Y,\n )\n } else {\n onChangeEnd?.(panValue as Y)\n }\n },\n onMove: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n onChange(currentIndex.current, panValue)\n },\n onStart: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n if (range) {\n const distances = value.map((value) => Math.abs(value - panValue))\n const closest = Math.min(...distances)\n const index = distances.indexOf(closest)\n\n currentIndex.current = index\n\n const start = index === 0\n const oppositeIndex = index === 0 ? 1 : 0\n const oppositeValue = value[oppositeIndex]\n\n onChangeStart?.(\n (start ? [panValue, oppositeValue] : [oppositeValue, panValue]) as Y,\n )\n } else {\n currentIndex.current = 0\n\n onChangeStart?.(value)\n }\n\n onChange(currentIndex.current, panValue)\n },\n })\n const range = !isNumber(value)\n const percent = (\n range\n ? value.map((value) => valueToPercent(value, min, max))\n : valueToPercent(value, min, max)\n ) as Y extends number ? number : number[]\n const tenStep = (max - min) / 10\n const oneStep = step || (max - min) / 100\n\n if (max < min) console.warn(\"Do not assign a number less than 'min' to 'max'\")\n\n const getMinMax = useCallback(\n (index: number) => {\n const start = index === 0\n const oppositeIndex = index === 0 ? 1 : 0\n const oppositeValue = range ? value[oppositeIndex] : value\n\n return {\n max: range ? (start ? oppositeValue - betweenThumbs : max) : max,\n min: range ? (start ? min : oppositeValue + betweenThumbs) : min,\n }\n },\n [betweenThumbs, max, min, range, value],\n )\n\n const getPanValue = useCallback(\n ({ x, y }: Point, { bottom, height, left, width }: DOMRect) => {\n const diff = orientation === \"horizontal\" ? x - left : bottom - y\n const length = orientation === \"horizontal\" ? width : height\n const percent = diff / length\n\n let nextValue = percentToValue(percent, min, max)\n\n nextValue = parseFloat(roundNumberToStep(nextValue, min, step))\n nextValue = clampNumber(nextValue, min, max)\n\n return nextValue\n },\n [orientation, min, max, step],\n )\n\n const onChange = useCallback(\n (index: number, value: number) => {\n if (!interactive) return\n\n const { max, min } = getMinMax(index)\n\n value = parseFloat(roundNumberToStep(value, min, oneStep))\n value = clampNumber(value, min, max)\n\n setValue((prev) => {\n if (isArray(prev)) {\n const next = [...prev]\n\n next[index] = value\n\n return next as Y\n } else {\n return value as Y\n }\n })\n },\n [getMinMax, interactive, oneStep, setValue],\n )\n\n const stepUp = useCallback(\n (index: number, step = oneStep) =>\n range\n ? onChange(index, value[index]! + step)\n : onChange(index, value + step),\n [oneStep, range, onChange, value],\n )\n\n const stepDown = useCallback(\n (index: number, step = oneStep) =>\n range\n ? onChange(index, value[index]! - step)\n : onChange(index, value - step),\n [oneStep, range, onChange, value],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLDivElement>) => {\n const { max, min } = getMinMax(index)\n\n runKeyAction(ev, {\n ArrowDown: () => stepDown(index),\n ArrowLeft: () => stepDown(index),\n ArrowRight: () => stepUp(index),\n ArrowUp: () => stepUp(index),\n End: () => onChange(index, max),\n Home: () => onChange(index, min),\n PageDown: () => stepDown(index, tenStep),\n PageUp: () => stepUp(index, tenStep),\n })\n },\n [getMinMax, onChange, stepDown, stepUp, tenStep],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => {\n const computedProps: HTMLProps = mergeProps(\n dataProps,\n { \"data-orientation\": orientation },\n rest,\n props,\n { onBlur: eventProps.onBlur, onFocus: eventProps.onFocus },\n )()\n\n computedProps.style ??= {}\n\n if (isArray(percent)) {\n computedProps.style[\"--range-start\"] = `${Math.abs(percent[0]!)}%`\n computedProps.style[\"--range-end\"] = `${Math.abs(percent[1]!)}%`\n } else {\n computedProps.style[\"--range-start\"] = \"0%\"\n computedProps.style[\"--range-end\"] = `${Math.abs(percent)}%`\n }\n\n return computedProps\n },\n [dataProps, eventProps, orientation, percent, rest],\n )\n\n const getInputProps: PropGetter<\"input\", { index?: number }> = useCallback(\n ({ index = 0, ...props } = {}) => ({\n ...visuallyHiddenAttributes,\n ...dataProps,\n ...ariaProps,\n id,\n type: \"hidden\",\n name,\n disabled,\n readOnly,\n required,\n value: range ? value[index]! : value,\n ...props,\n ref: index === 0 ? mergeRefs(props.ref, ref) : props.ref,\n }),\n [\n dataProps,\n ariaProps,\n id,\n name,\n disabled,\n readOnly,\n required,\n range,\n value,\n ref,\n ],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props) =>\n getPanEventProps({\n ...dataProps,\n \"data-orientation\": orientation,\n ...props,\n }),\n [dataProps, getPanEventProps, orientation],\n )\n\n const getRangeProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n \"data-orientation\": orientation,\n \"data-range\": dataAttr(range),\n ...props,\n }),\n [dataProps, orientation, range],\n )\n\n const getMarkProps: RequiredPropGetter<\"div\", { value: number }> =\n useCallback(\n ({ style, value: valueProp, ...props }) => {\n const between = range\n ? value[0] < valueProp && valueProp < value[1]\n : valueProp < value\n const percent = valueToPercent(valueProp, min, max)\n\n return {\n ...dataProps,\n \"aria-hidden\": true,\n \"data-between\": dataAttr(between),\n \"data-orientation\": orientation,\n role: \"presentation\",\n ...props,\n style: { ...style, \"--mark-position\": `${percent}%` },\n }\n },\n [dataProps, max, min, orientation, range, value],\n )\n\n const getThumbProps: PropGetter<\"div\", { index?: number }> = useCallback(\n ({ index = 0, ...rest } = {}) => {\n const { max, min } = getMinMax(index)\n\n const props: HTMLProps = {\n ...dataProps,\n ...ariaProps,\n \"aria-label\": t(\"Slider thumb\"),\n \"aria-orientation\": orientation,\n \"aria-valuemax\": max,\n \"aria-valuemin\": min,\n role: \"slider\",\n tabIndex: interactive ? 0 : -1,\n ...rest,\n \"aria-labelledby\": cx(rest[\"aria-labelledby\"], ariaLabelledBy),\n onKeyDown: handlerAll(rest.onKeyDown, onKeyDown(index)),\n }\n\n if (range) {\n const currentValue = value[index]!\n\n props[\"data-start\"] = dataAttr(index === 0)\n props[\"data-end\"] = dataAttr(index === 1)\n props[\"aria-valuenow\"] = currentValue\n props[\"aria-valuetext\"] =\n ariaValueText ??\n getAriaValueText?.(currentValue, index) ??\n currentValue.toString()\n } else {\n props[\"data-end\"] = dataAttr(index === 0)\n props[\"aria-valuenow\"] = value\n props[\"aria-valuetext\"] =\n ariaValueText ?? getAriaValueText?.(value, index) ?? value.toString()\n }\n\n return props\n },\n [\n t,\n ariaLabelledBy,\n ariaProps,\n ariaValueText,\n dataProps,\n getAriaValueText,\n getMinMax,\n interactive,\n onKeyDown,\n orientation,\n range,\n value,\n ],\n )\n\n return {\n percent,\n range,\n setValue,\n stepDown,\n stepUp,\n value,\n getInputProps,\n getMarkProps,\n getRangeProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n onChange,\n }\n}\n\nexport type UseSliderReturn = ReturnType<typeof useSlider>\n"],"mappings":";;;;;;;;;;;AA2GA,MAAa,aACX,QAA2B,CAAC,MACzB;CACH,MAAM,EACJ,OAAO,EACL,IACA,KACA,MACA,mBAAmB,gBACnB,kBAAkB,eAClB,gBAAgB,GAChB,eAAe,GACf,UACA,kBACA,MAAM,KACN,MAAM,GACN,cAAc,cACd,UACA,UACA,OAAO,GACP,OAAO,WACP,UAAU,cACV,aACA,eACA,GAAG,QAEL,WACA,WACA,eACEA,wBAAAA,cAAc,KAAK;CACvB,MAAM,CAAC,OAAO,YAAYC,2CAAAA,qBAAqB;EAC7C;EACA,OAAO;EACP,UAAU;CACZ,CAAC;CACD,MAAM,EAAE,MAAMC,sBAAAA,QAAQ,QAAQ;CAC9B,MAAM,gBAAA,GAAA,MAAA,OAAA,CAAsB,CAAC;CAC7B,MAAM,cAAc,EAAE,YAAY;CAClC,MAAM,CAAC,GAAG,oBAAoBC,kCAAAA,YAA4B;EACxD,QAAQ,GAAG,OAAO,SAAS;GACzB,IAAI,CAAC,aAAa;GAElB,MAAM,WAAW,YAAY,OAAO,IAAI;GAExC,IAAI,OAAO;IACT,MAAM,QAAQ,aAAa,YAAY;IAEvC,MAAM,gBAAgB,MADA,aAAa,YAAY,IAAI,IAAI;IAGvD,cACG,QAAQ,CAAC,UAAU,aAAa,IAAI,CAAC,eAAe,QAAQ,CAC/D;GACF,OACE,cAAc,QAAa;EAE/B;EACA,SAAS,GAAG,OAAO,SAAS;GAC1B,IAAI,CAAC,aAAa;GAElB,MAAM,WAAW,YAAY,OAAO,IAAI;GAExC,SAAS,aAAa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GAAA,oBAAA,cAAA,WAAA,CAAsB,KAAK,WAAW,UAAU,KAAK,CAAC;GACxD;GAEA,IAAI,OAAO;IACT,MAAM,eAAe,MAAM;IAE3B,MAAM,iBAAA,GAAA,oBAAA,cAAA,SAAA,CAAyB,UAAU,CAAC;IAC1C,MAAM,eAAA,GAAA,oBAAA,cAAA,SAAA,CAAuB,UAAU,CAAC;IACxC,MAAM,mBAAmB;IACzB,MAAM,oBACJ,iBACA,mBAAmB,cAAc,KAAK,KACtC,aAAa,SAAS;GAC1B,OAAO;IACL,MAAM,eAAA,GAAA,oBAAA,cAAA,SAAA,CAAuB,UAAU,CAAC;IACxC,MAAM,mBAAmB;IACzB,MAAM,oBACJ,iBAAiB,mBAAmB,OAAO,KAAK,KAAK,MAAM,SAAS;GACxE;GAEA,OAAO;EACT,GACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAcY;EACZ;EACA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-component.cjs","names":["Fragment","styled","getDisplayName","createContext","useSystem","getClassName","useComponentStyle","mergeProps","chainProps","getSlotClassName","useComponentSlotStyle","mergeSlotCSS"],"sources":["../../../../src/core/components/create-component.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, FunctionComponent } from \"react\"\nimport type { AnyString, Dict, Merge } from \"../../utils\"\nimport type { CSSObject, CSSSlotObject } from \"../css\"\nimport type {\n ComponentSlotStyle,\n ComponentStyle,\n StyledOptions,\n System,\n WithoutThemeProps,\n} from \"../system\"\nimport type {\n As,\n DOMElement,\n HTMLStyledProps,\n Component as OriginalComponent,\n} from \"./index.types\"\nimport { Fragment } from \"react\"\nimport {\n createContext,\n cx,\n isArray,\n isFunction,\n isObject,\n isString,\n runIfFn,\n toArray,\n toCamelCase,\n toPascalCase,\n} from \"../../utils\"\nimport { styled, useSystem } from \"../system\"\nimport { chainProps, mergeProps } from \"./props\"\nimport {\n getSlotClassName,\n mergeSlotCSS,\n useComponentSlotStyle,\n useComponentStyle,\n} from \"./use-component-style\"\nimport { getClassName, getDisplayName } from \"./utils\"\n\ntype AsWithFragment = \"fragment\" | As\ntype ClassName = ((system: System) => string) | string\n\ntype Component<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n> = Y extends \"fragment\"\n ? FunctionComponent<M>\n : OriginalComponent<Exclude<Y, \"fragment\">, M>\n\nexport type ComponentSlotName<\n Y extends ComponentSlotStyle | ComponentStyle = ComponentSlotStyle,\n> = AnyString | Extract<keyof NonNullable<Y[\"base\"]>, string>\n\nexport type ComponentSlot<Y extends string> =\n | [Y, Y]\n | Y\n | { name: string; slot: [Y, Y] | Y }\n\nexport type InitialProps<Y extends Dict = Dict> =\n | ((props: Y) => any)\n | Partial<Y>\nexport type SuperProps<Y extends Dict = Dict> = ((props: Y) => any) | Y\n\nexport type SuperWithoutThemeProps<\n Y extends Dict = Dict,\n M extends Dict = Dict,\n D extends keyof Y = keyof Y,\n> = ((props: WithoutThemeProps<Y, M, D>) => any) | WithoutThemeProps<Y, M, D>\n\nexport interface UseComponentPropsOptions<\n Y extends number | string | symbol = string,\n> {\n className?: ClassName\n withContext?: boolean\n transferProps?: Y[]\n}\n\nexport interface ComponentOptions extends Omit<StyledOptions, \"transferProps\"> {\n className?: ClassName\n shouldStyleProps?: boolean\n}\n\ninterface classNameOptions<Y extends string = string> {\n className?: ClassName\n slot?: ComponentSlot<Y>\n}\n\nexport interface ComponentWithContextOptions<\n Y extends number | string | symbol = string,\n>\n extends ComponentOptions, UseComponentPropsOptions<Y> {}\n\nfunction createProxyComponent<\n Y extends AsWithFragment = \"div\",\n M extends Dict = Dict,\n>(el: FC<M> | Y, { shouldStyleProps, ...options }: ComponentOptions = {}) {\n options.shouldForwardProp ??= isFunction(el)\n shouldStyleProps ??= !isFunction(el)\n\n if (el === \"fragment\") el = Fragment\n\n if (shouldStyleProps || isString(el)) {\n const ProxyComponent = styled(el as As, options)\n\n ProxyComponent.displayName = \"ProxyComponent\"\n\n return ProxyComponent\n } else {\n el.displayName ??= \"ProxyComponent\"\n\n return el as FC<M>\n }\n}\n\nfunction withDisplayName<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n>(Component: FC<M>, displayName: string) {\n Object.defineProperty(Component, \"name\", { value: displayName })\n Object.defineProperty(Component, \"displayName\", { value: displayName })\n\n return Component as Component<Y, M>\n}\n\nfunction getSlotKey<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"unknown\"\n\n if (isArray(slot) || !isObject(slot))\n return toCamelCase(toArray(slot).join(\"-\"))\n else return toCamelCase(slot.name)\n}\n\nfunction getSlotName<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"\"\n\n if (isArray(slot))\n return slot.map((value) => toPascalCase(value as string)).join(\"\")\n else if (isObject(slot)) return toPascalCase(slot.name)\n else return toPascalCase(slot as string)\n}\n\nexport function createComponent<\n Y extends object = {},\n M extends ComponentStyle = Dict,\n D extends Dict = Dict,\n>(name: string, style?: M) {\n const defaultClassName = style?.className\n const defaultDisplayName = getDisplayName(name)\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${defaultDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${defaultDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(name?: string, className?: ClassName) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getClassName(name, defaultClassName)(system)\n\n return className\n }\n\n function useComponentProps<H extends Y = Y, R extends keyof H = keyof H>(\n props: H,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= defaultClassName\n className ??= getClassName(name)(system)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as H)\n : props\n const [, rest] = useComponentStyle(mergedProps, {\n name,\n className,\n style,\n transferProps,\n })\n\n return rest\n }\n\n function component<D extends AsWithFragment = \"div\", H extends Dict = Y>(\n el: D | FC<H>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperProps<H>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps<any>(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withContext<\n D extends AsWithFragment = \"div\",\n H extends Y = Y,\n R extends keyof H = keyof H,\n >(\n el: D | FC<WithoutThemeProps<H, M, R>>,\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<R> = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperWithoutThemeProps<H, M, R>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useComponentProps(computedProps, {\n className,\n withContext,\n transferProps,\n })\n const rest = chainProps<any>(...toArray(superProps))()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n useComponentContext,\n usePropsContext,\n withContext,\n useComponentProps,\n }\n}\n\nexport function createSlotComponent<\n Y extends object = {},\n M extends ComponentSlotStyle = Dict,\n D extends Dict = Dict,\n>(rootName: string, style?: M) {\n const rootClassName = style?.className\n const rootDisplayName = getDisplayName(rootName)\n const classNameMap = new Map<string, classNameOptions>()\n const [StyleContext, useStyleContext] = createContext<\n CSSSlotObject<ComponentSlotName<M>>\n >({\n name: `${rootDisplayName}StyleContext`,\n })\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${rootDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${rootDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(\n slot?: ComponentSlot<ComponentSlotName<M>>,\n className?: ClassName,\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return className\n }\n\n function useClassNames() {\n const system = useSystem()\n const entries = classNameMap.entries().map(([key, { className, slot }]) => {\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return [key, className]\n })\n\n return Object.fromEntries(\n entries.filter(([_, className]) => className),\n ) as { [key: string]: string }\n }\n\n function useRootComponentProps<\n Y extends Dict = {},\n R extends keyof Y = keyof Y,\n >(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ): [\n CSSSlotObject,\n Merge<WithoutThemeProps<Y, M, R>, { css?: CSSObject | CSSObject[] }>,\n ] {\n className = useClassName(slot, className)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as Y)\n : props\n const [css, rest] = useComponentSlotStyle(mergedProps, {\n name: rootName,\n className,\n style,\n slot,\n transferProps,\n })\n\n return [css, rest]\n }\n\n function useSlotComponentProps<Y extends Dict = {}>(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { className }: Omit<UseComponentPropsOptions, \"transferProps\"> = {},\n ) {\n className = useClassName(slot, className)\n\n const style = useStyleContext()\n\n return {\n ...props,\n className: cx(className, props.className),\n css: mergeSlotCSS(slot, style, props.css),\n }\n }\n\n function component<H extends AsWithFragment = \"div\", R extends Dict = Dict>(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n className = useClassName(slot, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withProvider<\n H extends AsWithFragment = \"div\",\n R extends Y = Y,\n T extends keyof R = keyof R,\n >(\n el: FC<WithoutThemeProps<R, M, T>> | H,\n slot: ComponentSlot<ComponentSlotName<M>> = \"root\" as ComponentSlot<\n ComponentSlotName<M>\n >,\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<T> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperWithoutThemeProps<R, M, T>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const [context, mergedProps] = useRootComponentProps(\n computedProps,\n slot,\n {\n className,\n withContext,\n transferProps,\n },\n )\n const rest = chainProps<any>(...superProps)()(mergedProps)\n\n return (\n <StyleContext value={context}>\n <ProxyComponent {...rest} />\n </StyleContext>\n )\n }, displayName)\n }\n }\n\n function withContext<\n H extends AsWithFragment = \"div\",\n R extends Dict = H extends DOMElement ? HTMLStyledProps<H> : Dict,\n >(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n name,\n className,\n withContext,\n ...options\n }: Omit<ComponentWithContextOptions, \"transferProps\"> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useSlotComponentProps(computedProps, slot, {\n className,\n withContext,\n })\n const rest = chainProps(...superProps)()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n StyleContext,\n useClassNames,\n useComponentContext,\n usePropsContext,\n useStyleContext,\n withContext,\n withProvider,\n useRootComponentProps,\n useSlotComponentProps,\n }\n}\n"],"mappings":";;;;;;;;;;;AA8FA,SAAS,qBAGP,IAAe,EAAE,kBAAkB,GAAG,YAA8B,CAAC,GAAG;CACxE,QAAQ,uBAAA,GAAA,oBAAA,cAAA,WAAA,CAAiC,EAAE;CAC3C,qBAAqB,EAAA,GAAA,oBAAA,cAAA,WAAA,CAAY,EAAE;CAEnC,IAAI,OAAO,YAAY,KAAKA,MAAAA;CAE5B,IAAI,qBAAA,GAAA,oBAAA,cAAA,SAAA,CAA6B,EAAE,GAAG;EACpC,MAAM,iBAAiBC,gBAAAA,OAAO,IAAU,OAAO;EAE/C,eAAe,cAAc;EAE7B,OAAO;CACT,OAAO;EACL,GAAG,gBAAgB;EAEnB,OAAO;CACT;AACF;AAEA,SAAS,gBAGP,WAAkB,aAAqB;CACvC,OAAO,eAAe,WAAW,QAAQ,EAAE,OAAO,YAAY,CAAC;CAC/D,OAAO,eAAe,WAAW,eAAe,EAAE,OAAO,YAAY,CAA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A,eAAe,MAAM,GAAG,kBAD3B,YAAY,IACwC,GAAG;EAExE,aAAa,IAAI,SAAS;GAAE;GAAW;EAAK,CAAC;EAE7C,OAAO,SACL,cACA,GAAG,YACH;GACA,OAAO,iBAAuB,UAAU;IAItC,MAAM,cAAc,uBAAA,GAAA,oBAAA,cAAA,WAAA,CAHa,YAAY,IACzC,aAAa,KAAK,IAClBK,cAAAA,WAAW,gBAAgB,CAAC,GAAG,KAAK,CAAC,CAAC,GACe,MAAM;KAC7D;KACA;IACF,CAAC;IAGD,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAD,EAAgB,GAFVC,cAAAA,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,WAEX,EAAI,CAAA;GACpC,GAAG,WAAW;EAChB;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"create-component.cjs","names":["Fragment","styled","getDisplayName","createContext","useSystem","getClassName","useComponentStyle","mergeProps","chainProps","getSlotClassName","useComponentSlotStyle","mergeSlotCSS"],"sources":["../../../../src/core/components/create-component.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, FunctionComponent } from \"react\"\nimport type { AnyString, Dict, Merge } from \"../../utils\"\nimport type { CSSObject, CSSSlotObject } from \"../css\"\nimport type {\n ComponentSlotStyle,\n ComponentStyle,\n StyledOptions,\n System,\n WithoutThemeProps,\n} from \"../system\"\nimport type {\n As,\n DOMElement,\n HTMLStyledProps,\n Component as OriginalComponent,\n} from \"./index.types\"\nimport { Fragment } from \"react\"\nimport {\n createContext,\n cx,\n isArray,\n isFunction,\n isObject,\n isString,\n runIfFn,\n toArray,\n toCamelCase,\n toPascalCase,\n} from \"../../utils\"\nimport { styled, useSystem } from \"../system\"\nimport { chainProps, mergeProps } from \"./props\"\nimport {\n getSlotClassName,\n mergeSlotCSS,\n useComponentSlotStyle,\n useComponentStyle,\n} from \"./use-component-style\"\nimport { getClassName, getDisplayName } from \"./utils\"\n\ntype AsWithFragment = \"fragment\" | As\ntype ClassName = ((system: System) => string) | string\n\ntype Component<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n> = Y extends \"fragment\"\n ? FunctionComponent<M>\n : OriginalComponent<Exclude<Y, \"fragment\">, M>\n\nexport type ComponentSlotName<\n Y extends ComponentSlotStyle | ComponentStyle = ComponentSlotStyle,\n> = AnyString | Extract<keyof NonNullable<Y[\"base\"]>, string>\n\nexport type ComponentSlot<Y extends string> =\n | [Y, Y]\n | Y\n | { name: string; slot: [Y, Y] | Y }\n\nexport type InitialProps<Y extends Dict = Dict> =\n | ((props: Y) => any)\n | Partial<Y>\nexport type SuperProps<Y extends Dict = Dict> = ((props: Y) => any) | Y\n\nexport type SuperWithoutThemeProps<\n Y extends Dict = Dict,\n M extends Dict = Dict,\n D extends keyof Y = keyof Y,\n> = ((props: WithoutThemeProps<Y, M, D>) => any) | WithoutThemeProps<Y, M, D>\n\nexport interface UseComponentPropsOptions<\n Y extends number | string | symbol = string,\n> {\n className?: ClassName\n withContext?: boolean\n transferProps?: Y[]\n}\n\nexport interface ComponentOptions extends Omit<StyledOptions, \"transferProps\"> {\n className?: ClassName\n shouldStyleProps?: boolean\n}\n\ninterface classNameOptions<Y extends string = string> {\n className?: ClassName\n slot?: ComponentSlot<Y>\n}\n\nexport interface ComponentWithContextOptions<\n Y extends number | string | symbol = string,\n>\n extends ComponentOptions, UseComponentPropsOptions<Y> {}\n\nfunction createProxyComponent<\n Y extends AsWithFragment = \"div\",\n M extends Dict = Dict,\n>(el: FC<M> | Y, { shouldStyleProps, ...options }: ComponentOptions = {}) {\n options.shouldForwardProp ??= isFunction(el)\n shouldStyleProps ??= !isFunction(el)\n\n if (el === \"fragment\") el = Fragment\n\n if (shouldStyleProps || isString(el)) {\n const ProxyComponent = styled(el as As, options)\n\n ProxyComponent.displayName = \"ProxyComponent\"\n\n return ProxyComponent\n } else {\n el.displayName ??= \"ProxyComponent\"\n\n return el as FC<M>\n }\n}\n\nfunction withDisplayName<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n>(Component: FC<M>, displayName: string) {\n Object.defineProperty(Component, \"name\", { value: displayName })\n Object.defineProperty(Component, \"displayName\", { value: displayName })\n\n return Component as Component<Y, M>\n}\n\nfunction getSlotKey<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"unknown\"\n\n if (isArray(slot) || !isObject(slot))\n return toCamelCase(toArray(slot).join(\"-\"))\n else return toCamelCase(slot.name)\n}\n\nfunction getSlotName<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"\"\n\n if (isArray(slot))\n return slot.map((value) => toPascalCase(value as string)).join(\"\")\n else if (isObject(slot)) return toPascalCase(slot.name)\n else return toPascalCase(slot)\n}\n\nexport function createComponent<\n Y extends object = {},\n M extends ComponentStyle = Dict,\n D extends Dict = Dict,\n>(name: string, style?: M) {\n const defaultClassName = style?.className\n const defaultDisplayName = getDisplayName(name)\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${defaultDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${defaultDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(name?: string, className?: ClassName) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getClassName(name, defaultClassName)(system)\n\n return className\n }\n\n function useComponentProps<H extends Y = Y, R extends keyof H = keyof H>(\n props: H,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= defaultClassName\n className ??= getClassName(name)(system)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as H)\n : props\n const [, rest] = useComponentStyle(mergedProps, {\n name,\n className,\n style,\n transferProps,\n })\n\n return rest\n }\n\n function component<D extends AsWithFragment = \"div\", H extends Dict = Y>(\n el: D | FC<H>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperProps<H>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps<any>(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withContext<\n D extends AsWithFragment = \"div\",\n H extends Y = Y,\n R extends keyof H = keyof H,\n >(\n el: D | FC<WithoutThemeProps<H, M, R>>,\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<R> = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperWithoutThemeProps<H, M, R>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useComponentProps(computedProps, {\n className,\n withContext,\n transferProps,\n })\n const rest = chainProps<any>(...toArray(superProps))()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n useComponentContext,\n usePropsContext,\n withContext,\n useComponentProps,\n }\n}\n\nexport function createSlotComponent<\n Y extends object = {},\n M extends ComponentSlotStyle = Dict,\n D extends Dict = Dict,\n>(rootName: string, style?: M) {\n const rootClassName = style?.className\n const rootDisplayName = getDisplayName(rootName)\n const classNameMap = new Map<string, classNameOptions>()\n const [StyleContext, useStyleContext] = createContext<\n CSSSlotObject<ComponentSlotName<M>>\n >({\n name: `${rootDisplayName}StyleContext`,\n })\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${rootDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${rootDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(\n slot?: ComponentSlot<ComponentSlotName<M>>,\n className?: ClassName,\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return className\n }\n\n function useClassNames() {\n const system = useSystem()\n const entries = classNameMap.entries().map(([key, { className, slot }]) => {\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return [key, className]\n })\n\n return Object.fromEntries(\n entries.filter(([_, className]) => className),\n ) as { [key: string]: string }\n }\n\n function useRootComponentProps<\n Y extends Dict = {},\n R extends keyof Y = keyof Y,\n >(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ): [\n CSSSlotObject,\n Merge<WithoutThemeProps<Y, M, R>, { css?: CSSObject | CSSObject[] }>,\n ] {\n className = useClassName(slot, className)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as Y)\n : props\n const [css, rest] = useComponentSlotStyle(mergedProps, {\n name: rootName,\n className,\n style,\n slot,\n transferProps,\n })\n\n return [css, rest]\n }\n\n function useSlotComponentProps<Y extends Dict = {}>(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { className }: Omit<UseComponentPropsOptions, \"transferProps\"> = {},\n ) {\n className = useClassName(slot, className)\n\n const style = useStyleContext()\n\n return {\n ...props,\n className: cx(className, props.className),\n css: mergeSlotCSS(slot, style, props.css),\n }\n }\n\n function component<H extends AsWithFragment = \"div\", R extends Dict = Dict>(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n className = useClassName(slot, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withProvider<\n H extends AsWithFragment = \"div\",\n R extends Y = Y,\n T extends keyof R = keyof R,\n >(\n el: FC<WithoutThemeProps<R, M, T>> | H,\n slot: ComponentSlot<ComponentSlotName<M>> = \"root\",\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<T> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperWithoutThemeProps<R, M, T>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const [context, mergedProps] = useRootComponentProps(\n computedProps,\n slot,\n {\n className,\n withContext,\n transferProps,\n },\n )\n const rest = chainProps<any>(...superProps)()(mergedProps)\n\n return (\n <StyleContext value={context}>\n <ProxyComponent {...rest} />\n </StyleContext>\n )\n }, displayName)\n }\n }\n\n function withContext<\n H extends AsWithFragment = \"div\",\n R extends Dict = H extends DOMElement ? HTMLStyledProps<H> : Dict,\n >(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n name,\n className,\n withContext,\n ...options\n }: Omit<ComponentWithContextOptions, \"transferProps\"> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useSlotComponentProps(computedProps, slot, {\n className,\n withContext,\n })\n const rest = chainProps(...superProps)()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n StyleContext,\n useClassNames,\n useComponentContext,\n usePropsContext,\n useStyleContext,\n withContext,\n withProvider,\n useRootComponentProps,\n useSlotComponentProps,\n }\n}\n"],"mappings":";;;;;;;;;;;AA8FA,SAAS,qBAGP,IAAe,EAAE,kBAAkB,GAAG,YAA8B,CAAC,GAAG;CACxE,QAAQ,uBAAA,GAAA,oBAAA,cAAA,WAAA,CAAiC,EAAE;CAC3C,qBAAqB,EAAA,GAAA,oBAAA,cAAA,WAAA,CAAY,EAAE;CAEnC,IAAI,OAAO,YAAY,KAAKA,MAAAA;CAE5B,IAAI,qBAAA,GAAA,oBAAA,cAAA,SAAA,CAA6B,EAAE,GAAG;EACpC,MAAM,iBAAiBC,gBAAAA,OAAO,IAAU,OAAO;EAE/C,eAAe,cAAc;EAE7B,OAAO;CACT,OAAO;EACL,GAAG,gBAAgB;EAEnB,OAAO;CACT;AACF;AAEA,SAAS,gBAGP,WAAkB,aAAqB;CACvC,OAAO,eAAe,WAAW,QAAQ,EAAE,OAAO,YAAY,CAAC;CAC/D,OAAO,eAAe,WAAW,eAAe,EAAE,OAAO,YAAY,CAAC;CAEtE,OAAO;AACT;AAEA,SAAS,WAA6B,MAAyB;CAC7D,IAAI,CAAC,MAAM,OAAO;CAElB,KA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AK,CAAC;EAE7C,OAAO,SACL,cACA,GAAG,YACH;GACA,OAAO,iBAAuB,UAAU;IAItC,MAAM,cAAc,uBAAA,GAAA,oBAAA,cAAA,WAAA,CAHa,YAAY,IACzC,aAAa,KAAK,IAClBK,cAAAA,WAAW,gBAAgB,CAAC,GAAG,KAAK,CAAC,CAAC,GACe,MAAM;KAC7D;KACA;IACF,CAAC;IAGD,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAD,EAAgB,GAFVC,cAAAA,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,WAEX,EAAI,CAAA;GACpC,GAAG,WAAW;EAChB;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-component-style.cjs","names":["conditions","getCondition","useSystem","useColorSchemeContext","isEqualProps","mergeCSS"],"sources":["../../../../src/core/components/use-component-style.ts"],"sourcesContent":["\"use client\"\n\nimport type { Dict } from \"../../utils\"\nimport type {\n ColorModeArray,\n CSSModifierObject,\n CSSObject,\n CSSPropObject,\n CSSSlotObject,\n ResponsiveWithConditionObject,\n StyleValueWithCondition,\n} from \"../css\"\nimport type {\n Breakpoints,\n ComponentCompound,\n ComponentSlotStyle,\n ComponentStyle,\n Layers,\n LayerScheme,\n ThemeProps,\n WithoutThemeProps,\n} from \"../system\"\nimport type { ComponentSlot, ComponentSlotName } from \"./create-component\"\nimport type { HTMLStyledProps } from \"./index.types\"\nimport { useRef } from \"react\"\nimport {\n bem,\n cx,\n filterEmpty,\n isArray,\n isBooleanish,\n isEmptyObject,\n isObject,\n isRegExp,\n isUndefined,\n merge,\n omitObject,\n toArray,\n toKebabCase,\n} from \"../../utils\"\nimport { conditions, getCondition, mergeCSS } from \"../css\"\nimport { useColorSchemeContext, useSystem } from \"../system\"\nimport { isEqualProps } from \"./props\"\n\ntype Style<Y extends boolean = false> = Y extends false\n ? CSSObject\n : CSSSlotObject\n\ntype MergedStyle = CSSModifierObject | CSSModifierObject<CSSSlotObject>\n\ninterface GetStyleOptions\n extends Partial<Breakpoints>, Pick<Partial<Layers>, \"wrap\"> {\n hasSlot?: boolean\n modifier?: string\n name?: string\n selectors?: (string | undefined)[]\n value?: string\n}\n\nfunction getSelectorStyle<Y extends Dict = Dict>(\n selectors: (string | undefined)[],\n style: Y,\n) {\n return selectors.reduceRight<Dict>(\n (prev, key) => (key ? { [key]: prev } : prev),\n style,\n ) as Y\n}\n\nfunction getStyle<Y extends boolean = false>(\n style: CSSObject | CSSSlotObject | undefined,\n) {\n return function ({\n name: rootName,\n hasSlot = false,\n modifier,\n selectors = [],\n value,\n }: GetStyleOptions): Style<Y> | undefined {\n if (!style || isEmptyObject(style)) return\n\n if (hasSlot) {\n return Object.fromEntries(\n Object.entries(style as CSSSlotObject).map(([name, style]) => {\n if (selectors.length) {\n if (value && modifier)\n style = {\n [`--${rootName}-${name}-${modifier}`]: `\"${value}\"`,\n ...style,\n } as CSSObject\n\n return [name, getSelectorStyle(selectors, style ?? {})]\n } else {\n if (value && modifier)\n style = {\n [`--${rootName}-${name}-${modifier}`]: `\"${value}\"`,\n ...style,\n } as CSSObject\n\n return [name, style]\n }\n }),\n ) as Style<Y>\n } else if (selectors.length) {\n if (value && modifier)\n style = {\n [`--${rootName}-${modifier}`]: `\"${value}\"`,\n ...style,\n } as CSSObject\n\n return getSelectorStyle(selectors, style) as Style<Y>\n } else {\n if (value && modifier)\n style = {\n [`--${rootName}-${modifier}`]: `\"${value}\"`,\n ...style,\n } as CSSObject\n\n return style as Style<Y>\n }\n }\n}\n\nfunction getColorModeStyle<Y extends boolean = false>(\n value: ColorModeArray<string>,\n mergedStyle: MergedStyle,\n) {\n return function ({ selectors = [], ...rest }: GetStyleOptions) {\n const [lightValue, darkValue] = value\n\n const lightStyle = getModifierStyle<Y>(\n lightValue,\n mergedStyle,\n )({ ...rest, selectors })\n\n const darkStyle = getModifierStyle<Y>(\n darkValue,\n mergedStyle,\n )({ ...rest, selectors: [...selectors, conditions._dark] })\n\n return merge(lightStyle, darkStyle)\n }\n}\n\nfunction getConditionStyle<Y extends boolean = false>(\n value: ResponsiveWithConditionObject<string>,\n mergedStyle: MergedStyle,\n) {\n return function (options: GetStyleOptions) {\n const { isResponsiveKey, queries = [], selectors = [] } = options\n const conditionalKeys = Object.keys(value).filter(\n (key) => !isResponsiveKey?.(key),\n )\n\n const breakpointObj = queries.reduce<Style<Y>>(\n (prev, { breakpoint, query }) => {\n if (!isUndefined(value[breakpoint]))\n prev = merge(\n prev,\n getModifierStyle<Y>(\n value[breakpoint],\n mergedStyle,\n )({ ...options, selectors: [...selectors, query] }),\n )\n\n return prev\n },\n {},\n )\n\n const additionalObj = conditionalKeys.reduce<Style<Y>>((prev, key) => {\n prev = merge(\n prev,\n getModifierStyle<Y>(\n value[key as keyof typeof value],\n mergedStyle,\n )({ ...options, selectors: [...selectors, getCondition(key)] }),\n )\n\n return prev\n }, {})\n\n return merge(breakpointObj, additionalObj)\n }\n}\n\nfunction getModifierStyle<Y extends boolean = false>(\n value: StyleValueWithCondition<string> | undefined,\n mergedStyle: MergedStyle,\n) {\n return function (options: GetStyleOptions): Style<Y> | undefined {\n let style: Style<Y> | undefined = undefined\n\n if (!value) return style\n\n if (isArray(value))\n style = getColorModeStyle<Y>(value, mergedStyle)(options)\n else if (isObject(value))\n style = getConditionStyle<Y>(value, mergedStyle)(options)\n else style = getStyle<Y>(mergedStyle[value])({ ...options, value })\n\n return style\n }\n}\n\nfunction getPropStyle<Y extends boolean = false>(\n props: Dict,\n propVariants: CSSPropObject | CSSPropObject<CSSSlotObject>,\n style: Style<Y> | undefined = {},\n) {\n const variants = Object.entries(propVariants)\n\n return function (options: GetStyleOptions) {\n if (!variants.length) return style\n\n variants.forEach(([modifier, variants]) => {\n const value = props[modifier as keyof typeof props]\n\n if (value) {\n const propStyle = getModifierStyle<Y>(\n value,\n variants,\n )({ modifier, value, ...options })\n\n if (propStyle)\n style = merge(style, wrapStyle<Y>(\"props\", propStyle)(options))\n } else {\n const boolean = Object.keys(variants).every((key) => isBooleanish(key))\n\n if (boolean) {\n const propStyle = getModifierStyle<Y>(\n \"false\",\n variants,\n )({ modifier, value: \"true\", ...options })\n\n if (propStyle)\n style = merge(style, wrapStyle<Y>(\"props\", propStyle)(options))\n }\n }\n })\n\n return style\n }\n}\n\nfunction getCompoundStyle<Y extends boolean = false>(\n props: Dict,\n compounds: ComponentCompound<CSSSlotObject>[] | ComponentCompound[],\n style: Style<Y> | undefined = {},\n) {\n return function (options: GetStyleOptions) {\n if (!compounds.length) return style\n\n compounds.forEach(({ css, layer, ...rest }) => {\n const conditions = Object.entries(rest)\n\n if (!conditions.length) return\n\n const apply = conditions.every(([key, value]) =>\n isArray(value)\n ? value.includes(props[key])\n : isRegExp(value)\n ? value.test(props[key])\n : props[key] === value,\n )\n\n if (!apply) return\n\n style = merge(\n style,\n wrapStyle<Y>(layer ?? \"compounds\", css as Style<Y>)(options),\n )\n })\n\n return style\n }\n}\n\nexport function getSlotClassName<Y extends string>(\n className?: string,\n slot?: ComponentSlot<Y>,\n) {\n if (!className || !slot) return className\n\n if (isArray(slot)) {\n const [element, modifier] = slot.map((value) =>\n toKebabCase(value as string),\n )\n\n return cx(bem(className, element), bem(className, element, modifier))\n } else if (isObject(slot)) {\n const slotArray = toArray(slot.slot)\n const [element, modifier] = slotArray.map((value) =>\n toKebabCase(value as string),\n )\n\n return cx(bem(className, element), bem(className, element, modifier))\n } else {\n return bem(className, toKebabCase(slot as string))\n }\n}\n\nexport function mergeSlotCSS<Y extends string>(\n slot?: ComponentSlot<Y>,\n style?: CSSSlotObject<Y>,\n css?: CSSObject | CSSObject[],\n): CSSObject | CSSObject[] | undefined {\n if (!style || !slot) return css\n\n const temp: (CSSObject | undefined)[] = []\n\n if (isArray(slot)) temp.push(...slot.map((slot) => style[slot]))\n else if (isObject(slot))\n if (isArray(slot.slot)) temp.push(...slot.slot.map((slot) => style[slot]))\n else temp.push(style[slot.slot])\n else temp.push(style[slot])\n\n if (css) temp.push(...toArray(css))\n\n const result = filterEmpty(temp)\n\n return result.length ? result : undefined\n}\n\nfunction omitThemeProps<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n>(props: Y, omitKeys: string[] = [], transferProps?: D[]) {\n if (transferProps)\n omitKeys = omitKeys.filter((key) => !transferProps.includes(key as D))\n\n return omitObject(props, omitKeys) as unknown as WithoutThemeProps<Y, M, D>\n}\n\nfunction wrapStyle<Y extends boolean = false>(\n layer: LayerScheme,\n style?: Style<Y>,\n) {\n return function ({ hasSlot, wrap }: GetStyleOptions) {\n if (hasSlot) {\n if (!style) return undefined\n\n return Object.fromEntries(\n Object.entries(style).map(([slot, style]) => [\n slot,\n wrap?.(layer, style) ?? style,\n ]),\n )\n } else {\n return wrap?.(layer, style) ?? style\n }\n }\n}\n\nfunction getHasAtRuleStyle(css?: CSSObject | CSSObject[]) {\n return (getAtRule?: Layers[\"getAtRule\"]) => {\n let hasVariant = false\n let hasSize = false\n\n if (!css || !getAtRule) return { hasSize, hasVariant }\n\n const variantAtRule = getAtRule(\"variant\")\n const sizeAtRule = getAtRule(\"size\")\n\n css = toArray(css)\n\n css.forEach((css) => {\n const keys = Object.keys(css)\n\n if (keys.includes(variantAtRule)) hasVariant = true\n if (keys.includes(sizeAtRule)) hasSize = true\n })\n\n return { hasSize, hasVariant }\n }\n}\n\nfunction mergeDefaultProps<\n Y extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n M extends Dict = Dict,\n>(defaultProps: Y[\"defaultProps\"], props: M) {\n return Object.entries(defaultProps ?? {}).reduce<Dict>(\n (prev, [key, value]) => {\n prev[key] ??= value\n\n return prev\n },\n props,\n ) as M\n}\n\ninterface UseStyleOptions<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n H extends boolean = false,\n> {\n className?: string\n hasSlot?: H\n name?: string\n slot?: ComponentSlot<ComponentSlotName<M>>\n style?: M\n transferProps?: D[]\n}\n\nfunction useStyle<\n Y extends HTMLStyledProps & ThemeProps<{}> = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n H extends boolean = false,\n>(\n props: Y,\n {\n name,\n className: defaultClassName,\n style: componentStyle,\n hasSlot,\n slot,\n transferProps,\n }: UseStyleOptions<Y, M, D, H> = {},\n): [Style<H>, WithoutThemeProps<Y, M, D>] {\n const system = useSystem()\n const { getAtRule, wrap } = system.layers\n const rootColorScheme = useColorSchemeContext()\n const options = { ...system.breakpoints, name, hasSlot, wrap }\n\n const propsRef = useRef<Dict>({})\n const mergedPropsRef = useRef<Dict>({})\n const styleRef = useRef<Style<H> | undefined>(undefined)\n\n const hasComponentStyle =\n componentStyle && !!Object.keys(componentStyle).length\n\n if (hasComponentStyle) {\n const {\n className: customClassName,\n base,\n compounds,\n props: propVariants,\n sizes,\n variants,\n defaultProps: { colorScheme: defaultColorScheme, ...defaultProps } = {},\n } = componentStyle\n\n const colorScheme =\n props.colorScheme ?? rootColorScheme ?? defaultColorScheme\n\n const className = cx(defaultClassName ?? customClassName, props.className)\n const mergedProps = {\n ...mergeDefaultProps(defaultProps, props),\n className,\n colorScheme,\n }\n const omitProps = Object.keys(propVariants ?? {})\n const { size, variant } = mergedProps\n\n if (variants) omitProps.push(\"variant\")\n if (sizes) omitProps.push(\"size\")\n\n const computedProps = omitThemeProps(\n mergedProps,\n omitProps,\n transferProps,\n ) as Y\n\n if (\n !isEqualProps(mergedPropsRef.current, mergedProps, [\"css\", \"children\"])\n ) {\n const { hasSize, hasVariant } = getHasAtRuleStyle(props.css)(getAtRule)\n\n let style: Style<H> = {}\n\n if (base) {\n const baseStyle = getStyle<H>(base)(options)\n\n style = merge(style, wrapStyle<H>(\"base\", baseStyle)(options))\n }\n\n if (sizes && !hasSize) {\n const sizeStyle = merge(\n sizes.base,\n getModifierStyle<H>(size, sizes)({ modifier: \"size\", ...options }),\n )\n\n style = merge(style, wrapStyle<H>(\"size\", sizeStyle)(options))\n }\n\n if (variants && !hasVariant) {\n const variantStyle = merge(\n variants.base,\n getModifierStyle<H>(\n variant,\n variants,\n )({ modifier: \"variant\", ...options }),\n )\n\n style = merge(style, wrapStyle<H>(\"variant\", variantStyle)(options))\n }\n\n if (propVariants)\n style = getPropStyle<H>(mergedProps, propVariants, style)(options)\n\n if (compounds)\n style = getCompoundStyle<H>(mergedProps, compounds, style)(options)\n\n styleRef.current = style\n\n if (hasSlot)\n computedProps.css = mergeSlotCSS<ComponentSlotName<M>>(\n slot,\n style as CSSSlotObject,\n computedProps.css,\n )\n else computedProps.css = mergeCSS(style as CSSObject, computedProps.css)\n } else {\n computedProps.css = propsRef.current.css\n }\n\n mergedPropsRef.current = mergedProps\n\n if (!isEqualProps(propsRef.current, computedProps))\n propsRef.current = computedProps\n } else {\n const className = cx(defaultClassName, props.className)\n\n if (className) props.className = className\n\n if (!isEqualProps(propsRef.current, props))\n propsRef.current = props as unknown as WithoutThemeProps<Y, M, D>\n }\n\n return [\n styleRef.current ?? {},\n propsRef.current as WithoutThemeProps<Y, M, D>,\n ]\n}\n\nexport interface UseComponentStyleOptions<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n> extends Omit<UseStyleOptions<Y, M, D>, \"hasSlot\" | \"slot\"> {}\n\nexport function useComponentStyle<\n Y extends Dict = Dict,\n M extends ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n>(props: Y, options: UseComponentStyleOptions<Y, M, D> = {}) {\n return useStyle<Y, M, D>(props, options)\n}\n\nexport interface UseComponentSlotStyleOptions<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n> extends Omit<UseStyleOptions<Y, M, D, true>, \"hasSlot\"> {}\n\nexport function useComponentSlotStyle<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle = ComponentSlotStyle,\n D extends keyof Y = keyof Y,\n>(props: Y, options: UseComponentSlotStyleOptions<Y, M, D> = {}) {\n return useStyle<Y, M, D, true>(props, { ...options, hasSlot: true })\n}\n"],"mappings":";;;;;;;;;AA2DA,SAAS,iBACP,WACA,OACA;CACA,OAAO,UAAU,aACd,MAAM,QAAS,MAAM,GAAG,MAAM,KAAK,IAAI,MACxC,KACF;AACF;AAEA,SAAS,SACP,OACA;CACA,OAAO,SAAU,EACf,MAAM,UACN,UAAU,OACV,UACA,YAAY,CAAC,GACb,SACwC;EACxC,IAAI,CAAC,UAAA,GAAA,oBAAA,cAAA,cAAA,CAAuB,KAAK,GAAG;EAEpC,IAAI,SACF,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAsB,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW;GAC5D,IAAI,UAAU,QAAQ;IACpB,IAAI,SAAS,UACX,QAAQ;MACL,KAAK,SAAS,GAAG,KAAK,GAAG,aAAa,IAAI,MAAM;KACjD,GAAG;IACL;IAEF,OAAO,CAAC,MAAM,iBAAiB,WAAW,SAAS,CAAC,CAAC,CAAC;GACxD,OAAO;IACL,IAAI,SAAS,UACX,QAAQ;MACL,KAAK,SAAS,GAAG,KAAK,GAAG,aAAa,IAAI,MAAM;KACjD,GAAG;IACL;IAEF,OAAO,CAAC,MAAM,KAAK;GACrB;EACF,CAAC,CACH;OACK,IAAI,UAAU,QAAQ;GAC3B,IAAI,SAAS,UACX,QAAQ;KACL,KAAK,SAAS,GAAG,aAAa,IAAI,MAAM;IACzC,GAAG;GACL;GAEF,OAAO,iBAAiB,WAAW,KAAK;EAC1C,OAAO;GACL,IAAI,SAAS,UACX,QAAQ;KACL,KAAK,SAAS,GAAG,aAAa,IAAI,MAAM;IACzC,GAAG;GACL;GAEF,OAAO;EACT;CACF;AACF;AAEA,SAAS,kBACP,OACA,aACA;CACA,OAAO,SAAU,EAAE,YAAY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AC,OAAO;GAEpE,SAAS,UAAU;GAEnB,IAAI,SACF,cAAc,MAAM,aAClB,MACA,OACA,cAAc,GAChB;QACG,cAAc,MAAMC,kBAAAA,SAAS,OAAoB,cAAc,GAAG;EACzE,OACE,cAAc,MAAM,SAAS,QAAQ;EAGvC,eAAe,UAAU;EAEzB,IAAI,CAACD,cAAAA,aAAa,SAAS,SAAS,aAAa,GAC/C,SAAS,UAAU;CACvB,OAAO;EACL,MAAM,aAAA,GAAA,oBAAA,cAAA,GAAA,CAAe,kBAAkB,MAAM,SAAS;EAEtD,IAAI,WAAW,MAAM,YAAY;EAEjC,IAAI,CAACA,cAAAA,aAAa,SAAS,SAAS,KAAK,GACvC,SAAS,UAAU;CACvB;CAEA,OAAO,CACL,SAAS,WAAW,CAAC,GACrB,SAAS,OACX;AACF;AAQA,SAAgB,kBAId,OAAU,UAA6C,CAAC,GAAG;CAC3D,OAAO,SAAkB,OAAO,OAAO;AACzC;AAQA,SAAgB,sBAId,OAAU,UAAiD,CAAC,GAAG;CAC/D,OAAO,SAAwB,OAAO;EAAE,GAAG;EAAS,SAAS;CAAK,CAAC;AACrE"}
|
|
1
|
+
{"version":3,"file":"use-component-style.cjs","names":["conditions","getCondition","useSystem","useColorSchemeContext","isEqualProps","mergeCSS"],"sources":["../../../../src/core/components/use-component-style.ts"],"sourcesContent":["\"use client\"\n\nimport type { Dict } from \"../../utils\"\nimport type {\n ColorModeArray,\n CSSModifierObject,\n CSSObject,\n CSSPropObject,\n CSSSlotObject,\n ResponsiveWithConditionObject,\n StyleValueWithCondition,\n} from \"../css\"\nimport type {\n Breakpoints,\n ComponentCompound,\n ComponentSlotStyle,\n ComponentStyle,\n Layers,\n LayerScheme,\n ThemeProps,\n WithoutThemeProps,\n} from \"../system\"\nimport type { ComponentSlot, ComponentSlotName } from \"./create-component\"\nimport type { HTMLStyledProps } from \"./index.types\"\nimport { useRef } from \"react\"\nimport {\n bem,\n cx,\n filterEmpty,\n isArray,\n isBooleanish,\n isEmptyObject,\n isObject,\n isRegExp,\n isUndefined,\n merge,\n omitObject,\n toArray,\n toKebabCase,\n} from \"../../utils\"\nimport { conditions, getCondition, mergeCSS } from \"../css\"\nimport { useColorSchemeContext, useSystem } from \"../system\"\nimport { isEqualProps } from \"./props\"\n\ntype Style<Y extends boolean = false> = Y extends false\n ? CSSObject\n : CSSSlotObject\n\ntype MergedStyle = CSSModifierObject | CSSModifierObject<CSSSlotObject>\n\ninterface GetStyleOptions\n extends Partial<Breakpoints>, Pick<Partial<Layers>, \"wrap\"> {\n hasSlot?: boolean\n modifier?: string\n name?: string\n selectors?: (string | undefined)[]\n value?: string\n}\n\nfunction getSelectorStyle<Y extends Dict = Dict>(\n selectors: (string | undefined)[],\n style: Y,\n) {\n return selectors.reduceRight<Dict>(\n (prev, key) => (key ? { [key]: prev } : prev),\n style,\n ) as Y\n}\n\nfunction getStyle<Y extends boolean = false>(\n style: CSSObject | CSSSlotObject | undefined,\n) {\n return function ({\n name: rootName,\n hasSlot = false,\n modifier,\n selectors = [],\n value,\n }: GetStyleOptions): Style<Y> | undefined {\n if (!style || isEmptyObject(style)) return\n\n if (hasSlot) {\n return Object.fromEntries(\n Object.entries(style as CSSSlotObject).map(([name, style]) => {\n if (selectors.length) {\n if (value && modifier)\n style = {\n [`--${rootName}-${name}-${modifier}`]: `\"${value}\"`,\n ...style,\n }\n\n return [name, getSelectorStyle(selectors, style ?? {})]\n } else {\n if (value && modifier)\n style = {\n [`--${rootName}-${name}-${modifier}`]: `\"${value}\"`,\n ...style,\n }\n\n return [name, style]\n }\n }),\n ) as Style<Y>\n } else if (selectors.length) {\n if (value && modifier)\n style = {\n [`--${rootName}-${modifier}`]: `\"${value}\"`,\n ...style,\n } as CSSObject\n\n return getSelectorStyle(selectors, style) as Style<Y>\n } else {\n if (value && modifier)\n style = {\n [`--${rootName}-${modifier}`]: `\"${value}\"`,\n ...style,\n } as CSSObject\n\n return style as Style<Y>\n }\n }\n}\n\nfunction getColorModeStyle<Y extends boolean = false>(\n value: ColorModeArray<string>,\n mergedStyle: MergedStyle,\n) {\n return function ({ selectors = [], ...rest }: GetStyleOptions) {\n const [lightValue, darkValue] = value\n\n const lightStyle = getModifierStyle<Y>(\n lightValue,\n mergedStyle,\n )({ ...rest, selectors })\n\n const darkStyle = getModifierStyle<Y>(\n darkValue,\n mergedStyle,\n )({ ...rest, selectors: [...selectors, conditions._dark] })\n\n return merge(lightStyle, darkStyle)\n }\n}\n\nfunction getConditionStyle<Y extends boolean = false>(\n value: ResponsiveWithConditionObject<string>,\n mergedStyle: MergedStyle,\n) {\n return function (options: GetStyleOptions) {\n const { isResponsiveKey, queries = [], selectors = [] } = options\n const conditionalKeys = Object.keys(value).filter(\n (key) => !isResponsiveKey?.(key),\n )\n\n const breakpointObj = queries.reduce<Style<Y>>(\n (prev, { breakpoint, query }) => {\n if (!isUndefined(value[breakpoint]))\n prev = merge(\n prev,\n getModifierStyle<Y>(\n value[breakpoint],\n mergedStyle,\n )({ ...options, selectors: [...selectors, query] }),\n )\n\n return prev\n },\n {},\n )\n\n const additionalObj = conditionalKeys.reduce<Style<Y>>((prev, key) => {\n prev = merge(\n prev,\n getModifierStyle<Y>(\n value[key as keyof typeof value],\n mergedStyle,\n )({ ...options, selectors: [...selectors, getCondition(key)] }),\n )\n\n return prev\n }, {})\n\n return merge(breakpointObj, additionalObj)\n }\n}\n\nfunction getModifierStyle<Y extends boolean = false>(\n value: StyleValueWithCondition<string> | undefined,\n mergedStyle: MergedStyle,\n) {\n return function (options: GetStyleOptions): Style<Y> | undefined {\n let style: Style<Y> | undefined = undefined\n\n if (!value) return style\n\n if (isArray(value))\n style = getColorModeStyle<Y>(value, mergedStyle)(options)\n else if (isObject(value))\n style = getConditionStyle<Y>(value, mergedStyle)(options)\n else style = getStyle<Y>(mergedStyle[value])({ ...options, value })\n\n return style\n }\n}\n\nfunction getPropStyle<Y extends boolean = false>(\n props: Dict,\n propVariants: CSSPropObject | CSSPropObject<CSSSlotObject>,\n style: Style<Y> | undefined = {},\n) {\n const variants = Object.entries(propVariants)\n\n return function (options: GetStyleOptions) {\n if (!variants.length) return style\n\n variants.forEach(([modifier, variants]) => {\n const value = props[modifier as keyof typeof props]\n\n if (value) {\n const propStyle = getModifierStyle<Y>(\n value,\n variants,\n )({ modifier, value, ...options })\n\n if (propStyle)\n style = merge(style, wrapStyle<Y>(\"props\", propStyle)(options))\n } else {\n const boolean = Object.keys(variants).every((key) => isBooleanish(key))\n\n if (boolean) {\n const propStyle = getModifierStyle<Y>(\n \"false\",\n variants,\n )({ modifier, value: \"true\", ...options })\n\n if (propStyle)\n style = merge(style, wrapStyle<Y>(\"props\", propStyle)(options))\n }\n }\n })\n\n return style\n }\n}\n\nfunction getCompoundStyle<Y extends boolean = false>(\n props: Dict,\n compounds: ComponentCompound<CSSSlotObject>[] | ComponentCompound[],\n style: Style<Y> | undefined = {},\n) {\n return function (options: GetStyleOptions) {\n if (!compounds.length) return style\n\n compounds.forEach(({ css, layer, ...rest }) => {\n const conditions = Object.entries(rest)\n\n if (!conditions.length) return\n\n const apply = conditions.every(([key, value]) =>\n isArray(value)\n ? value.includes(props[key])\n : isRegExp(value)\n ? value.test(props[key])\n : props[key] === value,\n )\n\n if (!apply) return\n\n style = merge(\n style,\n wrapStyle<Y>(layer ?? \"compounds\", css as Style<Y>)(options),\n )\n })\n\n return style\n }\n}\n\nexport function getSlotClassName<Y extends string>(\n className?: string,\n slot?: ComponentSlot<Y>,\n) {\n if (!className || !slot) return className\n\n if (isArray(slot)) {\n const [element, modifier] = slot.map((value) =>\n toKebabCase(value as string),\n )\n\n return cx(bem(className, element), bem(className, element, modifier))\n } else if (isObject(slot)) {\n const slotArray = toArray(slot.slot)\n const [element, modifier] = slotArray.map((value) => toKebabCase(value))\n\n return cx(bem(className, element), bem(className, element, modifier))\n } else {\n return bem(className, toKebabCase(slot))\n }\n}\n\nexport function mergeSlotCSS<Y extends string>(\n slot?: ComponentSlot<Y>,\n style?: CSSSlotObject<Y>,\n css?: CSSObject | CSSObject[],\n): CSSObject | CSSObject[] | undefined {\n if (!style || !slot) return css\n\n const temp: (CSSObject | undefined)[] = []\n\n if (isArray(slot)) temp.push(...slot.map((slot) => style[slot]))\n else if (isObject(slot))\n if (isArray(slot.slot)) temp.push(...slot.slot.map((slot) => style[slot]))\n else temp.push(style[slot.slot])\n else temp.push(style[slot])\n\n if (css) temp.push(...toArray(css))\n\n const result = filterEmpty(temp)\n\n return result.length ? result : undefined\n}\n\nfunction omitThemeProps<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n>(props: Y, omitKeys: string[] = [], transferProps?: D[]) {\n if (transferProps)\n omitKeys = omitKeys.filter((key) => !transferProps.includes(key as D))\n\n return omitObject(props, omitKeys) as unknown as WithoutThemeProps<Y, M, D>\n}\n\nfunction wrapStyle<Y extends boolean = false>(\n layer: LayerScheme,\n style?: Style<Y>,\n) {\n return function ({ hasSlot, wrap }: GetStyleOptions) {\n if (hasSlot) {\n if (!style) return undefined\n\n return Object.fromEntries(\n Object.entries(style).map(([slot, style]) => [\n slot,\n wrap?.(layer, style) ?? style,\n ]),\n )\n } else {\n return wrap?.(layer, style) ?? style\n }\n }\n}\n\nfunction getHasAtRuleStyle(css?: CSSObject | CSSObject[]) {\n return (getAtRule?: Layers[\"getAtRule\"]) => {\n let hasVariant = false\n let hasSize = false\n\n if (!css || !getAtRule) return { hasSize, hasVariant }\n\n const variantAtRule = getAtRule(\"variant\")\n const sizeAtRule = getAtRule(\"size\")\n\n css = toArray(css)\n\n css.forEach((css) => {\n const keys = Object.keys(css)\n\n if (keys.includes(variantAtRule)) hasVariant = true\n if (keys.includes(sizeAtRule)) hasSize = true\n })\n\n return { hasSize, hasVariant }\n }\n}\n\nfunction mergeDefaultProps<\n Y extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n M extends Dict = Dict,\n>(defaultProps: Y[\"defaultProps\"], props: M) {\n return Object.entries(defaultProps ?? {}).reduce<Dict>(\n (prev, [key, value]) => {\n prev[key] ??= value\n\n return prev\n },\n props,\n ) as M\n}\n\ninterface UseStyleOptions<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n H extends boolean = false,\n> {\n className?: string\n hasSlot?: H\n name?: string\n slot?: ComponentSlot<ComponentSlotName<M>>\n style?: M\n transferProps?: D[]\n}\n\nfunction useStyle<\n Y extends HTMLStyledProps & ThemeProps<{}> = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n H extends boolean = false,\n>(\n props: Y,\n {\n name,\n className: defaultClassName,\n style: componentStyle,\n hasSlot,\n slot,\n transferProps,\n }: UseStyleOptions<Y, M, D, H> = {},\n): [Style<H>, WithoutThemeProps<Y, M, D>] {\n const system = useSystem()\n const { getAtRule, wrap } = system.layers\n const rootColorScheme = useColorSchemeContext()\n const options = { ...system.breakpoints, name, hasSlot, wrap }\n\n const propsRef = useRef<Dict>({})\n const mergedPropsRef = useRef<Dict>({})\n const styleRef = useRef<Style<H> | undefined>(undefined)\n\n const hasComponentStyle =\n componentStyle && !!Object.keys(componentStyle).length\n\n if (hasComponentStyle) {\n const {\n className: customClassName,\n base,\n compounds,\n props: propVariants,\n sizes,\n variants,\n defaultProps: { colorScheme: defaultColorScheme, ...defaultProps } = {},\n } = componentStyle\n\n const colorScheme =\n props.colorScheme ?? rootColorScheme ?? defaultColorScheme\n\n const className = cx(defaultClassName ?? customClassName, props.className)\n const mergedProps = {\n ...mergeDefaultProps(defaultProps, props),\n className,\n colorScheme,\n }\n const omitProps = Object.keys(propVariants ?? {})\n const { size, variant } = mergedProps\n\n if (variants) omitProps.push(\"variant\")\n if (sizes) omitProps.push(\"size\")\n\n const computedProps = omitThemeProps(\n mergedProps,\n omitProps,\n transferProps,\n ) as Y\n\n if (\n !isEqualProps(mergedPropsRef.current, mergedProps, [\"css\", \"children\"])\n ) {\n const { hasSize, hasVariant } = getHasAtRuleStyle(props.css)(getAtRule)\n\n let style: Style<H> = {}\n\n if (base) {\n const baseStyle = getStyle<H>(base)(options)\n\n style = merge(style, wrapStyle<H>(\"base\", baseStyle)(options))\n }\n\n if (sizes && !hasSize) {\n const sizeStyle = merge(\n sizes.base,\n getModifierStyle<H>(size, sizes)({ modifier: \"size\", ...options }),\n )\n\n style = merge(style, wrapStyle<H>(\"size\", sizeStyle)(options))\n }\n\n if (variants && !hasVariant) {\n const variantStyle = merge(\n variants.base,\n getModifierStyle<H>(\n variant,\n variants,\n )({ modifier: \"variant\", ...options }),\n )\n\n style = merge(style, wrapStyle<H>(\"variant\", variantStyle)(options))\n }\n\n if (propVariants)\n style = getPropStyle<H>(mergedProps, propVariants, style)(options)\n\n if (compounds)\n style = getCompoundStyle<H>(mergedProps, compounds, style)(options)\n\n styleRef.current = style\n\n if (hasSlot)\n computedProps.css = mergeSlotCSS<ComponentSlotName<M>>(\n slot,\n style as CSSSlotObject,\n computedProps.css,\n )\n else computedProps.css = mergeCSS(style as CSSObject, computedProps.css)\n } else {\n computedProps.css = propsRef.current.css\n }\n\n mergedPropsRef.current = mergedProps\n\n if (!isEqualProps(propsRef.current, computedProps))\n propsRef.current = computedProps\n } else {\n const className = cx(defaultClassName, props.className)\n\n if (className) props.className = className\n\n if (!isEqualProps(propsRef.current, props)) propsRef.current = props\n }\n\n return [\n styleRef.current ?? {},\n propsRef.current as WithoutThemeProps<Y, M, D>,\n ]\n}\n\nexport interface UseComponentStyleOptions<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n> extends Omit<UseStyleOptions<Y, M, D>, \"hasSlot\" | \"slot\"> {}\n\nexport function useComponentStyle<\n Y extends Dict = Dict,\n M extends ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n>(props: Y, options: UseComponentStyleOptions<Y, M, D> = {}) {\n return useStyle<Y, M, D>(props, options)\n}\n\nexport interface UseComponentSlotStyleOptions<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle | ComponentStyle = ComponentStyle,\n D extends keyof Y = keyof Y,\n> extends Omit<UseStyleOptions<Y, M, D, true>, \"hasSlot\"> {}\n\nexport function useComponentSlotStyle<\n Y extends Dict = Dict,\n M extends ComponentSlotStyle = ComponentSlotStyle,\n D extends keyof Y = keyof Y,\n>(props: Y, options: UseComponentSlotStyleOptions<Y, M, D> = {}) {\n return useStyle<Y, M, D, true>(props, { ...options, hasSlot: true })\n}\n"],"mappings":";;;;;;;;;AA2DA,SAAS,iBACP,WACA,OACA;CACA,OAAO,UAAU,aACd,MAAM,QAAS,MAAM,GAAG,MAAM,KAAK,IAAI,MACxC,KACF;AACF;AAEA,SAAS,SACP,OACA;CACA,OAAO,SAAU,EACf,MAAM,UACN,UAAU,OACV,UACA,YAAY,CAAC,GACb,SACwC;EACxC,IAAI,CAAC,UAAA,GAAA,oBAAA,cAAA,cAAA,CAAuB,KAAK,GAAG;EAEpC,IAAI,SACF,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAsB,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW;GAC5D,IAAI,UAAU,QAAQ;IACpB,IAAI,SAAS,UACX,QAAQ;MACL,KAAK,SAAS,GAAG,KAAK,GAAG,aAAa,IAAI,MAAM;KACjD,GAAG;IACL;IAEF,OAAO,CAAC,MAAM,iBAAiB,WAAW,SAAS,CAAC,CAAC,CAAC;GACxD,OAAO;IACL,IAAI,SAAS,UACX,QAAQ;MACL,KAAK,SAAS,GAAG,KAAK,GAAG,aAAa,IAAI,MAAM;KACjD,GAAG;IACL;IAEF,OAAO,CAAC,MAAM,KAAK;GACrB;EACF,CAAC,CACH;OACK,IAAI,UAAU,QAAQ;GAC3B,IAAI,SAAS,UACX,QAAQ;KACL,KAAK,SAAS,GAAG,aAAa,IAAI,MAAM;IACzC,GAAG;GACL;GAEF,OAAO,iBAAiB,WAAW,KAAK;EAC1C,OAAO;GACL,IAAI,SAAS,UACX,QAA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AAO,CAAC;GACrE;GAEA,IAAI,cACF,QAAQ,aAAgB,aAAa,cAAc,KAAK,CAAC,CAAC,OAAO;GAEnE,IAAI,WACF,QAAQ,iBAAoB,aAAa,WAAW,KAAK,CAAC,CAAC,OAAO;GAEpE,SAAS,UAAU;GAEnB,IAAI,SACF,cAAc,MAAM,aAClB,MACA,OACA,cAAc,GAChB;QACG,cAAc,MAAMC,kBAAAA,SAAS,OAAoB,cAAc,GAAG;EACzE,OACE,cAAc,MAAM,SAAS,QAAQ;EAGvC,eAAe,UAAU;EAEzB,IAAI,CAACD,cAAAA,aAAa,SAAS,SAAS,aAAa,GAC/C,SAAS,UAAU;CACvB,OAAO;EACL,MAAM,aAAA,GAAA,oBAAA,cAAA,GAAA,CAAe,kBAAkB,MAAM,SAAS;EAEtD,IAAI,WAAW,MAAM,YAAY;EAEjC,IAAI,CAACA,cAAAA,aAAa,SAAS,SAAS,KAAK,GAAG,SAAS,UAAU;CACjE;CAEA,OAAO,CACL,SAAS,WAAW,CAAC,GACrB,SAAS,OACX;AACF;AAQA,SAAgB,kBAId,OAAU,UAA6C,CAAC,GAAG;CAC3D,OAAO,SAAkB,OAAO,OAAO;AACzC;AAQA,SAAgB,sBAId,OAAU,UAAiD,CAAC,GAAG;CAC/D,OAAO,SAAwB,OAAO;EAAE,GAAG;EAAS,SAAS;CAAK,CAAC;AACrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["isRefObject"],"sources":["../../../../src/hooks/use-focus/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { RefObject } from \"react\"\nimport { useCallback, useRef } from \"react\"\nimport {\n getActiveElement,\n getDocument,\n getFirstFocusableElement,\n isRefObject,\n isSafari,\n useUpdateEffect,\n} from \"../../utils\"\nimport { useEventListener } from \"../use-event-listener\"\n\nexport interface UseFocusOnShowProps {\n focusTarget?: HTMLElement | null | RefObject<HTMLElement | null>\n preventScroll?: boolean\n shouldFocus?: boolean\n visible?: boolean\n}\n\n/**\n * `useFocusOnShow` is a custom hook that focuses on the target element when it is shown.\n *\n * @see https://yamada-ui.com/docs/hooks/use-focus-on-show\n */\nexport const useFocusOnShow = <Y extends HTMLElement>(\n refOrEl: RefObject<null | Y> | Y,\n {\n focusTarget: focusRefOrEl,\n preventScroll,\n shouldFocus,\n visible,\n }: UseFocusOnShowProps = {\n preventScroll: true,\n shouldFocus: false,\n },\n) => {\n const trulyShouldFocus = shouldFocus && visible\n const focused = useRef(false)\n\n const getTarget = useCallback(() => {\n return isRefObject(refOrEl) ? refOrEl.current : refOrEl\n }, [refOrEl])\n\n const getFocusTarget = useCallback(() => {\n return isRefObject(focusRefOrEl) ? focusRefOrEl.current : focusRefOrEl\n }, [focusRefOrEl])\n\n const onFocus = useCallback(() => {\n const target = getTarget()\n\n if (!target || !trulyShouldFocus || focused.current) return\n if (target.contains(document.activeElement
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isRefObject"],"sources":["../../../../src/hooks/use-focus/index.ts"],"sourcesContent":["\"use client\"\n\nimport type { RefObject } from \"react\"\nimport { useCallback, useRef } from \"react\"\nimport {\n getActiveElement,\n getDocument,\n getFirstFocusableElement,\n isRefObject,\n isSafari,\n useUpdateEffect,\n} from \"../../utils\"\nimport { useEventListener } from \"../use-event-listener\"\n\nexport interface UseFocusOnShowProps {\n focusTarget?: HTMLElement | null | RefObject<HTMLElement | null>\n preventScroll?: boolean\n shouldFocus?: boolean\n visible?: boolean\n}\n\n/**\n * `useFocusOnShow` is a custom hook that focuses on the target element when it is shown.\n *\n * @see https://yamada-ui.com/docs/hooks/use-focus-on-show\n */\nexport const useFocusOnShow = <Y extends HTMLElement>(\n refOrEl: RefObject<null | Y> | Y,\n {\n focusTarget: focusRefOrEl,\n preventScroll,\n shouldFocus,\n visible,\n }: UseFocusOnShowProps = {\n preventScroll: true,\n shouldFocus: false,\n },\n) => {\n const trulyShouldFocus = shouldFocus && visible\n const focused = useRef(false)\n\n const getTarget = useCallback(() => {\n return isRefObject(refOrEl) ? refOrEl.current : refOrEl\n }, [refOrEl])\n\n const getFocusTarget = useCallback(() => {\n return isRefObject(focusRefOrEl) ? focusRefOrEl.current : focusRefOrEl\n }, [focusRefOrEl])\n\n const onFocus = useCallback(() => {\n const target = getTarget()\n\n if (!target || !trulyShouldFocus || focused.current) return\n if (target.contains(document.activeElement)) return\n\n const focusTarget = getFocusTarget()\n\n if (focusTarget) {\n requestAnimationFrame(() => {\n focusTarget.focus({ preventScroll })\n\n focused.current = true\n })\n } else {\n const firstFocusable = getFirstFocusableElement(target)\n\n if (firstFocusable)\n requestAnimationFrame(() => {\n firstFocusable.focus({ preventScroll })\n\n focused.current = true\n })\n else\n requestAnimationFrame(() => {\n target.focus({ preventScroll })\n\n focused.current = true\n })\n }\n }, [getTarget, trulyShouldFocus, getFocusTarget, preventScroll])\n\n useUpdateEffect(() => {\n focused.current = !trulyShouldFocus\n }, [trulyShouldFocus])\n\n useUpdateEffect(() => {\n requestAnimationFrame(onFocus)\n }, [onFocus])\n\n useEventListener(getTarget, \"transitionend\", onFocus)\n}\n\nexport interface UseFocusOnMouseDownProps {\n ref: RefObject<HTMLElement | null>\n elements?: (HTMLElement | null | RefObject<HTMLElement | null>)[]\n enabled?: boolean\n}\n\n/**\n * `useFocusOnPointerDown` is a custom hook that focuses on the target element when it is clicked.\n *\n * @see https://yamada-ui.com/docs/hooks/use-focus-on-pointer-down\n */\nexport const useFocusOnPointerDown = ({\n ref,\n elements,\n enabled,\n}: UseFocusOnMouseDownProps) => {\n useEventListener(\n () => getDocument(ref.current),\n \"pointerdown\",\n (ev) => {\n if (!isSafari() || !enabled) return\n const target = ev.target as HTMLElement\n\n const els = elements ?? [ref]\n\n const validTarget = els.some((elOrRef) => {\n const el = isRefObject(elOrRef) ? elOrRef.current : elOrRef\n\n return el?.contains(target) || el === target\n })\n\n if (\n getActiveElement(getDocument(ref.current)) !== target &&\n validTarget\n ) {\n ev.preventDefault()\n\n target.focus()\n }\n },\n )\n}\n"],"mappings":";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yBAAyB,EACpC,KACA,UACA,cAC8B;CAC9B,uCAAA,wBAAA,GAAA,oBAAA,cAAA,YAAA,CACoB,IAAI,OAAO,GAC7B,gBACC,OAAO;EACN,IAAI,EAAA,GAAA,oBAAA,cAAA,SAAA,CAAU,KAAK,CAAC,SAAS;EAC7B,MAAM,SAAS,GAAG;EAIlB,MAAM,eAFM,YAAY,CAAC,GAAG,EAAA,CAEJ,MAAM,YAAY;GACxC,MAAM,KAAKA,YAAAA,YAAY,OAAO,IAAI,QAAQ,UAAU;GAEpD,OAAO,IAAI,SAAS,MAAM,KAAK,OAAO;EACxC,CAAC;EAED,KAAA,GAAA,oBAAA,cAAA,iBAAA,EAAA,GAAA,oBAAA,cAAA,YAAA,CAC+B,IAAI,OAAO,CAAC,MAAM,UAC/C,aACA;GACA,GAAG,eAAe;GAElB,OAAO,MAAM;EACf;CACF,CACF;AACF"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1182,6 +1182,7 @@ const require_panel_top_open_icon = require("./components/icon/icons/panel-top-o
|
|
|
1182
1182
|
const require_panels_left_bottom_icon = require("./components/icon/icons/panels-left-bottom-icon.cjs");
|
|
1183
1183
|
const require_panels_right_bottom_icon = require("./components/icon/icons/panels-right-bottom-icon.cjs");
|
|
1184
1184
|
const require_panels_top_left_icon = require("./components/icon/icons/panels-top-left-icon.cjs");
|
|
1185
|
+
const require_paper_bag_icon = require("./components/icon/icons/paper-bag-icon.cjs");
|
|
1185
1186
|
const require_paperclip_icon = require("./components/icon/icons/paperclip-icon.cjs");
|
|
1186
1187
|
const require_parasol_icon = require("./components/icon/icons/parasol-icon.cjs");
|
|
1187
1188
|
const require_parentheses_icon = require("./components/icon/icons/parentheses-icon.cjs");
|
|
@@ -3799,6 +3800,7 @@ var src_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
|
3799
3800
|
PanelsLeftBottomIcon: () => require_panels_left_bottom_icon.PanelsLeftBottomIcon,
|
|
3800
3801
|
PanelsRightBottomIcon: () => require_panels_right_bottom_icon.PanelsRightBottomIcon,
|
|
3801
3802
|
PanelsTopLeftIcon: () => require_panels_top_left_icon.PanelsTopLeftIcon,
|
|
3803
|
+
PaperBagIcon: () => require_paper_bag_icon.PaperBagIcon,
|
|
3802
3804
|
PaperclipIcon: () => require_paperclip_icon.PaperclipIcon,
|
|
3803
3805
|
ParasolIcon: () => require_parasol_icon.ParasolIcon,
|
|
3804
3806
|
ParenthesesIcon: () => require_parentheses_icon.ParenthesesIcon,
|
|
@@ -7095,6 +7097,7 @@ exports.PanelTopOpenIcon = require_panel_top_open_icon.PanelTopOpenIcon;
|
|
|
7095
7097
|
exports.PanelsLeftBottomIcon = require_panels_left_bottom_icon.PanelsLeftBottomIcon;
|
|
7096
7098
|
exports.PanelsRightBottomIcon = require_panels_right_bottom_icon.PanelsRightBottomIcon;
|
|
7097
7099
|
exports.PanelsTopLeftIcon = require_panels_top_left_icon.PanelsTopLeftIcon;
|
|
7100
|
+
exports.PaperBagIcon = require_paper_bag_icon.PaperBagIcon;
|
|
7098
7101
|
exports.PaperclipIcon = require_paperclip_icon.PaperclipIcon;
|
|
7099
7102
|
exports.ParasolIcon = require_parasol_icon.ParasolIcon;
|
|
7100
7103
|
exports.ParenthesesIcon = require_parentheses_icon.ParenthesesIcon;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.cjs","names":[],"sources":["../../../src/utils/store.ts"],"sourcesContent":["\"use client\"\n\nimport type { Path, Value } from \"@yamada-ui/utils\"\nimport {\n getMemoizedObject,\n isArray,\n isObject,\n isUndefined,\n runIfFn,\n toArray,\n} from \"@yamada-ui/utils\"\nimport { useSyncExternalStore } from \"react\"\n\nconst DEFAULT_IDENTIFIER = \"default\"\n\ninterface Subscribe {\n (listener: () => void): () => void\n}\n\ninterface Store<Y> {\n queue: Map<string, (() => void)[]>\n ref: { current: Y }\n get: () => Y\n set: (nextState: ((prevState: Y) => Y) | Y, key?: string | string[]) => void\n update: (key?: string | string[]) => void\n key?: string\n}\n\ntype IndexOrPath<Y> = Y extends any[]\n ? number\n : Y extends object\n ? Path<Y>\n : undefined\n\ntype ReturnArrayValue<Y extends any[], D> = D extends number\n ? undefined | Y[D]\n : Y\n\ntype ReturnObjectValue<Y extends object, D> = D extends string ? Value<Y, D> : Y\n\ntype ReturnValue<Y, D> = Y extends any[]\n ? ReturnArrayValue<Y, D>\n : Y extends object\n ? ReturnObjectValue<Y, D>\n : Y\n\ninterface UseStore<Y> {\n <D extends IndexOrPath<Y>>(path?: D, key?: string): ReturnValue<Y, D>\n}\n\ninterface CreateMethod<Y, M extends Function> {\n (store: Store<Y>): M\n}\n\ntype Methods<Y, M extends CustomMethods<Y>> = Omit<\n Store<Y>,\n \"key\" | \"update\"\n> & {\n [D in keyof M]: ReturnType<M[D]>\n} & { update: () => void }\n\ninterface CustomMethods<Y> {\n [key: string]: CreateMethod<Y, (...args: any[]) => Promise<void> | void>\n}\n\ninterface CreateStoreOptions<Y> {\n proxyHandler?: ProxyHandler<{ current: Y }>\n subscribe?: CreateMethod<Y, Subscribe>\n}\n\nexport function createStore<Y, M extends CustomMethods<Y>>(\n initialState: (() => Y) | Y,\n additionalMethods?: M,\n options: CreateStoreOptions<Y> = {},\n): [UseStore<Y>, Methods<Y, M>] {\n const queue = new Map<string, (() => void)[]>()\n const ref = new Proxy(\n { current: runIfFn(initialState) },\n { ...options.proxyHandler },\n )\n\n function get() {\n return ref.current\n }\n\n function executeQueue(key: string) {\n const listeners = queue.get(key) ?? []\n\n if (!listeners.length)\n console.warn(`createStore: ${key} is not subscribed.`)\n\n listeners.forEach((listener) => listener())\n }\n\n function update(key?: string | string[]) {\n if (!isUndefined(key)) toArray(key).forEach(executeQueue)\n\n executeQueue(DEFAULT_IDENTIFIER)\n }\n\n function set(nextState: ((prevState: Y) => Y) | Y, key?: string | string[]) {\n ref.current = runIfFn(nextState, ref.current)\n\n update(key)\n }\n\n const methods = { ref, get, queue, set, update }\n\n function useStore<D extends IndexOrPath<Y>>(path?: D, key?: string) {\n const customSubscribe = options.subscribe?.({\n key,\n ...methods,\n })\n\n const subscribe = function (listener: () => void) {\n if (key) {\n const listeners = queue.get(key) ?? []\n\n if (listeners.length)\n console.warn(`createStore: ${key} is already subscribed.`)\n\n queue.set(key, [listener])\n } else {\n const listeners = queue.get(DEFAULT_IDENTIFIER) ?? []\n\n queue.set(DEFAULT_IDENTIFIER, [...listeners, listener])\n }\n\n return function () {\n if (key) {\n queue.delete(key)\n } else {\n const listeners = queue.get(DEFAULT_IDENTIFIER) ?? []\n\n queue.set(\n DEFAULT_IDENTIFIER,\n listeners.filter((fn) => fn !== listener),\n )\n }\n }\n }\n\n function getSnapshot<H extends ReturnValue<Y, D>>(): H {\n if (!isUndefined(path))\n if (isObject(ref.current)) return getMemoizedObject(ref.current, path)\n else if (isArray(ref.current))
|
|
1
|
+
{"version":3,"file":"store.cjs","names":[],"sources":["../../../src/utils/store.ts"],"sourcesContent":["\"use client\"\n\nimport type { Path, Value } from \"@yamada-ui/utils\"\nimport {\n getMemoizedObject,\n isArray,\n isObject,\n isUndefined,\n runIfFn,\n toArray,\n} from \"@yamada-ui/utils\"\nimport { useSyncExternalStore } from \"react\"\n\nconst DEFAULT_IDENTIFIER = \"default\"\n\ninterface Subscribe {\n (listener: () => void): () => void\n}\n\ninterface Store<Y> {\n queue: Map<string, (() => void)[]>\n ref: { current: Y }\n get: () => Y\n set: (nextState: ((prevState: Y) => Y) | Y, key?: string | string[]) => void\n update: (key?: string | string[]) => void\n key?: string\n}\n\ntype IndexOrPath<Y> = Y extends any[]\n ? number\n : Y extends object\n ? Path<Y>\n : undefined\n\ntype ReturnArrayValue<Y extends any[], D> = D extends number\n ? undefined | Y[D]\n : Y\n\ntype ReturnObjectValue<Y extends object, D> = D extends string ? Value<Y, D> : Y\n\ntype ReturnValue<Y, D> = Y extends any[]\n ? ReturnArrayValue<Y, D>\n : Y extends object\n ? ReturnObjectValue<Y, D>\n : Y\n\ninterface UseStore<Y> {\n <D extends IndexOrPath<Y>>(path?: D, key?: string): ReturnValue<Y, D>\n}\n\ninterface CreateMethod<Y, M extends Function> {\n (store: Store<Y>): M\n}\n\ntype Methods<Y, M extends CustomMethods<Y>> = Omit<\n Store<Y>,\n \"key\" | \"update\"\n> & {\n [D in keyof M]: ReturnType<M[D]>\n} & { update: () => void }\n\ninterface CustomMethods<Y> {\n [key: string]: CreateMethod<Y, (...args: any[]) => Promise<void> | void>\n}\n\ninterface CreateStoreOptions<Y> {\n proxyHandler?: ProxyHandler<{ current: Y }>\n subscribe?: CreateMethod<Y, Subscribe>\n}\n\nexport function createStore<Y, M extends CustomMethods<Y>>(\n initialState: (() => Y) | Y,\n additionalMethods?: M,\n options: CreateStoreOptions<Y> = {},\n): [UseStore<Y>, Methods<Y, M>] {\n const queue = new Map<string, (() => void)[]>()\n const ref = new Proxy(\n { current: runIfFn(initialState) },\n { ...options.proxyHandler },\n )\n\n function get() {\n return ref.current\n }\n\n function executeQueue(key: string) {\n const listeners = queue.get(key) ?? []\n\n if (!listeners.length)\n console.warn(`createStore: ${key} is not subscribed.`)\n\n listeners.forEach((listener) => listener())\n }\n\n function update(key?: string | string[]) {\n if (!isUndefined(key)) toArray(key).forEach(executeQueue)\n\n executeQueue(DEFAULT_IDENTIFIER)\n }\n\n function set(nextState: ((prevState: Y) => Y) | Y, key?: string | string[]) {\n ref.current = runIfFn(nextState, ref.current)\n\n update(key)\n }\n\n const methods = { ref, get, queue, set, update }\n\n function useStore<D extends IndexOrPath<Y>>(path?: D, key?: string) {\n const customSubscribe = options.subscribe?.({\n key,\n ...methods,\n })\n\n const subscribe = function (listener: () => void) {\n if (key) {\n const listeners = queue.get(key) ?? []\n\n if (listeners.length)\n console.warn(`createStore: ${key} is already subscribed.`)\n\n queue.set(key, [listener])\n } else {\n const listeners = queue.get(DEFAULT_IDENTIFIER) ?? []\n\n queue.set(DEFAULT_IDENTIFIER, [...listeners, listener])\n }\n\n return function () {\n if (key) {\n queue.delete(key)\n } else {\n const listeners = queue.get(DEFAULT_IDENTIFIER) ?? []\n\n queue.set(\n DEFAULT_IDENTIFIER,\n listeners.filter((fn) => fn !== listener),\n )\n }\n }\n }\n\n function getSnapshot<H extends ReturnValue<Y, D>>(): H {\n if (!isUndefined(path))\n if (isObject(ref.current)) return getMemoizedObject(ref.current, path)\n else if (isArray(ref.current)) return ref.current[path as number]\n\n return ref.current as unknown as H\n }\n\n return useSyncExternalStore(\n customSubscribe ?? subscribe,\n getSnapshot,\n getSnapshot,\n )\n }\n\n const customMethods = Object.fromEntries(\n Object.entries(additionalMethods ?? {}).map(([key, value]) => [\n key,\n value(methods),\n ]),\n ) as { [D in keyof M]: ReturnType<M[D]> }\n\n return [useStore, { ...methods, ...customMethods }]\n}\n"],"mappings":";;;;AAaA,MAAM,qBAAqB;AAyD3B,SAAgB,YACd,cACA,mBACA,UAAiC,CAAC,GACJ;CAC9B,MAAM,wBAAQ,IAAI,IAA4B;CAC9C,MAAM,MAAM,IAAI,MACd,EAAE,UAAA,GAAA,iBAAA,QAAA,CAAiB,YAAY,EAAE,GACjC,EAAE,GAAG,QAAQ,aAAa,CAC5B;CAEA,SAAS,MAAM;EACb,OAAO,IAAI;CACb;CAEA,SAAS,aAAa,KAAa;EACjC,MAAM,YAAY,MAAM,IAAI,GAAG,KAAK,CAAC;EAErC,IAAI,CAAC,UAAU,QACb,QAAQ,KAAK,gBAAgB,IAAI,oBAAoB;EAEvD,UAAU,SAAS,aAAa,SAAS,CAAC;CAC5C;CAEA,SAAS,OAAO,KAAyB;EACvC,IAAI,EAAA,GAAA,iBAAA,YAAA,CAAa,GAAG,GAAG,CAAA,GAAA,iBAAA,QAAA,CAAQ,GAAG,CAAC,CAAC,QAAQ,YAAY;EAExD,aAAa,kBAAkB;CACjC;CAEA,SAAS,IAAI,WAAsC,KAAyB;EAC1E,IAAI,WAAA,GAAA,iBAAA,QAAA,CAAkB,WAAW,IAAI,OAAO;EAE5C,OAAO,GAAG;CACZ;CAEA,MAAM,UAAU;EAAE;EAAK;EAAK;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