@zag-js/rect-utils 1.47.0 → 1.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.js +11 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.mjs +11 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.mjs +13 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.js +8 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.mjs +8 -0
  7. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.js +15 -0
  8. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.mjs +10 -0
  9. package/dist/affine-transform.d.mts +36 -39
  10. package/dist/affine-transform.d.ts +36 -39
  11. package/dist/affine-transform.js +189 -187
  12. package/dist/affine-transform.mjs +185 -164
  13. package/dist/align.d.mts +2 -5
  14. package/dist/align.d.ts +2 -5
  15. package/dist/align.js +27 -44
  16. package/dist/align.mjs +23 -21
  17. package/dist/angle.d.mts +2 -5
  18. package/dist/angle.d.ts +2 -5
  19. package/dist/angle.js +8 -32
  20. package/dist/angle.mjs +4 -9
  21. package/dist/clamp.d.mts +8 -11
  22. package/dist/clamp.d.ts +8 -11
  23. package/dist/clamp.js +23 -46
  24. package/dist/clamp.mjs +18 -22
  25. package/dist/closest.d.mts +4 -7
  26. package/dist/closest.d.ts +4 -7
  27. package/dist/closest.js +35 -62
  28. package/dist/closest.mjs +29 -37
  29. package/dist/compass.d.mts +4 -7
  30. package/dist/compass.d.ts +4 -7
  31. package/dist/compass.js +48 -48
  32. package/dist/compass.mjs +43 -24
  33. package/dist/constrain.d.mts +2 -5
  34. package/dist/constrain.d.ts +2 -5
  35. package/dist/constrain.js +12 -37
  36. package/dist/constrain.mjs +8 -14
  37. package/dist/contains.d.mts +4 -7
  38. package/dist/contains.d.ts +4 -7
  39. package/dist/contains.js +11 -36
  40. package/dist/contains.mjs +5 -11
  41. package/dist/distance.d.mts +7 -10
  42. package/dist/distance.d.ts +7 -10
  43. package/dist/distance.js +55 -60
  44. package/dist/distance.mjs +48 -34
  45. package/dist/equality.d.mts +4 -7
  46. package/dist/equality.d.ts +4 -7
  47. package/dist/equality.js +13 -38
  48. package/dist/equality.mjs +7 -13
  49. package/dist/from-element.d.mts +12 -15
  50. package/dist/from-element.d.ts +12 -15
  51. package/dist/from-element.js +39 -58
  52. package/dist/from-element.mjs +35 -35
  53. package/dist/from-points.d.mts +2 -5
  54. package/dist/from-points.d.ts +2 -5
  55. package/dist/from-points.js +18 -36
  56. package/dist/from-points.mjs +14 -13
  57. package/dist/from-range.d.mts +2 -5
  58. package/dist/from-range.d.ts +2 -5
  59. package/dist/from-range.js +25 -46
  60. package/dist/from-range.mjs +19 -21
  61. package/dist/from-rotation.d.mts +4 -7
  62. package/dist/from-rotation.d.ts +4 -7
  63. package/dist/from-rotation.js +31 -56
  64. package/dist/from-rotation.mjs +25 -31
  65. package/dist/from-window.d.mts +13 -16
  66. package/dist/from-window.d.ts +13 -16
  67. package/dist/from-window.js +29 -44
  68. package/dist/from-window.mjs +24 -20
  69. package/dist/index.d.mts +22 -22
  70. package/dist/index.d.ts +22 -22
  71. package/dist/index.js +72 -63
  72. package/dist/index.mjs +21 -22
  73. package/dist/intersection.d.mts +4 -7
  74. package/dist/intersection.d.ts +4 -7
  75. package/dist/intersection.js +34 -45
  76. package/dist/intersection.mjs +28 -20
  77. package/dist/operations.d.mts +6 -9
  78. package/dist/operations.d.ts +6 -9
  79. package/dist/operations.js +38 -57
  80. package/dist/operations.mjs +30 -30
  81. package/dist/polygon.d.mts +6 -9
  82. package/dist/polygon.d.ts +6 -9
  83. package/dist/polygon.js +73 -82
  84. package/dist/polygon.mjs +67 -57
  85. package/dist/rect.d.mts +49 -52
  86. package/dist/rect.d.ts +49 -52
  87. package/dist/rect.js +57 -82
  88. package/dist/rect.mjs +46 -52
  89. package/dist/resize.d.mts +3 -6
  90. package/dist/resize.d.ts +3 -6
  91. package/dist/resize.js +73 -102
  92. package/dist/resize.mjs +68 -78
  93. package/dist/types.d.mts +45 -49
  94. package/dist/types.d.ts +45 -49
  95. package/dist/types.js +4 -18
  96. package/dist/types.mjs +1 -0
  97. package/dist/union.d.mts +2 -5
  98. package/dist/union.d.ts +2 -5
  99. package/dist/union.js +16 -39
  100. package/dist/union.mjs +12 -16
  101. package/package.json +3 -3
  102. package/dist/chunk-QZ7TP4HQ.mjs +0 -7
package/dist/rect.d.ts CHANGED
@@ -1,58 +1,55 @@
1
- import { Point, RectInit, Rect, RectEdge } from './types.js';
2
-
3
- declare const createPoint: (x: number, y: number) => {
1
+ import { Point, Rect, RectEdge, RectInit } from "./types.js";
2
+ export declare const createPoint: (x: number, y: number) => {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ export declare const subtractPoints: (a: Point, b: Point | null) => Point;
7
+ export declare const addPoints: (a: Point, b: Point) => {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ export declare function isPoint(v: any): v is Point;
12
+ export declare function createRect(r: RectInit): Rect;
13
+ export declare function isRect(v: any): v is Rect;
14
+ export declare function getRectCenters(v: Rect): {
15
+ top: {
4
16
  x: number;
5
17
  y: number;
6
- };
7
- declare const subtractPoints: (a: Point, b: Point | null) => Point;
8
- declare const addPoints: (a: Point, b: Point) => {
18
+ };
19
+ right: {
9
20
  x: number;
10
21
  y: number;
22
+ };
23
+ bottom: {
24
+ x: number;
25
+ y: number;
26
+ };
27
+ left: {
28
+ x: number;
29
+ y: number;
30
+ };
11
31
  };
12
- declare function isPoint(v: any): v is Point;
13
- declare function createRect(r: RectInit): Rect;
14
- declare function isRect(v: any): v is Rect;
15
- declare function getRectCenters(v: Rect): {
16
- top: {
17
- x: number;
18
- y: number;
19
- };
20
- right: {
21
- x: number;
22
- y: number;
23
- };
24
- bottom: {
25
- x: number;
26
- y: number;
27
- };
28
- left: {
29
- x: number;
30
- y: number;
31
- };
32
- };
33
- declare function getRectCorners(v: Rect): {
34
- top: {
35
- x: number;
36
- y: number;
37
- };
38
- right: {
39
- x: number;
40
- y: number;
41
- };
42
- bottom: {
43
- x: number;
44
- y: number;
45
- };
46
- left: {
47
- x: number;
48
- y: number;
49
- };
50
- };
51
- declare function getRectEdges(v: Rect): {
52
- top: RectEdge;
53
- right: RectEdge;
54
- bottom: RectEdge;
55
- left: RectEdge;
32
+ export declare function getRectCorners(v: Rect): {
33
+ top: {
34
+ x: number;
35
+ y: number;
36
+ };
37
+ right: {
38
+ x: number;
39
+ y: number;
40
+ };
41
+ bottom: {
42
+ x: number;
43
+ y: number;
44
+ };
45
+ left: {
46
+ x: number;
47
+ y: number;
48
+ };
56
49
  };
57
-
58
- export { addPoints, createPoint, createRect, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, subtractPoints };
50
+ export declare function getRectEdges(v: Rect): {
51
+ top: RectEdge;
52
+ right: RectEdge;
53
+ bottom: RectEdge;
54
+ left: RectEdge;
55
+ };
package/dist/rect.js CHANGED
@@ -1,97 +1,72 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
20
5
  // src/rect.ts
21
- var rect_exports = {};
22
- __export(rect_exports, {
23
- addPoints: () => addPoints,
24
- createPoint: () => createPoint,
25
- createRect: () => createRect,
26
- getRectCenters: () => getRectCenters,
27
- getRectCorners: () => getRectCorners,
28
- getRectEdges: () => getRectEdges,
29
- isPoint: () => isPoint,
30
- isRect: () => isRect,
31
- subtractPoints: () => subtractPoints
6
+ const createPoint = (x, y) => ({
7
+ x,
8
+ y
32
9
  });
33
- module.exports = __toCommonJS(rect_exports);
34
- var createPoint = (x, y) => ({ x, y });
35
- var subtractPoints = (a, b) => {
36
- if (!b) return a;
37
- return createPoint(a.x - b.x, a.y - b.y);
10
+ const subtractPoints = (a, b) => {
11
+ if (!b) return a;
12
+ return createPoint(a.x - b.x, a.y - b.y);
38
13
  };
39
- var addPoints = (a, b) => createPoint(a.x + b.x, a.y + b.y);
14
+ const addPoints = (a, b) => createPoint(a.x + b.x, a.y + b.y);
40
15
  function isPoint(v) {
41
- return Reflect.has(v, "x") && Reflect.has(v, "y");
16
+ return Reflect.has(v, "x") && Reflect.has(v, "y");
42
17
  }
43
18
  function createRect(r) {
44
- const { x, y, width, height } = r;
45
- const midX = x + width / 2;
46
- const midY = y + height / 2;
47
- return {
48
- x,
49
- y,
50
- width,
51
- height,
52
- minX: x,
53
- minY: y,
54
- maxX: x + width,
55
- maxY: y + height,
56
- midX,
57
- midY,
58
- center: createPoint(midX, midY)
59
- };
19
+ const { x, y, width, height } = r;
20
+ const midX = x + width / 2;
21
+ const midY = y + height / 2;
22
+ return {
23
+ x,
24
+ y,
25
+ width,
26
+ height,
27
+ minX: x,
28
+ minY: y,
29
+ maxX: x + width,
30
+ maxY: y + height,
31
+ midX,
32
+ midY,
33
+ center: createPoint(midX, midY)
34
+ };
60
35
  }
61
36
  function isRect(v) {
62
- return Reflect.has(v, "x") && Reflect.has(v, "y") && Reflect.has(v, "width") && Reflect.has(v, "height");
37
+ return Reflect.has(v, "x") && Reflect.has(v, "y") && Reflect.has(v, "width") && Reflect.has(v, "height");
63
38
  }
64
39
  function getRectCenters(v) {
65
- const top = createPoint(v.midX, v.minY);
66
- const right = createPoint(v.maxX, v.midY);
67
- const bottom = createPoint(v.midX, v.maxY);
68
- const left = createPoint(v.minX, v.midY);
69
- return { top, right, bottom, left };
40
+ return {
41
+ top: createPoint(v.midX, v.minY),
42
+ right: createPoint(v.maxX, v.midY),
43
+ bottom: createPoint(v.midX, v.maxY),
44
+ left: createPoint(v.minX, v.midY)
45
+ };
70
46
  }
71
47
  function getRectCorners(v) {
72
- const top = createPoint(v.minX, v.minY);
73
- const right = createPoint(v.maxX, v.minY);
74
- const bottom = createPoint(v.maxX, v.maxY);
75
- const left = createPoint(v.minX, v.maxY);
76
- return { top, right, bottom, left };
48
+ return {
49
+ top: createPoint(v.minX, v.minY),
50
+ right: createPoint(v.maxX, v.minY),
51
+ bottom: createPoint(v.maxX, v.maxY),
52
+ left: createPoint(v.minX, v.maxY)
53
+ };
77
54
  }
78
55
  function getRectEdges(v) {
79
- const c = getRectCorners(v);
80
- const top = [c.top, c.right];
81
- const right = [c.right, c.bottom];
82
- const bottom = [c.left, c.bottom];
83
- const left = [c.top, c.left];
84
- return { top, right, bottom, left };
56
+ const c = getRectCorners(v);
57
+ return {
58
+ top: [c.top, c.right],
59
+ right: [c.right, c.bottom],
60
+ bottom: [c.left, c.bottom],
61
+ left: [c.top, c.left]
62
+ };
85
63
  }
86
- // Annotate the CommonJS export names for ESM import in node:
87
- 0 && (module.exports = {
88
- addPoints,
89
- createPoint,
90
- createRect,
91
- getRectCenters,
92
- getRectCorners,
93
- getRectEdges,
94
- isPoint,
95
- isRect,
96
- subtractPoints
97
- });
64
+ exports.addPoints = addPoints;
65
+ exports.createPoint = createPoint;
66
+ exports.createRect = createRect;
67
+ exports.getRectCenters = getRectCenters;
68
+ exports.getRectCorners = getRectCorners;
69
+ exports.getRectEdges = getRectEdges;
70
+ exports.isPoint = isPoint;
71
+ exports.isRect = isRect;
72
+ exports.subtractPoints = subtractPoints;
package/dist/rect.mjs CHANGED
@@ -1,66 +1,60 @@
1
- import "./chunk-QZ7TP4HQ.mjs";
2
-
3
1
  // src/rect.ts
4
- var createPoint = (x, y) => ({ x, y });
5
- var subtractPoints = (a, b) => {
6
- if (!b) return a;
7
- return createPoint(a.x - b.x, a.y - b.y);
2
+ const createPoint = (x, y) => ({
3
+ x,
4
+ y
5
+ });
6
+ const subtractPoints = (a, b) => {
7
+ if (!b) return a;
8
+ return createPoint(a.x - b.x, a.y - b.y);
8
9
  };
9
- var addPoints = (a, b) => createPoint(a.x + b.x, a.y + b.y);
10
+ const addPoints = (a, b) => createPoint(a.x + b.x, a.y + b.y);
10
11
  function isPoint(v) {
11
- return Reflect.has(v, "x") && Reflect.has(v, "y");
12
+ return Reflect.has(v, "x") && Reflect.has(v, "y");
12
13
  }
13
14
  function createRect(r) {
14
- const { x, y, width, height } = r;
15
- const midX = x + width / 2;
16
- const midY = y + height / 2;
17
- return {
18
- x,
19
- y,
20
- width,
21
- height,
22
- minX: x,
23
- minY: y,
24
- maxX: x + width,
25
- maxY: y + height,
26
- midX,
27
- midY,
28
- center: createPoint(midX, midY)
29
- };
15
+ const { x, y, width, height } = r;
16
+ const midX = x + width / 2;
17
+ const midY = y + height / 2;
18
+ return {
19
+ x,
20
+ y,
21
+ width,
22
+ height,
23
+ minX: x,
24
+ minY: y,
25
+ maxX: x + width,
26
+ maxY: y + height,
27
+ midX,
28
+ midY,
29
+ center: createPoint(midX, midY)
30
+ };
30
31
  }
31
32
  function isRect(v) {
32
- return Reflect.has(v, "x") && Reflect.has(v, "y") && Reflect.has(v, "width") && Reflect.has(v, "height");
33
+ return Reflect.has(v, "x") && Reflect.has(v, "y") && Reflect.has(v, "width") && Reflect.has(v, "height");
33
34
  }
34
35
  function getRectCenters(v) {
35
- const top = createPoint(v.midX, v.minY);
36
- const right = createPoint(v.maxX, v.midY);
37
- const bottom = createPoint(v.midX, v.maxY);
38
- const left = createPoint(v.minX, v.midY);
39
- return { top, right, bottom, left };
36
+ return {
37
+ top: createPoint(v.midX, v.minY),
38
+ right: createPoint(v.maxX, v.midY),
39
+ bottom: createPoint(v.midX, v.maxY),
40
+ left: createPoint(v.minX, v.midY)
41
+ };
40
42
  }
41
43
  function getRectCorners(v) {
42
- const top = createPoint(v.minX, v.minY);
43
- const right = createPoint(v.maxX, v.minY);
44
- const bottom = createPoint(v.maxX, v.maxY);
45
- const left = createPoint(v.minX, v.maxY);
46
- return { top, right, bottom, left };
44
+ return {
45
+ top: createPoint(v.minX, v.minY),
46
+ right: createPoint(v.maxX, v.minY),
47
+ bottom: createPoint(v.maxX, v.maxY),
48
+ left: createPoint(v.minX, v.maxY)
49
+ };
47
50
  }
48
51
  function getRectEdges(v) {
49
- const c = getRectCorners(v);
50
- const top = [c.top, c.right];
51
- const right = [c.right, c.bottom];
52
- const bottom = [c.left, c.bottom];
53
- const left = [c.top, c.left];
54
- return { top, right, bottom, left };
52
+ const c = getRectCorners(v);
53
+ return {
54
+ top: [c.top, c.right],
55
+ right: [c.right, c.bottom],
56
+ bottom: [c.left, c.bottom],
57
+ left: [c.top, c.left]
58
+ };
55
59
  }
56
- export {
57
- addPoints,
58
- createPoint,
59
- createRect,
60
- getRectCenters,
61
- getRectCorners,
62
- getRectEdges,
63
- isPoint,
64
- isRect,
65
- subtractPoints
66
- };
60
+ export { addPoints, createPoint, createRect, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, subtractPoints };
package/dist/resize.d.mts CHANGED
@@ -1,6 +1,3 @@
1
- import { CompassDirection } from './compass.mjs';
2
- import { Rect, Point, ScalingOptions, RectInit } from './types.mjs';
3
-
4
- declare function resizeRect(rect: Rect, offset: Point, direction: CompassDirection, opts: ScalingOptions): RectInit;
5
-
6
- export { resizeRect };
1
+ import { CompassDirection } from "./compass.mjs";
2
+ import { Point, Rect, RectInit, ScalingOptions } from "./types.mjs";
3
+ export declare function resizeRect(rect: Rect, offset: Point, direction: CompassDirection, opts: ScalingOptions): RectInit;
package/dist/resize.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { CompassDirection } from './compass.js';
2
- import { Rect, Point, ScalingOptions, RectInit } from './types.js';
3
-
4
- declare function resizeRect(rect: Rect, offset: Point, direction: CompassDirection, opts: ScalingOptions): RectInit;
5
-
6
- export { resizeRect };
1
+ import { CompassDirection } from "./compass.js";
2
+ import { Point, Rect, RectInit, ScalingOptions } from "./types.js";
3
+ export declare function resizeRect(rect: Rect, offset: Point, direction: CompassDirection, opts: ScalingOptions): RectInit;
package/dist/resize.js CHANGED
@@ -1,113 +1,84 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/resize.ts
21
- var resize_exports = {};
22
- __export(resize_exports, {
23
- resizeRect: () => resizeRect
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
24
4
  });
25
- module.exports = __toCommonJS(resize_exports);
26
- var import_affine_transform = require("./affine-transform.js");
27
- var import_compass = require("./compass.js");
28
- var { sign, abs, min } = Math;
5
+ const require_affine_transform = require("./affine-transform.js");
6
+ const require_compass = require("./compass.js");
7
+ // src/resize.ts
8
+ const { sign, abs, min } = Math;
29
9
  function getRectExtentPoint(rect, direction) {
30
- const { minX, minY, maxX, maxY, midX, midY } = rect;
31
- const x = direction.includes("w") ? minX : direction.includes("e") ? maxX : midX;
32
- const y = direction.includes("n") ? minY : direction.includes("s") ? maxY : midY;
33
- return { x, y };
10
+ const { minX, minY, maxX, maxY, midX, midY } = rect;
11
+ return {
12
+ x: direction.includes("w") ? minX : direction.includes("e") ? maxX : midX,
13
+ y: direction.includes("n") ? minY : direction.includes("s") ? maxY : midY
14
+ };
34
15
  }
35
16
  function getOppositeDirection(direction) {
36
- return import_compass.oppositeDirectionMap[direction];
17
+ return require_compass.oppositeDirectionMap[direction];
37
18
  }
38
19
  function resizeRect(rect, offset, direction, opts) {
39
- const { scalingOriginMode, lockAspectRatio } = opts;
40
- const extent = getRectExtentPoint(rect, direction);
41
- const oppositeDirection = getOppositeDirection(direction);
42
- const oppositeExtent = getRectExtentPoint(rect, oppositeDirection);
43
- if (scalingOriginMode === "center") {
44
- offset = { x: offset.x * 2, y: offset.y * 2 };
45
- }
46
- const newExtent = {
47
- x: extent.x + offset.x,
48
- y: extent.y + offset.y
49
- };
50
- const multiplier = {
51
- x: import_compass.compassDirectionMap[direction].x * 2 - 1,
52
- y: import_compass.compassDirectionMap[direction].y * 2 - 1
53
- };
54
- const newSize = {
55
- width: newExtent.x - oppositeExtent.x,
56
- height: newExtent.y - oppositeExtent.y
57
- };
58
- const scaleX = multiplier.x * newSize.width / rect.width;
59
- const scaleY = multiplier.y * newSize.height / rect.height;
60
- const largestMagnitude = abs(scaleX) > abs(scaleY) ? scaleX : scaleY;
61
- const scale = lockAspectRatio ? { x: largestMagnitude, y: largestMagnitude } : {
62
- x: extent.x === oppositeExtent.x ? 1 : scaleX,
63
- y: extent.y === oppositeExtent.y ? 1 : scaleY
64
- };
65
- if (extent.y === oppositeExtent.y) {
66
- scale.y = abs(scale.y);
67
- } else if (sign(scale.y) !== sign(scaleY)) {
68
- scale.y *= -1;
69
- }
70
- if (extent.x === oppositeExtent.x) {
71
- scale.x = abs(scale.x);
72
- } else if (sign(scale.x) !== sign(scaleX)) {
73
- scale.x *= -1;
74
- }
75
- switch (scalingOriginMode) {
76
- case "extent":
77
- return transformRect(rect, import_affine_transform.AffineTransform.scale(scale.x, scale.y, oppositeExtent), false);
78
- case "center":
79
- return transformRect(
80
- rect,
81
- import_affine_transform.AffineTransform.scale(scale.x, scale.y, {
82
- x: rect.midX,
83
- y: rect.midY
84
- }),
85
- false
86
- );
87
- }
20
+ const { scalingOriginMode, lockAspectRatio } = opts;
21
+ const extent = getRectExtentPoint(rect, direction);
22
+ const oppositeExtent = getRectExtentPoint(rect, getOppositeDirection(direction));
23
+ if (scalingOriginMode === "center") offset = {
24
+ x: offset.x * 2,
25
+ y: offset.y * 2
26
+ };
27
+ const newExtent = {
28
+ x: extent.x + offset.x,
29
+ y: extent.y + offset.y
30
+ };
31
+ const multiplier = {
32
+ x: require_compass.compassDirectionMap[direction].x * 2 - 1,
33
+ y: require_compass.compassDirectionMap[direction].y * 2 - 1
34
+ };
35
+ const newSize = {
36
+ width: newExtent.x - oppositeExtent.x,
37
+ height: newExtent.y - oppositeExtent.y
38
+ };
39
+ const scaleX = multiplier.x * newSize.width / rect.width;
40
+ const scaleY = multiplier.y * newSize.height / rect.height;
41
+ const largestMagnitude = abs(scaleX) > abs(scaleY) ? scaleX : scaleY;
42
+ const scale = lockAspectRatio ? {
43
+ x: largestMagnitude,
44
+ y: largestMagnitude
45
+ } : {
46
+ x: extent.x === oppositeExtent.x ? 1 : scaleX,
47
+ y: extent.y === oppositeExtent.y ? 1 : scaleY
48
+ };
49
+ if (extent.y === oppositeExtent.y) scale.y = abs(scale.y);
50
+ else if (sign(scale.y) !== sign(scaleY)) scale.y *= -1;
51
+ if (extent.x === oppositeExtent.x) scale.x = abs(scale.x);
52
+ else if (sign(scale.x) !== sign(scaleX)) scale.x *= -1;
53
+ switch (scalingOriginMode) {
54
+ case "extent": return transformRect(rect, require_affine_transform.AffineTransform.scale(scale.x, scale.y, oppositeExtent), false);
55
+ case "center": return transformRect(rect, require_affine_transform.AffineTransform.scale(scale.x, scale.y, {
56
+ x: rect.midX,
57
+ y: rect.midY
58
+ }), false);
59
+ }
88
60
  }
89
61
  function createRectFromPoints(initialPoint, finalPoint, normalized = true) {
90
- if (normalized) {
91
- return {
92
- x: min(finalPoint.x, initialPoint.x),
93
- y: min(finalPoint.y, initialPoint.y),
94
- width: abs(finalPoint.x - initialPoint.x),
95
- height: abs(finalPoint.y - initialPoint.y)
96
- };
97
- }
98
- return {
99
- x: initialPoint.x,
100
- y: initialPoint.y,
101
- width: finalPoint.x - initialPoint.x,
102
- height: finalPoint.y - initialPoint.y
103
- };
62
+ if (normalized) return {
63
+ x: min(finalPoint.x, initialPoint.x),
64
+ y: min(finalPoint.y, initialPoint.y),
65
+ width: abs(finalPoint.x - initialPoint.x),
66
+ height: abs(finalPoint.y - initialPoint.y)
67
+ };
68
+ return {
69
+ x: initialPoint.x,
70
+ y: initialPoint.y,
71
+ width: finalPoint.x - initialPoint.x,
72
+ height: finalPoint.y - initialPoint.y
73
+ };
104
74
  }
105
75
  function transformRect(rect, transform, normalized = true) {
106
- const p1 = transform.applyTo({ x: rect.minX, y: rect.minY });
107
- const p2 = transform.applyTo({ x: rect.maxX, y: rect.maxY });
108
- return createRectFromPoints(p1, p2, normalized);
76
+ return createRectFromPoints(transform.applyTo({
77
+ x: rect.minX,
78
+ y: rect.minY
79
+ }), transform.applyTo({
80
+ x: rect.maxX,
81
+ y: rect.maxY
82
+ }), normalized);
109
83
  }
110
- // Annotate the CommonJS export names for ESM import in node:
111
- 0 && (module.exports = {
112
- resizeRect
113
- });
84
+ exports.resizeRect = resizeRect;