Skip to content

Commit df514d4

Browse files
authored
3.0.0-alpha.1 (#420)
2 parents ef8049f + 6866f00 commit df514d4

File tree

375 files changed

+6203
-16008
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

375 files changed

+6203
-16008
lines changed

.github/workflows/checks.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ on:
77

88
env:
99
platform: ${{ 'iOS Simulator' }}
10-
device: ${{ 'iPhone 12' }}
10+
device: ${{ 'iPhone 15' }}
1111
commit_sha: ${{ github.sha }}
12+
DEVELOPER_DIR: /Applications/Xcode_15.0.1.app/Contents/Developer
1213

1314
jobs:
1415
build:
1516
name: Build
16-
runs-on: macos-12
17+
runs-on: macos-13
1718
if: ${{ !github.event.pull_request.draft }}
1819
env:
1920
scheme: ${{ 'Readium-Package' }}
20-
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app/Contents/Developer
2121

2222
steps:
2323
- name: Checkout
@@ -42,7 +42,7 @@ jobs:
4242
4343
lint:
4444
name: Lint
45-
runs-on: macos-12
45+
runs-on: macos-13
4646
if: ${{ !github.event.pull_request.draft }}
4747
env:
4848
scripts: ${{ 'Sources/Navigator/EPUB/Scripts' }}
@@ -76,7 +76,7 @@ jobs:
7676

7777
int-dev:
7878
name: Integration (Local)
79-
runs-on: macos-12
79+
runs-on: macos-13
8080
if: ${{ !github.event.pull_request.draft }}
8181
defaults:
8282
run:
@@ -98,7 +98,7 @@ jobs:
9898
9999
int-spm:
100100
name: Integration (Swift Package Manager)
101-
runs-on: macos-12
101+
runs-on: macos-13
102102
if: ${{ !github.event.pull_request.draft }}
103103
defaults:
104104
run:
@@ -126,7 +126,7 @@ jobs:
126126
127127
int-carthage:
128128
name: Integration (Carthage)
129-
runs-on: macos-12
129+
runs-on: macos-13
130130
if: ${{ !github.event.pull_request.draft }}
131131
defaults:
132132
run:
@@ -157,7 +157,7 @@ jobs:
157157
int-cocoapods:
158158
name: Integration (CocoaPods)
159159
if: github.event_name == 'push'
160-
runs-on: macos-12
160+
runs-on: macos-13
161161
defaults:
162162
run:
163163
working-directory: TestApp

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ All notable changes to this project will be documented in this file. Take a look
66

77
<!-- ## [Unreleased] -->
88

9+
## [3.0.0-alpha.1]
10+
11+
### Changed
12+
13+
* The `R2Shared`, `R2Streamer` and `R2Navigator` packages are now called `ReadiumShared`, `ReadiumStreamer` and `ReadiumNavigator`.
14+
* Many APIs now expect one of the new URL types (`RelativeURL`, `AbsoluteURL`, `HTTPURL` and `FileURL`). This is helpful because:
15+
* It validates at compile time that we provide a URL that is supported.
16+
* The API's capabilities are better documented, e.g. a download API could look like this : `download(url: HTTPURL) -> FileURL`.
17+
18+
#### Shared
19+
20+
* `Link` and `Locator`'s `href` are normalized as valid URLs to improve interoperability with the Readium Web toolkits.
21+
* **You MUST migrate your database if you were persisting HREFs and Locators**. Take a look at [the migration guide](Documentation/Migration%20Guide.md) for guidance.
22+
* Links are not resolved to the `self` URL of a manifest anymore. However, you can still normalize the HREFs yourselves by calling `Manifest.normalizeHREFsToSelf()`.
23+
* `Publication.localizedTitle` is now optional, as we cannot guarantee a publication will always have a title.
24+
25+
926
## [2.7.1]
1027

1128
### Added
@@ -672,3 +689,4 @@ progression. Now if no reading progression is set, the `effectiveReadingProgress
672689
[2.6.1]: https://github.com/readium/swift-toolkit/compare/2.6.0...2.6.1
673690
[2.7.0]: https://github.com/readium/swift-toolkit/compare/2.6.1...2.7.0
674691
[2.7.1]: https://github.com/readium/swift-toolkit/compare/2.7.0...2.7.1
692+
[3.0.0-alpha.1]: https://github.com/readium/swift-toolkit/compare/2.7.1...3.0.0-alpha.1

CONTRIBUTING.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Contributing to the Readium Swift Toolkit
2+
3+
First and foremost, thanks for your interest! 🙏 We need contributors like you to help bring this project to fruition.
4+
5+
We welcome many kind of contributions such as improving the documentation, submitting bug reports and feature requests, or writing code.
6+
7+
## Writing code
8+
9+
### Coding standard
10+
11+
We use [`SwiftFormat`](https://github.com/nicklockwood/SwiftFormat) to ensure code formatting and avoid bikeshedding.
12+
13+
Before submitting a PR, save yourself some trouble by automatically formatting the code with `make format` from the project's root directory.
14+
15+
### Modifying the EPUB Navigator's JavaScript layer
16+
17+
The EPUB navigator injects a set of JavaScript files into a publication's resources, exposing a JavaScript API to the `WKWebView` under the `readium` global namespace. The JavaScript source code is located under [`Sources/Navigator/EPUB/Scripts`](Sources/Navigator/EPUB/Scripts).
18+
19+
`index-reflowable.js` is the root of the bundle injected in a reflowable EPUB's resources, while `index-fixed.js` is used for a fixed-layout EPUB's resources.
20+
21+
In the case of fixed-layout EPUBs, the publication resources are actually loaded inside an `iframe` in one of [our HTML wrapper pages](Sources/Navigator/EPUB/Assets/) (`fxl-spread-one.html` for single pages, `fxl-spread-two.html` when displaying two pages side-by-side). The matching `index-fixed-wrapper-one.js` and `index-fixed-wrapper-two.js` are injected in the HTML wrappers.
22+
23+
If you make any changes to the JavaScript files, you must regenerate the bundles embedded in the application. First, make sure you have [`corepack` installed](https://pnpm.io/installation#using-corepack). Then, run `make scripts` from the project's root directory.
24+
+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Getting started
2+
3+
The Readium Swift toolkit enables you to develop reading apps for iOS and iPadOS. It provides built-in support for multiple publication formats such as EPUB, PDF, audiobooks, and comics.
4+
5+
:warning: Readium offers only low-level tools. You are responsible for creating a user interface for reading and managing books, as well as a data layer to store the user's publications. The Test App is an example of such integration.
6+
7+
## Design principles
8+
9+
The toolkit has been designed following these core tenets:
10+
11+
* **Modular**: It is divided into separate modules that can be used independently.
12+
* **Extensible**: Integrators should be able to support a custom DRM, publication format or inject their own stylesheets without modifying the toolkit itself.
13+
* **Opiniated**: We adhere to open standards but sometimes interpret them for practicality.
14+
15+
## Packages
16+
17+
### Main packages
18+
19+
* `R2Shared` contains shared `Publication` models and utilities.
20+
* `R2Streamer` parses publication files (e.g. an EPUB) into a `Publication` object.
21+
* [`R2Navigator` renders the content of a publication](Navigator/Navigator.md).
22+
23+
### Specialized packages
24+
25+
* `ReadiumOPDS` parses [OPDS catalog feeds](https://opds.io) (both OPDS 1 and 2).
26+
* [`ReadiumLCP` downloads and decrypts LCP-protected publications](Readium%20LCP.md).
27+
28+
### Adapters to third-party dependencies
29+
30+
* `ReadiumAdapterGCDWebServer` provides an HTTP server built with [GCDWebServer](https://github.com/swisspol/GCDWebServer).
31+
32+
## Overview of the shared models (`R2Shared`)
33+
34+
The Readium toolkit provides models used as exchange types between packages.
35+
36+
### Publication models
37+
38+
#### Publication
39+
40+
`Publication` and its sub-components represent a single publication – ebook, audiobook or comic. It is loosely based on the [Readium Web Publication Manifest](https://readium.org/webpub-manifest/).
41+
42+
A `Publication` instance:
43+
44+
* holds the metadata of a publication, such as its author or table of contents,
45+
* allows to read the contents of a publication, e.g. XHTML or audio resources,
46+
* provides additional services, for example content extraction or text search.
47+
48+
#### Link
49+
50+
51+
A [`Link` object](https://readium.org/webpub-manifest/#24-the-link-object) holds a pointer (URL) to a resource or service along with additional metadata, such as its media type or title.
52+
53+
The `Publication` contains several `Link` collections, for example:
54+
55+
* `readingOrder` lists the publication resources arranged in the order they should be read.
56+
* `resources` contains secondary resources necessary for rendering the `readingOrder`, such as an image or a font file.
57+
* `tableOfContents` represents the table of contents as a tree of `Link` objects.
58+
* `links` exposes additional resources, such as a canonical link to the manifest or a search web service.
59+
60+
#### Locator
61+
62+
A [`Locator` object](https://readium.org/architecture/models/locators/) represents a precise location in a publication resource in a format that can be stored and shared across reading systems. It is more accurate than a `Link` and contains additional information about the location, e.g. progression percentage, position or textual context.
63+
64+
`Locator` objects are used for various features, including:
65+
66+
* reporting the current progression in the publication
67+
* saving bookmarks, highlights and annotations
68+
* navigating search results
69+
70+
### Data models
71+
72+
#### Publication Asset
73+
74+
A `PublicationAsset` is an interface representing a single file or package holding the content of a `Publication`. A default implementation `FileAsset` grants access to a publication stored locally.
75+
76+
#### Resource
77+
78+
A `Resource` provides read access to a single resource of a publication, such as a file or an entry in an archive.
79+
80+
`Resource` instances are usually created by a `Fetcher`. The toolkit ships with various implementations supporting different data access protocols such as local files, HTTP, etc.
81+
82+
#### Fetcher
83+
84+
A `Fetcher` provides read access to a collection of resources. `Fetcher` instances are created by a `PublicationAsset` to provide access to the content of a publication.
85+
86+
`Publication` objects internally use a `Fetcher` to expose their content.
87+
88+
## Opening a publication (`R2Streamer`)
89+
90+
To retrieve a `Publication` object from a publication file like an EPUB or audiobook, begin by creating a `PublicationAsset` object used to read the file. Readium provides a `FileAsset` implementation for reading a publication stored on the local file system.
91+
92+
```swift
93+
let file = URL(fileURLWithPath: "path/to/book.epub")
94+
let asset = FileAsset(file: file)
95+
```
96+
97+
Then, use a `Streamer` instance to parse the asset and create a `Publication` object.
98+
99+
```swift
100+
let streamer = Streamer()
101+
102+
streamer.open(asset: asset, allowUserInteraction: false) { result in
103+
switch result {
104+
case .success(let publication):
105+
print("Opened \(publication.metadata.title)")
106+
case .failure(let error):
107+
alert(error.localizedDescription)
108+
case .cancelled:
109+
// The user cancelled the opening, for example by dismissing a password pop-up.
110+
break
111+
}
112+
}
113+
```
114+
115+
The `allowUserInteraction` parameter is useful when supporting a DRM like Readium LCP. It indicates if the toolkit can prompt the user for credentials when the publication is protected.
116+
117+
## Accessing the metadata of a publication
118+
119+
After opening a publication, you may want to read its metadata to insert a new entity into your bookshelf database, for instance. The `publication.metadata` object contains everything you need, including `title`, `authors` and the `published` date.
120+
121+
You can retrieve the publication cover using `publication.cover`. Avoid calling this from the main thread to prevent blocking the user interface.
122+
123+
## Rendering the publication on the screen (`R2Navigator`)
124+
125+
You can use a Readium navigator to present the publication to the user. The `Navigator` renders resources on the screen and offers APIs and user interactions for navigating the contents.
126+
127+
```swift
128+
let navigator = try EPUBNavigatorViewController(
129+
publication: publication,
130+
initialLocation: lastReadLocation,
131+
httpServer: GCDHTTPServer.shared
132+
)
133+
134+
hostViewController.present(navigator, animated: true)
135+
```
136+
Please refer to the [Navigator guide](Navigator/Navigator.md) for more information.

0 commit comments

Comments
 (0)