erLeftWidth2 / 3, bounds.top + borderTopWidth2 / 3); this.topRightBorderDoubleOuterBox = tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left + topWidth, bounds.top + borderTopWidth2 / 3, trh - borderRightWidth2 / 3, trv - borderTopWidth2 / 3, CORNER.TOP_RIGHT) : new Vector(bounds.left + bounds.width - borderRightWidth2 / 3, bounds.top + borderTopWidth2 / 3); this.bottomRightBorderDoubleOuterBox = brh > 0 || brv > 0 ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh - borderRightWidth2 / 3, brv - borderBottomWidth2 / 3, CORNER.BOTTOM_RIGHT) : new Vector(bounds.left + bounds.width - borderRightWidth2 / 3, bounds.top + bounds.height - borderBottomWidth2 / 3); this.bottomLeftBorderDoubleOuterBox = blh > 0 || blv > 0 ? getCurvePoints(bounds.left + borderLeftWidth2 / 3, bounds.top + leftHeight, blh - borderLeftWidth2 / 3, blv - borderBottomWidth2 / 3, CORNER.BOTTOM_LEFT) : new Vector(bounds.left + borderLeftWidth2 / 3, bounds.top + bounds.height - borderBottomWidth2 / 3); this.topLeftBorderDoubleInnerBox = tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left + borderLeftWidth2 * 2 / 3, bounds.top + borderTopWidth2 * 2 / 3, tlh - borderLeftWidth2 * 2 / 3, tlv - borderTopWidth2 * 2 / 3, CORNER.TOP_LEFT) : new Vector(bounds.left + borderLeftWidth2 * 2 / 3, bounds.top + borderTopWidth2 * 2 / 3); this.topRightBorderDoubleInnerBox = tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left + topWidth, bounds.top + borderTopWidth2 * 2 / 3, trh - borderRightWidth2 * 2 / 3, trv - borderTopWidth2 * 2 / 3, CORNER.TOP_RIGHT) : new Vector(bounds.left + bounds.width - borderRightWidth2 * 2 / 3, bounds.top + borderTopWidth2 * 2 / 3); this.bottomRightBorderDoubleInnerBox = brh > 0 || brv > 0 ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh - borderRightWidth2 * 2 / 3, brv - borderBottomWidth2 * 2 / 3, CORNER.BOTTOM_RIGHT) : new Vector(bounds.left + bounds.width - borderRightWidth2 * 2 / 3, bounds.top + bounds.height - borderBottomWidth2 * 2 / 3); this.bottomLeftBorderDoubleInnerBox = blh > 0 || blv > 0 ? getCurvePoints(bounds.left + borderLeftWidth2 * 2 / 3, bounds.top + leftHeight, blh - borderLeftWidth2 * 2 / 3, blv - borderBottomWidth2 * 2 / 3, CORNER.BOTTOM_LEFT) : new Vector(bounds.left + borderLeftWidth2 * 2 / 3, bounds.top + bounds.height - borderBottomWidth2 * 2 / 3); this.topLeftBorderStroke = tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left + borderLeftWidth2 / 2, bounds.top + borderTopWidth2 / 2, tlh - borderLeftWidth2 / 2, tlv - borderTopWidth2 / 2, CORNER.TOP_LEFT) : new Vector(bounds.left + borderLeftWidth2 / 2, bounds.top + borderTopWidth2 / 2); this.topRightBorderStroke = tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left + topWidth, bounds.top + borderTopWidth2 / 2, trh - borderRightWidth2 / 2, trv - borderTopWidth2 / 2, CORNER.TOP_RIGHT) : new Vector(bounds.left + bounds.width - borderRightWidth2 / 2, bounds.top + borderTopWidth2 / 2); this.bottomRightBorderStroke = brh > 0 || brv > 0 ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh - borderRightWidth2 / 2, brv - borderBottomWidth2 / 2, CORNER.BOTTOM_RIGHT) : new Vector(bounds.left + bounds.width - borderRightWidth2 / 2, bounds.top + bounds.height - borderBottomWidth2 / 2); this.bottomLeftBorderStroke = blh > 0 || blv > 0 ? getCurvePoints(bounds.left + borderLeftWidth2 / 2, bounds.top + leftHeight, blh - borderLeftWidth2 / 2, blv - borderBottomWidth2 / 2, CORNER.BOTTOM_LEFT) : new Vector(bounds.left + borderLeftWidth2 / 2, bounds.top + bounds.height - borderBottomWidth2 / 2); this.topLeftBorderBox = tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left, bounds.top, tlh, tlv, CORNER.TOP_LEFT) : new Vector(bounds.left, bounds.top); this.topRightBorderBox = trh > 0 || trv > 0 ? getCurvePoints(bounds.left + topWidth, bounds.top, trh, trv, CORNER.TOP_RIGHT) : new Vector(bounds.left + bounds.width, bounds.top); this.bottomRightBorderBox = brh > 0 || brv > 0 ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh, brv, CORNER.BOTTOM_RIGHT) : new Vector(bounds.left + bounds.width, bounds.top + bounds.height); this.bottomLeftBorderBox = blh > 0 || blv > 0 ? getCurvePoints(bounds.left, bounds.top + leftHeight, blh, blv, CORNER.BOTTOM_LEFT) : new Vector(bounds.left, bounds.top + bounds.height); this.topLeftPaddingBox = tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left + borderLeftWidth2, bounds.top + borderTopWidth2, Math.max(0, tlh - borderLeftWidth2), Math.max(0, tlv - borderTopWidth2), CORNER.TOP_LEFT) : new Vector(bounds.left + borderLeftWidth2, bounds.top + borderTopWidth2); this.topRightPaddingBox = trh > 0 || trv > 0 ? getCurvePoints(bounds.left + Math.min(topWidth, bounds.width - borderRightWidth2), bounds.top + borderTopWidth2, topWidth > bounds.width + borderRightWidth2 ? 0 : Math.max(0, trh - borderRightWidth2), Math.max(0, trv - borderTopWidth2), CORNER.TOP_RIGHT) : new Vector(bounds.left + bounds.width - borderRightWidth2, bounds.top + borderTopWidth2); this.bottomRightPaddingBox = brh > 0 || brv > 0 ? getCurvePoints(bounds.left + Math.min(bottomWidth, bounds.width - borderLeftWidth2), bounds.top + Math.min(rightHeight, bounds.height - borderBottomWidth2), Math.max(0, brh - borderRightWidth2), Math.max(0, brv - borderBottomWidth2), CORNER.BOTTOM_RIGHT) : new Vector(bounds.left + bounds.width - borderRightWidth2, bounds.top + bounds.height - borderBottomWidth2); this.bottomLeftPaddingBox = blh > 0 || blv > 0 ? getCurvePoints(bounds.left + borderLeftWidth2, bounds.top + Math.min(leftHeight, bounds.height - borderBottomWidth2), Math.max(0, blh - borderLeftWidth2), Math.max(0, blv - borderBottomWidth2), CORNER.BOTTOM_LEFT) : new Vector(bounds.left + borderLeftWidth2, bounds.top + bounds.height - borderBottomWidth2); this.topLeftContentBox = tlh > 0 || tlv > 0 ? getCurvePoints(bounds.left + borderLeftWidth2 + paddingLeft2, bounds.top + borderTopWidth2 + paddingTop2, Math.max(0, tlh - (borderLeftWidth2 + paddingLeft2)), Math.max(0, tlv - (borderTopWidth2 + paddingTop2)), CORNER.TOP_LEFT) : new Vector(bounds.left + borderLeftWidth2 + paddingLeft2, bounds.top + borderTopWidth2 + paddingTop2); this.topRightContentBox = trh > 0 || trv > 0 ? getCurvePoints(bounds.left + Math.min(topWidth, bounds.width + borderLeftWidth2 + paddingLeft2), bounds.top + borderTopWidth2 + paddingTop2, topWidth > bounds.width + borderLeftWidth2 + paddingLeft2 ? 0 : trh - borderLeftWidth2 + paddingLeft2, trv - (borderTopWidth2 + paddingTop2), CORNER.TOP_RIGHT) : new Vector(bounds.left + bounds.width - (borderRightWidth2 + paddingRight2), bounds.top + borderTopWidth2 + paddingTop2); this.bottomRightContentBox = brh > 0 || brv > 0 ? getCurvePoints(bounds.left + Math.min(bottomWidth, bounds.width - (borderLeftWidth2 + paddingLeft2)), bounds.top + Math.min(rightHeight, bounds.height + borderTopWidth2 + paddingTop2), Math.max(0, brh - (borderRightWidth2 + paddingRight2)), brv - (borderBottomWidth2 + paddingBottom2), CORNER.BOTTOM_RIGHT) : new Vector(bounds.left + bounds.width - (borderRightWidth2 + paddingRight2), bounds.top + bounds.height - (borderBottomWidth2 + paddingBottom2)); this.bottomLeftContentBox = blh > 0 || blv > 0 ? getCurvePoints(bounds.left + borderLeftWidth2 + paddingLeft2, bounds.top + leftHeight, Math.max(0, blh - (borderLeftWidth2 + paddingLeft2)), blv - (borderBottomWidth2 + paddingBottom2), CORNER.BOTTOM_LEFT) : new Vector(bounds.left + borderLeftWidth2 + paddingLeft2, bounds.top + bounds.height - (borderBottomWidth2 + paddingBottom2)); } return BoundCurves2; }() ); var CORNER; (function(CORNER2) { CORNER2[CORNER2["TOP_LEFT"] = 0] = "TOP_LEFT"; CORNER2[CORNER2["TOP_RIGHT"] = 1] = "TOP_RIGHT"; CORNER2[CORNER2["BOTTOM_RIGHT"] = 2] = "BOTTOM_RIGHT"; CORNER2[CORNER2["BOTTOM_LEFT"] = 3] = "BOTTOM_LEFT"; })(CORNER || (CORNER = {})); var getCurvePoints = function(x, y, r1, r2, position2) { var kappa = 4 * ((Math.sqrt(2) - 1) / 3); var ox = r1 * kappa; var oy = r2 * kappa; var xm = x + r1; var ym = y + r2; switch (position2) { case CORNER.TOP_LEFT: return new BezierCurve(new Vector(x, ym), new Vector(x, ym - oy), new Vector(xm - ox, y), new Vector(xm, y)); case CORNER.TOP_RIGHT: return new BezierCurve(new Vector(x, y), new Vector(x + ox, y), new Vector(xm, ym - oy), new Vector(xm, ym)); case CORNER.BOTTOM_RIGHT: return new BezierCurve(new Vector(xm, y), new Vector(xm, y + oy), new Vector(x + ox, ym), new Vector(x, ym)); case CORNER.BOTTOM_LEFT: default: return new BezierCurve(new Vector(xm, ym), new Vector(xm - ox, ym), new Vector(x, y + oy), new Vector(x, y)); } }; var calculateBorderBoxPath = function(curves) { return [curves.topLeftBorderBox, curves.topRightBorderBox, curves.bottomRightBorderBox, curves.bottomLeftBorderBox]; }; var calculateContentBoxPath = function(curves) { return [ curves.topLeftContentBox, curves.topRightContentBox, curves.bottomRightContentBox, curves.bottomLeftContentBox ]; }; var calculatePaddingBoxPath = function(curves) { return [ curves.topLeftPaddingBox, curves.topRightPaddingBox, curves.bottomRightPaddingBox, curves.bottomLeftPaddingBox ]; }; var TransformEffect = ( /** @class */ /* @__PURE__ */ function() { function TransformEffect2(offsetX, offsetY, matrix2) { this.offsetX = offsetX; this.offsetY = offsetY; this.matrix = matrix2; this.type = 0; this.target = 2 | 4; } return TransformEffect2; }() ); var ClipEffect = ( /** @class */ /* @__PURE__ */ function() { function ClipEffect2(path, target) { this.path = path; this.target = target; this.type = 1; } return ClipEffect2; }() ); var OpacityEffect = ( /** @class */ /* @__PURE__ */ function() { function OpacityEffect2(opacity2) { this.opacity = opacity2; this.type = 2; this.target = 2 | 4; } return OpacityEffect2; }() ); var isTransformEffect = function(effect) { return effect.type === 0; }; var isClipEffect = function(effect) { return effect.type === 1; }; var isOpacityEffect = function(effect) { return effect.type === 2; }; var equalPath = function(a2, b) { if (a2.length === b.length) { return a2.some(function(v, i) { return v === b[i]; }); } return false; }; var transformPath = function(path, deltaX, deltaY, deltaW, deltaH) { return path.map(function(point, index) { switch (index) { case 0: return point.add(deltaX, deltaY); case 1: return point.add(deltaX + deltaW, deltaY); case 2: return point.add(deltaX + deltaW, deltaY + deltaH); case 3: return point.add(deltaX, deltaY + deltaH); } return point; }); }; var StackingContext = ( /** @class */ /* @__PURE__ */ function() { function StackingContext2(container) { this.element = container; this.inlineLevel = []; this.nonInlineLevel = []; this.negativeZIndex = []; this.zeroOrAutoZIndexOrTransformedOrOpacity = []; this.positiveZIndex = []; this.nonPositionedFloats = []; this.nonPositionedInlineLevel = []; } return StackingContext2; }() ); var ElementPaint = ( /** @class */ function() { function ElementPaint2(container, parent) { this.container = container; this.parent = parent; this.effects = []; this.curves = new BoundCurves(this.container); if (this.container.styles.opacity < 1) { this.effects.push(new OpacityEffect(this.container.styles.opacity)); } if (this.container.styles.transform !== null) { var offsetX = this.container.bounds.left + this.container.styles.transformOrigin[0].number; var offsetY = this.container.bounds.top + this.container.styles.transformOrigin[1].number; var matrix2 = this.container.styles.transform; this.effects.push(new TransformEffect(offsetX, offsetY, matrix2)); } if (this.container.styles.overflowX !== 0) { var borderBox = calculateBorderBoxPath(this.curves); var paddingBox2 = calculatePaddingBoxPath(this.curves); if (equalPath(borderBox, paddingBox2)) { this.effects.push(new ClipEffect( borderBox, 2 | 4 /* CONTENT */ )); } else { this.effects.push(new ClipEffect( borderBox, 2 /* BACKGROUND_BORDERS */ )); this.effects.push(new ClipEffect( paddingBox2, 4 /* CONTENT */ )); } } } ElementPaint2.prototype.getEffects = function(target) { var inFlow = [ 2, 3 /* FIXED */ ].indexOf(this.container.styles.position) === -1; var parent = this.parent; var effects = this.effects.slice(0); while (parent) { var croplessEffects = parent.effects.filter(function(effect) { return !isClipEffect(effect); }); if (inFlow || parent.container.styles.position !== 0 || !parent.parent) { effects.unshift.apply(effects, croplessEffects); inFlow = [ 2, 3 /* FIXED */ ].indexOf(parent.container.styles.position) === -1; if (parent.container.styles.overflowX !== 0) { var borderBox = calculateBorderBoxPath(parent.curves); var paddingBox2 = calculatePaddingBoxPath(parent.curves); if (!equalPath(borderBox, paddingBox2)) { effects.unshift(new ClipEffect( paddingBox2, 2 | 4 /* CONTENT */ )); } } } else { effects.unshift.apply(effects, croplessEffects); } parent = parent.parent; } return effects.filter(function(effect) { return contains(effect.target, target); }); }; return ElementPaint2; }() ); var parseStackTree = function(parent, stackingContext, realStackingContext, listItems) { parent.container.elements.forEach(function(child) { var treatAsRealStackingContext = contains( child.flags, 4 /* CREATES_REAL_STACKING_CONTEXT */ ); var createsStackingContext2 = contains( child.flags, 2 /* CREATES_STACKING_CONTEXT */ ); var paintContainer = new ElementPaint(child, parent); if (contains( child.styles.display, 2048 /* LIST_ITEM */ )) { listItems.push(paintContainer); } var listOwnerItems = contains( child.flags, 8 /* IS_LIST_OWNER */ ) ? [] : listItems; if (treatAsRealStackingContext || createsStackingContext2) { var parentStack = treatAsRealStackingContext || child.styles.isPositioned() ? realStackingContext : stackingContext; var stack = new StackingContext(paintContainer); if (child.styles.isPositioned() || child.styles.opacity < 1 || child.styles.isTransformed()) { var order_1 = child.styles.zIndex.order; if (order_1 < 0) { var index_1 = 0; parentStack.negativeZIndex.some(function(current, i) { if (order_1 > current.element.container.styles.zIndex.order) { index_1 = i; return false; } else if (index_1 > 0) { return true; } return false; }); parentStack.negativeZIndex.splice(index_1, 0, stack); } else if (order_1 > 0) { var index_2 = 0; parentStack.positiveZIndex.some(function(current, i) { if (order_1 >= current.element.container.styles.zIndex.order) { index_2 = i + 1; return false; } else if (index_2 > 0) { return true; } return false; }); parentStack.positiveZIndex.splice(index_2, 0, stack); } else { parentStack.zeroOrAutoZIndexOrTransformedOrOpacity.push(stack); } } else { if (child.styles.isFloating()) { parentStack.nonPositionedFloats.push(stack); } else { parentStack.nonPositionedInlineLevel.push(stack); } } parseStackTree(paintContainer, stack, treatAsRealStackingContext ? stack : realStackingContext, listOwnerItems); } else { if (child.styles.isInlineLevel()) { stackingContext.inlineLevel.push(paintContainer); } else { stackingContext.nonInlineLevel.push(paintContainer); } parseStackTree(paintContainer, stackingContext, realStackingContext, listOwnerItems); } if (contains( child.flags, 8 /* IS_LIST_OWNER */ )) { processListItems(child, listOwnerItems); } }); }; var processListItems = function(owner, elements) { var numbering = owner instanceof OLElementContainer ? owner.start : 1; var reversed = owner instanceof OLElementContainer ? owner.reversed : false; for (var i = 0; i < elements.length; i++) { var item = elements[i]; if (item.container instanceof LIElementContainer && typeof item.container.value === "number" && item.container.value !== 0) { numbering = item.container.value; } item.listValue = createCounterText(numbering, item.container.styles.listStyleType, true); numbering += reversed ? -1 : 1; } }; var parseStackingContexts = function(container) { var paintContainer = new ElementPaint(container, null); var root = new StackingContext(paintContainer); var listItems = []; parseStackTree(paintContainer, root, root, listItems); processListItems(paintContainer.container, listItems); return root; }; var parsePathForBorder = function(curves, borderSide) { switch (borderSide) { case 0: return createPathFromCurves(curves.topLeftBorderBox, curves.topLeftPaddingBox, curves.topRightBorderBox, curves.topRightPaddingBox); case 1: return createPathFromCurves(curves.topRightBorderBox, curves.topRightPaddingBox, curves.bottomRightBorderBox, curves.bottomRightPaddingBox); case 2: return createPathFromCurves(curves.bottomRightBorderBox, curves.bottomRightPaddingBox, curves.bottomLeftBorderBox, curves.bottomLeftPaddingBox); case 3: default: return createPathFromCurves(curves.bottomLeftBorderBox, curves.bottomLeftPaddingBox, curves.topLeftBorderBox, curves.topLeftPaddingBox); } }; var parsePathForBorderDoubleOuter = function(curves, borderSide) { switch (borderSide) { case 0: return createPathFromCurves(curves.topLeftBorderBox, curves.topLeftBorderDoubleOuterBox, curves.topRightBorderBox, curves.topRightBorderDoubleOuterBox); case 1: return createPathFromCurves(curves.topRightBorderBox, curves.topRightBorderDoubleOuterBox, curves.bottomRightBorderBox, curves.bottomRightBorderDoubleOuterBox); case 2: return createPathFromCurves(curves.bottomRightBorderBox, curves.bottomRightBorderDoubleOuterBox, curves.bottomLeftBorderBox, curves.bottomLeftBorderDoubleOuterBox); case 3: default: return createPathFromCurves(curves.bottomLeftBorderBox, curves.bottomLeftBorderDoubleOuterBox, curves.topLeftBorderBox, curves.topLeftBorderDoubleOuterBox); } }; var parsePathForBorderDoubleInner = function(curves, borderSide) { switch (borderSide) { case 0: return createPathFromCurves(curves.topLeftBorderDoubleInnerBox, curves.topLeftPaddingBox, curves.topRightBorderDoubleInnerBox, curves.topRightPaddingBox); case 1: return createPathFromCurves(curves.topRightBorderDoubleInnerBox, curves.topRightPaddingBox, curves.bottomRightBorderDoubleInnerBox, curves.bottomRightPaddingBox); case 2: return createPathFromCurves(curves.bottomRightBorderDoubleInnerBox, curves.bottomRightPaddingBox, curves.bottomLeftBorderDoubleInnerBox, curves.bottomLeftPaddingBox); case 3: default: return createPathFromCurves(curves.bottomLeftBorderDoubleInnerBox, curves.bottomLeftPaddingBox, curves.topLeftBorderDoubleInnerBox, curves.topLeftPaddingBox); } }; var parsePathForBorderStroke = function(curves, borderSide) { switch (borderSide) { case 0: return createStrokePathFromCurves(curves.topLeftBorderStroke, curves.topRightBorderStroke); case 1: return createStrokePathFromCurves(curves.topRightBorderStroke, curves.bottomRightBorderStroke); case 2: return createStrokePathFromCurves(curves.bottomRightBorderStroke, curves.bottomLeftBorderStroke); case 3: default: return createStrokePathFromCurves(curves.bottomLeftBorderStroke, curves.topLeftBorderStroke); } }; var createStrokePathFromCurves = function(outer1, outer2) { var path = []; if (isBezierCurve(outer1)) { path.push(outer1.subdivide(0.5, false)); } else { path.push(outer1); } if (isBezierCurve(outer2)) { path.push(outer2.subdivide(0.5, true)); } else { path.push(outer2); } return path; }; var createPathFromCurves = function(outer1, inner1, outer2, inner2) { var path = []; if (isBezierCurve(outer1)) { path.push(outer1.subdivide(0.5, false)); } else { path.push(outer1); } if (isBezierCurve(outer2)) { path.push(outer2.subdivide(0.5, true)); } else { path.push(outer2); } if (isBezierCurve(inner2)) { path.push(inner2.subdivide(0.5, true).reverse()); } else { path.push(inner2); } if (isBezierCurve(inner1)) { path.push(inner1.subdivide(0.5, false).reverse()); } else { path.push(inner1); } return path; }; var paddingBox = function(element) { var bounds = element.bounds; var styles = element.styles; return bounds.add(styles.borderLeftWidth, styles.borderTopWidth, -(styles.borderRightWidth + styles.borderLeftWidth), -(styles.borderTopWidth + styles.borderBottomWidth)); }; var contentBox = function(element) { var styles = element.styles; var bounds = element.bounds; var paddingLeft2 = getAbsoluteValue(styles.paddingLeft, bounds.width); var paddingRight2 = getAbsoluteValue(styles.paddingRight, bounds.width); var paddingTop2 = getAbsoluteValue(styles.paddingTop, bounds.width); var paddingBottom2 = getAbsoluteValue(styles.paddingBottom, bounds.width); return bounds.add(paddingLeft2 + styles.borderLeftWidth, paddingTop2 + styles.borderTopWidth, -(styles.borderRightWidth + styles.borderLeftWidth + paddingLeft2 + paddingRight2), -(styles.borderTopWidth + styles.borderBottomWidth + paddingTop2 + paddingBottom2)); }; var calculateBackgroundPositioningArea = function(backgroundOrigin2, element) { if (backgroundOrigin2 === 0) { return element.bounds; } if (backgroundOrigin2 === 2) { return contentBox(element); } return paddingBox(element); }; var calculateBackgroundPaintingArea = function(backgroundClip2, element) { if (backgroundClip2 === 0) { return element.bounds; } if (backgroundClip2 === 2) { return contentBox(element); } return paddingBox(element); }; var calculateBackgroundRendering = function(container, index, intrinsicSize) { var backgroundPositioningArea = calculateBackgroundPositioningArea(getBackgroundValueForIndex(container.styles.backgroundOrigin, index), container); var backgroundPaintingArea = calculateBackgroundPaintingArea(getBackgroundValueForIndex(container.styles.backgroundClip, index), container); var backgroundImageSize = calculateBackgroundSize(getBackgroundValueForIndex(container.styles.backgroundSize, index), intrinsicSize, backgroundPositioningArea); var sizeWidth = backgroundImageSize[0], sizeHeight = backgroundImageSize[1]; var position2 = getAbsoluteValueForTuple(getBackgroundValueForIndex(container.styles.backgroundPosition, index), backgroundPositioningArea.width - sizeWidth, backgroundPositioningArea.height - sizeHeight); var path = calculateBackgroundRepeatPath(getBackgroundValueForIndex(container.styles.backgroundRepeat, index), position2, backgroundImageSize, backgroundPositioningArea, backgroundPaintingArea); var offsetX = Math.round(backgroundPositioningArea.left + position2[0]); var offsetY = Math.round(backgroundPositioningArea.top + position2[1]); return [path, offsetX, offsetY, sizeWidth, sizeHeight]; }; var isAuto = function(token) { return isIdentToken(token) && token.value === BACKGROUND_SIZE.AUTO; }; var hasIntrinsicValue = function(value) { return typeof value === "number"; }; var calculateBackgroundSize = function(size, _a, bounds) { var intrinsicWidth = _a[0], intrinsicHeight = _a[1], intrinsicProportion = _a[2]; var first = size[0], second = size[1]; if (!first) { return [0, 0]; } if (isLengthPercentage(first) && second && isLengthPercentage(second)) { return [getAbsoluteValue(first, bounds.width), getAbsoluteValue(second, bounds.height)]; } var hasIntrinsicProportion = hasIntrinsicValue(intrinsicProportion); if (isIdentToken(first) && (first.value === BACKGROUND_SIZE.CONTAIN || first.value === BACKGROUND_SIZE.COVER)) { if (hasIntrinsicValue(intrinsicProportion)) { var targetRatio = bounds.width / bounds.height; return targetRatio < intrinsicProportion !== (first.value === BACKGROUND_SIZE.COVER) ? [bounds.width, bounds.width / intrinsicProportion] : [bounds.height * intrinsicProportion, bounds.height]; } return [bounds.width, bounds.height]; } var hasIntrinsicWidth = hasIntrinsicValue(intrinsicWidth); var hasIntrinsicHeight = hasIntrinsicValue(intrinsicHeight); var hasIntrinsicDimensions = hasIntrinsicWidth || hasIntrinsicHeight; if (isAuto(first) && (!second || isAuto(second))) { if (hasIntrinsicWidth && hasIntrinsicHeight) { return [intrinsicWidth, intrinsicHeight]; } if (!hasIntrinsicProportion && !hasIntrinsicDimensions) { return [bounds.width, bounds.height]; } if (hasIntrinsicDimensions && hasIntrinsicProportion) { var width_1 = hasIntrinsicWidth ? intrinsicWidth : intrinsicHeight * intrinsicProportion; var height_1 = hasIntrinsicHeight ? intrinsicHeight : intrinsicWidth / intrinsicProportion; return [width_1, height_1]; } var width_2 = hasIntrinsicWidth ? intrinsicWidth : bounds.width; var height_2 = hasIntrinsicHeight ? intrinsicHeight : bounds.height; return [width_2, height_2]; } if (hasIntrinsicProportion) { var width_3 = 0; var height_3 = 0; if (isLengthPercentage(first)) { width_3 = getAbsoluteValue(first, bounds.width); } else if (isLengthPercentage(second)) { height_3 = getAbsoluteValue(second, bounds.height); } if (isAuto(first)) { width_3 = height_3 * intrinsicProportion; } else if (!second || isAuto(second)) { height_3 = width_3 / intrinsicProportion; } return [width_3, height_3]; } var width = null; var height = null; if (isLengthPercentage(first)) { width = getAbsoluteValue(first, bounds.width); } else if (second && isLengthPercentage(second)) { height = getAbsoluteValue(second, bounds.height); } if (width !== null && (!second || isAuto(second))) { height = hasIntrinsicWidth && hasIntrinsicHeight ? width / intrinsicWidth * intrinsicHeight : bounds.height; } if (height !== null && isAuto(first)) { width = hasIntrinsicWidth && hasIntrinsicHeight ? height / intrinsicHeight * intrinsicWidth : bounds.width; } if (width !== null && height !== null) { return [width, height]; } throw new Error("Unable to calculate background-size for element"); }; var getBackgroundValueForIndex = function(values, index) { var value = values[index]; if (typeof value === "undefined") { return values[0]; } return value; }; var calculateBackgroundRepeatPath = function(repeat, _a, _b, backgroundPositioningArea, backgroundPaintingArea) { var x = _a[0], y = _a[1]; var width = _b[0], height = _b[1]; switch (repeat) { case 2: return [ new Vector(Math.round(backgroundPositioningArea.left), Math.round(backgroundPositioningArea.top + y)), new Vector(Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width), Math.round(backgroundPositioningArea.top + y)), new Vector(Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width), Math.round(height + backgroundPositioningArea.top + y)), new Vector(Math.round(backgroundPositioningArea.left), Math.round(height + backgroundPositioningArea.top + y)) ]; case 3: return [ new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.top)), new Vector(Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.top)), new Vector(Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top)), new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top)) ]; case 1: return [ new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.top + y)), new Vector(Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.top + y)), new Vector(Math.round(backgroundPositioningArea.left + x + width), Math.round(backgroundPositioningArea.top + y + height)), new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.top + y + height)) ]; default: return [ new Vector(Math.round(backgroundPaintingArea.left), Math.round(backgroundPaintingArea.top)), new Vector(Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width), Math.round(backgroundPaintingArea.top)), new Vector(Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width), Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top)), new Vector(Math.round(backgroundPaintingArea.left), Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top)) ]; } }; var SMALL_IMAGE = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; var SAMPLE_TEXT = "Hidden Text"; var FontMetrics = ( /** @class */ function() { function FontMetrics2(document2) { this._data = {}; this._document = document2; } FontMetrics2.prototype.parseMetrics = function(fontFamily2, fontSize2) { var container = this._document.createElement("div"); var img = this._document.createElement("img"); var span = this._document.createElement("span"); var body = this._document.body; container.style.visibility = "hidden"; container.style.fontFamily = fontFamily2; container.style.fontSize = fontSize2; container.style.margin = "0"; container.style.padding = "0"; container.style.whiteSpace = "nowrap"; body.appendChild(container); img.src = SMALL_IMAGE; img.width = 1; img.height = 1; img.style.margin = "0"; img.style.padding = "0"; img.style.verticalAlign = "baseline"; span.style.fontFamily = fontFamily2; span.style.fontSize = fontSize2; span.style.margin = "0"; span.style.padding = "0"; span.appendChild(this._document.createTextNode(SAMPLE_TEXT)); container.appendChild(span); container.appendChild(img); var baseline = img.offsetTop - span.offsetTop + 2; container.removeChild(span); container.appendChild(this._document.createTextNode(SAMPLE_TEXT)); container.style.lineHeight = "normal"; img.style.verticalAlign = "super"; var middle = img.offsetTop - container.offsetTop + 2; body.removeChild(container); return { baseline, middle }; }; FontMetrics2.prototype.getMetrics = function(fontFamily2, fontSize2) { var key = fontFamily2 + " " + fontSize2; if (typeof this._data[key] === "undefined") { this._data[key] = this.parseMetrics(fontFamily2, fontSize2); } return this._data[key]; }; return FontMetrics2; }() ); var Renderer = ( /** @class */ /* @__PURE__ */ function() { function Renderer2(context, options) { this.context = context; this.options = options; } return Renderer2; }() ); var MASK_OFFSET = 1e4; var CanvasRenderer = ( /** @class */ function(_super) { __extends(CanvasRenderer2, _super); function CanvasRenderer2(context, options) { var _this = _super.call(this, context, options) || this; _this._activeEffects = []; _this.canvas = options.canvas ? options.canvas : document.createElement("canvas"); _this.ctx = _this.canvas.getContext("2d"); if (!options.canvas) { _this.canvas.width = Math.floor(options.width * options.scale); _this.canvas.height = Math.floor(options.height * options.scale); _this.canvas.style.width = options.width + "px"; _this.canvas.style.height = options.height + "px"; } _this.fontMetrics = new FontMetrics(document); _this.ctx.scale(_this.options.scale, _this.options.scale); _this.ctx.translate(-options.x, -options.y); _this.ctx.textBaseline = "bottom"; _this._activeEffects = []; _this.context.logger.debug("Canvas renderer initialized (" + options.width + "x" + options.height + ") with scale " + options.scale); return _this; } CanvasRenderer2.prototype.applyEffects = function(effects) { var _this = this; while (this._activeEffects.length) { this.popEffect(); } effects.forEach(function(effect) { return _this.applyEffect(effect); }); }; CanvasRenderer2.prototype.applyEffect = function(effect) { this.ctx.save(); if (isOpacityEffect(effect)) { this.ctx.globalAlpha = effect.opacity; } if (isTransformEffect(effect)) { this.ctx.translate(effect.offsetX, effect.offsetY); this.ctx.transform(effect.matrix[0], effect.matrix[1], effect.matrix[2], effect.matrix[3], effect.matrix[4], effect.matrix[5]); this.ctx.translate(-effect.offsetX, -effect.offsetY); } if (isClipEffect(effect)) { this.path(effect.path); this.ctx.clip(); } this._activeEffects.push(effect); }; CanvasRenderer2.prototype.popEffect = function() { this._activeEffects.pop(); this.ctx.restore(); }; CanvasRenderer2.prototype.renderStack = function(stack) { return __awaiter(this, void 0, void 0, function() { var styles; return __generator(this, function(_a) { switch (_a.label) { case 0: styles = stack.element.container.styles; if (!styles.isVisible()) return [3, 2]; return [4, this.renderStackContent(stack)]; case 1: _a.sent(); _a.label = 2; case 2: return [ 2 /*return*/ ]; } }); }); }; CanvasRenderer2.prototype.renderNode = function(paint) { return __awaiter(this, void 0, void 0, function() { return __generator(this, function(_a) { switch (_a.label) { case 0: if (contains( paint.container.flags, 16 /* DEBUG_RENDER */ )) { debugger; } if (!paint.container.styles.isVisible()) return [3, 3]; return [4, this.renderNodeBackgroundAndBorders(paint)]; case 1: _a.sent(); return [4, this.renderNodeContent(paint)]; case 2: _a.sent(); _a.label = 3; case 3: return [ 2 /*return*/ ]; } }); }); }; CanvasRenderer2.prototype.renderTextWithLetterSpacing = function(text, letterSpacing2, baseline) { var _this = this; if (letterSpacing2 === 0) { this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline); } else { var letters = segmentGraphemes(text.text); letters.reduce(function(left, letter) { _this.ctx.fillText(letter, left, text.bounds.top + baseline); return left + _this.ctx.measureText(letter).width; }, text.bounds.left); } }; CanvasRenderer2.prototype.createFontStyle = function(styles) { var fontVariant2 = styles.fontVariant.filter(function(variant) { return variant === "normal" || variant === "small-caps"; }).join(""); var fontFamily2 = fixIOSSystemFonts(styles.fontFamily).join(", "); var fontSize2 = isDimensionToken(styles.fontSize) ? "" + styles.fontSize.number + styles.fontSize.unit : styles.fontSize.number + "px"; return [ [styles.fontStyle, fontVariant2, styles.fontWeight, fontSize2, fontFamily2].join(" "), fontFamily2, fontSize2 ]; }; CanvasRenderer2.prototype.renderTextNode = function(text, styles) { return __awaiter(this, void 0, void 0, function() { var _a, font, fontFamily2, fontSize2, _b, baseline, middle, paintOrder2; var _this = this; return __generator(this, function(_c) { _a = this.createFontStyle(styles), font = _a[0], fontFamily2 = _a[1], fontSize2 = _a[2]; this.ctx.font = font; this.ctx.direction = styles.direction === 1 ? "rtl" : "ltr"; this.ctx.textAlign = "left"; this.ctx.textBaseline = "alphabetic"; _b = this.fontMetrics.getMetrics(fontFamily2, fontSize2), baseline = _b.baseline, middle = _b.middle; paintOrder2 = styles.paintOrder; text.textBounds.forEach(function(text2) { paintOrder2.forEach(function(paintOrderLayer) { switch (paintOrderLayer) { case 0: _this.ctx.fillStyle = asString(styles.color); _this.renderTextWithLetterSpacing(text2, styles.letterSpacing, baseline); var textShadows = styles.textShadow; if (textShadows.length && text2.text.trim().length) { textShadows.slice(0).reverse().forEach(function(textShadow2) { _this.ctx.shadowColor = asString(textShadow2.color); _this.ctx.shadowOffsetX = textShadow2.offsetX.number * _this.options.scale; _this.ctx.shadowOffsetY = textShadow2.offsetY.number * _this.options.scale; _this.ctx.shadowBlur = textShadow2.blur.number; _this.renderTextWithLetterSpacing(text2, styles.letterSpacing, baseline); }); _this.ctx.shadowColor = ""; _this.ctx.shadowOffsetX = 0; _this.ctx.shadowOffsetY = 0; _this.ctx.shadowBlur = 0; } if (styles.textDecorationLine.length) { _this.ctx.fillStyle = asString(styles.textDecorationColor || styles.color); styles.textDecorationLine.forEach(function(textDecorationLine2) { switch (textDecorationLine2) { case 1: _this.ctx.fillRect(text2.bounds.left, Math.round(text2.bounds.top + baseline), text2.bounds.width, 1); break; case 2: _this.ctx.fillRect(text2.bounds.left, Math.round(text2.bounds.top), text2.bounds.width, 1); break; case 3: _this.ctx.fillRect(text2.bounds.left, Math.ceil(text2.bounds.top + middle), text2.bounds.width, 1); break; } }); } break; case 1: if (styles.webkitTextStrokeWidth && text2.text.trim().length) { _this.ctx.strokeStyle = asString(styles.webkitTextStrokeColor); _this.ctx.lineWidth = styles.webkitTextStrokeWidth; _this.ctx.lineJoin = !!window.chrome ? "miter" : "round"; _this.ctx.strokeText(text2.text, text2.bounds.left, text2.bounds.top + baseline); } _this.ctx.strokeStyle = ""; _this.ctx.lineWidth = 0; _this.ctx.lineJoin = "miter"; break; } }); }); return [ 2 /*return*/ ]; }); }); }; CanvasRenderer2.prototype.renderReplacedElement = function(container, curves, image2) { if (image2 && container.intrinsicWidth > 0 && container.intrinsicHeight > 0) { var box = contentBox(container); var path = calculatePaddingBoxPath(curves); this.path(path); this.ctx.save(); this.ctx.clip(); this.ctx.drawImage(image2, 0, 0, container.intrinsicWidth, container.intrinsicHeight, box.left, box.top, box.width, box.height); this.ctx.restore(); } }; CanvasRenderer2.prototype.renderNodeContent = function(paint) { return __awaiter(this, void 0, void 0, function() { var container, curves, styles, _i, _a, child, image2, image2, iframeRenderer, canvas, size, _b, fontFamily2, fontSize2, baseline, bounds, x, textBounds, img, image2, url, fontFamily2, bounds; return __generator(this, function(_c) { switch (_c.label) { case 0: this.applyEffects(paint.getEffects( 4 /* CONTENT */ )); container = paint.container; curves = paint.curves; styles = container.styles; _i = 0, _a = container.textNodes; _c.label = 1; case 1: if (!(_i < _a.length)) return [3, 4]; child = _a[_i]; return [4, this.renderTextNode(child, styles)]; case 2: _c.sent(); _c.label = 3; case 3: _i++; return [3, 1]; case 4: if (!(container instanceof ImageElementContainer)) return [3, 8]; _c.label = 5; case 5: _c.trys.push([5, 7, , 8]); return [4, this.context.cache.match(container.src)]; case 6: image2 = _c.sent(); this.renderReplacedElement(container, curves, image2); return [3, 8]; case 7: _c.sent(); this.context.logger.error("Error loading image " + container.src); return [3, 8]; case 8: if (container instanceof CanvasElementContainer) { this.renderReplacedElement(container, curves, container.canvas); } if (!(container instanceof SVGElementContainer)) return [3, 12]; _c.label = 9; case 9: _c.trys.push([9, 11, , 12]); return [4, this.context.cache.match(container.svg)]; case 10: image2 = _c.sent(); this.renderReplacedElement(container, curves, image2); return [3, 12]; case 11: _c.sent(); this.context.logger.error("Error loading svg " + container.svg.substring(0, 255)); return [3, 12]; case 12: if (!(container instanceof IFrameElementContainer && container.tree)) return [3, 14]; iframeRenderer = new CanvasRenderer2(this.context, { scale: this.options.scale, backgroundColor: container.backgroundColor, x: 0, y: 0, width: container.width, height: container.height }); return [4, iframeRenderer.render(container.tree)]; case 13: canvas = _c.sent(); if (container.width && container.height) { this.ctx.drawImage(canvas, 0, 0, container.width, container.height, container.bounds.left, container.bounds.top, container.bounds.width, container.bounds.height); } _c.label = 14; case 14: if (container instanceof InputElementContainer) { size = Math.min(container.bounds.width, container.bounds.height); if (container.type === CHECKBOX) { if (container.checked) { this.ctx.save(); this.path([ new Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79), new Vector(container.bounds.left + size * 0.16, container.bounds.top + size * 0.5549), new Vector(container.bounds.left + size * 0.27347, container.bounds.top + size * 0.44071), new Vector(container.bounds.left + size * 0.39694, container.bounds.top + size * 0.5649), new Vector(container.bounds.left + size * 0.72983, container.bounds.top + size * 0.23), new Vector(container.bounds.left + size * 0.84, container.bounds.top + size * 0.34085), new Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79) ]); this.ctx.fillStyle = asString(INPUT_COLOR); this.ctx.fill(); this.ctx.restore(); } } else if (container.type === RADIO) { if (container.checked) { this.ctx.save(); this.ctx.beginPath(); this.ctx.arc(container.bounds.left + size / 2, container.bounds.top + size / 2, size / 4, 0, Math.PI * 2, true); this.ctx.fillStyle = asString(INPUT_COLOR); this.ctx.fill(); this.ctx.restore(); } } } if (isTextInputElement(container) && container.value.length) { _b = this.createFontStyle(styles), fontFamily2 = _b[0], fontSize2 = _b[1]; baseline = this.fontMetrics.getMetrics(fontFamily2, fontSize2).baseline; this.ctx.font = fontFamily2; this.ctx.fillStyle = asString(styles.color); this.ctx.textBaseline = "alphabetic"; this.ctx.textAlign = canvasTextAlign(container.styles.textAlign); bounds = contentBox(container); x = 0; switch (container.styles.textAlign) { case 1: x += bounds.width / 2; break; case 2: x += bounds.width; break; } textBounds = bounds.add(x, 0, 0, -bounds.height / 2 + 1); this.ctx.save(); this.path([ new Vector(bounds.left, bounds.top), new Vector(bounds.left + bounds.width, bounds.top), new Vector(bounds.left + bounds.width, bounds.top + bounds.height), new Vector(bounds.left, bounds.top + bounds.height) ]); this.ctx.clip(); this.renderTextWithLetterSpacing(new TextBounds(container.value, textBounds), styles.letterSpacing, baseline); this.ctx.restore(); this.ctx.textBaseline = "alphabetic"; this.ctx.textAlign = "left"; } if (!contains( container.styles.display, 2048 /* LIST_ITEM */ )) return [3, 20]; if (!(container.styles.listStyleImage !== null)) return [3, 19]; img = container.styles.listStyleImage; if (!(img.type === 0)) return [3, 18]; image2 = void 0; url = img.url; _c.label = 15; case 15: _c.trys.push([15, 17, , 18]); return [4, this.context.cache.match(url)]; case 16: image2 = _c.sent(); this.ctx.drawImage(image2, container.bounds.left - (image2.width + 10), container.bounds.top); return [3, 18]; case 17: _c.sent(); this.context.logger.error("Error loading list-style-image " + url); return [3, 18]; case 18: return [3, 20]; case 19: if (paint.listValue && container.styles.listStyleType !== -1) { fontFamily2 = this.createFontStyle(styles)[0]; this.ctx.font = fontFamily2; this.ctx.fillStyle = asString(styles.color); this.ctx.textBaseline = "middle"; this.ctx.textAlign = "right"; bounds = new Bounds(container.bounds.left, container.bounds.top + getAbsoluteValue(container.styles.paddingTop, container.bounds.width), container.bounds.width, computeLineHeight(styles.lineHeight, styles.fontSize.number) / 2 + 1); this.renderTextWithLetterSpacing(new TextBounds(paint.listValue, bounds), styles.letterSpacing, computeLineHeight(styles.lineHeight, styles.fontSize.number) / 2 + 2); this.ctx.textBaseline = "bottom"; this.ctx.textAlign = "left"; } _c.label = 20; case 20: return [ 2 /*return*/ ]; } }); }); }; CanvasRenderer2.prototype.renderStackContent = function(stack) { return __awaiter(this, void 0, void 0, function() { var _i, _a, child, _b, _c, child, _d, _e, child, _f, _g, child, _h, _j, child, _k, _l, child, _m, _o, child; return __generator(this, function(_p) { switch (_p.label) { case 0: if (contains( stack.element.container.flags, 16 /* DEBUG_RENDER */ )) { debugger; } return [4, this.renderNodeBackgroundAndBorders(stack.element)]; case 1: _p.sent(); _i = 0, _a = stack.negativeZIndex; _p.label = 2; case 2: if (!(_i < _a.length)) return [3, 5]; child = _a[_i]; return [4, this.renderStack(child)]; case 3: _p.sent(); _p.label = 4; case 4: _i++; return [3, 2]; case 5: return [4, this.renderNodeContent(stack.element)]; case 6: _p.sent(); _b = 0, _c = stack.nonInlineLevel; _p.label = 7; case 7: if (!(_b < _c.length)) return [3, 10]; child = _c[_b]; return [4, this.renderNode(child)]; case 8: _p.sent(); _p.label = 9; case 9: _b++; return [3, 7]; case 10: _d = 0, _e = stack.nonPositionedFloats; _p.label = 11; case 11: if (!(_d < _e.length)) return [3, 14]; child = _e[_d]; return [4, this.renderStack(child)]; case 12: _p.sent(); _p.label = 13; case 13: _d++; return [3, 11]; case 14: _f = 0, _g = stack.nonPositionedInlineLevel; _p.label = 15; case 15: if (!(_f < _g.length)) return [3, 18]; child = _g[_f]; return [4, this.renderStack(child)]; case 16: _p.sent(); _p.label = 17; case 17: _f++; return [3, 15]; case 18: _h = 0, _j = stack.inlineLevel; _p.label = 19; case 19: if (!(_h < _j.length)) return [3, 22]; child = _j[_h]; return [4, this.renderNode(child)]; case 20: _p.sent(); _p.label = 21; case 21: _h++; return [3, 19]; case 22: _k = 0, _l = stack.zeroOrAutoZIndexOrTransformedOrOpacity; _p.label = 23; case 23: if (!(_k < _l.length)) return [3, 26]; child = _l[_k]; return [4, this.renderStack(child)]; case 24: _p.sent(); _p.label = 25; case 25: _k++; return [3, 23]; case 26: _m = 0, _o = stack.positiveZIndex; _p.label = 27; case 27: if (!(_m < _o.length)) return [3, 30]; child = _o[_m]; return [4, this.renderStack(child)]; case 28: _p.sent(); _p.label = 29; case 29: _m++; return [3, 27]; case 30: return [ 2 /*return*/ ]; } }); }); }; CanvasRenderer2.prototype.mask = function(paths) { this.ctx.beginPath(); this.ctx.moveTo(0, 0); this.ctx.lineTo(this.canvas.width, 0); this.ctx.lineTo(this.canvas.width, this.canvas.height); this.ctx.lineTo(0, this.canvas.height); this.ctx.lineTo(0, 0); this.formatPath(paths.slice(0).reverse()); this.ctx.closePath(); }; CanvasRenderer2.prototype.path = function(paths) { this.ctx.beginPath(); this.formatPath(paths); this.ctx.closePath(); }; CanvasRenderer2.prototype.formatPath = function(paths) { var _this = this; paths.forEach(function(point, index) { var start = isBezierCurve(point) ? point.start : point; if (index === 0) { _this.ctx.moveTo(start.x, start.y); } else { _this.ctx.lineTo(start.x, start.y); } if (isBezierCurve(point)) { _this.ctx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y); } }); }; CanvasRenderer2.prototype.renderRepeat = function(path, pattern, offsetX, offsetY) { this.path(path); this.ctx.fillStyle = pattern; this.ctx.translate(offsetX, offsetY); this.ctx.fill(); this.ctx.translate(-offsetX, -offsetY); }; CanvasRenderer2.prototype.resizeImage = function(image2, width, height) { var _a; if (image2.width === width && image2.height === height) { return image2; } var ownerDocument = (_a = this.canvas.ownerDocument) !== null && _a !== void 0 ? _a : document; var canvas = ownerDocument.createElement("canvas"); canvas.width = Math.max(1, width); canvas.height = Math.max(1, height); var ctx = canvas.getContext("2d"); ctx.drawImage(image2, 0, 0, image2.width, image2.height, 0, 0, width, height); return canvas; }; CanvasRenderer2.prototype.renderBackgroundImage = function(container) { return __awaiter(this, void 0, void 0, function() { var index, _loop_1, this_1, _i, _a, backgroundImage2; return __generator(this, function(_b) { switch (_b.label) { case 0: index = container.styles.backgroundImage.length - 1; _loop_1 = function(backgroundImage3) { var image2, url, _c, path, x, y, width, height, pattern, _d, path, x, y, width, height, _e, lineLength, x0, x1, y0, y1, canvas, ctx, gradient_1, pattern, _f, path, left, top_1, width, height, position2, x, y, _g, rx, ry, radialGradient_1, midX, midY, f2, invF; return __generator(this, function(_h) { switch (_h.label) { case 0: if (!(backgroundImage3.type === 0)) return [3, 5]; image2 = void 0; url = backgroundImage3.url; _h.label = 1; case 1: _h.trys.push([1, 3, , 4]); return [4, this_1.context.cache.match(url)]; case 2: image2 = _h.sent(); return [3, 4]; case 3: _h.sent(); this_1.context.logger.error("Error loading background-image " + url); return [3, 4]; case 4: if (image2) { _c = calculateBackgroundRendering(container, index, [ image2.width, image2.height, image2.width / image2.height ]), path = _c[0], x = _c[1], y = _c[2], width = _c[3], height = _c[4]; pattern = this_1.ctx.createPattern(this_1.resizeImage(image2, width, height), "repeat"); this_1.renderRepeat(path, pattern, x, y); } return [3, 6]; case 5: if (isLinearGradient(backgroundImage3)) { _d = calculateBackgroundRendering(container, index, [null, null, null]), path = _d[0], x = _d[1], y = _d[2], width = _d[3], height = _d[4]; _e = calculateGradientDirection(backgroundImage3.angle, width, height), lineLength = _e[0], x0 = _e[1], x1 = _e[2], y0 = _e[3], y1 = _e[4]; canvas = document.createElement("canvas"); canvas.width = width; canvas.height = height; ctx = canvas.getContext("2d"); gradient_1 = ctx.createLinearGradient(x0, y0, x1, y1); processColorStops(backgroundImage3.stops, lineLength).forEach(function(colorStop) { return gradient_1.addColorStop(colorStop.stop, asString(colorStop.color)); }); ctx.fillStyle = gradient_1; ctx.fillRect(0, 0, width, height); if (width > 0 && height > 0) { pattern = this_1.ctx.createPattern(canvas, "repeat"); this_1.renderRepeat(path, pattern, x, y); } } else if (isRadialGradient(backgroundImage3)) { _f = calculateBackgroundRendering(container, index, [ null, null, null ]), path = _f[0], left = _f[1], top_1 = _f[2], width = _f[3], height = _f[4]; position2 = backgroundImage3.position.length === 0 ? [FIFTY_PERCENT] : backgroundImage3.position; x = getAbsoluteValue(position2[0], width); y = getAbsoluteValue(position2[position2.length - 1], height); _g = calculateRadius(backgroundImage3, x, y, width, height), rx = _g[0], ry = _g[1]; if (rx > 0 && ry > 0) { radialGradient_1 = this_1.ctx.createRadialGradient(left + x, top_1 + y, 0, left + x, top_1 + y, rx); processColorStops(backgroundImage3.stops, rx * 2).forEach(function(colorStop) { return radialGradient_1.addColorStop(colorStop.stop, asString(colorStop.color)); }); this_1.path(path); this_1.ctx.fillStyle = radialGradient_1; if (rx !== ry) { midX = container.bounds.left + 0.5 * container.bounds.width; midY = container.bounds.top + 0.5 * container.bounds.height; f2 = ry / rx; invF = 1 / f2; this_1.ctx.save(); this_1.ctx.translate(midX, midY); this_1.ctx.transform(1, 0, 0, f2, 0, 0); this_1.ctx.translate(-midX, -midY); this_1.ctx.fillRect(left, invF * (top_1 - midY) + midY, width, height * invF); this_1.ctx.restore(); } else { this_1.ctx.fill(); } } } _h.label = 6; case 6: index--; return [ 2 /*return*/ ]; } }); }; this_1 = this; _i = 0, _a = container.styles.backgroundImage.slice(0).reverse(); _b.label = 1; case 1: if (!(_i < _a.length)) return [3, 4]; backgroundImage2 = _a[_i]; return [5, _loop_1(backgroundImage2)]; case 2: _b.sent(); _b.label = 3; case 3: _i++; return [3, 1]; case 4: return [ 2 /*return*/ ]; } }); }); }; CanvasRenderer2.prototype.renderSolidBorder = function(color2, side, curvePoints) { return __awaiter(this, void 0, void 0, function() { return __generator(this, function(_a) { this.path(parsePathForBorder(curvePoints, side)); this.ctx.fillStyle = asString(color2); this.ctx.fill(); return [ 2 /*return*/ ]; }); }); }; CanvasRenderer2.prototype.renderDoubleBorder = function(color2, width, side, curvePoints) { return __awaiter(this, void 0, void 0, function() { var outerPaths, innerPaths; return __generator(this, function(_a) { switch (_a.label) { case 0: if (!(width < 3)) return [3, 2]; return [4, this.renderSolidBorder(color2, side, curvePoints)]; case 1: _a.sent(); return [ 2 /*return*/ ]; case 2: outerPaths = parsePathForBorderDoubleOuter(curvePoints, side); this.path(outerPaths); this.ctx.fillStyle = asString(color2); this.ctx.fill(); innerPaths = parsePathForBorderDoubleInner(curvePoints, side); this.path(innerPaths); this.ctx.fill(); return [ 2 /*return*/ ]; } }); }); }; CanvasRenderer2.prototype.renderNodeBackgroundAndBorders = function(paint) { return __awaiter(this, void 0, void 0, function() { var styles, hasBackground, borders, backgroundPaintingArea, side, _i, borders_1, border; var _this = this; return __generator(this, function(_a) { switch (_a.label) { case 0: this.applyEffects(paint.getEffects( 2 /* BACKGROUND_