mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
resource process method, types fixes
This commit is contained in:
parent
5bad36d709
commit
231496a047
11 changed files with 76 additions and 49 deletions
42
src/book.js
42
src/book.js
|
@ -213,7 +213,7 @@ class Book {
|
|||
|
||||
// this.toc = undefined;
|
||||
if (this.settings.store) {
|
||||
this.store();
|
||||
this.store(this.settings.store);
|
||||
}
|
||||
|
||||
if(url) {
|
||||
|
@ -430,33 +430,33 @@ class Book {
|
|||
|
||||
|
||||
/**
|
||||
* unpack the contents of the Books packageXml
|
||||
* unpack the contents of the Books packaging
|
||||
* @private
|
||||
* @param {document} packageXml XML Document
|
||||
* @param {Packaging} packaging object
|
||||
*/
|
||||
unpack(opf) {
|
||||
this.package = opf;
|
||||
unpack(packaging) {
|
||||
this.package = packaging; //TODO: deprecated this
|
||||
|
||||
this.spine.unpack(this.package, this.resolve.bind(this), this.canonical.bind(this));
|
||||
this.spine.unpack(this.packaging, this.resolve.bind(this), this.canonical.bind(this));
|
||||
|
||||
this.resources = new Resources(this.package.manifest, {
|
||||
this.resources = new Resources(this.packaging.manifest, {
|
||||
archive: this.archive,
|
||||
resolver: this.resolve.bind(this),
|
||||
request: this.request.bind(this),
|
||||
replacements: this.settings.replacements || (this.archived ? "blobUrl" : "base64")
|
||||
});
|
||||
|
||||
this.loadNavigation(this.package).then(() => {
|
||||
this.loadNavigation(this.packaging).then(() => {
|
||||
// this.toc = this.navigation.toc;
|
||||
this.loading.navigation.resolve(this.navigation);
|
||||
});
|
||||
|
||||
if (this.package.coverPath) {
|
||||
this.cover = this.resolve(this.package.coverPath);
|
||||
if (this.packaging.coverPath) {
|
||||
this.cover = this.resolve(this.packaging.coverPath);
|
||||
}
|
||||
// Resolve promises
|
||||
this.loading.manifest.resolve(this.package.manifest);
|
||||
this.loading.metadata.resolve(this.package.metadata);
|
||||
this.loading.manifest.resolve(this.packaging.manifest);
|
||||
this.loading.metadata.resolve(this.packaging.metadata);
|
||||
this.loading.spine.resolve(this.spine);
|
||||
this.loading.cover.resolve(this.cover);
|
||||
this.loading.resources.resolve(this.resources);
|
||||
|
@ -481,19 +481,19 @@ class Book {
|
|||
/**
|
||||
* Load Navigation and PageList from package
|
||||
* @private
|
||||
* @param {document} opf XML Document
|
||||
* @param {Packaging} packaging
|
||||
*/
|
||||
loadNavigation(opf) {
|
||||
let navPath = opf.navPath || opf.ncxPath;
|
||||
let toc = opf.toc;
|
||||
loadNavigation(packaging) {
|
||||
let navPath = packaging.navPath || packaging.ncxPath;
|
||||
let toc = packaging.toc;
|
||||
|
||||
// From json manifest
|
||||
if (toc) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.navigation = new Navigation(toc);
|
||||
|
||||
if (opf.pageList) {
|
||||
this.pageList = new PageList(opf.pageList); // TODO: handle page lists from Manifest
|
||||
if (packaging.pageList) {
|
||||
this.pageList = new PageList(packaging.pageList); // TODO: handle page lists from Manifest
|
||||
}
|
||||
|
||||
resolve(this.navigation);
|
||||
|
@ -575,7 +575,7 @@ class Book {
|
|||
* @param {string} [encoding]
|
||||
* @return {Store}
|
||||
*/
|
||||
store() {
|
||||
store(name) {
|
||||
// Use "blobUrl" or "base64" for replacements
|
||||
let replacementsSetting = this.settings.replacements && this.settings.replacements !== "none";
|
||||
// Save original url
|
||||
|
@ -583,7 +583,7 @@ class Book {
|
|||
// Save original request method
|
||||
let requester = this.settings.requestMethod || request.bind(this);
|
||||
// Create new Store
|
||||
this.storage = new Store(this.settings.store, requester, this.resolve.bind(this));
|
||||
this.storage = new Store(name, requester, this.resolve.bind(this));
|
||||
// Replace request method to go through store
|
||||
this.request = this.storage.request.bind(this.storage);
|
||||
|
||||
|
@ -683,7 +683,7 @@ class Book {
|
|||
* @return {string} key
|
||||
*/
|
||||
key(identifier) {
|
||||
var ident = identifier || this.package.metadata.identifier || this.url.filename;
|
||||
var ident = identifier || this.packaging.metadata.identifier || this.url.filename;
|
||||
return `epubjs:${EPUBJS_VERSION}:${ident}`;
|
||||
}
|
||||
|
||||
|
|
|
@ -1031,7 +1031,7 @@ class Rendition {
|
|||
* @private
|
||||
*/
|
||||
injectIdentifier(doc, section) {
|
||||
let ident = this.book.package.metadata.identifier;
|
||||
let ident = this.book.packaging.metadata.identifier;
|
||||
let meta = doc.createElement("meta");
|
||||
meta.setAttribute("name", "dc.relation.ispartof");
|
||||
if (ident) {
|
||||
|
|
|
@ -22,6 +22,15 @@ class Resources {
|
|||
resolver: (options && options.resolver),
|
||||
request: (options && options.request)
|
||||
};
|
||||
|
||||
this.process(manifest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process resources
|
||||
* @param {Manifest} manifest
|
||||
*/
|
||||
process(manifest){
|
||||
this.manifest = manifest;
|
||||
this.resources = Object.keys(manifest).
|
||||
map(function (key){
|
||||
|
|
|
@ -25,7 +25,7 @@ class Themes {
|
|||
|
||||
/**
|
||||
* Add themes to be used by a rendition
|
||||
* @param {object | string}
|
||||
* @param {object | Array<object> | string}
|
||||
* @example themes.register("light", "http://example.com/light.css")
|
||||
* @example themes.register("light", { "body": { "color": "purple"}})
|
||||
* @example themes.register({ "light" : {...}, "dark" : {...}})
|
||||
|
|
9
types/book.d.ts
vendored
9
types/book.d.ts
vendored
|
@ -16,6 +16,8 @@ import Path from "./utils/path";
|
|||
import Resources from "./resources";
|
||||
import Container from "./container";
|
||||
import Packaging from "./packaging";
|
||||
import Store from "./store";
|
||||
|
||||
export interface BookOptions {
|
||||
requestMethod?: (url: string, type: string, withCredentials: object, headers: object) => Promise<object>;
|
||||
requestCredentials?: object,
|
||||
|
@ -33,7 +35,7 @@ export default class Book {
|
|||
|
||||
settings: BookOptions;
|
||||
opening: any; // should be core.defer
|
||||
opened: Promise<void>
|
||||
opened: Promise<Book>;
|
||||
isOpen: boolean;
|
||||
loaded: {
|
||||
metadata: Promise<PackagingMetadataObject>,
|
||||
|
@ -58,6 +60,7 @@ export default class Book {
|
|||
rendition: Rendition
|
||||
container: Container;
|
||||
packaging: Packaging;
|
||||
storage: Store;
|
||||
|
||||
|
||||
canonical(path: string): string;
|
||||
|
@ -70,7 +73,7 @@ export default class Book {
|
|||
|
||||
getRange(cfiRange: string): Range;
|
||||
|
||||
key(identifier: string): string;
|
||||
key(identifier?: string): string;
|
||||
|
||||
load(path: string): Promise<object>;
|
||||
|
||||
|
@ -103,6 +106,8 @@ export default class Book {
|
|||
|
||||
unarchive(input: BinaryType, encoding?: string): Promise<Archive>;
|
||||
|
||||
store(name: string): Store;
|
||||
|
||||
unpack(opf: XMLDocument): Promise<Book>;
|
||||
|
||||
// Event emitters
|
||||
|
|
4
types/locations.d.ts
vendored
4
types/locations.d.ts
vendored
|
@ -19,9 +19,9 @@ export default class Locations {
|
|||
|
||||
cfiFromPercentage(percentage: number): string;
|
||||
|
||||
load(locations: JSON): Array<string>;
|
||||
load(locations: string): Array<string>;
|
||||
|
||||
save(): JSON;
|
||||
save(): string;
|
||||
|
||||
currentLocation(): Location;
|
||||
currentLocation(curr: string | number): void;
|
||||
|
|
11
types/navigation.d.ts
vendored
11
types/navigation.d.ts
vendored
|
@ -1,7 +1,7 @@
|
|||
export interface NavItem {
|
||||
id?: string,
|
||||
href?: string,
|
||||
label?: string,
|
||||
id: string,
|
||||
href: string,
|
||||
label: string,
|
||||
subitems?: Array<NavItem>,
|
||||
parent?: NavItem
|
||||
}
|
||||
|
@ -15,13 +15,16 @@ export interface LandmarkItem {
|
|||
export default class Navigation {
|
||||
constructor(xml: XMLDocument);
|
||||
|
||||
toc: Array<NavItem>;
|
||||
landmarks: Array<LandmarkItem>;
|
||||
|
||||
parse(xml: XMLDocument): void;
|
||||
|
||||
get(target: string) : NavItem;
|
||||
|
||||
landmark(type: string) : LandmarkItem;
|
||||
|
||||
load(json: JSON): Array<NavItem>;
|
||||
load(json: string): Array<NavItem>;
|
||||
|
||||
forEach(fn: (item: NavItem) => {}): any;
|
||||
|
||||
|
|
10
types/packaging.d.ts
vendored
10
types/packaging.d.ts
vendored
|
@ -45,9 +45,17 @@ export interface PackagingManifestObject {
|
|||
export default class Packaging {
|
||||
constructor(packageDocument: XMLDocument);
|
||||
|
||||
manifest: PackagingManifestObject;
|
||||
navPath: string;
|
||||
ncxPath: string;
|
||||
coverPath: string;
|
||||
spineNodeIndex: number;
|
||||
spine: Array<PackagingSpineItem>;
|
||||
metadata: PackagingMetadataObject;
|
||||
|
||||
parse(packageDocument: XMLDocument): PackagingObject;
|
||||
|
||||
load(json: JSON): PackagingObject;
|
||||
load(json: string): PackagingObject;
|
||||
|
||||
destroy(): void;
|
||||
|
||||
|
|
2
types/resources.d.ts
vendored
2
types/resources.d.ts
vendored
|
@ -9,6 +9,8 @@ export default class Resources {
|
|||
request?: Function
|
||||
});
|
||||
|
||||
process(manifest: PackagingManifestObject): void;
|
||||
|
||||
createUrl(url: string): Promise<string>;
|
||||
|
||||
replacements(): Promise<Array<string>>;
|
||||
|
|
2
types/section.d.ts
vendored
2
types/section.d.ts
vendored
|
@ -28,7 +28,7 @@ export default class Section {
|
|||
constructor(item: SpineItem, hooks: HooksObject);
|
||||
|
||||
idref: string;
|
||||
linear: string;
|
||||
linear: boolean;
|
||||
properties: Array<string>;
|
||||
index: number;
|
||||
href: string;
|
||||
|
|
32
types/themes.d.ts
vendored
32
types/themes.d.ts
vendored
|
@ -4,35 +4,35 @@ import Contents from "./contents";
|
|||
export default class Themes {
|
||||
constructor(rendition: Rendition);
|
||||
|
||||
register( themeObject: object ): void;
|
||||
register( themeObject: object ): void;
|
||||
|
||||
register( theme: string, url: string ): void;
|
||||
register( theme: string, url: string ): void;
|
||||
|
||||
register( theme: string, themeObject: object ): void;
|
||||
register( theme: string, themeObject: object ): void;
|
||||
|
||||
default( theme: object | string ): void;
|
||||
default( theme: object | string ): void;
|
||||
|
||||
registerThemes( themes: object ): void;
|
||||
registerThemes( themes: object ): void;
|
||||
|
||||
registerUrl( name: string, input: string ): void;
|
||||
registerUrl( name: string, input: string ): void;
|
||||
|
||||
registerRules( name: string, rules: object ): void;
|
||||
registerRules( name: string, rules: object ): void;
|
||||
|
||||
select( name: string ): void;
|
||||
select( name: string ): void;
|
||||
|
||||
update( name: string ): void;
|
||||
update( name: string ): void;
|
||||
|
||||
inject( content: Contents ): void;
|
||||
inject( content: Contents ): void;
|
||||
|
||||
add( name: string, contents: Contents ): void;
|
||||
add( name: string, contents: Contents ): void;
|
||||
|
||||
override(name: string, value: string, priority: boolean): void;
|
||||
override(name: string, value: string, priority?: boolean): void;
|
||||
|
||||
overrides(contents: Contents): void;
|
||||
overrides(contents: Contents): void;
|
||||
|
||||
fontSize(size: string): void;
|
||||
fontSize(size: string): void;
|
||||
|
||||
font(f: string): void;
|
||||
font(f: string): void;
|
||||
|
||||
destroy(): void;
|
||||
destroy(): void;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue