/** * Thin frontend-only crop_fill setting (#99). * Default 0.9 — replaces duplicated FILL = 0.9 in png/inventory + png/overlay. * Not a full M3 Settings surface; localStorage so it survives reloads. */ import { DEFAULT_CROP_FILL, clampFill } from '../png/crop'; const KEY = 'slabuploader.crop_fill'; let cached: number | null = null; export function getCropFill(): number { if (cached != null) return cached; if (typeof localStorage === 'undefined') { cached = DEFAULT_CROP_FILL; return cached; } try { const raw = localStorage.getItem(KEY); if (raw == null) { cached = DEFAULT_CROP_FILL; return cached; } cached = clampFill(Number.parseFloat(raw)); return cached; } catch { cached = DEFAULT_CROP_FILL; return cached; } } export function setCropFill(fill: number): number { const next = clampFill(fill); cached = next; if (typeof localStorage !== 'undefined') { try { localStorage.setItem(KEY, String(next)); } catch { /* private mode / quota — in-memory still updated */ } } return next; } /** Test helper: clear cached value (and optional storage). */ export function _resetCropFillForTests(): void { cached = null; if (typeof localStorage !== 'undefined') { try { localStorage.removeItem(KEY); } catch { /* ignore */ } } }