UNPKG

4.79 kBJavaScriptView Raw
1import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3import { createVNode as _createVNode } from "vue";
4
5var __rest = this && this.__rest || function (s, e) {
6 var t = {};
7
8 for (var p in s) {
9 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
10 }
11
12 if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
13 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
14 }
15 return t;
16};
17
18import useRefs from '../../_util/hooks/useRefs';
19import { computed, defineComponent } from 'vue';
20import initDefaultProps from '../../_util/props-util/initDefaultProps';
21import { useTransitionDuration, defaultProps } from './common';
22import { propTypes } from './types';
23export default defineComponent({
24 name: 'Line',
25 props: initDefaultProps(propTypes, defaultProps),
26 setup: function setup(props) {
27 var percentList = computed(function () {
28 var percent = props.percent;
29 return Array.isArray(percent) ? percent : [percent];
30 });
31 var percentListProps = computed(function () {
32 var prefixCls = props.prefixCls,
33 strokeLinecap = props.strokeLinecap,
34 strokeWidth = props.strokeWidth,
35 transition = props.transition;
36 var stackPtg = 0;
37 return percentList.value.map(function (ptg, index) {
38 var dashPercent = 1;
39
40 switch (strokeLinecap) {
41 case 'round':
42 dashPercent = 1 - strokeWidth / 100;
43 break;
44
45 case 'square':
46 dashPercent = 1 - strokeWidth / 2 / 100;
47 break;
48
49 default:
50 dashPercent = 1;
51 break;
52 }
53
54 var pathStyle = {
55 strokeDasharray: "".concat(ptg * dashPercent, "px, 100px"),
56 strokeDashoffset: "-".concat(stackPtg, "px"),
57 transition: transition || 'stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear'
58 };
59 var color = strokeColorList.value[index] || strokeColorList.value[strokeColorList.value.length - 1];
60 stackPtg += ptg;
61 var pathProps = {
62 key: index,
63 d: pathString.value,
64 'stroke-linecap': strokeLinecap,
65 stroke: color,
66 'stroke-width': strokeWidth,
67 'fill-opacity': '0',
68 class: "".concat(prefixCls, "-line-path"),
69 style: pathStyle
70 };
71 return pathProps;
72 });
73 });
74 var strokeColorList = computed(function () {
75 var strokeColor = props.strokeColor;
76 return Array.isArray(strokeColor) ? strokeColor : [strokeColor];
77 });
78
79 var _useRefs = useRefs(),
80 _useRefs2 = _slicedToArray(_useRefs, 2),
81 setRef = _useRefs2[0],
82 paths = _useRefs2[1];
83
84 useTransitionDuration(paths);
85 var center = computed(function () {
86 return props.strokeWidth / 2;
87 });
88 var right = computed(function () {
89 return 100 - props.strokeWidth / 2;
90 });
91 var pathString = computed(function () {
92 return "M ".concat(props.strokeLinecap === 'round' ? center.value : 0, ",").concat(center.value, "\n L ").concat(props.strokeLinecap === 'round' ? right.value : 100, ",").concat(center.value);
93 });
94 var viewBoxString = computed(function () {
95 return "0 0 100 ".concat(props.strokeWidth);
96 });
97 var pathFirst = computed(function () {
98 return {
99 d: pathString.value,
100 'stroke-linecap': props.strokeLinecap,
101 stroke: props.trailColor,
102 'stroke-width': props.trailWidth || props.strokeWidth,
103 'fill-opacity': '0',
104 class: "".concat(props.prefixCls, "-line-trail")
105 };
106 });
107 return function () {
108 var percent = props.percent,
109 prefixCls = props.prefixCls,
110 strokeColor = props.strokeColor,
111 strokeLinecap = props.strokeLinecap,
112 strokeWidth = props.strokeWidth,
113 trailColor = props.trailColor,
114 trailWidth = props.trailWidth,
115 transition = props.transition,
116 restProps = __rest(props, ["percent", "prefixCls", "strokeColor", "strokeLinecap", "strokeWidth", "trailColor", "trailWidth", "transition"]);
117
118 delete restProps.gapPosition;
119 return _createVNode("svg", _objectSpread({
120 "class": "".concat(prefixCls, "-line"),
121 "viewBox": viewBoxString.value,
122 "preserveAspectRatio": "none"
123 }, restProps), [_createVNode("path", pathFirst.value, null), percentListProps.value.map(function (pathProps, index) {
124 return _createVNode("path", _objectSpread({
125 "ref": setRef(index)
126 }, pathProps), null);
127 })]);
128 };
129 }
130});
\No newline at end of file