@@ -431,13 +431,13 @@ open class EPUBNavigatorViewController: UIViewController,
431431 }
432432
433433 /// Mapping between reading order hrefs and the table of contents title.
434- private lazy var tableOfContentsTitleByHref : [ String : String ] = {
435- func fulfill( linkList: [ Link ] ) -> [ String : String ] {
436- var result = [ String : String] ( )
434+ private lazy var tableOfContentsTitleByHref : [ AnyURL : String ] = {
435+ func fulfill( linkList: [ Link ] ) -> [ AnyURL : String ] {
436+ var result = [ AnyURL : String] ( )
437437
438438 for link in linkList {
439439 if let title = link. title {
440- result [ link. href ] = title
440+ result [ link. url ( ) ] = title
441441 }
442442 let subResult = fulfill ( linkList: link. children)
443443 result. merge ( subResult) { current, _ -> String in
@@ -565,7 +565,7 @@ open class EPUBNavigatorViewController: UIViewController,
565565 return nil
566566 }
567567
568- return readingOrder. firstIndex ( withHREF : spreads [ currentSpreadIndex] . left. href )
568+ return readingOrder. firstIndexWithHREF ( spreads [ currentSpreadIndex] . left. url ( ) )
569569 }
570570
571571 private let reloadSpreadsCompletions = CompletionList ( )
@@ -615,7 +615,7 @@ open class EPUBNavigatorViewController: UIViewController,
615615 )
616616
617617 let initialIndex : Int = {
618- if let href = locator? . href, let foundIndex = self . spreads. firstIndex ( withHref : href) {
618+ if let href = locator? . href, let foundIndex = self . spreads. firstIndexWithHREF ( href) {
619619 return foundIndex
620620 } else {
621621 return 0
@@ -633,10 +633,10 @@ open class EPUBNavigatorViewController: UIViewController,
633633 }
634634 }
635635
636- private func loadedSpreadView ( forHREF href: String ) -> EPUBSpreadView ? {
636+ private func loadedSpreadViewForHREF < T : URLConvertible > ( _ href: T ) -> EPUBSpreadView ? {
637637 paginationView. loadedViews
638638 . compactMap { _, view in view as? EPUBSpreadView }
639- . first { $0. spread. links. first ( withHREF : href) != nil }
639+ . first { $0. spread. links. firstWithHREF ( href) != nil }
640640 }
641641
642642 // MARK: - Navigator
@@ -671,21 +671,21 @@ open class EPUBNavigatorViewController: UIViewController,
671671 }
672672
673673 let link = spreadView. focusedResource ?? spreadView. spread. leading
674- let href = link. href
674+ let href = link. url ( )
675675 let progression = min ( max ( spreadView. progression ( in: href) , 0.0 ) , 1.0 )
676676
677677 if
678678 // The positions are not always available, for example a Readium
679679 // WebPub doesn't have any unless a Publication Positions Web
680680 // Service is provided
681- let index = readingOrder. firstIndex ( withHREF : href) ,
681+ let index = readingOrder. firstIndexWithHREF ( href) ,
682682 let positionList = positionsByReadingOrder. getOrNil ( index) ,
683683 positionList. count > 0
684684 {
685685 // Gets the current locator from the positionList, and fill its missing data.
686686 let positionIndex = Int ( ceil ( progression * Double( positionList. count - 1 ) ) )
687687 return positionList [ positionIndex] . copy (
688- title: tableOfContentsTitleByHref [ href] ,
688+ title: tableOfContentsTitleByHref [ equivalent : href] ,
689689 locations: { $0. progression = progression }
690690 )
691691 } else {
@@ -726,8 +726,10 @@ open class EPUBNavigatorViewController: UIViewController,
726726 }
727727
728728 public func go( to locator: Locator , animated: Bool , completion: @escaping ( ) -> Void ) -> Bool {
729+ let locator = publication. normalizeLocator ( locator)
730+
729731 guard
730- let spreadIndex = spreads. firstIndex ( withHref : locator. href) ,
732+ let spreadIndex = spreads. firstIndexWithHREF ( locator. href) ,
731733 on ( . jump( locator) )
732734 else {
733735 return false
@@ -796,7 +798,11 @@ open class EPUBNavigatorViewController: UIViewController,
796798
797799 public func apply( decorations: [ Decoration ] , in group: String ) {
798800 let source = self . decorations [ group] ?? [ ]
799- let target = decorations. map { DiffableDecoration ( decoration: $0) }
801+ let target = decorations. map { d in
802+ var d = d
803+ d. locator = publication. normalizeLocator ( d. locator)
804+ return DiffableDecoration ( decoration: d)
805+ }
800806
801807 self . decorations [ group] = target
802808
@@ -815,7 +821,7 @@ open class EPUBNavigatorViewController: UIViewController,
815821 guard let script = changes. javascript ( forGroup: group, styles: config. decorationTemplates) else {
816822 continue
817823 }
818- loadedSpreadView ( forHREF : href) ? . evaluateScript ( script, inHREF: href)
824+ loadedSpreadViewForHREF ( href) ? . evaluateScript ( script, inHREF: href)
819825 }
820826 }
821827 }
@@ -922,7 +928,7 @@ extension EPUBNavigatorViewController: EPUBNavigatorViewModelDelegate {
922928 for (_, view) in paginationView. loadedViews {
923929 guard
924930 let view = view as? EPUBSpreadView ,
925- view. spread. links. first ( withHREF : href) != nil
931+ view. spread. links. firstWithHREF ( href) != nil
926932 else {
927933 continue
928934 }
@@ -966,10 +972,10 @@ extension EPUBNavigatorViewController: EPUBSpreadViewDelegate {
966972
967973 spreadView. evaluateScript ( " (function() { \n \( script) \n })(); " ) { _ in
968974 for link in spreadView. spread. links {
969- let href = link. href
975+ let href = link. url ( )
970976 for (group, decorations) in self . decorations {
971977 let decorations = decorations
972- . filter { $0. decoration. locator. href == href }
978+ . filter { $0. decoration. locator. href. isEquivalentTo ( href) }
973979 . map { DecorationChange . add ( $0. decoration) }
974980
975981 guard let script = decorations. javascript ( forGroup: group, styles: self . config. decorationTemplates) else {
@@ -1018,7 +1024,10 @@ extension EPUBNavigatorViewController: EPUBSpreadViewDelegate {
10181024 }
10191025
10201026 func spreadView( _ spreadView: EPUBSpreadView , didTapOnInternalLink href: String , clickEvent: ClickEvent ? ) {
1021- guard var link = publication. link ( withHREF: href) else {
1027+ guard
1028+ let url = AnyURL ( string: href) ,
1029+ var link = publication. linkWithHREF ( url)
1030+ else {
10221031 log ( . warning, " Cannot find link with HREF: \( href) " )
10231032 return
10241033 }
0 commit comments