Skip to content

🎥 Make videos programmatically with React

updated interpolate and interpolatecolors type

Shankhadeep Deyb2f5a7f69c98
diff --git a/packages/core/src/interpolate.ts b/packages/core/src/interpolate.ts
index 5596c5be2d..ecda749f16 100644
--- a/packages/core/src/interpolate.ts
+++ b/packages/core/src/interpolate.ts
@@ -71,7 +71,7 @@ function interpolateFunction(
return result;
}
-function findRange(input: number, inputRange: number[]) {
+function findRange(input: number, inputRange: readonly number[]) {
let i;
for (i = 1; i < inputRange.length - 1; ++i) {
if (inputRange[i] >= input) {
@@ -81,7 +81,7 @@ function findRange(input: number, inputRange: number[]) {
return i - 1;
}
-function checkValidInputRange(arr: number[]) {
+function checkValidInputRange(arr: readonly number[]) {
if (arr.length < 2) {
throw new Error('inputRange must have at least 2 elements');
}
@@ -96,7 +96,7 @@ function checkValidInputRange(arr: number[]) {
}
}
-function checkInfiniteRange(name: string, arr: number[]) {
+function checkInfiniteRange(name: string, arr: readonly number[]) {
if (arr.length < 2) {
throw new Error(name + ' must have at least 2 elements');
}
@@ -119,8 +119,8 @@ function checkInfiniteRange(name: string, arr: number[]) {
export function interpolate(
input: number,
- inputRange: number[],
- outputRange: number[],
+ inputRange: readonly number[],
+ outputRange: readonly number[],
options?: {
easing?: (input: number) => number;
extrapolateLeft?: ExtrapolateType;
diff --git a/packages/core/src/interpolateColors.ts b/packages/core/src/interpolateColors.ts
index 403e1f33c0..e008fc0b6d 100644
--- a/packages/core/src/interpolateColors.ts
+++ b/packages/core/src/interpolateColors.ts
@@ -18,6 +18,8 @@ interface HSV {
v: number;
}
+type MatcherType = RegExp | undefined;
+
// var INTEGER = '[-+]?\\d+';
const NUMBER = '[-+]?\\d*\\.?\\d+';
const PERCENTAGE = NUMBER + '%';
@@ -30,24 +32,30 @@ function call(...args: unknown[]): string {
// matchers use RegExp objects which needs to be created separately on JS and on
// the UI thread. We keep separate cache of Regexes for UI and JS using the below
// objects, then pick the right cache in getMatchers() method.
-const jsCachedMatchers = {};
-const uiCachedMatchers = !isConfigured() ? null : makeRemote({});
type Matchers = {
- rgb: RegExp;
- rgba: RegExp;
- hsl: RegExp;
- hsla: RegExp;
- hex3: RegExp;
- hex4: RegExp;
- hex5: RegExp;
- hex6: RegExp;
- hex8: RegExp;
+ rgb: MatcherType;
+ rgba: MatcherType;
+ hsl: MatcherType;
+ hsla: MatcherType;
+ hex3: MatcherType;
+ hex4: MatcherType;
+ hex5: MatcherType;
+ hex6: MatcherType;
+ hex8: MatcherType;
};
function getMatchers(): Matchers {
'worklet';
- const cachedMatchers: Matchers = _WORKLET
- ? uiCachedMatchers
- : jsCachedMatchers;
+ const cachedMatchers: Matchers = {
+ rgb: undefined,
+ rgba: undefined,
+ hsl: undefined,
+ hsla: undefined,
+ hex3: undefined,
+ hex4: undefined,
+ hex5: undefined,
+ hex6: undefined,
+ hex8: undefined,
+ };
if (cachedMatchers.rgb === undefined) {
cachedMatchers.rgb = new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER));
cachedMatchers.rgba = new RegExp(
@@ -66,10 +74,6 @@ function getMatchers(): Matchers {
}
return cachedMatchers;
}
-// cachedMatchers is lazy loaded and it is frozen when worklet is being created,
-// it is possible to call getMatchers() when the object is frozen, then cachedMatchers
-// has no assigned regexes
-getMatchers();
function hue2rgb(p: number, q: number, t: number): number {
'worklet';
@@ -149,162 +153,160 @@ function parsePercentage(str: string): number {
return int / 100;
}
-const names: any = !isConfigured()
- ? null
- : makeShareable({
- transparent: 0x00000000,
-
- // http://www.w3.org/TR/css3-color/#svg-color
- aliceblue: 0xf0f8ffff,
- antiquewhite: 0xfaebd7ff,
- aqua: 0x00ffffff,
- aquamarine: 0x7fffd4ff,
- azure: 0xf0ffffff,
- beige: 0xf5f5dcff,
- bisque: 0xffe4c4ff,
- black: 0x000000ff,
- blanchedalmond: 0xffebcdff,
- blue: 0x0000ffff,
- blueviolet: 0x8a2be2ff,
- brown: 0xa52a2aff,
- burlywood: 0xdeb887ff,
- burntsienna: 0xea7e5dff,
- cadetblue: 0x5f9ea0ff,
- chartreuse: 0x7fff00ff,
- chocolate: 0xd2691eff,
- coral: 0xff7f50ff,
- cornflowerblue: 0x6495edff,
- cornsilk: 0xfff8dcff,
- crimson: 0xdc143cff,
- cyan: 0x00ffffff,
- darkblue: 0x00008bff,
- darkcyan: 0x008b8bff,
- darkgoldenrod: 0xb8860bff,
- darkgray: 0xa9a9a9ff,
- darkgreen: 0x006400ff,
- darkgrey: 0xa9a9a9ff,
- darkkhaki: 0xbdb76bff,
- darkmagenta: 0x8b008bff,
- darkolivegreen: 0x556b2fff,
- darkorange: 0xff8c00ff,
- darkorchid: 0x9932ccff,
- darkred: 0x8b0000ff,
- darksalmon: 0xe9967aff,
- darkseagreen: 0x8fbc8fff,
- darkslateblue: 0x483d8bff,
- darkslategray: 0x2f4f4fff,
- darkslategrey: 0x2f4f4fff,
- darkturquoise: 0x00ced1ff,
- darkviolet: 0x9400d3ff,
- deeppink: 0xff1493ff,
- deepskyblue: 0x00bfffff,
- dimgray: 0x696969ff,
- dimgrey: 0x696969ff,
- dodgerblue: 0x1e90ffff,
- firebrick: 0xb22222ff,
- floralwhite: 0xfffaf0ff,
- forestgreen: 0x228b22ff,
- fuchsia: 0xff00ffff,
- gainsboro: 0xdcdcdcff,
- ghostwhite: 0xf8f8ffff,
- gold: 0xffd700ff,
- goldenrod: 0xdaa520ff,
- gray: 0x808080ff,
- green: 0x008000ff,
- greenyellow: 0xadff2fff,
- grey: 0x808080ff,
- honeydew: 0xf0fff0ff,
- hotpink: 0xff69b4ff,
- indianred: 0xcd5c5cff,
- indigo: 0x4b0082ff,
- ivory: 0xfffff0ff,
- khaki: 0xf0e68cff,
- lavender: 0xe6e6faff,
- lavenderblush: 0xfff0f5ff,
- lawngreen: 0x7cfc00ff,
- lemonchiffon: 0xfffacdff,
- lightblue: 0xadd8e6ff,
- lightcoral: 0xf08080ff,
- lightcyan: 0xe0ffffff,
- lightgoldenrodyellow: 0xfafad2ff,
- lightgray: 0xd3d3d3ff,
- lightgreen: 0x90ee90ff,
- lightgrey: 0xd3d3d3ff,
- lightpink: 0xffb6c1ff,
- lightsalmon: 0xffa07aff,
- lightseagreen: 0x20b2aaff,
- lightskyblue: 0x87cefaff,
- lightslategray: 0x778899ff,
- lightslategrey: 0x778899ff,
- lightsteelblue: 0xb0c4deff,
- lightyellow: 0xffffe0ff,
- lime: 0x00ff00ff,
- limegreen: 0x32cd32ff,
- linen: 0xfaf0e6ff,
- magenta: 0xff00ffff,
- maroon: 0x800000ff,
- mediumaquamarine: 0x66cdaaff,
- mediumblue: 0x0000cdff,
- mediumorchid: 0xba55d3ff,
- mediumpurple: 0x9370dbff,
- mediumseagreen: 0x3cb371ff,
- mediumslateblue: 0x7b68eeff,
- mediumspringgreen: 0x00fa9aff,
- mediumturquoise: 0x48d1ccff,
- mediumvioletred: 0xc71585ff,
- midnightblue: 0x191970ff,
- mintcream: 0xf5fffaff,
- mistyrose: 0xffe4e1ff,
- moccasin: 0xffe4b5ff,
- navajowhite: 0xffdeadff,
- navy: 0x000080ff,
- oldlace: 0xfdf5e6ff,
- olive: 0x808000ff,
- olivedrab: 0x6b8e23ff,
- orange: 0xffa500ff,
- orangered: 0xff4500ff,
- orchid: 0xda70d6ff,
- palegoldenrod: 0xeee8aaff,
- palegreen: 0x98fb98ff,
- paleturquoise: 0xafeeeeff,
- palevioletred: 0xdb7093ff,
- papayawhip: 0xffefd5ff,
- peachpuff: 0xffdab9ff,
- peru: 0xcd853fff,
- pink: 0xffc0cbff,
- plum: 0xdda0ddff,
- powderblue: 0xb0e0e6ff,
- purple: 0x800080ff,
- rebeccapurple: 0x663399ff,
- red: 0xff0000ff,
- rosybrown: 0xbc8f8fff,
- royalblue: 0x4169e1ff,
- saddlebrown: 0x8b4513ff,
- salmon: 0xfa8072ff,
- sandybrown: 0xf4a460ff,
- seagreen: 0x2e8b57ff,
- seashell: 0xfff5eeff,
- sienna: 0xa0522dff,
- silver: 0xc0c0c0ff,
- skyblue: 0x87ceebff,
- slateblue: 0x6a5acdff,
- slategray: 0x708090ff,
- slategrey: 0x708090ff,
- snow: 0xfffafaff,
- springgreen: 0x00ff7fff,
- steelblue: 0x4682b4ff,
- tan: 0xd2b48cff,
- teal: 0x008080ff,
- thistle: 0xd8bfd8ff,
- tomato: 0xff6347ff,
- turquoise: 0x40e0d0ff,
- violet: 0xee82eeff,
- wheat: 0xf5deb3ff,
- white: 0xffffffff,
- whitesmoke: 0xf5f5f5ff,
- yellow: 0xffff00ff,
- yellowgreen: 0x9acd32ff,
- });
+const names: any = {
+ transparent: 0x00000000,
+
+ // http://www.w3.org/TR/css3-color/#svg-color
+ aliceblue: 0xf0f8ffff,
+ antiquewhite: 0xfaebd7ff,
+ aqua: 0x00ffffff,
+ aquamarine: 0x7fffd4ff,
+ azure: 0xf0ffffff,
+ beige: 0xf5f5dcff,
+ bisque: 0xffe4c4ff,
+ black: 0x000000ff,
+ blanchedalmond: 0xffebcdff,
+ blue: 0x0000ffff,
+ blueviolet: 0x8a2be2ff,
+ brown: 0xa52a2aff,
+ burlywood: 0xdeb887ff,
+ burntsienna: 0xea7e5dff,
+ cadetblue: 0x5f9ea0ff,
+ chartreuse: 0x7fff00ff,
+ chocolate: 0xd2691eff,
+ coral: 0xff7f50ff,
+ cornflowerblue: 0x6495edff,
+ cornsilk: 0xfff8dcff,
+ crimson: 0xdc143cff,
+ cyan: 0x00ffffff,
+ darkblue: 0x00008bff,
+ darkcyan: 0x008b8bff,
+ darkgoldenrod: 0xb8860bff,
+ darkgray: 0xa9a9a9ff,
+ darkgreen: 0x006400ff,
+ darkgrey: 0xa9a9a9ff,
+ darkkhaki: 0xbdb76bff,
+ darkmagenta: 0x8b008bff,
+ darkolivegreen: 0x556b2fff,
+ darkorange: 0xff8c00ff,
+ darkorchid: 0x9932ccff,
+ darkred: 0x8b0000ff,
+ darksalmon: 0xe9967aff,
+ darkseagreen: 0x8fbc8fff,
+ darkslateblue: 0x483d8bff,
+ darkslategray: 0x2f4f4fff,
+ darkslategrey: 0x2f4f4fff,
+ darkturquoise: 0x00ced1ff,
+ darkviolet: 0x9400d3ff,
+ deeppink: 0xff1493ff,
+ deepskyblue: 0x00bfffff,
+ dimgray: 0x696969ff,
+ dimgrey: 0x696969ff,
+ dodgerblue: 0x1e90ffff,
+ firebrick: 0xb22222ff,
+ floralwhite: 0xfffaf0ff,
+ forestgreen: 0x228b22ff,
+ fuchsia: 0xff00ffff,
+ gainsboro: 0xdcdcdcff,
+ ghostwhite: 0xf8f8ffff,
+ gold: 0xffd700ff,
+ goldenrod: 0xdaa520ff,
+ gray: 0x808080ff,
+ green: 0x008000ff,
+ greenyellow: 0xadff2fff,
+ grey: 0x808080ff,
+ honeydew: 0xf0fff0ff,
+ hotpink: 0xff69b4ff,
+ indianred: 0xcd5c5cff,
+ indigo: 0x4b0082ff,
+ ivory: 0xfffff0ff,
+ khaki: 0xf0e68cff,
+ lavender: 0xe6e6faff,
+ lavenderblush: 0xfff0f5ff,
+ lawngreen: 0x7cfc00ff,
+ lemonchiffon: 0xfffacdff,
+ lightblue: 0xadd8e6ff,
+ lightcoral: 0xf08080ff,
+ lightcyan: 0xe0ffffff,
+ lightgoldenrodyellow: 0xfafad2ff,
+ lightgray: 0xd3d3d3ff,
+ lightgreen: 0x90ee90ff,
+ lightgrey: 0xd3d3d3ff,
+ lightpink: 0xffb6c1ff,
+ lightsalmon: 0xffa07aff,
+ lightseagreen: 0x20b2aaff,
+ lightskyblue: 0x87cefaff,
+ lightslategray: 0x778899ff,
+ lightslategrey: 0x778899ff,
+ lightsteelblue: 0xb0c4deff,
+ lightyellow: 0xffffe0ff,
+ lime: 0x00ff00ff,
+ limegreen: 0x32cd32ff,
+ linen: 0xfaf0e6ff,
+ magenta: 0xff00ffff,
+ maroon: 0x800000ff,
+ mediumaquamarine: 0x66cdaaff,
+ mediumblue: 0x0000cdff,
+ mediumorchid: 0xba55d3ff,
+ mediumpurple: 0x9370dbff,
+ mediumseagreen: 0x3cb371ff,
+ mediumslateblue: 0x7b68eeff,
+ mediumspringgreen: 0x00fa9aff,
+ mediumturquoise: 0x48d1ccff,
+ mediumvioletred: 0xc71585ff,
+ midnightblue: 0x191970ff,
+ mintcream: 0xf5fffaff,
+ mistyrose: 0xffe4e1ff,
+ moccasin: 0xffe4b5ff,
+ navajowhite: 0xffdeadff,
+ navy: 0x000080ff,
+ oldlace: 0xfdf5e6ff,
+ olive: 0x808000ff,
+ olivedrab: 0x6b8e23ff,
+ orange: 0xffa500ff,
+ orangered: 0xff4500ff,
+ orchid: 0xda70d6ff,
+ palegoldenrod: 0xeee8aaff,
+ palegreen: 0x98fb98ff,
+ paleturquoise: 0xafeeeeff,
+ palevioletred: 0xdb7093ff,
+ papayawhip: 0xffefd5ff,
+ peachpuff: 0xffdab9ff,
+ peru: 0xcd853fff,
+ pink: 0xffc0cbff,
+ plum: 0xdda0ddff,
+ powderblue: 0xb0e0e6ff,
+ purple: 0x800080ff,
+ rebeccapurple: 0x663399ff,
+ red: 0xff0000ff,
+ rosybrown: 0xbc8f8fff,
+ royalblue: 0x4169e1ff,
+ saddlebrown: 0x8b4513ff,
+ salmon: 0xfa8072ff,
+ sandybrown: 0xf4a460ff,
+ seagreen: 0x2e8b57ff,
+ seashell: 0xfff5eeff,
+ sienna: 0xa0522dff,
+ silver: 0xc0c0c0ff,
+ skyblue: 0x87ceebff,
+ slateblue: 0x6a5acdff,
+ slategray: 0x708090ff,
+ slategrey: 0x708090ff,
+ snow: 0xfffafaff,
+ springgreen: 0x00ff7fff,
+ steelblue: 0x4682b4ff,
+ tan: 0xd2b48cff,
+ teal: 0x008080ff,
+ thistle: 0xd8bfd8ff,
+ tomato: 0xff6347ff,
+ turquoise: 0x40e0d0ff,
+ violet: 0xee82eeff,
+ wheat: 0xf5deb3ff,
+ white: 0xffffffff,
+ whitesmoke: 0xf5f5f5ff,
+ yellow: 0xffff00ff,
+ yellowgreen: 0x9acd32ff,
+};
function normalizeColor(color: unknown): number | null {
'worklet';
@@ -325,94 +327,109 @@ function normalizeColor(color: unknown): number | null {
let match: RegExpExecArray | null;
// Ordered based on occurrences on Facebook codebase
- if ((match = matchers.hex6.exec(color))) {
- return Number.parseInt(match[1] + 'ff', 16) >>> 0;
+ if (matchers.hex6) {
+ if ((match = matchers.hex6.exec(color))) {
+ return Number.parseInt(match[1] + 'ff', 16) >>> 0;
+ }
}
if (names[color] !== undefined) {
return names[color];
}
-
- if ((match = matchers.rgb.exec(color))) {
- return (
- // b
- ((parse255(match[1]) << 24) | // r
- (parse255(match[2]) << 16) | // g
- (parse255(match[3]) << 8) |
- 0x000000ff) >>> // a
- 0
- );
+ if (matchers.rgb) {
+ if ((match = matchers.rgb.exec(color))) {
+ return (
+ // b
+ ((parse255(match[1]) << 24) | // r
+ (parse255(match[2]) << 16) | // g
+ (parse255(match[3]) << 8) |
+ 0x000000ff) >>> // a
+ 0
+ );
+ }
}
- if ((match = matchers.rgba.exec(color))) {
- return (
- // b
- ((parse255(match[1]) << 24) | // r
- (parse255(match[2]) << 16) | // g
- (parse255(match[3]) << 8) |
- parse1(match[4])) >>> // a
- 0
- );
+ if (matchers.rgba) {
+ if ((match = matchers.rgba.exec(color))) {
+ return (
+ // b
+ ((parse255(match[1]) << 24) | // r
+ (parse255(match[2]) << 16) | // g
+ (parse255(match[3]) << 8) |
+ parse1(match[4])) >>> // a
+ 0
+ );
+ }
}
- if ((match = matchers.hex3.exec(color))) {
- return (
- Number.parseInt(
- match[1] +
- match[1] + // r
- match[2] +
- match[2] + // g
- match[3] +
- match[3] + // b
- 'ff', // a
- 16
- ) >>> 0
- );
+ if (matchers.hex3) {
+ if ((match = matchers.hex3.exec(color))) {
+ return (
+ Number.parseInt(
+ match[1] +
+ match[1] + // r
+ match[2] +
+ match[2] + // g
+ match[3] +
+ match[3] + // b
+ 'ff', // a
+ 16
+ ) >>> 0
+ );
+ }
}
// https://drafts.csswg.org/css-color-4/#hex-notation
- if ((match = matchers.hex8.exec(color))) {
- return Number.parseInt(match[1], 16) >>> 0;
- }
-
- if ((match = matchers.hex4.exec(color))) {
- return (
- Number.parseInt(
- match[1] +
- match[1] + // r
- match[2] +
- match[2] + // g
- match[3] +
- match[3] + // b
- match[4] +
- match[4], // a
- 16
- ) >>> 0
- );
+ if (matchers.hex8) {
+ if ((match = matchers.hex8.exec(color))) {
+ return Number.parseInt(match[1], 16) >>> 0;
+ }
}
- if ((match = matchers.hsl.exec(color))) {
- return (
- (hslToRgb(
- parse360(match[1]), // h
- parsePercentage(match[2]), // s
- parsePercentage(match[3]) // l
- ) |
- 0x000000ff) >>> // a
- 0
- );
+ if (matchers.hex4) {
+ if ((match = matchers.hex4.exec(color))) {
+ return (
+ Number.parseInt(
+ match[1] +
+ match[1] + // r
+ match[2] +
+ match[2] + // g
+ match[3] +
+ match[3] + // b
+ match[4] +
+ match[4], // a
+ 16
+ ) >>> 0
+ );
+ }
}
- if ((match = matchers.hsla.exec(color))) {
- return (
- (hslToRgb(
- parse360(match[1]), // h
- parsePercentage(match[2]), // s
- parsePercentage(match[3]) // l
- ) |
- parse1(match[4])) >>> // a
- 0
- );
+ if (matchers.hsl) {
+ if ((match = matchers.hsl.exec(color))) {
+ return (
+ (hslToRgb(
+ parse360(match[1]), // h
+ parsePercentage(match[2]), // s
+ parsePercentage(match[3]) // l
+ ) |
+ 0x000000ff) >>> // a
+ 0
+ );
+ }
+ }
+
+ if (matchers.hsla) {
+ if ((match = matchers.hsla.exec(color))) {
+ return (
+ (hslToRgb(
+ parse360(match[1]), // h
+ parsePercentage(match[2]), // s
+ parsePercentage(match[3]) // l
+ ) |
+ parse1(match[4])) >>> // a
+ 0
+ );
+ }
}
return null;
@@ -444,20 +461,13 @@ export const rgbaColor = (
b: number,
alpha = 1
): number | string => {
- 'worklet';
- if (Platform.OS === 'web' || !_WORKLET) {
- return `rgba(${r}, ${g}, ${b}, ${alpha})`;
- }
const a = Math.round(alpha * 255);
const c =
a * (1 << 24) +
Math.round(r) * (1 << 16) +
Math.round(g) * (1 << 8) +
Math.round(b);
- if (Platform.OS === 'android') {
- // on Android color is represented as signed 32 bit int
- return c < (1 << 31) >>> 0 ? c : c - Math.pow(2, 32);
- }
+
return c;
};
@@ -468,10 +478,11 @@ export const rgbaColor = (
* 0 <= r, g, b <= 255
* returns 0 <= h, s, v <= 1
*/
+
+/* eslint no-redeclare: 0 */
function RGBtoHSV(rgb: RBG): HSV;
function RGBtoHSV(r: number, g: number, b: number): HSV;
function RGBtoHSV(r: any, g?: any, b?: any): HSV {
- 'worklet';
/* eslint-disable */
if (arguments.length === 1) {
g = r.g;
@@ -524,7 +535,6 @@ function RGBtoHSV(r: any, g?: any, b?: any): HSV {
function HSVtoRGB(hsv: HSV): RBG;
function HSVtoRGB(h: number, s: number, v: number): RBG;
function HSVtoRGB(h: any, s?: any, v?: any) {
- 'worklet';
/* eslint-disable */
var r, g, b, i, f, p, q, t;
if (arguments.length === 1) {
@@ -607,7 +617,7 @@ export function isColor(value: unknown): boolean {
export function processColor(color: unknown): number | null | undefined {
'worklet';
- let normalizedColor = processColorInitially(color);
+ const normalizedColor = processColorInitially(color);
if (normalizedColor === null || normalizedColor === undefined) {
return undefined;
}
@@ -616,14 +626,6 @@ export function processColor(color: unknown): number | null | undefined {
return null;
}
- if (Platform.OS === 'android') {
- // Android use 32 bit *signed* integer to represent the color
- // We utilize the fact that bitwise operations in JS also operates on
- // signed 32 bit integers, so that we can use those to convert from
- // *unsigned* to *signed* 32bit int that way.
- normalizedColor = normalizedColor | 0x0;
- }
-
return normalizedColor;
}
@@ -657,19 +659,28 @@ const interpolateColorsHSV = (
value,
inputRange,
colorsAsHSV.map((c) => c.h),
- Extrapolate.CLAMP
+ {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }
);
const s = interpolate(
value,
inputRange,
colorsAsHSV.map((c) => c.s),
- Extrapolate.CLAMP
+ {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }
);
const v = interpolate(
value,
inputRange,
colorsAsHSV.map((c) => c.v),
- Extrapolate.CLAMP
+ {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }
);
return hsvToColor(h, s, v);
};
@@ -685,7 +696,10 @@ const interpolateColorsRGB = (
value,
inputRange,
colors.map((c) => red(c)),
- Extrapolate.CLAMP
+ {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }
)
);
const g = Math.round(
@@ -693,7 +707,10 @@ const interpolateColorsRGB = (
value,
inputRange,
colors.map((c) => green(c)),
- Extrapolate.CLAMP
+ {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }
)
);
const b = Math.round(
@@ -701,14 +718,20 @@ const interpolateColorsRGB = (
value,
inputRange,
colors.map((c) => blue(c)),
- Extrapolate.CLAMP
+ {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }
)
);
const a = interpolate(
value,
inputRange,
colors.map((c) => opacity(c)),
- Extrapolate.CLAMP
+ {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }
);
return rgbaColor(r, g, b, a);
};