323f29b649
- One crop_fill (default 0.9) replaces duplicated FILL in inventory/overlay - Thin localStorage settings store; crop % only moves long-axis end insets - Pure tapeGeometry: fixed stage line, stage↔image map, tick span → px - measure() prefers tape tick span for scale; maskSpanAlong demoted - rotateCalibration bakes cal tilt into inventory + overlay only - Fix stale 80%-fill comment on slabBounds
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
/**
|
|
* 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 */
|
|
}
|
|
}
|
|
}
|