{"version":3,"file":"styloviz-core-persist.mjs","names":[],"sources":["../../../../projects/core/persist/persisted-state.ts","../../../../projects/core/persist/persisted-store.ts"],"sourcesContent":["declare const ngDevMode: boolean | undefined;\n\n/**\n * A blob the host has stored, and the schema it was written against.\n *\n * Six families in the kit hand the host state to keep — a dashboard layout, a\n * table's columns, a saved pivot view, a query, a set of facets, a project plan.\n * Every one of them was handed over as a bare object, which is a migration\n * nobody has written yet: the first release that renames a field reads the old\n * blob as if it were the new one, and a user's saved dashboard comes back\n * subtly wrong with nothing reported.\n *\n * The envelope is deliberately the smallest thing that fixes that. `kind` says\n * whose it is, `version` says which schema, `state` is the payload — and the\n * component that wrote it is the only thing that gets to interpret it.\n */\nimport { svFormatLabel } from '@styloviz/core/i18n';\nimport { SV_CORE_LABELS, type SvCoreLabels } from '@styloviz/core/i18n';\nimport { svWarn } from '@styloviz/core/dev';\n\n/** The `core` labels a refused restore's `detail` is written from. */\nexport type SvRestoreLabels = Pick<\n  SvCoreLabels,\n  | 'restoreUnreadable' | 'restoreUnsigned' | 'restoreForeign' | 'restoreNoVersion' | 'restoreTooNew'\n  | 'restoreBadShape' | 'restoreUnmigratable' | 'linkNoVersion' | 'linkBadVersion' | 'linkTooNew'\n>;\nexport interface SvPersistedState<T> {\n  /** Who wrote it: `'sv-widget-grid/layout'`. Namespaced by selector. */\n  readonly kind: string;\n  /** The schema version. Integer, starts at 1, bumped on any breaking change. */\n  readonly version: number;\n  /** The state itself. Must be JSON-safe — see {@link svPersistState}. */\n  readonly state: T;\n}\n\n/** Why a stored blob could not be restored. */\nexport type SvRestoreReason =\n  /** Not an envelope, and not adoptable as a pre-envelope blob either. */\n  | 'malformed'\n  /** An envelope, but another component's — a query pasted into a table. */\n  | 'foreign'\n  /** Written by a later release of the kit than the one reading it. */\n  | 'too-new'\n  /** Older, and the component offers no way to bring it forward. */\n  | 'unmigratable';\n\n/** The outcome of {@link svRestoreState}. */\nexport type SvRestoreResult<T> =\n  | {\n      readonly ok: true;\n      /** The state, at the current version. */\n      readonly state: T;\n      /**\n       * The version it was stored at. `0` means a pre-envelope blob that\n       * {@link SvRestoreSpec.adoptLegacy} accepted. When this is below the\n       * component's current version the host should re-save, or every load pays\n       * the migration again.\n       */\n      readonly from: number;\n    }\n  | {\n      readonly ok: false;\n      readonly reason: SvRestoreReason;\n      /** One sentence, safe to show a user. */\n      readonly detail: string;\n    };\n\n/** How a component reads its own stored state back. */\nexport interface SvRestoreSpec<T> {\n  /** Must equal the `kind` the component writes. */\n  readonly kind: string;\n  /** The schema version the component understands now. */\n  readonly version: number;\n  /**\n   * Parse a payload written at the current `version`, or return `null` if it is\n   * not one.\n   *\n   * ★ Required, not optional, because the alternative is a cast — and what comes\n   *   back out of `localStorage` or a URL is whatever anyone with devtools\n   *   decided to put there. A matching `kind` and `version` say which schema the\n   *   payload CLAIMS; only this says it holds.\n   */\n  readonly read: (state: unknown) => T | null;\n  /**\n   * Bring a `from`-version payload up to `version`, or return `null` when it\n   * cannot be brought forward. Only called for `from < version`, and responsible\n   * for validating what it reads exactly as `read` is.\n   *\n   * Written by the component, not the host: the component owns the schema, and\n   * a host asked to migrate a shape it did not design will guess.\n   */\n  readonly migrate?: (state: unknown, from: number) => T | null;\n  /**\n   * What to do with a blob that has no envelope at all.\n   *\n   * Not hypothetical, and the reason `from` can be `0`: every one of these\n   * families shipped its state bare before this contract existed, so there are\n   * stored dashboards and saved views in the wild with no `kind` and no\n   * `version`. Return `0` to hand the whole blob to `migrate` as the\n   * pre-versioning shape, or `null` to refuse it.\n   *\n   * A component that never shipped an unversioned form must leave this out. A\n   * blanket \"assume it is current\" would make `malformed` unreachable and let\n   * any object at all through.\n   */\n  readonly adoptLegacy?: (blob: Readonly<Record<string, unknown>>) => number | null;\n}\n\n/**\n * Wrap state for the host to store.\n *\n * The state must survive `JSON.stringify` → `JSON.parse` unchanged, which is\n * the one rule the type system will not enforce for you: a `Set` becomes `{}`,\n * a `Map` becomes `{}`, and a function member — `rollback` on an event payload\n * — vanishes without a word. So a component serializes a SNAPSHOT type of its\n * own, never the event payload it happens to have to hand.\n * `scripts/check-persisted-state.mjs` holds that line.\n */\nexport function svPersistState<T>(kind: string, version: number, state: T): SvPersistedState<T> {\n  return { kind, version, state };\n}\n\n/**\n * Read stored state back, or say precisely why it cannot be.\n *\n * ★ A blob from a NEWER version is refused, not read as far as it parses. This\n *   is the case a \"best effort\" restore gets wrong: the same field name means\n *   something different in v3, so a partial read does not fail — it silently\n *   produces a layout the user never arranged. Someone who arranges their\n *   dashboard in the current release and then loads last month's build on\n *   another machine should get their default view and a sentence saying why,\n *   not a mangled one.\n *\n * The host's side of this is three lines:\n *\n * ```ts\n * const restored = grid.restoreLayout(JSON.parse(raw));\n * if (!restored.ok) this.notice.set(restored.detail);\n * else if (restored.from < SV_WIDGET_GRID_LAYOUT_VERSION) this.save(grid.serializeLayout());\n * ```\n *\n * @param blob Whatever came out of storage. Untrusted: any shape, or none.\n */\nexport function svRestoreState<T>(\n  blob: unknown,\n  spec: SvRestoreSpec<T>,\n  labels: SvRestoreLabels = SV_CORE_LABELS,\n): SvRestoreResult<T> {\n  const { kind, version, adoptLegacy } = spec;\n\n  if (!blob || typeof blob !== 'object' || Array.isArray(blob)) {\n    return { ok: false, reason: 'malformed', detail: labels.restoreUnreadable };\n  }\n\n  const record = blob as Record<string, unknown>;\n  const envelope = typeof record['kind'] === 'string' && typeof record['version'] === 'number';\n\n  if (!envelope) {\n    const from = adoptLegacy?.(record) ?? null;\n    if (from === null) {\n      return {\n        ok: false,\n        reason: 'malformed',\n        detail: labels.restoreUnsigned,\n      };\n    }\n    return readAt(record, from, spec, labels);\n  }\n\n  if (record['kind'] !== kind) {\n    return {\n      ok: false,\n      reason: 'foreign',\n      detail: svFormatLabel(labels.restoreForeign, { found: String(record['kind']), expected: kind }),\n    };\n  }\n\n  const from = record['version'] as number;\n  if (!Number.isInteger(from) || from < 1) {\n    return { ok: false, reason: 'malformed', detail: labels.restoreNoVersion };\n  }\n  if (from > version) {\n    return {\n      ok: false,\n      reason: 'too-new',\n      detail: svFormatLabel(labels.restoreTooNew, { from: String(from), version: String(version) }),\n    };\n  }\n\n  return readAt(record['state'], from, spec, labels);\n}\n\nfunction readAt<T>(state: unknown, from: number, spec: SvRestoreSpec<T>, labels: SvRestoreLabels): SvRestoreResult<T> {\n  if (from === spec.version) {\n    const parsed = spec.read(state);\n    return parsed === null\n      ? { ok: false, reason: 'malformed', detail: labels.restoreBadShape }\n      : { ok: true, state: parsed, from };\n  }\n\n  const migrated = spec.migrate?.(state, from) ?? null;\n  if (migrated === null) {\n    return {\n      ok: false,\n      reason: 'unmigratable',\n      detail: svFormatLabel(labels.restoreUnmigratable, { from: String(from) }),\n    };\n  }\n  return { ok: true, state: migrated, from };\n}\n\n/** How a component reads its own state back out of a URL. */\nexport interface SvRestoreParamsSpec<T> {\n  /** The parameter carrying the schema version: `'fv'`. */\n  readonly versionParam: string;\n  /** The schema version the component writes now. */\n  readonly version: number;\n  /**\n   * Read parameters written at `from` (always below `version`), or `null` when\n   * they cannot be brought forward.\n   */\n  readonly migrate?: (params: URLSearchParams, from: number) => T | null;\n  /**\n   * The version to read a link that carries no version parameter as, or `null`\n   * to ignore its filters entirely. Links predating the version parameter are\n   * already pasted into other people's chat windows, so this is the case that\n   * actually happens.\n   */\n  readonly legacyVersion?: number | null;\n}\n\n/**\n * The same versioning contract over URL query parameters, for state whose whole\n * point is being shareable.\n *\n * A filtered listing has to survive being pasted into a chat window, so it\n * belongs in the URL rather than in storage — and a URL is read by people, so\n * base64-ing an envelope into one parameter is the wrong answer. The component\n * writes readable parameters plus one version parameter instead, and this\n * decides whether they can be trusted before `read` is ever called, so `read`\n * never has to guess which release wrote them.\n *\n * There is no `kind` here: a URL is scoped by its route already, and a second\n * component on the same page namespaces its own parameter names.\n *\n * @param params What came in from `location.search`. Untrusted.\n * @param read   Builds the state from parameters known to be current.\n */\nexport function svRestoreParams<T>(\n  params: URLSearchParams,\n  spec: SvRestoreParamsSpec<T>,\n  read: (params: URLSearchParams) => T,\n  // `linkUnmigratable` is optional so a labels object written against the\n  // earlier `SvRestoreLabels` still type-checks; core's English fills the gap.\n  labels: SvRestoreLabels & Partial<Pick<SvCoreLabels, 'linkUnmigratable'>> = SV_CORE_LABELS,\n): SvRestoreResult<T> {\n  const { versionParam, version, migrate, legacyVersion } = spec;\n  const raw = params.get(versionParam);\n\n  let from: number;\n  if (raw === null) {\n    if (legacyVersion == null) {\n      return {\n        ok: false,\n        reason: 'malformed',\n        detail: labels.linkNoVersion,\n      };\n    }\n    from = legacyVersion;\n  } else {\n    from = Number(raw);\n    if (!Number.isInteger(from) || from < 1) {\n      return { ok: false, reason: 'malformed', detail: labels.linkBadVersion };\n    }\n  }\n\n  if (from > version) {\n    return {\n      ok: false,\n      reason: 'too-new',\n      detail: svFormatLabel(labels.linkTooNew, { from: String(from), version: String(version) }),\n    };\n  }\n  if (from === version) return { ok: true, state: read(params), from };\n\n  const migrated = migrate?.(params, from) ?? null;\n  if (migrated === null) {\n    return {\n      ok: false,\n      reason: 'unmigratable',\n      detail: svFormatLabel(labels.linkUnmigratable ?? SV_CORE_LABELS.linkUnmigratable, { from: String(from) }),\n    };\n  }\n  return { ok: true, state: migrated, from };\n}\n\n/**\n * Warn, in dev mode only, that a restore was refused.\n *\n * A refused restore is silent by design — the component shows its default view,\n * which is the correct thing for the user to see. But during development that\n * looks exactly like the restore never being wired up, so this says which it\n * was.\n */\nexport function svWarnRestoreRefused(selector: string, result: { ok: false; reason: SvRestoreReason; detail: string }): void {\n  if (typeof ngDevMode !== 'undefined' && ngDevMode) {\n    svWarn(`[styloviz] ${selector}: saved state ignored (${result.reason}) — ${result.detail}`);\n  }\n}\n","import {\n  svPersistState,\n  svRestoreState,\n  type SvRestoreLabels,\n  type SvRestoreReason,\n  type SvRestoreSpec,\n} from './persisted-state';\nimport { SV_CORE_LABELS } from '@styloviz/core/i18n';\n\n/**\n * ============================================================================\n *  Storage glue around the persisted-state envelope — `X-6`\n * ============================================================================\n *\n * `svPersistState` / `svRestoreState` decide what a blob MEANS. Every component\n * that keeps a layout in `localStorage` then needs the same five pieces of glue\n * around them, and each one it hand-rolls is a place to get one wrong:\n *\n *  1. **An SSR guard.** `localStorage` does not exist on the server, and merely\n *     reading the global throws a `SecurityError` in some privacy modes.\n *  2. **Legacy keys.** A renamed storage key is a lost layout unless the old\n *     key is tried — EACH old key, in order, not just the first one that holds\n *     something — and the winner is moved so the migration runs once.\n *  3. **Refusal reporting.** A refused blob falls back to defaults, which is\n *     right for the user and silent for the developer. Every refusal is\n *     returned, with the key it came from.\n *  4. **Cross-tab sync.** A `storage` event from another tab is validated like\n *     any other untrusted blob, and adopting it must not echo it back.\n *  5. **Not writing back what storage already holds.** Loading is not a\n *     change, a reset is not a change, and an adopted value is not a change.\n *\n * ★★ (5) is a BASELINE, not a one-shot \"skip the next write\" flag. The flag\n * version — \"the next save carrying exactly this value is a no-op\" — is only\n * cleared by a save of that exact value. When the value never changes (a reset\n * of a layout that was already at its default) the flag outlives the moment it\n * was set for, and swallows the user's LATER change back to that value. A\n * baseline is simply \"what storage is known to represent\": a save equal to it\n * is skipped, and every save that is written becomes the new baseline — so no\n * earlier call can ever suppress a real change.\n *\n * Deliberately NOT Angular: no injection, no listener. The component owns its\n * `window:storage` listener and hands the event to {@link SvPersistedStore.adopt},\n * which keeps this usable from any lifecycle and trivially testable.\n *\n * Consumers: `sv-splitter`. Widget Grid and Query Builder write the same\n * envelope through their own host-driven `serialize…`/`restore…` pair and can\n * adopt this store unchanged when they take on storage themselves.\n */\n\n/** A stored blob that could not be applied, and where it came from. */\nexport interface SvPersistedStoreRefusal {\n  /** The storage key the refused blob was read from. */\n  readonly key: string;\n  /** Machine-readable reason: `malformed`, `foreign`, `too-new` or `unmigratable`. */\n  readonly reason: SvRestoreReason;\n  /** One sentence, safe to show a user. */\n  readonly detail: string;\n}\n\n/** What {@link SvPersistedStore.load} found. */\nexport interface SvPersistedStoreLoad<T> {\n  /** The restored state, at the current version — or `null` when nothing restored. */\n  readonly state: T | null;\n  /** The key it came from: the primary key, a legacy key, or `null`. */\n  readonly from: string | null;\n  /** Every stored blob that was refused on the way, in the order tried. */\n  readonly refusals: readonly SvPersistedStoreRefusal[];\n}\n\n/** Options for {@link svPersistedStore}. */\nexport interface SvPersistedStoreOptions<T> {\n  /** The storage key. A function when the key is itself an input that can change. */\n  readonly key: string | (() => string);\n  /** The envelope schema: `kind`, `version`, `read`, and any `migrate`/`adoptLegacy`. */\n  readonly spec: SvRestoreSpec<T>;\n  /**\n   * Keys an earlier release wrote this state under. Tried in order ONLY when the\n   * primary key holds nothing; the first that restores is copied to the primary\n   * key and removed. Refused ones are reported and left where they are.\n   * @default []\n   */\n  readonly legacyKeys?: readonly string[] | (() => readonly string[]);\n  /**\n   * The storage to use, or `null` where there is none. The test seam, and the\n   * SSR guard: the default returns `localStorage` in a browser and `null` on the\n   * server or when access to it throws.\n   */\n  readonly storage?: () => Storage | null;\n  /**\n   * The words of a refusal's `detail` — pass the component's own labels (its\n   * package carries the ten restore keys) so `restoreRefused` reads in the\n   * app's language.\n   * @default SV_CORE_LABELS (English)\n   */\n  readonly labels?: SvRestoreLabels;\n}\n\n/** A versioned, SSR-safe, cross-tab-aware home for one piece of state. */\nexport interface SvPersistedStore<T> {\n  /**\n   * Read the stored state: the primary key, else each legacy key in order.\n   * The result becomes the baseline, so the first save of the same value is\n   * not written back.\n   */\n  load(): SvPersistedStoreLoad<T>;\n  /**\n   * Write `state` in its envelope — unless storage already represents exactly\n   * this value (the baseline), in which case nothing is written. `false` when\n   * storage is unavailable or refused the write (quota, privacy mode).\n   */\n  save(state: T): boolean;\n  /**\n   * Declare that storage already represents `state` without writing it — what\n   * a component calls after a load that restored nothing, so its defaults are\n   * not written over a blob it refused (a newer release's, say).\n   */\n  markSynced(state: T): void;\n  /**\n   * Remove the stored value. `represents` is what an empty key now means (the\n   * default the component resets to), so saving that default is not written\n   * straight back; the next different value is.\n   */\n  clear(represents?: T): void;\n  /**\n   * Validate another tab's write. Returns the state to apply, or `null` when\n   * the event is for another key or storage area, is a removal, or is refused.\n   * An adopted value becomes the baseline, so applying it does not echo back.\n   */\n  adopt(event: StorageEvent): T | null;\n}\n\nfunction defaultStorage(): Storage | null {\n  return svLocalStorage();\n}\n\n/**\n * `localStorage`, or `null` when there is none (a server) or it is blocked.\n *\n * ★★ USE THIS, NOT `typeof localStorage === 'undefined'`. With site data\n *    blocked, evaluating the global — `typeof` included — throws a\n *    `SecurityError`, so a guard written that way is itself the crash\n *    (1.0 audit, M4: stepper, product tour and widget grid all had it).\n */\nexport function svLocalStorage(): Storage | null {\n  try {\n    return typeof localStorage === 'undefined' ? null : localStorage;\n  } catch {\n    return null;\n  }\n}\n\n/** Create a store for one piece of versioned state. See the file header. */\nexport function svPersistedStore<T>(options: SvPersistedStoreOptions<T>): SvPersistedStore<T> {\n  const { spec, storage = defaultStorage, labels = SV_CORE_LABELS } = options;\n  const keyOf = (): string => (typeof options.key === 'function' ? options.key() : options.key);\n  const legacyOf = (): readonly string[] => {\n    const legacy = options.legacyKeys;\n    return (typeof legacy === 'function' ? legacy() : legacy) ?? [];\n  };\n\n  /**\n   * The serialized value storage is known to represent — and UNDER WHICH KEY.\n   *\n   * ★ Keyed, because the key can change (`persistKey` bound to an account id):\n   *   a bare value made a save under a new key look \"already written\" whenever\n   *   the layout happened to match, so nothing ever reached the new key.\n   */\n  let baseline: { key: string; value: string } | null = null;\n  const synced = (key: string, value: string): boolean =>\n    baseline !== null && baseline.key === key && baseline.value === value;\n\n  const serialize = (state: T): string =>\n    JSON.stringify(svPersistState(spec.kind, spec.version, state));\n\n  /** `null` for absent, unparseable or unavailable — none is a refusal worth reporting. */\n  const readJson = (store: Storage, key: string): unknown => {\n    try {\n      const raw = store.getItem(key);\n      return raw ? (JSON.parse(raw) as unknown) : null;\n    } catch {\n      return null;\n    }\n  };\n\n  const write = (store: Storage, key: string, serialized: string): boolean => {\n    try {\n      store.setItem(key, serialized);\n      return true;\n    } catch {\n      return false; // quota / privacy mode\n    }\n  };\n\n  const remove = (store: Storage, key: string): void => {\n    try { store.removeItem(key); } catch { /* storage unavailable */ }\n  };\n\n  return {\n    load() {\n      const store = storage();\n      const key = keyOf();\n      const refusals: SvPersistedStoreRefusal[] = [];\n      if (!store || !key) return { state: null, from: null, refusals };\n\n      const primary = readJson(store, key);\n      if (primary !== null) {\n        const restored = svRestoreState(primary, spec, labels);\n        if (!restored.ok) {\n          refusals.push({ key, reason: restored.reason, detail: restored.detail });\n          return { state: null, from: null, refusals };\n        }\n        baseline = { key, value: serialize(restored.state) };\n        return { state: restored.state, from: key, refusals };\n      }\n\n      // ★ EACH legacy key, in order: an unreadable one is reported and skipped,\n      //   not the end of the search.\n      for (const legacy of legacyOf()) {\n        if (!legacy || legacy === key) continue;\n        const blob = readJson(store, legacy);\n        if (blob === null) continue;\n        const restored = svRestoreState(blob, spec, labels);\n        if (!restored.ok) {\n          refusals.push({ key: legacy, reason: restored.reason, detail: restored.detail });\n          continue;\n        }\n        const serialized = serialize(restored.state);\n        if (write(store, key, serialized)) {\n          baseline = { key, value: serialized };\n          remove(store, legacy);\n        }\n        return { state: restored.state, from: legacy, refusals };\n      }\n      return { state: null, from: null, refusals };\n    },\n\n    save(state) {\n      const serialized = serialize(state);\n      const key = keyOf();\n      if (synced(key, serialized)) return true;\n      const store = storage();\n      if (!store || !key) return false;\n      if (!write(store, key, serialized)) return false;\n      baseline = { key, value: serialized };\n      return true;\n    },\n\n    markSynced(state) {\n      baseline = { key: keyOf(), value: serialize(state) };\n    },\n\n    clear(represents) {\n      const store = storage();\n      const key = keyOf();\n      if (store && key) remove(store, key);\n      baseline = represents === undefined ? null : { key, value: serialize(represents) };\n    },\n\n    adopt(event) {\n      const key = keyOf();\n      if (!key || event.key !== key) return null;\n      const store = storage();\n      if (store && event.storageArea && event.storageArea !== store) return null;\n      // ★ Another tab removed the value (its reset): storage no longer holds\n      //   our baseline, so the next save must write even if it matches.\n      if (event.newValue === null) {\n        baseline = null;\n        return null;\n      }\n      let blob: unknown;\n      try { blob = JSON.parse(event.newValue) as unknown; } catch { return null; }\n      const restored = svRestoreState(blob, spec, labels);\n      if (!restored.ok) return null;\n      baseline = { key, value: serialize(restored.state) };\n      return restored.state;\n    },\n  };\n}\n"],"mappings":";;AAsHA,SAAgB,eAAkB,MAAc,SAAiB,OAAQ;CACvE,OAAO;EAAE;EAAM;EAAS;CAAK;AAC/B;AAuBA,SAAgB,eACd,MACA,MACA,SAA0B,gBAAc;CAExC,MAAM,EAAE,MAAM,SAAS,gBAAgB;CAEvC,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GACzD,OAAO;EAAE,IAAI;EAAO,QAAQ;EAAa,QAAQ,OAAO;CAAiB;CAG3E,MAAM,SAAS;CAGf,IAAI,EAFa,OAAO,OAAO,YAAY,YAAY,OAAO,OAAO,eAAe,WAErE;EACb,MAAM,OAAO,cAAc,MAAM,KAAK;EACtC,IAAI,SAAS,MACX,OAAO;GACL,IAAI;GACJ,QAAQ;GACR,QAAQ,OAAO;EAChB;EAEH,OAAO,OAAO,QAAQ,MAAM,MAAM,MAAM;CAC1C;CAEA,IAAI,OAAO,YAAY,MACrB,OAAO;EACL,IAAI;EACJ,QAAQ;EACR,QAAQ,cAAc,OAAO,gBAAgB;GAAE,OAAO,OAAO,OAAO,OAAO;GAAG,UAAU;EAAI,CAAE;CAC/F;CAGH,MAAM,OAAO,OAAO;CACpB,IAAI,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,GACpC,OAAO;EAAE,IAAI;EAAO,QAAQ;EAAa,QAAQ,OAAO;CAAgB;CAE1E,IAAI,OAAO,SACT,OAAO;EACL,IAAI;EACJ,QAAQ;EACR,QAAQ,cAAc,OAAO,eAAe;GAAE,MAAM,OAAO,IAAI;GAAG,SAAS,OAAO,OAAO;EAAC,CAAE;CAC7F;CAGH,OAAO,OAAO,OAAO,UAAU,MAAM,MAAM,MAAM;AACnD;AAEA,SAAS,OAAU,OAAgB,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