@epubook/core 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs +13 -1
- package/dist/index.d.ts +238 -236
- package/dist/index.mjs +13 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @epubook/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@epubook/theme-core) [](https://github.com/yjl9903/epubook/actions/workflows/ci.yml)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The fundamental module of [epubook](https://github.com/yjl9903/epubook). It provides low-level API for generating EPUB books.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
package/dist/index.cjs
CHANGED
|
@@ -242,6 +242,7 @@ class XHTMLBuilder {
|
|
|
242
242
|
};
|
|
243
243
|
this._head = [];
|
|
244
244
|
this._body = [];
|
|
245
|
+
this._bodyAttrs = {};
|
|
245
246
|
this._filename = filename;
|
|
246
247
|
this._meta.title = path__namespace$1.basename(filename);
|
|
247
248
|
}
|
|
@@ -287,6 +288,14 @@ class XHTMLBuilder {
|
|
|
287
288
|
this._body.push(...node);
|
|
288
289
|
return this;
|
|
289
290
|
}
|
|
291
|
+
bodyAttrs(attrs = {}) {
|
|
292
|
+
const a = Object.entries(attrs).map(([key, value]) => [`@_${key}`, value]);
|
|
293
|
+
this._bodyAttrs = {
|
|
294
|
+
...this._bodyAttrs,
|
|
295
|
+
...Object.fromEntries(a)
|
|
296
|
+
};
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
290
299
|
build() {
|
|
291
300
|
const content = builder.build({
|
|
292
301
|
html: {
|
|
@@ -298,7 +307,10 @@ class XHTMLBuilder {
|
|
|
298
307
|
title: this._meta.title,
|
|
299
308
|
...list(this._head)
|
|
300
309
|
},
|
|
301
|
-
body:
|
|
310
|
+
body: {
|
|
311
|
+
...this._bodyAttrs,
|
|
312
|
+
...list(this._body)
|
|
313
|
+
}
|
|
302
314
|
}
|
|
303
315
|
});
|
|
304
316
|
return new XHTML(this._filename, this._meta, content);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,266 +1,268 @@
|
|
|
1
1
|
import { Plugin } from 'rollup';
|
|
2
2
|
import { BuildConfig } from 'unbuild';
|
|
3
3
|
|
|
4
|
-
declare const MIMETYPE = "application/epub+zip";
|
|
5
|
-
declare const ImageGif = "image/gif";
|
|
6
|
-
declare const ImageJpeg = "image/jpeg";
|
|
7
|
-
declare const ImagePng = "image/png";
|
|
8
|
-
declare const ImageSvg = "image/svg+xml";
|
|
9
|
-
declare const ImageWebp = "image/webp";
|
|
10
|
-
type ImageMediaType = typeof ImageGif | typeof ImageJpeg | typeof ImagePng | typeof ImageSvg | typeof ImageWebp;
|
|
11
|
-
type ImageExtension = 'gif' | 'jpg' | 'jpeg' | 'png' | 'svg' | 'webp';
|
|
12
|
-
declare const TextCSS = "text/css";
|
|
13
|
-
declare const TextXHTML = "application/xhtml+xml";
|
|
14
|
-
type MediaType = ImageMediaType | typeof TextCSS | typeof TextXHTML;
|
|
4
|
+
declare const MIMETYPE = "application/epub+zip";
|
|
5
|
+
declare const ImageGif = "image/gif";
|
|
6
|
+
declare const ImageJpeg = "image/jpeg";
|
|
7
|
+
declare const ImagePng = "image/png";
|
|
8
|
+
declare const ImageSvg = "image/svg+xml";
|
|
9
|
+
declare const ImageWebp = "image/webp";
|
|
10
|
+
type ImageMediaType = typeof ImageGif | typeof ImageJpeg | typeof ImagePng | typeof ImageSvg | typeof ImageWebp;
|
|
11
|
+
type ImageExtension = 'gif' | 'jpg' | 'jpeg' | 'png' | 'svg' | 'webp';
|
|
12
|
+
declare const TextCSS = "text/css";
|
|
13
|
+
declare const TextXHTML = "application/xhtml+xml";
|
|
14
|
+
type MediaType = ImageMediaType | typeof TextCSS | typeof TextXHTML;
|
|
15
15
|
declare function getImageMediaType(file: string): ImageMediaType | undefined;
|
|
16
16
|
|
|
17
|
-
declare class ManifestItem {
|
|
18
|
-
private _href;
|
|
19
|
-
private _id;
|
|
20
|
-
private optional;
|
|
21
|
-
constructor(href: string, id: string);
|
|
22
|
-
update(info: typeof this$1.optional): this;
|
|
23
|
-
href(): string;
|
|
24
|
-
id(): string;
|
|
25
|
-
fallback(): string | undefined;
|
|
26
|
-
mediaOverlay(): string | undefined;
|
|
27
|
-
mediaType(): MediaType | undefined;
|
|
28
|
-
properties(): string | undefined;
|
|
29
|
-
ref(): ManifestItemRef;
|
|
30
|
-
}
|
|
31
|
-
declare class ManifestItemRef {
|
|
32
|
-
private _idref;
|
|
33
|
-
private optional;
|
|
34
|
-
constructor(idref: string);
|
|
35
|
-
update(info: typeof this$1.optional): this;
|
|
36
|
-
idref(): string;
|
|
37
|
-
id(): string | undefined;
|
|
38
|
-
linear(): string | undefined;
|
|
39
|
-
properties(): string | undefined;
|
|
17
|
+
declare class ManifestItem {
|
|
18
|
+
private _href;
|
|
19
|
+
private _id;
|
|
20
|
+
private optional;
|
|
21
|
+
constructor(href: string, id: string);
|
|
22
|
+
update(info: typeof this$1.optional): this;
|
|
23
|
+
href(): string;
|
|
24
|
+
id(): string;
|
|
25
|
+
fallback(): string | undefined;
|
|
26
|
+
mediaOverlay(): string | undefined;
|
|
27
|
+
mediaType(): MediaType | undefined;
|
|
28
|
+
properties(): string | undefined;
|
|
29
|
+
ref(): ManifestItemRef;
|
|
30
|
+
}
|
|
31
|
+
declare class ManifestItemRef {
|
|
32
|
+
private _idref;
|
|
33
|
+
private optional;
|
|
34
|
+
constructor(idref: string);
|
|
35
|
+
update(info: typeof this$1.optional): this;
|
|
36
|
+
idref(): string;
|
|
37
|
+
id(): string | undefined;
|
|
38
|
+
linear(): string | undefined;
|
|
39
|
+
properties(): string | undefined;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
declare abstract class Item {
|
|
43
|
-
private readonly file;
|
|
44
|
-
private readonly mediaType;
|
|
45
|
-
private _properties?;
|
|
46
|
-
constructor(file: string, mediaType: MediaType);
|
|
47
|
-
filename(): string;
|
|
48
|
-
relative(from: string): string;
|
|
49
|
-
update(info: Partial<{
|
|
50
|
-
properties: string;
|
|
51
|
-
}>): this;
|
|
52
|
-
id(): string;
|
|
53
|
-
manifest(): ManifestItem;
|
|
54
|
-
itemref(): ManifestItemRef;
|
|
55
|
-
abstract bundle(): Promise<Uint8Array>;
|
|
56
|
-
}
|
|
57
|
-
declare class Style extends Item {
|
|
58
|
-
private content;
|
|
59
|
-
constructor(file: string, content: string);
|
|
60
|
-
static read(src: string, dst: string): Promise<Style | undefined>;
|
|
61
|
-
bundle(): Promise<Uint8Array>;
|
|
62
|
-
}
|
|
63
|
-
declare class Image extends Item {
|
|
64
|
-
private data;
|
|
65
|
-
constructor(file: string, type: ImageMediaType, data: Uint8Array);
|
|
66
|
-
static read(file: string, src: string): Promise<Image | undefined>;
|
|
67
|
-
bundle(): Promise<Uint8Array>;
|
|
68
|
-
}
|
|
69
|
-
declare class HTML extends Item {
|
|
70
|
-
private content;
|
|
71
|
-
constructor(file: string, content: string);
|
|
72
|
-
static read(src: string, dst: string): Promise<HTML | undefined>;
|
|
73
|
-
bundle(): Promise<Uint8Array>;
|
|
42
|
+
declare abstract class Item {
|
|
43
|
+
private readonly file;
|
|
44
|
+
private readonly mediaType;
|
|
45
|
+
private _properties?;
|
|
46
|
+
constructor(file: string, mediaType: MediaType);
|
|
47
|
+
filename(): string;
|
|
48
|
+
relative(from: string): string;
|
|
49
|
+
update(info: Partial<{
|
|
50
|
+
properties: string;
|
|
51
|
+
}>): this;
|
|
52
|
+
id(): string;
|
|
53
|
+
manifest(): ManifestItem;
|
|
54
|
+
itemref(): ManifestItemRef;
|
|
55
|
+
abstract bundle(): Promise<Uint8Array>;
|
|
56
|
+
}
|
|
57
|
+
declare class Style extends Item {
|
|
58
|
+
private content;
|
|
59
|
+
constructor(file: string, content: string);
|
|
60
|
+
static read(src: string, dst: string): Promise<Style | undefined>;
|
|
61
|
+
bundle(): Promise<Uint8Array>;
|
|
62
|
+
}
|
|
63
|
+
declare class Image extends Item {
|
|
64
|
+
private data;
|
|
65
|
+
constructor(file: string, type: ImageMediaType, data: Uint8Array);
|
|
66
|
+
static read(file: string, src: string): Promise<Image | undefined>;
|
|
67
|
+
bundle(): Promise<Uint8Array>;
|
|
68
|
+
}
|
|
69
|
+
declare class HTML extends Item {
|
|
70
|
+
private content;
|
|
71
|
+
constructor(file: string, content: string);
|
|
72
|
+
static read(src: string, dst: string): Promise<HTML | undefined>;
|
|
73
|
+
bundle(): Promise<Uint8Array>;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
type Prettify<T> = {
|
|
77
|
-
[K in keyof T]: T[K];
|
|
76
|
+
type Prettify<T> = {
|
|
77
|
+
[K in keyof T]: T[K];
|
|
78
78
|
} & {};
|
|
79
79
|
|
|
80
|
-
declare global {
|
|
81
|
-
namespace JSX {
|
|
82
|
-
interface IntrinsicElements extends EpubIntrinsicElements {
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
interface XHTMLNode {
|
|
87
|
-
tag: string;
|
|
88
|
-
attrs?: Record<string, string>;
|
|
89
|
-
children?: Array<string | XHTMLNode>;
|
|
90
|
-
}
|
|
91
|
-
interface EpubIntrinsicElements {
|
|
92
|
-
nav: {};
|
|
93
|
-
ul: {};
|
|
94
|
-
ol: {};
|
|
95
|
-
li: {};
|
|
96
|
-
h1: {};
|
|
97
|
-
h2: {};
|
|
98
|
-
h3: {};
|
|
99
|
-
h4: {};
|
|
100
|
-
h5: {};
|
|
101
|
-
h6: {};
|
|
102
|
-
p: {};
|
|
103
|
-
pre: {};
|
|
104
|
-
span: {};
|
|
105
|
-
code: {};
|
|
106
|
-
a: {
|
|
107
|
-
href: string;
|
|
108
|
-
};
|
|
80
|
+
declare global {
|
|
81
|
+
namespace JSX {
|
|
82
|
+
interface IntrinsicElements extends EpubIntrinsicElements {
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
interface XHTMLNode {
|
|
87
|
+
tag: string;
|
|
88
|
+
attrs?: Record<string, string>;
|
|
89
|
+
children?: Array<string | XHTMLNode>;
|
|
90
|
+
}
|
|
91
|
+
interface EpubIntrinsicElements {
|
|
92
|
+
nav: {};
|
|
93
|
+
ul: {};
|
|
94
|
+
ol: {};
|
|
95
|
+
li: {};
|
|
96
|
+
h1: {};
|
|
97
|
+
h2: {};
|
|
98
|
+
h3: {};
|
|
99
|
+
h4: {};
|
|
100
|
+
h5: {};
|
|
101
|
+
h6: {};
|
|
102
|
+
p: {};
|
|
103
|
+
pre: {};
|
|
104
|
+
span: {};
|
|
105
|
+
code: {};
|
|
106
|
+
a: {
|
|
107
|
+
href: string;
|
|
108
|
+
};
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
declare const Fragment = "Fragment";
|
|
112
|
-
declare function h(tag: string, attrs?: Record<string, string>, ...children: Array<string | XHTMLNode | Array<string | XHTMLNode>>): {
|
|
113
|
-
tag: string;
|
|
114
|
-
attrs: Record<string, string>;
|
|
115
|
-
children: (string | XHTMLNode)[];
|
|
111
|
+
declare const Fragment = "Fragment";
|
|
112
|
+
declare function h(tag: string, attrs?: Record<string, string>, ...children: Array<string | XHTMLNode | Array<string | XHTMLNode>>): {
|
|
113
|
+
tag: string;
|
|
114
|
+
attrs: Record<string, string>;
|
|
115
|
+
children: (string | XHTMLNode)[];
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
interface HTMLMeta {
|
|
119
|
-
language: string;
|
|
120
|
-
title: string;
|
|
121
|
-
}
|
|
122
|
-
declare class XHTML extends Item {
|
|
123
|
-
private _meta;
|
|
124
|
-
private _content;
|
|
125
|
-
constructor(file: string, meta: HTMLMeta, content: string);
|
|
126
|
-
meta(): HTMLMeta;
|
|
127
|
-
title(): string;
|
|
128
|
-
language(): string;
|
|
129
|
-
content(): string;
|
|
130
|
-
bundle(): Promise<Uint8Array>;
|
|
131
|
-
}
|
|
132
|
-
declare class XHTMLBuilder {
|
|
133
|
-
private _meta;
|
|
134
|
-
private _filename;
|
|
135
|
-
private _head;
|
|
136
|
-
private _body;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
118
|
+
interface HTMLMeta {
|
|
119
|
+
language: string;
|
|
120
|
+
title: string;
|
|
121
|
+
}
|
|
122
|
+
declare class XHTML extends Item {
|
|
123
|
+
private _meta;
|
|
124
|
+
private _content;
|
|
125
|
+
constructor(file: string, meta: HTMLMeta, content: string);
|
|
126
|
+
meta(): HTMLMeta;
|
|
127
|
+
title(): string;
|
|
128
|
+
language(): string;
|
|
129
|
+
content(): string;
|
|
130
|
+
bundle(): Promise<Uint8Array>;
|
|
131
|
+
}
|
|
132
|
+
declare class XHTMLBuilder {
|
|
133
|
+
private _meta;
|
|
134
|
+
private _filename;
|
|
135
|
+
private _head;
|
|
136
|
+
private _body;
|
|
137
|
+
private _bodyAttrs;
|
|
138
|
+
constructor(filename: string);
|
|
139
|
+
language(value: string): this;
|
|
140
|
+
title(value: string): this;
|
|
141
|
+
style(...list: Array<string | Style>): this;
|
|
142
|
+
head(...node: XHTMLNode[]): this;
|
|
143
|
+
body(...node: XHTMLNode[]): this;
|
|
144
|
+
bodyAttrs(attrs?: Record<string, string>): this;
|
|
145
|
+
build(): XHTML;
|
|
144
146
|
}
|
|
145
147
|
|
|
146
|
-
type NavItem = {
|
|
147
|
-
title: string;
|
|
148
|
-
attrs?: Record<string, string>;
|
|
149
|
-
};
|
|
150
|
-
type NavLink = Prettify<NavItem & {
|
|
151
|
-
page: HTML | XHTML;
|
|
152
|
-
}>;
|
|
153
|
-
type NavSubList = Prettify<NavItem & {
|
|
154
|
-
list: NavLink[];
|
|
155
|
-
}>;
|
|
156
|
-
type NavList = Array<NavLink | NavSubList>;
|
|
157
|
-
interface NavOption {
|
|
158
|
-
title: string;
|
|
159
|
-
heading: 1 | 2 | 3 | 4 | 5 | 6;
|
|
160
|
-
titleAttrs: Record<string, string>;
|
|
161
|
-
builder?: XHTMLBuilder;
|
|
162
|
-
}
|
|
163
|
-
declare class Toc extends XHTML {
|
|
164
|
-
constructor(file: string, meta: HTMLMeta, content: string);
|
|
165
|
-
static from(xhtml: XHTML): Toc;
|
|
166
|
-
static generate(file: string, nav: NavList, { title, heading, titleAttrs, builder }?: Partial<NavOption>): XHTMLBuilder;
|
|
148
|
+
type NavItem = {
|
|
149
|
+
title: string;
|
|
150
|
+
attrs?: Record<string, string>;
|
|
151
|
+
};
|
|
152
|
+
type NavLink = Prettify<NavItem & {
|
|
153
|
+
page: HTML | XHTML;
|
|
154
|
+
}>;
|
|
155
|
+
type NavSubList = Prettify<NavItem & {
|
|
156
|
+
list: NavLink[];
|
|
157
|
+
}>;
|
|
158
|
+
type NavList = Array<NavLink | NavSubList>;
|
|
159
|
+
interface NavOption {
|
|
160
|
+
title: string;
|
|
161
|
+
heading: 1 | 2 | 3 | 4 | 5 | 6;
|
|
162
|
+
titleAttrs: Record<string, string>;
|
|
163
|
+
builder?: XHTMLBuilder;
|
|
164
|
+
}
|
|
165
|
+
declare class Toc extends XHTML {
|
|
166
|
+
constructor(file: string, meta: HTMLMeta, content: string);
|
|
167
|
+
static from(xhtml: XHTML): Toc;
|
|
168
|
+
static generate(file: string, nav: NavList, { title, heading, titleAttrs, builder }?: Partial<NavOption>): XHTMLBuilder;
|
|
167
169
|
}
|
|
168
170
|
|
|
169
|
-
interface Author {
|
|
170
|
-
name: string;
|
|
171
|
-
fileAs?: string;
|
|
172
|
-
role?: string;
|
|
173
|
-
uid?: string;
|
|
174
|
-
}
|
|
175
|
-
interface PackageDocumentMeta {
|
|
176
|
-
title: string;
|
|
177
|
-
language: string;
|
|
178
|
-
contributor: Author[];
|
|
179
|
-
coverage: string;
|
|
180
|
-
creator: Author;
|
|
181
|
-
date: Date;
|
|
182
|
-
description: string;
|
|
183
|
-
format: string;
|
|
184
|
-
publisher: string;
|
|
185
|
-
relation: string;
|
|
186
|
-
rights: string;
|
|
187
|
-
source: string;
|
|
188
|
-
subject: string;
|
|
189
|
-
type: string;
|
|
190
|
-
lastModified: Date;
|
|
191
|
-
}
|
|
192
|
-
declare class PackageDocument {
|
|
193
|
-
private readonly file;
|
|
194
|
-
private readonly SpecVersion;
|
|
195
|
-
private _uniqueIdentifier;
|
|
196
|
-
private _identifier;
|
|
197
|
-
private _metadata;
|
|
198
|
-
private _toc;
|
|
199
|
-
private _items;
|
|
200
|
-
private _spine;
|
|
201
|
-
constructor(file: string);
|
|
202
|
-
filename(): string;
|
|
203
|
-
version(): "3.0";
|
|
204
|
-
update(info: Partial<PackageDocumentMeta>): this;
|
|
205
|
-
title(): string;
|
|
206
|
-
language(): string;
|
|
207
|
-
creator(): Author;
|
|
208
|
-
metadata(): PackageDocumentMeta;
|
|
209
|
-
addItem(item: Item): this;
|
|
210
|
-
items(): Item[];
|
|
211
|
-
manifest(): ManifestItem[];
|
|
212
|
-
spine(): ManifestItemRef[];
|
|
213
|
-
setSpine(items: Item[]): this;
|
|
214
|
-
toc(): Toc | undefined;
|
|
215
|
-
setToc(nav: NavList, option?: Partial<NavOption>): this;
|
|
216
|
-
uniqueIdentifier(): string;
|
|
217
|
-
identifier(): string;
|
|
218
|
-
setIdentifier(identifier: string, uniqueIdentifier?: string): void;
|
|
171
|
+
interface Author {
|
|
172
|
+
name: string;
|
|
173
|
+
fileAs?: string;
|
|
174
|
+
role?: string;
|
|
175
|
+
uid?: string;
|
|
176
|
+
}
|
|
177
|
+
interface PackageDocumentMeta {
|
|
178
|
+
title: string;
|
|
179
|
+
language: string;
|
|
180
|
+
contributor: Author[];
|
|
181
|
+
coverage: string;
|
|
182
|
+
creator: Author;
|
|
183
|
+
date: Date;
|
|
184
|
+
description: string;
|
|
185
|
+
format: string;
|
|
186
|
+
publisher: string;
|
|
187
|
+
relation: string;
|
|
188
|
+
rights: string;
|
|
189
|
+
source: string;
|
|
190
|
+
subject: string;
|
|
191
|
+
type: string;
|
|
192
|
+
lastModified: Date;
|
|
193
|
+
}
|
|
194
|
+
declare class PackageDocument {
|
|
195
|
+
private readonly file;
|
|
196
|
+
private readonly SpecVersion;
|
|
197
|
+
private _uniqueIdentifier;
|
|
198
|
+
private _identifier;
|
|
199
|
+
private _metadata;
|
|
200
|
+
private _toc;
|
|
201
|
+
private _items;
|
|
202
|
+
private _spine;
|
|
203
|
+
constructor(file: string);
|
|
204
|
+
filename(): string;
|
|
205
|
+
version(): "3.0";
|
|
206
|
+
update(info: Partial<PackageDocumentMeta>): this;
|
|
207
|
+
title(): string;
|
|
208
|
+
language(): string;
|
|
209
|
+
creator(): Author;
|
|
210
|
+
metadata(): PackageDocumentMeta;
|
|
211
|
+
addItem(item: Item): this;
|
|
212
|
+
items(): Item[];
|
|
213
|
+
manifest(): ManifestItem[];
|
|
214
|
+
spine(): ManifestItemRef[];
|
|
215
|
+
setSpine(items: Item[]): this;
|
|
216
|
+
toc(): Toc | undefined;
|
|
217
|
+
setToc(nav: NavList, option?: Partial<NavOption>): this;
|
|
218
|
+
uniqueIdentifier(): string;
|
|
219
|
+
identifier(): string;
|
|
220
|
+
setIdentifier(identifier: string, uniqueIdentifier?: string): void;
|
|
219
221
|
}
|
|
220
222
|
|
|
221
|
-
declare class Epub {
|
|
222
|
-
/**
|
|
223
|
-
* See: https://www.w3.org/TR/epub-33/#sec-package-doc
|
|
224
|
-
*
|
|
225
|
-
* Now, it only supports single opf (OEBPS/content.opf)
|
|
226
|
-
*
|
|
227
|
-
* @returns list of package documents
|
|
228
|
-
*/
|
|
229
|
-
private opfs;
|
|
230
|
-
constructor(meta?: Partial<PackageDocumentMeta>);
|
|
231
|
-
packages(): PackageDocument[];
|
|
232
|
-
main(): PackageDocument;
|
|
233
|
-
item(...items: Item[]): this;
|
|
234
|
-
toc(nav: NavList, option?: Partial<NavOption>): this;
|
|
235
|
-
spine(...items: Item[]): this;
|
|
236
|
-
bundle(): Promise<Uint8Array>;
|
|
237
|
-
writeFile(file: string): Promise<void>;
|
|
223
|
+
declare class Epub {
|
|
224
|
+
/**
|
|
225
|
+
* See: https://www.w3.org/TR/epub-33/#sec-package-doc
|
|
226
|
+
*
|
|
227
|
+
* Now, it only supports single opf (OEBPS/content.opf)
|
|
228
|
+
*
|
|
229
|
+
* @returns list of package documents
|
|
230
|
+
*/
|
|
231
|
+
private opfs;
|
|
232
|
+
constructor(meta?: Partial<PackageDocumentMeta>);
|
|
233
|
+
packages(): PackageDocument[];
|
|
234
|
+
main(): PackageDocument;
|
|
235
|
+
item(...items: Item[]): this;
|
|
236
|
+
toc(nav: NavList, option?: Partial<NavOption>): this;
|
|
237
|
+
spine(...items: Item[]): this;
|
|
238
|
+
bundle(): Promise<Uint8Array>;
|
|
239
|
+
writeFile(file: string): Promise<void>;
|
|
238
240
|
}
|
|
239
241
|
|
|
240
|
-
declare class BundleError extends Error {
|
|
241
|
-
constructor(msg: string);
|
|
242
|
+
declare class BundleError extends Error {
|
|
243
|
+
constructor(msg: string);
|
|
242
244
|
}
|
|
243
245
|
|
|
244
|
-
type PageTemplate<T = any> = (file: string, props: T) => XHTMLBuilder;
|
|
245
|
-
interface Theme<P extends Record<string, PageTemplate<any>>> {
|
|
246
|
-
name: string;
|
|
247
|
-
styles: string[];
|
|
248
|
-
images: string[];
|
|
249
|
-
pages: Prettify<{
|
|
250
|
-
cover(file: string, props: {
|
|
251
|
-
image: Image;
|
|
252
|
-
title?: string;
|
|
253
|
-
}): XHTMLBuilder;
|
|
254
|
-
nav(file: string, props: {
|
|
255
|
-
nav: NavList;
|
|
256
|
-
option: Partial<NavOption>;
|
|
257
|
-
}): XHTMLBuilder;
|
|
258
|
-
} & P>;
|
|
246
|
+
type PageTemplate<T = any> = (file: string, props: T) => XHTMLBuilder;
|
|
247
|
+
interface Theme<P extends Record<string, PageTemplate<any>>> {
|
|
248
|
+
name: string;
|
|
249
|
+
styles: string[];
|
|
250
|
+
images: string[];
|
|
251
|
+
pages: Prettify<{
|
|
252
|
+
cover(file: string, props: {
|
|
253
|
+
image: Image;
|
|
254
|
+
title?: string;
|
|
255
|
+
}): XHTMLBuilder;
|
|
256
|
+
nav(file: string, props: {
|
|
257
|
+
nav: NavList;
|
|
258
|
+
option: Partial<NavOption>;
|
|
259
|
+
}): XHTMLBuilder;
|
|
260
|
+
} & P>;
|
|
259
261
|
}
|
|
260
262
|
|
|
261
|
-
declare const UnbuildPreset: (options?: {
|
|
262
|
-
inject?: boolean;
|
|
263
|
-
}) => BuildConfig;
|
|
263
|
+
declare const UnbuildPreset: (options?: {
|
|
264
|
+
inject?: boolean;
|
|
265
|
+
}) => BuildConfig;
|
|
264
266
|
declare function Rollup(): Plugin;
|
|
265
267
|
|
|
266
268
|
export { Author, BundleError, Epub, EpubIntrinsicElements, Fragment, HTML, HTMLMeta, Image, ImageExtension, ImageGif, ImageJpeg, ImageMediaType, ImagePng, ImageSvg, ImageWebp, Item, MIMETYPE, ManifestItem, ManifestItemRef, MediaType, NavList, NavOption, PackageDocument, PackageDocumentMeta, PageTemplate, Rollup, Style, TextCSS, TextXHTML, Theme, Toc, UnbuildPreset, XHTML, XHTMLBuilder, XHTMLNode, getImageMediaType, h };
|
package/dist/index.mjs
CHANGED
|
@@ -226,6 +226,7 @@ class XHTMLBuilder {
|
|
|
226
226
|
};
|
|
227
227
|
this._head = [];
|
|
228
228
|
this._body = [];
|
|
229
|
+
this._bodyAttrs = {};
|
|
229
230
|
this._filename = filename;
|
|
230
231
|
this._meta.title = path$1.basename(filename);
|
|
231
232
|
}
|
|
@@ -271,6 +272,14 @@ class XHTMLBuilder {
|
|
|
271
272
|
this._body.push(...node);
|
|
272
273
|
return this;
|
|
273
274
|
}
|
|
275
|
+
bodyAttrs(attrs = {}) {
|
|
276
|
+
const a = Object.entries(attrs).map(([key, value]) => [`@_${key}`, value]);
|
|
277
|
+
this._bodyAttrs = {
|
|
278
|
+
...this._bodyAttrs,
|
|
279
|
+
...Object.fromEntries(a)
|
|
280
|
+
};
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
274
283
|
build() {
|
|
275
284
|
const content = builder.build({
|
|
276
285
|
html: {
|
|
@@ -282,7 +291,10 @@ class XHTMLBuilder {
|
|
|
282
291
|
title: this._meta.title,
|
|
283
292
|
...list(this._head)
|
|
284
293
|
},
|
|
285
|
-
body:
|
|
294
|
+
body: {
|
|
295
|
+
...this._bodyAttrs,
|
|
296
|
+
...list(this._body)
|
|
297
|
+
}
|
|
286
298
|
}
|
|
287
299
|
});
|
|
288
300
|
return new XHTML(this._filename, this._meta, content);
|