tdesign-vue
Version:
455 lines (451 loc) • 18.3 kB
JavaScript
/**
* tdesign v1.14.1
* (c) 2025 tdesign
* @license MIT
*/
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, ref, computed, watch } from '@vue/composition-api';
import useCommonClassName from '../../hooks/useCommonClassName.js';
import { useConfig } from '../../config-provider/useConfig.js';
import useDefaultValue from '../../hooks/useDefaultValue.js';
import { useVModel } from '../../hooks/useVModel.js';
import { useBaseClassName } from '../hooks.js';
import props from '../props.js';
import AlphaSlider from './alpha.js';
import FormatPanel from './format/index.js';
import PanelHeader from './header.js';
import HueSlider from './hue.js';
import LinearGradient from './linear-gradient.js';
import SaturationPanel from './saturation.js';
import SwatchesPanel from './swatches.js';
import { DEFAULT_LINEAR_GRADIENT, DEFAULT_COLOR, DEFAULT_SYSTEM_SWATCH_COLORS, TD_COLOR_USED_COLORS_MAX_SIZE } from '../../_common/js/color-picker/constants.js';
import { initColorFormat } from '../../_common/js/color-picker/format.js';
import { Color, getColorObject } from '../../_common/js/color-picker/color.js';
import '../../config-provider/context.js';
import 'lodash-es';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '../../_chunks/dep-ba613a02.js';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-fdb1b253.js';
import 'dayjs';
import '../../_common/js/global-config/t.js';
import '../../hooks/useConfig.js';
import './slider.js';
import '../../select/index.js';
import '../../select/select.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../../hooks/tnode.js';
import '../../hooks/render-tnode.js';
import '../../select/props.js';
import '../../loading/index.js';
import '../../loading/directive.js';
import '../../loading/plugin.js';
import 'vue';
import '../../loading/loading.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/setStyle.js';
import '../../_common/js/utils/helper.js';
import '../../config-provider/config-receiver.js';
import '../../utils/mixins.js';
import '../../utils/dom.js';
import 'raf';
import '../../utils/easing.js';
import '../../utils/render-tnode.js';
import '@babel/runtime/helpers/readOnlyError';
import '../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../config.js';
import '../../utils/withInstall.js';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../utils/helper.js';
import '../../popup/props.js';
import '../../popup/container.js';
import '../../utils/event.js';
import '../../popup/utils.js';
import '../../utils/map-props.js';
import '../../popup/plugin.js';
import '../../_common/js/log/log.js';
import '../../input/index.js';
import '../../input/input.js';
import '../../_chunks/dep-6a4dc7bb.js';
import 'tdesign-icons-vue';
import '../../input/props.js';
import '../../input/input-group.js';
import '../../tag/index.js';
import '../../tag/tag.js';
import 'tinycolor2';
import '../../tag/props.js';
import '../../tag/check-tag.js';
import '../../tag/check-tag-props.js';
import '../../_common/js/common.js';
import '../../tag/check-tag-group.js';
import '../../tag/check-tag-group-props.js';
import '../../select-input/index.js';
import '../../select-input/select-input.js';
import '../../select-input/props.js';
import '../../select-input/useSingle.js';
import '../../select-input/useMultiple.js';
import '../../tag-input/index.js';
import '../../tag-input/tag-input.js';
import '../../tag-input/props.js';
import '../../tag-input/hooks/useTagScroll.js';
import '../../tag-input/useTagList.js';
import '../../tag-input/hooks/useHover.js';
import '../../tag-input/hooks/useDragSorter.js';
import '../../hooks/useGlobalIcon.js';
import '../../select-input/useOverlayInnerStyle.js';
import '../../common-components/fake-arrow.js';
import '../../select/option.js';
import '../../utils/ripple.js';
import '../../select/option-props.js';
import '../../checkbox/index.js';
import '../../checkbox/group.js';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../checkbox/constants.js';
import '../../checkbox/store.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '../../checkbox/hooks/useKeyboardEvent.js';
import '../../hooks/useFormDisabled.js';
import '../../hooks/useElementLazyRender.js';
import '../../_common/js/utils/observe.js';
import '../../checkbox/checkbox-group-props.js';
import '../../hooks/slots.js';
import '../../hooks/useLazyLoad.js';
import '../../select/util.js';
import '../../select/select-panel.js';
import '../../select/optionGroup.js';
import '../../select/option-group-props.js';
import '../../hooks/useVirtualScroll.js';
import '../../select/hooks/useSelectOptions.js';
import './base-props.js';
import '../../_common/js/color-picker/draggable.js';
import './format/inputs.js';
import '../../input-number/index.js';
import '../../input-number/input-number.js';
import '../../button/index.js';
import '../../button/button.js';
import '../../button/props.js';
import '../../input-number/props.js';
import '../../input-number/useInputNumber.js';
import '../../_common/js/input-number/number.js';
import '../../_common/js/input-number/large-number.js';
import '../../radio/index.js';
import '../../radio/radio.js';
import '../../radio/props.js';
import '../../radio/group.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../../radio/radio-group-props.js';
import '../../radio/radio-button.js';
import '../../_common/js/color-picker/cmyk.js';
import '../../_common/js/color-picker/gradient.js';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var ColorPanel = defineComponent({
name: "ColorPanel",
components: {
PanelHeader: PanelHeader,
LinearGradient: LinearGradient,
SaturationPanel: SaturationPanel,
HueSlider: HueSlider,
AlphaSlider: AlphaSlider,
FormatPanel: FormatPanel,
SwatchesPanel: SwatchesPanel
},
props: _objectSpread({}, props),
setup: function setup(props2) {
var baseClassName = useBaseClassName();
var _useCommonClassName = useCommonClassName(),
statusClassNames = _useCommonClassName.statusClassNames;
var _useConfig = useConfig("colorPicker"),
t = _useConfig.t,
global = _useConfig.global;
var _toRefs = toRefs(props2),
inputValue = _toRefs.value,
recentColors = _toRefs.recentColors;
var _useVModel = useVModel(inputValue, props2.defaultValue, props2.onChange, "change"),
_useVModel2 = _slicedToArray(_useVModel, 2),
innerValue = _useVModel2[0],
setInnerValue = _useVModel2[1];
var getModeByColor = function getModeByColor(input) {
if (props2.colorModes.length === 1) return props2.colorModes[0];
return props2.colorModes.includes("linear-gradient") && Color.isGradientColor(input) ? "linear-gradient" : "monochrome";
};
var mode = ref(getModeByColor(innerValue.value));
var isGradient = computed(function () {
return mode.value === "linear-gradient";
});
var defaultEmptyColor = computed(function () {
return isGradient.value ? DEFAULT_LINEAR_GRADIENT : DEFAULT_COLOR;
});
var color = ref(new Color(innerValue.value || defaultEmptyColor.value));
var formatModel = ref(initColorFormat(props2.format, props2.enableAlpha));
var _useDefaultValue = useDefaultValue(recentColors, props2.defaultRecentColors, props2.onRecentColorsChange, "recentColors", "recentColorsChange"),
_useDefaultValue2 = _slicedToArray(_useDefaultValue, 2),
recentlyUsedColors = _useDefaultValue2[0],
setRecentlyUsedColors = _useDefaultValue2[1];
var addRecentlyUsedColor = function addRecentlyUsedColor() {
if (recentlyUsedColors.value === null || recentlyUsedColors.value === false) {
return;
}
var colors = recentlyUsedColors.value || [];
var currentColor = color.value.isGradient ? color.value.linearGradient : color.value.rgba;
var index = colors.indexOf(currentColor);
if (index > -1) {
colors.splice(index, 1);
}
colors.unshift(currentColor);
if (colors.length > TD_COLOR_USED_COLORS_MAX_SIZE) {
colors.length = TD_COLOR_USED_COLORS_MAX_SIZE;
}
handleRecentlyUsedColorsChange(colors);
};
var handleRecentlyUsedColorsChange = function handleRecentlyUsedColorsChange(colors) {
recentlyUsedColors.value = colors;
setRecentlyUsedColors(colors);
};
var emitColorChange = function emitColorChange(trigger) {
var value = color.value.getFormattedColor(props2.format, props2.enableAlpha);
setInnerValue(value, {
color: getColorObject(color.value),
trigger: trigger || "palette-saturation-brightness"
});
};
watch(function () {
return innerValue.value;
}, function (newColor) {
var newMode = getModeByColor(newColor);
mode.value = newMode;
color.value.isGradient = newMode === "linear-gradient";
var currentColor = color.value.getFormattedColor(formatModel.value, props2.enableAlpha);
if (currentColor !== newColor) {
color.value.update(newColor);
}
});
var handleModeChange = function handleModeChange(newMode) {
mode.value = newMode;
var isGradientMode = newMode === "linear-gradient";
color.value.isGradient = isGradientMode;
if (isGradientMode) {
color.value.update(color.value.gradientColors.length > 0 ? color.value.linearGradient : DEFAULT_LINEAR_GRADIENT);
} else {
color.value.update(color.value.rgba);
}
emitColorChange();
};
var handleSatAndValueChange = function handleSatAndValueChange(_ref) {
var saturation = _ref.saturation,
value = _ref.value;
var _color$value = color.value,
sat = _color$value.saturation,
val = _color$value.value;
var changeTrigger = "palette-saturation-brightness";
if (value !== val && saturation !== sat) {
color.value.saturation = saturation;
color.value.value = value;
changeTrigger = "palette-saturation-brightness";
} else if (saturation !== sat) {
color.value.saturation = saturation;
changeTrigger = "palette-saturation";
} else if (value !== val) {
color.value.value = value;
changeTrigger = "palette-brightness";
} else {
return;
}
emitColorChange(changeTrigger);
};
var handleHueChange = function handleHueChange(hue) {
var _props2$onPaletteBarC;
color.value.hue = hue;
emitColorChange("palette-hue-bar");
(_props2$onPaletteBarC = props2.onPaletteBarChange) === null || _props2$onPaletteBarC === void 0 || _props2$onPaletteBarC.call(props2, {
color: getColorObject(color.value)
});
};
var handleAlphaChange = function handleAlphaChange(alpha) {
color.value.alpha = alpha;
emitColorChange("palette-alpha-bar");
};
var handleInputChange = function handleInputChange(input) {
color.value.update(input);
emitColorChange("input");
};
var handleGradientChange = function handleGradientChange(_ref2) {
var key = _ref2.key,
payload = _ref2.payload;
var trigger = "palette-saturation-brightness";
switch (key) {
case "degree":
color.value.gradientDegree = payload;
trigger = "input";
break;
case "selectedId":
color.value.gradientSelectedId = payload;
break;
case "colors":
color.value.gradientColors = payload;
break;
}
emitColorChange(trigger);
};
var handleSetColor = function handleSetColor(value, trigger) {
var newMode = getModeByColor(value);
mode.value = newMode;
color.value.isGradient = newMode === "linear-gradient";
color.value.update(value);
emitColorChange(trigger);
};
var previewColorStyle = computed(function () {
return mode.value === "linear-gradient" ? color.value.linearGradient : color.value.rgba;
});
return {
baseClassName: baseClassName,
statusClassNames: statusClassNames,
t: t,
global: global,
color: color,
mode: mode,
isGradient: isGradient,
formatModel: formatModel,
recentlyUsedColors: recentlyUsedColors,
previewColorStyle: previewColorStyle,
addRecentlyUsedColor: addRecentlyUsedColor,
handleModeChange: handleModeChange,
handleSatAndValueChange: handleSatAndValueChange,
handleHueChange: handleHueChange,
handleAlphaChange: handleAlphaChange,
handleGradientChange: handleGradientChange,
handleSetColor: handleSetColor,
handleInputChange: handleInputChange,
handleRecentlyUsedColorsChange: handleRecentlyUsedColorsChange
};
},
render: function render() {
var _this = this;
var h = arguments[0];
var baseClassName = this.baseClassName,
statusClassNames = this.statusClassNames,
t = this.t,
global = this.global,
swatchColors = this.swatchColors,
previewColorStyle = this.previewColorStyle,
isGradient = this.isGradient,
colorModes = this.colorModes;
var onlySupportGradient = colorModes.length === 1 && colorModes.includes("linear-gradient");
var recentColors = this.recentlyUsedColors;
if (onlySupportGradient && Array.isArray(recentColors)) {
recentColors = recentColors.filter(function (color) {
return Color.isGradientColor(color);
});
}
var showUsedColors = Array.isArray(this.recentlyUsedColors) || this.recentlyUsedColors === true;
var systemColors = swatchColors;
if (systemColors === void 0) {
systemColors = _toConsumableArray(DEFAULT_SYSTEM_SWATCH_COLORS);
}
if (onlySupportGradient) {
var _systemColors;
systemColors = (_systemColors = systemColors) === null || _systemColors === void 0 ? void 0 : _systemColors.filter(function (color) {
return Color.isGradientColor(color);
});
}
var showSystemColors = Array.isArray(systemColors) && systemColors.length > 0;
var renderSwatches = function renderSwatches() {
if (!showSystemColors && !showUsedColors) {
return null;
}
return h("div", {
"class": "".concat(baseClassName, "__swatches-wrap")
}, [showUsedColors ? h("swatches-panel", {
"attrs": {
"color": _this.color,
"disabled": _this.disabled,
"title": t(global.recentColorTitle),
"editable": true,
"colors": _this.recentlyUsedColors,
"handleAddColor": _this.addRecentlyUsedColor,
"handleSetColor": function handleSetColor(color) {
return _this.handleSetColor(color, "recent");
},
"handleChange": _this.handleRecentlyUsedColorsChange
}
}) : null, showSystemColors ? h("swatches-panel", {
"attrs": {
"color": _this.color,
"disabled": _this.disabled,
"title": t(global.swatchColorTitle),
"colors": systemColors,
"handleSetColor": function handleSetColor(color) {
return _this.handleSetColor(color, "preset");
}
}
}) : null]);
};
return h("div", {
"class": ["".concat(baseClassName, "__panel"), this.disabled ? statusClassNames.disabled : false]
}, [h("panel-header", {
"props": _objectSpread({}, _objectSpread({}, this.$props)),
"attrs": {
"mode": this.mode,
"handleModeChange": this.handleModeChange
}
}), h("div", {
"class": ["".concat(baseClassName, "__body")]
}, [isGradient ? h("linear-gradient", {
"attrs": {
"color": this.color,
"disabled": this.disabled,
"handleChange": this.handleGradientChange,
"enableMultipleGradient": this.enableMultipleGradient
}
}) : null, h("saturation-panel", {
"attrs": {
"color": this.color,
"disabled": this.disabled,
"handleChange": this.handleSatAndValueChange
}
}), h("div", {
"class": ["".concat(baseClassName, "__sliders-wrapper")]
}, [h("div", {
"class": ["".concat(baseClassName, "__sliders")]
}, [h("hue-slider", {
"attrs": {
"color": this.color,
"disabled": this.disabled,
"handleChange": this.handleHueChange
}
}), this.enableAlpha ? h("alpha-slider", {
"attrs": {
"color": this.color,
"disabled": this.disabled,
"handleChange": this.handleAlphaChange
}
}) : null]), this.showPrimaryColorPreview ? h("div", {
"class": ["".concat(baseClassName, "__sliders-preview"), "".concat(baseClassName, "--bg-alpha")]
}, [h("span", {
"class": "".concat(baseClassName, "__sliders-preview-inner"),
"style": {
background: previewColorStyle
}
})]) : null]), h("format-panel", {
"props": _objectSpread({}, _objectSpread(_objectSpread({}, this.$props), {}, {
format: this.formatModel
})),
"attrs": {
"color": this.color,
"handleFormatInputChange": this.handleInputChange
}
}), renderSwatches()])]);
}
});
export { ColorPanel as default };
//# sourceMappingURL=index.js.map