// re-export color utilities from kitchen-sink for convenience // these are the same implementations used in detox tests import * as fs from 'fs' import { PNG } from 'pngjs' export type RGB = { r: number; g: number; b: number } export function getDominantColor(screenshotPath: string): RGB { const data = fs.readFileSync(screenshotPath) const png = PNG.sync.read(data) const startX = Math.floor(png.width * 0.25) const endX = Math.floor(png.width * 0.75) const startY = Math.floor(png.height * 0.25) const endY = Math.floor(png.height * 0.75) let totalR = 0, totalG = 0, totalB = 0, count = 0 for (let y = startY; y < endY; y++) { for (let x = startX; x < endX; x++) { const idx = (png.width * y + x) * 4 totalR += png.data[idx] totalG += png.data[idx + 1] totalB += png.data[idx + 2] count++ } } return { r: Math.round(totalR / count), g: Math.round(totalG / count), b: Math.round(totalB / count), } } export function isBlueish(color: RGB): boolean { return color.b > 100 && color.b > color.r && color.b > color.g } export function isReddish(color: RGB): boolean { return color.r > 100 && color.r > color.b && color.r > color.g } export function isGreenish(color: RGB): boolean { return color.g > 100 && color.g > color.r && color.g > color.b } export function formatRGB(color: RGB): string { return `RGB(${color.r}, ${color.g}, ${color.b})` }