import { GrayImage } from "./image"; declare const com: any; declare const global: any; /** * Vector icons for window indicators (and anywhere else). SVGs are rendered * once to a correctly sized grayscale bitmap by the Java IconRenderer (a * small SVG subset: path/circle/rect/line/polyline) and cached here. To add * an icon, drop its SVG source into ICON_SVGS — Lucide icons * (https://lucide.dev, stroked, 24px viewBox) work as-is; simple single-color * Noun Project glyphs also work. */ // Stroke width in viewBox units (Lucide's default is 2). const ICON_STROKE_WIDTH = 2; // Lucide icons (MIT/ISC licensed). Kept verbatim so they can be diffed // against upstream if an icon needs updating. export const ICON_SVGS = { "layout-grid": '', timer: '', terminal: '', "file-text": '', music: '', activity: '', bell: '', calendar: '', "cloud-sun": '', "flask-conical": '', settings: '', mic: '', nightscout: '', } as const; export type IconName = keyof typeof ICON_SVGS; const cache = new Map(); /** Render an icon SVG to a size×size grayscale bitmap, rendered once and cached. */ export function renderIcon(name: IconName, size: number): GrayImage | null { const key = `${name}:${size}`; const cached = cache.get(key); if (cached !== undefined) return cached; let icon: GrayImage | null = null; if (global.isAndroid) { try { const bytes = com.faceclaw.app.IconRenderer.renderSvgGray(ICON_SVGS[name], Math.round(size), ICON_STROKE_WIDTH); if (bytes && bytes.length >= size * size) { icon = new GrayImage(size, size, 0); for (let i = 0; i < size * size; i++) { icon.pixels[i] = bytes[i] & 0xff; } } } catch (error) { console.warn(`renderIcon(${name}) failed: ${error}`); } } cache.set(key, icon); return icon; }