react-ui-animate 3.0.0-rc.0 → 3.0.0-rc.2

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.
Files changed (161) hide show
  1. package/dist/animation/core/helpers/isDefined.d.ts +1 -1
  2. package/dist/animation/core/helpers/isFluidValue.d.ts +8 -4
  3. package/dist/animation/lib/interpolation.d.ts +20 -15
  4. package/dist/gestures/helpers/math.d.ts +1 -1
  5. package/dist/index.js +1 -2897
  6. package/dist/index.js.map +1 -1
  7. package/package.json +2 -1
  8. package/.vscode/settings.json +0 -3
  9. package/dist/animation/animationType.d.ts +0 -15
  10. package/dist/animation/core/animation/Animation.d.ts +0 -16
  11. package/dist/animation/core/animation/FluidValue.d.ts +0 -21
  12. package/dist/animation/core/animation/RequestAnimationFrame.d.ts +0 -8
  13. package/dist/animation/core/animation/SpringAnimation.d.ts +0 -41
  14. package/dist/animation/core/animation/TimingAnimation.d.ts +0 -35
  15. package/dist/animation/core/animation/TransitionValue.d.ts +0 -21
  16. package/dist/animation/core/helpers/camelToDash.d.ts +0 -7
  17. package/dist/animation/core/helpers/canInterpolate.d.ts +0 -11
  18. package/dist/animation/core/helpers/getAnimatableObject.d.ts +0 -22
  19. package/dist/animation/core/helpers/getNonAnimatableStyle.d.ts +0 -6
  20. package/dist/animation/core/react/Tags.d.ts +0 -3
  21. package/dist/animation/core/react/TransformStyles.d.ts +0 -8
  22. package/dist/animation/core/react/animated.d.ts +0 -29
  23. package/dist/animation/core/react/combineRefs.d.ts +0 -2
  24. package/dist/animation/core/react/functions/camelToDash.d.ts +0 -7
  25. package/dist/animation/core/react/functions/getAnimatableObject.d.ts +0 -22
  26. package/dist/animation/core/react/functions/getCleanProps.d.ts +0 -4
  27. package/dist/animation/core/react/functions/getCssValue.d.ts +0 -8
  28. package/dist/animation/core/react/functions/getNonAnimatableStyle.d.ts +0 -6
  29. package/dist/animation/core/react/functions/index.d.ts +0 -7
  30. package/dist/animation/core/react/functions/isDefined.d.ts +0 -6
  31. package/dist/animation/core/react/functions/isTransitionValue.d.ts +0 -6
  32. package/dist/animation/core/react/helpers/camelToDash.d.ts +0 -7
  33. package/dist/animation/core/react/helpers/canInterpolate.d.ts +0 -7
  34. package/dist/animation/core/react/helpers/getAnimatableObject.d.ts +0 -22
  35. package/dist/animation/core/react/helpers/getCleanProps.d.ts +0 -4
  36. package/dist/animation/core/react/helpers/getCssValue.d.ts +0 -8
  37. package/dist/animation/core/react/helpers/getNonAnimatableStyle.d.ts +0 -6
  38. package/dist/animation/core/react/helpers/index.d.ts +0 -7
  39. package/dist/animation/core/react/helpers/isDefined.d.ts +0 -6
  40. package/dist/animation/core/react/helpers/isFluidValue.d.ts +0 -6
  41. package/dist/animation/core/react/helpers/isTransitionValue.d.ts +0 -6
  42. package/dist/animation/core/react/useMounts.d.ts +0 -26
  43. package/dist/animation/core/react/useTransition.d.ts +0 -9
  44. package/dist/animation/core/react/useTransitions.d.ts +0 -11
  45. package/dist/animation/core/types/animation.d.ts +0 -54
  46. package/dist/animation/core/types/common.d.ts +0 -4
  47. package/dist/animation/core/types/fluid.d.ts +0 -19
  48. package/dist/animation/core/types/index.d.ts +0 -2
  49. package/dist/animation/getInitialConfig.d.ts +0 -3
  50. package/dist/animation/index.d.ts +0 -6
  51. package/dist/animation/interpolation.d.ts +0 -21
  52. package/dist/animation/modules/AnimatedBlock.d.ts +0 -8
  53. package/dist/animation/modules/AnimatedImage.d.ts +0 -8
  54. package/dist/animation/modules/AnimatedInline.d.ts +0 -8
  55. package/dist/animation/modules/MountedBlock.d.ts +0 -29
  56. package/dist/animation/modules/ScrollableBlock.d.ts +0 -21
  57. package/dist/animation/modules/TransitionBlock.d.ts +0 -17
  58. package/dist/animation/modules/index.d.ts +0 -6
  59. package/dist/animation/useAnimatedValue.d.ts +0 -22
  60. package/dist/animation/useMountedValue.d.ts +0 -15
  61. package/dist/gestures/eventAttacher.d.ts +0 -11
  62. package/dist/gestures/index.d.ts +0 -2
  63. package/dist/gestures/math.d.ts +0 -34
  64. package/dist/gestures/types.d.ts +0 -51
  65. package/dist/gestures/withDefault.d.ts +0 -4
  66. package/dist/utils/isDefined.d.ts +0 -1
  67. package/ecosystem.config.js +0 -12
  68. package/example/README.md +0 -46
  69. package/example/package-lock.json +0 -19597
  70. package/example/package.json +0 -45
  71. package/example/public/favicon.ico +0 -0
  72. package/example/public/index.html +0 -20
  73. package/example/public/logo192.png +0 -0
  74. package/example/public/logo512.png +0 -0
  75. package/example/public/manifest.json +0 -25
  76. package/example/public/robots.txt +0 -3
  77. package/example/src/App.tsx +0 -41
  78. package/example/src/components/Draggable.tsx +0 -46
  79. package/example/src/components/Gestures.tsx +0 -151
  80. package/example/src/components/Interpolation.tsx +0 -21
  81. package/example/src/components/Loop.tsx +0 -48
  82. package/example/src/components/MountedBlock.tsx +0 -25
  83. package/example/src/components/MouseMove.tsx +0 -59
  84. package/example/src/components/MultistageTransition.tsx +0 -34
  85. package/example/src/components/Scroll.tsx +0 -39
  86. package/example/src/components/ScrollableBlock.tsx +0 -27
  87. package/example/src/components/SnapTo.tsx +0 -55
  88. package/example/src/components/TransitionBlock.tsx +0 -37
  89. package/example/src/components/Wheel.tsx +0 -39
  90. package/example/src/components/index.ts +0 -18
  91. package/example/src/components/svgLine.tsx +0 -48
  92. package/example/src/components/useAnimatedValue.tsx +0 -57
  93. package/example/src/components/useMountedValue.tsx +0 -62
  94. package/example/src/index.css +0 -8
  95. package/example/src/index.tsx +0 -16
  96. package/example/tsconfig.json +0 -26
  97. package/rollup.config.mjs +0 -18
  98. package/src/animation/core/controllers/Animation.ts +0 -27
  99. package/src/animation/core/controllers/FluidValue.ts +0 -97
  100. package/src/animation/core/controllers/RequestAnimationFrame.ts +0 -13
  101. package/src/animation/core/controllers/SpringAnimation.ts +0 -218
  102. package/src/animation/core/controllers/TimingAnimation.ts +0 -152
  103. package/src/animation/core/easing/Bezier.ts +0 -146
  104. package/src/animation/core/easing/Easing.ts +0 -132
  105. package/src/animation/core/helpers/camelCaseToKebabCase.ts +0 -10
  106. package/src/animation/core/helpers/getCleanProps.ts +0 -16
  107. package/src/animation/core/helpers/getCssValue.ts +0 -60
  108. package/src/animation/core/helpers/index.ts +0 -5
  109. package/src/animation/core/helpers/isDefined.ts +0 -14
  110. package/src/animation/core/helpers/isFluidValue.ts +0 -11
  111. package/src/animation/core/index.ts +0 -16
  112. package/src/animation/core/interpolation/Colors.ts +0 -232
  113. package/src/animation/core/interpolation/Interpolation.ts +0 -395
  114. package/src/animation/core/interpolation/__tests__/Colors.test.tsx +0 -35
  115. package/src/animation/core/react/fluid.ts +0 -197
  116. package/src/animation/core/react/makeFluid.ts +0 -294
  117. package/src/animation/core/react/transforms.ts +0 -90
  118. package/src/animation/core/react/useFluidValue.ts +0 -43
  119. package/src/animation/core/react/useMount.ts +0 -58
  120. package/src/animation/core/types/animation.d.ts +0 -56
  121. package/src/animation/core/types/common.d.ts +0 -4
  122. package/src/animation/core/types/fluid.d.ts +0 -38
  123. package/src/animation/lib/animationType.ts +0 -17
  124. package/src/animation/lib/getInitialConfig.ts +0 -61
  125. package/src/animation/lib/index.ts +0 -12
  126. package/src/animation/lib/interpolation.ts +0 -47
  127. package/src/animation/lib/modules/AnimatedBlock.ts +0 -8
  128. package/src/animation/lib/modules/AnimatedImage.ts +0 -8
  129. package/src/animation/lib/modules/AnimatedInline.ts +0 -8
  130. package/src/animation/lib/modules/MountedBlock.tsx +0 -51
  131. package/src/animation/lib/modules/ScrollableBlock.tsx +0 -68
  132. package/src/animation/lib/modules/TransitionBlock.tsx +0 -28
  133. package/src/animation/lib/modules/index.ts +0 -6
  134. package/src/animation/lib/useAnimatedValue.ts +0 -60
  135. package/src/animation/lib/useMountedValue.ts +0 -18
  136. package/src/gestures/controllers/DragGesture.ts +0 -178
  137. package/src/gestures/controllers/Gesture.ts +0 -54
  138. package/src/gestures/controllers/MouseMoveGesture.ts +0 -111
  139. package/src/gestures/controllers/ScrollGesture.ts +0 -107
  140. package/src/gestures/controllers/WheelGesture.ts +0 -123
  141. package/src/gestures/controllers/index.ts +0 -4
  142. package/src/gestures/helpers/eventAttacher.ts +0 -67
  143. package/src/gestures/helpers/index.ts +0 -1
  144. package/src/gestures/helpers/math.ts +0 -120
  145. package/src/gestures/helpers/withDefault.ts +0 -3
  146. package/src/gestures/hooks/index.ts +0 -5
  147. package/src/gestures/hooks/useDrag.ts +0 -14
  148. package/src/gestures/hooks/useGesture.ts +0 -38
  149. package/src/gestures/hooks/useMouseMove.ts +0 -11
  150. package/src/gestures/hooks/useRecognizer.ts +0 -59
  151. package/src/gestures/hooks/useScroll.ts +0 -11
  152. package/src/gestures/hooks/useWheel.ts +0 -11
  153. package/src/gestures/types/index.d.ts +0 -49
  154. package/src/hooks/index.ts +0 -3
  155. package/src/hooks/useMeasure.ts +0 -132
  156. package/src/hooks/useOutsideClick.ts +0 -36
  157. package/src/hooks/useWindowDimension.ts +0 -58
  158. package/src/index.ts +0 -42
  159. package/src/utils/delay.ts +0 -9
  160. package/src/utils/index.ts +0 -1
  161. package/tsconfig.json +0 -24
@@ -1,232 +0,0 @@
1
- export const COLOR_NUMBER_REGEX =
2
- /[+-]?\d+(\.\d+)?|[\s]?\.\d+|#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})/gi;
3
- export const HEX_NAME_COLOR =
4
- /#[a-f\d]{3,}|transparent|aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|burntsienna|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|rebeccapurple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen/gi;
5
-
6
- interface classNameType {
7
- [name: string]: string;
8
- }
9
-
10
- // Named colors
11
- export const colorNames: classNameType = {
12
- transparent: "#00000000",
13
- aliceblue: "#f0f8ffff",
14
- antiquewhite: "#faebd7ff",
15
- aqua: "#00ffffff",
16
- aquamarine: "#7fffd4ff",
17
- azure: "#f0ffffff",
18
- beige: "#f5f5dcff",
19
- bisque: "#ffe4c4ff",
20
- black: "#000000ff",
21
- blanchedalmond: "#ffebcdff",
22
- blue: "#0000ffff",
23
- blueviolet: "#8a2be2ff",
24
- brown: "#a52a2aff",
25
- burlywood: "#deb887ff",
26
- burntsienna: "#ea7e5dff",
27
- cadetblue: "#5f9ea0ff",
28
- chartreuse: "#7fff00ff",
29
- chocolate: "#d2691eff",
30
- coral: "#ff7f50ff",
31
- cornflowerblue: "#6495edff",
32
- cornsilk: "#fff8dcff",
33
- crimson: "#dc143cff",
34
- cyan: "#00ffffff",
35
- darkblue: "#00008bff",
36
- darkcyan: "#008b8bff",
37
- darkgoldenrod: "#b8860bff",
38
- darkgray: "#a9a9a9ff",
39
- darkgreen: "#006400ff",
40
- darkgrey: "#a9a9a9ff",
41
- darkkhaki: "#bdb76bff",
42
- darkmagenta: "#8b008bff",
43
- darkolivegreen: "#556b2fff",
44
- darkorange: "#ff8c00ff",
45
- darkorchid: "#9932ccff",
46
- darkred: "#8b0000ff",
47
- darksalmon: "#e9967aff",
48
- darkseagreen: "#8fbc8fff",
49
- darkslateblue: "#483d8bff",
50
- darkslategray: "#2f4f4fff",
51
- darkslategrey: "#2f4f4fff",
52
- darkturquoise: "#00ced1ff",
53
- darkviolet: "#9400d3ff",
54
- deeppink: "#ff1493ff",
55
- deepskyblue: "#00bfffff",
56
- dimgray: "#696969ff",
57
- dimgrey: "#696969ff",
58
- dodgerblue: "#1e90ffff",
59
- firebrick: "#b22222ff",
60
- floralwhite: "#fffaf0ff",
61
- forestgreen: "#228b22ff",
62
- fuchsia: "#ff00ffff",
63
- gainsboro: "#dcdcdcff",
64
- ghostwhite: "#f8f8ffff",
65
- gold: "#ffd700ff",
66
- goldenrod: "#daa520ff",
67
- gray: "#808080ff",
68
- green: "#008000ff",
69
- greenyellow: "#adff2fff",
70
- grey: "#808080ff",
71
- honeydew: "#f0fff0ff",
72
- hotpink: "#ff69b4ff",
73
- indianred: "#cd5c5cff",
74
- indigo: "#4b0082ff",
75
- ivory: "#fffff0ff",
76
- khaki: "#f0e68cff",
77
- lavender: "#e6e6faff",
78
- lavenderblush: "#fff0f5ff",
79
- lawngreen: "#7cfc00ff",
80
- lemonchiffon: "#fffacdff",
81
- lightblue: "#add8e6ff",
82
- lightcoral: "#f08080ff",
83
- lightcyan: "#e0ffffff",
84
- lightgoldenrodyellow: "#fafad2ff",
85
- lightgray: "#d3d3d3ff",
86
- lightgreen: "#90ee90ff",
87
- lightgrey: "#d3d3d3ff",
88
- lightpink: "#ffb6c1ff",
89
- lightsalmon: "#ffa07aff",
90
- lightseagreen: "#20b2aaff",
91
- lightskyblue: "#87cefaff",
92
- lightslategray: "#778899ff",
93
- lightslategrey: "#778899ff",
94
- lightsteelblue: "#b0c4deff",
95
- lightyellow: "#ffffe0ff",
96
- lime: "#00ff00ff",
97
- limegreen: "#32cd32ff",
98
- linen: "#faf0e6ff",
99
- magenta: "#ff00ffff",
100
- maroon: "#800000ff",
101
- mediumaquamarine: "#66cdaaff",
102
- mediumblue: "#0000cdff",
103
- mediumorchid: "#ba55d3ff",
104
- mediumpurple: "#9370dbff",
105
- mediumseagreen: "#3cb371ff",
106
- mediumslateblue: "#7b68eeff",
107
- mediumspringgreen: "#00fa9aff",
108
- mediumturquoise: "#48d1ccff",
109
- mediumvioletred: "#c71585ff",
110
- midnightblue: "#191970ff",
111
- mintcream: "#f5fffaff",
112
- mistyrose: "#ffe4e1ff",
113
- moccasin: "#ffe4b5ff",
114
- navajowhite: "#ffdeadff",
115
- navy: "#000080ff",
116
- oldlace: "#fdf5e6ff",
117
- olive: "#808000ff",
118
- olivedrab: "#6b8e23ff",
119
- orange: "#ffa500ff",
120
- orangered: "#ff4500ff",
121
- orchid: "#da70d6ff",
122
- palegoldenrod: "#eee8aaff",
123
- palegreen: "#98fb98ff",
124
- paleturquoise: "#afeeeeff",
125
- palevioletred: "#db7093ff",
126
- papayawhip: "#ffefd5ff",
127
- peachpuff: "#ffdab9ff",
128
- peru: "#cd853fff",
129
- pink: "#ffc0cbff",
130
- plum: "#dda0ddff",
131
- powderblue: "#b0e0e6ff",
132
- purple: "#800080ff",
133
- rebeccapurple: "#663399ff",
134
- red: "#ff0000ff",
135
- rosybrown: "#bc8f8fff",
136
- royalblue: "#4169e1ff",
137
- saddlebrown: "#8b4513ff",
138
- salmon: "#fa8072ff",
139
- sandybrown: "#f4a460ff",
140
- seagreen: "#2e8b57ff",
141
- seashell: "#fff5eeff",
142
- sienna: "#a0522dff",
143
- silver: "#c0c0c0ff",
144
- skyblue: "#87ceebff",
145
- slateblue: "#6a5acdff",
146
- slategray: "#708090ff",
147
- slategrey: "#708090ff",
148
- snow: "#fffafaff",
149
- springgreen: "#00ff7fff",
150
- steelblue: "#4682b4ff",
151
- tan: "#d2b48cff",
152
- teal: "#008080ff",
153
- thistle: "#d8bfd8ff",
154
- tomato: "#ff6347ff",
155
- turquoise: "#40e0d0ff",
156
- violet: "#ee82eeff",
157
- wheat: "#f5deb3ff",
158
- white: "#ffffffff",
159
- whitesmoke: "#f5f5f5ff",
160
- yellow: "#ffff00ff",
161
- yellowgreen: "#9acd32ff",
162
- };
163
-
164
- function conv3to6(hex: string) {
165
- const regex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
166
-
167
- return hex.replace(regex, function (_, r, g, b) {
168
- return "#" + r + r + g + g + b + b;
169
- });
170
- }
171
-
172
- function conv6to8(hex: string) {
173
- if (hex.length === 7) {
174
- return hex + "FF";
175
- }
176
-
177
- return hex;
178
- }
179
-
180
- export function hexToRgba(hex: string) {
181
- const hex6: string = conv3to6(hex);
182
- const hex8: string = conv6to8(hex6);
183
- const hexRgba: any =
184
- /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex8);
185
-
186
- return {
187
- r: parseInt(hexRgba[1], 16),
188
- g: parseInt(hexRgba[2], 16),
189
- b: parseInt(hexRgba[3], 16),
190
- a: parseInt(hexRgba[4], 16) / 255,
191
- };
192
- }
193
-
194
- export function rgbaToHex(rgba: {
195
- r: number;
196
- g: number;
197
- b: number;
198
- a: number;
199
- }) {
200
- const { r, g, b, a } = rgba;
201
-
202
- const hexR = (r | (1 << 8)).toString(16).slice(1);
203
- const hexG = (g | (1 << 8)).toString(16).slice(1);
204
- const hexB = (b | (1 << 8)).toString(16).slice(1);
205
- const hexA = ((a * 255) | (1 << 8)).toString(16).slice(1);
206
-
207
- return "#" + hexR + hexG + hexB + hexA;
208
- }
209
-
210
- export function processColor(color: number | string) {
211
- if (typeof color === "number") {
212
- const alpha = ((color >> 24) & 255) / 255;
213
- const red = (color >> 16) & 255;
214
- const green = (color >> 8) & 255;
215
- const blue = color & 255;
216
-
217
- return { r: red, g: green, b: blue, a: alpha };
218
- } else {
219
- // If string then check whether it has # in 0 index
220
- if (color[0] === "#") {
221
- return hexToRgba(color);
222
- } else {
223
- // It is string color
224
- const hexColorName: string = colorNames[color];
225
- if (hexColorName) {
226
- return hexToRgba(hexColorName);
227
- } else {
228
- throw new Error("String cannot be parsed!");
229
- }
230
- }
231
- }
232
- }
@@ -1,395 +0,0 @@
1
- import {
2
- rgbaToHex,
3
- hexToRgba,
4
- COLOR_NUMBER_REGEX,
5
- HEX_NAME_COLOR,
6
- colorNames,
7
- } from './Colors';
8
- import { isFluidValue } from '../helpers';
9
- import { FluidValue } from '../controllers/FluidValue';
10
-
11
- type ExtrapolateType = 'identity' | 'extend' | 'clamp';
12
-
13
- const _internalInterpolate = (
14
- val: number,
15
- arr: any,
16
- extrapolateLeft: ExtrapolateType,
17
- extrapolateRight: ExtrapolateType
18
- ) => {
19
- const [inputMin, inputMax, outputMin, outputMax] = arr;
20
- let result: number = val;
21
-
22
- // EXTRAPOLATE
23
- if (result < inputMin) {
24
- if (extrapolateLeft === 'identity') {
25
- return result;
26
- } else if (extrapolateLeft === 'clamp') {
27
- result = inputMin;
28
- } else if (extrapolateLeft === 'extend') {
29
- // noop
30
- }
31
- }
32
-
33
- if (result > inputMax) {
34
- if (extrapolateRight === 'identity') {
35
- return result;
36
- } else if (extrapolateRight === 'clamp') {
37
- result = inputMax;
38
- } else if (extrapolateRight === 'extend') {
39
- // noop
40
- }
41
- }
42
-
43
- if (outputMin === outputMax) {
44
- return outputMin;
45
- }
46
-
47
- if (inputMin === inputMax) {
48
- if (val <= inputMin) {
49
- return outputMin;
50
- }
51
- return outputMax;
52
- }
53
-
54
- // Input Range
55
- if (inputMin === -Infinity) {
56
- result = -result;
57
- } else if (inputMax === Infinity) {
58
- result = result - inputMin;
59
- } else {
60
- result = (result - inputMin) / (inputMax - inputMin);
61
- }
62
-
63
- // Output Range
64
- if (outputMin === -Infinity) {
65
- result = -result;
66
- } else if (outputMax === Infinity) {
67
- result = result + outputMin;
68
- } else {
69
- result = result * (outputMax - outputMin) + outputMin;
70
- }
71
-
72
- return result;
73
- };
74
-
75
- const _getNarrowedInputArray = function (
76
- x: number,
77
- input: number[],
78
- output: Array<number | string>
79
- ): Array<number | string> {
80
- const length = input.length;
81
- let narrowedInput: Array<number | string> = [];
82
-
83
- // Boundaries
84
- if (x < input[0]) {
85
- narrowedInput = [input[0], input[1], output[0], output[1]];
86
- } else if (x > input[length - 1]) {
87
- narrowedInput = [
88
- input[length - 2],
89
- input[length - 1],
90
- output[length - 2],
91
- output[length - 1],
92
- ];
93
- }
94
-
95
- // Narrow the input and output ranges
96
- for (let i = 1; i < length; ++i) {
97
- if (x <= input[i]) {
98
- narrowedInput = [input[i - 1], input[i], output[i - 1], output[i]];
99
- break;
100
- }
101
- }
102
-
103
- return narrowedInput;
104
- };
105
-
106
- const _getColorInterpolate = (value: number, narrowedInput: Array<string>) => {
107
- const [inputMin, inputMax, outputMin, outputMax] = narrowedInput;
108
-
109
- const outputMinProcessed = hexToRgba(outputMin);
110
- const outputMaxProcessed = hexToRgba(outputMax);
111
-
112
- const red = _internalInterpolate(
113
- value,
114
- [inputMin, inputMax, outputMinProcessed.r, outputMaxProcessed.r],
115
- 'clamp',
116
- 'clamp'
117
- );
118
-
119
- const green = _internalInterpolate(
120
- value,
121
- [inputMin, inputMax, outputMinProcessed.g, outputMaxProcessed.g],
122
- 'clamp',
123
- 'clamp'
124
- );
125
-
126
- const blue = _internalInterpolate(
127
- value,
128
- [inputMin, inputMax, outputMinProcessed.b, outputMaxProcessed.b],
129
- 'clamp',
130
- 'clamp'
131
- );
132
-
133
- const alpha = _internalInterpolate(
134
- value,
135
- [inputMin, inputMax, outputMinProcessed.a, outputMaxProcessed.a],
136
- 'clamp',
137
- 'clamp'
138
- );
139
-
140
- return rgbaToHex({ r: red, g: green, b: blue, a: alpha });
141
- };
142
-
143
- const _getArrayInterpolate = (
144
- value: number,
145
- narrowedInput: Array<any>,
146
- _extrapolateLeft: ExtrapolateType,
147
- _extrapolateRight: ExtrapolateType
148
- ) => {
149
- const [inputMin, inputMax, outputMin, outputMax] = narrowedInput;
150
-
151
- if (outputMin.length === outputMax.length) {
152
- return outputMin.map((val: any, index: number) => {
153
- if (typeof val === 'string') {
154
- // IF IT IS STRING THEN IT MUST BE HEX COLOR
155
- return _getColorInterpolate(value, [
156
- inputMin,
157
- inputMax,
158
- val,
159
- outputMax[index],
160
- ]);
161
- } else {
162
- return _internalInterpolate(
163
- value,
164
- [inputMin, inputMax, val, outputMax[index]],
165
- _extrapolateLeft,
166
- _extrapolateRight
167
- );
168
- }
169
- });
170
- } else {
171
- throw new Error("Array length doesn't match");
172
- }
173
- };
174
-
175
- export const _getTemplateString = (str: string) => {
176
- return str.replace(COLOR_NUMBER_REGEX, '$');
177
- };
178
-
179
- const _getParsedStringArray = (str: any) => {
180
- return str.match(COLOR_NUMBER_REGEX).map((v: string) => {
181
- if (v.indexOf('#') !== -1) {
182
- return v;
183
- } else {
184
- return Number(v);
185
- }
186
- });
187
- };
188
-
189
- /**
190
- * Function returns if the template of two strings are matched
191
- * i.e. they can be interpolated
192
- * @param str1 - first string
193
- * @param str2 - second string
194
- * @returns boolean indicating two strings matched or not
195
- */
196
- export const stringMatched = (str1: string, str2: string) =>
197
- _getTemplateString(str1).trim().replace(/\s/g, '') ===
198
- _getTemplateString(str2).trim().replace(/\s/g, '');
199
-
200
- /**
201
- * Function which proccess the
202
- * hexadecimal colors to its proper formats
203
- * @param str - string
204
- * @returns hex color string
205
- */
206
- export const getProcessedColor = (str: string) => {
207
- return str.replace(HEX_NAME_COLOR, function (match: any) {
208
- if (match.indexOf('#') !== -1) {
209
- return rgbaToHex(hexToRgba(match));
210
- } else if (Object.prototype.hasOwnProperty.call(colorNames, match)) {
211
- return colorNames[match];
212
- } else {
213
- throw new Error('String cannot be parsed!');
214
- }
215
- });
216
- };
217
-
218
- export interface ExtrapolateConfig {
219
- extrapolate?: ExtrapolateType;
220
- extrapolateRight?: ExtrapolateType;
221
- extrapolateLeft?: ExtrapolateType;
222
- }
223
-
224
- /**
225
- * interpolateNumbers to interpolate the numeric value
226
- * @param value - number
227
- * @param inputRange
228
- * @param outputRange
229
- * @param extrapolateConfig
230
- * @returns - number | string
231
- */
232
- export function interpolateNumbers(
233
- value: number,
234
- inputRange: Array<number>,
235
- outputRange: Array<number | string>,
236
- extrapolateConfig?: ExtrapolateConfig
237
- ) {
238
- const extrapolate = extrapolateConfig?.extrapolate;
239
- const extrapolateLeft = extrapolateConfig?.extrapolateLeft;
240
- const extrapolateRight = extrapolateConfig?.extrapolateRight;
241
-
242
- const narrowedInput = _getNarrowedInputArray(value, inputRange, outputRange);
243
-
244
- let _extrapolateLeft: ExtrapolateType = 'extend';
245
- if (extrapolateLeft !== undefined) {
246
- _extrapolateLeft = extrapolateLeft;
247
- } else if (extrapolate !== undefined) {
248
- _extrapolateLeft = extrapolate;
249
- }
250
-
251
- let _extrapolateRight: ExtrapolateType = 'extend';
252
- if (extrapolateRight !== undefined) {
253
- _extrapolateRight = extrapolateRight;
254
- } else if (extrapolate !== undefined) {
255
- _extrapolateRight = extrapolate;
256
- }
257
-
258
- if (outputRange.length) {
259
- if (typeof outputRange[0] === 'number') {
260
- return _internalInterpolate(
261
- value,
262
- narrowedInput,
263
- _extrapolateLeft,
264
- _extrapolateRight
265
- );
266
- } else if (Array.isArray(outputRange[0])) {
267
- return _getArrayInterpolate(
268
- value,
269
- narrowedInput,
270
- _extrapolateLeft,
271
- _extrapolateRight
272
- );
273
- } else {
274
- const [inputMin, inputMax, outputMin, outputMax] = narrowedInput;
275
-
276
- const processedOutputMin = getProcessedColor(outputMin as string);
277
- const processedOutputMax = getProcessedColor(outputMax as string);
278
-
279
- let templateString = _getTemplateString(processedOutputMin);
280
-
281
- if (stringMatched(processedOutputMin, processedOutputMax)) {
282
- const outputMinParsed = _getParsedStringArray(processedOutputMin);
283
- const outputMaxParsed = _getParsedStringArray(processedOutputMax);
284
-
285
- const result = _getArrayInterpolate(
286
- value,
287
- [inputMin, inputMax, outputMinParsed, outputMaxParsed],
288
- _extrapolateLeft,
289
- _extrapolateRight
290
- );
291
-
292
- for (const v of result) templateString = templateString.replace('$', v);
293
- return templateString;
294
- } else {
295
- throw new Error("Output range doesn't match string format!");
296
- }
297
- }
298
- } else {
299
- throw new Error('Output range cannot be Empty');
300
- }
301
- }
302
-
303
- /**
304
- * interpolateTransitionValue to interpolating TransitionValue type value
305
- * @param value
306
- * @param inputRange
307
- * @param outputRange
308
- * @param extrapolateConfig
309
- * @returns TransitionValue
310
- */
311
- export const interpolateTransitionValue = (
312
- value: FluidValue,
313
- inputRange: Array<number>,
314
- outputRange: Array<number | string>,
315
- extrapolateConfig?: ExtrapolateConfig
316
- ) => {
317
- return {
318
- ...value,
319
- isInterpolation: true,
320
- interpolationConfig: {
321
- inputRange,
322
- outputRange,
323
- extrapolateConfig,
324
- },
325
- };
326
- };
327
-
328
- /**
329
- * interpolate function to interpolate both transition
330
- * as well as numerical value
331
- * @param value
332
- * @param inputRange
333
- * @param outputRange
334
- * @param extrapolateConfig
335
- */
336
- export const interpolate = (
337
- value: number | FluidValue,
338
- inputRange: Array<number>,
339
- outputRange: Array<number | string>,
340
- extrapolateConfig?: ExtrapolateConfig
341
- ) => {
342
- if (isFluidValue(value)) {
343
- return interpolateTransitionValue(
344
- value as FluidValue,
345
- inputRange,
346
- outputRange,
347
- extrapolateConfig
348
- );
349
- } else if (typeof value === 'number') {
350
- return interpolateNumbers(
351
- value,
352
- inputRange,
353
- outputRange,
354
- extrapolateConfig
355
- );
356
- } else {
357
- throw new Error(`'${typeof value}' cannot be interpolated!`);
358
- }
359
- };
360
-
361
- /**
362
- * Determines if two values can be interpolated.
363
- * This function checks if two values, either numbers or strings,
364
- * can be interpolated by ensuring they are of the same type and, in the case of strings,
365
- * that they are compatible for interpolation based on processed color values.
366
- *
367
- * @param previousValue - The previous value to compare. Can be a number or a string.
368
- * @param newValue - The new value to compare. Can be a number or a string.
369
- * @returns True if interpolation is possible, false otherwise.
370
- */
371
- export function canInterpolate(
372
- previousValue: number | string,
373
- newValue: number | string
374
- ): boolean {
375
- if (typeof previousValue !== typeof newValue) {
376
- return false;
377
- }
378
-
379
- if (typeof newValue === 'number') {
380
- return true;
381
- }
382
-
383
- if (typeof previousValue === 'string') {
384
- const processedPreviousValue = getProcessedColor(previousValue);
385
- const processedNewValue = getProcessedColor(newValue);
386
-
387
- return (
388
- processedPreviousValue !== processedNewValue &&
389
- _getTemplateString(processedPreviousValue) ===
390
- _getTemplateString(processedNewValue)
391
- );
392
- }
393
-
394
- return false;
395
- }
@@ -1,35 +0,0 @@
1
- import { rgbaToHex, hexToRgba } from '../Colors';
2
-
3
- describe('Colors', () => {
4
- it('rgbaToHex() function to convert rgba object to hex string', () => {
5
- expect(rgbaToHex({ r: 255, g: 255, b: 255, a: 1 })).toStrictEqual(
6
- '#ffffffff'
7
- );
8
- expect(rgbaToHex({ r: 252, g: 186, b: 3, a: 1 })).toStrictEqual(
9
- '#fcba03ff'
10
- );
11
- });
12
-
13
- it('hexToRgba() function to convert hex string to rgba object', () => {
14
- expect(hexToRgba('#ffffff')).toStrictEqual({
15
- r: 255,
16
- g: 255,
17
- b: 255,
18
- a: 1,
19
- });
20
-
21
- expect(hexToRgba('#fff')).toStrictEqual({
22
- r: 255,
23
- g: 255,
24
- b: 255,
25
- a: 1,
26
- });
27
-
28
- expect(hexToRgba('#2a6e55')).toStrictEqual({
29
- r: 42,
30
- g: 110,
31
- b: 85,
32
- a: 1,
33
- });
34
- });
35
- });