/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
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('../config-provider/useConfig.js');
require('../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../hooks/render-tnode.js');
require('lodash/isString');
require('lodash/isObject');
require('@babel/runtime/helpers/objectWithoutProperties');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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__default["default"](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 _Watermark = VueCompositionAPI.defineComponent({
  name: "TWatermark",
  props: watermark_props["default"],
  setup: function setup(props2) {
    var backgroundImage = VueCompositionAPI.ref("");
    var watermarkRef = VueCompositionAPI.ref();
    var watermarkContentRef = VueCompositionAPI.ref();
    var parent = VueCompositionAPI.ref();
    var gapX = VueCompositionAPI.computed(function () {
      return props2.movable ? 0 : props2.x;
    });
    var gapY = VueCompositionAPI.computed(function () {
      return props2.movable ? 0 : props2.y;
    });
    var rotate = VueCompositionAPI.computed(function () {
      return props2.movable ? 0 : props2.rotate;
    });
    var backgroundRepeat = VueCompositionAPI.computed(function () {
      if (props2.movable) {
        return "no-repeat";
      }

      return props2.isRepeat ? "repeat" : "no-repeat";
    });
    var offsetLeft = VueCompositionAPI.computed(function () {
      var _props2$offset;

      return ((_props2$offset = props2.offset) === null || _props2$offset === void 0 ? void 0 : _props2$offset[0]) || gapX.value / 2;
    });
    var offsetTop = VueCompositionAPI.computed(function () {
      var _props2$offset2;

      return ((_props2$offset2 = props2.offset) === null || _props2$offset2 === void 0 ? void 0 : _props2$offset2[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
    };
    VueCompositionAPI.onMounted(function () {
      var _watermarkRef$value;

      _common_js_watermark_generateBase64Url["default"](bgImageOptions, function (base64Url) {
        backgroundImage.value = base64Url;
      });
      parent.value = (_watermarkRef$value = watermarkRef.value) === null || _watermarkRef$value === void 0 ? void 0 : _watermarkRef$value.parentElement;
      var keyframesStyle = _common_js_watermark_randomMovingStyle["default"]();
      _common_js_utils_injectStyle["default"](keyframesStyle);
      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
      });
    });
    return {
      gapX: gapX,
      gapY: gapY,
      backgroundRepeat: backgroundRepeat,
      backgroundImage: backgroundImage,
      watermarkRef: watermarkRef,
      watermarkContentRef: watermarkContentRef,
      bgImageOptions: bgImageOptions
    };
  },
  watch: {
    watermarkContent: function watermarkContent(content) {
      var _this = this;

      _common_js_watermark_generateBase64Url["default"](_objectSpread(_objectSpread({}, this.bgImageOptions), {}, {
        watermarkContent: content
      }), function (base64Url) {
        _this.backgroundImage = base64Url;
      });
    }
  },
  render: function render() {
    var h = arguments[0];
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("watermark");
    var renderContent = hooks_tnode.useContent();
    return h("div", {
      "style": {
        position: "relative",
        overflow: "hidden",
        width: "100%"
      },
      "class": COMPONENT_NAME.value,
      "ref": "watermarkRef"
    }, [renderContent("default", "content"), h("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"
      }
    })]);
  }
});

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