tdesign-vue-next
Version:
TDesign Component for vue-next
153 lines (147 loc) • 5.41 kB
JavaScript
/**
* tdesign v1.20.0
* (c) 2026 tdesign
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var Vue = require('vue');
var constants = require('../../../_chunks/dep-b85d60b6.js');
require('../../../_chunks/dep-9441b4d3.js');
var draggable = require('../../../_chunks/dep-1fd238cc.js');
require('@babel/runtime/helpers/toConsumableArray');
var colorPicker_hooks_index = require('../../hooks/index.js');
var colorPicker_components_panel_baseProps = require('./base-props.js');
require('@babel/runtime/helpers/slicedToArray');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('@babel/runtime/helpers/defineProperty');
require('tinycolor2');
require('../../../_chunks/dep-f549ecb7.js');
require('../../../_chunks/dep-caa8987f.js');
require('@babel/runtime/helpers/typeof');
require('../../../_chunks/dep-8e3205d4.js');
require('../../../_chunks/dep-67d3c773.js');
require('../../../_chunks/dep-0e867224.js');
require('../../../_chunks/dep-b3ef977e.js');
require('../../../_chunks/dep-b9c82189.js');
require('../../../config-provider/hooks/useConfig.js');
require('../../../_chunks/dep-a64c9b8c.js');
require('../../../_chunks/dep-aafbacfe.js');
require('dayjs');
require('../../../_chunks/dep-c539b8cf.js');
require('../../../_chunks/dep-bd404105.js');
require('../../../_chunks/dep-5ed96ff4.js');
require('../../../_chunks/dep-cd6733fb.js');
require('../../../_chunks/dep-5c730151.js');
require('../../../_chunks/dep-b937ef62.js');
require('../../../_chunks/dep-0ad5a5a6.js');
require('../../../_chunks/dep-68ca5b5a.js');
require('../../../_chunks/dep-ce54d478.js');
require('../../../_chunks/dep-9b493151.js');
require('../../../_chunks/dep-933eb47e.js');
require('../../../_chunks/dep-01e6d254.js');
require('../../../_chunks/dep-d3fa0c96.js');
require('../../../_chunks/dep-5a252af6.js');
require('../../../_chunks/dep-f4839f43.js');
require('../../../_chunks/dep-330e6dfc.js');
require('../../../_chunks/dep-af55a921.js');
require('../../../_chunks/dep-ce392f73.js');
var SaturationPanel = Vue.defineComponent({
name: "SaturationPanel",
props: colorPicker_components_panel_baseProps["default"],
setup: function setup(props) {
var baseClassName = colorPicker_hooks_index.useBaseClassName();
var refPanel = Vue.ref();
var refThumb = Vue.ref(null);
var dragInstance = Vue.ref(null);
var panelRect = Vue.reactive({
width: constants.SATURATION_PANEL_DEFAULT_WIDTH,
height: constants.SATURATION_PANEL_DEFAULT_HEIGHT
});
var styles = Vue.computed(function () {
var _props$color = props.color,
saturation = _props$color.saturation,
value = _props$color.value;
var width = panelRect.width,
height = panelRect.height;
var top = Math.round((1 - value) * height);
var left = Math.round(saturation * width);
return {
color: props.color.rgb,
left: "".concat(left, "px"),
top: "".concat(top, "px")
};
});
var getSaturationAndValueByCoordinate = function getSaturationAndValueByCoordinate(coordinate) {
var width = panelRect.width,
height = panelRect.height;
var x = coordinate.x,
y = coordinate.y;
var saturation = Math.round(x / width * 100);
var value = Math.round((1 - y / height) * 100);
return {
saturation: saturation,
value: value
};
};
var handleDrag = function handleDrag(coordinate, isEnded) {
if (props.disabled) {
return;
}
var _getSaturationAndValu = getSaturationAndValueByCoordinate(coordinate),
saturation = _getSaturationAndValu.saturation,
value = _getSaturationAndValu.value;
props.onChange({
saturation: saturation / 100,
value: value / 100,
addUsedColor: isEnded
});
};
var handleDragEnd = function handleDragEnd(coordinate) {
if (props.disabled) {
return;
}
Vue.nextTick(function () {
handleDrag(coordinate, true);
});
};
var panelBackground = Vue.computed(function () {
return "hsl(".concat(props.color.hue, ", 100%, 50%)");
});
Vue.onMounted(function () {
panelRect.width = refPanel.value.offsetWidth || constants.SATURATION_PANEL_DEFAULT_WIDTH;
panelRect.height = refPanel.value.offsetHeight || constants.SATURATION_PANEL_DEFAULT_HEIGHT;
dragInstance.value = new draggable.Draggable(refPanel.value, {
start: function start() {
panelRect.width = refPanel.value.offsetWidth;
panelRect.height = refPanel.value.offsetHeight;
},
drag: function drag(coordinate) {
handleDrag(coordinate);
},
end: handleDragEnd
});
});
Vue.onBeforeUnmount(function () {
dragInstance.value.destroy();
});
return function () {
return Vue.createVNode("div", {
"class": ["".concat(baseClassName.value, "__saturation")],
"ref": refPanel,
"style": {
background: panelBackground.value
}
}, [Vue.createVNode("span", {
"class": ["".concat(baseClassName.value, "__thumb")],
"role": "slider",
"tabindex": 0,
"ref": refThumb,
"style": styles.value
}, null)]);
};
}
});
exports["default"] = SaturationPanel;
//# sourceMappingURL=saturation.js.map