Merge remote-tracking branch 'upstream/main'

This commit is contained in:
2026-08-26 09:31:34 +08:00
parent 9b8c4bfab6
commit 394eb0285d
34137 changed files with 3589424 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
export declare function normalizeLineDash(lineType: any, lineWidth?: number): number[] | false;
+13
View File
@@ -0,0 +1,13 @@
import { isArray, isNumber } from '../../core/util.js';
export function normalizeLineDash(lineType, lineWidth) {
if (!lineType || lineType === 'solid' || !(lineWidth > 0)) {
return null;
}
lineWidth = lineWidth || 1;
return lineType === 'dashed'
? [4 * lineWidth, 2 * lineWidth]
: lineType === 'dotted'
? [lineWidth]
: isNumber(lineType)
? [lineType] : isArray(lineType) ? lineType : null;
}
@@ -0,0 +1,6 @@
import { PropType } from '../../core/types';
import Path from '../Path';
import Displayable from '../Displayable';
declare type BrushType = PropType<Path, 'brush'>;
export default function (orignalBrush: BrushType): (ctx: CanvasRenderingContext2D, prevEl?: Displayable<import("../Displayable").DisplayableOption>) => void;
export {};
+42
View File
@@ -0,0 +1,42 @@
"use strict";
exports.__esModule = true;
var env_1 = require("../../core/env");
var shadowTemp = [
['shadowBlur', 0],
['shadowColor', '#000'],
['shadowOffsetX', 0],
['shadowOffsetY', 0]
];
function default_1(orignalBrush) {
return (env_1["default"].browser.ie && env_1["default"].browser.version >= 11)
? function (ctx, prevEl) {
var clipPaths = this.__clipPaths;
var style = this.style;
var modified;
if (clipPaths) {
for (var i = 0; i < clipPaths.length; i++) {
var clipPath = clipPaths[i];
var shape = clipPath && clipPath.shape;
var type = clipPath && clipPath.type;
if (shape && ((type === 'sector' && shape.startAngle === shape.endAngle)
|| (type === 'rect' && (!shape.width || !shape.height)))) {
for (var j = 0; j < shadowTemp.length; j++) {
shadowTemp[j][2] = style[shadowTemp[j][0]];
style[shadowTemp[j][0]] = shadowTemp[j][1];
}
modified = true;
break;
}
}
}
orignalBrush.call(this, ctx, prevEl);
if (modified) {
for (var j = 0; j < shadowTemp.length; j++) {
style[shadowTemp[j][0]] = shadowTemp[j][2];
}
}
}
: orignalBrush;
}
exports["default"] = default_1;
//# sourceMappingURL=fixClipWithShadow.js.map
@@ -0,0 +1 @@
{"version":3,"file":"fixClipWithShadow.js","sourceRoot":"","sources":["../../../src/graphic/helper/fixClipWithShadow.ts"],"names":[],"mappings":";;AAAA,sCAAiC;AAoBjC,IAAM,UAAU,GAAG;IACf,CAAC,YAAY,EAAE,CAAC,CAAC;IACjB,CAAC,aAAa,EAAE,MAAM,CAAC;IACvB,CAAC,eAAe,EAAE,CAAC,CAAC;IACpB,CAAC,eAAe,EAAE,CAAC,CAAC;CACvB,CAAC;AAIF,mBAAyB,YAAuB;IAG5C,OAAO,CAAC,gBAAG,CAAC,OAAO,CAAC,EAAE,IAAK,gBAAG,CAAC,OAAO,CAAC,OAAkB,IAAI,EAAE,CAAC;QAE5D,CAAC,CAAC,UAA6B,GAA6B,EAAE,MAAmB;YAC7E,IAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC;YACnC,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;YACzB,IAAI,QAAQ,CAAC;YAEb,IAAI,SAAS,EAAE;gBACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBACvC,IAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;oBAC9B,IAAM,KAAK,GAAG,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC;oBACzC,IAAM,IAAI,GAAG,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC;oBAEvC,IAAI,KAAK,IAAI,CACT,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,QAAQ,CAAC;2BACvD,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAC1D,EAAE;wBACC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;4BAGxC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAI,KAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;4BACnD,KAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;yBACvD;wBACD,QAAQ,GAAG,IAAI,CAAC;wBAChB,MAAM;qBACT;iBACJ;aACJ;YAED,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;YAErC,IAAI,QAAQ,EAAE;gBACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBACvC,KAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;iBACvD;aACJ;QACL,CAAC;QAED,CAAC,CAAC,YAAY,CAAC;AACvB,CAAC;AA1CD,+BA0CC"}
+1
View File
@@ -0,0 +1 @@
export default function (ctx: CanvasRenderingContext2D, propName: string, value: number): number;
+21
View File
@@ -0,0 +1,21 @@
"use strict";
exports.__esModule = true;
var SHADOW_PROPS = {
'shadowBlur': 1,
'shadowOffsetX': 1,
'shadowOffsetY': 1,
'textShadowBlur': 1,
'textShadowOffsetX': 1,
'textShadowOffsetY': 1,
'textBoxShadowBlur': 1,
'textBoxShadowOffsetX': 1,
'textBoxShadowOffsetY': 1
};
function default_1(ctx, propName, value) {
if (SHADOW_PROPS.hasOwnProperty(propName)) {
return value *= ctx.dpr;
}
return value;
}
exports["default"] = default_1;
//# sourceMappingURL=fixShadow.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"fixShadow.js","sourceRoot":"","sources":["../../../src/graphic/helper/fixShadow.ts"],"names":[],"mappings":";;AAEA,IAAM,YAAY,GAAG;IACjB,YAAY,EAAE,CAAC;IACf,eAAe,EAAE,CAAC;IAClB,eAAe,EAAE,CAAC;IAClB,gBAAgB,EAAE,CAAC;IACnB,mBAAmB,EAAE,CAAC;IACtB,mBAAmB,EAAE,CAAC;IACtB,mBAAmB,EAAE,CAAC;IACtB,sBAAsB,EAAE,CAAC;IACzB,sBAAsB,EAAE,CAAC;CAC5B,CAAC;AAEF,mBACI,GAA6B,EAC7B,QAAgB,EAChB,KAAa;IAEb,IAAI,YAAY,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;QACvC,OAAO,KAAK,IAAK,GAAgC,CAAC,GAAG,CAAC;KACzD;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AATD,+BASC"}
+6
View File
@@ -0,0 +1,6 @@
import { ImageLike } from '../../core/types';
export declare function findExistImage(newImageOrSrc: string | ImageLike): ImageLike;
export declare function createOrUpdateImage<T>(newImageOrSrc: string | ImageLike, image: ImageLike, hostEl: {
dirty: () => void;
}, onload?: (image: ImageLike, payload: T) => void, cbPayload?: T): ImageLike;
export declare function isImageReady(image: ImageLike): number;
+54
View File
@@ -0,0 +1,54 @@
import LRU from '../../core/LRU.js';
import { platformApi } from '../../core/platform.js';
var globalImageCache = new LRU(50);
export function findExistImage(newImageOrSrc) {
if (typeof newImageOrSrc === 'string') {
var cachedImgObj = globalImageCache.get(newImageOrSrc);
return cachedImgObj && cachedImgObj.image;
}
else {
return newImageOrSrc;
}
}
export function createOrUpdateImage(newImageOrSrc, image, hostEl, onload, cbPayload) {
if (!newImageOrSrc) {
return image;
}
else if (typeof newImageOrSrc === 'string') {
if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
return image;
}
var cachedImgObj = globalImageCache.get(newImageOrSrc);
var pendingWrap = { hostEl: hostEl, cb: onload, cbPayload: cbPayload };
if (cachedImgObj) {
image = cachedImgObj.image;
!isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
}
else {
image = platformApi.loadImage(newImageOrSrc, imageOnLoad, imageOnLoad);
image.__zrImageSrc = newImageOrSrc;
globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
image: image,
pending: [pendingWrap]
});
}
return image;
}
else {
return newImageOrSrc;
}
}
function imageOnLoad() {
var cachedImgObj = this.__cachedImgObj;
this.onload = this.onerror = this.__cachedImgObj = null;
for (var i = 0; i < cachedImgObj.pending.length; i++) {
var pendingWrap = cachedImgObj.pending[i];
var cb = pendingWrap.cb;
cb && cb(this, pendingWrap.cbPayload);
pendingWrap.hostEl.dirty();
}
cachedImgObj.pending.length = 0;
}
export function isImageReady(image) {
return image && image.width && image.height;
}
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../src/graphic/helper/image.ts"],"names":[],"mappings":";;AACA,sCAAiC;AAGjC,IAAM,gBAAgB,GAAG,IAAI,gBAAG,CAAiB,EAAE,CAAC,CAAC;AAarD,SAAgB,cAAc,CAAC,aAAiC;IAC5D,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;QACnC,IAAM,YAAY,GAAG,gBAAgB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACzD,OAAO,YAAY,IAAI,YAAY,CAAC,KAAK,CAAC;KAC7C;SACI;QACD,OAAO,aAAa,CAAC;KACxB;AACL,CAAC;AARD,wCAQC;AAaD,SAAgB,mBAAmB,CAC/B,aAAiC,EACjC,KAAgB,EAChB,MAA6B,EAC7B,EAA2C,EAC3C,SAAa;IAEb,IAAI,CAAC,aAAa,EAAE;QAChB,OAAO,KAAK,CAAC;KAChB;SACI,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;QAGxC,IAAI,CAAC,KAAK,IAAK,KAAa,CAAC,YAAY,KAAK,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE;YACrE,OAAO,KAAK,CAAC;SAChB;QAID,IAAM,YAAY,GAAG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C,KAAK,EAAE,CAAC;KAC9B;IACD,YAAY,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,YAAY,CAAC,KAAgB;IACzC,OAAO,KAAK,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC;AAChD,CAAC;AAFD,oCAEC"}
+54
View File
@@ -0,0 +1,54 @@
import { TextAlign, TextVerticalAlign } from '../../core/types';
import { TextStyleProps } from '../Text';
interface InnerTruncateOption {
maxIteration?: number;
minChar?: number;
placeholder?: string;
maxIterations?: number;
}
export declare function truncateText(text: string, containerWidth: number, font: string, ellipsis: string, options: InnerTruncateOption): string;
export interface PlainTextContentBlock {
lineHeight: number;
calculatedLineHeight: number;
contentWidth: number;
contentHeight: number;
width: number;
height: number;
outerWidth: number;
outerHeight: number;
lines: string[];
}
export declare function parsePlainText(text: string, style?: TextStyleProps): PlainTextContentBlock;
declare class RichTextToken {
styleName: string;
text: string;
width: number;
height: number;
innerHeight: number;
contentHeight: number;
contentWidth: number;
lineHeight: number;
font: string;
align: TextAlign;
verticalAlign: TextVerticalAlign;
textPadding: number[];
percentWidth?: string;
isLineHolder: boolean;
}
declare class RichTextLine {
lineHeight: number;
width: number;
tokens: RichTextToken[];
constructor(tokens?: RichTextToken[]);
}
export declare class RichTextContentBlock {
width: number;
height: number;
contentWidth: number;
contentHeight: number;
outerWidth: number;
outerHeight: number;
lines: RichTextLine[];
}
export declare function parseRichText(text: string, style: TextStyleProps): RichTextContentBlock;
export {};
+466
View File
@@ -0,0 +1,466 @@
import * as imageHelper from '../helper/image.js';
import { extend, retrieve2, retrieve3, reduce } from '../../core/util.js';
import { getLineHeight, getWidth, parsePercent } from '../../contain/text.js';
var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
export function truncateText(text, containerWidth, font, ellipsis, options) {
if (!containerWidth) {
return '';
}
var textLines = (text + '').split('\n');
options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
for (var i = 0, len = textLines.length; i < len; i++) {
textLines[i] = truncateSingleLine(textLines[i], options);
}
return textLines.join('\n');
}
function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
options = options || {};
var preparedOpts = extend({}, options);
preparedOpts.font = font;
ellipsis = retrieve2(ellipsis, '...');
preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
preparedOpts.cnCharWidth = getWidth('国', font);
var ascCharWidth = preparedOpts.ascCharWidth = getWidth('a', font);
preparedOpts.placeholder = retrieve2(options.placeholder, '');
var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
contentWidth -= ascCharWidth;
}
var ellipsisWidth = getWidth(ellipsis, font);
if (ellipsisWidth > contentWidth) {
ellipsis = '';
ellipsisWidth = 0;
}
contentWidth = containerWidth - ellipsisWidth;
preparedOpts.ellipsis = ellipsis;
preparedOpts.ellipsisWidth = ellipsisWidth;
preparedOpts.contentWidth = contentWidth;
preparedOpts.containerWidth = containerWidth;
return preparedOpts;
}
function truncateSingleLine(textLine, options) {
var containerWidth = options.containerWidth;
var font = options.font;
var contentWidth = options.contentWidth;
if (!containerWidth) {
return '';
}
var lineWidth = getWidth(textLine, font);
if (lineWidth <= containerWidth) {
return textLine;
}
for (var j = 0;; j++) {
if (lineWidth <= contentWidth || j >= options.maxIterations) {
textLine += options.ellipsis;
break;
}
var subLength = j === 0
? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
: lineWidth > 0
? Math.floor(textLine.length * contentWidth / lineWidth)
: 0;
textLine = textLine.substr(0, subLength);
lineWidth = getWidth(textLine, font);
}
if (textLine === '') {
textLine = options.placeholder;
}
return textLine;
}
function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
var width = 0;
var i = 0;
for (var len = text.length; i < len && width < contentWidth; i++) {
var charCode = text.charCodeAt(i);
width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
}
return i;
}
export function parsePlainText(text, style) {
text != null && (text += '');
var overflow = style.overflow;
var padding = style.padding;
var font = style.font;
var truncate = overflow === 'truncate';
var calculatedLineHeight = getLineHeight(font);
var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
var bgColorDrawn = !!(style.backgroundColor);
var truncateLineOverflow = style.lineOverflow === 'truncate';
var width = style.width;
var lines;
if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
}
else {
lines = text ? text.split('\n') : [];
}
var contentHeight = lines.length * lineHeight;
var height = retrieve2(style.height, contentHeight);
if (contentHeight > height && truncateLineOverflow) {
var lineCount = Math.floor(height / lineHeight);
lines = lines.slice(0, lineCount);
}
if (text && truncate && width != null) {
var options = prepareTruncateOptions(width, font, style.ellipsis, {
minChar: style.truncateMinChar,
placeholder: style.placeholder
});
for (var i = 0; i < lines.length; i++) {
lines[i] = truncateSingleLine(lines[i], options);
}
}
var outerHeight = height;
var contentWidth = 0;
for (var i = 0; i < lines.length; i++) {
contentWidth = Math.max(getWidth(lines[i], font), contentWidth);
}
if (width == null) {
width = contentWidth;
}
var outerWidth = contentWidth;
if (padding) {
outerHeight += padding[0] + padding[2];
outerWidth += padding[1] + padding[3];
width += padding[1] + padding[3];
}
if (bgColorDrawn) {
outerWidth = width;
}
return {
lines: lines,
height: height,
outerWidth: outerWidth,
outerHeight: outerHeight,
lineHeight: lineHeight,
calculatedLineHeight: calculatedLineHeight,
contentWidth: contentWidth,
contentHeight: contentHeight,
width: width
};
}
var RichTextToken = (function () {
function RichTextToken() {
}
return RichTextToken;
}());
var RichTextLine = (function () {
function RichTextLine(tokens) {
this.tokens = [];
if (tokens) {
this.tokens = tokens;
}
}
return RichTextLine;
}());
var RichTextContentBlock = (function () {
function RichTextContentBlock() {
this.width = 0;
this.height = 0;
this.contentWidth = 0;
this.contentHeight = 0;
this.outerWidth = 0;
this.outerHeight = 0;
this.lines = [];
}
return RichTextContentBlock;
}());
export { RichTextContentBlock };
export function parseRichText(text, style) {
var contentBlock = new RichTextContentBlock();
text != null && (text += '');
if (!text) {
return contentBlock;
}
var topWidth = style.width;
var topHeight = style.height;
var overflow = style.overflow;
var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
: null;
var lastIndex = STYLE_REG.lastIndex = 0;
var result;
while ((result = STYLE_REG.exec(text)) != null) {
var matchedIndex = result.index;
if (matchedIndex > lastIndex) {
pushTokens(contentBlock, text.substring(lastIndex, matchedIndex), style, wrapInfo);
}
pushTokens(contentBlock, result[2], style, wrapInfo, result[1]);
lastIndex = STYLE_REG.lastIndex;
}
if (lastIndex < text.length) {
pushTokens(contentBlock, text.substring(lastIndex, text.length), style, wrapInfo);
}
var pendingList = [];
var calculatedHeight = 0;
var calculatedWidth = 0;
var stlPadding = style.padding;
var truncate = overflow === 'truncate';
var truncateLine = style.lineOverflow === 'truncate';
function finishLine(line, lineWidth, lineHeight) {
line.width = lineWidth;
line.lineHeight = lineHeight;
calculatedHeight += lineHeight;
calculatedWidth = Math.max(calculatedWidth, lineWidth);
}
outer: for (var i = 0; i < contentBlock.lines.length; i++) {
var line = contentBlock.lines[i];
var lineHeight = 0;
var lineWidth = 0;
for (var j = 0; j < line.tokens.length; j++) {
var token = line.tokens[j];
var tokenStyle = token.styleName && style.rich[token.styleName] || {};
var textPadding = token.textPadding = tokenStyle.padding;
var paddingH = textPadding ? textPadding[1] + textPadding[3] : 0;
var font = token.font = tokenStyle.font || style.font;
token.contentHeight = getLineHeight(font);
var tokenHeight = retrieve2(tokenStyle.height, token.contentHeight);
token.innerHeight = tokenHeight;
textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
token.height = tokenHeight;
token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
token.align = tokenStyle && tokenStyle.align || style.align;
token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
if (j > 0) {
line.tokens = line.tokens.slice(0, j);
finishLine(line, lineWidth, lineHeight);
contentBlock.lines = contentBlock.lines.slice(0, i + 1);
}
else {
contentBlock.lines = contentBlock.lines.slice(0, i);
}
break outer;
}
var styleTokenWidth = tokenStyle.width;
var tokenWidthNotSpecified = styleTokenWidth == null || styleTokenWidth === 'auto';
if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
token.percentWidth = styleTokenWidth;
pendingList.push(token);
token.contentWidth = getWidth(token.text, font);
}
else {
if (tokenWidthNotSpecified) {
var textBackgroundColor = tokenStyle.backgroundColor;
var bgImg = textBackgroundColor && textBackgroundColor.image;
if (bgImg) {
bgImg = imageHelper.findExistImage(bgImg);
if (imageHelper.isImageReady(bgImg)) {
token.width = Math.max(token.width, bgImg.width * tokenHeight / bgImg.height);
}
}
}
var remainTruncWidth = truncate && topWidth != null
? topWidth - lineWidth : null;
if (remainTruncWidth != null && remainTruncWidth < token.width) {
if (!tokenWidthNotSpecified || remainTruncWidth < paddingH) {
token.text = '';
token.width = token.contentWidth = 0;
}
else {
token.text = truncateText(token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
token.width = token.contentWidth = getWidth(token.text, font);
}
}
else {
token.contentWidth = getWidth(token.text, font);
}
}
token.width += paddingH;
lineWidth += token.width;
tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
}
finishLine(line, lineWidth, lineHeight);
}
contentBlock.outerWidth = contentBlock.width = retrieve2(topWidth, calculatedWidth);
contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
contentBlock.contentHeight = calculatedHeight;
contentBlock.contentWidth = calculatedWidth;
if (stlPadding) {
contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
}
for (var i = 0; i < pendingList.length; i++) {
var token = pendingList[i];
var percentWidth = token.percentWidth;
token.width = parseInt(percentWidth, 10) / 100 * contentBlock.width;
}
return contentBlock;
}
function pushTokens(block, str, style, wrapInfo, styleName) {
var isEmptyStr = str === '';
var tokenStyle = styleName && style.rich[styleName] || {};
var lines = block.lines;
var font = tokenStyle.font || style.font;
var newLine = false;
var strLines;
var linesWidths;
if (wrapInfo) {
var tokenPadding = tokenStyle.padding;
var tokenPaddingH = tokenPadding ? tokenPadding[1] + tokenPadding[3] : 0;
if (tokenStyle.width != null && tokenStyle.width !== 'auto') {
var outerWidth_1 = parsePercent(tokenStyle.width, wrapInfo.width) + tokenPaddingH;
if (lines.length > 0) {
if (outerWidth_1 + wrapInfo.accumWidth > wrapInfo.width) {
strLines = str.split('\n');
newLine = true;
}
}
wrapInfo.accumWidth = outerWidth_1;
}
else {
var res = wrapText(str, font, wrapInfo.width, wrapInfo.breakAll, wrapInfo.accumWidth);
wrapInfo.accumWidth = res.accumWidth + tokenPaddingH;
linesWidths = res.linesWidths;
strLines = res.lines;
}
}
else {
strLines = str.split('\n');
}
for (var i = 0; i < strLines.length; i++) {
var text = strLines[i];
var token = new RichTextToken();
token.styleName = styleName;
token.text = text;
token.isLineHolder = !text && !isEmptyStr;
if (typeof tokenStyle.width === 'number') {
token.width = tokenStyle.width;
}
else {
token.width = linesWidths
? linesWidths[i]
: getWidth(text, font);
}
if (!i && !newLine) {
var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
var tokensLen = tokens.length;
(tokensLen === 1 && tokens[0].isLineHolder)
? (tokens[0] = token)
: ((text || !tokensLen || isEmptyStr) && tokens.push(token));
}
else {
lines.push(new RichTextLine([token]));
}
}
}
function isLatin(ch) {
var code = ch.charCodeAt(0);
return code >= 0x21 && code <= 0x17F;
}
var breakCharMap = reduce(',&?/;] '.split(''), function (obj, ch) {
obj[ch] = true;
return obj;
}, {});
function isWordBreakChar(ch) {
if (isLatin(ch)) {
if (breakCharMap[ch]) {
return true;
}
return false;
}
return true;
}
function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
var lines = [];
var linesWidths = [];
var line = '';
var currentWord = '';
var currentWordWidth = 0;
var accumWidth = 0;
for (var i = 0; i < text.length; i++) {
var ch = text.charAt(i);
if (ch === '\n') {
if (currentWord) {
line += currentWord;
accumWidth += currentWordWidth;
}
lines.push(line);
linesWidths.push(accumWidth);
line = '';
currentWord = '';
currentWordWidth = 0;
accumWidth = 0;
continue;
}
var chWidth = getWidth(ch, font);
var inWord = isBreakAll ? false : !isWordBreakChar(ch);
if (!lines.length
? lastAccumWidth + accumWidth + chWidth > lineWidth
: accumWidth + chWidth > lineWidth) {
if (!accumWidth) {
if (inWord) {
lines.push(currentWord);
linesWidths.push(currentWordWidth);
currentWord = ch;
currentWordWidth = chWidth;
}
else {
lines.push(ch);
linesWidths.push(chWidth);
}
}
else if (line || currentWord) {
if (inWord) {
if (!line) {
line = currentWord;
currentWord = '';
currentWordWidth = 0;
accumWidth = currentWordWidth;
}
lines.push(line);
linesWidths.push(accumWidth - currentWordWidth);
currentWord += ch;
currentWordWidth += chWidth;
line = '';
accumWidth = currentWordWidth;
}
else {
if (currentWord) {
line += currentWord;
currentWord = '';
currentWordWidth = 0;
}
lines.push(line);
linesWidths.push(accumWidth);
line = ch;
accumWidth = chWidth;
}
}
continue;
}
accumWidth += chWidth;
if (inWord) {
currentWord += ch;
currentWordWidth += chWidth;
}
else {
if (currentWord) {
line += currentWord;
currentWord = '';
currentWordWidth = 0;
}
line += ch;
}
}
if (!lines.length && !line) {
line = text;
currentWord = '';
currentWordWidth = 0;
}
if (currentWord) {
line += currentWord;
}
if (line) {
lines.push(line);
linesWidths.push(accumWidth);
}
if (lines.length === 1) {
accumWidth += lastAccumWidth;
}
return {
accumWidth: accumWidth,
lines: lines,
linesWidths: linesWidths
};
}
File diff suppressed because one or more lines are too long
+7
View File
@@ -0,0 +1,7 @@
import { VectorArray } from '../../core/vector';
import PathProxy from '../../core/PathProxy';
export declare function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: {
points: VectorArray[];
smooth?: number;
smoothConstraint?: VectorArray[];
}, closePath: boolean): void;
+25
View File
@@ -0,0 +1,25 @@
import smoothBezier from './smoothBezier.js';
export function buildPath(ctx, shape, closePath) {
var smooth = shape.smooth;
var points = shape.points;
if (points && points.length >= 2) {
if (smooth) {
var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
ctx.moveTo(points[0][0], points[0][1]);
var len = points.length;
for (var i = 0; i < (closePath ? len : len - 1); i++) {
var cp1 = controlPoints[i * 2];
var cp2 = controlPoints[i * 2 + 1];
var p = points[(i + 1) % len];
ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
}
}
else {
ctx.moveTo(points[0][0], points[0][1]);
for (var i = 1, l = points.length; i < l; i++) {
ctx.lineTo(points[i][0], points[i][1]);
}
}
closePath && ctx.closePath();
}
}
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"poly.js","sourceRoot":"","sources":["../../../src/graphic/helper/poly.ts"],"names":[],"mappings":";;AACA,+CAA0C;AAC1C,+CAA0C;AAI1C,SAAgB,SAAS,CACrB,GAAyC,EACzC,KAIC,EACD,SAAkB;IAElB,IAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,IAAI,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC1B,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE;QAC9B,IAAI,MAAM,IAAI,MAAM,KAAK,QAAQ,EAAE;YAC/B,IAAM,aAAa,GAAG,yBAAY,CAC9B,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,gBAAgB,CACpD,CAAC;YAEF,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,IAAM,GAAG,GAAG,MAAM,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}
+8
View File
@@ -0,0 +1,8 @@
import PathProxy from '../../core/PathProxy';
export declare function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: {
x: number;
y: number;
width: number;
height: number;
r?: number | number[];
}): void;
+75
View File
@@ -0,0 +1,75 @@
export function buildPath(ctx, shape) {
var x = shape.x;
var y = shape.y;
var width = shape.width;
var height = shape.height;
var r = shape.r;
var r1;
var r2;
var r3;
var r4;
if (width < 0) {
x = x + width;
width = -width;
}
if (height < 0) {
y = y + height;
height = -height;
}
if (typeof r === 'number') {
r1 = r2 = r3 = r4 = r;
}
else if (r instanceof Array) {
if (r.length === 1) {
r1 = r2 = r3 = r4 = r[0];
}
else if (r.length === 2) {
r1 = r3 = r[0];
r2 = r4 = r[1];
}
else if (r.length === 3) {
r1 = r[0];
r2 = r4 = r[1];
r3 = r[2];
}
else {
r1 = r[0];
r2 = r[1];
r3 = r[2];
r4 = r[3];
}
}
else {
r1 = r2 = r3 = r4 = 0;
}
var total;
if (r1 + r2 > width) {
total = r1 + r2;
r1 *= width / total;
r2 *= width / total;
}
if (r3 + r4 > width) {
total = r3 + r4;
r3 *= width / total;
r4 *= width / total;
}
if (r2 + r3 > height) {
total = r2 + r3;
r2 *= height / total;
r3 *= height / total;
}
if (r1 + r4 > height) {
total = r1 + r4;
r1 *= height / total;
r4 *= height / total;
}
ctx.moveTo(x + r1, y);
ctx.lineTo(x + width - r2, y);
r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
ctx.lineTo(x + width, y + height - r3);
r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
ctx.lineTo(x + r4, y + height);
r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
ctx.lineTo(x, y + r1);
r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
}
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"roundRect.js","sourceRoot":"","sources":["../../../src/graph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AAE,CAAC,CAAC,CAAC;IAC9B,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACjE,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,MAAM,GAAG,EAAE,CAAC,CAAC;IACvC,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACzE,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC;IAC/B,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IACvE,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACtB,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;AACpE,CAAC;AApFD,8BAoFC"}
+11
View File
@@ -0,0 +1,11 @@
import PathProxy from '../../core/PathProxy';
export declare function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: {
cx: number;
cy: number;
startAngle: number;
endAngle: number;
clockwise?: boolean;
r?: number;
r0?: number;
cornerRadius?: number | number[];
}): void;
+227
View File
@@ -0,0 +1,227 @@
import { isArray } from '../../core/util.js';
var PI = Math.PI;
var PI2 = PI * 2;
var mathSin = Math.sin;
var mathCos = Math.cos;
var mathACos = Math.acos;
var mathATan2 = Math.atan2;
var mathAbs = Math.abs;
var mathSqrt = Math.sqrt;
var mathMax = Math.max;
var mathMin = Math.min;
var e = 1e-4;
function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
var dx10 = x1 - x0;
var dy10 = y1 - y0;
var dx32 = x3 - x2;
var dy32 = y3 - y2;
var t = dy32 * dx10 - dx32 * dy10;
if (t * t < e) {
return;
}
t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
return [x0 + t * dx10, y0 + t * dy10];
}
function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
var x01 = x0 - x1;
var y01 = y0 - y1;
var lo = (clockwise ? cr : -cr) / mathSqrt(x01 * x01 + y01 * y01);
var ox = lo * y01;
var oy = -lo * x01;
var x11 = x0 + ox;
var y11 = y0 + oy;
var x10 = x1 + ox;
var y10 = y1 + oy;
var x00 = (x11 + x10) / 2;
var y00 = (y11 + y10) / 2;
var dx = x10 - x11;
var dy = y10 - y11;
var d2 = dx * dx + dy * dy;
var r = radius - cr;
var s = x11 * y10 - x10 * y11;
var d = (dy < 0 ? -1 : 1) * mathSqrt(mathMax(0, r * r * d2 - s * s));
var cx0 = (s * dy - dx * d) / d2;
var cy0 = (-s * dx - dy * d) / d2;
var cx1 = (s * dy + dx * d) / d2;
var cy1 = (-s * dx + dy * d) / d2;
var dx0 = cx0 - x00;
var dy0 = cy0 - y00;
var dx1 = cx1 - x00;
var dy1 = cy1 - y00;
if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
cx0 = cx1;
cy0 = cy1;
}
return {
cx: cx0,
cy: cy0,
x0: -ox,
y0: -oy,
x1: cx0 * (radius / r - 1),
y1: cy0 * (radius / r - 1)
};
}
function normalizeCornerRadius(cr) {
var arr;
if (isArray(cr)) {
var len = cr.length;
if (!len) {
return cr;
}
if (len === 1) {
arr = [cr[0], cr[0], 0, 0];
}
else if (len === 2) {
arr = [cr[0], cr[0], cr[1], cr[1]];
}
else if (len === 3) {
arr = cr.concat(cr[2]);
}
else {
arr = cr;
}
}
else {
arr = [cr, cr, cr, cr];
}
return arr;
}
export function buildPath(ctx, shape) {
var _a;
var radius = mathMax(shape.r, 0);
var innerRadius = mathMax(shape.r0 || 0, 0);
var hasRadius = radius > 0;
var hasInnerRadius = innerRadius > 0;
if (!hasRadius && !hasInnerRadius) {
return;
}
if (!hasRadius) {
radius = innerRadius;
innerRadius = 0;
}
if (innerRadius > radius) {
var tmp = radius;
radius = innerRadius;
innerRadius = tmp;
}
var startAngle = shape.startAngle, endAngle = shape.endAngle;
if (isNaN(startAngle) || isNaN(endAngle)) {
return;
}
var cx = shape.cx, cy = shape.cy;
var clockwise = !!shape.clockwise;
var arc = mathAbs(endAngle - startAngle);
var mod = arc > PI2 && arc % PI2;
mod > e && (arc = mod);
if (!(radius > e)) {
ctx.moveTo(cx, cy);
}
else if (arc > PI2 - e) {
ctx.moveTo(cx + radius * mathCos(startAngle), cy + radius * mathSin(startAngle));
ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
if (innerRadius > e) {
ctx.moveTo(cx + innerRadius * mathCos(endAngle), cy + innerRadius * mathSin(endAngle));
ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
}
}
else {
var icrStart = void 0;
var icrEnd = void 0;
var ocrStart = void 0;
var ocrEnd = void 0;
var ocrs = void 0;
var ocre = void 0;
var icrs = void 0;
var icre = void 0;
var ocrMax = void 0;
var icrMax = void 0;
var limitedOcrMax = void 0;
var limitedIcrMax = void 0;
var xre = void 0;
var yre = void 0;
var xirs = void 0;
var yirs = void 0;
var xrs = radius * mathCos(startAngle);
var yrs = radius * mathSin(startAngle);
var xire = innerRadius * mathCos(endAngle);
var yire = innerRadius * mathSin(endAngle);
var hasArc = arc > e;
if (hasArc) {
var cornerRadius = shape.cornerRadius;
if (cornerRadius) {
_a = normalizeCornerRadius(cornerRadius), icrStart = _a[0], icrEnd = _a[1], ocrStart = _a[2], ocrEnd = _a[3];
}
var halfRd = mathAbs(radius - innerRadius) / 2;
ocrs = mathMin(halfRd, ocrStart);
ocre = mathMin(halfRd, ocrEnd);
icrs = mathMin(halfRd, icrStart);
icre = mathMin(halfRd, icrEnd);
limitedOcrMax = ocrMax = mathMax(ocrs, ocre);
limitedIcrMax = icrMax = mathMax(icrs, icre);
if (ocrMax > e || icrMax > e) {
xre = radius * mathCos(endAngle);
yre = radius * mathSin(endAngle);
xirs = innerRadius * mathCos(startAngle);
yirs = innerRadius * mathSin(startAngle);
if (arc < PI) {
var it_1 = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
if (it_1) {
var x0 = xrs - it_1[0];
var y0 = yrs - it_1[1];
var x1 = xre - it_1[0];
var y1 = yre - it_1[1];
var a = 1 / mathSin(mathACos((x0 * x1 + y0 * y1) / (mathSqrt(x0 * x0 + y0 * y0) * mathSqrt(x1 * x1 + y1 * y1))) / 2);
var b = mathSqrt(it_1[0] * it_1[0] + it_1[1] * it_1[1]);
limitedOcrMax = mathMin(ocrMax, (radius - b) / (a + 1));
limitedIcrMax = mathMin(icrMax, (innerRadius - b) / (a - 1));
}
}
}
}
if (!hasArc) {
ctx.moveTo(cx + xrs, cy + yrs);
}
else if (limitedOcrMax > e) {
var crStart = mathMin(ocrStart, limitedOcrMax);
var crEnd = mathMin(ocrEnd, limitedOcrMax);
var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, radius, crStart, clockwise);
var ct1 = computeCornerTangents(xre, yre, xire, yire, radius, crEnd, clockwise);
ctx.moveTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
if (limitedOcrMax < ocrMax && crStart === crEnd) {
ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedOcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
}
else {
crStart > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crStart, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
ctx.arc(cx, cy, radius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), !clockwise);
crEnd > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crEnd, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
}
}
else {
ctx.moveTo(cx + xrs, cy + yrs);
ctx.arc(cx, cy, radius, startAngle, endAngle, !clockwise);
}
if (!(innerRadius > e) || !hasArc) {
ctx.lineTo(cx + xire, cy + yire);
}
else if (limitedIcrMax > e) {
var crStart = mathMin(icrStart, limitedIcrMax);
var crEnd = mathMin(icrEnd, limitedIcrMax);
var ct0 = computeCornerTangents(xire, yire, xre, yre, innerRadius, -crEnd, clockwise);
var ct1 = computeCornerTangents(xrs, yrs, xirs, yirs, innerRadius, -crStart, clockwise);
ctx.lineTo(cx + ct0.cx + ct0.x0, cy + ct0.cy + ct0.y0);
if (limitedIcrMax < icrMax && crStart === crEnd) {
ctx.arc(cx + ct0.cx, cy + ct0.cy, limitedIcrMax, mathATan2(ct0.y0, ct0.x0), mathATan2(ct1.y0, ct1.x0), !clockwise);
}
else {
crEnd > 0 && ctx.arc(cx + ct0.cx, cy + ct0.cy, crEnd, mathATan2(ct0.y0, ct0.x0), mathATan2(ct0.y1, ct0.x1), !clockwise);
ctx.arc(cx, cy, innerRadius, mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1), mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1), clockwise);
crStart > 0 && ctx.arc(cx + ct1.cx, cy + ct1.cy, crStart, mathATan2(ct1.y1, ct1.x1), mathATan2(ct1.y0, ct1.x0), !clockwise);
}
}
else {
ctx.lineTo(cx + xire, cy + yire);
ctx.arc(cx, cy, innerRadius, endAngle, startAngle, clockwise);
}
}
ctx.closePath();
}
+2
View File
@@ -0,0 +1,2 @@
import { VectorArray } from '../../core/vector';
export default function smoothBezier(points: VectorArray[], smooth?: number, isLoop?: boolean, constraint?: VectorArray[]): any[][];
+63
View File
@@ -0,0 +1,63 @@
import { min as v2Min, max as v2Max, scale as v2Scale, distance as v2Distance, add as v2Add, clone as v2Clone, sub as v2Sub } from '../../core/vector.js';
export default function smoothBezier(points, smooth, isLoop, constraint) {
var cps = [];
var v = [];
var v1 = [];
var v2 = [];
var prevPoint;
var nextPoint;
var min;
var max;
if (constraint) {
min = [Infinity, Infinity];
max = [-Infinity, -Infinity];
for (var i = 0, len = points.length; i < len; i++) {
v2Min(min, min, points[i]);
v2Max(max, max, points[i]);
}
v2Min(min, min, constraint[0]);
v2Max(max, max, constraint[1]);
}
for (var i = 0, len = points.length; i < len; i++) {
var point = points[i];
if (isLoop) {
prevPoint = points[i ? i - 1 : len - 1];
nextPoint = points[(i + 1) % len];
}
else {
if (i === 0 || i === len - 1) {
cps.push(v2Clone(points[i]));
continue;
}
else {
prevPoint = points[i - 1];
nextPoint = points[i + 1];
}
}
v2Sub(v, nextPoint, prevPoint);
v2Scale(v, v, smooth);
var d0 = v2Distance(point, prevPoint);
var d1 = v2Distance(point, nextPoint);
var sum = d0 + d1;
if (sum !== 0) {
d0 /= sum;
d1 /= sum;
}
v2Scale(v1, v, -d0);
v2Scale(v2, v, d1);
var cp0 = v2Add([], point, v1);
var cp1 = v2Add([], point, v2);
if (constraint) {
v2Max(cp0, cp0, min);
v2Min(cp0, cp0, max);
v2Max(cp1, cp1, min);
v2Min(cp1, cp1, max);
}
cps.push(cp0);
cps.push(cp1);
}
if (isLoop) {
cps.push(cps.shift());
}
return cps;
}
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"smoothBezier.js","sourceRoot":"","sources":["../../../src/graphic/helper/smoothBezier.ts"],"names":[],"mappings":";;AAIA,4CAS2B;AAY3B,mBACI,MAAqB,EACrB,MAAe,EACf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,EAAE,GAAG,CAAC,CAAC;YACrB,YAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;SACxB;QACD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACd,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACjB;IAED,IAAI,MAAM,EAAE;QACR,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;KACzB;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AA9ED,+BA8EC"}
+2
View File
@@ -0,0 +1,2 @@
import { VectorArray } from '../../core/vector';
export default function smoothSpline(points: VectorArray[], isLoop?: boolean): VectorArray[];
+44
View File
@@ -0,0 +1,44 @@
import { distance as v2Distance } from '../../core/vector.js';
function interpolate(p0, p1, p2, p3, t, t2, t3) {
var v0 = (p2 - p0) * 0.5;
var v1 = (p3 - p1) * 0.5;
return (2 * (p1 - p2) + v0 + v1) * t3
+ (-3 * (p1 - p2) - 2 * v0 - v1) * t2
+ v0 * t + p1;
}
export default function smoothSpline(points, isLoop) {
var len = points.length;
var ret = [];
var distance = 0;
for (var i = 1; i < len; i++) {
distance += v2Distance(points[i - 1], points[i]);
}
var segs = distance / 2;
segs = segs < len ? len : segs;
for (var i = 0; i < segs; i++) {
var pos = i / (segs - 1) * (isLoop ? len : len - 1);
var idx = Math.floor(pos);
var w = pos - idx;
var p0 = void 0;
var p1 = points[idx % len];
var p2 = void 0;
var p3 = void 0;
if (!isLoop) {
p0 = points[idx === 0 ? idx : idx - 1];
p2 = points[idx > len - 2 ? len - 1 : idx + 1];
p3 = points[idx > len - 3 ? len - 1 : idx + 2];
}
else {
p0 = points[(idx - 1 + len) % len];
p2 = points[(idx + 1) % len];
p3 = points[(idx + 2) % len];
}
var w2 = w * w;
var w3 = w * w2;
ret.push([
interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
]);
}
return ret;
}
+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CAAC;QAElB,GAAG,CAAC,IAAI,CAAC;YACL,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;YAClD,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;SACrD,CAAC,CAAC;KACN;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAzCD,+BAyCC"}
+18
View File
@@ -0,0 +1,18 @@
import { PathStyleProps } from '../Path';
declare type LineShape = {
x1: number;
y1: number;
x2: number;
y2: number;
};
declare type RectShape = {
x: number;
y: number;
width: number;
height: number;
r?: number | number[];
};
export declare function subPixelOptimizeLine(outputShape: Partial<LineShape>, inputShape: LineShape, style: Pick<PathStyleProps, 'lineWidth'>): LineShape;
export declare function subPixelOptimizeRect(outputShape: Partial<RectShape>, inputShape: RectShape, style: Pick<PathStyleProps, 'lineWidth'>): RectShape;
export declare function subPixelOptimize(position: number, lineWidth?: number, positiveOrNegative?: boolean): number;
export {};
+56
View File
@@ -0,0 +1,56 @@
var round = Math.round;
export function subPixelOptimizeLine(outputShape, inputShape, style) {
if (!inputShape) {
return;
}
var x1 = inputShape.x1;
var x2 = inputShape.x2;
var y1 = inputShape.y1;
var y2 = inputShape.y2;
outputShape.x1 = x1;
outputShape.x2 = x2;
outputShape.y1 = y1;
outputShape.y2 = y2;
var lineWidth = style && style.lineWidth;
if (!lineWidth) {
return outputShape;
}
if (round(x1 * 2) === round(x2 * 2)) {
outputShape.x1 = outputShape.x2 = subPixelOptimize(x1, lineWidth, true);
}
if (round(y1 * 2) === round(y2 * 2)) {
outputShape.y1 = outputShape.y2 = subPixelOptimize(y1, lineWidth, true);
}
return outputShape;
}
export function subPixelOptimizeRect(outputShape, inputShape, style) {
if (!inputShape) {
return;
}
var originX = inputShape.x;
var originY = inputShape.y;
var originWidth = inputShape.width;
var originHeight = inputShape.height;
outputShape.x = originX;
outputShape.y = originY;
outputShape.width = originWidth;
outputShape.height = originHeight;
var lineWidth = style && style.lineWidth;
if (!lineWidth) {
return outputShape;
}
outputShape.x = subPixelOptimize(originX, lineWidth, true);
outputShape.y = subPixelOptimize(originY, lineWidth, true);
outputShape.width = Math.max(subPixelOptimize(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
outputShape.height = Math.max(subPixelOptimize(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
return outputShape;
}
export function subPixelOptimize(position, lineWidth, positiveOrNegative) {
if (!lineWidth) {
return position;
}
var doubledPosition = round(position * 2);
return (doubledPosition + round(lineWidth)) % 2 === 0
? doubledPosition / 2
: (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
}
@@ -0,0 +1 @@
{"version":3,"file":"subPixelOptimize.js","sourceRoot":"","sources":["../../../src/graphic/helper/subPixelOptimize.ts"],"names":[],"mappings":";;AAOA,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;AAwBzB,SAAgB,oBAAoB,CAChC,WAA+B,EAC/B,UAAqB,EACrB,KAAwC;IAExC,IAAI,CAAC,UAAU,EAAE;QACb,OAAO;KACV;IAED,IAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;IACzB,IAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;IACzB,IAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;IACzB,IAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;IAEzB,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;IACpB,WAAW,CAAC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style';
import Displayable from '../Displayable';
import { RectLike } from '../../core/BoundingRect';
import { PropType } from '../../core/types';
import { PatternObject } from '../Pattern';
declare type CalculateTextPositionResult = ReturnType<typeof textContain.calculateTextPosition>;
declare type TextBoxPosition = CalculateTextPositionResult & {
baseX: number;
baseY: number;
};
export declare function normalizeTextStyle(style: StyleOption): StyleOption;
export declare function renderText(hostEl: Displayable, ctx: CanvasRenderingContext2D, text: string, style: StyleOption, rect: RectLike, prevEl?: Displayable | typeof WILL_BE_RESTORED): void;
export declare function getBoxPosition<T>(out: Partial<TextBoxPosition>, hostEl: Displayable<T>, style: StyleOption, rect: RectLike): Partial<TextBoxPosition>;
export declare function getStroke(stroke?: PropType<StyleOption, 'textStroke'>, lineWidth?: number): string | PatternObject | import("../LinearGradient").LinearGradientObject | import("../RadialGradient").RadialGradientObject;
export declare function getFill(fill?: PropType<StyleOption, 'textStroke'>): string | PatternObject | import("../LinearGradient").LinearGradientObject | import("../RadialGradient").RadialGradientObject;
export declare function parsePercent(value: number | string, maxValue: number): number;
export declare function needDrawText(text: string, style: StyleOption): boolean;
export {};
+409
View File
@@ -0,0 +1,409 @@
"use strict";
exports.__esModule = true;
var util_1 = require("../../core/util");
var textContain = require("../../contain/text");
var roundRectHelper = require("./roundRect");
var imageHelper = require("./image");
var fixShadow_1 = require("./fixShadow");
var constant_1 = require("../constant");
var DEFAULT_FONT = textContain.DEFAULT_FONT;
var VALID_TEXT_ALIGN = { left: true, right: 1, center: 1 };
var VALID_TEXT_VERTICAL_ALIGN = { top: 1, bottom: 1, middle: 1 };
var SHADOW_STYLE_COMMON_PROPS = [
['textShadowBlur', 'shadowBlur', 0],
['textShadowOffsetX', 'shadowOffsetX', 0],
['textShadowOffsetY', 'shadowOffsetY', 0],
['textShadowColor', 'shadowColor', 'transparent']
];
var _tmpTextPositionResult = {};
var _tmpBoxPositionResult = {};
function normalizeTextStyle(style) {
normalizeStyle(style);
util_1.each(style.rich, normalizeStyle);
return style;
}
exports.normalizeTextStyle = normalizeTextStyle;
function normalizeStyle(style) {
if (style) {
style.font = textContain.makeFont(style);
var textAlign = style.textAlign;
textAlign === 'middle' && (textAlign = 'center');
style.textAlign = (textAlign == null || VALID_TEXT_ALIGN[textAlign]) ? textAlign : 'left';
var textVerticalAlign = style.textVerticalAlign || style.textBaseline;
textVerticalAlign === 'center' && (textVerticalAlign = 'middle');
style.textVerticalAlign = (textVerticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[textVerticalAlign]) ? textVerticalAlign : 'top';
var textPadding = style.textPadding;
if (textPadding) {
style.textPadding = util_1.normalizeCssArray(style.textPadding);
}
}
}
function renderText(hostEl, ctx, text, style, rect, prevEl) {
style.rich
? renderRichText(hostEl, ctx, text, style, rect, prevEl)
: renderPlainText(hostEl, ctx, text, style, rect, prevEl);
}
exports.renderText = renderText;
function renderPlainText(hostEl, ctx, text, style, rect, prevEl) {
'use strict';
var needDrawBg = needDrawBackground(style);
var cachedByMe = ctx.__attrCachedBy === constant_1.ContextCachedBy.PLAIN_TEXT;
var prevStyle;
var checkCache = false;
if (prevEl !== constant_1.WILL_BE_RESTORED) {
if (prevEl) {
prevStyle = prevEl.style;
checkCache = !needDrawBg && cachedByMe && !!prevStyle;
}
ctx.__attrCachedBy = needDrawBg ? constant_1.ContextCachedBy.NONE : constant_1.ContextCachedBy.PLAIN_TEXT;
}
else if (cachedByMe) {
ctx.__attrCachedBy = constant_1.ContextCachedBy.NONE;
}
var styleFont = style.font || DEFAULT_FONT;
if (!checkCache || styleFont !== (prevStyle.font || DEFAULT_FONT)) {
ctx.font = styleFont;
}
var computedFont = hostEl.__computedFont;
if (hostEl.__styleFont !== styleFont) {
hostEl.__styleFont = styleFont;
computedFont = hostEl.__computedFont = ctx.font;
}
var textPadding = style.textPadding;
var textLineHeight = style.textLineHeight;
var contentBlock = hostEl.__textCotentBlock;
if (!contentBlock || hostEl.__dirtyText) {
contentBlock = hostEl.__textCotentBlock = textContain.parsePlainText(text, computedFont, textPadding, textLineHeight, style.truncate);
}
var outerHeight = contentBlock.outerHeight;
var textLines = contentBlock.lines;
var lineHeight = contentBlock.lineHeight;
var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
var baseX = boxPos.baseX;
var baseY = boxPos.baseY;
var textAlign = boxPos.textAlign || 'left';
var textVerticalAlign = boxPos.textVerticalAlign;
applyTextRotation(ctx, style, rect, baseX, baseY);
var boxY = textContain.adjustTextY(baseY, outerHeight, textVerticalAlign);
var textX = baseX;
var textY = boxY;
if (needDrawBg || textPadding) {
var textWidth = textContain.getWidth(text, computedFont);
var outerWidth_1 = textWidth;
textPadding && (outerWidth_1 += textPadding[1] + textPadding[3]);
var boxX = textContain.adjustTextX(baseX, outerWidth_1, textAlign);
needDrawBg && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth_1, outerHeight);
if (textPadding) {
textX = getTextXForPadding(baseX, textAlign, textPadding);
textY += textPadding[0];
}
}
ctx.textAlign = textAlign;
ctx.textBaseline = 'middle';
ctx.globalAlpha = style.opacity || 1;
for (var i = 0; i < SHADOW_STYLE_COMMON_PROPS.length; i++) {
var propItem = SHADOW_STYLE_COMMON_PROPS[i];
var styleProp = propItem[0];
var ctxProp = propItem[1];
var val = style[styleProp];
if (!checkCache || val !== prevStyle[styleProp]) {
ctx[ctxProp] = fixShadow_1["default"](ctx, ctxProp, (val || propItem[2]));
}
}
textY += lineHeight / 2;
var textStrokeWidth = style.textStrokeWidth;
var textStrokeWidthPrev = checkCache ? prevStyle.textStrokeWidth : null;
var strokeWidthChanged = !checkCache || textStrokeWidth !== textStrokeWidthPrev;
var strokeChanged = !checkCache || strokeWidthChanged || style.textStroke !== prevStyle.textStroke;
var textStroke = getStroke(style.textStroke, textStrokeWidth);
var textFill = getFill(style.textFill);
if (textStroke) {
if (strokeWidthChanged) {
ctx.lineWidth = textStrokeWidth;
}
if (strokeChanged) {
ctx.strokeStyle = textStroke;
}
}
if (textFill) {
if (!checkCache || style.textFill !== prevStyle.textFill) {
ctx.fillStyle = textFill;
}
}
if (textLines.length === 1) {
textStroke && ctx.strokeText(textLines[0], textX, textY);
textFill && ctx.fillText(textLines[0], textX, textY);
}
else {
for (var i = 0; i < textLines.length; i++) {
textStroke && ctx.strokeText(textLines[i], textX, textY);
textFill && ctx.fillText(textLines[i], textX, textY);
textY += lineHeight;
}
}
}
function renderRichText(hostEl, ctx, text, style, rect, prevEl) {
if (prevEl !== constant_1.WILL_BE_RESTORED) {
ctx.__attrCachedBy = constant_1.ContextCachedBy.NONE;
}
var contentBlock = hostEl.__textCotentBlock;
if (!contentBlock || hostEl.__dirtyText) {
contentBlock = hostEl.__textCotentBlock = textContain.parseRichText(text, style);
}
drawRichText(hostEl, ctx, contentBlock, style, rect);
}
function drawRichText(hostEl, ctx, contentBlock, style, rect) {
var contentWidth = contentBlock.width;
var outerWidth = contentBlock.outerWidth;
var outerHeight = contentBlock.outerHeight;
var textPadding = style.textPadding;
var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
var baseX = boxPos.baseX;
var baseY = boxPos.baseY;
var textAlign = boxPos.textAlign;
var textVerticalAlign = boxPos.textVerticalAlign;
applyTextRotation(ctx, style, rect, baseX, baseY);
var boxX = textContain.adjustTextX(baseX, outerWidth, textAlign);
var boxY = textContain.adjustTextY(baseY, outerHeight, textVerticalAlign);
var xLeft = boxX;
var lineTop = boxY;
if (textPadding) {
xLeft += textPadding[3];
lineTop += textPadding[0];
}
var xRight = xLeft + contentWidth;
needDrawBackground(style) && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
for (var i = 0; i < contentBlock.lines.length; i++) {
var line = contentBlock.lines[i];
var tokens = line.tokens;
var tokenCount = tokens.length;
var lineHeight = line.lineHeight;
var usedWidth = line.width;
var leftIndex = 0;
var lineXLeft = xLeft;
var lineXRight = xRight;
var rightIndex = tokenCount - 1;
var token = void 0;
while (leftIndex < tokenCount
&& (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')) {
placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');
usedWidth -= token.width;
lineXLeft += token.width;
leftIndex++;
}
while (rightIndex >= 0
&& (token = tokens[rightIndex], token.textAlign === 'right')) {
placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');
usedWidth -= token.width;
lineXRight -= token.width;
rightIndex--;
}
lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - usedWidth) / 2;
while (leftIndex <= rightIndex) {
token = tokens[leftIndex];
placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center');
lineXLeft += token.width;
leftIndex++;
}
lineTop += lineHeight;
}
}
function applyTextRotation(ctx, style, rect, x, y) {
if (rect && style.textRotation) {
var origin_1 = style.textOrigin;
if (origin_1 === 'center') {
x = rect.width / 2 + rect.x;
y = rect.height / 2 + rect.y;
}
else if (origin_1) {
x = origin_1[0] + rect.x;
y = origin_1[1] + rect.y;
}
ctx.translate(x, y);
ctx.rotate(-style.textRotation);
ctx.translate(-x, -y);
}
}
function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
var tokenStyle = style.rich[token.styleName] || {};
tokenStyle.text = token.text;
var textVerticalAlign = token.textVerticalAlign;
var y = lineTop + lineHeight / 2;
if (textVerticalAlign === 'top') {
y = lineTop + token.height / 2;
}
else if (textVerticalAlign === 'bottom') {
y = lineTop + lineHeight - token.height / 2;
}
!token.isLineHolder && needDrawBackground(tokenStyle) && drawBackground(hostEl, ctx, tokenStyle, textAlign === 'right'
? x - token.width
: textAlign === 'center'
? x - token.width / 2
: x, y - token.height / 2, token.width, token.height);
var textPadding = token.textPadding;
if (textPadding) {
x = getTextXForPadding(x, textAlign, textPadding);
y -= token.height / 2 - textPadding[2] - token.textHeight / 2;
}
setCtx(ctx, 'shadowBlur', util_1.retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));
setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');
setCtx(ctx, 'shadowOffsetX', util_1.retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));
setCtx(ctx, 'shadowOffsetY', util_1.retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));
setCtx(ctx, 'textAlign', textAlign);
setCtx(ctx, 'textBaseline', 'middle');
setCtx(ctx, 'font', token.font || DEFAULT_FONT);
var textStrokeWidth = util_1.retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth);
var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);
var textFill = getFill(tokenStyle.textFill || style.textFill);
if (textStroke) {
setCtx(ctx, 'lineWidth', textStrokeWidth);
setCtx(ctx, 'strokeStyle', textStroke);
ctx.strokeText(token.text, x, y);
}
if (textFill) {
setCtx(ctx, 'fillStyle', textFill);
ctx.fillText(token.text, x, y);
}
}
function needDrawBackground(style) {
return !!(style.textBackgroundColor
|| (style.textBorderWidth && style.textBorderColor));
}
function drawBackground(hostEl, ctx, style, x, y, width, height) {
var textBackgroundColor = style.textBackgroundColor;
var textBorderWidth = style.textBorderWidth;
var textBorderColor = style.textBorderColor;
var isPlainBg = util_1.isString(textBackgroundColor);
setCtx(ctx, 'shadowBlur', style.textBoxShadowBlur || 0);
setCtx(ctx, 'shadowColor', style.textBoxShadowColor || 'transparent');
setCtx(ctx, 'shadowOffsetX', style.textBoxShadowOffsetX || 0);
setCtx(ctx, 'shadowOffsetY', style.textBoxShadowOffsetY || 0);
if (isPlainBg || (textBorderWidth && textBorderColor)) {
ctx.beginPath();
var textBorderRadius = style.textBorderRadius;
if (!textBorderRadius) {
ctx.rect(x, y, width, height);
}
else {
roundRectHelper.buildPath(ctx, {
x: x, y: y, width: width, height: height, r: textBorderRadius
});
}
ctx.closePath();
}
if (isPlainBg) {
setCtx(ctx, 'fillStyle', textBackgroundColor);
if (style.fillOpacity != null) {
var originalGlobalAlpha = ctx.globalAlpha;
ctx.globalAlpha = style.fillOpacity * style.opacity;
ctx.fill();
ctx.globalAlpha = originalGlobalAlpha;
}
else {
ctx.fill();
}
}
else if (textBackgroundColor && textBackgroundColor.image) {
var image = textBackgroundColor.image;
image = imageHelper.createOrUpdateImage(image, null, hostEl, onBgImageLoaded, textBackgroundColor);
if (image && imageHelper.isImageReady(image)) {
ctx.drawImage(image, x, y, width, height);
}
}
if (textBorderWidth && textBorderColor) {
setCtx(ctx, 'lineWidth', textBorderWidth);
setCtx(ctx, 'strokeStyle', textBorderColor);
if (style.strokeOpacity != null) {
var originalGlobalAlpha = ctx.globalAlpha;
ctx.globalAlpha = style.strokeOpacity * style.opacity;
ctx.stroke();
ctx.globalAlpha = originalGlobalAlpha;
}
else {
ctx.stroke();
}
}
}
function onBgImageLoaded(image, textBackgroundColor) {
textBackgroundColor.image = image;
}
function getBoxPosition(out, hostEl, style, rect) {
var baseX = style.x || 0;
var baseY = style.y || 0;
var textAlign = style.textAlign;
var textVerticalAlign = style.textVerticalAlign;
if (rect) {
var textPosition = style.textPosition;
if (textPosition instanceof Array) {
baseX = rect.x + parsePercent(textPosition[0], rect.width);
baseY = rect.y + parsePercent(textPosition[1], rect.height);
}
else {
var res = (hostEl && hostEl.calculateTextPosition)
? hostEl.calculateTextPosition(_tmpTextPositionResult, style, rect)
: textContain.calculateTextPosition(_tmpTextPositionResult, style, rect);
baseX = res.x;
baseY = res.y;
textAlign = textAlign || res.textAlign;
textVerticalAlign = textVerticalAlign || res.textVerticalAlign;
}
var textOffset = style.textOffset;
if (textOffset) {
baseX += textOffset[0];
baseY += textOffset[1];
}
}
out = out || {};
out.baseX = baseX;
out.baseY = baseY;
out.textAlign = textAlign;
out.textVerticalAlign = textVerticalAlign;
return out;
}
exports.getBoxPosition = getBoxPosition;
function setCtx(ctx, prop, value) {
ctx[prop] = fixShadow_1["default"](ctx, prop, value);
return ctx[prop];
}
function getStroke(stroke, lineWidth) {
return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
? null
: (stroke.image || stroke.colorStops)
? '#000'
: stroke;
}
exports.getStroke = getStroke;
function getFill(fill) {
return (fill == null || fill === 'none')
? null
: (fill.image || fill.colorStops)
? '#000'
: fill;
}
exports.getFill = getFill;
function parsePercent(value, maxValue) {
if (typeof value === 'string') {
if (value.lastIndexOf('%') >= 0) {
return parseFloat(value) / 100 * maxValue;
}
return parseFloat(value);
}
return value;
}
exports.parsePercent = parsePercent;
function getTextXForPadding(x, textAlign, textPadding) {
return textAlign === 'right'
? (x - textPadding[1])
: textAlign === 'center'
? (x + textPadding[3] / 2 - textPadding[1] / 2)
: (x + textPadding[3]);
}
function needDrawText(text, style) {
return text != null
&& !!(text
|| style.textBackgroundColor
|| (style.textBorderWidth && style.textBorderColor)
|| style.textPadding);
}
exports.needDrawText = needDrawText;
//# sourceMappingURL=text.js.map
File diff suppressed because one or more lines are too long