| // Problem: https://github.com/animatedjs/animated/pull/102 | |
| // Solution: https://stackoverflow.com/questions/638565/parsing-scientific-notation-sensibly/658662 | |
| export const numberRegex = /[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g | |
| // Covers rgb, rgba, hsl, hsla | |
| // Taken from https://gist.github.com/olmokramer/82ccce673f86db7cda5e | |
| export const colorRegex = | |
| /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))/gi | |
| // Gets numbers with units when specified | |
| export const unitRegex = new RegExp(`(${numberRegex.source})(%|[a-z]+)`, 'i') | |
| // get values of rgba string | |
| export const rgbaRegex = | |
| /rgba\(([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+)\)/gi | |
| /** | |
| * Parse special CSS variable format into a CSS token and a fallback. | |
| * | |
| * ``` | |
| * `var(--foo, #fff)` => [`--foo`, '#fff'] | |
| * ``` | |
| * | |
| */ | |
| export const cssVariableRegex = | |
| /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/ | |