@epubook/core 0.0.2 → 0.0.3

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/dist/index.d.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  import { Plugin } from 'rollup';
2
- import { RollupBuildOptions } from 'unbuild';
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 XHTML = "application/xhtml+xml";
12
- type MediaType = ImageMediaType | typeof TextCSS | typeof XHTML;
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(src: string, dst: string): Promise<Image | undefined>;
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
+ }
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
+ title(): string;
127
+ language(): string;
128
+ bundle(): Promise<Uint8Array>;
129
+ }
130
+ declare class XHTMLBuilder {
131
+ private meta;
132
+ private _filename;
133
+ private _head;
134
+ private _body;
135
+ constructor(filename: string);
136
+ language(value: string): this;
137
+ title(value: string): this;
138
+ style(href: string | Style): this;
139
+ head(...node: XHTMLNode[]): this;
140
+ body(...node: XHTMLNode[]): this;
141
+ build(): XHTML;
142
+ }
143
+
144
+ type NavItem = {
145
+ title: string;
146
+ attrs?: Record<string, string>;
147
+ };
148
+ type NavLink = Prettify<NavItem & {
149
+ page: HTML | XHTML;
150
+ }>;
151
+ type NavSubList = Prettify<NavItem & {
152
+ list: NavLink[];
153
+ }>;
154
+ type NavList = Array<NavLink | NavSubList>;
155
+ interface NavOption {
156
+ title: string;
157
+ heading: 1 | 2 | 3 | 4 | 5 | 6;
158
+ titleAttrs: Record<string, string>;
159
+ head: XHTMLNode[];
160
+ body: XHTMLNode[];
161
+ }
162
+ declare class Toc extends Item {
163
+ private _builder;
164
+ constructor(file: string);
165
+ generate(nav: NavList, { title, heading, titleAttrs, head, body }?: Partial<NavOption>): XHTMLBuilder;
68
166
  bundle(): Promise<Uint8Array>;
69
- private static getExtMediaType;
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
- toc(nav: NavOption, title?: string): this;
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
- addItem(...items: Item[]): this;
143
- toc(nav: NavOption, title?: string): this;
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,21 @@ declare class BundleError extends Error {
150
241
  constructor(msg: string);
151
242
  }
152
243
 
153
- interface Theme {
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
+ }): XHTMLBuilder;
253
+ } & P>;
158
254
  }
159
255
 
160
- declare global {
161
- namespace JSX {
162
- interface IntrinsicElements extends EpubIntrinsicElements {
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']>;
256
+ declare const UnbuildPreset: (options?: {
257
+ inject?: boolean;
258
+ }) => BuildConfig;
210
259
  declare function Rollup(): Plugin;
211
260
 
212
- export { Author, BundleError, Epub, EpubIntrinsicElements, EsbuildOptions, Fragment, Html, Image, Item, ManifestItem, ManifestItemRef, NavOption, PackageDocument, PackageDocumentMeta, Rollup, Style, Theme, XHTMLBuilder, XHTMLNode, h };
261
+ export { Author, BundleError, Epub, EpubIntrinsicElements, Fragment, HTML, 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 };