@epubook/core 0.0.10 → 0.0.12-beta.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @epubook/core
2
2
 
3
- [![version](https://img.shields.io/npm/v/@epubook/core?color=rgb%2850%2C203%2C86%29&label=@epubook/core)](https://www.npmjs.com/package/@epubook/theme-core) [![CI](https://github.com/yjl9903/epubook/actions/workflows/ci.yml/badge.svg)](https://github.com/yjl9903/epubook/actions/workflows/ci.yml)
3
+ [![version](https://img.shields.io/npm/v/@epubook/core?color=rgb%2850%2C203%2C86%29&label=@epubook/core)](https://www.npmjs.com/package/@epubook/core) [![CI](https://github.com/yjl9903/epubook/actions/workflows/ci.yml/badge.svg)](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
 
@@ -36,39 +36,19 @@ await book.writeFile('./test.epub')
36
36
  You can use jsx to create XHTML node.
37
37
 
38
38
  ```tsx
39
- // Your theme code ...
39
+ /** @jsxImportSource @epubook/xml */
40
40
 
41
41
  import { XHTMLBuilder } from '@epubook/core'
42
42
 
43
43
  const builder = new XHTMLBuilder()
44
44
 
45
- builder
46
- .body(<h1>Title</h1>)
47
- .body(<p>This is a paragraph</p>)
45
+ const xhtml = builder
46
+ .appendBody(<h1>Title</h1>)
47
+ .appendBody(<p>This is a paragraph</p>)
48
48
  .build()
49
49
  ```
50
50
 
51
- Currently, it supports use [unbuild](https://github.com/unjs/unbuild) to transform JSX / TSX and bundle your library.
52
-
53
- ```ts
54
- // build.config.ts
55
-
56
- import { defineBuildConfig } from 'unbuild';
57
-
58
- import { UnbuildPreset } from '@epubook/core';
59
-
60
- export default defineBuildConfig({
61
- entries: ['src/index'],
62
- declaration: true,
63
- clean: true,
64
- rollup: {
65
- emitCJS: true
66
- },
67
- preset: UnbuildPreset()
68
- });
69
- ```
70
-
71
- You can see [@epubook/theme-default](https://github.com/yjl9903/epubook/tree/main/packages/theme-default) for more details.
51
+ You can see [@epubook/theme](https://github.com/yjl9903/epubook/tree/main/packages/theme) for more details.
72
52
 
73
53
  ## License
74
54
 
@@ -0,0 +1,235 @@
1
+ import * as _$_epubook_xml0 from "@epubook/xml";
2
+ import { XHTMLMeta } from "@epubook/xml";
3
+
4
+ //#region src/utils/types.d.ts
5
+ type Prettify<T> = { [K in keyof T]: T[K] } & {};
6
+ //#endregion
7
+ //#region src/constant.d.ts
8
+ declare const MIMETYPE = "application/epub+zip";
9
+ declare const ImageGif = "image/gif";
10
+ declare const ImageJpeg = "image/jpeg";
11
+ declare const ImagePng = "image/png";
12
+ declare const ImageSvg = "image/svg+xml";
13
+ declare const ImageWebp = "image/webp";
14
+ type ImageMediaType = typeof ImageGif | typeof ImageJpeg | typeof ImagePng | typeof ImageSvg | typeof ImageWebp;
15
+ type ImageExtension = 'gif' | 'jpg' | 'jpeg' | 'png' | 'svg' | 'webp';
16
+ declare const TextCSS = "text/css";
17
+ declare const TextXHTML = "application/xhtml+xml";
18
+ type MediaType = ImageMediaType | typeof TextCSS | typeof TextXHTML;
19
+ type Properties = 'nav' | 'cover-image' | string;
20
+ declare function getImageMediaType(file: string): ImageMediaType | undefined;
21
+ //#endregion
22
+ //#region src/epub/manifest.d.ts
23
+ declare class Manifest {
24
+ readonly rendition: Rendition;
25
+ private _resources;
26
+ constructor(rendition: Rendition);
27
+ get resources(): Resource[];
28
+ get items(): Item[];
29
+ get itemrefs(): ItemRef[];
30
+ add(...resources: Resource[]): this;
31
+ [Symbol.iterator](): ArrayIterator<Resource>;
32
+ map(fn: (resource: Resource, index: number, manifest: Manifest) => boolean): Resource[];
33
+ filter(predicate: (resource: Resource, index: number, manifest: Manifest) => boolean): Manifest;
34
+ }
35
+ declare class Item {
36
+ private _href;
37
+ private _id;
38
+ private optional;
39
+ constructor(href: string, id: string, info?: typeof this.optional);
40
+ update(info: typeof this.optional): this;
41
+ href(): string;
42
+ id(): string;
43
+ fallback(): string | undefined;
44
+ mediaOverlay(): string | undefined;
45
+ mediaType(): MediaType | undefined;
46
+ properties(): string | undefined;
47
+ ref(): ItemRef;
48
+ }
49
+ declare class ItemRef {
50
+ private _idref;
51
+ private optional;
52
+ constructor(idref: string);
53
+ update(info: typeof this.optional): this;
54
+ idref(): string;
55
+ id(): string | undefined;
56
+ linear(): string | undefined;
57
+ properties(): string | undefined;
58
+ }
59
+ //#endregion
60
+ //#region src/resource/resource.d.ts
61
+ declare abstract class Resource {
62
+ protected readonly _id: string;
63
+ protected readonly _fullPath: string;
64
+ protected _mediaType: MediaType;
65
+ protected _properties?: Properties;
66
+ constructor(id: string | undefined, fullPath: string, mediaType: MediaType);
67
+ get id(): string;
68
+ get path(): string;
69
+ relative(from: string): any;
70
+ updateAttrs(info: Partial<{
71
+ mediaType: MediaType;
72
+ properties: Properties;
73
+ }>): this;
74
+ item(): Item;
75
+ itemref(): ItemRef;
76
+ abstract bundle(): Promise<Uint8Array>;
77
+ }
78
+ declare class StyleSheet extends Resource {
79
+ private _content;
80
+ constructor(fullPath: string, content?: string, options?: {
81
+ id?: string;
82
+ });
83
+ update(content: string): this;
84
+ bundle(): Promise<Uint8Array>;
85
+ }
86
+ declare class Image extends Resource {
87
+ private _data;
88
+ constructor(fullPath: string, type: ImageMediaType, data?: Uint8Array | undefined, options?: {
89
+ id?: string;
90
+ });
91
+ update(type: ImageMediaType, data: Uint8Array): this;
92
+ bundle(): Promise<Uint8Array>;
93
+ }
94
+ declare class Cover extends Image {
95
+ constructor(fullPath: string, type: ImageMediaType, data?: Uint8Array | undefined, options?: {
96
+ id?: string;
97
+ });
98
+ }
99
+ declare class XHTML extends Resource {
100
+ private _meta;
101
+ private _content;
102
+ constructor(fullPath: string, meta?: Partial<XHTMLMeta>, content?: string | undefined, options?: {
103
+ id?: string;
104
+ });
105
+ get meta(): XHTMLMeta;
106
+ get title(): string;
107
+ get language(): string;
108
+ get content(): string | undefined;
109
+ update(text: string): this;
110
+ bundle(): Promise<Uint8Array>;
111
+ }
112
+ //#endregion
113
+ //#region src/resource/navigation.d.ts
114
+ type NavItem = {
115
+ title: string;
116
+ attrs?: Record<string, string>;
117
+ };
118
+ type NavResourceLink = Prettify<NavItem & {
119
+ resource: Resource;
120
+ }>;
121
+ type NavStaticLink = Prettify<NavItem & {
122
+ href: string;
123
+ }>;
124
+ type NavLink = NavResourceLink | NavStaticLink;
125
+ type NavSubList = Prettify<NavItem & {
126
+ children: NavLink[];
127
+ }>;
128
+ type NavList = Array<NavLink | NavSubList>;
129
+ interface NavOption {
130
+ title?: string;
131
+ heading?: {
132
+ level?: 1 | 2 | 3 | 4 | 5 | 6;
133
+ attrs?: Record<string, string>;
134
+ text?: string;
135
+ };
136
+ }
137
+ declare class Navigation extends Resource {
138
+ private _nav;
139
+ private _options;
140
+ constructor(fullPath?: string, nav?: NavList, options?: Partial<NavOption>);
141
+ update(nav: NavList, options?: Partial<NavOption>): this;
142
+ generate(): {
143
+ filename: string;
144
+ meta: _$_epubook_xml0.XHTMLMeta;
145
+ content: string;
146
+ };
147
+ bundle(): Promise<Uint8Array>;
148
+ }
149
+ //#endregion
150
+ //#region src/epub/spine.d.ts
151
+ declare class Spine {
152
+ readonly rendition: Rendition;
153
+ private _itemrefs;
154
+ constructor(rendition: Rendition);
155
+ get itemrefs(): ItemRef[];
156
+ shift(): ItemRef | undefined;
157
+ unshift(ref: ItemRef): this;
158
+ pop(): ItemRef | undefined;
159
+ push(...itemrefs: ItemRef[]): this;
160
+ clear(): this;
161
+ [Symbol.iterator](): ArrayIterator<ItemRef>;
162
+ }
163
+ //#endregion
164
+ //#region src/epub/rendition.d.ts
165
+ interface Author {
166
+ name: string;
167
+ fileAs?: string;
168
+ role?: string;
169
+ uid?: string;
170
+ }
171
+ interface PackageDocumentMeta {
172
+ title: string;
173
+ language: string;
174
+ contributor: Author[];
175
+ coverage: string;
176
+ creator: Author;
177
+ date: Date;
178
+ description: string;
179
+ format: string;
180
+ publisher: string;
181
+ relation: string;
182
+ rights: string;
183
+ source: string;
184
+ subject: string;
185
+ type: string;
186
+ lastModified: Date;
187
+ }
188
+ declare class Rendition {
189
+ private readonly _fullPath;
190
+ private readonly _specVersion;
191
+ private _uniqueIdentifier;
192
+ private _identifier;
193
+ private _metadata;
194
+ private _cover;
195
+ private _manifest;
196
+ private _spine;
197
+ private _navigation;
198
+ constructor(fullPath: string);
199
+ get path(): string;
200
+ get version(): "3.0";
201
+ get title(): string;
202
+ get language(): string;
203
+ get creator(): Author;
204
+ get metadata(): PackageDocumentMeta;
205
+ get cover(): Cover | undefined;
206
+ updateMetadata(newMetadata: Partial<PackageDocumentMeta>): this;
207
+ get uniqueIdentifier(): string;
208
+ get identifier(): string;
209
+ setIdentifier(identifier: string, uniqueIdentifier?: string): this;
210
+ get manifest(): Manifest;
211
+ get spine(): Spine;
212
+ get navigation(): Navigation | undefined;
213
+ setNavigation(navigation: Navigation): this;
214
+ setCover(cover: Cover): this;
215
+ addResource(resource: Resource): this;
216
+ }
217
+ //#endregion
218
+ //#region src/epub/publication.d.ts
219
+ declare class EpubPublication {
220
+ /**
221
+ * See: https://www.w3.org/TR/epub-33/#sec-package-doc
222
+ *
223
+ * Now, it only supports single opf (OEBPS/content.opf)
224
+ *
225
+ * @returns list of package documents
226
+ */
227
+ private _rootfiles;
228
+ private constructor();
229
+ static empty(): EpubPublication;
230
+ static create(fullPath?: string, rootMeta?: Partial<PackageDocumentMeta>): EpubPublication;
231
+ get rootfile(): Rendition;
232
+ get rootfiles(): Rendition[];
233
+ }
234
+ //#endregion
235
+ export { Author, Cover, EpubPublication, Image, ImageExtension, ImageGif, ImageJpeg, ImageMediaType, ImagePng, ImageSvg, ImageWebp, Item, ItemRef, MIMETYPE, Manifest, MediaType, NavItem, NavLink, NavList, NavOption, NavResourceLink, NavStaticLink, NavSubList, Navigation, PackageDocumentMeta, Properties, Rendition, Resource, StyleSheet, TextCSS, TextXHTML, XHTML, getImageMediaType };