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,27 +1,28 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import TestTicker from '../timing/testticker.js';
3
- import TestResponsiveEvent from '../responsive/testevent.js';
4
- import { animate, timeline } from '../chnobli.js';
5
- import { responsive } from '../utils/utils.js';
6
- import { el } from '../target/testdomnode.js';
2
+ import TestTicker from '../timing/TestTicker';
3
+ import TestResponsiveEvent from '../responsive/TestEvent';
4
+ import { animate, timeline } from '../chnobli';
5
+ import { responsive } from '../utils/utils';
6
+ import { el } from '../target/TestDomNode';
7
7
 
8
8
  describe('usecases', () => {
9
9
  it('accordion', () => {
10
- const ticker = new TestTicker;
11
- const respEv = new TestResponsiveEvent;
10
+ const ticker = new TestTicker();
11
+ const respEv = new TestResponsiveEvent();
12
12
 
13
13
  const itm = el();
14
14
  const ctn = el();
15
15
  ctn.computedStyle.maxHeight = 'none';
16
+ // @ts-ignore
16
17
  ctn.scrollHeight = '100px';
17
18
 
18
19
  const tl = timeline()
19
20
  .set(itm, {
20
- cls: 'open'
21
+ cls: 'open',
21
22
  })
22
23
  .add(ctn, {
23
24
  maxHeight: responsive(el => el.scrollHeight),
24
- duration: 100
25
+ duration: 100,
25
26
  });
26
27
 
27
28
  tl.play();
@@ -40,6 +41,7 @@ describe('usecases', () => {
40
41
  expect(itm.classList.contains('open')).toBe(true);
41
42
 
42
43
  // now a resize comes
44
+ // @ts-ignore
43
45
  ctn.scrollHeight = '200px';
44
46
  tl.update();
45
47
  expect(ctn.style.maxHeight).toBe('200.000px');
@@ -52,6 +54,7 @@ describe('usecases', () => {
52
54
  expect(ctn.style.maxHeight).toBe('176.000px');
53
55
  expect(itm.classList.contains('open')).toBe(true);
54
56
 
57
+ // @ts-ignore
55
58
  ctn.scrollHeight = '150px';
56
59
  respEv.resize(1000, 1000);
57
60
  expect(ctn.style.maxHeight).toBe('132.000px');
@@ -61,4 +64,4 @@ describe('usecases', () => {
61
64
  expect(ctn.style.maxHeight).toBe(undefined);
62
65
  expect(itm.classList.contains('open')).toBe(false);
63
66
  });
64
- });
67
+ });
@@ -1,14 +1,12 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import TestTicker from '../timing/testticker.js';
3
- import TestResponsiveEvent from '../responsive/testevent.js';
4
- import { animate, timeline } from '../chnobli.js';
5
- import { responsive, from, fromTo } from '../utils/utils.js';
6
- import { el, getRootElement } from '../target/testdomnode.js';
7
- import { timeout } from 'fire/util.js';
2
+ import TestTicker from '../timing/TestTicker';
3
+ import { animate, timeline } from '../chnobli';
4
+ import { responsive, from, fromTo } from '../utils/utils';
5
+ import { el, getRootElement } from '../target/TestDomNode';
8
6
 
9
7
  describe('values', () => {
10
8
  it('rem unit', () => {
11
- const ticker = new TestTicker;
9
+ const ticker = new TestTicker();
12
10
 
13
11
  const root = getRootElement();
14
12
  root.computedStyle.fontSize = '13px';
@@ -17,11 +15,11 @@ describe('values', () => {
17
15
  const tl = timeline()
18
16
  .add(div, {
19
17
  width: '10rem',
20
- duration: 5
18
+ duration: 5,
21
19
  })
22
20
  .add(div, {
23
21
  width: 20,
24
- duration: 5
22
+ duration: 5,
25
23
  })
26
24
  .play();
27
25
 
@@ -33,7 +31,7 @@ describe('values', () => {
33
31
  });
34
32
 
35
33
  it('percent unit', () => {
36
- const ticker = new TestTicker;
34
+ const ticker = new TestTicker();
37
35
 
38
36
  const div = el();
39
37
  div.computedStyle.width = '10px';
@@ -41,7 +39,7 @@ describe('values', () => {
41
39
  .add(div, {
42
40
  x: '10%',
43
41
  width: '50%',
44
- duration: 10
42
+ duration: 10,
45
43
  })
46
44
  .play();
47
45
 
@@ -50,12 +48,14 @@ describe('values', () => {
50
48
  expect(div.style.width).toBe('100.000%');
51
49
 
52
50
  ticker.run();
53
- expect(div.style.transform).toBe('translate3d(10.000%,0.000px,0.000px)');
51
+ expect(div.style.transform).toBe(
52
+ 'translate3d(10.000%,0.000px,0.000px)',
53
+ );
54
54
  expect(div.style.width).toBe('50.000%');
55
55
  });
56
56
 
57
57
  it('multiple values', () => {
58
- const ticker = new TestTicker;
58
+ const ticker = new TestTicker();
59
59
 
60
60
  const root = getRootElement();
61
61
  root.computedStyle.fontSize = '10px';
@@ -65,7 +65,7 @@ describe('values', () => {
65
65
  const tl = timeline()
66
66
  .add(div, {
67
67
  padding: '10px 20rem',
68
- duration: 10
68
+ duration: 10,
69
69
  })
70
70
  .play();
71
71
 
@@ -77,7 +77,7 @@ describe('values', () => {
77
77
  });
78
78
 
79
79
  it('display', () => {
80
- const ticker = new TestTicker;
80
+ const ticker = new TestTicker();
81
81
 
82
82
  const div = el();
83
83
  div.computedStyle.display = 'block';
@@ -86,7 +86,7 @@ describe('values', () => {
86
86
  display: 'none',
87
87
  position: from('absolute'),
88
88
  visibility: fromTo('hidden', 'visible'),
89
- duration: 10
89
+ duration: 10,
90
90
  })
91
91
  .play();
92
92
 
@@ -108,7 +108,7 @@ describe('values', () => {
108
108
  });
109
109
 
110
110
  it('colors', () => {
111
- const ticker = new TestTicker;
111
+ const ticker = new TestTicker();
112
112
  const div = el();
113
113
  div.computedStyle.color = 'rgb(120, 130, 20)';
114
114
 
@@ -116,7 +116,7 @@ describe('values', () => {
116
116
  .add(div, {
117
117
  color: 'black',
118
118
  backgroundColor: 'hsl(10, 80%, 40%)',
119
- duration: 10
119
+ duration: 10,
120
120
  })
121
121
  .play();
122
122
 
@@ -134,7 +134,7 @@ describe('values', () => {
134
134
  });
135
135
 
136
136
  it('css-vars', () => {
137
- const ticker = new TestTicker;
137
+ const ticker = new TestTicker();
138
138
  const div = el();
139
139
  div.computedStyle['--color'] = 'rgb(120, 130, 20)';
140
140
  div.computedStyle['--border'] = '20px';
@@ -143,7 +143,7 @@ describe('values', () => {
143
143
  .add(div, {
144
144
  '--color': 'black',
145
145
  '--border': '1px 20px',
146
- duration: 10
146
+ duration: 10,
147
147
  })
148
148
  .play();
149
149
 
@@ -159,4 +159,4 @@ describe('values', () => {
159
159
  expect(div.style['--color']).toBe('rgba(0, 0, 0, 1.000)');
160
160
  expect(div.style['--border']).toBe('1.000px 20.000px');
161
161
  });
162
- });
162
+ });
@@ -1,10 +1,12 @@
1
- import { takeProp } from '../utils/internal.js';
2
- import Timeline from './timeline.js';
3
- import { timelineAdd } from './public.js';
4
-
1
+ import { takeProp } from '../utils/internal';
2
+ import Timeline from './TimeLine';
3
+ import { timelineAdd } from './public';
5
4
 
6
5
  export default class NestedTimeline {
7
- constructor(props = {}) {
6
+ _defaults: Record<string, any>;
7
+ _inner: Timeline;
8
+
9
+ constructor(props: Record<string, any> = {}) {
8
10
  this._defaults = takeProp(props, 'defaults', {});
9
11
 
10
12
  if ('duration' in props)
@@ -17,17 +19,17 @@ export default class NestedTimeline {
17
19
  * Set's properties
18
20
  * offset can be staggered, a number, a label or a string `+=10`
19
21
  */
20
- set(targets, props, offset = null) {
22
+ set(targets: any, props: Record<string, any>, offset: any = null) {
21
23
  // for the moment let's just add as usual but set the duration to 0
22
24
  return this.add(targets, { ...props, duration: 0 }, offset);
23
25
  }
24
26
 
25
27
  /**
26
28
  * Add an animation to the timeline
27
- *
29
+ *
28
30
  * offset can be staggered, a number, a label or a string `+=10`
29
31
  */
30
- add(targets, props, offset = null) {
32
+ add(targets: any, props: Record<string, any>, offset: any = null) {
31
33
  timelineAdd(this, targets, props, offset);
32
34
 
33
35
  return this;
@@ -38,7 +40,7 @@ export default class NestedTimeline {
38
40
  *
39
41
  * This label can then be used in offsets
40
42
  */
41
- label(label, offset = null) {
43
+ label(label: string, offset: any = null) {
42
44
  this._inner.label(label, offset);
43
45
 
44
46
  return this;
@@ -46,10 +48,14 @@ export default class NestedTimeline {
46
48
 
47
49
  /**
48
50
  * Allows to nest timelines
49
- *
51
+ *
50
52
  * fn: (timeline)
51
53
  */
52
- nest(fn, opts = {}, offset = null) {
54
+ nest(
55
+ fn: (tl: NestedTimeline) => void,
56
+ opts: Record<string, any> = {},
57
+ offset: any = null,
58
+ ) {
53
59
  const tl = new NestedTimeline(opts);
54
60
 
55
61
  fn(tl);
@@ -58,4 +64,4 @@ export default class NestedTimeline {
58
64
 
59
65
  return this;
60
66
  }
61
- }
67
+ }
@@ -1,18 +1,45 @@
1
- import { takeProp } from '../utils/internal.js';
1
+ import { takeProp } from '../utils/internal';
2
2
  import Timing, {
3
- parseEase, parseRepeat, parseAlternate, parseReversed,
4
- STATE_BEFORE, STATE_ENDED
5
- } from '../timing/timing.js';
6
- import Ticker from '../timing/ticker.js';
7
- import Animation from '../animation/animation.js';
3
+ parseEase,
4
+ parseRepeat,
5
+ parseAlternate,
6
+ parseReversed,
7
+ STATE_BEFORE,
8
+ STATE_ENDED,
9
+ } from '../timing/Timing';
10
+ import Ticker from '../timing/Ticker';
11
+ import Animation from '../animation/Animation';
12
+ import AnimationFrameTicker from '../timing/AnimationFrameTicker';
13
+
14
+ type Entry = {
15
+ type: 'label' | 'animation' | 'timeline';
16
+ value: any;
17
+ offset: Offset;
18
+ relativeOffset: number;
19
+ start?: number;
20
+ end?: number;
21
+ };
8
22
 
9
23
  /**
10
24
  * Timeline is the most versatile class
11
- *
25
+ *
12
26
  * A timeline can contain multiple animation, ordered one after the other or
13
27
  * offset.
14
28
  */
15
29
  export default class Timeline {
30
+ timing: Timing;
31
+ ticker: Ticker;
32
+
33
+ private entries: Entry[];
34
+
35
+ private _beforeResponsiveFn: () => void;
36
+ private _initialized: boolean;
37
+ private _renderQueue: {
38
+ upcoming: Animation[];
39
+ passed: Animation[];
40
+ active: Animation[];
41
+ };
42
+
16
43
  /*
17
44
  {
18
45
  ease,
@@ -20,24 +47,28 @@ export default class Timeline {
20
47
  alternate
21
48
  }
22
49
  */
23
- constructor(props = {}) {
50
+ constructor(props: Record<string, any> = {}) {
24
51
  const nProps = {
25
52
  duration: 1000,
26
53
  ease: parseEase(takeProp(props, 'ease', null)),
27
54
  repeat: parseRepeat(takeProp(props, 'repeat', false)),
28
55
  alternate: parseAlternate(takeProp(props, 'alternate', true)),
29
- reversed: parseReversed(takeProp(props, 'reversed', false))
56
+ reversed: parseReversed(takeProp(props, 'reversed', false)),
30
57
  };
31
58
 
32
59
  this.timing = new Timing(nProps);
33
- this.ticker = Ticker.global();
60
+ this.ticker = AnimationFrameTicker.global();
34
61
 
35
62
  // { type: label|animation, value: {}, offset, start: x, end: y, render }
36
63
  this.entries = [];
37
64
 
38
65
  this._beforeResponsiveFn = () => {};
39
66
  this._initialized = false;
40
- this._renderQueue = null;
67
+ this._renderQueue = {
68
+ upcoming: [],
69
+ passed: [],
70
+ active: [],
71
+ };
41
72
  }
42
73
 
43
74
  isFinite() {
@@ -48,8 +79,13 @@ export default class Timeline {
48
79
 
49
80
  // relative represents the point which the offset should be taken
50
81
  // if relative 1 is done the offset will be taken from the previous - 1
51
- add(targets, props, offset = null, relative = 0) {
52
- const animation = new Animation(targets, this.ticker, props);
82
+ add(
83
+ target: any,
84
+ props: Record<string, any>,
85
+ offset: any = null,
86
+ relative = 0,
87
+ ) {
88
+ const animation = new Animation(target, this.ticker, props);
53
89
 
54
90
  if (!animation.isFinite())
55
91
  throw new Error('the animation needs to be finite');
@@ -58,96 +94,92 @@ export default class Timeline {
58
94
  type: 'animation',
59
95
  value: animation,
60
96
  offset: new Offset(offset),
61
- relativeOffset: relative
97
+ relativeOffset: relative,
62
98
  });
63
99
 
64
100
  return this;
65
101
  }
66
102
 
67
- addTimeline(tl, offset = null) {
68
- if (!tl.isFinite())
69
- throw new Error('the animation needs to be finite');
103
+ addTimeline(tl: Timeline, offset: any = null) {
104
+ if (!tl.isFinite()) throw new Error('the animation needs to be finite');
70
105
 
71
106
  this.entries.push({
72
107
  type: 'timeline',
73
108
  value: tl,
74
109
  offset: new Offset(offset),
75
- relativeOffset: 0
110
+ relativeOffset: 0,
76
111
  });
77
112
  }
78
113
 
79
- label(label, offset = null) {
114
+ label(label: string, offset: any = null) {
80
115
  this.entries.push({
81
116
  type: 'label',
82
117
  value: label,
83
118
  offset: new Offset(offset),
84
- relativeOffset: 0
119
+ relativeOffset: 0,
85
120
  });
86
121
 
87
122
  return this;
88
123
  }
89
124
 
90
125
  // set's a function which get's called before any responsive call
91
- setBeforeResponsiveFn(fn) {
126
+ setBeforeResponsiveFn(fn: () => void) {
92
127
  this._beforeResponsiveFn = fn;
93
128
  }
94
129
 
95
- advance(change) {
130
+ advance(change: number) {
96
131
  this.timing.advance(change);
97
132
 
98
133
  this._updateTimings();
99
134
  }
100
135
 
101
- seekMs(ms) {
136
+ seekMs(ms: number) {
102
137
  this.timing.seekMs(ms);
103
138
 
104
139
  this._updateTimings();
105
140
  }
106
141
 
107
- seek(pos) {
142
+ seek(pos: number) {
108
143
  this.timing.seek(pos);
109
144
 
110
145
  this._updateTimings();
111
146
  }
112
147
 
113
148
  init() {
114
- if (this._initialized)
115
- return;
149
+ if (this._initialized) return;
116
150
  this._initialized = true;
117
151
 
118
152
  let duration = 0;
119
153
 
120
- const labels = {};
154
+ const labels: Record<string, any> = {};
121
155
 
122
156
  let i = -1;
123
157
  for (const entry of this.entries) {
124
158
  i++;
125
159
  let offset = entry.offset;
160
+ const label = offset.label();
126
161
 
127
- if (offset.type === 'label') {
128
- if (!(offset.value in labels))
129
- throw new Error('could not find label ' + offset.value);
162
+ if (label) {
163
+ if (!(label in labels))
164
+ throw new Error('could not find label ' + label);
130
165
 
131
- offset = new Offset(labels[offset.value]);
166
+ offset = new Offset(labels[label]);
132
167
  }
133
168
 
134
169
  const pos = this.entries[i - 1 - entry.relativeOffset]?.end ?? 0;
135
170
 
136
171
  let start = offset.calculate(pos);
137
- if (start < 0)
138
- throw new Error('cannot go in the past start < 0');
172
+ if (start < 0) throw new Error('cannot go in the past start < 0');
139
173
 
140
174
  let end = start;
141
- if (entry.type === 'animation')
142
- end += entry.value.duration;
175
+ if (entry.type === 'animation') end += entry.value.duration;
143
176
 
144
177
  if (entry.type === 'timeline') {
145
178
  entry.value.init();
146
179
  end += entry.value.timing.duration;
147
180
  }
148
181
 
149
- if (entry.type === 'label')
150
- labels[entry.value] = start;
182
+ if (entry.type === 'label') labels[entry.value] = start;
151
183
 
152
184
  entry.start = start;
153
185
  entry.end = end;
@@ -174,12 +206,12 @@ export default class Timeline {
174
206
  const startOrdered = this.entries.filter(e => {
175
207
  return e.type === 'animation' || e.type === 'timeline';
176
208
  });
177
- startOrdered.sort((a, b) => a.start - b.start);
209
+ startOrdered.sort((a, b) => a.start! - b.start!);
178
210
 
179
211
  for (let i = 0; i < startOrdered.length; i++) {
180
212
  const entry = startOrdered[i];
181
213
 
182
- this.timing.seekMs(entry.start);
214
+ this.timing.seekMs(entry.start!);
183
215
 
184
216
  const pos = this.timing.positionMs();
185
217
 
@@ -188,7 +220,7 @@ export default class Timeline {
188
220
  const prevEntry = startOrdered[y];
189
221
  const prevAnimation = prevEntry.value;
190
222
 
191
- prevAnimation.seekMs(pos - prevEntry.start);
223
+ prevAnimation.seekMs(pos - prevEntry.start!);
192
224
  prevAnimation.render();
193
225
  }
194
226
 
@@ -226,7 +258,7 @@ export default class Timeline {
226
258
  this._renderQueue = {
227
259
  upcoming: [],
228
260
  passed: [],
229
- active: []
261
+ active: [],
230
262
  };
231
263
 
232
264
  const pos = this.timing.positionMsUnbounded();
@@ -236,7 +268,7 @@ export default class Timeline {
236
268
  continue;
237
269
 
238
270
  const animation = entry.value;
239
- animation.seekMs(pos - entry.start);
271
+ animation.seekMs(pos - entry.start!);
240
272
 
241
273
  if (animation.timing.state >= STATE_ENDED) {
242
274
  this._renderQueue.passed.push(animation);
@@ -249,8 +281,7 @@ export default class Timeline {
249
281
  }
250
282
 
251
283
  update() {
252
- if (!this._initialized)
253
- return;
284
+ if (!this._initialized) return;
254
285
 
255
286
  const pos = this.timing.savePosition();
256
287
  const reversed = this.timing.reversed;
@@ -278,26 +309,28 @@ export default class Timeline {
278
309
  for (const entry of this.entries) {
279
310
  if (entry.type === 'timeline') {
280
311
  entry.value.destroy();
281
- continue
312
+ continue;
282
313
  }
283
314
 
284
- if (entry.type !== 'animation')
285
- continue;
315
+ if (entry.type !== 'animation') continue;
286
316
 
287
317
  const animation = entry.value;
288
318
  animation.destroy();
289
319
  }
290
320
 
291
321
  this.entries = [];
292
- this._beforeResponsiveFn = null;
322
+ this._beforeResponsiveFn = () => {};
293
323
  this.ticker.applyTargets();
294
324
  }
295
325
  }
296
326
 
297
-
298
327
  class Offset {
299
- constructor(offset = null) {
328
+ type: 'none' | 'absolute' | 'sub' | 'add' | 'label';
329
+ value: number | string | null;
330
+
331
+ constructor(offset: any = null) {
300
332
  this.type = 'none';
333
+ this.value = null;
301
334
 
302
335
  if (typeof offset === 'number') {
303
336
  this.type = 'absolute';
@@ -316,19 +349,26 @@ class Offset {
316
349
  }
317
350
  }
318
351
 
319
- calculate(pos) {
320
- if (this.type === 'none')
321
- return pos;
352
+ label(): string | null {
353
+ if (this.type !== 'label') return null;
322
354
 
323
- if (this.type === 'absolute')
324
- return this.value;
355
+ return this.value as string;
356
+ }
325
357
 
326
- if (this.type === 'sub')
327
- return pos - this.value;
358
+ // this is bullshit
359
+ /* isAbsolute(this: Offset): this is { type: 'absolute'; value: number } {
360
+ return this.type === 'absolute';
361
+ } */
328
362
 
329
- if (this.type === 'add')
330
- return pos + this.value;
363
+ calculate(pos: number): number {
364
+ if (this.type === 'none') return pos;
365
+
366
+ if (this.type === 'absolute') return this.value as number;
367
+
368
+ if (this.type === 'sub') return pos - (this.value as number);
369
+
370
+ if (this.type === 'add') return pos + (this.value as number);
331
371
 
332
372
  throw new Error('cannot calculate for type ' + this.type);
333
373
  }
334
- }
374
+ }