@xtia/timeline 1.1.15 → 1.1.16

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.
@@ -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
  }
package/internal/tween.js CHANGED
@@ -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.16",
4
4
  "repository": {
5
5
  "url": "https://github.com/tiadrop/timeline",
6
6
  "type": "github"