@xtia/timeline 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ### Not Just Another Animation Library
4
4
 
5
- Timeline is a type-safe, deterministic choreography system that can control state transitions in any environment, whether that's a simple or complex CSS animation, managing a microcontroller's output, or synchronising complex hardware sequences.
5
+ Timeline is a type-safe, seekable, deterministic choreography system that can control state transitions in any environment, whether that's a simple or complex CSS animation, managing a microcontroller's output, or synchronising complex hardware sequences.
6
6
 
7
7
  * [API Reference](#reference)
8
8
  * [Playground](https://stackblitz.com/edit/timeline-string-tween?file=src%2Fmain.ts)
@@ -17,7 +17,7 @@ import { Timeline } from "@xtia/timeline";
17
17
  // create a Timeline
18
18
  const timeline = new Timeline();
19
19
 
20
- // over the first second, fade the body's background colour
20
+ // over the first second, fade an element's background colour
21
21
  timeline
22
22
  .range(0, 1000)
23
23
  .tween("#646", "#000")
@@ -510,8 +510,8 @@ Registers an emission handler that calls one function for forward seeks to or pa
510
510
  ```ts
511
511
  point
512
512
  .applyDirectional(
513
- element.classList.add("faded"),
514
- element.classList.remove("faded"),
513
+ () => element.classList.add("faded"),
514
+ () => element.classList.remove("faded"),
515
515
  );
516
516
  ```
517
517
 
@@ -66,8 +66,8 @@ export declare class TimelinePoint extends Emitter<PointEvent> {
66
66
  * ```
67
67
  * point
68
68
  * .applyDirectional(
69
- * element.classList.add("faded"),
70
- * element.classList.remove("faded"),
69
+ * () => element.classList.add("faded"),
70
+ * () => element.classList.remove("faded"),
71
71
  * );
72
72
  * ```
73
73
  *
package/internal/point.js CHANGED
@@ -87,8 +87,8 @@ export class TimelinePoint extends Emitter {
87
87
  * ```
88
88
  * point
89
89
  * .applyDirectional(
90
- * element.classList.add("faded"),
91
- * element.classList.remove("faded"),
90
+ * () => element.classList.add("faded"),
91
+ * () => element.classList.remove("faded"),
92
92
  * );
93
93
  * ```
94
94
  *
@@ -151,6 +151,7 @@ export interface ChainingInterface {
151
151
  thenTween<T extends Tweenable>(duration: number, apply: (v: Widen<T>) => void, from: T, to: T, easer: Easer): ChainingInterface;
152
152
  then(action: () => void): ChainingInterface;
153
153
  thenWait(duration: number): ChainingInterface;
154
+ fork(fn: (chain: ChainingInterface) => void): ChainingInterface;
154
155
  readonly end: TimelinePoint;
155
156
  }
156
157
  export {};
@@ -330,12 +330,12 @@ export class Timeline {
330
330
  reverse = action;
331
331
  if (action)
332
332
  point.apply(reverse
333
- ? (event => event.direction < 0 ? reverse() : action)
333
+ ? (event => event.direction < 0 ? reverse() : action())
334
334
  : action);
335
335
  return this.createChainingInterface(point.position);
336
336
  }
337
337
  createChainingInterface(position) {
338
- return {
338
+ const chain = {
339
339
  thenTween: (duration, apply, from, to, easer) => {
340
340
  return this.tween(position, duration, apply, from, to, easer);
341
341
  },
@@ -344,8 +344,13 @@ export class Timeline {
344
344
  this.point(position + delay);
345
345
  return this.createChainingInterface(position + delay);
346
346
  },
347
+ fork: fn => {
348
+ fn(chain);
349
+ return chain;
350
+ },
347
351
  end: this.point(position),
348
352
  };
353
+ return chain;
349
354
  }
350
355
  /**
351
356
  * @deprecated use `timeline.currentTime`
package/internal/tween.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { clamp } from "./utils";
2
- const tokenTypes = {
3
- none: 0,
4
- number: 1,
5
- colour: 2,
6
- };
2
+ var TokenTypes;
3
+ (function (TokenTypes) {
4
+ TokenTypes[TokenTypes["none"] = 0] = "none";
5
+ TokenTypes[TokenTypes["number"] = 1] = "number";
6
+ TokenTypes[TokenTypes["colour"] = 2] = "colour";
7
+ })(TokenTypes || (TokenTypes = {}));
8
+ ;
7
9
  export function createTween(from, to) {
8
10
  if (from === to)
9
11
  return () => from;
@@ -39,9 +41,9 @@ function createStringTween(from, to) {
39
41
  const fromToken = chunk.token;
40
42
  const toToken = toChunks[i].token;
41
43
  const prefix = chunk.prefix;
42
- if (chunk.type === tokenTypes.none)
44
+ if (chunk.type === TokenTypes.none)
43
45
  return () => prefix;
44
- if (chunk.type === tokenTypes.colour) {
46
+ if (chunk.type === TokenTypes.colour) {
45
47
  const fromColour = parseColour(fromToken);
46
48
  const toColour = parseColour(toToken);
47
49
  return progress => prefix + blendColours(fromColour, toColour, progress);
@@ -142,13 +144,13 @@ function tokenise(s) {
142
144
  // trailing literal after the last token – stored as a final chunk
143
145
  const tail = s.slice(lastIdx);
144
146
  if (tail.length) {
145
- chunks.push({ prefix: tail, token: "", type: tokenTypes.none });
147
+ chunks.push({ prefix: tail, token: "", type: TokenTypes.none });
146
148
  }
147
149
  return chunks;
148
150
  }
149
151
  ;
150
152
  function getTokenType(token) {
151
153
  if (token.startsWith("#"))
152
- return tokenTypes.colour;
153
- return tokenTypes.number;
154
+ return TokenTypes.colour;
155
+ return TokenTypes.number;
154
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtia/timeline",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "repository": {
5
5
  "url": "https://github.com/tiadrop/timeline",
6
6
  "type": "github"