1import { normalizeMetadata, normalizePresentation } from './state.js'23export function workingStateSnapshot(state, mode = 'open') {4 return JSON.stringify({5 mode,6 type: state.type,7 source: state.source,8 options: state.options ?? {},9 meta: normalizeMetadata(state.meta),10 presentation: normalizePresentation(state.presentation),11 })12}1314export function workingStateIsDirty(state, {15 mode = 'open',16 keyEnvelopeDirty = false,17 savedSnapshot = null,18 defaultStateFor,19} = {}) {20 if (keyEnvelopeDirty) return true21 const baseline = savedSnapshot ?? workingStateSnapshot(defaultStateFor(state.type), 'open')22 return workingStateSnapshot(state, mode) !== baseline23}