{"version":3,"file":"differential-YEjxNScf.mjs","names":[],"sources":["../src/styles/differential.ts"],"sourcesContent":["// DifferentialStyle (DXF) — partial style overlay used by conditional\n// formatting and Excel-table style elements. Mirrors\n// openpyxl/openpyxl/styles/differential.py.\n//\n// Where a NamedStyle / CellXf carries a *complete* style snapshot, a\n// DifferentialStyle carries only the components that override the base.\n// The Stylesheet keeps DXFs in their own pool (`dxfs`) and conditional-\n// formatting rules / table-style elements reference them by index.\n\nimport { stableStringify } from '../utils/stable-stringify';\nimport type { Alignment } from './alignment';\nimport type { Border } from './borders';\nimport type { Fill } from './fills';\nimport type { Font } from './fonts';\nimport type { NumberFormat } from './numbers';\nimport type { Protection } from './protection';\nimport type { Stylesheet } from './stylesheet';\n\n/**\n * Differential (\"partial\") style. Every component is optional; only\n * the set fields override the base style of whatever the DXF is\n * applied to.\n */\nexport interface DifferentialStyle {\n  readonly font?: Font;\n  readonly fill?: Fill;\n  readonly border?: Border;\n  readonly alignment?: Alignment;\n  readonly protection?: Protection;\n  /**\n   * NumberFormat carries both the id and the format code so DXFs can\n   * reference custom user-defined number formats without ambiguity.\n   */\n  readonly numFmt?: NumberFormat;\n}\n\nexport function makeDifferentialStyle(opts: Partial<DifferentialStyle> = {}): DifferentialStyle {\n  const out: { -readonly [K in keyof DifferentialStyle]: DifferentialStyle[K] } = {};\n  if (opts.font !== undefined) out.font = opts.font;\n  if (opts.fill !== undefined) out.fill = opts.fill;\n  if (opts.border !== undefined) out.border = opts.border;\n  if (opts.alignment !== undefined) out.alignment = opts.alignment;\n  if (opts.protection !== undefined) out.protection = opts.protection;\n  if (opts.numFmt !== undefined) out.numFmt = opts.numFmt;\n  return Object.freeze(out);\n}\n\n/**\n * Stylesheet pool extension. The DXF list is allocated lazily on first\n * use so empty stylesheets stay slim.\n */\nexport interface StylesheetWithDxfs extends Stylesheet {\n  dxfs?: DifferentialStyle[];\n  _dxfIdByKey?: Map<string, number>;\n}\n\n/**\n * Add a DifferentialStyle to the stylesheet's `dxfs` pool. Returns\n * the 0-based index. Idempotent on structural equality (via\n * stableStringify).\n */\nexport function addDxf(ss: Stylesheet, dxf: DifferentialStyle): number {\n  const w = ss as StylesheetWithDxfs;\n  if (w.dxfs === undefined) w.dxfs = [];\n  if (w._dxfIdByKey === undefined) w._dxfIdByKey = new Map();\n  const key = stableStringify(dxf);\n  const cached = w._dxfIdByKey.get(key);\n  if (cached !== undefined) return cached;\n  const id = w.dxfs.length;\n  w.dxfs.push(dxf);\n  w._dxfIdByKey.set(key, id);\n  return id;\n}\n\n/** Read-only access to the dxfs pool. Returns `[]` when none registered. */\nexport function getDxfs(ss: Stylesheet): ReadonlyArray<DifferentialStyle> {\n  return (ss as StylesheetWithDxfs).dxfs ?? [];\n}\n"],"mappings":";;AAoCA,SAAgB,sBAAsB,OAAmC,CAAC,GAAsB;CAC9F,MAAM,MAA0E,CAAC;CACjF,IAAI,KAAK,SAAS,KAAA,GAAW,IAAI,OAAO,KAAK;CAC7C,IAAI,KAAK,SAAS,KAAA,GAAW,IAAI,OAAO,KAAK;CAC7C,IAAI,KAAK,WAAW,KAAA,GAAW,IAAI,SAAS,KAAK;CACjD,IAAI,KAAK,cAAc,KAAA,GAAW,IAAI,YAAY,KAAK;CACvD,IAAI,KAAK,eAAe,KAAA,GAAW,IAAI,aAAa,KAAK;CACzD,IAAI,KAAK,WAAW,KAAA,GAAW,IAAI,SAAS,KAAK;CACjD,OAAO,OAAO,OAAO,GAAG;AAC1B;;;;;;AAgBA,SAAgB,OAAO,IAAgB,KAAgC;CACrE,MAAM,IAAI;CACV,IAAI,EAAE,SAAS,KAAA,GAAW,EAAE,OAAO,CAAC;CACpC,IAAI,EAAE,gBAAgB,KAAA,GAAW,EAAE,8BAAc,IAAI,IAAI;CACzD,MAAM,MAAM,gBAAgB,GAAG;CAC/B,MAAM,SAAS,EAAE,YAAY,IAAI,GAAG;CACpC,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,KAAK,EAAE,KAAK;CAClB,EAAE,KAAK,KAAK,GAAG;CACf,EAAE,YAAY,IAAI,KAAK,EAAE;CACzB,OAAO;AACT;;AAGA,SAAgB,QAAQ,IAAkD;CACxE,OAAQ,GAA0B,QAAQ,CAAC;AAC7C"}