UNPKG

fabric

Version:

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

2 lines 5.02 kB
import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{config as t}from"../config.min.mjs";import{SKEW_X as n,SKEW_Y as r}from"../constants.min.mjs";import{classRegistry as i}from"../ClassRegistry.min.mjs";import{Point as a}from"../Point.min.mjs";import{degreesToRadians as o}from"../util/misc/radiansDegreesConversion.min.mjs";import{calcDimensionsMatrix as s,transformPoint as c}from"../util/misc/matrix.min.mjs";import{toFixed as l}from"../util/misc/toFixed.min.mjs";import{escapeXml as u}from"../util/lang_string.min.mjs";import{makeBoundingBoxFromPoints as d}from"../util/misc/boundingBoxFromPoints.min.mjs";import{cacheProperties as f}from"./Object/defaultValues.min.mjs";import{FabricObject as p}from"./Object/FabricObject.min.mjs";import{projectStrokeOnPoints as m}from"../util/misc/projectStroke/index.min.mjs";import{SHARED_ATTRIBUTES as h}from"../parser/attributes.min.mjs";import{parseAttributes as g}from"../parser/parseAttributes.min.mjs";import{parsePointsAttribute as _}from"../parser/parsePointsAttribute.min.mjs";const v={exactBoundingBox:!1};var y=class n extends p{static getDefaults(){return{...super.getDefaults(),...n.ownDefaults}}constructor(t=[],r={}){super(),e(this,`strokeDiff`,void 0),Object.assign(this,n.ownDefaults),this.setOptions(r),this.points=t;let{left:i,top:a}=r;this.initialized=!0,this.setBoundingBox(!0),typeof i==`number`&&this.set(`left`,i),typeof a==`number`&&this.set(`top`,a)}isOpen(){return!0}_projectStrokeOnPoints(e){return m(this.points,e,this.isOpen())}_calcDimensions(e){e={scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth,...e||{}};let t=this.exactBoundingBox?this._projectStrokeOnPoints(e).map(e=>e.projectedPoint):this.points;if(t.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new a,strokeOffset:new a,strokeDiff:new a};let n=d(t),r=s({...e,scaleX:1,scaleY:1}),i=d(this.points.map(e=>c(e,r,!0))),l=new a(this.scaleX,this.scaleY),u=n.left+n.width/2,f=n.top+n.height/2;return this.exactBoundingBox&&(u-=f*Math.tan(o(this.skewX)),f-=u*Math.tan(o(this.skewY))),{...n,pathOffset:new a(u,f),strokeOffset:new a(i.left,i.top).subtract(new a(n.left,n.top)).multiply(l),strokeDiff:new a(n.width,n.height).subtract(new a(i.width,i.height)).multiply(l)}}_findCenterFromElement(){let e=d(this.points);return new a(e.left+e.width/2,e.top+e.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(e){let{left:t,top:n,width:r,height:i,pathOffset:o,strokeOffset:s,strokeDiff:c}=this._calcDimensions();this.set({width:r,height:i,pathOffset:o,strokeOffset:s,strokeDiff:c}),e&&this.setPositionByOrigin(new a(t+r/2,n+i/2),`center`,`center`)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new a(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(e={}){if(this.exactBoundingBox){let o;if(Object.keys(e).some(e=>this.strokeUniform||this.constructor.layoutProperties.includes(e))){var t,n;let{width:r,height:i}=this._calcDimensions(e);o=new a((t=e.width)==null?r:t,(n=e.height)==null?i:n)}else{var r,i;o=new a((r=e.width)==null?this.width:r,(i=e.height)==null?this.height:i)}return o.multiply(new a(e.scaleX||this.scaleX,e.scaleY||this.scaleY))}return super._getTransformedDimensions(e)}_set(e,t){let n=this.initialized&&this[e]!==t,r=super._set(e,t);return this.exactBoundingBox&&n&&((e===`scaleX`||e===`scaleY`)&&this.strokeUniform&&this.constructor.layoutProperties.includes(`strokeUniform`)||this.constructor.layoutProperties.includes(e))&&this.setDimensions(),r}toObject(e=[]){return{...super.toObject(e),points:this.points.map(({x:e,y:t})=>({x:e,y:t}))}}_toSVG(){let e=this.pathOffset.x,n=this.pathOffset.y,r=t.NUM_FRACTION_DIGITS,i=this.points.map(({x:t,y:i})=>`${l(t-e,r)},${l(i-n,r)}`).join(` `);return[`<${u(this.constructor.type).toLowerCase()} `,`COMMON_PARTS`,`points="${i}" />\n`]}_render(e){let t=this.points.length,n=this.pathOffset.x,r=this.pathOffset.y;if(t&&!isNaN(this.points[t-1].y)){e.beginPath(),e.moveTo(this.points[0].x-n,this.points[0].y-r);for(let i=0;i<t;i++){let t=this.points[i];e.lineTo(t.x-n,t.y-r)}!this.isOpen()&&e.closePath(),this._renderPaintInOrder(e)}}complexity(){return this.points.length}static async fromElement(e,t,n){let r=_(e.getAttribute(`points`)),{left:i,top:a,...o}=g(e,this.ATTRIBUTE_NAMES,n);return new this(r,{...o,...t})}static fromObject(e){return this._fromObject(e,{extraParam:`points`})}};e(y,`ownDefaults`,v),e(y,`type`,`Polyline`),e(y,`layoutProperties`,[n,r,`strokeLineCap`,`strokeLineJoin`,`strokeMiterLimit`,`strokeWidth`,`strokeUniform`,`points`]),e(y,`cacheProperties`,[...f,`points`]),e(y,`ATTRIBUTE_NAMES`,[...h]),i.setClass(y),i.setSVGClass(y);export{y as Polyline,v as polylineDefaultValues}; //# sourceMappingURL=Polyline.min.mjs.map