Skip to content

Commit 114c1ac

Browse files
committed
fix: add warnings for no shape data back
1 parent 304e13e commit 114c1ac

File tree

16 files changed

+191
-66
lines changed

16 files changed

+191
-66
lines changed

package-lock.json

Lines changed: 62 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@
1111
"preview": "vite preview",
1212
"stats": "npx cloc ./src",
1313
"check-types": "tsc -p tsconfig.app.json --noEmit",
14-
"test": "vitest"
14+
"test": "vitest",
15+
"postinstall": "npx patch-package"
1516
},
1617
"dependencies": {
17-
"@flatten-js/core": "^1.6.1",
18+
"@flatten-js/core": "^1.6.2",
19+
"blend-promise-utils": "^1.29.2",
1820
"blob-stream": "^0.1.3",
1921
"clsx": "^2.1.1",
2022
"es-toolkit": "^1.16.0",
2123
"file-saver": "^2.0.5",
22-
"jspdf": "^2.5.2",
24+
"jspdf": "^3.0.1",
2325
"react": "^18.3.1",
2426
"react-dom": "^18.3.1",
27+
"react-toastify": "^11.0.5",
2528
"svg-parser": "^2.0.4",
2629
"svg2pdf.js": "^2.5.0",
2730
"teenyicons": "^0.4.1",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
diff --git a/node_modules/@flatten-js/core/dist/main.cjs b/node_modules/@flatten-js/core/dist/main.cjs
2+
index 9ed46e1..d6b1b59 100644
3+
--- a/node_modules/@flatten-js/core/dist/main.cjs
4+
+++ b/node_modules/@flatten-js/core/dist/main.cjs
5+
@@ -6601,7 +6601,7 @@ class Box extends Shape {
6+
7+
if (shape instanceof Flatten.Arc) {
8+
return shape.vertices.every(vertex => this.contains(vertex)) &&
9+
- shape.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0)
10+
+ this.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0)
11+
}
12+
13+
if (shape instanceof Flatten.Line || shape instanceof Flatten.Ray) {
14+
diff --git a/node_modules/@flatten-js/core/dist/main.mjs b/node_modules/@flatten-js/core/dist/main.mjs
15+
index 0d1bec8..12eb0a2 100644
16+
--- a/node_modules/@flatten-js/core/dist/main.mjs
17+
+++ b/node_modules/@flatten-js/core/dist/main.mjs
18+
@@ -6597,7 +6597,7 @@ class Box extends Shape {
19+
20+
if (shape instanceof Flatten.Arc) {
21+
return shape.vertices.every(vertex => this.contains(vertex)) &&
22+
- shape.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0)
23+
+ this.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0)
24+
}
25+
26+
if (shape instanceof Flatten.Line || shape instanceof Flatten.Ray) {
27+
diff --git a/node_modules/@flatten-js/core/dist/main.umd.js b/node_modules/@flatten-js/core/dist/main.umd.js
28+
index a886341..8a0b6bb 100644
29+
--- a/node_modules/@flatten-js/core/dist/main.umd.js
30+
+++ b/node_modules/@flatten-js/core/dist/main.umd.js
31+
@@ -6603,7 +6603,7 @@
32+
33+
if (shape instanceof Flatten.Arc) {
34+
return shape.vertices.every(vertex => this.contains(vertex)) &&
35+
- shape.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0)
36+
+ this.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0)
37+
}
38+
39+
if (shape instanceof Flatten.Line || shape instanceof Flatten.Ray) {
40+
diff --git a/node_modules/@flatten-js/core/src/classes/box.js b/node_modules/@flatten-js/core/src/classes/box.js
41+
index af21b93..be48775 100644
42+
--- a/node_modules/@flatten-js/core/src/classes/box.js
43+
+++ b/node_modules/@flatten-js/core/src/classes/box.js
44+
@@ -269,7 +269,7 @@ export class Box extends Shape {
45+
46+
if (shape instanceof Flatten.Arc) {
47+
return shape.vertices.every(vertex => this.contains(vertex)) &&
48+
- shape.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0)
49+
+ this.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0)
50+
}
51+
52+
if (shape instanceof Flatten.Line || shape instanceof Flatten.Ray) {

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import './App.css';
2+
import {ToastContainer} from 'react-toastify';
23
import {Toolbar} from './components/Toolbar.tsx';
34

45
function App() {
56
return (
67
<div className="overflow-y-scroll h-lvh pb-12 w-80" style={{ scrollbarWidth: 'none' }}>
78
<Toolbar />
9+
<ToastContainer position="bottom-right" theme="light" />
810
</div>
911
);
1012
}

src/entities/ArcEntity.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ export class ArcEntity implements Entity {
239239
throw new Error('Invalid Entity type in JSON');
240240
}
241241

242+
if (!jsonEntity.shapeData) {
243+
throw new Error('Invalid JSON entity of type Arc: missing shapeData');
244+
}
245+
242246
const center = new Point(
243247
jsonEntity.shapeData.center.x,
244248
jsonEntity.shapeData.center.y,

src/entities/ArrowHeadEntity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ export class ArrowHeadEntity implements Entity {
140140
public static async fromJson(
141141
jsonEntity: JsonEntity<ArrowHeadJsonData>
142142
): Promise<ArrowHeadEntity> {
143+
if (!jsonEntity.shapeData) {
144+
throw new Error('Invalid JSON entity of type Arrow: missing shapeData');
145+
}
143146
const p1 = new Point(jsonEntity.shapeData.p1.x, jsonEntity.shapeData.p1.y);
144147
const p2 = new Point(jsonEntity.shapeData.p2.x, jsonEntity.shapeData.p2.y);
145148
const p3 = new Point(jsonEntity.shapeData.p3.x, jsonEntity.shapeData.p3.y);

src/entities/CircleEntity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ export class CircleEntity implements Entity {
205205
public static async fromJson(
206206
jsonEntity: JsonEntity<CircleJsonData>,
207207
): Promise<CircleEntity> {
208+
if (!jsonEntity.shapeData) {
209+
throw new Error('Invalid JSON entity of type Circle: missing shapeData');
210+
}
208211
const center = new Point(
209212
jsonEntity.shapeData.center.x,
210213
jsonEntity.shapeData.center.y,

src/entities/ImageEntity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ export class ImageEntity implements Entity {
221221
}
222222

223223
public static async fromJson(jsonEntity: JsonEntity<ImageJsonData>): Promise<ImageEntity> {
224+
if (!jsonEntity.shapeData) {
225+
throw new Error('Invalid JSON entity of type Image: missing shapeData');
226+
}
224227
const rectangle = new Polygon(
225228
jsonEntity.shapeData.points.map((point) => new Point(point.x, point.y))
226229
);

src/entities/LineEntity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ export class LineEntity implements Entity {
186186
}
187187

188188
public static async fromJson(jsonEntity: JsonEntity<LineJsonData>): Promise<LineEntity> {
189+
if (!jsonEntity.shapeData) {
190+
throw new Error('Invalid JSON entity of type Line: missing shapeData');
191+
}
189192
const startPoint = new Point(
190193
jsonEntity.shapeData.startPoint.x,
191194
jsonEntity.shapeData.startPoint.y

src/entities/MeasurementEntity.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import {Box, Line, Point, Segment, Vector} from '@flatten-js/core';
22
import {minBy, round} from 'es-toolkit';
33
import {max, min} from 'es-toolkit/compat';
44
import {
5-
ARROW_HEAD_LENGTH,
6-
ARROW_HEAD_WIDTH,
7-
MEASUREMENT_DECIMAL_PLACES,
8-
MEASUREMENT_EXTENSION_LENGTH,
9-
MEASUREMENT_FONT_SIZE,
10-
MEASUREMENT_LABEL_OFFSET,
11-
MEASUREMENT_ORIGIN_MARGIN,
12-
TO_RADIANS,
5+
ARROW_HEAD_LENGTH,
6+
ARROW_HEAD_WIDTH,
7+
MEASUREMENT_DECIMAL_PLACES,
8+
MEASUREMENT_EXTENSION_LENGTH,
9+
MEASUREMENT_FONT_SIZE,
10+
MEASUREMENT_LABEL_OFFSET,
11+
MEASUREMENT_ORIGIN_MARGIN,
12+
TO_RADIANS,
1313
} from '../App.consts';
1414
import type {Shape, SnapPoint} from '../App.types';
1515
import type {DrawController} from '../drawControllers/DrawController';
@@ -381,6 +381,9 @@ export class MeasurementEntity implements Entity {
381381
public static async fromJson(
382382
jsonEntity: JsonEntity<MeasurementJsonData>
383383
): Promise<MeasurementEntity> {
384+
if (!jsonEntity.shapeData) {
385+
throw new Error('Invalid JSON entity of type Measurement: missing shapeData');
386+
}
384387
const startPoint = new Point(
385388
jsonEntity.shapeData.startPoint.x,
386389
jsonEntity.shapeData.startPoint.y

0 commit comments

Comments
 (0)