import { CanvasElement, DefaultEditTypes } from "@hylimo/diagram-common"; import type { IncrementalUpdate, ResizeEdit } from "@hylimo/diagram-protocol"; import type { EditHandler } from "./editHandler.js"; import { SharedSettings } from "@hylimo/diagram-protocol"; /** * Handler for resize height edits */ export const resizeHeight: EditHandler = { type: DefaultEditTypes.RESIZE_HEIGHT, predictActionDiff(lastApplied, newest, elements) { const updates: IncrementalUpdate[] = []; for (const element of elements) { if (CanvasElement.isCanvasElement(element) && element.height !== 0) { updates.push({ target: element.id, changes: { height: newest.height, // scale the relative y position according to the new height dy: (newest.height! / element.height) * element.dy } }); } } return updates; }, transformEdit(edit, config) { const { height, dh } = edit.values; edit.values.dh = SharedSettings.roundToResizePrecision(config.settings, dh!); edit.values.height = height! - (dh! - edit.values.dh); } };