Skip to content

Commit 5db13a5

Browse files
authored
Colorjsio 0.6.0 beta.1 (#40)
* chore: upgrade colorjs.io to 0.6.0-beta.1 * failed to register all spaces in 1 go, so add TODO
1 parent 1596f9e commit 5db13a5

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

package-lock.json

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"dependencies": {
3737
"@projectwallace/css-analyzer": "^7.6.0",
3838
"color-sorter": "^7.0.0",
39-
"colorjs.io": "^0.6.0-alpha.1",
39+
"colorjs.io": "^0.6.0-beta.1",
4040
"css-time-sort": "^3.0.0",
4141
"css-tree": "^3.1.0"
4242
},

src/colors.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { colorKeywords as color_keywords, cssKeywords as css_keywords } from '@projectwallace/css-analyzer'
22
import { type ColorValue, type ColorSpace as tColorSpace } from './types.js'
33
import {
4-
parse,
4+
tryColor,
55
ColorSpace,
66
XYZ_D65,
77
XYZ_D50,
@@ -28,6 +28,8 @@ import {
2828
} from 'colorjs.io/fn'
2929

3030
// Register color spaces for parsing and converting
31+
// TODO: According to the changelog we should be able to import
32+
// and register all spaces in one go but it doesn't seem to work
3133
ColorSpace.register(sRGB) // Parses keywords and hex colors
3234
ColorSpace.register(XYZ_D65)
3335
ColorSpace.register(XYZ_D50)
@@ -72,17 +74,14 @@ export function color_to_token(color: string): ColorValue | null {
7274
return null
7375
}
7476

75-
try {
76-
let parsed_color = parse(color)
77-
let [component_a, component_b, component_c] = parsed_color.coords
77+
let parsed_color = tryColor(color)
7878

79-
return {
80-
colorSpace: parsed_color.spaceId as tColorSpace,
81-
components: [component_a ?? 'none', component_b ?? 'none', component_c ?? 'none'],
82-
alpha: parsed_color.alpha ?? 1,
83-
}
84-
} catch (error) {
85-
// A catch for edge cases that we don't support yet.
86-
return null
79+
if (parsed_color === null) return null
80+
let [component_a, component_b, component_c] = parsed_color.coords
81+
82+
return {
83+
colorSpace: parsed_color.space.id as tColorSpace,
84+
components: [component_a ?? 'none', component_b ?? 'none', component_c ?? 'none'],
85+
alpha: parsed_color.alpha ?? 1,
8786
}
8887
}

0 commit comments

Comments
 (0)