postext 1.91.1 → 1.92.0

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.
Files changed (301) hide show
  1. package/dist/__tests__/exports.test.js +92 -0
  2. package/dist/__tests__/exports.test.js.map +1 -1
  3. package/dist/__tests__/paint/cropMarks.test.js +31 -0
  4. package/dist/__tests__/paint/cropMarks.test.js.map +1 -1
  5. package/dist/__tests__/pipeline/pages/reliefPlates.test.d.ts +2 -0
  6. package/dist/__tests__/pipeline/pages/reliefPlates.test.d.ts.map +1 -0
  7. package/dist/__tests__/pipeline/pages/reliefPlates.test.js +92 -0
  8. package/dist/__tests__/pipeline/pages/reliefPlates.test.js.map +1 -0
  9. package/dist/__tests__/pipeline/passFrontPages.test.d.ts +2 -0
  10. package/dist/__tests__/pipeline/passFrontPages.test.d.ts.map +1 -0
  11. package/dist/__tests__/pipeline/passFrontPages.test.js +66 -0
  12. package/dist/__tests__/pipeline/passFrontPages.test.js.map +1 -0
  13. package/dist/__tests__/production/compose.test.d.ts +2 -0
  14. package/dist/__tests__/production/compose.test.d.ts.map +1 -0
  15. package/dist/__tests__/production/compose.test.js +177 -0
  16. package/dist/__tests__/production/compose.test.js.map +1 -0
  17. package/dist/__tests__/production/config.test.d.ts +2 -0
  18. package/dist/__tests__/production/config.test.d.ts.map +1 -0
  19. package/dist/__tests__/production/config.test.js +83 -0
  20. package/dist/__tests__/production/config.test.js.map +1 -0
  21. package/dist/__tests__/production/cover.test.d.ts +2 -0
  22. package/dist/__tests__/production/cover.test.d.ts.map +1 -0
  23. package/dist/__tests__/production/cover.test.js +273 -0
  24. package/dist/__tests__/production/cover.test.js.map +1 -0
  25. package/dist/__tests__/production/coverLayers.test.d.ts +2 -0
  26. package/dist/__tests__/production/coverLayers.test.d.ts.map +1 -0
  27. package/dist/__tests__/production/coverLayers.test.js +198 -0
  28. package/dist/__tests__/production/coverLayers.test.js.map +1 -0
  29. package/dist/__tests__/production/coverOutputs.test.d.ts +2 -0
  30. package/dist/__tests__/production/coverOutputs.test.d.ts.map +1 -0
  31. package/dist/__tests__/production/coverOutputs.test.js +104 -0
  32. package/dist/__tests__/production/coverOutputs.test.js.map +1 -0
  33. package/dist/__tests__/production/geometry.test.d.ts +2 -0
  34. package/dist/__tests__/production/geometry.test.d.ts.map +1 -0
  35. package/dist/__tests__/production/geometry.test.js +281 -0
  36. package/dist/__tests__/production/geometry.test.js.map +1 -0
  37. package/dist/__tests__/production/mirrorBleed.test.d.ts +2 -0
  38. package/dist/__tests__/production/mirrorBleed.test.d.ts.map +1 -0
  39. package/dist/__tests__/production/mirrorBleed.test.js +129 -0
  40. package/dist/__tests__/production/mirrorBleed.test.js.map +1 -0
  41. package/dist/__tests__/production/shapes.test.d.ts +2 -0
  42. package/dist/__tests__/production/shapes.test.d.ts.map +1 -0
  43. package/dist/__tests__/production/shapes.test.js +107 -0
  44. package/dist/__tests__/production/shapes.test.js.map +1 -0
  45. package/dist/__tests__/production/sheets.test.d.ts +2 -0
  46. package/dist/__tests__/production/sheets.test.d.ts.map +1 -0
  47. package/dist/__tests__/production/sheets.test.js +153 -0
  48. package/dist/__tests__/production/sheets.test.js.map +1 -0
  49. package/dist/bundle/api.d.ts +8 -0
  50. package/dist/bundle/api.d.ts.map +1 -1
  51. package/dist/bundle/api.js +3 -0
  52. package/dist/bundle/api.js.map +1 -1
  53. package/dist/bundle/codec/files.d.ts.map +1 -1
  54. package/dist/bundle/codec/files.js +2 -0
  55. package/dist/bundle/codec/files.js.map +1 -1
  56. package/dist/bundle/codec/plan.d.ts +12 -0
  57. package/dist/bundle/codec/plan.d.ts.map +1 -1
  58. package/dist/bundle/codec/plan.js +12 -1
  59. package/dist/bundle/codec/plan.js.map +1 -1
  60. package/dist/bundle/codec/read.d.ts +3 -0
  61. package/dist/bundle/codec/read.d.ts.map +1 -1
  62. package/dist/bundle/codec/read.js +14 -2
  63. package/dist/bundle/codec/read.js.map +1 -1
  64. package/dist/bundle/index.d.ts +1 -1
  65. package/dist/bundle/index.d.ts.map +1 -1
  66. package/dist/bundle/index.js +1 -1
  67. package/dist/bundle/index.js.map +1 -1
  68. package/dist/bundle/manifest/locale.d.ts +3 -0
  69. package/dist/bundle/manifest/locale.d.ts.map +1 -1
  70. package/dist/bundle/manifest/locale.js +5 -0
  71. package/dist/bundle/manifest/locale.js.map +1 -1
  72. package/dist/bundle/manifest/validation.d.ts.map +1 -1
  73. package/dist/bundle/manifest/validation.js +4 -0
  74. package/dist/bundle/manifest/validation.js.map +1 -1
  75. package/dist/bundle/manifest.d.ts +1 -1
  76. package/dist/bundle/manifest.d.ts.map +1 -1
  77. package/dist/bundle/manifest.js +1 -1
  78. package/dist/bundle/manifest.js.map +1 -1
  79. package/dist/bundle/types.d.ts +7 -0
  80. package/dist/bundle/types.d.ts.map +1 -1
  81. package/dist/checks/configWarnings/collect.d.ts +6 -1
  82. package/dist/checks/configWarnings/collect.d.ts.map +1 -1
  83. package/dist/checks/configWarnings/collect.js +9 -1
  84. package/dist/checks/configWarnings/collect.js.map +1 -1
  85. package/dist/checks/configWarnings/cover.d.ts +17 -0
  86. package/dist/checks/configWarnings/cover.d.ts.map +1 -0
  87. package/dist/checks/configWarnings/cover.js +146 -0
  88. package/dist/checks/configWarnings/cover.js.map +1 -0
  89. package/dist/checks/configWarnings/production.d.ts +12 -0
  90. package/dist/checks/configWarnings/production.d.ts.map +1 -0
  91. package/dist/checks/configWarnings/production.js +48 -0
  92. package/dist/checks/configWarnings/production.js.map +1 -0
  93. package/dist/checks/preflight.d.ts.map +1 -1
  94. package/dist/checks/preflight.js +5 -0
  95. package/dist/checks/preflight.js.map +1 -1
  96. package/dist/checks/preflightFolds.d.ts +19 -0
  97. package/dist/checks/preflightFolds.d.ts.map +1 -0
  98. package/dist/checks/preflightFolds.js +81 -0
  99. package/dist/checks/preflightFolds.js.map +1 -0
  100. package/dist/checks/preflightIssues.d.ts +24 -0
  101. package/dist/checks/preflightIssues.d.ts.map +1 -1
  102. package/dist/composed/paint.d.ts +2 -1
  103. package/dist/composed/paint.d.ts.map +1 -1
  104. package/dist/composed/paint.js +3 -2
  105. package/dist/composed/paint.js.map +1 -1
  106. package/dist/defaults/bookKeys.d.ts +2 -2
  107. package/dist/defaults/bookKeys.d.ts.map +1 -1
  108. package/dist/defaults/bookKeys.js +2 -2
  109. package/dist/defaults/bookKeys.js.map +1 -1
  110. package/dist/defaults/index.d.ts +1 -1
  111. package/dist/defaults/index.d.ts.map +1 -1
  112. package/dist/defaults/index.js +1 -1
  113. package/dist/defaults/index.js.map +1 -1
  114. package/dist/defaults/output/folio.d.ts +6 -1
  115. package/dist/defaults/output/folio.d.ts.map +1 -1
  116. package/dist/defaults/output/folio.js +10 -0
  117. package/dist/defaults/output/folio.js.map +1 -1
  118. package/dist/defaults/output/production.d.ts +12 -0
  119. package/dist/defaults/output/production.d.ts.map +1 -0
  120. package/dist/defaults/output/production.js +83 -0
  121. package/dist/defaults/output/production.js.map +1 -0
  122. package/dist/defaults/page.d.ts.map +1 -1
  123. package/dist/defaults/page.js +4 -1
  124. package/dist/defaults/page.js.map +1 -1
  125. package/dist/defaults/structure/headerFooter/resolve.d.ts.map +1 -1
  126. package/dist/defaults/structure/headerFooter/resolve.js +1 -0
  127. package/dist/defaults/structure/headerFooter/resolve.js.map +1 -1
  128. package/dist/design/elementKeys.d.ts +6 -0
  129. package/dist/design/elementKeys.d.ts.map +1 -1
  130. package/dist/design/elementKeys.js +5 -5
  131. package/dist/design/elementKeys.js.map +1 -1
  132. package/dist/designs/parts.d.ts +2 -1
  133. package/dist/designs/parts.d.ts.map +1 -1
  134. package/dist/designs/parts.js +2 -1
  135. package/dist/designs/parts.js.map +1 -1
  136. package/dist/index.d.ts +2 -2
  137. package/dist/index.d.ts.map +1 -1
  138. package/dist/index.js +1 -1
  139. package/dist/index.js.map +1 -1
  140. package/dist/paint/cropMarks.d.ts +2 -1
  141. package/dist/paint/cropMarks.d.ts.map +1 -1
  142. package/dist/paint/cropMarks.js +7 -1
  143. package/dist/paint/cropMarks.js.map +1 -1
  144. package/dist/pipeline/build/passMade.d.ts +37 -0
  145. package/dist/pipeline/build/passMade.d.ts.map +1 -1
  146. package/dist/pipeline/build/passMade.js +59 -0
  147. package/dist/pipeline/build/passMade.js.map +1 -1
  148. package/dist/pipeline/build/passRejoin.d.ts.map +1 -1
  149. package/dist/pipeline/build/passRejoin.js +23 -0
  150. package/dist/pipeline/build/passRejoin.js.map +1 -1
  151. package/dist/pipeline/build/passReuse.d.ts +6 -0
  152. package/dist/pipeline/build/passReuse.d.ts.map +1 -1
  153. package/dist/pipeline/build/passReuse.js +44 -28
  154. package/dist/pipeline/build/passReuse.js.map +1 -1
  155. package/dist/pipeline/config.d.ts.map +1 -1
  156. package/dist/pipeline/config.js +9 -2
  157. package/dist/pipeline/config.js.map +1 -1
  158. package/dist/pipeline/pages/dieCuts.d.ts +2 -1
  159. package/dist/pipeline/pages/dieCuts.d.ts.map +1 -1
  160. package/dist/pipeline/pages/dieCuts.js +18 -2
  161. package/dist/pipeline/pages/dieCuts.js.map +1 -1
  162. package/dist/pipeline/pages/headerFooter/pageDecoration.d.ts.map +1 -1
  163. package/dist/pipeline/pages/headerFooter/pageDecoration.js +8 -3
  164. package/dist/pipeline/pages/headerFooter/pageDecoration.js.map +1 -1
  165. package/dist/pipeline/pages/headerFooter/slotLayout.d.ts +3 -2
  166. package/dist/pipeline/pages/headerFooter/slotLayout.d.ts.map +1 -1
  167. package/dist/pipeline/pages/headerFooter/slotLayout.js +1 -1
  168. package/dist/pipeline/pages/headerFooter/slotLayout.js.map +1 -1
  169. package/dist/production/barcodeSvg.d.ts +28 -0
  170. package/dist/production/barcodeSvg.d.ts.map +1 -0
  171. package/dist/production/barcodeSvg.js +64 -0
  172. package/dist/production/barcodeSvg.js.map +1 -0
  173. package/dist/production/buildCover.d.ts +104 -0
  174. package/dist/production/buildCover.d.ts.map +1 -0
  175. package/dist/production/buildCover.js +169 -0
  176. package/dist/production/buildCover.js.map +1 -0
  177. package/dist/production/catalogue.d.ts +40 -0
  178. package/dist/production/catalogue.d.ts.map +1 -0
  179. package/dist/production/catalogue.js +106 -0
  180. package/dist/production/catalogue.js.map +1 -0
  181. package/dist/production/compose.d.ts +120 -0
  182. package/dist/production/compose.d.ts.map +1 -0
  183. package/dist/production/compose.js +288 -0
  184. package/dist/production/compose.js.map +1 -0
  185. package/dist/production/config.d.ts +15 -0
  186. package/dist/production/config.d.ts.map +1 -0
  187. package/dist/production/config.js +143 -0
  188. package/dist/production/config.js.map +1 -0
  189. package/dist/production/coverArt.d.ts +74 -0
  190. package/dist/production/coverArt.d.ts.map +1 -0
  191. package/dist/production/coverArt.js +355 -0
  192. package/dist/production/coverArt.js.map +1 -0
  193. package/dist/production/coverDesign.d.ts +22 -0
  194. package/dist/production/coverDesign.d.ts.map +1 -0
  195. package/dist/production/coverDesign.js +111 -0
  196. package/dist/production/coverDesign.js.map +1 -0
  197. package/dist/production/coverLabels.d.ts +8 -0
  198. package/dist/production/coverLabels.d.ts.map +1 -0
  199. package/dist/production/coverLabels.js +23 -0
  200. package/dist/production/coverLabels.js.map +1 -0
  201. package/dist/production/coverSource.d.ts +79 -0
  202. package/dist/production/coverSource.d.ts.map +1 -0
  203. package/dist/production/coverSource.js +142 -0
  204. package/dist/production/coverSource.js.map +1 -0
  205. package/dist/production/exchange.d.ts +38 -0
  206. package/dist/production/exchange.d.ts.map +1 -0
  207. package/dist/production/exchange.js +146 -0
  208. package/dist/production/exchange.js.map +1 -0
  209. package/dist/production/folio.d.ts +21 -0
  210. package/dist/production/folio.d.ts.map +1 -0
  211. package/dist/production/folio.js +35 -0
  212. package/dist/production/folio.js.map +1 -0
  213. package/dist/production/geometry.d.ts +84 -0
  214. package/dist/production/geometry.d.ts.map +1 -0
  215. package/dist/production/geometry.js +220 -0
  216. package/dist/production/geometry.js.map +1 -0
  217. package/dist/production/guards.d.ts +6 -0
  218. package/dist/production/guards.d.ts.map +1 -0
  219. package/dist/production/guards.js +6 -0
  220. package/dist/production/guards.js.map +1 -0
  221. package/dist/production/index.d.ts +25 -0
  222. package/dist/production/index.d.ts.map +1 -0
  223. package/dist/production/index.js +19 -0
  224. package/dist/production/index.js.map +1 -0
  225. package/dist/production/isbn.d.ts +67 -0
  226. package/dist/production/isbn.d.ts.map +1 -0
  227. package/dist/production/isbn.js +135 -0
  228. package/dist/production/isbn.js.map +1 -0
  229. package/dist/production/measures.d.ts +30 -0
  230. package/dist/production/measures.d.ts.map +1 -0
  231. package/dist/production/measures.js +54 -0
  232. package/dist/production/measures.js.map +1 -0
  233. package/dist/production/mirrorBleed.d.ts +54 -0
  234. package/dist/production/mirrorBleed.d.ts.map +1 -0
  235. package/dist/production/mirrorBleed.js +92 -0
  236. package/dist/production/mirrorBleed.js.map +1 -0
  237. package/dist/production/shapes.d.ts +65 -0
  238. package/dist/production/shapes.d.ts.map +1 -0
  239. package/dist/production/shapes.js +313 -0
  240. package/dist/production/shapes.js.map +1 -0
  241. package/dist/production/spine.d.ts +38 -0
  242. package/dist/production/spine.d.ts.map +1 -0
  243. package/dist/production/spine.js +48 -0
  244. package/dist/production/spine.js.map +1 -0
  245. package/dist/production/svgSafe.d.ts +25 -0
  246. package/dist/production/svgSafe.d.ts.map +1 -0
  247. package/dist/production/svgSafe.js +33 -0
  248. package/dist/production/svgSafe.js.map +1 -0
  249. package/dist/production/version.d.ts +66 -0
  250. package/dist/production/version.d.ts.map +1 -0
  251. package/dist/production/version.js +68 -0
  252. package/dist/production/version.js.map +1 -0
  253. package/dist/types/config.d.ts +12 -0
  254. package/dist/types/config.d.ts.map +1 -1
  255. package/dist/types/designCut.d.ts +13 -1
  256. package/dist/types/designCut.d.ts.map +1 -1
  257. package/dist/types/designElements.d.ts +15 -0
  258. package/dist/types/designElements.d.ts.map +1 -1
  259. package/dist/types/output/cover.d.ts +230 -0
  260. package/dist/types/output/cover.d.ts.map +1 -0
  261. package/dist/types/output/cover.js +2 -0
  262. package/dist/types/output/cover.js.map +1 -0
  263. package/dist/types/output/production.d.ts +186 -0
  264. package/dist/types/output/production.d.ts.map +1 -0
  265. package/dist/types/output/production.js +2 -0
  266. package/dist/types/output/production.js.map +1 -0
  267. package/dist/types/page.d.ts +5 -0
  268. package/dist/types/page.d.ts.map +1 -1
  269. package/dist/types.d.ts +2 -0
  270. package/dist/types.d.ts.map +1 -1
  271. package/dist/util/base64.d.ts +3 -0
  272. package/dist/util/base64.d.ts.map +1 -0
  273. package/dist/util/base64.js +48 -0
  274. package/dist/util/base64.js.map +1 -0
  275. package/dist/util/png.d.ts +10 -0
  276. package/dist/util/png.d.ts.map +1 -0
  277. package/dist/util/png.js +60 -0
  278. package/dist/util/png.js.map +1 -0
  279. package/dist/util/xmlEscape.d.ts +6 -0
  280. package/dist/util/xmlEscape.d.ts.map +1 -0
  281. package/dist/util/xmlEscape.js +15 -0
  282. package/dist/util/xmlEscape.js.map +1 -0
  283. package/dist/vdt/design.d.ts +10 -1
  284. package/dist/vdt/design.d.ts.map +1 -1
  285. package/dist/vdt/design.js.map +1 -1
  286. package/dist/vdt/pages.d.ts +13 -0
  287. package/dist/vdt/pages.d.ts.map +1 -1
  288. package/dist/vdt.d.ts +1 -1
  289. package/dist/vdt.d.ts.map +1 -1
  290. package/dist/word/anchors/base64.d.ts +1 -2
  291. package/dist/word/anchors/base64.d.ts.map +1 -1
  292. package/dist/word/anchors/base64.js +2 -46
  293. package/dist/word/anchors/base64.js.map +1 -1
  294. package/dist/word/semantic/design/ground.d.ts.map +1 -1
  295. package/dist/word/semantic/design/ground.js +5 -47
  296. package/dist/word/semantic/design/ground.js.map +1 -1
  297. package/dist/word/xml.d.ts +1 -4
  298. package/dist/word/xml.d.ts.map +1 -1
  299. package/dist/word/xml.js +1 -13
  300. package/dist/word/xml.js.map +1 -1
  301. package/package.json +5 -1
@@ -0,0 +1,177 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { caseSheet, coverSource, coverElementRect, coverPage, PROMO_FORMATS, placeCoverElement, promoSheet, resolveBindingMeasures, sheetGuides, softcoverSheet, } from '../../production/index.js';
3
+ const trim = { width: 150, height: 230 };
4
+ const zone = (sheet, name) => sheet.zones.find((z) => z.name === name);
5
+ describe('coverPage', () => {
6
+ const m = resolveBindingMeasures({ id: 'x', name: 'X', style: 'perfect' }, trim);
7
+ it('gives each zone a frame in its safe area, measured from the trim', () => {
8
+ const sheet = softcoverSheet(trim, 20, m, true);
9
+ const cover = coverPage(sheet);
10
+ expect(cover.slots).toEqual(['flapBack', 'back', 'spine', 'front', 'flapFront']);
11
+ const front = cover.template.frames.find((f) => f.name === 'front');
12
+ const safe = zone(sheet, 'front').safe;
13
+ expect(front.placement.offset.x.value).toBeCloseTo(safe.x - sheet.trim.x, 3);
14
+ expect(front.width).toEqual({ value: Math.round(safe.width * 1000) / 1000, unit: 'mm' });
15
+ expect(cover.page.width).toEqual({ value: sheet.trim.width, unit: 'mm' });
16
+ expect(cover.page.cutLines.bleed).toEqual({ value: m.bleed, unit: 'mm' });
17
+ });
18
+ it('turns the spine frame to read up it, or down it', () => {
19
+ const sheet = softcoverSheet(trim, 20, m, false);
20
+ const up = coverPage(sheet).template.frames.find((f) => f.name === 'spine');
21
+ expect(up.rotate).toBe(-90);
22
+ expect(up.width).toEqual({ value: zone(sheet, 'spine').safe.height, unit: 'mm' });
23
+ const down = coverPage(sheet, { spineText: { direction: 'topToBottom' } }).template.frames.find((f) => f.name === 'spine');
24
+ expect(down.rotate).toBe(90);
25
+ });
26
+ it('leaves a spine too thin for text without a frame', () => {
27
+ expect(coverPage(softcoverSheet(trim, 4, m, false)).slots).not.toContain('spine');
28
+ });
29
+ it("marks the folds inside the trim, not a case's turn-in folds", () => {
30
+ const soft = softcoverSheet(trim, 20, m, true);
31
+ expect(coverPage(soft).page.cutLines.foldMarks.length).toBe(soft.lines.length);
32
+ const c = resolveBindingMeasures({ id: 'y', name: 'Y', style: 'caseFlat' }, trim);
33
+ const cs = caseSheet(trim, 26, c);
34
+ expect(coverPage(cs).page.cutLines.foldMarks.length).toBe(4);
35
+ });
36
+ it('draws the barcode in the back cover by the spine and the foot', () => {
37
+ const sheet = softcoverSheet(trim, 20, m, false);
38
+ const cover = coverPage(sheet, { isbn: '978-0-306-40615-7' });
39
+ const el = cover.template.decoration.elements[0];
40
+ const back = zone(sheet, 'back').safe;
41
+ expect(el.placement.offset.x.value + el.placement.size.width.value).toBeCloseTo(back.x + back.width - sheet.trim.x, 2);
42
+ expect(new TextDecoder().decode(cover.files['postext-cover-isbn.svg'])).toContain('ISBN 978-0-306-40615-7');
43
+ expect(coverPage(sheet, { isbn: 'nope' }).resources).toEqual([]);
44
+ });
45
+ it('reports an ISBN that does not read and makes no barcode', () => {
46
+ const sheet = softcoverSheet(trim, 20, m, false);
47
+ const cover = coverPage(sheet, { isbn: 'nope' });
48
+ expect(cover.issues).toEqual([{ kind: 'coverIsbnInvalid', isbn: 'nope' }]);
49
+ expect(cover.template.decoration).toBeUndefined();
50
+ });
51
+ it('wraps the cover Markdown in the cover page fence', () => {
52
+ const { markdown, issues } = coverSource(':::frame{slot="back"}\nBlurb.\n:::', ['back', 'front']);
53
+ expect(markdown).toBe('::::page{template="postext-cover"}\n:::frame{slot="back"}\nBlurb.\n:::\n::::');
54
+ expect(issues).toEqual([]);
55
+ });
56
+ });
57
+ describe('cover design', () => {
58
+ const m = resolveBindingMeasures({ id: 'x', name: 'X', style: 'perfect' }, trim);
59
+ const ink = (hex) => ({ hex, model: 'hex' });
60
+ it('draws the ground, the picture and the zones under the barcode, into the bleed', () => {
61
+ const sheet = softcoverSheet(trim, 20, m, true);
62
+ const cover = coverPage(sheet, {
63
+ isbn: '978-0-306-40615-7',
64
+ cover: { background: ink('#123456'), image: { resourceId: 'photo' }, zones: { spine: ink('#ffcc00'), flapFront: ink('#eeeeee') } },
65
+ });
66
+ const els = cover.template.decoration.elements;
67
+ expect(els.map((e) => e.id)).toEqual(['cover-ground', 'cover-image', 'cover-zone-spine', 'cover-zone-flapFront', 'cover-isbn']);
68
+ const ground = els[0];
69
+ expect(ground.placement.size.width.value).toBeCloseTo(sheet.width, 3);
70
+ expect(els[1].fit).toBe('cover');
71
+ // The spine runs from the top of the bleed to its foot, between its folds.
72
+ const spine = els[2];
73
+ expect(spine.placement.offset.y.value).toBe(0);
74
+ expect(spine.placement.size.height.value).toBeCloseTo(sheet.height, 3);
75
+ expect(spine.placement.offset.x.value).toBeCloseTo(zone(sheet, 'spine').rect.x, 3);
76
+ // The front flap reaches the right edge of the bleed.
77
+ const flap = els[3];
78
+ expect(flap.placement.offset.x.value + flap.placement.size.width.value).toBeCloseTo(sheet.width, 3);
79
+ });
80
+ it('puts the picture on the front cover only when asked', () => {
81
+ const sheet = softcoverSheet(trim, 20, m, false);
82
+ const els = coverPage(sheet, { cover: { image: { resourceId: 'photo', area: 'front' } } }).template.decoration.elements;
83
+ const front = zone(sheet, 'front').rect;
84
+ expect(els[0].placement.offset.x.value).toBeCloseTo(front.x, 3);
85
+ expect(els[0].placement.offset.x.value + els[0].placement.size.width.value).toBeCloseTo(sheet.width, 3);
86
+ });
87
+ it('draws nothing without a design', () => {
88
+ expect(coverPage(softcoverSheet(trim, 20, m, false)).template.decoration).toBeUndefined();
89
+ });
90
+ });
91
+ describe('zone placement', () => {
92
+ it('sets a zone’s text at the top, middle or foot of it', () => {
93
+ const m = resolveBindingMeasures({ id: 'x', name: 'X', style: 'perfect' }, trim);
94
+ const cover = coverPage(softcoverSheet(trim, 20, m, false), { cover: { verticalAlign: { front: 'bottom', back: 'top' } } });
95
+ const frames = Object.fromEntries(cover.template.frames.map((f) => [f.name, f]));
96
+ expect(frames.front.verticalAlign).toBe('bottom');
97
+ expect(frames.back.verticalAlign).toBeUndefined();
98
+ expect(frames.spine.verticalAlign).toBe('middle');
99
+ });
100
+ });
101
+ describe('promoSheet', () => {
102
+ it('recomposes the front cover in a screen format, without bleed or marks', () => {
103
+ const sheet = promoSheet(trim, 'epub', 5);
104
+ expect(sheet.width).toBe(150);
105
+ expect(sheet.height).toBeCloseTo(240, 6);
106
+ expect(sheet.zones.map((z) => z.name)).toEqual(['front']);
107
+ expect(promoSheet(trim, 'square', 5).height).toBe(150);
108
+ const cover = coverPage(sheet, { isbn: '978-0-306-40615-7', cover: { image: { resourceId: 'p', area: 'front' } } });
109
+ expect(cover.page.cutLines).toEqual({ enabled: false });
110
+ expect(cover.slots).toEqual(['front']);
111
+ expect(cover.resources).toEqual([]);
112
+ expect(cover.template.decoration.elements[0].placement.size.height.value).toBeCloseTo(240, 3);
113
+ expect(PROMO_FORMATS.story).toEqual({ width: 1080, height: 1920 });
114
+ });
115
+ });
116
+ describe('sheetGuides', () => {
117
+ const m = resolveBindingMeasures({ id: 'x', name: 'X', style: 'perfect' }, trim);
118
+ it('puts a guide on every fold and score, measured from the trim, and none on its edges', () => {
119
+ const sheet = softcoverSheet(trim, 20, m, true);
120
+ const guides = sheetGuides(sheet);
121
+ for (const l of sheet.lines) {
122
+ expect(guides).toContainEqual(expect.objectContaining({ orientation: 'vertical', at: expect.closeTo(l.x - sheet.trim.x, 3), kind: l.kind }));
123
+ }
124
+ expect(guides.every((g) => g.at > 0 && g.at < (g.orientation === 'vertical' ? sheet.trim.width : sheet.trim.height))).toBe(true);
125
+ });
126
+ it('marks each safe area once, the spine’s included', () => {
127
+ const sheet = softcoverSheet(trim, 20, m, false);
128
+ const guides = sheetGuides(sheet);
129
+ const spine = zone(sheet, 'spine').safe;
130
+ expect(guides).toContainEqual({ orientation: 'vertical', at: expect.closeTo(spine.x - sheet.trim.x, 3), kind: 'safe' });
131
+ const top = guides.filter((g) => g.orientation === 'horizontal');
132
+ expect(top.map((g) => g.at)).toEqual([...new Set(top.map((g) => g.at))]);
133
+ expect(top).toContainEqual({ orientation: 'horizontal', at: expect.closeTo(zone(sheet, 'front').safe.y - sheet.trim.y, 3), kind: 'safe' });
134
+ });
135
+ it('marks a case’s joints', () => {
136
+ const c = resolveBindingMeasures({ id: 'y', name: 'Y', style: 'caseFlat' }, trim);
137
+ expect(sheetGuides(caseSheet(trim, 26, c)).filter((g) => g.kind === 'joint').length).toBeGreaterThan(0);
138
+ });
139
+ });
140
+ describe('cover elements', () => {
141
+ const m = resolveBindingMeasures({ id: 'x', name: 'X', style: 'perfect' }, trim);
142
+ it('stand by their zone, so they move with it when the spine grows', () => {
143
+ const el = { id: 'a', kind: 'box', color: { hex: '#ff0000', model: 'hex' }, zone: 'front', x: 10, y: 20, width: 30, height: 40 };
144
+ const thin = coverElementRect(softcoverSheet(trim, 10, m, false), el);
145
+ const thick = coverElementRect(softcoverSheet(trim, 30, m, false), el);
146
+ expect(thick.x - thin.x).toBeCloseTo(20, 3);
147
+ expect(thick.y).toBe(thin.y);
148
+ });
149
+ it('fall back to the board when the sheet has no flap', () => {
150
+ const el = { id: 'a', kind: 'box', zone: 'flapFront', x: 0, y: 0, width: 5, height: 5 };
151
+ expect(coverElementRect(softcoverSheet(trim, 10, m, false), el).x).toBeCloseTo(zone(softcoverSheet(trim, 10, m, false), 'front').rect.x, 3);
152
+ });
153
+ it('are placed by the zone their centre falls in when moved', () => {
154
+ const sheet = softcoverSheet(trim, 20, m, false);
155
+ const back = zone(sheet, 'back').rect;
156
+ const el = { id: 'a', kind: 'box', zone: 'front', x: 0, y: 0, width: 10, height: 10 };
157
+ const moved = placeCoverElement(sheet, el, { x: back.x + 5, y: back.y + 5, width: 10, height: 10 });
158
+ expect(moved).toMatchObject({ zone: 'back', x: 5, y: 5 });
159
+ expect(coverElementRect(sheet, moved)).toEqual({ x: back.x + 5, y: back.y + 5, width: 10, height: 10 });
160
+ });
161
+ it('are drawn over the grounds, in order, and a box without a colour is left out', () => {
162
+ const sheet = softcoverSheet(trim, 20, m, false);
163
+ const red = { hex: '#ff0000', model: 'hex' };
164
+ const cover = coverPage(sheet, {
165
+ cover: {
166
+ background: red,
167
+ elements: [
168
+ { id: 'pic', kind: 'image', resourceId: 'logo', zone: 'front', x: 1, y: 1, width: 10, height: 10 },
169
+ { id: 'none', kind: 'box', zone: 'front', x: 1, y: 1, width: 10, height: 10 },
170
+ { id: 'band', kind: 'box', color: red, zone: 'back', x: 0, y: 0, width: 10, height: 10 },
171
+ ],
172
+ },
173
+ });
174
+ expect(cover.template.decoration.elements.map((e) => e.id)).toEqual(['cover-ground', 'cover-el-pic', 'cover-el-band']);
175
+ });
176
+ });
177
+ //# sourceMappingURL=compose.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.test.js","sourceRoot":"","sources":["../../../src/__tests__/production/compose.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,sBAAsB,EACtB,WAAW,EACX,cAAc,GAEf,MAAM,2BAA2B,CAAC;AAGnC,MAAM,IAAI,GAAW,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACjD,MAAM,IAAI,GAAG,CAAC,KAAsB,EAAE,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAE,CAAC;AAEjG,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,MAAM,CAAC,GAAG,sBAAsB,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,IAAI,CAAC,CAAC;IAEjF,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;QAC1E,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/B,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU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AAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;oBAC7E,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;iBACzF;aACF;SACF,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;IAC1H,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/production/config.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,83 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { readProductionConfig } from '../../production/index.js';
3
+ import { collectConfigWarnings } from '../../checks/configWarnings.js';
4
+ import { createBundle, openBundle } from '../../bundle/index.js';
5
+ import { buildDocument } from '../../pipeline/index.js';
6
+ import { isBookOwnKey, isBookWideKey } from '../../defaults/index.js';
7
+ // Deterministic text measurement (no DOM in the node test env).
8
+ globalThis.OffscreenCanvas = class {
9
+ getContext() {
10
+ return { font: '', measureText: (t) => ({ width: t.length * 7 }) };
11
+ }
12
+ };
13
+ const production = {
14
+ versions: [
15
+ { id: 'pb', name: 'Paperback', binding: 'perfect', flaps: true, isbn: '978-0-306-40615-7' },
16
+ { id: 'hc', name: 'Hardcover', binding: 'case-flat', isbn: '0-8044-2957-X', caseMaterial: 'cloth' },
17
+ ],
18
+ collection: { name: 'Pocket Classics', isbn: '978-0-306-40615-7', catalogue: [{ id: 'v1', title: 'The Lantern' }] },
19
+ };
20
+ describe('readProductionConfig', () => {
21
+ it('keeps a production that reads, untouched', () => {
22
+ expect(readProductionConfig(production)).toEqual({ production, issues: [] });
23
+ expect(readProductionConfig(undefined)).toEqual({ issues: [] });
24
+ });
25
+ it('leaves out what does not read and lists it', () => {
26
+ const read = readProductionConfig({
27
+ versions: [
28
+ { id: 'a', binding: 'perfect', isbnAddOn: '12', flaps: 'yes', overrides: { bleed: 3, colour: 1, joint: -2 }, spineText: { direction: 'up' } },
29
+ { name: 'no id', binding: 'perfect' },
30
+ { id: 'b' },
31
+ { id: 'a', binding: 'perfect' },
32
+ { id: 'c', binding: { id: 'x', style: 'spiral' } },
33
+ ],
34
+ bindings: 'perfect',
35
+ collection: { name: 'C', catalogue: [{ id: 'v', title: 3 }] },
36
+ });
37
+ expect(read.production?.versions).toEqual([{ id: 'a', name: 'a', binding: 'perfect', overrides: { bleed: 3 }, spineText: {} }]);
38
+ expect(read.production?.bindings).toBeUndefined();
39
+ expect(read.production?.collection).toEqual({ name: 'C', catalogue: [] });
40
+ expect(read.issues.map((i) => `${i.where}:${i.reason}`)).toEqual([
41
+ 'versions[0].isbnAddOn:badText',
42
+ 'versions[0].flaps:badText',
43
+ 'versions[0].overrides.colour:badMeasure',
44
+ 'versions[0].overrides.joint:badNumber',
45
+ 'versions[0].spineText.direction:badText',
46
+ 'versions[1]:missingId',
47
+ 'versions[2].binding:missingId',
48
+ 'versions[3]:missingId',
49
+ 'versions[4].binding:unknownStyle',
50
+ 'bindings:badText',
51
+ 'collection.catalogue[0]:badText',
52
+ ]);
53
+ });
54
+ });
55
+ describe('production in a book', () => {
56
+ it("is the book's own and book-wide: never a design's or a chapter style's", () => {
57
+ expect(isBookOwnKey('production')).toBe(true);
58
+ expect(isBookWideKey('production')).toBe(true);
59
+ });
60
+ it('warns about what the cover reader leaves out and an ISBN that does not read', () => {
61
+ const config = {
62
+ production: { versions: [{ id: 'pb', name: 'P', binding: 'perfect', isbn: '978-0-306-40615-0' }], extra: 1 },
63
+ };
64
+ const warnings = collectConfigWarnings(config).filter((w) => w.path.startsWith('production'));
65
+ expect(warnings).toEqual([
66
+ { kind: 'unknownConfigKey', path: 'production.extra', value: 'extra', used: '' },
67
+ { kind: 'unknownConfigValue', path: 'production.versions[0].isbn', value: '978-0-306-40615-0', used: '' },
68
+ ]);
69
+ expect(collectConfigWarnings({ production }).filter((w) => w.path.startsWith('production'))).toEqual([]);
70
+ });
71
+ it('travels in a bundle', async () => {
72
+ const { bytes, manifest } = await createBundle({ name: 'The Lantern', markdown: '# Dusk\n\nThe lantern.', config: { production } });
73
+ expect(manifest.config?.production).toEqual(production);
74
+ expect((await openBundle(bytes)).config.production).toEqual(production);
75
+ });
76
+ it('never changes a page', () => {
77
+ const markdown = '# Dusk\n\nThe lantern hung by the door, and nobody moved it all night.';
78
+ const plain = buildDocument({ markdown }, {});
79
+ const published = buildDocument({ markdown }, { production });
80
+ expect(JSON.stringify(published.pages)).toBe(JSON.stringify(plain.pages));
81
+ });
82
+ });
83
+ //# sourceMappingURL=config.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.test.js","sourceRoot":"","sources":["../../../src/__tests__/production/config.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,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;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cover.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cover.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/production/cover.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,273 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { buildCover, coverZoneBox, caseSheet, coverPage, coverSource, markdownLiteral, resolveBindingMeasures, softcoverSheet, workIsbnCaption, } from '../../production/index.js';
3
+ import { mirrorBands, mirrorBleedSvg, MAX_MIRROR_BANDS } from '../../production/mirrorBleed.js';
4
+ import { collectConfigWarnings } from '../../checks/configWarnings.js';
5
+ import { buildDocument } from '../../pipeline/index.js';
6
+ import { flowRectToPage, pageIsMirrored } from '../../vdt/flowFrames.js';
7
+ import { isBookOwnKey, isBookWideKey } from '../../defaults/index.js';
8
+ import { DESIGN_PARTS, DESIGN_PART_KEYS } from '../../designs/parts.js';
9
+ import { preflightDocument } from '../../checks/preflight.js';
10
+ // The cover as a Markdown document on a composed page (#1667): what the
11
+ // cover makes of untrusted values, the Markdown and the metadata, the
12
+ // whole cover built from a book, and the mirror bleed's limits.
13
+ globalThis.OffscreenCanvas = class {
14
+ getContext() {
15
+ return { font: '', measureText: (t) => ({ width: t.length * 7 }) };
16
+ }
17
+ };
18
+ const trim = { width: 150, height: 230 };
19
+ const m = resolveBindingMeasures({ id: 'x', name: 'X', style: 'perfect' }, trim);
20
+ const sheet = softcoverSheet(trim, 20, m, true);
21
+ const text = (bytes) => new TextDecoder().decode(bytes);
22
+ describe('values a cover writes into SVG', () => {
23
+ const hostile = '"/><script>alert(1)</script><x a="';
24
+ it('never lets an id, a colour or a picture address out of its attribute', () => {
25
+ const cover = coverPage(sheet, {
26
+ cover: {
27
+ elements: [
28
+ { id: hostile, kind: 'box', color: { hex: hostile, model: 'hex' }, shadow: { color: { hex: hostile, model: 'hex' }, opacity: 0.5, x: 1, y: 1, blur: 2 }, zone: 'front', x: 1, y: 1, width: 20, height: 20 },
29
+ { id: 'pic', kind: 'image', resourceId: 'p', clip: [[{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 0, y: 1 }]], zone: 'front', x: 1, y: 30, width: 20, height: 20 },
30
+ ],
31
+ },
32
+ mirrorPictures: { p: { href: `javascript:alert(1)${hostile}`, width: 10, height: 10 } },
33
+ });
34
+ for (const [name, bytes] of Object.entries(cover.files)) {
35
+ expect(name).toMatch(/^[A-Za-z0-9_.-]+$/);
36
+ expect(text(bytes)).not.toContain('<script');
37
+ expect(text(bytes)).not.toContain('javascript:');
38
+ }
39
+ for (const r of cover.resources)
40
+ expect(r.id).toMatch(/^[A-Za-z0-9_-]+$/);
41
+ // The picture whose address is no PNG or JPEG data is drawn whole.
42
+ expect(cover.issues).toEqual([{ kind: 'coverClipSkipped', resources: ['p'] }]);
43
+ });
44
+ it('keeps a blur from costing more than its picture', () => {
45
+ const start = Date.now();
46
+ coverPage(sheet, { cover: { elements: [{ id: 'b', kind: 'box', color: { hex: '#ffffff', model: 'hex' }, shadow: { color: { hex: '#000000', model: 'hex' }, opacity: 1, x: 0, y: 0, blur: 1e9 }, zone: 'front', x: 0, y: 0, width: 50, height: 50 }] } });
47
+ expect(Date.now() - start).toBeLessThan(2000);
48
+ });
49
+ it('leaves out a text box named as a zone, as another box or not as an id', () => {
50
+ const cover = coverPage(sheet, { cover: { textBoxes: [
51
+ { name: 'front', rect: { x: 0, y: 0, width: 10, height: 10 } },
52
+ { name: 'a"b', rect: { x: 0, y: 0, width: 10, height: 10 } },
53
+ { name: 'title', rect: { x: 0, y: 0, width: 10, height: 10 } },
54
+ { name: 'title', rect: { x: 0, y: 0, width: 10, height: 10 } },
55
+ ] } });
56
+ expect(cover.slots.filter((s) => s === 'title')).toHaveLength(1);
57
+ expect(cover.issues.map((i) => i.kind === 'coverTextBoxName' && i.name)).toEqual(['front', 'a"b', 'title']);
58
+ });
59
+ });
60
+ describe("the cover's Markdown", () => {
61
+ const slots = ['flapBack', 'back', 'spine', 'front', 'flapFront'];
62
+ it('fills the front and the spine from the metadata, in the cover styles, escaped', () => {
63
+ const { markdown } = coverSource(':::frame{slot="back"}\nBlurb.\n:::', slots, { title: 'C++ *Primer*', subtitle: 'Fifth edition', author: 'S. Lippman' });
64
+ expect(markdown).toContain(':::frame{slot="back"}\nBlurb.\n:::');
65
+ expect(markdown).toContain(':::frame{slot="front"}\n:::paragraphs{style="cover-title"}\nC\\+\\+ \\*Primer\\*\n:::');
66
+ expect(markdown).toContain(':::paragraphs{style="cover-author"}\nS. Lippman\n:::');
67
+ expect(markdown).toContain(':::frame{slot="spine"}\n:::paragraphs{style="cover-spine"}\nC\\+\\+ \\*Primer\\* · S. Lippman\n:::');
68
+ });
69
+ it('leaves a front or a spine the cover writes itself alone, and fills nothing without metadata', () => {
70
+ const own = coverSource(':::frame{slot="front"}\n# My title\n:::\n\n:::frame{slot="spine"}\nSpine\n:::', slots, { title: 'Other' }).markdown;
71
+ expect(own).not.toContain('cover-title');
72
+ expect(own).not.toContain('Other');
73
+ expect(coverSource('', slots).markdown).toBe('::::page{template="postext-cover"}\n\n::::');
74
+ expect(coverSource('', ['front']).markdown).not.toContain('spine');
75
+ });
76
+ it('reports a slot the cover has not and a slot filled twice', () => {
77
+ const { issues } = coverSource(':::frame{slot="back"}\nA\n:::\n:::frame{slot=back}\nB\n:::\n:::frame{slot="rear"}\nC\n:::', slots);
78
+ expect(issues.map((i) => [i.kind, 'slot' in i ? i.slot : i.sheet])).toEqual([['coverSlotRepeated', 'back'], ['coverSlotUnknown', 'rear']]);
79
+ });
80
+ it('writes text as Markdown that reads as written', () => {
81
+ expect(markdownLiteral(' A_b [c](d)\n:::x 5$ ')).toBe('A\\_b [c](d) :::x 5\\$');
82
+ });
83
+ });
84
+ describe('buildCover', () => {
85
+ const config = {
86
+ page: { sizePreset: 'custom', width: { value: 150, unit: 'mm' }, height: { value: 230, unit: 'mm' } },
87
+ header: { elements: [{ kind: 'text', id: 'h', content: '{title}', fontSize: { value: 9, unit: 'pt' }, placement: { anchor: { to: 'page', edge: 'top-left' } } }] },
88
+ production: {
89
+ versions: [
90
+ { id: 'pb', name: 'Paperback', binding: 'perfect', flaps: true, isbn: '978-0-306-40615-7', workIsbn: '978-84-9835-000-2' },
91
+ { id: 'hc', name: 'Hardcover', binding: 'case-flat' },
92
+ ],
93
+ },
94
+ cover: {
95
+ background: { hex: '#123456', model: 'hex' },
96
+ finishes: [{ id: 'seal', process: 'emboss', shape: { box: { zone: 'front', x: 40, y: 150, width: 30, height: 30 } } }],
97
+ },
98
+ paragraphStyles: [{ id: 'cover-title', fontSize: { value: 40, unit: 'pt' } }],
99
+ locale: 'es',
100
+ };
101
+ const metadata = { title: 'La linterna', author: 'Ana Ruiz' };
102
+ it('makes the sheet of a version a document of its own, the metadata on the front and the spine', () => {
103
+ const built = buildCover({ config, version: 'pb', pages: 240, markdown: ':::frame{slot="back"}\nUna historia.\n:::', metadata });
104
+ expect(built.config).toBeDefined();
105
+ expect(built.sheet.kind).toBe('softcover');
106
+ expect(built.config.production).toBeUndefined();
107
+ expect(built.config.cover).toBeUndefined();
108
+ expect(built.config.header).toEqual({ elements: [] });
109
+ expect(built.config.pageTemplates.map((t) => t.id)).toEqual(['postext-cover']);
110
+ // The book's own title style wins; the rest are the cover's defaults.
111
+ const styles = built.config.paragraphStyles;
112
+ expect(styles.find((s) => s.id === 'cover-title').fontSize).toEqual({ value: 40, unit: 'pt' });
113
+ expect(styles.map((s) => s.id)).toEqual(['cover-title', 'cover-subtitle', 'cover-author', 'cover-spine', 'cover-catalogue', 'cover-catalogue-current']);
114
+ expect(built.content.resources.map((r) => r.id)).toContain('postext-cover-isbn');
115
+ expect(text(built.files['postext-cover-isbn.svg'])).toContain('978-0-306-40615-7');
116
+ const doc = buildDocument(built.content, built.config);
117
+ expect(doc.pages).toHaveLength(1);
118
+ const page = doc.pages[0];
119
+ const words = [...(page.floats ?? [])].flatMap((b) => b.lines.map((l) => l.text)).join(' ');
120
+ expect(words).toContain('La linterna');
121
+ expect(words).toContain('Ana Ruiz');
122
+ expect(words).toContain('Una historia.');
123
+ // The whole work's ISBN in the book's language, over the barcode.
124
+ const deco = page.composed.decoration.blocks;
125
+ expect(deco.some((b) => b.kind === 'text' && b.lines.some((l) => l.text.includes('ISBN obra completa 978-84-9835-000-2')))).toBe(true);
126
+ expect(page.plates).toEqual([expect.objectContaining({ process: 'emboss' })]);
127
+ expect(built.issues.filter((i) => i.kind !== 'spineTooThinForText')).toEqual([]);
128
+ });
129
+ it('takes the spine from the laid-out pages and gives a case its jacket and endpapers', () => {
130
+ const thin = buildCover({ config, version: 'pb', pages: 40 });
131
+ const thick = buildCover({ config, version: 'pb', pages: 400 });
132
+ expect(thick.sheets.spine.used).toBeGreaterThan(thin.sheets.spine.used);
133
+ expect(thick.sheet.width).toBeGreaterThan(thin.sheet.width);
134
+ const hc = buildCover({ config, version: 'hc', pages: 240, sheet: 'endpaperFront' });
135
+ expect(hc.sheet.kind).toBe('endpaper');
136
+ expect(hc.content.resources.some((r) => r.id === 'postext-cover-isbn')).toBe(false);
137
+ });
138
+ it('prints the collection’s ISBN beside the barcode when the version names no work ISBN', () => {
139
+ const series = { ...config, production: { collection: { name: 'Serie', isbn: '978-84-9835-000-2' }, versions: [{ id: 'v', name: 'Tomo', binding: 'perfect', isbn: '978-0-306-40615-7' }] } };
140
+ const built = buildCover({ config: series, version: 'v', pages: 240 });
141
+ const page = buildDocument(built.content, built.config).pages[0];
142
+ const deco = page.composed.decoration.blocks;
143
+ expect(deco.some((b) => b.kind === 'text' && b.lines.some((l) => l.text.includes('978-84-9835-000-2')))).toBe(true);
144
+ const bad = { ...series, production: { ...series.production, collection: { name: 'Serie', isbn: '978-84-9835-000-3' } } };
145
+ expect(collectConfigWarnings(bad).some((w) => w.path === 'production.collection.isbn')).toBe(true);
146
+ });
147
+ it('prints the barcode on the jacket of a case that wears one, and on the case that does not', () => {
148
+ const jacketed = { ...config, production: { versions: [{ id: 'hc', name: 'Hardcover', binding: 'case-flat', flaps: true, isbn: '978-0-306-40615-7', workIsbn: '978-84-9835-000-2' }] } };
149
+ const barcode = (c, sheet) => buildCover({ config: c, version: 'hc', pages: 240, sheet }).content.resources?.some((r) => r.id === 'postext-cover-isbn');
150
+ expect(barcode(jacketed, 'jacket')).toBe(true);
151
+ expect(barcode(jacketed)).toBe(false);
152
+ const bare = { ...config, production: { versions: [{ id: 'hc', name: 'Hardcover', binding: 'case-flat', isbn: '978-0-306-40615-7' }] } };
153
+ expect(barcode(bare)).toBe(true);
154
+ });
155
+ it('mirrors the sheet of a book bound on the right: the front on the left, the back on the right', () => {
156
+ const order = (c, version = 'pb', sheet) => buildCover({ config: c, version, pages: 240, ...(sheet ? { sheet } : {}) }).sheet.zones.map((z) => z.name);
157
+ expect(order(config)).toEqual(['flapBack', 'back', 'spine', 'front', 'flapFront']);
158
+ // An Arabic book (direction auto from its language), a vertical one, a page bound on the right.
159
+ const arabic = { ...config, locale: 'ar' };
160
+ const vertical = { ...config, locale: 'ja', layout: { writingMode: 'vertical-rl' } };
161
+ const right = { ...config, page: { ...config.page, binding: 'right' } };
162
+ for (const c of [arabic, vertical, right])
163
+ expect(order(c)).toEqual(['flapFront', 'front', 'spine', 'back', 'flapBack']);
164
+ expect(order(arabic, 'hc')).toEqual(['front', 'jointFront', 'spine', 'jointBack', 'back']);
165
+ const built = buildCover({ config: arabic, version: 'pb', pages: 240 });
166
+ const zone = (n) => built.sheet.zones.find((z) => z.name === n);
167
+ // The same panels, moved across: the back flap ends where the sheet's bleed starts.
168
+ expect(zone('flapBack').rect.x + zone('flapBack').rect.width).toBeCloseTo(built.sheet.width - built.sheet.bleed, 6);
169
+ expect(built.sheet.lines.map((l) => l.x)).toEqual([...built.sheet.lines.map((l) => l.x)].sort((a, b) => a - b));
170
+ });
171
+ it('sets each zone’s text in its own panel on a sheet bound either way', () => {
172
+ const arabic = { ...config, locale: 'ar' };
173
+ const vertical = { ...config, locale: 'ja', layout: { writingMode: 'vertical-rl' } };
174
+ const right = { ...config, page: { ...config.page, binding: 'right' } };
175
+ for (const c of [config, arabic, vertical, right]) {
176
+ const built = buildCover({ config: c, version: 'pb', pages: 240, markdown: ':::frame{slot="back"}\nUna historia.\n:::', metadata });
177
+ const doc = buildDocument(built.content, built.config);
178
+ const page = doc.pages[0];
179
+ const centre = (text) => {
180
+ // A line that says only that: the spine joins the title and the author.
181
+ const block = (page.floats ?? []).find((b) => b.lines.some((l) => l.text === text));
182
+ // Where it is painted: a right-to-left page's flow is mirrored; a
183
+ // vertical page's frames are laid out on the page itself.
184
+ const r = pageIsMirrored(page) ? flowRectToPage(page, block.bbox) : block.bbox;
185
+ return r.x + r.width / 2;
186
+ };
187
+ const inside = (text, zone) => {
188
+ const box = coverZoneBox(built, zone, doc);
189
+ const x = centre(text);
190
+ expect(x, `${c.locale ?? 'en'} ${zone}`).toBeGreaterThan(box.x);
191
+ expect(x, `${c.locale ?? 'en'} ${zone}`).toBeLessThan(box.x + box.width);
192
+ };
193
+ inside('Una historia.', 'back');
194
+ inside('La linterna', 'front');
195
+ // A turned spine is turned about its centre, so its box's centre holds.
196
+ inside('La linterna · Ana Ruiz', 'spine');
197
+ }
198
+ // A vertical book's sheet is a horizontal page whose zones are set vertical.
199
+ const v = buildCover({ config: vertical, version: 'pb', pages: 240 });
200
+ expect(v.config.layout?.writingMode).toBe('horizontal-tb');
201
+ expect(new Set(v.config.pageTemplates[0].frames.map((f) => f.writingMode))).toEqual(new Set(['vertical-rl']));
202
+ });
203
+ it('says what is missing instead of making a cover', () => {
204
+ expect(buildCover({ config, version: 'nope', pages: 10 })).toEqual({ issues: [{ kind: 'coverVersionMissing', version: 'nope' }] });
205
+ expect(buildCover({ config, version: 'pb', pages: 10, sheet: 'jacket' }).issues).toContainEqual({ kind: 'coverSheetMissing', sheet: 'jacket' });
206
+ });
207
+ it('lays out the same book with and without a cover design', () => {
208
+ const book = { markdown: '# One\n\nText of the book.' };
209
+ const a = buildDocument(book, { ...config, cover: undefined });
210
+ const b = buildDocument(book, config);
211
+ expect(b.pages.map((p) => p.columns)).toEqual(a.pages.map((p) => p.columns));
212
+ });
213
+ });
214
+ describe('the cover in the configuration', () => {
215
+ it('is a design part of its own, book-wide, never the book’s alone', () => {
216
+ expect(DESIGN_PARTS).toContain('cover');
217
+ expect(DESIGN_PART_KEYS.cover).toEqual(['cover']);
218
+ expect(isBookWideKey('cover')).toBe(true);
219
+ expect(isBookOwnKey('cover')).toBe(false);
220
+ });
221
+ it('warns of what the cover changes or leaves out', () => {
222
+ const cover = {
223
+ bakground: { hex: '#fff', model: 'hex' },
224
+ background: { hex: 'red', model: 'hex' },
225
+ elements: [{ id: 'a b', kind: 'box', zone: 'roof', x: 0, y: 0, width: 1, height: 1 }],
226
+ finishes: [
227
+ { id: 'f', process: 'glitter', shape: { box: { zone: 'front', x: 0, y: 0, width: 1, height: 1 } } },
228
+ { id: 'g', process: 'foil', ink: { hex: '#ff0000', model: 'hex' }, shape: { element: 'nothing' } },
229
+ ],
230
+ textBoxes: [{ name: 'spine', rect: { x: 0, y: 0, width: 1, height: 1 } }],
231
+ mirrorMargin: 0.5,
232
+ barcodeMagnification: 0.5,
233
+ };
234
+ const paths = collectConfigWarnings({ cover }).filter((w) => w.path.startsWith('cover')).map((w) => w.path);
235
+ expect(paths).toEqual([
236
+ 'cover.bakground', 'cover.background', 'cover.elements[0].id', 'cover.elements[0].zone',
237
+ 'cover.finishes[0].process', 'cover.finishes[1].ink', 'cover.finishes[1].shape.element',
238
+ 'cover.textBoxes[0].name', 'cover.mirrorMargin', 'cover.barcodeMagnification',
239
+ ]);
240
+ expect(collectConfigWarnings({ cover: { background: { hex: '#ffffff', model: 'hex' } } }).filter((w) => w.path.startsWith('cover'))).toEqual([]);
241
+ });
242
+ });
243
+ describe('mirror bleed limits', () => {
244
+ it('folds no narrower than 2 mm', () => {
245
+ const { designed } = mirrorBands(20, 120, 140, 0.1);
246
+ expect(designed).toEqual([18, 122]);
247
+ });
248
+ it('stops at its most bands and says so', () => {
249
+ const wide = { width: 400, height: 400, trim: { x: 150, y: 150, width: 100, height: 100 } };
250
+ const out = mirrorBleedSvg(wide, 2, '<rect/>');
251
+ expect(out.capped).toBe(true);
252
+ expect(mirrorBands(150, 250, 400, 2).before).toHaveLength(MAX_MIRROR_BANDS);
253
+ const c = resolveBindingMeasures({ id: 'c', name: 'C', style: 'caseFlat' }, trim);
254
+ expect(mirrorBleedSvg(caseSheet(trim, 26, c), c.designMargin, '<rect/>').capped).toBe(false);
255
+ });
256
+ });
257
+ describe('the cover in the preflight', () => {
258
+ it('reports text across a fold of the sheet', () => {
259
+ const built = buildCover({
260
+ config: { production: { versions: [{ id: 'pb', name: 'P', binding: 'perfect' }] }, cover: { textBoxes: [{ name: 'band', rect: { x: 150, y: 50, width: 40, height: 20 } }] } },
261
+ version: 'pb',
262
+ pages: 200,
263
+ markdown: ':::frame{slot="band"}\nA line of words long enough to run across the spine fold\n:::',
264
+ });
265
+ const doc = buildDocument(built.content, built.config);
266
+ expect(preflightDocument(doc).some((i) => i.kind === 'foldText')).toBe(true);
267
+ });
268
+ it('names the whole work in the book’s language, English by default', () => {
269
+ expect(workIsbnCaption('978-84', 'ca-ES')).toBe('ISBN obra completa 978-84');
270
+ expect(workIsbnCaption('978-84', 'nl')).toBe('ISBN of the complete work 978-84');
271
+ });
272
+ });
273
+ //# sourceMappingURL=cover.test.js.map