13
13
* limitations under the License.
14
14
*/
15
15
16
- "use strict" ;
16
+ let opMap ;
17
17
18
- // eslint-disable-next-line no-var
19
- var FontInspector = ( function FontInspectorClosure ( ) {
18
+ const FontInspector = ( function FontInspectorClosure ( ) {
20
19
let fonts ;
21
20
let active = false ;
22
21
const fontAttribute = "data-font-name" ;
@@ -49,8 +48,7 @@ var FontInspector = (function FontInspectorClosure() {
49
48
}
50
49
const fontName = e . target . dataset . fontName ;
51
50
const selects = document . getElementsByTagName ( "input" ) ;
52
- for ( let i = 0 ; i < selects . length ; ++ i ) {
53
- const select = selects [ i ] ;
51
+ for ( const select of selects ) {
54
52
if ( select . dataset . fontName !== fontName ) {
55
53
continue ;
56
54
}
@@ -65,7 +63,7 @@ var FontInspector = (function FontInspectorClosure() {
65
63
name : "Font Inspector" ,
66
64
panel : null ,
67
65
manager : null ,
68
- init : function init ( pdfjsLib ) {
66
+ init ( pdfjsLib ) {
69
67
const panel = this . panel ;
70
68
const tmp = document . createElement ( "button" ) ;
71
69
tmp . addEventListener ( "click" , resetSelection ) ;
@@ -75,7 +73,7 @@ var FontInspector = (function FontInspectorClosure() {
75
73
fonts = document . createElement ( "div" ) ;
76
74
panel . appendChild ( fonts ) ;
77
75
} ,
78
- cleanup : function cleanup ( ) {
76
+ cleanup ( ) {
79
77
fonts . textContent = "" ;
80
78
} ,
81
79
enabled : false ,
@@ -93,16 +91,16 @@ var FontInspector = (function FontInspectorClosure() {
93
91
}
94
92
} ,
95
93
// FontInspector specific functions.
96
- fontAdded : function fontAdded ( fontObj , url ) {
94
+ fontAdded ( fontObj , url ) {
97
95
function properties ( obj , list ) {
98
96
const moreInfo = document . createElement ( "table" ) ;
99
- for ( let i = 0 ; i < list . length ; i ++ ) {
97
+ for ( const entry of list ) {
100
98
const tr = document . createElement ( "tr" ) ;
101
99
const td1 = document . createElement ( "td" ) ;
102
- td1 . textContent = list [ i ] ;
100
+ td1 . textContent = entry ;
103
101
tr . appendChild ( td1 ) ;
104
102
const td2 = document . createElement ( "td" ) ;
105
- td2 . textContent = obj [ list [ i ] ] . toString ( ) ;
103
+ td2 . textContent = obj [ entry ] . toString ( ) ;
106
104
tr . appendChild ( td2 ) ;
107
105
moreInfo . appendChild ( tr ) ;
108
106
}
@@ -155,12 +153,8 @@ var FontInspector = (function FontInspectorClosure() {
155
153
} ;
156
154
} ) ( ) ;
157
155
158
- let opMap ;
159
-
160
156
// Manages all the page steppers.
161
- //
162
- // eslint-disable-next-line no-var
163
- var StepperManager = ( function StepperManagerClosure ( ) {
157
+ const StepperManager = ( function StepperManagerClosure ( ) {
164
158
let steppers = [ ] ;
165
159
let stepperDiv = null ;
166
160
let stepperControls = null ;
@@ -172,7 +166,7 @@ var StepperManager = (function StepperManagerClosure() {
172
166
name : "Stepper" ,
173
167
panel : null ,
174
168
manager : null ,
175
- init : function init ( pdfjsLib ) {
169
+ init ( pdfjsLib ) {
176
170
const self = this ;
177
171
stepperControls = document . createElement ( "div" ) ;
178
172
stepperChooser = document . createElement ( "select" ) ;
@@ -192,15 +186,15 @@ var StepperManager = (function StepperManagerClosure() {
192
186
opMap [ pdfjsLib . OPS [ key ] ] = key ;
193
187
}
194
188
} ,
195
- cleanup : function cleanup ( ) {
189
+ cleanup ( ) {
196
190
stepperChooser . textContent = "" ;
197
191
stepperDiv . textContent = "" ;
198
192
steppers = [ ] ;
199
193
} ,
200
194
enabled : false ,
201
195
active : false ,
202
196
// Stepper specific functions.
203
- create : function create ( pageIndex ) {
197
+ create ( pageIndex ) {
204
198
const debug = document . createElement ( "div" ) ;
205
199
debug . id = "stepper" + pageIndex ;
206
200
debug . hidden = true ;
@@ -218,23 +212,19 @@ var StepperManager = (function StepperManagerClosure() {
218
212
}
219
213
return stepper ;
220
214
} ,
221
- selectStepper : function selectStepper ( pageIndex , selectPanel ) {
222
- let i ;
215
+ selectStepper ( pageIndex , selectPanel ) {
223
216
pageIndex |= 0 ;
224
217
if ( selectPanel ) {
225
218
this . manager . selectPanel ( this ) ;
226
219
}
227
- for ( i = 0 ; i < steppers . length ; ++ i ) {
228
- const stepper = steppers [ i ] ;
220
+ for ( const stepper of steppers ) {
229
221
stepper . panel . hidden = stepper . pageIndex !== pageIndex ;
230
222
}
231
- const options = stepperChooser . options ;
232
- for ( i = 0 ; i < options . length ; ++ i ) {
233
- const option = options [ i ] ;
223
+ for ( const option of stepperChooser . options ) {
234
224
option . selected = ( option . value | 0 ) === pageIndex ;
235
225
}
236
226
} ,
237
- saveBreakPoints : function saveBreakPoints ( pageIndex , bps ) {
227
+ saveBreakPoints ( pageIndex , bps ) {
238
228
breakPoints [ pageIndex ] = bps ;
239
229
sessionStorage . setItem ( "pdfjsBreakPoints" , JSON . stringify ( breakPoints ) ) ;
240
230
} ,
@@ -292,6 +282,7 @@ const Stepper = (function StepperClosure() {
292
282
this . breakPoints = initialBreakPoints ;
293
283
this . currentIdx = - 1 ;
294
284
this . operatorListIdx = 0 ;
285
+ this . indentLevel = 0 ;
295
286
}
296
287
297
288
init ( operatorList ) {
@@ -360,8 +351,7 @@ const Stepper = (function StepperClosure() {
360
351
const charCodeRow = c ( "tr" ) ;
361
352
const fontCharRow = c ( "tr" ) ;
362
353
const unicodeRow = c ( "tr" ) ;
363
- for ( let j = 0 ; j < glyphs . length ; j ++ ) {
364
- const glyph = glyphs [ j ] ;
354
+ for ( const glyph of glyphs ) {
365
355
if ( typeof glyph === "object" && glyph !== null ) {
366
356
charCodeRow . appendChild ( c ( "td" , glyph . originalCharCode ) ) ;
367
357
fontCharRow . appendChild ( c ( "td" , glyph . fontChar ) ) ;
@@ -382,8 +372,14 @@ const Stepper = (function StepperClosure() {
382
372
table . appendChild ( charCodeRow ) ;
383
373
table . appendChild ( fontCharRow ) ;
384
374
table . appendChild ( unicodeRow ) ;
375
+ } else if ( fn === "restore" ) {
376
+ this . indentLevel -- ;
377
+ }
378
+ line . appendChild ( c ( "td" , " " . repeat ( this . indentLevel * 2 ) + fn ) ) ;
379
+ if ( fn === "save" ) {
380
+ this . indentLevel ++ ;
385
381
}
386
- line . appendChild ( c ( "td" , fn ) ) ;
382
+
387
383
if ( decArgs instanceof HTMLElement ) {
388
384
line . appendChild ( decArgs ) ;
389
385
} else {
@@ -403,9 +399,9 @@ const Stepper = (function StepperClosure() {
403
399
this . breakPoints . sort ( function ( a , b ) {
404
400
return a - b ;
405
401
} ) ;
406
- for ( let i = 0 ; i < this . breakPoints . length ; i ++ ) {
407
- if ( this . breakPoints [ i ] > this . currentIdx ) {
408
- return this . breakPoints [ i ] ;
402
+ for ( const breakPoint of this . breakPoints ) {
403
+ if ( breakPoint > this . currentIdx ) {
404
+ return breakPoint ;
409
405
}
410
406
}
411
407
return null ;
@@ -437,8 +433,7 @@ const Stepper = (function StepperClosure() {
437
433
438
434
goTo ( idx ) {
439
435
const allRows = this . panel . getElementsByClassName ( "line" ) ;
440
- for ( let x = 0 , xx = allRows . length ; x < xx ; ++ x ) {
441
- const row = allRows [ x ] ;
436
+ for ( const row of allRows ) {
442
437
if ( ( row . dataset . idx | 0 ) === idx ) {
443
438
row . style . backgroundColor = "rgb(251,250,207)" ;
444
439
row . scrollIntoView ( ) ;
@@ -451,17 +446,14 @@ const Stepper = (function StepperClosure() {
451
446
return Stepper ;
452
447
} ) ( ) ;
453
448
454
- // eslint-disable-next-line no-var
455
- var Stats = ( function Stats ( ) {
449
+ const Stats = ( function Stats ( ) {
456
450
let stats = [ ] ;
457
451
function clear ( node ) {
458
- while ( node . hasChildNodes ( ) ) {
459
- node . removeChild ( node . lastChild ) ;
460
- }
452
+ node . textContent = "" ; // Remove any `node` contents from the DOM.
461
453
}
462
454
function getStatIndex ( pageNumber ) {
463
- for ( let i = 0 , ii = stats . length ; i < ii ; ++ i ) {
464
- if ( stats [ i ] . pageNumber === pageNumber ) {
455
+ for ( const [ i , stat ] of stats . entries ( ) ) {
456
+ if ( stat . pageNumber === pageNumber ) {
465
457
return i ;
466
458
}
467
459
}
@@ -483,8 +475,7 @@ var Stats = (function Stats() {
483
475
}
484
476
const statsIndex = getStatIndex ( pageNumber ) ;
485
477
if ( statsIndex !== false ) {
486
- const b = stats [ statsIndex ] ;
487
- this . panel . removeChild ( b . div ) ;
478
+ stats [ statsIndex ] . div . remove ( ) ;
488
479
stats . splice ( statsIndex , 1 ) ;
489
480
}
490
481
const wrapper = document . createElement ( "div" ) ;
@@ -501,8 +492,8 @@ var Stats = (function Stats() {
501
492
return a . pageNumber - b . pageNumber ;
502
493
} ) ;
503
494
clear ( this . panel ) ;
504
- for ( let i = 0 , ii = stats . length ; i < ii ; ++ i ) {
505
- this . panel . appendChild ( stats [ i ] . div ) ;
495
+ for ( const entry of stats ) {
496
+ this . panel . appendChild ( entry . div ) ;
506
497
}
507
498
} ,
508
499
cleanup ( ) {
@@ -513,7 +504,7 @@ var Stats = (function Stats() {
513
504
} ) ( ) ;
514
505
515
506
// Manages all the debugging tools.
516
- window . PDFBug = ( function PDFBugClosure ( ) {
507
+ const PDFBug = ( function PDFBugClosure ( ) {
517
508
const panelWidth = 300 ;
518
509
const buttons = [ ] ;
519
510
let activePanel = null ;
@@ -523,8 +514,7 @@ window.PDFBug = (function PDFBugClosure() {
523
514
enable ( ids ) {
524
515
const all = ids . length === 1 && ids [ 0 ] === "all" ;
525
516
const tools = this . tools ;
526
- for ( let i = 0 ; i < tools . length ; ++ i ) {
527
- const tool = tools [ i ] ;
517
+ for ( const tool of tools ) {
528
518
if ( all || ids . includes ( tool . id ) ) {
529
519
tool . enabled = true ;
530
520
}
@@ -566,22 +556,14 @@ window.PDFBug = (function PDFBugClosure() {
566
556
container . style . right = panelWidth + "px" ;
567
557
568
558
// Initialize all the debugging tools.
569
- const tools = this . tools ;
570
- const self = this ;
571
- for ( let i = 0 ; i < tools . length ; ++ i ) {
572
- const tool = tools [ i ] ;
559
+ for ( const tool of this . tools ) {
573
560
const panel = document . createElement ( "div" ) ;
574
561
const panelButton = document . createElement ( "button" ) ;
575
562
panelButton . textContent = tool . name ;
576
- panelButton . addEventListener (
577
- "click" ,
578
- ( function ( selected ) {
579
- return function ( event ) {
580
- event . preventDefault ( ) ;
581
- self . selectPanel ( selected ) ;
582
- } ;
583
- } ) ( i )
584
- ) ;
563
+ panelButton . addEventListener ( "click" , event => {
564
+ event . preventDefault ( ) ;
565
+ this . selectPanel ( tool ) ;
566
+ } ) ;
585
567
controls . appendChild ( panelButton ) ;
586
568
panels . appendChild ( panel ) ;
587
569
tool . panel = panel ;
@@ -598,9 +580,9 @@ window.PDFBug = (function PDFBugClosure() {
598
580
this . selectPanel ( 0 ) ;
599
581
} ,
600
582
cleanup ( ) {
601
- for ( let i = 0 , ii = this . tools . length ; i < ii ; i ++ ) {
602
- if ( this . tools [ i ] . enabled ) {
603
- this . tools [ i ] . cleanup ( ) ;
583
+ for ( const tool of this . tools ) {
584
+ if ( tool . enabled ) {
585
+ tool . cleanup ( ) ;
604
586
}
605
587
}
606
588
} ,
@@ -612,13 +594,18 @@ window.PDFBug = (function PDFBugClosure() {
612
594
return ;
613
595
}
614
596
activePanel = index ;
615
- const tools = this . tools ;
616
- for ( let j = 0 ; j < tools . length ; ++ j ) {
597
+ for ( const [ j , tool ] of this . tools . entries ( ) ) {
617
598
const isActive = j === index ;
618
599
buttons [ j ] . classList . toggle ( "active" , isActive ) ;
619
- tools [ j ] . active = isActive ;
620
- tools [ j ] . panel . hidden = ! isActive ;
600
+ tool . active = isActive ;
601
+ tool . panel . hidden = ! isActive ;
621
602
}
622
603
} ,
623
604
} ;
624
605
} ) ( ) ;
606
+
607
+ globalThis . FontInspector = FontInspector ;
608
+ globalThis . StepperManager = StepperManager ;
609
+ globalThis . Stats = Stats ;
610
+
611
+ export { PDFBug } ;
0 commit comments