@easyv/charts 1.2.12 → 1.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/Marquee.js +23 -25
- package/package.json +1 -1
- package/src/components/Marquee.js +19 -25
|
@@ -9,6 +9,8 @@ exports["default"] = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
12
14
|
var _react = require("react");
|
|
13
15
|
|
|
14
16
|
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; }
|
|
@@ -25,33 +27,27 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (props) {
|
|
|
25
27
|
_props$speed = props.speed,
|
|
26
28
|
speed = _props$speed === void 0 ? 5 : _props$speed;
|
|
27
29
|
var dom = (0, _react.useRef)(null);
|
|
28
|
-
var content = (0, _react.useRef)(null);
|
|
30
|
+
var content = (0, _react.useRef)(null);
|
|
29
31
|
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
+
var _useState = (0, _react.useState)(false),
|
|
33
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
34
|
+
fresh = _useState2[0],
|
|
35
|
+
setFresh = _useState2[1];
|
|
32
36
|
|
|
33
|
-
var textList = (0, _react.
|
|
37
|
+
var textList = (0, _react.useRef)([value]);
|
|
38
|
+
var duration = (0, _react.useRef)(10 / speed);
|
|
39
|
+
(0, _react.useEffect)(function () {
|
|
34
40
|
if (dom.current && content.current) {
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
var content_ = content.current;
|
|
38
|
-
contentRect.current = content_.getBoundingClientRect();
|
|
41
|
+
var domRectWidth = dom.current.getBoundingClientRect().width;
|
|
42
|
+
var contentRectWidth = content.current.getBoundingClientRect().width;
|
|
39
43
|
|
|
40
|
-
if (
|
|
41
|
-
|
|
44
|
+
if (domRectWidth < contentRectWidth) {
|
|
45
|
+
textList.current = [value, value];
|
|
46
|
+
duration.current = contentRectWidth / domRectWidth / speed * 10;
|
|
47
|
+
setFresh(!fresh);
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
|
-
|
|
45
|
-
return [value];
|
|
46
|
-
}, [value]); //value和speed变化时,直接更新duration
|
|
47
|
-
|
|
48
|
-
var duration = (0, _react.useMemo)(function () {
|
|
49
|
-
if (domRect.current && contentRect.current && domRect.current.width < contentRect.current.width) {
|
|
50
|
-
return contentRect.current.width / domRect.current.width / speed * 10;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return 5;
|
|
54
|
-
}, [speed]); //在head标签中注入keyframes动画
|
|
50
|
+
}, [value, speed]); //在head标签中注入keyframes动画
|
|
55
51
|
|
|
56
52
|
(0, _react.useEffect)(function () {
|
|
57
53
|
var md_marquee = document.getElementById('md_marquee'); //先查找是否已经存在md_marquee
|
|
@@ -68,24 +64,26 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (props) {
|
|
|
68
64
|
document.getElementsByTagName('head')[0].appendChild(_style);
|
|
69
65
|
}
|
|
70
66
|
}, []);
|
|
67
|
+
var overflow = textList.current.length == 2;
|
|
71
68
|
return /*#__PURE__*/React.createElement("span", {
|
|
72
69
|
style: _objectSpread(_objectSpread({
|
|
73
70
|
width: '100%'
|
|
74
71
|
}, style), {}, {
|
|
75
72
|
display: 'flex',
|
|
76
73
|
whiteSpace: 'nowrap',
|
|
77
|
-
overflow: 'hidden'
|
|
74
|
+
overflow: 'hidden',
|
|
75
|
+
justifyContent: overflow ? "start" : style.justifyContent || ""
|
|
78
76
|
}),
|
|
79
77
|
ref: dom
|
|
80
|
-
}, textList.map(function (item, itemIndex) {
|
|
78
|
+
}, textList.current.map(function (item, itemIndex) {
|
|
81
79
|
return /*#__PURE__*/React.createElement("span", {
|
|
82
80
|
key: itemIndex,
|
|
83
|
-
style:
|
|
81
|
+
style: overflow ? {
|
|
84
82
|
//如果文本数量为2,则需要滚动
|
|
85
83
|
animationName: 'md_marquee',
|
|
86
84
|
animationTimingFunction: 'linear',
|
|
87
85
|
animationIterationCount: 'infinite',
|
|
88
|
-
animationDuration: duration + 's'
|
|
86
|
+
animationDuration: duration.current + 's'
|
|
89
87
|
} : {},
|
|
90
88
|
ref: itemIndex == 0 ? content : null
|
|
91
89
|
}, "\xA0", item);
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, memo, useRef,
|
|
1
|
+
import { useEffect, memo, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 文字跑马灯组件
|
|
@@ -14,31 +14,23 @@ export default memo((props) => {
|
|
|
14
14
|
|
|
15
15
|
const dom = useRef(null);
|
|
16
16
|
const content = useRef(null);
|
|
17
|
-
//dom和content盒子对象,避免speed变化时重新获取盒子对象
|
|
18
|
-
const domRect = useRef(null);
|
|
19
|
-
const contentRect = useRef(null);
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const [fresh,setFresh] = useState(false);
|
|
19
|
+
let textList = useRef([value]);
|
|
20
|
+
let duration = useRef(10/speed);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
23
|
if(dom.current && content.current){
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
let domRectWidth = dom.current.getBoundingClientRect().width;
|
|
25
|
+
let contentRectWidth = content.current.getBoundingClientRect().width;
|
|
26
|
+
if (domRectWidth < contentRectWidth) {
|
|
27
|
+
textList.current = [value,value];
|
|
28
|
+
duration.current = contentRectWidth / domRectWidth / speed * 10;
|
|
29
|
+
setFresh(!fresh);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//value和speed变化时,直接更新duration
|
|
36
|
-
const duration = useMemo(() => {
|
|
37
|
-
if (domRect.current && contentRect.current && domRect.current.width < contentRect.current.width) {
|
|
38
|
-
return (contentRect.current.width / domRect.current.width / speed) * 10;
|
|
39
|
-
}
|
|
40
|
-
return 5
|
|
41
|
-
}, [speed]);
|
|
32
|
+
}, [value,speed]);
|
|
33
|
+
|
|
42
34
|
//在head标签中注入keyframes动画
|
|
43
35
|
useEffect(() => {
|
|
44
36
|
let md_marquee = document.getElementById('md_marquee'); //先查找是否已经存在md_marquee
|
|
@@ -57,6 +49,7 @@ export default memo((props) => {
|
|
|
57
49
|
document.getElementsByTagName('head')[0].appendChild(style);
|
|
58
50
|
}
|
|
59
51
|
}, []);
|
|
52
|
+
let overflow = textList.current.length==2;
|
|
60
53
|
return (
|
|
61
54
|
<span
|
|
62
55
|
style={{
|
|
@@ -65,21 +58,22 @@ export default memo((props) => {
|
|
|
65
58
|
display: 'flex',
|
|
66
59
|
whiteSpace: 'nowrap',
|
|
67
60
|
overflow: 'hidden',
|
|
61
|
+
justifyContent:overflow?"start":(style.justifyContent || "")
|
|
68
62
|
}}
|
|
69
63
|
ref={dom}
|
|
70
64
|
>
|
|
71
|
-
{textList.map((item, itemIndex) => {
|
|
65
|
+
{textList.current.map((item, itemIndex) => {
|
|
72
66
|
return (
|
|
73
67
|
<span
|
|
74
68
|
key={itemIndex}
|
|
75
69
|
style={
|
|
76
|
-
|
|
70
|
+
overflow
|
|
77
71
|
? {
|
|
78
72
|
//如果文本数量为2,则需要滚动
|
|
79
73
|
animationName: 'md_marquee',
|
|
80
74
|
animationTimingFunction: 'linear',
|
|
81
75
|
animationIterationCount: 'infinite',
|
|
82
|
-
animationDuration: duration + 's',
|
|
76
|
+
animationDuration: duration.current + 's',
|
|
83
77
|
}
|
|
84
78
|
: {}
|
|
85
79
|
}
|