{"version":3,"file":"cell-selectors.cjs","sources":["../../../src/selectors/cell-selectors.ts"],"sourcesContent":["import type { CellId, CellRecord, ElementRecord, Computed } from '../types/cell.types';\n\n/**\n * Ready-made selectors to pass into {@link useCell} / {@link useCells}.\n *\n * Each one picks a single field off the resolved cell record so a component\n * re-renders only when that field changes, not on every unrelated cell update.\n * Reach for them when you want to subscribe to just the position, size, data,\n * or another slice of a cell.\n */\n\n// ── Element slice selectors ────────────────────────────────────────────────\n\n/**\n * Selects an element's top-left position `{ x, y }`. A subscribed component\n * re-renders only when the element moves.\n * @group Selectors\n * @param element - the resolved element record\n * @example\n * ```tsx\n * import { useCell, selectElementPosition } from '@joint/react';\n *\n * const { x, y } = useCell(elementId, selectElementPosition);\n * ```\n */\nexport function selectElementPosition(element: Computed<ElementRecord>) {\n  return element.position;\n}\n\n/**\n * Selects an element's bounding-box size `{ width, height }`. A subscribed\n * component re-renders only when the element is resized.\n * @group Selectors\n * @param element - the resolved element record\n * @example\n * ```tsx\n * import { useCell, selectElementSize } from '@joint/react';\n *\n * const { width, height } = useCell(elementId, selectElementSize);\n * ```\n */\nexport function selectElementSize(element: Computed<ElementRecord>) {\n  return element.size;\n}\n\n/**\n * Selects an element's rotation in degrees, falling back to `0` when the\n * element has no explicit angle.\n * @group Selectors\n * @param element - the resolved element record\n * @example\n * ```tsx\n * import { useCell, selectElementAngle } from '@joint/react';\n *\n * const angle = useCell(elementId, selectElementAngle);\n * ```\n */\nexport function selectElementAngle(element: Computed<ElementRecord>): number {\n  return element.angle ?? 0;\n}\n\n/**\n * Selects an element's custom `data` payload, typed as `ElementData`. Supply\n * the type when you call it (`selectElementData<NodeData>`) and TypeScript\n * carries `NodeData` through to the value {@link useCell} returns.\n * @group Selectors\n * @template ElementData - shape of the custom `data` payload carried on the element\n * @param element - the resolved element record\n * @example\n * ```tsx\n * import { useCell, selectElementData } from '@joint/react';\n *\n * type NodeData = { label: string };\n * const data = useCell(elementId, selectElementData<NodeData>);\n * ```\n */\nexport function selectElementData<ElementData = unknown>(\n  element: Computed<ElementRecord<ElementData>>\n): ElementData {\n  return element.data as ElementData;\n}\n\n// ── Cell-level selectors (work for both elements and links) ───────────────\n\n/**\n * Selects a cell's id. Prefer {@link useCellId} when the id is all you need —\n * it skips the selector machinery.\n * @group Selectors\n * @param cell - the resolved cell record\n * @example\n * ```tsx\n * import { useCell, selectCellId } from '@joint/react';\n *\n * const id = useCell(cellId, selectCellId);\n * ```\n */\nexport const selectCellId = (cell: Computed<CellRecord>) => cell.id;\n\n/**\n * Selects a cell's `type` discriminator — `'element'` for React elements or\n * `'link'` for React links. Handy for branching on the kind of cell.\n * @group Selectors\n * @param cell - the resolved cell record\n * @example\n * ```tsx\n * import { useCell, selectCellType } from '@joint/react';\n *\n * const type = useCell(cellId, selectCellType);\n * ```\n */\nexport const selectCellType = (cell: Computed<CellRecord>) => cell.type;\n\n/**\n * Selects the id of the cell this one is embedded in, or `null` for a\n * top-level cell. Works for elements and links alike, since any cell can be\n * embedded.\n * @group Selectors\n * @param cell - the resolved cell record\n * @example\n * ```tsx\n * import { useCell, selectCellParent } from '@joint/react';\n *\n * const parentId = useCell(cellId, selectCellParent);\n * ```\n */\nexport const selectCellParent = (cell: Computed<CellRecord>): CellId | null =>\n  cell.parent ?? null;\n\n/**\n * Selects the name of the paper layer the cell renders into, or `null` when it\n * sits on the paper's default layer.\n * @group Selectors\n * @param cell - the resolved cell record\n * @example\n * ```tsx\n * import { useCell, selectCellLayer } from '@joint/react';\n *\n * const layer = useCell(cellId, selectCellLayer);\n * ```\n */\nexport const selectCellLayer = (cell: Computed<CellRecord>): string | null =>\n  cell.layer ?? null;\n\n/**\n * Selects a cell's z-index — its paint order within a layer, where higher\n * values draw on top. Falls back to `0` when the cell has no explicit z-index.\n * @group Selectors\n * @param cell - the resolved cell record\n * @example\n * ```tsx\n * import { useCell, selectCellZIndex } from '@joint/react';\n *\n * const z = useCell(cellId, selectCellZIndex);\n * ```\n */\nexport const selectCellZIndex = (cell: Computed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