graphics-debug 0.0.83 → 0.0.85
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-HU5LL4ZE.js → chunk-5O6JHGHI.js} +2 -2
- package/dist/chunk-5O6JHGHI.js.map +1 -0
- package/dist/{chunk-NYENUFOW.js → chunk-7236NVI2.js} +5 -1
- package/dist/chunk-7236NVI2.js.map +1 -0
- package/dist/chunk-FLFF6QXL.js +89 -0
- package/dist/chunk-FLFF6QXL.js.map +1 -0
- package/dist/{chunk-BQ3ZHEQO.js → chunk-K37Y2KHE.js} +5 -1
- package/dist/chunk-K37Y2KHE.js.map +1 -0
- package/dist/{chunk-PPB7D4OE.js → chunk-ME47RV6O.js} +85 -10
- package/dist/chunk-ME47RV6O.js.map +1 -0
- package/dist/{chunk-GZRUE2GP.js → chunk-OB4CGOL3.js} +6 -1
- package/dist/chunk-OB4CGOL3.js.map +1 -0
- package/dist/{chunk-IOVKI3ZO.js → chunk-PCHDJSKZ.js} +48 -2
- package/dist/chunk-PCHDJSKZ.js.map +1 -0
- package/dist/{chunk-MXOATGTD.js → chunk-PEHHGMS7.js} +4 -4
- package/dist/{chunk-7NMLOZRC.js → chunk-TBTTAU4R.js} +122 -8
- package/dist/chunk-TBTTAU4R.js.map +1 -0
- package/dist/cli/cli.js +9 -8
- package/dist/cli/cli.js.map +1 -1
- package/dist/lib/arrowHelpers.d.ts +27 -1
- package/dist/lib/arrowHelpers.js +5 -3
- package/dist/lib/drawGraphicsToCanvas.js +3 -2
- package/dist/lib/getSvgFromGraphicsObject.d.ts +3 -2
- package/dist/lib/getSvgFromGraphicsObject.js +3 -2
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +9 -8
- package/dist/lib/infiniteLineHelpers.d.ts +7 -0
- package/dist/lib/infiniteLineHelpers.js +9 -0
- package/dist/lib/infiniteLineHelpers.js.map +1 -0
- package/dist/lib/matcher.js +3 -2
- package/dist/lib/matcher.js.map +1 -1
- package/dist/lib/mergeGraphics.js +1 -1
- package/dist/lib/react.d.ts +1 -1
- package/dist/lib/react.js +260 -114
- package/dist/lib/react.js.map +1 -1
- package/dist/lib/setStepOfAllObjects.js +1 -1
- package/dist/lib/stackGraphics.js +6 -5
- package/dist/lib/translateGraphics.js +1 -1
- package/dist/lib/types.d.ts +21 -1
- package/package.json +1 -1
- package/dist/chunk-7NMLOZRC.js.map +0 -1
- package/dist/chunk-BQ3ZHEQO.js.map +0 -1
- package/dist/chunk-GZRUE2GP.js.map +0 -1
- package/dist/chunk-HU5LL4ZE.js.map +0 -1
- package/dist/chunk-IOVKI3ZO.js.map +0 -1
- package/dist/chunk-NYENUFOW.js.map +0 -1
- package/dist/chunk-PPB7D4OE.js.map +0 -1
- /package/dist/{chunk-MXOATGTD.js.map → chunk-PEHHGMS7.js.map} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-NG6H63SM.js";
|
|
4
4
|
import {
|
|
5
5
|
getSvgFromGraphicsObject
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TBTTAU4R.js";
|
|
7
7
|
|
|
8
8
|
// lib/index.ts
|
|
9
9
|
function getSvgFromLogString(logString) {
|
|
@@ -53,4 +53,4 @@ export {
|
|
|
53
53
|
getHtmlFromLogString,
|
|
54
54
|
getSvgsFromLogString
|
|
55
55
|
};
|
|
56
|
-
//# sourceMappingURL=chunk-
|
|
56
|
+
//# sourceMappingURL=chunk-5O6JHGHI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/index.ts"],"sourcesContent":["import {\n computeTransformFromViewbox,\n drawGraphicsToCanvas,\n getBounds,\n} from \"./drawGraphicsToCanvas\"\nimport { getGraphicsObjectsFromLogString } from \"./getGraphicsObjectsFromLogString\"\nimport { getSvgFromGraphicsObject } from \"./getSvgFromGraphicsObject\"\nimport { mergeGraphics } from \"./mergeGraphics\"\nimport { setStepOfAllObjects } from \"./setStepOfAllObjects\"\nimport {\n createGraphicsGrid,\n stackGraphicsHorizontally,\n stackGraphicsVertically,\n} from \"./stackGraphics\"\n\nexport type {\n Point,\n Line,\n InfiniteLine,\n Rect,\n Circle,\n Polygon,\n Arrow,\n Text,\n NinePointAnchor,\n GraphicsObject,\n Viewbox,\n CenterViewbox,\n TransformOptions,\n} from \"./types\"\nexport { getGraphicsObjectsFromLogString } from \"./getGraphicsObjectsFromLogString\"\nexport { getSvgFromGraphicsObject } from \"./getSvgFromGraphicsObject\"\nexport {\n drawGraphicsToCanvas,\n computeTransformFromViewbox,\n getBounds,\n} from \"./drawGraphicsToCanvas\"\nexport { translateGraphics } from \"./translateGraphics\"\nexport { mergeGraphics } from \"./mergeGraphics\"\nexport { setStepOfAllObjects } from \"./setStepOfAllObjects\"\nexport {\n stackGraphicsHorizontally,\n stackGraphicsVertically,\n createGraphicsGrid,\n} from \"./stackGraphics\"\nexport { FONT_SIZE_WIDTH_RATIO, FONT_SIZE_HEIGHT_RATIO } from \"./constants\"\n\nexport function getSvgFromLogString(logString: string): string {\n const objects = getGraphicsObjectsFromLogString(logString)\n if (objects.length === 0) return \"\"\n return getSvgFromGraphicsObject(objects[0])\n}\n\nexport function getHtmlFromLogString(logString: string): string {\n const svgs = getSvgsFromLogString(logString)\n if (svgs.length === 0) return \"\"\n\n const sections = svgs\n .map(\n ({ title, svg }) => `\n <section>\n <h2>${title}</h2>\n ${svg}\n </section>\n `,\n )\n .join(\"\\n\")\n\n return `\n<!DOCTYPE html>\n<html>\n<head>\n <title>Graphics Debug Output</title>\n <style>\n body { font-family: system-ui; max-width: 1200px; margin: 0 auto; padding: 20px; }\n h1 { color: #333; }\n section { margin: 40px 0; }\n svg { max-width: 100%; height: auto; border: 1px solid #eee; }\n </style>\n</head>\n<body>\n <h1>Graphics Debug Output</h1>\n ${sections}\n</body>\n</html>`\n}\n\nexport function getSvgsFromLogString(\n logString: string,\n): Array<{ title: string; svg: string }> {\n const objects = getGraphicsObjectsFromLogString(logString)\n return objects.map((obj) => ({\n title: obj.title || \"Untitled Graphic\",\n svg: getSvgFromGraphicsObject(obj),\n }))\n}\n"],"mappings":";;;;;;;;AA+CO,SAAS,oBAAoB,WAA2B;AAC7D,QAAM,UAAU,gCAAgC,SAAS;AACzD,MAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,SAAO,yBAAyB,QAAQ,CAAC,CAAC;AAC5C;AAEO,SAAS,qBAAqB,WAA2B;AAC9D,QAAM,OAAO,qBAAqB,SAAS;AAC3C,MAAI,KAAK,WAAW,EAAG,QAAO;AAE9B,QAAM,WAAW,KACd;AAAA,IACC,CAAC,EAAE,OAAO,IAAI,MAAM;AAAA;AAAA,YAEd,KAAK;AAAA,QACT,GAAG;AAAA;AAAA;AAAA,EAGP,EACC,KAAK,IAAI;AAEZ,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcL,QAAQ;AAAA;AAAA;AAGZ;AAEO,SAAS,qBACd,WACuC;AACvC,QAAM,UAAU,gCAAgC,SAAS;AACzD,SAAO,QAAQ,IAAI,CAAC,SAAS;AAAA,IAC3B,OAAO,IAAI,SAAS;AAAA,IACpB,KAAK,yBAAyB,GAAG;AAAA,EACnC,EAAE;AACJ;","names":[]}
|
|
@@ -11,6 +11,10 @@ function translateGraphics(graphics, dx, dy) {
|
|
|
11
11
|
...line,
|
|
12
12
|
points: line.points.map((pt) => ({ x: pt.x + dx, y: pt.y + dy }))
|
|
13
13
|
})),
|
|
14
|
+
infiniteLines: graphics.infiniteLines?.map((line) => ({
|
|
15
|
+
...line,
|
|
16
|
+
origin: { x: line.origin.x + dx, y: line.origin.y + dy }
|
|
17
|
+
})),
|
|
14
18
|
polygons: graphics.polygons?.map((polygon) => ({
|
|
15
19
|
...polygon,
|
|
16
20
|
points: polygon.points.map((pt) => ({ x: pt.x + dx, y: pt.y + dy }))
|
|
@@ -39,4 +43,4 @@ function translateGraphics(graphics, dx, dy) {
|
|
|
39
43
|
export {
|
|
40
44
|
translateGraphics
|
|
41
45
|
};
|
|
42
|
-
//# sourceMappingURL=chunk-
|
|
46
|
+
//# sourceMappingURL=chunk-7236NVI2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/translateGraphics.ts"],"sourcesContent":["import type { GraphicsObject } from \"./types\"\n\nexport function translateGraphics(\n graphics: GraphicsObject,\n dx: number,\n dy: number,\n): GraphicsObject {\n return {\n ...graphics,\n points: graphics.points?.map((p) => ({\n ...p,\n x: p.x + dx,\n y: p.y + dy,\n })),\n lines: graphics.lines?.map((line) => ({\n ...line,\n points: line.points.map((pt) => ({ x: pt.x + dx, y: pt.y + dy })),\n })),\n infiniteLines: graphics.infiniteLines?.map((line) => ({\n ...line,\n origin: { x: line.origin.x + dx, y: line.origin.y + dy },\n })),\n polygons: graphics.polygons?.map((polygon) => ({\n ...polygon,\n points: polygon.points.map((pt) => ({ x: pt.x + dx, y: pt.y + dy })),\n })),\n rects: graphics.rects?.map((rect) => ({\n ...rect,\n center: { x: rect.center.x + dx, y: rect.center.y + dy },\n })),\n circles: graphics.circles?.map((circle) => ({\n ...circle,\n center: { x: circle.center.x + dx, y: circle.center.y + dy },\n })),\n arrows: graphics.arrows?.map((arrow) => ({\n ...arrow,\n start: { x: arrow.start.x + dx, y: arrow.start.y + dy },\n end: { x: arrow.end.x + dx, y: arrow.end.y + dy },\n })),\n texts: graphics.texts?.map((text) => ({\n ...text,\n x: text.x + dx,\n y: text.y + dy,\n })),\n }\n}\n"],"mappings":";AAEO,SAAS,kBACd,UACA,IACA,IACgB;AAChB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ,SAAS,QAAQ,IAAI,CAAC,OAAO;AAAA,MACnC,GAAG;AAAA,MACH,GAAG,EAAE,IAAI;AAAA,MACT,GAAG,EAAE,IAAI;AAAA,IACX,EAAE;AAAA,IACF,OAAO,SAAS,OAAO,IAAI,CAAC,UAA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d,EAAE;AAAA,EACJ;AACF;","names":[]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// lib/infiniteLineHelpers.ts
|
|
2
|
+
import { applyToPoint, inverse } from "transformation-matrix";
|
|
3
|
+
var EPSILON = 1e-9;
|
|
4
|
+
var isWithin = (value, min, max) => {
|
|
5
|
+
return value >= min - EPSILON && value <= max + EPSILON;
|
|
6
|
+
};
|
|
7
|
+
var dedupePoints = (points) => {
|
|
8
|
+
const unique = [];
|
|
9
|
+
for (const point of points) {
|
|
10
|
+
if (!unique.some(
|
|
11
|
+
(other) => Math.abs(other.x - point.x) < EPSILON && Math.abs(other.y - point.y) < EPSILON
|
|
12
|
+
)) {
|
|
13
|
+
unique.push(point);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return unique;
|
|
17
|
+
};
|
|
18
|
+
function clipInfiniteLineToBounds(infiniteLine, bounds) {
|
|
19
|
+
const { origin, directionVector } = infiniteLine;
|
|
20
|
+
if (Math.abs(directionVector.x) < EPSILON && Math.abs(directionVector.y) < EPSILON) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const intersections = [];
|
|
24
|
+
if (Math.abs(directionVector.x) >= EPSILON) {
|
|
25
|
+
const tAtMinX = (bounds.minX - origin.x) / directionVector.x;
|
|
26
|
+
const yAtMinX = origin.y + tAtMinX * directionVector.y;
|
|
27
|
+
if (isWithin(yAtMinX, bounds.minY, bounds.maxY)) {
|
|
28
|
+
intersections.push({ x: bounds.minX, y: yAtMinX });
|
|
29
|
+
}
|
|
30
|
+
const tAtMaxX = (bounds.maxX - origin.x) / directionVector.x;
|
|
31
|
+
const yAtMaxX = origin.y + tAtMaxX * directionVector.y;
|
|
32
|
+
if (isWithin(yAtMaxX, bounds.minY, bounds.maxY)) {
|
|
33
|
+
intersections.push({ x: bounds.maxX, y: yAtMaxX });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (Math.abs(directionVector.y) >= EPSILON) {
|
|
37
|
+
const tAtMinY = (bounds.minY - origin.y) / directionVector.y;
|
|
38
|
+
const xAtMinY = origin.x + tAtMinY * directionVector.x;
|
|
39
|
+
if (isWithin(xAtMinY, bounds.minX, bounds.maxX)) {
|
|
40
|
+
intersections.push({ x: xAtMinY, y: bounds.minY });
|
|
41
|
+
}
|
|
42
|
+
const tAtMaxY = (bounds.maxY - origin.y) / directionVector.y;
|
|
43
|
+
const xAtMaxY = origin.x + tAtMaxY * directionVector.x;
|
|
44
|
+
if (isWithin(xAtMaxY, bounds.minX, bounds.maxX)) {
|
|
45
|
+
intersections.push({ x: xAtMaxY, y: bounds.maxY });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const uniqueIntersections = dedupePoints(intersections);
|
|
49
|
+
if (uniqueIntersections.length < 2) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
let first = uniqueIntersections[0];
|
|
53
|
+
let second = uniqueIntersections[1];
|
|
54
|
+
let maxDistanceSquared = (first.x - second.x) ** 2 + (first.y - second.y) ** 2;
|
|
55
|
+
for (let i = 0; i < uniqueIntersections.length; i++) {
|
|
56
|
+
for (let j = i + 1; j < uniqueIntersections.length; j++) {
|
|
57
|
+
const a = uniqueIntersections[i];
|
|
58
|
+
const b = uniqueIntersections[j];
|
|
59
|
+
const distanceSquared = (a.x - b.x) ** 2 + (a.y - b.y) ** 2;
|
|
60
|
+
if (distanceSquared > maxDistanceSquared) {
|
|
61
|
+
first = a;
|
|
62
|
+
second = b;
|
|
63
|
+
maxDistanceSquared = distanceSquared;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return [first, second];
|
|
68
|
+
}
|
|
69
|
+
function getViewportBoundsFromMatrix(matrix, width, height) {
|
|
70
|
+
const screenToReal = inverse(matrix);
|
|
71
|
+
const corners = [
|
|
72
|
+
applyToPoint(screenToReal, { x: 0, y: 0 }),
|
|
73
|
+
applyToPoint(screenToReal, { x: width, y: 0 }),
|
|
74
|
+
applyToPoint(screenToReal, { x: 0, y: height }),
|
|
75
|
+
applyToPoint(screenToReal, { x: width, y: height })
|
|
76
|
+
];
|
|
77
|
+
return {
|
|
78
|
+
minX: Math.min(...corners.map((p) => p.x)),
|
|
79
|
+
maxX: Math.max(...corners.map((p) => p.x)),
|
|
80
|
+
minY: Math.min(...corners.map((p) => p.y)),
|
|
81
|
+
maxY: Math.max(...corners.map((p) => p.y))
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
clipInfiniteLineToBounds,
|
|
87
|
+
getViewportBoundsFromMatrix
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=chunk-FLFF6QXL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/infiniteLineHelpers.ts"],"sourcesContent":["import { type Matrix, applyToPoint, inverse } from \"transformation-matrix\"\nimport type { InfiniteLine, Point, Viewbox } from \"./types\"\n\nconst EPSILON = 1e-9\n\nconst isWithin = (value: number, min: number, max: number) => {\n return value >= min - EPSILON && value <= max + EPSILON\n}\n\nconst dedupePoints = (points: Point[]) => {\n const unique: Point[] = []\n for (const point of points) {\n if (\n !unique.some(\n (other) =>\n Math.abs(other.x - point.x) < EPSILON &&\n Math.abs(other.y - point.y) < EPSILON,\n )\n ) {\n unique.push(point)\n }\n }\n return unique\n}\n\nexport function clipInfiniteLineToBounds(\n infiniteLine: InfiniteLine,\n bounds: Viewbox,\n): [Point, Point] | null {\n const { origin, directionVector } = infiniteLine\n\n if (\n Math.abs(directionVector.x) < EPSILON &&\n Math.abs(directionVector.y) < EPSILON\n ) {\n return null\n }\n\n const intersections: Point[] = []\n\n if (Math.abs(directionVector.x) >= EPSILON) {\n const tAtMinX = (bounds.minX - origin.x) / directionVector.x\n const yAtMinX = origin.y + tAtMinX * directionVector.y\n if (isWithin(yAtMinX, bounds.minY, bounds.maxY)) {\n intersections.push({ x: bounds.minX, y: yAtMinX })\n }\n\n const tAtMaxX = (bounds.maxX - origin.x) / directionVector.x\n const yAtMaxX = origin.y + tAtMaxX * directionVector.y\n if (isWithin(yAtMaxX, bounds.minY, bounds.maxY)) {\n intersections.push({ x: bounds.maxX, y: yAtMaxX })\n }\n }\n\n if (Math.abs(directionVector.y) >= EPSILON) {\n const tAtMinY = (bounds.minY - origin.y) / directionVector.y\n const xAtMinY = origin.x + tAtMinY * directionVector.x\n if (isWithin(xAtMinY, bounds.minX, bounds.maxX)) {\n intersections.push({ x: xAtMinY, y: bounds.minY })\n }\n\n const tAtMaxY = (bounds.maxY - origin.y) / directionVector.y\n const xAtMaxY = origin.x + tAtMaxY * directionVector.x\n if (isWithin(xAtMaxY, bounds.minX, bounds.maxX)) {\n intersections.push({ x: xAtMaxY, y: bounds.maxY })\n }\n }\n\n const uniqueIntersections = dedupePoints(intersections)\n\n if (uniqueIntersections.length < 2) {\n return null\n }\n\n let first = uniqueIntersections[0]\n let second = uniqueIntersections[1]\n let maxDistanceSquared = (first.x - second.x) ** 2 + (first.y - second.y) ** 2\n\n for (let i = 0; i < uniqueIntersections.length; i++) {\n for (let j = i + 1; j < uniqueIntersections.length; j++) {\n const a = uniqueIntersections[i]\n const b = uniqueIntersections[j]\n const distanceSquared = (a.x - b.x) ** 2 + (a.y - b.y) ** 2\n if (distanceSquared > maxDistanceSquared) {\n first = a\n second = b\n maxDistanceSquared = distanceSquared\n }\n }\n }\n\n return [first, second]\n}\n\nexport function getViewportBoundsFromMatrix(\n matrix: Matrix,\n width: number,\n height: number,\n): Viewbox {\n const screenToReal = inverse(matrix)\n const corners = [\n applyToPoint(screenToReal, { x: 0, y: 0 }),\n applyToPoint(screenToReal, { x: width, y: 0 }),\n applyToPoint(screenToReal, { x: 0, y: height }),\n applyToPoint(screenToReal, { x: width, y: height }),\n ]\n\n return {\n minX: Math.min(...corners.map((p) => p.x)),\n maxX: Math.max(...corners.map((p) => p.x)),\n minY: Math.min(...corners.map((p) => p.y)),\n maxY: Math.max(...corners.map((p) => p.y)),\n }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Aa,cAAc,EAAE,GAAG,OAAO,GAAG,EAAE,CAAC;AAAA,IAC7C,aAAa,cAAc,EAAE,GAAG,GAAG,GAAG,OAAO,CAAC;AAAA,IAC9C,aAAa,cAAc,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC;AAAA,EACpD;AAEA,SAAO;AAAA,IACL,MAAM,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAAA,IACzC,MAAM,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAAA,IACzC,MAAM,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAAA,IACzC,MAAM,KAAK,IAAI,GAAG,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAAA,EAC3C;AACF;","names":[]}
|
|
@@ -5,6 +5,10 @@ var mergeGraphics = (graphics1, graphics2) => {
|
|
|
5
5
|
rects: [...graphics1.rects ?? [], ...graphics2.rects ?? []],
|
|
6
6
|
points: [...graphics1.points ?? [], ...graphics2.points ?? []],
|
|
7
7
|
lines: [...graphics1.lines ?? [], ...graphics2.lines ?? []],
|
|
8
|
+
infiniteLines: [
|
|
9
|
+
...graphics1.infiniteLines ?? [],
|
|
10
|
+
...graphics2.infiniteLines ?? []
|
|
11
|
+
],
|
|
8
12
|
polygons: [...graphics1.polygons ?? [], ...graphics2.polygons ?? []],
|
|
9
13
|
circles: [...graphics1.circles ?? [], ...graphics2.circles ?? []],
|
|
10
14
|
arrows: [...graphics1.arrows ?? [], ...graphics2.arrows ?? []],
|
|
@@ -15,4 +19,4 @@ var mergeGraphics = (graphics1, graphics2) => {
|
|
|
15
19
|
export {
|
|
16
20
|
mergeGraphics
|
|
17
21
|
};
|
|
18
|
-
//# sourceMappingURL=chunk-
|
|
22
|
+
//# sourceMappingURL=chunk-K37Y2KHE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/mergeGraphics.ts"],"sourcesContent":["import type { GraphicsObject } from \"./types\"\n\nexport const mergeGraphics = (\n graphics1: GraphicsObject,\n graphics2: GraphicsObject,\n): GraphicsObject => {\n return {\n ...graphics1,\n rects: [...(graphics1.rects ?? []), ...(graphics2.rects ?? [])],\n points: [...(graphics1.points ?? []), ...(graphics2.points ?? [])],\n lines: [...(graphics1.lines ?? []), ...(graphics2.lines ?? [])],\n infiniteLines: [\n ...(graphics1.infiniteLines ?? []),\n ...(graphics2.infiniteLines ?? []),\n ],\n polygons: [...(graphics1.polygons ?? []), ...(graphics2.polygons ?? [])],\n circles: [...(graphics1.circles ?? []), ...(graphics2.circles ?? [])],\n arrows: [...(graphics1.arrows ?? []), ...(graphics2.arrows ?? [])],\n texts: [...(graphics1.texts ?? []), ...(graphics2.texts ?? [])],\n }\n}\n"],"mappings":";AAEO,IAAM,gBAAgB,CAC3B,WACA,cACmB;AACnB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,CAAC,GAAI,UAAU,SAAS,CAAC,GAAI,GAAI,UAAU,SAAS,CAAC,CAAE;AAAA,IAC9D,QAAQ,CAAC,GAAI,UAAU,UAAU,CAAC,GAAI,GAAI,UAAU,UAAU,CAAC,CAAE;AAAA,IACjE,OAAO,CAAC,GAAI,UAAU,SAAS,CAAC,GAAI,GAAI,UAAU,SAAS,CAAC,CAAE;AAAA,IAC9D,eAAe;AAAA,MACb,GAAI,UAAU,iBAAiB,CAAC;AAAA,MAChC,GAAI,UAAU,iBAAiB,CAAC;AAAA,IAClC;AAAA,IACA,UAAU,CAAC,GAAI,UAAU,YAAY,CAAC,GAAI,GAAI,UAAU,YAAY,CAAC,CAAE;AAAA,IACvE,SAAS,CAAC,GAAI,UAAU,WAAW,CAAC,GAAI,GAAI,UAAU,WAAW,CAAC,CAAE;AAAA,IACpE,QAAQ,CAAC,GAAI,UAAU,UAAU,CAAC,GAAI,GAAI,UAAU,UAAU,CAAC,CAAE;AAAA,IACjE,OAAO,CAAC,GAAI,UAAU,SAAS,CAAC,GAAI,GAAI,UAAU,SAAS,CAAC,CAAE;AAAA,EAChE;AACF;","names":[]}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getArrowBoundingBox,
|
|
3
|
-
getArrowGeometry
|
|
4
|
-
|
|
3
|
+
getArrowGeometry,
|
|
4
|
+
getInlineLabelLayout
|
|
5
|
+
} from "./chunk-PCHDJSKZ.js";
|
|
5
6
|
import {
|
|
6
7
|
FONT_SIZE_HEIGHT_RATIO,
|
|
7
8
|
FONT_SIZE_WIDTH_RATIO
|
|
8
9
|
} from "./chunk-ZGI74PYD.js";
|
|
9
|
-
|
|
10
|
-
// lib/drawGraphicsToCanvas.ts
|
|
11
10
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
applyToPoint
|
|
16
|
-
} from "transformation-matrix";
|
|
11
|
+
clipInfiniteLineToBounds,
|
|
12
|
+
getViewportBoundsFromMatrix
|
|
13
|
+
} from "./chunk-FLFF6QXL.js";
|
|
17
14
|
|
|
18
15
|
// site/components/InteractiveGraphics/defaultColors.ts
|
|
19
16
|
var defaultColors = [
|
|
@@ -56,6 +53,12 @@ var defaultColors = [
|
|
|
56
53
|
];
|
|
57
54
|
|
|
58
55
|
// lib/drawGraphicsToCanvas.ts
|
|
56
|
+
import {
|
|
57
|
+
applyToPoint,
|
|
58
|
+
compose,
|
|
59
|
+
scale,
|
|
60
|
+
translate
|
|
61
|
+
} from "transformation-matrix";
|
|
59
62
|
function computeTransformFromViewbox(viewbox, canvasWidth, canvasHeight, options = {}) {
|
|
60
63
|
const padding = options.padding ?? 40;
|
|
61
64
|
const yFlip = options.yFlip ?? false;
|
|
@@ -283,6 +286,41 @@ function drawGraphicsToCanvas(graphics, target, options = {}) {
|
|
|
283
286
|
ctx.closePath();
|
|
284
287
|
ctx.fill();
|
|
285
288
|
});
|
|
289
|
+
const fontSize = 12;
|
|
290
|
+
const screenStrokeWidth = geometry.shaftWidth * (scaleFactor || 1);
|
|
291
|
+
const alongSeparation = fontSize * 0.6;
|
|
292
|
+
const inlineLabelLayout = getInlineLabelLayout(shaftStart, shaftEnd, {
|
|
293
|
+
fontSize,
|
|
294
|
+
strokeWidth: screenStrokeWidth,
|
|
295
|
+
normalPadding: 6,
|
|
296
|
+
alongOffset: arrow.label ? alongSeparation : 0
|
|
297
|
+
});
|
|
298
|
+
const arrowLabelLayout = getInlineLabelLayout(shaftStart, shaftEnd, {
|
|
299
|
+
fontSize,
|
|
300
|
+
strokeWidth: screenStrokeWidth,
|
|
301
|
+
normalPadding: 12,
|
|
302
|
+
alongOffset: arrow.inlineLabel ? -alongSeparation : 0
|
|
303
|
+
});
|
|
304
|
+
ctx.fillStyle = color;
|
|
305
|
+
ctx.font = `${fontSize}px sans-serif`;
|
|
306
|
+
if (!options.disableLabels && arrow.label) {
|
|
307
|
+
const labelX = arrowLabelLayout.x;
|
|
308
|
+
const labelY = arrowLabelLayout.y;
|
|
309
|
+
ctx.save();
|
|
310
|
+
ctx.textAlign = "center";
|
|
311
|
+
ctx.textBaseline = "middle";
|
|
312
|
+
ctx.fillText(arrow.label, labelX, labelY);
|
|
313
|
+
ctx.restore();
|
|
314
|
+
}
|
|
315
|
+
if (!options.hideInlineLabels && arrow.inlineLabel) {
|
|
316
|
+
ctx.save();
|
|
317
|
+
ctx.translate(inlineLabelLayout.x, inlineLabelLayout.y);
|
|
318
|
+
ctx.rotate(inlineLabelLayout.angleRadians);
|
|
319
|
+
ctx.textAlign = "center";
|
|
320
|
+
ctx.textBaseline = "middle";
|
|
321
|
+
ctx.fillText(arrow.inlineLabel, 0, 0);
|
|
322
|
+
ctx.restore();
|
|
323
|
+
}
|
|
286
324
|
});
|
|
287
325
|
}
|
|
288
326
|
if (graphics.lines && graphics.lines.length > 0) {
|
|
@@ -321,6 +359,43 @@ function drawGraphicsToCanvas(graphics, target, options = {}) {
|
|
|
321
359
|
ctx.stroke();
|
|
322
360
|
});
|
|
323
361
|
}
|
|
362
|
+
if (graphics.infiniteLines && graphics.infiniteLines.length > 0) {
|
|
363
|
+
const viewportBounds = getViewportBoundsFromMatrix(
|
|
364
|
+
matrix,
|
|
365
|
+
canvasWidth,
|
|
366
|
+
canvasHeight
|
|
367
|
+
);
|
|
368
|
+
graphics.infiniteLines.forEach((line, lineIndex) => {
|
|
369
|
+
const segment = clipInfiniteLineToBounds(line, viewportBounds);
|
|
370
|
+
if (!segment) return;
|
|
371
|
+
const [start, end] = segment;
|
|
372
|
+
const projectedStart = applyToPoint(matrix, start);
|
|
373
|
+
const projectedEnd = applyToPoint(matrix, end);
|
|
374
|
+
ctx.beginPath();
|
|
375
|
+
ctx.moveTo(projectedStart.x, projectedStart.y);
|
|
376
|
+
ctx.lineTo(projectedEnd.x, projectedEnd.y);
|
|
377
|
+
ctx.strokeStyle = line.strokeColor || defaultColors[lineIndex % defaultColors.length];
|
|
378
|
+
ctx.lineWidth = line.strokeWidth ? line.strokeWidth * Math.abs(matrix.a) : 2;
|
|
379
|
+
ctx.lineCap = "round";
|
|
380
|
+
if (line.strokeDash) {
|
|
381
|
+
if (typeof line.strokeDash === "string") {
|
|
382
|
+
let dashArray;
|
|
383
|
+
if (line.strokeDash.includes(",")) {
|
|
384
|
+
dashArray = line.strokeDash.split(",").map((s) => parseFloat(s.trim())).filter((n) => !Number.isNaN(n));
|
|
385
|
+
} else {
|
|
386
|
+
const value = parseFloat(line.strokeDash.trim());
|
|
387
|
+
dashArray = !Number.isNaN(value) ? [value] : [];
|
|
388
|
+
}
|
|
389
|
+
ctx.setLineDash(dashArray);
|
|
390
|
+
} else {
|
|
391
|
+
ctx.setLineDash(line.strokeDash.map((n) => n * Math.abs(matrix.a)));
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
ctx.setLineDash([]);
|
|
395
|
+
}
|
|
396
|
+
ctx.stroke();
|
|
397
|
+
});
|
|
398
|
+
}
|
|
324
399
|
if (graphics.points && graphics.points.length > 0) {
|
|
325
400
|
graphics.points.forEach((point, pointIndex) => {
|
|
326
401
|
const projected = applyToPoint(matrix, point);
|
|
@@ -377,4 +452,4 @@ export {
|
|
|
377
452
|
getBounds,
|
|
378
453
|
drawGraphicsToCanvas
|
|
379
454
|
};
|
|
380
|
-
//# sourceMappingURL=chunk-
|
|
455
|
+
//# sourceMappingURL=chunk-ME47RV6O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../site/components/InteractiveGraphics/defaultColors.ts","../lib/drawGraphicsToCanvas.ts"],"sourcesContent":["// These are default colors if no color is provided\n// colors are made based on the index of the item in the array\n\nexport const defaultColors = [\n \"rgba(239, 68, 68, 0.8)\", // red-300\n \"rgba(249, 115, 22, 0.8)\", // orange-300\n \"rgba(245, 158, 11, 0.8)\", // amber-300\n \"rgba(234, 179, 8, 0.8)\", // yellow-300\n \"rgba(132, 204, 22, 0.8)\", // lime-300\n \"rgba(34, 197, 94, 0.8)\", // green-300\n \"rgba(16, 185, 129, 0.8)\", // emerald-300\n \"rgba(20, 184, 166, 0.8)\", // teal-300\n \"rgba(6, 182, 212, 0.8)\", // cyan-300\n \"rgba(14, 165, 233, 0.8)\", // sky-300\n \"rgba(59, 130, 246, 0.8)\", // blue-300\n \"rgba(99, 102, 241, 0.8)\", // indigo-300\n \"rgba(139, 92, 246, 0.8)\", // violet-300\n \"rgba(168, 85, 247, 0.8)\", // purple-300\n \"rgba(217, 70, 239, 0.8)\", // fuchsia-300\n \"rgba(236, 72, 153, 0.8)\", // pink-300\n \"rgba(249, 168, 212, 0.8)\", // rose-300\n \"rgba(161, 161, 170, 0.8)\", // zinc-300\n]\n","import { defaultColors } from \"site/components/InteractiveGraphics/defaultColors\"\nimport {\n type Matrix,\n applyToPoint,\n compose,\n scale,\n translate,\n} from \"transformation-matrix\"\nimport {\n getArrowBoundingBox,\n getArrowGeometry,\n getInlineLabelLayout,\n} from \"./arrowHelpers\"\nimport { FONT_SIZE_HEIGHT_RATIO, FONT_SIZE_WIDTH_RATIO } from \"./constants\"\nimport {\n clipInfiniteLineToBounds,\n getViewportBoundsFromMatrix,\n} from \"./infiniteLineHelpers\"\nimport type {\n CenterViewbox,\n GraphicsObject,\n TransformOptions,\n Viewbox,\n} from \"./types\"\n\n/**\n * Computes a transformation matrix based on a provided viewbox\n * Handles both min/max style viewboxes and center/width/height style viewboxes\n */\nexport function computeTransformFromViewbox(\n viewbox: Viewbox | CenterViewbox,\n canvasWidth: number,\n canvasHeight: number,\n options: { padding?: number; yFlip?: boolean } = {},\n): Matrix {\n const padding = options.padding ?? 40\n const yFlip = options.yFlip ?? false\n\n // Convert CenterViewbox to Viewbox if needed\n let bounds: Viewbox\n if (\"center\" in viewbox) {\n const halfWidth = viewbox.width / 2\n const halfHeight = viewbox.height / 2\n bounds = {\n minX: viewbox.center.x - halfWidth,\n maxX: viewbox.center.x + halfWidth,\n minY: viewbox.center.y - halfHeight,\n maxY: viewbox.center.y + halfHeight,\n }\n } else {\n bounds = viewbox\n }\n\n const width = bounds.maxX - bounds.minX || 1\n const height = bounds.maxY - bounds.minY || 1\n\n const scale_factor = Math.min(\n (canvasWidth - 2 * padding) / width,\n (canvasHeight - 2 * padding) / height,\n )\n\n return compose(\n translate(canvasWidth / 2, canvasHeight / 2),\n scale(scale_factor, yFlip ? -scale_factor : scale_factor),\n translate(-(bounds.minX + width / 2), -(bounds.minY + height / 2)),\n )\n}\n\n/**\n * Computes bounds for a graphics object\n */\nexport function getBounds(graphics: GraphicsObject): Viewbox {\n const points = [\n ...(graphics.points || []),\n ...(graphics.lines || []).flatMap((line) => line.points),\n ...(graphics.polygons || []).flatMap((polygon) => polygon.points),\n ...(graphics.rects || []).flatMap((rect) => {\n const halfWidth = rect.width / 2\n const halfHeight = rect.height / 2\n return [\n { x: rect.center.x - halfWidth, y: rect.center.y - halfHeight },\n { x: rect.center.x + halfWidth, y: rect.center.y - halfHeight },\n { x: rect.center.x - halfWidth, y: rect.center.y + halfHeight },\n { x: rect.center.x + halfWidth, y: rect.center.y + halfHeight },\n ]\n }),\n ...(graphics.circles || []).flatMap((circle) => [\n { x: circle.center.x - circle.radius, y: circle.center.y }, // left\n { x: circle.center.x + circle.radius, y: circle.center.y }, // right\n { x: circle.center.x, y: circle.center.y - circle.radius }, // top\n { x: circle.center.x, y: circle.center.y + circle.radius }, // bottom\n ]),\n ...(graphics.arrows || []).flatMap((arrow) => {\n const bounds = getArrowBoundingBox(arrow)\n return [\n { x: bounds.minX, y: bounds.minY },\n { x: bounds.maxX, y: bounds.maxY },\n ]\n }),\n ...(graphics.texts || []).flatMap((text) => {\n const fontSize = text.fontSize ?? 12\n const width = text.text.length * fontSize * FONT_SIZE_WIDTH_RATIO\n const height = fontSize * FONT_SIZE_HEIGHT_RATIO\n const anchor = text.anchorSide ?? \"center\"\n const offsetMap: Record<string, { dx: number; dy: number }> = {\n top_left: { dx: 0, dy: 0 },\n top_center: { dx: -width / 2, dy: 0 },\n top_right: { dx: -width, dy: 0 },\n center_left: { dx: 0, dy: -height / 2 },\n center: { dx: -width / 2, dy: -height / 2 },\n center_right: { dx: -width, dy: -height / 2 },\n bottom_left: { dx: 0, dy: -height },\n bottom_center: { dx: -width / 2, dy: -height },\n bottom_right: { dx: -width, dy: -height },\n }\n const { dx, dy } = offsetMap[anchor]\n const x0 = text.x + dx\n const y0 = text.y + dy\n return [\n { x: x0, y: y0 },\n { x: x0 + width, y: y0 + height },\n ]\n }),\n ]\n\n if (points.length === 0) {\n return { minX: -1, maxX: 1, minY: -1, maxY: 1 }\n }\n\n return points.reduce(\n (bounds, point) => ({\n minX: Math.min(bounds.minX, point.x),\n maxX: Math.max(bounds.maxX, point.x),\n minY: Math.min(bounds.minY, point.y),\n maxY: Math.max(bounds.maxY, point.y),\n }),\n { minX: Infinity, maxX: -Infinity, minY: Infinity, maxY: -Infinity },\n )\n}\n\n/**\n * Draws a graphics object onto a canvas or context\n * @param graphics - The graphics object to draw\n * @param target - The canvas element or 2D context to draw on\n * @param options - Options for controlling the transform and rendering\n */\nexport function drawGraphicsToCanvas(\n graphics: GraphicsObject,\n target: HTMLCanvasElement | CanvasRenderingContext2D,\n options: TransformOptions = {},\n): void {\n // Get the context\n const ctx =\n target instanceof HTMLCanvasElement ? target.getContext(\"2d\") : target\n\n if (!ctx) {\n throw new Error(\"Could not get 2D context from canvas\")\n }\n\n // Get canvas dimensions\n const canvasWidth =\n target instanceof HTMLCanvasElement ? target.width : target.canvas.width\n\n const canvasHeight =\n target instanceof HTMLCanvasElement ? target.height : target.canvas.height\n\n // Get or compute the transform matrix\n let matrix: Matrix\n\n if (options.transform) {\n matrix = options.transform\n } else if (options.viewbox) {\n matrix = computeTransformFromViewbox(\n options.viewbox,\n canvasWidth,\n canvasHeight,\n {\n padding: options.padding,\n yFlip: options.yFlip,\n },\n )\n } else {\n // Auto-compute bounds and transform if not provided\n const bounds = getBounds(graphics)\n const yFlip = graphics.coordinateSystem === \"cartesian\"\n matrix = computeTransformFromViewbox(bounds, canvasWidth, canvasHeight, {\n padding: options.padding ?? 40,\n yFlip,\n })\n }\n\n // Clear the canvas\n ctx.clearRect(0, 0, canvasWidth, canvasHeight)\n\n // Save the current transform state\n ctx.save()\n\n // Draw the graphics elements\n // Draw rectangles\n if (graphics.rects && graphics.rects.length > 0) {\n graphics.rects.forEach((rect) => {\n const halfWidth = rect.width / 2\n const halfHeight = rect.height / 2\n\n const topLeft = applyToPoint(matrix, {\n x: rect.center.x - halfWidth,\n y: rect.center.y - halfHeight,\n })\n\n const bottomRight = applyToPoint(matrix, {\n x: rect.center.x + halfWidth,\n y: rect.center.y + halfHeight,\n })\n\n const width = Math.abs(bottomRight.x - topLeft.x)\n const height = Math.abs(bottomRight.y - topLeft.y)\n\n ctx.beginPath()\n ctx.rect(\n Math.min(topLeft.x, bottomRight.x),\n Math.min(topLeft.y, bottomRight.y),\n width,\n height,\n )\n\n if (rect.fill) {\n ctx.fillStyle = rect.fill\n ctx.fill()\n }\n\n if (rect.stroke) {\n ctx.strokeStyle = rect.stroke\n ctx.stroke()\n }\n })\n }\n\n // Draw circles\n if (graphics.circles && graphics.circles.length > 0) {\n graphics.circles.forEach((circle) => {\n const projected = applyToPoint(matrix, circle.center)\n const scaledRadius = circle.radius * Math.abs(matrix.a) // Use matrix scale factor\n\n ctx.beginPath()\n ctx.arc(projected.x, projected.y, scaledRadius, 0, 2 * Math.PI)\n\n if (circle.fill) {\n ctx.fillStyle = circle.fill\n ctx.fill()\n }\n\n if (circle.stroke) {\n ctx.strokeStyle = circle.stroke ?? \"transparent\"\n ctx.stroke()\n }\n })\n }\n\n // Draw polygons\n if (graphics.polygons && graphics.polygons.length > 0) {\n graphics.polygons.forEach((polygon) => {\n if (polygon.points.length === 0) return\n\n const projectedPoints = polygon.points.map((point) =>\n applyToPoint(matrix, point),\n )\n\n ctx.beginPath()\n ctx.moveTo(projectedPoints[0].x, projectedPoints[0].y)\n for (let i = 1; i < projectedPoints.length; i++) {\n ctx.lineTo(projectedPoints[i].x, projectedPoints[i].y)\n }\n ctx.closePath()\n\n if (polygon.fill) {\n ctx.fillStyle = polygon.fill\n ctx.fill()\n }\n\n if (polygon.stroke) {\n ctx.strokeStyle = polygon.stroke\n if (polygon.strokeWidth !== undefined) {\n ctx.lineWidth = polygon.strokeWidth * Math.abs(matrix.a)\n }\n ctx.stroke()\n }\n })\n }\n\n if (graphics.arrows && graphics.arrows.length > 0) {\n graphics.arrows.forEach((arrow, arrowIndex) => {\n const geometry = getArrowGeometry(arrow)\n const shaftStart = applyToPoint(matrix, geometry.shaftStart)\n const shaftEnd = applyToPoint(matrix, geometry.shaftEnd)\n\n const color =\n arrow.color || defaultColors[arrowIndex % defaultColors.length]\n const scaleFactor = Math.hypot(matrix.a, matrix.b)\n\n ctx.strokeStyle = color\n ctx.fillStyle = color\n ctx.lineWidth = geometry.shaftWidth * (scaleFactor || 1)\n ctx.lineCap = \"round\"\n ctx.setLineDash([])\n\n ctx.beginPath()\n ctx.moveTo(shaftStart.x, shaftStart.y)\n ctx.lineTo(shaftEnd.x, shaftEnd.y)\n ctx.stroke()\n\n geometry.heads.forEach((head) => {\n const tip = applyToPoint(matrix, head.tip)\n const leftWing = applyToPoint(matrix, head.leftWing)\n const rightWing = applyToPoint(matrix, head.rightWing)\n\n ctx.beginPath()\n ctx.moveTo(tip.x, tip.y)\n ctx.lineTo(leftWing.x, leftWing.y)\n ctx.lineTo(rightWing.x, rightWing.y)\n ctx.closePath()\n ctx.fill()\n })\n\n const fontSize = 12\n const screenStrokeWidth = geometry.shaftWidth * (scaleFactor || 1)\n const alongSeparation = fontSize * 0.6\n const inlineLabelLayout = getInlineLabelLayout(shaftStart, shaftEnd, {\n fontSize,\n strokeWidth: screenStrokeWidth,\n normalPadding: 6,\n alongOffset: arrow.label ? alongSeparation : 0,\n })\n const arrowLabelLayout = getInlineLabelLayout(shaftStart, shaftEnd, {\n fontSize,\n strokeWidth: screenStrokeWidth,\n normalPadding: 12,\n alongOffset: arrow.inlineLabel ? -alongSeparation : 0,\n })\n\n ctx.fillStyle = color\n ctx.font = `${fontSize}px sans-serif`\n\n if (!options.disableLabels && arrow.label) {\n const labelX = arrowLabelLayout.x\n const labelY = arrowLabelLayout.y\n\n ctx.save()\n ctx.textAlign = \"center\"\n ctx.textBaseline = \"middle\"\n ctx.fillText(arrow.label, labelX, labelY)\n ctx.restore()\n }\n\n if (!options.hideInlineLabels && arrow.inlineLabel) {\n ctx.save()\n ctx.translate(inlineLabelLayout.x, inlineLabelLayout.y)\n ctx.rotate(inlineLabelLayout.angleRadians)\n ctx.textAlign = \"center\"\n ctx.textBaseline = \"middle\"\n ctx.fillText(arrow.inlineLabel, 0, 0)\n ctx.restore()\n }\n })\n }\n\n // Draw lines\n if (graphics.lines && graphics.lines.length > 0) {\n graphics.lines.forEach((line, lineIndex) => {\n if (line.points.length === 0) return\n\n ctx.beginPath()\n\n const firstPoint = applyToPoint(matrix, line.points[0])\n ctx.moveTo(firstPoint.x, firstPoint.y)\n\n for (let i = 1; i < line.points.length; i++) {\n const projected = applyToPoint(matrix, line.points[i])\n ctx.lineTo(projected.x, projected.y)\n }\n\n ctx.strokeStyle =\n line.strokeColor || defaultColors[lineIndex % defaultColors.length]\n if (line.strokeWidth) {\n ctx.lineWidth = line.strokeWidth * matrix.a\n } else {\n ctx.lineWidth = 2\n }\n ctx.lineCap = \"round\"\n\n if (line.strokeDash) {\n if (typeof line.strokeDash === \"string\") {\n // Convert string to array of numbers, handling single values properly\n let dashArray: number[]\n\n // If the string contains commas, split and convert to numbers\n if (line.strokeDash.includes(\",\")) {\n dashArray = line.strokeDash\n .split(\",\")\n .map((s) => parseFloat(s.trim()))\n .filter((n) => !Number.isNaN(n))\n } else {\n // Handle single value case\n const value = parseFloat(line.strokeDash.trim())\n dashArray = !Number.isNaN(value) ? [value] : []\n }\n\n // Scale dash values based on transform matrix\n ctx.setLineDash(dashArray)\n } else {\n // Handle array format\n ctx.setLineDash(line.strokeDash.map((n) => n * Math.abs(matrix.a)))\n }\n } else {\n ctx.setLineDash([])\n }\n\n ctx.stroke()\n })\n }\n\n if (graphics.infiniteLines && graphics.infiniteLines.length > 0) {\n const viewportBounds = getViewportBoundsFromMatrix(\n matrix,\n canvasWidth,\n canvasHeight,\n )\n\n graphics.infiniteLines.forEach((line, lineIndex) => {\n const segment = clipInfiniteLineToBounds(line, viewportBounds)\n if (!segment) return\n\n const [start, end] = segment\n const projectedStart = applyToPoint(matrix, start)\n const projectedEnd = applyToPoint(matrix, end)\n\n ctx.beginPath()\n ctx.moveTo(projectedStart.x, projectedStart.y)\n ctx.lineTo(projectedEnd.x, projectedEnd.y)\n\n ctx.strokeStyle =\n line.strokeColor || defaultColors[lineIndex % defaultColors.length]\n ctx.lineWidth = line.strokeWidth\n ? line.strokeWidth * Math.abs(matrix.a)\n : 2\n ctx.lineCap = \"round\"\n\n if (line.strokeDash) {\n if (typeof line.strokeDash === \"string\") {\n let dashArray: number[]\n if (line.strokeDash.includes(\",\")) {\n dashArray = line.strokeDash\n .split(\",\")\n .map((s) => parseFloat(s.trim()))\n .filter((n) => !Number.isNaN(n))\n } else {\n const value = parseFloat(line.strokeDash.trim())\n dashArray = !Number.isNaN(value) ? [value] : []\n }\n ctx.setLineDash(dashArray)\n } else {\n ctx.setLineDash(line.strokeDash.map((n) => n * Math.abs(matrix.a)))\n }\n } else {\n ctx.setLineDash([])\n }\n\n ctx.stroke()\n })\n }\n\n // Draw points\n if (graphics.points && graphics.points.length > 0) {\n graphics.points.forEach((point, pointIndex) => {\n const projected = applyToPoint(matrix, point)\n\n // Draw point as a small circle\n ctx.beginPath()\n ctx.arc(projected.x, projected.y, 3, 0, 2 * Math.PI)\n ctx.fillStyle =\n point.color || defaultColors[pointIndex % defaultColors.length]\n ctx.fill()\n\n // Draw label if present and labels aren't disabled\n if (point.label && !options.disableLabels) {\n ctx.fillStyle = point.color || \"black\"\n ctx.font = \"12px sans-serif\"\n ctx.fillText(point.label, projected.x + 5, projected.y - 5)\n }\n })\n }\n\n // Draw texts\n if (graphics.texts && graphics.texts.length > 0) {\n graphics.texts.forEach((text) => {\n const projected = applyToPoint(matrix, { x: text.x, y: text.y })\n ctx.fillStyle = text.color || \"black\"\n ctx.font = `${(text.fontSize ?? 12) * Math.abs(matrix.a)}px sans-serif`\n\n const anchor = text.anchorSide ?? \"center\"\n const alignMap: Record<string, CanvasTextAlign> = {\n top_left: \"left\",\n center_left: \"left\",\n bottom_left: \"left\",\n top_center: \"center\",\n center: \"center\",\n bottom_center: \"center\",\n top_right: \"right\",\n center_right: \"right\",\n bottom_right: \"right\",\n }\n const baselineMap: Record<string, CanvasTextBaseline> = {\n top_left: \"top\",\n top_center: \"top\",\n top_right: \"top\",\n center_left: \"middle\",\n center: \"middle\",\n center_right: \"middle\",\n bottom_left: \"bottom\",\n bottom_center: \"bottom\",\n bottom_right: \"bottom\",\n }\n ctx.textAlign = alignMap[anchor]\n ctx.textBaseline = baselineMap[anchor]\n\n ctx.fillText(text.text, projected.x, projected.y)\n })\n }\n\n // Restore the original transform\n ctx.restore()\n}\n"],"mappings":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AAA,QACX,aAAa;AAAA,QACb,QAAQ;AAAA,QACR,cAAc;AAAA,QACd,aAAa;AAAA,QACb,eAAe;AAAA,QACf,cAAc;AAAA,MAChB;AACA,UAAI,YAAY,SAAS,MAAM;AAC/B,UAAI,eAAe,YAAY,MAAM;AAErC,UAAI,SAAS,KAAK,MAAM,UAAU,GAAG,UAAU,CAAC;AAAA,IAClD,CAAC;AAAA,EACH;AAGA,MAAI,QAAQ;AACd;","names":[]}
|
|
@@ -10,6 +10,11 @@ function setStepOfAllObjects(graphics, step) {
|
|
|
10
10
|
line.step = step;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
if (graphics.infiniteLines) {
|
|
14
|
+
for (const infiniteLine of graphics.infiniteLines) {
|
|
15
|
+
infiniteLine.step = step;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
13
18
|
if (graphics.polygons) {
|
|
14
19
|
for (const polygon of graphics.polygons) {
|
|
15
20
|
polygon.step = step;
|
|
@@ -36,4 +41,4 @@ function setStepOfAllObjects(graphics, step) {
|
|
|
36
41
|
export {
|
|
37
42
|
setStepOfAllObjects
|
|
38
43
|
};
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
44
|
+
//# sourceMappingURL=chunk-OB4CGOL3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/setStepOfAllObjects.ts"],"sourcesContent":["import type { GraphicsObject } from \"./types\"\n\nexport function setStepOfAllObjects(\n graphics: GraphicsObject,\n step: number,\n): GraphicsObject {\n if (graphics.points) {\n for (const p of graphics.points) {\n p.step = step\n }\n }\n if (graphics.lines) {\n for (const line of graphics.lines) {\n line.step = step\n }\n }\n if (graphics.infiniteLines) {\n for (const infiniteLine of graphics.infiniteLines) {\n infiniteLine.step = step\n }\n }\n if (graphics.polygons) {\n for (const polygon of graphics.polygons) {\n polygon.step = step\n }\n }\n if (graphics.rects) {\n for (const rect of graphics.rects) {\n rect.step = step\n }\n }\n if (graphics.circles) {\n for (const circle of graphics.circles) {\n circle.step = step\n }\n }\n if (graphics.texts) {\n for (const text of graphics.texts) {\n text.step = step\n }\n }\n return graphics\n}\n"],"mappings":";AAEO,SAAS,oBACd,UACA,MACgB;AAChB,MAAI,SAAS,QAAQ;AACnB,eAAW,KAAK,SAAS,QAAQ;AAC/B,QAAE,OAAO;AAAA,IACX;AAAA,EACF;AACA,MAAI,SAAS,OAAO;AAClB,eAAW,QAAQ,SAAS,OAAO;AACjC,WAAK,OAAO;AAAA,IACd;AAAA,EACF;AACA,MAAI,SAAS,eAAe;AAC1B,eAAW,gBAAgB,SAAS,eAAe;AACjD,mBAAa,OAAO;AAAA,IACtB;AAAA,EACF;AACA,MAAI,SAAS,UAAU;AACrB,eAAW,WAAW,SAAS,UAAU;AACvC,cAAQ,OAAO;AAAA,IACjB;AAAA,EACF;AACA,MAAI,SAAS,OAAO;AAClB,eAAW,QAAQ,SAAS,OAAO;AACjC,WAAK,OAAO;AAAA,IACd;AAAA,EACF;AACA,MAAI,SAAS,SAAS;AACpB,eAAW,UAAU,SAAS,SAAS;AACrC,aAAO,OAAO;AAAA,IAChB;AAAA,EACF;AACA,MAAI,SAAS,OAAO;AAClB,eAAW,QAAQ,SAAS,OAAO;AACjC,WAAK,OAAO;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -98,9 +98,55 @@ function getArrowBoundingBox(arrow) {
|
|
|
98
98
|
{ minX: Infinity, maxX: -Infinity, minY: Infinity, maxY: -Infinity }
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
|
+
function getInlineLabelLayout(shaftStart, shaftEnd, {
|
|
102
|
+
fontSize = 12,
|
|
103
|
+
strokeWidth = 2,
|
|
104
|
+
normalPadding = 6,
|
|
105
|
+
alongOffset = 0
|
|
106
|
+
} = {}) {
|
|
107
|
+
const midpoint = {
|
|
108
|
+
x: (shaftStart.x + shaftEnd.x) / 2,
|
|
109
|
+
y: (shaftStart.y + shaftEnd.y) / 2
|
|
110
|
+
};
|
|
111
|
+
const dx = shaftEnd.x - shaftStart.x;
|
|
112
|
+
const dy = shaftEnd.y - shaftStart.y;
|
|
113
|
+
const length = Math.hypot(dx, dy);
|
|
114
|
+
if (length === 0) {
|
|
115
|
+
return {
|
|
116
|
+
x: midpoint.x + alongOffset,
|
|
117
|
+
y: midpoint.y - (strokeWidth / 2 + fontSize * 0.65 + normalPadding),
|
|
118
|
+
angleRadians: 0,
|
|
119
|
+
angleDegrees: 0,
|
|
120
|
+
direction: { x: 1, y: 0 },
|
|
121
|
+
normal: { x: 0, y: -1 }
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
let dirX = dx / length;
|
|
125
|
+
let dirY = dy / length;
|
|
126
|
+
let normalX = -dirY;
|
|
127
|
+
let normalY = dirX;
|
|
128
|
+
const isUpsideDown = dirX < 0 || dirX === 0 && dirY < 0;
|
|
129
|
+
if (isUpsideDown) {
|
|
130
|
+
dirX = -dirX;
|
|
131
|
+
dirY = -dirY;
|
|
132
|
+
normalX = -normalX;
|
|
133
|
+
normalY = -normalY;
|
|
134
|
+
}
|
|
135
|
+
const angleRadians = Math.atan2(dirY, dirX);
|
|
136
|
+
const normalOffset = strokeWidth / 2 + fontSize * 0.65 + normalPadding;
|
|
137
|
+
return {
|
|
138
|
+
x: midpoint.x + normalX * normalOffset + dirX * alongOffset,
|
|
139
|
+
y: midpoint.y + normalY * normalOffset + dirY * alongOffset,
|
|
140
|
+
angleRadians,
|
|
141
|
+
angleDegrees: angleRadians * 180 / Math.PI,
|
|
142
|
+
direction: { x: dirX, y: dirY },
|
|
143
|
+
normal: { x: normalX, y: normalY }
|
|
144
|
+
};
|
|
145
|
+
}
|
|
101
146
|
|
|
102
147
|
export {
|
|
103
148
|
getArrowGeometry,
|
|
104
|
-
getArrowBoundingBox
|
|
149
|
+
getArrowBoundingBox,
|
|
150
|
+
getInlineLabelLayout
|
|
105
151
|
};
|
|
106
|
-
//# sourceMappingURL=chunk-
|
|
152
|
+
//# sourceMappingURL=chunk-PCHDJSKZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../lib/arrowHelpers.ts"],"sourcesContent":["import type { Arrow } from \"./types\"\n\nconst DEFAULT_ARROW_SHAFT_WIDTH = 2\nconst DEFAULT_ARROW_HEAD_WIDTH = 12\nconst DEFAULT_ARROW_HEAD_LENGTH = 12\n\nexport type ArrowHeadGeometry = {\n tip: { x: number; y: number }\n base: { x: number; y: number }\n leftWing: { x: number; y: number }\n rightWing: { x: number; y: number }\n}\n\nexport type ArrowGeometry = {\n shaftStart: { x: number; y: number }\n shaftEnd: { x: number; y: number }\n heads: ArrowHeadGeometry[]\n shaftWidth: number\n headLength: number\n headWidth: number\n length: number\n}\n\nexport type InlineLabelLayout = {\n x: number\n y: number\n angleRadians: number\n angleDegrees: number\n direction: { x: number; y: number }\n normal: { x: number; y: number }\n}\n\nconst createDegenerateHead = (point: {\n x: number\n y: number\n}): ArrowHeadGeometry => ({\n tip: { ...point },\n base: { ...point },\n leftWing: { ...point },\n rightWing: { ...point },\n})\n\nconst createHead = (\n tip: { x: number; y: number },\n base: { x: number; y: number },\n headWidth: number,\n): ArrowHeadGeometry => {\n const dirX = tip.x - base.x\n const dirY = tip.y - base.y\n const length = Math.hypot(dirX, dirY)\n\n if (length === 0) {\n return createDegenerateHead(tip)\n }\n\n const dirUnitX = dirX / length\n const dirUnitY = dirY / length\n const perpX = -dirUnitY * (headWidth / 2)\n const perpY = dirUnitX * (headWidth / 2)\n\n return {\n tip: { ...tip },\n base: { ...base },\n leftWing: { x: base.x + perpX, y: base.y + perpY },\n rightWing: { x: base.x - perpX, y: base.y - perpY },\n }\n}\n\nexport function getArrowGeometry(arrow: Arrow): ArrowGeometry {\n const { start, end } = arrow\n\n const vx = end.x - start.x\n const vy = end.y - start.y\n const length = Math.hypot(vx, vy)\n\n const shaftWidth = DEFAULT_ARROW_SHAFT_WIDTH\n const headWidth = DEFAULT_ARROW_HEAD_WIDTH\n\n if (length === 0) {\n const heads = arrow.doubleSided\n ? [createDegenerateHead(start), createDegenerateHead(start)]\n : [createDegenerateHead(start)]\n return {\n shaftStart: { ...start },\n shaftEnd: { ...start },\n heads,\n shaftWidth,\n headLength: 0,\n headWidth,\n length,\n }\n }\n\n const ux = vx / length\n const uy = vy / length\n\n const baseHeadLength = Math.min(DEFAULT_ARROW_HEAD_LENGTH, length * 0.5)\n const desiredHeadLength = Math.max(baseHeadLength, shaftWidth * 2)\n const maxHeadLength = arrow.doubleSided ? length / 2 : length\n const headLength = Math.min(desiredHeadLength, maxHeadLength)\n\n const endHeadBase = {\n x: end.x - ux * headLength,\n y: end.y - uy * headLength,\n }\n\n const heads: ArrowHeadGeometry[] = [createHead(end, endHeadBase, headWidth)]\n\n let shaftStart = { ...start }\n const shaftEnd = { ...endHeadBase }\n\n if (arrow.doubleSided) {\n const startHeadBase = {\n x: start.x + ux * headLength,\n y: start.y + uy * headLength,\n }\n\n heads.unshift(createHead(start, startHeadBase, headWidth))\n shaftStart = startHeadBase\n }\n\n return {\n shaftStart,\n shaftEnd,\n heads,\n shaftWidth,\n headLength,\n headWidth,\n length,\n }\n}\n\nexport function getArrowBoundingBox(arrow: Arrow) {\n const geometry = getArrowGeometry(arrow)\n const points = [\n geometry.shaftStart,\n geometry.shaftEnd,\n ...geometry.heads.flatMap((head) => [\n head.tip,\n head.base,\n head.leftWing,\n head.rightWing,\n ]),\n ]\n\n return points.reduce(\n (acc, point) => ({\n minX: Math.min(acc.minX, point.x),\n maxX: Math.max(acc.maxX, point.x),\n minY: Math.min(acc.minY, point.y),\n maxY: Math.max(acc.maxY, point.y),\n }),\n { minX: Infinity, maxX: -Infinity, minY: Infinity, maxY: -Infinity },\n )\n}\n\nexport function getInlineLabelLayout(\n shaftStart: { x: number; y: number },\n shaftEnd: { x: number; y: number },\n {\n fontSize = 12,\n strokeWidth = 2,\n normalPadding = 6,\n alongOffset = 0,\n }: {\n fontSize?: number\n strokeWidth?: number\n normalPadding?: number\n alongOffset?: number\n } = {},\n): InlineLabelLayout {\n const midpoint = {\n x: (shaftStart.x + shaftEnd.x) / 2,\n y: (shaftStart.y + shaftEnd.y) / 2,\n }\n const dx = shaftEnd.x - shaftStart.x\n const dy = shaftEnd.y - shaftStart.y\n const length = Math.hypot(dx, dy)\n\n if (length === 0) {\n return {\n x: midpoint.x + alongOffset,\n y: midpoint.y - (strokeWidth / 2 + fontSize * 0.65 + normalPadding),\n angleRadians: 0,\n angleDegrees: 0,\n direction: { x: 1, y: 0 },\n normal: { x: 0, y: -1 },\n }\n }\n\n let dirX = dx / length\n let dirY = dy / length\n let normalX = -dirY\n let normalY = dirX\n\n const isUpsideDown = dirX < 0 || (dirX === 0 && dirY < 0)\n if (isUpsideDown) {\n dirX = -dirX\n dirY = -dirY\n normalX = -normalX\n normalY = -normalY\n }\n\n const angleRadians = Math.atan2(dirY, dirX)\n const normalOffset = strokeWidth / 2 + fontSize * 0.65 + normalPadding\n\n return {\n x: midpoint.x + normalX * normalOffset + dirX * alongOffset,\n y: midpoint.y + normalY * normalOffset + dirY * alongOffset,\n angleRadians,\n angleDegrees: (angleRadians * 180) / Math.PI,\n direction: { x: dirX, y: dirY },\n normal: { x: normalX, y: normalY },\n }\n}\n"],"mappings":";AAEA,IAAM,4BAA4B;AAClC,IAAM,2BAA2B;AACjC,IAAM,4BAA4B;AA4BlC,IAAM,uBAAuB,CAAC,WAGJ;AAAA,EACxB,KAAK,EAAE,GAAG,MAAM;AAAA,EAChB,MAAM,EAAE,GAAG,MAAM;AAAA,EACjB,UAAU,EAAE,GAAG,MAAM;AAAA,EACrB,WAAW,EAAE,GAAG,MAAM;AACxB;AAEA,IAAM,aAAa,CACjB,KACA,MACA,cACsB;AACtB,QAAM,OAAO,IAAI,IAAI,KAAK;AAC1B,QAAM,OAAO,IAAI,IAAI,KAAK;AAC1B,QAAM,SAAS,KAAK,MAAM,MAAM,IAAI;AAEpC,MAAI,WAAW,GAAG;AAChB,WAAO,qBAAqB,GAAG;AAAA,EACjC;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|
6
|
+
} from "./chunk-7236NVI2.js";
|
|
7
7
|
import {
|
|
8
8
|
getBounds
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-ME47RV6O.js";
|
|
10
10
|
|
|
11
11
|
// lib/stackGraphics.ts
|
|
12
12
|
function stackGraphicsHorizontally(graphicsList, opts = {}) {
|
|
@@ -118,4 +118,4 @@ export {
|
|
|
118
118
|
stackGraphicsVertically,
|
|
119
119
|
createGraphicsGrid
|
|
120
120
|
};
|
|
121
|
-
//# sourceMappingURL=chunk-
|
|
121
|
+
//# sourceMappingURL=chunk-PEHHGMS7.js.map
|