Skip to content

Commit 8743ea8

Browse files
authored
Merge branch 'main' into groupComplete
2 parents d30c35f + 6536e9d commit 8743ea8

File tree

10 files changed

+78
-15
lines changed

10 files changed

+78
-15
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
33

4-
name: build and tests
4+
name: build and test
55

66
on: [push]
77

88
jobs:
9-
build:
9+
build-and-test:
1010
runs-on: ubuntu-latest
1111

1212
strategy:
1313
matrix:
14-
node-version: [16.x, 18.x, 20.x]
14+
node-version: [lts/*]
1515

1616
steps:
1717
- uses: actions/checkout@v2
1818
- name: Use Node.js ${{ matrix.node-version }}
19-
uses: actions/setup-node@v1
19+
uses: actions/setup-node@v4
2020
with:
2121
node-version: ${{ matrix.node-version }}
22-
- run: npm install
22+
- run: npm clean-install
2323
- run: npm test

dist/tween.amd.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ define(['exports'], (function (exports) { 'use strict';
215215
},
216216
});
217217

218-
var now = function () { return performance.now(); };
218+
var _nowFunc = function () { return performance.now(); };
219+
var now = function () {
220+
return _nowFunc();
221+
};
222+
function setNow(nowFunction) {
223+
_nowFunc = nowFunction;
224+
}
219225

220226
/**
221227
* Controlling groups of tweens
@@ -1155,6 +1161,7 @@ define(['exports'], (function (exports) { 'use strict';
11551161
Group: Group,
11561162
Interpolation: Interpolation,
11571163
now: now,
1164+
setNow: setNow,
11581165
Sequence: Sequence,
11591166
nextId: nextId,
11601167
Tween: Tween,
@@ -1414,6 +1421,7 @@ define(['exports'], (function (exports) { 'use strict';
14141421
exports.now = now;
14151422
exports.remove = remove;
14161423
exports.removeAll = removeAll;
1424+
exports.setNow = setNow;
14171425
exports.update = update;
14181426

14191427
Object.defineProperty(exports, '__esModule', { value: true });

dist/tween.cjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ var Easing = Object.freeze({
217217
},
218218
});
219219

220-
var now = function () { return performance.now(); };
220+
var _nowFunc = function () { return performance.now(); };
221+
var now = function () {
222+
return _nowFunc();
223+
};
224+
function setNow(nowFunction) {
225+
_nowFunc = nowFunction;
226+
}
221227

222228
/**
223229
* Controlling groups of tweens
@@ -1157,6 +1163,7 @@ var exports$1 = {
11571163
Group: Group,
11581164
Interpolation: Interpolation,
11591165
now: now,
1166+
setNow: setNow,
11601167
Sequence: Sequence,
11611168
nextId: nextId,
11621169
Tween: Tween,
@@ -1416,4 +1423,5 @@ exports.nextId = nextId;
14161423
exports.now = now;
14171424
exports.remove = remove;
14181425
exports.removeAll = removeAll;
1426+
exports.setNow = setNow;
14191427
exports.update = update;

dist/tween.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ declare class Group {
186186
}
187187

188188
declare const now: () => number;
189+
declare function setNow(nowFunction: Function): void;
189190

190191
/**
191192
* Utils
@@ -472,6 +473,7 @@ declare const exports: {
472473
};
473474
};
474475
now: () => number;
476+
setNow: typeof setNow;
475477
Sequence: typeof Sequence;
476478
nextId: typeof Sequence.nextId;
477479
Tween: typeof Tween;
@@ -721,4 +723,4 @@ declare const exports: {
721723
};
722724
};
723725

724-
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };
726+
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, setNow, update };

dist/tween.esm.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ var Easing = Object.freeze({
213213
},
214214
});
215215

216-
var now = function () { return performance.now(); };
216+
var _nowFunc = function () { return performance.now(); };
217+
var now = function () {
218+
return _nowFunc();
219+
};
220+
function setNow(nowFunction) {
221+
_nowFunc = nowFunction;
222+
}
217223

218224
/**
219225
* Controlling groups of tweens
@@ -1153,6 +1159,7 @@ var exports = {
11531159
Group: Group,
11541160
Interpolation: Interpolation,
11551161
now: now,
1162+
setNow: setNow,
11561163
Sequence: Sequence,
11571164
nextId: nextId,
11581165
Tween: Tween,
@@ -1399,4 +1406,4 @@ var exports = {
13991406
update: update,
14001407
};
14011408

1402-
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };
1409+
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, setNow, update };

dist/tween.umd.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@
219219
},
220220
});
221221

222-
var now = function () { return performance.now(); };
222+
var _nowFunc = function () { return performance.now(); };
223+
var now = function () {
224+
return _nowFunc();
225+
};
226+
function setNow(nowFunction) {
227+
_nowFunc = nowFunction;
228+
}
223229

224230
/**
225231
* Controlling groups of tweens
@@ -1159,6 +1165,7 @@
11591165
Group: Group,
11601166
Interpolation: Interpolation,
11611167
now: now,
1168+
setNow: setNow,
11621169
Sequence: Sequence,
11631170
nextId: nextId,
11641171
Tween: Tween,
@@ -1418,6 +1425,7 @@
14181425
exports.now = now;
14191426
exports.remove = remove;
14201427
exports.removeAll = removeAll;
1428+
exports.setNow = setNow;
14211429
exports.update = update;
14221430

14231431
Object.defineProperty(exports, '__esModule', { value: true });

docs/user_guide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,12 @@ Note that the interpolation function is global to all properties that are tweene
642642

643643
Check [06_array_interpolation](../examples/06_array_interpolation.html) for an example.
644644

645+
## Changing the Definition of "Now"
646+
647+
When working with tweening, you inevitably rely on a definition of what "now" is. By default, Tween.js uses performance.now, which is a reliable and precise approach. However, if you need to adjust the flow of time—for instance, to slow it down or manipulate it for a custom purpose—you may encounter discrepancies between your internal definition of "now" and what Tween.js considers "now."
648+
649+
To address this, a new function, setNow, has been introduced. This function allows you to redefine the internal "now" used by Tween.js. You can pass a custom function to setNow, which will replace the default definition. This provides greater flexibility and enables synchronization with your specific requirements for time control.
650+
645651
## Getting the best performance
646652

647653
While Tween.js tries to be performant on its own, nothing prevents you from using it in a way that is counterperformant. Here are some of the ways you can avoid slowing down your projects when using Tween.js (or when animating in the web, in general).

scripts/write-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs'
2-
import pkg from '../package.json' assert {type: 'json'}
2+
import pkg from '../package.json' with {type: 'json'}
33

44
const {version} = pkg
55

src/Index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import Easing from './Easing'
1111
import Group from './Group'
1212
import Interpolation from './Interpolation'
13-
import now from './Now'
13+
import now, {setNow} from './Now'
1414
import Sequence from './Sequence'
1515
import Tween from './Tween'
1616
import VERSION from './Version'
@@ -273,13 +273,29 @@ const update = TWEEN.update.bind(TWEEN)
273273

274274
// NOTE! Make sure both lists of exports below are kept in sync:
275275

276-
export {Easing, Group, Interpolation, now, Sequence, nextId, Tween, VERSION, getAll, removeAll, add, remove, update}
276+
export {
277+
Easing,
278+
Group,
279+
Interpolation,
280+
now,
281+
setNow,
282+
Sequence,
283+
nextId,
284+
Tween,
285+
VERSION,
286+
getAll,
287+
removeAll,
288+
add,
289+
remove,
290+
update,
291+
}
277292

278293
const exports = {
279294
Easing,
280295
Group,
281296
Interpolation,
282297
now,
298+
setNow,
283299
Sequence,
284300
nextId,
285301
Tween,

src/Now.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
const now = (): number => performance.now()
1+
let _nowFunc: Function = () => performance.now()
2+
3+
const now = (): number => {
4+
return _nowFunc()
5+
}
6+
7+
export function setNow(nowFunction: Function) {
8+
_nowFunc = nowFunction
9+
}
210

311
export default now

0 commit comments

Comments
 (0)