File size: 2,026 Bytes
82cdb59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// The fixed six colour reference rotation, wave 52 (W52-T05, contract C3, instruction 7, rule CR-4).
//
// `AutoWiki/waves/wave52/proto/excel-behaviour-spec.md` CR-4: Excel's own reference-colouring
// palette is NOT documented anywhere sourceable. Rather than guess at it, the spec FIXES this
// app's own six colour rotation and a lane must use exactly these, in exactly this order, cycling
// after the sixth. `formulaAssist.ts::refsIn` assigns SLOT INDEXES (0-5); this file is the only
// place that turns a slot index into a hex colour, so the formula text and the grid outline always
// agree (CR-1, "so a reference and its cell always agree" per the ticket brief).
//
// PURE data and pure functions only. No React, no DOM.

export interface RefColorSlot {
  name: string;
  light: string;
  dark: string;
}

/** CR-4's table, verbatim, in rotation order. Never reorder; never add or remove a slot. */
export const REF_COLORS: readonly RefColorSlot[] = [
  { name: "Blue", light: "#1B6AC9", dark: "#5CA8F0" },
  { name: "Red", light: "#C0392B", dark: "#F07167" },
  { name: "Purple", light: "#7A4DBF", dark: "#B18CE6" },
  { name: "Green", light: "#1E8449", dark: "#4FBF7F" },
  { name: "Orange", light: "#C87A00", dark: "#E8A33D" },
  { name: "Teal", light: "#0F7B7B", dark: "#3FB8B8" },
];

export const REF_COLOR_COUNT = REF_COLORS.length;

/** Any slot index (including >= 6, including negative) wraps into the six slot rotation. */
function slotIndex(slot: number): number {
  const n = REF_COLOR_COUNT;
  return ((slot % n) + n) % n;
}

/** The hex for one slot, in the given theme. Wraps after the sixth slot (CR-4's "cycling"). */
export function colorForSlot(slot: number, theme: "light" | "dark" = "light"): string {
  const entry = REF_COLORS[slotIndex(slot)];
  return theme === "dark" ? entry.dark : entry.light;
}

/** The slot's display name (for an aria label or a legend), independent of theme. CR-7. */
export function nameForSlot(slot: number): string {
  return REF_COLORS[slotIndex(slot)].name;
}