{
  "version": 3,
  "sources": ["../../../../src/lib/tools/SelectTool/selectHelpers.ts"],
  "sourcesContent": ["import {\n\tEditor,\n\tExtractShapeByProps,\n\tHALF_PI,\n\trichTextValidator,\n\tTLEventInfo,\n\tTLRichText,\n\tTLShape,\n\tTLShapeId,\n\tVec,\n\tVecLike,\n\tpointInPolygon,\n\tapproximately,\n} from '@tldraw/editor'\n\n/** @internal */\nexport function hasRichText(\n\tshape: TLShape\n): shape is ExtractShapeByProps<{ richText: TLRichText }> {\n\treturn 'richText' in shape.props && richTextValidator.isValid(shape.props.richText)\n}\n/**\n * Start editing a shape that has rich text, such as text, note, geo, or arrow shapes.\n * This will enter the editing state for the shape and optionally select all the text.\n *\n * @param editor - The editor instance.\n * @param shapeOrId - The shape to start editing. This shape must have a richText property with a TLRichText value.\n * @param options - Options: selectAll or info (TLEventInfo)\n *\n * @public\n */\nexport function startEditingShapeWithRichText(\n\teditor: Editor,\n\tshapeOrId: TLShape | TLShapeId,\n\toptions: { selectAll?: boolean; info?: TLEventInfo } = {}\n) {\n\tconst shape = typeof shapeOrId === 'string' ? editor.getShape(shapeOrId) : shapeOrId\n\tif (!shape) return\n\n\tif (!editor.canEditShape(shape)) return\n\n\tif (!hasRichText(shape)) {\n\t\tthrow new Error('Shape does not have rich text')\n\t}\n\t// Finish this shape and start editing the next one\n\teditor.setEditingShape(shape)\n\teditor.setCurrentTool('select.editing_shape', {\n\t\t...options.info,\n\t\ttarget: 'shape',\n\t\tshape: shape,\n\t})\n\tif (options.selectAll) {\n\t\teditor.emit('select-all-text', { shapeId: shape.id })\n\t}\n}\n\n/**\n * Start editing any editable shape. Shapes with rich text go through\n * `startEditingShapeWithRichText`; editable shapes without it (frame, video, embed) would\n * make that helper throw, so they enter the editing state directly.\n *\n * @internal\n */\nexport function startEditingShape(\n\teditor: Editor,\n\tshape: TLShape,\n\toptions: { selectAll?: boolean; info?: TLEventInfo } = {}\n) {\n\tif (!editor.canEditShape(shape)) return\n\tif (hasRichText(shape)) {\n\t\tstartEditingShapeWithRichText(editor, shape, options)\n\t\treturn\n\t}\n\teditor.setEditingShape(shape)\n\teditor.setCurrentTool('select.editing_shape', { ...options.info, target: 'shape', shape })\n}\n\n/**\n * Whether a page point is inside the selection's rotated bounding box. The box returned by\n * `getSelectionRotatedPageBounds` is expressed in the rotated frame, so a plain `containsPoint`\n * on it is only meaningful when the selection rotation is zero.\n *\n * @internal\n */\nexport function isPointInRotatedSelectionBounds(editor: Editor, point: VecLike) {\n\tconst selectionBounds = editor.getSelectionRotatedPageBounds()\n\tif (!selectionBounds) return false\n\n\tconst selectionRotation = editor.getSelectionRotation()\n\tif (!selectionRotation) return selectionBounds.containsPoint(point)\n\n\treturn pointInPolygon(\n\t\tpoint,\n\t\tselectionBounds.corners.map((c) => Vec.RotWith(c, selectionBounds.point, selectionRotation))\n\t)\n}\n\n/**\n * Whether a rotation is a multiple of 90 degrees. An exact `rotation % HALF_PI === 0` misses\n * page rotations accumulated through rotated parents, which land a few ulps off and silently\n * disable right-angle-only behavior such as bounds snapping.\n *\n * @internal\n */\nexport function isRightAngleRotation(rotation: number) {\n\tconst turns = rotation / HALF_PI\n\treturn approximately(turns, Math.round(turns))\n}\n"],
  "mappings": "AAAA;AAAA,EAGC;AAAA,EACA;AAAA,EAKA;AAAA,EAEA;AAAA,EACA;AAAA,OACM;AAGA,SAAS,YACf,OACyD;AACzD,SAAO,cAAc,MAAM,SAAS,kBAAkB,QAAQ,MAAM,MAAM,QAAQ;AACnF;AAWO,SAAS,8BACf,QACA,WACA,UAAuD,CAAC,GACvD;AACD,QAAM,QAAQ,OAAO,cAAc,WAAW,OAAO,SAAS,SAAS,IAAI;AAC3E,MAAI,CAAC,MAAO;AAEZ,MAAI,CAAC,OAAO,aAAa,KAAK,EAAG;AAEjC,MAAI,CAAC,YAAY,KAAK,GAAG;AACxB,UAAM,IAAI,MAAM,+BAA+B;AAAA,EAChD;AAEA,SAAO,gBAAgB,KAAK;AAC5B,SAAO,eAAe,wBAAwB;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