import { classRegistry } from '../ClassRegistry'; import { FabricObject } from './Object/FabricObject'; import type { FabricObjectProps, SerializedObjectProps, TProps, } from './Object/types'; import type { ObjectEvents } from '../EventTypeDefs'; export const triangleDefaultValues = { width: 100, height: 100, }; export class Triangle< Props extends TProps = Partial, SProps extends SerializedObjectProps = SerializedObjectProps, EventSpec extends ObjectEvents = ObjectEvents > extends FabricObject implements FabricObjectProps { static ownDefaults: Record = triangleDefaultValues; static getDefaults() { return { ...super.getDefaults(), ...Triangle.ownDefaults }; } /** * @private * @param {CanvasRenderingContext2D} ctx Context to render on */ _render(ctx: CanvasRenderingContext2D) { const widthBy2 = this.width / 2, heightBy2 = this.height / 2; ctx.beginPath(); ctx.moveTo(-widthBy2, heightBy2); ctx.lineTo(0, -heightBy2); ctx.lineTo(widthBy2, heightBy2); ctx.closePath(); this._renderPaintInOrder(ctx); } /** * Returns svg representation of an instance * @return {Array} an array of strings with the specific svg representation * of the instance */ _toSVG() { const widthBy2 = this.width / 2, heightBy2 = this.height / 2, points = `${-widthBy2} ${heightBy2},0 ${-heightBy2},${widthBy2} ${heightBy2}`; return ['']; } } classRegistry.setClass(Triangle); classRegistry.setSVGClass(Triangle);