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.
Files changed (238) hide show
  1. package/.prettierignore +4 -0
  2. package/.prettierrc +6 -0
  3. package/.vscode/settings.json +4 -0
  4. package/auto-docs/easing.js.html +342 -0
  5. package/auto-docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  6. package/auto-docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
  7. package/auto-docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  8. package/auto-docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  9. package/auto-docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  10. package/auto-docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  11. package/auto-docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  12. package/auto-docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
  13. package/auto-docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  14. package/auto-docs/fonts/OpenSans-Light-webfont.eot +0 -0
  15. package/auto-docs/fonts/OpenSans-Light-webfont.svg +1831 -0
  16. package/auto-docs/fonts/OpenSans-Light-webfont.woff +0 -0
  17. package/auto-docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  18. package/auto-docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  19. package/auto-docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  20. package/auto-docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  21. package/auto-docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
  22. package/auto-docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  23. package/auto-docs/global.html +4810 -0
  24. package/auto-docs/index.html +65 -0
  25. package/auto-docs/scripts/linenumber.js +25 -0
  26. package/auto-docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  27. package/auto-docs/scripts/prettify/lang-css.js +2 -0
  28. package/auto-docs/scripts/prettify/prettify.js +28 -0
  29. package/auto-docs/styles/jsdoc-default.css +358 -0
  30. package/auto-docs/styles/prettify-jsdoc.css +111 -0
  31. package/auto-docs/styles/prettify-tomorrow.css +132 -0
  32. package/dist/animation/Animation.d.ts +36 -0
  33. package/dist/animation/Animation.d.ts.map +1 -0
  34. package/dist/animation/Animation.js +230 -0
  35. package/dist/animation/Animation.js.map +1 -0
  36. package/dist/animation/animation.d.ts +36 -0
  37. package/dist/animation/animation.d.ts.map +1 -0
  38. package/dist/animation/animation.js +230 -0
  39. package/dist/animation/animation.js.map +1 -0
  40. package/dist/animation/public.d.ts +55 -0
  41. package/dist/animation/public.d.ts.map +1 -0
  42. package/dist/animation/public.js +104 -0
  43. package/dist/animation/public.js.map +1 -0
  44. package/dist/chnobli.d.ts +15 -0
  45. package/dist/chnobli.d.ts.map +1 -0
  46. package/dist/chnobli.js +63 -0
  47. package/dist/chnobli.js.map +1 -0
  48. package/dist/property/BasicProperty.d.ts +38 -0
  49. package/dist/property/BasicProperty.d.ts.map +1 -0
  50. package/dist/property/BasicProperty.js +72 -0
  51. package/dist/property/BasicProperty.js.map +1 -0
  52. package/dist/property/ClassProperty.d.ts +32 -0
  53. package/dist/property/ClassProperty.d.ts.map +1 -0
  54. package/dist/property/ClassProperty.js +108 -0
  55. package/dist/property/ClassProperty.js.map +1 -0
  56. package/dist/property/Property.d.ts +13 -0
  57. package/dist/property/Property.d.ts.map +1 -0
  58. package/dist/property/Property.js +20 -0
  59. package/dist/property/Property.js.map +1 -0
  60. package/dist/property/StyleProperty.d.ts +25 -0
  61. package/dist/property/StyleProperty.d.ts.map +1 -0
  62. package/dist/property/StyleProperty.js +221 -0
  63. package/dist/property/StyleProperty.js.map +1 -0
  64. package/dist/property/TransformProperty.d.ts +15 -0
  65. package/dist/property/TransformProperty.d.ts.map +1 -0
  66. package/dist/property/TransformProperty.js +43 -0
  67. package/dist/property/TransformProperty.js.map +1 -0
  68. package/dist/property/TransformXYProperty.d.ts +28 -0
  69. package/dist/property/TransformXYProperty.d.ts.map +1 -0
  70. package/dist/property/TransformXYProperty.js +65 -0
  71. package/dist/property/TransformXYProperty.js.map +1 -0
  72. package/dist/responsive/ResponsiveEvent.d.ts +17 -0
  73. package/dist/responsive/ResponsiveEvent.d.ts.map +1 -0
  74. package/dist/responsive/ResponsiveEvent.js +45 -0
  75. package/dist/responsive/ResponsiveEvent.js.map +1 -0
  76. package/dist/responsive/TestEvent.d.ts +11 -0
  77. package/dist/responsive/TestEvent.d.ts.map +1 -0
  78. package/dist/responsive/TestEvent.js +26 -0
  79. package/dist/responsive/TestEvent.js.map +1 -0
  80. package/dist/responsive/event.d.ts +10 -0
  81. package/dist/responsive/event.d.ts.map +1 -0
  82. package/dist/responsive/event.js +39 -0
  83. package/dist/responsive/event.js.map +1 -0
  84. package/dist/scroll/Scroll.d.ts +27 -0
  85. package/dist/scroll/Scroll.d.ts.map +1 -0
  86. package/dist/scroll/Scroll.js +132 -0
  87. package/dist/scroll/Scroll.js.map +1 -0
  88. package/dist/scroll/ScrollEvent.d.ts +17 -0
  89. package/dist/scroll/ScrollEvent.d.ts.map +1 -0
  90. package/dist/scroll/ScrollEvent.js +39 -0
  91. package/dist/scroll/ScrollEvent.js.map +1 -0
  92. package/dist/scroll/public.d.ts +7 -0
  93. package/dist/scroll/public.d.ts.map +1 -0
  94. package/dist/scroll/public.js +17 -0
  95. package/dist/scroll/public.js.map +1 -0
  96. package/dist/stagger/stagger.d.ts +13 -0
  97. package/dist/stagger/stagger.d.ts.map +1 -0
  98. package/dist/stagger/stagger.js +35 -0
  99. package/dist/stagger/stagger.js.map +1 -0
  100. package/dist/target/BaseTarget.old.d.ts +33 -0
  101. package/dist/target/BaseTarget.old.d.ts.map +1 -0
  102. package/dist/target/BaseTarget.old.js +73 -0
  103. package/dist/target/BaseTarget.old.js.map +1 -0
  104. package/dist/target/DomTarget.d.ts +41 -0
  105. package/dist/target/DomTarget.d.ts.map +1 -0
  106. package/dist/target/DomTarget.js +230 -0
  107. package/dist/target/DomTarget.js.map +1 -0
  108. package/dist/target/Target.d.ts +22 -0
  109. package/dist/target/Target.d.ts.map +1 -0
  110. package/dist/target/Target.js +21 -0
  111. package/dist/target/Target.js.map +1 -0
  112. package/dist/target/TestDomNode.d.ts +14 -0
  113. package/dist/target/TestDomNode.d.ts.map +1 -0
  114. package/dist/target/TestDomNode.js +55 -0
  115. package/dist/target/TestDomNode.js.map +1 -0
  116. package/dist/timeline/Nested.d.ts +30 -0
  117. package/dist/timeline/Nested.d.ts.map +1 -0
  118. package/dist/timeline/Nested.js +51 -0
  119. package/dist/timeline/Nested.js.map +1 -0
  120. package/dist/timeline/TimeLine.d.ts +32 -0
  121. package/dist/timeline/TimeLine.d.ts.map +1 -0
  122. package/dist/timeline/TimeLine.js +288 -0
  123. package/dist/timeline/TimeLine.js.map +1 -0
  124. package/dist/timeline/public.d.ts +120 -0
  125. package/dist/timeline/public.d.ts.map +1 -0
  126. package/dist/timeline/public.js +301 -0
  127. package/dist/timeline/public.js.map +1 -0
  128. package/dist/timing/AnimationFrameTicker.d.ts +32 -0
  129. package/dist/timing/AnimationFrameTicker.d.ts.map +1 -0
  130. package/dist/timing/AnimationFrameTicker.js +134 -0
  131. package/dist/timing/AnimationFrameTicker.js.map +1 -0
  132. package/dist/timing/Ease.d.ts +6 -0
  133. package/dist/timing/Ease.d.ts.map +1 -0
  134. package/dist/timing/Ease.js +15 -0
  135. package/dist/timing/Ease.js.map +1 -0
  136. package/dist/timing/TestTicker.d.ts +19 -0
  137. package/dist/timing/TestTicker.d.ts.map +1 -0
  138. package/dist/timing/TestTicker.js +81 -0
  139. package/dist/timing/TestTicker.js.map +1 -0
  140. package/dist/timing/Ticker.d.ts +14 -0
  141. package/dist/timing/Ticker.d.ts.map +1 -0
  142. package/dist/timing/Ticker.js +2 -0
  143. package/dist/timing/Ticker.js.map +1 -0
  144. package/dist/timing/Timing.d.ts +62 -0
  145. package/dist/timing/Timing.d.ts.map +1 -0
  146. package/dist/timing/Timing.js +257 -0
  147. package/dist/timing/Timing.js.map +1 -0
  148. package/dist/timing/easing.d.ts +158 -0
  149. package/dist/timing/easing.d.ts.map +1 -0
  150. package/dist/timing/easing.js +273 -0
  151. package/dist/timing/easing.js.map +1 -0
  152. package/dist/utils/Events.d.ts +9 -0
  153. package/dist/utils/Events.d.ts.map +1 -0
  154. package/dist/utils/Events.js +35 -0
  155. package/dist/utils/Events.js.map +1 -0
  156. package/dist/utils/internal.d.ts +2 -0
  157. package/dist/utils/internal.d.ts.map +1 -0
  158. package/dist/utils/internal.js +6 -0
  159. package/dist/utils/internal.js.map +1 -0
  160. package/dist/utils/motionpath.d.ts +16 -0
  161. package/dist/utils/motionpath.d.ts.map +1 -0
  162. package/dist/utils/motionpath.js +41 -0
  163. package/dist/utils/motionpath.js.map +1 -0
  164. package/dist/utils/utils.d.ts +43 -0
  165. package/dist/utils/utils.d.ts.map +1 -0
  166. package/dist/utils/utils.js +93 -0
  167. package/dist/utils/utils.js.map +1 -0
  168. package/dist/values/ColorValue.d.ts +12 -0
  169. package/dist/values/ColorValue.d.ts.map +1 -0
  170. package/dist/values/ColorValue.js +133 -0
  171. package/dist/values/ColorValue.js.map +1 -0
  172. package/dist/values/StyleValue.d.ts +40 -0
  173. package/dist/values/StyleValue.d.ts.map +1 -0
  174. package/dist/values/StyleValue.js +149 -0
  175. package/dist/values/StyleValue.js.map +1 -0
  176. package/dist/values/Value.d.ts +13 -0
  177. package/dist/values/Value.d.ts.map +1 -0
  178. package/dist/values/Value.js +38 -0
  179. package/dist/values/Value.js.map +1 -0
  180. package/dist/values/defaultcolors.d.ts +2 -0
  181. package/dist/values/defaultcolors.d.ts.map +1 -0
  182. package/dist/values/defaultcolors.js +149 -0
  183. package/dist/values/defaultcolors.js.map +1 -0
  184. package/package.json +11 -7
  185. package/src/animation/{animation.js → Animation.ts} +56 -54
  186. package/src/animation/{public.js → public.ts} +23 -18
  187. package/src/{chnobli.js → chnobli.ts} +11 -12
  188. package/src/property/BasicProperty.ts +91 -0
  189. package/src/property/ClassProperty.ts +132 -0
  190. package/src/property/Property.ts +33 -0
  191. package/src/property/StyleProperty.ts +273 -0
  192. package/src/property/TransformProperty.ts +56 -0
  193. package/src/property/TransformXYProperty.ts +88 -0
  194. package/src/responsive/ResponsiveEvent.ts +60 -0
  195. package/src/responsive/{testevent.js → TestEvent.ts} +12 -10
  196. package/src/scroll/{scroll.js → Scroll.ts} +53 -35
  197. package/src/scroll/ScrollEvent.ts +53 -0
  198. package/src/scroll/public.ts +20 -0
  199. package/src/stagger/stagger.ts +45 -0
  200. package/src/target/{basetarget.js → BaseTarget.old.ts} +25 -26
  201. package/src/target/DomTarget.ts +281 -0
  202. package/src/target/Target.ts +48 -0
  203. package/src/target/{testdomnode.js → TestDomNode.ts} +18 -15
  204. package/src/tests/{properties.test.js → properties.test.ts} +54 -49
  205. package/src/tests/timeline.test.ts +290 -0
  206. package/src/tests/{timing.test.js → timing.test.ts} +25 -22
  207. package/src/tests/{usecases.test.js → usecases.test.ts} +13 -10
  208. package/src/tests/{values.test.js → values.test.ts} +21 -21
  209. package/src/timeline/Nested.ts +67 -0
  210. package/src/timeline/{timeline.js → TimeLine.ts} +126 -56
  211. package/src/timeline/{public.js → public.ts} +112 -73
  212. package/src/timing/{ticker.js → AnimationFrameTicker.ts} +36 -21
  213. package/src/timing/{ease.js → Ease.ts} +6 -5
  214. package/src/timing/{testticker.js → TestTicker.ts} +27 -24
  215. package/src/timing/Ticker.ts +11 -0
  216. package/src/timing/{timing.js → Timing.ts} +72 -63
  217. package/src/timing/{easing.js → easing.ts} +52 -43
  218. package/src/utils/{events.js → Events.ts} +12 -11
  219. package/src/utils/internal.ts +10 -0
  220. package/src/utils/{motionpath.js → motionpath.ts} +36 -13
  221. package/src/utils/utils.ts +110 -0
  222. package/src/values/{colorvalue.js → ColorValue.ts} +46 -47
  223. package/src/values/StyleValue.ts +186 -0
  224. package/src/values/{value.js → Value.ts} +14 -12
  225. package/src/values/{defaultcolors.js → defaultcolors.ts} +2 -2
  226. package/tsconfig.build.json +19 -0
  227. package/tsconfig.json +17 -108
  228. package/src/animation/property.js +0 -556
  229. package/src/responsive/event.js +0 -46
  230. package/src/scroll/event.js +0 -41
  231. package/src/scroll/public.js +0 -17
  232. package/src/stagger/stagger.js +0 -42
  233. package/src/target/domtarget.js +0 -266
  234. package/src/target/target.js +0 -22
  235. package/src/tests/timeline.test.js +0 -234
  236. package/src/utils/internal.js +0 -7
  237. package/src/utils/utils.js +0 -75
  238. package/src/values/stylevalue.js +0 -148
@@ -1,16 +1,34 @@
1
- import { takeProp } from '../utils/internal.js';
2
- import Timeline from './timeline.js';
3
- import { STATE_ENDED } from '../timing/timing.js';
4
- import { callStagger } from '../stagger/stagger.js';
5
- import Events from '../utils/events.js';
6
- import ResponsiveEvent from '../responsive/event.js';
1
+ import { takeProp } from '../utils/internal';
2
+ import Timeline from './TimeLine';
3
+ import { STATE_ENDED } from '../timing/Timing';
4
+ import { callStagger } from '../stagger/stagger';
5
+ import Events from '../utils/Events';
6
+ import ResponsiveEvent from '../responsive/ResponsiveEvent';
7
+ import NestedTimeline from './Nested';
7
8
 
8
9
  const STATE_PAUSED = 0;
9
10
  const STATE_RENDER_ONCE = 1;
10
11
  const STATE_PLAYING = 2;
11
12
 
13
+ export type Responsive = {
14
+ responsive: () => void;
15
+ };
16
+
12
17
  export default class PublicTimeline {
13
- constructor(props = {}) {
18
+ _defaults: Record<string, any>;
19
+ private _responsive: boolean;
20
+
21
+ _inner: Timeline;
22
+
23
+ private _events: Events;
24
+
25
+ private _state: number;
26
+ private _renderedOnce: boolean;
27
+ private _runningTicker: any;
28
+ private _responsiveBlocks: { responsive: () => void }[];
29
+ private _responsiveEvent: any;
30
+
31
+ constructor(props: Record<string, any> = {}) {
14
32
  this._defaults = takeProp(props, 'defaults', {});
15
33
  this._responsive = takeProp(props, 'responsive', true);
16
34
 
@@ -22,15 +40,15 @@ export default class PublicTimeline {
22
40
  this._inner = new Timeline(props);
23
41
 
24
42
  // 'start', 'end'
25
- this._events = new Events;
43
+ this._events = new Events();
26
44
 
27
45
  this._state = STATE_PAUSED;
28
46
  this._renderedOnce = false;
29
47
  this._runningTicker = null;
30
48
  this._responsiveBlocks = [];
31
49
  if (this._responsive) {
32
- this._responsiveEvent = ResponsiveEvent.global()?.add((...args) => {
33
- this._onResponsive(...args);
50
+ this._responsiveEvent = ResponsiveEvent.global()?.add((a, b) => {
51
+ this._onResponsive(a, b);
34
52
  });
35
53
 
36
54
  // setup callback so we can notify our listeners
@@ -48,39 +66,18 @@ export default class PublicTimeline {
48
66
  * Set's properties
49
67
  * offset can be staggered, a number, a label or a string `+=10`
50
68
  */
51
- set(targets, props, offset = null) {
69
+ set(targets: any, props: Record<string, any>, offset = null) {
52
70
  // for the moment let's just add as usual but set the duration to 0
53
71
  return this.add(targets, { ...props, duration: 0 }, offset);
54
72
  }
55
73
 
56
74
  /**
57
75
  * Add an animation to the timeline
58
- *
76
+ *
59
77
  * offset can be staggered, a number, a label or a string `+=10`
60
78
  */
61
- add(targets, props, offset = null) {
62
- if (Array.from(targets).length === 0)
63
- targets = [targets];
64
- else
65
- targets = Array.from(targets);
66
-
67
- let i = -1;
68
- for (const target of targets) {
69
- i++;
70
-
71
- const nProps = {
72
- ...this._defaults,
73
- ...props
74
- };
75
-
76
- for (const prop in nProps) {
77
- nProps[prop] = callStagger(nProps[prop], i, targets.length);
78
- }
79
-
80
- const nOffset = callStagger(offset, i);
81
-
82
- this._inner.add(target, nProps, nOffset, i);
83
- }
79
+ add(targets: any, props: Record<string, any>, offset = null) {
80
+ timelineAdd(this, targets, props, offset);
84
81
 
85
82
  return this;
86
83
  }
@@ -90,17 +87,33 @@ export default class PublicTimeline {
90
87
  *
91
88
  * This label can then be used in offsets
92
89
  */
93
- label(label, offset = null) {
90
+ label(label: string, offset: any = null) {
94
91
  this._inner.label(label, offset);
95
92
 
96
93
  return this;
97
94
  }
98
95
 
96
+ /**
97
+ * Allows to nest timelines
98
+ *
99
+ * fn: (timeline)
100
+ */
101
+ // todo probably tl should be an interface
102
+ nest(fn: (tl: NestedTimeline) => void, opts = {}, offset: any = null) {
103
+ const tl = new NestedTimeline(opts);
104
+
105
+ fn(tl);
106
+
107
+ this._inner.addTimeline(tl._inner, offset);
108
+
109
+ return this;
110
+ }
111
+
99
112
  /**
100
113
  * Adds a responsive function call which get's called before the responsive
101
114
  * functions in properties
102
115
  */
103
- addResponsive(responsive) {
116
+ addResponsive(responsive: Responsive | Responsive[]) {
104
117
  if (!this._responsiveEvent)
105
118
  throw new Error('this timeline is not responsive');
106
119
 
@@ -121,8 +134,7 @@ export default class PublicTimeline {
121
134
  * Starts to play the timeline if it hasn't started
122
135
  */
123
136
  play() {
124
- if (this._state === STATE_PLAYING)
125
- return;
137
+ if (this._state === STATE_PLAYING) return this;
126
138
 
127
139
  this._state = STATE_PLAYING;
128
140
 
@@ -135,8 +147,7 @@ export default class PublicTimeline {
135
147
  * Pause the timeline at the current position
136
148
  */
137
149
  pause() {
138
- if (this._state === STATE_PAUSED)
139
- return;
150
+ if (this._state === STATE_PAUSED) return;
140
151
 
141
152
  this._state = STATE_PAUSED;
142
153
 
@@ -146,29 +157,27 @@ export default class PublicTimeline {
146
157
  /**
147
158
  * Seeks to a position in the timeline
148
159
  */
149
- seekMs(ms) {
160
+ seekMs(ms: number) {
150
161
  this._inner.init();
151
162
 
152
163
  this._inner.seekMs(ms);
153
164
 
154
- if (this._state !== STATE_PLAYING)
155
- this._state = STATE_RENDER_ONCE;
165
+ if (this._state !== STATE_PLAYING) this._state = STATE_RENDER_ONCE;
156
166
 
157
167
  this._startTicker();
158
168
  }
159
169
 
160
170
  /**
161
171
  * Seeks to a normalized position in the timeline
162
- *
172
+ *
163
173
  * @param pos = number between 0 and 1
164
174
  */
165
- seek(pos) {
175
+ seek(pos: number) {
166
176
  this._inner.init();
167
177
 
168
178
  this._inner.seek(pos);
169
179
 
170
- if (this._state !== STATE_PLAYING)
171
- this._state = STATE_RENDER_ONCE;
180
+ if (this._state !== STATE_PLAYING) this._state = STATE_RENDER_ONCE;
172
181
 
173
182
  this._startTicker();
174
183
  }
@@ -189,7 +198,7 @@ export default class PublicTimeline {
189
198
  */
190
199
  resetProps() {
191
200
  const reversed = this._inner.timing.reverse;
192
- this._inner.timing.reverse = false;
201
+ this._inner.timing.reversed = false;
193
202
  this._inner.seek(-1);
194
203
  this._inner.render();
195
204
  this._inner.ticker.applyTargets();
@@ -215,9 +224,8 @@ export default class PublicTimeline {
215
224
  /**
216
225
  * Set's the timeline to a specific direction
217
226
  */
218
- setReversed(reversed) {
219
- if (this.isReversed() == reversed)
220
- return;
227
+ setReversed(reversed: boolean) {
228
+ if (this.isReversed() == reversed) return;
221
229
  this.reverse();
222
230
  }
223
231
 
@@ -230,22 +238,22 @@ export default class PublicTimeline {
230
238
 
231
239
  /**
232
240
  * Listen on events
233
- *
241
+ *
234
242
  * returns a function to remove the event listener
235
- *
243
+ *
236
244
  * ## Events
237
- *
245
+ *
238
246
  * ### end
239
247
  * Get's executed once the timeline comes to the end
240
248
  * Does not get executed during seeking
241
- *
249
+ *
242
250
  */
243
- on(event, fn) {
251
+ on(event: string, fn: (...args: any[]) => void) {
244
252
  return this._events.add(event, fn);
245
253
  }
246
254
 
247
- // not wroking
248
- onPromise(event) {
255
+ // not working
256
+ onPromise(event: string) {
249
257
  return this._events.wait(event);
250
258
  }
251
259
 
@@ -258,12 +266,12 @@ export default class PublicTimeline {
258
266
  this._events.destroy();
259
267
  this._responsiveEvent?.remove();
260
268
  this._responsiveBlocks = [];
269
+ // @ts-ignore
261
270
  this._inner = null;
262
271
  }
263
272
 
264
273
  _startTicker() {
265
- if (this._runningTicker)
266
- return;
274
+ if (this._runningTicker) return;
267
275
 
268
276
  this._inner.init();
269
277
 
@@ -274,12 +282,11 @@ export default class PublicTimeline {
274
282
  this._inner.render();
275
283
  }
276
284
 
277
- if (this._state === STATE_PLAYING)
278
- this._events.trigger('end');
285
+ if (this._state === STATE_PLAYING) this._events.trigger('end');
279
286
 
280
287
  this._state = STATE_PAUSED;
281
288
  this._stopTicker();
282
- return
289
+ return;
283
290
  }
284
291
 
285
292
  // if (this._inner.timing.state <= STATE_START) {
@@ -292,20 +299,18 @@ export default class PublicTimeline {
292
299
  // return;
293
300
  // }
294
301
 
295
- if (this._state === STATE_PLAYING)
296
- this._inner.advance(change);
302
+ if (this._state === STATE_PLAYING) this._inner.advance(change);
297
303
 
298
304
  // todo when we add smooth seeks we need to update this
299
305
 
300
306
  this._inner.render();
301
307
 
302
308
  if (this._inner.timing.state >= STATE_ENDED) {
303
- if (this._state === STATE_PLAYING)
304
- this._events.trigger('end');
309
+ if (this._state === STATE_PLAYING) this._events.trigger('end');
305
310
 
306
311
  this._state = STATE_PAUSED;
307
312
  this._stopTicker();
308
- return
313
+ return;
309
314
  }
310
315
 
311
316
  // we rendered once let's stop
@@ -317,17 +322,51 @@ export default class PublicTimeline {
317
322
  }
318
323
 
319
324
  _stopTicker() {
320
- if (!this._runningTicker)
321
- return;
325
+ if (!this._runningTicker) return;
322
326
 
323
327
  this._runningTicker.remove();
324
328
  this._runningTicker = null;
325
329
  }
326
330
 
327
- _onResponsive(_obj) {
331
+ _onResponsive(
332
+ a: { width: number; height: number },
333
+ b: { remove: () => void },
334
+ ) {
328
335
  // // make sure we don't render something if we never did
329
336
  // if (!this._renderedOnce)
330
337
  // return;
331
338
  this._inner.update();
332
339
  }
333
- }
340
+ }
341
+
342
+ /**
343
+ * Add an animation to the timeline
344
+ * tl needs to have _defaults, and _inner
345
+ */
346
+ export function timelineAdd(
347
+ tl: PublicTimeline | NestedTimeline,
348
+ targets: any,
349
+ props: Record<string, any>,
350
+ offset: any = null,
351
+ ) {
352
+ if (Array.from(targets).length === 0) targets = [targets];
353
+ else targets = Array.from(targets);
354
+
355
+ let i = -1;
356
+ for (const target of targets) {
357
+ i++;
358
+
359
+ const nProps = {
360
+ ...tl._defaults,
361
+ ...props,
362
+ };
363
+
364
+ for (const prop in nProps) {
365
+ nProps[prop] = callStagger(nProps[prop], i, targets.length);
366
+ }
367
+
368
+ const nOffset = callStagger(offset, i);
369
+
370
+ tl._inner.add(target, nProps, nOffset, i);
371
+ }
372
+ }
@@ -1,15 +1,23 @@
1
- import { newTarget } from '../target/target.js';
1
+ import { newTarget } from '../target/Target';
2
+ import Ticker, { Callback } from './Ticker';
2
3
 
3
4
  /**
4
5
  * The ticker is the main driver for all animations
5
- *
6
+ *
6
7
  * it also manages all targets allowing to only call the dom api
7
8
  * at the end of every frame
8
9
  */
9
- export default class Ticker {
10
+ export default class AnimationFrameTicker implements Ticker {
11
+ private _listeners: Set<Callback>;
12
+ private _targets: GlobalTargets;
13
+
14
+ running: boolean;
15
+
16
+ private _previousTick: number | null;
17
+
10
18
  constructor() {
11
- this._listeners = new Set;
12
- this._targets = new GlobalTargets;
19
+ this._listeners = new Set();
20
+ this._targets = new GlobalTargets();
13
21
 
14
22
  this.running = false;
15
23
 
@@ -18,22 +26,27 @@ export default class Ticker {
18
26
 
19
27
  static global() {
20
28
  // allow to define a test ticker
29
+ // @ts-ignore
21
30
  if (typeof globalThis !== 'undefined' && globalThis.chnobliTicker)
31
+ // @ts-ignore
22
32
  return globalThis.chnobliTicker;
23
33
 
24
34
  if (typeof window === 'undefined')
25
35
  throw new Error('can only be executed in a browser context');
26
36
 
37
+ // @ts-ignore
27
38
  if (typeof window.chnobliTicker === 'undefined')
28
- window.chnobliTicker = new Ticker;
39
+ // @ts-ignore
40
+ window.chnobliTicker = new Ticker();
41
+ // @ts-ignore
29
42
  return window.chnobliTicker;
30
43
  }
31
44
 
32
- registerTarget(target) {
45
+ registerTarget(target: any) {
33
46
  return this._targets.register(target);
34
47
  }
35
48
 
36
- unregisterTarget(target) {
49
+ unregisterTarget(target: any) {
37
50
  return this._targets.unregister(target);
38
51
  }
39
52
 
@@ -41,7 +54,7 @@ export default class Ticker {
41
54
  return this._targets.apply();
42
55
  }
43
56
 
44
- add(fn) {
57
+ add(fn: Callback): { remove: () => void } {
45
58
  this._listeners.add(fn);
46
59
 
47
60
  if (!this.running) {
@@ -52,23 +65,22 @@ export default class Ticker {
52
65
  return {
53
66
  remove: () => {
54
67
  this.remove(fn);
55
- }
68
+ },
56
69
  };
57
70
  }
58
71
 
59
- remove(fn) {
72
+ remove(fn: Callback) {
60
73
  this._listeners.delete(fn);
61
74
  }
62
75
 
63
- _tick(elapsed) {
76
+ _tick(elapsed: number) {
64
77
  if (this._listeners.size === 0) {
65
78
  this.running = false;
66
79
  this._previousTick = null;
67
80
  return;
68
81
  }
69
82
 
70
- if (this._previousTick === null)
71
- this._previousTick = elapsed;
83
+ if (this._previousTick === null) this._previousTick = elapsed;
72
84
 
73
85
  let change = elapsed - this._previousTick;
74
86
  // lagSmoothing
@@ -83,7 +95,7 @@ export default class Ticker {
83
95
  for (const fn of this._listeners) {
84
96
  fn(change, {
85
97
  // changes,
86
- remove: () => this.remove(fn)
98
+ remove: () => this.remove(fn),
87
99
  });
88
100
  }
89
101
 
@@ -112,17 +124,19 @@ export default class Ticker {
112
124
  // }
113
125
 
114
126
  export class GlobalTargets {
127
+ private _targets: Map<any, { target: any; ref: number }>;
128
+
115
129
  constructor() {
116
130
  // {target, ref}
117
- this._targets = new Map;
131
+ this._targets = new Map();
118
132
  }
119
133
 
120
- register(target) {
134
+ register(target: any) {
121
135
  let storedTarget = this._targets.get(target);
122
136
  if (!storedTarget) {
123
137
  storedTarget = {
124
138
  target: newTarget(target),
125
- ref: 0
139
+ ref: 0,
126
140
  };
127
141
  this._targets.set(target, storedTarget);
128
142
  }
@@ -131,8 +145,10 @@ export class GlobalTargets {
131
145
  return storedTarget.target;
132
146
  }
133
147
 
134
- unregister(target) {
148
+ unregister(target: any) {
135
149
  const storedTarget = this._targets.get(target);
150
+ if (!storedTarget) return;
151
+
136
152
  storedTarget.ref -= 1;
137
153
  }
138
154
 
@@ -141,8 +157,7 @@ export class GlobalTargets {
141
157
  const { target, ref } = storedTarget;
142
158
  target.apply();
143
159
 
144
- if (ref <= 0)
145
- this._targets.delete(target.target);
160
+ if (ref <= 0) this._targets.delete(target.target);
146
161
  }
147
162
  }
148
163
 
@@ -1,5 +1,7 @@
1
1
  export default class Ease {
2
- constructor(prop) {
2
+ fn: ((t: number) => number) | null;
3
+
4
+ constructor(prop: any) {
3
5
  // parse prop
4
6
  if (prop !== null && typeof prop !== 'function')
5
7
  throw new Error('ease needs to be a function');
@@ -7,10 +9,9 @@ export default class Ease {
7
9
  this.fn = prop;
8
10
  }
9
11
 
10
- apply(t) {
11
- if (this.fn === null)
12
- return t;
12
+ apply(t: number) {
13
+ if (this.fn === null) return t;
13
14
 
14
15
  return this.fn(t);
15
16
  }
16
- }
17
+ }
@@ -1,22 +1,31 @@
1
- import { GlobalTargets } from './ticker.js';
1
+ import { GlobalTargets } from './AnimationFrameTicker';
2
+ import Ticker, { Callback } from './Ticker';
3
+
4
+ export default class TestTicker implements Ticker {
5
+ private _listeners: Set<Callback>;
6
+ targets: GlobalTargets;
7
+
8
+ running: boolean;
9
+
10
+ private _previousTick: number | null;
2
11
 
3
- export default class TestTicker {
4
12
  constructor() {
5
- this._listeners = new Set;
6
- this.targets = new GlobalTargets;
13
+ this._listeners = new Set();
14
+ this.targets = new GlobalTargets();
7
15
 
8
16
  this.running = false;
9
17
 
10
18
  this._previousTick = null;
11
19
 
20
+ // @ts-ignore
12
21
  globalThis.chnobliTicker = this;
13
22
  }
14
23
 
15
- registerTarget(target) {
24
+ registerTarget(target: any) {
16
25
  return this.targets.register(target);
17
26
  }
18
27
 
19
- unregisterTarget(target) {
28
+ unregisterTarget(target: any) {
20
29
  return this.targets.unregister(target);
21
30
  }
22
31
 
@@ -24,20 +33,19 @@ export default class TestTicker {
24
33
  return this.targets.apply();
25
34
  }
26
35
 
27
- add(fn) {
36
+ add(fn: Callback) {
28
37
  this._listeners.add(fn);
29
38
 
30
- if (!this.running)
31
- this.running = true;
39
+ if (!this.running) this.running = true;
32
40
 
33
41
  return {
34
42
  remove: () => {
35
43
  this.remove(fn);
36
- }
44
+ },
37
45
  };
38
46
  }
39
47
 
40
- remove(fn) {
48
+ remove(fn: Callback) {
41
49
  this._listeners.delete(fn);
42
50
  }
43
51
 
@@ -45,30 +53,25 @@ export default class TestTicker {
45
53
  ///
46
54
  /// runs until the ticker ends this allows to run
47
55
  run(max = 3000, step = 1) {
48
- if (!this.running)
49
- return true;
56
+ if (!this.running) return true;
50
57
 
51
- if (this._previousTick === null)
52
- this.tick(0);
58
+ if (this._previousTick === null) this.tick(0);
53
59
 
54
60
  let i = 0;
55
61
  const start = this._previousTick ?? 0;
56
62
 
57
63
  for (i = 1; i <= max; i += step) {
58
- if (!this.tick(start + i))
59
- return true;
64
+ if (!this.tick(start + i)) return true;
60
65
  }
61
66
 
62
67
  return false;
63
68
  }
64
69
 
65
70
  // elapsed in ms
66
- tick(elapsed) {
67
- if (!this.running)
68
- return false;
71
+ tick(elapsed: number) {
72
+ if (!this.running) return false;
69
73
 
70
- if (this._previousTick === null)
71
- this._previousTick = elapsed;
74
+ if (this._previousTick === null) this._previousTick = elapsed;
72
75
 
73
76
  let change = elapsed - this._previousTick;
74
77
  // lagSmoothing
@@ -81,7 +84,7 @@ export default class TestTicker {
81
84
  for (const fn of this._listeners) {
82
85
  fn(change, {
83
86
  // changes,
84
- remove: () => this.remove(fn)
87
+ remove: () => this.remove(fn),
85
88
  });
86
89
  }
87
90
 
@@ -95,4 +98,4 @@ export default class TestTicker {
95
98
 
96
99
  return true;
97
100
  }
98
- }
101
+ }
@@ -0,0 +1,11 @@
1
+ import { Target } from '../target/Target';
2
+
3
+ export type Callback = (change: number, api: { remove: () => void }) => void;
4
+
5
+ export default interface Ticker {
6
+ registerTarget(target: any): Target;
7
+ unregisterTarget(target: any): void;
8
+ applyTargets(): void;
9
+ add(fn: Callback): { remove: () => void };
10
+ remove(fn: Callback): void;
11
+ }