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