UNPKG

cione-comp-lib

Version:

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

131 lines (130 loc) 7.06 kB
import { hasOwn, each } from "../../../zrender/lib/core/util.mjs"; function isEC4CompatibleStyle(style, elType, hasOwnTextContentOption, hasOwnTextConfig) { return style && (style.legacy || style.legacy !== false && !hasOwnTextContentOption && !hasOwnTextConfig && elType !== "tspan" && (elType === "text" || hasOwn(style, "text"))); } function convertFromEC4CompatibleStyle(hostStyle, elType, isNormal) { var srcStyle = hostStyle; var textConfig; var textContent; var textContentStyle; if (elType === "text") { textContentStyle = srcStyle; } else { textContentStyle = {}; hasOwn(srcStyle, "text") && (textContentStyle.text = srcStyle.text); hasOwn(srcStyle, "rich") && (textContentStyle.rich = srcStyle.rich); hasOwn(srcStyle, "textFill") && (textContentStyle.fill = srcStyle.textFill); hasOwn(srcStyle, "textStroke") && (textContentStyle.stroke = srcStyle.textStroke); hasOwn(srcStyle, "fontFamily") && (textContentStyle.fontFamily = srcStyle.fontFamily); hasOwn(srcStyle, "fontSize") && (textContentStyle.fontSize = srcStyle.fontSize); hasOwn(srcStyle, "fontStyle") && (textContentStyle.fontStyle = srcStyle.fontStyle); hasOwn(srcStyle, "fontWeight") && (textContentStyle.fontWeight = srcStyle.fontWeight); textContent = { type: "text", style: textContentStyle, silent: true }; textConfig = {}; var hasOwnPos = hasOwn(srcStyle, "textPosition"); if (isNormal) { textConfig.position = hasOwnPos ? srcStyle.textPosition : "inside"; } else { hasOwnPos && (textConfig.position = srcStyle.textPosition); } hasOwn(srcStyle, "textPosition") && (textConfig.position = srcStyle.textPosition); hasOwn(srcStyle, "textOffset") && (textConfig.offset = srcStyle.textOffset); hasOwn(srcStyle, "textRotation") && (textConfig.rotation = srcStyle.textRotation); hasOwn(srcStyle, "textDistance") && (textConfig.distance = srcStyle.textDistance); } convertEC4CompatibleRichItem(textContentStyle, hostStyle); each(textContentStyle.rich, function(richItem) { convertEC4CompatibleRichItem(richItem, richItem); }); return { textConfig, textContent }; } function convertEC4CompatibleRichItem(out, richItem) { if (!richItem) { return; } richItem.font = richItem.textFont || richItem.font; hasOwn(richItem, "textStrokeWidth") && (out.lineWidth = richItem.textStrokeWidth); hasOwn(richItem, "textAlign") && (out.align = richItem.textAlign); hasOwn(richItem, "textVerticalAlign") && (out.verticalAlign = richItem.textVerticalAlign); hasOwn(richItem, "textLineHeight") && (out.lineHeight = richItem.textLineHeight); hasOwn(richItem, "textWidth") && (out.width = richItem.textWidth); hasOwn(richItem, "textHeight") && (out.height = richItem.textHeight); hasOwn(richItem, "textBackgroundColor") && (out.backgroundColor = richItem.textBackgroundColor); hasOwn(richItem, "textPadding") && (out.padding = richItem.textPadding); hasOwn(richItem, "textBorderColor") && (out.borderColor = richItem.textBorderColor); hasOwn(richItem, "textBorderWidth") && (out.borderWidth = richItem.textBorderWidth); hasOwn(richItem, "textBorderRadius") && (out.borderRadius = richItem.textBorderRadius); hasOwn(richItem, "textBoxShadowColor") && (out.shadowColor = richItem.textBoxShadowColor); hasOwn(richItem, "textBoxShadowBlur") && (out.shadowBlur = richItem.textBoxShadowBlur); hasOwn(richItem, "textBoxShadowOffsetX") && (out.shadowOffsetX = richItem.textBoxShadowOffsetX); hasOwn(richItem, "textBoxShadowOffsetY") && (out.shadowOffsetY = richItem.textBoxShadowOffsetY); } function convertToEC4StyleForCustomSerise(itemStl, txStl, txCfg) { var out = itemStl; out.textPosition = out.textPosition || txCfg.position || "inside"; txCfg.offset != null && (out.textOffset = txCfg.offset); txCfg.rotation != null && (out.textRotation = txCfg.rotation); txCfg.distance != null && (out.textDistance = txCfg.distance); var isInside = out.textPosition.indexOf("inside") >= 0; var hostFill = itemStl.fill || "#000"; convertToEC4RichItem(out, txStl); var textFillNotSet = out.textFill == null; if (isInside) { if (textFillNotSet) { out.textFill = txCfg.insideFill || "#fff"; !out.textStroke && txCfg.insideStroke && (out.textStroke = txCfg.insideStroke); !out.textStroke && (out.textStroke = hostFill); out.textStrokeWidth == null && (out.textStrokeWidth = 2); } } else { if (textFillNotSet) { out.textFill = itemStl.fill || txCfg.outsideFill || "#000"; } !out.textStroke && txCfg.outsideStroke && (out.textStroke = txCfg.outsideStroke); } out.text = txStl.text; out.rich = txStl.rich; each(txStl.rich, function(richItem) { convertToEC4RichItem(richItem, richItem); }); return out; } function convertToEC4RichItem(out, richItem) { if (!richItem) { return; } hasOwn(richItem, "fill") && (out.textFill = richItem.fill); hasOwn(richItem, "stroke") && (out.textStroke = richItem.fill); hasOwn(richItem, "lineWidth") && (out.textStrokeWidth = richItem.lineWidth); hasOwn(richItem, "font") && (out.font = richItem.font); hasOwn(richItem, "fontStyle") && (out.fontStyle = richItem.fontStyle); hasOwn(richItem, "fontWeight") && (out.fontWeight = richItem.fontWeight); hasOwn(richItem, "fontSize") && (out.fontSize = richItem.fontSize); hasOwn(richItem, "fontFamily") && (out.fontFamily = richItem.fontFamily); hasOwn(richItem, "align") && (out.textAlign = richItem.align); hasOwn(richItem, "verticalAlign") && (out.textVerticalAlign = richItem.verticalAlign); hasOwn(richItem, "lineHeight") && (out.textLineHeight = richItem.lineHeight); hasOwn(richItem, "width") && (out.textWidth = richItem.width); hasOwn(richItem, "height") && (out.textHeight = richItem.height); hasOwn(richItem, "backgroundColor") && (out.textBackgroundColor = richItem.backgroundColor); hasOwn(richItem, "padding") && (out.textPadding = richItem.padding); hasOwn(richItem, "borderColor") && (out.textBorderColor = richItem.borderColor); hasOwn(richItem, "borderWidth") && (out.textBorderWidth = richItem.borderWidth); hasOwn(richItem, "borderRadius") && (out.textBorderRadius = richItem.borderRadius); hasOwn(richItem, "shadowColor") && (out.textBoxShadowColor = richItem.shadowColor); hasOwn(richItem, "shadowBlur") && (out.textBoxShadowBlur = richItem.shadowBlur); hasOwn(richItem, "shadowOffsetX") && (out.textBoxShadowOffsetX = richItem.shadowOffsetX); hasOwn(richItem, "shadowOffsetY") && (out.textBoxShadowOffsetY = richItem.shadowOffsetY); hasOwn(richItem, "textShadowColor") && (out.textShadowColor = richItem.textShadowColor); hasOwn(richItem, "textShadowBlur") && (out.textShadowBlur = richItem.textShadowBlur); hasOwn(richItem, "textShadowOffsetX") && (out.textShadowOffsetX = richItem.textShadowOffsetX); hasOwn(richItem, "textShadowOffsetY") && (out.textShadowOffsetY = richItem.textShadowOffsetY); } export { convertFromEC4CompatibleStyle, convertToEC4StyleForCustomSerise, isEC4CompatibleStyle };