Skip to content

Replace reading order indices with HREFs in the EPUB viewport #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Sources/Navigator/EPUB/EPUBNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ open class EPUBNavigatorViewController: InputObservableViewController,

/// Information about the visible portion of the publication.
public struct Viewport: Equatable {
/// Indices of the visible reading order resources.
public var readingOrderIndices: ClosedRange<[Link].Index>
/// Visible reading order resources.
public var readingOrder: [AnyURL]

/// Range of visible scroll progressions for each visible reading order
/// resource.
public var progressions: [[Link].Index: ClosedRange<Double>]
public var progressions: [AnyURL: ClosedRange<Double>]

/// Range of visible positions.
public var positions: ClosedRange<Int>?
Expand Down Expand Up @@ -627,11 +627,14 @@ open class EPUBNavigatorViewController: InputObservableViewController,
return (nil, nil)
}

let visibleReadingOrder: [(index: Int, href: AnyURL)] = spreadView.spread.readingOrderIndices
.map { ($0, readingOrder[$0].url()) }

var viewport = Viewport(
readingOrderIndices: spreadView.spread.readingOrderIndices,
progressions: spreadView.spread.readingOrderIndices.reduce([:]) { progressions, index in
readingOrder: visibleReadingOrder.map(\.href),
progressions: visibleReadingOrder.reduce([:]) { progressions, i in
var progressions = progressions
progressions[index] = spreadView.progression(in: index)
progressions[i.href] = spreadView.progression(in: i.index)
return progressions
},
positions: nil
Expand Down