@epubook/core 0.0.2 → 0.0.4
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 +7 -13
- package/dist/chunks/index.cjs +4 -3
- package/dist/chunks/index.mjs +4 -3
- package/dist/index.cjs +588 -24
- package/dist/index.d.ts +131 -77
- package/dist/index.mjs +550 -7
- package/package.json +4 -4
- package/dist/shared/core.2c388ac3.cjs +0 -490
- package/dist/shared/core.c365bf12.mjs +0 -461
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { Plugin } from 'rollup';
|
|
2
|
-
import {
|
|
2
|
+
import { BuildConfig } from 'unbuild';
|
|
3
3
|
|
|
4
|
+
declare const MIMETYPE = "application/epub+zip";
|
|
4
5
|
declare const ImageGif = "image/gif";
|
|
5
6
|
declare const ImageJpeg = "image/jpeg";
|
|
6
7
|
declare const ImagePng = "image/png";
|
|
7
8
|
declare const ImageSvg = "image/svg+xml";
|
|
8
9
|
declare const ImageWebp = "image/webp";
|
|
9
10
|
type ImageMediaType = typeof ImageGif | typeof ImageJpeg | typeof ImagePng | typeof ImageSvg | typeof ImageWebp;
|
|
11
|
+
type ImageExtension = 'gif' | 'jpg' | 'jpeg' | 'png' | 'svg' | 'webp';
|
|
10
12
|
declare const TextCSS = "text/css";
|
|
11
|
-
declare const
|
|
12
|
-
type MediaType = ImageMediaType | typeof TextCSS | typeof
|
|
13
|
+
declare const TextXHTML = "application/xhtml+xml";
|
|
14
|
+
type MediaType = ImageMediaType | typeof TextCSS | typeof TextXHTML;
|
|
15
|
+
declare function getImageMediaType(file: string): ImageMediaType | undefined;
|
|
13
16
|
|
|
14
17
|
declare class ManifestItem {
|
|
15
18
|
private _href;
|
|
@@ -34,13 +37,15 @@ declare class ManifestItemRef {
|
|
|
34
37
|
id(): string | undefined;
|
|
35
38
|
linear(): string | undefined;
|
|
36
39
|
properties(): string | undefined;
|
|
37
|
-
}
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
declare abstract class Item {
|
|
39
43
|
private readonly file;
|
|
40
44
|
private readonly mediaType;
|
|
41
45
|
private _properties?;
|
|
42
46
|
constructor(file: string, mediaType: MediaType);
|
|
43
47
|
filename(): string;
|
|
48
|
+
relative(from: string): string;
|
|
44
49
|
update(info: Partial<{
|
|
45
50
|
properties: string;
|
|
46
51
|
}>): this;
|
|
@@ -49,12 +54,6 @@ declare abstract class Item {
|
|
|
49
54
|
itemref(): ManifestItemRef;
|
|
50
55
|
abstract bundle(): Promise<Uint8Array>;
|
|
51
56
|
}
|
|
52
|
-
declare class Html extends Item {
|
|
53
|
-
private content;
|
|
54
|
-
constructor(file: string, content: string);
|
|
55
|
-
static read(src: string, dst: string): Promise<Html | undefined>;
|
|
56
|
-
bundle(): Promise<Uint8Array>;
|
|
57
|
-
}
|
|
58
57
|
declare class Style extends Item {
|
|
59
58
|
private content;
|
|
60
59
|
constructor(file: string, content: string);
|
|
@@ -64,9 +63,107 @@ declare class Style extends Item {
|
|
|
64
63
|
declare class Image extends Item {
|
|
65
64
|
private data;
|
|
66
65
|
constructor(file: string, type: ImageMediaType, data: Uint8Array);
|
|
67
|
-
static read(
|
|
66
|
+
static read(file: string, src: string): Promise<Image | undefined>;
|
|
68
67
|
bundle(): Promise<Uint8Array>;
|
|
69
|
-
|
|
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
|
+
}
|
|
75
|
+
|
|
76
|
+
type Prettify<T> = {
|
|
77
|
+
[K in keyof T]: T[K];
|
|
78
|
+
} & {};
|
|
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
|
+
};
|
|
109
|
+
}
|
|
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)[];
|
|
116
|
+
};
|
|
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
|
+
constructor(filename: string);
|
|
138
|
+
language(value: string): this;
|
|
139
|
+
title(value: string): this;
|
|
140
|
+
style(...list: Array<string | Style>): this;
|
|
141
|
+
head(...node: XHTMLNode[]): this;
|
|
142
|
+
body(...node: XHTMLNode[]): this;
|
|
143
|
+
build(): XHTML;
|
|
144
|
+
}
|
|
145
|
+
|
|
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;
|
|
70
167
|
}
|
|
71
168
|
|
|
72
169
|
interface Author {
|
|
@@ -112,20 +209,14 @@ declare class PackageDocument {
|
|
|
112
209
|
addItem(item: Item): this;
|
|
113
210
|
items(): Item[];
|
|
114
211
|
manifest(): ManifestItem[];
|
|
115
|
-
setSpine(items: Item[]): this;
|
|
116
212
|
spine(): ManifestItemRef[];
|
|
117
|
-
|
|
213
|
+
setSpine(items: Item[]): this;
|
|
214
|
+
toc(): Toc | undefined;
|
|
215
|
+
setToc(nav: NavList, option?: Partial<NavOption>): this;
|
|
118
216
|
uniqueIdentifier(): string;
|
|
119
217
|
identifier(): string;
|
|
120
218
|
setIdentifier(identifier: string, uniqueIdentifier?: string): void;
|
|
121
|
-
}
|
|
122
|
-
type NavOption = Array<{
|
|
123
|
-
text: string;
|
|
124
|
-
item: Html | Array<{
|
|
125
|
-
text: string;
|
|
126
|
-
item: Html;
|
|
127
|
-
}>;
|
|
128
|
-
}>;
|
|
219
|
+
}
|
|
129
220
|
|
|
130
221
|
declare class Epub {
|
|
131
222
|
/**
|
|
@@ -139,8 +230,8 @@ declare class Epub {
|
|
|
139
230
|
constructor(meta?: Partial<PackageDocumentMeta>);
|
|
140
231
|
packages(): PackageDocument[];
|
|
141
232
|
main(): PackageDocument;
|
|
142
|
-
|
|
143
|
-
toc(nav:
|
|
233
|
+
item(...items: Item[]): this;
|
|
234
|
+
toc(nav: NavList, option?: Partial<NavOption>): this;
|
|
144
235
|
spine(...items: Item[]): this;
|
|
145
236
|
bundle(): Promise<Uint8Array>;
|
|
146
237
|
writeFile(file: string): Promise<void>;
|
|
@@ -150,63 +241,26 @@ declare class BundleError extends Error {
|
|
|
150
241
|
constructor(msg: string);
|
|
151
242
|
}
|
|
152
243
|
|
|
153
|
-
|
|
244
|
+
type PageTemplate<T = any> = (file: string, props: T) => XHTMLBuilder;
|
|
245
|
+
interface Theme<P extends Record<string, PageTemplate<any>>> {
|
|
154
246
|
name: string;
|
|
155
|
-
pages: string[];
|
|
156
247
|
styles: string[];
|
|
157
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>;
|
|
158
259
|
}
|
|
159
260
|
|
|
160
|
-
declare
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
interface XHTMLNode {
|
|
167
|
-
tag: string;
|
|
168
|
-
attrs?: Record<string, string>;
|
|
169
|
-
children?: Array<string | XHTMLNode>;
|
|
170
|
-
}
|
|
171
|
-
interface EpubIntrinsicElements {
|
|
172
|
-
nav: {};
|
|
173
|
-
ul: {};
|
|
174
|
-
ol: {};
|
|
175
|
-
li: {};
|
|
176
|
-
h1: {};
|
|
177
|
-
h2: {};
|
|
178
|
-
h3: {};
|
|
179
|
-
h4: {};
|
|
180
|
-
h5: {};
|
|
181
|
-
h6: {};
|
|
182
|
-
p: {};
|
|
183
|
-
pre: {};
|
|
184
|
-
span: {};
|
|
185
|
-
code: {};
|
|
186
|
-
a: {
|
|
187
|
-
href: string;
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
declare class XHTMLBuilder {
|
|
192
|
-
private info;
|
|
193
|
-
private _head;
|
|
194
|
-
private _body;
|
|
195
|
-
constructor();
|
|
196
|
-
language(value: string): this;
|
|
197
|
-
title(value: string): this;
|
|
198
|
-
style(href: string): this;
|
|
199
|
-
body(node: XHTMLNode): this;
|
|
200
|
-
build(): string;
|
|
201
|
-
}
|
|
202
|
-
declare const Fragment = "Fragment";
|
|
203
|
-
declare function h(tag: string, attrs?: Record<string, string>, ...children: Array<string | XHTMLNode | Array<string | XHTMLNode>>): {
|
|
204
|
-
tag: string;
|
|
205
|
-
attrs: Record<string, string>;
|
|
206
|
-
children: (string | XHTMLNode)[];
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
declare const EsbuildOptions: Partial<RollupBuildOptions['esbuild']>;
|
|
261
|
+
declare const UnbuildPreset: (options?: {
|
|
262
|
+
inject?: boolean;
|
|
263
|
+
}) => BuildConfig;
|
|
210
264
|
declare function Rollup(): Plugin;
|
|
211
265
|
|
|
212
|
-
export { Author, BundleError, Epub, EpubIntrinsicElements,
|
|
266
|
+
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 };
|