'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../hooks/index.js');
var index$1 = require('../../dialog/index.js');
var uploadCropper = require('./upload-cropper2.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var index = require('../../../hooks/use-namespace/index.js');

const _hoisted_1 = ["src"];
const _hoisted_2 = ["src"];
const __default__ = vue.defineComponent({
  name: "ElCropper"
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...__default__,
  props: uploadCropper.cropperProps,
  emits: uploadCropper.croppersEmits,
  setup(__props, { emit }) {
    const props = __props;
    const ns = index.useNamespace("cropper");
    const clippingNs = index.useNamespace("cropper-clipping");
    const previewNs = index.useNamespace("cropper-preview");
    const {
      createImgUrl,
      isShowDialog,
      previewImgStyle,
      shadeStyle,
      sourImgStyle,
      scalingRatio,
      canvasRef,
      startMoveImg,
      moveImg,
      zoomImg,
      data2blob,
      createImg,
      sourImgUrl
    } = uploadCropper.useCropper(props);
    const handleClose = () => {
      emit("update:modelValue", false);
    };
    const confirm = () => {
      if (!sourImgUrl.value || !createImgUrl.value) {
        return;
      }
      const blob = data2blob(createImgUrl.value);
      if (blob) {
        emit("cropUploadSuccess", blob);
        handleClose();
      }
    };
    const preventDefault = (e) => {
      e.preventDefault();
      return false;
    };
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(vue.unref(index$1.ElDialog), {
        modelValue: vue.unref(isShowDialog),
        "onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => vue.isRef(isShowDialog) ? isShowDialog.value = $event : null),
        title: "\u56FE\u7247\u526A\u5207",
        "before-close": handleClose,
        width: "580px",
        "submit-handle": confirm
      }, {
        default: vue.withCtx(() => [
          vue.createElementVNode("div", {
            class: vue.normalizeClass(vue.unref(ns).b())
          }, [
            vue.createElementVNode("div", {
              class: vue.normalizeClass(vue.unref(clippingNs).b())
            }, [
              vue.createElementVNode("div", {
                class: vue.normalizeClass(vue.unref(clippingNs).e("picture"))
              }, [
                vue.createElementVNode("img", {
                  class: vue.normalizeClass(vue.unref(clippingNs).e("picture-img")),
                  src: vue.unref(sourImgUrl),
                  style: vue.normalizeStyle(vue.unref(sourImgStyle)),
                  draggable: "false",
                  onDrag: preventDefault,
                  onDragstart: preventDefault,
                  onDragend: preventDefault,
                  onDragleave: preventDefault,
                  onDragover: preventDefault,
                  onDragenter: preventDefault,
                  onMousedown: _cache[0] || (_cache[0] = (...args) => vue.unref(startMoveImg) && vue.unref(startMoveImg)(...args)),
                  onMousemove: _cache[1] || (_cache[1] = (...args) => vue.unref(moveImg) && vue.unref(moveImg)(...args)),
                  onMouseup: _cache[2] || (_cache[2] = (...args) => vue.unref(createImg) && vue.unref(createImg)(...args)),
                  onMouseout: _cache[3] || (_cache[3] = (...args) => vue.unref(createImg) && vue.unref(createImg)(...args))
                }, null, 46, _hoisted_1),
                vue.createElementVNode("div", {
                  class: vue.normalizeClass([
                    vue.unref(clippingNs).e("picture-shade"),
                    vue.unref(clippingNs).em("picture-shade", "left")
                  ]),
                  style: vue.normalizeStyle(vue.unref(shadeStyle))
                }, null, 6),
                vue.createElementVNode("div", {
                  class: vue.normalizeClass([
                    vue.unref(clippingNs).e("picture-shade"),
                    vue.unref(clippingNs).em("picture-shade", "right")
                  ]),
                  style: vue.normalizeStyle(vue.unref(shadeStyle))
                }, null, 6)
              ], 2),
              vue.createElementVNode("div", {
                class: vue.normalizeClass(vue.unref(clippingNs).e("range"))
              }, [
                vue.withDirectives(vue.createElementVNode("input", {
                  "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => vue.isRef(scalingRatio) ? scalingRatio.value = $event : null),
                  type: "range",
                  step: 1,
                  min: 0,
                  max: 100,
                  class: vue.normalizeClass(vue.unref(clippingNs).e("range-input"))
                }, null, 2), [
                  [vue.vModelText, vue.unref(scalingRatio)]
                ]),
                vue.createElementVNode("span", {
                  class: vue.normalizeClass(vue.unref(clippingNs).e("range-track"))
                }, null, 2),
                vue.createElementVNode("i", {
                  class: vue.normalizeClass([
                    vue.unref(clippingNs).e("range-icon"),
                    vue.unref(clippingNs).em("range-icon", "plus")
                  ]),
                  onClick: _cache[5] || (_cache[5] = ($event) => vue.unref(zoomImg)(-1))
                }, null, 2),
                vue.createElementVNode("i", {
                  class: vue.normalizeClass([
                    vue.unref(clippingNs).e("range-icon"),
                    vue.unref(clippingNs).em("range-icon", "minus")
                  ]),
                  onClick: _cache[6] || (_cache[6] = ($event) => vue.unref(zoomImg)(-2))
                }, null, 2)
              ], 2)
            ], 2),
            vue.createElementVNode("div", {
              class: vue.normalizeClass(vue.unref(previewNs).b())
            }, [
              vue.createElementVNode("div", {
                class: vue.normalizeClass(vue.unref(previewNs).e("title"))
              }, "\u56FE\u7247\u9884\u89C8\uFF1A", 2),
              vue.unref(createImgUrl) !== "" ? (vue.openBlock(), vue.createElementBlock("img", {
                key: 0,
                src: vue.unref(createImgUrl),
                style: vue.normalizeStyle(vue.unref(previewImgStyle))
              }, null, 12, _hoisted_2)) : vue.createCommentVNode("v-if", true)
            ], 2)
          ], 2),
          vue.withDirectives(vue.createElementVNode("canvas", {
            ref_key: "canvasRef",
            ref: canvasRef
          }, null, 512), [
            [vue.vShow, false]
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
});
var UploadCropper = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "/Users/judai/code/d-element-plus/packages/components/upload/src/upload-cropper.vue"]]);

exports["default"] = UploadCropper;
//# sourceMappingURL=upload-cropper.js.map
