#697: Added the ability to override the internal "now" function using the "setNow" function.

This commit is contained in:
J00nz 2024-12-18 11:52:54 +01:00
parent eb07dd2012
commit 60de314b09
8 changed files with 52 additions and 10 deletions

10
dist/tween.amd.js vendored
View File

@ -215,7 +215,13 @@ define(['exports'], (function (exports) { 'use strict';
},
});
var now = function () { return performance.now(); };
var _nowFunc = function () { return performance.now(); };
var now = function () {
return _nowFunc();
};
function setNow(nowFunction) {
_nowFunc = nowFunction;
}
/**
* Controlling groups of tweens
@ -1139,6 +1145,7 @@ define(['exports'], (function (exports) { 'use strict';
Group: Group,
Interpolation: Interpolation,
now: now,
setNow: setNow,
Sequence: Sequence,
nextId: nextId,
Tween: Tween,
@ -1398,6 +1405,7 @@ define(['exports'], (function (exports) { 'use strict';
exports.now = now;
exports.remove = remove;
exports.removeAll = removeAll;
exports.setNow = setNow;
exports.update = update;
Object.defineProperty(exports, '__esModule', { value: true });

10
dist/tween.cjs vendored
View File

@ -217,7 +217,13 @@ var Easing = Object.freeze({
},
});
var now = function () { return performance.now(); };
var _nowFunc = function () { return performance.now(); };
var now = function () {
return _nowFunc();
};
function setNow(nowFunction) {
_nowFunc = nowFunction;
}
/**
* Controlling groups of tweens
@ -1141,6 +1147,7 @@ var exports$1 = {
Group: Group,
Interpolation: Interpolation,
now: now,
setNow: setNow,
Sequence: Sequence,
nextId: nextId,
Tween: Tween,
@ -1400,4 +1407,5 @@ exports.nextId = nextId;
exports.now = now;
exports.remove = remove;
exports.removeAll = removeAll;
exports.setNow = setNow;
exports.update = update;

4
dist/tween.d.ts vendored
View File

@ -184,6 +184,7 @@ declare class Group {
}
declare const now: () => number;
declare function setNow(nowFunction: Function): void;
/**
* Utils
@ -470,6 +471,7 @@ declare const exports: {
};
};
now: () => number;
setNow: typeof setNow;
Sequence: typeof Sequence;
nextId: typeof Sequence.nextId;
Tween: typeof Tween;
@ -719,4 +721,4 @@ declare const exports: {
};
};
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, setNow, update };

11
dist/tween.esm.js vendored
View File

@ -213,7 +213,13 @@ var Easing = Object.freeze({
},
});
var now = function () { return performance.now(); };
var _nowFunc = function () { return performance.now(); };
var now = function () {
return _nowFunc();
};
function setNow(nowFunction) {
_nowFunc = nowFunction;
}
/**
* Controlling groups of tweens
@ -1137,6 +1143,7 @@ var exports = {
Group: Group,
Interpolation: Interpolation,
now: now,
setNow: setNow,
Sequence: Sequence,
nextId: nextId,
Tween: Tween,
@ -1383,4 +1390,4 @@ var exports = {
update: update,
};
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, setNow, update };

10
dist/tween.umd.js vendored
View File

@ -219,7 +219,13 @@
},
});
var now = function () { return performance.now(); };
var _nowFunc = function () { return performance.now(); };
var now = function () {
return _nowFunc();
};
function setNow(nowFunction) {
_nowFunc = nowFunction;
}
/**
* Controlling groups of tweens
@ -1143,6 +1149,7 @@
Group: Group,
Interpolation: Interpolation,
now: now,
setNow: setNow,
Sequence: Sequence,
nextId: nextId,
Tween: Tween,
@ -1402,6 +1409,7 @@
exports.now = now;
exports.remove = remove;
exports.removeAll = removeAll;
exports.setNow = setNow;
exports.update = update;
Object.defineProperty(exports, '__esModule', { value: true });

View File

@ -1,5 +1,5 @@
import fs from 'fs'
import pkg from '../package.json' assert {type: 'json'}
import pkg from '../package.json' with {type: 'json'}
const {version} = pkg

View File

@ -10,7 +10,7 @@
import Easing from './Easing'
import Group from './Group'
import Interpolation from './Interpolation'
import now from './Now'
import now, { setNow } from './Now'
import Sequence from './Sequence'
import Tween from './Tween'
import VERSION from './Version'
@ -273,13 +273,14 @@ const update = TWEEN.update.bind(TWEEN)
// NOTE! Make sure both lists of exports below are kept in sync:
export {Easing, Group, Interpolation, now, Sequence, nextId, Tween, VERSION, getAll, removeAll, add, remove, update}
export {Easing, Group, Interpolation, now, setNow, Sequence, nextId, Tween, VERSION, getAll, removeAll, add, remove, update}
const exports = {
Easing,
Group,
Interpolation,
now,
setNow,
Sequence,
nextId,
Tween,

View File

@ -1,3 +1,11 @@
const now = (): number => performance.now()
let _nowFunc: Function = () => performance.now()
const now = (): number => {
return _nowFunc()
}
export function setNow(nowFunction: Function) {
_nowFunc = nowFunction
}
export default now