UNPKG

tdesign-vue-next

Version:
153 lines (147 loc) 5.41 kB
/** * tdesign v1.20.5 * (c) 2026 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var Vue = require('vue'); var constants = require('../../../_chunks/dep-4314be62.js'); require('../../../_chunks/dep-5345f800.js'); var draggable = require('../../../_chunks/dep-d06c3521.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-68db1aaa.js'); require('../../../_chunks/dep-769d7974.js'); require('@babel/runtime/helpers/typeof'); require('../../../_chunks/dep-623344fa.js'); require('../../../_chunks/dep-7ea4d038.js'); require('../../../_chunks/dep-585d6c94.js'); require('../../../_chunks/dep-cd7082a8.js'); require('../../../_chunks/dep-b1d94383.js'); require('../../../config-provider/hooks/useConfig.js'); require('../../../_chunks/dep-c4cfd635.js'); require('../../../_chunks/dep-d126d743.js'); require('dayjs'); require('../../../_chunks/dep-96f790a8.js'); require('../../../_chunks/dep-a8736751.js'); require('../../../_chunks/dep-33b91282.js'); require('../../../_chunks/dep-2d37d5cd.js'); require('../../../_chunks/dep-1afc7792.js'); require('../../../_chunks/dep-8dbc3afe.js'); require('../../../_chunks/dep-c2be3f4f.js'); require('../../../_chunks/dep-d22c1428.js'); require('../../../_chunks/dep-4c389805.js'); require('../../../_chunks/dep-b23043e8.js'); require('../../../_chunks/dep-4236e391.js'); require('../../../_chunks/dep-761a1054.js'); require('../../../_chunks/dep-4ba8d64f.js'); require('../../../_chunks/dep-2a3acdc6.js'); require('../../../_chunks/dep-34f739da.js'); require('../../../_chunks/dep-6b6b1c14.js'); require('../../../_chunks/dep-6a34d9fa.js'); require('../../../_chunks/dep-baf36d63.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