roundel 0.5.3 → 0.5.4

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/dist/theme.js CHANGED
@@ -43,6 +43,7 @@ const SGR_256 = 5;
43
43
  const SGR_RGB = 2;
44
44
  const TRUECOLOR = 3;
45
45
  const COLORS_256 = 2;
46
+ const step = (v) => Math.round((v / SRGB_MAX) * CUBE_STEPS);
46
47
  function ansi256(r, g, b) {
47
48
  if (r === g && g === b) {
48
49
  if (r < GREY_LOW)
@@ -51,11 +52,10 @@ function ansi256(r, g, b) {
51
52
  return CUBE_WHITE;
52
53
  return Math.round(((r - GREY_LOW) / GREY_SPAN) * GREY_STEPS) + GREY_START;
53
54
  }
54
- const step = (v) => Math.round((v / SRGB_MAX) * CUBE_STEPS);
55
55
  return CUBE_START + CUBE_ROW * step(r) + CUBE_COL * step(g) + step(b);
56
56
  }
57
+ const on = (v) => Math.round(v / SRGB_MAX);
57
58
  function ansi16(r, g, b) {
58
- const on = (v) => Math.round(v / SRGB_MAX);
59
59
  const index = (on(b) << BLUE_BIT) | (on(g) << GREEN_BIT) | on(r);
60
60
  const name = BASIC_NAMES[index] ?? 'white';
61
61
  if (index === 0)
@@ -64,23 +64,23 @@ function ansi16(r, g, b) {
64
64
  return name;
65
65
  return name === 'black' ? 'gray' : `${name}Bright`;
66
66
  }
67
+ const hex = (r, g, b) => `#${[r, g, b].map((v) => v.toString(HEX_BASE).padStart(2, '0')).join('')}`;
68
+ const at = (i) => CUBE_LEVELS[i];
67
69
  export function rgb256(index) {
68
- const hex = (r, g, b) => `#${[r, g, b].map((v) => v.toString(HEX_BASE).padStart(2, '0')).join('')}`;
69
70
  if (index >= GREY_START)
70
71
  return hex(...Array(RGB_PARTS).fill(GREY_LOW + (index - GREY_START) * GREY_STEP));
71
72
  const n = index - CUBE_START;
72
- const at = (i) => CUBE_LEVELS[i];
73
73
  return hex(at(Math.floor(n / CUBE_ROW)), at(Math.floor((n % CUBE_ROW) / CUBE_COL)), at(n % CUBE_COL));
74
74
  }
75
75
  const LINEAR_THRESHOLD = 0.04045;
76
76
  const LINEAR_DIVISOR = 12.92;
77
77
  const GAMMA_OFFSET = 0.055;
78
78
  const GAMMA_EXPONENT = 2.4;
79
+ const lin = (v) => {
80
+ const c = v / SRGB_MAX;
81
+ return c <= LINEAR_THRESHOLD ? c / LINEAR_DIVISOR : ((c + GAMMA_OFFSET) / (1 + GAMMA_OFFSET)) ** GAMMA_EXPONENT;
82
+ };
79
83
  export function toOklab(r, g, b) {
80
- const lin = (v) => {
81
- const c = v / SRGB_MAX;
82
- return c <= LINEAR_THRESHOLD ? c / LINEAR_DIVISOR : ((c + GAMMA_OFFSET) / (1 + GAMMA_OFFSET)) ** GAMMA_EXPONENT;
83
- };
84
84
  const R = lin(r);
85
85
  const G = lin(g);
86
86
  const B = lin(b);
package/dist/tokens.js CHANGED
@@ -8,8 +8,8 @@ function paint(p, s) {
8
8
  return styleText([...p], s, { validateStream: false });
9
9
  }
10
10
  const LINE_BREAK = /\r?\n/g;
11
+ const code = (p) => `${CSI}${p}m`;
11
12
  export function sgr(chain, s) {
12
- const code = (p) => `${CSI}${p}m`;
13
13
  const openAll = chain.map((p) => code(p.open)).join('');
14
14
  const closeAll = chain.map((p) => code(p.close)).reverse().join('');
15
15
  let out = s;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roundel",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "The colours a CLI carries. One output policy, semantic tokens, a theme, and a chalk migration path lighter than chalk. Zero dependencies.",
5
5
  "license": "MIT",
6
6
  "type": "module",