@eclipse-glsp/client
Version:
A sprotty-based client for GLSP
84 lines • 4.92 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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoundedCornerNodeView = void 0;
exports.toClipPathId = toClipPathId;
/********************************************************************************
* Copyright (c) 2021-2025 EclipseSource 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
********************************************************************************/
/** @jsx svg */
const sprotty_1 = require("@eclipse-glsp/sprotty");
const inversify_1 = require("inversify");
const argument_utils_1 = require("../utils/argument-utils");
const rounded_corner_1 = require("./rounded-corner");
let RoundedCornerNodeView = class RoundedCornerNodeView extends sprotty_1.RectangularNodeView {
render(node, context) {
if (!this.isVisible(node, context)) {
return undefined;
}
const cornerRadius = argument_utils_1.CornerRadius.from(node);
if (!cornerRadius) {
return this.renderWithoutRadius(node, context);
}
const wrapper = new rounded_corner_1.RoundedCornerWrapper(node, cornerRadius);
return ((0, sprotty_1.svg)("g", { "class-node": true },
(0, sprotty_1.svg)("defs", null,
(0, sprotty_1.svg)("clipPath", { id: toClipPathId(node) },
(0, sprotty_1.svg)("path", { d: this.renderPath(wrapper, context, this.getClipPathInsets() || 0) }))),
this.renderPathNode(wrapper, context),
context.renderChildren(node)));
}
renderWithoutRadius(node, context) {
return super.render(node, context);
}
getClipPathInsets() {
return 2;
}
renderPathNode(wrapper, context) {
return ((0, sprotty_1.svg)("path", { d: this.renderPath(wrapper, context, 0), "class-sprotty-node": wrapper.element instanceof sprotty_1.GNode, "class-sprotty-port": wrapper.element instanceof sprotty_1.GPort, "class-mouseover": wrapper.element.hoverFeedback, "class-selected": wrapper.element.selected, ...this.additionalClasses(wrapper.element, context) }));
}
additionalClasses(_node, _context) {
return {};
}
renderPath(wrapper, _context, inset) {
// Calculate length of straight line segments
const topLineLength = Math.max(0, wrapper.size.width - wrapper.cornerRadius.topLeft - wrapper.cornerRadius.topRight);
const rightLineLength = Math.max(0, wrapper.size.height - wrapper.cornerRadius.topRight - wrapper.cornerRadius.bottomRight);
const bottomLineLength = Math.max(0, wrapper.size.width - wrapper.cornerRadius.bottomLeft - wrapper.cornerRadius.bottomRight);
const path = `M${0 + inset},${0 + wrapper.topLeftCorner.radiusY}` +
`q${0},${-(wrapper.topLeftCorner.radiusY - inset)} ${wrapper.topLeftCorner.radiusX - inset},${-(wrapper.topLeftCorner.radiusY - inset)}` +
`h${topLineLength}` +
`q${wrapper.topRightCorner.radiusX - inset},0 ${wrapper.topRightCorner.radiusX - inset},${wrapper.topRightCorner.radiusY - inset}` +
`v${rightLineLength}` +
`q0,${wrapper.bottomRightCorner.radiusY - inset} ${-(wrapper.bottomRightCorner.radiusX - inset)},${wrapper.bottomRightCorner.radiusY - inset}` +
`h${-bottomLineLength}` +
`q${-(wrapper.bottomLeftCorner.radiusX - inset)},0 ${-(wrapper.bottomLeftCorner.radiusX - inset)},${-(wrapper.bottomLeftCorner.radiusY - inset)}` +
'z ';
return path;
}
};
exports.RoundedCornerNodeView = RoundedCornerNodeView;
exports.RoundedCornerNodeView = RoundedCornerNodeView = __decorate([
(0, inversify_1.injectable)()
], RoundedCornerNodeView);
function toClipPathId(node) {
return `${node.id}_clip_path`;
}
//# sourceMappingURL=rounded-corner-view.js.map