/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var config = require('../../config.js');
var utils_setStyle = require('../../utils/set-style.js');

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

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

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 name = "".concat(config.prefix, "-loading__gradient");
var classname = "".concat(config.prefix, "-icon-loading");
var GradientIcon = Vue__default["default"].extend({
  name: name,
  mounted: function mounted() {
    var _this = this;

    this.$nextTick(function () {
      _this.updateColor();
    });
  },
  updated: function updated() {
    this.updateColor();
  },
  methods: {
    updateColor: function updateColor() {
      var _window, _window$navigator;

      var basicStyle = {};
      var circleElem = this.$refs.circle;

      if (!circleElem) {
        return;
      }

      var _window$getComputedSt = window.getComputedStyle(circleElem),
          color = _window$getComputedSt.color,
          fontSize = _window$getComputedSt.fontSize;

      var ua = (_window = window) === null || _window === void 0 ? void 0 : (_window$navigator = _window.navigator) === null || _window$navigator === void 0 ? void 0 : _window$navigator.userAgent;
      var isSafari = /Safari/.test(ua) && !/Chrome/.test(ua);

      if (isSafari) {
        basicStyle = {
          transformOrigin: "-1px -1px",
          transform: "scale(".concat(parseInt(fontSize, 10) / 14, ")")
        };
      }

      if (color) {
        var matched = color.match(/[\d.]+/g);
        var endColor = "rgba(".concat(matched[0], ", ").concat(matched[1], ", ").concat(matched[2], ", 0)");
        utils_setStyle["default"](circleElem, _objectSpread(_objectSpread({}, basicStyle), {}, {
          background: "conic-gradient(from 90deg at 50% 50%,".concat(endColor, " 0deg, ").concat(color, " 360deg)")
        }));
      } else {
        utils_setStyle["default"](circleElem, _objectSpread(_objectSpread({}, basicStyle), {}, {
          background: ""
        }));
      }
    }
  },
  render: function render() {
    var h = arguments[0];
    var classes = [name, classname];
    return h("svg", {
      "class": classes,
      "attrs": {
        "viewBox": "0 0 14 14",
        "version": "1.1",
        "width": "1em",
        "height": "1em",
        "xmlns": "http://www.w3.org/2000/svg"
      }
    }, [h("foreignObject", {
      "attrs": {
        "x": "1",
        "y": "1",
        "width": "12",
        "height": "12"
      }
    }, [h("div", {
      "class": "".concat(name, "-conic"),
      "ref": "circle"
    })])]);
  }
});

exports["default"] = GradientIcon;
//# sourceMappingURL=gradient.js.map
