/* eslint-disable @typescript-eslint/no-explicit-any */ import { TLPolygonShape, TLPolygonShapeProps } from '@tldraw/core' import { SVGContainer, TLComponentProps } from '@tldraw/react' import { observer } from 'mobx-react-lite' import { CustomStyleProps, withClampedStyles } from './style-props' import { getComputedColor } from '../color' interface PolygonShapeProps extends TLPolygonShapeProps, CustomStyleProps { type: 'polygon' } export class PolygonShape extends TLPolygonShape { static id = 'polygon' static defaultProps: PolygonShapeProps = { id: 'polygon', parentId: 'page', type: 'polygon', point: [0, 0], size: [100, 100], sides: 3, ratio: 1, isFlippedY: false, stroke: '', fill: '', noFill: false, strokeType: 'line', strokeWidth: 2, opacity: 1, } ReactComponent = observer(({ events, isErasing, isSelected }: TLComponentProps) => { const { offset: [x, y], props: { stroke, fill, noFill, strokeWidth, opacity, strokeType }, } = this const path = this.getVertices(strokeWidth / 2).join() return ( ) }) ReactIndicator = observer(() => { const { offset: [x, y], props: { strokeWidth }, } = this return ( ) }) validateProps = (props: Partial) => { if (props.sides !== undefined) props.sides = Math.max(props.sides, 3) return withClampedStyles(this, props) } /** * Get a svg group element that can be used to render the shape with only the props data. In the * base, draw any shape as a box. Can be overridden by subclasses. */ getShapeSVGJsx(opts: any) { // Do not need to consider the original point here const { offset: [x, y], props: { stroke, fill, noFill, strokeWidth, opacity, strokeType }, } = this const path = this.getVertices(strokeWidth / 2).join() return ( ) } }