Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 84494eb

Browse files
committed
* fix(tween): string infinite-loop fix
1 parent c671f70 commit 84494eb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/dist/SubTween.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let isIncrementReqForColor = /ahsv|ahsl|argb/g
99
const numRegExp =
1010
/\s+|([A-Za-z?().,{}:""[\]#]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g
1111
let hexColor = /^#([0-9a-f]{6}|[0-9a-f]{3})$/i
12+
let trimRegExp = /\n|\r|\t/g
1213
let hexReplace = (all, hex) => {
1314
let r
1415
let g
@@ -25,12 +26,13 @@ let hexReplace = (all, hex) => {
2526

2627
return `rgb(${r},${g},${b}`
2728
}
29+
let trim = str => typeof str === 'string' ? str.replace(trimRegExp, '') : str
2830

2931
const SubTween = (start, end, roundv = 10000) => {
3032
if (Array.isArray(start)) {
3133
let isColorPropsExist = null
3234
let startIndex = null
33-
end = end.map((v, i) => colorMatch.test(v) ? ((isColorPropsExist = v), (startIndex = i), null) : v === start[i] ? null : typeof v === 'number' ? (v - start[i]) : SubTween(start[i], v))
35+
end = end.map((v, i) => colorMatch.test(v) ? ((isColorPropsExist = v), (startIndex = i), null) : v === start[i] ? null : typeof v === 'number' ? (v - start[i]) : numRegExp.test(v) ? SubTween(trim(start[i]), trim(v)) : v)
3436
let endIndex = startIndex !== null ? startIndex + 6 : null
3537
if (isColorPropsExist && isIncrementReqForColor.test(isColorPropsExist)) {
3638
startIndex++
@@ -60,7 +62,7 @@ const SubTween = (start, end, roundv = 10000) => {
6062
end[property] = null
6163
} else if (typeof start[property] === 'number') {
6264
end[property] -= start[property]
63-
} else if (typeof end[property] === 'object' || typeof [end] === 'string') {
65+
} else if (typeof end[property] === 'object' || (typeof end[property] === 'string' && numRegExp.test(end[property]))) {
6466
end[property] = SubTween(start[property], end[property])
6567
}
6668
}
@@ -84,9 +86,9 @@ const SubTween = (start, end, roundv = 10000) => {
8486
return (t) => {
8587
return isSame ? end : (((start + end * t) * roundv) | 0) / roundv
8688
}
87-
} else if (typeof start === 'string') {
88-
let _startMap = start.replace(hexColor, hexReplace).match(numRegExp).map(toNumber)
89-
let _endMap = end.replace(hexColor, hexReplace).match(numRegExp).map(toNumber)
89+
} else if (typeof start === 'string' && numRegExp.test(start) && numRegExp.test(end)) {
90+
let _startMap = trim(start).replace(hexColor, hexReplace).match(numRegExp).map(toNumber)
91+
let _endMap = trim(end).replace(hexColor, hexReplace).match(numRegExp).map(toNumber)
9092
let _tween = SubTween(_startMap, _endMap)
9193
return (t) => {
9294
let _t = _tween(t)

0 commit comments

Comments
 (0)