@xtia/timeline 1.1.15 → 1.1.17

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { Timeline, animate, ChainingInterface } from "./internal/timeline";
2
- export { TimelinePoint, PointEvent } from "./internal/point";
3
- export { TimelineRange } from "./internal/range";
4
- export { Emitter, RangeProgression, UnsubscribeFunc } from "./internal/emitters";
5
- export { easers } from "./internal/easing";
1
+ export { Timeline, animate, ChainingInterface } from "./internal/timeline.js";
2
+ export { TimelinePoint, PointEvent } from "./internal/point.js";
3
+ export { TimelineRange } from "./internal/range.js";
4
+ export { Emitter, RangeProgression, UnsubscribeFunc } from "./internal/emitters.js";
5
+ export { easers } from "./internal/easing.js";
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { Timeline, animate } from "./internal/timeline";
2
- export { TimelinePoint } from "./internal/point";
3
- export { TimelineRange } from "./internal/range";
4
- export { Emitter, RangeProgression } from "./internal/emitters";
5
- export { easers } from "./internal/easing";
1
+ export { Timeline, animate } from "./internal/timeline.js";
2
+ export { TimelinePoint } from "./internal/point.js";
3
+ export { TimelineRange } from "./internal/range.js";
4
+ export { Emitter, RangeProgression } from "./internal/emitters.js";
5
+ export { easers } from "./internal/easing.js";
@@ -1,6 +1,6 @@
1
- import { Easer, easers } from "./easing";
2
- import { Path, XY } from "./path";
3
- import { BlendableWith, Tweenable } from "./tween";
1
+ import { Easer, easers } from "./easing.js";
2
+ import { Path, XY } from "./path.js";
3
+ import { BlendableWith, Tweenable } from "./tween.js";
4
4
  type Handler<T> = (value: T) => void;
5
5
  export type ListenFunc<T> = (handler: Handler<T>) => UnsubscribeFunc;
6
6
  export type UnsubscribeFunc = () => void;
@@ -1,7 +1,7 @@
1
- import { easers } from "./easing";
2
- import { createPathEmitter } from "./path";
3
- import { createTween } from "./tween";
4
- import { clamp } from "./utils";
1
+ import { easers } from "./easing.js";
2
+ import { createPathEmitter } from "./path.js";
3
+ import { createTween } from "./tween.js";
4
+ import { clamp } from "./utils.js";
5
5
  export class Emitter {
6
6
  constructor(onListen) {
7
7
  this.onListen = onListen;
@@ -139,10 +139,14 @@ export class RangeProgression extends Emitter {
139
139
  * @returns Listenable: emits the sampled values
140
140
  */
141
141
  sample(source) {
142
+ if (source.length === 0) {
143
+ throw new Error("Sample source is empty");
144
+ }
145
+ const sourceArray = Array.from(source);
142
146
  const listen = this.transform((value, emit) => {
143
147
  const clampedProgress = clamp(value);
144
- const index = Math.floor(clampedProgress * (source.length - 1));
145
- emit(source[index]);
148
+ const index = Math.floor(clampedProgress * (sourceArray.length - 1));
149
+ emit(sourceArray[index]);
146
150
  });
147
151
  return new Emitter(listen);
148
152
  }
@@ -1,5 +1,5 @@
1
- import { Easer, easers } from "./easing";
2
- import { ListenFunc } from "./emitters";
1
+ import { Easer, easers } from "./easing.js";
2
+ import { ListenFunc } from "./emitters.js";
3
3
  export type XY = [number, number];
4
4
  type SegmentEvaluator = (t: number) => XY;
5
5
  type LineSegment = {
package/internal/path.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createListenable } from "./emitters";
2
- import { Timeline } from "./timeline";
1
+ import { createListenable } from "./emitters.js";
2
+ import { Timeline } from "./timeline.js";
3
3
  export function createPathEmitter(input) {
4
4
  const { listen, emit } = createListenable();
5
5
  const tl = new Timeline();
@@ -1,7 +1,7 @@
1
- import { Easer } from "./easing";
2
- import { Emitter, ListenFunc, UnsubscribeFunc } from "./emitters";
3
- import { TimelineRange } from "./range";
4
- import { Timeline } from "./timeline";
1
+ import { Easer } from "./easing.js";
2
+ import { Emitter, ListenFunc, UnsubscribeFunc } from "./emitters.js";
3
+ import { TimelineRange } from "./range.js";
4
+ import { Timeline } from "./timeline.js";
5
5
  export type PointEvent = {
6
6
  readonly direction: -1 | 1;
7
7
  };
package/internal/point.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Emitter } from "./emitters";
1
+ import { Emitter } from "./emitters.js";
2
2
  export class TimelinePoint extends Emitter {
3
3
  /** @internal Manual construction of TimelinePoint is outside of the API contract and subject to undocumented change */
4
4
  constructor(onListen, timeline,
@@ -1,7 +1,7 @@
1
- import { Easer, easers } from "./easing";
2
- import { ListenFunc, RangeProgression } from "./emitters";
3
- import { TimelinePoint } from "./point";
4
- import { Timeline } from "./timeline";
1
+ import { Easer, easers } from "./easing.js";
2
+ import { ListenFunc, RangeProgression } from "./emitters.js";
3
+ import { TimelinePoint } from "./point.js";
4
+ import { Timeline } from "./timeline.js";
5
5
  export declare class TimelineRange extends RangeProgression {
6
6
  private timeline;
7
7
  /** The point on the Timeline at which this range begins */
package/internal/range.js CHANGED
@@ -1,5 +1,5 @@
1
- import { RangeProgression } from "./emitters";
2
- import { TimelinePoint } from "./point";
1
+ import { RangeProgression } from "./emitters.js";
2
+ import { TimelinePoint } from "./point.js";
3
3
  export class TimelineRange extends RangeProgression {
4
4
  /** @internal Manual construction of RangeProgression is outside of the API contract and subject to undocumented change */
5
5
  constructor(onListen, timeline,
@@ -1,9 +1,9 @@
1
- import { Easer, easers } from "./easing";
2
- import { RangeProgression, UnsubscribeFunc } from "./emitters";
3
- import { TimelinePoint } from "./point";
4
- import { TimelineRange } from "./range";
5
- import { Tweenable } from "./tween";
6
- import { Widen } from "./utils";
1
+ import { Easer, easers } from "./easing.js";
2
+ import { RangeProgression, UnsubscribeFunc } from "./emitters.js";
3
+ import { TimelinePoint } from "./point.js";
4
+ import { TimelineRange } from "./range.js";
5
+ import { Tweenable } from "./tween.js";
6
+ import { Widen } from "./utils.js";
7
7
  declare const EndAction: {
8
8
  readonly pause: 0;
9
9
  readonly continue: 1;
@@ -1,7 +1,7 @@
1
- import { createListenable, RangeProgression } from "./emitters";
2
- import { TimelinePoint } from "./point";
3
- import { TimelineRange } from "./range";
4
- import { clamp } from "./utils";
1
+ import { createListenable, RangeProgression } from "./emitters.js";
2
+ import { TimelinePoint } from "./point.js";
3
+ import { TimelineRange } from "./range.js";
4
+ import { clamp } from "./utils.js";
5
5
  const default_fps = 60;
6
6
  const requestAnimFrame = globalThis?.requestAnimationFrame;
7
7
  const cancelAnimFrame = globalThis?.cancelAnimationFrame;
package/internal/tween.js CHANGED
@@ -1,4 +1,4 @@
1
- import { clamp } from "./utils";
1
+ import { clamp } from "./utils.js";
2
2
  var TokenTypes;
3
3
  (function (TokenTypes) {
4
4
  TokenTypes[TokenTypes["none"] = 0] = "none";
@@ -132,21 +132,18 @@ function parseColour(code) {
132
132
  rawHex += "ff";
133
133
  return [...rawHex.matchAll(/../g)].map(hex => parseInt(hex[0], 16));
134
134
  }
135
- function blendColours(from, to, bias) {
136
- const blended = from.map((val, i) => clamp(blendNumbers(val, to[i], bias), 0, 255));
137
- if (blended[3] === 255) {
138
- return "#" +
139
- Math.round(blended[0]).toString(16).padStart(2, "0") +
140
- Math.round(blended[1]).toString(16).padStart(2, "0") +
141
- Math.round(blended[2]).toString(16).padStart(2, "0");
142
- }
143
- else {
144
- return "#" +
145
- Math.round(blended[0]).toString(16).padStart(2, "0") +
146
- Math.round(blended[1]).toString(16).padStart(2, "0") +
147
- Math.round(blended[2]).toString(16).padStart(2, "0") +
148
- Math.round(blended[3]).toString(16).padStart(2, "0");
149
- }
135
+ const hexLookup = new Array(256);
136
+ for (let i = 0; i < 256; i++) {
137
+ hexLookup[i] = i.toString(16).padStart(2, "0");
138
+ }
139
+ function blendColours([fromR, fromG, fromB, fromA], [toR, toG, toB, toA], bias) {
140
+ const r = Math.max(0, Math.min(255, Math.round(fromR + bias * (toR - fromR))));
141
+ const g = Math.max(0, Math.min(255, Math.round(fromG + bias * (toG - fromG))));
142
+ const b = Math.max(0, Math.min(255, Math.round(fromB + bias * (toB - fromB))));
143
+ const a = Math.max(0, Math.min(255, Math.round(fromA + bias * (toA - fromA))));
144
+ return a === 255
145
+ ? "#" + hexLookup[r] + hexLookup[g] + hexLookup[b]
146
+ : "#" + hexLookup[r] + hexLookup[g] + hexLookup[b] + hexLookup[a];
150
147
  }
151
148
  const tweenableTokenRegex = /(#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)/g;
152
149
  function tokenise(s) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtia/timeline",
3
- "version": "1.1.15",
3
+ "version": "1.1.17",
4
4
  "repository": {
5
5
  "url": "https://github.com/tiadrop/timeline",
6
6
  "type": "github"