Skip to content

Commit 7be30bf

Browse files
committed
refactor: let user decide about export quality, backgrounds and margins
1 parent 80c4070 commit 7be30bf

File tree

5 files changed

+54
-44
lines changed

5 files changed

+54
-44
lines changed

docs/tdev/gallery/tools/image-markup/images/demo.svg

Lines changed: 2 additions & 2 deletions
Loading

docs/tdev/gallery/tools/image-markup/images/demo.svg.excalidraw

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22
"type": "excalidraw",
33
"version": 2,
44
"elements": [
5+
{
6+
"id": "TDEV-STANDALONE-DRAWING",
7+
"type": "rectangle",
8+
"x": -423.0333231608073,
9+
"y": -271.4722315470378,
10+
"width": 833.3333129882812,
11+
"height": 530.6666870117188,
12+
"strokeColor": "#1e1e1ea1",
13+
"backgroundColor": "transparent",
14+
"fillStyle": "solid",
15+
"strokeWidth": 0.05,
16+
"strokeStyle": "dotted",
17+
"roughness": 0,
18+
"opacity": 100,
19+
"locked": true,
20+
"version": 2,
21+
"versionNonce": 943970152,
22+
"index": "Zz",
23+
"isDeleted": false,
24+
"angle": 0,
25+
"seed": 1,
26+
"groupIds": [],
27+
"frameId": null,
28+
"roundness": null,
29+
"boundElements": [],
30+
"updated": 1763308684156,
31+
"link": null
32+
},
533
{
634
"id": "IuZRsqPjub8yxxLCdL9gL",
735
"type": "diamond",
@@ -24,11 +52,11 @@
2452
"type": 2
2553
},
2654
"seed": 306917131,
27-
"version": 56,
28-
"versionNonce": 2025318123,
55+
"version": 59,
56+
"versionNonce": 1746086936,
2957
"isDeleted": false,
3058
"boundElements": [],
31-
"updated": 1755449004392,
59+
"updated": 1763308785072,
3260
"link": null,
3361
"locked": false
3462
},

packages/tdev/excalidoc/ImageMarkupEditor/helpers/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export const EXCALIDRAW_STANDALONE_DRAWING_RECTANGLE = {
4848
y: 0,
4949
width: 400,
5050
height: 300,
51-
strokeColor: '#1e1e1e',
51+
strokeColor: '#1e1e1ea1',
5252
backgroundColor: 'transparent',
5353
fillStyle: 'solid',
54-
strokeWidth: 1,
54+
strokeWidth: 0.05,
5555
strokeStyle: 'dotted',
5656
roughness: 0,
5757
opacity: 100,

packages/tdev/excalidoc/ImageMarkupEditor/helpers/createExcalidrawMarkup.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
EXCALIDRAW_BACKGROUND_IMAGE,
1212
EXCALIDRAW_MAX_WIDTH,
1313
CustomData,
14-
EXCALIDRAW_STANDALONE_DRAWING_ID
14+
EXCALIDRAW_STANDALONE_DRAWING_ID,
15+
EXCALIDRAW_STANDALONE_DRAWING_RECTANGLE
1516
} from './constants';
1617
import { withoutMetaElements } from './getElementsFromScene';
1718
import { getBoundingRect } from './getBoundingRect';
@@ -68,6 +69,8 @@ const handleStandaloneDrawing = (excalidrawState: ExcalidrawInitialDataState): E
6869

6970
(excalidrawState.elements as ExcalidrawElement[]).splice(standaloneDrawingIdx, 1, {
7071
...excalidrawState.elements[standaloneDrawingIdx],
72+
strokeWidth: EXCALIDRAW_STANDALONE_DRAWING_RECTANGLE.strokeWidth,
73+
strokeColor: EXCALIDRAW_STANDALONE_DRAWING_RECTANGLE.strokeColor,
7174
width,
7275
height,
7376
x: x,
@@ -82,13 +85,19 @@ export const updateRectangleDimensions = (
8285
if (!excalidrawState.elements) {
8386
return excalidrawState;
8487
}
85-
const isStandaloneDrawing = excalidrawState.elements.some(
86-
(e) => e.id === EXCALIDRAW_STANDALONE_DRAWING_ID
87-
);
88-
if (isStandaloneDrawing) {
88+
const backgroundImage = excalidrawState.elements.find((e) => e.id === EXCALIDRAW_BACKGROUND_IMAGE_ID);
89+
if (!backgroundImage) {
90+
const isStandaloneDrawing = excalidrawState.elements.some(
91+
(e) => e.id === EXCALIDRAW_STANDALONE_DRAWING_ID
92+
);
93+
if (!isStandaloneDrawing) {
94+
// add standalone markup drawing rectangle
95+
(excalidrawState.elements as ExcalidrawElement[]).splice(0, 0, {
96+
...EXCALIDRAW_STANDALONE_DRAWING_RECTANGLE
97+
});
98+
}
8999
return handleStandaloneDrawing(excalidrawState);
90100
}
91-
const backgroundImage = excalidrawState.elements.find((e) => e.id === EXCALIDRAW_BACKGROUND_IMAGE_ID);
92101
if (!backgroundImage || backgroundImage.type !== 'image') {
93102
return excalidrawState;
94103
}

packages/tdev/excalidoc/ImageMarkupEditor/helpers/getBoundingRect.ts

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,14 @@ interface Rect {
77
height: number;
88
}
99

10-
const extractMinX = (element: ExcalidrawFreeDrawElement): number => {
11-
const xs = element.points.map((p) => p[0]);
12-
return Math.min(...xs) + element.x - 2 * element.strokeWidth;
13-
};
14-
15-
const extractMaxX = (element: ExcalidrawFreeDrawElement): number => {
16-
return element.x + element.width;
17-
};
18-
19-
const extractMinY = (element: ExcalidrawFreeDrawElement): number => {
20-
const ys = element.points.map((p) => p[1]);
21-
return element.y + element.height - Math.abs(Math.max(...ys)) - 2.1 * element.strokeWidth;
22-
};
23-
24-
const extractMaxY = (element: ExcalidrawFreeDrawElement): number => {
25-
const ys = element.points.map((p) => p[1]);
26-
return element.y + Math.max(...ys) + 2.1 * element.strokeWidth;
27-
};
28-
2910
export const getBoundingRect = (elements: readonly ExcalidrawElement[]): Rect => {
3011
if (elements.length === 0) {
3112
return { x: 0, y: 0, width: 400, height: 300 };
3213
}
33-
const minX = Math.min(
34-
...elements.map((e) => (e.type === 'freedraw' ? extractMinX(e) : e.x - e.strokeWidth / 2))
35-
);
36-
const minY = Math.min(
37-
...elements.map((e) => (e.type === 'freedraw' ? extractMinY(e) : e.y - e.strokeWidth / 2))
38-
);
39-
const maxX = Math.max(
40-
...elements.map((e) => (e.type === 'freedraw' ? extractMaxX(e) : e.x + e.width + e.strokeWidth / 2))
41-
);
42-
const maxY = Math.max(
43-
...elements.map((e) => (e.type === 'freedraw' ? extractMaxY(e) : e.y + e.height + e.strokeWidth / 2))
44-
);
14+
const minX = Math.min(...elements.map((e) => e.x - e.strokeWidth / 2));
15+
const minY = Math.min(...elements.map((e) => e.y - e.strokeWidth / 2));
16+
const maxX = Math.max(...elements.map((e) => e.x + e.width + e.strokeWidth / 2));
17+
const maxY = Math.max(...elements.map((e) => e.y + e.height + e.strokeWidth / 2));
4518
return {
4619
x: minX,
4720
y: minY,

0 commit comments

Comments
 (0)