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

Commit 944d6b0

Browse files
committed
* feat(Interpolation.js): stepped string, object, array, everything interpolation based on your easing
1 parent 5e55944 commit 944d6b0

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/dist/Interpolation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const Interpolation = {
5858
Utils: {
5959

6060
Linear (p0, p1, t) {
61-
return (p1 - p0) * t + p0
61+
return typeof p1 === 'function' ? p1(t) : (p1 - p0) * t + p0
6262
},
6363

6464
Bernstein (n, i) {

src/dist/SubTween.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let hexReplace = (all, hex) => {
2424
b = parseInt(hex.substr(4, 6), 16)
2525
}
2626

27-
return `rgb(${r},${g},${b}`
27+
return `rgb(${r},${g},${b})`
2828
}
2929
let trim = str => typeof str === 'string' ? str.replace(trimRegExp, '') : str
3030

@@ -86,7 +86,7 @@ const SubTween = (start, end, roundv = 10000) => {
8686
return (t) => {
8787
return isSame ? end : (((start + end * t) * roundv) | 0) / roundv
8888
}
89-
} else if (typeof start === 'string' && numRegExp.test(start) && numRegExp.test(end)) {
89+
} else if ((typeof start === 'string' && typeof end === 'string' && numRegExp.test(start) && numRegExp.test(end)) || (typeof end === 'string' && (hexColor.test(start) || hexColor.test(end)))) {
9090
let _startMap = trim(start).replace(hexColor, hexReplace).match(numRegExp).map(toNumber)
9191
let _endMap = trim(end).replace(hexColor, hexReplace).match(numRegExp).map(toNumber)
9292
let _tween = SubTween(_startMap, _endMap)
@@ -103,6 +103,10 @@ const SubTween = (start, end, roundv = 10000) => {
103103
}
104104
} else if (typeof end === 'function') {
105105
return end
106+
} else if (!Array.isArray(start) && Array.isArray(end)) {
107+
end.unshift(start)
108+
end.push(end[end.length - 1])
109+
return end.map((v, i) => SubTween(i === 0 ? start : end[i - 1], v))
106110
} else {
107111
let isSame = start === end
108112
return (t) => isSame ? start : t >= 0.5 ? end : start

src/dist/Tween.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Tween extends EventClass {
3636

3737
this._duration = 1000
3838
this._easingFunction = defaultEasing
39-
this._interpolationFunction = Interpolation.None
39+
this._interpolationFunction = Interpolation.Linear
4040

4141
this._startTime = 0
4242
this._delayTime = 0
@@ -178,10 +178,14 @@ class Tween extends EventClass {
178178
for (let property in _valuesEnd) {
179179
if (typeof _valuesEnd[property] === 'object' && _valuesEnd[property]) {
180180
this._valuesEnd[property] = SubTween(object[property], _valuesEnd[property])
181-
this.object[property] = this._valuesEnd[property](0)
181+
if (typeof this._valuesEnd[property] === 'function') {
182+
this.object[property] = this._valuesEnd[property](0)
183+
}
182184
} else if (typeof _valuesEnd[property] === 'string' && typeof object[property] === 'string') {
183185
this._valuesEnd[property] = SubTween(object[property], _valuesEnd[property])
184-
this.object[property] = this._valuesEnd[property](0)
186+
if (typeof this._valuesEnd[property] === 'function') {
187+
this.object[property] = this._valuesEnd[property](0)
188+
}
185189
}
186190

187191
// If `to()` specifies a property that doesn't exist in the source object,

0 commit comments

Comments
 (0)