diff --git a/package.json b/package.json index dc8701b..ef20d10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "es6-tween", - "version": "5.5.7", + "version": "5.5.8", "description": "ES6 implementation of amazing tween.js", "browser": "bundled/Tween.min.js", "cdn": "bundled/Tween.min.js", diff --git a/src/Tween.js b/src/Tween.js index 01dfeaa..013a1d7 100644 --- a/src/Tween.js +++ b/src/Tween.js @@ -426,6 +426,7 @@ class Tween { ) { continue } + _valuesStart[property] = start if (Array.isArray(end)) { if (!Array.isArray(start)) { end.unshift(start) @@ -437,14 +438,16 @@ class Tween { } else { if (end.isString && object[property].isString && !start.isString) { start.isString = true + } else { + decompose(property, object, _valuesStart, _valuesEnd) } } + } else { + decompose(property, object, _valuesStart, _valuesEnd) } - _valuesStart[property] = start if (typeof start === 'number' && typeof end === 'string' && end[1] === '=') { continue } - decompose(property, object, _valuesStart, _valuesEnd) } if (Tween.Renderer && this.node && Tween.Renderer.init) { @@ -716,7 +719,7 @@ class Tween { if (typeof end === 'number') { object[property] = start + (end - start) * value - } else if (Array.isArray(end) && !end.isString && (!Array.isArray(start) || start.isString)) { + } else if (Array.isArray(end) && !end.isString && !Array.isArray(start)) { object[property] = _interpolationFunctionCall(end, value, object[property]) } else if (end && end.update) { end.update(value) @@ -724,8 +727,6 @@ class Tween { object[property] = end(value) } else if (typeof end === 'string' && typeof start === 'number') { object[property] = start + parseFloat(end[0] + end.substr(2)) * value - } else if (start && end && start.splice && end.splice && start.isString && end.isString) { - object[property] = recompose(property, object, _valuesStart, _valuesEnd, value, elapsed) } else { recompose(property, object, _valuesStart, _valuesEnd, value, elapsed) } diff --git a/src/constants.js b/src/constants.js index 61da124..fe556d8 100644 --- a/src/constants.js +++ b/src/constants.js @@ -59,7 +59,13 @@ const hex2rgb = (all, hex) => { } export function decomposeString (fromValue) { - if (typeof fromValue !== 'string' || (fromValue && fromValue.splice && fromValue.isString)) { + if (fromValue && fromValue.splice && fromValue.isString) { + return fromValue + } + if (typeof fromValue !== 'string') { + return fromValue + } + if (fromValue.charAt(1) === '=') { return fromValue } const value = fromValue @@ -71,10 +77,24 @@ export function decomposeString (fromValue) { } // Decompose value, now for only `string` that required -export function decompose (prop, obj, from, to, stringBuffer) { +export function decompose (prop, obj, from, to) { const fromValue = from[prop] const toValue = to[prop] + if (fromValue === toValue) { + return true + } else if (Array.isArray(fromValue) && Array.isArray(toValue) && fromValue.length === toValue.length) { + for (let i = 0, len = toValue.length; i < len; i++) { + const a = fromValue[i] + const b = toValue[i] + + if (a === b || (typeof a === 'number' && typeof b === 'number')) { + continue + } else { + decompose(i, obj[prop], fromValue, toValue) + } + } + } if (typeof fromValue === 'number' && typeof toValue === 'number') { // } else if (fromValue && fromValue.splice && fromValue.isString && toValue && toValue.splice && toValue.isString) { @@ -89,6 +109,9 @@ export function decompose (prop, obj, from, to, stringBuffer) { let fromValue1 = Array.isArray(fromValue) && fromValue[0] === STRING_PROP ? fromValue : decomposeString(fromValue) let toValue1 = Array.isArray(toValue) && toValue[0] === STRING_PROP ? toValue : decomposeString(toValue) + if (fromValue1 === undefined) { + return + } let i = 1 while (i < fromValue1.length) { if (fromValue1[i] === toValue1[i] && typeof fromValue1[i - 1] === 'string') { @@ -132,7 +155,7 @@ export const isRGBColor = (v, i, r = RGB) => typeof v[i] === 'number' && (v[i - 1] === r || v[i - 3] === r || v[i - 5] === r) export function recompose (prop, obj, from, to, t, originalT, stringBuffer) { const fromValue = stringBuffer ? from : from[prop] - const toValue = stringBuffer ? to : to[prop] + let toValue = stringBuffer ? to : to[prop] if (toValue === undefined) { return fromValue } @@ -177,7 +200,7 @@ export function recompose (prop, obj, from, to, t, originalT, stringBuffer) { return STRING_BUFFER } else if (Array.isArray(fromValue) && fromValue[0] !== STRING_PROP) { for (let i = 0, len = fromValue.length; i < len; i++) { - if (fromValue[i] === toValue[i]) { + if (fromValue[i] === toValue[i] || typeof obj[prop] === 'string') { continue } recompose(i, obj[prop], fromValue, toValue, t, originalT) diff --git a/test.js b/test.js index e4fb884..8c82b50 100644 --- a/test.js +++ b/test.js @@ -49,7 +49,6 @@ test('Events', (t) => { test('Value Interpolation', (t) => { const m = ['rgb(', 0, ', 204, ', 255, ')'] - m.isString = true let obj = { a: 0, @@ -75,7 +74,6 @@ test('Value Interpolation', (t) => { }) const m2 = ['rgb(', 255, ', 204, ', 0, ')'] - m2.isString = true new Tween(obj) .to( { @@ -89,7 +87,7 @@ test('Value Interpolation', (t) => { j: [1, 2], k: ['rgb(100, 100, 100)', 'rgb(200, 200, 200)'], l: '#fc0', - m: 'rgb(255, 204, 0)' + m: m2 }, 100 ) @@ -107,7 +105,7 @@ test('Value Interpolation', (t) => { t.is(obj.j, 0) t.is(obj.k, 'rgb(0, 0, 0)') t.is(obj.l, 'rgb(0, 204, 255)') - t.is(obj.m, 'rgb(0, 204, 255)') + t.deepEqual(obj.m, ['rgb(', 0, ', 204, ', 255, ')']) update(50) @@ -150,7 +148,7 @@ test('Value Interpolation', (t) => { t.is(obj.j, 2, 'Multi-Interpolation not worked as excepted') t.is(obj.k, 'rgb(200, 200, 200)', 'Multi-Interpolation not worked as excepted') t.is(obj.l, 'rgb(255, 204, 0)', 'String interpolation not worked as excepted') - t.is(obj.m, 'rgb(255, 204, 0)', 'Array as string interpolation not worked as excepted') + t.deepEqual(obj.m, m2, 'Array interpolation not worked as excepted') }) test('Value Array-based Interpolation', (t) => { diff --git a/withPage.js b/withPage.js index 440fc81..78759c0 100644 --- a/withPage.js +++ b/withPage.js @@ -3,6 +3,14 @@ import puppeteer from 'puppeteer' const fs = require('fs') const path = require('path') +// Parse +function describe (jsHandle) { + return jsHandle.executionContext().evaluate((obj) => { + // serialize |obj| however you want + return JSON.stringify(obj) + }, jsHandle) +} + export default (t, run) => { let _browser return puppeteer @@ -12,11 +20,13 @@ export default (t, run) => { return browser .newPage() .then((page) => { + page.on('console', async (msg) => { + const args = await Promise.all(msg.args().map((arg) => describe(arg))) + console.log('Logs from Headless Chrome', ...args) + }) return page.evaluate(fs.readFileSync(path.join(__dirname, 'bundled/Tween.js'), 'utf8')).then(() => page) }) - .then((page) => { - return run(t, page).then(() => page) - }) + .then((page) => run(t, page).then(() => page)) }) .then((page) => { _browser.close()