• Stars
    star
    339
  • Rank 124,632 (Top 3 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created about 11 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

EPUB processing engine written in Javascript

readium-js

EPUB core processing engine written in Javascript.

This is a software component used by the Readium Chrome extension and the "cloud reader" ( https://github.com/readium/readium-js-viewer ).

Please see https://github.com/readium/readium-shared-js for more information about the underlying rendering engine.

You can try Readium here:

License

BSD-3-Clause ( http://opensource.org/licenses/BSD-3-Clause )

See license.txt.

Prerequisites

Development

Initial setup:

  • git submodule update --init --recursive to ensure that the readium-js chain of dependencies is initialised (readium-shared-js and readium-cfi-js)
  • git checkout BRANCH_NAME && git submodule foreach --recursive "git checkout BRANCH_NAME" to switch to the desired BRANCH_NAME
  • npm run prepare:all (to perform required preliminary tasks, like patching code before building)
  • OR: yarn run prepare:yarn:all (to use Yarn instead of NPM for node_module management)

Note that in some cases, administrator rights may be needed in order to install dependencies, because of NPM-related file access permissions (the console log would clearly show the error). Should this be the case, running sudo npm run prepare:all usually solves this.

Note that the above command executes the following:

  • npm install (to download dependencies defined in package.json ... note that the --production option can be used to avoid downloading development dependencies, for example when testing only the pre-built build-output folder contents)
  • npm update (to make sure that the dependency tree is up to date)

Typical workflow:

No RequireJS optimization:

  • npm run http (to launch an http server. This automatically opens a web browser instance to the HTML files in the dev folder, choose index_RequireJS_no-optimize.html, or the *LITE.html variant which do include only the reader view, not the ebook library view)
  • Hack away! (e.g. source code in the src/js folder)
  • Press F5 (refresh / reload) in the web browser

Or to use optimized Javascript bundles (single or multiple):

  • npm run build (to update the RequireJS bundles in the build output folder)
  • npm run http:watch (to launch an http server. This automatically opens a web browser instance to the HTML files in the dev folder, choose index_RequireJS_single-bundle.html or index_RequireJS_multiple-bundles.html, or the *LITE.html variants which do include only the reader view, not the ebook library view)
  • npm run http (same as above, but without watching for file changes (no automatic rebuild))

Plugins integration:

When invoking the npm run build command, the generated build-output folder contains RequireJS module bundles that include the default plugins specified in readium-js-shared/plugins/plugins.cson (see the readium-js-shared/PLUGINS.md documentation). Developers can override the default plugins configuration by using an additional file called plugins-override.cson. This file is git-ignored (not persistent in the Git repository), which means that Readium's default plugins configuration is never at risk of being mistakenly overridden by developers, whilst giving developers the possibility of creating custom builds on their local machines.

For example, the annotations plugin can be activated by adding it to the include section in readium-js-shared/plugins/plugins-override.cson. This way, after invoking npm run http, the ./dev/index*.html demo apps can be used to create / remove highlighted selections in the web browser.

NPM (Node Package Manager)

All packages "owned" and maintained by the Readium Foundation are listed here: https://www.npmjs.com/~readium

Note that although Node and NPM natively use the CommonJS format, Readium modules are currently only defined as AMD (RequireJS). This explains why Browserify ( http://browserify.org ) is not used by this Readium project. More information at http://requirejs.org/docs/commonjs.html and http://requirejs.org/docs/node.html

Note: the --dev option after npm install readium-js can be used to force the download of development dependencies, but this is kind of pointless as the code source and RequireJS build configuration files are missing. See below if you need to hack the code.

How to use (RequireJS bundles / AMD modules)

The build-output directory contains common CSS styles, as well as two distinct folders:

Single bundle

The _single-bundle folder contains readium-js_all.js (and its associated source-map file, as well as a RequireJS bundle index file (which isn't actually needed at runtime, so here just as a reference)), which aggregates all the required code (external library dependencies included, such as Underscore, jQuery, etc.), as well as the "Almond" lightweight AMD loader ( https://github.com/jrburke/almond ).

This means that the full RequireJS library ( http://requirejs.org ) is not actually needed to bootstrap the AMD modules at runtime, as demonstrated by the HTML file in the dev folder (trimmed for brevity):

<html>
<head>

<!-- main code bundle, which includes its own Almond AMD loader (no need for the full RequireJS library) -->
<script type="text/javascript" src="../build-output/_single-bundle/readium-js_all.js"> </script>

<!-- index.js calls into the above library -->
<script type="text/javascript" src="./index.js"> </script>

</head>
<body>
<div id="viewport"> </div>
</body>
</html>

Multiple bundles

The _multiple-bundles folder contains several Javascript bundles (and their respective source-map files, as well as RequireJS bundle index files):

  • readium-external-libs.js: aggregated library dependencies (e.g. Underscore, jQuery, etc.)
  • readium-shared-js.js: shared Readium code (basically, equivalent to the js folder of the "readium-shared-js" submodule)
  • readium-cfi-js.js: Readium CFI library (basically, equivalent to the js folder of the readium-cfi-js submodule)
  • readium-js.js: this Readium code (see the js folder, which includes epub-fetch and epub-model source code)
  • readium-plugin-example.js: simple plugin demo
  • readium-plugin-annotations.js: the annotation plugin (DOM selection + highlight), which bundle actually contains the "Backbone" library, as this dependency is not already included in the "external libs" bundle. )

In addition, the folder contains the full RequireJS.js library ( http://requirejs.org ), as the above bundles do no include the lightweight "Almond" AMD loader ( https://github.com/jrburke/almond ).

Usage is demonstrated by the HTML file in the dev folder (trimmed for brevity):

<html>
<head>

<!-- full RequireJS library -->
<script type="text/javascript" src="../build-output/_multiple-bundles/RequireJS.js"> </script>



<!-- individual bundles: -->

<!-- readium CFI library -->
<script type="text/javascript" src="../build-output/_multiple-bundles/readium-cfi-js.js"> </script>

<!-- external libraries -->
<script type="text/javascript" src="../build-output/_multiple-bundles/readium-external-libs.js"> </script>

<!-- readium itself -->
<script type="text/javascript" src="../build-output/_multiple-bundles/readium-shared-js.js"> </script>

<!-- simple example plugin -->
<script type="text/javascript" src="../build-output/_multiple-bundles/readium-plugin-example.js"> </script>

<!-- annotations plugin -->
<script type="text/javascript" src="../build-output/_multiple-bundles/readium-plugin-annotations.js"> </script>

<!-- readium js -->
<script type="text/javascript" src="../build-output/_multiple-bundles/readium-js.js"> </script>


<!-- index.js calls into the above libraries -->
<script type="text/javascript" src="./index.js"> </script>

</head>
<body>
<div id="viewport"> </div>
</body>
</html>

Note how the "external libs" set of AMD modules can be explicitly described using the bundles RequireJS configuration directive (this eliminates the apparent opacity of such as large container of library dependencies):

<script type="text/javascript">
requirejs.config({
    baseUrl: '../build-output/_multiple-bundles'
});
</script>

<script type="text/javascript" src="../build-output/_multiple-bundles/readium-cfi-js.js.bundles.js"> </script>

<script type="text/javascript" src="../build-output/_multiple-bundles/readium-external-libs.js.bundles.js"> </script>

<script type="text/javascript" src="../build-output/_multiple-bundles/readium-shared-js.js.bundles.js"> </script>

<script type="text/javascript" src="../build-output/_multiple-bundles/readium-plugin-example.js.bundles.js"> </script>

<script type="text/javascript" src="../build-output/_multiple-bundles/readium-plugin-annotations.js.bundles.js"> </script>

<script type="text/javascript" src="../build-output/_multiple-bundles/readium-js.js.bundles.js"> </script>

CSON vs. JSON (package.json)

CSON = CoffeeScript-Object-Notation ( https://github.com/bevry/cson )

Running the command npm run cson2json will re-generate the package.json JSON file. For more information, see comments in the master package.cson CSON file.

Why CSON? Because it is a lot more readable than JSON, and therefore easier to maintain. The syntax is not only less verbose (separators, etc.), more importantly it allows comments and line breaking!

Although these benefits are not so critical for basic "package" definitions, here package.cson/json declares relatively intricate script tasks that are used in the development workflow. npm run SCRIPT_NAME offers a lightweight technique to handle most build tasks, as NPM CLI utilities are available to perform cross-platform operations (agnostic to the actual command line interface / shell). For more complex build processes, Grunt / Gulp can be used, but these build systems do not necessarily offer the most readable / maintainable options.

Downside: DO NOT invoke npm init or npm install --save --save-dev --save-optional, as this would overwrite / update the JSON, not the master CSON!

API

See separate API doc.

More Repositories

1

readium-js-viewer

👁 ReadiumJS viewer: default web app for Readium.js library
HTML
517
star
2

readium-sdk

A C++ ePub renderer SDK
C
372
star
3

swift-toolkit

A toolkit for ebooks, audiobooks and comics written in Swift
Swift
260
star
4

kotlin-toolkit

A toolkit for ebooks, audiobooks and comics written in Kotlin
Kotlin
185
star
5

awesome-readium

⭐️ Awesome Readium-related resources
172
star
6

architecture

📚 Documents the architecture of the Readium project
JavaScript
153
star
7

r2-testapp-swift

Swift
149
star
8

r2-testapp-kotlin

Kotlin
128
star
9

mobile

📱 Readium Mobile is a toolkit for ebooks, audiobooks and comics written in Swift & Kotlin.
HTML
104
star
10

readium-css

🌈 A set of reference stylesheets for EPUB Reading Systems, starting with Readium Mobile
HTML
87
star
11

readium-shared-js

Repository for the shared JavaScript libraries that are used in the SDK-Launchers and other applications developed on top of the SDK
JavaScript
78
star
12

SDKLauncher-Android

Launcher app for Readium SDK on Android
JavaScript
76
star
13

webpub-manifest

📜 A JSON based Web Publication Manifest format used at the core of the Readium project
HTML
72
star
14

SDKLauncher-iOS

A small iOS application to serve as a launcher/testbed for the Readium SDK.
JavaScript
70
star
15

readium-lcp-server

Repository for the Readium LCP Server
Go
61
star
16

ts-toolkit

A toolkit for ebooks, audiobooks and comics written in Typescript
TypeScript
59
star
17

readium-cfi-js

JavaScript
43
star
18

go-toolkit

A toolkit for ebooks, audiobooks and comics written in Go
Go
38
star
19

desktop

Readium Desktop is an SDK for ebooks, audiobooks and comics written in Typescript and using node.js and Electron.js.
23
star
20

r2-streamer-swift

Swift
22
star
21

SDKLauncher-OSX

A small OS X application to serve as a launcher/testbed for the Readium SDK on the Mac.
JavaScript
21
star
22

r2-navigator-swift

JavaScript
19
star
23

r2-streamer-kotlin

Kotlin
18
star
24

r2-streamer-js

NodeJS Readium2 "streamer"
JavaScript
15
star
25

readium.github.io

Base repo for hosting the landing pages for the organization's web pages
HTML
14
star
26

r2-navigator-kotlin

Kotlin
12
star
27

readium-lcp-client

This repository is for the Readium Licenced Content Protection (LCP) client side implementation work.
C++
11
star
28

r2-shared-swift

Swift
10
star
29

r2-navigator-web

A Readium Navigator module for Web applications, written in Typescript
TypeScript
8
star
30

r2-shared-kotlin

Kotlin
8
star
31

r2-testapp-js

NodeJS Readium2 "test app"
TypeScript
8
star
32

r2-shared-js

NodeJS Readium2 "shared" components
TypeScript
8
star
33

r2-workspace-kotlin

A workspace for on-boarding developers
8
star
34

r2-streamer-java

A Java implementation of the Readium-2 streamer
Java
8
star
35

lcp-specs

🔐 Releases, drafts and schema for Readium LCP
SCSS
7
star
36

r2-opds-swift

Swift
7
star
37

r2-opds-js

NodeJS Readium2 "opds" component
TypeScript
7
star
38

readium-test-files

Some ePub3 files used to demonstrate the capabilities of the Readium SDK and derived reading systems.
JavaScript
6
star
39

r2-navigator-js

NodeJS Readium2 "navigator"
TypeScript
6
star
40

r2-lcp-swift

Swift LCP module
Swift
5
star
41

r2-opds-kotlin

Kotlin
4
star
42

r2-glue-js

Javascript resources that are injected by a Readium-2 streamer or navigator
TypeScript
3
star
43

r2-lcp-kotlin

Kotlin
3
star
44

r2-lcp-js

NodeJS LCP Module
TypeScript
3
star
45

r2-utils-js

NodeJS Readium2 "utils"
TypeScript
2
star
46

r2-workspace-swift

A workspace for on-boarding developers
2
star
47

readium-planning

A repo for various planning documents (as opposed to code/architecture documents)
1
star
48

readium-interfaces

A set of interfaces that provide access to the functionality in Readium 1 and 2.
JavaScript
1
star
49

divina-player-js

JS Player for Digital Visual Narratives
JavaScript
1
star
50

guided-navigation

🪧 Guiding readers through a publication using a JSON based document
HTML
1
star