react-ui-animate 2.0.0-rc.7 → 3.0.0-rc.0

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 (222) hide show
  1. package/.vscode/settings.json +3 -3
  2. package/LICENSE +21 -21
  3. package/README.md +115 -115
  4. package/dist/animation/animationType.d.ts +15 -15
  5. package/dist/animation/core/animation/Animation.d.ts +16 -0
  6. package/dist/animation/core/animation/FluidValue.d.ts +21 -0
  7. package/dist/animation/core/animation/RequestAnimationFrame.d.ts +8 -0
  8. package/dist/animation/core/animation/SpringAnimation.d.ts +41 -0
  9. package/dist/animation/core/animation/TimingAnimation.d.ts +35 -0
  10. package/dist/animation/core/animation/TransitionValue.d.ts +21 -0
  11. package/dist/animation/core/controllers/Animation.d.ts +16 -0
  12. package/dist/animation/core/controllers/FluidValue.d.ts +32 -0
  13. package/dist/animation/core/controllers/RequestAnimationFrame.d.ts +8 -0
  14. package/dist/animation/core/controllers/SpringAnimation.d.ts +41 -0
  15. package/dist/animation/core/controllers/TimingAnimation.d.ts +35 -0
  16. package/dist/animation/core/easing/Bezier.d.ts +8 -0
  17. package/dist/animation/core/easing/Easing.d.ts +40 -0
  18. package/dist/animation/core/helpers/camelCaseToKebabCase.d.ts +8 -0
  19. package/dist/animation/core/helpers/camelToDash.d.ts +7 -0
  20. package/dist/animation/core/helpers/canInterpolate.d.ts +11 -0
  21. package/dist/animation/core/helpers/getAnimatableObject.d.ts +22 -0
  22. package/dist/animation/core/helpers/getCleanProps.d.ts +10 -0
  23. package/dist/animation/core/helpers/getCssValue.d.ts +8 -0
  24. package/dist/animation/core/helpers/getNonAnimatableStyle.d.ts +6 -0
  25. package/dist/animation/core/helpers/index.d.ts +5 -0
  26. package/dist/animation/core/helpers/isDefined.d.ts +12 -0
  27. package/dist/animation/core/helpers/isFluidValue.d.ts +6 -0
  28. package/dist/animation/core/index.d.ts +11 -0
  29. package/dist/animation/core/interpolation/Colors.d.ts +25 -0
  30. package/dist/animation/core/interpolation/Interpolation.d.ts +80 -0
  31. package/dist/animation/core/interpolation/__tests__/Colors.test.d.ts +1 -0
  32. package/dist/animation/core/react/Tags.d.ts +3 -0
  33. package/dist/animation/core/react/TransformStyles.d.ts +8 -0
  34. package/dist/animation/core/react/animated.d.ts +29 -0
  35. package/dist/animation/core/react/combineRefs.d.ts +2 -0
  36. package/dist/animation/core/react/fluid.d.ts +6 -0
  37. package/dist/animation/core/react/functions/camelToDash.d.ts +7 -0
  38. package/dist/animation/core/react/functions/getAnimatableObject.d.ts +22 -0
  39. package/dist/animation/core/react/functions/getCleanProps.d.ts +4 -0
  40. package/dist/animation/core/react/functions/getCssValue.d.ts +8 -0
  41. package/dist/animation/core/react/functions/getNonAnimatableStyle.d.ts +6 -0
  42. package/dist/animation/core/react/functions/index.d.ts +7 -0
  43. package/dist/animation/core/react/functions/isDefined.d.ts +6 -0
  44. package/dist/animation/core/react/functions/isTransitionValue.d.ts +6 -0
  45. package/dist/animation/core/react/helpers/camelToDash.d.ts +7 -0
  46. package/dist/animation/core/react/helpers/canInterpolate.d.ts +7 -0
  47. package/dist/animation/core/react/helpers/getAnimatableObject.d.ts +22 -0
  48. package/dist/animation/core/react/helpers/getCleanProps.d.ts +4 -0
  49. package/dist/animation/core/react/helpers/getCssValue.d.ts +8 -0
  50. package/dist/animation/core/react/helpers/getNonAnimatableStyle.d.ts +6 -0
  51. package/dist/animation/core/react/helpers/index.d.ts +7 -0
  52. package/dist/animation/core/react/helpers/isDefined.d.ts +6 -0
  53. package/dist/animation/core/react/helpers/isFluidValue.d.ts +6 -0
  54. package/dist/animation/core/react/helpers/isTransitionValue.d.ts +6 -0
  55. package/dist/animation/core/react/makeFluid.d.ts +30 -0
  56. package/dist/animation/core/react/transforms.d.ts +6 -0
  57. package/dist/animation/core/react/useFluidValue.d.ts +9 -0
  58. package/dist/animation/core/react/useMount.d.ts +20 -0
  59. package/dist/animation/core/react/useMounts.d.ts +26 -0
  60. package/dist/animation/core/react/useTransition.d.ts +9 -0
  61. package/dist/animation/core/react/useTransitions.d.ts +11 -0
  62. package/dist/animation/core/types/animation.d.ts +54 -0
  63. package/dist/animation/core/types/common.d.ts +4 -0
  64. package/dist/animation/core/types/fluid.d.ts +19 -0
  65. package/dist/animation/core/types/index.d.ts +2 -0
  66. package/dist/animation/getInitialConfig.d.ts +3 -3
  67. package/dist/animation/index.d.ts +6 -6
  68. package/dist/animation/interpolation.d.ts +21 -21
  69. package/dist/animation/lib/animationType.d.ts +15 -0
  70. package/dist/animation/lib/getInitialConfig.d.ts +3 -0
  71. package/dist/animation/lib/index.d.ts +5 -0
  72. package/dist/animation/lib/interpolation.d.ts +20 -0
  73. package/dist/animation/lib/modules/AnimatedBlock.d.ts +8 -0
  74. package/dist/animation/lib/modules/AnimatedImage.d.ts +8 -0
  75. package/dist/animation/lib/modules/AnimatedInline.d.ts +8 -0
  76. package/dist/animation/lib/modules/MountedBlock.d.ts +29 -0
  77. package/dist/animation/lib/modules/ScrollableBlock.d.ts +22 -0
  78. package/dist/animation/lib/modules/TransitionBlock.d.ts +18 -0
  79. package/dist/animation/lib/modules/index.d.ts +6 -0
  80. package/dist/animation/lib/useAnimatedValue.d.ts +17 -0
  81. package/dist/animation/lib/useMountedValue.d.ts +14 -0
  82. package/dist/animation/modules/AnimatedBlock.d.ts +8 -8
  83. package/dist/animation/modules/AnimatedImage.d.ts +8 -8
  84. package/dist/animation/modules/AnimatedInline.d.ts +8 -8
  85. package/dist/animation/modules/MountedBlock.d.ts +29 -18
  86. package/dist/animation/modules/ScrollableBlock.d.ts +21 -21
  87. package/dist/animation/modules/TransitionBlock.d.ts +17 -17
  88. package/dist/animation/modules/index.d.ts +6 -6
  89. package/dist/animation/useAnimatedValue.d.ts +22 -22
  90. package/dist/animation/useMountedValue.d.ts +15 -15
  91. package/dist/gestures/controllers/DragGesture.d.ts +17 -17
  92. package/dist/gestures/controllers/Gesture.d.ts +20 -20
  93. package/dist/gestures/controllers/MouseMoveGesture.d.ts +13 -13
  94. package/dist/gestures/controllers/ScrollGesture.d.ts +14 -14
  95. package/dist/gestures/controllers/WheelGesture.d.ts +15 -15
  96. package/dist/gestures/controllers/index.d.ts +4 -4
  97. package/dist/gestures/eventAttacher.d.ts +11 -11
  98. package/dist/gestures/helpers/eventAttacher.d.ts +11 -0
  99. package/dist/gestures/helpers/index.d.ts +1 -0
  100. package/dist/gestures/helpers/math.d.ts +34 -0
  101. package/dist/gestures/helpers/withDefault.d.ts +4 -0
  102. package/dist/gestures/hooks/index.d.ts +5 -5
  103. package/dist/gestures/hooks/useDrag.d.ts +4 -4
  104. package/dist/gestures/hooks/useGesture.d.ts +9 -9
  105. package/dist/gestures/hooks/useMouseMove.d.ts +4 -4
  106. package/dist/gestures/hooks/useRecognizer.d.ts +10 -10
  107. package/dist/gestures/hooks/useScroll.d.ts +4 -4
  108. package/dist/gestures/hooks/useWheel.d.ts +4 -4
  109. package/dist/gestures/index.d.ts +2 -2
  110. package/dist/gestures/math.d.ts +34 -34
  111. package/dist/gestures/types.d.ts +51 -51
  112. package/dist/gestures/withDefault.d.ts +4 -4
  113. package/dist/hooks/index.d.ts +3 -3
  114. package/dist/hooks/useMeasure.d.ts +14 -14
  115. package/dist/hooks/useOutsideClick.d.ts +2 -2
  116. package/dist/hooks/useWindowDimension.d.ts +9 -9
  117. package/dist/index.d.ts +9 -5
  118. package/dist/index.js +2758 -1052
  119. package/dist/index.js.map +1 -1
  120. package/dist/utils/delay.d.ts +5 -5
  121. package/dist/utils/index.d.ts +1 -2
  122. package/dist/utils/isDefined.d.ts +1 -1
  123. package/ecosystem.config.js +12 -0
  124. package/example/README.md +46 -0
  125. package/example/package-lock.json +19597 -0
  126. package/example/package.json +45 -0
  127. package/example/public/favicon.ico +0 -0
  128. package/example/public/index.html +20 -0
  129. package/example/public/logo192.png +0 -0
  130. package/example/public/logo512.png +0 -0
  131. package/example/public/manifest.json +25 -0
  132. package/example/public/robots.txt +3 -0
  133. package/example/src/App.tsx +41 -0
  134. package/example/src/components/Draggable.tsx +46 -0
  135. package/example/src/components/Gestures.tsx +151 -0
  136. package/example/src/components/Interpolation.tsx +21 -0
  137. package/example/src/components/Loop.tsx +48 -0
  138. package/example/src/components/MountedBlock.tsx +25 -0
  139. package/example/src/components/MouseMove.tsx +59 -0
  140. package/example/src/components/MultistageTransition.tsx +34 -0
  141. package/example/src/components/Scroll.tsx +39 -0
  142. package/example/src/components/ScrollableBlock.tsx +27 -0
  143. package/example/src/components/SnapTo.tsx +55 -0
  144. package/example/src/components/TransitionBlock.tsx +37 -0
  145. package/example/src/components/Wheel.tsx +39 -0
  146. package/example/src/components/index.ts +18 -0
  147. package/example/src/components/svgLine.tsx +48 -0
  148. package/example/src/components/useAnimatedValue.tsx +57 -0
  149. package/example/src/components/useMountedValue.tsx +62 -0
  150. package/example/src/index.css +8 -0
  151. package/example/src/index.tsx +16 -0
  152. package/example/tsconfig.json +26 -0
  153. package/package.json +48 -48
  154. package/{rollup.config.js → rollup.config.mjs} +18 -18
  155. package/src/animation/core/controllers/Animation.ts +27 -0
  156. package/src/animation/core/controllers/FluidValue.ts +97 -0
  157. package/src/animation/core/controllers/RequestAnimationFrame.ts +13 -0
  158. package/src/animation/core/controllers/SpringAnimation.ts +218 -0
  159. package/src/animation/core/controllers/TimingAnimation.ts +152 -0
  160. package/src/animation/core/easing/Bezier.ts +146 -0
  161. package/src/animation/core/easing/Easing.ts +132 -0
  162. package/src/animation/core/helpers/camelCaseToKebabCase.ts +10 -0
  163. package/src/animation/core/helpers/getCleanProps.ts +16 -0
  164. package/src/animation/core/helpers/getCssValue.ts +60 -0
  165. package/src/animation/core/helpers/index.ts +5 -0
  166. package/src/animation/core/helpers/isDefined.ts +14 -0
  167. package/src/animation/core/helpers/isFluidValue.ts +11 -0
  168. package/src/animation/core/index.ts +16 -0
  169. package/src/animation/core/interpolation/Colors.ts +232 -0
  170. package/src/animation/core/interpolation/Interpolation.ts +395 -0
  171. package/src/animation/core/interpolation/__tests__/Colors.test.tsx +35 -0
  172. package/src/animation/core/react/fluid.ts +197 -0
  173. package/src/animation/core/react/makeFluid.ts +294 -0
  174. package/src/animation/core/react/transforms.ts +90 -0
  175. package/src/animation/core/react/useFluidValue.ts +43 -0
  176. package/src/animation/core/react/useMount.ts +58 -0
  177. package/src/animation/core/types/animation.d.ts +56 -0
  178. package/src/animation/core/types/common.d.ts +4 -0
  179. package/src/animation/core/types/fluid.d.ts +38 -0
  180. package/src/animation/{animationType.ts → lib/animationType.ts} +17 -17
  181. package/src/animation/{getInitialConfig.ts → lib/getInitialConfig.ts} +61 -61
  182. package/src/animation/lib/index.ts +12 -0
  183. package/src/animation/{interpolation.ts → lib/interpolation.ts} +47 -48
  184. package/src/animation/{modules → lib/modules}/AnimatedBlock.ts +8 -8
  185. package/src/animation/{modules → lib/modules}/AnimatedImage.ts +8 -8
  186. package/src/animation/{modules → lib/modules}/AnimatedInline.ts +8 -8
  187. package/src/animation/lib/modules/MountedBlock.tsx +51 -0
  188. package/src/animation/{modules → lib/modules}/ScrollableBlock.tsx +68 -69
  189. package/src/animation/{modules → lib/modules}/TransitionBlock.tsx +28 -29
  190. package/src/animation/{modules → lib/modules}/index.ts +6 -6
  191. package/src/animation/{useAnimatedValue.ts → lib/useAnimatedValue.ts} +60 -71
  192. package/src/animation/{useMountedValue.ts → lib/useMountedValue.ts} +18 -19
  193. package/src/gestures/controllers/DragGesture.ts +178 -177
  194. package/src/gestures/controllers/Gesture.ts +54 -54
  195. package/src/gestures/controllers/MouseMoveGesture.ts +111 -111
  196. package/src/gestures/controllers/ScrollGesture.ts +107 -107
  197. package/src/gestures/controllers/WheelGesture.ts +123 -123
  198. package/src/gestures/controllers/index.ts +4 -4
  199. package/src/gestures/{eventAttacher.ts → helpers/eventAttacher.ts} +67 -67
  200. package/src/gestures/helpers/index.ts +1 -0
  201. package/src/gestures/{math.ts → helpers/math.ts} +120 -120
  202. package/src/gestures/{withDefault.ts → helpers/withDefault.ts} +3 -3
  203. package/src/gestures/hooks/index.ts +5 -5
  204. package/src/gestures/hooks/useDrag.ts +14 -14
  205. package/src/gestures/hooks/useGesture.ts +38 -38
  206. package/src/gestures/hooks/useMouseMove.ts +11 -11
  207. package/src/gestures/hooks/useRecognizer.ts +59 -59
  208. package/src/gestures/hooks/useScroll.ts +11 -11
  209. package/src/gestures/hooks/useWheel.ts +11 -11
  210. package/src/gestures/{types.ts → types/index.d.ts} +49 -49
  211. package/src/hooks/index.ts +3 -3
  212. package/src/hooks/useMeasure.ts +132 -133
  213. package/src/hooks/useOutsideClick.ts +36 -36
  214. package/src/hooks/useWindowDimension.ts +58 -59
  215. package/src/index.ts +42 -5
  216. package/src/utils/delay.ts +9 -9
  217. package/src/utils/index.ts +1 -2
  218. package/tsconfig.json +24 -25
  219. package/src/animation/index.ts +0 -10
  220. package/src/animation/modules/MountedBlock.tsx +0 -25
  221. package/src/gestures/index.ts +0 -2
  222. package/src/utils/isDefined.ts +0 -4
@@ -0,0 +1,60 @@
1
+ const unitlessStyleProps = [
2
+ 'borderImageOutset',
3
+ 'borderImageSlice',
4
+ 'borderImageWidth',
5
+ 'fontWeight',
6
+ 'lineHeight',
7
+ 'opacity',
8
+ 'orphans',
9
+ 'tabSize',
10
+ 'widows',
11
+ 'zIndex',
12
+ 'zoom',
13
+ // SVG-related properties
14
+ 'fillOpacity',
15
+ 'floodOpacity',
16
+ 'stopOpacity',
17
+ 'strokeDasharray',
18
+ 'strokeDashoffset',
19
+ 'strokeMiterlimit',
20
+ 'strokeOpacity',
21
+ 'strokeWidth',
22
+ // prefixed
23
+ 'animationIterationCount',
24
+ 'boxFlex',
25
+ 'boxFlexGroup',
26
+ 'boxOrdinalGroup',
27
+ 'columnCount',
28
+ 'flex',
29
+ 'flexGrow',
30
+ 'flexPositive',
31
+ 'flexShrink',
32
+ 'flexNegative',
33
+ 'flexOrder',
34
+ 'gridRow',
35
+ 'gridColumn',
36
+ 'order',
37
+ 'lineClamp',
38
+ ];
39
+
40
+ /**
41
+ * getCssValue() function to get css value with unit or without unit
42
+ * it is only for style property - it cannot be used with transform keys
43
+ * @param property - style property
44
+ * @param value - style value
45
+ * @returns - value with unit or without unit
46
+ */
47
+ export function getCssValue(property: string, value: number | string) {
48
+ let cssValue;
49
+ if (typeof value === 'number') {
50
+ if (unitlessStyleProps.includes(property)) {
51
+ cssValue = value;
52
+ } else {
53
+ cssValue = value + 'px';
54
+ }
55
+ } else {
56
+ cssValue = value;
57
+ }
58
+
59
+ return cssValue;
60
+ }
@@ -0,0 +1,5 @@
1
+ export * from './getCleanProps';
2
+ export * from './getCssValue';
3
+ export * from './isDefined';
4
+ export * from './isFluidValue';
5
+ export * from './camelCaseToKebabCase';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Checks if a value is defined (not null or undefined).
3
+ *
4
+ * This utility function helps in determining whether a given value is neither `null` nor `undefined`.
5
+ * It can be useful for validation checks to ensure that a value is properly defined before proceeding
6
+ * with further operations.
7
+ *
8
+ * @param {T} value - The value to check.
9
+ * @returns {boolean} - Returns `true` if the value is neither `null` nor `undefined`, otherwise returns `false`.
10
+ *
11
+ */
12
+ export const isDefined = <T>(value: T) => {
13
+ return value !== null && value !== undefined;
14
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * isFluidValue to check the value is FluidValue or not
3
+ * @param value - any
4
+ * @returns - boolean
5
+ */
6
+ export const isFluidValue = (value: any) => {
7
+ return (
8
+ typeof value === 'object' &&
9
+ Object.prototype.hasOwnProperty.call(value, '_subscribe')
10
+ );
11
+ };
@@ -0,0 +1,16 @@
1
+ // React
2
+ export { fluid } from './react/fluid';
3
+ export { makeFluid } from './react/makeFluid';
4
+ export { useFluidValue } from './react/useFluidValue';
5
+ export { useMount } from './react/useMount';
6
+
7
+ // Helpers and Utilities
8
+ export { isFluidValue } from './helpers/isFluidValue';
9
+ export { Easing } from './easing/Easing';
10
+ export { interpolate } from './interpolation/Interpolation';
11
+ export { FluidValue } from './controllers/FluidValue';
12
+
13
+ // Types
14
+ export type { FluidValueConfig } from './types/animation';
15
+ export type { UseMountConfig } from './react/useMount';
16
+ export type { ExtrapolateConfig } from './interpolation/Interpolation';
@@ -0,0 +1,232 @@
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
+ }