Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type { KonvaNode, WorkingArea } from "./types";
import { MIN_SIZE } from "../../../tools/Base";
 
export const getNodeAbsoluteDimensions = (node: KonvaNode, workingArea: WorkingArea) => {
  const { realWidth: width, realHeight: height } = workingArea;
 
  const result = {
    x: (node.x() / width) * 100,
    y: (node.y() / height) * 100,
    width: (node.width() / width) * 100,
    height: (node.height() / height) * 100,
    rotation: node.rotation(),
  };
 
  return result;
};
 
export const normalizeNodeDimentions = <T extends KonvaNode>(node: T, shapeType: "rect") => {
  const scaleX = node.scaleX();
  const scaleY = node.scaleY();
 
  switch (shapeType) {
    case "rect": {
      node.width(Math.max(MIN_SIZE.X, node.width() * scaleX));
      node.height(Math.max(MIN_SIZE.Y, node.height() * scaleY));
      break;
    }
  }
 
  node.scaleX(1);
  node.scaleY(1);
};