UNPKG

fabric

Version:

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

1 lines 1.71 kB
{"version":3,"file":"setStrokeFillOpacity.min.mjs","names":[],"sources":["../../../src/parser/setStrokeFillOpacity.ts"],"sourcesContent":["import { Color } from '../color/Color';\nimport { toFixed } from '../util/misc/toFixed';\nimport { FabricObject } from '../shapes/Object/FabricObject';\n\nconst colorAttributesMap = {\n stroke: 'strokeOpacity',\n fill: 'fillOpacity',\n};\n\n/**\n * @private\n * @param {Object} attributes Array of attributes to parse\n */\n\nexport function setStrokeFillOpacity(\n attributes: Record<string, any>,\n): Record<string, any> {\n const defaults = FabricObject.getDefaults();\n Object.entries(colorAttributesMap).forEach(([attr, colorAttr]) => {\n if (\n typeof attributes[colorAttr] === 'undefined' ||\n attributes[attr] === ''\n ) {\n return;\n }\n if (typeof attributes[attr] === 'undefined') {\n if (!defaults[attr]) {\n return;\n }\n attributes[attr] = defaults[attr];\n }\n if (attributes[attr].indexOf('url(') === 0) {\n return;\n }\n const color = new Color(attributes[attr]);\n attributes[attr] = color\n .setAlpha(toFixed(color.getAlpha() * attributes[colorAttr], 2))\n .toRgba();\n });\n return attributes;\n}\n"],"mappings":"2KAIA,MAAM,EAAqB,CACzB,OAAQ,gBACR,KAAM,cAAA,CAQR,SAAgB,EACd,EAAA,CAEA,IAAM,EAAW,EAAa,aAAA,CAsB9B,OArBA,OAAO,QAAQ,EAAA,CAAoB,SAAA,CAAU,EAAM,KAAA,CACjD,GACS,EAAW,KADpB,IACmC,IACjC,EAAW,KAAU,GAErB,OAEF,GAAW,EAAW,KAAtB,IAAgC,GAAa,CAC3C,GAAA,CAAK,EAAS,GACZ,OAEF,EAAW,GAAQ,EAAS,GAE9B,GAAI,EAAW,GAAM,QAAQ,OAAA,GAAY,EACvC,OAEF,IAAM,EAAQ,IAAI,EAAM,EAAW,GAAA,CACnC,EAAW,GAAQ,EAChB,SAAS,EAAQ,EAAM,UAAA,CAAa,EAAW,GAAY,EAAA,CAAA,CAC3D,QAAA,EAAA,CAEE,EAAA,OAAA,KAAA"}