// Where the reader is presented from: the root, once (`hostsReader`). A book// card's tap and the `reader.open` act ask the presenter in their// environment; neither presents a reader of its own.importSwiftUI/// The reader's state at the root: the book open, if one is.@MainActor @ObservablefinalclassReaderPresenter {var current: ReaderOpening?/// A place asked of the book already open (`reader.open { at }`).var jump: ReaderOpening?funcopen(_ opening: ReaderOpening) {if current?.id == opening.id {if opening.at != nil { jump = opening } } else { current = opening } }func close() { current = nil jump = nil }}extensionEnvironmentValues {/// The reader books open in; nil in a preview or a test. @Entry var readerPresenter: ReaderPresenter? = nil}#if os(iOS)/// Holds the presenter and presents the reader over everything under it.privatestructReaderHost: ViewModifier { @State privatevar presenter = ReaderPresenter()func body(content: Content) -> someView { content .environment(\.readerPresenter, presenter) .fullScreenCover(item: $presenter.current) { opening inBookReaderScreen(opening: opening) { presenter.close() } .environment(\.readerPresenter, presenter) } }}extensionView {/// The root of a window: a book opened anywhere under it opens here.func hostsReader() -> someView { modifier(ReaderHost()) }}#endif/// The phone's own act that opens a book (`reader.open { id, at? }`).enumReaderMethod {staticletopen = "reader.open"}extensionTableDefinition {/// A table whose read act is the reader's on the record itself: its/// card's tap opens the book (`DeckCardTap.reader`). A highlight's/// Open in book names its book by a column, so its tap stays its own.var opensReader: Bool { (commands ?? []).contains { $0.method == ReaderMethod.open && $0.bindings?["id"] == "$id" } }}