PromoCursed/node_modules/.cache/babel-loader/5633e37128b35e38178c57fbb604ccb6592dc29a3d68d4ea19579dcdc9e93e2f.json

1 line
11 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"\"use client\";\n\nimport React, { useMemo } from 'react';\nimport { ColorBlock, Color as RcColor } from '@rc-component/color-picker';\nimport classNames from 'classnames';\nimport useMergedState from \"rc-util/es/hooks/useMergedState\";\nimport Collapse from '../../collapse';\nimport { useLocale } from '../../locale';\nimport { useToken } from '../../theme/internal';\nimport { generateColor } from '../util';\nconst genPresetColor = list => list.map(value => {\n value.colors = value.colors.map(generateColor);\n return value;\n});\nconst isBright = (value, bgColorToken) => {\n const {\n r,\n g,\n b,\n a\n } = value.toRgb();\n const hsv = new RcColor(value.toRgbString()).onBackground(bgColorToken).toHsv();\n if (a <= 0.5) {\n // Adapted to dark mode\n return hsv.v > 0.5;\n }\n return r * 0.299 + g * 0.587 + b * 0.114 > 192;\n};\nconst genCollapsePanelKey = _ref => {\n let {\n label\n } = _ref;\n return `panel-${label}`;\n};\nconst ColorPresets = _ref2 => {\n let {\n prefixCls,\n presets,\n value: color,\n onChange\n } = _ref2;\n const [locale] = useLocale('ColorPicker');\n const [, token] = useToken();\n const [presetsValue] = useMergedState(genPresetColor(presets), {\n value: genPresetColor(presets),\n postState: genPresetColor\n });\n const colorPresetsPrefixCls = `${prefixCls}-presets`;\n const activeKeys = useMemo(() => presetsValue.reduce((acc, preset) => {\n const {\n defaultOpen = true\n } = preset;\n if (defaultOpen) acc.push(genCollapsePanelKey(preset));\n return acc;\n }, []), [presetsValue]);\n const handleClick = colorValue => {\n onChange === null || onChange === void 0 ? void 0 : onChange(colorValue);\n };\n const items = presetsValue.map(preset => {\n var _a;\n return {\n key: genCollapsePanelKey(preset),\n label: /*#__PURE__*/React.createElement(\"div\", {\n className: `${colorPresetsPrefixCls}-label`\n }, preset === null || preset === void 0 ? void 0 : preset.label),\n children: ( /*#__PURE__*/React.createElement(\"div\", {\n className: `${colorPresetsPrefixCls}-items`\n }, Array.isArray(preset === null || preset === void 0 ? void 0 : preset.colors) && ((_a = preset.colors) === null || _a === void 0 ? void 0 : _a.length) > 0 ? preset.colors.map((presetColor, index) => ( /*#__PURE__*/React.createElement(ColorBlock\n // eslint-disable-next-line react/no-array-index-key\n , {\n // eslint-disable-next-line react/no-array-index-key\n key: `preset-${index}-${presetColor.toHexString()}`,\n color: generateColor(presetColor).toRgbString(),\n prefixCls: prefixCls,\n className: classNames(`${colorPresetsPrefixCls}-color`, {\n [`${colorPresetsPrefixCls}-color-checked`]: presetColor.toHexString() === (color === null || color === void 0 ? void 0 : color.toHexString()),\n [`${colorPresetsPrefixCls}-color-bright`]: isBright(presetColor, token.colorBgElevated)\n }),\n onClick: () => handleClick(presetColor)\n }))) : ( /*#__PURE__*/React.createElement(\"span\", {\n className: `${colorPresetsPrefixCls}-empty`\n }, locale.presetEmpty))))\n };\n });\n return /*#__PURE__*/React.createElement(\"div\", {\n className: colorPresetsPrefixCls\n }, /*#__PURE__*/React.createElement(Collapse, {\n defaultActiveKey: activeKeys,\n ghost: true,\n items: items\n }));\n};\nexport default ColorPresets;","map":{"version":3,"names":["React","useMemo","ColorBlock","Color","RcColor","classNames","useMergedState","Collapse","useLocale","useToken","generateColor","genPresetColor","list","map","value","colors","isBright","bgColorToken","r","g","b","a","toRgb","hsv","toRgbString","onBackground","toHsv","v","genCollapsePanelKey","_ref","label","ColorPresets","_ref2","prefixCls","presets","color","onChange","locale","token","presetsValue","postState","colorPresetsPrefixCls","activeKeys","reduce","acc","preset","defaultOpen","push","handleClick","colorValue","items","_a","key","createElement","clas