MCPcopy Index your code
hub / github.com/anomalyco/opencode / nearestIndexed

Function nearestIndexed

packages/opencode/src/cli/cmd/run/theme.ts:242–264  ·  view source on GitHub ↗
(indexed: RGBA[], rgba: RGBA)

Source from the content-addressed store, hash-verified

240}
241
242function nearestIndexed(indexed: RGBA[], rgba: RGBA): RGBA {
243 const target = oklab(rgba)
244 const hit = indexed.reduce(
245 (best, item) => {
246 const sample = oklab(item)
247 const dl = sample.l - target.l
248 const da = sample.a - target.a
249 const db = sample.b - target.b
250 const dist = dl * dl * 2 + da * da + db * db
251 if (dist >= best.dist) return best
252 return {
253 dist,
254 item,
255 }
256 },
257 {
258 dist: Number.POSITIVE_INFINITY,
259 item: indexed[0]!,
260 },
261 )
262
263 return RGBA.clone(hit.item)
264}
265
266function paletteColor(colors: TerminalColors, index: number): RGBA {
267 const value = colors.palette[index]

Callers 3

splashShadowFunction · 0.85
quantizeColorFunction · 0.85
splashThemeFunction · 0.85

Calls 2

oklabFunction · 0.85
cloneMethod · 0.80

Tested by

no test coverage detected