chnobli 0.1.4 → 0.1.6
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/.prettierignore +4 -0
- package/.prettierrc +6 -0
- package/.vscode/settings.json +4 -0
- package/auto-docs/easing.js.html +342 -0
- package/auto-docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/auto-docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/auto-docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/auto-docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/auto-docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/auto-docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/auto-docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/auto-docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/auto-docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/auto-docs/global.html +4810 -0
- package/auto-docs/index.html +65 -0
- package/auto-docs/scripts/linenumber.js +25 -0
- package/auto-docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/auto-docs/scripts/prettify/lang-css.js +2 -0
- package/auto-docs/scripts/prettify/prettify.js +28 -0
- package/auto-docs/styles/jsdoc-default.css +358 -0
- package/auto-docs/styles/prettify-jsdoc.css +111 -0
- package/auto-docs/styles/prettify-tomorrow.css +132 -0
- package/dist/animation/Animation.d.ts +36 -0
- package/dist/animation/Animation.d.ts.map +1 -0
- package/dist/animation/Animation.js +230 -0
- package/dist/animation/Animation.js.map +1 -0
- package/dist/animation/animation.d.ts +36 -0
- package/dist/animation/animation.d.ts.map +1 -0
- package/dist/animation/animation.js +230 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/public.d.ts +55 -0
- package/dist/animation/public.d.ts.map +1 -0
- package/dist/animation/public.js +104 -0
- package/dist/animation/public.js.map +1 -0
- package/dist/chnobli.d.ts +15 -0
- package/dist/chnobli.d.ts.map +1 -0
- package/dist/chnobli.js +63 -0
- package/dist/chnobli.js.map +1 -0
- package/dist/property/BasicProperty.d.ts +38 -0
- package/dist/property/BasicProperty.d.ts.map +1 -0
- package/dist/property/BasicProperty.js +72 -0
- package/dist/property/BasicProperty.js.map +1 -0
- package/dist/property/ClassProperty.d.ts +32 -0
- package/dist/property/ClassProperty.d.ts.map +1 -0
- package/dist/property/ClassProperty.js +108 -0
- package/dist/property/ClassProperty.js.map +1 -0
- package/dist/property/Property.d.ts +13 -0
- package/dist/property/Property.d.ts.map +1 -0
- package/dist/property/Property.js +20 -0
- package/dist/property/Property.js.map +1 -0
- package/dist/property/StyleProperty.d.ts +25 -0
- package/dist/property/StyleProperty.d.ts.map +1 -0
- package/dist/property/StyleProperty.js +221 -0
- package/dist/property/StyleProperty.js.map +1 -0
- package/dist/property/TransformProperty.d.ts +15 -0
- package/dist/property/TransformProperty.d.ts.map +1 -0
- package/dist/property/TransformProperty.js +43 -0
- package/dist/property/TransformProperty.js.map +1 -0
- package/dist/property/TransformXYProperty.d.ts +28 -0
- package/dist/property/TransformXYProperty.d.ts.map +1 -0
- package/dist/property/TransformXYProperty.js +65 -0
- package/dist/property/TransformXYProperty.js.map +1 -0
- package/dist/responsive/ResponsiveEvent.d.ts +17 -0
- package/dist/responsive/ResponsiveEvent.d.ts.map +1 -0
- package/dist/responsive/ResponsiveEvent.js +45 -0
- package/dist/responsive/ResponsiveEvent.js.map +1 -0
- package/dist/responsive/TestEvent.d.ts +11 -0
- package/dist/responsive/TestEvent.d.ts.map +1 -0
- package/dist/responsive/TestEvent.js +26 -0
- package/dist/responsive/TestEvent.js.map +1 -0
- package/dist/responsive/event.d.ts +10 -0
- package/dist/responsive/event.d.ts.map +1 -0
- package/dist/responsive/event.js +39 -0
- package/dist/responsive/event.js.map +1 -0
- package/dist/scroll/Scroll.d.ts +27 -0
- package/dist/scroll/Scroll.d.ts.map +1 -0
- package/dist/scroll/Scroll.js +132 -0
- package/dist/scroll/Scroll.js.map +1 -0
- package/dist/scroll/ScrollEvent.d.ts +17 -0
- package/dist/scroll/ScrollEvent.d.ts.map +1 -0
- package/dist/scroll/ScrollEvent.js +39 -0
- package/dist/scroll/ScrollEvent.js.map +1 -0
- package/dist/scroll/public.d.ts +7 -0
- package/dist/scroll/public.d.ts.map +1 -0
- package/dist/scroll/public.js +17 -0
- package/dist/scroll/public.js.map +1 -0
- package/dist/stagger/stagger.d.ts +13 -0
- package/dist/stagger/stagger.d.ts.map +1 -0
- package/dist/stagger/stagger.js +35 -0
- package/dist/stagger/stagger.js.map +1 -0
- package/dist/target/BaseTarget.old.d.ts +33 -0
- package/dist/target/BaseTarget.old.d.ts.map +1 -0
- package/dist/target/BaseTarget.old.js +73 -0
- package/dist/target/BaseTarget.old.js.map +1 -0
- package/dist/target/DomTarget.d.ts +41 -0
- package/dist/target/DomTarget.d.ts.map +1 -0
- package/dist/target/DomTarget.js +230 -0
- package/dist/target/DomTarget.js.map +1 -0
- package/dist/target/Target.d.ts +22 -0
- package/dist/target/Target.d.ts.map +1 -0
- package/dist/target/Target.js +21 -0
- package/dist/target/Target.js.map +1 -0
- package/dist/target/TestDomNode.d.ts +14 -0
- package/dist/target/TestDomNode.d.ts.map +1 -0
- package/dist/target/TestDomNode.js +55 -0
- package/dist/target/TestDomNode.js.map +1 -0
- package/dist/timeline/Nested.d.ts +30 -0
- package/dist/timeline/Nested.d.ts.map +1 -0
- package/dist/timeline/Nested.js +51 -0
- package/dist/timeline/Nested.js.map +1 -0
- package/dist/timeline/TimeLine.d.ts +32 -0
- package/dist/timeline/TimeLine.d.ts.map +1 -0
- package/dist/timeline/TimeLine.js +288 -0
- package/dist/timeline/TimeLine.js.map +1 -0
- package/dist/timeline/public.d.ts +120 -0
- package/dist/timeline/public.d.ts.map +1 -0
- package/dist/timeline/public.js +301 -0
- package/dist/timeline/public.js.map +1 -0
- package/dist/timing/AnimationFrameTicker.d.ts +32 -0
- package/dist/timing/AnimationFrameTicker.d.ts.map +1 -0
- package/dist/timing/AnimationFrameTicker.js +134 -0
- package/dist/timing/AnimationFrameTicker.js.map +1 -0
- package/dist/timing/Ease.d.ts +6 -0
- package/dist/timing/Ease.d.ts.map +1 -0
- package/dist/timing/Ease.js +15 -0
- package/dist/timing/Ease.js.map +1 -0
- package/dist/timing/TestTicker.d.ts +19 -0
- package/dist/timing/TestTicker.d.ts.map +1 -0
- package/dist/timing/TestTicker.js +81 -0
- package/dist/timing/TestTicker.js.map +1 -0
- package/dist/timing/Ticker.d.ts +14 -0
- package/dist/timing/Ticker.d.ts.map +1 -0
- package/dist/timing/Ticker.js +2 -0
- package/dist/timing/Ticker.js.map +1 -0
- package/dist/timing/Timing.d.ts +62 -0
- package/dist/timing/Timing.d.ts.map +1 -0
- package/dist/timing/Timing.js +257 -0
- package/dist/timing/Timing.js.map +1 -0
- package/dist/timing/easing.d.ts +158 -0
- package/dist/timing/easing.d.ts.map +1 -0
- package/dist/timing/easing.js +273 -0
- package/dist/timing/easing.js.map +1 -0
- package/dist/utils/Events.d.ts +9 -0
- package/dist/utils/Events.d.ts.map +1 -0
- package/dist/utils/Events.js +35 -0
- package/dist/utils/Events.js.map +1 -0
- package/dist/utils/internal.d.ts +2 -0
- package/dist/utils/internal.d.ts.map +1 -0
- package/dist/utils/internal.js +6 -0
- package/dist/utils/internal.js.map +1 -0
- package/dist/utils/motionpath.d.ts +16 -0
- package/dist/utils/motionpath.d.ts.map +1 -0
- package/dist/utils/motionpath.js +41 -0
- package/dist/utils/motionpath.js.map +1 -0
- package/dist/utils/utils.d.ts +43 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +93 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/values/ColorValue.d.ts +12 -0
- package/dist/values/ColorValue.d.ts.map +1 -0
- package/dist/values/ColorValue.js +133 -0
- package/dist/values/ColorValue.js.map +1 -0
- package/dist/values/StyleValue.d.ts +40 -0
- package/dist/values/StyleValue.d.ts.map +1 -0
- package/dist/values/StyleValue.js +149 -0
- package/dist/values/StyleValue.js.map +1 -0
- package/dist/values/Value.d.ts +13 -0
- package/dist/values/Value.d.ts.map +1 -0
- package/dist/values/Value.js +38 -0
- package/dist/values/Value.js.map +1 -0
- package/dist/values/defaultcolors.d.ts +2 -0
- package/dist/values/defaultcolors.d.ts.map +1 -0
- package/dist/values/defaultcolors.js +149 -0
- package/dist/values/defaultcolors.js.map +1 -0
- package/package.json +11 -7
- package/src/animation/{animation.js → Animation.ts} +56 -54
- package/src/animation/{public.js → public.ts} +23 -18
- package/src/{chnobli.js → chnobli.ts} +11 -12
- package/src/property/BasicProperty.ts +91 -0
- package/src/property/ClassProperty.ts +132 -0
- package/src/property/Property.ts +33 -0
- package/src/property/StyleProperty.ts +273 -0
- package/src/property/TransformProperty.ts +56 -0
- package/src/property/TransformXYProperty.ts +88 -0
- package/src/responsive/ResponsiveEvent.ts +60 -0
- package/src/responsive/{testevent.js → TestEvent.ts} +12 -10
- package/src/scroll/{scroll.js → Scroll.ts} +53 -35
- package/src/scroll/ScrollEvent.ts +53 -0
- package/src/scroll/public.ts +20 -0
- package/src/stagger/stagger.ts +45 -0
- package/src/target/{basetarget.js → BaseTarget.old.ts} +25 -26
- package/src/target/DomTarget.ts +281 -0
- package/src/target/Target.ts +48 -0
- package/src/target/{testdomnode.js → TestDomNode.ts} +18 -15
- package/src/tests/{properties.test.js → properties.test.ts} +54 -49
- package/src/tests/timeline.test.ts +290 -0
- package/src/tests/{timing.test.js → timing.test.ts} +25 -22
- package/src/tests/{usecases.test.js → usecases.test.ts} +13 -10
- package/src/tests/{values.test.js → values.test.ts} +21 -21
- package/src/timeline/Nested.ts +67 -0
- package/src/timeline/{timeline.js → TimeLine.ts} +126 -56
- package/src/timeline/{public.js → public.ts} +112 -73
- package/src/timing/{ticker.js → AnimationFrameTicker.ts} +36 -21
- package/src/timing/{ease.js → Ease.ts} +6 -5
- package/src/timing/{testticker.js → TestTicker.ts} +27 -24
- package/src/timing/Ticker.ts +11 -0
- package/src/timing/{timing.js → Timing.ts} +72 -63
- package/src/timing/{easing.js → easing.ts} +52 -43
- package/src/utils/{events.js → Events.ts} +12 -11
- package/src/utils/internal.ts +10 -0
- package/src/utils/{motionpath.js → motionpath.ts} +36 -13
- package/src/utils/utils.ts +110 -0
- package/src/values/{colorvalue.js → ColorValue.ts} +46 -47
- package/src/values/StyleValue.ts +186 -0
- package/src/values/{value.js → Value.ts} +14 -12
- package/src/values/{defaultcolors.js → defaultcolors.ts} +2 -2
- package/tsconfig.build.json +19 -0
- package/tsconfig.json +17 -108
- package/src/animation/property.js +0 -556
- package/src/responsive/event.js +0 -46
- package/src/scroll/event.js +0 -41
- package/src/scroll/public.js +0 -17
- package/src/stagger/stagger.js +0 -42
- package/src/target/domtarget.js +0 -266
- package/src/target/target.js +0 -22
- package/src/tests/timeline.test.js +0 -234
- package/src/utils/internal.js +0 -7
- package/src/utils/utils.js +0 -75
- package/src/values/stylevalue.js +0 -148
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import TestTicker from '../timing/
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { el, getRootElement } from '../target/testdomnode.js';
|
|
7
|
-
import { timeout } from 'fire/util.js';
|
|
2
|
+
import TestTicker from '../timing/TestTicker';
|
|
3
|
+
import { animate, timeline } from '../chnobli';
|
|
4
|
+
import { responsive, from, fromTo } from '../utils/utils';
|
|
5
|
+
import { el, getRootElement } from '../target/TestDomNode';
|
|
8
6
|
|
|
9
7
|
describe('values', () => {
|
|
10
8
|
it('rem unit', () => {
|
|
11
|
-
const ticker = new TestTicker;
|
|
9
|
+
const ticker = new TestTicker();
|
|
12
10
|
|
|
13
11
|
const root = getRootElement();
|
|
14
12
|
root.computedStyle.fontSize = '13px';
|
|
@@ -17,11 +15,11 @@ describe('values', () => {
|
|
|
17
15
|
const tl = timeline()
|
|
18
16
|
.add(div, {
|
|
19
17
|
width: '10rem',
|
|
20
|
-
duration: 5
|
|
18
|
+
duration: 5,
|
|
21
19
|
})
|
|
22
20
|
.add(div, {
|
|
23
21
|
width: 20,
|
|
24
|
-
duration: 5
|
|
22
|
+
duration: 5,
|
|
25
23
|
})
|
|
26
24
|
.play();
|
|
27
25
|
|
|
@@ -33,7 +31,7 @@ describe('values', () => {
|
|
|
33
31
|
});
|
|
34
32
|
|
|
35
33
|
it('percent unit', () => {
|
|
36
|
-
const ticker = new TestTicker;
|
|
34
|
+
const ticker = new TestTicker();
|
|
37
35
|
|
|
38
36
|
const div = el();
|
|
39
37
|
div.computedStyle.width = '10px';
|
|
@@ -41,7 +39,7 @@ describe('values', () => {
|
|
|
41
39
|
.add(div, {
|
|
42
40
|
x: '10%',
|
|
43
41
|
width: '50%',
|
|
44
|
-
duration: 10
|
|
42
|
+
duration: 10,
|
|
45
43
|
})
|
|
46
44
|
.play();
|
|
47
45
|
|
|
@@ -50,12 +48,14 @@ describe('values', () => {
|
|
|
50
48
|
expect(div.style.width).toBe('100.000%');
|
|
51
49
|
|
|
52
50
|
ticker.run();
|
|
53
|
-
expect(div.style.transform).toBe(
|
|
51
|
+
expect(div.style.transform).toBe(
|
|
52
|
+
'translate3d(10.000%,0.000px,0.000px)',
|
|
53
|
+
);
|
|
54
54
|
expect(div.style.width).toBe('50.000%');
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
it('multiple values', () => {
|
|
58
|
-
const ticker = new TestTicker;
|
|
58
|
+
const ticker = new TestTicker();
|
|
59
59
|
|
|
60
60
|
const root = getRootElement();
|
|
61
61
|
root.computedStyle.fontSize = '10px';
|
|
@@ -65,7 +65,7 @@ describe('values', () => {
|
|
|
65
65
|
const tl = timeline()
|
|
66
66
|
.add(div, {
|
|
67
67
|
padding: '10px 20rem',
|
|
68
|
-
duration: 10
|
|
68
|
+
duration: 10,
|
|
69
69
|
})
|
|
70
70
|
.play();
|
|
71
71
|
|
|
@@ -77,7 +77,7 @@ describe('values', () => {
|
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
it('display', () => {
|
|
80
|
-
const ticker = new TestTicker;
|
|
80
|
+
const ticker = new TestTicker();
|
|
81
81
|
|
|
82
82
|
const div = el();
|
|
83
83
|
div.computedStyle.display = 'block';
|
|
@@ -86,7 +86,7 @@ describe('values', () => {
|
|
|
86
86
|
display: 'none',
|
|
87
87
|
position: from('absolute'),
|
|
88
88
|
visibility: fromTo('hidden', 'visible'),
|
|
89
|
-
duration: 10
|
|
89
|
+
duration: 10,
|
|
90
90
|
})
|
|
91
91
|
.play();
|
|
92
92
|
|
|
@@ -108,7 +108,7 @@ describe('values', () => {
|
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
it('colors', () => {
|
|
111
|
-
const ticker = new TestTicker;
|
|
111
|
+
const ticker = new TestTicker();
|
|
112
112
|
const div = el();
|
|
113
113
|
div.computedStyle.color = 'rgb(120, 130, 20)';
|
|
114
114
|
|
|
@@ -116,7 +116,7 @@ describe('values', () => {
|
|
|
116
116
|
.add(div, {
|
|
117
117
|
color: 'black',
|
|
118
118
|
backgroundColor: 'hsl(10, 80%, 40%)',
|
|
119
|
-
duration: 10
|
|
119
|
+
duration: 10,
|
|
120
120
|
})
|
|
121
121
|
.play();
|
|
122
122
|
|
|
@@ -134,7 +134,7 @@ describe('values', () => {
|
|
|
134
134
|
});
|
|
135
135
|
|
|
136
136
|
it('css-vars', () => {
|
|
137
|
-
const ticker = new TestTicker;
|
|
137
|
+
const ticker = new TestTicker();
|
|
138
138
|
const div = el();
|
|
139
139
|
div.computedStyle['--color'] = 'rgb(120, 130, 20)';
|
|
140
140
|
div.computedStyle['--border'] = '20px';
|
|
@@ -143,7 +143,7 @@ describe('values', () => {
|
|
|
143
143
|
.add(div, {
|
|
144
144
|
'--color': 'black',
|
|
145
145
|
'--border': '1px 20px',
|
|
146
|
-
duration: 10
|
|
146
|
+
duration: 10,
|
|
147
147
|
})
|
|
148
148
|
.play();
|
|
149
149
|
|
|
@@ -159,4 +159,4 @@ describe('values', () => {
|
|
|
159
159
|
expect(div.style['--color']).toBe('rgba(0, 0, 0, 1.000)');
|
|
160
160
|
expect(div.style['--border']).toBe('1.000px 20.000px');
|
|
161
161
|
});
|
|
162
|
-
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { takeProp } from '../utils/internal';
|
|
2
|
+
import Timeline from './TimeLine';
|
|
3
|
+
import { timelineAdd } from './public';
|
|
4
|
+
|
|
5
|
+
export default class NestedTimeline {
|
|
6
|
+
_defaults: Record<string, any>;
|
|
7
|
+
_inner: Timeline;
|
|
8
|
+
|
|
9
|
+
constructor(props: Record<string, any> = {}) {
|
|
10
|
+
this._defaults = takeProp(props, 'defaults', {});
|
|
11
|
+
|
|
12
|
+
if ('duration' in props)
|
|
13
|
+
throw new Error('a timeline does not accept a duration');
|
|
14
|
+
|
|
15
|
+
this._inner = new Timeline(props);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Set's properties
|
|
20
|
+
* offset can be staggered, a number, a label or a string `+=10`
|
|
21
|
+
*/
|
|
22
|
+
set(targets: any, props: Record<string, any>, offset: any = null) {
|
|
23
|
+
// for the moment let's just add as usual but set the duration to 0
|
|
24
|
+
return this.add(targets, { ...props, duration: 0 }, offset);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Add an animation to the timeline
|
|
29
|
+
*
|
|
30
|
+
* offset can be staggered, a number, a label or a string `+=10`
|
|
31
|
+
*/
|
|
32
|
+
add(targets: any, props: Record<string, any>, offset: any = null) {
|
|
33
|
+
timelineAdd(this, targets, props, offset);
|
|
34
|
+
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Adds a label at to the current nOffse
|
|
40
|
+
*
|
|
41
|
+
* This label can then be used in offsets
|
|
42
|
+
*/
|
|
43
|
+
label(label: string, offset: any = null) {
|
|
44
|
+
this._inner.label(label, offset);
|
|
45
|
+
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Allows to nest timelines
|
|
51
|
+
*
|
|
52
|
+
* fn: (timeline)
|
|
53
|
+
*/
|
|
54
|
+
nest(
|
|
55
|
+
fn: (tl: NestedTimeline) => void,
|
|
56
|
+
opts: Record<string, any> = {},
|
|
57
|
+
offset: any = null,
|
|
58
|
+
) {
|
|
59
|
+
const tl = new NestedTimeline(opts);
|
|
60
|
+
|
|
61
|
+
fn(tl);
|
|
62
|
+
|
|
63
|
+
this._inner.addTimeline(tl._inner, offset);
|
|
64
|
+
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,18 +1,45 @@
|
|
|
1
|
-
import { takeProp } from '../utils/internal
|
|
1
|
+
import { takeProp } from '../utils/internal';
|
|
2
2
|
import Timing, {
|
|
3
|
-
parseEase,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
parseEase,
|
|
4
|
+
parseRepeat,
|
|
5
|
+
parseAlternate,
|
|
6
|
+
parseReversed,
|
|
7
|
+
STATE_BEFORE,
|
|
8
|
+
STATE_ENDED,
|
|
9
|
+
} from '../timing/Timing';
|
|
10
|
+
import Ticker from '../timing/Ticker';
|
|
11
|
+
import Animation from '../animation/Animation';
|
|
12
|
+
import AnimationFrameTicker from '../timing/AnimationFrameTicker';
|
|
13
|
+
|
|
14
|
+
type Entry = {
|
|
15
|
+
type: 'label' | 'animation' | 'timeline';
|
|
16
|
+
value: any;
|
|
17
|
+
offset: Offset;
|
|
18
|
+
relativeOffset: number;
|
|
19
|
+
start?: number;
|
|
20
|
+
end?: number;
|
|
21
|
+
};
|
|
8
22
|
|
|
9
23
|
/**
|
|
10
24
|
* Timeline is the most versatile class
|
|
11
|
-
*
|
|
25
|
+
*
|
|
12
26
|
* A timeline can contain multiple animation, ordered one after the other or
|
|
13
27
|
* offset.
|
|
14
28
|
*/
|
|
15
29
|
export default class Timeline {
|
|
30
|
+
timing: Timing;
|
|
31
|
+
ticker: Ticker;
|
|
32
|
+
|
|
33
|
+
private entries: Entry[];
|
|
34
|
+
|
|
35
|
+
private _beforeResponsiveFn: () => void;
|
|
36
|
+
private _initialized: boolean;
|
|
37
|
+
private _renderQueue: {
|
|
38
|
+
upcoming: Animation[];
|
|
39
|
+
passed: Animation[];
|
|
40
|
+
active: Animation[];
|
|
41
|
+
};
|
|
42
|
+
|
|
16
43
|
/*
|
|
17
44
|
{
|
|
18
45
|
ease,
|
|
@@ -20,30 +47,45 @@ export default class Timeline {
|
|
|
20
47
|
alternate
|
|
21
48
|
}
|
|
22
49
|
*/
|
|
23
|
-
constructor(props = {}) {
|
|
50
|
+
constructor(props: Record<string, any> = {}) {
|
|
24
51
|
const nProps = {
|
|
25
52
|
duration: 1000,
|
|
26
53
|
ease: parseEase(takeProp(props, 'ease', null)),
|
|
27
54
|
repeat: parseRepeat(takeProp(props, 'repeat', false)),
|
|
28
55
|
alternate: parseAlternate(takeProp(props, 'alternate', true)),
|
|
29
|
-
reversed: parseReversed(takeProp(props, 'reversed', false))
|
|
56
|
+
reversed: parseReversed(takeProp(props, 'reversed', false)),
|
|
30
57
|
};
|
|
31
58
|
|
|
32
59
|
this.timing = new Timing(nProps);
|
|
33
|
-
this.ticker =
|
|
60
|
+
this.ticker = AnimationFrameTicker.global();
|
|
34
61
|
|
|
35
62
|
// { type: label|animation, value: {}, offset, start: x, end: y, render }
|
|
36
63
|
this.entries = [];
|
|
37
64
|
|
|
38
65
|
this._beforeResponsiveFn = () => {};
|
|
39
66
|
this._initialized = false;
|
|
40
|
-
this._renderQueue =
|
|
67
|
+
this._renderQueue = {
|
|
68
|
+
upcoming: [],
|
|
69
|
+
passed: [],
|
|
70
|
+
active: [],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
isFinite() {
|
|
75
|
+
return !this.entries.some(e => {
|
|
76
|
+
return e.type === 'animation' && !e.value.isFinite();
|
|
77
|
+
});
|
|
41
78
|
}
|
|
42
79
|
|
|
43
80
|
// relative represents the point which the offset should be taken
|
|
44
81
|
// if relative 1 is done the offset will be taken from the previous - 1
|
|
45
|
-
add(
|
|
46
|
-
|
|
82
|
+
add(
|
|
83
|
+
target: any,
|
|
84
|
+
props: Record<string, any>,
|
|
85
|
+
offset: any = null,
|
|
86
|
+
relative = 0,
|
|
87
|
+
) {
|
|
88
|
+
const animation = new Animation(target, this.ticker, props);
|
|
47
89
|
|
|
48
90
|
if (!animation.isFinite())
|
|
49
91
|
throw new Error('the animation needs to be finite');
|
|
@@ -52,79 +94,92 @@ export default class Timeline {
|
|
|
52
94
|
type: 'animation',
|
|
53
95
|
value: animation,
|
|
54
96
|
offset: new Offset(offset),
|
|
55
|
-
relativeOffset: relative
|
|
97
|
+
relativeOffset: relative,
|
|
56
98
|
});
|
|
57
99
|
|
|
58
100
|
return this;
|
|
59
101
|
}
|
|
60
102
|
|
|
61
|
-
|
|
103
|
+
addTimeline(tl: Timeline, offset: any = null) {
|
|
104
|
+
if (!tl.isFinite()) throw new Error('the animation needs to be finite');
|
|
105
|
+
|
|
106
|
+
this.entries.push({
|
|
107
|
+
type: 'timeline',
|
|
108
|
+
value: tl,
|
|
109
|
+
offset: new Offset(offset),
|
|
110
|
+
relativeOffset: 0,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
label(label: string, offset: any = null) {
|
|
62
115
|
this.entries.push({
|
|
63
116
|
type: 'label',
|
|
64
117
|
value: label,
|
|
65
118
|
offset: new Offset(offset),
|
|
66
|
-
relativeOffset: 0
|
|
119
|
+
relativeOffset: 0,
|
|
67
120
|
});
|
|
68
121
|
|
|
69
122
|
return this;
|
|
70
123
|
}
|
|
71
124
|
|
|
72
125
|
// set's a function which get's called before any responsive call
|
|
73
|
-
setBeforeResponsiveFn(fn) {
|
|
126
|
+
setBeforeResponsiveFn(fn: () => void) {
|
|
74
127
|
this._beforeResponsiveFn = fn;
|
|
75
128
|
}
|
|
76
129
|
|
|
77
|
-
advance(change) {
|
|
130
|
+
advance(change: number) {
|
|
78
131
|
this.timing.advance(change);
|
|
79
132
|
|
|
80
133
|
this._updateTimings();
|
|
81
134
|
}
|
|
82
135
|
|
|
83
|
-
seekMs(ms) {
|
|
136
|
+
seekMs(ms: number) {
|
|
84
137
|
this.timing.seekMs(ms);
|
|
85
138
|
|
|
86
139
|
this._updateTimings();
|
|
87
140
|
}
|
|
88
141
|
|
|
89
|
-
seek(pos) {
|
|
142
|
+
seek(pos: number) {
|
|
90
143
|
this.timing.seek(pos);
|
|
91
144
|
|
|
92
145
|
this._updateTimings();
|
|
93
146
|
}
|
|
94
147
|
|
|
95
148
|
init() {
|
|
96
|
-
if (this._initialized)
|
|
97
|
-
return;
|
|
149
|
+
if (this._initialized) return;
|
|
98
150
|
this._initialized = true;
|
|
99
151
|
|
|
100
152
|
let duration = 0;
|
|
101
153
|
|
|
102
|
-
const labels = {};
|
|
154
|
+
const labels: Record<string, any> = {};
|
|
103
155
|
|
|
104
156
|
let i = -1;
|
|
105
157
|
for (const entry of this.entries) {
|
|
106
158
|
i++;
|
|
107
159
|
let offset = entry.offset;
|
|
160
|
+
const label = offset.label();
|
|
108
161
|
|
|
109
|
-
if (
|
|
110
|
-
if (!(
|
|
111
|
-
throw new Error('could not find label ' +
|
|
162
|
+
if (label) {
|
|
163
|
+
if (!(label in labels))
|
|
164
|
+
throw new Error('could not find label ' + label);
|
|
112
165
|
|
|
113
|
-
offset = new Offset(labels[
|
|
166
|
+
offset = new Offset(labels[label]);
|
|
114
167
|
}
|
|
115
168
|
|
|
116
169
|
const pos = this.entries[i - 1 - entry.relativeOffset]?.end ?? 0;
|
|
117
170
|
|
|
118
171
|
let start = offset.calculate(pos);
|
|
119
|
-
if (start < 0)
|
|
120
|
-
throw new Error('cannot go in the past start < 0');
|
|
172
|
+
if (start < 0) throw new Error('cannot go in the past start < 0');
|
|
121
173
|
|
|
122
174
|
let end = start;
|
|
123
|
-
if (entry.type === 'animation')
|
|
124
|
-
|
|
175
|
+
if (entry.type === 'animation') end += entry.value.duration;
|
|
176
|
+
|
|
177
|
+
if (entry.type === 'timeline') {
|
|
178
|
+
entry.value.init();
|
|
179
|
+
end += entry.value.timing.duration;
|
|
180
|
+
}
|
|
125
181
|
|
|
126
|
-
if (entry.type === 'label')
|
|
127
|
-
labels[entry.value] = start;
|
|
182
|
+
if (entry.type === 'label') labels[entry.value] = start;
|
|
128
183
|
|
|
129
184
|
entry.start = start;
|
|
130
185
|
entry.end = end;
|
|
@@ -148,13 +203,15 @@ export default class Timeline {
|
|
|
148
203
|
// initialization means
|
|
149
204
|
// we need to define which value should be used as the from and the to
|
|
150
205
|
// value
|
|
151
|
-
const startOrdered = this.entries.filter(e =>
|
|
152
|
-
|
|
206
|
+
const startOrdered = this.entries.filter(e => {
|
|
207
|
+
return e.type === 'animation' || e.type === 'timeline';
|
|
208
|
+
});
|
|
209
|
+
startOrdered.sort((a, b) => a.start! - b.start!);
|
|
153
210
|
|
|
154
211
|
for (let i = 0; i < startOrdered.length; i++) {
|
|
155
212
|
const entry = startOrdered[i];
|
|
156
213
|
|
|
157
|
-
this.timing.seekMs(entry.start);
|
|
214
|
+
this.timing.seekMs(entry.start!);
|
|
158
215
|
|
|
159
216
|
const pos = this.timing.positionMs();
|
|
160
217
|
|
|
@@ -163,7 +220,7 @@ export default class Timeline {
|
|
|
163
220
|
const prevEntry = startOrdered[y];
|
|
164
221
|
const prevAnimation = prevEntry.value;
|
|
165
222
|
|
|
166
|
-
prevAnimation.seekMs(pos - prevEntry.start);
|
|
223
|
+
prevAnimation.seekMs(pos - prevEntry.start!);
|
|
167
224
|
prevAnimation.render();
|
|
168
225
|
}
|
|
169
226
|
|
|
@@ -201,17 +258,17 @@ export default class Timeline {
|
|
|
201
258
|
this._renderQueue = {
|
|
202
259
|
upcoming: [],
|
|
203
260
|
passed: [],
|
|
204
|
-
active: []
|
|
261
|
+
active: [],
|
|
205
262
|
};
|
|
206
263
|
|
|
207
264
|
const pos = this.timing.positionMsUnbounded();
|
|
208
265
|
|
|
209
266
|
for (const entry of this.entries) {
|
|
210
|
-
if (entry.type !== 'animation')
|
|
267
|
+
if (entry.type !== 'animation' && entry.type !== 'timeline')
|
|
211
268
|
continue;
|
|
212
269
|
|
|
213
270
|
const animation = entry.value;
|
|
214
|
-
animation.seekMs(pos - entry.start);
|
|
271
|
+
animation.seekMs(pos - entry.start!);
|
|
215
272
|
|
|
216
273
|
if (animation.timing.state >= STATE_ENDED) {
|
|
217
274
|
this._renderQueue.passed.push(animation);
|
|
@@ -224,8 +281,7 @@ export default class Timeline {
|
|
|
224
281
|
}
|
|
225
282
|
|
|
226
283
|
update() {
|
|
227
|
-
if (!this._initialized)
|
|
228
|
-
return;
|
|
284
|
+
if (!this._initialized) return;
|
|
229
285
|
|
|
230
286
|
const pos = this.timing.savePosition();
|
|
231
287
|
const reversed = this.timing.reversed;
|
|
@@ -251,23 +307,30 @@ export default class Timeline {
|
|
|
251
307
|
|
|
252
308
|
destroy() {
|
|
253
309
|
for (const entry of this.entries) {
|
|
254
|
-
if (entry.type
|
|
310
|
+
if (entry.type === 'timeline') {
|
|
311
|
+
entry.value.destroy();
|
|
255
312
|
continue;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (entry.type !== 'animation') continue;
|
|
256
316
|
|
|
257
317
|
const animation = entry.value;
|
|
258
318
|
animation.destroy();
|
|
259
319
|
}
|
|
260
320
|
|
|
261
321
|
this.entries = [];
|
|
262
|
-
this._beforeResponsiveFn =
|
|
322
|
+
this._beforeResponsiveFn = () => {};
|
|
263
323
|
this.ticker.applyTargets();
|
|
264
324
|
}
|
|
265
325
|
}
|
|
266
326
|
|
|
267
|
-
|
|
268
327
|
class Offset {
|
|
269
|
-
|
|
328
|
+
type: 'none' | 'absolute' | 'sub' | 'add' | 'label';
|
|
329
|
+
value: number | string | null;
|
|
330
|
+
|
|
331
|
+
constructor(offset: any = null) {
|
|
270
332
|
this.type = 'none';
|
|
333
|
+
this.value = null;
|
|
271
334
|
|
|
272
335
|
if (typeof offset === 'number') {
|
|
273
336
|
this.type = 'absolute';
|
|
@@ -286,19 +349,26 @@ class Offset {
|
|
|
286
349
|
}
|
|
287
350
|
}
|
|
288
351
|
|
|
289
|
-
|
|
290
|
-
if (this.type
|
|
291
|
-
|
|
352
|
+
label(): string | null {
|
|
353
|
+
if (this.type !== 'label') return null;
|
|
354
|
+
|
|
355
|
+
return this.value as string;
|
|
356
|
+
}
|
|
292
357
|
|
|
293
|
-
|
|
294
|
-
|
|
358
|
+
// this is bullshit
|
|
359
|
+
/* isAbsolute(this: Offset): this is { type: 'absolute'; value: number } {
|
|
360
|
+
return this.type === 'absolute';
|
|
361
|
+
} */
|
|
295
362
|
|
|
296
|
-
|
|
297
|
-
|
|
363
|
+
calculate(pos: number): number {
|
|
364
|
+
if (this.type === 'none') return pos;
|
|
298
365
|
|
|
299
|
-
if (this.type === '
|
|
300
|
-
|
|
366
|
+
if (this.type === 'absolute') return this.value as number;
|
|
367
|
+
|
|
368
|
+
if (this.type === 'sub') return pos - (this.value as number);
|
|
369
|
+
|
|
370
|
+
if (this.type === 'add') return pos + (this.value as number);
|
|
301
371
|
|
|
302
372
|
throw new Error('cannot calculate for type ' + this.type);
|
|
303
373
|
}
|
|
304
|
-
}
|
|
374
|
+
}
|