UNPKG

fabric

Version:

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

6 lines 3.13 kB
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{getSafeSvgStyleNumber as s,getSafeSvgStyleToken as c}from"../../util/internals/svgExportCheck.min.mjs";import{colorPropToSVG as l}from"../../util/misc/svgParsing.min.mjs";var u=class{getSvgStyles(r){let i=this.fillRule==null?`nonzero`:c(this.fillRule),a=this.strokeWidth==null?`0`:s(this.strokeWidth),u=this.strokeDashArray==null?t:this.strokeDashArray.every(e=>Number.isFinite(Number(e)))?this.strokeDashArray.join(` `):``,d=this.strokeDashOffset==null?`0`:s(this.strokeDashOffset),f=this.strokeLineCap==null?`butt`:c(this.strokeLineCap),p=this.strokeLineJoin==null?`miter`:c(this.strokeLineJoin),m=this.strokeMiterLimit==null?`4`:s(this.strokeMiterLimit),h=this.opacity==null?`1`:s(this.opacity),g=this.visible?``:` visibility: hidden;`,_=r?``:this.getSvgFilter(),v=l(e,this.fill);return[l(n,this.stroke),a?`stroke-width: ${a}; `:``,u?`stroke-dasharray: ${u}; `:``,f?`stroke-linecap: ${f}; `:``,d?`stroke-dashoffset: ${d}; `:``,p?`stroke-linejoin: ${p}; `:``,m?`stroke-miterlimit: ${m}; `:``,v,i?`fill-rule: ${i}; `:``,h?`opacity: ${h};`:``,_,g].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(#${o(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{u as FabricObjectSVGExportMixin}; //# sourceMappingURL=FabricObjectSVGExportMixin.min.mjs.map