| 1228 | // Input: "transparent" |
| 1229 | // Output: [0, 0, 0, 0.0] |
| 1230 | export function parseColor(colorString) { |
| 1231 | if (colorString === "transparent") { |
| 1232 | return [0, 0, 0, 0.0]; |
| 1233 | } else if (colorString.indexOf("rgb") !== 0) { |
| 1234 | throw "Expected a CSS rgb string but found: " + colorString; |
| 1235 | } |
| 1236 | var start = colorString.indexOf("(") + 1; |
| 1237 | var end = colorString.indexOf(")"); |
| 1238 | var nums = colorString.substring(start, end).split(","); |
| 1239 | return [ |
| 1240 | parseInt(nums[0].trim(), 10), |
| 1241 | parseInt(nums[1].trim(), 10), |
| 1242 | parseInt(nums[2].trim(), 10), |
| 1243 | nums.length < 4 ? 1.0 : parseFloat(nums[3].trim()) |
| 1244 | ]; |
| 1245 | }; |
| 1246 | |
| 1247 | function normalizedCssValue(attributeName, value) { |
| 1248 | var div = document.createElement("div"); |