@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.
@@ -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); //dom和content盒子对象,避免speed变化时重新获取盒子对象
30
+ var content = (0, _react.useRef)(null);
29
31
 
30
- var domRect = (0, _react.useRef)(null);
31
- var contentRect = (0, _react.useRef)(null); //文本变化时,需要重新计算dom和content的宽高
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.useMemo)(function () {
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 dom_ = dom.current;
36
- domRect.current = dom_.getBoundingClientRect();
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 (domRect.current.width < contentRect.current.width) {
41
- return [value, value];
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: textList.length == 2 ? {
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { useEffect, memo, useRef, useMemo } from 'react';
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
- //文本变化时,需要重新计算dom和content的宽高
22
- const textList = useMemo(()=>{
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
- const dom_ = dom.current;
25
- domRect.current = dom_.getBoundingClientRect();
26
- let content_ = content.current;
27
- contentRect.current = content_.getBoundingClientRect();
28
- if (domRect.current.width < contentRect.current.width) {
29
- return [value, value];
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
- return [value];
33
- },[value])
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
- textList.length == 2
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
  }