a tool for shared writing and social publishing
1import { Color } from "react-aria-components";
2
3export function ColorToRGBA(color: Color) {
4 if (!color)
5 return {
6 $type: "pub.leaflet.theme.color#rgba" as const,
7 r: 0,
8 g: 0,
9 b: 0,
10 a: 1,
11 };
12 let c = color.toFormat("rgba");
13 const r = c.getChannelValue("red");
14 const g = c.getChannelValue("green");
15 const b = c.getChannelValue("blue");
16 const a = c.getChannelValue("alpha");
17 return {
18 $type: "pub.leaflet.theme.color#rgba" as const,
19 r: Math.round(r),
20 g: Math.round(g),
21 b: Math.round(b),
22 a: Math.round(a * 100),
23 };
24}
25
26export function ColorToRGB(color: Color) {
27 if (!color)
28 return {
29 $type: "pub.leaflet.theme.color#rgb" as const,
30 r: 0,
31 g: 0,
32 b: 0,
33 };
34 let c = color.toFormat("rgb");
35 const r = c.getChannelValue("red");
36 const g = c.getChannelValue("green");
37 const b = c.getChannelValue("blue");
38 return {
39 $type: "pub.leaflet.theme.color#rgb" as const,
40 r: Math.round(r),
41 g: Math.round(g),
42 b: Math.round(b),
43 };
44}