@gorpacrate/core-graphics
Version:
A core library for creating shape-based graphic editors
60 lines • 2.88 kB
JavaScript
;
exports.__esModule = true;
var tslib_1 = require("tslib");
var React = require("react");
var declarations_1 = require("../declarations");
var bounding_box_1 = require("../utils/bounding-box");
var constants_1 = require("./constants");
var SHAPE_BB_HOVER_PADDING = 10;
function getBBRect(params) {
var mode = params.mode;
if (!(declarations_1.isSelectedMode(mode) || declarations_1.isResizingMode(mode) || declarations_1.isMovingMode(mode))) {
return undefined;
}
var shapesDeclarations = params.shapesDeclarations, scene = params.scene;
var _a = bounding_box_1.getSelectedOrTransformedShapesBoundingBox({ mode: mode, shapesDeclarations: shapesDeclarations, scene: scene }), x1 = _a.x1, y1 = _a.y1, width = _a.width, height = _a.height;
var x = Math.round(x1) + 0.5;
var y = Math.round(y1) + 0.5;
var tWidth = Math.round(width);
var tHeight = Math.round(height);
return {
x: x, y: y, width: tWidth, height: tHeight
};
}
var BoundingBoxBorderRenderer = /** @class */ (function (_super) {
tslib_1.__extends(BoundingBoxBorderRenderer, _super);
function BoundingBoxBorderRenderer() {
return _super !== null && _super.apply(this, arguments) || this;
}
BoundingBoxBorderRenderer.prototype.render = function () {
var _a = this.props, mode = _a.mode, shapesDeclarations = _a.shapesDeclarations, scene = _a.scene;
var bbRect = getBBRect({ mode: mode, shapesDeclarations: shapesDeclarations, scene: scene });
if (!bbRect) {
return null;
}
else {
return (React.createElement("rect", tslib_1.__assign({ fill: 'none', strokeWidth: '1', stroke: constants_1.MAIN_COLOR, style: { cursor: 'move' } }, bbRect)));
}
};
return BoundingBoxBorderRenderer;
}(React.Component));
exports.BoundingBoxBorderRenderer = BoundingBoxBorderRenderer;
var BoundingBoxBackgroundRenderer = /** @class */ (function (_super) {
tslib_1.__extends(BoundingBoxBackgroundRenderer, _super);
function BoundingBoxBackgroundRenderer() {
return _super !== null && _super.apply(this, arguments) || this;
}
BoundingBoxBackgroundRenderer.prototype.render = function () {
var _a = this.props, mode = _a.mode, shapesDeclarations = _a.shapesDeclarations, scene = _a.scene;
var bbRect = getBBRect({ mode: mode, shapesDeclarations: shapesDeclarations, scene: scene });
if (!bbRect) {
return null;
}
else {
return (React.createElement("rect", tslib_1.__assign({ fill: 'transparent', strokeWidth: SHAPE_BB_HOVER_PADDING, stroke: 'trasparent', style: { cursor: 'move' } }, bbRect)));
}
};
return BoundingBoxBackgroundRenderer;
}(React.Component));
exports.BoundingBoxBackgroundRenderer = BoundingBoxBackgroundRenderer;
//# sourceMappingURL=bounding-box.js.map