UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

105 lines (104 loc) 3.31 kB
import { map, keys } from "../core/util.mjs"; import { encodeHTML } from "../core/dom.mjs"; var SVGNS = "http://www.w3.org/2000/svg"; var XLINKNS = "http://www.w3.org/1999/xlink"; var XMLNS = "http://www.w3.org/2000/xmlns/"; var XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"; function createElement(name) { return document.createElementNS(SVGNS, name); } function createVNode(tag, key, attrs, children, text) { return { tag, attrs: attrs || {}, children, text, key }; } function createElementOpen(name, attrs) { var attrsStr = []; if (attrs) { for (var key in attrs) { var val = attrs[key]; var part = key; if (val === false) { continue; } else if (val !== true && val != null) { part += '="' + val + '"'; } attrsStr.push(part); } } return "<" + name + " " + attrsStr.join(" ") + ">"; } function createElementClose(name) { return "</" + name + ">"; } function vNodeToString(el, opts) { opts = opts || {}; var S = opts.newline ? "\n" : ""; function convertElToString(el2) { var children = el2.children, tag = el2.tag, attrs = el2.attrs; return createElementOpen(tag, attrs) + encodeHTML(el2.text) + (children ? "" + S + map(children, function(child) { return convertElToString(child); }).join(S) + S : "") + createElementClose(tag); } return convertElToString(el); } function getCssString(selectorNodes, animationNodes, opts) { opts = opts || {}; var S = opts.newline ? "\n" : ""; var bracketBegin = " {" + S; var bracketEnd = S + "}"; var selectors = map(keys(selectorNodes), function(className) { return className + bracketBegin + map(keys(selectorNodes[className]), function(attrName) { return attrName + ":" + selectorNodes[className][attrName] + ";"; }).join(S) + bracketEnd; }).join(S); var animations = map(keys(animationNodes), function(animationName) { return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function(percent) { return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function(attrName) { var val = animationNodes[animationName][percent][attrName]; if (attrName === "d") { val = 'path("' + val + '")'; } return attrName + ":" + val + ";"; }).join(S) + bracketEnd; }).join(S) + bracketEnd; }).join(S); if (!selectors && !animations) { return ""; } return ["<![CDATA[", selectors, animations, "]]>"].join(S); } function createBrushScope(zrId) { return { zrId, shadowCache: {}, patternCache: {}, gradientCache: {}, clipPathCache: {}, defs: {}, cssNodes: {}, cssAnims: {}, cssClassIdx: 0, cssAnimIdx: 0, shadowIdx: 0, gradientIdx: 0, patternIdx: 0, clipPathIdx: 0 }; } function createSVGVNode(width, height, children, useViewBox) { return createVNode("svg", "root", { "width": width, "height": height, "xmlns": SVGNS, "xmlns:xlink": XLINKNS, "version": "1.1", "baseProfile": "full", "viewBox": useViewBox ? "0 0 " + width + " " + height : false }, children); } export { SVGNS, XLINKNS, XMLNS, XML_NAMESPACE, createBrushScope, createElement, createSVGVNode, createVNode, getCssString, vNodeToString };