pulpweaver4 0.0.91 → 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 (502) hide show
  1. package/dist/ast/djot.js +23 -0
  2. package/dist/ast/djot.js.map +1 -1
  3. package/dist/ast/index.d.ts +1 -0
  4. package/dist/ast/index.js +1 -0
  5. package/dist/ast/index.js.map +1 -1
  6. package/dist/ast/nodes.d.ts +59 -5
  7. package/dist/ast/nodes.js.map +1 -1
  8. package/dist/ast/table.d.ts +27 -0
  9. package/dist/ast/table.js +32 -0
  10. package/dist/ast/table.js.map +1 -0
  11. package/dist/browser.js +2420 -0
  12. package/dist/citations/index.d.ts +1 -1
  13. package/dist/citations/index.js +1 -1
  14. package/dist/citations/index.js.map +1 -1
  15. package/dist/citations/project.d.ts +12 -2
  16. package/dist/citations/project.js +21 -7
  17. package/dist/citations/project.js.map +1 -1
  18. package/dist/colour/images.d.ts +11 -2
  19. package/dist/colour/images.js +53 -3
  20. package/dist/colour/images.js.map +1 -1
  21. package/dist/colour/ink-limit.d.ts +2 -2
  22. package/dist/colour/ink-limit.js +6 -0
  23. package/dist/colour/ink-limit.js.map +1 -1
  24. package/dist/colour/previews.d.ts +8 -4
  25. package/dist/colour/previews.js +11 -8
  26. package/dist/colour/previews.js.map +1 -1
  27. package/dist/config/config.d.ts +91 -3
  28. package/dist/config/config.js +200 -3
  29. package/dist/config/config.js.map +1 -1
  30. package/dist/config/project-schema.d.ts +0 -8
  31. package/dist/config/project-schema.js +207 -12
  32. package/dist/config/project-schema.js.map +1 -1
  33. package/dist/config/schema.js +10 -0
  34. package/dist/config/schema.js.map +1 -1
  35. package/dist/config/secrets.d.ts +11 -0
  36. package/dist/config/secrets.js +19 -0
  37. package/dist/config/secrets.js.map +1 -0
  38. package/dist/csl/project.d.ts +19 -4
  39. package/dist/csl/project.js +23 -10
  40. package/dist/csl/project.js.map +1 -1
  41. package/dist/fonts/index.d.ts +1 -1
  42. package/dist/fonts/index.js +1 -1
  43. package/dist/fonts/index.js.map +1 -1
  44. package/dist/fonts/lint.d.ts +51 -0
  45. package/dist/fonts/lint.js +101 -16
  46. package/dist/fonts/lint.js.map +1 -1
  47. package/dist/fonts/walk.d.ts +13 -0
  48. package/dist/fonts/walk.js +50 -33
  49. package/dist/fonts/walk.js.map +1 -1
  50. package/dist/html/css.d.ts +4 -0
  51. package/dist/html/css.js +11 -3
  52. package/dist/html/css.js.map +1 -1
  53. package/dist/html/dom.d.ts +6 -1
  54. package/dist/html/dom.js +28 -6
  55. package/dist/html/dom.js.map +1 -1
  56. package/dist/html/generated.d.ts +17 -0
  57. package/dist/html/generated.js +21 -0
  58. package/dist/html/generated.js.map +1 -0
  59. package/dist/html/images.d.ts +18 -0
  60. package/dist/html/images.js +49 -2
  61. package/dist/html/images.js.map +1 -1
  62. package/dist/html/index.d.ts +1 -0
  63. package/dist/html/index.js +1 -0
  64. package/dist/html/index.js.map +1 -1
  65. package/dist/html/render.d.ts +5 -4
  66. package/dist/html/render.js +24 -6
  67. package/dist/html/render.js.map +1 -1
  68. package/dist/hyphenation/exceptions.d.ts +5 -0
  69. package/dist/hyphenation/exceptions.js +11 -0
  70. package/dist/hyphenation/exceptions.js.map +1 -1
  71. package/dist/hyphenation/index.d.ts +1 -1
  72. package/dist/hyphenation/index.js +1 -1
  73. package/dist/hyphenation/index.js.map +1 -1
  74. package/dist/import/convert.d.ts +21 -0
  75. package/dist/import/convert.js +65 -0
  76. package/dist/import/convert.js.map +1 -0
  77. package/dist/incremental/cache.d.ts +59 -0
  78. package/dist/incremental/cache.js +64 -0
  79. package/dist/incremental/cache.js.map +1 -0
  80. package/dist/incremental/index.d.ts +3 -0
  81. package/dist/incremental/index.js +4 -0
  82. package/dist/incremental/index.js.map +1 -0
  83. package/dist/incremental/keys.d.ts +27 -0
  84. package/dist/incremental/keys.js +89 -0
  85. package/dist/incremental/keys.js.map +1 -0
  86. package/dist/incremental/session.d.ts +180 -0
  87. package/dist/incremental/session.js +401 -0
  88. package/dist/incremental/session.js.map +1 -0
  89. package/dist/index.d.ts +6 -0
  90. package/dist/index.js +6 -0
  91. package/dist/index.js.map +1 -1
  92. package/dist/indexes/layout.d.ts +8 -2
  93. package/dist/indexes/layout.js +6 -4
  94. package/dist/indexes/layout.js.map +1 -1
  95. package/dist/layout/cache.d.ts +174 -0
  96. package/dist/layout/cache.js +150 -0
  97. package/dist/layout/cache.js.map +1 -0
  98. package/dist/layout/converge.d.ts +28 -0
  99. package/dist/layout/converge.js +102 -9
  100. package/dist/layout/converge.js.map +1 -1
  101. package/dist/layout/counters.d.ts +4 -0
  102. package/dist/layout/counters.js +15 -0
  103. package/dist/layout/counters.js.map +1 -1
  104. package/dist/layout/index.d.ts +5 -2
  105. package/dist/layout/index.js +3 -0
  106. package/dist/layout/index.js.map +1 -1
  107. package/dist/layout/lists.d.ts +52 -3
  108. package/dist/layout/lists.js +513 -46
  109. package/dist/layout/lists.js.map +1 -1
  110. package/dist/layout/lookahead.d.ts +151 -0
  111. package/dist/layout/lookahead.js +581 -0
  112. package/dist/layout/lookahead.js.map +1 -0
  113. package/dist/layout/margin-boxes.d.ts +11 -1
  114. package/dist/layout/margin-boxes.js +24 -1
  115. package/dist/layout/margin-boxes.js.map +1 -1
  116. package/dist/layout/page-rules.d.ts +6 -1
  117. package/dist/layout/page-rules.js +42 -1
  118. package/dist/layout/page-rules.js.map +1 -1
  119. package/dist/layout/page.js +4 -2
  120. package/dist/layout/page.js.map +1 -1
  121. package/dist/layout/pagebuilder.d.ts +248 -3
  122. package/dist/layout/pagebuilder.js +512 -19
  123. package/dist/layout/pagebuilder.js.map +1 -1
  124. package/dist/layout/pages.d.ts +108 -1
  125. package/dist/layout/pages.js +1362 -159
  126. package/dist/layout/pages.js.map +1 -1
  127. package/dist/layout/paragraph.d.ts +14 -0
  128. package/dist/layout/paragraph.js +304 -31
  129. package/dist/layout/paragraph.js.map +1 -1
  130. package/dist/layout/pre.js +4 -0
  131. package/dist/layout/pre.js.map +1 -1
  132. package/dist/layout/protrusion.d.ts +26 -0
  133. package/dist/layout/protrusion.js +39 -0
  134. package/dist/layout/protrusion.js.map +1 -0
  135. package/dist/layout/ranges.d.ts +2 -0
  136. package/dist/layout/ranges.js +22 -0
  137. package/dist/layout/ranges.js.map +1 -0
  138. package/dist/layout/region.d.ts +2 -1
  139. package/dist/layout/region.js +9 -5
  140. package/dist/layout/region.js.map +1 -1
  141. package/dist/layout/templates.d.ts +71 -0
  142. package/dist/layout/templates.js +290 -0
  143. package/dist/layout/templates.js.map +1 -0
  144. package/dist/layout/vlist.d.ts +3 -3
  145. package/dist/linebreak/items.d.ts +27 -2
  146. package/dist/linebreak/items.js +10 -3
  147. package/dist/linebreak/items.js.map +1 -1
  148. package/dist/linebreak/knuth-plass.d.ts +20 -0
  149. package/dist/linebreak/knuth-plass.js +68 -16
  150. package/dist/linebreak/knuth-plass.js.map +1 -1
  151. package/dist/lint/book.d.ts +13 -0
  152. package/dist/lint/book.js +52 -0
  153. package/dist/lint/book.js.map +1 -0
  154. package/dist/lint/config.d.ts +9 -0
  155. package/dist/lint/config.js +40 -6
  156. package/dist/lint/config.js.map +1 -1
  157. package/dist/lint/linter.js +1 -0
  158. package/dist/lint/linter.js.map +1 -1
  159. package/dist/lint/project.js +1 -1
  160. package/dist/lint/project.js.map +1 -1
  161. package/dist/lint/rules/layout.d.ts +3 -1
  162. package/dist/lint/rules/layout.js +8 -6
  163. package/dist/lint/rules/layout.js.map +1 -1
  164. package/dist/lint/rules/source.js +1 -1
  165. package/dist/lint/rules/source.js.map +1 -1
  166. package/dist/lint/testing.js +1 -0
  167. package/dist/lint/testing.js.map +1 -1
  168. package/dist/measure/bidi-data.d.ts +14 -0
  169. package/dist/measure/bidi-data.js +69 -0
  170. package/dist/measure/bidi-data.js.map +1 -0
  171. package/dist/measure/bidi.d.ts +70 -0
  172. package/dist/measure/bidi.js +225 -0
  173. package/dist/measure/bidi.js.map +1 -0
  174. package/dist/measure/css.d.ts +5 -0
  175. package/dist/measure/css.js +2 -0
  176. package/dist/measure/css.js.map +1 -1
  177. package/dist/measure/measurer.d.ts +36 -2
  178. package/dist/measure/measurer.js +220 -22
  179. package/dist/measure/measurer.js.map +1 -1
  180. package/dist/measure/model.d.ts +20 -2
  181. package/dist/measure/model.js +13 -6
  182. package/dist/measure/model.js.map +1 -1
  183. package/dist/measure/script-data.d.ts +6 -0
  184. package/dist/measure/script-data.js +34 -0
  185. package/dist/measure/script-data.js.map +1 -0
  186. package/dist/measure/scripts.d.ts +36 -0
  187. package/dist/measure/scripts.js +293 -0
  188. package/dist/measure/scripts.js.map +1 -0
  189. package/dist/output/output.d.ts +35 -3
  190. package/dist/output/output.js +26 -4
  191. package/dist/output/output.js.map +1 -1
  192. package/dist/paint/backgrounds.js +7 -20
  193. package/dist/paint/backgrounds.js.map +1 -1
  194. package/dist/paint/blend.d.ts +33 -13
  195. package/dist/paint/blend.js +73 -21
  196. package/dist/paint/blend.js.map +1 -1
  197. package/dist/paint/cache.d.ts +80 -0
  198. package/dist/paint/cache.js +537 -0
  199. package/dist/paint/cache.js.map +1 -0
  200. package/dist/paint/canvas.d.ts +4 -13
  201. package/dist/paint/canvas.js +45 -5
  202. package/dist/paint/canvas.js.map +1 -1
  203. package/dist/paint/context.d.ts +2 -0
  204. package/dist/paint/emphasis.js +1 -1
  205. package/dist/paint/emphasis.js.map +1 -1
  206. package/dist/paint/flatten.d.ts +24 -2
  207. package/dist/paint/flatten.js +55 -12
  208. package/dist/paint/flatten.js.map +1 -1
  209. package/dist/paint/forms.d.ts +64 -0
  210. package/dist/paint/forms.js +319 -0
  211. package/dist/paint/forms.js.map +1 -0
  212. package/dist/paint/images.d.ts +4 -1
  213. package/dist/paint/images.js +13 -2
  214. package/dist/paint/images.js.map +1 -1
  215. package/dist/paint/layers.d.ts +64 -0
  216. package/dist/paint/layers.js +137 -0
  217. package/dist/paint/layers.js.map +1 -0
  218. package/dist/paint/painter.d.ts +19 -6
  219. package/dist/paint/painter.js +15 -135
  220. package/dist/paint/painter.js.map +1 -1
  221. package/dist/paint/stacking.d.ts +1 -1
  222. package/dist/paint/stacking.js +9 -2
  223. package/dist/paint/stacking.js.map +1 -1
  224. package/dist/paint/text.d.ts +14 -3
  225. package/dist/paint/text.js +25 -4
  226. package/dist/paint/text.js.map +1 -1
  227. package/dist/paint/vertical.js +2 -2
  228. package/dist/paint/vertical.js.map +1 -1
  229. package/dist/pdf/encoded.d.ts +16 -0
  230. package/dist/pdf/encoded.js +35 -0
  231. package/dist/pdf/encoded.js.map +1 -0
  232. package/dist/pdf/include/colour.d.ts +105 -0
  233. package/dist/pdf/include/colour.js +349 -0
  234. package/dist/pdf/include/colour.js.map +1 -0
  235. package/dist/pdf/include/functions.d.ts +17 -0
  236. package/dist/pdf/include/functions.js +389 -0
  237. package/dist/pdf/include/functions.js.map +1 -0
  238. package/dist/pdf/include/pages.d.ts +14 -0
  239. package/dist/pdf/include/pages.js +27 -0
  240. package/dist/pdf/include/pages.js.map +1 -0
  241. package/dist/pdf/include/pdfjs/LICENSE +177 -0
  242. package/dist/pdf/include/pdfjs/pdf.min.mjs +27 -0
  243. package/dist/pdf/include/pdfjs/pdf.worker.min.mjs +27 -0
  244. package/dist/pdf/include/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
  245. package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
  246. package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
  247. package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  248. package/dist/pdf/include/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
  249. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
  250. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
  251. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  252. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
  253. package/dist/pdf/include/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
  254. package/dist/pdf/include/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
  255. package/dist/pdf/include/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
  256. package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
  257. package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  258. package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
  259. package/dist/pdf/include/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
  260. package/dist/pdf/include/pdfjs/wasm/LICENSE_JBIG2 +196 -0
  261. package/dist/pdf/include/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
  262. package/dist/pdf/include/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  263. package/dist/pdf/include/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  264. package/dist/pdf/include/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
  265. package/dist/pdf/include/pdfjs/wasm/LICENSE_QCMS +21 -0
  266. package/dist/pdf/include/pdfjs/wasm/jbig2.wasm +0 -0
  267. package/dist/pdf/include/pdfjs/wasm/openjpeg.wasm +0 -0
  268. package/dist/pdf/include/pdfjs/wasm/qcms_bg.wasm +0 -0
  269. package/dist/pdf/include/pdfjs/wasm/quickjs-eval.wasm +0 -0
  270. package/dist/pdf/include/prepare.d.ts +58 -0
  271. package/dist/pdf/include/prepare.js +266 -0
  272. package/dist/pdf/include/prepare.js.map +1 -0
  273. package/dist/pdf/include/preview.d.ts +38 -0
  274. package/dist/pdf/include/preview.js +101 -0
  275. package/dist/pdf/include/preview.js.map +1 -0
  276. package/dist/pdf/include/rewrite.d.ts +57 -0
  277. package/dist/pdf/include/rewrite.js +803 -0
  278. package/dist/pdf/include/rewrite.js.map +1 -0
  279. package/dist/pdf/include/serialize.d.ts +32 -0
  280. package/dist/pdf/include/serialize.js +158 -0
  281. package/dist/pdf/include/serialize.js.map +1 -0
  282. package/dist/pdf/include/testing.d.ts +26 -0
  283. package/dist/pdf/include/testing.js +50 -0
  284. package/dist/pdf/include/testing.js.map +1 -0
  285. package/dist/pdf/index.d.ts +1 -0
  286. package/dist/pdf/index.js +1 -0
  287. package/dist/pdf/index.js.map +1 -1
  288. package/dist/pdf/structure/annotations.d.ts +33 -0
  289. package/dist/pdf/structure/annotations.js +112 -0
  290. package/dist/pdf/structure/annotations.js.map +1 -0
  291. package/dist/pdf/structure/forms.d.ts +10 -0
  292. package/dist/pdf/structure/forms.js +46 -0
  293. package/dist/pdf/structure/forms.js.map +1 -0
  294. package/dist/pdf/structure/index.d.ts +41 -5
  295. package/dist/pdf/structure/index.js +40 -5
  296. package/dist/pdf/structure/index.js.map +1 -1
  297. package/dist/pdf/structure/links.d.ts +2 -0
  298. package/dist/pdf/structure/links.js +1 -1
  299. package/dist/pdf/structure/links.js.map +1 -1
  300. package/dist/pdf/structure/presentation.d.ts +28 -0
  301. package/dist/pdf/structure/presentation.js +79 -0
  302. package/dist/pdf/structure/presentation.js.map +1 -0
  303. package/dist/pdf/structure/tags.d.ts +34 -2
  304. package/dist/pdf/structure/tags.js +117 -14
  305. package/dist/pdf/structure/tags.js.map +1 -1
  306. package/dist/pdf/types.d.ts +357 -11
  307. package/dist/pdf/wasm/pulpweaver4_pdf.d.ts +44 -2
  308. package/dist/pdf/wasm/pulpweaver4_pdf.js +191 -2
  309. package/dist/pdf/wasm/pulpweaver4_pdf_bg.wasm +0 -0
  310. package/dist/pdf/writer.d.ts +13 -1
  311. package/dist/pdf/writer.js +26 -1
  312. package/dist/pdf/writer.js.map +1 -1
  313. package/dist/plugin/define.d.ts +200 -15
  314. package/dist/plugin/define.js +124 -15
  315. package/dist/plugin/define.js.map +1 -1
  316. package/dist/plugin/failure.d.ts +1 -1
  317. package/dist/plugin/index.d.ts +5 -4
  318. package/dist/plugin/index.js +5 -4
  319. package/dist/plugin/index.js.map +1 -1
  320. package/dist/plugin/reference.d.ts +38 -0
  321. package/dist/plugin/reference.js +287 -0
  322. package/dist/plugin/reference.js.map +1 -0
  323. package/dist/plugin/register.d.ts +39 -7
  324. package/dist/plugin/register.js +83 -2
  325. package/dist/plugin/register.js.map +1 -1
  326. package/dist/preflight/index.d.ts +1 -1
  327. package/dist/preflight/index.js +1 -1
  328. package/dist/preflight/index.js.map +1 -1
  329. package/dist/preflight/pdfx.d.ts +35 -0
  330. package/dist/preflight/pdfx.js +33 -2
  331. package/dist/preflight/pdfx.js.map +1 -1
  332. package/dist/preflight/reader.d.ts +10 -3
  333. package/dist/preflight/reader.js +86 -5
  334. package/dist/preflight/reader.js.map +1 -1
  335. package/dist/print/impose.d.ts +66 -0
  336. package/dist/print/impose.js +331 -0
  337. package/dist/print/impose.js.map +1 -0
  338. package/dist/print/output.js +400 -50
  339. package/dist/print/output.js.map +1 -1
  340. package/dist/problem.js +4 -3
  341. package/dist/problem.js.map +1 -1
  342. package/dist/profile/index.d.ts +1 -0
  343. package/dist/profile/index.js +1 -0
  344. package/dist/profile/index.js.map +1 -1
  345. package/dist/profile/lint.d.ts +1 -1
  346. package/dist/profile/lint.js +29 -1
  347. package/dist/profile/lint.js.map +1 -1
  348. package/dist/profile/list-table.d.ts +51 -0
  349. package/dist/profile/list-table.js +137 -0
  350. package/dist/profile/list-table.js.map +1 -0
  351. package/dist/profile/metadata.js +3 -0
  352. package/dist/profile/metadata.js.map +1 -1
  353. package/dist/profile/profile.d.ts +3 -0
  354. package/dist/profile/profile.js +9 -1
  355. package/dist/profile/profile.js.map +1 -1
  356. package/dist/project.js +3 -0
  357. package/dist/project.js.map +1 -1
  358. package/dist/qpdf/index.d.ts +2 -0
  359. package/dist/qpdf/index.js +3 -0
  360. package/dist/qpdf/index.js.map +1 -0
  361. package/dist/qpdf/qpdf.d.ts +125 -0
  362. package/dist/qpdf/qpdf.js +205 -0
  363. package/dist/qpdf/qpdf.js.map +1 -0
  364. package/dist/qpdf/testing.d.ts +12 -0
  365. package/dist/qpdf/testing.js +9 -0
  366. package/dist/qpdf/testing.js.map +1 -0
  367. package/dist/qpdf/wasm/LICENSE-qpdf +202 -0
  368. package/dist/qpdf/wasm/LICENSE-zlib +22 -0
  369. package/dist/qpdf/wasm/NOTICE-qpdf.md +42 -0
  370. package/dist/qpdf/wasm/qpdf.wasm +0 -0
  371. package/dist/render/index.d.ts +3 -0
  372. package/dist/render/index.js +2 -0
  373. package/dist/render/index.js.map +1 -0
  374. package/dist/render/render.d.ts +98 -0
  375. package/dist/render/render.js +243 -0
  376. package/dist/render/render.js.map +1 -0
  377. package/dist/reproducible/clock.d.ts +4 -5
  378. package/dist/reproducible/clock.js +4 -5
  379. package/dist/reproducible/clock.js.map +1 -1
  380. package/dist/spike/spike-page.chromium.json +4 -4
  381. package/dist/style/colours.d.ts +7 -2
  382. package/dist/style/colours.js +24 -2
  383. package/dist/style/colours.js.map +1 -1
  384. package/dist/style/compile.js +1 -1
  385. package/dist/style/compile.js.map +1 -1
  386. package/dist/style/defaults.d.ts +9 -3
  387. package/dist/style/defaults.js +14 -2
  388. package/dist/style/defaults.js.map +1 -1
  389. package/dist/style/gcpm.d.ts +1 -1
  390. package/dist/style/gcpm.js +17 -5
  391. package/dist/style/gcpm.js.map +1 -1
  392. package/dist/style/properties.js +84 -0
  393. package/dist/style/properties.js.map +1 -1
  394. package/dist/test/book.d.ts +22 -2
  395. package/dist/test/book.js +35 -2
  396. package/dist/test/book.js.map +1 -1
  397. package/dist/test/build.d.ts +23 -0
  398. package/dist/test/build.js +86 -33
  399. package/dist/test/build.js.map +1 -1
  400. package/dist/test/layout.js +128 -19
  401. package/dist/test/layout.js.map +1 -1
  402. package/dist/test/limits.d.ts +8 -0
  403. package/dist/test/limits.js +9 -0
  404. package/dist/test/limits.js.map +1 -0
  405. package/dist/test/pipeline.d.ts +23 -0
  406. package/dist/test/pipeline.js.map +1 -1
  407. package/dist/test/render.d.ts +26 -3
  408. package/dist/test/render.js +151 -23
  409. package/dist/test/render.js.map +1 -1
  410. package/dist/test/runner.d.ts +6 -3
  411. package/dist/test/runner.js +172 -105
  412. package/dist/test/runner.js.map +1 -1
  413. package/dist/test/text.js +2 -2
  414. package/dist/test/text.js.map +1 -1
  415. package/dist/text/output.js +2 -2
  416. package/dist/text/output.js.map +1 -1
  417. package/dist/text/render.d.ts +4 -3
  418. package/dist/text/render.js +126 -4
  419. package/dist/text/render.js.map +1 -1
  420. package/dist/transform/index.d.ts +1 -1
  421. package/dist/transform/index.js +1 -1
  422. package/dist/transform/index.js.map +1 -1
  423. package/dist/transform/run.d.ts +2 -0
  424. package/dist/transform/run.js +32 -16
  425. package/dist/transform/run.js.map +1 -1
  426. package/dist/web/output.js +116 -10
  427. package/dist/web/output.js.map +1 -1
  428. package/dist/web/runtime/justify.js.txt +2 -2
  429. package/dist/web/site.d.ts +2 -0
  430. package/dist/web/site.js +8 -1
  431. package/dist/web/site.js.map +1 -1
  432. package/docs/README.md +6 -1
  433. package/docs/manual/chapters/front.dj +34 -0
  434. package/docs/manual/chapters/guides/citations.dj +426 -0
  435. package/docs/manual/chapters/guides/colour-and-prepress.dj +261 -0
  436. package/docs/manual/chapters/guides/editions.dj +329 -0
  437. package/docs/manual/chapters/guides/in-a-web-page.dj +143 -0
  438. package/docs/manual/chapters/guides/lines-and-pages.dj +681 -0
  439. package/docs/manual/chapters/guides/lint-rules.dj +355 -0
  440. package/docs/manual/chapters/guides/pdfs.dj +501 -0
  441. package/docs/manual/chapters/guides/plugins.dj +425 -0
  442. package/docs/manual/chapters/guides/testing.dj +264 -0
  443. package/docs/manual/chapters/guides/writing-in-djot.dj +537 -0
  444. package/docs/manual/chapters/start/for-latex-users.dj +256 -0
  445. package/docs/manual/chapters/start/getting-started.dj +167 -0
  446. package/docs/manual/chapters/start/your-first-book.dj +426 -0
  447. package/docs/manual/fonts/CrimsonPro-Italic-VF.ttf +0 -0
  448. package/docs/manual/fonts/CrimsonPro-VF.ttf +0 -0
  449. package/docs/manual/fonts/JetBrainsMono-Regular.otf +0 -0
  450. package/docs/manual/fonts/NotoSansSymbols2-Boxes.ttf +0 -0
  451. package/docs/manual/fonts/OFL.txt +95 -0
  452. package/docs/manual/pulpweaver4.toml +39 -0
  453. package/docs/manual/styles/manual.css +137 -0
  454. package/docs/reference/css-properties/index.md +9 -0
  455. package/docs/reference/css-properties/pw-expansion.md +31 -0
  456. package/docs/reference/css-properties/pw-flow-into.md +31 -0
  457. package/docs/reference/css-properties/pw-knockout.md +26 -0
  458. package/docs/reference/css-properties/pw-layer.md +24 -0
  459. package/docs/reference/css-properties/pw-page-breaking.md +30 -0
  460. package/docs/reference/css-properties/pw-page-duration.md +28 -0
  461. package/docs/reference/css-properties/pw-page-rotate.md +29 -0
  462. package/docs/reference/css-properties/pw-page-transition.md +29 -0
  463. package/docs/reference/css-properties/pw-protrusion.md +31 -0
  464. package/docs/reference/lint-rules/ibid-across-page.md +2 -2
  465. package/docs/reference/plugin-api/capabilities.md +2 -2
  466. package/docs/reference/plugin-api/claim-kind.md +1 -1
  467. package/docs/reference/plugin-api/combine-exceptions.md +19 -0
  468. package/docs/reference/plugin-api/element-break-context.md +34 -0
  469. package/docs/reference/plugin-api/element-break-item.md +24 -0
  470. package/docs/reference/plugin-api/element-breaker.md +24 -0
  471. package/docs/reference/plugin-api/flow-definition.md +30 -0
  472. package/docs/reference/plugin-api/generated-reference.md +32 -0
  473. package/docs/reference/plugin-api/index-definition.md +32 -0
  474. package/docs/reference/plugin-api/index-titles.md +18 -0
  475. package/docs/reference/plugin-api/index.md +27 -3
  476. package/docs/reference/plugin-api/insert-class-definition.md +46 -0
  477. package/docs/reference/plugin-api/insert-placement.md +22 -0
  478. package/docs/reference/plugin-api/insert-placements.md +18 -0
  479. package/docs/reference/plugin-api/layout-definition.md +9 -5
  480. package/docs/reference/plugin-api/layout-slot.md +6 -16
  481. package/docs/reference/plugin-api/lint-context.md +3 -1
  482. package/docs/reference/plugin-api/lint-definition.md +1 -1
  483. package/docs/reference/plugin-api/lint-edition.md +2 -0
  484. package/docs/reference/plugin-api/page-builder-event.md +22 -0
  485. package/docs/reference/plugin-api/page-builder-hook.md +7 -3
  486. package/docs/reference/plugin-api/page-builder-page-event.md +30 -0
  487. package/docs/reference/plugin-api/page-template-definition.md +34 -0
  488. package/docs/reference/plugin-api/page-template-region-definition.md +46 -0
  489. package/docs/reference/plugin-api/plugin-definition.md +5 -1
  490. package/docs/reference/plugin-api/plugin-reference-options.md +32 -0
  491. package/docs/reference/plugin-api/plugin-reference.md +22 -0
  492. package/docs/reference/plugin-api/plugin-registry.md +15 -5
  493. package/docs/reference/plugin-api/plugin-stage.md +1 -1
  494. package/docs/reference/plugin-api/plugin.md +9 -2
  495. package/docs/reference/plugin-api/reference-page.md +34 -0
  496. package/docs/reference/plugin-api/render-reference-page.md +18 -0
  497. package/docs/reference/plugin-api/renderers.md +1 -1
  498. package/docs/reference/pulpweaver4-toml/editions.md +239 -2
  499. package/docs/reference/pulpweaver4-toml/index.md +44 -1
  500. package/docs/reference/pulpweaver4-toml/inks.md +15 -4
  501. package/docs/reference/pulpweaver4-toml/lint.md +1 -1
  502. package/package.json +5 -1
@@ -0,0 +1,425 @@
1
+ ``` =meta
2
+ description = 'Extend pulpweaver4 with a plugin — claim a block, number it, render it to HTML and text, style it, keep it on one page, lint it and test it; break lines, process images and add pw commands — and load it from the project, npm or a URL.'
3
+ ```
4
+
5
+ {#plugins}
6
+ # Writing a plugin
7
+
8
+ Everything beyond the core is a plugin: a block of your own, a transform
9
+ that numbers or looks things up, a lint rule, a matcher for tests, an output
10
+ format. Where LaTeX has `\newcommand` and packages, pulpweaver4 has plugins,
11
+ written in JavaScript or TypeScript, with tests, and kept out of the source:
12
+ a chapter stays plain Djot that any tool can read.
13
+
14
+ {#a-plugin-is-a-module}
15
+ ## A plugin is a module
16
+
17
+ A plugin is an ES module whose default export says what it adds. This one
18
+ gives a book `::: note` blocks, numbered through the book, set apart in a
19
+ box that never breaks across pages:
20
+
21
+ {project=note file="plugins/note.js"}
22
+ ``` js
23
+ // plugins/note.js
24
+ function* walk(node) {
25
+ yield node
26
+ for (const child of node.children ?? []) yield* walk(child)
27
+ }
28
+ const isNote = (node) => node.type === 'pluginBlock' && node.name === 'note'
29
+
30
+ export default {
31
+ name: 'note',
32
+ api: 1,
33
+ description: 'Numbered notes, set apart from the text.',
34
+ url: import.meta.url,
35
+ options: {
36
+ type: 'object',
37
+ additionalProperties: false,
38
+ properties: { label: { type: 'string', description: 'The word before each number.' } },
39
+ },
40
+ blocks: {
41
+ note: { description: 'A note.', attributes: { kind: { type: 'string', enum: ['tip', 'warning'] } } },
42
+ },
43
+ transform: {
44
+ phase: 'number',
45
+ run(ast, ctx) {
46
+ let n = 0
47
+ for (const document of ast.documents) {
48
+ for (const node of walk(document)) {
49
+ if (isNote(node)) node.number = `${ctx.options.label ?? 'Note'} ${++n}`
50
+ }
51
+ }
52
+ },
53
+ },
54
+ render: {
55
+ note: {
56
+ html: (node, h, ctx) =>
57
+ h('aside.note', { 'data-kind': node.attributes?.kind ?? 'tip' }, [
58
+ h('b.note-label', node.number),
59
+ ...ctx.render(node.children),
60
+ ]),
61
+ text: (node, render) => `[${node.number}] ${render.children(node)}`,
62
+ },
63
+ },
64
+ styles: ['./note.css'],
65
+ layout: { boxes: ['aside.note'] },
66
+ }
67
+ ```
68
+
69
+ Its stylesheet is a file beside it, `./note.css`, read from beside the module
70
+ (`url`, its `import.meta.url`, says where that is when a test imports it):
71
+
72
+ {project=note file="plugins/note.css"}
73
+ ``` css
74
+ /* plugins/note.css */
75
+ .note { border: 0.5pt solid; padding: 6pt 9pt; margin: 9pt 0; }
76
+ .note-label { display: block; }
77
+ ```
78
+
79
+ Name it in `pulpweaver4.toml`, with its options:
80
+
81
+ {project=note}
82
+ ``` toml
83
+ [plugins]
84
+ "./plugins/note.js" = { label = "Aside" }
85
+ ```
86
+
87
+ and use it in a chapter:
88
+
89
+ {project=note}
90
+ ``` djot
91
+ {kind=warning}
92
+ ::: note
93
+ Print the letter edition at actual size.
94
+ :::
95
+ ```
96
+
97
+ `pw build` puts “Aside 1” over the note, in a box, in every PDF; on the web
98
+ the same `<aside>`; and in the text edition “\[Aside 1\] Print the letter
99
+ edition at actual size.”
100
+
101
+ {#loading-plugins}
102
+ ## Loading plugins
103
+
104
+ `[plugins]` names each plugin with a table of its options:
105
+
106
+ - *A file in the project*: the key is its path, quoted, starting `./`:
107
+ `"./plugins/note.js" = {}`. It is a JavaScript module, imported as a
108
+ browser imports one from a server of the project’s folder: it can import
109
+ modules beside it (`import { count } from './count.js'`), and
110
+ `pulpweaver4` (`import { definePlugin } from 'pulpweaver4'`), which is
111
+ the core of the `pw` running it. That holds in every `pw`: `pw build`,
112
+ `pw lint`, `pw test` and the plugin’s own commands. A plugin to share
113
+ between books is better as a package.
114
+ - *An npm package*, installed in the project, by its name:
115
+ `pulpweaver4-questions = {}`. `pw add pulpweaver4-questions` does both,
116
+ `npm install` in the project and the line in `[plugins]`. A
117
+ package can import `pulpweaver4` (as a peer dependency), import its own
118
+ files, fetch the fonts and data it ships by
119
+ `new URL('../fonts/x.otf', import.meta.url)`, as it would unbundled, and
120
+ be written in TypeScript.
121
+ - *A URL*, `"https://…/plugin.js" = {}`, which `pw build` and `pw lint`
122
+ fetch.
123
+
124
+ The browser app has the official plugins built in, `pulpweaver4-epub`,
125
+ `pulpweaver4-rst` and `pulpweaver4-scripture`, and loads a plugin in the
126
+ project or at a URL as `pw build` does; another npm package, which the
127
+ page can’t install, is an error there that says so. `pw dev` loads a
128
+ project’s plugins as `pw build` does, from its `node_modules`.
129
+
130
+ The options are checked against the plugin’s `options` schema, a subset of
131
+ JSON Schema, so a mistake, `label = 3` say, is an error at its place in
132
+ `pulpweaver4.toml`:
133
+
134
+ {.untested}
135
+ ``` text
136
+ pulpweaver4.toml:26:33: error: plugins."./plugins/note.js".label must be a string, not 3 [wrong-type]
137
+ |
138
+ 24 |
139
+ 25 | [plugins]
140
+ 26 | "./plugins/note.js" = { label = 3 }
141
+ | ^
142
+ ```
143
+
144
+ A plugin without an `options` schema takes no options.
145
+
146
+ {#what-a-plugin-can-add}
147
+ ## What a plugin can add
148
+
149
+ | Key | Adds | Works now |
150
+ |----|----|----|
151
+ | `blocks`, `inlines` | `::: name` blocks and `[text]{.name}` spans it owns, with the attributes they take, which the build checks | Yes |
152
+ | `transform` | A function that changes the document in a phase: `resolve`, `number`, `cite`, `index`, `link` or `finalize` | Yes |
153
+ | `render` | HTML for its nodes (`html`, or a function), and their text-edition form (`text`) | Yes |
154
+ | `styles` | CSS, a path beside the module or `{ css: '…' }`, in a cascade layer of its own, `pw.plugins.<name>`, applying only to what it renders | Yes |
155
+ | `layout` | `boxes`: selectors of elements kept whole, never broken across pages; `penalties`: a penalty before or after them | Yes |
156
+ | `lint` | Lint rules and presets, its `recommended` on wherever the core’s is: see [Lint rules for your press](#writing-your-own) | Yes |
157
+ | `matchers` | `expect` matchers for tests | In a test’s own build: [below](#testing-a-plugin) |
158
+ | `read` | A reader for another source format, by file extension | Yes |
159
+ | `output` | An output format, for an edition’s `output` | Yes |
160
+ | `layout`’s `lineBreakers` | Line breakers of your own, by element or language: [below](#line-breakers) | Yes |
161
+ | `layout`’s `resolvers` | What a print edition fills in from its pages, as page references and indexes are: each is given the pages and the book’s HTML, changes the HTML, and returns the elements it changed, the book laid out again until none change. A link it adds is tagged as one in a tagged PDF | Yes |
162
+ | `assets` | Processing the project’s images and fonts, by file type: [below](#processing-images-and-fonts) | Yes |
163
+ | `commands` | `pw <command>`: [below](#commands) | Yes |
164
+ | `layout`’s `inserts`, `pageTemplates`, `flows`, `pageBuilder` | New kinds of inserts, page templates, flows, page-builder hooks | Not yet: accepted, not used ([#138](https://gitlab.com/inkylabs/pulpweaver4/-/issues/138)) |
165
+
166
+ A misspelled key, or a stage written wrong, is an error naming the
167
+ plugin. `api: 1` is the plugin API’s version; a plugin for another version
168
+ is refused.
169
+
170
+ {#plugins-the-document}
171
+ ### The document
172
+
173
+ A transform gets the book as its documents, `ast.documents`, each a tree of
174
+ nodes with a `type` (`section`, `heading`, `paragraph`, `text`...), `children`,
175
+ `attributes` and a `position` in the source. A block a plugin claims is a
176
+ `pluginBlock` node whose `name` is the block’s; an inline, a
177
+ `pluginInline`. `ctx.options` holds the plugin’s options, and
178
+ `ctx.error(node, code, message, fix)` and `ctx.warn(…)` report a problem
179
+ at a node, with a code of your own and, if you like, its fix.
180
+
181
+ {#rendering}
182
+ ### Rendering
183
+
184
+ An `html` renderer gets the node, `h` (hastscript’s, so
185
+ `h('aside.note', { id: 'x' }, children)`) and `ctx`, whose
186
+ `ctx.render(children)` renders the node’s children and whose `ctx.edition`
187
+ says which edition it is for. A `text` renderer returns a string; its
188
+ second argument’s `children(node)` renders the children as text. A node with
189
+ no text renderer is written as its children.
190
+
191
+ {#line-breakers-assets-and-commands}
192
+ ## Line breakers, assets and commands
193
+
194
+ These three work beyond the document: on the engine’s lines, on the
195
+ project’s files, and on the command line. A press’s plugin might have all
196
+ three, as this one does, with a module of its own beside it:
197
+
198
+ {project=press file="plugins/words.js"}
199
+ ``` js
200
+ // plugins/words.js
201
+ /** The number of words in a text. */
202
+ export const countWords = (text) => text.split(/\s+/).filter(Boolean).length
203
+ ```
204
+
205
+ {#line-breakers}
206
+ ### Line breakers
207
+
208
+ A line breaker sets a paragraph’s lines in place of the core’s Knuth--Plass,
209
+ for the paragraphs a selector matches (`elements`) or those in a language
210
+ (`languages`, `ja` for `ja-JP` too), as a press might for a script the core
211
+ doesn’t break well. It is given the paragraph as the engine’s list of
212
+ boxes, glue and penalties and the line breaking options, and returns the
213
+ lines; `setLines`, from `pulpweaver4`, packs the breaks it chooses. This one
214
+ breaks after every word:
215
+
216
+ {project=press file="plugins/press.js"}
217
+ ``` js
218
+ // plugins/press.js
219
+ import { setLines } from 'pulpweaver4'
220
+ import { countWords } from './words.js'
221
+
222
+ // Breaks after every word: at each glue that follows a box.
223
+ function wordALine(items, options) {
224
+ const breaks = items.flatMap((item, k) => (item.type === 'glue' && items[k - 1]?.type === 'box' ? [k] : []))
225
+ return setLines(items, breaks, options)
226
+ }
227
+
228
+ export default {
229
+ name: 'press',
230
+ api: 1,
231
+ layout: { lineBreakers: { elements: { 'p.word-a-line': wordALine } } },
232
+ assets: {
233
+ svg: {
234
+ description: 'Takes out comments.',
235
+ process: (data) => new TextEncoder().encode(new TextDecoder().decode(data).replace(/<!--[^]*?-->/g, '')),
236
+ },
237
+ },
238
+ commands: {
239
+ words: {
240
+ description: 'Count the words in files of the project.',
241
+ usage: '<file>…',
242
+ async run(args, { fs, out }) {
243
+ if (!args.length || !fs) {
244
+ out('pw words: name a file of the project')
245
+ return 2
246
+ }
247
+ for (const file of args) out(`${file}: ${countWords(await fs.readText(file))} words`)
248
+ },
249
+ },
250
+ },
251
+ }
252
+ ```
253
+
254
+ {project=press}
255
+ ``` djot
256
+ {.word-a-line}
257
+ One word a line.
258
+ ```
259
+
260
+ In print, the paragraph is four lines, “One”, “word”, “a”, “line.”. Two
261
+ breakers claiming one paragraph is an error, and so is one that throws: the
262
+ core breaks that paragraph instead. `--pw-line-breaking: browser` still
263
+ gives a paragraph the browser’s lines.
264
+
265
+ {#processing-images-and-fonts}
266
+ ### Processing images and fonts
267
+
268
+ `assets` processes the project’s files of a type, by extension, for each
269
+ edition: the images print and the web edition use, and the fonts. The
270
+ plugin above takes the comments out of SVGs. Each file is processed once
271
+ per edition, whatever its name or however often the book uses it, and a
272
+ processor that throws leaves the file as it was, with an error naming the
273
+ plugin.
274
+
275
+ {project=press file="images/box.svg"}
276
+ ``` svg
277
+ <svg xmlns="http://www.w3.org/2000/svg" width="120" height="80" viewBox="0 0 120 80">
278
+ <!-- Drawn for the guide. -->
279
+ <rect x="10" y="10" width="100" height="60" fill="#3b5bdb"/>
280
+ </svg>
281
+ ```
282
+
283
+ {project=press}
284
+ ``` djot
285
+ ![A blue box](images/box.svg)
286
+ ```
287
+
288
+ {project=press}
289
+ ``` toml
290
+ [plugins]
291
+ "./plugins/press.js" = {}
292
+ ```
293
+
294
+ {#commands}
295
+ ### Commands
296
+
297
+ `commands` adds commands to `pw`, run in the project’s folder: `run` gets
298
+ the command’s arguments and a context with the project’s files (`fs`) and
299
+ `out`, to print a line, and returns the exit status. The plugin above adds
300
+ `pw words`:
301
+
302
+ {project=press}
303
+ ``` sh
304
+ pw words chapters/01-beginning.dj
305
+ ```
306
+
307
+ {project=press .output}
308
+ ``` text
309
+ chapters/01-beginning.dj: 100 words
310
+ ```
311
+
312
+ `pw --help`, in the project, lists it after pw’s own commands:
313
+
314
+ {project=press output="pw --help"}
315
+ ``` text
316
+ ...
317
+ The project's plugins' commands:
318
+ pw words <file>…
319
+ Count the words in files of the project. (press)
320
+ ...
321
+ ```
322
+
323
+ A plugin can’t take a name `pw` has, such as `build`; a command that throws
324
+ is an error naming the plugin, with exit status 1.
325
+
326
+ {#plugins-are-a-set}
327
+ ## Plugins are a set
328
+
329
+ In LaTeX, swapping two `\usepackage` lines can change a book. In pulpweaver4,
330
+ a project’s plugins are a set, and their order in `pulpweaver4.toml` changes
331
+ nothing:
332
+
333
+ - *Each name has one owner.* A block, an inline, a renderer, a reader, an
334
+ output or a matcher belongs to one plugin; a second plugin claiming it is
335
+ an error naming both. Lint rules are named `<plugin>/<rule>`, so they
336
+ can’t collide.
337
+ - *Transforms in a phase all see the document as the phase before left
338
+ it*, and each may change only the nodes it owns (and add nodes, and its
339
+ own attributes). A plugin that needs another’s result in the same phase
340
+ says so: `after: ['pulpweaver4-scripture']`.
341
+ - *Each plugin’s CSS has its own layer*, scoped to what it renders.
342
+
343
+ {#builds-you-can-repeat}
344
+ ## Builds you can repeat
345
+
346
+ A plugin runs without a clock: `Date` and `performance.now()` give the
347
+ book’s date (`date`, or `SOURCE_DATE_EPOCH`), and `Math.random()` is
348
+ seeded by the plugin and its stage, so the same book always builds the same. A
349
+ plugin that throws is named in the error, with its stage and the node it
350
+ was working on; its output for that node is left out, and the build goes on.
351
+
352
+ {#testing-a-plugin}
353
+ ## Testing a plugin
354
+
355
+ `runPlugin(plugin, djot)` builds a little Djot with the plugin and returns
356
+ the [book](#testing), with the plugin’s matchers on `expect`. It
357
+ reads the stylesheets the plugin names by path beside its `url`, which is
358
+ why the note plugin gives `url: import.meta.url`; without it, the build
359
+ says to give it:
360
+
361
+ {project=note file="tests/note.test.ts"}
362
+ ``` ts
363
+ // tests/note.test.ts
364
+ import { runPlugin } from 'pulpweaver4/test'
365
+ import note from '../plugins/note.js'
366
+
367
+ test('notes are numbered through the book', async () => {
368
+ const book = await runPlugin(note, '::: note\nOne.\n:::\n\n::: note\nTwo.\n:::\n')
369
+ const labels = [...book.html.querySelectorAll('.note-label')].map((b) => b.textContent)
370
+ expect(labels).toEqual(['Note 1', 'Note 2'])
371
+ })
372
+ ```
373
+
374
+ `build()` builds the whole project as `pulpweaver4.toml` sets it out, with
375
+ its plugins, their options and their matchers:
376
+
377
+ {project=note file="tests/notes.test.ts"}
378
+ ``` ts
379
+ import { build } from 'pulpweaver4/test'
380
+
381
+ const book = await build({ edition: 'paperback' })
382
+
383
+ test('the notes keep to one page', () => {
384
+ for (const note of book.ast.select('pluginBlock.note')) {
385
+ expect(book.pages.of(note)).toFitOnOnePage()
386
+ }
387
+ })
388
+ ```
389
+
390
+ `pw test` runs both files, with the starter’s:
391
+
392
+ {project=note}
393
+ ``` sh
394
+ pw test
395
+ ```
396
+
397
+ {project=note .output}
398
+ ``` text
399
+ ...
400
+ Test Files 3 passed (3)
401
+ Tests 5 passed (5)
402
+ ...
403
+ ```
404
+
405
+ {#publishing-a-plugin}
406
+ ## Publishing a plugin
407
+
408
+ A plugin for others is an npm package whose main module is the plugin, with
409
+ `pulpweaver4` as a peer dependency (`npm install --save-peer pulpweaver4`). Name it `pulpweaver4-<name>` so it is
410
+ easy to find. The core’s repository has a whole one, written as a press
411
+ would write it, with a block, an inline, a transform, renderers, styles,
412
+ layout, a lint rule and a matcher:
413
+ [`pulpweaver4-questions`](https://gitlab.com/inkylabs/pulpweaver4/-/tree/master/tests/plugins/pulpweaver4-questions).
414
+
415
+ {#plugins-not-yet}
416
+ ## Not yet
417
+
418
+ - *Page-builder hooks, page templates, flows, insert classes* of a
419
+ plugin’s own
420
+ ([#138](https://gitlab.com/inkylabs/pulpweaver4/-/issues/138)): plugins
421
+ can declare them, but the core doesn’t use them yet. A stylesheet’s
422
+ flows and page templates work ([Flows and page templates](#flows)).
423
+ - *A plugin declaring the capabilities it needs* (`needs: ['fs']`), so the
424
+ browser app can run it in a sandbox
425
+ ([#71](https://gitlab.com/inkylabs/pulpweaver4/-/issues/71)).
@@ -0,0 +1,264 @@
1
+ ``` =meta
2
+ description = 'Tests for a book with pw test — facts about its pages, lines, structure and citations, in TypeScript with describe, test and expect, and snapshots of pages, HTML and text.'
3
+ ```
4
+
5
+ {#testing}
6
+ # Testing your book
7
+
8
+ A book has facts worth checking every time it is built: each chapter opens
9
+ on a right-hand page, no line runs into the margin, the title page looks as
10
+ it was approved, the introduction cites the source it should. pulpweaver4’s
11
+ tests check them, as a programmer’s tests check code. They are TypeScript
12
+ files with the `describe`, `test` and `expect` you may know from
13
+ [Vitest](https://vitest.dev) or Jest, and they can see everything the build
14
+ makes: the document’s structure, its HTML and its laid-out pages.
15
+
16
+ Tests check particular facts about this book. To hold every book to a
17
+ policy (no widows, no straight quotes), use [lint
18
+ rules](#lint-rules) instead.
19
+
20
+ {#running-the-tests}
21
+ ## Running the tests
22
+
23
+ `pw new` makes `tests/book.test.ts`. `pw test` runs every
24
+ `tests/**/*.test.ts` in headless Chromium, the same browser `pw build` lays
25
+ pages out in:
26
+
27
+ {project=tests}
28
+ ``` sh
29
+ pw test
30
+ ```
31
+
32
+ {project=tests .output}
33
+ ``` text
34
+ ...
35
+ Test Files 1 passed (1)
36
+ Tests 3 passed (3)
37
+ ...
38
+ ```
39
+
40
+ The tests need nothing installed in the project: `pulpweaver4` and
41
+ `pulpweaver4/test` are pw’s own, and `describe`, `test` and `expect` are
42
+ there without importing them. Starting the browser and building the book
43
+ take some seconds; the tests themselves are quick. The browser app and
44
+ `pw dev` run the same files in the page, with their *Run tests* button
45
+ ([Watching as you write](#watching-as-you-write)).
46
+
47
+ To run some of the tests, give words from their files’ paths, as Vitest’s
48
+ filters are: `pw test chapters` runs `tests/chapters.test.ts`. A first
49
+ argument that is a project’s folder, one with `pulpweaver4.toml`, is the
50
+ project to test: `pw test my-book chapters`.
51
+
52
+ {project=tests}
53
+ ``` sh
54
+ pw test book
55
+ ```
56
+
57
+ {project=tests .output}
58
+ ``` text
59
+ ...
60
+ Test Files 1 passed (1)
61
+ Tests 3 passed (3)
62
+ ...
63
+ ```
64
+
65
+ {#building-the-book-in-a-test}
66
+ ## Building the book in a test
67
+
68
+ `build()` builds the project as `pw build` does, without writing files,
69
+ and returns the `Book`:
70
+
71
+ {project=tests file="tests/chapters.test.ts"}
72
+ ``` ts
73
+ import { build } from 'pulpweaver4/test'
74
+
75
+ const book = await build({ edition: 'paperback' })
76
+
77
+ test('each chapter opens on a right-hand page', () => {
78
+ for (const chapter of book.ast.select('document > section')) {
79
+ expect(book.pages.of(chapter).first).toBeRecto()
80
+ }
81
+ })
82
+ ```
83
+
84
+ - *`edition`* is an edition’s name from `pulpweaver4.toml`. Without it,
85
+ `build()` builds the first PDF edition. A web edition has no pages, so
86
+ tests of pages need a print edition.
87
+ - *The project’s plugins* are loaded as `pw build` loads them, with their
88
+ options, so their blocks render and their matchers are on `expect`.
89
+ - *A problem in the book*, an unknown label say, makes `build()` throw,
90
+ with every problem listed as `pw build` lists them. `build({ edition: 'paperback', errors: 'keep' })` returns the book anyway, with its problems
91
+ in `book.problems`.
92
+ - *Lint rules:* `build()` runs the edition’s [lint rules](#lint-rules), as
93
+ `pw build` does. Their problems are in `book.problems`, with the rule’s
94
+ name as `rule`, and an error among them makes `build()` throw too ([Lint
95
+ in a test](#lint-in-a-test)). `build({ lint: false })` leaves them out.
96
+ - *Build once, at the top of the file*, and share the book between the
97
+ file’s tests: a build takes a moment.
98
+
99
+ {#what-a-test-can-see}
100
+ ## What a test can see
101
+
102
+ {#testing-the-document}
103
+ ### The document
104
+
105
+ `book.ast.select(selector)` finds nodes of the document, in order, with a
106
+ CSS-like selector over node types, classes and labels:
107
+
108
+ | Selector | Finds |
109
+ |----|----|
110
+ | `document > section` | Each chapter: a file’s top-level sections |
111
+ | `section#writing` | The section labelled `writing` |
112
+ | `section#writing > heading` | Its heading |
113
+ | `paragraph`, `blockQuote`, `table`, `footnote`, `citation` | Nodes of a type |
114
+ | `div.note` | `::: note` divs |
115
+ | `section paragraph` | Paragraphs anywhere in a section |
116
+ | `[lang]`, `[lang=de]` | Nodes with an attribute, or with that value |
117
+
118
+ The selectors are a part of CSS’s: types, classes (`.note`), labels
119
+ (`#intro`), attributes, the descendant and child (`>`) combinators, and
120
+ lists (`a, b`), but no pseudo-classes, and neither `+` nor `~`. A second
121
+ argument searches within a node: `book.ast.select('.note', chapter)`.
122
+
123
+ {#the-pages}
124
+ ### The pages
125
+
126
+ `book.pages` are the laid-out pages:
127
+
128
+ - *`book.pages.at(3)`* is page 3, counting from 1; `at(-1)` is the last.
129
+ - *`book.pages.of(x)`* is the pages something is on: a node from
130
+ `ast.select`, a CSS selector over the HTML (`'blockquote'`), or an
131
+ element. Its `first` and `last` are pages, and `length` how many.
132
+ - *`book.pages.length`*, and `for (const page of book.pages)`.
133
+
134
+ Each page has its `number`, its `side` (`'recto'` or `'verso'`), its
135
+ `spread` (the pages that face each other), whether it is `blank`, and its
136
+ `lines`. Each line has its `text`, its `width` and `measure`, its adjustment
137
+ `ratio` and `badness` as TeX computes them, whether it is `overfull`, and
138
+ whether it ends `hyphenated`:
139
+
140
+ {project=tests file="tests/chapters.test.ts"}
141
+ ``` ts
142
+ test('the paperback fits in 64 pages', () => {
143
+ expect(book.pages.length).toBeLessThanOrEqual(64)
144
+ })
145
+
146
+ test('no page ends with a hyphen', () => {
147
+ for (const page of book.pages) {
148
+ expect(page.lines.at(-1)?.hyphenated ?? false).toBe(false)
149
+ }
150
+ })
151
+ ```
152
+
153
+ {#the-index}
154
+ ### The index
155
+
156
+ `book.index('subject')` is the subject index, from the book’s [index
157
+ terms](#index-terms). Its `entry(term)`, a term
158
+ written as in the Djot, with `!` between levels, has the `pages` it is on
159
+ (none, if the book has no such term), its page `ranges`, and its `see` and
160
+ `seeAlso` references. With a term in the second chapter:
161
+
162
+ {project=tests}
163
+ ``` djot
164
+ [Parachurch ministries amass sizable revenues]{index="Cru; parachurch!revenues"},
165
+ and [tithing]{.xi} is older still.
166
+ ```
167
+
168
+ {project=tests file="tests/chapters.test.ts"}
169
+ ``` ts
170
+ test('the index sends tithing to the second chapter', () => {
171
+ const tithing = book.index('subject').entry('tithing')
172
+ expect(tithing.pages).toEqual([book.pages.of('#writing').first])
173
+ })
174
+ ```
175
+
176
+ {#the-rest}
177
+ ### The rest
178
+
179
+ `book.html` is the book’s HTML before layout; `await book.text()` is the
180
+ book as the text edition writes it; `book.problems` is what the build
181
+ warned of.
182
+
183
+ {#matchers-for-books}
184
+ ## Matchers for books
185
+
186
+ Besides Vitest’s own matchers, `expect` has these:
187
+
188
+ | Matcher | Checks |
189
+ |----|----|
190
+ | `expect(page).toBeRecto()` | A page is a right-hand page |
191
+ | `expect(book.pages.of(x)).toFitOnOnePage()` | Something isn’t broken across pages |
192
+ | `expect(book.pages.of(x)).toStartPage()` | Something begins at the top of a page |
193
+ | `expect(book).toHaveNoOverfullLines()` | No line is wider than its measure, in the book, a page or `pages.of(x)` |
194
+ | `expect(book).toCite('bauckham')` | The book, or its pages from `pages.of(x)`, cites a source |
195
+ | `await expect(page).toMatchPageSnapshot()` | A page looks as it did, pixel for pixel |
196
+ | `await expect(book).toMatchHtmlSnapshot()` | The HTML is as it was |
197
+ | `await expect(book).toMatchTextSnapshot()` | The text edition is as it was |
198
+
199
+ A failure says what it found:
200
+
201
+ {project=failing file="tests/book.test.ts" .replace}
202
+ ``` ts
203
+ import { build } from 'pulpweaver4/test'
204
+
205
+ const book = await build({ edition: 'paperback' })
206
+
207
+ test('page 2 is a recto', () => {
208
+ expect(book.pages.at(2)).toBeRecto()
209
+ })
210
+
211
+ test('the quotation starts a page', () => {
212
+ expect(book.pages.of('blockquote')).toStartPage()
213
+ })
214
+ ```
215
+
216
+ {project=failing}
217
+ ``` sh
218
+ pw test
219
+ ```
220
+
221
+ {project=failing .output}
222
+ ``` text
223
+ ...
224
+ Error: expected page 2 to be a recto, but it is a verso
225
+ ...
226
+ Error: expected "blockquote" to start a page, but it begins partway down page 3
227
+ ...
228
+ Test Files 1 failed (1)
229
+ Tests 2 failed (2)
230
+ ...
231
+ ```
232
+
233
+ {#snapshots}
234
+ ## Snapshots
235
+
236
+ A snapshot matcher compares what the book makes with what it made before,
237
+ kept in `tests/__snapshots__/`, beside the test, one file per snapshot: a
238
+ PNG of a page, HTML or text. The first run writes them; look at them, and
239
+ commit them. After that, a page that changes fails its test, and a page
240
+ whose snapshot doesn’t match gets an `.actual.png` beside it to compare.
241
+
242
+ {project=tests file="tests/chapters.test.ts"}
243
+ ``` ts
244
+ test('the title page is as approved', async () => {
245
+ await expect(book.pages.at(1)).toMatchPageSnapshot()
246
+ })
247
+ ```
248
+
249
+ When a change is meant, `pw test --update` writes the snapshots anew. In CI
250
+ (with `CI` set), a missing snapshot fails instead of being written, so
251
+ write them before you commit:
252
+
253
+ {project=tests}
254
+ ``` sh
255
+ pw test --update
256
+ ```
257
+
258
+ {project=tests .output}
259
+ ``` text
260
+ ...
261
+ Test Files 2 passed (2)
262
+ Tests 8 passed (8)
263
+ ...
264
+ ```