@@ -30,17 +30,17 @@ import {
30
30
getDashArrayDashed ,
31
31
getDashArrayDotted ,
32
32
RECT_CORNER_RADIUS_FACTOR ,
33
+ ROUND_RADIUS_FACTOR ,
33
34
WS_URL ,
34
35
} from "@/config/constants" ;
35
36
import { MessageQueue } from "./MessageQueue" ;
36
37
import { decryptData , encryptData } from "@/utils/crypto" ;
37
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
38
- // @ts -expect-error
39
- import { RoughCanvas } from "roughjs/canvas" ;
40
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
41
- // @ts -expect-error
42
- import { Options } from "roughjs/core" ;
38
+
43
39
import rough from "roughjs/bin/rough" ;
40
+ import { RoughCanvas } from "roughjs/bin/canvas" ;
41
+ import { Options } from "roughjs/bin/core" ;
42
+ import type { Point } from "roughjs/bin/geometry" ;
43
+
44
44
import { getFontSize , getLineHeight } from "@/utils/textUtils" ;
45
45
import { generateFreeDrawPath } from "./RenderElements" ;
46
46
@@ -382,11 +382,15 @@ export class CanvasEngine {
382
382
bgFill ?: string ,
383
383
strokeStyle ?: StrokeStyle ,
384
384
fillStyle ?: FillStyle ,
385
- hachureAngle : number = 60
385
+ hachureAngle : number = 60 ,
386
+ shapeType ?: Shape [ "type" ]
386
387
) : Options {
388
+ const isCurveSensitive =
389
+ shapeType === "ellipse" || shapeType === "free-draw" ;
390
+
387
391
const options : Options = {
388
392
stroke : strokeFill ,
389
- strokeWidth : strokeStyle !== "solid" ? strokeWidth + 0.5 : strokeWidth ,
393
+ strokeWidth : strokeStyle !== "solid" ? strokeWidth + 0.6 : strokeWidth ,
390
394
roughness : roughStyle ,
391
395
bowing : roughStyle === 0 ? 0 : 0.5 * roughStyle ,
392
396
fill : bgFill ?? "" ,
@@ -403,16 +407,26 @@ export class CanvasEngine {
403
407
: strokeStyle === "dotted"
404
408
? getDashArrayDotted ( strokeWidth )
405
409
: undefined ,
410
+ dashOffset :
411
+ strokeStyle === "dashed" ? 5 : strokeStyle === "dotted" ? 2 : undefined ,
412
+ ...( isCurveSensitive
413
+ ? { }
414
+ : {
415
+ curveFitting : 1 ,
416
+ curveTightness : 1 ,
417
+ preserveVertices : true ,
418
+ } ) ,
419
+
420
+ // Ensure the sketchy path closely follows the original shape with minimal deviation
421
+ // curveFitting: 1,
422
+
423
+ // Tightens the curves around corner control points for smoother rounded corners
424
+ // curveTightness: 1,
425
+
426
+ // Prevents Rough.js from altering the actual vertex points — keeps the shape precise
427
+ // preserveVertices: true,
406
428
} ;
407
429
408
- if ( strokeStyle === "dashed" ) {
409
- options . dashOffset = 5 ;
410
- options . dashArray = getDashArrayDashed ( strokeWidth ) ;
411
- } else if ( strokeStyle === "dotted" ) {
412
- options . dashOffset = 2 ;
413
- options . dashArray = getDashArrayDotted ( strokeWidth ) ;
414
- }
415
-
416
430
return options ;
417
431
}
418
432
@@ -1369,28 +1383,19 @@ export class CanvasEngine {
1369
1383
) ;
1370
1384
1371
1385
if ( rounded === "round" ) {
1372
- const radius = Math . min (
1373
- Math . abs (
1374
- Math . max ( normalizedWidth , normalizedHeight ) /
1375
- RECT_CORNER_RADIUS_FACTOR
1376
- ) ,
1377
- normalizedWidth / 2 ,
1378
- normalizedHeight / 2
1379
- ) ;
1380
- options . curveFitting = 1 ;
1381
- options . curveTightness = 1 ;
1386
+ const r = Math . min ( normalizedWidth , normalizedHeight ) * ROUND_RADIUS_FACTOR ;
1382
1387
1383
1388
this . roughCanvas . path (
1384
- `M ${ posX + radius } ${ posY }
1385
- L ${ posX + normalizedWidth - radius } ${ posY }
1386
- Q ${ posX + normalizedWidth } ${ posY } ${ posX + normalizedWidth } ${ posY + radius }
1387
- L ${ posX + normalizedWidth } ${ posY + normalizedHeight - radius }
1388
- Q ${ posX + normalizedWidth } ${ posY + normalizedHeight } ${ posX + normalizedWidth - radius } ${ posY + normalizedHeight }
1389
- L ${ posX + radius } ${ posY + normalizedHeight }
1390
- Q ${ posX } ${ posY + normalizedHeight } ${ posX } ${ posY + normalizedHeight - radius }
1391
- L ${ posX } ${ posY + radius }
1392
- Q ${ posX } ${ posY } ${ posX + radius } ${ posY }
1393
- Z` ,
1389
+ `M ${ posX + r } ${ posY }
1390
+ L ${ posX + normalizedWidth - r } ${ posY }
1391
+ Q ${ posX + normalizedWidth } ${ posY } , ${ posX + normalizedWidth } ${ posY + r }
1392
+ L ${ posX + normalizedWidth } ${ posY + normalizedHeight - r }
1393
+ Q ${ posX + normalizedWidth } ${ posY + normalizedHeight } , ${ posX + normalizedWidth - r } ${ posY + normalizedHeight }
1394
+ L ${ posX + r } ${ posY + normalizedHeight }
1395
+ Q ${ posX } ${ posY + normalizedHeight } , ${ posX } ${ posY + normalizedHeight - r }
1396
+ L ${ posX } ${ posY + r }
1397
+ Q ${ posX } ${ posY } , ${ posX + r } ${ posY }
1398
+ Z` ,
1394
1399
options
1395
1400
) ;
1396
1401
} else {
@@ -1447,7 +1452,9 @@ export class CanvasEngine {
1447
1452
roughStyle ,
1448
1453
bgFill ,
1449
1454
strokeStyle ,
1450
- fillStyle
1455
+ fillStyle ,
1456
+ 60 ,
1457
+ "ellipse"
1451
1458
) ;
1452
1459
this . roughCanvas . ellipse (
1453
1460
x ,
@@ -1589,7 +1596,7 @@ export class CanvasEngine {
1589
1596
fillStyle
1590
1597
) ;
1591
1598
1592
- const diamondPoints = [
1599
+ const diamondPoints : Point [ ] = [
1593
1600
[ centerX , centerY - halfHeight ] ,
1594
1601
[ centerX + halfWidth , centerY ] ,
1595
1602
[ centerX , centerY + halfHeight ] ,
0 commit comments