{
  "version": 3,
  "sources": ["../../src/shapes/TLLineShape.ts"],
  "sourcesContent": ["import { IndexKey, getIndices, objectMapFromEntries, sortByIndex } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { createShapePropsMigrationIds, createShapePropsMigrationSequence } from '../records/TLShape'\nimport { RecordProps } from '../recordsWithProps'\nimport { StyleProp } from '../styles/StyleProp'\nimport { DefaultColorStyle, TLDefaultColorStyle } from '../styles/TLColorStyle'\nimport { DefaultDashStyle, TLDefaultDashStyle } from '../styles/TLDashStyle'\nimport { DefaultSizeStyle, TLDefaultSizeStyle } from '../styles/TLSizeStyle'\nimport { TLBaseShape } from './TLBaseShape'\n\n/**\n * Style property for line shape spline interpolation. Determines how the line is rendered\n * between points - either as straight line segments or smooth cubic curves.\n *\n * @public\n * @example\n * ```ts\n * // Create a shape with cubic spline interpolation\n * const lineProps = {\n *   spline: 'cubic' as TLLineShapeSplineStyle,\n *   // other props...\n * }\n * ```\n */\nexport const LineShapeSplineStyle = StyleProp.defineEnum('tldraw:spline', {\n\tdefaultValue: 'line',\n\tvalues: ['cubic', 'line'],\n})\n\n/**\n * Type representing the spline style options for line shapes.\n * - 'line': Straight line segments between points\n * - 'cubic': Smooth cubic bezier curves between points\n *\n * @public\n */\nexport type TLLineShapeSplineStyle = T.TypeOf<typeof LineShapeSplineStyle>\n\n/**\n * Represents a single point in a line shape. Line shapes are made up of multiple points\n * that define the path of the line, with each point having coordinates and ordering information.\n *\n * @public\n * @example\n * ```ts\n * const linePoint: TLLineShapePoint = {\n *   id: 'a1',\n *   index: 'a1' as IndexKey,\n *   x: 100,\n *   y: 50\n * }\n * ```\n */\nexport interface TLLineShapePoint {\n\t/** Unique identifier for this point, used for tracking and ordering */\n\tid: string\n\t/** Fractional index key used for ordering points along the line */\n\tindex: IndexKey\n\t/** X coordinate of the point relative to the line shape's origin */\n\tx: number\n\t/** Y coordinate of the point relative to the line shape's origin */\n\ty: number\n}\n\nconst lineShapePointValidator: T.ObjectValidator<TLLineShapePoint> = T.object({\n\tid: T.string,\n\tindex: T.indexKey,\n\tx: T.number,\n\ty: T.number,\n})\n\n/**\n * Properties for a line shape. Line shapes represent multi-point lines or splines\n * that can be drawn by connecting multiple points with either straight segments or curves.\n *\n * @public\n * @example\n * ```ts\n * const lineProps: TLLineShapeProps = {\n *   color: 'black',\n *   dash: 'solid',\n *   size: 'm',\n *   spline: 'line',\n *   points: {\n *     'a1': { id: 'a1', index: 'a1', x: 0, y: 0 },\n *     'a2': { id: 'a2', index: 'a2', x: 100, y: 50 }\n *   },\n *   scale: 1\n * }\n * ```\n */\nexport interface TLLineShapeProps {\n\t/** Color style of the line stroke */\n\tcolor: TLDefaultColorStyle\n\t/** Dash pattern style for the line (solid, dashed, dotted) */\n\tdash: TLDefaultDashStyle\n\t/** Size/thickness style of the line stroke */\n\tsize: TLDefaultSizeStyle\n\t/** Interpolation style between points (straight lines or curved splines) */\n\tspline: TLLineShapeSplineStyle\n\t/** Dictionary of points that make up the line, keyed by point ID */\n\tpoints: Record<string, TLLineShapePoint>\n\t/** Scale factor applied to the line shape for display */\n\tscale: number\n}\n\n/**\n * A line shape that represents a multi-point line or spline on the canvas. Line shapes\n * allow users to draw connected paths with multiple points, supporting both straight\n * line segments and smooth curved splines.\n *\n * @public\n * @example\n * ```ts\n * const lineShape: TLLineShape = {\n *   id: 'shape:line1',\n *   type: 'line',\n *   x: 100,\n *   y: 100,\n *   rotation: 0,\n *   index: 'a1',\n *   parentId: 'page:main',\n *   isLocked: false,\n *   opacity: 1,\n *   props: {\n *     color: 'red',\n *     dash: 'dashed',\n *     size: 'l',\n *     spline: 'cubic',\n *     points: {\n *       'start': { id: 'start', index: 'a1', x: 0, y: 0 },\n *       'end': { id: 'end', index: 'a2', x: 200, y: 100 }\n *     },\n *     scale: 1\n *   },\n *   meta: {},\n *   typeName: 'shape'\n * }\n * ```\n */\nexport type TLLineShape = TLBaseShape<'line', TLLineShapeProps>\n\n/**\n * Validation schema for line shape properties. Defines the runtime validation rules\n * for all properties of line shapes, ensuring data integrity and type safety.\n *\n * @public\n * @example\n * ```ts\n * import { lineShapeProps } from '@tldraw/tlschema'\n *\n * // Used internally by the validation system\n * const validator = T.object(lineShapeProps)\n * const validatedProps = validator.validate(someLineProps)\n * ```\n */\nexport const lineShapeProps: RecordProps<TLLineShape> = {\n\tcolor: DefaultColorStyle,\n\tdash: DefaultDashStyle,\n\tsize: DefaultSizeStyle,\n\tspline: LineShapeSplineStyle,\n\tpoints: T.dict(T.string, lineShapePointValidator),\n\tscale: T.nonZeroNumber,\n}\n\n/**\n * Version identifiers for line shape migrations. These version numbers track\n * significant schema changes over time, enabling proper data migration between versions.\n *\n * @public\n */\nexport const lineShapeVersions = createShapePropsMigrationIds('line', {\n\tAddSnapHandles: 1,\n\tRemoveExtraHandleProps: 2,\n\tHandlesToPoints: 3,\n\tPointIndexIds: 4,\n\tAddScale: 5,\n})\n\n/**\n * Migration sequence for line shapes. Handles schema evolution over time by defining\n * how to upgrade and downgrade line shape data between different versions. Includes\n * major structural changes like the transition from handles to points and the addition\n * of scaling support.\n *\n * @public\n */\nexport const lineShapeMigrations = createShapePropsMigrationSequence({\n\tsequence: [\n\t\t{\n\t\t\tid: lineShapeVersions.AddSnapHandles,\n\t\t\tup: (props) => {\n\t\t\t\tfor (const handle of Object.values(props.handles)) {\n\t\t\t\t\t;(handle as any).canSnap = true\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: 'retired',\n\t\t},\n\t\t{\n\t\t\tid: lineShapeVersions.RemoveExtraHandleProps,\n\t\t\tup: (props) => {\n\t\t\t\tprops.handles = objectMapFromEntries(\n\t\t\t\t\tObject.values(props.handles).map((handle: any) => [\n\t\t\t\t\t\thandle.index,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tx: handle.x,\n\t\t\t\t\t\t\ty: handle.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t])\n\t\t\t\t)\n\t\t\t},\n\t\t\tdown: (props) => {\n\t\t\t\tconst handles = Object.entries(props.handles)\n\t\t\t\t\t.map(([index, handle]: any) => ({ index, ...handle }))\n\t\t\t\t\t.sort(sortByIndex)\n\t\t\t\tprops.handles = Object.fromEntries(\n\t\t\t\t\thandles.map((handle, i) => {\n\t\t\t\t\t\tconst id =\n\t\t\t\t\t\t\ti === 0 ? 'start' : i === handles.length - 1 ? 'end' : `handle:${handle.index}`\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\ttype: 'vertex',\n\t\t\t\t\t\t\t\tcanBind: false,\n\t\t\t\t\t\t\t\tcanSnap: true,\n\t\t\t\t\t\t\t\tindex: handle.index,\n\t\t\t\t\t\t\t\tx: handle.x,\n\t\t\t\t\t\t\t\ty: handle.y,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t]\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: lineShapeVersions.HandlesToPoints,\n\t\t\tup: (props) => {\n\t\t\t\tconst sortedHandles = (\n\t\t\t\t\tObject.entries(props.handles) as [IndexKey, { x: number; y: number }][]\n\t\t\t\t)\n\t\t\t\t\t.map(([index, { x, y }]) => ({ x, y, index }))\n\t\t\t\t\t.sort(sortByIndex)\n\n\t\t\t\tprops.points = sortedHandles.map(({ x, y }) => ({ x, y }))\n\t\t\t\tdelete props.handles\n\t\t\t},\n\t\t\tdown: (props) => {\n\t\t\t\tconst indices = getIndices(props.points.length)\n\n\t\t\t\tprops.handles = Object.fromEntries(\n\t\t\t\t\tprops.points.map((handle: { x: number; y: number }, i: number) => {\n\t\t\t\t\t\tconst index = indices[i]\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tx: handle.x,\n\t\t\t\t\t\t\t\ty: handle.y,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t]\n\t\t\t\t\t})\n\t\t\t\t)\n\n\t\t\t\tdelete props.points\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: lineShapeVersions.PointIndexIds,\n\t\t\tup: (props) => {\n\t\t\t\tconst indices = getIndices(props.points.length)\n\n\t\t\t\tprops.points = Object.fromEntries(\n\t\t\t\t\tprops.points.map((point: { x: number; y: number }, i: number) => {\n\t\t\t\t\t\tconst id = indices[i]\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tid: id,\n\t\t\t\t\t\t\t\tindex: id,\n\t\t\t\t\t\t\t\tx: point.x,\n\t\t\t\t\t\t\t\ty: point.y,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t]\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t},\n\t\t\tdown: (props) => {\n\t\t\t\tconst sortedHandles = (\n\t\t\t\t\tObject.values(props.points) as { x: number; y: number; index: IndexKey }[]\n\t\t\t\t).sort(sortByIndex)\n\n\t\t\t\tprops.points = sortedHandles.map(({ x, y }) => ({ x, y }))\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: lineShapeVersions.AddScale,\n\t\t\tup: (props) => {\n\t\t\t\tprops.scale = 1\n\t\t\t},\n\t\t\tdown: (props) => {\n\t\t\t\tdelete props.scale\n\t\t\t},\n\t\t},\n\t],\n})\n"],
  "mappings": "AAAA,SAAmB,YAAY,sBAAsB,mBAAmB;AACxE,SAAS,SAAS;AAClB,SAAS,8BAA8B,yCAAyC;AAEhF,SAAS,iBAAiB;AAC1B,SAAS,yBAA8C;AACvD,SAAS,wBAA4C;AACrD,SAAS,wBAA4C;AAiB9C,MAAM,uBAAuB,UAAU,WAAW,iBAAiB;AAAA,EACzE,cAAc;AAAA,EACd,QAAQ,CAAC,SAAS,MAAM;AACzB,CAAC;AAqCD,MAAM,0BAA+D,EAAE,OAAO;AAAA,EAC7E,IAAI,EAAE;AAAA,EACN,OAAO,EAAE;AAAA,EACT,GAAG,EAAE;AAAA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