1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | var _typeof3 = require("@babel/runtime/helpers/typeof");
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = void 0;
|
9 | var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
10 | var React = _interopRequireWildcard(require("react"));
|
11 | function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
12 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
13 | var Block = function Block(_ref) {
|
14 | var bg = _ref.bg,
|
15 | children = _ref.children;
|
16 | return React.createElement("div", {
|
17 | style: {
|
18 | width: '100%',
|
19 | height: '100%',
|
20 | background: bg
|
21 | }
|
22 | }, children);
|
23 | };
|
24 | function getPtgColors(color, scale) {
|
25 | return Object.keys(color).map(function (key) {
|
26 | var parsedKey = parseFloat(key);
|
27 | var ptgKey = "".concat(Math.floor(parsedKey * scale), "%");
|
28 | return "".concat(color[key], " ").concat(ptgKey);
|
29 | });
|
30 | }
|
31 | var PtgCircle = React.forwardRef(function (props, ref) {
|
32 | var prefixCls = props.prefixCls,
|
33 | color = props.color,
|
34 | gradientId = props.gradientId,
|
35 | radius = props.radius,
|
36 | circleStyleForStack = props.style,
|
37 | ptg = props.ptg,
|
38 | strokeLinecap = props.strokeLinecap,
|
39 | strokeWidth = props.strokeWidth,
|
40 | size = props.size,
|
41 | gapDegree = props.gapDegree;
|
42 | var isGradient = color && (0, _typeof2.default)(color) === 'object';
|
43 | var stroke = isGradient ? "#FFF" : undefined;
|
44 |
|
45 |
|
46 | var halfSize = size / 2;
|
47 | var circleNode = React.createElement("circle", {
|
48 | className: "".concat(prefixCls, "-circle-path"),
|
49 | r: radius,
|
50 | cx: halfSize,
|
51 | cy: halfSize,
|
52 | stroke: stroke,
|
53 | strokeLinecap: strokeLinecap,
|
54 | strokeWidth: strokeWidth,
|
55 | opacity: ptg === 0 ? 0 : 1,
|
56 | style: circleStyleForStack,
|
57 | ref: ref
|
58 | });
|
59 |
|
60 |
|
61 | if (!isGradient) {
|
62 | return circleNode;
|
63 | }
|
64 | var maskId = "".concat(gradientId, "-conic");
|
65 | var fromDeg = gapDegree ? "".concat(180 + gapDegree / 2, "deg") : '0deg';
|
66 | var conicColors = getPtgColors(color, (360 - gapDegree) / 360);
|
67 | var linearColors = getPtgColors(color, 1);
|
68 | var conicColorBg = "conic-gradient(from ".concat(fromDeg, ", ").concat(conicColors.join(', '), ")");
|
69 | var linearColorBg = "linear-gradient(to ".concat(gapDegree ? 'bottom' : 'top', ", ").concat(linearColors.join(', '), ")");
|
70 | return React.createElement(React.Fragment, null, React.createElement("mask", {
|
71 | id: maskId
|
72 | }, circleNode), React.createElement("foreignObject", {
|
73 | x: 0,
|
74 | y: 0,
|
75 | width: size,
|
76 | height: size,
|
77 | mask: "url(#".concat(maskId, ")")
|
78 | }, React.createElement(Block, {
|
79 | bg: linearColorBg
|
80 | }, React.createElement(Block, {
|
81 | bg: conicColorBg
|
82 | }))));
|
83 | });
|
84 | if (process.env.NODE_ENV !== 'production') {
|
85 | PtgCircle.displayName = 'PtgCircle';
|
86 | }
|
87 | var _default = exports.default = PtgCircle; |
\ | No newline at end of file |