Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed color creation from CSS color string with modern "space-separated" syntax #11271

Merged
merged 28 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5106280
Fix `Color.fromCssColorString` in case of parsing `rgb(a)`/`hsl(a)` C…
aerialist7 May 7, 2023
561220c
Add `Alexander Popoff` (@aerialist7) to the list of contributors
aerialist7 May 7, 2023
0742c2e
Escaping
aerialist7 May 11, 2023
5c4d80b
Disable `/` parsing
aerialist7 May 14, 2023
f41a023
Fix regexps
aerialist7 May 14, 2023
0305583
Only remove surrounding whitespace from color strings
aerialist7 May 24, 2023
8d57b4f
Enable `/` parsing
aerialist7 May 24, 2023
6e75ce9
Formatting
aerialist7 May 25, 2023
5d17b06
Make sure availability tiles are loaded before deciding there is no t…
ggetz May 8, 2023
2beefd1
Return the correct promise
ggetz May 18, 2023
bfb121a
Update CHANGES.md
ggetz May 18, 2023
7946505
Adjust camera controls for 3D
ggetz May 3, 2023
9dd48b6
Use first picked position in drag when possible
ggetz May 5, 2023
62ef59a
Use pick position direction for panning
ggetz May 9, 2023
4c63490
Only use new camera controls when globe is false
ggetz May 10, 2023
4d6d3e7
Spin3d should fallback to old behavior when globe is defined
ggetz May 10, 2023
b2cc3ae
pick globe on spin3d
ggetz May 10, 2023
9ca84eb
Fallback to old behavior for spin3d
ggetz May 10, 2023
de048c8
Updates for Google Photorealistic 3D Tiles
ggetz May 10, 2023
edf6aef
Updates for 1.105.1 release
ggetz May 10, 2023
9c62cce
Fix doc for Entity.prototype.computeModelMatrix (#11277)
jjhembd May 11, 2023
02d5cb4
Update widgets version
ggetz May 15, 2023
2dc1744
fixed datasource display visualizer callback typedef (#11294)
bkuster May 18, 2023
2cb1b4d
Add TextureUniform type for setUniform value type (#11284)
fredj May 18, 2023
fd63854
Add unit test
ggetz May 19, 2023
526fc5c
Enable standard derivatives extension in demodernizeShader
May 24, 2023
4f029bb
Merge branch 'main' into space-separated-css-colors-support
aerialist7 May 25, 2023
d49b8f2
Update CHANGES.md
aerialist7 May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

##### Fixes :wrench:

- Fixed color creation from CSS color string with modern "space-separated" syntax. [#11271](https://github.com/CesiumGS/cesium/pull/11271)
- Fixed a race condition when loading cut-out terrain. [#11296](https://github.com/CesiumGS/cesium/pull/11296)

### 1.105.2 - 2023-05-15
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [王秋艳](https://github.com/wqy224488)
- [Jason Summercamp](https://github.com/fullstacc)
- [Shapovalov Kirill](https://github.com/ShapovalovKL)
- [Alexander Popoff](https://github.com/aerialist7)
8 changes: 4 additions & 4 deletions packages/engine/Source/Core/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ const rgbaMatcher = /^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i;
//#rrggbbaa
const rrggbbaaMatcher = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i;
//rgb(), rgba(), or rgb%()
const rgbParenthesesMatcher = /^rgba?\(\s*([0-9.]+%?)\s*,\s*([0-9.]+%?)\s*,\s*([0-9.]+%?)(?:\s*,\s*([0-9.]+))?\s*\)$/i;
const rgbParenthesesMatcher = /^rgba?\s*\(\s*([0-9.]+%?)\s*[,\s]+\s*([0-9.]+%?)\s*[,\s]+\s*([0-9.]+%?)(?:\s*[,\s/]+\s*([0-9.]+))?\s*\)$/i;
//hsl() or hsla()
const hslParenthesesMatcher = /^hsla?\(\s*([0-9.]+)\s*,\s*([0-9.]+%)\s*,\s*([0-9.]+%)(?:\s*,\s*([0-9.]+))?\s*\)$/i;
const hslParenthesesMatcher = /^hsla?\s*\(\s*([0-9.]+)\s*[,\s]+\s*([0-9.]+%)\s*[,\s]+\s*([0-9.]+%)(?:\s*[,\s/]+\s*([0-9.]+))?\s*\)$/i;

/**
* Creates a Color instance from a CSS color value.
Expand All @@ -379,8 +379,8 @@ Color.fromCssColorString = function (color, result) {
result = new Color();
}

// Remove all whitespaces from the color string
color = color.replace(/\s/g, "");
// Remove all surrounding whitespaces from the color string
color = color.trim();

const namedColor = Color[color.toUpperCase()];
if (defined(namedColor)) {
Expand Down
67 changes: 67 additions & 0 deletions packages/engine/Specs/Core/ColorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ describe("Core/Color", function () {
);
});

it("fromCssColorString supports the rgb() format with absolute values (space-separated)", function () {
expect(Color.fromCssColorString("rgb(255 0 0)")).toEqual(Color.RED);
expect(Color.fromCssColorString("rgb(0 255 0)")).toEqual(Color.LIME);
expect(Color.fromCssColorString("rgb(0 0 255)")).toEqual(Color.BLUE);
expect(Color.fromCssColorString("rgb(51 102 204)")).toEqual(
new Color(0.2, 0.4, 0.8, 1.0)
);
});

it("fromCssColorString supports the rgb() format with percentages", function () {
expect(Color.fromCssColorString("rgb(100%, 0, 0)")).toEqual(Color.RED);
expect(Color.fromCssColorString("rgb(0, 100%, 0)")).toEqual(Color.LIME);
Expand All @@ -253,6 +262,15 @@ describe("Core/Color", function () {
);
});

it("fromCssColorString supports the rgb() format with percentages (space-separated)", function () {
expect(Color.fromCssColorString("rgb(100% 0 0)")).toEqual(Color.RED);
expect(Color.fromCssColorString("rgb(0 100% 0)")).toEqual(Color.LIME);
expect(Color.fromCssColorString("rgb(0 0 100%)")).toEqual(Color.BLUE);
expect(Color.fromCssColorString("rgb(20% 40% 80%)")).toEqual(
new Color(0.2, 0.4, 0.8, 1.0)
);
});

it("fromCssColorString supports the rgba() format with absolute values", function () {
expect(Color.fromCssColorString("rgba(255, 0, 0, 1.0)")).toEqual(Color.RED);
expect(Color.fromCssColorString("rgba(0, 255, 0, 1.0)")).toEqual(
Expand All @@ -266,6 +284,15 @@ describe("Core/Color", function () {
);
});

it("fromCssColorString supports the rgba() format with absolute values (space-separated)", function () {
expect(Color.fromCssColorString("rgba(255 0 0 / 1.0)")).toEqual(Color.RED);
expect(Color.fromCssColorString("rgba(0 255 0 / 1.0)")).toEqual(Color.LIME);
expect(Color.fromCssColorString("rgba(0 0 255 / 1.0)")).toEqual(Color.BLUE);
expect(Color.fromCssColorString("rgba(51 102 204 / 0.6)")).toEqual(
new Color(0.2, 0.4, 0.8, 0.6)
);
});

it("fromCssColorString supports the rgba() format with percentages", function () {
expect(Color.fromCssColorString("rgba(100%, 0, 0, 1.0)")).toEqual(
Color.RED
Expand All @@ -281,6 +308,19 @@ describe("Core/Color", function () {
);
});

it("fromCssColorString supports the rgba() format with percentages (space-separated)", function () {
expect(Color.fromCssColorString("rgba(100% 0 0 / 1.0)")).toEqual(Color.RED);
expect(Color.fromCssColorString("rgba(0 100% 0 / 1.0)")).toEqual(
Color.LIME
);
expect(Color.fromCssColorString("rgba(0 0 100% / 1.0)")).toEqual(
Color.BLUE
);
expect(Color.fromCssColorString("rgba(20% 40% 80% / 0.6)")).toEqual(
new Color(0.2, 0.4, 0.8, 0.6)
);
});

it("fromCssColorString supports named colors regardless of case", function () {
expect(Color.fromCssColorString("red")).toEqual(Color.RED);
expect(Color.fromCssColorString("GREEN")).toEqual(Color.GREEN);
Expand All @@ -297,6 +337,16 @@ describe("Core/Color", function () {
);
});

it("fromCssColorString supports the hsl() format (space-separated)", function () {
expect(Color.fromCssColorString("hsl(0 100% 50%)")).toEqual(Color.RED);
expect(Color.fromCssColorString("hsl(120 100% 50%)")).toEqual(Color.LIME);
expect(Color.fromCssColorString("hsl(240 100% 50%)")).toEqual(Color.BLUE);
expect(Color.fromCssColorString("hsl(220 60% 50%)")).toEqualEpsilon(
new Color(0.2, 0.4, 0.8),
CesiumMath.EPSILON15
);
});

it("fromCssColorString supports the hsla() format", function () {
expect(Color.fromCssColorString("hsla(0, 100%, 50%, 1.0)")).toEqual(
Color.RED
Expand All @@ -313,6 +363,22 @@ describe("Core/Color", function () {
);
});

it("fromCssColorString supports the hsla() format (space-separated)", function () {
expect(Color.fromCssColorString("hsla(0 100% 50% / 1.0)")).toEqual(
Color.RED
);
expect(Color.fromCssColorString("hsla(120 100% 50% / 1.0)")).toEqual(
Color.LIME
);
expect(Color.fromCssColorString("hsla(240 100% 50% / 1.0)")).toEqual(
Color.BLUE
);
expect(Color.fromCssColorString("hsla(220 60% 50% / 0.6)")).toEqualEpsilon(
new Color(0.2, 0.4, 0.8, 0.6),
CesiumMath.EPSILON15
);
});

it("fromCssColorString wraps hue into valid range for hsl() format", function () {
expect(Color.fromCssColorString("hsl(720, 100%, 50%)")).toEqual(Color.RED);
expect(Color.fromCssColorString("hsla(720, 100%, 50%, 1.0)")).toEqual(
Expand Down Expand Up @@ -363,6 +429,7 @@ describe("Core/Color", function () {
expect(Color.fromCssColorString("rgb( 255, 255, 255) ")).toEqual(
Color.WHITE
);
expect(Color.fromCssColorString("rgb (0 0 255) ")).toEqual(Color.BLUE);
expect(Color.fromCssColorString(" #FF0000")).toEqual(Color.RED);
expect(Color.fromCssColorString("#FF0 ")).toEqual(Color.YELLOW);
expect(Color.fromCssColorString(" hsla(720, 100%, 50%, 1.0) ")).toEqual(
Expand Down