Skip to content

Commit b732d33

Browse files
committed
Parse both dashed-ident and ident versions, and add missing dashed-idents to color spaces.
1 parent c3cdaac commit b732d33

22 files changed

+116
-79
lines changed

src/parse.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ export default function parse (str, {meta} = {}) {
7878
if (name === "color") {
7979
// color() function
8080
let id = env.parsed.args.shift();
81-
let undashedId = id.startsWith("--") ? id.substring(2) : id;
82-
let ids = [id, undashedId];
81+
// Check against both <dashed-ident> and <ident> versions
82+
let alternateId = id.startsWith("--") ? id.substring(2) : `--${id}`;
83+
let ids = [id, alternateId];
8384
let alpha = env.parsed.rawArgs.indexOf("/") > 0 ? env.parsed.args.pop() : 1;
8485

8586
for (let space of ColorSpace.all) {
@@ -109,10 +110,10 @@ export default function parse (str, {meta} = {}) {
109110

110111
// Not found
111112
let didYouMean = "";
112-
let registryId = id in ColorSpace.registry ? id : undashedId;
113+
let registryId = id in ColorSpace.registry ? id : alternateId;
113114
if (registryId in ColorSpace.registry) {
114115
// Used color space id instead of color() id, these are often different
115-
let cssId = ColorSpace.registry[registryId].formats?.functions?.color?.id;
116+
let cssId = ColorSpace.registry[registryId].formats?.color?.id;
116117

117118
if (cssId) {
118119
didYouMean = `Did you mean color(${cssId})?`;

src/space.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export default class ColorSpace {
4545
format.name ||= name;
4646
}
4747

48-
if (options.cssId && !this.formats.functions?.color) {
48+
if (options.cssId && !this.formats.color) {
4949
this.formats.color = { id: options.cssId };
5050
Object.defineProperty(this, "cssId", {value: options.cssId});
5151
}
52-
else if (this.formats?.color && !this.formats?.color.id) {
53-
this.formats.color.id = this.id;
52+
else if (!this.formats.color?.id) {
53+
this.formats.color = { ...this.formats.color ?? {}, id: this.id };
5454
}
5555

5656
// Gamut space
@@ -122,7 +122,7 @@ export default class ColorSpace {
122122
}
123123

124124
get cssId () {
125-
return this.formats.functions?.color?.id || this.id;
125+
return this.formats?.color?.id || this.id;
126126
}
127127

128128
get isPolar () {

src/spaces/a98rgb-linear.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const fromXYZ_M = [
2020

2121
export default new RGBColorSpace({
2222
id: "a98rgb-linear",
23+
cssId: "--a98-rgb-linear",
2324
name: "Linear Adobe® 98 RGB compatible",
2425
white: "D65",
2526
toXYZ_M,

src/spaces/a98rgb.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import A98Linear from "./a98rgb-linear.js";
33

44
export default new RGBColorSpace({
55
id: "a98rgb",
6+
cssId: "a98-rgb",
67
name: "Adobe® 98 RGB compatible",
78
base: A98Linear,
89
toBase: RGB => RGB.map(val => Math.pow(Math.abs(val), 563 / 256) * Math.sign(val)),
9-
fromBase: RGB => RGB.map(val => Math.pow(Math.abs(val), 256 / 563) * Math.sign(val)),
10-
formats: {
11-
color: {
12-
id: "a98-rgb"
13-
}
14-
},
10+
fromBase: RGB => RGB.map(val => Math.pow(Math.abs(val), 256 / 563) * Math.sign(val))
1511
});

src/spaces/acescc.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ACES_cc_max = (Math.log2(65504) + 9.72) / 17.52; // 1.468
1313

1414
export default new RGBColorSpace({
1515
id: "acescc",
16+
cssId: "--acescc",
1617
name: "ACEScc",
1718
// see S-2014-003 ACEScc – A Logarithmic Encoding of ACES Data
1819
// https://docs.acescentral.com/specifications/acescc/
@@ -69,10 +70,7 @@ export default new RGBColorSpace({
6970
return (Math.log2(val) + 9.72) / 17.52;
7071
}
7172
});
72-
},
73+
}
7374
// encoded media white (rgb 1,1,1) => linear [ 222.861, 222.861, 222.861 ]
7475
// encoded media black (rgb 0,0,0) => linear [ 0.0011857, 0.0011857, 0.0011857]
75-
formats: {
76-
color: {}
77-
}
7876
});

src/spaces/acescg.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const fromXYZ_M = [
2222

2323
export default new RGBColorSpace({
2424
id: "acescg",
25+
cssId: "--acescg",
2526
name: "ACEScg",
2627

2728
// ACEScg – A scene-referred, linear-light encoding of ACES Data
@@ -47,11 +48,7 @@ export default new RGBColorSpace({
4748
white: WHITES.ACES,
4849

4950
toXYZ_M,
50-
fromXYZ_M,
51-
52-
formats: {
53-
color: {}
54-
},
51+
fromXYZ_M
5552
});
5653

5754
// export default Color;

src/spaces/cam16.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ export function toCam16 (xyzd65, env) {
329329
// Results compared against: https://github.com/colour-science/colour
330330
export default new ColorSpace({
331331
id: "cam16-jmh",
332+
cssId: "--cam16-jmh",
332333
name: "CAM16-JMh",
333334
coords: {
334335
j: {
@@ -357,10 +358,5 @@ export default new ColorSpace({
357358
{J: cam16[0], M: cam16[1], h: cam16[2]},
358359
viewingConditions
359360
);
360-
},
361-
formats: {
362-
color: {
363-
id: "--cam16-jmh"
364-
},
365-
},
361+
}
366362
});

src/spaces/ictcp.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const LMStoXYZ_M = [
6666
// https://professional.dolby.com/siteassets/pdfs/dolby-vision-measuring-perceptual-color-volume-v7.1.pdf
6767
export default new ColorSpace({
6868
id: "ictcp",
69+
cssId: "--ictcp",
6970
name: "ICTCP",
7071
// From BT.2100-2 page 7:
7172
// During production, signal values are expected to exceed the
@@ -102,10 +103,7 @@ export default new ColorSpace({
102103
let LMS = ICtCptoLMS(ICtCp);
103104

104105
return multiplyMatrices(LMStoXYZ_M, LMS);
105-
},
106-
formats: {
107-
color: {}
108-
},
106+
}
109107
});
110108

111109
function LMStoICtCp (LMS) {

src/spaces/jzazbz.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export default new ColorSpace({
112112
formats: {
113113
// https://drafts.csswg.org/css-color-hdr/#Jzazbz
114114
"color": {
115+
id: "--jzazbz",
115116
coords: ["<number> | <percentage>", "<number> | <percentage>[-1,1]", "<number> | <percentage>[-1,1]"],
116117
}
117118
}

src/spaces/jzczhz.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {constrain as constrainAngle} from "../angles.js";
44

55
export default new ColorSpace({
66
id: "jzczhz",
7+
cssId: "--jzczhz",
78
name: "JzCzHz",
89
coords: {
910
jz: {
@@ -49,8 +50,5 @@ export default new ColorSpace({
4950
jzczhz[1] * Math.cos(jzczhz[2] * Math.PI / 180), // az
5051
jzczhz[1] * Math.sin(jzczhz[2] * Math.PI / 180) // bz
5152
];
52-
},
53-
formats: {
54-
color: {}
55-
},
53+
}
5654
});

0 commit comments

Comments
 (0)