@@ -78,10 +78,6 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {
7878
7979 private _lastNavigationTime = 0 ;
8080
81- private _debugStartCFI = true ;
82-
83- private _debugMarker : HTMLElement | null = null ;
84-
8581 constructor ( options : DOMViewOptions < EPUBViewState , EPUBViewData > ) {
8682 super ( options ) ;
8783 if ( options . data . buf ) {
@@ -467,112 +463,6 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {
467463 }
468464 }
469465
470- protected override _renderAnnotations ( synchronous = false ) {
471- super . _renderAnnotations ( synchronous ) ;
472- if ( ! this . _debugStartCFI ) {
473- if ( this . _debugMarker ) {
474- this . _debugMarker . remove ( ) ;
475- this . _debugMarker = null ;
476- }
477- return ;
478- }
479- let cfi = this . flow ?. startCFI ;
480- if ( ! cfi ) {
481- if ( this . _debugMarker ) {
482- this . _debugMarker . style . display = 'none' ;
483- }
484- return ;
485- }
486- // Resolve CFI to a range exactly as _keepPosition -> navigate does
487- let range = this . getRange ( cfi . toString ( ) , false ) ;
488- if ( ! range ) {
489- if ( this . _debugMarker ) {
490- this . _debugMarker . style . display = 'none' ;
491- }
492- return ;
493- }
494- let nativeRange = range . toRange ( ) ;
495- let rect = nativeRange . getBoundingClientRect ( ) ;
496- let offsetBlock = this . flow . startCFIOffset ?? 0 ;
497- let textNear = this . _getTextNear ( nativeRange ) ;
498- let cfiShort = cfi . toString ( ) . slice ( 0 , 60 ) + ( cfi . toString ( ) . length > 60 ? '...' : '' ) ;
499- let cached = this . _rangeCache . has ( cfi . toString ( ) ) ;
500- if ( ! this . _debugMarker ) {
501- this . _debugMarker = this . _iframeDocument . createElement ( 'div' ) ;
502- this . _debugMarker . style . cssText = `
503- position: fixed;
504- z-index: 999999;
505- pointer-events: none;
506- ` ;
507- this . _annotationShadowRoot . append ( this . _debugMarker ) ;
508- }
509- this . _debugMarker . style . display = '' ;
510- // CFI range marker (red): where getRange() resolves the CFI
511- // offsetBlock marker (blue): the offset from the top of the viewport
512- // _keepPosition scrolls so that the CFI rect.top == offsetBlock
513- let escHtml = ( s : string ) => s . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) ;
514- this . _debugMarker . innerHTML = `
515- <div style="
516- position: fixed;
517- left: 0;
518- top: ${ rect . top } px;
519- width: 100%;
520- height: 2px;
521- background: red;
522- opacity: 0.7;
523- "></div>
524- <div style="
525- position: fixed;
526- right: 4px;
527- top: ${ rect . top + 2 } px;
528- background: red;
529- color: white;
530- font: bold 10px sans-serif;
531- padding: 1px 4px;
532- border-radius: 2px;
533- opacity: 0.8;
534- max-width: 50%;
535- overflow: hidden;
536- text-overflow: ellipsis;
537- white-space: nowrap;
538- ">CFI top=${ Math . round ( rect . top ) } ${ cached ? '(cached)' : '(fresh)' } "${ escHtml ( textNear ) } "</div>
539- <div style="
540- position: fixed;
541- left: 0;
542- top: ${ offsetBlock } px;
543- width: 100%;
544- height: 2px;
545- background: blue;
546- opacity: 0.7;
547- "></div>
548- <div style="
549- position: fixed;
550- left: 4px;
551- top: ${ offsetBlock + 2 } px;
552- background: blue;
553- color: white;
554- font: bold 10px sans-serif;
555- padding: 1px 4px;
556- border-radius: 2px;
557- opacity: 0.8;
558- ">offsetBlock=${ Math . round ( offsetBlock ) } </div>
559- <div style="
560- position: fixed;
561- left: 4px;
562- bottom: 4px;
563- background: rgba(0,0,0,0.75);
564- color: #0f0;
565- font: 9px monospace;
566- padding: 2px 4px;
567- border-radius: 2px;
568- max-width: 90%;
569- overflow: hidden;
570- text-overflow: ellipsis;
571- white-space: nowrap;
572- ">${ escHtml ( cfiShort ) } </div>
573- ` ;
574- }
575-
576466 protected override _getHistoryLocation ( ) : NavLocation | null {
577467 let cfi = this . flow . startCFI ?. toString ( ) ;
578468 if ( ! cfi ) return null ;
@@ -582,39 +472,8 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {
582472 private _keepPosition < T > ( block ?: ( ) => T ) {
583473 let cfiBefore = this . flow ?. startCFI ;
584474 let offsetBefore = this . flow ?. startCFIOffset ;
585- let caller = block ? 'block' : 'resize' ;
586-
587- if ( this . _debugStartCFI && cfiBefore ) {
588- let cfiStr = cfiBefore . toString ( ) ;
589- let rangeBefore = this . getRange ( cfiStr , false ) ;
590- let rectBefore = rangeBefore ?. toRange ( ) . getBoundingClientRect ( ) ;
591- let textBefore = rangeBefore ? this . _getTextNear ( rangeBefore . toRange ( ) ) : null ;
592- console . group ( `_keepPosition (${ caller } )` ) ;
593- console . log ( 'CFI:' , cfiStr ) ;
594- console . log ( 'offsetBlock:' , offsetBefore ) ;
595- console . log ( 'range before block:' , rangeBefore ? 'resolved' : 'NULL' ) ;
596- console . log ( 'rect before block:' , rectBefore ? `top=${ Math . round ( rectBefore . top ) } left=${ Math . round ( rectBefore . left ) } ` : 'N/A' ) ;
597- console . log ( 'text near CFI:' , textBefore ) ;
598- console . log ( 'rangeCache hit:' , this . _rangeCache . has ( cfiStr ) ) ;
599- }
600-
601475 let result = block ?.( ) ;
602-
603476 if ( cfiBefore ) {
604- if ( this . _debugStartCFI ) {
605- let cfiStr = cfiBefore . toString ( ) ;
606- let rangeAfter = this . getRange ( cfiStr , true ) ;
607- let rectAfter = rangeAfter ?. toRange ( ) . getBoundingClientRect ( ) ;
608- let textAfter = rangeAfter ? this . _getTextNear ( rangeAfter . toRange ( ) ) : null ;
609- console . log ( '--- after block ---' ) ;
610- console . log ( 'range after block:' , rangeAfter ? 'resolved' : 'NULL' ) ;
611- console . log ( 'rect after block:' , rectAfter ? `top=${ Math . round ( rectAfter . top ) } left=${ Math . round ( rectAfter . left ) } ` : 'N/A' ) ;
612- console . log ( 'text near CFI (after):' , textAfter ) ;
613- if ( rangeAfter && rectAfter ) {
614- let scrollDelta = rectAfter . top - ( offsetBefore ?? 0 ) ;
615- console . log ( 'will scrollBy:' , Math . round ( scrollDelta ) , 'px' ) ;
616- }
617- }
618477 this . navigate (
619478 { pageNumber : cfiBefore . toString ( ) } ,
620479 {
@@ -623,32 +482,10 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {
623482 offsetBlock : offsetBefore ?? undefined
624483 }
625484 ) ;
626- if ( this . _debugStartCFI ) {
627- let cfiStr = cfiBefore . toString ( ) ;
628- let rangeAfterNav = this . getRange ( cfiStr , false ) ;
629- let rectAfterNav = rangeAfterNav ?. toRange ( ) . getBoundingClientRect ( ) ;
630- console . log ( '--- after navigate ---' ) ;
631- console . log ( 'rect after navigate:' , rectAfterNav ? `top=${ Math . round ( rectAfterNav . top ) } left=${ Math . round ( rectAfterNav . left ) } ` : 'N/A' ) ;
632- console . log ( 'target was top=' + ( offsetBefore ?? 0 ) ) ;
633- console . groupEnd ( ) ;
634- }
635- }
636- else if ( this . _debugStartCFI ) {
637- console . warn ( '_keepPosition: no startCFI, skipping navigation' ) ;
638- console . groupEnd ( ) ;
639485 }
640486 return result ;
641487 }
642488
643- private _getTextNear ( range : Range ) : string {
644- let node = range . startContainer ;
645- let text = node . textContent ?? '' ;
646- let offset = range . startOffset ;
647- let start = Math . max ( 0 , offset - 20 ) ;
648- let end = Math . min ( text . length , offset + 20 ) ;
649- return '...' + text . slice ( start , offset ) + '|' + text . slice ( offset , end ) + '...' ;
650- }
651-
652489 navigateToSelector ( selector : Selector , options : NavigateOptions = { } ) {
653490 if ( ! isFragment ( selector ) || selector . conformsTo !== FragmentSelectorConformsTo . EPUB3 ) {
654491 console . warn ( "Not a CFI FragmentSelector" , selector ) ;
0 commit comments