@noisybrood/cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -6
- package/dist/brood/api/src/client.js +58 -0
- package/dist/brood/api/src/origin.js +7 -0
- package/dist/brood/api/src/values.js +37 -0
- package/dist/brood/figures/index.js +0 -6
- package/dist/brood/tokens/dark.js +2 -0
- package/dist/brood.js +22 -0
- package/dist/client.js +7 -7
- package/dist/commands.js +190 -11
- package/dist/keychain.js +104 -0
- package/dist/main.js +28 -8
- package/dist/sign-in.js +8 -8
- package/dist/store.js +62 -7
- package/dist/wren.js +7 -13
- package/package.json +3 -3
- package/dist/brood/api/src/fields.js +0 -335
- package/dist/brood/api/src/index.js +0 -528
- package/dist/brood/tokens/dark.css +0 -86
- package/dist/brood/tokens/src/contrast.js +0 -109
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reading the colour tokens, and WCAG's contrast arithmetic over them (#608).
|
|
3
|
-
*
|
|
4
|
-
* One copy, for the brandkit, which shows each pair's grade, and for the test
|
|
5
|
-
* beside this file, which holds the pairs used as text to WCAG 2.2 AA. The
|
|
6
|
-
* CSS is passed in: the brandkit inlines it at build time, the test reads the
|
|
7
|
-
* files.
|
|
8
|
-
*/
|
|
9
|
-
export function readColourTokens(css) {
|
|
10
|
-
const out = [];
|
|
11
|
-
let note;
|
|
12
|
-
for (const raw of css.split("\n")) {
|
|
13
|
-
const line = raw.trim();
|
|
14
|
-
const comment = line.match(/^\/\*\s*(.*?)\s*\*\/$/);
|
|
15
|
-
if (comment) {
|
|
16
|
-
note = comment[1];
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
// Both groups are guaranteed by the match, but `noUncheckedIndexedAccess`
|
|
20
|
-
// cannot know that — and reading them through the guard costs nothing.
|
|
21
|
-
const decl = line.match(/^--color-([a-z0-9-]+)\s*:\s*([^;]+);/i);
|
|
22
|
-
if (decl?.[1] && decl[2]) {
|
|
23
|
-
const value = decl[2].trim();
|
|
24
|
-
out.push({
|
|
25
|
-
name: decl[1],
|
|
26
|
-
value,
|
|
27
|
-
alpha: /rgb|hsl|\//.test(value),
|
|
28
|
-
note,
|
|
29
|
-
});
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
// A blank line ends a group, so a note does not leak onto the next one.
|
|
33
|
-
if (line === "")
|
|
34
|
-
note = undefined;
|
|
35
|
-
}
|
|
36
|
-
if (!out.length)
|
|
37
|
-
throw new Error("No --color-* tokens found");
|
|
38
|
-
return out;
|
|
39
|
-
}
|
|
40
|
-
/** Relative luminance, per WCAG. */
|
|
41
|
-
function luminance(hex) {
|
|
42
|
-
const m = hex.match(/^#([0-9a-f]{6})$/i);
|
|
43
|
-
const digits = m?.[1];
|
|
44
|
-
if (!digits)
|
|
45
|
-
return null;
|
|
46
|
-
// Read each channel by name rather than destructuring out of `.map`, which
|
|
47
|
-
// hands back `number | undefined` for every element however many there are.
|
|
48
|
-
const channel = (i) => parseInt(digits.slice(i, i + 2), 16) / 255;
|
|
49
|
-
const f = (c) => c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
50
|
-
return (0.2126 * f(channel(0)) + 0.7152 * f(channel(2)) + 0.0722 * f(channel(4)));
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* The contrast ratio exactly, or null when either colour carries alpha and
|
|
54
|
-
* cannot be judged alone. For grading: WCAG's thresholds are not to be met by
|
|
55
|
-
* rounding up.
|
|
56
|
-
*/
|
|
57
|
-
export function exactContrast(a, b) {
|
|
58
|
-
const la = luminance(a);
|
|
59
|
-
const lb = luminance(b);
|
|
60
|
-
if (la === null || lb === null)
|
|
61
|
-
return null;
|
|
62
|
-
const [hi, lo] = la > lb ? [la, lb] : [lb, la];
|
|
63
|
-
return (hi + 0.05) / (lo + 0.05);
|
|
64
|
-
}
|
|
65
|
-
/** Contrast ratio to two places, for a caption, or null as `exactContrast`. */
|
|
66
|
-
export function contrast(a, b) {
|
|
67
|
-
const r = exactContrast(a, b);
|
|
68
|
-
return r === null ? null : Math.round(r * 100) / 100;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* A translucent `rgb(r g b / a)` laid over an opaque ground, as the hex a
|
|
72
|
-
* reader actually sees. A contrast figure for a translucent colour is only true
|
|
73
|
-
* against one backdrop, so this takes the backdrop explicitly rather than
|
|
74
|
-
* guessing it. Hexes pass through unchanged; anything else returns null.
|
|
75
|
-
*/
|
|
76
|
-
export function over(value, ground) {
|
|
77
|
-
if (/^#[0-9a-f]{6}$/i.test(value))
|
|
78
|
-
return value;
|
|
79
|
-
const m = value.match(/^rgb\(\s*(\d+)\s+(\d+)\s+(\d+)\s*\/\s*([\d.]+)\s*\)$/i);
|
|
80
|
-
const g = ground.match(/^#([0-9a-f]{6})$/i)?.[1];
|
|
81
|
-
if (!m || !g)
|
|
82
|
-
return null;
|
|
83
|
-
const alpha = Number(m[4]);
|
|
84
|
-
const mix = (i) => {
|
|
85
|
-
const fg = Number(m[i + 1]);
|
|
86
|
-
const bg = parseInt(g.slice(i * 2, i * 2 + 2), 16);
|
|
87
|
-
return Math.round(fg * alpha + bg * (1 - alpha))
|
|
88
|
-
.toString(16)
|
|
89
|
-
.padStart(2, "0");
|
|
90
|
-
};
|
|
91
|
-
return `#${mix(0)}${mix(1)}${mix(2)}`;
|
|
92
|
-
}
|
|
93
|
-
/** Contrast of a colour, translucent or not, as it lands on `ground`. */
|
|
94
|
-
export function contrastOn(value, ground) {
|
|
95
|
-
const seen = over(value, ground);
|
|
96
|
-
return seen === null ? null : contrast(seen, ground);
|
|
97
|
-
}
|
|
98
|
-
/** WCAG grade for body text at normal size. */
|
|
99
|
-
export function grade(ratio) {
|
|
100
|
-
if (ratio === null)
|
|
101
|
-
return "—";
|
|
102
|
-
if (ratio >= 7)
|
|
103
|
-
return "AAA";
|
|
104
|
-
if (ratio >= 4.5)
|
|
105
|
-
return "AA";
|
|
106
|
-
if (ratio >= 3)
|
|
107
|
-
return "AA large";
|
|
108
|
-
return "fails";
|
|
109
|
-
}
|