UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

2 lines 1.99 kB
import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import"../constants.min.mjs";import{classRegistry as t}from"../ClassRegistry.min.mjs";import{escapeXml as n}from"../util/lang_string.min.mjs";import{cacheProperties as r}from"./Object/defaultValues.min.mjs";import{FabricObject as i}from"./Object/FabricObject.min.mjs";import{SHARED_ATTRIBUTES as a}from"../parser/attributes.min.mjs";import{parseAttributes as o}from"../parser/parseAttributes.min.mjs";const s=[`rx`,`ry`];var c=class e extends i{static getDefaults(){return{...super.getDefaults(),...e.ownDefaults}}constructor(t){super(),Object.assign(this,e.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){let{rx:e,ry:t}=this;e&&!t?this.ry=e:t&&!e&&(this.rx=t)}_render(e){let{width:t,height:n}=this,r=-t/2,i=-n/2,a=this.rx?Math.min(this.rx,t/2):0,o=this.ry?Math.min(this.ry,n/2):0,s=a!==0||o!==0;e.beginPath(),e.moveTo(r+a,i),e.lineTo(r+t-a,i),s&&e.bezierCurveTo(r+t-.4477152502*a,i,r+t,i+.4477152502*o,r+t,i+o),e.lineTo(r+t,i+n-o),s&&e.bezierCurveTo(r+t,i+n-.4477152502*o,r+t-.4477152502*a,i+n,r+t-a,i+n),e.lineTo(r+a,i+n),s&&e.bezierCurveTo(r+.4477152502*a,i+n,r,i+n-.4477152502*o,r,i+n-o),e.lineTo(r,i+o),s&&e.bezierCurveTo(r,i+.4477152502*o,r+.4477152502*a,i,r+a,i),e.closePath(),this._renderPaintInOrder(e)}toObject(e=[]){return super.toObject([...s,...e])}_toSVG(){let{width:e,height:t,rx:r,ry:i}=this;return[`<rect `,`COMMON_PARTS`,`x="${-e/2}" y="${-t/2}" rx="${n(r)}" ry="${n(i)}" width="${n(e)}" height="${n(t)}" />\n`]}static async fromElement(e,t,n){let{left:r=0,top:i=0,width:a=0,height:s=0,visible:c=!0,...l}=o(e,this.ATTRIBUTE_NAMES,n);return new this({...t,...l,left:r,top:i,width:a,height:s,visible:!!(c&&a&&s)})}};e(c,`type`,`Rect`),e(c,`cacheProperties`,[...r,...s]),e(c,`ownDefaults`,{rx:0,ry:0}),e(c,`ATTRIBUTE_NAMES`,[...a,`x`,`y`,`rx`,`ry`,`width`,`height`]),t.setClass(c),t.setSVGClass(c);export{c as Rect}; //# sourceMappingURL=Rect.min.mjs.map