@kieler/klighd-core
Version:
Core KLighD diagram visualization with Sprotty
76 lines • 3.88 kB
JavaScript
;
/*
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2021-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
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.KlighdSvgExporter = void 0;
const inversify_1 = require("inversify");
const sprotty_1 = require("sprotty");
const actions_1 = require("./actions/actions");
/* global document, Document, Element */
let KlighdSvgExporter = class KlighdSvgExporter extends sprotty_1.SvgExporter {
export(root, request) {
var _a;
// Same as Sprotty's SvgExporter.export, but with KlighdExportSvgAction instead of
// ExportSvgAction to have a better default export name based on the root ID (its model URI).
if (typeof document !== 'undefined') {
const hiddenDiv = document.getElementById(this.options.hiddenDiv);
if (hiddenDiv === null) {
this.log.warn(this, `Element with id ${this.options.hiddenDiv} not found. Nothing to export.`);
return;
}
const svgElement = hiddenDiv.querySelector('svg');
if (svgElement === null) {
this.log.warn(this, `No svg element found in ${this.options.hiddenDiv} div. Nothing to export.`);
return;
}
const svg = this.createSvg(svgElement, root, (_a = request === null || request === void 0 ? void 0 : request.options) !== null && _a !== void 0 ? _a : {}, request);
this.actionDispatcher.dispatch(actions_1.KlighdExportSvgAction.create(svg, request ? request.requestId : '', root.id, request === null || request === void 0 ? void 0 : request.options));
}
}
copyStyles(_source, _target, _skippedProperties) {
// Just don't copy the styles. This would overwrite any styles set by the SVG renderer and we do not need any other styles that may get copied here.
// So overwrite Sprotty's copyStyles method with an empty method.
}
getBounds(root, document) {
const svgElement = document.querySelector('svg');
if (svgElement) {
// Get the actual bounding box of the SVG element, including the stroke width.
// should use { stroke: true } argument here, but it's not supported in chromium.
const box = svgElement.getBBox();
// Instead, remove the x/y offset and assume that the diagram is at 0/0 and that the offset on the other side is the same.
const xOffset = box.x;
const yOffset = box.y;
box.x = 0;
box.y = 0;
box.width += xOffset * 2;
box.height += yOffset * 2;
return box;
}
return super.getBounds(root, document);
}
};
exports.KlighdSvgExporter = KlighdSvgExporter;
exports.KlighdSvgExporter = KlighdSvgExporter = __decorate([
(0, inversify_1.injectable)()
], KlighdSvgExporter);
//# sourceMappingURL=klighd-svg-exporter.js.map