fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
3 lines (2 loc) • 3.09 kB
JavaScript
import{uid as t}from"../../util/internals/uid.min.mjs";import{colorPropToSVG as i}from"../../util/misc/svgParsing.min.mjs";import{NONE as s,FILL as r,STROKE as o}from"../../constants.min.mjs";import{isFiller as e}from"../../util/typeAssertions.min.mjs";import{matrixToSVG as n}from"../../util/misc/svgExport.min.mjs";class h{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",n=this.strokeWidth?this.strokeWidth:"0",h=this.strokeDashArray?this.strokeDashArray.join(" "):s,a=this.strokeDashOffset?this.strokeDashOffset:"0",l=this.strokeLineCap?this.strokeLineCap:"butt",c=this.strokeLineJoin?this.strokeLineJoin:"miter",m=this.strokeMiterLimit?this.strokeMiterLimit:"4",p=void 0!==this.opacity?this.opacity:"1",d=this.visible?"":" visibility: hidden;",g=t?"":this.getSvgFilter(),u=i(r,this.fill);return[i(o,this.stroke),"stroke-width: ",n,"; ","stroke-dasharray: ",h,"; ","stroke-linecap: ",l,"; ","stroke-dashoffset: ",a,"; ","stroke-linejoin: ",c,"; ","stroke-miterlimit: ",m,"; ",u,"fill-rule: ",e,"; ","opacity: ",p,";",g,d].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const s=t?this.calcTransformMatrix():this.calcOwnMatrix(),r='transform="'.concat(n(s));return"".concat(r).concat(i,'" ')}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:i,additionalTransform:s=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),o=t.indexOf("COMMON_PARTS");return t[o]=r,i?i(t.join("")):t.join("")}_createBaseSVGMarkup(i){let{noStyle:s,reviver:r,withShadow:o,additionalTransform:n}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const h=s?"":'style="'.concat(this.getSvgStyles(),'" '),a=o?'style="'.concat(this.getSvgFilter(),'" '):"",l=this.clipPath,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",m=l&&l.absolutePositioned,p=this.stroke,d=this.fill,g=this.shadow,u=[],S=i.indexOf("COMMON_PARTS");let f;l&&(l.clipPathId="CLIPPATH_".concat(t()),f='<clipPath id="'.concat(l.clipPathId,'" >\n').concat(l.toClipPathSVG(r),"</clipPath>\n")),m&&u.push("<g ",a,this.getSvgCommons()," >\n"),u.push("<g ",this.getSvgTransform(!1),m?"":a+this.getSvgCommons()," >\n");const v=[h,c,s?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return i[S]=v,e(d)&&u.push(d.toSVG(this)),e(p)&&u.push(p.toSVG(this)),g&&u.push(g.toSVG(this)),l&&u.push(f),u.push(i.join("")),u.push("</g>\n"),m&&u.push("</g>\n"),r?r(u.join("")):u.join("")}addPaintOrder(){return this.paintFirst!==r?' paint-order="'.concat(this.paintFirst,'" '):""}}export{h as FabricObjectSVGExportMixin};
//# sourceMappingURL=FabricObjectSVGExportMixin.min.mjs.map