@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.
- package/internal/emitters.js +6 -2
- package/internal/tween.js +12 -15
- package/package.json +1 -1
package/internal/emitters.js
CHANGED
|
@@ -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 * (
|
|
145
|
-
emit(
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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) {
|