1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = exports.handleGradient = exports.sortGradient = void 0;
|
7 |
|
8 | var _vue = require("vue");
|
9 |
|
10 | var _utils = require("./utils");
|
11 |
|
12 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
13 |
|
14 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
15 |
|
16 | function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
17 |
|
18 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
19 |
|
20 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
21 |
|
22 | function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
23 |
|
24 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
25 |
|
26 | var __rest = void 0 && (void 0).__rest || function (s, e) {
|
27 | var t = {};
|
28 |
|
29 | for (var p in s) {
|
30 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
31 | }
|
32 |
|
33 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
34 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
35 | }
|
36 | return t;
|
37 | };
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | var sortGradient = function sortGradient(gradients) {
|
49 | var tempArr = [];
|
50 |
|
51 | for (var _i = 0, _Object$entries = Object.entries(gradients); _i < _Object$entries.length; _i++) {
|
52 | var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
53 | key = _Object$entries$_i[0],
|
54 | value = _Object$entries$_i[1];
|
55 |
|
56 | var formatKey = parseFloat(key.replace(/%/g, ''));
|
57 |
|
58 | if (isNaN(formatKey)) {
|
59 | return {};
|
60 | }
|
61 |
|
62 | tempArr.push({
|
63 | key: formatKey,
|
64 | value: value
|
65 | });
|
66 | }
|
67 |
|
68 | tempArr = tempArr.sort(function (a, b) {
|
69 | return a.key - b.key;
|
70 | });
|
71 | return tempArr.map(function (_ref) {
|
72 | var key = _ref.key,
|
73 | value = _ref.value;
|
74 | return "".concat(value, " ").concat(key, "%");
|
75 | }).join(', ');
|
76 | };
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | exports.sortGradient = sortGradient;
|
95 |
|
96 | var handleGradient = function handleGradient(strokeColor) {
|
97 | var _strokeColor$from = strokeColor.from,
|
98 | from = _strokeColor$from === void 0 ? '#1890ff' : _strokeColor$from,
|
99 | _strokeColor$to = strokeColor.to,
|
100 | to = _strokeColor$to === void 0 ? '#1890ff' : _strokeColor$to,
|
101 | _strokeColor$directio = strokeColor.direction,
|
102 | direction = _strokeColor$directio === void 0 ? 'to right' : _strokeColor$directio,
|
103 | rest = __rest(strokeColor, ["from", "to", "direction"]);
|
104 |
|
105 | if (Object.keys(rest).length !== 0) {
|
106 | var sortedGradients = sortGradient(rest);
|
107 | return {
|
108 | backgroundImage: "linear-gradient(".concat(direction, ", ").concat(sortedGradients, ")")
|
109 | };
|
110 | }
|
111 |
|
112 | return {
|
113 | backgroundImage: "linear-gradient(".concat(direction, ", ").concat(from, ", ").concat(to, ")")
|
114 | };
|
115 | };
|
116 |
|
117 | exports.handleGradient = handleGradient;
|
118 |
|
119 | var Line = function Line(_, _ref2) {
|
120 | var attrs = _ref2.attrs,
|
121 | slots = _ref2.slots;
|
122 | var prefixCls = attrs.prefixCls,
|
123 | percent = attrs.percent,
|
124 | successPercent = attrs.successPercent,
|
125 | strokeWidth = attrs.strokeWidth,
|
126 | size = attrs.size,
|
127 | strokeColor = attrs.strokeColor,
|
128 | strokeLinecap = attrs.strokeLinecap;
|
129 | var backgroundProps;
|
130 |
|
131 | if (strokeColor && typeof strokeColor !== 'string') {
|
132 | backgroundProps = handleGradient(strokeColor);
|
133 | } else {
|
134 | backgroundProps = {
|
135 | background: strokeColor
|
136 | };
|
137 | }
|
138 |
|
139 | var percentStyle = _extends({
|
140 | width: "".concat((0, _utils.validProgress)(percent), "%"),
|
141 | height: "".concat(strokeWidth || (size === 'small' ? 6 : 8), "px"),
|
142 | background: strokeColor,
|
143 | borderRadius: strokeLinecap === 'square' ? 0 : '100px'
|
144 | }, backgroundProps);
|
145 |
|
146 | var successPercentStyle = {
|
147 | width: "".concat((0, _utils.validProgress)(successPercent), "%"),
|
148 | height: "".concat(strokeWidth || (size === 'small' ? 6 : 8), "px"),
|
149 | borderRadius: strokeLinecap === 'square' ? 0 : ''
|
150 | };
|
151 | var successSegment = successPercent !== undefined ? (0, _vue.createVNode)("div", {
|
152 | "class": "".concat(prefixCls, "-success-bg"),
|
153 | "style": successPercentStyle
|
154 | }, null) : null;
|
155 | return (0, _vue.createVNode)("div", null, [(0, _vue.createVNode)("div", {
|
156 | "class": "".concat(prefixCls, "-outer")
|
157 | }, [(0, _vue.createVNode)("div", {
|
158 | "class": "".concat(prefixCls, "-inner")
|
159 | }, [(0, _vue.createVNode)("div", {
|
160 | "class": "".concat(prefixCls, "-bg"),
|
161 | "style": percentStyle
|
162 | }, null), successSegment])]), slots === null || slots === void 0 ? void 0 : slots.default()]);
|
163 | };
|
164 |
|
165 | var _default = Line;
|
166 | exports.default = _default; |
\ | No newline at end of file |