PromoCursed/node_modules/.cache/babel-loader/2e4c544fcd97e16a6b3b9408148cc311561d44c1e313daf4af1935f4fb5757a3.json
2024-08-20 23:25:37 +04:00

1 line
7.5 KiB
JSON

{"ast":null,"code":"import * as React from 'react';\nimport { useEvent, useMergedState } from 'rc-util';\nimport { useLocale } from '../../locale';\nimport { generateColor } from '../util';\n/**\n * Combine the `color` and `mode` to make sure sync of state.\n */\nexport default function useModeColor(defaultValue, value, mode) {\n const [locale] = useLocale('ColorPicker');\n // ======================== Base ========================\n // Color\n const [mergedColor, setMergedColor] = useMergedState(defaultValue, {\n value\n });\n // Mode\n const [modeState, setModeState] = React.useState('single');\n const [modeOptionList, modeSet] = React.useMemo(() => {\n const list = (Array.isArray(mode) ? mode : [mode]).filter(m => m);\n if (!list.length) {\n list.push('single');\n }\n const modes = new Set(list);\n const optionList = [];\n const pushOption = (modeType, localeTxt) => {\n if (modes.has(modeType)) {\n optionList.push({\n label: localeTxt,\n value: modeType\n });\n }\n };\n pushOption('single', locale.singleColor);\n pushOption('gradient', locale.gradientColor);\n return [optionList, modes];\n }, [mode]);\n // ======================== Post ========================\n // We need align `mode` with `color` state\n // >>>>> Color\n const [cacheColor, setCacheColor] = React.useState(null);\n const setColor = useEvent(nextColor => {\n setCacheColor(nextColor);\n setMergedColor(nextColor);\n });\n const postColor = React.useMemo(() => {\n const colorObj = generateColor(mergedColor || '');\n // Use `cacheColor` in case the color is `cleared`\n return colorObj.equals(cacheColor) ? cacheColor : colorObj;\n }, [mergedColor, cacheColor]);\n // >>>>> Mode\n const postMode = React.useMemo(() => {\n var _a;\n if (modeSet.has(modeState)) {\n return modeState;\n }\n return (_a = modeOptionList[0]) === null || _a === void 0 ? void 0 : _a.value;\n }, [modeSet, modeState, modeOptionList]);\n // ======================= Effect =======================\n // Dynamic update mode when color change\n React.useEffect(() => {\n setModeState(postColor.isGradient() ? 'gradient' : 'single');\n }, [postColor]);\n // ======================= Return =======================\n return [postColor, setColor, postMode, setModeState, modeOptionList];\n}","map":{"version":3,"names":["React","useEvent","useMergedState","useLocale","generateColor","useModeColor","defaultValue","value","mode","locale","mergedColor","setMergedColor","modeState","setModeState","useState","modeOptionList","modeSet","useMemo","list","Array","isArray","filter","m","length","push","modes","Set","optionList","pushOption","modeType","localeTxt","has","label","singleColor","gradientColor","cacheColor","setCacheColor","setColor","nextColor","postColor","colorObj","equals","postMode","_a","useEffect","isGradient"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/antd/es/color-picker/hooks/useModeColor.js"],"sourcesContent":["import * as React from 'react';\nimport { useEvent, useMergedState } from 'rc-util';\nimport { useLocale } from '../../locale';\nimport { generateColor } from '../util';\n/**\n * Combine the `color` and `mode` to make sure sync of state.\n */\nexport default function useModeColor(defaultValue, value, mode) {\n const [locale] = useLocale('ColorPicker');\n // ======================== Base ========================\n // Color\n const [mergedColor, setMergedColor] = useMergedState(defaultValue, {\n value\n });\n // Mode\n const [modeState, setModeState] = React.useState('single');\n const [modeOptionList, modeSet] = React.useMemo(() => {\n const list = (Array.isArray(mode) ? mode : [mode]).filter(m => m);\n if (!list.length) {\n list.push('single');\n }\n const modes = new Set(list);\n const optionList = [];\n const pushOption = (modeType, localeTxt) => {\n if (modes.has(modeType)) {\n optionList.push({\n label: localeTxt,\n value: modeType\n });\n }\n };\n pushOption('single', locale.singleColor);\n pushOption('gradient', locale.gradientColor);\n return [optionList, modes];\n }, [mode]);\n // ======================== Post ========================\n // We need align `mode` with `color` state\n // >>>>> Color\n const [cacheColor, setCacheColor] = React.useState(null);\n const setColor = useEvent(nextColor => {\n setCacheColor(nextColor);\n setMergedColor(nextColor);\n });\n const postColor = React.useMemo(() => {\n const colorObj = generateColor(mergedColor || '');\n // Use `cacheColor` in case the color is `cleared`\n return colorObj.equals(cacheColor) ? cacheColor : colorObj;\n }, [mergedColor, cacheColor]);\n // >>>>> Mode\n const postMode = React.useMemo(() => {\n var _a;\n if (modeSet.has(modeState)) {\n return modeState;\n }\n return (_a = modeOptionList[0]) === null || _a === void 0 ? void 0 : _a.value;\n }, [modeSet, modeState, modeOptionList]);\n // ======================= Effect =======================\n // Dynamic update mode when color change\n React.useEffect(() => {\n setModeState(postColor.isGradient() ? 'gradient' : 'single');\n }, [postColor]);\n // ======================= Return =======================\n return [postColor, setColor, postMode, setModeState, modeOptionList];\n}"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,EAAEC,cAAc,QAAQ,SAAS;AAClD,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,aAAa,QAAQ,SAAS;AACvC;AACA;AACA;AACA,eAAe,SAASC,YAAYA,CAACC,YAAY,EAAEC,KAAK,EAAEC,IAAI,EAAE;EAC9D,MAAM,CAACC,MAAM,CAAC,GAAGN,SAAS,CAAC,aAAa,CAAC;EACzC;EACA;EACA,MAAM,CAACO,WAAW,EAAEC,cAAc,CAAC,GAAGT,cAAc,CAACI,YAAY,EAAE;IACjEC;EACF,CAAC,CAAC;EACF;EACA,MAAM,CAACK,SAAS,EAAEC,YAAY,CAAC,GAAGb,KAAK,CAACc,QAAQ,CAAC,QAAQ,CAAC;EAC1D,MAAM,CAACC,cAAc,EAAEC,OAAO,CAAC,GAAGhB,KAAK,CAACiB,OAAO,CAAC,MAAM;IACpD,MAAMC,IAAI,GAAG,CAACC,KAAK,CAACC,OAAO,CAACZ,IAAI,CAAC,GAAGA,IAAI,GAAG,CAACA,IAAI,CAAC,EAAEa,MAAM,CAACC,CAAC,IAAIA,CAAC,CAAC;IACjE,IAAI,CAACJ,IAAI,CAACK,MAAM,EAAE;MAChBL,IAAI,CAACM,IAAI,CAAC,QAAQ,CAAC;IACrB;IACA,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAACR,IAAI,CAAC;IAC3B,MAAMS,UAAU,GAAG,EAAE;IACrB,MAAMC,UAAU,GAAGA,CAACC,QAAQ,EAAEC,SAAS,KAAK;MAC1C,IAAIL,KAAK,CAACM,GAAG,CAACF,QAAQ,CAAC,EAAE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