@@ -16,7 +16,13 @@ import type {
1616
1717import { resolveAnnotationSubmission } from "./AnnotationKeyboard.ts" ;
1818import type { StrokeGeometry } from "./AnnotationStroke.ts" ;
19- import { beginStroke , extendStroke , strokeBounds , strokePath } from "./AnnotationStroke.ts" ;
19+ import {
20+ beginStroke ,
21+ extendStroke ,
22+ strokeBounds ,
23+ strokeChunkPath ,
24+ takeClosedChunk ,
25+ } from "./AnnotationStroke.ts" ;
2026import { previewAnnotationStyles } from "./AnnotationStyles.generated.ts" ;
2127import {
2228 ANNOTATION_CAPTURED_CHANNEL ,
@@ -457,7 +463,8 @@ function startAnnotation(): void {
457463 let dragStart : PreviewAnnotationPoint | null = null ;
458464 let activeStroke : {
459465 target : PreviewAnnotationStrokeTarget ;
460- path : SVGPathElement ;
466+ group : SVGGElement ;
467+ chunkPath : SVGPathElement ;
461468 geometry : StrokeGeometry ;
462469 } | null = null ;
463470 let pendingCapture = false ;
@@ -1052,7 +1059,16 @@ function startAnnotation(): void {
10521059 if ( tool === "draw" && activeStroke ) {
10531060 extendStroke ( activeStroke . geometry , { x : event . clientX , y : event . clientY } ) ;
10541061 activeStroke . target . bounds = strokeBounds ( activeStroke . geometry , activeStroke . target . width ) ;
1055- activeStroke . path . setAttribute ( "d" , strokePath ( activeStroke . geometry ) ) ;
1062+ // Only the growing chunk's `d` is ever rewritten, so the renderer never
1063+ // re-parses more than one chunk of path text per move.
1064+ const closedChunk = takeClosedChunk ( activeStroke . geometry ) ;
1065+ if ( closedChunk !== null ) {
1066+ activeStroke . chunkPath . setAttribute ( "d" , closedChunk ) ;
1067+ const nextChunk = document . createElementNS ( "http://www.w3.org/2000/svg" , "path" ) ;
1068+ activeStroke . group . appendChild ( nextChunk ) ;
1069+ activeStroke . chunkPath = nextChunk ;
1070+ }
1071+ activeStroke . chunkPath . setAttribute ( "d" , strokeChunkPath ( activeStroke . geometry ) ) ;
10561072 }
10571073 } ;
10581074
@@ -1079,16 +1095,18 @@ function startAnnotation(): void {
10791095 points : geometry . points ,
10801096 bounds : { x : dragStart . x , y : dragStart . y , width : 1 , height : 1 } ,
10811097 } ;
1082- const path = document . createElementNS ( "http://www.w3.org/2000/svg" , "path" ) ;
1083- path . setAttribute ( OVERLAY_ATTRIBUTE , "" ) ;
1084- path . setAttribute ( "data-stroke-id" , stroke . id ) ;
1085- path . setAttribute ( "fill" , "none" ) ;
1086- path . setAttribute ( "stroke" , stroke . color ) ;
1087- path . setAttribute ( "stroke-width" , String ( stroke . width ) ) ;
1088- path . setAttribute ( "stroke-linecap" , "round" ) ;
1089- path . setAttribute ( "stroke-linejoin" , "round" ) ;
1090- svg . appendChild ( path ) ;
1091- activeStroke = { target : stroke , path, geometry } ;
1098+ const group = document . createElementNS ( "http://www.w3.org/2000/svg" , "g" ) ;
1099+ group . setAttribute ( OVERLAY_ATTRIBUTE , "" ) ;
1100+ group . setAttribute ( "data-stroke-id" , stroke . id ) ;
1101+ group . setAttribute ( "fill" , "none" ) ;
1102+ group . setAttribute ( "stroke" , stroke . color ) ;
1103+ group . setAttribute ( "stroke-width" , String ( stroke . width ) ) ;
1104+ group . setAttribute ( "stroke-linecap" , "round" ) ;
1105+ group . setAttribute ( "stroke-linejoin" , "round" ) ;
1106+ const chunkPath = document . createElementNS ( "http://www.w3.org/2000/svg" , "path" ) ;
1107+ group . appendChild ( chunkPath ) ;
1108+ svg . appendChild ( group ) ;
1109+ activeStroke = { target : stroke , group, chunkPath, geometry } ;
10921110 }
10931111 } ;
10941112
@@ -1115,7 +1133,7 @@ function startAnnotation(): void {
11151133 }
11161134 } else if ( tool === "draw" && activeStroke ) {
11171135 if ( activeStroke . target . points . length > 1 ) strokes . push ( activeStroke . target ) ;
1118- else activeStroke . path . remove ( ) ;
1136+ else activeStroke . group . remove ( ) ;
11191137 activeStroke = null ;
11201138 }
11211139 dragStart = null ;
0 commit comments