1 line
16 KiB
JSON
1 line
16 KiB
JSON
|
{"ast":null,"code":"import \"core-js/modules/es.array.join.js\";\nimport \"core-js/modules/es.number.to-fixed.js\";\nimport \"core-js/modules/web.dom-exception.constructor.js\";\nimport \"core-js/modules/web.dom-exception.stack.js\";\nimport \"core-js/modules/web.dom-exception.to-string-tag.js\";\nimport \"core-js/modules/es.object.to-string.js\";\nimport \"core-js/modules/es.regexp.to-string.js\";\nimport { RADIAN_TO_DEGREE, retrieve2, logError, isFunction } from '../core/util.js';\nimport { parse } from '../tool/color.js';\nimport env from '../core/env.js';\nvar mathRound = Math.round;\nexport function normalizeColor(color) {\n var opacity;\n\n if (!color || color === 'transparent') {\n color = 'none';\n } else if (typeof color === 'string' && color.indexOf('rgba') > -1) {\n var arr = parse(color);\n\n if (arr) {\n color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';\n opacity = arr[3];\n }\n }\n\n return {\n color: color,\n opacity: opacity == null ? 1 : opacity\n };\n}\nvar EPSILON = 1e-4;\nexport function isAroundZero(transform) {\n return transform < EPSILON && transform > -EPSILON;\n}\nexport function round3(transform) {\n return mathRound(transform * 1e3) / 1e3;\n}\nexport function round4(transform) {\n return mathRound(transform * 1e4) / 1e4;\n}\nexport function round1(transform) {\n return mathRound(transform * 10) / 10;\n}\nexport function getMatrixStr(m) {\n return 'matrix(' + round3(m[0]) + ',' + round3(m[1]) + ',' + round3(m[2]) + ',' + round3(m[3]) + ',' + round4(m[4]) + ',' + round4(m[5]) + ')';\n}\nexport var TEXT_ALIGN_TO_ANCHOR = {\n left: 'start',\n right: 'end',\n center: 'middle',\n middle: 'middle'\n};\nexport function adjustTextY(y, lineHeight, textBaseline) {\n if (textBaseline === 'top') {\n y += lineHeight / 2;\n } else if (textBaseline === 'bottom') {\n y -= lineHeight / 2;\n }\n\n return y;\n}\nexport function hasShadow(style) {\n return style && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);\n}\nexport function getShadowKey(displayable) {\n var style = displayable.style;\n var globalScale = displayable.getGlobalScale();\n return [style.shadowColor, (style.shadowBlur || 0).toFixed(2), (style.shadowOffsetX || 0).toFixed(2), (style.shadowOffsetY || 0).toFixed(2), globalScale[0], globalScale[1]].join(',');\n}\nexport function getClipPathsKey(clipPaths) {\n var key = [];\n\n if (clipPaths) {\n for (var i = 0; i < clipPaths.length; i++) {\n var clipPath = clipPaths[i];\n key.push(clipPath.id);\n }\n }\n\n return key.join(',');\n}\nexport function isImagePattern(val) {\n return val && !!val.image;\n}\nexport function isSVGPattern(val) {\n return val && !!val.svgElement;\n}\nexport function isPattern(val) {\n return isImagePattern(val) || isSVGPattern(val);\n}\nexport function isLinearGradient(val) {\n return val.type === 'linear';\n}\nexport function isRadialGradient(val) {\n return val.type === 'radial';\n}\nexport function isGradient(val) {\n return val && (val.type === 'linear' || val.type === 'radial');\n}\nexport function getIdURL(id) {\n return \"url(#\" + id + \")\";\n}\nexport function getPathPrecision(el) {\n var scale = el.getGlobalScale();\n var size = Math.max(scale[0], scale[1]);\n return Math.max(Math.ceil(Math.log(size) / Math.log(10)), 1);\n}\nexport function getSRTTransformString(transform) {\n var x = transform.x || 0;\n var y = transform.y || 0;\n var rotation = (transform.rotation || 0) * RADIAN_TO_DEGREE;\n var scaleX = retrieve2(transform.scaleX, 1);\n var scaleY = retrieve2(transform.scaleY, 1);\n var skewX = transform.skewX || 0;\n var skewY = transform.skewY || 0;\n var res = [];\n\n if (x || y) {\n res.push(\"translate(\" + x + \"px,\" + y + \"px)\");\n }\n\n if (rotation) {\n res.push(\"rotate(\" + rotation + \")\");\n }\n\n if (scaleX !== 1 || scaleY !== 1) {\n res.push(\"scale(\" + scaleX + \",\" + scaleY + \")\");\n }\n\n if (skewX || skewY) {\n res.push(\"skew(\" + mathRound(skewX * RADIAN_TO_DEGREE) + \"deg, \" + mathRound(skew
|