base.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. const start = 1;
  2. module.exports = {
  3. opf: function (info, list) {
  4. return new Promise(resolve => {
  5. function item(list) {
  6. let html = '';
  7. list.forEach(key => {
  8. if (startAndEnd(key)) {
  9. html += `
  10. <item id="text${key.index}.xhtml" href="Text/text${key.index}.xhtml" media-type="application/xhtml+xml"/>
  11. `;
  12. }
  13. });
  14. return html;
  15. }
  16. function itemref(list) {
  17. let html = '';
  18. list.forEach(key => {
  19. if (startAndEnd(key)) {
  20. html += `
  21. <itemref idref="text${key.index}.xhtml"/>`;
  22. }
  23. });
  24. return html;
  25. }
  26. let html = `<?xml version="1.0" encoding="utf-8"?>
  27. <package version="2.0" unique-identifier="BookId" xmlns="http://www.idpf.org/2007/opf">
  28. <metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/">
  29. <dc:creator>${info.author}</dc:creator>
  30. <dc:language>zh</dc:language>
  31. <dc:title>${info.name}</dc:title>
  32. <meta content="0.9.10" name="Sigil version" />
  33. <dc:date xmlns:opf="http://www.idpf.org/2007/opf" opf:event="modification">${info.time}</dc:date>
  34. <dc:identifier id="BookId" opf:scheme="UUID">urn:uuid:${info.uid}</dc:identifier>
  35. <meta name="cover" content="cover.jpg" />
  36. </metadata>
  37. <manifest>
  38. <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
  39. ${item(list)}
  40. <item id="book.xhtml" href="Text/book.xhtml" media-type="application/xhtml+xml"/>
  41. <item id="mc-style.css" href="Styles/mc-style.css" media-type="text/css"/>
  42. <item id="cover.jpg" href="Images/cover.jpg" media-type="image/jpeg"/>
  43. <item id="cover.xhtml" href="Text/cover.xhtml" media-type="application/xhtml+xml"/>
  44. </manifest>
  45. <spine toc="ncx">
  46. <itemref idref="cover.xhtml"/>
  47. <itemref idref="book.xhtml"/>
  48. ${itemref(list)}
  49. </spine>
  50. <guide>
  51. <reference type="cover" title="封面" href="Text/cover.xhtml"/>
  52. </guide>
  53. </package>
  54. `;
  55. resolve(html);
  56. });
  57. },
  58. tocNcx: function (info, list) {
  59. return new Promise(resolve => {
  60. function navPoint(list) {
  61. let page = '';
  62. list.forEach(key => {
  63. if (startAndEnd(key)) {
  64. page += `<navPoint id="navPoint-${key.index + 1}" playOrder="${key.index + 1}">
  65. <navLabel>
  66. <text>${key.title}</text>
  67. </navLabel>
  68. <content src="Text/text${key.index}.xhtml"/>
  69. </navPoint>`;
  70. }
  71. });
  72. return page;
  73. }
  74. const html = `<?xml version="1.0" encoding="UTF-8"?>
  75. <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
  76. "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
  77. <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
  78. <head>
  79. <meta name="dtb:uid" content="urn:uuid:${info.uid}"/>
  80. <meta name="dtb:depth" content="1"/>
  81. <meta name="dtb:totalPageCount" content="0"/>
  82. <meta name="dtb:maxPageNumber" content="0"/>
  83. </head>
  84. <docTitle>
  85. <text>${info.name}</text>
  86. </docTitle>
  87. <navMap>
  88. <navPoint id="navPoint-1" playOrder="1">
  89. <navLabel>
  90. <text>制作信息</text>
  91. </navLabel>
  92. <content src="Text/book.xhtml"/>
  93. </navPoint>
  94. ${navPoint(list)}
  95. </navMap>
  96. </ncx>
  97. `;
  98. resolve(html);
  99. });
  100. },
  101. book: function (info) {
  102. return new Promise(resolve => {
  103. const html = `<?xml version="1.0" encoding="utf-8"?>
  104. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  105. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  106. <html xmlns="http://www.w3.org/1999/xhtml">
  107. <head>
  108. <title></title>
  109. <link href="../Styles/mc-style.css" type="text/css" rel="stylesheet"/>
  110. </head>
  111. <body>
  112. <h1 class="sigil_not_in_toc">${info.name}</h1>
  113. <div class="author">
  114. <b>${info.author}</b> <span style="font-size: smaller;">/ 著</span>
  115. </div>
  116. <div class="copyright">
  117. 排版/制作:飞鼠
  118. </div>
  119. <p style="text-align: center; font-size: smaller; text-indent: 0;"><a href="http://mebook.cc" target="_blank">www.mebook.cc</a></p>
  120. </body>
  121. </html>`;
  122. resolve(html);
  123. });
  124. },
  125. page: function (item, content) {
  126. return new Promise(resolve => {
  127. function page(content) {
  128. let contents = content.split('\n');
  129. let html = '';
  130. contents.forEach(key => {
  131. html += `
  132. <p>${key}</p>`;
  133. });
  134. return html;
  135. }
  136. const html = `
  137. <?xml version="1.0" encoding="utf-8"?>
  138. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  139. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  140. <html xmlns="http://www.w3.org/1999/xhtml">
  141. <head><title></title>
  142. <link href="../Styles/mc-style.css" type="text/css" rel="stylesheet"/>
  143. </head>
  144. <body>
  145. <h3 id="id${item.index}">${content.title}</h3>
  146. ${page(content.page)}
  147. </body>
  148. </html>
  149. `;
  150. resolve(html);
  151. });
  152. },
  153. cover: function () {
  154. return `<?xml version="1.0" encoding="utf-8"?>
  155. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  156. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  157. <html xmlns="http://www.w3.org/1999/xhtml">
  158. <head>
  159. <title>Cover</title>
  160. </head>
  161. <body>
  162. <div style="text-align: center; padding: 0pt; margin: 0pt;">
  163. <svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 240 300" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink">
  164. <image width="240" height="300" xlink:href="../Images/cover.jpg"/>
  165. </svg>
  166. </div>
  167. </body>
  168. </html>`;
  169. },
  170. style() {
  171. return `@charset "UTF-8";
  172. /*=========================font-face=========================*/
  173. @font-face {
  174. font-family:"zw";
  175. src:
  176. local("宋体"),local("明体"),local("明朝"),
  177. local("微软雅黑"),local("黑体"),
  178. local("Songti"),local("Songti SC"),local("Songti TC"),
  179. local("Song S"),local("Song T"),local("STBShusong"),local("TBMincho"),local("HYMyeongJo"),
  180. local("DK-SONGTI")
  181. local("Heiti"),local("Heiti SC"),local("Heiti TC"),
  182. local("MYing Hei S"),local("MYing Hei T"),local("TBGothic"),
  183. local("DK-HEITI"),
  184. url(../Fonts/fzzy.ttf);
  185. }
  186. /* This defines styles and classes used in sioebook */
  187. /*Global Setting*/
  188. * {
  189. margin: 0;
  190. padding: 0;
  191. }
  192. body {
  193. padding: 3% 2%;
  194. margin-top: 3%;
  195. margin-bottom: 3%;
  196. margin-left: 1%;
  197. margin-right: 1%;
  198. line-height: 1.3em;
  199. text-align: justify;
  200. font-family: "Times New Roman","方正书宋","宋体","明体","zw",sans-serif;
  201. }
  202. /* P 正常段落 */
  203. p {
  204. margin: 0.5em 0em;
  205. line-height: 1.3em;
  206. text-indent: 2em;
  207. }
  208. /* 居中、右、左 */
  209. .center {
  210. text-indent: 0em;
  211. text-align: center;
  212. }
  213. .right {
  214. text-indent: 0em;
  215. text-align: right;
  216. }
  217. .left {
  218. text-indent: 0em;
  219. text-align: left;
  220. }
  221. /*图片*/
  222. img {
  223. border: none;
  224. text-align: center;
  225. /*max-width: 100%;*/
  226. max-height: 100%;
  227. }
  228. /* 表格 */
  229. table {
  230. border-collapse: collapse;
  231. border-spacing: 0;
  232. margin: 0 auto 0;
  233. width: 100%;
  234. font-size: small;
  235. vertical-align:center;
  236. }
  237. tr,th,td {
  238. margin: 0;
  239. padding: 0.25em;
  240. border: none;
  241. font-size: 95%;
  242. font-family: "Times New Roman","方正书宋","宋体","明体","zw",sans-serif;
  243. text-indent: 0!important;
  244. text-align: left;
  245. vertical-align: middle;
  246. color: #666666;
  247. line-height: 1.05em;
  248. }
  249. /* 列表格式 */
  250. ul, ol {
  251. list-style:none;
  252. }
  253. /* 链接 颜色 不加下划线 */
  254. a {
  255. text-decoration:none;
  256. color: #663366;
  257. }
  258. a:hover {
  259. text-decoration:none;
  260. color: #CC99CC;
  261. }
  262. /* 文案 */
  263. .oval {
  264. padding: 5% 5%;
  265. margin: 12% 5% 2%;
  266. border: 0px dotted #993333;
  267. text-indent: 0em;
  268. font-size: 0.9em;
  269. color: #666666;
  270. }
  271. /* 水平线 */
  272. hr {
  273. border:0;
  274. background-color:#BEBEBE;
  275. height:1.5px;
  276. margin-top: 2%;
  277. margin-bottom: 2%;
  278. }
  279. /* 上下标注 */
  280. sup {
  281. font-size:small;
  282. }
  283. sub {
  284. font-size:small;
  285. }
  286. /* 标题1 书名 卷 */
  287. h1 {
  288. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  289. text-indent: 0em;
  290. text-align:center;
  291. line-height: 2em;
  292. margin-top: 30%;
  293. color: #996699;
  294. text-shadow: 1px 1px 1px gray;
  295. }
  296. h2 {
  297. color: #FFFFFF;
  298. margin-left:25%;
  299. line-height:200%;
  300. border-style: none double solid solid;
  301. border-width: 0px 3px 2px 30px;
  302. font-weight:bold;
  303. font-size:large;
  304. border-color: #FFFFFF;
  305. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  306. text-shadow: 1px 1px 1px gray;
  307. padding: 2px 10px 2px 10px;
  308. }
  309. h2.epub {
  310. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  311. text-indent: 0em;
  312. font-size: 1.2em;
  313. text-align: center;
  314. width: 1em;
  315. margin: 0em 5% 1.5em;
  316. line-height: 110%;
  317. color: #EEEEEE;
  318. border-style: none double none none;
  319. border-width: 0px 3px 0px 0px;
  320. border-color: #EEEEEE;
  321. padding: 0.5em 10px 0.5em 2px;
  322. text-shadow: 0px 0px 0px #AAAAAA;
  323. }
  324. h3 {
  325. margin: 1em 0 5em;
  326. color: #663366;
  327. line-height: 120%;
  328. text-align: left;
  329. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  330. text-shadow: 1px 1px 1px gray;
  331. padding: 15px 12px 1em 5px;
  332. border-style: none none dotted none;
  333. border-color: #CC6699;
  334. border-width: 0px 0px 1px 0px;
  335. text-shadow: 1px 1px 1px #AAAAAA;
  336. }
  337. h3.ebook {
  338. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  339. text-indent: 0em;
  340. margin: 1em 0 1em;
  341. padding: 2px 12px 2px 2px;
  342. text-align: left;
  343. line-height: 120%;
  344. border-style: none none none none;
  345. text-shadow: 1px 1px 1px #AAAAAA;
  346. }
  347. /* 章节序号 */
  348. .num {
  349. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  350. background-color: #CC6699;
  351. border-radius: 2px;
  352. padding: 4px 0.5em;
  353. color: #FFF;
  354. font-size: small;
  355. text-shadow: 1px 1px 1px #AAAAAA;
  356. }
  357. h4 {
  358. line-height: 2em;
  359. text-indent: 0em;
  360. color: #FFFFFF;
  361. margin-left:25%;
  362. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  363. text-shadow: 1px 1px 1px gray;
  364. }
  365. h5 {
  366. line-height: 1.5em;
  367. text-indent: 0em;
  368. color: #FF9900;
  369. font-size: 14px;
  370. }
  371. .vol {
  372. padding: 30% 5% 20%;
  373. margin: 15% -2em 2%;
  374. background-color: #996699;
  375. text-indent: 0em;
  376. }
  377. .volbg {
  378. background-color: #996699;
  379. }
  380. /* 作者译者编者等 */
  381. .author {
  382. margin: 20% 0;
  383. text-indent: 0em;
  384. text-align: center;
  385. font-size: 1em;
  386. line-height: 60%;
  387. font-weight: 600;
  388. /*color: #;*/
  389. }
  390. .wt {
  391. text-indent: 0em;
  392. font-style:italic;
  393. font-size: 0.9rem;
  394. line-height: 1.2em;
  395. color: #336699;
  396. }
  397. /* 出版社 */
  398. .copyright {
  399. margin: 35% 0 0;
  400. text-indent: 0em;
  401. text-align: center;
  402. font-size: 1em;
  403. line-height: 120%;
  404. font-weight: 300;
  405. /*color: #;*/
  406. }
  407. /* 书票 */
  408. .exL {
  409. margin: 45% 0;
  410. text-align: center;
  411. page-break-before: always;
  412. }
  413. .kh {
  414. text-indent: 0em;
  415. text-align: center;
  416. font-size: 0.80em;
  417. color: #EEEEEE;
  418. }
  419. /* 电子书信息 */
  420. .info {
  421. font-size: 1em;
  422. font-weight: bold;
  423. line-height: 150%;
  424. color: #666666;
  425. margin: 0 0 1em 20%;
  426. }
  427. .info_items {
  428. font-size: 0.8em;
  429. line-height: 120%;
  430. color: #666666;
  431. margin: 0 0 0 20%;
  432. }
  433. /* 多看 图框 */
  434. .duokan-image-single {
  435. margin: 0.5em 0;
  436. bottom: 2%;
  437. text-align: center;
  438. }
  439. /*++*/
  440. .rht {
  441. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  442. font-size: 115%;
  443. line-height: 120%;
  444. text-indent: 0em;
  445. text-align: right;
  446. color: #CCCCCC;
  447. }
  448. .lt {
  449. font-size: 80%;
  450. text-indent: 0em;
  451. text-align: right;
  452. color: #003366;
  453. }
  454. div.float {
  455. width: 42%;
  456. float: right;
  457. margin: 1em 0 0em 1em;
  458. }`;
  459. },
  460. container() {
  461. return `<?xml version="1.0" encoding="UTF-8"?>
  462. <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
  463. <rootfiles>
  464. <rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
  465. </rootfiles>
  466. </container>`;
  467. }
  468. };
  469. function startAndEnd(item) {
  470. return item.index > 0 && item.index < 6005;
  471. }