diff --git a/web/image_conveyor_reference_autosave_math.mjs b/web/image_conveyor_reference_autosave_math.mjs new file mode 100644 index 0000000..df80820 --- /dev/null +++ b/web/image_conveyor_reference_autosave_math.mjs @@ -0,0 +1,25 @@ +import { normalizeReferenceSlots } from './image_conveyor_math.mjs' + +export function referencePresetStateSnapshot(state) { + const source = state && typeof state === 'object' ? state : {} + const presetId = String(source.active_reference_preset_id ?? '').trim() + const slots = normalizeReferenceSlots(source.reference_slots) + return { + presetId, + slots, + slotKey: JSON.stringify(slots.map((slot) => slot?.annotated || '')) + } +} + +export function shouldAutosaveReferencePreset(previous, current) { + if (!previous || !current?.presetId) return false + if (previous.presetId !== current.presetId) return false + return previous.slotKey !== current.slotKey +} + +export function referencePresetSaveKey(presetId, slots) { + const normalizedId = String(presetId ?? '').trim() + if (!normalizedId) return '' + const normalizedSlots = normalizeReferenceSlots(slots) + return `${normalizedId}:${JSON.stringify(normalizedSlots.map((slot) => slot?.annotated || ''))}` +}