@xtia/timeline 1.0.0 → 1.0.1
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 +8 -1
- package/index.d.ts +11 -1
- package/index.js +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,6 +93,7 @@ eased.listen(
|
|
|
93
93
|
const frames = eased
|
|
94
94
|
.tween(0, 30)
|
|
95
95
|
.map(Math.floor)
|
|
96
|
+
.noRepeat()
|
|
96
97
|
.map(n => `animation-frame-${n}.png`)
|
|
97
98
|
.listen(filename => img.src = filename);
|
|
98
99
|
```
|
|
@@ -210,7 +211,7 @@ const wrappingTimeline = new Timeline(true, "wrap");
|
|
|
210
211
|
const foreverTimeline = new Timeline(true, "continue");
|
|
211
212
|
|
|
212
213
|
// "pause" is the default behaviour: stop at the end
|
|
213
|
-
const
|
|
214
|
+
const pausingTimeline = new Timeline(true, "pause");
|
|
214
215
|
|
|
215
216
|
// "restart" and "wrap" strategies can designate a position
|
|
216
217
|
// to loop back to
|
|
@@ -266,6 +267,12 @@ resourceUrls.forEach(url => {
|
|
|
266
267
|
});
|
|
267
268
|
```
|
|
268
269
|
|
|
270
|
+
We can pass a second argument to `seek()` to perform a 'smooth seek' over the given duration. A third argument can provide an easing function for the smooth seek process:
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
timeline.seek(timeline.end, 400, "overshootIn");
|
|
274
|
+
```
|
|
275
|
+
|
|
269
276
|
## Backward-compatibility
|
|
270
277
|
|
|
271
278
|
Despite the massive overhaul, the previous API is present and expanded and upgrading to 1.0.0 should be frictionless in the vast majority of cases.
|
package/index.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ export declare class Timeline {
|
|
|
103
103
|
* @param easer Optional easing function for the smooth-seek process
|
|
104
104
|
* @returns A promise, resolved when the smooth-seek process finishes
|
|
105
105
|
*/
|
|
106
|
-
seek(toPosition: number | TimelinePoint, duration: number, easer?: Easer): Promise<void>;
|
|
106
|
+
seek(toPosition: number | TimelinePoint, duration: number, easer?: Easer | keyof typeof easers): Promise<void>;
|
|
107
107
|
private seekDirect;
|
|
108
108
|
private seekPoints;
|
|
109
109
|
private seekRanges;
|
|
@@ -202,6 +202,16 @@ interface Emitter<T> {
|
|
|
202
202
|
*/
|
|
203
203
|
listen(handler: Handler<T>): Disposer;
|
|
204
204
|
map<R>(mapFunc: (value: T) => R): Emitter<R>;
|
|
205
|
+
/**
|
|
206
|
+
* Selectively forwards emissions along the chain
|
|
207
|
+
* @param check Function that takes an emitted value and returns true if the emission should be forwarded along the chain
|
|
208
|
+
*/
|
|
209
|
+
filter(check: (value: T) => boolean): Emitter<T>;
|
|
210
|
+
/**
|
|
211
|
+
* Discards emitted values that are the same as the last emitted value
|
|
212
|
+
* @param compare Function that takes the previous and next values and returns true if they should be considered equal
|
|
213
|
+
*/
|
|
214
|
+
noRepeat(compare?: (a: T, b: T) => boolean): Emitter<T>;
|
|
205
215
|
}
|
|
206
216
|
export interface TweenEmitter<T extends Tweenable> extends Emitter<T> {
|
|
207
217
|
}
|
package/index.js
CHANGED
|
@@ -553,6 +553,31 @@ function createEmitter(onListen, api) {
|
|
|
553
553
|
});
|
|
554
554
|
}
|
|
555
555
|
},
|
|
556
|
+
filter: {
|
|
557
|
+
value: (filterFunc) => {
|
|
558
|
+
return createEmitter(handler => {
|
|
559
|
+
const filteredHandler = (value) => {
|
|
560
|
+
if (filterFunc(value))
|
|
561
|
+
handler(value);
|
|
562
|
+
};
|
|
563
|
+
return onListen(filteredHandler);
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
noRepeat: {
|
|
568
|
+
value: (compare) => {
|
|
569
|
+
let previous = null;
|
|
570
|
+
return createEmitter(handler => {
|
|
571
|
+
const filteredHandler = (value) => {
|
|
572
|
+
if (!previous || (compare ? !compare(previous.value, value) : (previous.value !== value))) {
|
|
573
|
+
handler(value);
|
|
574
|
+
previous = { value };
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
return onListen(filteredHandler);
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
556
581
|
});
|
|
557
582
|
return emitter;
|
|
558
583
|
}
|