{"version":3,"file":"normalize-cell-input.cjs","sources":["../../../src/utils/normalize-cell-input.ts"],"sourcesContent":["import { dia } from '@joint/core';\nimport type {\n  ElementJSONInit,\n  LinkJSONInit,\n  CellId,\n  CellInput,\n  CellRef,\n} from '../types/cell.types';\nimport { toCellRecord } from '../state/data-mapping/cell-record-merge';\nimport { mapCellToAttributes } from '../state/data-mapping/cell-mapper';\n\n/**\n * Resolve a cell reference to its id.\n * @param cellRef - cell id or dia.Cell instance\n * @returns the cell id\n */\nexport function resolveCellRef(cellRef: CellRef): CellId {\n  if (cellRef instanceof dia.Cell) {\n    return cellRef.id as CellId;\n  }\n  return cellRef as CellId;\n}\n\n/**\n * Convert a cell input to its record form. `dia.Cell` instances are\n * converted via `toCellRecord`; plain records pass through unchanged.\n * @param input - plain record or dia.Cell instance\n * @returns normalized record\n */\nexport function cellInputToRecord<\n  Element extends ElementJSONInit = ElementJSONInit,\n  Link extends LinkJSONInit = LinkJSONInit,\n>(input: CellInput<Element, Link>): Element | Link {\n  if (input instanceof dia.Cell) {\n    return toCellRecord<Element, Link>(input);\n  }\n  return input;\n}\n\n/**\n * Convert a cell input to what `graph.resetCells` / `graph.addCells` accepts.\n * `dia.Cell` instances pass through directly; plain records are mapped to\n * JointJS attributes via `mapCellToAttributes`.\n * @param input - plain record or dia.Cell instance\n * @param graph - graph used for type-constructor resolution on records\n * @returns dia.Cell instance or attributes object ready for the graph\n */\nexport function cellInputToModel<\n  Element extends ElementJSONInit = ElementJSONInit,\n  Link extends LinkJSONInit = LinkJSONInit,\n>(input: CellInput<Element, Link>, graph: dia.Graph): dia.Cell | dia.Cell.JSONInit {\n  if (input instanceof dia.Cell) {\n    return input;\n  }\n  return mapCellToAttributes(input, graph);\n}\n"],"names":["dia","toCellRecord","mapCellToAttributes"],"mappings":";;;;;;;;;;;;;AA6BO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CA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