UNPKG

fabric

Version:

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

1 lines 2.54 kB
{"version":3,"file":"setStrokeFillOpacity.mjs","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"],"names":["colorAttributesMap","stroke","fill","setStrokeFillOpacity","attributes","defaults","FabricObject","getDefaults","Object","entries","forEach","_ref","attr","colorAttr","indexOf","color","Color","setAlpha","toFixed","getAlpha","toRgba"],"mappings":";;;;AAIA,MAAMA,kBAAkB,GAAG;AACzBC,EAAAA,MAAM,EAAE,eAAe;AACvBC,EAAAA,IAAI,EAAE,aAAA;AACR,CAAC,CAAA;;AAED;AACA;AACA;AACA;;AAEO,SAASC,oBAAoBA,CAClCC,UAA+B,EACV;AACrB,EAAA,MAAMC,QAAQ,GAAGC,YAAY,CAACC,WAAW,EAAE,CAAA;EAC3CC,MAAM,CAACC,OAAO,CAACT,kBAAkB,CAAC,CAACU,OAAO,CAACC,IAAA,IAAuB;AAAA,IAAA,IAAtB,CAACC,IAAI,EAAEC,SAAS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