@epubook/theme 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/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.mjs +42 -0
- package/package.json +54 -0
- package/styles/cover.css +13 -0
- package/styles/main.css +263 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 XLor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @epubook/theme
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@epubook/theme)
|
|
4
|
+
|
|
5
|
+
The default theme for [epubook](https://github.com/yjl9903/epubook).
|
|
6
|
+
|
|
7
|
+
## Page templates
|
|
8
|
+
|
|
9
|
+
+ nav: Generate empty nav page
|
|
10
|
+
+ cover: Generate a page with a single cover image
|
|
11
|
+
+ chapter: Generate a content page with a title and lines of content
|
|
12
|
+
|
|
13
|
+
## Conventions
|
|
14
|
+
|
|
15
|
+
Themes are published to npm registry, and they should follow the conventions below:
|
|
16
|
+
|
|
17
|
+
+ Package name should start with `epubook-theme-`, for example `epubook-theme-custom` or `@my/epubook-theme-custom`
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
MIT License © 2023 [XLor](https://github.com/yjl9903)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type DefaultThemePageTemplate = {
|
|
3
|
+
chapter: PageTemplate<{
|
|
4
|
+
title: string;
|
|
5
|
+
content: string;
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/chapter.d.ts
|
|
10
|
+
declare const Chapter: DefaultThemePageTemplate['chapter'];
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/index.d.ts
|
|
13
|
+
declare function DefaultTheme(): Promise<Theme<DefaultThemePageTemplate>>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { Chapter, DefaultTheme, DefaultThemePageTemplate };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { XHTMLBuilder } from "@epubook/core";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "@epubook/xml/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/chapter.tsx
|
|
8
|
+
const Chapter = (file, { title, content }) => {
|
|
9
|
+
const lines = content.split(/\r?\n/);
|
|
10
|
+
return new XHTMLBuilder(file).title(title).body(/* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h2", { children: title }), lines.map((l) => /* @__PURE__ */ jsx("p", { children: l }))] }));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/index.ts
|
|
15
|
+
const styles = ["./styles/main.css", "./styles/cover.css"];
|
|
16
|
+
async function DefaultTheme() {
|
|
17
|
+
return {
|
|
18
|
+
name: "@epubook/theme-default",
|
|
19
|
+
styles: await Promise.all(styles.map((d) => loadStyle(d))),
|
|
20
|
+
images: [],
|
|
21
|
+
pages: {
|
|
22
|
+
cover(file, { image, title = "封面" }) {
|
|
23
|
+
return new XHTMLBuilder(file).title(title).bodyAttrs({ class: "cover" }).body({
|
|
24
|
+
tag: "img",
|
|
25
|
+
attrs: { src: image.relative(file) }
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
nav(file, { nav, option }) {
|
|
29
|
+
if (!option.title) option.title = "目录";
|
|
30
|
+
return new XHTMLBuilder(file).title("目录");
|
|
31
|
+
},
|
|
32
|
+
chapter: Chapter
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function loadStyle(dir) {
|
|
37
|
+
const d = path.join(fileURLToPath(import.meta.url), "../../", dir);
|
|
38
|
+
return fs.promises.readFile(d, "utf-8");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { Chapter, DefaultTheme };
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@epubook/theme",
|
|
3
|
+
"version": "0.0.12-beta.1",
|
|
4
|
+
"description": "Epubook theme",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ebook",
|
|
7
|
+
"epub",
|
|
8
|
+
"epub-generator",
|
|
9
|
+
"epubook",
|
|
10
|
+
"epubook-theme"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/yjl9903/epubook#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/yjl9903/epubook/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/yjl9903/epubook.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "XLor",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"import": "./dist/index.mjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"module": "./dist/index.mjs",
|
|
31
|
+
"types": "./dist/index.d.mts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"styles"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@epubook/core": "0.0.12-beta.1",
|
|
38
|
+
"@epubook/xml": "0.0.12-beta.1"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=v20.10.0"
|
|
42
|
+
},
|
|
43
|
+
"epubook": {
|
|
44
|
+
"styles": [
|
|
45
|
+
"styles/main.css",
|
|
46
|
+
"styles/cover.css"
|
|
47
|
+
],
|
|
48
|
+
"images": []
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build!": "tsdown",
|
|
52
|
+
"typecheck!": "tsc --noEmit"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/styles/cover.css
ADDED
package/styles/main.css
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/* See: https://github.com/spajak/epub3-boilerplate */
|
|
2
|
+
|
|
3
|
+
@charset "UTF-8";
|
|
4
|
+
|
|
5
|
+
@page {
|
|
6
|
+
margin-left: 10pt;
|
|
7
|
+
margin-right: 10pt;
|
|
8
|
+
padding: 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.hidden, [hidden] {
|
|
12
|
+
display: none;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* --- sections --- */
|
|
16
|
+
article,
|
|
17
|
+
aside,
|
|
18
|
+
blockquote,
|
|
19
|
+
figure,
|
|
20
|
+
figcaption,
|
|
21
|
+
footer,
|
|
22
|
+
header,
|
|
23
|
+
main,
|
|
24
|
+
nav,
|
|
25
|
+
section {
|
|
26
|
+
display: block;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
body {
|
|
30
|
+
font-size: 100%;
|
|
31
|
+
font-weight: normal;
|
|
32
|
+
text-align: justify;
|
|
33
|
+
line-height: 1.35;
|
|
34
|
+
margin: 0;
|
|
35
|
+
padding: 0;
|
|
36
|
+
-webkit-hyphens: auto;
|
|
37
|
+
hyphens: auto;
|
|
38
|
+
widows: 2;
|
|
39
|
+
orphans: 2;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
section, nav {
|
|
43
|
+
page-break-before: always;
|
|
44
|
+
page-break-after: always;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
h1, h2, h3, h4, h5, h6 {
|
|
48
|
+
text-align: center;
|
|
49
|
+
line-height: 1.25;
|
|
50
|
+
font-weight: bold;
|
|
51
|
+
margin: 1.5em 0;
|
|
52
|
+
-epub-hyphens: none;
|
|
53
|
+
hyphens: none;
|
|
54
|
+
page-break-after: avoid;
|
|
55
|
+
page-break-inside: avoid;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
h1 {
|
|
59
|
+
font-size: 2em;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
h2 {
|
|
63
|
+
font-size: 1.625em;
|
|
64
|
+
margin-top: 2.75em;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
h3 {
|
|
68
|
+
font-size: 1.375em;
|
|
69
|
+
margin-top: 2em;
|
|
70
|
+
margin-bottom: 1.25em;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
h4 {
|
|
74
|
+
font-size: 1.125em;
|
|
75
|
+
margin-bottom: 1em;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
h5, h6 {
|
|
79
|
+
font-size: 1em;
|
|
80
|
+
margin-top: 1em;
|
|
81
|
+
margin-bottom: 0.75em;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
h6 {
|
|
85
|
+
font-style: italic;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* --- Content grouping --- */
|
|
89
|
+
p, blockquote, figure, ol, ul, dl, pre {
|
|
90
|
+
margin-top: 1em;
|
|
91
|
+
margin-bottom: 1em;
|
|
92
|
+
text-indent: 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
p.classic,
|
|
96
|
+
p.book,
|
|
97
|
+
p.novel {
|
|
98
|
+
margin-top: 0;
|
|
99
|
+
margin-bottom: 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
p + p.classic,
|
|
103
|
+
p + p.book,
|
|
104
|
+
p + p.novel {
|
|
105
|
+
text-indent: 1.125em;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
p.stanza, p.verses, p.verse, p.poetry {
|
|
109
|
+
margin-top: 1em;
|
|
110
|
+
margin-bottom: 1em;
|
|
111
|
+
text-align: left;
|
|
112
|
+
text-indent: 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
blockquote {
|
|
116
|
+
padding-left: 18pt;
|
|
117
|
+
padding-right: 18pt;
|
|
118
|
+
margin-left: 0;
|
|
119
|
+
margin-right: 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
blockquote.fancy {
|
|
123
|
+
padding-left: 10pt;
|
|
124
|
+
padding-right: 16pt;
|
|
125
|
+
border-left: 0.875rem solid #9F9F9F;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
dt {
|
|
129
|
+
font-weight: bold;
|
|
130
|
+
text-align: left;
|
|
131
|
+
page-break-after: avoid;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
dd {
|
|
135
|
+
padding: 0;
|
|
136
|
+
margin-left: 0;
|
|
137
|
+
margin-right: 0;
|
|
138
|
+
margin-bottom: 0.25em;
|
|
139
|
+
padding-left: 22pt;
|
|
140
|
+
page-break-before: avoid;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
figure {
|
|
144
|
+
padding: 0;
|
|
145
|
+
margin-left: 0;
|
|
146
|
+
margin-right: 0;
|
|
147
|
+
text-align: center;
|
|
148
|
+
page-break-inside: avoid;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
figcaption {
|
|
152
|
+
margin: 0.25em auto;
|
|
153
|
+
line-height: 1.25;
|
|
154
|
+
font-size: 0.875em;
|
|
155
|
+
text-align: center;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
hr {
|
|
159
|
+
height: 0;
|
|
160
|
+
width: auto;
|
|
161
|
+
padding: 0;
|
|
162
|
+
border: 0 none;
|
|
163
|
+
border-top: 0.125rem solid currentColor;
|
|
164
|
+
margin: 1.5em auto;
|
|
165
|
+
text-align: center;
|
|
166
|
+
page-break-after: avoid;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
pre {
|
|
170
|
+
tab-size: 2;
|
|
171
|
+
text-align: left;
|
|
172
|
+
display: block;
|
|
173
|
+
white-space: pre-wrap;
|
|
174
|
+
font-size: 0.8125em;
|
|
175
|
+
line-height: 1.25;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* --- List --- */
|
|
179
|
+
ul, ol {
|
|
180
|
+
text-align: initial;
|
|
181
|
+
list-style-position: outside;
|
|
182
|
+
margin-left: 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
ol {
|
|
186
|
+
list-style-type: decimal;
|
|
187
|
+
padding-left: 34pt;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
ol.wide {
|
|
191
|
+
padding-left: 44pt;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
ul {
|
|
195
|
+
list-style-type: disc;
|
|
196
|
+
padding-left: 24pt;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
ul ul {
|
|
200
|
+
list-style-type: circle;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
li ol, li ul {
|
|
204
|
+
margin-top: 0;
|
|
205
|
+
margin-bottom: 0;
|
|
206
|
+
padding-left: 24pt;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
li ul {
|
|
210
|
+
padding-left: 16pt;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* --- Image --- */
|
|
214
|
+
img {
|
|
215
|
+
max-width: 100%;
|
|
216
|
+
max-height: 100%;
|
|
217
|
+
object-fit: contain;
|
|
218
|
+
vertical-align: bottom;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* --- Text --- */
|
|
222
|
+
em, cite, q, i {
|
|
223
|
+
font-style: italic;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
q {
|
|
227
|
+
quotes: none !important;
|
|
228
|
+
font-style: italic !important;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
dfn {
|
|
232
|
+
font-style: normal;
|
|
233
|
+
font-weight: bold;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
strong, b {
|
|
237
|
+
font-weight: bold;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
small {
|
|
241
|
+
font-size: 0.875em;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
sub, sup {
|
|
245
|
+
font-size: 0.675em;
|
|
246
|
+
line-height: 1.2;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
sub {
|
|
250
|
+
vertical-align: sub;
|
|
251
|
+
vertical-align: -20%;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
sup {
|
|
255
|
+
vertical-align: super;
|
|
256
|
+
vertical-align: 35%;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
code {
|
|
260
|
+
white-space: pre;
|
|
261
|
+
text-align: left;
|
|
262
|
+
font-family: monospace;
|
|
263
|
+
}
|