chnobli 0.1.5 → 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.js → timeline.test.ts} +92 -75
- 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.js → Nested.ts} +18 -12
- package/src/timeline/{timeline.js → TimeLine.ts} +100 -60
- package/src/timeline/{public.js → public.ts} +75 -60
- 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/utils/internal.js +0 -7
- package/src/utils/utils.js +0 -107
- package/src/values/stylevalue.js +0 -148
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { takeProp } from '../utils/internal
|
|
1
|
+
import { takeProp } from '../utils/internal';
|
|
2
2
|
|
|
3
3
|
export const STATE_BEFORE = 0;
|
|
4
4
|
/// start only occurs if the current position is exactly 0 or 1 if reversed
|
|
@@ -8,24 +8,41 @@ export const STATE_RUNNING = 2;
|
|
|
8
8
|
export const STATE_ENDED = 3;
|
|
9
9
|
export const STATE_AFTER = 4;
|
|
10
10
|
|
|
11
|
+
export type Position = {
|
|
12
|
+
progress: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
11
15
|
/**
|
|
12
16
|
* This class handles everything timing related
|
|
13
|
-
*
|
|
17
|
+
*
|
|
14
18
|
* It manages easing, keeps track of where we are at the moment
|
|
15
|
-
*
|
|
19
|
+
*
|
|
16
20
|
* The most important property is position which gives the calculated position
|
|
17
|
-
*
|
|
18
|
-
*
|
|
21
|
+
*
|
|
22
|
+
*
|
|
19
23
|
* Timing works the same as in after effects
|
|
20
24
|
* if the duration is not at least 1ms the position is always 1 and either
|
|
21
25
|
* STATE_BEFORE or STATE_AFTER
|
|
22
|
-
*
|
|
26
|
+
*
|
|
23
27
|
* if the duration is 1ms seek 0 or 1 will always result in position 1
|
|
24
28
|
* because it is like one frame, so it's an image
|
|
25
29
|
*/
|
|
26
30
|
export default class Timing {
|
|
27
31
|
// removes the relevant properties from the props
|
|
28
32
|
|
|
33
|
+
iterDuration: number;
|
|
34
|
+
duration: number;
|
|
35
|
+
|
|
36
|
+
ease: (t: number) => number;
|
|
37
|
+
repeat: number;
|
|
38
|
+
alternate: boolean;
|
|
39
|
+
reversed: boolean;
|
|
40
|
+
|
|
41
|
+
position: number;
|
|
42
|
+
state: number;
|
|
43
|
+
|
|
44
|
+
private _progress: number;
|
|
45
|
+
|
|
29
46
|
/*
|
|
30
47
|
seeking
|
|
31
48
|
if repeat is infinite
|
|
@@ -41,11 +58,13 @@ export default class Timing {
|
|
|
41
58
|
alternate
|
|
42
59
|
}
|
|
43
60
|
*/
|
|
44
|
-
constructor(props) {
|
|
61
|
+
constructor(props: Record<string, any>) {
|
|
45
62
|
// these vars are only readonly
|
|
46
63
|
// use functions to update them
|
|
47
64
|
|
|
48
|
-
this.
|
|
65
|
+
this.iterDuration = props.duration;
|
|
66
|
+
this.duration = props.duration;
|
|
67
|
+
|
|
49
68
|
this.ease = props.ease ?? (t => t);
|
|
50
69
|
this.repeat = props.repeat ?? 0;
|
|
51
70
|
this.alternate = props.alternate ?? true;
|
|
@@ -61,6 +80,15 @@ export default class Timing {
|
|
|
61
80
|
// scrub
|
|
62
81
|
}
|
|
63
82
|
|
|
83
|
+
setDuration(iterDuration: number) {
|
|
84
|
+
this.iterDuration = iterDuration;
|
|
85
|
+
|
|
86
|
+
this.duration = this.iterDuration;
|
|
87
|
+
if (this.repeat > -1) {
|
|
88
|
+
this.duration = (this.repeat + 1) * this.iterDuration;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
64
92
|
positionMs() {
|
|
65
93
|
return this.position * this.iterDuration;
|
|
66
94
|
}
|
|
@@ -68,39 +96,26 @@ export default class Timing {
|
|
|
68
96
|
// todo find a better name
|
|
69
97
|
/**
|
|
70
98
|
* Returns the position in milliseconds
|
|
71
|
-
*
|
|
99
|
+
*
|
|
72
100
|
* If the state is before or after the position might be more/less than
|
|
73
101
|
* required
|
|
74
102
|
*/
|
|
75
103
|
positionMsUnbounded() {
|
|
76
|
-
const outOfBounds =
|
|
77
|
-
|| this.state >= STATE_AFTER;
|
|
104
|
+
const outOfBounds =
|
|
105
|
+
this.state <= STATE_BEFORE || this.state >= STATE_AFTER;
|
|
78
106
|
|
|
79
|
-
if (!outOfBounds)
|
|
80
|
-
return this.position * this.iterDuration;
|
|
107
|
+
if (!outOfBounds) return this.position * this.iterDuration;
|
|
81
108
|
|
|
82
|
-
if (this.position === 0)
|
|
83
|
-
return -1;
|
|
109
|
+
if (this.position === 0) return -1;
|
|
84
110
|
return this.position * this.iterDuration + 1;
|
|
85
111
|
}
|
|
86
112
|
|
|
87
|
-
/// iterDuration should always be >=0
|
|
88
|
-
setDuration(iterDuration) {
|
|
89
|
-
this.iterDuration = iterDuration;
|
|
90
|
-
|
|
91
|
-
this.duration = this.iterDuration;
|
|
92
|
-
if (this.repeat > -1) {
|
|
93
|
-
this.duration = (this.repeat + 1) * this.iterDuration;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
113
|
isFinite() {
|
|
98
114
|
return this.repeat > -1;
|
|
99
115
|
}
|
|
100
116
|
|
|
101
|
-
advance(change) {
|
|
102
|
-
if (this.state >= STATE_AFTER)
|
|
103
|
-
return;
|
|
117
|
+
advance(change: number) {
|
|
118
|
+
if (this.state >= STATE_AFTER) return;
|
|
104
119
|
|
|
105
120
|
if (this.iterDuration <= 0) {
|
|
106
121
|
this._updateProgress(1);
|
|
@@ -110,7 +125,7 @@ export default class Timing {
|
|
|
110
125
|
this._updateProgress(this._progress + change / this.iterDuration);
|
|
111
126
|
}
|
|
112
127
|
|
|
113
|
-
seekMs(ms) {
|
|
128
|
+
seekMs(ms: number) {
|
|
114
129
|
if (this.iterDuration <= 0) {
|
|
115
130
|
this._updateProgress(Math.sign(ms));
|
|
116
131
|
return;
|
|
@@ -120,28 +135,27 @@ export default class Timing {
|
|
|
120
135
|
}
|
|
121
136
|
|
|
122
137
|
// should be between 0-1 if outside might change the state
|
|
123
|
-
seek(pos) {
|
|
138
|
+
seek(pos: number) {
|
|
124
139
|
if (this.repeat <= 0) {
|
|
125
140
|
this._updateProgress(pos);
|
|
126
141
|
} else {
|
|
127
|
-
|
|
142
|
+
// finite
|
|
128
143
|
this._updateProgress(pos * (this.repeat + 1));
|
|
129
144
|
}
|
|
130
145
|
}
|
|
131
146
|
|
|
132
|
-
savePosition() {
|
|
147
|
+
savePosition(): Position {
|
|
133
148
|
return {
|
|
134
|
-
progress: this._progress
|
|
149
|
+
progress: this._progress,
|
|
135
150
|
};
|
|
136
151
|
}
|
|
137
152
|
|
|
138
|
-
restorePosition(pos) {
|
|
153
|
+
restorePosition(pos: Position) {
|
|
139
154
|
this._updateProgress(pos.progress);
|
|
140
155
|
}
|
|
141
156
|
|
|
142
|
-
setAlternate(alternate) {
|
|
143
|
-
if (this.alternate == alternate)
|
|
144
|
-
return;
|
|
157
|
+
setAlternate(alternate: boolean) {
|
|
158
|
+
if (this.alternate == alternate) return;
|
|
145
159
|
|
|
146
160
|
// make sure the reversed is updated according to the current inversion
|
|
147
161
|
this.reversed = alternate == this._shouldInvert();
|
|
@@ -151,9 +165,8 @@ export default class Timing {
|
|
|
151
165
|
reverse() {
|
|
152
166
|
this.reversed = !this.reversed;
|
|
153
167
|
|
|
154
|
-
const wrapAround = p => {
|
|
155
|
-
if (this.repeat > -1)
|
|
156
|
-
return p % (this.repeat + 1);
|
|
168
|
+
const wrapAround = (p: number) => {
|
|
169
|
+
if (this.repeat > -1) return p % (this.repeat + 1);
|
|
157
170
|
return p;
|
|
158
171
|
};
|
|
159
172
|
|
|
@@ -162,9 +175,9 @@ export default class Timing {
|
|
|
162
175
|
p = 2;
|
|
163
176
|
} else if (this.state >= STATE_AFTER) {
|
|
164
177
|
p = -1;
|
|
165
|
-
|
|
178
|
+
// check if the values should be reversed
|
|
166
179
|
} else if (this.reversed != this._shouldInvert()) {
|
|
167
|
-
let decimal = 1 - this._progress % 1;
|
|
180
|
+
let decimal = 1 - (this._progress % 1);
|
|
168
181
|
p = wrapAround(Math.floor(this._progress) + decimal);
|
|
169
182
|
} else {
|
|
170
183
|
p = wrapAround(this._progress);
|
|
@@ -177,7 +190,7 @@ export default class Timing {
|
|
|
177
190
|
return this.alternate && Math.floor(this._progress) % 2 === 1;
|
|
178
191
|
}
|
|
179
192
|
|
|
180
|
-
_updateProgress(newProgress) {
|
|
193
|
+
_updateProgress(newProgress: number) {
|
|
181
194
|
// if duration is zero the position is always 1
|
|
182
195
|
// and the state is either BEFORE or AFTER
|
|
183
196
|
if (this.iterDuration <= 0) {
|
|
@@ -185,10 +198,8 @@ export default class Timing {
|
|
|
185
198
|
this._progress = newProgress;
|
|
186
199
|
this.position = 1;
|
|
187
200
|
|
|
188
|
-
if (newProgress < 0)
|
|
189
|
-
|
|
190
|
-
else
|
|
191
|
-
this.state = STATE_AFTER;
|
|
201
|
+
if (newProgress < 0) this.state = STATE_BEFORE;
|
|
202
|
+
else this.state = STATE_AFTER;
|
|
192
203
|
|
|
193
204
|
return;
|
|
194
205
|
}
|
|
@@ -230,66 +241,64 @@ export default class Timing {
|
|
|
230
241
|
}
|
|
231
242
|
}
|
|
232
243
|
|
|
233
|
-
export function newTiming(props) {
|
|
244
|
+
export function newTiming(props: Record<string, any>) {
|
|
234
245
|
const nProps = {
|
|
235
246
|
duration: parseDuration(takeProp(props, 'duration', 1000)),
|
|
236
247
|
ease: parseEase(takeProp(props, 'ease', null)),
|
|
237
248
|
repeat: parseRepeat(takeProp(props, 'repeat', false)),
|
|
238
|
-
alternate: parseAlternate(takeProp(props, 'alternate', true))
|
|
249
|
+
alternate: parseAlternate(takeProp(props, 'alternate', true)),
|
|
239
250
|
};
|
|
240
251
|
// this._delay = parseDelay(takeProp(props, 'delay', 0));
|
|
241
252
|
|
|
242
253
|
return new Timing(nProps);
|
|
243
254
|
}
|
|
244
255
|
|
|
245
|
-
export function parseDuration(dur) {
|
|
246
|
-
if (typeof dur !== 'number')
|
|
247
|
-
throw new Error('duration is not a number');
|
|
256
|
+
export function parseDuration(dur: any) {
|
|
257
|
+
if (typeof dur !== 'number') throw new Error('duration is not a number');
|
|
248
258
|
|
|
249
259
|
dur = Math.round(dur);
|
|
250
260
|
|
|
251
261
|
return Math.max(dur, 0);
|
|
252
262
|
}
|
|
253
263
|
|
|
254
|
-
export function parseEase(ease) {
|
|
264
|
+
export function parseEase(ease: any): (t: number) => number {
|
|
255
265
|
if (ease !== null && typeof ease !== 'function')
|
|
256
266
|
throw new Error('ease needs to be null or a function');
|
|
257
267
|
|
|
258
268
|
return ease;
|
|
259
269
|
}
|
|
260
270
|
|
|
261
|
-
export function parseRepeat(repeat) {
|
|
271
|
+
export function parseRepeat(repeat: any): number {
|
|
262
272
|
if (
|
|
263
|
-
repeat !== true &&
|
|
273
|
+
repeat !== true &&
|
|
274
|
+
repeat !== false &&
|
|
264
275
|
(typeof repeat !== 'number' || repeat < 0)
|
|
265
276
|
)
|
|
266
277
|
throw new Error('repeat needs to be true|false|0+');
|
|
267
278
|
|
|
268
|
-
if (repeat === true)
|
|
269
|
-
|
|
270
|
-
else if (repeat === false)
|
|
271
|
-
repeat = 0;
|
|
279
|
+
if (repeat === true) repeat = -1;
|
|
280
|
+
else if (repeat === false) repeat = 0;
|
|
272
281
|
|
|
273
282
|
return repeat;
|
|
274
283
|
}
|
|
275
284
|
|
|
276
|
-
export function parseDelay(delay) {
|
|
285
|
+
export function parseDelay(delay: any): number {
|
|
277
286
|
if (typeof delay !== 'number' || delay < 0)
|
|
278
287
|
throw new Error('delay needs to be 0+');
|
|
279
288
|
|
|
280
289
|
return delay;
|
|
281
290
|
}
|
|
282
291
|
|
|
283
|
-
export function parseAlternate(alternate) {
|
|
292
|
+
export function parseAlternate(alternate: any): boolean {
|
|
284
293
|
if (alternate !== true && alternate !== false)
|
|
285
294
|
throw new Error('alternate needs to be true|false');
|
|
286
295
|
|
|
287
296
|
return alternate;
|
|
288
297
|
}
|
|
289
298
|
|
|
290
|
-
export function parseReversed(reversed) {
|
|
299
|
+
export function parseReversed(reversed: any): boolean {
|
|
291
300
|
if (reversed !== true && reversed !== false)
|
|
292
301
|
throw new Error('reversed needs to be true|false');
|
|
293
302
|
|
|
294
303
|
return reversed;
|
|
295
|
-
}
|
|
304
|
+
}
|
|
@@ -9,7 +9,7 @@ import bezierEasing from 'bezier-easing';
|
|
|
9
9
|
* @param {number} t
|
|
10
10
|
* @returns {number}
|
|
11
11
|
*/
|
|
12
|
-
export function linear(t) {
|
|
12
|
+
export function linear(t: number): number {
|
|
13
13
|
return t;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ export function linear(t) {
|
|
|
17
17
|
* @param {number} t
|
|
18
18
|
* @returns {number}
|
|
19
19
|
*/
|
|
20
|
-
export function backInOut(t) {
|
|
20
|
+
export function backInOut(t: number): number {
|
|
21
21
|
const s = 1.70158 * 1.525;
|
|
22
22
|
if ((t *= 2) < 1) return 0.5 * (t * t * ((s + 1) * t - s));
|
|
23
23
|
return 0.5 * ((t -= 2) * t * ((s + 1) * t + s) + 2);
|
|
@@ -27,7 +27,7 @@ export function backInOut(t) {
|
|
|
27
27
|
* @param {number} t
|
|
28
28
|
* @returns {number}
|
|
29
29
|
*/
|
|
30
|
-
export function backIn(t) {
|
|
30
|
+
export function backIn(t: number): number {
|
|
31
31
|
const s = 1.70158;
|
|
32
32
|
return t * t * ((s + 1) * t - s);
|
|
33
33
|
}
|
|
@@ -36,7 +36,7 @@ export function backIn(t) {
|
|
|
36
36
|
* @param {number} t
|
|
37
37
|
* @returns {number}
|
|
38
38
|
*/
|
|
39
|
-
export function backOut(t) {
|
|
39
|
+
export function backOut(t: number): number {
|
|
40
40
|
const s = 1.70158;
|
|
41
41
|
return --t * t * ((s + 1) * t + s) + 1;
|
|
42
42
|
}
|
|
@@ -45,7 +45,7 @@ export function backOut(t) {
|
|
|
45
45
|
* @param {number} t
|
|
46
46
|
* @returns {number}
|
|
47
47
|
*/
|
|
48
|
-
export function bounceOut(t) {
|
|
48
|
+
export function bounceOut(t: number): number {
|
|
49
49
|
const a = 4.0 / 11.0;
|
|
50
50
|
const b = 8.0 / 11.0;
|
|
51
51
|
const c = 9.0 / 10.0;
|
|
@@ -56,25 +56,27 @@ export function bounceOut(t) {
|
|
|
56
56
|
return t < a
|
|
57
57
|
? 7.5625 * t2
|
|
58
58
|
: t < b
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
? 9.075 * t2 - 9.9 * t + 3.4
|
|
60
|
+
: t < c
|
|
61
|
+
? ca * t2 - cb * t + cc
|
|
62
|
+
: 10.8 * t * t - 20.52 * t + 10.72;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* @param {number} t
|
|
67
67
|
* @returns {number}
|
|
68
68
|
*/
|
|
69
|
-
export function bounceInOut(t) {
|
|
70
|
-
return t < 0.5
|
|
69
|
+
export function bounceInOut(t: number): number {
|
|
70
|
+
return t < 0.5
|
|
71
|
+
? 0.5 * (1.0 - bounceOut(1.0 - t * 2.0))
|
|
72
|
+
: 0.5 * bounceOut(t * 2.0 - 1.0) + 0.5;
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
/**
|
|
74
76
|
* @param {number} t
|
|
75
77
|
* @returns {number}
|
|
76
78
|
*/
|
|
77
|
-
export function bounceIn(t) {
|
|
79
|
+
export function bounceIn(t: number): number {
|
|
78
80
|
return 1.0 - bounceOut(1.0 - t);
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -82,7 +84,7 @@ export function bounceIn(t) {
|
|
|
82
84
|
* @param {number} t
|
|
83
85
|
* @returns {number}
|
|
84
86
|
*/
|
|
85
|
-
export function circInOut(t) {
|
|
87
|
+
export function circInOut(t: number): number {
|
|
86
88
|
if ((t *= 2) < 1) return -0.5 * (Math.sqrt(1 - t * t) - 1);
|
|
87
89
|
return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
|
|
88
90
|
}
|
|
@@ -91,7 +93,7 @@ export function circInOut(t) {
|
|
|
91
93
|
* @param {number} t
|
|
92
94
|
* @returns {number}
|
|
93
95
|
*/
|
|
94
|
-
export function circIn(t) {
|
|
96
|
+
export function circIn(t: number): number {
|
|
95
97
|
return 1.0 - Math.sqrt(1.0 - t * t);
|
|
96
98
|
}
|
|
97
99
|
|
|
@@ -99,7 +101,7 @@ export function circIn(t) {
|
|
|
99
101
|
* @param {number} t
|
|
100
102
|
* @returns {number}
|
|
101
103
|
*/
|
|
102
|
-
export function circOut(t) {
|
|
104
|
+
export function circOut(t: number): number {
|
|
103
105
|
return Math.sqrt(1 - --t * t);
|
|
104
106
|
}
|
|
105
107
|
|
|
@@ -107,7 +109,7 @@ export function circOut(t) {
|
|
|
107
109
|
* @param {number} t
|
|
108
110
|
* @returns {number}
|
|
109
111
|
*/
|
|
110
|
-
export function cubicInOut(t) {
|
|
112
|
+
export function cubicInOut(t: number): number {
|
|
111
113
|
return t < 0.5 ? 4.0 * t * t * t : 0.5 * Math.pow(2.0 * t - 2.0, 3.0) + 1.0;
|
|
112
114
|
}
|
|
113
115
|
|
|
@@ -115,7 +117,7 @@ export function cubicInOut(t) {
|
|
|
115
117
|
* @param {number} t
|
|
116
118
|
* @returns {number}
|
|
117
119
|
*/
|
|
118
|
-
export function cubicIn(t) {
|
|
120
|
+
export function cubicIn(t: number): number {
|
|
119
121
|
return t * t * t;
|
|
120
122
|
}
|
|
121
123
|
|
|
@@ -123,7 +125,7 @@ export function cubicIn(t) {
|
|
|
123
125
|
* @param {number} t
|
|
124
126
|
* @returns {number}
|
|
125
127
|
*/
|
|
126
|
-
export function cubicOut(t) {
|
|
128
|
+
export function cubicOut(t: number): number {
|
|
127
129
|
const f = t - 1.0;
|
|
128
130
|
return f * f * f + 1.0;
|
|
129
131
|
}
|
|
@@ -132,9 +134,11 @@ export function cubicOut(t) {
|
|
|
132
134
|
* @param {number} t
|
|
133
135
|
* @returns {number}
|
|
134
136
|
*/
|
|
135
|
-
export function elasticInOut(t) {
|
|
137
|
+
export function elasticInOut(t: number): number {
|
|
136
138
|
return t < 0.5
|
|
137
|
-
? 0.5 *
|
|
139
|
+
? 0.5 *
|
|
140
|
+
Math.sin(((+13.0 * Math.PI) / 2) * 2.0 * t) *
|
|
141
|
+
Math.pow(2.0, 10.0 * (2.0 * t - 1.0))
|
|
138
142
|
: 0.5 *
|
|
139
143
|
Math.sin(((-13.0 * Math.PI) / 2) * (2.0 * t - 1.0 + 1.0)) *
|
|
140
144
|
Math.pow(2.0, -10.0 * (2.0 * t - 1.0)) +
|
|
@@ -145,7 +149,7 @@ export function elasticInOut(t) {
|
|
|
145
149
|
* @param {number} t
|
|
146
150
|
* @returns {number}
|
|
147
151
|
*/
|
|
148
|
-
export function elasticIn(t) {
|
|
152
|
+
export function elasticIn(t: number): number {
|
|
149
153
|
return Math.sin((13.0 * t * Math.PI) / 2) * Math.pow(2.0, 10.0 * (t - 1.0));
|
|
150
154
|
}
|
|
151
155
|
|
|
@@ -153,27 +157,30 @@ export function elasticIn(t) {
|
|
|
153
157
|
* @param {number} t
|
|
154
158
|
* @returns {number}
|
|
155
159
|
*/
|
|
156
|
-
export function elasticOut(t) {
|
|
157
|
-
return
|
|
160
|
+
export function elasticOut(t: number): number {
|
|
161
|
+
return (
|
|
162
|
+
Math.sin((-13.0 * (t + 1.0) * Math.PI) / 2) * Math.pow(2.0, -10.0 * t) +
|
|
163
|
+
1.0
|
|
164
|
+
);
|
|
158
165
|
}
|
|
159
166
|
|
|
160
167
|
/**
|
|
161
168
|
* @param {number} t
|
|
162
169
|
* @returns {number}
|
|
163
170
|
*/
|
|
164
|
-
export function expoInOut(t) {
|
|
171
|
+
export function expoInOut(t: number): number {
|
|
165
172
|
return t === 0.0 || t === 1.0
|
|
166
173
|
? t
|
|
167
174
|
: t < 0.5
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
? +0.5 * Math.pow(2.0, 20.0 * t - 10.0)
|
|
176
|
+
: -0.5 * Math.pow(2.0, 10.0 - t * 20.0) + 1.0;
|
|
170
177
|
}
|
|
171
178
|
|
|
172
179
|
/**
|
|
173
180
|
* @param {number} t
|
|
174
181
|
* @returns {number}
|
|
175
182
|
*/
|
|
176
|
-
export function expoIn(t) {
|
|
183
|
+
export function expoIn(t: number): number {
|
|
177
184
|
return t === 0.0 ? t : Math.pow(2.0, 10.0 * (t - 1.0));
|
|
178
185
|
}
|
|
179
186
|
|
|
@@ -181,7 +188,7 @@ export function expoIn(t) {
|
|
|
181
188
|
* @param {number} t
|
|
182
189
|
* @returns {number}
|
|
183
190
|
*/
|
|
184
|
-
export function expoOut(t) {
|
|
191
|
+
export function expoOut(t: number): number {
|
|
185
192
|
return t === 1.0 ? t : 1.0 - Math.pow(2.0, -10.0 * t);
|
|
186
193
|
}
|
|
187
194
|
|
|
@@ -189,7 +196,7 @@ export function expoOut(t) {
|
|
|
189
196
|
* @param {number} t
|
|
190
197
|
* @returns {number}
|
|
191
198
|
*/
|
|
192
|
-
export function quadInOut(t) {
|
|
199
|
+
export function quadInOut(t: number): number {
|
|
193
200
|
t /= 0.5;
|
|
194
201
|
if (t < 1) return 0.5 * t * t;
|
|
195
202
|
t--;
|
|
@@ -200,7 +207,7 @@ export function quadInOut(t) {
|
|
|
200
207
|
* @param {number} t
|
|
201
208
|
* @returns {number}
|
|
202
209
|
*/
|
|
203
|
-
export function quadIn(t) {
|
|
210
|
+
export function quadIn(t: number): number {
|
|
204
211
|
return t * t;
|
|
205
212
|
}
|
|
206
213
|
|
|
@@ -208,7 +215,7 @@ export function quadIn(t) {
|
|
|
208
215
|
* @param {number} t
|
|
209
216
|
* @returns {number}
|
|
210
217
|
*/
|
|
211
|
-
export function quadOut(t) {
|
|
218
|
+
export function quadOut(t: number): number {
|
|
212
219
|
return -t * (t - 2.0);
|
|
213
220
|
}
|
|
214
221
|
|
|
@@ -216,15 +223,17 @@ export function quadOut(t) {
|
|
|
216
223
|
* @param {number} t
|
|
217
224
|
* @returns {number}
|
|
218
225
|
*/
|
|
219
|
-
export function quartInOut(t) {
|
|
220
|
-
return t < 0.5
|
|
226
|
+
export function quartInOut(t: number): number {
|
|
227
|
+
return t < 0.5
|
|
228
|
+
? +8.0 * Math.pow(t, 4.0)
|
|
229
|
+
: -8.0 * Math.pow(t - 1.0, 4.0) + 1.0;
|
|
221
230
|
}
|
|
222
231
|
|
|
223
232
|
/**
|
|
224
233
|
* @param {number} t
|
|
225
234
|
* @returns {number}
|
|
226
235
|
*/
|
|
227
|
-
export function quartIn(t) {
|
|
236
|
+
export function quartIn(t: number): number {
|
|
228
237
|
return Math.pow(t, 4.0);
|
|
229
238
|
}
|
|
230
239
|
|
|
@@ -232,7 +241,7 @@ export function quartIn(t) {
|
|
|
232
241
|
* @param {number} t
|
|
233
242
|
* @returns {number}
|
|
234
243
|
*/
|
|
235
|
-
export function quartOut(t) {
|
|
244
|
+
export function quartOut(t: number): number {
|
|
236
245
|
return Math.pow(t - 1.0, 3.0) * (1.0 - t) + 1.0;
|
|
237
246
|
}
|
|
238
247
|
|
|
@@ -240,7 +249,7 @@ export function quartOut(t) {
|
|
|
240
249
|
* @param {number} t
|
|
241
250
|
* @returns {number}
|
|
242
251
|
*/
|
|
243
|
-
export function quintInOut(t) {
|
|
252
|
+
export function quintInOut(t: number): number {
|
|
244
253
|
if ((t *= 2) < 1) return 0.5 * t * t * t * t * t;
|
|
245
254
|
return 0.5 * ((t -= 2) * t * t * t * t + 2);
|
|
246
255
|
}
|
|
@@ -249,7 +258,7 @@ export function quintInOut(t) {
|
|
|
249
258
|
* @param {number} t
|
|
250
259
|
* @returns {number}
|
|
251
260
|
*/
|
|
252
|
-
export function quintIn(t) {
|
|
261
|
+
export function quintIn(t: number): number {
|
|
253
262
|
return t * t * t * t * t;
|
|
254
263
|
}
|
|
255
264
|
|
|
@@ -257,7 +266,7 @@ export function quintIn(t) {
|
|
|
257
266
|
* @param {number} t
|
|
258
267
|
* @returns {number}
|
|
259
268
|
*/
|
|
260
|
-
export function quintOut(t) {
|
|
269
|
+
export function quintOut(t: number): number {
|
|
261
270
|
return --t * t * t * t * t + 1;
|
|
262
271
|
}
|
|
263
272
|
|
|
@@ -265,7 +274,7 @@ export function quintOut(t) {
|
|
|
265
274
|
* @param {number} t
|
|
266
275
|
* @returns {number}
|
|
267
276
|
*/
|
|
268
|
-
export function sineInOut(t) {
|
|
277
|
+
export function sineInOut(t: number): number {
|
|
269
278
|
return -0.5 * (Math.cos(Math.PI * t) - 1);
|
|
270
279
|
}
|
|
271
280
|
|
|
@@ -273,7 +282,7 @@ export function sineInOut(t) {
|
|
|
273
282
|
* @param {number} t
|
|
274
283
|
* @returns {number}
|
|
275
284
|
*/
|
|
276
|
-
export function sineIn(t) {
|
|
285
|
+
export function sineIn(t: number): number {
|
|
277
286
|
const v = Math.cos(t * Math.PI * 0.5);
|
|
278
287
|
if (Math.abs(v) < 1e-14) return 1;
|
|
279
288
|
else return 1 - v;
|
|
@@ -283,10 +292,10 @@ export function sineIn(t) {
|
|
|
283
292
|
* @param {number} t
|
|
284
293
|
* @returns {number}
|
|
285
294
|
*/
|
|
286
|
-
export function sineOut(t) {
|
|
295
|
+
export function sineOut(t: number): number {
|
|
287
296
|
return Math.sin((t * Math.PI) / 2);
|
|
288
297
|
}
|
|
289
298
|
|
|
290
|
-
export function cubicBezier(x1, y1, x2, y2) {
|
|
299
|
+
export function cubicBezier(x1: number, y1: number, x2: number, y2: number) {
|
|
291
300
|
return bezierEasing(x1, y1, x2, y2);
|
|
292
|
-
}
|
|
301
|
+
}
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import Listeners from 'fire/
|
|
1
|
+
import Listeners from 'fire/sync/Listeners';
|
|
2
2
|
|
|
3
3
|
export default class Events {
|
|
4
|
+
private listeners: Map<string, Listeners<any>>;
|
|
5
|
+
|
|
4
6
|
constructor() {
|
|
5
|
-
this.listeners = new Map;
|
|
7
|
+
this.listeners = new Map();
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
add(event, fn) {
|
|
10
|
+
add(event: string, fn: (...args: any[]) => void) {
|
|
9
11
|
let list = this.listeners.get(event);
|
|
10
12
|
if (!list) {
|
|
11
|
-
list = new Listeners;
|
|
13
|
+
list = new Listeners();
|
|
12
14
|
this.listeners.set(event, list);
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
return list.add(fn);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
wait(event) {
|
|
20
|
+
wait(event: string): any {
|
|
19
21
|
return new Promise(resolve => {
|
|
20
22
|
let rm = () => {};
|
|
21
|
-
const call = a => {
|
|
23
|
+
const call = (a: any) => {
|
|
22
24
|
rm();
|
|
23
25
|
resolve(a);
|
|
24
26
|
};
|
|
@@ -26,14 +28,13 @@ export default class Events {
|
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
trigger(event, ...args) {
|
|
31
|
+
trigger(event: string, ...args: any[]) {
|
|
30
32
|
let list = this.listeners.get(event);
|
|
31
|
-
if (!list)
|
|
32
|
-
return;
|
|
33
|
+
if (!list) return;
|
|
33
34
|
list.trigger(...args);
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
destroy() {
|
|
37
|
-
this.listeners = new Map;
|
|
38
|
+
this.listeners = new Map();
|
|
38
39
|
}
|
|
39
|
-
}
|
|
40
|
+
}
|