/** Own a JSON-like input at the call boundary; never retain consumer objects. */ export function snapshotOrgChartDataset(input: T): T { const copy = structuredClone(input); const pending: unknown[] = [copy]; const seen = new WeakSet(); while (pending.length) { const current = pending.pop(); if (current === null || typeof current !== 'object' || seen.has(current)) continue; seen.add(current); for (const child of Object.values(current)) pending.push(child); Object.freeze(current); } return copy; }