@tscircuit/math-utils 0.0.11 → 0.0.13
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.
- package/dist/chunk-K7F26NYD.js +98 -0
- package/dist/chunk-K7F26NYD.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -7
- package/dist/segment-distance.d.ts +26 -1
- package/dist/segment-distance.js +8 -1
- package/package.json +1 -1
- package/dist/chunk-6C2XJHEO.js +0 -29
- package/dist/chunk-6C2XJHEO.js.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
distance,
|
|
3
|
+
doSegmentsIntersect,
|
|
4
|
+
pointToSegmentDistance
|
|
5
|
+
} from "./chunk-CHQOCSFB.js";
|
|
6
|
+
import {
|
|
7
|
+
clamp
|
|
8
|
+
} from "./chunk-MHHTZHOJ.js";
|
|
9
|
+
|
|
10
|
+
// src/segment-distance.ts
|
|
11
|
+
function segmentToSegmentMinDistance(a, b, u, v) {
|
|
12
|
+
if (a.x === b.x && a.y === b.y) {
|
|
13
|
+
return pointToSegmentDistance(a, u, v);
|
|
14
|
+
}
|
|
15
|
+
if (u.x === v.x && u.y === v.y) {
|
|
16
|
+
return pointToSegmentDistance(u, a, b);
|
|
17
|
+
}
|
|
18
|
+
if (doSegmentsIntersect(a, b, u, v)) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
const distances = [
|
|
22
|
+
pointToSegmentDistance(a, u, v),
|
|
23
|
+
pointToSegmentDistance(b, u, v),
|
|
24
|
+
pointToSegmentDistance(u, a, b),
|
|
25
|
+
pointToSegmentDistance(v, a, b)
|
|
26
|
+
];
|
|
27
|
+
return Math.min(...distances);
|
|
28
|
+
}
|
|
29
|
+
function segmentToBoundsMinDistance(a, b, bounds) {
|
|
30
|
+
const topLeft = { x: bounds.minX, y: bounds.minY };
|
|
31
|
+
const topRight = { x: bounds.maxX, y: bounds.minY };
|
|
32
|
+
const bottomLeft = { x: bounds.minX, y: bounds.maxY };
|
|
33
|
+
const bottomRight = { x: bounds.maxX, y: bounds.maxY };
|
|
34
|
+
if (doSegmentsIntersect(a, b, topLeft, topRight) || doSegmentsIntersect(a, b, topRight, bottomRight) || doSegmentsIntersect(a, b, bottomRight, bottomLeft) || doSegmentsIntersect(a, b, bottomLeft, topLeft)) {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
if (a.x >= bounds.minX && a.x <= bounds.maxX && a.y >= bounds.minY && a.y <= bounds.maxY && b.x >= bounds.minX && b.x <= bounds.maxX && b.y >= bounds.minY && b.y <= bounds.maxY) {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
const distances = [
|
|
41
|
+
pointToSegmentDistance(topLeft, a, b),
|
|
42
|
+
pointToSegmentDistance(topRight, a, b),
|
|
43
|
+
pointToSegmentDistance(bottomLeft, a, b),
|
|
44
|
+
pointToSegmentDistance(bottomRight, a, b)
|
|
45
|
+
];
|
|
46
|
+
if (a.x >= bounds.minX && a.x <= bounds.maxX && a.y >= bounds.minY && a.y <= bounds.maxY) {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
if (b.x >= bounds.minX && b.x <= bounds.maxX && b.y >= bounds.minY && b.y <= bounds.maxY) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
if (a.x < bounds.minX || a.x > bounds.maxX || a.y < bounds.minY || a.y > bounds.maxY) {
|
|
53
|
+
const closestX = clamp(a.x, bounds.minX, bounds.maxX);
|
|
54
|
+
const closestY = clamp(a.y, bounds.minY, bounds.maxY);
|
|
55
|
+
distances.push(distance(a, { x: closestX, y: closestY }));
|
|
56
|
+
}
|
|
57
|
+
if (b.x < bounds.minX || b.x > bounds.maxX || b.y < bounds.minY || b.y > bounds.maxY) {
|
|
58
|
+
const closestX = clamp(b.x, bounds.minX, bounds.maxX);
|
|
59
|
+
const closestY = clamp(b.y, bounds.minY, bounds.maxY);
|
|
60
|
+
distances.push(distance(b, { x: closestX, y: closestY }));
|
|
61
|
+
}
|
|
62
|
+
return Math.min(...distances);
|
|
63
|
+
}
|
|
64
|
+
function segmentToBoxMinDistance(a, b, box) {
|
|
65
|
+
const halfWidth = box.width / 2;
|
|
66
|
+
const halfHeight = box.height / 2;
|
|
67
|
+
const bounds = {
|
|
68
|
+
minX: box.center.x - halfWidth,
|
|
69
|
+
maxX: box.center.x + halfWidth,
|
|
70
|
+
minY: box.center.y - halfHeight,
|
|
71
|
+
maxY: box.center.y + halfHeight
|
|
72
|
+
};
|
|
73
|
+
return segmentToBoundsMinDistance(a, b, bounds);
|
|
74
|
+
}
|
|
75
|
+
function segmentToCircleMinDistance(a, b, circle) {
|
|
76
|
+
const circleCenter = { x: circle.x, y: circle.y };
|
|
77
|
+
if (a.x === b.x && a.y === b.y) {
|
|
78
|
+
return Math.max(0, distance(a, circleCenter) - circle.radius);
|
|
79
|
+
}
|
|
80
|
+
const ab = { x: b.x - a.x, y: b.y - a.y };
|
|
81
|
+
const ac = { x: circleCenter.x - a.x, y: circleCenter.y - a.y };
|
|
82
|
+
const abLengthSq = ab.x * ab.x + ab.y * ab.y;
|
|
83
|
+
const t = Math.max(0, Math.min(1, (ab.x * ac.x + ab.y * ac.y) / abLengthSq));
|
|
84
|
+
const closestPoint = {
|
|
85
|
+
x: a.x + t * ab.x,
|
|
86
|
+
y: a.y + t * ab.y
|
|
87
|
+
};
|
|
88
|
+
const distToCenter = distance(closestPoint, circleCenter);
|
|
89
|
+
return Math.max(0, distToCenter - circle.radius);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
segmentToSegmentMinDistance,
|
|
94
|
+
segmentToBoundsMinDistance,
|
|
95
|
+
segmentToBoxMinDistance,
|
|
96
|
+
segmentToCircleMinDistance
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=chunk-K7F26NYD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/segment-distance.ts"],"sourcesContent":["import type { Point } from \"./common\"\nimport {\n distance,\n doSegmentsIntersect,\n pointToSegmentDistance,\n} from \"./line-intersections\"\nimport { clamp } from \"./nearest-box\"\n\n/**\n * Returns the minimum distance between two line segments.\n */\nexport function segmentToSegmentMinDistance(\n a: Point,\n b: Point,\n u: Point,\n v: Point,\n): number {\n // Handle degenerate cases: segments of zero length\n if (a.x === b.x && a.y === b.y) {\n return pointToSegmentDistance(a, u, v)\n }\n if (u.x === v.x && u.y === v.y) {\n return pointToSegmentDistance(u, a, b)\n }\n\n // Check if segments intersect\n if (doSegmentsIntersect(a, b, u, v)) {\n return 0\n }\n\n // Compute the minimum distance between the segments\n const distances = [\n pointToSegmentDistance(a, u, v),\n pointToSegmentDistance(b, u, v),\n pointToSegmentDistance(u, a, b),\n pointToSegmentDistance(v, a, b),\n ]\n\n return Math.min(...distances)\n}\n\n/**\n * Returns the minimum distance from a line segment to a bounding box.\n */\nexport function segmentToBoundsMinDistance(\n a: Point,\n b: Point,\n bounds: { minX: number; minY: number; maxX: number; maxY: number },\n): number {\n // Check if segment intersects with the bounds\n // Create the four edges of the bounds\n const topLeft = { x: bounds.minX, y: bounds.minY }\n const topRight = { x: bounds.maxX, y: bounds.minY }\n const bottomLeft = { x: bounds.minX, y: bounds.maxY }\n const bottomRight = { x: bounds.maxX, y: bounds.maxY }\n\n // Check if segment intersects with any of the bounds edges\n if (\n doSegmentsIntersect(a, b, topLeft, topRight) ||\n doSegmentsIntersect(a, b, topRight, bottomRight) ||\n doSegmentsIntersect(a, b, bottomRight, bottomLeft) ||\n doSegmentsIntersect(a, b, bottomLeft, topLeft)\n ) {\n return 0\n }\n\n // Check if segment is entirely inside the bounds\n if (\n a.x >= bounds.minX &&\n a.x <= bounds.maxX &&\n a.y >= bounds.minY &&\n a.y <= bounds.maxY &&\n b.x >= bounds.minX &&\n b.x <= bounds.maxX &&\n b.y >= bounds.minY &&\n b.y <= bounds.maxY\n ) {\n return 0\n }\n\n // If not intersecting, calculate the minimum distance\n const distances = [\n pointToSegmentDistance(topLeft, a, b),\n pointToSegmentDistance(topRight, a, b),\n pointToSegmentDistance(bottomLeft, a, b),\n pointToSegmentDistance(bottomRight, a, b),\n ]\n\n // If one of the segment endpoints is inside the bounds, we need to consider its distance to the bounds as 0\n if (\n a.x >= bounds.minX &&\n a.x <= bounds.maxX &&\n a.y >= bounds.minY &&\n a.y <= bounds.maxY\n ) {\n return 0\n }\n\n if (\n b.x >= bounds.minX &&\n b.x <= bounds.maxX &&\n b.y >= bounds.minY &&\n b.y <= bounds.maxY\n ) {\n return 0\n }\n\n // Calculate distances from segment endpoints to bounds if outside\n if (\n a.x < bounds.minX ||\n a.x > bounds.maxX ||\n a.y < bounds.minY ||\n a.y > bounds.maxY\n ) {\n const closestX = clamp(a.x, bounds.minX, bounds.maxX)\n const closestY = clamp(a.y, bounds.minY, bounds.maxY)\n distances.push(distance(a, { x: closestX, y: closestY }))\n }\n\n if (\n b.x < bounds.minX ||\n b.x > bounds.maxX ||\n b.y < bounds.minY ||\n b.y > bounds.maxY\n ) {\n const closestX = clamp(b.x, bounds.minX, bounds.maxX)\n const closestY = clamp(b.y, bounds.minY, bounds.maxY)\n distances.push(distance(b, { x: closestX, y: closestY }))\n }\n\n return Math.min(...distances)\n}\n\n/**\n * Returns the minimum distance from a line segment to a box.\n */\nexport function segmentToBoxMinDistance(\n a: Point,\n b: Point,\n box: { center: Point; width: number; height: number },\n): number {\n const halfWidth = box.width / 2\n const halfHeight = box.height / 2\n const bounds = {\n minX: box.center.x - halfWidth,\n maxX: box.center.x + halfWidth,\n minY: box.center.y - halfHeight,\n maxY: box.center.y + halfHeight,\n }\n\n return segmentToBoundsMinDistance(a, b, bounds)\n}\n\n/**\n * Returns the minimum distance from a line segment to a circle.\n */\nexport function segmentToCircleMinDistance(\n a: Point,\n b: Point,\n circle: { x: number; y: number; radius: number },\n): number {\n // Calculate the distance from the circle center to the line segment\n const circleCenter = { x: circle.x, y: circle.y }\n\n // Handle degenerate case: segment of zero length (point to circle)\n if (a.x === b.x && a.y === b.y) {\n return Math.max(0, distance(a, circleCenter) - circle.radius)\n }\n\n // Vector from a to b\n const ab = { x: b.x - a.x, y: b.y - a.y }\n // Vector from a to circle center\n const ac = { x: circleCenter.x - a.x, y: circleCenter.y - a.y }\n\n // Length of segment ab squared\n const abLengthSq = ab.x * ab.x + ab.y * ab.y\n\n // Calculate projection of ac onto ab, normalized by the length of ab\n const t = Math.max(0, Math.min(1, (ab.x * ac.x + ab.y * ac.y) / abLengthSq))\n\n // Find the closest point on the segment to the circle center\n const closestPoint = {\n x: a.x + t * ab.x,\n y: a.y + t * ab.y,\n }\n\n // Calculate distance from closest point to circle center\n const distToCenter = distance(closestPoint, circleCenter)\n\n // Return the distance to the circle (subtract radius from distance to center)\n return Math.max(0, distToCenter - circle.radius)\n}\n"],"mappings":";;;;;;;;;;AAWO,SAAS,4BACd,GACA,GACA,GACA,GACQ;AAER,MAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG;AAC9B,WAAO,uBAAuB,GAAG,GAAG,CAAC;AAAA,EACvC;AACA,MAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG;AAC9B,WAAO,uBAAuB,GAAG,GAAG,CAAC;AAAA,EACvC;AAGA,MAAI,oBAAoB,GAAG,GAAG,GAAG,CAAC,GAAG;AACnC,WAAO;AAAA,EACT;AAGA,QAAM,YAAY;AAAA,IAChB,uBAAuB,GAAG,GAAG,CAAC;AAAA,IAC9B,uBAAuB,GAAG,GAAG,CAAC;AAAA,IAC9B,uBAAuB,GAAG,GAAG,CAAC;AAAA,IAC9B,uBAAuB,GAAG,GAAG,CAAC;AAAA,EAChC;AAEA,SAAO,KAAK,IAAI,GAAG,SAAS;AAC9B;AAKO,SAAS,2BACd,GACA,GACA,QACQ;AAGR,QAAM,UAAU,EAAE,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK;AACjD,QAAM,WAAW,EAAE,GAAG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KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,UAAU,CAAC;AAG3E,QAAM,eAAe;AAAA,IACnB,GAAG,EAAE,IAAI,IAAI,GAAG;AAAA,IAChB,GAAG,EAAE,IAAI,IAAI,GAAG;AAAA,EAClB;AAGA,QAAM,eAAe,SAAS,cAAc,YAAY;AAGxD,SAAO,KAAK,IAAI,GAAG,eAAe,OAAO,MAAM;AACjD;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { Box, BoxSet, GridCell, clamp, computeDistanceBetweenBoxes, findNearestP
|
|
|
3
3
|
export { Point } from './common.js';
|
|
4
4
|
export { getUnitVectorFromDirection, getUnitVectorFromPointAToB } from './get-unit-vector.js';
|
|
5
5
|
export { GridCellPositions, GridOptions, grid } from './grid.js';
|
|
6
|
-
export { segmentToSegmentMinDistance } from './segment-distance.js';
|
|
6
|
+
export { segmentToBoundsMinDistance, segmentToBoxMinDistance, segmentToCircleMinDistance, segmentToSegmentMinDistance } from './segment-distance.js';
|
package/dist/index.js
CHANGED
|
@@ -7,14 +7,11 @@ import {
|
|
|
7
7
|
grid
|
|
8
8
|
} from "./chunk-U45EKA3R.js";
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
getBoundingBox
|
|
14
|
-
} from "./chunk-MHHTZHOJ.js";
|
|
15
|
-
import {
|
|
10
|
+
segmentToBoundsMinDistance,
|
|
11
|
+
segmentToBoxMinDistance,
|
|
12
|
+
segmentToCircleMinDistance,
|
|
16
13
|
segmentToSegmentMinDistance
|
|
17
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-K7F26NYD.js";
|
|
18
15
|
import {
|
|
19
16
|
distance,
|
|
20
17
|
doSegmentsIntersect,
|
|
@@ -23,6 +20,12 @@ import {
|
|
|
23
20
|
orientation,
|
|
24
21
|
pointToSegmentDistance
|
|
25
22
|
} from "./chunk-CHQOCSFB.js";
|
|
23
|
+
import {
|
|
24
|
+
clamp,
|
|
25
|
+
computeDistanceBetweenBoxes,
|
|
26
|
+
findNearestPointsBetweenBoxSets,
|
|
27
|
+
getBoundingBox
|
|
28
|
+
} from "./chunk-MHHTZHOJ.js";
|
|
26
29
|
export {
|
|
27
30
|
clamp,
|
|
28
31
|
computeDistanceBetweenBoxes,
|
|
@@ -37,6 +40,9 @@ export {
|
|
|
37
40
|
onSegment,
|
|
38
41
|
orientation,
|
|
39
42
|
pointToSegmentDistance,
|
|
43
|
+
segmentToBoundsMinDistance,
|
|
44
|
+
segmentToBoxMinDistance,
|
|
45
|
+
segmentToCircleMinDistance,
|
|
40
46
|
segmentToSegmentMinDistance
|
|
41
47
|
};
|
|
42
48
|
//# sourceMappingURL=index.js.map
|
|
@@ -4,5 +4,30 @@ import { Point } from './common.js';
|
|
|
4
4
|
* Returns the minimum distance between two line segments.
|
|
5
5
|
*/
|
|
6
6
|
declare function segmentToSegmentMinDistance(a: Point, b: Point, u: Point, v: Point): number;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the minimum distance from a line segment to a bounding box.
|
|
9
|
+
*/
|
|
10
|
+
declare function segmentToBoundsMinDistance(a: Point, b: Point, bounds: {
|
|
11
|
+
minX: number;
|
|
12
|
+
minY: number;
|
|
13
|
+
maxX: number;
|
|
14
|
+
maxY: number;
|
|
15
|
+
}): number;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the minimum distance from a line segment to a box.
|
|
18
|
+
*/
|
|
19
|
+
declare function segmentToBoxMinDistance(a: Point, b: Point, box: {
|
|
20
|
+
center: Point;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}): number;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the minimum distance from a line segment to a circle.
|
|
26
|
+
*/
|
|
27
|
+
declare function segmentToCircleMinDistance(a: Point, b: Point, circle: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
radius: number;
|
|
31
|
+
}): number;
|
|
7
32
|
|
|
8
|
-
export { segmentToSegmentMinDistance };
|
|
33
|
+
export { segmentToBoundsMinDistance, segmentToBoxMinDistance, segmentToCircleMinDistance, segmentToSegmentMinDistance };
|
package/dist/segment-distance.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
+
segmentToBoundsMinDistance,
|
|
3
|
+
segmentToBoxMinDistance,
|
|
4
|
+
segmentToCircleMinDistance,
|
|
2
5
|
segmentToSegmentMinDistance
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-K7F26NYD.js";
|
|
4
7
|
import "./chunk-CHQOCSFB.js";
|
|
8
|
+
import "./chunk-MHHTZHOJ.js";
|
|
5
9
|
export {
|
|
10
|
+
segmentToBoundsMinDistance,
|
|
11
|
+
segmentToBoxMinDistance,
|
|
12
|
+
segmentToCircleMinDistance,
|
|
6
13
|
segmentToSegmentMinDistance
|
|
7
14
|
};
|
|
8
15
|
//# sourceMappingURL=segment-distance.js.map
|
package/package.json
CHANGED
package/dist/chunk-6C2XJHEO.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
doSegmentsIntersect,
|
|
3
|
-
pointToSegmentDistance
|
|
4
|
-
} from "./chunk-CHQOCSFB.js";
|
|
5
|
-
|
|
6
|
-
// src/segment-distance.ts
|
|
7
|
-
function segmentToSegmentMinDistance(a, b, u, v) {
|
|
8
|
-
if (a.x === b.x && a.y === b.y) {
|
|
9
|
-
return pointToSegmentDistance(a, u, v);
|
|
10
|
-
}
|
|
11
|
-
if (u.x === v.x && u.y === v.y) {
|
|
12
|
-
return pointToSegmentDistance(u, a, b);
|
|
13
|
-
}
|
|
14
|
-
if (doSegmentsIntersect(a, b, u, v)) {
|
|
15
|
-
return 0;
|
|
16
|
-
}
|
|
17
|
-
const distances = [
|
|
18
|
-
pointToSegmentDistance(a, u, v),
|
|
19
|
-
pointToSegmentDistance(b, u, v),
|
|
20
|
-
pointToSegmentDistance(u, a, b),
|
|
21
|
-
pointToSegmentDistance(v, a, b)
|
|
22
|
-
];
|
|
23
|
-
return Math.min(...distances);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export {
|
|
27
|
-
segmentToSegmentMinDistance
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=chunk-6C2XJHEO.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/segment-distance.ts"],"sourcesContent":["import type { Point } from \"./common\"\nimport {\n distance,\n doSegmentsIntersect,\n pointToSegmentDistance,\n} from \"./line-intersections\"\n\n/**\n * Returns the minimum distance between two line segments.\n */\nexport function segmentToSegmentMinDistance(\n a: Point,\n b: Point,\n u: Point,\n v: Point,\n): number {\n // Handle degenerate cases: segments of zero length\n if (a.x === b.x && a.y === b.y) {\n return pointToSegmentDistance(a, u, v)\n }\n if (u.x === v.x && u.y === v.y) {\n return pointToSegmentDistance(u, a, b)\n }\n\n // Check if segments intersect\n if (doSegmentsIntersect(a, b, u, v)) {\n return 0\n }\n\n // Compute the minimum distance between the segments\n const distances = [\n pointToSegmentDistance(a, u, v),\n pointToSegmentDistance(b, u, v),\n pointToSegmentDistance(u, a, b),\n pointToSegmentDistance(v, a, b),\n ]\n\n return Math.min(...distances)\n}\n"],"mappings":";;;;;;AAUO,SAAS,4BACd,GACA,GACA,GACA,GACQ;AAER,MAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG;AAC9B,WAAO,uBAAuB,GAAG,GAAG,CAAC;AAAA,EACvC;AACA,MAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG;AAC9B,WAAO,uBAAuB,GAAG,GAAG,CAAC;AAAA,EACvC;AAGA,MAAI,oBAAoB,GAAG,GAAG,GAAG,CAAC,GAAG;AACnC,WAAO;AAAA,EACT;AAGA,QAAM,YAAY;AAAA,IAChB,uBAAuB,GAAG,GAAG,CAAC;AAAA,IAC9B,uBAAuB,GAAG,GAAG,CAAC;AAAA,IAC9B,uBAAuB,GAAG,GAAG,CAAC;AAAA,IAC9B,uBAAuB,GAAG,GAAG,CAAC;AAAA,EAChC;AAEA,SAAO,KAAK,IAAI,GAAG,SAAS;AAC9B;","names":[]}
|