a4d456367c9bc1859c6c7791095c7f14308d11cdd76fa2ab43603717142284143eb5210965d044df63cc88112f5a770b3e8c92deaa1de0283f72cec084e0b3 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var draggable = require('../utils/draggable.js');
  5. var pluginVue_exportHelper = require('../../../../_virtual/plugin-vue_export-helper.js');
  6. var index = require('../../../../hooks/use-namespace/index.js');
  7. var position = require('../../../../utils/dom/position.js');
  8. const _sfc_main = vue.defineComponent({
  9. name: "ElSlPanel",
  10. props: {
  11. color: {
  12. type: Object,
  13. required: true
  14. },
  15. disabled: Boolean
  16. },
  17. setup(props) {
  18. const ns = index.useNamespace("color-svpanel");
  19. const instance = vue.getCurrentInstance();
  20. const cursorTop = vue.ref(0);
  21. const cursorLeft = vue.ref(0);
  22. const background = vue.ref("hsl(0, 100%, 50%)");
  23. const colorValue = vue.computed(() => {
  24. const hue = props.color.get("hue");
  25. const value = props.color.get("value");
  26. return { hue, value };
  27. });
  28. function update() {
  29. const saturation = props.color.get("saturation");
  30. const value = props.color.get("value");
  31. const el = instance.vnode.el;
  32. const { clientWidth: width, clientHeight: height } = el;
  33. cursorLeft.value = saturation * width / 100;
  34. cursorTop.value = (100 - value) * height / 100;
  35. background.value = `hsl(${props.color.get("hue")}, 100%, 50%)`;
  36. }
  37. function handleDrag(event) {
  38. if (props.disabled)
  39. return;
  40. const el = instance.vnode.el;
  41. const rect = el.getBoundingClientRect();
  42. const { clientX, clientY } = position.getClientXY(event);
  43. let left = clientX - rect.left;
  44. let top = clientY - rect.top;
  45. left = Math.max(0, left);
  46. left = Math.min(left, rect.width);
  47. top = Math.max(0, top);
  48. top = Math.min(top, rect.height);
  49. cursorLeft.value = left;
  50. cursorTop.value = top;
  51. props.color.set({
  52. saturation: left / rect.width * 100,
  53. value: 100 - top / rect.height * 100
  54. });
  55. }
  56. vue.watch(() => colorValue.value, () => {
  57. update();
  58. });
  59. vue.onMounted(() => {
  60. draggable.draggable(instance.vnode.el, {
  61. drag: (event) => {
  62. handleDrag(event);
  63. },
  64. end: (event) => {
  65. handleDrag(event);
  66. }
  67. });
  68. update();
  69. });
  70. return {
  71. cursorTop,
  72. cursorLeft,
  73. background,
  74. colorValue,
  75. handleDrag,
  76. update,
  77. ns
  78. };
  79. }
  80. });
  81. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  82. return vue.openBlock(), vue.createElementBlock("div", {
  83. class: vue.normalizeClass(_ctx.ns.b()),
  84. style: vue.normalizeStyle({
  85. backgroundColor: _ctx.background
  86. })
  87. }, [
  88. vue.createElementVNode("div", {
  89. class: vue.normalizeClass(_ctx.ns.e("white"))
  90. }, null, 2),
  91. vue.createElementVNode("div", {
  92. class: vue.normalizeClass(_ctx.ns.e("black"))
  93. }, null, 2),
  94. vue.createElementVNode("div", {
  95. class: vue.normalizeClass(_ctx.ns.e("cursor")),
  96. style: vue.normalizeStyle({
  97. top: _ctx.cursorTop + "px",
  98. left: _ctx.cursorLeft + "px"
  99. })
  100. }, [
  101. vue.createElementVNode("div")
  102. ], 6)
  103. ], 6);
  104. }
  105. var SvPanel = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "sv-panel.vue"]]);
  106. exports["default"] = SvPanel;
  107. //# sourceMappingURL=sv-panel.js.map