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

'use strict';

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

var vue = require('vue');
var _common_js_watermark_generateBase64Url = require('../_common/js/watermark/generateBase64Url.js');
var _common_js_watermark_randomMovingStyle = require('../_common/js/watermark/randomMovingStyle.js');
var _common_js_utils_injectStyle = require('../_common/js/utils/injectStyle.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var watermark_hooks = require('./hooks.js');
var watermark_props = require('./props.js');
require('@babel/runtime/helpers/defineProperty');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('@babel/runtime/helpers/objectWithoutProperties');

var _Watermark = vue.defineComponent({
  name: "TWatermark",
  props: watermark_props["default"],
  setup: function setup(props2) {
    var backgroundImage = vue.ref("");
    var watermarkRef = vue.ref();
    var watermarkContentRef = vue.ref();
    var parent = vue.ref();
    var offset = vue.reactive(props2.offset || []);
    var gapX = vue.computed(function () {
      return props2.movable ? 0 : props2.x;
    });
    var gapY = vue.computed(function () {
      return props2.movable ? 0 : props2.y;
    });
    var rotate = vue.computed(function () {
      return props2.movable ? 0 : props2.rotate;
    });
    var backgroundRepeat = vue.computed(function () {
      if (props2.movable) return "no-repeat";
      return props2.isRepeat ? "repeat" : "no-repeat";
    });
    var offsetLeft = vue.computed(function () {
      return offset[0] || gapX.value / 2;
    });
    var offsetTop = vue.computed(function () {
      return offset[1] || gapY.value / 2;
    });
    var bgImageOptions = {
      width: props2.width,
      height: props2.height,
      rotate: rotate.value,
      lineSpace: props2.lineSpace,
      alpha: props2.alpha,
      gapX: gapX.value,
      gapY: gapY.value,
      watermarkContent: props2.watermarkContent,
      offsetLeft: offsetLeft.value,
      offsetTop: offsetTop.value
    };
    var injectWaterMark = function injectWaterMark() {
      _common_js_watermark_generateBase64Url["default"](bgImageOptions, function (base64Url) {
        backgroundImage.value = base64Url;
      });
      var keyframesStyle = _common_js_watermark_randomMovingStyle["default"]();
      _common_js_utils_injectStyle["default"](keyframesStyle);
    };
    vue.onMounted(function () {
      injectWaterMark();
      parent.value = watermarkRef.value.parentElement;
      watermark_hooks.useMutationObserver(parent.value, function (mutations) {
        if (props2.removable) return;
        mutations.forEach(function (mutation) {
          if (mutation.type === "childList") {
            var removeNodes = mutation.removedNodes;
            removeNodes.forEach(function (node) {
              var element = node;
              if (element === watermarkRef.value) parent.value.appendChild(element);
              if (element === watermarkContentRef.value) watermarkRef.value.appendChild(element);
            });
          }
        });
      }, {
        attributes: true,
        childList: true,
        characterData: true,
        subtree: true
      });
    });
    vue.watch(function () {
      return props2.watermarkContent;
    }, injectWaterMark, {
      deep: true
    });
    return {
      gapX: gapX,
      gapY: gapY,
      backgroundRepeat: backgroundRepeat,
      backgroundImage: backgroundImage,
      watermarkRef: watermarkRef,
      watermarkContentRef: watermarkContentRef,
      bgImageOptions: bgImageOptions
    };
  },
  render: function render() {
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("watermark");
    var renderContent = hooks_tnode.useContent();
    return vue.createVNode("div", {
      "style": {
        position: "relative",
        overflow: "hidden",
        width: "100%"
      },
      "class": COMPONENT_NAME.value,
      "ref": "watermarkRef"
    }, [renderContent("default", "content"), vue.createVNode("div", {
      "ref": "watermarkContentRef",
      "style": {
        zIndex: this.zIndex,
        position: "absolute",
        left: 0,
        right: 0,
        top: 0,
        bottom: 0,
        width: "100%",
        height: "100%",
        backgroundSize: "".concat(this.gapX + this.width, "px"),
        pointerEvents: "none",
        backgroundRepeat: this.backgroundRepeat,
        backgroundImage: "url('".concat(this.backgroundImage, "')"),
        animation: this.movable ? "watermark infinite ".concat(this.moveInterval * 4 / 60, "s") : "none"
      }
    }, null)]);
  }
});

exports["default"] = _Watermark;
//# sourceMappingURL=watermark.js.map
