* Guesses the input color format and returns a Color instance. * @param {string} value * @returns {Color}
(value)
| 41 | * @returns {Color} |
| 42 | */ |
| 43 | static fromString(value) { |
| 44 | const v = String(value) |
| 45 | for (const conv of [ |
| 46 | Color.#fromRgb, |
| 47 | Color.#fromRgbPct, |
| 48 | Color.#fromRgba, |
| 49 | Color.#fromRgbaPct, |
| 50 | Color.#fromHex6, |
| 51 | Color.#fromHex3, |
| 52 | Color.#fromHsl, |
| 53 | Color.#fromHsla, |
| 54 | Color.#fromNamed, |
| 55 | ]) { |
| 56 | const c = conv(v) |
| 57 | if (c) return c |
| 58 | } |
| 59 | throw new Error(`Did not know how to convert ${value} into color`) |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Sets opacity (alpha channel). |