{"version":3,"file":"snapshot-for-wire.mjs","names":[],"sources":["../src/snapshot-for-wire.ts"],"sourcesContent":["/**\n * Browser-safe wire-format helper. Exported through the\n * `@unpunnyfuns/swatchbook-core/snapshot-for-wire` subpath so the\n * addon's virtual-module emitter and HMR re-broadcast share one\n * implementation — the field list and the Map-to-Object conversions\n * live in one place rather than three.\n *\n * Builds a JSON-friendly subset of `Project` plus the emitter's CSS\n * string. Drops fields that don't survive `JSON.stringify` (the\n * resolver function on `parserInput`, the `resolveAt` closure). Slims\n * `listing` entries down to the three fields blocks actually read\n * (`names`, `previewValue`, `source`).\n *\n * Consumers:\n * - addon's Vite plugin emits the virtual ESM module body from this\n * - addon's Vite plugin sends it as the HMR custom event payload\n * - the addon's `host-source.ts` listener reads the same shape from\n *   `TOKENS_UPDATED_EVENT` and forwards it into blocks' ambient project\n *   source\n *\n * The `InitPayload` shape in `packages/addon/src/channel-types.ts` is\n * a subset of this (manager-side doesn't need CSS or listing); kept\n * separately for now because the manager bundle has its own\n * import-resolution constraints.\n */\nimport type { ListedToken } from '@terrazzo/plugin-token-listing';\nimport type { ColorFormat } from '#/color-formats.ts';\nimport type { TokenGraph } from '#/token-graph/types.ts';\nimport type { Project } from '#/types.ts';\n\n/**\n * Slimmed `ListedToken` — the three fields blocks actually consume.\n * Drops `originalValue` (large; not needed for display), the wrapping\n * `$extensions` envelope, and per-platform listings the blocks don't\n * render yet.\n */\nexport interface SlimListedToken {\n  names: Record<string, string>;\n  previewValue?: ListedToken['$extensions']['app.terrazzo.listing']['previewValue'];\n  source?: ListedToken['$extensions']['app.terrazzo.listing']['source'];\n}\n\n/**\n * JSON-friendly snapshot of `Project` for wire transport (virtual\n * module body, HMR custom event, the addon's TOKENS_UPDATED_EVENT\n * Storybook-channel broadcast). Field set is the union every blocks-side\n * consumer reads; the manager-side INIT_EVENT shape is a subset (no\n * `css` / `listing`).\n */\nexport interface SnapshotForWire {\n  axes: Project['axes'];\n  disabledAxes: Project['disabledAxes'];\n  presets: Project['presets'];\n  diagnostics: Project['diagnostics'];\n  cssVarPrefix: string;\n  /** Project-wide baseline for the block row-indicator strip; `config.indicators` passed through verbatim. */\n  indicators: Readonly<Record<string, boolean>>;\n  /** Starting color format for blocks that display color values; `config.defaultColorFormat`, defaulted to `'hex'`. */\n  defaultColorFormat: ColorFormat;\n  css: string;\n  listing: Readonly<Record<string, SlimListedToken>>;\n  defaultTuple: Project['defaultTuple'];\n  tokenGraph: TokenGraph;\n}\n\n/**\n * Build the wire snapshot from a `Project` plus the emitter's CSS\n * string. The CSS isn't on `Project` itself — it's the\n * `emitAxisProjectedCss(project)` output that the addon's plugin\n * computes alongside the project load.\n */\nexport function snapshotForWire(project: Project, css: string): SnapshotForWire {\n  return {\n    axes: project.axes,\n    disabledAxes: project.disabledAxes,\n    presets: project.presets,\n    diagnostics: project.diagnostics,\n    cssVarPrefix: project.config.cssVarPrefix ?? '',\n    indicators: project.config.indicators ?? {},\n    defaultColorFormat: project.config.defaultColorFormat ?? 'hex',\n    css,\n    listing: slimListing(project.listing),\n    defaultTuple: project.defaultTuple,\n    tokenGraph: project.tokenGraph,\n  };\n}\n\nfunction slimListing(listing: Project['listing']): Record<string, SlimListedToken> {\n  const out: Record<string, SlimListedToken> = {};\n  for (const [path, entry] of Object.entries(listing)) {\n    const ext = entry.$extensions['app.terrazzo.listing'];\n    const slim: SlimListedToken = { names: ext.names };\n    if (ext.previewValue !== undefined) slim.previewValue = ext.previewValue;\n    if (ext.source !== undefined) slim.source = ext.source;\n    out[path] = slim;\n  }\n  return out;\n}\n"],"mappings":";;;;;;;AAuEA,SAAgB,gBAAgB,SAAkB,KAA8B;AAC9E,QAAO;EACL,MAAM,QAAQ;EACd,cAAc,QAAQ;EACtB,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,cAAc,QAAQ,OAAO,gBAAgB;EAC7C,YAAY,QAAQ,OAAO,cAAc,EAAE;EAC3C,oBAAoB,QAAQ,OAAO,sBAAsB;EACzD;EACA,SAAS,YAAY,QAAQ,QAAQ;EACrC,cAAc,QAAQ;EACtB,YAAY,QAAQ;EACrB;;AAGH,SAAS,YAAY,SAA8D;CACjF,MAAM,MAAuC,EAAE;AAC/C,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,EAAE;EACnD,MAAM,MAAM,MAAM,YAAY;EAC9B,MAAM,OAAwB,EAAE,OAAO,IAAI,OAAO;AAClD,MAAI,IAAI,iBAAiB,KAAA,EAAW,MAAK,eAAe,IAAI;AAC5D,MAAI,IAAI,WAAW,KAAA,EAAW,MAAK,SAAS,IAAI;AAChD,MAAI,QAAQ;;AAEd,QAAO"}