diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-09-23 16:04:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-23 16:04:37 -0700 |
commit | a0e20a6b0ffdff1c27ca2f5e53b73b66799d12e1 (patch) | |
tree | b4610ab4eb5a675c5233ccafdf9d62ec99917a49 /platform/darwin/scripts | |
parent | 8bc8713e70e52ee8a8653b50ad8cf4be40beb9a1 (diff) | |
download | qtlocation-mapboxgl-a0e20a6b0ffdff1c27ca2f5e53b73b66799d12e1.tar.gz |
[ios, macos] Allow full hexadecimal colors in layer documentation (#6444)
* [ios, macos] Allow full hex colors in layer docs
CSS hexadecimal RGB syntax can contain all the hexadecimal digits, not just the decimal digits.
* [ios, macos] Parse colors with csscolorparser
Diffstat (limited to 'platform/darwin/scripts')
-rw-r--r-- | platform/darwin/scripts/generate-style-code.js | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index e934b39da0..023bf648c6 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -3,6 +3,7 @@ const fs = require('fs'); const ejs = require('ejs'); const spec = require('mapbox-gl-style-spec').latest; +const colorParser = require('csscolorparser'); const prefix = 'MGL'; const suffix = 'StyleLayer'; @@ -112,25 +113,13 @@ global.propertyReqs = function (property, layoutPropertiesByName, type) { }; global.parseColor = function (str) { - let m = str.match(/^#(\d\d)(\d\d)(\d\d)$/); - if (m) { - return { - r: parseInt(m[1], 16) / 255, - g: parseInt(m[2], 16) / 255, - b: parseInt(m[3], 16) / 255, - a: 1.0, - }; - } - - m = str.match(/^rgba\(\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+),\s*([\d.]+)\s*\)$/); - if (m) { - return { - r: parseFloat(m[1]) / 255, - g: parseFloat(m[2]) / 255, - b: parseFloat(m[3]) / 255, - a: parseFloat(m[4]), - }; - } + let color = colorParser.parseCSSColor(str); + return { + r: color[0] / 255, + g: color[1] / 255, + b: color[2] / 255, + a: color[3], + }; }; global.describeValue = function (value, property, layerType) { |