bard-legends-framework 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_interfaces/index.d.ts +2 -2
- package/dist/_interfaces/index.js +2 -3
- package/dist/game-entities/attachable/attachable.d.ts +6 -6
- package/dist/game-entities/attachable/attachable.js +28 -30
- package/dist/game-entities/attachable/attachable.spec.js +129 -128
- package/dist/game-entities/attachable/attachable.store.d.ts +5 -5
- package/dist/game-entities/attachable/attachable.store.js +34 -32
- package/dist/game-entities/attachable/attachable.test.js +132 -131
- package/dist/game-entities/attachable/destroyable.d.ts +13 -13
- package/dist/game-entities/attachable/destroyable.js +64 -69
- package/dist/game-entities/attachable/helpers/decorate-actions-lib.d.ts +15 -15
- package/dist/game-entities/attachable/helpers/decorate-actions-lib.js +125 -116
- package/dist/game-entities/attachable/helpers/referance-variable.d.ts +15 -15
- package/dist/game-entities/attachable/helpers/referance-variable.js +47 -48
- package/dist/game-entities/attachable/interfaces.d.ts +6 -6
- package/dist/game-entities/attachable/interfaces.js +2 -3
- package/dist/game-entities/base/helpers/decorate-actions-lib.js +0 -1
- package/dist/game-entities/controller/controller.js +0 -1
- package/dist/game-entities/controller/controller.spec.js +128 -125
- package/dist/game-entities/entity/entity.spec.js +263 -293
- package/dist/game-entities/entity/helpers/view-creation.helper.d.ts +7 -7
- package/dist/game-entities/entity/helpers/view-creation.helper.js +48 -48
- package/dist/game-entities/scene/scene.spec.js +219 -223
- package/dist/game-entities/service/service.js +0 -4
- package/dist/game-entities/service/service.spec.js +265 -237
- package/dist/game-entities/service/service.test.js +4 -2
- package/dist/game-entities/update-loop.d.ts +18 -18
- package/dist/game-entities/update-loop.js +46 -28
- package/dist/game-entities/view/view.spec.js +490 -506
- package/dist/game-entities/view/view.test.js +1 -1
- package/dist/lib/animator/animations.d.ts +13 -13
- package/dist/lib/animator/animations.js +43 -40
- package/dist/lib/animator/animator.d.ts +41 -41
- package/dist/lib/animator/animator.js +194 -197
- package/dist/lib/animator/animator.spec.js +699 -612
- package/dist/lib/animator/index.js +24 -19
- package/dist/lib/libraries/animator/animations.d.ts +13 -13
- package/dist/lib/libraries/animator/animations.js +43 -40
- package/dist/lib/libraries/animator/animator.d.ts +41 -41
- package/dist/lib/libraries/animator/animator.js +194 -197
- package/dist/lib/libraries/animator/animator.spec.js +699 -612
- package/dist/lib/libraries/animator/index.js +24 -19
- package/dist/lib/libraries/path-finder/path-finder.d.ts +2 -2
- package/dist/lib/libraries/path-finder/path-finder.js +19 -20
- package/dist/lib/path-finder/path-finder.d.ts +2 -2
- package/dist/lib/path-finder/path-finder.js +19 -20
- package/dist/lib/services/keyboard/keyboard.d.ts +4 -4
- package/dist/lib/services/keyboard/keyboard.js +39 -31
- package/dist/lib/services/mouse/mouse.service.d.ts +8 -8
- package/dist/lib/services/mouse/mouse.service.js +65 -53
- package/dist/lib/services/mouse/mouser-target-focus.service.d.ts +11 -11
- package/dist/lib/services/mouse/mouser-target-focus.service.js +83 -81
- package/dist/lib/update-loop.d.ts +10 -10
- package/dist/lib/update-loop.js +35 -27
- package/dist/physics/entitity-types/immovable-physics-entity.d.ts +6 -6
- package/dist/physics/entitity-types/immovable-physics-entity.js +23 -24
- package/dist/physics/entitity-types/movable-entity.d.ts +6 -6
- package/dist/physics/entitity-types/movable-entity.js +21 -22
- package/dist/physics/entitity-types/movable-physics-entity.d.ts +14 -14
- package/dist/physics/entitity-types/movable-physics-entity.js +83 -88
- package/dist/physics/entitity-types/physics-entity.d.ts +23 -23
- package/dist/physics/entitity-types/physics-entity.js +97 -88
- package/dist/physics/helpers/closest-available-space.helper.d.ts +16 -16
- package/dist/physics/helpers/closest-available-space.helper.js +98 -96
- package/dist/physics/helpers/closest-available-space.helper.spec.js +115 -68
- package/dist/physics/helpers/p2js.helper.d.ts +3 -3
- package/dist/physics/helpers/p2js.helper.js +21 -22
- package/dist/physics/helpers/shape-factory.d.ts +9 -4
- package/dist/physics/helpers/shape-factory.js +99 -75
- package/dist/physics/libs/p2js.helper.js +1 -1
- package/dist/physics/libs/position-to-grid-position-converter.d.ts +3 -3
- package/dist/physics/libs/position-to-grid-position-converter.js +15 -13
- package/dist/physics/module//360/237/223/220services/availability-grid.service.d.ts +10 -5
- package/dist/physics/module//360/237/223/220services/availability-grid.service.js +77 -57
- package/dist/physics/module//360/237/223/220services/border.service.d.ts +2 -2
- package/dist/physics/module//360/237/223/220services/border.service.js +57 -37
- package/dist/physics/module//360/237/223/220services/collision/physics-body-group.service.js +1 -1
- package/dist/physics/module//360/237/223/220services/collisions.service.d.ts +7 -7
- package/dist/physics/module//360/237/223/220services/collisions.service.js +110 -98
- package/dist/physics/module//360/237/223/220services/debug-visuals.service.d.ts +28 -6
- package/dist/physics/module//360/237/223/220services/debug-visuals.service.js +121 -89
- package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.d.ts +15 -7
- package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.js +117 -93
- package/dist/physics/module//360/237/223/220services/explosion.service.d.ts +14 -7
- package/dist/physics/module//360/237/223/220services/explosion.service.js +102 -77
- package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.d.ts +15 -7
- package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.js +117 -93
- package/dist/physics/module//360/237/223/220services/explosions/explosion.service.d.ts +14 -7
- package/dist/physics/module//360/237/223/220services/explosions/explosion.service.js +102 -77
- package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.js +71 -67
- package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.js +71 -67
- package/dist/physics/module//360/237/223/220services/impact/eliptic-explosion.service.js +1 -1
- package/dist/physics/module//360/237/223/220services/materials.service.d.ts +16 -11
- package/dist/physics/module//360/237/223/220services/materials.service.js +118 -108
- package/dist/physics/module//360/237/223/220services/path-finder.service.d.ts +19 -8
- package/dist/physics/module//360/237/223/220services/path-finder.service.js +121 -82
- package/dist/physics/module//360/237/223/220services/physics-world.service.d.ts +30 -15
- package/dist/physics/module//360/237/223/220services/physics-world.service.js +122 -100
- package/dist/physics/module//360/237/223/220services/ray-casting.service.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/ray-casting.service.js +87 -86
- package/dist/physics/module//360/237/223/220services/shape-creation.service.d.ts +9 -4
- package/dist/physics/module//360/237/223/220services/shape-creation.service.js +113 -84
- package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +2 -1
- package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.d.ts +8 -8
- package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.js +32 -33
- package/dist/physics/physics-world.d.ts +50 -34
- package/dist/physics/physics-world.js +142 -133
- package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.d.ts +3 -3
- package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.js +15 -13
- package/dist/physics/sub-elements/available-spaces/physics-availability-grid.d.ts +9 -9
- package/dist/physics/sub-elements/available-spaces/physics-availability-grid.js +82 -77
- package/dist/physics/sub-elements/available-spaces/physics-available-spaces.d.ts +18 -14
- package/dist/physics/sub-elements/available-spaces/physics-available-spaces.js +91 -79
- package/dist/physics/sub-elements/collisions/contact-equation-orginiser.d.ts +11 -11
- package/dist/physics/sub-elements/collisions/contact-equation-orginiser.js +84 -76
- package/dist/physics/sub-elements/collisions/physics-collision.d.ts +7 -7
- package/dist/physics/sub-elements/collisions/physics-collision.js +43 -44
- package/dist/physics/sub-elements/elements/physics-body-groups.d.ts +11 -11
- package/dist/physics/sub-elements/elements/physics-body-groups.js +54 -54
- package/dist/physics/sub-elements/elements/physics-materials.d.ts +15 -10
- package/dist/physics/sub-elements/elements/physics-materials.js +101 -100
- package/dist/physics/sub-elements/elements/physics-world-borders.d.ts +3 -3
- package/dist/physics/sub-elements/elements/physics-world-borders.js +69 -45
- package/dist/physics/sub-elements/physics-body-groups.d.ts +8 -8
- package/dist/physics/sub-elements/physics-body-groups.js +41 -42
- package/dist/physics/sub-elements/physics-collision.d.ts +16 -16
- package/dist/physics/sub-elements/physics-collision.js +141 -121
- package/dist/physics/sub-elements/physics-materials.d.ts +15 -10
- package/dist/physics/sub-elements/physics-materials.js +101 -100
- package/dist/physics/sub-elements/physics-world-borders.d.ts +2 -2
- package/dist/physics/sub-elements/physics-world-borders.js +25 -26
- package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.d.ts +15 -11
- package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.js +59 -59
- package/dist/physics/sub-elements/raycasting/physics-explosion.d.ts +13 -6
- package/dist/physics/sub-elements/raycasting/physics-explosion.js +108 -73
- package/dist/physics/sub-elements/raycasting/ray-cast.d.ts +19 -19
- package/dist/physics/sub-elements/raycasting/ray-cast.js +93 -98
- package/dist/pixi/display-object/components/filters.d.ts +18 -18
- package/dist/pixi/display-object/components/filters.js +106 -81
- package/dist/pixi/display-object/components/glow-effect.d.ts +8 -8
- package/dist/pixi/display-object/components/glow-effect.js +33 -36
- package/dist/pixi/display-object/components/glow-filter.d.ts +8 -8
- package/dist/pixi/display-object/components/glow-filter.js +33 -36
- package/dist/pixi/display-object/container-attributes.js +1 -1
- package/dist/pixi/display-object/display-object-attributes.d.ts +41 -41
- package/dist/pixi/display-object/display-object-attributes.js +148 -150
- package/dist/pixi/display-object/display-object.d.ts +17 -17
- package/dist/pixi/display-object/display-object.js +79 -75
- package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.d.ts +9 -4
- package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.js +89 -77
- package/dist/pixi/display-object/filters/base-filters/blur.filter.js +30 -30
- package/dist/pixi/display-object/filters/base-filters/contrast-filter.d.ts +9 -4
- package/dist/pixi/display-object/filters/base-filters/contrast-filter.js +62 -53
- package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.d.ts +10 -5
- package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.js +93 -81
- package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.d.ts +12 -7
- package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.js +120 -109
- package/dist/pixi/display-object/filters/base-filters/expand-with-color.d.ts +10 -5
- package/dist/pixi/display-object/filters/base-filters/expand-with-color.filter.js +32 -32
- package/dist/pixi/display-object/filters/base-filters/expand-with-color.js +92 -85
- package/dist/pixi/display-object/filters/templates/checking-neighbors.template.js +28 -28
- package/dist/pixi/display-object/filters/templates/plane.template.js +20 -20
- package/dist/pixi/display-object/filters.js +20 -4
- package/dist/pixi/display-object/objects/components/filters.d.ts +18 -18
- package/dist/pixi/display-object/objects/components/filters.js +106 -81
- package/dist/pixi/display-object/objects/container.d.ts +2 -2
- package/dist/pixi/display-object/objects/container.js +39 -30
- package/dist/pixi/display-object/objects/graphics.d.ts +28 -28
- package/dist/pixi/display-object/objects/graphics.js +218 -202
- package/dist/pixi/display-object/objects/helpers/filters.d.ts +25 -25
- package/dist/pixi/display-object/objects/helpers/filters.js +150 -124
- package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.d.ts +7 -7
- package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.js +114 -95
- package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.d.ts +5 -5
- package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.js +81 -57
- package/dist/pixi/display-object/objects/sprite.d.ts +43 -43
- package/dist/pixi/display-object/objects/sprite.js +248 -233
- package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.js +1 -1
- package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.test.js +9 -9
- package/dist/pixi/display-object/objects/text/helpers/rich-text-to-plane-text.d.ts +1 -1
- package/dist/pixi/display-object/objects/text.d.ts +25 -25
- package/dist/pixi/display-object/objects/text.js +111 -102
- package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.d.ts +13 -9
- package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.js +96 -67
- package/dist/pixi/game.d.ts +1 -1
- package/dist/pixi/game.js +2 -2
- package/dist/pixi/helpers/glow-sprite-generator.d.ts +6 -6
- package/dist/pixi/helpers/glow-sprite-generator.js +99 -84
- package/dist/pixi/helpers/pixi-container.helper.d.ts +1 -1
- package/dist/pixi/helpers/pixi-container.helper.js +10 -8
- package/dist/pixi/helpers/screen-position-to-stage.helper.d.ts +1 -1
- package/dist/pixi/helpers/screen-position-to-stage.helper.js +12 -12
- package/dist/pixi/helpers/screen-position-to-stage.helper.test.js +174 -79
- package/dist/pixi/modules/CAMERA/index.d.ts +1 -1
- package/dist/pixi/modules/CAMERA/index.js +3 -3
- package/dist/services/keyboard/keyboard.d.ts +4 -4
- package/dist/services/keyboard/keyboard.js +39 -31
- package/dist/services/mouse/mouse.service.d.ts +8 -8
- package/dist/services/mouse/mouse.service.js +65 -53
- package/dist/services/mouse/mouser-target-focus.service.d.ts +11 -11
- package/dist/services/mouse/mouser-target-focus.service.js +83 -81
- package/dist/utilities/libraries/animator/animating-content/state-animation.d.ts +29 -26
- package/dist/utilities/libraries/animator/animating-content/state-animation.js +159 -165
- package/dist/utilities/libraries/animator/animating-content/state-animation.test.js +386 -375
- package/dist/utilities/libraries/animator/animator.spec.js +765 -656
- package/dist/utilities/libraries/binary-heap/binary-heap.d.ts +11 -11
- package/dist/utilities/libraries/binary-heap/binary-heap.js +79 -81
- package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.d.ts +11 -11
- package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.js +79 -81
- package/dist/utilities/libraries/data-structures/grid/grid.d.ts +35 -31
- package/dist/utilities/libraries/data-structures/grid/grid.js +128 -117
- package/dist/utilities/libraries/data-structures/grid/grid.spec.js +176 -138
- package/dist/utilities/libraries/data-structures/grid/grid.test.js +218 -141
- package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.d.ts +3 -3
- package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.js +15 -13
- package/dist/utilities/libraries/data-structures/queue/queue.d.ts +21 -21
- package/dist/utilities/libraries/data-structures/queue/queue.js +63 -66
- package/dist/utilities/libraries/data-structures/queue/queue.test.js +54 -55
- package/dist/utilities/libraries/grid-algorithms/closest-available-space/closest-available-space.helper.spec.js +122 -68
- package/dist/utilities/libraries/grid-algorithms/path-finder/path-finder.spec.js +140 -135
- package/dist/utilities/libraries/grid-algorithms/vector-field-path-finder/vector-field-path-finder.spec.js +293 -229
- package/dist/utilities/libraries/path-finder/path-finder.d.ts +7 -7
- package/dist/utilities/libraries/path-finder/path-finder.js +113 -109
- package/dist/utilities/libraries/path-finder/path-finder.spec.js +131 -106
- package/dist/utilities/services/keyboard/keyboard.d.ts +4 -4
- package/dist/utilities/services/keyboard/keyboard.js +42 -34
- package/dist/utilities/services/mouse/helpers/mouse-position.helper.d.ts +1 -1
- package/dist/utilities/services/mouse/helpers/mouse-position.helper.js +12 -12
- package/dist/utilities/services/mouse/helpers/mouse-position.helper.test.js +168 -73
- package/dist/utilities/services/mouse/mouse-target-focus.service.d.ts +15 -15
- package/dist/utilities/services/mouse/mouse-target-focus.service.js +79 -76
- package/dist/utilities/services/mouse/mouse.service.d.ts +9 -9
- package/dist/utilities/services/mouse/mouse.service.js +86 -72
- package/dist/utilities/services/mouse/mouser-target-focus.service.d.ts +11 -11
- package/dist/utilities/services/mouse/mouser-target-focus.service.js +83 -81
- package/package.json +4 -10
|
@@ -1,670 +1,779 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
var __createBinding =
|
|
2
|
+
(this && this.__createBinding) ||
|
|
3
|
+
(Object.create
|
|
4
|
+
? (o, m, k, k2) => {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: () => m[k] };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}
|
|
12
|
+
: (o, m, k, k2) => {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
});
|
|
16
|
+
var __setModuleDefault =
|
|
17
|
+
(this && this.__setModuleDefault) ||
|
|
18
|
+
(Object.create
|
|
19
|
+
? (o, v) => {
|
|
20
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
21
|
+
}
|
|
22
|
+
: (o, v) => {
|
|
23
|
+
o['default'] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar =
|
|
26
|
+
(this && this.__importStar) ||
|
|
27
|
+
(mod => {
|
|
19
28
|
if (mod && mod.__esModule) return mod;
|
|
20
29
|
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !==
|
|
30
|
+
if (mod != null) for (var k in mod) if (k !== 'default' && Object.hasOwn(mod, k)) __createBinding(result, mod, k);
|
|
22
31
|
__setModuleDefault(result, mod);
|
|
23
32
|
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports,
|
|
26
|
-
const vitest_1 = require(
|
|
27
|
-
const helpers_lib_1 = require(
|
|
28
|
-
const ActionsLib = __importStar(require(
|
|
29
|
-
const animator_1 = require(
|
|
30
|
-
const animations_1 = require(
|
|
31
|
-
const decorate_actions_lib_1 = require(
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
35
|
+
const vitest_1 = require('vitest');
|
|
36
|
+
const helpers_lib_1 = require('helpers-lib');
|
|
37
|
+
const ActionsLib = __importStar(require('actions-lib'));
|
|
38
|
+
const animator_1 = require('./animator');
|
|
39
|
+
const animations_1 = require('./animations');
|
|
40
|
+
const decorate_actions_lib_1 = require('../../../game-entities/attachable/helpers/decorate-actions-lib');
|
|
32
41
|
decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
|
|
33
42
|
(0, vitest_1.describe)('ANIMATOR', () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
(0, vitest_1.test)('constructor should throw error if target does not have all target properties', () => {
|
|
42
|
-
let obj = { x: 1, y: 2, z: 3 };
|
|
43
|
-
(0, vitest_1.expect)(() => {
|
|
44
|
-
new animator_1.Animator(obj, ['x', 't']);
|
|
45
|
-
}).toThrow();
|
|
46
|
-
});
|
|
47
|
-
(0, vitest_1.test)('constructor should throw error if target property is not a number', () => {
|
|
48
|
-
let obj = { x: 'fail' };
|
|
49
|
-
(0, vitest_1.expect)(() => {
|
|
50
|
-
new animator_1.Animator(obj, ['x']);
|
|
51
|
-
}).toThrow();
|
|
52
|
-
});
|
|
53
|
-
(0, vitest_1.test)('animate should throw error if non effected property tried to animate', () => {
|
|
54
|
-
(0, vitest_1.expect)(() => {
|
|
55
|
-
let obj = { x: 0, y: 0 };
|
|
56
|
-
let animator = new animator_1.Animator(obj, ['x', 't']);
|
|
57
|
-
animator.animate({ x: 5, y: 5 });
|
|
58
|
-
}).toThrow();
|
|
59
|
-
});
|
|
60
|
-
(0, vitest_1.test)('should throw error if multiple animators decorate the same object', () => {
|
|
61
|
-
(0, vitest_1.expect)(() => {
|
|
62
|
-
let obj = { x: 0 };
|
|
63
|
-
new animator_1.Animator(obj, 'x');
|
|
64
|
-
new animator_1.Animator(obj, 'x');
|
|
65
|
-
}).toThrow();
|
|
66
|
-
});
|
|
67
|
-
(0, vitest_1.test)('setting multiple update callbacks should throw error', () => {
|
|
68
|
-
(0, vitest_1.expect)(() => {
|
|
69
|
-
let obj = { x: 0 };
|
|
70
|
-
new animator_1.Animator(obj, 'x').onChange(() => { }).onChange(() => { });
|
|
71
|
-
}).toThrow();
|
|
72
|
-
});
|
|
43
|
+
(0, vitest_1.describe)('Setup', () => {
|
|
44
|
+
(0, vitest_1.test)('constructor should throw error if target is not an object', () => {
|
|
45
|
+
const obj = 'string';
|
|
46
|
+
(0, vitest_1.expect)(() => {
|
|
47
|
+
new animator_1.Animator(obj, 'x');
|
|
48
|
+
}).toThrow();
|
|
73
49
|
});
|
|
74
|
-
(0, vitest_1.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
80
|
-
});
|
|
81
|
-
(0, vitest_1.test)('animate to target in lineer', () => {
|
|
82
|
-
let obj = { x: 0 };
|
|
83
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationLineer() });
|
|
84
|
-
animator.animate({ x: 4 });
|
|
85
|
-
animator['update'](1);
|
|
86
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
87
|
-
animator['update'](1);
|
|
88
|
-
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
89
|
-
animator['update'](1);
|
|
90
|
-
(0, vitest_1.expect)(obj.x).toEqual(3);
|
|
91
|
-
animator['update'](1);
|
|
92
|
-
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
93
|
-
});
|
|
94
|
-
(0, vitest_1.test)('animate only one property should not effect the other', () => {
|
|
95
|
-
let obj = { x: 0, y: 0 };
|
|
96
|
-
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: new animations_1.AnimationLineer() });
|
|
97
|
-
animator.animate({ x: 4 });
|
|
98
|
-
animator['update'](1);
|
|
99
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 1, y: 0 });
|
|
100
|
-
animator['update'](1);
|
|
101
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
|
|
102
|
-
animator['update'](1);
|
|
103
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 3, y: 0 });
|
|
104
|
-
animator['update'](1);
|
|
105
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 4, y: 0 });
|
|
106
|
-
});
|
|
107
|
-
(0, vitest_1.test)('animate with custom values should override the default settings', () => {
|
|
108
|
-
let obj = { x: 0 };
|
|
109
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 10, animation: new animations_1.AnimationLineer() });
|
|
110
|
-
animator.animate({ x: 10 }, { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
111
|
-
animator['update'](1);
|
|
112
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 1.25 });
|
|
113
|
-
animator['update'](1);
|
|
114
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 5 });
|
|
115
|
-
animator['update'](1);
|
|
116
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 8.75 });
|
|
117
|
-
animator['update'](1);
|
|
118
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 10 });
|
|
119
|
-
});
|
|
120
|
-
(0, vitest_1.test)('animate to target in easeInOut starting from zero', () => {
|
|
121
|
-
let obj = { x: 0 };
|
|
122
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
123
|
-
animator.animate({ x: 10 });
|
|
124
|
-
animator['update'](1);
|
|
125
|
-
(0, vitest_1.expect)(obj.x).toEqual(1.25);
|
|
126
|
-
animator['update'](1);
|
|
127
|
-
(0, vitest_1.expect)(obj.x).toEqual(5);
|
|
128
|
-
animator['update'](1);
|
|
129
|
-
(0, vitest_1.expect)(obj.x).toEqual(8.75);
|
|
130
|
-
animator['update'](1);
|
|
131
|
-
(0, vitest_1.expect)(obj.x).toEqual(10);
|
|
132
|
-
});
|
|
133
|
-
(0, vitest_1.test)('animate to target in easeInOut starting from different value than zero', () => {
|
|
134
|
-
let obj = { x: 10 };
|
|
135
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
136
|
-
animator.animate({ x: 20 });
|
|
137
|
-
animator['update'](1);
|
|
138
|
-
(0, vitest_1.expect)(obj.x).toEqual(11.25);
|
|
139
|
-
animator['update'](1);
|
|
140
|
-
(0, vitest_1.expect)(obj.x).toEqual(15);
|
|
141
|
-
animator['update'](1);
|
|
142
|
-
(0, vitest_1.expect)(obj.x).toEqual(18.75);
|
|
143
|
-
animator['update'](1);
|
|
144
|
-
(0, vitest_1.expect)(obj.x).toEqual(20);
|
|
145
|
-
});
|
|
146
|
-
(0, vitest_1.test)('animate to target and return back', () => {
|
|
147
|
-
let obj = { x: 0 };
|
|
148
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: new animations_1.AnimationLineer() });
|
|
149
|
-
animator.animate({ x: 4 });
|
|
150
|
-
animator['update'](1);
|
|
151
|
-
animator.animate({ x: 0 });
|
|
152
|
-
animator['update'](1);
|
|
153
|
-
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
154
|
-
});
|
|
155
|
-
(0, vitest_1.test)('animate onChange callbacks', () => {
|
|
156
|
-
let obj = { x: 0 };
|
|
157
|
-
let valueFromOnStep = 0;
|
|
158
|
-
let onStepCallCount = 0;
|
|
159
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationEaseInOut() }).onChange(item => {
|
|
160
|
-
valueFromOnStep = item.x;
|
|
161
|
-
onStepCallCount++;
|
|
162
|
-
});
|
|
163
|
-
animator.animate({ x: 10 });
|
|
164
|
-
(0, vitest_1.expect)(valueFromOnStep).toEqual(0);
|
|
165
|
-
(0, vitest_1.expect)(onStepCallCount).toEqual(0);
|
|
166
|
-
animator['update'](1);
|
|
167
|
-
(0, vitest_1.expect)(onStepCallCount).toEqual(1);
|
|
168
|
-
(0, vitest_1.expect)(valueFromOnStep).toEqual(1.25);
|
|
169
|
-
animator['update'](1);
|
|
170
|
-
(0, vitest_1.expect)(onStepCallCount).toEqual(2);
|
|
171
|
-
(0, vitest_1.expect)(valueFromOnStep).toEqual(5);
|
|
172
|
-
animator['update'](1);
|
|
173
|
-
(0, vitest_1.expect)(onStepCallCount).toEqual(3);
|
|
174
|
-
(0, vitest_1.expect)(valueFromOnStep).toEqual(8.75);
|
|
175
|
-
animator['update'](1);
|
|
176
|
-
(0, vitest_1.expect)(onStepCallCount).toEqual(4);
|
|
177
|
-
(0, vitest_1.expect)(valueFromOnStep).toEqual(10);
|
|
178
|
-
animator['update'](1);
|
|
179
|
-
animator['update'](1);
|
|
180
|
-
animator['update'](1);
|
|
181
|
-
(0, vitest_1.expect)(onStepCallCount).toEqual(4);
|
|
182
|
-
});
|
|
183
|
-
(0, vitest_1.test)('animate onChange should not be triggered before starting the animation', () => {
|
|
184
|
-
let onStepCallCount = 0;
|
|
185
|
-
let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 4, animation: new animations_1.AnimationEaseInOut() }).onChange(() => {
|
|
186
|
-
onStepCallCount++;
|
|
187
|
-
});
|
|
188
|
-
animator['update'](1);
|
|
189
|
-
(0, vitest_1.expect)(onStepCallCount).toEqual(0);
|
|
190
|
-
});
|
|
191
|
-
(0, vitest_1.test)('animation complete promise', async () => {
|
|
192
|
-
let obj = { x: 0 };
|
|
193
|
-
let completed = false;
|
|
194
|
-
let animator = new animator_1.Animator(obj, 'x');
|
|
195
|
-
animator.animate({ x: 1 }, { duration: 2 }).then(() => {
|
|
196
|
-
completed = true;
|
|
197
|
-
});
|
|
198
|
-
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
199
|
-
animator['update'](1);
|
|
200
|
-
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
201
|
-
animator['update'](1);
|
|
202
|
-
await (0, helpers_lib_1.Wait)();
|
|
203
|
-
(0, vitest_1.expect)(completed).toBeTruthy();
|
|
204
|
-
});
|
|
205
|
-
(0, vitest_1.test)('animate getter/setter property', () => {
|
|
206
|
-
class Foo {
|
|
207
|
-
constructor() {
|
|
208
|
-
this._x = 10;
|
|
209
|
-
}
|
|
210
|
-
get x() {
|
|
211
|
-
return this._x;
|
|
212
|
-
}
|
|
213
|
-
set x(value) {
|
|
214
|
-
this._x = value;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
let obj = new Foo();
|
|
218
|
-
let animator = new animator_1.Animator(obj, ['x'], { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
219
|
-
animator.animate({ x: 20 });
|
|
220
|
-
animator['update'](1);
|
|
221
|
-
(0, vitest_1.expect)(obj.x).toEqual(11.25);
|
|
222
|
-
animator['update'](1);
|
|
223
|
-
(0, vitest_1.expect)(obj.x).toEqual(15);
|
|
224
|
-
animator['update'](1);
|
|
225
|
-
(0, vitest_1.expect)(obj.x).toEqual(18.75);
|
|
226
|
-
animator['update'](1);
|
|
227
|
-
(0, vitest_1.expect)(obj.x).toEqual(20);
|
|
228
|
-
});
|
|
229
|
-
(0, vitest_1.test)('is animating should return true if it is animating', () => {
|
|
230
|
-
let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 1, animation: new animations_1.AnimationLineer() });
|
|
231
|
-
animator.animate({ x: 1 });
|
|
232
|
-
(0, vitest_1.expect)(animator.isAnimating).toBeTruthy();
|
|
233
|
-
});
|
|
234
|
-
(0, vitest_1.test)('is animating should return false if it is not animating', () => {
|
|
235
|
-
let obj = { x: 0 };
|
|
236
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: new animations_1.AnimationLineer() });
|
|
237
|
-
(0, vitest_1.expect)(animator.isAnimating).toBeFalsy();
|
|
238
|
-
animator.animate({ x: 1 });
|
|
239
|
-
animator['update'](1);
|
|
240
|
-
(0, vitest_1.expect)(animator.isAnimating).toBeFalsy();
|
|
241
|
-
});
|
|
50
|
+
(0, vitest_1.test)('constructor should throw error if target does not have all target properties', () => {
|
|
51
|
+
const obj = { x: 1, y: 2, z: 3 };
|
|
52
|
+
(0, vitest_1.expect)(() => {
|
|
53
|
+
new animator_1.Animator(obj, ['x', 't']);
|
|
54
|
+
}).toThrow();
|
|
242
55
|
});
|
|
243
|
-
(0, vitest_1.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
animator['update'](1);
|
|
249
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 1 });
|
|
250
|
-
animator['update'](1);
|
|
251
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
252
|
-
animator.pauseAnimations();
|
|
253
|
-
animator['update'](1);
|
|
254
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
255
|
-
animator['update'](1);
|
|
256
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
257
|
-
animator.resumeAnimations();
|
|
258
|
-
animator['update'](1);
|
|
259
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 3 });
|
|
260
|
-
animator['update'](1);
|
|
261
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 4 });
|
|
262
|
-
});
|
|
263
|
-
(0, vitest_1.test)('new animations should not proceed while the animations are paused', async () => {
|
|
264
|
-
let obj = { x: 0 };
|
|
265
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 2, animation: new animations_1.AnimationLineer() });
|
|
266
|
-
animator.pauseAnimations();
|
|
267
|
-
animator.animate({ x: 2 });
|
|
268
|
-
animator['update'](1);
|
|
269
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 0 });
|
|
270
|
-
animator['update'](1);
|
|
271
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 0 });
|
|
272
|
-
animator.resumeAnimations();
|
|
273
|
-
animator['update'](1);
|
|
274
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 1 });
|
|
275
|
-
animator['update'](1);
|
|
276
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
277
|
-
});
|
|
278
|
-
(0, vitest_1.test)('animation loop', async () => {
|
|
279
|
-
let obj = { x: 0 };
|
|
280
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 2, animation: new animations_1.AnimationLineer(), loop: true });
|
|
281
|
-
animator.animate({ x: 2 }, { duration: 2 });
|
|
282
|
-
animator['update'](1);
|
|
283
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
284
|
-
animator['update'](1);
|
|
285
|
-
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
286
|
-
animator['update'](1);
|
|
287
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
288
|
-
animator['update'](0.8);
|
|
289
|
-
(0, vitest_1.expect)(obj.x).toEqual(1.8);
|
|
290
|
-
animator['update'](0.7);
|
|
291
|
-
(0, vitest_1.expect)(obj.x).toEqual(0.5);
|
|
292
|
-
});
|
|
56
|
+
(0, vitest_1.test)('constructor should throw error if target property is not a number', () => {
|
|
57
|
+
const obj = { x: 'fail' };
|
|
58
|
+
(0, vitest_1.expect)(() => {
|
|
59
|
+
new animator_1.Animator(obj, ['x']);
|
|
60
|
+
}).toThrow();
|
|
293
61
|
});
|
|
294
|
-
(0, vitest_1.
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
animator['update'](1);
|
|
301
|
-
(0, vitest_1.expect)(async () => await animator.animate({ x: 0 })).rejects.toThrow();
|
|
302
|
-
});
|
|
303
|
-
(0, vitest_1.test)('re-animation handling option ignore should ignore new animation', () => {
|
|
304
|
-
let obj = { x: 0 };
|
|
305
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 1, reAnimateHandling: animator_1.ReAnimateHandlingType.ignore });
|
|
306
|
-
animator.animate({ x: 1 });
|
|
307
|
-
animator.animate({ x: 2 });
|
|
308
|
-
animator['update'](1);
|
|
309
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
310
|
-
});
|
|
311
|
-
(0, vitest_1.test)('re-animation handling option ignore should ignore multiple property animation', () => {
|
|
312
|
-
let obj = { x: 0, y: 0 };
|
|
313
|
-
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 1, reAnimateHandling: animator_1.ReAnimateHandlingType.ignore });
|
|
314
|
-
animator.animate({ x: 1 });
|
|
315
|
-
animator.animate({ x: 2, y: 1 });
|
|
316
|
-
animator['update'](1);
|
|
317
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 1, y: 1 });
|
|
318
|
-
});
|
|
319
|
-
(0, vitest_1.test)('animate switch after finishes to a different animation type should not throw error', () => {
|
|
320
|
-
let obj = { x: 1 };
|
|
321
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 1 });
|
|
322
|
-
animator.animate({ x: 0 }, { animation: new animations_1.AnimationLineer() });
|
|
323
|
-
animator['update'](1);
|
|
324
|
-
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
325
|
-
animator.animate({ x: 10 }, { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
326
|
-
animator['update'](1);
|
|
327
|
-
(0, vitest_1.expect)(obj.x).toEqual(1.25);
|
|
328
|
-
animator['update'](1);
|
|
329
|
-
(0, vitest_1.expect)(obj.x).toEqual(5);
|
|
330
|
-
animator['update'](1);
|
|
331
|
-
(0, vitest_1.expect)(obj.x).toEqual(8.75);
|
|
332
|
-
animator['update'](1);
|
|
333
|
-
(0, vitest_1.expect)(obj.x).toEqual(10);
|
|
334
|
-
});
|
|
335
|
-
(0, vitest_1.test)('re-animation handling option canceling should cancel the ongoing animation', () => {
|
|
336
|
-
let obj = { x: 0 };
|
|
337
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 1, reAnimateHandling: animator_1.ReAnimateHandlingType.cancelPrevious });
|
|
338
|
-
animator.animate({ x: 1 });
|
|
339
|
-
animator.animate({ x: 2 });
|
|
340
|
-
animator['update'](1);
|
|
341
|
-
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
342
|
-
});
|
|
343
|
-
(0, vitest_1.test)('re-animation handling option canceling should cancel the ongoing multiple property animation', () => {
|
|
344
|
-
let obj = { x: 0, y: 0 };
|
|
345
|
-
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 1, reAnimateHandling: animator_1.ReAnimateHandlingType.cancelPrevious });
|
|
346
|
-
animator.animate({ x: 1 });
|
|
347
|
-
animator.animate({ x: 2, y: 1 });
|
|
348
|
-
animator['update'](1);
|
|
349
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 1 });
|
|
350
|
-
});
|
|
351
|
-
(0, vitest_1.test)('re-animation handling option canceling should cancel the animation with keeping the current value', () => {
|
|
352
|
-
let obj = { x: 0 };
|
|
353
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 2, reAnimateHandling: animator_1.ReAnimateHandlingType.cancelPrevious });
|
|
354
|
-
animator.animate({ x: 2 });
|
|
355
|
-
animator['update'](1);
|
|
356
|
-
animator.animate({ x: 3 });
|
|
357
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
358
|
-
animator['update'](1);
|
|
359
|
-
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
360
|
-
animator['update'](1);
|
|
361
|
-
(0, vitest_1.expect)(obj.x).toEqual(3);
|
|
362
|
-
});
|
|
62
|
+
(0, vitest_1.test)('animate should throw error if non effected property tried to animate', () => {
|
|
63
|
+
(0, vitest_1.expect)(() => {
|
|
64
|
+
const obj = { x: 0, y: 0 };
|
|
65
|
+
const animator = new animator_1.Animator(obj, ['x', 't']);
|
|
66
|
+
animator.animate({ x: 5, y: 5 });
|
|
67
|
+
}).toThrow();
|
|
363
68
|
});
|
|
364
|
-
(0, vitest_1.
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}).toThrow();
|
|
371
|
-
});
|
|
372
|
-
(0, vitest_1.test)('it should throw error if the property is not valid', () => {
|
|
373
|
-
let animator = new animator_1.Animator({ x: 0 }, 'x');
|
|
374
|
-
(0, vitest_1.expect)(() => {
|
|
375
|
-
animator.set({ t: 0 });
|
|
376
|
-
}).toThrow();
|
|
377
|
-
});
|
|
378
|
-
(0, vitest_1.test)('it should change the original value', () => {
|
|
379
|
-
let obj = { x: 0, y: 1, z: 2 };
|
|
380
|
-
let animator = new animator_1.Animator(obj, ['x', 'y', 'z']);
|
|
381
|
-
animator.set({ x: 3, y: 4 });
|
|
382
|
-
(0, vitest_1.expect)(obj).toEqual({ x: 3, y: 4, z: 2 });
|
|
383
|
-
});
|
|
384
|
-
(0, vitest_1.test)('it should trigger onChange', () => {
|
|
385
|
-
let obj = { x: 0 };
|
|
386
|
-
let valueFromOnStep = 0;
|
|
387
|
-
let onStepCallCount = 0;
|
|
388
|
-
let animator = new animator_1.Animator(obj, 'x').onChange(item => {
|
|
389
|
-
valueFromOnStep = item.x;
|
|
390
|
-
onStepCallCount++;
|
|
391
|
-
});
|
|
392
|
-
animator.set({ x: 1 });
|
|
393
|
-
(0, vitest_1.expect)(valueFromOnStep).toEqual(1);
|
|
394
|
-
(0, vitest_1.expect)(onStepCallCount).toEqual(1);
|
|
395
|
-
});
|
|
396
|
-
(0, vitest_1.test)('it should not trigger onChange if the value is the same', () => {
|
|
397
|
-
let obj = { x: 0 };
|
|
398
|
-
let onStepCallCount = 0;
|
|
399
|
-
let animator = new animator_1.Animator(obj, 'x').onChange(() => {
|
|
400
|
-
onStepCallCount++;
|
|
401
|
-
});
|
|
402
|
-
animator.set({ x: 0 });
|
|
403
|
-
(0, vitest_1.expect)(onStepCallCount).toEqual(0);
|
|
404
|
-
});
|
|
69
|
+
(0, vitest_1.test)('should throw error if multiple animators decorate the same object', () => {
|
|
70
|
+
(0, vitest_1.expect)(() => {
|
|
71
|
+
const obj = { x: 0 };
|
|
72
|
+
new animator_1.Animator(obj, 'x');
|
|
73
|
+
new animator_1.Animator(obj, 'x');
|
|
74
|
+
}).toThrow();
|
|
405
75
|
});
|
|
406
|
-
(0, vitest_1.
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
animation: new animations_1.AnimationLineer(),
|
|
412
|
-
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
413
|
-
});
|
|
414
|
-
animator.animate({ x: 1 });
|
|
415
|
-
animator['update'](1);
|
|
416
|
-
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
417
|
-
});
|
|
418
|
-
(0, vitest_1.test)('complete animations should finalize the ongoing animation', async () => {
|
|
419
|
-
let obj = { x: 0 };
|
|
420
|
-
let completed = false;
|
|
421
|
-
let animator = new animator_1.Animator(obj, 'x');
|
|
422
|
-
animator.animate({ x: 1 }, { duration: 4 }).then(() => {
|
|
423
|
-
completed = true;
|
|
424
|
-
});
|
|
425
|
-
animator['update'](1);
|
|
426
|
-
await (0, helpers_lib_1.Wait)();
|
|
427
|
-
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
428
|
-
animator.completeAnimations();
|
|
429
|
-
await (0, helpers_lib_1.Wait)();
|
|
430
|
-
(0, vitest_1.expect)(completed).toBeTruthy();
|
|
431
|
-
});
|
|
432
|
-
(0, vitest_1.test)('complete animations should finalize the all ongoing animations', async () => {
|
|
433
|
-
let completed1 = false;
|
|
434
|
-
let completed2 = false;
|
|
435
|
-
let obj = { x: 0, y: 0 };
|
|
436
|
-
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
437
|
-
animator.animate({ y: 10 }, { loop: true }).then(() => {
|
|
438
|
-
completed1 = true;
|
|
439
|
-
});
|
|
440
|
-
animator['update'](1);
|
|
441
|
-
animator.animate({ x: 10 }).then(() => {
|
|
442
|
-
completed2 = true;
|
|
443
|
-
});
|
|
444
|
-
animator['update'](1);
|
|
445
|
-
await (0, helpers_lib_1.Wait)();
|
|
446
|
-
(0, vitest_1.expect)(completed1).toBeFalsy();
|
|
447
|
-
(0, vitest_1.expect)(completed2).toBeFalsy();
|
|
448
|
-
animator.completeAnimations();
|
|
449
|
-
await (0, helpers_lib_1.Wait)();
|
|
450
|
-
(0, vitest_1.expect)(completed1).toBeTruthy();
|
|
451
|
-
(0, vitest_1.expect)(completed2).toBeTruthy();
|
|
452
|
-
});
|
|
453
|
-
(0, vitest_1.test)('complete animations stay in current state', async () => {
|
|
454
|
-
let obj = { x: 0 };
|
|
455
|
-
let animator = new animator_1.Animator(obj, 'x');
|
|
456
|
-
animator.animate({ x: 4 }, {
|
|
457
|
-
duration: 4,
|
|
458
|
-
animation: new animations_1.AnimationLineer(),
|
|
459
|
-
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
|
|
460
|
-
});
|
|
461
|
-
animator['update'](1);
|
|
462
|
-
await (0, helpers_lib_1.Wait)();
|
|
463
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
464
|
-
animator.completeAnimations();
|
|
465
|
-
animator['update'](1);
|
|
466
|
-
await (0, helpers_lib_1.Wait)();
|
|
467
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
468
|
-
});
|
|
469
|
-
(0, vitest_1.test)('complete animations jump to end', async () => {
|
|
470
|
-
let obj = { x: 0 };
|
|
471
|
-
let animator = new animator_1.Animator(obj, 'x');
|
|
472
|
-
animator.animate({ x: 4 }, {
|
|
473
|
-
duration: 4,
|
|
474
|
-
animation: new animations_1.AnimationLineer(),
|
|
475
|
-
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
|
|
476
|
-
});
|
|
477
|
-
animator['update'](1);
|
|
478
|
-
await (0, helpers_lib_1.Wait)();
|
|
479
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
480
|
-
animator.completeAnimations();
|
|
481
|
-
animator['update'](1);
|
|
482
|
-
await (0, helpers_lib_1.Wait)();
|
|
483
|
-
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
484
|
-
});
|
|
485
|
-
(0, vitest_1.test)('complete animations return to original', async () => {
|
|
486
|
-
let obj = { x: 0 };
|
|
487
|
-
let animator = new animator_1.Animator(obj, 'x');
|
|
488
|
-
animator.animate({ x: 4 }, {
|
|
489
|
-
duration: 4,
|
|
490
|
-
animation: new animations_1.AnimationLineer(),
|
|
491
|
-
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
492
|
-
});
|
|
493
|
-
animator['update'](1);
|
|
494
|
-
await (0, helpers_lib_1.Wait)();
|
|
495
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
496
|
-
animator.completeAnimations();
|
|
497
|
-
animator['update'](1);
|
|
498
|
-
await (0, helpers_lib_1.Wait)();
|
|
499
|
-
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
500
|
-
});
|
|
501
|
-
(0, vitest_1.test)('complete animations options overriden in animate', async () => {
|
|
502
|
-
let obj = { x: 0 };
|
|
503
|
-
let animator = new animator_1.Animator(obj, 'x', {
|
|
504
|
-
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
505
|
-
});
|
|
506
|
-
animator.animate({ x: 4 }, {
|
|
507
|
-
duration: 4,
|
|
508
|
-
animation: new animations_1.AnimationLineer(),
|
|
509
|
-
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
|
|
510
|
-
});
|
|
511
|
-
animator['update'](1);
|
|
512
|
-
await (0, helpers_lib_1.Wait)();
|
|
513
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
514
|
-
animator.completeAnimations();
|
|
515
|
-
animator['update'](1);
|
|
516
|
-
await (0, helpers_lib_1.Wait)();
|
|
517
|
-
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
518
|
-
});
|
|
519
|
-
(0, vitest_1.test)('complete animations options overriden in complete animations funciton', async () => {
|
|
520
|
-
let obj = { x: 0 };
|
|
521
|
-
let animator = new animator_1.Animator(obj, 'x', {
|
|
522
|
-
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
523
|
-
});
|
|
524
|
-
animator.animate({ x: 4 }, {
|
|
525
|
-
duration: 4,
|
|
526
|
-
animation: new animations_1.AnimationLineer(),
|
|
527
|
-
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
|
|
528
|
-
});
|
|
529
|
-
animator['update'](1);
|
|
530
|
-
await (0, helpers_lib_1.Wait)();
|
|
531
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
532
|
-
animator.completeAnimations(animator_1.CompleteAnimationsHandlingType.stayInCurrentState);
|
|
533
|
-
animator['update'](1);
|
|
534
|
-
await (0, helpers_lib_1.Wait)();
|
|
535
|
-
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
536
|
-
});
|
|
537
|
-
(0, vitest_1.test)('complete animations should trigger onChange', async () => {
|
|
538
|
-
let obj = { x: 0 };
|
|
539
|
-
let completed = false;
|
|
540
|
-
let animator = new animator_1.Animator(obj, 'x', { duration: 1 }).onChange(() => {
|
|
541
|
-
completed = true;
|
|
542
|
-
});
|
|
543
|
-
animator.animate({ x: 1 });
|
|
544
|
-
animator.completeAnimations();
|
|
545
|
-
await (0, helpers_lib_1.Wait)();
|
|
546
|
-
(0, vitest_1.expect)(completed).toBeTruthy();
|
|
547
|
-
});
|
|
548
|
-
(0, vitest_1.test)('complete animations should not trigger on change if it is not animating', async () => {
|
|
549
|
-
let completed = false;
|
|
550
|
-
let animator = new animator_1.Animator({ x: 0 }, 'x').onChange(() => {
|
|
551
|
-
completed = true;
|
|
552
|
-
});
|
|
553
|
-
animator.completeAnimations();
|
|
554
|
-
await (0, helpers_lib_1.Wait)();
|
|
555
|
-
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
556
|
-
});
|
|
76
|
+
(0, vitest_1.test)('setting multiple update callbacks should throw error', () => {
|
|
77
|
+
(0, vitest_1.expect)(() => {
|
|
78
|
+
const obj = { x: 0 };
|
|
79
|
+
new animator_1.Animator(obj, 'x').onChange(() => {}).onChange(() => {});
|
|
80
|
+
}).toThrow();
|
|
557
81
|
});
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
82
|
+
});
|
|
83
|
+
(0, vitest_1.describe)('Animate', () => {
|
|
84
|
+
(0, vitest_1.test)('animate should not change the value before the update ticks', () => {
|
|
85
|
+
const obj = { x: 0 };
|
|
86
|
+
const animator = new animator_1.Animator(obj, 'x');
|
|
87
|
+
animator.animate({ x: 5 });
|
|
88
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
89
|
+
});
|
|
90
|
+
(0, vitest_1.test)('animate to target in lineer', () => {
|
|
91
|
+
const obj = { x: 0 };
|
|
92
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
93
|
+
duration: 4,
|
|
94
|
+
animation: new animations_1.AnimationLineer()
|
|
95
|
+
});
|
|
96
|
+
animator.animate({ x: 4 });
|
|
97
|
+
animator['update'](1);
|
|
98
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
99
|
+
animator['update'](1);
|
|
100
|
+
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
101
|
+
animator['update'](1);
|
|
102
|
+
(0, vitest_1.expect)(obj.x).toEqual(3);
|
|
103
|
+
animator['update'](1);
|
|
104
|
+
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
105
|
+
});
|
|
106
|
+
(0, vitest_1.test)('animate only one property should not effect the other', () => {
|
|
107
|
+
const obj = { x: 0, y: 0 };
|
|
108
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
109
|
+
duration: 4,
|
|
110
|
+
animation: new animations_1.AnimationLineer()
|
|
111
|
+
});
|
|
112
|
+
animator.animate({ x: 4 });
|
|
113
|
+
animator['update'](1);
|
|
114
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1, y: 0 });
|
|
115
|
+
animator['update'](1);
|
|
116
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
|
|
117
|
+
animator['update'](1);
|
|
118
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 3, y: 0 });
|
|
119
|
+
animator['update'](1);
|
|
120
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 4, y: 0 });
|
|
121
|
+
});
|
|
122
|
+
(0, vitest_1.test)('animate with custom values should override the default settings', () => {
|
|
123
|
+
const obj = { x: 0 };
|
|
124
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
125
|
+
duration: 10,
|
|
126
|
+
animation: new animations_1.AnimationLineer()
|
|
127
|
+
});
|
|
128
|
+
animator.animate({ x: 10 }, { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
129
|
+
animator['update'](1);
|
|
130
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25 });
|
|
131
|
+
animator['update'](1);
|
|
132
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5 });
|
|
133
|
+
animator['update'](1);
|
|
134
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75 });
|
|
135
|
+
animator['update'](1);
|
|
136
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10 });
|
|
137
|
+
});
|
|
138
|
+
(0, vitest_1.test)('animate to target in easeInOut starting from zero', () => {
|
|
139
|
+
const obj = { x: 0 };
|
|
140
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
141
|
+
duration: 4,
|
|
142
|
+
animation: new animations_1.AnimationEaseInOut()
|
|
143
|
+
});
|
|
144
|
+
animator.animate({ x: 10 });
|
|
145
|
+
animator['update'](1);
|
|
146
|
+
(0, vitest_1.expect)(obj.x).toEqual(1.25);
|
|
147
|
+
animator['update'](1);
|
|
148
|
+
(0, vitest_1.expect)(obj.x).toEqual(5);
|
|
149
|
+
animator['update'](1);
|
|
150
|
+
(0, vitest_1.expect)(obj.x).toEqual(8.75);
|
|
151
|
+
animator['update'](1);
|
|
152
|
+
(0, vitest_1.expect)(obj.x).toEqual(10);
|
|
153
|
+
});
|
|
154
|
+
(0, vitest_1.test)('animate to target in easeInOut starting from different value than zero', () => {
|
|
155
|
+
const obj = { x: 10 };
|
|
156
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
157
|
+
duration: 4,
|
|
158
|
+
animation: new animations_1.AnimationEaseInOut()
|
|
159
|
+
});
|
|
160
|
+
animator.animate({ x: 20 });
|
|
161
|
+
animator['update'](1);
|
|
162
|
+
(0, vitest_1.expect)(obj.x).toEqual(11.25);
|
|
163
|
+
animator['update'](1);
|
|
164
|
+
(0, vitest_1.expect)(obj.x).toEqual(15);
|
|
165
|
+
animator['update'](1);
|
|
166
|
+
(0, vitest_1.expect)(obj.x).toEqual(18.75);
|
|
167
|
+
animator['update'](1);
|
|
168
|
+
(0, vitest_1.expect)(obj.x).toEqual(20);
|
|
169
|
+
});
|
|
170
|
+
(0, vitest_1.test)('animate to target and return back', () => {
|
|
171
|
+
const obj = { x: 0 };
|
|
172
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
173
|
+
duration: 1,
|
|
174
|
+
animation: new animations_1.AnimationLineer()
|
|
175
|
+
});
|
|
176
|
+
animator.animate({ x: 4 });
|
|
177
|
+
animator['update'](1);
|
|
178
|
+
animator.animate({ x: 0 });
|
|
179
|
+
animator['update'](1);
|
|
180
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
181
|
+
});
|
|
182
|
+
(0, vitest_1.test)('animate onChange callbacks', () => {
|
|
183
|
+
const obj = { x: 0 };
|
|
184
|
+
let valueFromOnStep = 0;
|
|
185
|
+
let onStepCallCount = 0;
|
|
186
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
187
|
+
duration: 4,
|
|
188
|
+
animation: new animations_1.AnimationEaseInOut()
|
|
189
|
+
}).onChange(item => {
|
|
190
|
+
valueFromOnStep = item.x;
|
|
191
|
+
onStepCallCount++;
|
|
192
|
+
});
|
|
193
|
+
animator.animate({ x: 10 });
|
|
194
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(0);
|
|
195
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(0);
|
|
196
|
+
animator['update'](1);
|
|
197
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(1);
|
|
198
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(1.25);
|
|
199
|
+
animator['update'](1);
|
|
200
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(2);
|
|
201
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(5);
|
|
202
|
+
animator['update'](1);
|
|
203
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(3);
|
|
204
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(8.75);
|
|
205
|
+
animator['update'](1);
|
|
206
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(4);
|
|
207
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(10);
|
|
208
|
+
animator['update'](1);
|
|
209
|
+
animator['update'](1);
|
|
210
|
+
animator['update'](1);
|
|
211
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(4);
|
|
212
|
+
});
|
|
213
|
+
(0, vitest_1.test)('animate onChange should not be triggered before starting the animation', () => {
|
|
214
|
+
let onStepCallCount = 0;
|
|
215
|
+
const animator = new animator_1.Animator({ x: 0 }, 'x', {
|
|
216
|
+
duration: 4,
|
|
217
|
+
animation: new animations_1.AnimationEaseInOut()
|
|
218
|
+
}).onChange(() => {
|
|
219
|
+
onStepCallCount++;
|
|
220
|
+
});
|
|
221
|
+
animator['update'](1);
|
|
222
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(0);
|
|
223
|
+
});
|
|
224
|
+
(0, vitest_1.test)('animation complete promise', async () => {
|
|
225
|
+
const obj = { x: 0 };
|
|
226
|
+
let completed = false;
|
|
227
|
+
const animator = new animator_1.Animator(obj, 'x');
|
|
228
|
+
animator.animate({ x: 1 }, { duration: 2 }).then(() => {
|
|
229
|
+
completed = true;
|
|
230
|
+
});
|
|
231
|
+
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
232
|
+
animator['update'](1);
|
|
233
|
+
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
234
|
+
animator['update'](1);
|
|
235
|
+
await (0, helpers_lib_1.Wait)();
|
|
236
|
+
(0, vitest_1.expect)(completed).toBeTruthy();
|
|
237
|
+
});
|
|
238
|
+
(0, vitest_1.test)('animate getter/setter property', () => {
|
|
239
|
+
class Foo {
|
|
240
|
+
constructor() {
|
|
241
|
+
this._x = 10;
|
|
242
|
+
}
|
|
243
|
+
get x() {
|
|
244
|
+
return this._x;
|
|
245
|
+
}
|
|
246
|
+
set x(value) {
|
|
247
|
+
this._x = value;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const obj = new Foo();
|
|
251
|
+
const animator = new animator_1.Animator(obj, ['x'], {
|
|
252
|
+
duration: 4,
|
|
253
|
+
animation: new animations_1.AnimationEaseInOut()
|
|
254
|
+
});
|
|
255
|
+
animator.animate({ x: 20 });
|
|
256
|
+
animator['update'](1);
|
|
257
|
+
(0, vitest_1.expect)(obj.x).toEqual(11.25);
|
|
258
|
+
animator['update'](1);
|
|
259
|
+
(0, vitest_1.expect)(obj.x).toEqual(15);
|
|
260
|
+
animator['update'](1);
|
|
261
|
+
(0, vitest_1.expect)(obj.x).toEqual(18.75);
|
|
262
|
+
animator['update'](1);
|
|
263
|
+
(0, vitest_1.expect)(obj.x).toEqual(20);
|
|
264
|
+
});
|
|
265
|
+
(0, vitest_1.test)('is animating should return true if it is animating', () => {
|
|
266
|
+
const animator = new animator_1.Animator({ x: 0 }, 'x', {
|
|
267
|
+
duration: 1,
|
|
268
|
+
animation: new animations_1.AnimationLineer()
|
|
269
|
+
});
|
|
270
|
+
animator.animate({ x: 1 });
|
|
271
|
+
(0, vitest_1.expect)(animator.isAnimating).toBeTruthy();
|
|
272
|
+
});
|
|
273
|
+
(0, vitest_1.test)('is animating should return false if it is not animating', () => {
|
|
274
|
+
const obj = { x: 0 };
|
|
275
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
276
|
+
duration: 1,
|
|
277
|
+
animation: new animations_1.AnimationLineer()
|
|
278
|
+
});
|
|
279
|
+
(0, vitest_1.expect)(animator.isAnimating).toBeFalsy();
|
|
280
|
+
animator.animate({ x: 1 });
|
|
281
|
+
animator['update'](1);
|
|
282
|
+
(0, vitest_1.expect)(animator.isAnimating).toBeFalsy();
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
(0, vitest_1.describe)('Animation Cycle Changes', () => {
|
|
286
|
+
(0, vitest_1.test)('pause animations should halt the progress', async () => {
|
|
287
|
+
const obj = { x: 0 };
|
|
288
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
289
|
+
duration: 4,
|
|
290
|
+
animation: new animations_1.AnimationLineer()
|
|
291
|
+
});
|
|
292
|
+
animator.animate({ x: 4 });
|
|
293
|
+
animator['update'](1);
|
|
294
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1 });
|
|
295
|
+
animator['update'](1);
|
|
296
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
297
|
+
animator.pauseAnimations();
|
|
298
|
+
animator['update'](1);
|
|
299
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
300
|
+
animator['update'](1);
|
|
301
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
302
|
+
animator.resumeAnimations();
|
|
303
|
+
animator['update'](1);
|
|
304
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 3 });
|
|
305
|
+
animator['update'](1);
|
|
306
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 4 });
|
|
307
|
+
});
|
|
308
|
+
(0, vitest_1.test)('new animations should not proceed while the animations are paused', async () => {
|
|
309
|
+
const obj = { x: 0 };
|
|
310
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
311
|
+
duration: 2,
|
|
312
|
+
animation: new animations_1.AnimationLineer()
|
|
313
|
+
});
|
|
314
|
+
animator.pauseAnimations();
|
|
315
|
+
animator.animate({ x: 2 });
|
|
316
|
+
animator['update'](1);
|
|
317
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 0 });
|
|
318
|
+
animator['update'](1);
|
|
319
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 0 });
|
|
320
|
+
animator.resumeAnimations();
|
|
321
|
+
animator['update'](1);
|
|
322
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1 });
|
|
323
|
+
animator['update'](1);
|
|
324
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
325
|
+
});
|
|
326
|
+
(0, vitest_1.test)('animation loop', async () => {
|
|
327
|
+
const obj = { x: 0 };
|
|
328
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
329
|
+
duration: 2,
|
|
330
|
+
animation: new animations_1.AnimationLineer(),
|
|
331
|
+
loop: true
|
|
332
|
+
});
|
|
333
|
+
animator.animate({ x: 2 }, { duration: 2 });
|
|
334
|
+
animator['update'](1);
|
|
335
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
336
|
+
animator['update'](1);
|
|
337
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
338
|
+
animator['update'](1);
|
|
339
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
340
|
+
animator['update'](0.8);
|
|
341
|
+
(0, vitest_1.expect)(obj.x).toEqual(1.8);
|
|
342
|
+
animator['update'](0.7);
|
|
343
|
+
(0, vitest_1.expect)(obj.x).toEqual(0.5);
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
(0, vitest_1.describe)('Animation Type Switch', () => {
|
|
347
|
+
(0, vitest_1.test)('re-animation handling option throw error should throw error', () => {
|
|
348
|
+
const obj = { x: 0 };
|
|
349
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
350
|
+
duration: 4,
|
|
351
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.throwError
|
|
352
|
+
});
|
|
353
|
+
animator.animate({ x: 1 });
|
|
354
|
+
(0, vitest_1.expect)(async () => await animator.animate({ x: 0 })).rejects.toThrow();
|
|
355
|
+
animator['update'](1);
|
|
356
|
+
(0, vitest_1.expect)(async () => await animator.animate({ x: 0 })).rejects.toThrow();
|
|
357
|
+
});
|
|
358
|
+
(0, vitest_1.test)('re-animation handling option ignore should ignore new animation', () => {
|
|
359
|
+
const obj = { x: 0 };
|
|
360
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
361
|
+
duration: 1,
|
|
362
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.ignore
|
|
363
|
+
});
|
|
364
|
+
animator.animate({ x: 1 });
|
|
365
|
+
animator.animate({ x: 2 });
|
|
366
|
+
animator['update'](1);
|
|
367
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
368
|
+
});
|
|
369
|
+
(0, vitest_1.test)('re-animation handling option ignore should ignore multiple property animation', () => {
|
|
370
|
+
const obj = { x: 0, y: 0 };
|
|
371
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
372
|
+
duration: 1,
|
|
373
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.ignore
|
|
374
|
+
});
|
|
375
|
+
animator.animate({ x: 1 });
|
|
376
|
+
animator.animate({ x: 2, y: 1 });
|
|
377
|
+
animator['update'](1);
|
|
378
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1, y: 1 });
|
|
379
|
+
});
|
|
380
|
+
(0, vitest_1.test)('animate switch after finishes to a different animation type should not throw error', () => {
|
|
381
|
+
const obj = { x: 1 };
|
|
382
|
+
const animator = new animator_1.Animator(obj, 'x', { duration: 1 });
|
|
383
|
+
animator.animate({ x: 0 }, { animation: new animations_1.AnimationLineer() });
|
|
384
|
+
animator['update'](1);
|
|
385
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
386
|
+
animator.animate({ x: 10 }, { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
387
|
+
animator['update'](1);
|
|
388
|
+
(0, vitest_1.expect)(obj.x).toEqual(1.25);
|
|
389
|
+
animator['update'](1);
|
|
390
|
+
(0, vitest_1.expect)(obj.x).toEqual(5);
|
|
391
|
+
animator['update'](1);
|
|
392
|
+
(0, vitest_1.expect)(obj.x).toEqual(8.75);
|
|
393
|
+
animator['update'](1);
|
|
394
|
+
(0, vitest_1.expect)(obj.x).toEqual(10);
|
|
395
|
+
});
|
|
396
|
+
(0, vitest_1.test)('re-animation handling option canceling should cancel the ongoing animation', () => {
|
|
397
|
+
const obj = { x: 0 };
|
|
398
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
399
|
+
duration: 1,
|
|
400
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.cancelPrevious
|
|
401
|
+
});
|
|
402
|
+
animator.animate({ x: 1 });
|
|
403
|
+
animator.animate({ x: 2 });
|
|
404
|
+
animator['update'](1);
|
|
405
|
+
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
406
|
+
});
|
|
407
|
+
(0, vitest_1.test)('re-animation handling option canceling should cancel the ongoing multiple property animation', () => {
|
|
408
|
+
const obj = { x: 0, y: 0 };
|
|
409
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
410
|
+
duration: 1,
|
|
411
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.cancelPrevious
|
|
412
|
+
});
|
|
413
|
+
animator.animate({ x: 1 });
|
|
414
|
+
animator.animate({ x: 2, y: 1 });
|
|
415
|
+
animator['update'](1);
|
|
416
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 1 });
|
|
417
|
+
});
|
|
418
|
+
(0, vitest_1.test)(
|
|
419
|
+
're-animation handling option canceling should cancel the animation with keeping the current value',
|
|
420
|
+
() => {
|
|
421
|
+
const obj = { x: 0 };
|
|
422
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
423
|
+
duration: 2,
|
|
424
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.cancelPrevious
|
|
425
|
+
});
|
|
426
|
+
animator.animate({ x: 2 });
|
|
427
|
+
animator['update'](1);
|
|
428
|
+
animator.animate({ x: 3 });
|
|
429
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
430
|
+
animator['update'](1);
|
|
431
|
+
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
432
|
+
animator['update'](1);
|
|
433
|
+
(0, vitest_1.expect)(obj.x).toEqual(3);
|
|
434
|
+
}
|
|
435
|
+
);
|
|
436
|
+
});
|
|
437
|
+
(0, vitest_1.describe)('Set', () => {
|
|
438
|
+
(0, vitest_1.test)('it should throw error if it is animating', () => {
|
|
439
|
+
const animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 1 });
|
|
440
|
+
animator.animate({ x: 1 });
|
|
441
|
+
(0, vitest_1.expect)(() => {
|
|
442
|
+
animator.set({ x: 0 });
|
|
443
|
+
}).toThrow();
|
|
444
|
+
});
|
|
445
|
+
(0, vitest_1.test)('it should throw error if the property is not valid', () => {
|
|
446
|
+
const animator = new animator_1.Animator({ x: 0 }, 'x');
|
|
447
|
+
(0, vitest_1.expect)(() => {
|
|
448
|
+
animator.set({ t: 0 });
|
|
449
|
+
}).toThrow();
|
|
450
|
+
});
|
|
451
|
+
(0, vitest_1.test)('it should change the original value', () => {
|
|
452
|
+
const obj = { x: 0, y: 1, z: 2 };
|
|
453
|
+
const animator = new animator_1.Animator(obj, ['x', 'y', 'z']);
|
|
454
|
+
animator.set({ x: 3, y: 4 });
|
|
455
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 3, y: 4, z: 2 });
|
|
456
|
+
});
|
|
457
|
+
(0, vitest_1.test)('it should trigger onChange', () => {
|
|
458
|
+
const obj = { x: 0 };
|
|
459
|
+
let valueFromOnStep = 0;
|
|
460
|
+
let onStepCallCount = 0;
|
|
461
|
+
const animator = new animator_1.Animator(obj, 'x').onChange(item => {
|
|
462
|
+
valueFromOnStep = item.x;
|
|
463
|
+
onStepCallCount++;
|
|
464
|
+
});
|
|
465
|
+
animator.set({ x: 1 });
|
|
466
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(1);
|
|
467
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(1);
|
|
468
|
+
});
|
|
469
|
+
(0, vitest_1.test)('it should not trigger onChange if the value is the same', () => {
|
|
470
|
+
const obj = { x: 0 };
|
|
471
|
+
let onStepCallCount = 0;
|
|
472
|
+
const animator = new animator_1.Animator(obj, 'x').onChange(() => {
|
|
473
|
+
onStepCallCount++;
|
|
474
|
+
});
|
|
475
|
+
animator.set({ x: 0 });
|
|
476
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(0);
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
(0, vitest_1.describe)('Complete Animations', () => {
|
|
480
|
+
(0, vitest_1.test)('when animation is done it should respect the complete animaitons option', () => {
|
|
481
|
+
const obj = { x: 0 };
|
|
482
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
483
|
+
duration: 1,
|
|
484
|
+
animation: new animations_1.AnimationLineer(),
|
|
485
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
486
|
+
});
|
|
487
|
+
animator.animate({ x: 1 });
|
|
488
|
+
animator['update'](1);
|
|
489
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
490
|
+
});
|
|
491
|
+
(0, vitest_1.test)('complete animations should finalize the ongoing animation', async () => {
|
|
492
|
+
const obj = { x: 0 };
|
|
493
|
+
let completed = false;
|
|
494
|
+
const animator = new animator_1.Animator(obj, 'x');
|
|
495
|
+
animator.animate({ x: 1 }, { duration: 4 }).then(() => {
|
|
496
|
+
completed = true;
|
|
497
|
+
});
|
|
498
|
+
animator['update'](1);
|
|
499
|
+
await (0, helpers_lib_1.Wait)();
|
|
500
|
+
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
501
|
+
animator.completeAnimations();
|
|
502
|
+
await (0, helpers_lib_1.Wait)();
|
|
503
|
+
(0, vitest_1.expect)(completed).toBeTruthy();
|
|
504
|
+
});
|
|
505
|
+
(0, vitest_1.test)('complete animations should finalize the all ongoing animations', async () => {
|
|
506
|
+
let completed1 = false;
|
|
507
|
+
let completed2 = false;
|
|
508
|
+
const obj = { x: 0, y: 0 };
|
|
509
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
510
|
+
duration: 4,
|
|
511
|
+
animation: new animations_1.AnimationEaseInOut()
|
|
512
|
+
});
|
|
513
|
+
animator.animate({ y: 10 }, { loop: true }).then(() => {
|
|
514
|
+
completed1 = true;
|
|
515
|
+
});
|
|
516
|
+
animator['update'](1);
|
|
517
|
+
animator.animate({ x: 10 }).then(() => {
|
|
518
|
+
completed2 = true;
|
|
519
|
+
});
|
|
520
|
+
animator['update'](1);
|
|
521
|
+
await (0, helpers_lib_1.Wait)();
|
|
522
|
+
(0, vitest_1.expect)(completed1).toBeFalsy();
|
|
523
|
+
(0, vitest_1.expect)(completed2).toBeFalsy();
|
|
524
|
+
animator.completeAnimations();
|
|
525
|
+
await (0, helpers_lib_1.Wait)();
|
|
526
|
+
(0, vitest_1.expect)(completed1).toBeTruthy();
|
|
527
|
+
(0, vitest_1.expect)(completed2).toBeTruthy();
|
|
528
|
+
});
|
|
529
|
+
(0, vitest_1.test)('complete animations stay in current state', async () => {
|
|
530
|
+
const obj = { x: 0 };
|
|
531
|
+
const animator = new animator_1.Animator(obj, 'x');
|
|
532
|
+
animator.animate(
|
|
533
|
+
{ x: 4 },
|
|
534
|
+
{
|
|
535
|
+
duration: 4,
|
|
536
|
+
animation: new animations_1.AnimationLineer(),
|
|
537
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
|
|
538
|
+
}
|
|
539
|
+
);
|
|
540
|
+
animator['update'](1);
|
|
541
|
+
await (0, helpers_lib_1.Wait)();
|
|
542
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
543
|
+
animator.completeAnimations();
|
|
544
|
+
animator['update'](1);
|
|
545
|
+
await (0, helpers_lib_1.Wait)();
|
|
546
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
547
|
+
});
|
|
548
|
+
(0, vitest_1.test)('complete animations jump to end', async () => {
|
|
549
|
+
const obj = { x: 0 };
|
|
550
|
+
const animator = new animator_1.Animator(obj, 'x');
|
|
551
|
+
animator.animate(
|
|
552
|
+
{ x: 4 },
|
|
553
|
+
{
|
|
554
|
+
duration: 4,
|
|
555
|
+
animation: new animations_1.AnimationLineer(),
|
|
556
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
|
|
557
|
+
}
|
|
558
|
+
);
|
|
559
|
+
animator['update'](1);
|
|
560
|
+
await (0, helpers_lib_1.Wait)();
|
|
561
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
562
|
+
animator.completeAnimations();
|
|
563
|
+
animator['update'](1);
|
|
564
|
+
await (0, helpers_lib_1.Wait)();
|
|
565
|
+
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
566
|
+
});
|
|
567
|
+
(0, vitest_1.test)('complete animations return to original', async () => {
|
|
568
|
+
const obj = { x: 0 };
|
|
569
|
+
const animator = new animator_1.Animator(obj, 'x');
|
|
570
|
+
animator.animate(
|
|
571
|
+
{ x: 4 },
|
|
572
|
+
{
|
|
573
|
+
duration: 4,
|
|
574
|
+
animation: new animations_1.AnimationLineer(),
|
|
575
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
576
|
+
}
|
|
577
|
+
);
|
|
578
|
+
animator['update'](1);
|
|
579
|
+
await (0, helpers_lib_1.Wait)();
|
|
580
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
581
|
+
animator.completeAnimations();
|
|
582
|
+
animator['update'](1);
|
|
583
|
+
await (0, helpers_lib_1.Wait)();
|
|
584
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
585
|
+
});
|
|
586
|
+
(0, vitest_1.test)('complete animations options overriden in animate', async () => {
|
|
587
|
+
const obj = { x: 0 };
|
|
588
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
589
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
590
|
+
});
|
|
591
|
+
animator.animate(
|
|
592
|
+
{ x: 4 },
|
|
593
|
+
{
|
|
594
|
+
duration: 4,
|
|
595
|
+
animation: new animations_1.AnimationLineer(),
|
|
596
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
|
|
597
|
+
}
|
|
598
|
+
);
|
|
599
|
+
animator['update'](1);
|
|
600
|
+
await (0, helpers_lib_1.Wait)();
|
|
601
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
602
|
+
animator.completeAnimations();
|
|
603
|
+
animator['update'](1);
|
|
604
|
+
await (0, helpers_lib_1.Wait)();
|
|
605
|
+
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
606
|
+
});
|
|
607
|
+
(0, vitest_1.test)('complete animations options overriden in complete animations funciton', async () => {
|
|
608
|
+
const obj = { x: 0 };
|
|
609
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
610
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
611
|
+
});
|
|
612
|
+
animator.animate(
|
|
613
|
+
{ x: 4 },
|
|
614
|
+
{
|
|
615
|
+
duration: 4,
|
|
616
|
+
animation: new animations_1.AnimationLineer(),
|
|
617
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
|
|
618
|
+
}
|
|
619
|
+
);
|
|
620
|
+
animator['update'](1);
|
|
621
|
+
await (0, helpers_lib_1.Wait)();
|
|
622
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
623
|
+
animator.completeAnimations(animator_1.CompleteAnimationsHandlingType.stayInCurrentState);
|
|
624
|
+
animator['update'](1);
|
|
625
|
+
await (0, helpers_lib_1.Wait)();
|
|
626
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
627
|
+
});
|
|
628
|
+
(0, vitest_1.test)('complete animations should trigger onChange', async () => {
|
|
629
|
+
const obj = { x: 0 };
|
|
630
|
+
let completed = false;
|
|
631
|
+
const animator = new animator_1.Animator(obj, 'x', {
|
|
632
|
+
duration: 1
|
|
633
|
+
}).onChange(() => {
|
|
634
|
+
completed = true;
|
|
635
|
+
});
|
|
636
|
+
animator.animate({ x: 1 });
|
|
637
|
+
animator.completeAnimations();
|
|
638
|
+
await (0, helpers_lib_1.Wait)();
|
|
639
|
+
(0, vitest_1.expect)(completed).toBeTruthy();
|
|
640
|
+
});
|
|
641
|
+
(0, vitest_1.test)('complete animations should not trigger on change if it is not animating', async () => {
|
|
642
|
+
let completed = false;
|
|
643
|
+
const animator = new animator_1.Animator({ x: 0 }, 'x').onChange(() => {
|
|
644
|
+
completed = true;
|
|
645
|
+
});
|
|
646
|
+
animator.completeAnimations();
|
|
647
|
+
await (0, helpers_lib_1.Wait)();
|
|
648
|
+
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
(0, vitest_1.describe)('Mixing Different Configurations', () => {
|
|
652
|
+
(0, vitest_1.test)('animate multiple properties without mixing animation type', () => {
|
|
653
|
+
const obj = { x: 0, y: 10 };
|
|
654
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
655
|
+
duration: 4,
|
|
656
|
+
animation: new animations_1.AnimationEaseInOut()
|
|
657
|
+
});
|
|
658
|
+
animator.animate({ x: 10, y: 0 });
|
|
659
|
+
animator['update'](1);
|
|
660
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 8.75 });
|
|
661
|
+
animator['update'](1);
|
|
662
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5, y: 5 });
|
|
663
|
+
animator['update'](1);
|
|
664
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 1.25 });
|
|
665
|
+
animator['update'](1);
|
|
666
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 0 });
|
|
667
|
+
});
|
|
668
|
+
(0, vitest_1.test)('animate multiple properties with mixing animation type', () => {
|
|
669
|
+
const obj = { x: 0, y: 4 };
|
|
670
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
671
|
+
duration: 4
|
|
672
|
+
});
|
|
673
|
+
animator.animate({ x: 10 }, { animation: new animations_1.AnimationEaseInOut() });
|
|
674
|
+
animator.animate({ y: 0 }, { animation: new animations_1.AnimationLineer() });
|
|
675
|
+
animator['update'](1);
|
|
676
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 3 });
|
|
677
|
+
animator['update'](1);
|
|
678
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5, y: 2 });
|
|
679
|
+
animator['update'](1);
|
|
680
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 1 });
|
|
681
|
+
animator['update'](1);
|
|
682
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 0 });
|
|
683
|
+
});
|
|
684
|
+
(0, vitest_1.test)('animate multiple properties async', () => {
|
|
685
|
+
const obj = { x: 0, y: 0 };
|
|
686
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
687
|
+
duration: 4,
|
|
688
|
+
animation: new animations_1.AnimationEaseInOut()
|
|
689
|
+
});
|
|
690
|
+
animator.animate({ y: 10 });
|
|
691
|
+
animator['update'](1);
|
|
692
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 0, y: 1.25 });
|
|
693
|
+
animator.animate({ x: 10 });
|
|
694
|
+
animator['update'](1);
|
|
695
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 5 });
|
|
696
|
+
animator['update'](1);
|
|
697
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5, y: 8.75 });
|
|
698
|
+
animator['update'](1);
|
|
699
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 10 });
|
|
700
|
+
animator['update'](1);
|
|
701
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 10 });
|
|
702
|
+
});
|
|
703
|
+
(0, vitest_1.test)('animate multiple properties mixed with loop', () => {
|
|
704
|
+
const obj = { x: 0, y: 0 };
|
|
705
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
706
|
+
duration: 4,
|
|
707
|
+
animation: new animations_1.AnimationEaseInOut()
|
|
708
|
+
});
|
|
709
|
+
animator.animate({ y: 10 }, { loop: true });
|
|
710
|
+
animator['update'](1);
|
|
711
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 0, y: 1.25 });
|
|
712
|
+
animator.animate({ x: 10 });
|
|
713
|
+
animator['update'](1);
|
|
714
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 5 });
|
|
715
|
+
animator['update'](1);
|
|
716
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5, y: 8.75 });
|
|
717
|
+
animator['update'](1);
|
|
718
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 0 });
|
|
719
|
+
animator['update'](1);
|
|
720
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 1.25 });
|
|
721
|
+
animator['update'](1);
|
|
722
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 5 });
|
|
723
|
+
});
|
|
724
|
+
(0, vitest_1.test)('animate multiple properties complete promise', async () => {
|
|
725
|
+
let completed1 = false;
|
|
726
|
+
let completed2 = false;
|
|
727
|
+
const obj = { x: 0, y: 0 };
|
|
728
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
729
|
+
duration: 4
|
|
730
|
+
});
|
|
731
|
+
animator.animate({ y: 10 }).then(() => {
|
|
732
|
+
completed1 = true;
|
|
733
|
+
});
|
|
734
|
+
animator['update'](1);
|
|
735
|
+
animator.animate({ x: 10 }).then(() => {
|
|
736
|
+
completed2 = true;
|
|
737
|
+
});
|
|
738
|
+
animator['update'](2);
|
|
739
|
+
await (0, helpers_lib_1.Wait)();
|
|
740
|
+
(0, vitest_1.expect)(completed1).toBeFalsy();
|
|
741
|
+
(0, vitest_1.expect)(completed2).toBeFalsy();
|
|
742
|
+
animator['update'](1);
|
|
743
|
+
await (0, helpers_lib_1.Wait)();
|
|
744
|
+
(0, vitest_1.expect)(completed1).toBeTruthy();
|
|
745
|
+
(0, vitest_1.expect)(completed2).toBeFalsy();
|
|
746
|
+
animator['update'](1);
|
|
747
|
+
await (0, helpers_lib_1.Wait)();
|
|
748
|
+
(0, vitest_1.expect)(completed1).toBeTruthy();
|
|
749
|
+
(0, vitest_1.expect)(completed2).toBeTruthy();
|
|
750
|
+
});
|
|
751
|
+
(0, vitest_1.test)('pause animations with mixed commands', async () => {
|
|
752
|
+
const obj = { x: 0, y: 0 };
|
|
753
|
+
const animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
754
|
+
duration: 4,
|
|
755
|
+
animation: new animations_1.AnimationLineer()
|
|
756
|
+
});
|
|
757
|
+
animator.resumeAnimations();
|
|
758
|
+
animator.animate({ x: 4 });
|
|
759
|
+
animator['update'](1);
|
|
760
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1, y: 0 });
|
|
761
|
+
animator['update'](1);
|
|
762
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
|
|
763
|
+
animator.pauseAnimations();
|
|
764
|
+
animator['update'](1);
|
|
765
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
|
|
766
|
+
animator.pauseAnimations();
|
|
767
|
+
animator.animate({ y: 4 });
|
|
768
|
+
animator['update'](1);
|
|
769
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
|
|
770
|
+
animator.resumeAnimations();
|
|
771
|
+
animator['update'](1);
|
|
772
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 3, y: 1 });
|
|
773
|
+
animator.resumeAnimations();
|
|
774
|
+
animator['update'](1);
|
|
775
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 4, y: 2 });
|
|
668
776
|
});
|
|
777
|
+
});
|
|
669
778
|
});
|
|
670
|
-
//# sourceMappingURL=animator.spec.js.map
|
|
779
|
+
//# sourceMappingURL=animator.spec.js.map
|