@visactor/vrender-core
Version:
## Description
79 lines (73 loc) • 3.42 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.createPath = exports.Path = void 0;
const vutils_1 = require("@visactor/vutils"), graphic_1 = require("./graphic"), custom_path2d_1 = require("../common/custom-path2d"), theme_1 = require("./theme"), application_1 = require("../application"), constants_1 = require("./constants"), common_outer_boder_bounds_1 = require("./graphic-service/common-outer-boder-bounds"), PATH_UPDATE_TAG_KEY = [ "path", "customPath", ...graphic_1.GRAPHIC_UPDATE_TAG_KEY ];
class Path extends graphic_1.Graphic {
constructor(params) {
super(params), this.type = "path", this.numberType = constants_1.PATH_NUMBER_TYPE;
}
get pathShape() {
return this.tryUpdateAABBBounds(), this.getParsedPathShape();
}
isValid() {
return super.isValid() && this._isValid();
}
_isValid() {
const {path: path} = this.attribute;
return null != path && "" !== path;
}
getParsedPathShape() {
const pathTheme = this.getGraphicTheme();
if (!this.valid) return pathTheme.path;
const attribute = this.attribute;
return attribute.path instanceof custom_path2d_1.CustomPath2D ? attribute.path : ((0,
vutils_1.isNil)(this.cache) && this.doUpdatePathShape(), this.cache instanceof custom_path2d_1.CustomPath2D ? this.cache : pathTheme.path);
}
getGraphicTheme() {
return (0, theme_1.getTheme)(this).path;
}
updateAABBBounds(attribute, pathTheme, aabbBounds) {
if (!this.updatePathProxyAABBBounds(aabbBounds)) {
const pathShape = this.getParsedPathShape();
aabbBounds.union(pathShape.getBounds());
}
const {tb1: tb1, tb2: tb2} = application_1.application.graphicService.updateTempAABBBounds(aabbBounds);
(0, common_outer_boder_bounds_1.updateBoundsOfCommonOuterBorder)(attribute, pathTheme, tb1),
aabbBounds.union(tb1), tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);
const {lineJoin: lineJoin = pathTheme.lineJoin} = attribute;
return application_1.application.graphicService.transformAABBBounds(attribute, aabbBounds, pathTheme, "miter" === lineJoin, this),
aabbBounds;
}
doUpdateAABBBounds(full) {
return this.doUpdatePathShape(), super.doUpdateAABBBounds(full);
}
doUpdatePathShape() {
const attribute = this.attribute;
(0, vutils_1.isString)(attribute.path, !0) ? this.cache = (new custom_path2d_1.CustomPath2D).fromString(attribute.path) : attribute.customPath && (this.cache = new custom_path2d_1.CustomPath2D,
attribute.customPath(this.cache, this));
}
needUpdateTags(keys) {
return super.needUpdateTags(keys, PATH_UPDATE_TAG_KEY);
}
needUpdateTag(key) {
return super.needUpdateTag(key, PATH_UPDATE_TAG_KEY);
}
toCustomPath() {
return (new custom_path2d_1.CustomPath2D).fromCustomPath2D(this.getParsedPathShape(), 0, 0);
}
clone() {
return new Path(Object.assign({}, this.attribute));
}
getNoWorkAnimateAttr() {
return Path.NOWORK_ANIMATE_ATTR;
}
}
function createPath(attributes) {
return new Path(attributes);
}
exports.Path = Path, Path.NOWORK_ANIMATE_ATTR = Object.assign({
path: 1,
customPath: 1
}, graphic_1.NOWORK_ANIMATE_ATTR), exports.createPath = createPath;
//# sourceMappingURL=path.js.map