UNPKG

fabric

Version:

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

2 lines 2.5 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{classRegistry as n}from"./ClassRegistry.min.mjs";import{Point as r}from"./Point.min.mjs";import{uid as i}from"./util/internals/uid.min.mjs";import{degreesToRadians as a}from"./util/misc/radiansDegreesConversion.min.mjs";import{pickBy as o}from"./util/misc/pick.min.mjs";import{toFixed as s}from"./util/misc/toFixed.min.mjs";import{escapeXml as c}from"./util/lang_string.min.mjs";import{rotateVector as l}from"./util/misc/vectors.min.mjs";import{Color as u}from"./color/Color.min.mjs";import{reNum as d}from"./parser/constants.min.mjs";const f=`(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?`,p=RegExp(`(?:\\s|^)`+f+f+`(`+d+`?(?:px)?)?(?:\\s?|$)(?:$|\\s)`);var m=class e{constructor(t={}){let n=typeof t==`string`?e.parseShadow(t):t;Object.assign(this,e.ownDefaults,n),this.id=i()}static parseShadow(e){let t=e.trim(),[,n=0,r=0,i=0]=(p.exec(t)||[]).map(e=>parseFloat(e)||0);return{color:(t.replace(p,``)||`rgb(0,0,0)`).trim(),offsetX:n,offsetY:r,blur:i}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join(`px `)}toSVG(e){let n=l(new r(this.offsetX,this.offsetY),a(-e.angle)),i=t.NUM_FRACTION_DIGITS,o=new u(this.color),d=40,f=40;return e.width&&e.height&&(d=100*s((Math.abs(n.x)+this.blur)/e.width,i)+20,f=100*s((Math.abs(n.y)+this.blur)/e.height,i)+20),e.flipX&&(n.x*=-1),e.flipY&&(n.y*=-1),`<filter id="SVGID_${c(this.id)}" y="-${f}%" height="${100+2*f}%" x="-${d}%" width="${100+2*d}%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="${s(this.blur?this.blur/2:0,i)}"></feGaussianBlur>\n\t<feOffset dx="${s(n.x,i)}" dy="${s(n.y,i)}" result="oBlur" ></feOffset>\n\t<feFlood flood-color="${o.toRgb()}" flood-opacity="${o.getAlpha()}"/>\n\t<feComposite in2="oBlur" operator="in" />\n\t<feMerge>\n\t\t<feMergeNode></feMergeNode>\n\t\t<feMergeNode in="SourceGraphic"></feMergeNode>\n\t</feMerge>\n</filter>\n`}toObject(){let t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},n=e.ownDefaults;return this.includeDefaultValues?t:o(t,(e,t)=>e!==n[t])}static async fromObject(e){return new this(e)}};e(m,`ownDefaults`,{color:`rgb(0,0,0)`,blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),e(m,`type`,`shadow`),n.setClass(m,`shadow`);export{m as Shadow}; //# sourceMappingURL=Shadow.min.mjs.map