fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 2.85 kB
Source Map (JSON)
{"version":3,"file":"Triangle.mjs","names":[],"sources":["../../../src/shapes/Triangle.ts"],"sourcesContent":["import { classRegistry } from '../ClassRegistry';\nimport { FabricObject } from './Object/FabricObject';\nimport type { FabricObjectProps, SerializedObjectProps } from './Object/types';\nimport type { TClassProperties, TOptions } from '../typedefs';\nimport type { ObjectEvents } from '../EventTypeDefs';\n\nexport const triangleDefaultValues: Partial<TClassProperties<Triangle>> = {\n width: 100,\n height: 100,\n};\n\nexport class Triangle<\n Props extends TOptions<FabricObjectProps> = Partial<FabricObjectProps>,\n SProps extends SerializedObjectProps = SerializedObjectProps,\n EventSpec extends ObjectEvents = ObjectEvents,\n>\n extends FabricObject<Props, SProps, EventSpec>\n implements FabricObjectProps\n{\n static type = 'Triangle';\n\n static ownDefaults = triangleDefaultValues;\n\n static getDefaults(): Record<string, any> {\n return { ...super.getDefaults(), ...Triangle.ownDefaults };\n }\n\n /**\n * Constructor\n * @param {Object} [options] Options object\n */\n constructor(options?: Props) {\n super();\n Object.assign(this, Triangle.ownDefaults);\n this.setOptions(options);\n }\n\n /**\n * @private\n * @param {CanvasRenderingContext2D} ctx Context to render on\n */\n _render(ctx: CanvasRenderingContext2D) {\n const widthBy2 = this.width / 2,\n heightBy2 = this.height / 2;\n\n ctx.beginPath();\n ctx.moveTo(-widthBy2, heightBy2);\n ctx.lineTo(0, -heightBy2);\n ctx.lineTo(widthBy2, heightBy2);\n ctx.closePath();\n\n this._renderPaintInOrder(ctx);\n }\n\n /**\n * Returns svg representation of an instance\n * @return {Array} an array of strings with the specific svg representation\n * of the instance\n */\n _toSVG() {\n const widthBy2 = this.width / 2,\n heightBy2 = this.height / 2,\n points = `${-widthBy2} ${heightBy2},0 ${-heightBy2},${widthBy2} ${heightBy2}`;\n return ['<polygon ', 'COMMON_PARTS', 'points=\"', points, '\" />'];\n }\n}\n\nclassRegistry.setClass(Triangle);\nclassRegistry.setSVGClass(Triangle);\n"],"mappings":";;;;AAMA,MAAa,wBAA6D;CACxE,OAAO;CACP,QAAQ;CACT;AAED,IAAa,WAAb,MAAa,iBAKH,aAEV;CAKE,OAAO,cAAmC;AACxC,SAAO;GAAE,GAAG,MAAM,aAAa;GAAE,GAAG,SAAS;GAAa;;;;;;CAO5D,YAAY,SAAiB;AAC3B,SAAO;AACP,SAAO,OAAO,MAAM,SAAS,YAAY;AACzC,OAAK,WAAW,QAAQ;;;;;;CAO1B,QAAQ,KAA+B;EACrC,MAAM,WAAW,KAAK,QAAQ,GAC5B,YAAY,KAAK,SAAS;AAE5B,MAAI,WAAW;AACf,MAAI,OAAO,CAAC,UAAU,UAAU;AAChC,MAAI,OAAO,GAAG,CAAC,UAAU;AACzB,MAAI,OAAO,UAAU,UAAU;AAC/B,MAAI,WAAW;AAEf,OAAK,oBAAoB,IAAI;;;;;;;CAQ/B,SAAS;EACP,MAAM,WAAW,KAAK,QAAQ,GAC5B,YAAY,KAAK,SAAS;AAE5B,SAAO;GAAC;GAAa;GAAgB;GAD1B,GAAG,CAAC,SAAS,GAAG,UAAU,KAAK,CAAC,UAAU,GAAG,SAAS,GAAG;GACX;GAAO;;;0BA5C3D,QAAO,WAAW;0BAElB,eAAc,sBAAsB;AA8C7C,cAAc,SAAS,SAAS;AAChC,cAAc,YAAY,SAAS"}