From e8ba77b104cdc975b5f02a7eb4e191d862a2cf4a Mon Sep 17 00:00:00 2001 From: xmarre <54859656+xmarre@users.noreply.github.com> Date: Wed, 19 Aug 2026 10:56:25 +0200 Subject: [PATCH] Add reference preset autosave state math --- ...image_conveyor_reference_autosave_math.mjs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 web/image_conveyor_reference_autosave_math.mjs 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 || ''))}` +}