1 |
- {"ast":null,"code":"\"use client\";\n\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport { AggregationColor } from '../../color';\nimport { getGradientPercentColor } from '../../util';\nimport { GradientColorSlider } from '../ColorSlider';\nfunction sortColors(colors) {\n return _toConsumableArray(colors).sort((a, b) => a.percent - b.percent);\n}\n/**\n * GradientColorBar will auto show when the mode is `gradient`.\n */\nconst GradientColorBar = props => {\n const {\n prefixCls,\n mode,\n onChange,\n onChangeComplete,\n onActive,\n activeIndex,\n onGradientDragging,\n colors\n } = props;\n const isGradient = mode === 'gradient';\n // ============================= Colors =============================\n const colorList = React.useMemo(() => colors.map(info => ({\n percent: info.percent,\n color: info.color.toRgbString()\n })), [colors]);\n const values = React.useMemo(() => colorList.map(info => info.percent), [colorList]);\n // ============================== Drag ==============================\n const colorsRef = React.useRef(colorList);\n // Record current colors\n const onDragStart = ({\n rawValues,\n draggingIndex,\n draggingValue\n }) => {\n if (rawValues.length > colorList.length) {\n // Add new node\n const newPointColor = getGradientPercentColor(colorList, draggingValue);\n const nextColors = _toConsumableArray(colorList);\n nextColors.splice(draggingIndex, 0, {\n percent: draggingValue,\n color: newPointColor\n });\n colorsRef.current = nextColors;\n } else {\n colorsRef.current = colorList;\n }\n onGradientDragging(true);\n onChange(new AggregationColor(sortColors(colorsRef.current)), true);\n };\n // Adjust color when dragging\n const onDragChange = ({\n deleteIndex,\n draggingIndex,\n draggingValue\n }) => {\n let nextColors = _toConsumableArray(colorsRef.current);\n if (deleteIndex !== -1) {\n nextColors.splice(deleteIndex, 1);\n } else {\n nextColors[draggingIndex] = Object.assign(Object.assign({}, nextColors[draggingIndex]), {\n percent: draggingValue\n });\n nextColors = sortColors(nextColors);\n }\n onChange(new AggregationColor(nextColors), true);\n };\n // ============================== Key ===============================\n const onKeyDelete = index => {\n const nextColors = _toConsumableArray(colorList);\n nextColors.splice(index, 1);\n const nextColor = new AggregationColor(nextColors);\n onChange(nextColor);\n onChangeComplete(nextColor);\n };\n // ============================= Change =============================\n const onInternalChangeComplete = nextValues => {\n onChangeComplete(new AggregationColor(colorList));\n // Reset `activeIndex` if out of range\n if (activeIndex >= nextValues.length) {\n onActive(nextValues.length - 1);\n }\n onGradientDragging(false);\n };\n // ============================= Render =============================\n if (!isGradient) {\n return null;\n }\n return /*#__PURE__*/React.createElement(GradientColorSlider, {\n min: 0,\n max: 100,\n prefixCls: prefixCls,\n className: `${prefixCls}-gradient-slider`,\n colors: colorList,\n color: null,\n value: values,\n range: true,\n onChangeComplete: onInternalChangeComplete,\n disabled: false,\n type: \"gradient\",\n // Active\n activeIndex: activeIndex,\n onActive: onActive,\n // Drag\n onDragStart: onDragStart,\n onDragChange: onDragChange,\n onKeyDelete: onKeyDelete\n });\n};\nexport default /*#__PURE__*/React.memo(GradientColorBar);","map":{"version":3,"names":["_toConsumableArray","React","AggregationColor","getGradientPercentColor","GradientColorSlider","sortColors","colors","sort","a","b","percent","GradientColorBar","props","prefixCls","mode","onChange","onChangeComplete","onActive","activeIndex","onGradientDragging","isGradient","colorList","useMemo","map","info","color","toRgbString","values","colorsRef","useRef","onDragStart","rawValues","draggingIndex","draggingValue","length","newPointColor","nextColors","splice","current","onDragChange","deleteIndex","Object","assign","onKeyDelete","index","nextColor","onInternalChangeComplete","nextValues","createElement","min","max","className","value","range","disabled","type","memo"],"sources":["/Users/max_liu/max_liu/company/tools_auto_pt/node_modules/antd/es/color-picker/components/PanelPicker/GradientColorBar.js"],"sourcesContent":["\"use client\";\n\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport { AggregationColor } from '../../color';\nimport { getGradientPercentColor } from '../../util';\nimport { GradientColorSlider } from '../ColorSlider';\nfunction sortColors(colors) {\n return _toConsumableArray(colors).sort((a, b) => a.percent - b.percent);\n}\n/**\n * GradientColorBar will auto show when the mode is `gradient`.\n */\nconst GradientColorBar = props => {\n const {\n prefixCls,\n mode,\n onChange,\n onChangeComplete,\n onActive,\n activeIndex,\n onGradientDragging,\n colors\n } = props;\n const isGradient = mode === 'gradient';\n // ============================= Colors =============================\n const colorList = React.useMemo(() => colors.map(info => ({\n percent: info.percent,\n color: info.color.toRgbString()\n })), [colors]);\n const values = React.useMemo(() => colorList.map(info => info.percent), [colorList]);\n // ============================== Drag ==============================\n const colorsRef = React.useRef(colorList);\n // Record current colors\n const onDragStart = ({\n rawValues,\n draggingIndex,\n draggingValue\n }) => {\n if (rawValues.length > colorList.length) {\n // Add new node\n const newPointColor = getGradientPercentColor(colorList, draggingValue);\n const nextColors = _toConsumableArray(colorList);\n nextColors.splice(draggingIndex, 0, {\n percent: draggingValue,\n color: newPointColor\n });\n colorsRef.current = nextColors;\n } else {\n colorsRef.current = colorList;\n }\n onGradientDragging(true);\n onChange(new AggregationColor(sortColors(colorsRef.current)), true);\n };\n // Adjust color when dragging\n const onDragChange = ({\n deleteIndex,\n draggingIndex,\n draggingValue\n }) => {\n let nextColors = _toConsumableArray(colorsRef.current);\n if (deleteIndex !== -1) {\n nextColors.splice(deleteIndex, 1);\n } else {\n nextColors[draggingIndex] = Object.assign(Object.assign({}, nextColors[draggingIndex]), {\n percent: draggingValue\n });\n nextColors = sortColors(nextColors);\n }\n onChange(new AggregationColor(nextColors), true);\n };\n // ============================== Key ===============================\n const onKeyDelete = index => {\n const nextColors = _toConsumableArray(colorList);\n nextColors.splice(index, 1);\n const nextColor = new AggregationColor(nextColors);\n onChange(nextColor);\n onChangeComplete(nextColor);\n };\n // ============================= Change =============================\n const onInternalChangeComplete = nextValues => {\n onChangeComplete(new AggregationColor(colorList));\n // Reset `activeIndex` if out of range\n if (activeIndex >= nextValues.length) {\n onActive(nextValues.length - 1);\n }\n onGradientDragging(false);\n };\n // ============================= Render =============================\n if (!isGradient) {\n return null;\n }\n return /*#__PURE__*/React.createElement(GradientColorSlider, {\n min: 0,\n max: 100,\n prefixCls: prefixCls,\n className: `${prefixCls}-gradient-slider`,\n colors: colorList,\n color: null,\n value: values,\n range: true,\n onChangeComplete: onInternalChangeComplete,\n disabled: false,\n type: \"gradient\",\n // Active\n activeIndex: activeIndex,\n onActive: onActive,\n // Drag\n onDragStart: onDragStart,\n onDragChange: onDragChange,\n onKeyDelete: onKeyDelete\n });\n};\nexport default /*#__PURE__*/React.memo(GradientColorBar);"],"mappings":"AAAA,YAAY;;AAEZ,OAAOA,kBAAkB,MAAM,8CAA8C;AAC7E,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,gBAAgB,QAAQ,aAAa;AAC9C,SAASC,uBAAuB,QAAQ,YAAY;AACpD,SAASC,mBAAmB,QAAQ,gBAAgB;AACpD,SAASC,UAAUA,CAACC,MAAM,EAAE;EAC1B,OAAON,kBAAkB,CAACM,MAAM,CAAC,CAACC,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACE,OAAO,GAAGD,CAAC,CAACC,OAAO,CAAC;AACzE;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGC,KAAK,IAAI;EAChC,MAAM;IACJC,SAAS;IACTC,IAAI;IACJC,QAAQ;IACRC,gBAAgB;IAChBC,QAAQ;IACRC,WAAW;IACXC,kBAAkB;IAClBb;EACF,CAAC,GAAGM,KAAK;EACT,MAAMQ,UAAU,GAAGN,IAAI,KAAK,UAAU;EACtC;EACA,MAAMO,SAAS,GAAGpB,KAAK,CAACqB,OAAO,CAAC,MAAMhB,MAAM,CAACiB,GAAG,CAACC,IAAI,KAAK;IACxDd,OAAO,EAAEc,IAAI,CAACd,OAAO;IACrBe,KAAK,EAAED,IAAI,CAACC,KAAK,CAACC,WAAW,CAAC;EAChC,CAAC,CAAC,CAAC,EAAE,CAACpB,MAAM,CAAC,CAAC;EACd,MAAMqB,MAAM,GAAG1B,KAAK,CAACqB,OAAO,CAAC,MAAMD,SAAS,CAACE,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACd,OAAO,CAAC,EAAE,CAACW,SAAS,CAAC,CAAC;EACpF;EACA,M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