@visactor/vtable
Version:
canvas table width high performance
91 lines (79 loc) • 8.22 kB
JavaScript
var __decorate = this && this.__decorate || function(decorators, target, key, desc) {
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) (d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { BaseRenderContributionTime, injectable } from "./../../../vrender";
import { getWidthInfo, renderStroke } from "./group-contribution-render";
import { isArray } from "@visactor/vutils";
import { createRectPath } from "./../../../vrender";
let SplitRectBeforeRenderContribution = class {
constructor() {
this.time = BaseRenderContributionTime.beforeFillStroke, this.useStyle = !0, this.order = 0;
}
drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb, doFillOrStroke) {
const {stroke: stroke = rectAttribute.stroke, strokeArrayWidth: strokeArrayWidth = rectAttribute.strokeArrayWidth, strokeArrayColor: strokeArrayColor = rectAttribute.strokeArrayColor} = rect.attribute;
stroke && (Array.isArray(stroke) || Array.isArray(strokeArrayWidth) || Array.isArray(strokeArrayColor)) && (doFillOrStroke.doStroke = !1);
}
};
SplitRectBeforeRenderContribution = __decorate([ injectable() ], SplitRectBeforeRenderContribution);
export { SplitRectBeforeRenderContribution };
let SplitRectAfterRenderContribution = class {
constructor() {
this.time = BaseRenderContributionTime.afterFillStroke, this.useStyle = !0, this.order = 0;
}
drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
const {width: width = rectAttribute.width, height: height = rectAttribute.height, stroke: stroke = rectAttribute.stroke, strokeArrayColor: strokeArrayColor = rectAttribute.strokeArrayColor, strokeArrayWidth: strokeArrayWidth = rectAttribute.strokeArrayWidth, lineWidth: lineWidth = rectAttribute.lineWidth, strokeColor: strokeColor = rectAttribute.stroke, cornerRadius: cornerRadius = rectAttribute.cornerRadius} = rect.attribute;
if (stroke && (Array.isArray(strokeArrayWidth) || 0 !== lineWidth) && (Array.isArray(stroke) || Array.isArray(strokeArrayColor) || Array.isArray(strokeArrayWidth))) {
const deltaWidth = 0, deltaHeight = 0;
"border-rect" !== rect.name && "table-border-rect" !== rect.name && ("number" == typeof lineWidth && 1 & lineWidth || Array.isArray(strokeArrayWidth) && strokeArrayWidth.some((width => 1 & width))) && (x = Math.floor(x) + .5,
y = Math.floor(y) + .5), 0 === cornerRadius || isArray(cornerRadius) && cornerRadius.every((num => 0 === num)) ? renderStroke(rect, context, x, y, rectAttribute, stroke, strokeArrayWidth || lineWidth, strokeArrayColor || strokeColor, Math.ceil(width + deltaWidth), Math.ceil(height + deltaHeight)) : (context.beginPath(),
createRectPath(context, x, y, width, height, cornerRadius, new Array(4).fill(0).map(((_, i) => (x1, y1, x2, y2) => {
renderStrokeWithCornerRadius(i, x1, y1, x2, y2, rect, context, x, y, rectAttribute, stroke, strokeArrayWidth || lineWidth, strokeArrayColor || strokeColor, Math.ceil(width + deltaWidth), Math.ceil(height + deltaHeight));
}))), context.stroke());
}
}
};
SplitRectAfterRenderContribution = __decorate([ injectable() ], SplitRectAfterRenderContribution);
export { SplitRectAfterRenderContribution };
export function renderStrokeWithCornerRadius(i, x1, y1, x2, y2, rect, context, x, y, rectAttribute, stroke, strokeArrayWidth, strokeArrayColor, width, height) {
var _a, _b, _c, _d;
const group = rect, groupAttribute = rectAttribute, widthInfo = getWidthInfo(strokeArrayWidth), isWidthNumber = !Array.isArray(strokeArrayWidth), isStrokeTrue = !Array.isArray(stroke), isSplitDraw = Array.isArray(strokeArrayColor) || widthInfo.isSplitDraw;
context.stroke(), context.setStrokeStyle(rect, rect.attribute, x, y, rectAttribute);
const {lineDash: lineDash = groupAttribute.lineDash} = group.attribute;
let isDash = !1;
lineDash.length && lineDash.some((dash => Array.isArray(dash))) && (isDash = !0),
context.beginPath(), context.moveTo(x, y);
const strokeTop = (isStrokeTrue || stroke[0]) && (isWidthNumber || strokeArrayWidth[0]), strokeRight = (isStrokeTrue || stroke[1]) && (isWidthNumber || strokeArrayWidth[1]), strokeBottom = (isStrokeTrue || stroke[2]) && (isWidthNumber || strokeArrayWidth[2]), strokeLeft = (isStrokeTrue || stroke[3]) && (isWidthNumber || strokeArrayWidth[3]);
if (strokeTop && 0 === i) {
isWidthNumber ? widthInfo.width : strokeArrayWidth[0], isWidthNumber ? widthInfo.width : strokeArrayWidth[0];
context.moveTo(x1, y1), context.lineTo(x2, y2), (isSplitDraw || isDash) && (strokeArrayColor && strokeArrayColor[0] ? context.strokeStyle = strokeArrayColor[0] : strokeArrayColor && !strokeArrayColor[0] && (context.strokeStyle = "transparent"),
isWidthNumber || (context.lineWidth = strokeArrayWidth[0]), context.lineDashOffset = context.currentMatrix.e / context.currentMatrix.a,
isDash && context.setLineDash(null !== (_a = lineDash[0]) && void 0 !== _a ? _a : []),
context.stroke(), context.beginPath());
} else 0 === i && context.moveTo(x + width, y);
if (strokeRight && 1 === i) {
isWidthNumber ? widthInfo.width : strokeArrayWidth[1], isWidthNumber ? widthInfo.width : strokeArrayWidth[1];
context.moveTo(x1, y1), context.lineTo(x2, y2), (isSplitDraw || isDash) && (strokeArrayColor && strokeArrayColor[1] ? context.strokeStyle = strokeArrayColor[1] : strokeArrayColor && !strokeArrayColor[1] && (context.strokeStyle = "transparent"),
isWidthNumber || (context.lineWidth = strokeArrayWidth[1]), context.lineDashOffset = context.currentMatrix.f / context.currentMatrix.d,
isDash && context.setLineDash(null !== (_b = lineDash[1]) && void 0 !== _b ? _b : []),
context.stroke(), context.beginPath(), context.moveTo(x + width, y + height));
} else 1 === i && context.moveTo(x + width, y + height);
if (strokeBottom && 2 === i) {
isWidthNumber ? widthInfo.width : strokeArrayWidth[2], isWidthNumber ? widthInfo.width : strokeArrayWidth[2];
context.moveTo(x1, y1), context.lineTo(x2, y2), (isSplitDraw || isDash) && (strokeArrayColor && strokeArrayColor[2] ? context.strokeStyle = strokeArrayColor[2] : strokeArrayColor && !strokeArrayColor[2] && (context.strokeStyle = "transparent"),
isWidthNumber || (context.lineWidth = strokeArrayWidth[2]), context.lineDashOffset = context.currentMatrix.e / context.currentMatrix.a,
isDash && context.setLineDash(null !== (_c = lineDash[2]) && void 0 !== _c ? _c : []),
context.stroke(), context.beginPath(), context.moveTo(x, y + height));
} else 2 === i && context.moveTo(x, y + height);
if (strokeLeft && 3 === i) {
isWidthNumber ? widthInfo.width : strokeArrayWidth[3], isWidthNumber ? widthInfo.width : strokeArrayWidth[3];
context.moveTo(x1, y1), context.lineTo(x2, y2), (isSplitDraw || isDash) && (strokeArrayColor && strokeArrayColor[3] ? context.strokeStyle = strokeArrayColor[3] : strokeArrayColor && !strokeArrayColor[3] && (context.strokeStyle = "transparent"),
isWidthNumber || (context.lineWidth = strokeArrayWidth[3]), context.lineDashOffset = context.currentMatrix.f / context.currentMatrix.d,
isDash && context.setLineDash(null !== (_d = lineDash[3]) && void 0 !== _d ? _d : []),
context.stroke(), context.beginPath(), context.moveTo(x, y));
} else 3 === i && context.moveTo(x, y);
context.closePath(), isSplitDraw || isDash || (!isWidthNumber && widthInfo.width && (context.lineWidth = widthInfo.width),
context.stroke()), context.lineDashOffset = 0, context.setLineDash([]), context.beginPath();
}
//# sourceMappingURL=rect-contribution-render.js.map