{"version":3,"file":"cell-mapper.cjs","sources":["../../../../src/state/data-mapping/cell-mapper.ts"],"sourcesContent":["import type { dia } from '@joint/core';\nimport type { ElementJSONInit, LinkJSONInit } from '../../types/cell.types';\nimport { isElementType, isLinkType } from '../../utils/cell-type';\nimport { mapElementToAttributes } from './element-mapper';\nimport { mapLinkToAttributes } from './link-mapper';\n\n/**\n * Route a unified cell record to its JointJS attributes, preserving any\n * custom `type` that isn't the library default.\n *\n * Known element / link types, including any `dia.Element` or `dia.Link`\n * subclass registered in the graph's `cellNamespace`, go through the typed\n * mappers (`mapElementToAttributes` / `mapLinkToAttributes`) so that\n * declarative fields like `portMap`, `style`, and `labelMap` are expanded\n * correctly. Types the graph cannot classify pass through verbatim, the\n * user-chosen `type` and attributes are authoritative.\n *\n * Classification is done via `graph.getTypeConstructor(type).prototype.isElement()`\n * / `.isLink()`, so naive `cell.type === ELEMENT_MODEL_TYPE` checks that miss\n * custom subtypes no longer leak into the mapper pipeline.\n * @template ElementData - user data shape on elements\n * @template LinkData - user data shape on links\n * @param cell - cell record to map\n * @param graph - active graph, used to classify custom cell types\n * @returns JointJS cell attributes with `id` guaranteed\n */\nexport function mapCellToAttributes<\n  Element extends ElementJSONInit = ElementJSONInit,\n  Link extends LinkJSONInit = LinkJSONInit,\n>(cell: Element | Link, graph: dia.Graph): dia.Cell.JSONInit {\n  // `ElementAttributes` / `LinkAttributes` only declare `id`; the discriminator\n  // `type` lives on `WithType` (which `ElementRecord` / `LinkRecord` extend).\n  // Read it through a narrow cast so the index signature\n  // (`[key: string]: unknown`) doesn't widen `cell.type` to `unknown`.\n  const cellType = cell.type;\n  if (isElementType(cellType, graph)) {\n    const attributes = mapElementToAttributes(cell);\n    if (cell.id !== undefined) attributes.id = cell.id;\n    return attributes;\n  }\n  if (isLinkType(cellType, graph)) {\n    const attributes = mapLinkToAttributes(cell);\n    if (cell.id !== undefined) attributes.id = cell.id;\n    return attributes;\n  }\n  // fallback for unrecognized types: pass through verbatim (id may be omitted —\n  // JointJS will assign one).\n  return { ...cell } as dia.Cell.JSONInit;\n}\n"],"names":["cellType","isElementType","mapElementToAttributes","isLinkType","mapLinkToAttributes"],"mappings":";;;;;;;;;;;;;AA0BO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAGd,CAAA,CAAA,CAAA,GAAsB,KAAA,CAAA,CAAqC,CAAA;AAK3D,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAMA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,IAAW,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA;AACtB,CAAA,CAAA,IAAIC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,CAAcD,UAAA,CAAA,CAAU,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAG,CAAA;AAClC,CAAA,CAAA,CAAA,CAAA,MAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAaE,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,EAAuB,IAAI,CAAA,CAAA;AAC9C,CAAA,CAAA,CAAA,CAAA,C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