UNPKG

fabric

Version:

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

3 lines (2 loc) 2.38 kB
import{defineProperty as t,objectSpread2 as s,objectWithoutProperties as e}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{SHARED_ATTRIBUTES as r}from"../parser/attributes.min.mjs";import{parseAttributes as i}from"../parser/parseAttributes.min.mjs";import{cos as n}from"../util/misc/cos.min.mjs";import{degreesToRadians as o}from"../util/misc/radiansDegreesConversion.min.mjs";import{sin as a}from"../util/misc/sin.min.mjs";import{classRegistry as c}from"../ClassRegistry.min.mjs";import{FabricObject as u}from"./Object/FabricObject.min.mjs";import{SCALE_X as m,SCALE_Y as l}from"../constants.min.mjs";import{cacheProperties as d}from"./Object/defaultValues.min.mjs";const h=["left","top","radius"],p=["radius","startAngle","endAngle","counterClockwise"],g={radius:0,startAngle:0,endAngle:360,counterClockwise:!1};class f extends u{static getDefaults(){return s(s({},super.getDefaults()),f.ownDefaults)}constructor(t){super(),Object.assign(this,f.ownDefaults),this.setOptions(t)}_set(t,s){return super._set(t,s),"radius"===t&&this.setRadius(s),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,o(this.startAngle),o(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(m)}getRadiusY(){return this.get("radius")*this.get(l)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return super.toObject([...p,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(0===t)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),'" />\n'];{const{radius:s}=this,e=o(this.startAngle),r=o(this.endAngle),i=n(e)*s,c=a(e)*s,u=n(r)*s,m=a(r)*s,l=t>180?1:0,d=this.counterClockwise?0:1;return['<path d="M '.concat(i," ").concat(c," A ").concat(s," ").concat(s," 0 ").concat(l," ").concat(d," ").concat(u," ").concat(m,'" '),"COMMON_PARTS"," />\n"]}}static async fromElement(t,r,n){const o=i(t,this.ATTRIBUTE_NAMES,n),{left:a=0,top:c=0,radius:u=0}=o,m=e(o,h);return new this(s(s({},m),{},{radius:u,left:a-u,top:c-u}))}static fromObject(t){return super._fromObject(t)}}t(f,"type","Circle"),t(f,"cacheProperties",[...d,...p]),t(f,"ownDefaults",g),t(f,"ATTRIBUTE_NAMES",["cx","cy","r",...r]),c.setClass(f),c.setSVGClass(f);export{f as Circle,g as circleDefaultValues}; //# sourceMappingURL=Circle.min.mjs.map