@@ -30,10 +30,18 @@ export const getOffsetFromId = (id: string, max: number) => {
3030
3131export const rounded = ( value : number ) => Math . round ( value * 2 ) / 2 ;
3232
33- export const addBlankSpaceToPath = ( currentX : number , height : number ) => {
33+ export const addBlankSpaceToPath = (
34+ currentX : number ,
35+ maxWidth : number ,
36+ height : number
37+ ) => {
3438 currentX += SPACE_WIDTH ;
39+
40+ // We don't want to go out of the area, if not transformer won't work well
41+ const adjustedEndX = Math . min ( currentX , maxWidth ) ;
42+
3543 return {
36- pathSlice : `M ${ currentX } ,${ height / 2 } ` ,
44+ pathSlice : `M ${ adjustedEndX } ,${ height / 2 } ` ,
3745 newCurrentX : currentX ,
3846 } ;
3947} ;
@@ -42,6 +50,7 @@ const drawCharScribble = (
4250 char : string ,
4351 i : number ,
4452 currentX : number ,
53+ maxWidth : number ,
4554 height : number
4655) => {
4756 const amplitude = height / 3 ;
@@ -61,8 +70,11 @@ const drawCharScribble = (
6170 const endX = currentX + charWidth ;
6271 const endY = height / 2 ;
6372
73+ // We don't want to go out of the area, if not transformer won't work well
74+ const adjustedEndX = Math . min ( endX , maxWidth ) ;
75+
6476 return {
65- pathSegment : `C ${ controlX1 } ,${ controlY1 } ${ controlX2 } ,${ controlY2 } ${ endX } ,${ endY } ` ,
77+ pathSegment : `C ${ controlX1 } ,${ controlY1 } ${ controlX2 } ,${ controlY2 } ${ adjustedEndX } ,${ endY } ` ,
6678 endX,
6779 } ;
6880} ;
@@ -86,12 +98,22 @@ export const calculatePath = (width: number, height: number, id: string) => {
8698
8799 if ( char !== ' ' ) {
88100 // Draw the character scribble
89- const { pathSegment, endX } = drawCharScribble ( char , i , currentX , height ) ;
101+ const { pathSegment, endX } = drawCharScribble (
102+ char ,
103+ i ,
104+ currentX ,
105+ width ,
106+ height
107+ ) ;
90108 path . push ( pathSegment ) ;
91109 currentX = endX ;
92110 } else {
93111 // If it's a space, we need to add a blank space to the path
94- const { pathSlice, newCurrentX } = addBlankSpaceToPath ( currentX , height ) ;
112+ const { pathSlice, newCurrentX } = addBlankSpaceToPath (
113+ currentX ,
114+ width ,
115+ height
116+ ) ;
95117 path . push ( pathSlice ) ;
96118 currentX = newCurrentX ;
97119 }
0 commit comments