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;
}, __metadata = this && this.__metadata || function(k, v) {
    if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
}, __param = this && this.__param || function(paramIndex, decorator) {
    return function(target, key) {
        decorator(target, key, paramIndex);
    };
};

import { isArray } from "@visactor/vutils";

import { inject, injectable, named } from "../../../common/inversify-lite";

import { getTheme } from "../../../graphic/theme";

import { RECT_NUMBER_TYPE } from "../../../graphic/constants";

import { createRectPath } from "../../../common/shape/rect";

import { ContributionProvider } from "../../../common/contribution-provider";

import { RectRenderContribution } from "./contributions/constants";

import { rectFillVisible, rectStrokeVisible, runFill, runStroke } from "./utils";

import { BaseRender } from "./base-render";

import { defaultRectBackgroundRenderContribution, defaultRectRenderContribution, defaultRectTextureRenderContribution } from "./contributions";

let DefaultCanvasRectRender = class extends BaseRender {
    constructor(rectRenderContribitions) {
        super(), this.rectRenderContribitions = rectRenderContribitions, this.type = "rect", 
        this.numberType = RECT_NUMBER_TYPE, this.builtinContributions = [ defaultRectRenderContribution, defaultRectBackgroundRenderContribution, defaultRectTextureRenderContribution ], 
        this.init(rectRenderContribitions);
    }
    drawShape(rect, context, x, y, drawContext, params, fillCb, strokeCb, rectAttribute) {
        rectAttribute = null != rectAttribute ? rectAttribute : getTheme(rect, null == params ? void 0 : params.theme).rect;
        const {fill: fill = rectAttribute.fill, background: background, stroke: stroke = rectAttribute.stroke, cornerRadius: cornerRadius = rectAttribute.cornerRadius, cornerType: cornerType = rectAttribute.cornerType, opacity: opacity = rectAttribute.opacity, fillOpacity: fillOpacity = rectAttribute.fillOpacity, lineWidth: lineWidth = rectAttribute.lineWidth, strokeOpacity: strokeOpacity = rectAttribute.strokeOpacity, visible: visible = rectAttribute.visible, x1: x1, y1: y1, x: originX = rectAttribute.x, y: originY = rectAttribute.y, fillStrokeOrder: fillStrokeOrder = rectAttribute.fillStrokeOrder} = rect.attribute;
        let {width: width, height: height} = rect.attribute;
        width = (null != width ? width : x1 - originX) || 0, height = (null != height ? height : y1 - originY) || 0;
        const fVisible = rectFillVisible(opacity, fillOpacity, width, height, fill), sVisible = rectStrokeVisible(opacity, strokeOpacity, width, height), doFill = runFill(fill, background), doStroke = runStroke(stroke, lineWidth);
        if (!rect.valid || !visible) return;
        if (!doFill && !doStroke) return;
        if (!(fVisible || sVisible || fillCb || strokeCb || background)) return;
        0 === cornerRadius || isArray(cornerRadius) && cornerRadius.every((num => 0 === num)) ? (context.beginPath(), 
        context.rect(x, y, width, height)) : (context.beginPath(), createRectPath(context, x, y, width, height, cornerRadius, "bevel" !== cornerType));
        const doFillOrStroke = {
            doFill: doFill,
            doStroke: doStroke
        };
        context.setShadowBlendStyle && context.setShadowBlendStyle(rect, rect.attribute, rectAttribute), 
        this.beforeRenderStep(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb, doFillOrStroke), 
        fillStrokeOrder ? (this._runStroke(rect, context, x, y, rectAttribute, doFillOrStroke, sVisible, originX, originY, strokeCb), 
        this._runFill(rect, context, x, y, rectAttribute, doFillOrStroke, fVisible, originX, originY, fillCb)) : (this._runFill(rect, context, x, y, rectAttribute, doFillOrStroke, fVisible, originX, originY, fillCb), 
        this._runStroke(rect, context, x, y, rectAttribute, doFillOrStroke, sVisible, originX, originY, strokeCb)), 
        this.afterRenderStep(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb);
    }
    _runFill(rect, context, x, y, rectAttribute, doFillOrStroke, fVisible, originX, originY, fillCb) {
        doFillOrStroke.doFill && (fillCb ? fillCb(context, rect.attribute, rectAttribute) : fVisible && (context.setCommonStyle(rect, rect.attribute, originX - x, originY - y, rectAttribute), 
        context.fill()));
    }
    _runStroke(rect, context, x, y, rectAttribute, doFillOrStroke, sVisible, originX, originY, strokeCb) {
        doFillOrStroke.doStroke && (strokeCb ? strokeCb(context, rect.attribute, rectAttribute) : sVisible && (context.setStrokeStyle(rect, rect.attribute, originX - x, originY - y, rectAttribute), 
        context.stroke()));
    }
    draw(rect, renderService, drawContext, params) {
        const rectAttribute = getTheme(rect, null == params ? void 0 : params.theme).rect;
        this._draw(rect, rectAttribute, !1, drawContext, params, rectAttribute);
    }
};

DefaultCanvasRectRender = __decorate([ injectable(), __param(0, inject(ContributionProvider)), __param(0, named(RectRenderContribution)), __metadata("design:paramtypes", [ Object ]) ], DefaultCanvasRectRender);

export { DefaultCanvasRectRender };
//# sourceMappingURL=rect-render.js.map
