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,18 +1,24 @@
1
- import {
2
- newTiming, STATE_BEFORE, STATE_AFTER
3
- } from '../timing/timing.js';
4
-
5
- import { newProperty } from './property.js';
1
+ import Timing, { newTiming, STATE_BEFORE, STATE_AFTER } from '../timing/Timing';
6
2
 
3
+ import Property, { ParseableValue, newProperty } from '../property/Property';
4
+ import Ticker from '../timing/Ticker';
5
+ import { Target } from '../target/Target';
7
6
 
8
7
  export default class Animation {
9
- // targets;
10
- // #timing;
8
+ timing: Timing;
9
+ target: Target;
10
+ props: Record<string, PropertyAnimation<any>>;
11
+
12
+ private _ticker: Ticker;
13
+
14
+ private _prevTimingState: number;
15
+ private _props: PropertyAnimation<any>[];
16
+ private _initialized: boolean;
11
17
 
12
18
  /*
13
19
  props
14
20
  */
15
- constructor(target, ticker, props = {}) {
21
+ constructor(target: any, ticker: Ticker, props: Record<string, any> = {}) {
16
22
  this.timing = newTiming(props);
17
23
  this._ticker = ticker;
18
24
  this.target = ticker.registerTarget(target);
@@ -21,45 +27,39 @@ export default class Animation {
21
27
  this._props = [];
22
28
  this._initialized = false;
23
29
 
30
+ this.props = {};
31
+
24
32
  for (const prop in props) {
25
- if (prop in this)
26
- throw new Error('prop: ' + prop + ' is not allowed');
27
-
28
- this[prop] = new PropertyAnimation(
29
- prop,
30
- props[prop],
31
- this
32
- );
33
- this._props.push(this[prop]);
33
+ this.props[prop] = new PropertyAnimation(prop, props[prop], this);
34
+ this._props.push(this.props[prop]);
34
35
  }
35
36
  }
36
37
 
37
- advance(change) {
38
+ advance(change: number) {
38
39
  this._prevTimingState = this.timing.state;
39
40
  this.timing.advance(change);
40
41
  }
41
42
 
42
- seekMs(ms) {
43
+ seekMs(ms: number) {
43
44
  this._prevTimingState = this.timing.state;
44
45
  this.timing.seekMs(ms);
45
46
  }
46
47
 
47
- seek(pos) {
48
+ seek(pos: number) {
48
49
  this._prevTimingState = this.timing.state;
49
50
  this.timing.seek(pos);
50
51
  }
51
52
 
52
- isFinite() {
53
+ isFinite(): boolean {
53
54
  return this.timing.isFinite();
54
55
  }
55
56
 
56
- get duration() {
57
+ get duration(): number {
57
58
  return this.timing.duration;
58
59
  }
59
60
 
60
61
  init(reset = false) {
61
- if (this._initialized && !reset)
62
- return;
62
+ if (this._initialized && !reset) return;
63
63
  this._initialized = true;
64
64
 
65
65
  for (const prop of this._props) {
@@ -75,7 +75,7 @@ export default class Animation {
75
75
  prop.restoreBefore(this.target);
76
76
  }
77
77
 
78
- // to render before we need to remove
78
+ // to render before we need to remove
79
79
 
80
80
  return;
81
81
  } else if (this.timing.state === STATE_AFTER) {
@@ -96,18 +96,26 @@ export default class Animation {
96
96
  prop.restoreBefore(this.target);
97
97
  }
98
98
 
99
- this._ticker.unregisterTarget(this.target.target);
99
+ this._ticker.unregisterTarget(this.target.inner());
100
100
  }
101
101
  }
102
102
 
103
- function maybeResponsiveValue(prop, val) {
104
- if (typeof val === 'object' && 'responsive' in val)
105
- return val.responsive;
103
+ function maybeResponsiveValue<V>(prop: Property<V>, val: any): V {
104
+ if (typeof val === 'object' && 'responsive' in val) return val.responsive;
106
105
  return prop.parseValue(val);
107
106
  }
108
107
 
109
- class PropertyAnimation {
110
- constructor(prop, value, animation) {
108
+ class PropertyAnimation<V> {
109
+ prop: Property<V>;
110
+
111
+ private staticValueFn: boolean;
112
+ private valueFn: ((pos: number) => ParseableValue) | null;
113
+
114
+ private iniResponsive: any;
115
+ private iniFrom: V | null;
116
+ private iniTo: V | null;
117
+
118
+ constructor(prop: string, value: any, animation: Animation) {
111
119
  this.prop = newProperty(prop, animation.target.type());
112
120
  // we will get the from the targets
113
121
 
@@ -124,15 +132,14 @@ class PropertyAnimation {
124
132
  if ('to' in value)
125
133
  this.iniTo = maybeResponsiveValue(this.prop, value.to);
126
134
 
127
- if ('responsive' in value)
128
- this.iniResponsive = value.responsive;
135
+ if ('responsive' in value) this.iniResponsive = value.responsive;
129
136
 
130
137
  if (!this.iniFrom && !this.iniTo && !this.iniResponsive)
131
138
  throw new Error('from or to expected');
132
139
  } else if (typeof value === 'function') {
133
140
  if (!this.prop.allowsValueFn()) {
134
141
  throw new Error(
135
- 'prop ' + prop + ' does not allow value functions'
142
+ 'prop ' + prop + ' does not allow value functions',
136
143
  );
137
144
  }
138
145
 
@@ -144,11 +151,10 @@ class PropertyAnimation {
144
151
  }
145
152
 
146
153
  // calculate from and to position
147
- init(target) {
154
+ init(target: Target) {
148
155
  // there is nothing to initialize since on every render we call the
149
156
  // value Fn
150
- if (this.staticValueFn)
151
- return;
157
+ if (this.staticValueFn) return;
152
158
 
153
159
  this.valueFn = null;
154
160
  let from = null;
@@ -156,20 +162,18 @@ class PropertyAnimation {
156
162
 
157
163
  // init via responsive fn
158
164
  if (this.iniResponsive) {
159
- const value = this.iniResponsive(target.target);
165
+ // todo this access to target can't be
166
+ const value = this.iniResponsive((target as any).target);
160
167
 
161
168
  if (typeof value === 'object') {
162
- if ('from' in value)
163
- from = this.prop.parseValue(value.from);
164
- if ('to' in value)
165
- to = this.prop.parseValue(value.to);
169
+ if ('from' in value) from = this.prop.parseValue(value.from);
170
+ if ('to' in value) to = this.prop.parseValue(value.to);
166
171
 
167
- if (!from && !to)
168
- throw new Error('from or to expected');
172
+ if (!from && !to) throw new Error('from or to expected');
169
173
  } else if (typeof value === 'function') {
170
174
  if (!this.prop.allowsValueFn()) {
171
175
  throw new Error(
172
- `prop ${this.prop.name} does not allow value functions`
176
+ `prop ${this.prop.name} does not allow value functions`,
173
177
  );
174
178
  }
175
179
 
@@ -183,28 +187,26 @@ class PropertyAnimation {
183
187
  // init from
184
188
  if (!from) {
185
189
  if (typeof this.iniFrom === 'function')
186
- from = this.prop.parseValue(this.iniFrom(target.target));
187
- else
188
- from = this.iniFrom;
190
+ from = this.prop.parseValue(this.iniFrom(target.inner()));
191
+ else from = this.iniFrom;
189
192
  }
190
193
 
191
194
  // init to
192
195
  if (!to) {
193
196
  if (typeof this.iniTo === 'function')
194
- to = this.prop.parseValue(this.iniTo(target.target));
195
- else
196
- to = this.iniTo;
197
+ to = this.prop.parseValue(this.iniTo(target.inner()));
198
+ else to = this.iniTo;
197
199
  }
198
200
 
199
201
  this.prop.init(target, from, to);
200
202
  }
201
203
 
202
- restoreBefore(target) {
204
+ restoreBefore(target: Target) {
203
205
  // todo this might not be enough
204
206
  this.prop.removeValue(target);
205
207
  }
206
208
 
207
- render(pos, target) {
209
+ render(pos: number, target: Target) {
208
210
  if (this.valueFn) {
209
211
  this.prop.setValue(target, this.prop.parseValue(this.valueFn(pos)));
210
212
  return;
@@ -263,4 +265,4 @@ tl.addGroup()
263
265
 
264
266
  tl.add()
265
267
 
266
- */
268
+ */
@@ -1,16 +1,18 @@
1
- import { takeProp } from '../utils/internal.js';
2
- import Timeline from '../timeline/public.js';
3
- import { staggerMap } from '../stagger/stagger.js';
1
+ import { takeProp } from '../utils/internal';
2
+ import Timeline from '../timeline/public';
3
+ import { staggerMap } from '../stagger/stagger';
4
4
 
5
5
  /**
6
6
  * The animation consist of a timeline with just one animation
7
7
  * This allows to reuse a lot of code
8
- *
8
+ *
9
9
  * ## Props
10
- *
10
+ *
11
11
  */
12
12
  export default class PublicAnimation {
13
- constructor(targets, props = {}) {
13
+ private _tl: Timeline;
14
+
15
+ constructor(targets: any, props: Record<string, any> = {}) {
14
16
  const autoplay = parseAutoplay(takeProp(props, 'autoplay', true));
15
17
  const delay = takeProp(props, 'delay', 0);
16
18
 
@@ -23,10 +25,13 @@ export default class PublicAnimation {
23
25
  props.ease = ease;
24
26
  props.duration = duration;
25
27
 
26
- this._tl.add(targets, props, staggerMap(delay, v => '+=' + v));
28
+ this._tl.add(
29
+ targets,
30
+ props,
31
+ staggerMap(delay, v => '+=' + v),
32
+ );
27
33
 
28
- if (autoplay)
29
- this._tl.play();
34
+ if (autoplay) this._tl.play();
30
35
  }
31
36
 
32
37
  play() {
@@ -40,16 +45,16 @@ export default class PublicAnimation {
40
45
  /**
41
46
  * Seeks to a position in the timeline
42
47
  */
43
- seekMs(ms) {
48
+ seekMs(ms: number) {
44
49
  this._tl.seekMs(ms);
45
50
  }
46
51
 
47
52
  /**
48
53
  * Seeks to a normalized position in the timeline
49
- *
54
+ *
50
55
  * @param pos = number between 0 and 1
51
56
  */
52
- seek(pos) {
57
+ seek(pos: number) {
53
58
  this._tl.seek(pos);
54
59
  }
55
60
 
@@ -75,7 +80,6 @@ export default class PublicAnimation {
75
80
  this._tl.update();
76
81
  }
77
82
 
78
-
79
83
  /**
80
84
  * Returns wether the timeline is set to reversed
81
85
  */
@@ -86,7 +90,7 @@ export default class PublicAnimation {
86
90
  /**
87
91
  * Set's the timeline to a specific direction
88
92
  */
89
- setReversed(reversed) {
93
+ setReversed(reversed: boolean) {
90
94
  this._tl.setReversed(reversed);
91
95
  }
92
96
 
@@ -97,12 +101,12 @@ export default class PublicAnimation {
97
101
  this._tl.reverse();
98
102
  }
99
103
 
100
- on(event, fn) {
104
+ on(event: string, fn: (...args: any[]) => void) {
101
105
  return this._tl.on(event, fn);
102
106
  }
103
107
 
104
108
  // not wroking
105
- onPromise(event) {
109
+ onPromise(event: string) {
106
110
  return this._tl.onPromise(event);
107
111
  }
108
112
 
@@ -111,13 +115,14 @@ export default class PublicAnimation {
111
115
  */
112
116
  destroy() {
113
117
  this._tl.destroy();
118
+ // @ts-ignore
114
119
  this._tl = null;
115
120
  }
116
121
  }
117
122
 
118
- function parseAutoplay(autoplay) {
123
+ function parseAutoplay(autoplay: any): boolean {
119
124
  if (autoplay !== true && autoplay !== false)
120
125
  throw new Error('autoplay needs to be true|false');
121
126
 
122
127
  return autoplay;
123
- }
128
+ }
@@ -1,30 +1,29 @@
1
- import Animation from './animation/public.js';
2
- import Timeline from './timeline/public.js';
3
- import Scroll from './scroll/public.js';
4
- import Stagger from './stagger/stagger.js';
5
-
1
+ import Animation from './animation/public';
2
+ import Timeline from './timeline/public';
3
+ import Scroll from './scroll/public';
4
+ import Stagger from './stagger/stagger';
6
5
 
7
6
  // todo maybe add, to, from and fromTo to the animate function
8
7
 
9
8
  /**
10
9
  * Creates a simple animation
11
- *
10
+ *
12
11
  * ## Properties
13
- *
12
+ *
14
13
  */
15
- export function animate(targets, props = {}) {
14
+ export function animate(targets: any, props: Record<string, any> = {}) {
16
15
  return new Animation(targets, props);
17
16
  }
18
17
 
19
- export function timeline(props = {}) {
18
+ export function timeline(props: Record<string, any> = {}) {
20
19
  return new Timeline(props);
21
20
  }
22
21
 
23
- export function stagger(value) {
22
+ export function stagger(value: any) {
24
23
  return new Stagger(value);
25
24
  }
26
25
 
27
- export function scroll(props = {}) {
26
+ export function scroll(props: Record<string, any> = {}) {
28
27
  return new Scroll(props);
29
28
  }
30
29
 
@@ -66,4 +65,4 @@ animate(target, {
66
65
  alternate
67
66
  })
68
67
 
69
- */
68
+ */
@@ -0,0 +1,91 @@
1
+ import Value from '../values/Value';
2
+ import Property, { ParseableValue } from './Property';
3
+ import { Target } from '../target/Target';
4
+
5
+ export default class BasicProperty implements Property<Value> {
6
+ /**
7
+ * The name of the property
8
+ */
9
+ name: string;
10
+
11
+ /**
12
+ * The value at the start
13
+ */
14
+ from: Value | null;
15
+
16
+ /**
17
+ * The value at the end
18
+ */
19
+ to: Value | null;
20
+
21
+ constructor(name: string) {
22
+ // this is the property name
23
+ this.name = name;
24
+
25
+ this.from = null;
26
+ this.to = null;
27
+ }
28
+
29
+ allowsValueFn() {
30
+ return true;
31
+ }
32
+
33
+ /**
34
+ * From or to might be null
35
+ */
36
+ init(target: Target, from: Value | null, to: Value | null) {
37
+ if (!from) from = this.getValue(target);
38
+
39
+ if (!to) to = this.getValue(target);
40
+
41
+ if (!from || !to)
42
+ throw new Error('could not determine from or to value');
43
+
44
+ const [nFrom, nTo] = target.unifyValues(this.name, from, to);
45
+
46
+ this.from = nFrom;
47
+ this.to = nTo;
48
+ }
49
+
50
+ /**
51
+ * Gets called with the value of a property
52
+ *
53
+ * For examply during initializiation
54
+ */
55
+ parseValue(val: ParseableValue): Value {
56
+ if (typeof val !== 'string')
57
+ throw new Error('only strings are supported');
58
+
59
+ return Value.parse(val);
60
+ }
61
+
62
+ defaultValue(): Value {
63
+ throw new Error('default value for ' + this.name + ' not known');
64
+ }
65
+
66
+ // try to access the value from the target
67
+ getValue(target: Target): Value {
68
+ const val = target.getValue(this.name);
69
+ if (typeof val === 'undefined' || val === null)
70
+ return this.defaultValue();
71
+
72
+ return val;
73
+ }
74
+
75
+ /**
76
+ * Pos needs to be between 0 and 1
77
+ */
78
+ interpolate(pos: number): Value {
79
+ const dif = this.to!.num - this.from!.num;
80
+
81
+ return this.from!.cloneAdd(pos * dif);
82
+ }
83
+
84
+ setValue(target: Target, val: Value) {
85
+ return target.setValue(this.name, val);
86
+ }
87
+
88
+ removeValue(target: Target) {
89
+ return target.removeValue(this.name);
90
+ }
91
+ }
@@ -0,0 +1,132 @@
1
+ import { Target } from '../target/Target';
2
+ import Property, { type ParseableValue } from './Property';
3
+
4
+ export type Interpolated = {
5
+ add: string[];
6
+ remove: string[];
7
+ };
8
+
9
+ /**
10
+ * In most cases we wan't to add the class at pos 0
11
+ * and in reverse remove it at pos 0
12
+ *
13
+ * so this behaviour should be in str|{ to }
14
+ *
15
+ * If we wan't to remove the class at pos 1
16
+ * and in reverse add it at pos 1
17
+ * we do it in { from }
18
+ */
19
+ export default class ClassProperty implements Property<string[], Interpolated> {
20
+ name: string;
21
+
22
+ from!: string[];
23
+ to!: string[];
24
+
25
+ private preStates!: Map<string, boolean>;
26
+ private states!: Map<string, boolean>;
27
+
28
+ constructor(name: string) {
29
+ this.name = name;
30
+ }
31
+
32
+ allowsValueFn(): boolean {
33
+ return false;
34
+ }
35
+
36
+ init(target: Target, from: string[] | null, to: string[] | null) {
37
+ this.from = from ?? [];
38
+ this.to = to ?? [];
39
+
40
+ this.preStates = new Map();
41
+ this.states = new Map();
42
+
43
+ for (const cls of [...this.from, ...this.to]) {
44
+ const exists = target.hasClass(cls);
45
+ this.preStates.set(cls, exists);
46
+ this.states.set(cls, exists);
47
+ }
48
+ }
49
+
50
+ parseValue(val: ParseableValue): string[] {
51
+ if (Array.isArray(val)) {
52
+ return val.map(v => {
53
+ if (typeof v !== 'string')
54
+ throw new Error('cls only accepts strings[]');
55
+
56
+ return v;
57
+ });
58
+ }
59
+
60
+ if (typeof val === 'string') return [val];
61
+
62
+ throw new Error('cls only accepts strings and strings[]');
63
+ }
64
+
65
+ getValue(_target: Target): string[] | null {
66
+ throw new Error('unused');
67
+ }
68
+
69
+ interpolate(pos: number): Interpolated {
70
+ /**
71
+ * ## to
72
+ * add the class at pos >0
73
+ * and in reverse remove it at pos 0
74
+ *
75
+ * ## from
76
+ * remove the class at pos <1
77
+ * and in reverse add it at pos 1
78
+ */
79
+
80
+ let obj: Interpolated = {
81
+ add: [],
82
+ remove: [],
83
+ };
84
+
85
+ if (pos <= 0) {
86
+ obj.remove = this.to;
87
+ } else {
88
+ obj.add = this.to;
89
+ }
90
+
91
+ if (pos >= 1) {
92
+ obj.remove = this.from;
93
+ } else {
94
+ obj.add = [...obj.add, ...this.from];
95
+ }
96
+
97
+ return obj;
98
+ }
99
+
100
+ setValue(target: Target, val: Interpolated) {
101
+ let { add, remove } = val;
102
+ add = add ?? [];
103
+ remove = remove ?? [];
104
+
105
+ if (!Array.isArray(add) || !Array.isArray(remove))
106
+ throw new Error('add or remove expected');
107
+
108
+ add.forEach(cls => {
109
+ const exists = this.states.get(cls);
110
+ if (!exists) {
111
+ target.addClass(cls);
112
+ this.states.set(cls, true);
113
+ }
114
+ });
115
+
116
+ remove.forEach(cls => {
117
+ const exists = this.states.get(cls);
118
+ if (exists) {
119
+ target.removeClass(cls);
120
+ this.states.set(cls, false);
121
+ }
122
+ });
123
+ }
124
+
125
+ removeValue(target: Target) {
126
+ this.preStates.forEach((exists, cls) => {
127
+ if (exists) target.addClass(cls);
128
+ else target.removeClass(cls);
129
+ });
130
+ this.states = new Map(this.preStates);
131
+ }
132
+ }
@@ -0,0 +1,33 @@
1
+ import { Target } from '../target/Target';
2
+ import TransformProperty, { TRANSFORM_PROPS } from './TransformProperty';
3
+ import TransformXYProperty from './TransformXYProperty';
4
+ import StyleProperty, { STYLE_PROPS } from './StyleProperty';
5
+ import ClassProperty from './ClassProperty';
6
+
7
+ export type ParseableValue = string | number | (string | number)[];
8
+
9
+ export default interface Property<V, I = V> {
10
+ name: string;
11
+
12
+ allowsValueFn(): boolean;
13
+
14
+ init(target: Target, from: V | null, to: V | null): void;
15
+
16
+ parseValue(value: ParseableValue): V;
17
+ interpolate(pos: number): I;
18
+ setValue(target: Target, value: I): void;
19
+ removeValue(target: Target): void;
20
+ }
21
+
22
+ export function newProperty(prop: string, targetType = ''): Property<any> {
23
+ if (targetType !== 'dom')
24
+ throw new Error('only dom is supported as target');
25
+
26
+ if (prop in TRANSFORM_PROPS) return new TransformProperty(prop);
27
+ if (prop === 'xy') return new TransformXYProperty(prop);
28
+ if (prop.startsWith('--')) return new StyleProperty(prop);
29
+ if (prop in STYLE_PROPS) return new StyleProperty(prop);
30
+ if (prop === 'cls') return new ClassProperty(prop);
31
+
32
+ throw new Error('unknown prop ' + prop);
33
+ }