UNPKG

tdesign-vue-next

Version:
150 lines (144 loc) 5.28 kB
/** * tdesign v1.20.2 * (c) 2026 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var Vue = require('vue'); var constants = require('../../../_chunks/dep-5a84661a.js'); require('../../../_chunks/dep-25a2fcb0.js'); var draggable = require('../../../_chunks/dep-8fa69637.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-df5442c5.js'); require('@babel/runtime/helpers/typeof'); require('../../../_chunks/dep-3ffe18b0.js'); require('../../../_chunks/dep-449273df.js'); require('../../../_chunks/dep-f9b59444.js'); require('../../../_chunks/dep-95cb1381.js'); require('../../../config-provider/hooks/useConfig.js'); require('../../../_chunks/dep-31abb282.js'); require('../../../_chunks/dep-c71a9cd7.js'); require('dayjs'); require('../../../_chunks/dep-39529ef1.js'); require('../../../_chunks/dep-f4c1cb5b.js'); require('../../../_chunks/dep-4896d30f.js'); require('../../../_chunks/dep-80827572.js'); require('../../../_chunks/dep-2610df9f.js'); require('../../../_chunks/dep-2c7a67b8.js'); require('../../../_chunks/dep-db6459dd.js'); require('../../../_chunks/dep-4d7a3a91.js'); require('../../../_chunks/dep-6e64ef0e.js'); require('../../../_chunks/dep-959f4847.js'); require('../../../_chunks/dep-ae380218.js'); require('../../../_chunks/dep-fdac7521.js'); require('../../../_chunks/dep-141cbae1.js'); require('../../../_chunks/dep-c277c7cb.js'); require('../../../_chunks/dep-7653f80f.js'); require('../../../_chunks/dep-6e7a2100.js'); require('../../../_chunks/dep-497fc9a5.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