/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _defineProperty } from '../../_chunks/dep-2db7b3ec.mjs';
import { defineComponent, ref, reactive, computed, nextTick, onMounted, onBeforeUnmount, createVNode } from 'vue';
import '../const.mjs';
import '../utils/index.mjs';
import { useBaseClassName } from '../hooks.mjs';
import baseProps from './base-props.mjs';
import { SATURATION_PANEL_DEFAULT_WIDTH, SATURATION_PANEL_DEFAULT_HEIGHT } from '../../_common/js/color-picker/constants.mjs';
import { Draggable } from '../../_common/js/color-picker/draggable.mjs';
import '../../_chunks/dep-255303ba.mjs';
import '../../_common/js/color-picker/index.mjs';
import '../../_common/js/color-picker/cmyk.mjs';
import '../../_common/js/color-picker/color.mjs';
import '../../_chunks/dep-84acf3c2.mjs';
import '../../_chunks/dep-b8d7992c.mjs';
import '../../_chunks/dep-ccbc47f4.mjs';
import '../../_chunks/dep-9ac6ced8.mjs';
import '../../_common/js/color-picker/gradient.mjs';
import '../../_chunks/dep-876fb3ec.mjs';
import '../../_chunks/dep-eba0ea6e.mjs';
import '../../_chunks/dep-469b4ae0.mjs';
import '../../_chunks/dep-b57180d0.mjs';
import '../../_chunks/dep-c8d7b6b4.mjs';
import '../../_chunks/dep-3da99438.mjs';
import '../../_chunks/dep-ed5ebb35.mjs';
import '../../hooks/useConfig.mjs';
import '../../config-provider/useConfig.mjs';
import '../../_chunks/dep-095107f7.mjs';
import '../../_chunks/dep-c989dff3.mjs';
import '../../_chunks/dep-9cf86cf1.mjs';
import '../../_chunks/dep-bc1d737a.mjs';
import '../../_chunks/dep-4d7a675b.mjs';
import '../../_chunks/dep-5717e263.mjs';
import '../../_chunks/dep-a8bcacea.mjs';
import '../../_chunks/dep-2e7f59b1.mjs';
import '../../_chunks/dep-855db8bc.mjs';
import '../../_chunks/dep-a87f3e4c.mjs';
import '../../_chunks/dep-1e566bb5.mjs';
import '../../_chunks/dep-1434aa15.mjs';
import '../../_chunks/dep-e5eb9f23.mjs';
import '../../_chunks/dep-9fe2ef12.mjs';
import '../../_chunks/dep-672e7d1a.mjs';
import '../../_chunks/dep-42a19209.mjs';
import '../../_chunks/dep-9262ee2f.mjs';
import '../../_chunks/dep-334a4f6b.mjs';
import '../../_chunks/dep-8d3e9aa3.mjs';
import '../../_chunks/dep-40d69a9c.mjs';
import '../../_chunks/dep-dcc83161.mjs';
import '../../_chunks/dep-0fc02184.mjs';
import '../../_chunks/dep-f1994936.mjs';
import '../../_chunks/dep-345e1be3.mjs';
import '../../_common/js/global-config/default-config.mjs';
import '../../_common/js/global-config/locale/zh_CN.mjs';
import '../../_chunks/dep-9888611c.mjs';
import '../../_chunks/dep-697a1365.mjs';
import '../../config-provider/type.mjs';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var SaturationPanel = defineComponent({
  name: "SaturationPanel",
  props: _objectSpread({}, 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 {
      baseClassName: baseClassName,
      refThumb: refThumb,
      refPanel: refPanel,
      styles: styles,
      panelBackground: panelBackground
    };
  },
  render: function render() {
    var baseClassName = this.baseClassName,
      styles = this.styles,
      panelBackground = this.panelBackground;
    return createVNode("div", {
      "class": ["".concat(baseClassName, "__saturation")],
      "ref": "refPanel",
      "style": {
        background: panelBackground
      }
    }, [createVNode("span", {
      "class": ["".concat(baseClassName, "__thumb")],
      "role": "slider",
      "tabindex": 0,
      "ref": "refThumb",
      "style": styles
    }, null)]);
  }
});

export { SaturationPanel as default };
//# sourceMappingURL=saturation.mjs.map
