pulpweaver4 0.0.88 → 0.0.185

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 (540) hide show
  1. package/dist/ast/djot.d.ts +2 -1
  2. package/dist/ast/djot.js +31 -2
  3. package/dist/ast/djot.js.map +1 -1
  4. package/dist/ast/index.d.ts +1 -0
  5. package/dist/ast/index.js +1 -0
  6. package/dist/ast/index.js.map +1 -1
  7. package/dist/ast/nodes.d.ts +72 -9
  8. package/dist/ast/nodes.js +8 -0
  9. package/dist/ast/nodes.js.map +1 -1
  10. package/dist/ast/table.d.ts +27 -0
  11. package/dist/ast/table.js +32 -0
  12. package/dist/ast/table.js.map +1 -0
  13. package/dist/browser.js +2420 -0
  14. package/dist/citations/book.d.ts +2 -0
  15. package/dist/citations/book.js +17 -6
  16. package/dist/citations/book.js.map +1 -1
  17. package/dist/citations/collect.d.ts +5 -1
  18. package/dist/citations/collect.js +5 -1
  19. package/dist/citations/collect.js.map +1 -1
  20. package/dist/citations/index.d.ts +1 -1
  21. package/dist/citations/index.js +1 -1
  22. package/dist/citations/index.js.map +1 -1
  23. package/dist/citations/notes.js +54 -11
  24. package/dist/citations/notes.js.map +1 -1
  25. package/dist/citations/positions.js +4 -4
  26. package/dist/citations/positions.js.map +1 -1
  27. package/dist/citations/project.d.ts +12 -2
  28. package/dist/citations/project.js +21 -7
  29. package/dist/citations/project.js.map +1 -1
  30. package/dist/colour/images.d.ts +11 -2
  31. package/dist/colour/images.js +53 -3
  32. package/dist/colour/images.js.map +1 -1
  33. package/dist/colour/ink-limit.d.ts +2 -2
  34. package/dist/colour/ink-limit.js +6 -0
  35. package/dist/colour/ink-limit.js.map +1 -1
  36. package/dist/colour/intents.d.ts +10 -0
  37. package/dist/colour/intents.js +10 -0
  38. package/dist/colour/intents.js.map +1 -1
  39. package/dist/colour/previews.d.ts +8 -4
  40. package/dist/colour/previews.js +11 -8
  41. package/dist/colour/previews.js.map +1 -1
  42. package/dist/config/config.d.ts +99 -6
  43. package/dist/config/config.js +217 -6
  44. package/dist/config/config.js.map +1 -1
  45. package/dist/config/project-schema.d.ts +0 -8
  46. package/dist/config/project-schema.js +221 -12
  47. package/dist/config/project-schema.js.map +1 -1
  48. package/dist/config/schema.js +10 -0
  49. package/dist/config/schema.js.map +1 -1
  50. package/dist/config/secrets.d.ts +11 -0
  51. package/dist/config/secrets.js +19 -0
  52. package/dist/config/secrets.js.map +1 -0
  53. package/dist/csl/processor.d.ts +3 -1
  54. package/dist/csl/processor.js +19 -13
  55. package/dist/csl/processor.js.map +1 -1
  56. package/dist/csl/project.d.ts +19 -4
  57. package/dist/csl/project.js +31 -11
  58. package/dist/csl/project.js.map +1 -1
  59. package/dist/djot/djot.js/src/ast.d.ts +4 -1
  60. package/dist/djot/djot.js/src/ast.js +8 -1
  61. package/dist/djot/djot.js/src/ast.js.map +1 -1
  62. package/dist/djot/djot.js/src/djot-renderer.js +3 -3
  63. package/dist/djot/djot.js/src/djot-renderer.js.map +1 -1
  64. package/dist/djot/djot.js/src/html.js +2 -1
  65. package/dist/djot/djot.js/src/html.js.map +1 -1
  66. package/dist/djot/djot.js/src/inline.d.ts +1 -1
  67. package/dist/djot/djot.js/src/inline.js +25 -12
  68. package/dist/djot/djot.js/src/inline.js.map +1 -1
  69. package/dist/djot/djot.js/src/pandoc.js +81 -11
  70. package/dist/djot/djot.js/src/pandoc.js.map +1 -1
  71. package/dist/djot/djot.js/src/parse.js +12 -3
  72. package/dist/djot/djot.js/src/parse.js.map +1 -1
  73. package/dist/fonts/index.d.ts +1 -1
  74. package/dist/fonts/index.js +1 -1
  75. package/dist/fonts/index.js.map +1 -1
  76. package/dist/fonts/lint.d.ts +51 -0
  77. package/dist/fonts/lint.js +101 -16
  78. package/dist/fonts/lint.js.map +1 -1
  79. package/dist/fonts/walk.d.ts +13 -0
  80. package/dist/fonts/walk.js +50 -33
  81. package/dist/fonts/walk.js.map +1 -1
  82. package/dist/html/css.d.ts +4 -0
  83. package/dist/html/css.js +11 -3
  84. package/dist/html/css.js.map +1 -1
  85. package/dist/html/dom.d.ts +6 -1
  86. package/dist/html/dom.js +28 -6
  87. package/dist/html/dom.js.map +1 -1
  88. package/dist/html/generated.d.ts +17 -0
  89. package/dist/html/generated.js +21 -0
  90. package/dist/html/generated.js.map +1 -0
  91. package/dist/html/images.d.ts +18 -0
  92. package/dist/html/images.js +49 -2
  93. package/dist/html/images.js.map +1 -1
  94. package/dist/html/index.d.ts +1 -0
  95. package/dist/html/index.js +1 -0
  96. package/dist/html/index.js.map +1 -1
  97. package/dist/html/render.d.ts +5 -4
  98. package/dist/html/render.js +34 -9
  99. package/dist/html/render.js.map +1 -1
  100. package/dist/hyphenation/exceptions.d.ts +5 -0
  101. package/dist/hyphenation/exceptions.js +11 -0
  102. package/dist/hyphenation/exceptions.js.map +1 -1
  103. package/dist/hyphenation/index.d.ts +1 -1
  104. package/dist/hyphenation/index.js +1 -1
  105. package/dist/hyphenation/index.js.map +1 -1
  106. package/dist/import/convert.d.ts +21 -0
  107. package/dist/import/convert.js +65 -0
  108. package/dist/import/convert.js.map +1 -0
  109. package/dist/incremental/cache.d.ts +59 -0
  110. package/dist/incremental/cache.js +64 -0
  111. package/dist/incremental/cache.js.map +1 -0
  112. package/dist/incremental/index.d.ts +3 -0
  113. package/dist/incremental/index.js +4 -0
  114. package/dist/incremental/index.js.map +1 -0
  115. package/dist/incremental/keys.d.ts +27 -0
  116. package/dist/incremental/keys.js +89 -0
  117. package/dist/incremental/keys.js.map +1 -0
  118. package/dist/incremental/session.d.ts +180 -0
  119. package/dist/incremental/session.js +401 -0
  120. package/dist/incremental/session.js.map +1 -0
  121. package/dist/index.d.ts +6 -0
  122. package/dist/index.js +6 -0
  123. package/dist/index.js.map +1 -1
  124. package/dist/indexes/layout.d.ts +8 -2
  125. package/dist/indexes/layout.js +6 -4
  126. package/dist/indexes/layout.js.map +1 -1
  127. package/dist/layout/cache.d.ts +174 -0
  128. package/dist/layout/cache.js +150 -0
  129. package/dist/layout/cache.js.map +1 -0
  130. package/dist/layout/converge.d.ts +28 -0
  131. package/dist/layout/converge.js +102 -9
  132. package/dist/layout/converge.js.map +1 -1
  133. package/dist/layout/counters.d.ts +4 -0
  134. package/dist/layout/counters.js +15 -0
  135. package/dist/layout/counters.js.map +1 -1
  136. package/dist/layout/index.d.ts +5 -2
  137. package/dist/layout/index.js +3 -0
  138. package/dist/layout/index.js.map +1 -1
  139. package/dist/layout/lists.d.ts +52 -3
  140. package/dist/layout/lists.js +513 -46
  141. package/dist/layout/lists.js.map +1 -1
  142. package/dist/layout/lookahead.d.ts +151 -0
  143. package/dist/layout/lookahead.js +581 -0
  144. package/dist/layout/lookahead.js.map +1 -0
  145. package/dist/layout/margin-boxes.d.ts +11 -1
  146. package/dist/layout/margin-boxes.js +24 -1
  147. package/dist/layout/margin-boxes.js.map +1 -1
  148. package/dist/layout/page-box.d.ts +2 -0
  149. package/dist/layout/page-box.js +6 -4
  150. package/dist/layout/page-box.js.map +1 -1
  151. package/dist/layout/page-rules.d.ts +8 -1
  152. package/dist/layout/page-rules.js +46 -2
  153. package/dist/layout/page-rules.js.map +1 -1
  154. package/dist/layout/page.js +4 -2
  155. package/dist/layout/page.js.map +1 -1
  156. package/dist/layout/pagebuilder.d.ts +248 -3
  157. package/dist/layout/pagebuilder.js +512 -19
  158. package/dist/layout/pagebuilder.js.map +1 -1
  159. package/dist/layout/pages.d.ts +116 -3
  160. package/dist/layout/pages.js +1396 -162
  161. package/dist/layout/pages.js.map +1 -1
  162. package/dist/layout/paragraph.d.ts +14 -0
  163. package/dist/layout/paragraph.js +304 -31
  164. package/dist/layout/paragraph.js.map +1 -1
  165. package/dist/layout/pre.js +4 -0
  166. package/dist/layout/pre.js.map +1 -1
  167. package/dist/layout/protrusion.d.ts +26 -0
  168. package/dist/layout/protrusion.js +39 -0
  169. package/dist/layout/protrusion.js.map +1 -0
  170. package/dist/layout/ranges.d.ts +2 -0
  171. package/dist/layout/ranges.js +22 -0
  172. package/dist/layout/ranges.js.map +1 -0
  173. package/dist/layout/region.d.ts +2 -1
  174. package/dist/layout/region.js +9 -5
  175. package/dist/layout/region.js.map +1 -1
  176. package/dist/layout/templates.d.ts +71 -0
  177. package/dist/layout/templates.js +290 -0
  178. package/dist/layout/templates.js.map +1 -0
  179. package/dist/layout/vlist.d.ts +3 -3
  180. package/dist/linebreak/items.d.ts +27 -2
  181. package/dist/linebreak/items.js +10 -3
  182. package/dist/linebreak/items.js.map +1 -1
  183. package/dist/linebreak/knuth-plass.d.ts +20 -0
  184. package/dist/linebreak/knuth-plass.js +68 -16
  185. package/dist/linebreak/knuth-plass.js.map +1 -1
  186. package/dist/lint/book.d.ts +13 -0
  187. package/dist/lint/book.js +52 -0
  188. package/dist/lint/book.js.map +1 -0
  189. package/dist/lint/config.d.ts +9 -0
  190. package/dist/lint/config.js +40 -6
  191. package/dist/lint/config.js.map +1 -1
  192. package/dist/lint/linter.js +1 -0
  193. package/dist/lint/linter.js.map +1 -1
  194. package/dist/lint/project.js +1 -1
  195. package/dist/lint/project.js.map +1 -1
  196. package/dist/lint/rules/layout.d.ts +3 -1
  197. package/dist/lint/rules/layout.js +8 -6
  198. package/dist/lint/rules/layout.js.map +1 -1
  199. package/dist/lint/rules/source.d.ts +3 -1
  200. package/dist/lint/rules/source.js +9 -4
  201. package/dist/lint/rules/source.js.map +1 -1
  202. package/dist/lint/testing.js +1 -0
  203. package/dist/lint/testing.js.map +1 -1
  204. package/dist/measure/bidi-data.d.ts +14 -0
  205. package/dist/measure/bidi-data.js +69 -0
  206. package/dist/measure/bidi-data.js.map +1 -0
  207. package/dist/measure/bidi.d.ts +70 -0
  208. package/dist/measure/bidi.js +225 -0
  209. package/dist/measure/bidi.js.map +1 -0
  210. package/dist/measure/css.d.ts +5 -0
  211. package/dist/measure/css.js +2 -0
  212. package/dist/measure/css.js.map +1 -1
  213. package/dist/measure/measurer.d.ts +36 -2
  214. package/dist/measure/measurer.js +220 -22
  215. package/dist/measure/measurer.js.map +1 -1
  216. package/dist/measure/model.d.ts +20 -2
  217. package/dist/measure/model.js +13 -6
  218. package/dist/measure/model.js.map +1 -1
  219. package/dist/measure/script-data.d.ts +6 -0
  220. package/dist/measure/script-data.js +34 -0
  221. package/dist/measure/script-data.js.map +1 -0
  222. package/dist/measure/scripts.d.ts +36 -0
  223. package/dist/measure/scripts.js +293 -0
  224. package/dist/measure/scripts.js.map +1 -0
  225. package/dist/output/output.d.ts +35 -3
  226. package/dist/output/output.js +26 -4
  227. package/dist/output/output.js.map +1 -1
  228. package/dist/paint/backgrounds.js +7 -20
  229. package/dist/paint/backgrounds.js.map +1 -1
  230. package/dist/paint/blend.d.ts +33 -13
  231. package/dist/paint/blend.js +73 -21
  232. package/dist/paint/blend.js.map +1 -1
  233. package/dist/paint/cache.d.ts +80 -0
  234. package/dist/paint/cache.js +537 -0
  235. package/dist/paint/cache.js.map +1 -0
  236. package/dist/paint/canvas.d.ts +4 -13
  237. package/dist/paint/canvas.js +45 -5
  238. package/dist/paint/canvas.js.map +1 -1
  239. package/dist/paint/context.d.ts +2 -0
  240. package/dist/paint/emphasis.js +1 -1
  241. package/dist/paint/emphasis.js.map +1 -1
  242. package/dist/paint/flatten.d.ts +24 -2
  243. package/dist/paint/flatten.js +55 -12
  244. package/dist/paint/flatten.js.map +1 -1
  245. package/dist/paint/forms.d.ts +64 -0
  246. package/dist/paint/forms.js +319 -0
  247. package/dist/paint/forms.js.map +1 -0
  248. package/dist/paint/images.d.ts +4 -1
  249. package/dist/paint/images.js +13 -2
  250. package/dist/paint/images.js.map +1 -1
  251. package/dist/paint/layers.d.ts +64 -0
  252. package/dist/paint/layers.js +137 -0
  253. package/dist/paint/layers.js.map +1 -0
  254. package/dist/paint/painter.d.ts +19 -6
  255. package/dist/paint/painter.js +15 -135
  256. package/dist/paint/painter.js.map +1 -1
  257. package/dist/paint/stacking.d.ts +1 -1
  258. package/dist/paint/stacking.js +9 -2
  259. package/dist/paint/stacking.js.map +1 -1
  260. package/dist/paint/text.d.ts +14 -3
  261. package/dist/paint/text.js +25 -4
  262. package/dist/paint/text.js.map +1 -1
  263. package/dist/paint/vertical.js +2 -2
  264. package/dist/paint/vertical.js.map +1 -1
  265. package/dist/pdf/encoded.d.ts +16 -0
  266. package/dist/pdf/encoded.js +35 -0
  267. package/dist/pdf/encoded.js.map +1 -0
  268. package/dist/pdf/include/colour.d.ts +105 -0
  269. package/dist/pdf/include/colour.js +349 -0
  270. package/dist/pdf/include/colour.js.map +1 -0
  271. package/dist/pdf/include/functions.d.ts +17 -0
  272. package/dist/pdf/include/functions.js +389 -0
  273. package/dist/pdf/include/functions.js.map +1 -0
  274. package/dist/pdf/include/pages.d.ts +14 -0
  275. package/dist/pdf/include/pages.js +27 -0
  276. package/dist/pdf/include/pages.js.map +1 -0
  277. package/dist/pdf/include/pdfjs/LICENSE +177 -0
  278. package/dist/pdf/include/pdfjs/pdf.min.mjs +27 -0
  279. package/dist/pdf/include/pdfjs/pdf.worker.min.mjs +27 -0
  280. package/dist/pdf/include/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
  281. package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
  282. package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
  283. package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  284. package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
  285. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
  286. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
  287. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  288. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
  289. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
  290. package/dist/pdf/include/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
  291. package/dist/pdf/include/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
  292. package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
  293. package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  294. package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
  295. package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
  296. package/dist/pdf/include/pdfjs/wasm/LICENSE_JBIG2 +196 -0
  297. package/dist/pdf/include/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
  298. package/dist/pdf/include/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  299. package/dist/pdf/include/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  300. package/dist/pdf/include/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
  301. package/dist/pdf/include/pdfjs/wasm/LICENSE_QCMS +21 -0
  302. package/dist/pdf/include/pdfjs/wasm/jbig2.wasm +0 -0
  303. package/dist/pdf/include/pdfjs/wasm/openjpeg.wasm +0 -0
  304. package/dist/pdf/include/pdfjs/wasm/qcms_bg.wasm +0 -0
  305. package/dist/pdf/include/pdfjs/wasm/quickjs-eval.wasm +0 -0
  306. package/dist/pdf/include/prepare.d.ts +58 -0
  307. package/dist/pdf/include/prepare.js +266 -0
  308. package/dist/pdf/include/prepare.js.map +1 -0
  309. package/dist/pdf/include/preview.d.ts +38 -0
  310. package/dist/pdf/include/preview.js +101 -0
  311. package/dist/pdf/include/preview.js.map +1 -0
  312. package/dist/pdf/include/rewrite.d.ts +57 -0
  313. package/dist/pdf/include/rewrite.js +803 -0
  314. package/dist/pdf/include/rewrite.js.map +1 -0
  315. package/dist/pdf/include/serialize.d.ts +32 -0
  316. package/dist/pdf/include/serialize.js +158 -0
  317. package/dist/pdf/include/serialize.js.map +1 -0
  318. package/dist/pdf/include/testing.d.ts +26 -0
  319. package/dist/pdf/include/testing.js +50 -0
  320. package/dist/pdf/include/testing.js.map +1 -0
  321. package/dist/pdf/index.d.ts +1 -0
  322. package/dist/pdf/index.js +1 -0
  323. package/dist/pdf/index.js.map +1 -1
  324. package/dist/pdf/structure/annotations.d.ts +33 -0
  325. package/dist/pdf/structure/annotations.js +112 -0
  326. package/dist/pdf/structure/annotations.js.map +1 -0
  327. package/dist/pdf/structure/forms.d.ts +10 -0
  328. package/dist/pdf/structure/forms.js +46 -0
  329. package/dist/pdf/structure/forms.js.map +1 -0
  330. package/dist/pdf/structure/index.d.ts +41 -5
  331. package/dist/pdf/structure/index.js +40 -5
  332. package/dist/pdf/structure/index.js.map +1 -1
  333. package/dist/pdf/structure/links.d.ts +2 -0
  334. package/dist/pdf/structure/links.js +1 -1
  335. package/dist/pdf/structure/links.js.map +1 -1
  336. package/dist/pdf/structure/presentation.d.ts +28 -0
  337. package/dist/pdf/structure/presentation.js +79 -0
  338. package/dist/pdf/structure/presentation.js.map +1 -0
  339. package/dist/pdf/structure/tags.d.ts +34 -2
  340. package/dist/pdf/structure/tags.js +117 -14
  341. package/dist/pdf/structure/tags.js.map +1 -1
  342. package/dist/pdf/types.d.ts +378 -15
  343. package/dist/pdf/wasm/pulpweaver4_pdf.d.ts +44 -2
  344. package/dist/pdf/wasm/pulpweaver4_pdf.js +191 -2
  345. package/dist/pdf/wasm/pulpweaver4_pdf_bg.wasm +0 -0
  346. package/dist/pdf/writer.d.ts +13 -1
  347. package/dist/pdf/writer.js +26 -1
  348. package/dist/pdf/writer.js.map +1 -1
  349. package/dist/plugin/define.d.ts +200 -15
  350. package/dist/plugin/define.js +124 -15
  351. package/dist/plugin/define.js.map +1 -1
  352. package/dist/plugin/failure.d.ts +1 -1
  353. package/dist/plugin/index.d.ts +5 -4
  354. package/dist/plugin/index.js +5 -4
  355. package/dist/plugin/index.js.map +1 -1
  356. package/dist/plugin/reference.d.ts +38 -0
  357. package/dist/plugin/reference.js +287 -0
  358. package/dist/plugin/reference.js.map +1 -0
  359. package/dist/plugin/register.d.ts +39 -7
  360. package/dist/plugin/register.js +83 -2
  361. package/dist/plugin/register.js.map +1 -1
  362. package/dist/preflight/index.d.ts +1 -1
  363. package/dist/preflight/index.js +1 -1
  364. package/dist/preflight/index.js.map +1 -1
  365. package/dist/preflight/pdfx.d.ts +35 -0
  366. package/dist/preflight/pdfx.js +37 -4
  367. package/dist/preflight/pdfx.js.map +1 -1
  368. package/dist/preflight/reader.d.ts +10 -3
  369. package/dist/preflight/reader.js +86 -5
  370. package/dist/preflight/reader.js.map +1 -1
  371. package/dist/print/impose.d.ts +66 -0
  372. package/dist/print/impose.js +331 -0
  373. package/dist/print/impose.js.map +1 -0
  374. package/dist/print/output.js +426 -60
  375. package/dist/print/output.js.map +1 -1
  376. package/dist/problem.js +4 -3
  377. package/dist/problem.js.map +1 -1
  378. package/dist/profile/index.d.ts +1 -0
  379. package/dist/profile/index.js +1 -0
  380. package/dist/profile/index.js.map +1 -1
  381. package/dist/profile/lint.d.ts +1 -1
  382. package/dist/profile/lint.js +29 -1
  383. package/dist/profile/lint.js.map +1 -1
  384. package/dist/profile/list-table.d.ts +51 -0
  385. package/dist/profile/list-table.js +137 -0
  386. package/dist/profile/list-table.js.map +1 -0
  387. package/dist/profile/metadata.js +3 -0
  388. package/dist/profile/metadata.js.map +1 -1
  389. package/dist/profile/profile.d.ts +3 -0
  390. package/dist/profile/profile.js +9 -1
  391. package/dist/profile/profile.js.map +1 -1
  392. package/dist/project.js +3 -0
  393. package/dist/project.js.map +1 -1
  394. package/dist/qpdf/index.d.ts +2 -0
  395. package/dist/qpdf/index.js +3 -0
  396. package/dist/qpdf/index.js.map +1 -0
  397. package/dist/qpdf/qpdf.d.ts +125 -0
  398. package/dist/qpdf/qpdf.js +205 -0
  399. package/dist/qpdf/qpdf.js.map +1 -0
  400. package/dist/qpdf/testing.d.ts +12 -0
  401. package/dist/qpdf/testing.js +9 -0
  402. package/dist/qpdf/testing.js.map +1 -0
  403. package/dist/qpdf/wasm/LICENSE-qpdf +202 -0
  404. package/dist/qpdf/wasm/LICENSE-zlib +22 -0
  405. package/dist/qpdf/wasm/NOTICE-qpdf.md +42 -0
  406. package/dist/qpdf/wasm/qpdf.wasm +0 -0
  407. package/dist/render/index.d.ts +3 -0
  408. package/dist/render/index.js +2 -0
  409. package/dist/render/index.js.map +1 -0
  410. package/dist/render/render.d.ts +98 -0
  411. package/dist/render/render.js +243 -0
  412. package/dist/render/render.js.map +1 -0
  413. package/dist/reproducible/clock.d.ts +4 -5
  414. package/dist/reproducible/clock.js +4 -5
  415. package/dist/reproducible/clock.js.map +1 -1
  416. package/dist/spike/spike-page.chromium.json +4 -4
  417. package/dist/style/colours.d.ts +7 -2
  418. package/dist/style/colours.js +24 -2
  419. package/dist/style/colours.js.map +1 -1
  420. package/dist/style/compile.js +1 -1
  421. package/dist/style/compile.js.map +1 -1
  422. package/dist/style/defaults.d.ts +9 -3
  423. package/dist/style/defaults.js +14 -2
  424. package/dist/style/defaults.js.map +1 -1
  425. package/dist/style/gcpm.d.ts +1 -1
  426. package/dist/style/gcpm.js +17 -5
  427. package/dist/style/gcpm.js.map +1 -1
  428. package/dist/style/properties.js +84 -0
  429. package/dist/style/properties.js.map +1 -1
  430. package/dist/test/book.d.ts +22 -2
  431. package/dist/test/book.js +35 -2
  432. package/dist/test/book.js.map +1 -1
  433. package/dist/test/build.d.ts +23 -0
  434. package/dist/test/build.js +86 -33
  435. package/dist/test/build.js.map +1 -1
  436. package/dist/test/layout.js +132 -22
  437. package/dist/test/layout.js.map +1 -1
  438. package/dist/test/limits.d.ts +8 -0
  439. package/dist/test/limits.js +9 -0
  440. package/dist/test/limits.js.map +1 -0
  441. package/dist/test/pipeline.d.ts +26 -0
  442. package/dist/test/pipeline.js +4 -2
  443. package/dist/test/pipeline.js.map +1 -1
  444. package/dist/test/render.d.ts +26 -3
  445. package/dist/test/render.js +151 -23
  446. package/dist/test/render.js.map +1 -1
  447. package/dist/test/runner.d.ts +6 -3
  448. package/dist/test/runner.js +172 -105
  449. package/dist/test/runner.js.map +1 -1
  450. package/dist/test/text.js +2 -2
  451. package/dist/test/text.js.map +1 -1
  452. package/dist/text/output.js +2 -2
  453. package/dist/text/output.js.map +1 -1
  454. package/dist/text/render.d.ts +4 -3
  455. package/dist/text/render.js +128 -6
  456. package/dist/text/render.js.map +1 -1
  457. package/dist/transform/index.d.ts +1 -1
  458. package/dist/transform/index.js +1 -1
  459. package/dist/transform/index.js.map +1 -1
  460. package/dist/transform/run.d.ts +2 -0
  461. package/dist/transform/run.js +32 -16
  462. package/dist/transform/run.js.map +1 -1
  463. package/dist/web/output.js +116 -10
  464. package/dist/web/output.js.map +1 -1
  465. package/dist/web/runtime/justify.js.txt +2 -2
  466. package/dist/web/site.d.ts +2 -0
  467. package/dist/web/site.js +8 -1
  468. package/dist/web/site.js.map +1 -1
  469. package/docs/README.md +6 -1
  470. package/docs/manual/chapters/front.dj +34 -0
  471. package/docs/manual/chapters/guides/citations.dj +426 -0
  472. package/docs/manual/chapters/guides/colour-and-prepress.dj +261 -0
  473. package/docs/manual/chapters/guides/editions.dj +329 -0
  474. package/docs/manual/chapters/guides/in-a-web-page.dj +143 -0
  475. package/docs/manual/chapters/guides/lines-and-pages.dj +681 -0
  476. package/docs/manual/chapters/guides/lint-rules.dj +355 -0
  477. package/docs/manual/chapters/guides/pdfs.dj +501 -0
  478. package/docs/manual/chapters/guides/plugins.dj +425 -0
  479. package/docs/manual/chapters/guides/testing.dj +264 -0
  480. package/docs/manual/chapters/guides/writing-in-djot.dj +537 -0
  481. package/docs/manual/chapters/start/for-latex-users.dj +256 -0
  482. package/docs/manual/chapters/start/getting-started.dj +167 -0
  483. package/docs/manual/chapters/start/your-first-book.dj +426 -0
  484. package/docs/manual/fonts/CrimsonPro-Italic-VF.ttf +0 -0
  485. package/docs/manual/fonts/CrimsonPro-VF.ttf +0 -0
  486. package/docs/manual/fonts/JetBrainsMono-Regular.otf +0 -0
  487. package/docs/manual/fonts/NotoSansSymbols2-Boxes.ttf +0 -0
  488. package/docs/manual/fonts/OFL.txt +95 -0
  489. package/docs/manual/pulpweaver4.toml +39 -0
  490. package/docs/manual/styles/manual.css +137 -0
  491. package/docs/reference/css-properties/index.md +9 -0
  492. package/docs/reference/css-properties/pw-expansion.md +31 -0
  493. package/docs/reference/css-properties/pw-flow-into.md +31 -0
  494. package/docs/reference/css-properties/pw-knockout.md +26 -0
  495. package/docs/reference/css-properties/pw-layer.md +24 -0
  496. package/docs/reference/css-properties/pw-page-breaking.md +30 -0
  497. package/docs/reference/css-properties/pw-page-duration.md +28 -0
  498. package/docs/reference/css-properties/pw-page-rotate.md +29 -0
  499. package/docs/reference/css-properties/pw-page-transition.md +29 -0
  500. package/docs/reference/css-properties/pw-protrusion.md +31 -0
  501. package/docs/reference/lint-rules/ibid-across-page.md +2 -2
  502. package/docs/reference/lint-rules/unused-entry.md +3 -1
  503. package/docs/reference/plugin-api/capabilities.md +2 -2
  504. package/docs/reference/plugin-api/claim-kind.md +1 -1
  505. package/docs/reference/plugin-api/combine-exceptions.md +19 -0
  506. package/docs/reference/plugin-api/element-break-context.md +34 -0
  507. package/docs/reference/plugin-api/element-break-item.md +24 -0
  508. package/docs/reference/plugin-api/element-breaker.md +24 -0
  509. package/docs/reference/plugin-api/flow-definition.md +30 -0
  510. package/docs/reference/plugin-api/generated-reference.md +32 -0
  511. package/docs/reference/plugin-api/index-definition.md +32 -0
  512. package/docs/reference/plugin-api/index-titles.md +18 -0
  513. package/docs/reference/plugin-api/index.md +27 -3
  514. package/docs/reference/plugin-api/insert-class-definition.md +46 -0
  515. package/docs/reference/plugin-api/insert-placement.md +22 -0
  516. package/docs/reference/plugin-api/insert-placements.md +18 -0
  517. package/docs/reference/plugin-api/layout-definition.md +9 -5
  518. package/docs/reference/plugin-api/layout-slot.md +6 -16
  519. package/docs/reference/plugin-api/lint-context.md +3 -1
  520. package/docs/reference/plugin-api/lint-definition.md +1 -1
  521. package/docs/reference/plugin-api/lint-edition.md +2 -0
  522. package/docs/reference/plugin-api/page-builder-event.md +22 -0
  523. package/docs/reference/plugin-api/page-builder-hook.md +7 -3
  524. package/docs/reference/plugin-api/page-builder-page-event.md +30 -0
  525. package/docs/reference/plugin-api/page-template-definition.md +34 -0
  526. package/docs/reference/plugin-api/page-template-region-definition.md +46 -0
  527. package/docs/reference/plugin-api/plugin-definition.md +5 -1
  528. package/docs/reference/plugin-api/plugin-reference-options.md +32 -0
  529. package/docs/reference/plugin-api/plugin-reference.md +22 -0
  530. package/docs/reference/plugin-api/plugin-registry.md +15 -5
  531. package/docs/reference/plugin-api/plugin-stage.md +1 -1
  532. package/docs/reference/plugin-api/plugin.md +9 -2
  533. package/docs/reference/plugin-api/reference-page.md +34 -0
  534. package/docs/reference/plugin-api/render-reference-page.md +18 -0
  535. package/docs/reference/plugin-api/renderers.md +1 -1
  536. package/docs/reference/pulpweaver4-toml/editions.md +253 -2
  537. package/docs/reference/pulpweaver4-toml/index.md +57 -1
  538. package/docs/reference/pulpweaver4-toml/inks.md +15 -4
  539. package/docs/reference/pulpweaver4-toml/lint.md +1 -1
  540. package/package.json +5 -1
@@ -5,13 +5,28 @@
5
5
  * pages (the test API's `render` and `layout` stages, so a test's `build()`
6
6
  * of the edition sees these very pages), checks every character it sets has
7
7
  * a project face, paints the pages (`paintDocument`) in the edition's
8
- * colour, flattens their transparency for PDF/X-1a and X-3
8
+ * colour, makes form controls their looks alone in PDF/X (`fieldsAsContent`),
9
+ * flattens their transparency for PDF/X-1a and X-3
9
10
  * (`flattenTransparency`), adds the PDF's links, bookmarks, page labels and
10
- * tags (`structurePdf`), and writes it with the edition's standards (PDF/X
11
+ * tags (`structurePdf`), puts what `--pw-layer` names in layers (`layerOps`), imposes a booklet or n-up edition's pages onto its
12
+ * sheets (`imposeDocument`), with creep and on press sheets with a slug line if it asks, makes its included PDFs (figures, `{.pages}`)
13
+ * fit for the edition's colour and standards, refusing what they can't meet
14
+ * (`prepareIncludedPdfs`), and writes it with the edition's standards (PDF/X
11
15
  * through `asPdfX`), output intent and metadata, the date being the
12
- * build's, never the clock's.
16
+ * build's, never the clock's; then, if the edition says, encrypts,
17
+ * linearizes it and packs its objects into object streams, with qpdf.
13
18
  *
14
19
  * It writes one file, `<edition>.pdf`.
20
+ *
21
+ * A build session's export (`BuildSession.writePdf`, #157) gives it the
22
+ * session's book (`OutputContext.laidOut`): it paints those pages, laid out
23
+ * as its own layout would lay them out, and keeps each page's display list
24
+ * in the session's paint cache, so only the pages an edit changed are
25
+ * painted again, into the same file, and flattened and tagged again: what
26
+ * those steps made of every other page is kept beside its display list
27
+ * (#178). Its font check looks again only at the text nodes whose text or
28
+ * fonts changed, what it found in the rest kept in the session's
29
+ * `FontCheckCache` (#187).
15
30
  */
16
31
  import { CmykConverter } from '../colour/cmyk.js';
17
32
  import { loadOutputIntent, OutputIntentError, outputIntentProblem } from '../colour/intents.js';
@@ -22,13 +37,19 @@ import { FontRegistry } from '../layout/fonts.js';
22
37
  import { Measurer } from '../measure/measurer.js';
23
38
  import { editionStyles } from '../output/stylesheets.js';
24
39
  import { flattenTransparency } from '../paint/flatten.js';
25
- import { paintDocument } from '../paint/painter.js';
26
- import { editionPdf, structurePdf } from '../pdf/structure/index.js';
40
+ import { layerOps, PageLayers } from '../paint/layers.js';
41
+ import { paintDocument, paintedFrom } from '../paint/painter.js';
42
+ import { attachment, commentNote, editionPdf, fieldsAsContent, mediaTypeOf, placedAnnotations, structurePdf } from '../pdf/structure/index.js';
43
+ import { isProjectSrc, projectImagePath } from '../html/images.js';
44
+ import { prepareIncludedPdfs } from '../pdf/include/prepare.js';
27
45
  import { asPdfX } from '../pdf/pdfx.js';
46
+ import { addPresentation } from '../pdf/structure/presentation.js';
28
47
  import { initPdfWriter, PDF_WRITER_WASM_URL, PdfRefusedError, writePdf } from '../pdf/writer.js';
48
+ import { initQpdf, QPDF_WASM_URL, rewritePdf } from '../qpdf/qpdf.js';
29
49
  import { EMPTY_REGISTRY } from '../plugin/register.js';
30
50
  import { rendererRegistry } from '../plugin/render.js';
31
51
  import { hasErrors, problemAt } from '../problem.js';
52
+ import { ImposeError, imposeDocument } from './impose.js';
32
53
  import { layoutStage } from '../test/layout.js';
33
54
  import { projectEdition } from '../test/pipeline.js';
34
55
  import { renderStage } from '../test/render.js';
@@ -39,7 +60,7 @@ export function pdfFile(edition) {
39
60
  /** The core's PDF output. */
40
61
  export const pdfOutput = { name: 'pdf', write: writeEditionPdf };
41
62
  async function writeEditionPdf(ctx) {
42
- const { project, edition, manuscript, out } = ctx;
63
+ const { project, edition, out } = ctx;
43
64
  const { config } = project;
44
65
  const host = ctx.document ?? document;
45
66
  const problems = [];
@@ -58,8 +79,15 @@ async function writeEditionPdf(ctx) {
58
79
  problems.push(at(edition.outputIntent === undefined ? 'pdf-standard' : 'output-intent', 'pdf-x-output-intent', `${edition.pdfStandards.join(', ')} needs the printer’s profile as its output intent`, 'set output-intent = "GRACoL2013" and color = "cmyk", or the path of the printer’s .icc file'));
59
80
  return { files: [], problems };
60
81
  }
82
+ // A registered condition is named alone, so the PDF must name one: a printer's own profile is Custom.
83
+ const registered = edition.outputProfile === 'registered';
84
+ if (registered && intent && !intent.standard) {
85
+ problems.push(at('output-profile', 'pdf-unregistered-intent', `output-profile = "registered" names the output intent’s condition alone, and ${edition.outputIntent} is a printer’s own profile, which no registry has`, 'take output-profile out, which embeds the profile'));
86
+ return { files: [], problems };
87
+ }
61
88
  // PDF/A-1 is PDF 1.4, which holds ICC profiles of version 2 at most (GRACoL 2013's is 4.2).
62
- const version = intent?.profile?.[8];
89
+ // A registered condition's profile isn't in the file, only converted through, so any version will do.
90
+ const version = registered ? undefined : intent?.profile?.[8];
63
91
  const minor = (intent?.profile?.[9] ?? 0) >> 4;
64
92
  if (edition.pdfStandards.some((s) => s.startsWith('PDF/A-1')) && version !== undefined && version > 2) {
65
93
  problems.push(at('output-intent', 'pdf-a1-profile', `PDF/A-1’s PDF 1.4 holds ICC profiles of version 2 at most, and ${edition.outputIntent}’s is version ${version}.${minor}`, 'use "PDF/A-2b" (or "PDF/A-2a"), or a version 2 profile, such as "FOGRA39"'));
@@ -71,65 +99,135 @@ async function writeEditionPdf(ctx) {
71
99
  if (x && version !== undefined && (x === 'PDF/X-4' ? version > 4 || (version === 4 && minor > 2) : version > 2)) {
72
100
  problems.push(x === 'PDF/X-4'
73
101
  ? at('output-intent', 'pdf-x-profile', `PDF/X-4’s output intent is an ICC profile of version 4.2 at most, and ${edition.outputIntent}’s is version ${version}.${minor}`, 'ask the printer for their profile in ICC version 4.2 or 2')
74
- : at('output-intent', 'pdf-x-profile', `${x}’s output intent is an ICC profile of version 2, as ICC.1:1998 defines it, and ${edition.outputIntent}’s is version ${version}.${minor}`, 'use "PDF/X-4", which takes it, or a version 2 profile, such as "FOGRA39"'));
102
+ : at('output-intent', 'pdf-x-profile', `${x}’s output intent is an ICC profile of version 2, as ICC.1:1998 defines it, and ${edition.outputIntent}’s is version ${version}.${minor}`, 'use "PDF/X-4", which takes it, a version 2 profile, such as "FOGRA39", or output-profile = "registered", which names the condition without its profile'));
75
103
  return { files: [], problems };
76
104
  }
105
+ // The files the edition carries, read before anything is laid out: one that isn't there stops the build.
106
+ const files = [];
107
+ for (const a of edition.attachments ?? []) {
108
+ const path = ['editions', edition.name, 'attachments', a.file];
109
+ if (!project.files.includes(a.file)) {
110
+ problems.push(TomlDocument.parse(project.configText, CONFIG_FILE).problem(path, 'key', 'missing-attachment', `the file ${a.file} to attach is not in the project`, 'name the file by its path from the project’s root'));
111
+ continue;
112
+ }
113
+ files.push({
114
+ name: a.file.slice(a.file.lastIndexOf('/') + 1), data: await project.fs.readFile(a.file), mime: a.mediaType ?? mediaTypeOf(a.file),
115
+ description: a.description ?? a.file.slice(a.file.lastIndexOf('/') + 1), association: a.relationship ?? 'supplement',
116
+ ...(ctx.date ? { modificationDate: ctx.date } : {}),
117
+ });
118
+ }
119
+ // The scripts the edition runs when opened, read before anything is laid out: one that isn't there stops the build.
120
+ const scripts = [];
121
+ for (const file of edition.javascript ?? []) {
122
+ if (!project.files.includes(file)) {
123
+ problems.push(TomlDocument.parse(project.configText, CONFIG_FILE).problem(['editions', edition.name, 'javascript', edition.javascript.indexOf(file)], 'value', 'missing-script', `the script ${file} is not in the project`, 'name the file by its path from the project’s root'));
124
+ continue;
125
+ }
126
+ const source = await project.fs.readText(file);
127
+ if (source.trim())
128
+ scripts.push({ name: file, source });
129
+ }
130
+ if (hasErrors(problems))
131
+ return { files: [], problems };
77
132
  const cmyk = edition.colour === 'cmyk' && intent?.colourSpace === 'CMYK' && intent.profile ? await CmykConverter.create(intent.profile) : undefined;
78
133
  const container = host.createElement('div');
79
134
  container.className = 'pw-build';
80
- host.body.append(container);
81
135
  try {
82
- const measurer = ctx.measurer ?? (await Measurer.create());
83
- const styles = await editionStyles(project, edition.name, {
84
- measurer, document: host, ...(ctx.stylesheets ? { stylesheets: ctx.stylesheets } : {}), ...(ctx.registry ? { registry: ctx.registry } : {}), ...(cmyk ? { cmykPreview: (c) => cmyk.toSrgb(c) } : {}),
85
- });
86
- problems.push(...styles.problems);
87
- const fonts = new FontRegistry(measurer);
88
- for (const face of styles.fonts.faces)
89
- fonts.use(face.family, face.font, face);
90
- // The test API's stages, so `build()` lays the edition out as this does.
91
- const registry = ctx.registry ?? EMPTY_REGISTRY;
92
- const stage = {
93
- edition: projectEdition(edition.name, project), project, sources: [], plugins: [], registry, fonts, container, problems,
94
- };
95
- const rendered = await renderStage(manuscript, stage, ctx.renderers ?? rendererRegistry(registry));
96
- // Its images were read from the project by the render stage (`loadProjectImages`).
97
- rendered.css = styles.css;
98
- // The structure tree is the HTML's before the layout takes it apart.
99
- const html = rendered.html.cloneNode(true);
100
- const style = host.createElement('style');
101
- style.textContent = styles.css;
102
- container.append(style, rendered.html);
103
- await host.fonts.ready;
104
- // Fonts are never substituted: a character no project face has is an error in print, at its place in the source.
105
- for (const p of checkFonts(rendered.html, styles.fonts, { media: 'print', locate: (node) => rendered.locate?.(node) })) {
106
- problems.push(problemAt(p.position, p, AT_CONFIG));
107
- }
108
- let laidOut;
109
- try {
110
- laidOut = await layoutStage(rendered, stage);
111
- }
112
- catch (e) {
113
- // The layout can't go on without a face for every font it measures: the fonts' errors say why.
114
- if (hasErrors(problems))
115
- return { files: [], problems };
116
- throw e;
117
- }
118
- problems.push(...(laidOut.problems ?? []));
119
- const pages = laidOut.pages.map((p) => p.element);
136
+ const laidOut = ctx.laidOut ? await bookPages(ctx.laidOut.book, ctx, problems) : await layOut(ctx, container, cmyk, problems);
137
+ if (!laidOut)
138
+ return { files: [], problems };
139
+ const { pages, html, styles, measurer, locate } = laidOut;
120
140
  await initPdfWriter(ctx.load ? ctx.load(PDF_WRITER_WASM_URL) : undefined);
121
141
  const colour = cmyk && intent?.profile ? { colour: { cmyk: { profile: intent.profile } } } : {};
122
- const doc = await paintDocument(pages, { faces: styles.fonts, measurer }, { colours: styles.colours, ...colour });
142
+ // A session's export paints only the pages that changed since its last (`paint/cache.ts`), into the same file.
143
+ const fonts = { faces: styles.fonts, measurer };
144
+ const options = { colours: styles.colours, ...colour };
145
+ const cache = ctx.laidOut?.paint;
146
+ const doc = cache ? await cache.paint(pages, fonts, options) : await paintDocument(pages, fonts, options);
147
+ // A session keeps what flattening and tagging make of each page beside its display list, and redoes them only
148
+ // for the pages that changed (#178); never a page with a form control's look on it, which other pages' controls choose.
149
+ const looks = new Set(pdf.forms ? [] : (doc.fields ?? []).flatMap((f) => f.widgets.map((w) => w.page)));
150
+ // PDF/X allows no form fields, so its controls are their looks alone; PDF/A, no button that resets the form.
151
+ if (!pdf.forms)
152
+ fieldsAsContent(doc);
153
+ else if (!pdf.formActions)
154
+ for (const f of doc.fields ?? [])
155
+ delete f.action;
123
156
  // PDF/X-1a and X-3 allow no transparency: what can't be blended over a solid colour is rasterized, with a warning.
124
157
  if (pdf.flatten) {
125
- for (const p of await flattenTransparency(doc, colour)) {
158
+ for (const p of await flattenTransparency(doc, { ...colour, ...(cache ? { pages: flattenedPages(cache, looks) } : {}) })) {
126
159
  const { node, page: _, ...fields } = p;
127
160
  const element = node && (node.nodeType === 1 ? node : node.parentElement);
128
- problems.push(problemAt(element ? rendered.locate?.(element) : undefined, fields, AT_CONFIG));
161
+ problems.push(problemAt(element ? locate(element) : undefined, fields, AT_CONFIG));
162
+ }
163
+ }
164
+ // A link only the pages have (the layout keys every one of the HTML's) would be in no `Link` element: it is left as text.
165
+ const unlinked = (a) => problems.push(problemAt(locate(a), {
166
+ severity: 'warning', code: 'link-untagged',
167
+ message: `the link to ${a.getAttribute('href')} is on the pages but in no element of the book’s HTML, so it is left as text: a tagged PDF has every link in its structure`,
168
+ fix: 'add the link to the book’s HTML, as a resolver does (layout.resolvers), not to the laid-out pages',
169
+ }, AT_CONFIG));
170
+ const annotations = await pageAnnotations(pages, html, project, pdf.annotations, locate, problems, ctx.date);
171
+ // PDF/A records when each attached file was changed, which a reproducible build takes from its date alone.
172
+ if ((files.length || annotations.some((a) => a.attachment)) && pdf.standards.some((s) => s.startsWith('pdf/a')) && !ctx.date) {
173
+ problems.push(at('pdf-standard', 'pdf-a-date', `${edition.pdfStandards.join(', ')} needs the date each attached file was changed, and the build has none`, 'set date in pulpweaver4.toml, or SOURCE_DATE_EPOCH'));
174
+ return { files: [], problems };
175
+ }
176
+ structurePdf(doc, { html, pages, links: pdf.links, unlinked, annotations, ...(cache ? { tags: keptTags(cache, doc, looks) } : {}) });
177
+ // `@page`'s rotation, duration and transition, for a viewer and a presentation.
178
+ for (const message of addPresentation(doc, pages)) {
179
+ problems.push(problemAt(undefined, { severity: 'warning', code: 'page-presentation', message, fix: 'see the property’s values in the manual’s PDFs chapter' }, AT_CONFIG));
180
+ }
181
+ if (edition.start && edition.start.page > doc.pages.length) {
182
+ problems.push(at('start-page', 'bad-value', `start-page is ${edition.start.page}, and the PDF has ${doc.pages.length} page${doc.pages.length === 1 ? '' : 's'}`, `name a page from 1 to ${doc.pages.length}`));
183
+ return { files: [], problems };
184
+ }
185
+ // `--pw-layer`'s optional content groups, inside the tags, around what each element painted (#167).
186
+ if (styles.css.includes('--pw-layer') || pages.some((p) => p.querySelector('[style*="--pw-layer"]'))) {
187
+ const layers = new PageLayers(pages);
188
+ layerOps(doc, layers, paintedFrom);
189
+ for (const { node, ...fields } of layers.problems)
190
+ problems.push(problemAt(locate(node), fields, AT_CONFIG));
191
+ }
192
+ // A booklet or n-up edition's pages, painted as they are, are put on its sheets, or on press sheets.
193
+ if (edition.impose || edition.nUp || edition.sheet) {
194
+ const marks = { crop: !!pages[0]?.querySelector('.pw-crop-mark'), cross: !!pages[0]?.querySelector('.pw-cross-mark') };
195
+ const black = cmyk ? { cmyk: cmyk.fromSrgb([0, 0, 0]) } : { rgb: [0, 0, 0] };
196
+ const sheet = edition.sheet && { width: edition.sheet.width, height: edition.sheet.height };
197
+ const slug = sheet && slugLine(doc, measurer, [config.title, edition.name], ctx.date, black);
198
+ try {
199
+ imposeDocument(doc, {
200
+ booklet: edition.impose === 'booklet', ...(edition.nUp ? { nUp: edition.nUp } : {}), marks, black,
201
+ ...(edition.creep ? { creep: edition.creep } : {}), ...(sheet ? { sheet } : {}), ...(slug ? { slug } : {}),
202
+ });
203
+ }
204
+ catch (e) {
205
+ if (!(e instanceof ImposeError))
206
+ throw e;
207
+ if (e.code === 'press-sheet-size')
208
+ problems.push(at('sheet', e.code, e.message, 'name a bigger press sheet, or set fewer of the edition’s sheets on it with n-up'));
209
+ else
210
+ problems.push(at(edition.impose ? 'impose' : edition.nUp ? 'n-up' : 'sheet', e.code, e.message, 'give every page the edition’s size: an @page rule with another size, bleed or marks makes pages that can’t be imposed with the rest'));
211
+ return { files: [], problems };
129
212
  }
130
213
  }
131
- structurePdf(doc, { html, pages, links: pdf.links });
132
214
  finish(doc, edition, config.title, config.language, intent, ctx.date);
215
+ if (files.length)
216
+ doc.files = files;
217
+ if (scripts.length)
218
+ doc.scripts = scripts;
219
+ // Included PDFs, converted to the edition's colour and checked against its standards, which it knows by now.
220
+ if (doc.pdfs?.length) {
221
+ const included = await prepareIncludedPdfs(doc, cmyk && intent?.profile ? { cmyk: { converter: cmyk, profile: intent.profile } } : {});
222
+ for (const p of included) {
223
+ const { node, ...fields } = p;
224
+ const element = node && (node.nodeType === 1 ? node : node.parentElement);
225
+ problems.push(problemAt(element ? locate(element) : undefined, fields, AT_CONFIG));
226
+ }
227
+ // What a standard refuses in an included PDF is said where it is included: the file can't be written as it claims.
228
+ if (included.some((p) => p.severity === 'error'))
229
+ return { files: [], problems };
230
+ }
133
231
  let bytes;
134
232
  try {
135
233
  bytes = writePdf(doc);
@@ -144,6 +242,19 @@ async function writeEditionPdf(ctx) {
144
242
  problems.push(at(key, 'pdf-refused', `the PDF can't be written: ${e instanceof Error ? e.message : String(e)}`));
145
243
  return { files: [], problems };
146
244
  }
245
+ const rewrite = rewriteOptions(edition);
246
+ if (rewrite) {
247
+ await initQpdf(ctx.load ? ctx.load(QPDF_WASM_URL) : undefined);
248
+ try {
249
+ bytes = rewritePdf(bytes, rewrite);
250
+ }
251
+ catch (e) {
252
+ // qpdf's words, which never hold a password.
253
+ const key = rewrite.encryption ? 'encryption' : rewrite.linearize ? 'linearize' : 'object-streams';
254
+ problems.push(at(key, 'pdf-rewrite', `the PDF can’t be ${rewrite.encryption ? 'encrypted' : rewrite.linearize ? 'linearized' : 'packed into object streams'}: ${e instanceof Error ? e.message : String(e)}`));
255
+ return { files: [], problems };
256
+ }
257
+ }
147
258
  const file = pdfFile(edition.name);
148
259
  await out.writeFile(file, bytes);
149
260
  return { files: [file], problems };
@@ -153,6 +264,173 @@ async function writeEditionPdf(ctx) {
153
264
  cmyk?.close();
154
265
  }
155
266
  }
267
+ /**
268
+ * The pages' comments and attached files (`{comment=…}`, `{attach=…}`),
269
+ * each attached file read from the project as an image is found, beside
270
+ * its chapter or from the project's root; one that isn't there is
271
+ * `missing-attachment`. PDF/X allows none, so there they are left out, each
272
+ * a warning.
273
+ */
274
+ async function pageAnnotations(pages, html, project, allowed, locate, problems, date) {
275
+ const placed = placedAnnotations(pages);
276
+ if (!placed.length)
277
+ return [];
278
+ const byKey = new Map([...html.querySelectorAll('[data-pw-key]')].map((e) => [e.dataset.pwKey, e]));
279
+ const have = new Set(project.files);
280
+ const out = [];
281
+ for (const p of placed) {
282
+ const what = p.kind === 'comment' ? 'comment' : `file ${p.value} attached`;
283
+ if (!allowed) {
284
+ problems.push(problemAt(locate(p.element), {
285
+ severity: 'warning', code: 'annotation-left-out',
286
+ message: `the ${what} here is left out: PDF/X allows no annotation where the page is printed`,
287
+ fix: 'leave it to editions without PDF/X, with {.edition-<name>} or a condition',
288
+ }, AT_CONFIG));
289
+ continue;
290
+ }
291
+ if (p.kind === 'comment') {
292
+ out.push({ placed: p, note: commentNote(p) });
293
+ continue;
294
+ }
295
+ const chapter = (byKey.get(p.key) ?? p.element).closest('[data-pw-file]')?.dataset.pwFile;
296
+ const path = isProjectSrc(p.value) ? projectImagePath(p.value, chapter, have) : undefined;
297
+ if (path === undefined) {
298
+ problems.push(problemAt(locate(p.element), {
299
+ severity: 'error', code: 'missing-attachment', message: `the file ${p.value} to attach is not in the project`,
300
+ fix: 'put the file in the project, beside the chapter or from its root, or check the path',
301
+ }, AT_CONFIG));
302
+ continue;
303
+ }
304
+ const name = path.slice(path.lastIndexOf('/') + 1);
305
+ const file = attachment(p, { name, data: await project.fs.readFile(path), mime: mediaTypeOf(path) });
306
+ if (date)
307
+ file.modificationDate = date;
308
+ out.push({ placed: p, attachment: file });
309
+ }
310
+ return out;
311
+ }
312
+ /**
313
+ * Styles the edition, renders the book and lays it out in `container`,
314
+ * which it puts in the document, and checks that every character set has a
315
+ * project face; undefined if the layout can't go on.
316
+ */
317
+ async function layOut(ctx, container, cmyk, problems) {
318
+ const { project, edition, manuscript } = ctx;
319
+ const host = ctx.document ?? document;
320
+ host.body.append(container);
321
+ const measurer = ctx.measurer ?? (await Measurer.create());
322
+ const styles = await editionStyles(project, edition.name, {
323
+ measurer, document: host, ...(ctx.stylesheets ? { stylesheets: ctx.stylesheets } : {}), ...(ctx.registry ? { registry: ctx.registry } : {}), ...(cmyk ? { cmykPreview: (c) => cmyk.toSrgb(c) } : {}),
324
+ });
325
+ problems.push(...styles.problems);
326
+ const fonts = new FontRegistry(measurer);
327
+ for (const face of styles.fonts.faces)
328
+ fonts.use(face.family, face.font, face);
329
+ // The test API's stages, so `build()` lays the edition out as this does.
330
+ const registry = ctx.registry ?? EMPTY_REGISTRY;
331
+ const stage = {
332
+ edition: projectEdition(edition.name, project), project, sources: [], plugins: [], registry, fonts, container, problems,
333
+ };
334
+ const rendered = await renderStage(manuscript, stage, ctx.renderers ?? rendererRegistry(registry));
335
+ // Its images were read from the project by the render stage (`loadProjectImages`).
336
+ rendered.css = styles.css;
337
+ const style = host.createElement('style');
338
+ style.textContent = styles.css;
339
+ container.append(style, rendered.html);
340
+ await host.fonts.ready;
341
+ const locate = (node) => rendered.locate?.(node);
342
+ // Fonts are never substituted: a character no project face has is an error in print, at its place in the source.
343
+ for (const p of checkFonts(rendered.html, styles.fonts, { media: 'print', locate }))
344
+ problems.push(problemAt(p.position, p, AT_CONFIG));
345
+ let laidOut;
346
+ try {
347
+ laidOut = await layoutStage(rendered, stage);
348
+ }
349
+ catch (e) {
350
+ // The layout can't go on without a face for every font it measures: the fonts' errors say why.
351
+ if (hasErrors(problems))
352
+ return undefined;
353
+ throw e;
354
+ }
355
+ problems.push(...(laidOut.problems ?? []));
356
+ return {
357
+ pages: laidOut.pages.map((p) => p.element),
358
+ // The structure tree is the HTML's, whole as the layout leaves it, with what it filled in from the pages
359
+ // (an index's locator links, #161) and none of the pages' pieces.
360
+ html: rendered.html.cloneNode(true),
361
+ styles, measurer, locate,
362
+ };
363
+ }
364
+ /**
365
+ * The pages of a book a build session laid out (`OutputContext.laidOut`),
366
+ * as the PDF takes them: what the session's build styled it with, and every
367
+ * character set checked for a project face as `layOut` checks it, in the
368
+ * HTML as the layout left it, put back beside the pages for that.
369
+ */
370
+ async function bookPages(book, ctx, problems) {
371
+ const html = book.laidOutHtml;
372
+ const styles = book.styles;
373
+ const pages = [...book.pages].map((p) => p.element);
374
+ const parent = pages[0]?.parentElement;
375
+ if (!html || !styles || !ctx.measurer || !parent)
376
+ throw new Error('a laid-out book for a PDF needs its HTML, its edition\'s styles, its measurer and its pages in the document');
377
+ const locate = (node) => book.locate(node);
378
+ // Checked at once, the session's fonts loaded long since: no frame shows the HTML beside the pages.
379
+ parent.append(html);
380
+ try {
381
+ const cache = ctx.laidOut?.fonts;
382
+ for (const p of checkFonts(html, styles.fonts, { media: 'print', locate, ...(cache ? { cache } : {}) }))
383
+ problems.push(problemAt(p.position, p, AT_CONFIG));
384
+ }
385
+ finally {
386
+ html.remove();
387
+ }
388
+ return { pages, html: html.cloneNode(true), styles, measurer: ctx.measurer, locate };
389
+ }
390
+ /** The pages a session's paint cache keeps flattened, but those with a form control's look on them. */
391
+ function flattenedPages(cache, looks) {
392
+ return {
393
+ get: (i, doc) => {
394
+ if (looks.has(i))
395
+ return undefined;
396
+ const kept = cache.kept('flatten', i, doc);
397
+ return kept && { ops: kept.ops, problems: kept.value.map((p, n) => ({ ...p, ...(kept.nodes[n] ? { node: kept.nodes[n] } : {}) })) };
398
+ },
399
+ set: (i, doc, page) => {
400
+ if (looks.has(i))
401
+ return;
402
+ const images = doc.images?.slice(page.firstImage) ?? [];
403
+ cache.keep('flatten', i, doc, {
404
+ ops: page.ops, firstImage: page.firstImage, images,
405
+ nodes: page.problems.map((p) => p.node), value: page.problems.map(({ node: _, ...p }) => p),
406
+ });
407
+ },
408
+ };
409
+ }
410
+ /** The pages a session's paint cache keeps tagged, but those with a form control's look on them. */
411
+ function keptTags(cache, doc, looks) {
412
+ return {
413
+ get: (i, context) => {
414
+ if (looks.has(i))
415
+ return undefined;
416
+ return cache.kept('tags', i, doc, (v) => v.context === context)?.value.tags;
417
+ },
418
+ set: (i, context, tags) => {
419
+ if (!looks.has(i))
420
+ cache.keep('tags', i, doc, { ops: [], value: { context, tags } });
421
+ },
422
+ };
423
+ }
424
+ /** What qpdf does to the edition's PDF once it is written, if anything. */
425
+ function rewriteOptions(edition) {
426
+ if (!edition.encryption && !edition.linearize && !edition.objectStreams)
427
+ return undefined;
428
+ return {
429
+ ...(edition.encryption ? { encryption: edition.encryption } : {}),
430
+ ...(edition.linearize ? { linearize: true } : {}),
431
+ ...(edition.objectStreams ? { objectStreams: true } : {}),
432
+ };
433
+ }
156
434
  /** The edition's output intent, loaded; a problem at its `output-intent` if it can't be. */
157
435
  async function outputIntent(edition, ctx, problems) {
158
436
  if (edition.outputIntent === undefined)
@@ -175,17 +453,10 @@ async function outputIntent(edition, ctx, problems) {
175
453
  */
176
454
  function finish(doc, edition, title, lang, intent, date) {
177
455
  const { standards } = editionPdf(edition.pdfStandards);
178
- const outputIntent = intent?.profile
179
- ? {
180
- profile: intent.profile, identifier: intent.identifier,
181
- ...(intent.condition ? { condition: intent.condition } : {}),
182
- ...(intent.registryName ? { registryName: intent.registryName } : {}),
183
- ...(intent.info ? { info: intent.info } : {}),
184
- }
185
- : undefined;
456
+ const outputIntent = intent?.profile ? pdfOutputIntent(intent, intent.profile, edition.outputProfile) : undefined;
186
457
  const others = standards.filter((s) => !s.startsWith('pdf/x-'));
187
458
  doc.settings = { ...doc.settings, ...(others.length ? { standards: others } : {}), ...(outputIntent ? { outputIntent } : {}) };
188
- doc.metadata = { ...doc.metadata, title, lang, ...(date ? { creationDate: date } : {}) };
459
+ doc.metadata = { ...doc.metadata, title, lang, ...(date ? { creationDate: date } : {}), ...xmpMetadata(edition), ...viewerMetadata(edition) };
189
460
  const x = standards.find((s) => s.startsWith('pdf/x-'));
190
461
  if (!x)
191
462
  return;
@@ -194,6 +465,101 @@ function finish(doc, edition, title, lang, intent, date) {
194
465
  throw new Error(`${x} without ${outputIntent ? 'a date' : 'the printer’s profile'}`);
195
466
  asPdfX(doc, { standard: x, outputIntent, title, creationDate: date });
196
467
  }
468
+ const PAGE_MODES = { none: 'use-none', bookmarks: 'use-outlines', thumbnails: 'use-thumbs', layers: 'use-oc', attachments: 'use-attachments', 'full-screen': 'full-screen' };
469
+ /** What an edition asks of a viewer: `page-mode`, `start-page` and `start-view`, and `[viewer]`. */
470
+ function viewerMetadata(edition) {
471
+ const out = {};
472
+ if (edition.pageMode)
473
+ out.pageMode = PAGE_MODES[edition.pageMode];
474
+ if (edition.start)
475
+ out.openAt = { page: edition.start.page - 1, fit: edition.start.view === 'fit-page' ? 'page' : edition.start.view === 'fit-width' ? 'width' : 'xyz' };
476
+ const v = edition.viewer;
477
+ if (v) {
478
+ const prefs = {
479
+ ...(v.hideToolbar !== undefined ? { hideToolbar: v.hideToolbar } : {}),
480
+ ...(v.hideMenubar !== undefined ? { hideMenubar: v.hideMenubar } : {}),
481
+ ...(v.hideWindowUi !== undefined ? { hideWindowUi: v.hideWindowUi } : {}),
482
+ ...(v.fitWindow !== undefined ? { fitWindow: v.fitWindow } : {}),
483
+ ...(v.centerWindow !== undefined ? { centerWindow: v.centerWindow } : {}),
484
+ ...(v.showTitle !== undefined ? { displayDocTitle: v.showTitle } : {}),
485
+ ...(v.afterFullScreen ? { nonFullScreenPageMode: PAGE_MODES[v.afterFullScreen] } : {}),
486
+ };
487
+ if (Object.keys(prefs).length)
488
+ out.viewerPreferences = prefs;
489
+ }
490
+ return out;
491
+ }
492
+ /**
493
+ * An edition's custom XMP (`[editions.<name>.xmp.<prefix>]`): its
494
+ * properties, and under PDF/A-1 to A-3, which require one, a description of
495
+ * each namespace, every property text.
496
+ */
497
+ function xmpMetadata(edition) {
498
+ if (!edition.xmp?.length)
499
+ return {};
500
+ const describe = edition.pdfStandards.some((s) => /^PDF\/A-[123]/.test(s));
501
+ return {
502
+ xmpProperties: edition.xmp.flatMap((n) => Object.entries(n.properties).map(([name, value]) => ({ prefix: n.prefix, uri: n.uri, name, value }))),
503
+ ...(describe ? {
504
+ xmpSchemas: edition.xmp.map((n) => ({
505
+ prefix: n.prefix, uri: n.uri, ...(n.schema ? { name: n.schema } : {}),
506
+ properties: Object.keys(n.properties).map((name) => ({ name, description: name })),
507
+ })),
508
+ } : {}),
509
+ };
510
+ }
511
+ /**
512
+ * The output intent as the PDF names it: with its profile, or for
513
+ * `output-profile = "registered"` the registered condition alone, whose
514
+ * profile the build has converted through but leaves out of the file.
515
+ */
516
+ function pdfOutputIntent(intent, profile, form) {
517
+ const name = {
518
+ identifier: intent.identifier,
519
+ ...(intent.condition ? { condition: intent.condition } : {}),
520
+ ...(intent.registryName ? { registryName: intent.registryName } : {}),
521
+ ...(intent.info ? { info: intent.info } : {}),
522
+ };
523
+ if (form === 'embedded')
524
+ return { ...name, profile };
525
+ return { ...name, colourSpace: intent.colourSpace === 'GRAY' ? 'grey' : intent.colourSpace === 'RGB' ? 'rgb' : 'cmyk' };
526
+ }
527
+ /**
528
+ * What sets a press sheet's slug line: the book's title, the edition's name,
529
+ * which sheet and side it is, and the build's date, in the face the book's
530
+ * text is most set in, at the instance it is set in, so it adds no font to
531
+ * the file. Characters the face lacks are left out. None if the book sets no
532
+ * text.
533
+ */
534
+ function slugLine(doc, measurer, job, date, black) {
535
+ const uses = new Map();
536
+ for (const page of doc.pages)
537
+ for (const op of page.ops ?? [])
538
+ if (op.op === 'glyphs')
539
+ uses.set(op.font, (uses.get(op.font) ?? 0) + op.glyphs.length);
540
+ const index = [...uses].sort((a, b) => b[1] - a[1] || a[0] - b[0])[0]?.[0];
541
+ const pdfFont = index === undefined ? undefined : doc.fonts?.[index];
542
+ if (index === undefined || !pdfFont)
543
+ return undefined;
544
+ const font = measurer.loadFont(pdfFont.data, pdfFont.index ?? 0);
545
+ const variations = Object.fromEntries((pdfFont.variations ?? []).map((v) => [v.tag, v.value]));
546
+ const day = date && `${date.year}-${String(date.month).padStart(2, '0')}-${String(date.day).padStart(2, '0')}`;
547
+ return (label, { x, y, size }) => {
548
+ const text = [...job, label, ...(day ? [day] : [])].join(' · ');
549
+ const style = { sizePx: size / 0.75, features: {}, variations, opticalSizing: false, letterSpacingPx: 0, wordSpacingPx: 0, lang: '', direction: 'ltr' };
550
+ const run = measurer.shape(font, text, style, { glyphs: true });
551
+ const starts = [...new Set(run.glyphs.map((g) => g.cluster))].sort((a, b) => a - b);
552
+ const glyphs = [];
553
+ for (const g of run.glyphs) {
554
+ const end = starts.find((s) => s > g.cluster) ?? text.length;
555
+ if (g.id === 0)
556
+ continue;
557
+ glyphs.push({ id: g.id, advance: g.advance * 0.75, text: [g.cluster, end], ...(g.offsetX ? { dx: g.offsetX * 0.75 } : {}), ...(g.offsetY ? { dy: -g.offsetY * 0.75 } : {}) });
558
+ }
559
+ const op = { op: 'glyphs', font: index, size: run.setSize * 0.75, x, y, text, glyphs, fill: { colour: black } };
560
+ return [op];
561
+ };
562
+ }
197
563
  /** Where a problem with no place in the source is put: the configuration. */
198
564
  const AT_CONFIG = { file: 'pulpweaver4.toml', line: 1, column: 1, endLine: 1, endColumn: 1 };
199
565
  //# sourceMappingURL=output.js.map