UNPKG

@visactor/vrender-core

Version:
66 lines (55 loc) 2.46 kB
import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from "./graphic"; import { CustomPath2D } from "../common/custom-path2d"; import { getTheme } from "./theme"; import { application } from "../application"; import { RECT_NUMBER_TYPE } from "./constants"; import { normalizeRectAttributes } from "../common/rect-utils"; import { updateBoundsOfCommonOuterBorder } from "./graphic-service/common-outer-boder-bounds"; const RECT_UPDATE_TAG_KEY = [ "width", "x1", "y1", "height", "cornerRadius", ...GRAPHIC_UPDATE_TAG_KEY ]; export class Rect extends Graphic { constructor(params) { super(params), this.type = "rect", this.numberType = RECT_NUMBER_TYPE; } isValid() { return super.isValid() && this._isValid(); } _isValid() { return !0; } getGraphicTheme() { return getTheme(this).rect; } updateAABBBounds(attribute, rectTheme, aabbBounds) { if (!this.updatePathProxyAABBBounds(aabbBounds)) { let {width: width, height: height} = attribute; const {x1: x1, y1: y1, x: x, y: y} = attribute; width = null != width ? width : x1 - x, height = null != height ? height : y1 - y, (isFinite(width) || isFinite(height) || isFinite(x) || isFinite(y)) && aabbBounds.set(0, 0, width || 0, height || 0); } const {tb1: tb1, tb2: tb2} = application.graphicService.updateTempAABBBounds(aabbBounds); return updateBoundsOfCommonOuterBorder(attribute, rectTheme, tb1), aabbBounds.union(tb1), tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2), application.graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, !1, this), aabbBounds; } needUpdateTags(keys) { return super.needUpdateTags(keys, RECT_UPDATE_TAG_KEY); } needUpdateTag(key) { return super.needUpdateTag(key, RECT_UPDATE_TAG_KEY); } toCustomPath() { const attribute = this.attribute, {x: x, y: y, width: width, height: height} = normalizeRectAttributes(attribute), path = new CustomPath2D; return path.moveTo(x, y), path.rect(x, y, width, height), path; } clone() { return new Rect(Object.assign({}, this.attribute)); } getNoWorkAnimateAttr() { return Rect.NOWORK_ANIMATE_ATTR; } } Rect.NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR; export function createRect(attributes) { return new Rect(attributes); } //# sourceMappingURL=rect.js.map