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

Commit bd4fa36

Browse files
committed
* fix: Tests now passes
* fix: Added missing file
1 parent 52ee9b3 commit bd4fa36

File tree

4 files changed

+84
-7
lines changed

4 files changed

+84
-7
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "es6-tween",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "ES6 implementation of amazing tween.js",
55
"browser": "dist/Tween.min.js",
66
"cdn": "dist/Tween.min.js",

src/dist/PlaybackPosition.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
export default class PlaybackPosition {
2+
constructor () {
3+
this.totalTime = 0
4+
this.labels = []
5+
this.offsets = []
6+
}
7+
parseLabel (name, offset) {
8+
const { offsets, labels } = this
9+
let i = labels.indexOf(name)
10+
if (typeof name === 'string' && name.indexOf('=') !== -1 && !offset && i === -1) {
11+
const rty = name.substr(name.indexOf('=') - 1, 2)
12+
let rt = name.split(rty)
13+
offset = rt.length === 2 ? rty + rt[1] : null
14+
name = rt[0]
15+
i = labels.indexOf(name)
16+
}
17+
if (i !== -1 && name) {
18+
let currOffset = offsets[i] || 0
19+
if (typeof offset === 'number') {
20+
currOffset = offset
21+
} else if (typeof offset === 'string') {
22+
if (offset.indexOf('=') !== -1) {
23+
const type = offset.charAt(0)
24+
offset = Number(offset.substr(2))
25+
if (type === '+' || type === '-') {
26+
currOffset += parseFloat(type + offset)
27+
} else if (type === '*') {
28+
currOffset *= offset
29+
} else if (type === '/') {
30+
currOffset /= offset
31+
} else if (type === '%') {
32+
currOffset *= offset / 100
33+
}
34+
}
35+
}
36+
return currOffset
37+
}
38+
return typeof offset === 'number' ? offset : 0
39+
}
40+
addLabel (name, offset) {
41+
this.labels.push(name)
42+
this.offsets.push(this.parseLabel(name, offset))
43+
return this
44+
}
45+
setLabel (name, offset) {
46+
const i = this.labels.indexOf(name)
47+
if (i !== -1) {
48+
this.offsets.splice(i, 1, this.parseLabel(name, offset))
49+
}
50+
return this
51+
}
52+
eraseLabel (name) {
53+
const i = this.labels.indexOf(name)
54+
if (i !== -1) {
55+
this.labels.splice(i, 1)
56+
this.offsets.splice(i, 1)
57+
}
58+
return this
59+
}
60+
}

src/dist/Tween.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class Tween extends EventClass {
326326
return this.object
327327
}
328328

329-
update (time) {
329+
update (time, preserve) {
330330
let {
331331
_onStartCallbackFired,
332332
_easingFunction,
@@ -389,6 +389,17 @@ class Tween extends EventClass {
389389
object[property] = _interpolationFunction(end, value)
390390
} else if (typeof (end) === 'number') {
391391
object[property] = start + (end - start) * value
392+
} else if (typeof (end) === 'string') {
393+
if (end.charAt(0) === '+' || end.charAt(0) === '-') {
394+
end = start + parseFloat(end)
395+
} else {
396+
end = parseFloat(end)
397+
}
398+
399+
// Protect against non numeric properties.
400+
if (typeof (end) === 'number') {
401+
object[property] = start + (end - start) * value
402+
}
392403
}
393404
}
394405

@@ -400,6 +411,12 @@ class Tween extends EventClass {
400411
this._repeat--
401412
}
402413

414+
for (property in _valuesEnd) {
415+
if (typeof (_valuesEnd[property]) === 'string' && typeof (_valuesStart[property]) === 'number') {
416+
_valuesStart[property] = _valuesStart[property] + parseFloat(_valuesEnd[property])
417+
}
418+
}
419+
403420
// Reassign starting values, restart by making startTime = now
404421
this.emit(_reversed ? EVENT_REVERSE : EVENT_REPEAT, object)
405422

@@ -415,11 +432,11 @@ class Tween extends EventClass {
415432
this._startTime += _duration
416433
}
417434

418-
this.reassignValues()
419-
420435
return true
421436
} else {
422-
remove(this)
437+
if (!preserve) {
438+
remove(this)
439+
}
423440
this.emit(EVENT_COMPLETE, object)
424441
this._repeat = this._r
425442

src/dist/core.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ let now = (function () {
9696
}
9797
}())
9898

99-
const update = (time) => {
99+
const update = (time, preserve) => {
100100
time = time !== undefined ? time : now()
101101

102102
_tick = _ticker(update)
@@ -110,7 +110,7 @@ const update = (time) => {
110110
}
111111

112112
for (i in _tweens) {
113-
_tweens[i].update(time)
113+
_tweens[i].update(time, preserve)
114114
}
115115

116116
return true

0 commit comments

Comments
 (0)