chnobli 0.1.5 → 0.1.7

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