UNPKG

fabric

Version:

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

2 lines 2.59 kB
import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{CENTER as t}from"../constants.min.mjs";import{classRegistry as n}from"../ClassRegistry.min.mjs";import{Point as r}from"../Point.min.mjs";import{isFiller as i}from"../util/typeAssertions.min.mjs";import{makeBoundingBoxFromPoints as a}from"../util/misc/boundingBoxFromPoints.min.mjs";import{cacheProperties as o}from"./Object/defaultValues.min.mjs";import{FabricObject as s}from"./Object/FabricObject.min.mjs";import{SHARED_ATTRIBUTES as c}from"../parser/attributes.min.mjs";import{parseAttributes as l}from"../parser/parseAttributes.min.mjs";const u=[`x1`,`x2`,`y1`,`y2`];var d=class e extends s{constructor([t,n,r,i]=[0,0,0,0],a={}){super(),Object.assign(this,e.ownDefaults),this.setOptions(a),this.x1=t,this.x2=r,this.y1=n,this.y2=i,this._setWidthHeight();let{left:o,top:s}=a;typeof o==`number`&&this.set(`left`,o),typeof s==`number`&&this.set(`top`,s)}_setWidthHeight(){let{x1:e,y1:n,x2:i,y2:o}=this;this.width=Math.abs(i-e),this.height=Math.abs(o-n);let{left:s,top:c,width:l,height:u}=a([{x:e,y:n},{x:i,y:o}]),d=new r(s+l/2,c+u/2);this.setPositionByOrigin(d,t,t)}_set(e,t){return super._set(e,t),u.includes(e)&&this._setWidthHeight(),this}_render(e){e.beginPath();let t=this.calcLinePoints();e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.lineWidth=this.strokeWidth;let n=e.strokeStyle;var r;i(this.stroke)?e.strokeStyle=this.stroke.toLive(e):e.strokeStyle=(r=this.stroke)==null?e.fillStyle:r,this.stroke&&this._renderStroke(e),e.strokeStyle=n}_findCenterFromElement(){return new r((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(e=[]){return{...super.toObject(e),...this.calcLinePoints()}}_getNonTransformedDimensions(){let e=super._getNonTransformedDimensions();return this.strokeLineCap===`butt`&&(this.width===0&&(e.y-=this.strokeWidth),this.height===0&&(e.x-=this.strokeWidth)),e}calcLinePoints(){let{x1:e,x2:t,y1:n,y2:r,width:i,height:a}=this,o=e<=t?-.5:.5,s=n<=r?-.5:.5;return{x1:o*i,x2:o*-i,y1:s*a,y2:s*-a}}_toSVG(){let{x1:e,x2:t,y1:n,y2:r}=this.calcLinePoints();return[`<line `,`COMMON_PARTS`,`x1="${e}" y1="${n}" x2="${t}" y2="${r}" />\n`]}static async fromElement(e,t,n){let{x1:r=0,y1:i=0,x2:a=0,y2:o=0,...s}=l(e,this.ATTRIBUTE_NAMES,n);return new this([r,i,a,o],s)}static fromObject({x1:e,y1:t,x2:n,y2:r,...i}){return this._fromObject({...i,points:[e,t,n,r]},{extraParam:`points`})}};e(d,`type`,`Line`),e(d,`cacheProperties`,[...o,...u]),e(d,`ATTRIBUTE_NAMES`,c.concat(u)),n.setClass(d),n.setSVGClass(d);export{d as Line}; //# sourceMappingURL=Line.min.mjs.map