@eclipse-glsp/client
Version:
A sprotty-based client for GLSP
154 lines • 8.77 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DebugBoundsDecorator = exports.CSS_DEBUG_BOUNDS = void 0;
/********************************************************************************
* Copyright (c) 2024 Axon Ivy AG and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
/* eslint-disable max-len */
/** @jsx svg */
const sprotty_1 = require("@eclipse-glsp/sprotty");
const inversify_1 = require("inversify");
const model_1 = require("../../model");
exports.CSS_DEBUG_BOUNDS = 'debug-bounds';
let DebugBoundsDecorator = class DebugBoundsDecorator {
decorate(vnode, element) {
var _a;
if (!((_a = this.debugManager) === null || _a === void 0 ? void 0 : _a.isDebugEnabled)) {
return vnode;
}
if ((0, sprotty_1.isSizeable)(element) && this.shouldDecorateSizeable(element)) {
this.decorateSizeable(vnode, element);
}
if (element instanceof model_1.GGraph && this.shouldDecorateGraph(element)) {
this.decorateGraph(vnode, element);
}
return vnode;
}
postUpdate() { }
get decorationSize() {
return 5;
}
shouldDecorateGraph(graph) {
return true;
}
decorateGraph(vnode, graph) {
var _a, _b, _c;
(0, sprotty_1.setClass)(vnode, exports.CSS_DEBUG_BOUNDS, true);
const svgChild = (_a = vnode.children) === null || _a === void 0 ? void 0 : _a.find(child => typeof child !== 'string' && child.sel === 'svg');
const group = (_b = svgChild === null || svgChild === void 0 ? void 0 : svgChild.children) === null || _b === void 0 ? void 0 : _b.find(child => typeof child !== 'string' && child.sel === 'g');
(_c = group === null || group === void 0 ? void 0 : group.children) === null || _c === void 0 ? void 0 : _c.push(this.renderOrigin(graph));
}
renderOrigin(graph) {
return ((0, sprotty_1.svg)("polyline", { "class-debug-bounds-decoration": true, "class-debug-bounds-origin": true, points: `0,${this.decorationSize} 0,0 ${this.decorationSize},0` },
(0, sprotty_1.svg)("title", null, "Origin = x: 0, y: 0")));
}
shouldDecorateSizeable(element) {
return !(0, sprotty_1.isDecoration)(element);
}
decorateSizeable(vnode, element) {
var _a, _b, _c, _d, _e;
(0, sprotty_1.setClass)(vnode, exports.CSS_DEBUG_BOUNDS, true);
(_a = vnode.children) === null || _a === void 0 ? void 0 : _a.push(this.renderTopLeftCorner(element));
(_b = vnode.children) === null || _b === void 0 ? void 0 : _b.push(this.renderTopRightCorner(element));
(_c = vnode.children) === null || _c === void 0 ? void 0 : _c.push(this.renderBottomLeftCorner(element));
(_d = vnode.children) === null || _d === void 0 ? void 0 : _d.push(this.renderBottomRightCorner(element));
(_e = vnode.children) === null || _e === void 0 ? void 0 : _e.push(this.renderCenter(element));
}
renderTopLeftCorner(element) {
const position = sprotty_1.Bounds.position(element.bounds);
const topLeft = sprotty_1.Bounds.topLeft(element.bounds);
const corner = sprotty_1.Point.subtract(topLeft, position);
return ((0, sprotty_1.svg)("polyline", { "class-debug-bounds-decoration": true, "class-debug-bounds-top-left": true, points: `${corner.x},${corner.y + this.decorationSize} ${corner.x},${corner.y} ${corner.x + this.decorationSize},${corner.y}` },
(0, sprotty_1.svg)("title", null,
"Top Left = x: ",
topLeft.x,
", y: ",
topLeft.y)));
}
renderTopRightCorner(element) {
const position = sprotty_1.Bounds.position(element.bounds);
const topRight = sprotty_1.Bounds.topRight(element.bounds);
const corner = sprotty_1.Point.subtract(topRight, position);
return ((0, sprotty_1.svg)("polyline", { "class-debug-bounds-decoration": true, "class-debug-bounds-top-right": true, points: `${corner.x - this.decorationSize},${corner.y} ${corner.x},${corner.y} ${corner.x},${corner.y + this.decorationSize}` },
(0, sprotty_1.svg)("title", null,
"Top Right = x: ",
topRight.x,
", y: ",
topRight.y)));
}
renderBottomLeftCorner(element) {
const position = sprotty_1.Bounds.position(element.bounds);
const bottomLeft = sprotty_1.Bounds.bottomLeft(element.bounds);
const corner = sprotty_1.Point.subtract(bottomLeft, position);
return ((0, sprotty_1.svg)("polyline", { "class-debug-bounds-decoration": true, "class-debug-bounds-bottom-left": true, points: `${corner.x},${corner.y - this.decorationSize} ${corner.x},${corner.y} ${corner.x + this.decorationSize},${corner.y}` },
(0, sprotty_1.svg)("title", null,
"Bottom Left = x: ",
bottomLeft.x,
", y: ",
bottomLeft.y)));
}
renderBottomRightCorner(element) {
const position = sprotty_1.Bounds.position(element.bounds);
const bottomRight = sprotty_1.Bounds.bottomRight(element.bounds);
const corner = sprotty_1.Point.subtract(bottomRight, position);
return ((0, sprotty_1.svg)("polyline", { "class-debug-bounds-decoration": true, "class-debug-bounds-bottom-right": true, points: `${corner.x - this.decorationSize},${corner.y} ${corner.x},${corner.y} ${corner.x},${corner.y - this.decorationSize}` },
(0, sprotty_1.svg)("title", null,
"Bottom Right = x: ",
bottomRight.x,
", y: ",
bottomRight.y)));
}
renderCenter(element) {
const bounds = element.bounds;
const position = sprotty_1.Bounds.position(bounds);
const center = sprotty_1.Bounds.center(bounds);
const corner = sprotty_1.Point.subtract(center, position);
return ((0, sprotty_1.svg)("g", null,
(0, sprotty_1.svg)("title", null,
"Center = x: ",
center.x,
", y: ",
center.y,
"\rBounds = x: ",
bounds.x,
", y: ",
bounds.y,
", width: ",
bounds.width,
", height: ",
bounds.height),
(0, sprotty_1.svg)("polyline", { "class-debug-bounds-decoration": true, "class-debug-bounds-center": true, points: `${corner.x - this.decorationSize / 2},${corner.y - this.decorationSize / 2} ${corner.x + this.decorationSize / 2},${corner.y + this.decorationSize / 2}` }),
(0, sprotty_1.svg)("polyline", { "class-debug-bounds-decoration": true, "class-debug-bounds-center": true, points: `${corner.x + this.decorationSize / 2},${corner.y - this.decorationSize / 2} ${corner.x - this.decorationSize / 2},${corner.y + this.decorationSize / 2}` })));
}
};
exports.DebugBoundsDecorator = DebugBoundsDecorator;
__decorate([
(0, inversify_1.inject)(sprotty_1.TYPES.IDebugManager),
(0, inversify_1.optional)(),
__metadata("design:type", Object)
], DebugBoundsDecorator.prototype, "debugManager", void 0);
exports.DebugBoundsDecorator = DebugBoundsDecorator = __decorate([
(0, inversify_1.injectable)()
], DebugBoundsDecorator);
//# sourceMappingURL=debug-bounds-decorator.js.map