UNPKG

tdesign-vue-next

Version:
133 lines (129 loc) 4.55 kB
/** * tdesign v1.13.2 * (c) 2025 tdesign * @license MIT */ import { defineComponent, ref, reactive, computed, nextTick, onMounted, onBeforeUnmount, createVNode } from 'vue'; import { S as SATURATION_PANEL_DEFAULT_WIDTH, d as SATURATION_PANEL_DEFAULT_HEIGHT } from '../../../_chunks/dep-17f1b91e.mjs'; import '../../utils/index.mjs'; import { useBaseClassName } from '../../hooks/index.mjs'; import baseProps from './base-props.mjs'; import { D as Draggable } from '../../../_chunks/dep-db7af4ee.mjs'; import '../../../_chunks/dep-9c4aef07.mjs'; import 'lodash-es'; import '../../../_chunks/dep-b981148e.mjs'; import '../../../_chunks/dep-f1895f5a.mjs'; import '../../../_chunks/dep-a81129ec.mjs'; import '../../../utils/render-tnode.mjs'; import '../../../config-provider/hooks/useConfig.mjs'; import '../../../config-provider/utils/context.mjs'; import '../../../_chunks/dep-466a0666.mjs'; import '../../../_chunks/dep-24ce1cec.mjs'; import '../../../_chunks/dep-160caab6.mjs'; import '../../../_chunks/dep-e497214e.mjs'; import '../../../_chunks/dep-98cd1e2d.mjs'; import '../../../_chunks/dep-23a929e8.mjs'; import '../../../_chunks/dep-48e13ca0.mjs'; import '../../../_chunks/dep-033df8e6.mjs'; import '../../../utils/dom.mjs'; import '../../../_chunks/dep-20550dcc.mjs'; import '../../../_chunks/dep-0bb39574.mjs'; import '../../../_chunks/dep-34116a33.mjs'; var SaturationPanel = defineComponent({ name: "SaturationPanel", props: baseProps, setup: function setup(props) { var baseClassName = useBaseClassName(); var refPanel = ref(null); var refThumb = ref(null); var dragInstance = ref(null); var panelRect = reactive({ width: SATURATION_PANEL_DEFAULT_WIDTH, height: SATURATION_PANEL_DEFAULT_HEIGHT }); var styles = 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; } nextTick(function () { handleDrag(coordinate, true); }); }; var panelBackground = computed(function () { return "hsl(".concat(props.color.hue, ", 100%, 50%)"); }); onMounted(function () { panelRect.width = refPanel.value.offsetWidth || SATURATION_PANEL_DEFAULT_WIDTH; panelRect.height = refPanel.value.offsetHeight || SATURATION_PANEL_DEFAULT_HEIGHT; dragInstance.value = new Draggable(refPanel.value, { start: function start() { panelRect.width = refPanel.value.offsetWidth; panelRect.height = refPanel.value.offsetHeight; }, drag: function drag(coordinate) { handleDrag(coordinate); }, end: handleDragEnd }); }); onBeforeUnmount(function () { dragInstance.value.destroy(); }); return function () { return createVNode("div", { "class": ["".concat(baseClassName.value, "__saturation")], "ref": refPanel, "style": { background: panelBackground.value } }, [createVNode("span", { "class": ["".concat(baseClassName.value, "__thumb")], "role": "slider", "tabindex": 0, "ref": refThumb, "style": styles.value }, null)]); }; } }); export { SaturationPanel as default }; //# sourceMappingURL=saturation.mjs.map