The OPF package
Wrapper around the package. The details of the various entries are in the EPUB 3 Specification.
The module relies on the xmlbuilder2 package, which generates an XML file out of a set of JS objects. See the documentation of that library for
the details; the short overview is:
- JSON names starting with
"@""represent an attribute. - JSON name
"#""represent textual content of the element. - Otherwise a JSON name refers to an embedded dictionary representing a subelement in XML.
The core of the module is in the [[PackageWrapper]] class.
The OPF Wrapper
-
add_a11y_feature(features: string[]): void
Add accessibility feature strings to the metadata
-
add_collection(new_collection: Collection): void
Add a new OPF collection. This is used when the final EPUB is itself a collection of parts; each collection in the OPF sense collects the constituents of a specific part.
-
add_creators(creators: string[]): void
Add a list of creators (authors) to the publication.
-
add_dates(date: string): void
Set the date and the modification date of the publication.
-
add_manifest_item(): voiditem: ManifestItem,add_spine_item?: boolean
Add a manifest item, i.e., the reference to a resource that is part of the publication.
-
add_spine_item(): voididref: string,add_linear?: boolean
Add a spine item, i.e., the reference to the resource in the manifest that is a constituent of the spite (i.e., reading order) of the book
-
add_wcag_link(): void
Add an A11y link to WCAG A, to specify that the document conforms to this level
-
id: number
Id generated to the editors for cross reference
-
serialize(): string
Serialize the Package document into (pretty printed) XML.
-
thePackage: Package
The Package document content itself, stored in a JSON object for an easier manipulation
Representations of the "collections" element
The minimal metadata, used in collections
The "link" element content, as define in the spec. @rel is optional, because it is also used for OPF collections, and
@rel is indeed optional in that context.
Encoding of the XML structure of the package file in JSON; simply a wrapper around [[PackageContent]].
Usage
import * as mod from "lib/opf.ts";