UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

60 lines 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DiagramMovementCalculator = exports.MovementCalculator = 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 ********************************************************************************/ const sprotty_1 = require("@eclipse-glsp/sprotty"); class MovementCalculator { setPosition(position) { this.position = { ...position }; } updatePosition(param) { var _a; const vector = sprotty_1.Vector.is(param) ? param : param.vector; this.setPosition(sprotty_1.Point.add((_a = this.position) !== null && _a !== void 0 ? _a : sprotty_1.Point.ORIGIN, vector)); } get hasPosition() { return this.position !== undefined; } calculateMoveTo(targetPosition) { return !this.position ? sprotty_1.Movement.ZERO : sprotty_1.Point.move(this.position, targetPosition); } dispose() { this.position = undefined; } } exports.MovementCalculator = MovementCalculator; class DiagramMovementCalculator extends MovementCalculator { constructor(positionTracker) { super(); this.positionTracker = positionTracker; } init() { const position = this.positionTracker.lastPositionOnDiagram; if (position) { this.setPosition(position); } } calculateMoveToCurrent() { const targetPosition = this.positionTracker.lastPositionOnDiagram; return targetPosition ? this.calculateMoveTo(targetPosition) : sprotty_1.Movement.ZERO; } reset() { this.dispose(); } } exports.DiagramMovementCalculator = DiagramMovementCalculator; //# sourceMappingURL=tracker.js.map