20
20
// eslint-disable-next-line max-len
21
21
/** @typedef {import("../../web/interfaces").IDownloadManager } IDownloadManager */
22
22
/** @typedef {import("../../web/interfaces").IPDFLinkService } IPDFLinkService */
23
+ // eslint-disable-next-line max-len
24
+ /** @typedef {import("../src/display/editor/tools.js").AnnotationEditorUIManager } AnnotationEditorUIManager */
23
25
24
26
import {
25
27
AnnotationBorderStyleType ,
@@ -157,6 +159,8 @@ class AnnotationElementFactory {
157
159
}
158
160
159
161
class AnnotationElement {
162
+ #updates = null ;
163
+
160
164
#hasBorder = false ;
161
165
162
166
constructor (
@@ -197,6 +201,52 @@ class AnnotationElement {
197
201
return AnnotationElement . _hasPopupData ( this . data ) ;
198
202
}
199
203
204
+ updateEdited ( params ) {
205
+ if ( ! this . container ) {
206
+ return ;
207
+ }
208
+
209
+ this . #updates ||= {
210
+ rect : this . data . rect . slice ( 0 ) ,
211
+ } ;
212
+
213
+ const { rect } = params ;
214
+
215
+ if ( rect ) {
216
+ this . #setRectEdited( rect ) ;
217
+ }
218
+ }
219
+
220
+ resetEdited ( ) {
221
+ if ( ! this . #updates) {
222
+ return ;
223
+ }
224
+ this . #setRectEdited( this . #updates. rect ) ;
225
+ this . #updates = null ;
226
+ }
227
+
228
+ #setRectEdited( rect ) {
229
+ const {
230
+ container : { style } ,
231
+ data : { rect : currentRect , rotation } ,
232
+ parent : {
233
+ viewport : {
234
+ rawDims : { pageWidth, pageHeight, pageX, pageY } ,
235
+ } ,
236
+ } ,
237
+ } = this ;
238
+ currentRect ?. splice ( 0 , 4 , ...rect ) ;
239
+ const { width, height } = getRectDims ( rect ) ;
240
+ style . left = `${ ( 100 * ( rect [ 0 ] - pageX ) ) / pageWidth } %` ;
241
+ style . top = `${ ( 100 * ( pageHeight - rect [ 3 ] + pageY ) ) / pageHeight } %` ;
242
+ if ( rotation === 0 ) {
243
+ style . width = `${ ( 100 * width ) / pageWidth } %` ;
244
+ style . height = `${ ( 100 * height ) / pageHeight } %` ;
245
+ } else {
246
+ this . setRotation ( rotation ) ;
247
+ }
248
+ }
249
+
200
250
/**
201
251
* Create an empty container for the annotation's HTML element.
202
252
*
@@ -216,13 +266,14 @@ class AnnotationElement {
216
266
if ( ! ( this instanceof WidgetAnnotationElement ) ) {
217
267
container . tabIndex = DEFAULT_TAB_INDEX ;
218
268
}
269
+ const { style } = container ;
219
270
220
271
// The accessibility manager will move the annotation in the DOM in
221
272
// order to match the visual ordering.
222
273
// But if an annotation is above an other one, then we must draw it
223
274
// after the other one whatever the order is in the DOM, hence the
224
275
// use of the z-index.
225
- container . style . zIndex = this . parent . zIndex ++ ;
276
+ style . zIndex = this . parent . zIndex ++ ;
226
277
227
278
if ( data . popupRef ) {
228
279
container . setAttribute ( "aria-haspopup" , "dialog" ) ;
@@ -236,8 +287,6 @@ class AnnotationElement {
236
287
container . classList . add ( "norotate" ) ;
237
288
}
238
289
239
- const { pageWidth, pageHeight, pageX, pageY } = viewport . rawDims ;
240
-
241
290
if ( ! data . rect || this instanceof PopupAnnotationElement ) {
242
291
const { rotation } = data ;
243
292
if ( ! data . hasOwnCanvas && rotation !== 0 ) {
@@ -248,35 +297,26 @@ class AnnotationElement {
248
297
249
298
const { width, height } = getRectDims ( data . rect ) ;
250
299
251
- // Do *not* modify `data.rect`, since that will corrupt the annotation
252
- // position on subsequent calls to `_createContainer` (see issue 6804).
253
- const rect = Util . normalizeRect ( [
254
- data . rect [ 0 ] ,
255
- page . view [ 3 ] - data . rect [ 1 ] + page . view [ 1 ] ,
256
- data . rect [ 2 ] ,
257
- page . view [ 3 ] - data . rect [ 3 ] + page . view [ 1 ] ,
258
- ] ) ;
259
-
260
300
if ( ! ignoreBorder && data . borderStyle . width > 0 ) {
261
- container . style . borderWidth = `${ data . borderStyle . width } px` ;
301
+ style . borderWidth = `${ data . borderStyle . width } px` ;
262
302
263
303
const horizontalRadius = data . borderStyle . horizontalCornerRadius ;
264
304
const verticalRadius = data . borderStyle . verticalCornerRadius ;
265
305
if ( horizontalRadius > 0 || verticalRadius > 0 ) {
266
306
const radius = `calc(${ horizontalRadius } px * var(--scale-factor)) / calc(${ verticalRadius } px * var(--scale-factor))` ;
267
- container . style . borderRadius = radius ;
307
+ style . borderRadius = radius ;
268
308
} else if ( this instanceof RadioButtonWidgetAnnotationElement ) {
269
309
const radius = `calc(${ width } px * var(--scale-factor)) / calc(${ height } px * var(--scale-factor))` ;
270
- container . style . borderRadius = radius ;
310
+ style . borderRadius = radius ;
271
311
}
272
312
273
313
switch ( data . borderStyle . style ) {
274
314
case AnnotationBorderStyleType . SOLID :
275
- container . style . borderStyle = "solid" ;
315
+ style . borderStyle = "solid" ;
276
316
break ;
277
317
278
318
case AnnotationBorderStyleType . DASHED :
279
- container . style . borderStyle = "dashed" ;
319
+ style . borderStyle = "dashed" ;
280
320
break ;
281
321
282
322
case AnnotationBorderStyleType . BEVELED :
@@ -288,7 +328,7 @@ class AnnotationElement {
288
328
break ;
289
329
290
330
case AnnotationBorderStyleType . UNDERLINE :
291
- container . style . borderBottomStyle = "solid" ;
331
+ style . borderBottomStyle = "solid" ;
292
332
break ;
293
333
294
334
default :
@@ -298,24 +338,34 @@ class AnnotationElement {
298
338
const borderColor = data . borderColor || null ;
299
339
if ( borderColor ) {
300
340
this . #hasBorder = true ;
301
- container . style . borderColor = Util . makeHexColor (
341
+ style . borderColor = Util . makeHexColor (
302
342
borderColor [ 0 ] | 0 ,
303
343
borderColor [ 1 ] | 0 ,
304
344
borderColor [ 2 ] | 0
305
345
) ;
306
346
} else {
307
347
// Transparent (invisible) border, so do not draw it at all.
308
- container . style . borderWidth = 0 ;
348
+ style . borderWidth = 0 ;
309
349
}
310
350
}
311
351
312
- container . style . left = `${ ( 100 * ( rect [ 0 ] - pageX ) ) / pageWidth } %` ;
313
- container . style . top = `${ ( 100 * ( rect [ 1 ] - pageY ) ) / pageHeight } %` ;
352
+ // Do *not* modify `data.rect`, since that will corrupt the annotation
353
+ // position on subsequent calls to `_createContainer` (see issue 6804).
354
+ const rect = Util . normalizeRect ( [
355
+ data . rect [ 0 ] ,
356
+ page . view [ 3 ] - data . rect [ 1 ] + page . view [ 1 ] ,
357
+ data . rect [ 2 ] ,
358
+ page . view [ 3 ] - data . rect [ 3 ] + page . view [ 1 ] ,
359
+ ] ) ;
360
+ const { pageWidth, pageHeight, pageX, pageY } = viewport . rawDims ;
361
+
362
+ style . left = `${ ( 100 * ( rect [ 0 ] - pageX ) ) / pageWidth } %` ;
363
+ style . top = `${ ( 100 * ( rect [ 1 ] - pageY ) ) / pageHeight } %` ;
314
364
315
365
const { rotation } = data ;
316
366
if ( data . hasOwnCanvas || rotation === 0 ) {
317
- container . style . width = `${ ( 100 * width ) / pageWidth } %` ;
318
- container . style . height = `${ ( 100 * height ) / pageHeight } %` ;
367
+ style . width = `${ ( 100 * width ) / pageWidth } %` ;
368
+ style . height = `${ ( 100 * height ) / pageHeight } %` ;
319
369
} else {
320
370
this . setRotation ( rotation , container ) ;
321
371
}
@@ -2897,6 +2947,7 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
2897
2947
* @property {Object<string, Array<Object>> | null } [fieldObjects]
2898
2948
* @property {Map<string, HTMLCanvasElement> } [annotationCanvasMap]
2899
2949
* @property {TextAccessibilityManager } [accessibilityManager]
2950
+ * @property {AnnotationEditorUIManager } [annotationEditorUIManager]
2900
2951
*/
2901
2952
2902
2953
/**
@@ -2913,6 +2964,7 @@ class AnnotationLayer {
2913
2964
div,
2914
2965
accessibilityManager,
2915
2966
annotationCanvasMap,
2967
+ annotationEditorUIManager,
2916
2968
page,
2917
2969
viewport,
2918
2970
} ) {
@@ -2922,6 +2974,7 @@ class AnnotationLayer {
2922
2974
this . page = page ;
2923
2975
this . viewport = viewport ;
2924
2976
this . zIndex = 0 ;
2977
+ this . _annotationEditorUIManager = annotationEditorUIManager ;
2925
2978
2926
2979
if ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "TESTING" ) ) {
2927
2980
// For testing purposes.
@@ -3011,15 +3064,16 @@ class AnnotationLayer {
3011
3064
}
3012
3065
}
3013
3066
3014
- if ( element . annotationEditorType > 0 ) {
3015
- this . #editableAnnotations. set ( element . data . id , element ) ;
3016
- }
3017
-
3018
3067
const rendered = element . render ( ) ;
3019
3068
if ( data . hidden ) {
3020
3069
rendered . style . visibility = "hidden" ;
3021
3070
}
3022
3071
this . #appendElement( rendered , data . id ) ;
3072
+
3073
+ if ( element . annotationEditorType > 0 ) {
3074
+ this . #editableAnnotations. set ( element . data . id , element ) ;
3075
+ this . _annotationEditorUIManager ?. renderAnnotationElement ( element ) ;
3076
+ }
3023
3077
}
3024
3078
3025
3079
this . #setAnnotationCanvasMap( ) ;
@@ -3051,13 +3105,16 @@ class AnnotationLayer {
3051
3105
continue ;
3052
3106
}
3053
3107
3108
+ canvas . className = "annotationContent" ;
3054
3109
const { firstChild } = element ;
3055
3110
if ( ! firstChild ) {
3056
3111
element . append ( canvas ) ;
3057
3112
} else if ( firstChild . nodeName === "CANVAS" ) {
3058
3113
firstChild . replaceWith ( canvas ) ;
3059
- } else {
3114
+ } else if ( ! firstChild . classList . contains ( "annotationContent" ) ) {
3060
3115
firstChild . before ( canvas ) ;
3116
+ } else {
3117
+ firstChild . after ( canvas ) ;
3061
3118
}
3062
3119
}
3063
3120
this . #annotationCanvasMap. clear ( ) ;
0 commit comments