pulpweaver4 0.0.0-stage → 0.0.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast/djot.d.ts +124 -0
- package/dist/ast/djot.js +464 -0
- package/dist/ast/djot.js.map +1 -0
- package/dist/ast/index.d.ts +10 -0
- package/dist/ast/index.js +11 -0
- package/dist/ast/index.js.map +1 -0
- package/dist/ast/locator.d.ts +27 -0
- package/dist/ast/locator.js +77 -0
- package/dist/ast/locator.js.map +1 -0
- package/dist/ast/nodes.d.ts +543 -0
- package/dist/ast/nodes.js +56 -0
- package/dist/ast/nodes.js.map +1 -0
- package/dist/ast/position.d.ts +88 -0
- package/dist/ast/position.js +98 -0
- package/dist/ast/position.js.map +1 -0
- package/dist/ast/traverse.d.ts +12 -0
- package/dist/ast/traverse.js +37 -0
- package/dist/ast/traverse.js.map +1 -0
- package/dist/bibliography/biblatex.d.ts +13 -0
- package/dist/bibliography/biblatex.js +849 -0
- package/dist/bibliography/biblatex.js.map +1 -0
- package/dist/bibliography/bibtex.d.ts +39 -0
- package/dist/bibliography/bibtex.js +259 -0
- package/dist/bibliography/bibtex.js.map +1 -0
- package/dist/bibliography/csl.d.ts +9 -0
- package/dist/bibliography/csl.js +241 -0
- package/dist/bibliography/csl.js.map +1 -0
- package/dist/bibliography/dates.d.ts +33 -0
- package/dist/bibliography/dates.js +223 -0
- package/dist/bibliography/dates.js.map +1 -0
- package/dist/bibliography/index.d.ts +8 -0
- package/dist/bibliography/index.js +9 -0
- package/dist/bibliography/index.js.map +1 -0
- package/dist/bibliography/item.d.ts +142 -0
- package/dist/bibliography/item.js +181 -0
- package/dist/bibliography/item.js.map +1 -0
- package/dist/bibliography/latex.d.ts +21 -0
- package/dist/bibliography/latex.js +586 -0
- package/dist/bibliography/latex.js.map +1 -0
- package/dist/bibliography/names.d.ts +23 -0
- package/dist/bibliography/names.js +244 -0
- package/dist/bibliography/names.js.map +1 -0
- package/dist/bibliography/read.d.ts +24 -0
- package/dist/bibliography/read.js +50 -0
- package/dist/bibliography/read.js.map +1 -0
- package/dist/citations/book.d.ts +93 -0
- package/dist/citations/book.js +217 -0
- package/dist/citations/book.js.map +1 -0
- package/dist/citations/collect.d.ts +56 -0
- package/dist/citations/collect.js +129 -0
- package/dist/citations/collect.js.map +1 -0
- package/dist/citations/hast.d.ts +12 -0
- package/dist/citations/hast.js +49 -0
- package/dist/citations/hast.js.map +1 -0
- package/dist/citations/index.d.ts +14 -0
- package/dist/citations/index.js +15 -0
- package/dist/citations/index.js.map +1 -0
- package/dist/citations/lint.d.ts +70 -0
- package/dist/citations/lint.js +92 -0
- package/dist/citations/lint.js.map +1 -0
- package/dist/citations/notes.d.ts +11 -0
- package/dist/citations/notes.js +163 -0
- package/dist/citations/notes.js.map +1 -0
- package/dist/citations/positions.d.ts +34 -0
- package/dist/citations/positions.js +90 -0
- package/dist/citations/positions.js.map +1 -0
- package/dist/citations/project.d.ts +7 -0
- package/dist/citations/project.js +24 -0
- package/dist/citations/project.js.map +1 -0
- package/dist/colour/cmyk.d.ts +71 -0
- package/dist/colour/cmyk.js +210 -0
- package/dist/colour/cmyk.js.map +1 -0
- package/dist/colour/images.d.ts +36 -0
- package/dist/colour/images.js +106 -0
- package/dist/colour/images.js.map +1 -0
- package/dist/colour/index.d.ts +7 -0
- package/dist/colour/index.js +8 -0
- package/dist/colour/index.js.map +1 -0
- package/dist/colour/ink-limit.d.ts +68 -0
- package/dist/colour/ink-limit.js +109 -0
- package/dist/colour/ink-limit.js.map +1 -0
- package/dist/colour/intents.d.ts +145 -0
- package/dist/colour/intents.js +193 -0
- package/dist/colour/intents.js.map +1 -0
- package/dist/colour/lcms.d.ts +79 -0
- package/dist/colour/lcms.js +229 -0
- package/dist/colour/lcms.js.map +1 -0
- package/dist/colour/previews.d.ts +49 -0
- package/dist/colour/previews.js +116 -0
- package/dist/colour/previews.js.map +1 -0
- package/dist/colour/wasm/LICENSE-lcms2 +22 -0
- package/dist/colour/wasm/lcms2.wasm +0 -0
- package/dist/config/config.d.ts +114 -0
- package/dist/config/config.js +309 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/index.js +7 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/page.d.ts +42 -0
- package/dist/config/page.js +95 -0
- package/dist/config/page.js.map +1 -0
- package/dist/config/project-schema.d.ts +23 -0
- package/dist/config/project-schema.js +223 -0
- package/dist/config/project-schema.js.map +1 -0
- package/dist/config/schema.d.ts +68 -0
- package/dist/config/schema.js +333 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/toml.d.ts +54 -0
- package/dist/config/toml.js +238 -0
- package/dist/config/toml.js.map +1 -0
- package/dist/contents/index.d.ts +8 -0
- package/dist/contents/index.js +9 -0
- package/dist/contents/index.js.map +1 -0
- package/dist/contents/transform.d.ts +64 -0
- package/dist/contents/transform.js +149 -0
- package/dist/contents/transform.js.map +1 -0
- package/dist/csl/affix.d.ts +16 -0
- package/dist/csl/affix.js +74 -0
- package/dist/csl/affix.js.map +1 -0
- package/dist/csl/data/chicago-author-date.d.ts +2 -0
- package/dist/csl/data/chicago-author-date.js +3 -0
- package/dist/csl/data/chicago-author-date.js.map +1 -0
- package/dist/csl/data/chicago-notes-bibliography.d.ts +2 -0
- package/dist/csl/data/chicago-notes-bibliography.js +3 -0
- package/dist/csl/data/chicago-notes-bibliography.js.map +1 -0
- package/dist/csl/data/locales-en-GB.d.ts +2 -0
- package/dist/csl/data/locales-en-GB.js +3 -0
- package/dist/csl/data/locales-en-GB.js.map +1 -0
- package/dist/csl/data/locales-en-US.d.ts +2 -0
- package/dist/csl/data/locales-en-US.js +3 -0
- package/dist/csl/data/locales-en-US.js.map +1 -0
- package/dist/csl/dates.d.ts +30 -0
- package/dist/csl/dates.js +223 -0
- package/dist/csl/dates.js.map +1 -0
- package/dist/csl/format.d.ts +29 -0
- package/dist/csl/format.js +157 -0
- package/dist/csl/format.js.map +1 -0
- package/dist/csl/index.d.ts +26 -0
- package/dist/csl/index.js +16 -0
- package/dist/csl/index.js.map +1 -0
- package/dist/csl/ir.d.ts +103 -0
- package/dist/csl/ir.js +549 -0
- package/dist/csl/ir.js.map +1 -0
- package/dist/csl/load.d.ts +98 -0
- package/dist/csl/load.js +163 -0
- package/dist/csl/load.js.map +1 -0
- package/dist/csl/locale.d.ts +90 -0
- package/dist/csl/locale.js +251 -0
- package/dist/csl/locale.js.map +1 -0
- package/dist/csl/names.d.ts +41 -0
- package/dist/csl/names.js +203 -0
- package/dist/csl/names.js.map +1 -0
- package/dist/csl/numbers.d.ts +48 -0
- package/dist/csl/numbers.js +170 -0
- package/dist/csl/numbers.js.map +1 -0
- package/dist/csl/processor.d.ts +179 -0
- package/dist/csl/processor.js +765 -0
- package/dist/csl/processor.js.map +1 -0
- package/dist/csl/project.d.ts +21 -0
- package/dist/csl/project.js +85 -0
- package/dist/csl/project.js.map +1 -0
- package/dist/csl/render.d.ts +130 -0
- package/dist/csl/render.js +748 -0
- package/dist/csl/render.js.map +1 -0
- package/dist/csl/style.d.ts +168 -0
- package/dist/csl/style.js +262 -0
- package/dist/csl/style.js.map +1 -0
- package/dist/csl/xml.d.ts +28 -0
- package/dist/csl/xml.js +162 -0
- package/dist/csl/xml.js.map +1 -0
- package/dist/djot/djot.js/LICENSE +20 -0
- package/dist/djot/djot.js/src/ast.d.ts +327 -0
- package/dist/djot/djot.js/src/ast.js +68 -0
- package/dist/djot/djot.js/src/ast.js.map +1 -0
- package/dist/djot/djot.js/src/attributes.d.ts +31 -0
- package/dist/djot/djot.js/src/attributes.js +300 -0
- package/dist/djot/djot.js/src/attributes.js.map +1 -0
- package/dist/djot/djot.js/src/block.d.ts +87 -0
- package/dist/djot/djot.js/src/block.js +1201 -0
- package/dist/djot/djot.js/src/block.js.map +1 -0
- package/dist/djot/djot.js/src/djot-renderer.d.ts +8 -0
- package/dist/djot/djot.js/src/djot-renderer.js +755 -0
- package/dist/djot/djot.js/src/djot-renderer.js.map +1 -0
- package/dist/djot/djot.js/src/event.d.ts +6 -0
- package/dist/djot/djot.js/src/event.js +2 -0
- package/dist/djot/djot.js/src/event.js.map +1 -0
- package/dist/djot/djot.js/src/filter.d.ts +13 -0
- package/dist/djot/djot.js/src/filter.js +159 -0
- package/dist/djot/djot.js/src/filter.js.map +1 -0
- package/dist/djot/djot.js/src/find.d.ts +7 -0
- package/dist/djot/djot.js/src/find.js +33 -0
- package/dist/djot/djot.js/src/find.js.map +1 -0
- package/dist/djot/djot.js/src/html.d.ts +40 -0
- package/dist/djot/djot.js/src/html.js +657 -0
- package/dist/djot/djot.js/src/html.js.map +1 -0
- package/dist/djot/djot.js/src/index.d.ts +9 -0
- package/dist/djot/djot.js/src/index.js +9 -0
- package/dist/djot/djot.js/src/index.js.map +1 -0
- package/dist/djot/djot.js/src/inline.d.ts +62 -0
- package/dist/djot/djot.js/src/inline.js +1032 -0
- package/dist/djot/djot.js/src/inline.js.map +1 -0
- package/dist/djot/djot.js/src/options.d.ts +13 -0
- package/dist/djot/djot.js/src/options.js +27 -0
- package/dist/djot/djot.js/src/options.js.map +1 -0
- package/dist/djot/djot.js/src/pandoc.d.ts +20 -0
- package/dist/djot/djot.js/src/pandoc.js +1110 -0
- package/dist/djot/djot.js/src/pandoc.js.map +1 -0
- package/dist/djot/djot.js/src/parse.d.ts +19 -0
- package/dist/djot/djot.js/src/parse.js +1445 -0
- package/dist/djot/djot.js/src/parse.js.map +1 -0
- package/dist/djot/djot.js/src/version.d.ts +1 -0
- package/dist/djot/djot.js/src/version.js +2 -0
- package/dist/djot/djot.js/src/version.js.map +1 -0
- package/dist/djot/index.d.ts +5 -0
- package/dist/djot/index.js +6 -0
- package/dist/djot/index.js.map +1 -0
- package/dist/djot/read.d.ts +57 -0
- package/dist/djot/read.js +146 -0
- package/dist/djot/read.js.map +1 -0
- package/dist/fonts/css.d.ts +82 -0
- package/dist/fonts/css.js +329 -0
- package/dist/fonts/css.js.map +1 -0
- package/dist/fonts/faces.d.ts +101 -0
- package/dist/fonts/faces.js +226 -0
- package/dist/fonts/faces.js.map +1 -0
- package/dist/fonts/index.d.ts +12 -0
- package/dist/fonts/index.js +13 -0
- package/dist/fonts/index.js.map +1 -0
- package/dist/fonts/lint.d.ts +58 -0
- package/dist/fonts/lint.js +209 -0
- package/dist/fonts/lint.js.map +1 -0
- package/dist/fonts/match.d.ts +36 -0
- package/dist/fonts/match.js +104 -0
- package/dist/fonts/match.js.map +1 -0
- package/dist/fonts/names.d.ts +9 -0
- package/dist/fonts/names.js +50 -0
- package/dist/fonts/names.js.map +1 -0
- package/dist/fonts/subset.d.ts +72 -0
- package/dist/fonts/subset.js +169 -0
- package/dist/fonts/subset.js.map +1 -0
- package/dist/fonts/walk.d.ts +33 -0
- package/dist/fonts/walk.js +120 -0
- package/dist/fonts/walk.js.map +1 -0
- package/dist/fonts/wasm/LICENSE-harfbuzzjs +19 -0
- package/dist/fonts/wasm/harfbuzz-subset.wasm +0 -0
- package/dist/html/check.d.ts +62 -0
- package/dist/html/check.js +186 -0
- package/dist/html/check.js.map +1 -0
- package/dist/html/counters.d.ts +32 -0
- package/dist/html/counters.js +72 -0
- package/dist/html/counters.js.map +1 -0
- package/dist/html/css.d.ts +33 -0
- package/dist/html/css.js +72 -0
- package/dist/html/css.js.map +1 -0
- package/dist/html/dom.d.ts +28 -0
- package/dist/html/dom.js +162 -0
- package/dist/html/dom.js.map +1 -0
- package/dist/html/editions.d.ts +26 -0
- package/dist/html/editions.js +57 -0
- package/dist/html/editions.js.map +1 -0
- package/dist/html/images.d.ts +13 -0
- package/dist/html/images.js +62 -0
- package/dist/html/images.js.map +1 -0
- package/dist/html/index.d.ts +14 -0
- package/dist/html/index.js +15 -0
- package/dist/html/index.js.map +1 -0
- package/dist/html/registry.d.ts +120 -0
- package/dist/html/registry.js +48 -0
- package/dist/html/registry.js.map +1 -0
- package/dist/html/render.d.ts +99 -0
- package/dist/html/render.js +694 -0
- package/dist/html/render.js.map +1 -0
- package/dist/hyphenation/NOTICE +429 -0
- package/dist/hyphenation/exceptions.d.ts +60 -0
- package/dist/hyphenation/exceptions.js +79 -0
- package/dist/hyphenation/exceptions.js.map +1 -0
- package/dist/hyphenation/hyphenator.d.ts +66 -0
- package/dist/hyphenation/hyphenator.js +245 -0
- package/dist/hyphenation/hyphenator.js.map +1 -0
- package/dist/hyphenation/index.d.ts +4 -0
- package/dist/hyphenation/index.js +5 -0
- package/dist/hyphenation/index.js.map +1 -0
- package/dist/hyphenation/languages.d.ts +20 -0
- package/dist/hyphenation/languages.js +75 -0
- package/dist/hyphenation/languages.js.map +1 -0
- package/dist/hyphenation/patterns/af.wasm +0 -0
- package/dist/hyphenation/patterns/as.wasm +0 -0
- package/dist/hyphenation/patterns/be.wasm +0 -0
- package/dist/hyphenation/patterns/bg.wasm +0 -0
- package/dist/hyphenation/patterns/bn.wasm +0 -0
- package/dist/hyphenation/patterns/ca.wasm +0 -0
- package/dist/hyphenation/patterns/cy.wasm +0 -0
- package/dist/hyphenation/patterns/da.wasm +0 -0
- package/dist/hyphenation/patterns/de.wasm +0 -0
- package/dist/hyphenation/patterns/el-monoton.wasm +0 -0
- package/dist/hyphenation/patterns/el-polyton.wasm +0 -0
- package/dist/hyphenation/patterns/en-gb.wasm +0 -0
- package/dist/hyphenation/patterns/en-us.wasm +0 -0
- package/dist/hyphenation/patterns/eo.wasm +0 -0
- package/dist/hyphenation/patterns/es.wasm +0 -0
- package/dist/hyphenation/patterns/et.wasm +0 -0
- package/dist/hyphenation/patterns/eu.wasm +0 -0
- package/dist/hyphenation/patterns/fi-x-school.wasm +0 -0
- package/dist/hyphenation/patterns/fr.wasm +0 -0
- package/dist/hyphenation/patterns/fur.wasm +0 -0
- package/dist/hyphenation/patterns/ga.wasm +0 -0
- package/dist/hyphenation/patterns/gl.wasm +0 -0
- package/dist/hyphenation/patterns/gu.wasm +0 -0
- package/dist/hyphenation/patterns/hi.wasm +0 -0
- package/dist/hyphenation/patterns/hr.wasm +0 -0
- package/dist/hyphenation/patterns/hsb.wasm +0 -0
- package/dist/hyphenation/patterns/ia.wasm +0 -0
- package/dist/hyphenation/patterns/is.wasm +0 -0
- package/dist/hyphenation/patterns/it.wasm +0 -0
- package/dist/hyphenation/patterns/ka.wasm +0 -0
- package/dist/hyphenation/patterns/kmr.wasm +0 -0
- package/dist/hyphenation/patterns/kn.wasm +0 -0
- package/dist/hyphenation/patterns/la.wasm +0 -0
- package/dist/hyphenation/patterns/lt.wasm +0 -0
- package/dist/hyphenation/patterns/ml.wasm +0 -0
- package/dist/hyphenation/patterns/mn-cyrl.wasm +0 -0
- package/dist/hyphenation/patterns/mr.wasm +0 -0
- package/dist/hyphenation/patterns/nb.wasm +0 -0
- package/dist/hyphenation/patterns/nl.wasm +0 -0
- package/dist/hyphenation/patterns/nn.wasm +0 -0
- package/dist/hyphenation/patterns/no.wasm +0 -0
- package/dist/hyphenation/patterns/oc.wasm +0 -0
- package/dist/hyphenation/patterns/or.wasm +0 -0
- package/dist/hyphenation/patterns/pa.wasm +0 -0
- package/dist/hyphenation/patterns/pi.wasm +0 -0
- package/dist/hyphenation/patterns/pl.wasm +0 -0
- package/dist/hyphenation/patterns/pms.wasm +0 -0
- package/dist/hyphenation/patterns/pt.wasm +0 -0
- package/dist/hyphenation/patterns/rm.wasm +0 -0
- package/dist/hyphenation/patterns/ru.wasm +0 -0
- package/dist/hyphenation/patterns/sh-cyrl.wasm +0 -0
- package/dist/hyphenation/patterns/sh-latn.wasm +0 -0
- package/dist/hyphenation/patterns/sk.wasm +0 -0
- package/dist/hyphenation/patterns/sl.wasm +0 -0
- package/dist/hyphenation/patterns/sq.wasm +0 -0
- package/dist/hyphenation/patterns/sv.wasm +0 -0
- package/dist/hyphenation/patterns/ta.wasm +0 -0
- package/dist/hyphenation/patterns/te.wasm +0 -0
- package/dist/hyphenation/patterns/th.wasm +0 -0
- package/dist/hyphenation/patterns/tk.wasm +0 -0
- package/dist/hyphenation/patterns/tr.wasm +0 -0
- package/dist/hyphenation/patterns/uk.wasm +0 -0
- package/dist/hyphenation/patterns/zh-latn-pinyin.wasm +0 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/indexes/index.d.ts +10 -0
- package/dist/indexes/index.js +11 -0
- package/dist/indexes/index.js.map +1 -0
- package/dist/indexes/layout.d.ts +30 -0
- package/dist/indexes/layout.js +83 -0
- package/dist/indexes/layout.js.map +1 -0
- package/dist/indexes/locators.d.ts +33 -0
- package/dist/indexes/locators.js +51 -0
- package/dist/indexes/locators.js.map +1 -0
- package/dist/indexes/terms.d.ts +97 -0
- package/dist/indexes/terms.js +211 -0
- package/dist/indexes/terms.js.map +1 -0
- package/dist/indexes/transform.d.ts +90 -0
- package/dist/indexes/transform.js +154 -0
- package/dist/indexes/transform.js.map +1 -0
- package/dist/layout/calibrate.d.ts +12 -0
- package/dist/layout/calibrate.js +50 -0
- package/dist/layout/calibrate.js.map +1 -0
- package/dist/layout/converge.d.ts +31 -0
- package/dist/layout/converge.js +84 -0
- package/dist/layout/converge.js.map +1 -0
- package/dist/layout/counters.d.ts +16 -0
- package/dist/layout/counters.js +62 -0
- package/dist/layout/counters.js.map +1 -0
- package/dist/layout/first-letter.d.ts +34 -0
- package/dist/layout/first-letter.js +183 -0
- package/dist/layout/first-letter.js.map +1 -0
- package/dist/layout/fonts.d.ts +67 -0
- package/dist/layout/fonts.js +110 -0
- package/dist/layout/fonts.js.map +1 -0
- package/dist/layout/generated.d.ts +9 -0
- package/dist/layout/generated.js +83 -0
- package/dist/layout/generated.js.map +1 -0
- package/dist/layout/glue.d.ts +18 -0
- package/dist/layout/glue.js +48 -0
- package/dist/layout/glue.js.map +1 -0
- package/dist/layout/index.d.ts +17 -0
- package/dist/layout/index.js +18 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/lists.d.ts +91 -0
- package/dist/layout/lists.js +1068 -0
- package/dist/layout/lists.js.map +1 -0
- package/dist/layout/margin-boxes.d.ts +114 -0
- package/dist/layout/margin-boxes.js +429 -0
- package/dist/layout/margin-boxes.js.map +1 -0
- package/dist/layout/minipage.d.ts +85 -0
- package/dist/layout/minipage.js +83 -0
- package/dist/layout/minipage.js.map +1 -0
- package/dist/layout/page-box.d.ts +34 -0
- package/dist/layout/page-box.js +112 -0
- package/dist/layout/page-box.js.map +1 -0
- package/dist/layout/page-rules.d.ts +49 -0
- package/dist/layout/page-rules.js +205 -0
- package/dist/layout/page-rules.js.map +1 -0
- package/dist/layout/page.d.ts +51 -0
- package/dist/layout/page.js +133 -0
- package/dist/layout/page.js.map +1 -0
- package/dist/layout/pagebuilder.d.ts +243 -0
- package/dist/layout/pagebuilder.js +591 -0
- package/dist/layout/pagebuilder.js.map +1 -0
- package/dist/layout/pages.d.ts +77 -0
- package/dist/layout/pages.js +772 -0
- package/dist/layout/pages.js.map +1 -0
- package/dist/layout/paragraph.d.ts +194 -0
- package/dist/layout/paragraph.js +1148 -0
- package/dist/layout/paragraph.js.map +1 -0
- package/dist/layout/pre.d.ts +8 -0
- package/dist/layout/pre.js +151 -0
- package/dist/layout/pre.js.map +1 -0
- package/dist/layout/region.d.ts +66 -0
- package/dist/layout/region.js +200 -0
- package/dist/layout/region.js.map +1 -0
- package/dist/layout/vlist.d.ts +218 -0
- package/dist/layout/vlist.js +72 -0
- package/dist/layout/vlist.js.map +1 -0
- package/dist/linebreak/items.d.ts +69 -0
- package/dist/linebreak/items.js +44 -0
- package/dist/linebreak/items.js.map +1 -0
- package/dist/linebreak/knuth-plass.d.ts +149 -0
- package/dist/linebreak/knuth-plass.js +461 -0
- package/dist/linebreak/knuth-plass.js.map +1 -0
- package/dist/lint/config.d.ts +48 -0
- package/dist/lint/config.js +185 -0
- package/dist/lint/config.js.map +1 -0
- package/dist/lint/context.d.ts +64 -0
- package/dist/lint/context.js +37 -0
- package/dist/lint/context.js.map +1 -0
- package/dist/lint/fix.d.ts +40 -0
- package/dist/lint/fix.js +86 -0
- package/dist/lint/fix.js.map +1 -0
- package/dist/lint/index.d.ts +14 -0
- package/dist/lint/index.js +15 -0
- package/dist/lint/index.js.map +1 -0
- package/dist/lint/linter.d.ts +59 -0
- package/dist/lint/linter.js +239 -0
- package/dist/lint/linter.js.map +1 -0
- package/dist/lint/presets.d.ts +20 -0
- package/dist/lint/presets.js +65 -0
- package/dist/lint/presets.js.map +1 -0
- package/dist/lint/project.d.ts +31 -0
- package/dist/lint/project.js +100 -0
- package/dist/lint/project.js.map +1 -0
- package/dist/lint/rules/html.d.ts +30 -0
- package/dist/lint/rules/html.js +163 -0
- package/dist/lint/rules/html.js.map +1 -0
- package/dist/lint/rules/layout.d.ts +42 -0
- package/dist/lint/rules/layout.js +428 -0
- package/dist/lint/rules/layout.js.map +1 -0
- package/dist/lint/rules/source.d.ts +67 -0
- package/dist/lint/rules/source.js +339 -0
- package/dist/lint/rules/source.js.map +1 -0
- package/dist/lint/testing.d.ts +7 -0
- package/dist/lint/testing.js +77 -0
- package/dist/lint/testing.js.map +1 -0
- package/dist/math/hast.d.ts +46 -0
- package/dist/math/hast.js +297 -0
- package/dist/math/hast.js.map +1 -0
- package/dist/math/index.d.ts +9 -0
- package/dist/math/index.js +10 -0
- package/dist/math/index.js.map +1 -0
- package/dist/math/mathjax/LICENSE-mathjax +202 -0
- package/dist/math/mathjax/LICENSE-speech-rule-engine +177 -0
- package/dist/math/mathjax/sre/af.json +146 -0
- package/dist/math/mathjax/sre/base.json +140 -0
- package/dist/math/mathjax/sre/ca.json +140 -0
- package/dist/math/mathjax/sre/da.json +140 -0
- package/dist/math/mathjax/sre/de.json +146 -0
- package/dist/math/mathjax/sre/en.json +158 -0
- package/dist/math/mathjax/sre/es.json +140 -0
- package/dist/math/mathjax/sre/euro.json +32 -0
- package/dist/math/mathjax/sre/fr.json +146 -0
- package/dist/math/mathjax/sre/hi.json +146 -0
- package/dist/math/mathjax/sre/it.json +146 -0
- package/dist/math/mathjax/sre/ko.json +146 -0
- package/dist/math/mathjax/sre/nb.json +146 -0
- package/dist/math/mathjax/sre/nemeth.json +125 -0
- package/dist/math/mathjax/sre/nn.json +146 -0
- package/dist/math/mathjax/sre/sv.json +146 -0
- package/dist/math/mathjax/svg/PUA.json +1 -0
- package/dist/math/mathjax/svg/accents-b-i.json +1 -0
- package/dist/math/mathjax/svg/accents.json +1 -0
- package/dist/math/mathjax/svg/arabic.json +1 -0
- package/dist/math/mathjax/svg/arrows.json +1 -0
- package/dist/math/mathjax/svg/braille-d.json +1 -0
- package/dist/math/mathjax/svg/braille.json +1 -0
- package/dist/math/mathjax/svg/calligraphic.json +1 -0
- package/dist/math/mathjax/svg/cherokee.json +1 -0
- package/dist/math/mathjax/svg/cyrillic-ss.json +1 -0
- package/dist/math/mathjax/svg/cyrillic.json +1 -0
- package/dist/math/mathjax/svg/devanagari.json +1 -0
- package/dist/math/mathjax/svg/double-struck.json +1 -0
- package/dist/math/mathjax/svg/fraktur.json +1 -0
- package/dist/math/mathjax/svg/greek-ss.json +1 -0
- package/dist/math/mathjax/svg/greek.json +1 -0
- package/dist/math/mathjax/svg/hebrew.json +1 -0
- package/dist/math/mathjax/svg/latin-b.json +1 -0
- package/dist/math/mathjax/svg/latin-bi.json +1 -0
- package/dist/math/mathjax/svg/latin-i.json +1 -0
- package/dist/math/mathjax/svg/latin.json +1 -0
- package/dist/math/mathjax/svg/marrows.json +1 -0
- package/dist/math/mathjax/svg/math.json +1 -0
- package/dist/math/mathjax/svg/monospace-ex.json +1 -0
- package/dist/math/mathjax/svg/monospace-l.json +1 -0
- package/dist/math/mathjax/svg/monospace.json +1 -0
- package/dist/math/mathjax/svg/mshapes.json +1 -0
- package/dist/math/mathjax/svg/phonetics-ss.json +1 -0
- package/dist/math/mathjax/svg/phonetics.json +1 -0
- package/dist/math/mathjax/svg/sans-serif-b.json +1 -0
- package/dist/math/mathjax/svg/sans-serif-bi.json +1 -0
- package/dist/math/mathjax/svg/sans-serif-ex.json +1 -0
- package/dist/math/mathjax/svg/sans-serif-i.json +1 -0
- package/dist/math/mathjax/svg/sans-serif-r.json +1 -0
- package/dist/math/mathjax/svg/sans-serif.json +1 -0
- package/dist/math/mathjax/svg/script.json +1 -0
- package/dist/math/mathjax/svg/shapes.json +1 -0
- package/dist/math/mathjax/svg/symbols-b-i.json +1 -0
- package/dist/math/mathjax/svg/symbols.json +1 -0
- package/dist/math/mathjax/svg/variants.json +1 -0
- package/dist/math/mathjax.d.ts +67 -0
- package/dist/math/mathjax.js +162 -0
- package/dist/math/mathjax.js.map +1 -0
- package/dist/math/speech.d.ts +27 -0
- package/dist/math/speech.js +87 -0
- package/dist/math/speech.js.map +1 -0
- package/dist/math/typeset.d.ts +75 -0
- package/dist/math/typeset.js +108 -0
- package/dist/math/typeset.js.map +1 -0
- package/dist/measure/css.d.ts +44 -0
- package/dist/measure/css.js +158 -0
- package/dist/measure/css.js.map +1 -0
- package/dist/measure/index.d.ts +3 -0
- package/dist/measure/index.js +4 -0
- package/dist/measure/index.js.map +1 -0
- package/dist/measure/measurer.d.ts +159 -0
- package/dist/measure/measurer.js +300 -0
- package/dist/measure/measurer.js.map +1 -0
- package/dist/measure/model.d.ts +46 -0
- package/dist/measure/model.js +47 -0
- package/dist/measure/model.js.map +1 -0
- package/dist/output/assets.d.ts +10 -0
- package/dist/output/assets.js +65 -0
- package/dist/output/assets.js.map +1 -0
- package/dist/output/index.d.ts +4 -0
- package/dist/output/index.js +5 -0
- package/dist/output/index.js.map +1 -0
- package/dist/output/output.d.ts +103 -0
- package/dist/output/output.js +86 -0
- package/dist/output/output.js.map +1 -0
- package/dist/output/stylesheets.d.ts +45 -0
- package/dist/output/stylesheets.js +50 -0
- package/dist/output/stylesheets.js.map +1 -0
- package/dist/paint/backgrounds.d.ts +56 -0
- package/dist/paint/backgrounds.js +261 -0
- package/dist/paint/backgrounds.js.map +1 -0
- package/dist/paint/blend.d.ts +61 -0
- package/dist/paint/blend.js +157 -0
- package/dist/paint/blend.js.map +1 -0
- package/dist/paint/border-image.d.ts +13 -0
- package/dist/paint/border-image.js +149 -0
- package/dist/paint/border-image.js.map +1 -0
- package/dist/paint/borders.d.ts +47 -0
- package/dist/paint/borders.js +329 -0
- package/dist/paint/borders.js.map +1 -0
- package/dist/paint/canvas.d.ts +52 -0
- package/dist/paint/canvas.js +274 -0
- package/dist/paint/canvas.js.map +1 -0
- package/dist/paint/colours.d.ts +55 -0
- package/dist/paint/colours.js +380 -0
- package/dist/paint/colours.js.map +1 -0
- package/dist/paint/columns.d.ts +11 -0
- package/dist/paint/columns.js +42 -0
- package/dist/paint/columns.js.map +1 -0
- package/dist/paint/context.d.ts +47 -0
- package/dist/paint/context.js +2 -0
- package/dist/paint/context.js.map +1 -0
- package/dist/paint/decoration.d.ts +97 -0
- package/dist/paint/decoration.js +280 -0
- package/dist/paint/decoration.js.map +1 -0
- package/dist/paint/effects.d.ts +64 -0
- package/dist/paint/effects.js +342 -0
- package/dist/paint/effects.js.map +1 -0
- package/dist/paint/emphasis.d.ts +13 -0
- package/dist/paint/emphasis.js +95 -0
- package/dist/paint/emphasis.js.map +1 -0
- package/dist/paint/flatten.d.ts +33 -0
- package/dist/paint/flatten.js +968 -0
- package/dist/paint/flatten.js.map +1 -0
- package/dist/paint/geometry.d.ts +62 -0
- package/dist/paint/geometry.js +170 -0
- package/dist/paint/geometry.js.map +1 -0
- package/dist/paint/gradients.d.ts +31 -0
- package/dist/paint/gradients.js +394 -0
- package/dist/paint/gradients.js.map +1 -0
- package/dist/paint/images.d.ts +17 -0
- package/dist/paint/images.js +80 -0
- package/dist/paint/images.js.map +1 -0
- package/dist/paint/lint.d.ts +46 -0
- package/dist/paint/lint.js +105 -0
- package/dist/paint/lint.js.map +1 -0
- package/dist/paint/overprint.d.ts +13 -0
- package/dist/paint/overprint.js +12 -0
- package/dist/paint/overprint.js.map +1 -0
- package/dist/paint/painter.d.ts +92 -0
- package/dist/paint/painter.js +281 -0
- package/dist/paint/painter.js.map +1 -0
- package/dist/paint/path.d.ts +9 -0
- package/dist/paint/path.js +173 -0
- package/dist/paint/path.js.map +1 -0
- package/dist/paint/raster.d.ts +32 -0
- package/dist/paint/raster.js +180 -0
- package/dist/paint/raster.js.map +1 -0
- package/dist/paint/shadows.d.ts +28 -0
- package/dist/paint/shadows.js +104 -0
- package/dist/paint/shadows.js.map +1 -0
- package/dist/paint/sources.d.ts +13 -0
- package/dist/paint/sources.js +17 -0
- package/dist/paint/sources.js.map +1 -0
- package/dist/paint/stacking.d.ts +75 -0
- package/dist/paint/stacking.js +327 -0
- package/dist/paint/stacking.js.map +1 -0
- package/dist/paint/svg-lint.d.ts +57 -0
- package/dist/paint/svg-lint.js +119 -0
- package/dist/paint/svg-lint.js.map +1 -0
- package/dist/paint/svg.d.ts +95 -0
- package/dist/paint/svg.js +728 -0
- package/dist/paint/svg.js.map +1 -0
- package/dist/paint/tables.d.ts +18 -0
- package/dist/paint/tables.js +178 -0
- package/dist/paint/tables.js.map +1 -0
- package/dist/paint/text-shadow.d.ts +26 -0
- package/dist/paint/text-shadow.js +187 -0
- package/dist/paint/text-shadow.js.map +1 -0
- package/dist/paint/text.d.ts +144 -0
- package/dist/paint/text.js +713 -0
- package/dist/paint/text.js.map +1 -0
- package/dist/paint/values.d.ts +24 -0
- package/dist/paint/values.js +160 -0
- package/dist/paint/values.js.map +1 -0
- package/dist/paint/vertical.d.ts +19 -0
- package/dist/paint/vertical.js +236 -0
- package/dist/paint/vertical.js.map +1 -0
- package/dist/pdf/index.d.ts +6 -0
- package/dist/pdf/index.js +7 -0
- package/dist/pdf/index.js.map +1 -0
- package/dist/pdf/pdfx.d.ts +30 -0
- package/dist/pdf/pdfx.js +18 -0
- package/dist/pdf/pdfx.js.map +1 -0
- package/dist/pdf/structure/index.d.ts +53 -0
- package/dist/pdf/structure/index.js +52 -0
- package/dist/pdf/structure/index.js.map +1 -0
- package/dist/pdf/structure/labels.d.ts +16 -0
- package/dist/pdf/structure/labels.js +45 -0
- package/dist/pdf/structure/labels.js.map +1 -0
- package/dist/pdf/structure/links.d.ts +49 -0
- package/dist/pdf/structure/links.js +136 -0
- package/dist/pdf/structure/links.js.map +1 -0
- package/dist/pdf/structure/tags.d.ts +79 -0
- package/dist/pdf/structure/tags.js +314 -0
- package/dist/pdf/structure/tags.js.map +1 -0
- package/dist/pdf/types.d.ts +551 -0
- package/dist/pdf/types.js +16 -0
- package/dist/pdf/types.js.map +1 -0
- package/dist/pdf/wasm/pulpweaver4_pdf.d.ts +41 -0
- package/dist/pdf/wasm/pulpweaver4_pdf.js +286 -0
- package/dist/pdf/wasm/pulpweaver4_pdf_bg.wasm +0 -0
- package/dist/pdf/writer.d.ts +41 -0
- package/dist/pdf/writer.js +78 -0
- package/dist/pdf/writer.js.map +1 -0
- package/dist/plugin/attributes.d.ts +10 -0
- package/dist/plugin/attributes.js +63 -0
- package/dist/plugin/attributes.js.map +1 -0
- package/dist/plugin/define.d.ts +425 -0
- package/dist/plugin/define.js +311 -0
- package/dist/plugin/define.js.map +1 -0
- package/dist/plugin/failure.d.ts +80 -0
- package/dist/plugin/failure.js +97 -0
- package/dist/plugin/failure.js.map +1 -0
- package/dist/plugin/index.d.ts +11 -0
- package/dist/plugin/index.js +12 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/load.d.ts +105 -0
- package/dist/plugin/load.js +197 -0
- package/dist/plugin/load.js.map +1 -0
- package/dist/plugin/register.d.ts +166 -0
- package/dist/plugin/register.js +306 -0
- package/dist/plugin/register.js.map +1 -0
- package/dist/plugin/render.d.ts +4 -0
- package/dist/plugin/render.js +28 -0
- package/dist/plugin/render.js.map +1 -0
- package/dist/preflight/index.d.ts +3 -0
- package/dist/preflight/index.js +4 -0
- package/dist/preflight/index.js.map +1 -0
- package/dist/preflight/pdfx.d.ts +440 -0
- package/dist/preflight/pdfx.js +1781 -0
- package/dist/preflight/pdfx.js.map +1 -0
- package/dist/preflight/reader.d.ts +126 -0
- package/dist/preflight/reader.js +832 -0
- package/dist/preflight/reader.js.map +1 -0
- package/dist/preflight/xmp.d.ts +30 -0
- package/dist/preflight/xmp.js +145 -0
- package/dist/preflight/xmp.js.map +1 -0
- package/dist/print/index.d.ts +2 -0
- package/dist/print/index.js +3 -0
- package/dist/print/index.js.map +1 -0
- package/dist/print/output.d.ts +5 -0
- package/dist/print/output.js +215 -0
- package/dist/print/output.js.map +1 -0
- package/dist/problem.d.ts +142 -0
- package/dist/problem.js +234 -0
- package/dist/problem.js.map +1 -0
- package/dist/profile/index.d.ts +10 -0
- package/dist/profile/index.js +11 -0
- package/dist/profile/index.js.map +1 -0
- package/dist/profile/lint.d.ts +69 -0
- package/dist/profile/lint.js +282 -0
- package/dist/profile/lint.js.map +1 -0
- package/dist/profile/metadata.d.ts +27 -0
- package/dist/profile/metadata.js +38 -0
- package/dist/profile/metadata.js.map +1 -0
- package/dist/profile/profile.d.ts +92 -0
- package/dist/profile/profile.js +282 -0
- package/dist/profile/profile.js.map +1 -0
- package/dist/project.d.ts +56 -0
- package/dist/project.js +137 -0
- package/dist/project.js.map +1 -0
- package/dist/reproducible/clock.d.ts +46 -0
- package/dist/reproducible/clock.js +173 -0
- package/dist/reproducible/clock.js.map +1 -0
- package/dist/reproducible/date.d.ts +42 -0
- package/dist/reproducible/date.js +82 -0
- package/dist/reproducible/date.js.map +1 -0
- package/dist/reproducible/index.d.ts +8 -0
- package/dist/reproducible/index.js +9 -0
- package/dist/reproducible/index.js.map +1 -0
- package/dist/spike/spike-page.chromium.json +330 -0
- package/dist/spike/spike.d.ts +75 -0
- package/dist/spike/spike.js +106 -0
- package/dist/spike/spike.js.map +1 -0
- package/dist/style/borders.d.ts +25 -0
- package/dist/style/borders.js +177 -0
- package/dist/style/borders.js.map +1 -0
- package/dist/style/colours.d.ts +34 -0
- package/dist/style/colours.js +138 -0
- package/dist/style/colours.js.map +1 -0
- package/dist/style/compile.d.ts +79 -0
- package/dist/style/compile.js +325 -0
- package/dist/style/compile.js.map +1 -0
- package/dist/style/defaults.d.ts +20 -0
- package/dist/style/defaults.js +45 -0
- package/dist/style/defaults.js.map +1 -0
- package/dist/style/gcpm.d.ts +22 -0
- package/dist/style/gcpm.js +86 -0
- package/dist/style/gcpm.js.map +1 -0
- package/dist/style/index.d.ts +4 -0
- package/dist/style/index.js +5 -0
- package/dist/style/index.js.map +1 -0
- package/dist/style/media.d.ts +22 -0
- package/dist/style/media.js +342 -0
- package/dist/style/media.js.map +1 -0
- package/dist/style/properties.d.ts +44 -0
- package/dist/style/properties.js +497 -0
- package/dist/style/properties.js.map +1 -0
- package/dist/style/scope.d.ts +6 -0
- package/dist/style/scope.js +134 -0
- package/dist/style/scope.js.map +1 -0
- package/dist/style/values.d.ts +45 -0
- package/dist/style/values.js +106 -0
- package/dist/style/values.js.map +1 -0
- package/dist/test/book.d.ts +180 -0
- package/dist/test/book.js +314 -0
- package/dist/test/book.js.map +1 -0
- package/dist/test/build.d.ts +58 -0
- package/dist/test/build.js +222 -0
- package/dist/test/build.js.map +1 -0
- package/dist/test/environment.d.ts +63 -0
- package/dist/test/environment.js +46 -0
- package/dist/test/environment.js.map +1 -0
- package/dist/test/index.d.ts +17 -0
- package/dist/test/index.js +18 -0
- package/dist/test/index.js.map +1 -0
- package/dist/test/indexes.d.ts +4 -0
- package/dist/test/indexes.js +48 -0
- package/dist/test/indexes.js.map +1 -0
- package/dist/test/layout.d.ts +8 -0
- package/dist/test/layout.js +121 -0
- package/dist/test/layout.js.map +1 -0
- package/dist/test/matchers.d.ts +80 -0
- package/dist/test/matchers.js +177 -0
- package/dist/test/matchers.js.map +1 -0
- package/dist/test/pipeline.d.ts +231 -0
- package/dist/test/pipeline.js +75 -0
- package/dist/test/pipeline.js.map +1 -0
- package/dist/test/plugins.d.ts +13 -0
- package/dist/test/plugins.js +22 -0
- package/dist/test/plugins.js.map +1 -0
- package/dist/test/render.d.ts +46 -0
- package/dist/test/render.js +149 -0
- package/dist/test/render.js.map +1 -0
- package/dist/test/runner.d.ts +61 -0
- package/dist/test/runner.js +256 -0
- package/dist/test/runner.js.map +1 -0
- package/dist/test/select.d.ts +54 -0
- package/dist/test/select.js +193 -0
- package/dist/test/select.js.map +1 -0
- package/dist/test/snapshot.d.ts +52 -0
- package/dist/test/snapshot.js +175 -0
- package/dist/test/snapshot.js.map +1 -0
- package/dist/test/text.d.ts +7 -0
- package/dist/test/text.js +46 -0
- package/dist/test/text.js.map +1 -0
- package/dist/test/vitest.d.ts +3 -0
- package/dist/test/vitest.js +39 -0
- package/dist/test/vitest.js.map +1 -0
- package/dist/text/index.d.ts +5 -0
- package/dist/text/index.js +6 -0
- package/dist/text/index.js.map +1 -0
- package/dist/text/output.d.ts +5 -0
- package/dist/text/output.js +39 -0
- package/dist/text/output.js.map +1 -0
- package/dist/text/render.d.ts +82 -0
- package/dist/text/render.js +583 -0
- package/dist/text/render.js.map +1 -0
- package/dist/text/width.d.ts +16 -0
- package/dist/text/width.js +90 -0
- package/dist/text/width.js.map +1 -0
- package/dist/text/wrap.d.ts +19 -0
- package/dist/text/wrap.js +151 -0
- package/dist/text/wrap.js.map +1 -0
- package/dist/transform/core.d.ts +19 -0
- package/dist/transform/core.js +22 -0
- package/dist/transform/core.js.map +1 -0
- package/dist/transform/index.d.ts +10 -0
- package/dist/transform/index.js +11 -0
- package/dist/transform/index.js.map +1 -0
- package/dist/transform/numbering.d.ts +47 -0
- package/dist/transform/numbering.js +142 -0
- package/dist/transform/numbering.js.map +1 -0
- package/dist/transform/references.d.ts +38 -0
- package/dist/transform/references.js +182 -0
- package/dist/transform/references.js.map +1 -0
- package/dist/transform/run.d.ts +32 -0
- package/dist/transform/run.js +210 -0
- package/dist/transform/run.js.map +1 -0
- package/dist/transform/store.d.ts +111 -0
- package/dist/transform/store.js +331 -0
- package/dist/transform/store.js.map +1 -0
- package/dist/transform/testing.d.ts +31 -0
- package/dist/transform/testing.js +76 -0
- package/dist/transform/testing.js.map +1 -0
- package/dist/transform/transform.d.ts +104 -0
- package/dist/transform/transform.js +89 -0
- package/dist/transform/transform.js.map +1 -0
- package/dist/vfs/fsa.d.ts +14 -0
- package/dist/vfs/fsa.js +123 -0
- package/dist/vfs/fsa.js.map +1 -0
- package/dist/vfs/index.d.ts +7 -0
- package/dist/vfs/index.js +8 -0
- package/dist/vfs/index.js.map +1 -0
- package/dist/vfs/memory.d.ts +15 -0
- package/dist/vfs/memory.js +101 -0
- package/dist/vfs/memory.js.map +1 -0
- package/dist/vfs/path.d.ts +30 -0
- package/dist/vfs/path.js +67 -0
- package/dist/vfs/path.js.map +1 -0
- package/dist/vfs/vfs.d.ts +66 -0
- package/dist/vfs/vfs.js +68 -0
- package/dist/vfs/vfs.js.map +1 -0
- package/dist/vfs/zip.d.ts +27 -0
- package/dist/vfs/zip.js +67 -0
- package/dist/vfs/zip.js.map +1 -0
- package/dist/web/css.d.ts +15 -0
- package/dist/web/css.js +80 -0
- package/dist/web/css.js.map +1 -0
- package/dist/web/hast.d.ts +44 -0
- package/dist/web/hast.js +175 -0
- package/dist/web/hast.js.map +1 -0
- package/dist/web/index.d.ts +11 -0
- package/dist/web/index.js +12 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/justify-main.d.ts +1 -0
- package/dist/web/justify-main.js +38 -0
- package/dist/web/justify-main.js.map +1 -0
- package/dist/web/justify.d.ts +46 -0
- package/dist/web/justify.js +147 -0
- package/dist/web/justify.js.map +1 -0
- package/dist/web/output.d.ts +28 -0
- package/dist/web/output.js +251 -0
- package/dist/web/output.js.map +1 -0
- package/dist/web/runtime/LICENSE-harfbuzzjs.txt +19 -0
- package/dist/web/runtime/NOTICE-patterns.txt +429 -0
- package/dist/web/runtime/harfbuzz.wasm +0 -0
- package/dist/web/runtime/justify.js.txt +2 -0
- package/dist/web/site.d.ts +53 -0
- package/dist/web/site.js +219 -0
- package/dist/web/site.js.map +1 -0
- package/docs/README.md +16 -0
- package/docs/reference/css-properties/index.md +94 -0
- package/docs/reference/css-properties/pw-adj-demerits.md +22 -0
- package/docs/reference/css-properties/pw-border-bottom-width.md +24 -0
- package/docs/reference/css-properties/pw-border-left-width.md +24 -0
- package/docs/reference/css-properties/pw-border-right-width.md +24 -0
- package/docs/reference/css-properties/pw-border-top-width.md +24 -0
- package/docs/reference/css-properties/pw-box.md +28 -0
- package/docs/reference/css-properties/pw-broken-penalty.md +22 -0
- package/docs/reference/css-properties/pw-club-penalty.md +24 -0
- package/docs/reference/css-properties/pw-column-rule-width.md +23 -0
- package/docs/reference/css-properties/pw-content-after.md +31 -0
- package/docs/reference/css-properties/pw-content-before.md +31 -0
- package/docs/reference/css-properties/pw-double-hyphen-demerits.md +23 -0
- package/docs/reference/css-properties/pw-emergency-stretch.md +28 -0
- package/docs/reference/css-properties/pw-ex-hyphen-penalty.md +22 -0
- package/docs/reference/css-properties/pw-final-hyphen-demerits.md +22 -0
- package/docs/reference/css-properties/pw-float-skip.md +22 -0
- package/docs/reference/css-properties/pw-float.md +33 -0
- package/docs/reference/css-properties/pw-footnote-max-height.md +22 -0
- package/docs/reference/css-properties/pw-footnote-skip.md +23 -0
- package/docs/reference/css-properties/pw-hyphen-penalty.md +24 -0
- package/docs/reference/css-properties/pw-inter-line-penalty.md +24 -0
- package/docs/reference/css-properties/pw-leader-space.md +22 -0
- package/docs/reference/css-properties/pw-leader.md +29 -0
- package/docs/reference/css-properties/pw-left-hyphen-min.md +23 -0
- package/docs/reference/css-properties/pw-line-breaking.md +29 -0
- package/docs/reference/css-properties/pw-line-penalty.md +23 -0
- package/docs/reference/css-properties/pw-list-indent.md +18 -0
- package/docs/reference/css-properties/pw-looseness.md +30 -0
- package/docs/reference/css-properties/pw-max-depth.md +22 -0
- package/docs/reference/css-properties/pw-minipage-footnotes.md +23 -0
- package/docs/reference/css-properties/pw-orphans.md +24 -0
- package/docs/reference/css-properties/pw-outline-width.md +23 -0
- package/docs/reference/css-properties/pw-overprint.md +26 -0
- package/docs/reference/css-properties/pw-padding-bottom.md +22 -0
- package/docs/reference/css-properties/pw-padding-left.md +22 -0
- package/docs/reference/css-properties/pw-padding-right.md +22 -0
- package/docs/reference/css-properties/pw-padding-top.md +22 -0
- package/docs/reference/css-properties/pw-page-prefix.md +28 -0
- package/docs/reference/css-properties/pw-page.md +32 -0
- package/docs/reference/css-properties/pw-penalty-after.md +23 -0
- package/docs/reference/css-properties/pw-penalty-before.md +30 -0
- package/docs/reference/css-properties/pw-pretolerance.md +23 -0
- package/docs/reference/css-properties/pw-right-hyphen-min.md +22 -0
- package/docs/reference/css-properties/pw-running.md +23 -0
- package/docs/reference/css-properties/pw-site-background.md +21 -0
- package/docs/reference/css-properties/pw-site-link.md +17 -0
- package/docs/reference/css-properties/pw-site-measure.md +17 -0
- package/docs/reference/css-properties/pw-site-muted.md +21 -0
- package/docs/reference/css-properties/pw-site-rule.md +17 -0
- package/docs/reference/css-properties/pw-site-text.md +22 -0
- package/docs/reference/css-properties/pw-space-after.md +23 -0
- package/docs/reference/css-properties/pw-space-before.md +29 -0
- package/docs/reference/css-properties/pw-string-set.md +32 -0
- package/docs/reference/css-properties/pw-tolerance.md +33 -0
- package/docs/reference/css-properties/pw-top-skip.md +22 -0
- package/docs/reference/css-properties/pw-widow-penalty.md +32 -0
- package/docs/reference/css-properties/pw-widows.md +24 -0
- package/docs/reference/css-properties/pw-word-space.md +22 -0
- package/docs/reference/css-properties/pw-xspace.md +22 -0
- package/docs/reference/index.md +17 -0
- package/docs/reference/lint-rules/black-text.md +31 -0
- package/docs/reference/lint-rules/blank-page.md +35 -0
- package/docs/reference/lint-rules/chapter-verso.md +34 -0
- package/docs/reference/lint-rules/citation-in-heading.md +24 -0
- package/docs/reference/lint-rules/consecutive-hyphens.md +34 -0
- package/docs/reference/lint-rules/empty-link.md +32 -0
- package/docs/reference/lint-rules/figure-distance.md +34 -0
- package/docs/reference/lint-rules/fonts.md +24 -0
- package/docs/reference/lint-rules/generated-text.md +24 -0
- package/docs/reference/lint-rules/heading-levels.md +30 -0
- package/docs/reference/lint-rules/ibid-across-page.md +30 -0
- package/docs/reference/lint-rules/image-alt.md +30 -0
- package/docs/reference/lint-rules/image-resolution.md +34 -0
- package/docs/reference/lint-rules/index.md +120 -0
- package/docs/reference/lint-rules/ink-limit.md +30 -0
- package/docs/reference/lint-rules/missing-field.md +37 -0
- package/docs/reference/lint-rules/orphan.md +34 -0
- package/docs/reference/lint-rules/overfull-line.md +28 -0
- package/docs/reference/lint-rules/profile.md +24 -0
- package/docs/reference/lint-rules/raw-html.md +30 -0
- package/docs/reference/lint-rules/signature.md +34 -0
- package/docs/reference/lint-rules/straight-quotes.md +33 -0
- package/docs/reference/lint-rules/svg-use-css.md +24 -0
- package/docs/reference/lint-rules/underfull-line.md +35 -0
- package/docs/reference/lint-rules/unknown-citation.md +30 -0
- package/docs/reference/lint-rules/unknown-label.md +31 -0
- package/docs/reference/lint-rules/unpaintable.md +24 -0
- package/docs/reference/lint-rules/unplaced-index.md +31 -0
- package/docs/reference/lint-rules/unused-entry.md +38 -0
- package/docs/reference/lint-rules/widow.md +34 -0
- package/docs/reference/plugin-api/assert-no-errors.md +18 -0
- package/docs/reference/plugin-api/asset-processor.md +28 -0
- package/docs/reference/plugin-api/attribute-problem.md +26 -0
- package/docs/reference/plugin-api/attribute-type.md +18 -0
- package/docs/reference/plugin-api/capabilities.md +18 -0
- package/docs/reference/plugin-api/capability.md +22 -0
- package/docs/reference/plugin-api/check-attributes.md +18 -0
- package/docs/reference/plugin-api/claim-kind.md +20 -0
- package/docs/reference/plugin-api/combine-penalties.md +17 -0
- package/docs/reference/plugin-api/command-context.md +30 -0
- package/docs/reference/plugin-api/command-definition.md +34 -0
- package/docs/reference/plugin-api/core-claims.md +18 -0
- package/docs/reference/plugin-api/define-plugin.md +20 -0
- package/docs/reference/plugin-api/define-rule.md +19 -0
- package/docs/reference/plugin-api/describe-error.md +14 -0
- package/docs/reference/plugin-api/describe-node.md +14 -0
- package/docs/reference/plugin-api/empty-registry.md +18 -0
- package/docs/reference/plugin-api/failed-on.md +32 -0
- package/docs/reference/plugin-api/fails-as.md +18 -0
- package/docs/reference/plugin-api/import-plugins.md +20 -0
- package/docs/reference/plugin-api/import-text.md +14 -0
- package/docs/reference/plugin-api/index.md +123 -0
- package/docs/reference/plugin-api/layout-definition.md +42 -0
- package/docs/reference/plugin-api/layout-slot.md +28 -0
- package/docs/reference/plugin-api/line-breaker.md +18 -0
- package/docs/reference/plugin-api/lint-context.md +48 -0
- package/docs/reference/plugin-api/lint-definition.md +32 -0
- package/docs/reference/plugin-api/lint-edition.md +38 -0
- package/docs/reference/plugin-api/lint-fix.md +36 -0
- package/docs/reference/plugin-api/lint-level.md +20 -0
- package/docs/reference/plugin-api/lint-preset.md +30 -0
- package/docs/reference/plugin-api/lint-rule.md +42 -0
- package/docs/reference/plugin-api/load-failure.md +32 -0
- package/docs/reference/plugin-api/load-plugins-options.md +32 -0
- package/docs/reference/plugin-api/load-plugins.md +20 -0
- package/docs/reference/plugin-api/loaded-plugin.md +32 -0
- package/docs/reference/plugin-api/node-claim.md +34 -0
- package/docs/reference/plugin-api/output-definition.md +28 -0
- package/docs/reference/plugin-api/owned.md +28 -0
- package/docs/reference/plugin-api/page-builder-hook.md +18 -0
- package/docs/reference/plugin-api/penalty-rule.md +34 -0
- package/docs/reference/plugin-api/plugin-api.md +18 -0
- package/docs/reference/plugin-api/plugin-definition.md +66 -0
- package/docs/reference/plugin-api/plugin-error.md +22 -0
- package/docs/reference/plugin-api/plugin-failure.md +30 -0
- package/docs/reference/plugin-api/plugin-importer.md +34 -0
- package/docs/reference/plugin-api/plugin-problem.md +30 -0
- package/docs/reference/plugin-api/plugin-registry.md +83 -0
- package/docs/reference/plugin-api/plugin-scope.md +15 -0
- package/docs/reference/plugin-api/plugin-stage.md +18 -0
- package/docs/reference/plugin-api/plugin-threw-problem.md +34 -0
- package/docs/reference/plugin-api/plugin-threw.md +21 -0
- package/docs/reference/plugin-api/plugin.md +69 -0
- package/docs/reference/plugin-api/project-with-plugins.md +36 -0
- package/docs/reference/plugin-api/read-context.md +30 -0
- package/docs/reference/plugin-api/read-failure.md +18 -0
- package/docs/reference/plugin-api/read-plugin-styles.md +22 -0
- package/docs/reference/plugin-api/reader.md +22 -0
- package/docs/reference/plugin-api/register-options.md +28 -0
- package/docs/reference/plugin-api/register-plugins.md +20 -0
- package/docs/reference/plugin-api/render-format.md +18 -0
- package/docs/reference/plugin-api/render-formats.md +18 -0
- package/docs/reference/plugin-api/renderer-registry.md +18 -0
- package/docs/reference/plugin-api/renderer-set.md +34 -0
- package/docs/reference/plugin-api/renderers.md +34 -0
- package/docs/reference/plugin-api/specifier-kind.md +14 -0
- package/docs/reference/plugin-api/style-source.md +18 -0
- package/docs/reference/plugin-api/text-context.md +28 -0
- package/docs/reference/plugin-api/text-edit.md +28 -0
- package/docs/reference/plugin-api/text-renderer.md +24 -0
- package/docs/reference/plugin-api/try-plugin-async.md +18 -0
- package/docs/reference/plugin-api/try-plugin.md +20 -0
- package/docs/reference/pulpweaver4-toml/editions.md +208 -0
- package/docs/reference/pulpweaver4-toml/index.md +195 -0
- package/docs/reference/pulpweaver4-toml/inks.md +50 -0
- package/docs/reference/pulpweaver4-toml/lint.md +36 -0
- package/docs/reference/test-matchers/index.md +33 -0
- package/docs/reference/test-matchers/to-be-recto.md +20 -0
- package/docs/reference/test-matchers/to-cite.md +22 -0
- package/docs/reference/test-matchers/to-fit-on-one-page.md +20 -0
- package/docs/reference/test-matchers/to-have-no-overfull-lines.md +20 -0
- package/docs/reference/test-matchers/to-match-html-snapshot.md +20 -0
- package/docs/reference/test-matchers/to-match-page-snapshot.md +20 -0
- package/docs/reference/test-matchers/to-match-text-snapshot.md +21 -0
- package/docs/reference/test-matchers/to-start-page.md +20 -0
- package/package.json +75 -4
- package/README.md +0 -3
|
@@ -0,0 +1,1148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A paragraph through the engine: its DOM and computed styles become TeX's
|
|
3
|
+
* list of boxes, glue and penalties, Knuth–Plass breaks it, and each line is
|
|
4
|
+
* written back into the DOM as a block of the exact measure
|
|
5
|
+
* (https://plans.inkylabs.com/pulpweaver#the-box-glue-and-penalty-model-in-css):
|
|
6
|
+
*
|
|
7
|
+
* - its adjustment ratio applied as `word-spacing`: one value a line in
|
|
8
|
+
* Chromium, per space where Firefox's rounding to app units needs it;
|
|
9
|
+
* - a hyphen at a hyphenated break, inserted as a span of its own, which
|
|
10
|
+
* the layout reports (`LaidOutLine.hyphen`): Chromium gives a hyphen it
|
|
11
|
+
* draws itself no DOM position, so the painter paints these from the
|
|
12
|
+
* layout, not from the text;
|
|
13
|
+
* - every character kept, in reading order, so the PDF can be searched,
|
|
14
|
+
* selected and tagged: the space at a break stays at the end of its line;
|
|
15
|
+
* - every inline element on every line it occupies: a line inside an
|
|
16
|
+
* element (a citation, a link, an `em`) is wrapped in a shallow clone of
|
|
17
|
+
* it, with its classes, attributes and `data-pw-key`, so its pieces style,
|
|
18
|
+
* tag and locate as the one element they are. Only the first piece keeps
|
|
19
|
+
* its `id`, and the pieces are sliced as `box-decoration-break: slice`
|
|
20
|
+
* slices a box broken across lines: padding, border, margin and radii
|
|
21
|
+
* only where the element starts and ends. A clone wraps a line's whole
|
|
22
|
+
* content, so it adds no element boundary inside the line.
|
|
23
|
+
*
|
|
24
|
+
* Its list follows the plan's table: a box per word fragment (HarfBuzz's
|
|
25
|
+
* widths) and per atomic inline (an image, inline math, an `inline-block`:
|
|
26
|
+
* the browser's used width); glue per space, from `--pw-word-space`, or
|
|
27
|
+
* `--pw-xspace` after a sentence; a penalty per hyphenation point, soft
|
|
28
|
+
* hyphen and explicit hyphen (`--pw-hyphen-penalty`,
|
|
29
|
+
* `--pw-ex-hyphen-penalty`). What doesn't belong on a line (a footnote, a
|
|
30
|
+
* running head) is taken out first and reported with the line it was on, as
|
|
31
|
+
* TeX's inserts and marks migrate out of a paragraph
|
|
32
|
+
* (`ParagraphOptions.migrate`).
|
|
33
|
+
*
|
|
34
|
+
* Its `text-align` is TeX's glue at the lines' ends (`textAlignment`): `justify`
|
|
35
|
+
* stretches the spaces; any other alignment sets them rigid, as plain TeX's
|
|
36
|
+
* `\raggedright` does, with the stretch in the skips at the lines' ends, and
|
|
37
|
+
* each line is placed in the measure as those skips would set it.
|
|
38
|
+
*
|
|
39
|
+
* An element with `--pw-leader` is TeX's `\leaders\hbox{…}\hfill`, as a
|
|
40
|
+
* table of contents' dots are (`leaderOf`): glue of `fill` stretch, which no
|
|
41
|
+
* line breaks at (`\nobreak` either side) and which outstretches any `fil`
|
|
42
|
+
* of the alignment, filled with copies of a box (its text, `--pw-leader-space`
|
|
43
|
+
* either side) set at whole multiples of the box's width from the
|
|
44
|
+
* paragraph's edge, so the dots of every line and every entry line up.
|
|
45
|
+
*
|
|
46
|
+
* Its lines may each have their own measure and indent, as TeX's
|
|
47
|
+
* `\parshape` gives them (`ParagraphOptions.shape`): the lines beside a CSS
|
|
48
|
+
* float, each block placed at its indent.
|
|
49
|
+
*
|
|
50
|
+
* With `--pw-line-breaking: browser` the lines are the browser's: it lays
|
|
51
|
+
* the paragraph out, its breaks are read back from where it puts each
|
|
52
|
+
* character (`browserLineStarts`), and the lines are set and written as the
|
|
53
|
+
* engine's are, from the same list, its spaces the browser's own (justified,
|
|
54
|
+
* stretched alike, as the browser stretches them). It breaks words at the
|
|
55
|
+
* engine's hyphenation points, given it as soft hyphens while it lays them
|
|
56
|
+
* out, so a paragraph hyphenates the same in every browser.
|
|
57
|
+
*/
|
|
58
|
+
import { hyphenMins } from '../hyphenation/hyphenator.js';
|
|
59
|
+
import { INFINITE_PENALTY, box, finishParagraph, hyphenationPoint, penalty, } from '../linebreak/items.js';
|
|
60
|
+
import { breakLines, setLines } from '../linebreak/knuth-plass.js';
|
|
61
|
+
import { appliedSpacing, fontStyleFromComputed } from '../measure/index.js';
|
|
62
|
+
import { calibrateSize } from './calibrate.js';
|
|
63
|
+
import { DEFAULT_WORD_SPACE, parseGlue, parseLength } from './glue.js';
|
|
64
|
+
const SOFT_HYPHEN = '';
|
|
65
|
+
/** What stands for an atomic inline in a paragraph's text. */
|
|
66
|
+
export const OBJECT_REPLACEMENT = '\uFFFC';
|
|
67
|
+
/** Characters a sentence's end may hide behind, as TeX's `\sfcode` 0 makes `)`, `]` and `'` transparent. */
|
|
68
|
+
const CLOSERS = /[\p{Pe}\p{Pf}"']/u;
|
|
69
|
+
/** Hyphens and dashes after which a word may break, as TeX's `\exhyphenpenalty` allows. */
|
|
70
|
+
const EXPLICIT_HYPHENS = /[-‐–]/;
|
|
71
|
+
/** A word that is a URL, which may break inside: its scheme and `//`, or `www.`. */
|
|
72
|
+
const URL_START = /^[(<\[]?(?:[a-z][a-z0-9+.-]*:\/\/|www\.)/i;
|
|
73
|
+
/**
|
|
74
|
+
* Whether a URL may break before `at`: before a slash that isn't one of a
|
|
75
|
+
* `//`, or a full stop, with more of the URL after it (never before its
|
|
76
|
+
* last character, which may be the sentence's full stop), as Chicago
|
|
77
|
+
* breaks URLs (14.18). Breaks after a hyphen are the explicit hyphen's.
|
|
78
|
+
*/
|
|
79
|
+
function urlBreakBefore(text, at, end) {
|
|
80
|
+
const c = text[at];
|
|
81
|
+
if (c !== '/' && c !== '.')
|
|
82
|
+
return false;
|
|
83
|
+
if (at + 1 >= end || !/[\p{L}\p{N}_~%-]/u.test(text[at + 1]))
|
|
84
|
+
return false;
|
|
85
|
+
return c === '.' || (text[at - 1] !== '/' && text[at + 1] !== '/');
|
|
86
|
+
}
|
|
87
|
+
/** Breaks a paragraph into lines and writes them into its DOM. */
|
|
88
|
+
export function layoutParagraph(el, opts) {
|
|
89
|
+
const measurer = opts.fonts.measurer;
|
|
90
|
+
const model = measurer.model;
|
|
91
|
+
const pcs = getComputedStyle(el);
|
|
92
|
+
const shape = opts.shape?.length ? opts.shape : undefined;
|
|
93
|
+
const measure = shape ? shape.map((l) => l.measure) : opts.measure ?? contentWidth(el, pcs);
|
|
94
|
+
const lineShape = (n) => shape ? shape[Math.min(n, shape.length - 1)] : { measure: measure, left: 0 };
|
|
95
|
+
const align = textAlignment(pcs);
|
|
96
|
+
const justify = align.body === 'justify';
|
|
97
|
+
const skips = alignmentSkips(align, Number.parseFloat(pcs.fontSize));
|
|
98
|
+
const browser = pcs.getPropertyValue('--pw-line-breaking').trim() === 'browser';
|
|
99
|
+
const { segments, atoms, text, migrated: anchors } = collect(el, opts);
|
|
100
|
+
const atomAt = new Map(atoms.map((a) => [a.at, a]));
|
|
101
|
+
const segAt = (i) => segments.find((s) => i >= s.start && i < s.end) ?? segments.at(-1);
|
|
102
|
+
const widthOf = (a, b) => {
|
|
103
|
+
let w = 0;
|
|
104
|
+
for (const s of segments)
|
|
105
|
+
if (s.end > a && s.start < b)
|
|
106
|
+
w += s.run.widthBetween(Math.max(a, s.start), Math.min(b, s.end));
|
|
107
|
+
for (const atom of atoms)
|
|
108
|
+
if (atom.at >= a && atom.at < b)
|
|
109
|
+
w += atom.width;
|
|
110
|
+
return w;
|
|
111
|
+
};
|
|
112
|
+
/** A space's width as the browser sets it before word-spacing: its glyph, and letter-spacing. */
|
|
113
|
+
const spaceWidth = (i) => {
|
|
114
|
+
const s = segAt(i);
|
|
115
|
+
return s.run.widthBetween(i, i + 1) - s.run.wordSpacing;
|
|
116
|
+
};
|
|
117
|
+
// The list: a box per word fragment, glue per space, penalties where a
|
|
118
|
+
// word may break.
|
|
119
|
+
const items = [];
|
|
120
|
+
const origins = [];
|
|
121
|
+
const push = (item, origin) => {
|
|
122
|
+
items.push(item);
|
|
123
|
+
origins.push(origin);
|
|
124
|
+
};
|
|
125
|
+
const indent = parseLength(pcs.getPropertyValue('text-indent') || '0px', Number.parseFloat(pcs.fontSize));
|
|
126
|
+
if (indent)
|
|
127
|
+
push(box(indent), { kind: 'box', start: 0, end: 0 });
|
|
128
|
+
const hyphenPenalty = intProperty(pcs, '--pw-hyphen-penalty', 50);
|
|
129
|
+
const exHyphenPenalty = intProperty(pcs, '--pw-ex-hyphen-penalty', 50);
|
|
130
|
+
/** Where the hyphenator would break the word from `start` to `end`, as offsets in the text. */
|
|
131
|
+
const autoPoints = (start, end) => {
|
|
132
|
+
if (!opts.hyphenator)
|
|
133
|
+
return [];
|
|
134
|
+
const seg = segAt(start);
|
|
135
|
+
if (hyphensOf(seg.computed) !== 'auto')
|
|
136
|
+
return [];
|
|
137
|
+
const lang = seg.style.lang;
|
|
138
|
+
const mins = hyphenMins(lang);
|
|
139
|
+
const left = intProperty(seg.computed, '--pw-left-hyphen-min', mins.left);
|
|
140
|
+
const right = intProperty(seg.computed, '--pw-right-hyphen-min', mins.right);
|
|
141
|
+
return opts.hyphenator.points(text.slice(start, end), lang, { left, right }).map((p) => start + p);
|
|
142
|
+
};
|
|
143
|
+
/** Where the browser starts each line but the first, when the lines are its own. */
|
|
144
|
+
const lineStarts = browser ? browserLineStarts(text, segments, atoms, words(text, atomAt).flatMap(([a, b]) => autoPoints(a, b))) : undefined;
|
|
145
|
+
let i = 0;
|
|
146
|
+
while (i < text.length) {
|
|
147
|
+
if (text[i] === ' ') {
|
|
148
|
+
// A space after a sentence is `--pw-xspace`, if set, as TeX's
|
|
149
|
+
// `\xspaceskip`; otherwise every space is a word space, as TeX's
|
|
150
|
+
// `\frenchspacing` has it.
|
|
151
|
+
const seg = segAt(i);
|
|
152
|
+
if (browser) {
|
|
153
|
+
// The browser's space, stretched in a justified line as the browser
|
|
154
|
+
// stretches it: every space alike.
|
|
155
|
+
push({ type: 'glue', width: seg.run.widthBetween(i, i + 1), stretch: justify ? 1 : 0, shrink: 0 }, { kind: 'space', at: i, segment: seg, sentence: false });
|
|
156
|
+
i++;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const word = seg.computed.getPropertyValue('--pw-word-space').trim() || DEFAULT_WORD_SPACE;
|
|
160
|
+
const x = seg.computed.getPropertyValue('--pw-xspace').trim();
|
|
161
|
+
const sentence = x !== '' && x !== word && endsSentence(text, i);
|
|
162
|
+
const spec = parseGlue(sentence ? x : word, seg.style.sizePx);
|
|
163
|
+
// Unjustified, a space keeps its natural width, as plain TeX's
|
|
164
|
+
// `\raggedright` makes `\spaceskip` and `\xspaceskip` rigid.
|
|
165
|
+
push({ type: 'glue', ...spec, ...(justify ? {} : { stretch: 0, shrink: 0, stretchOrder: 0 }) }, { kind: 'space', at: i, segment: seg, sentence });
|
|
166
|
+
i++;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (atomAt.get(i)?.leader) {
|
|
170
|
+
// A leader is `\nobreak\leaders\hbox{…}\hfill\nobreak`: no
|
|
171
|
+
// break before it, and none after, as no glue follows it.
|
|
172
|
+
push(penalty(INFINITE_PENALTY), { kind: 'leader', at: i });
|
|
173
|
+
push({ type: 'glue', width: 0, stretch: 1, shrink: 0, stretchOrder: 2 }, { kind: 'leader', at: i });
|
|
174
|
+
i++;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (atomAt.has(i)) {
|
|
178
|
+
// An atomic inline is a box of its own, with no break either side
|
|
179
|
+
// unless a space makes one.
|
|
180
|
+
push(box(atomAt.get(i).width), { kind: 'box', start: i, end: i + 1 });
|
|
181
|
+
i++;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const end = wordEnd(text, atomAt, i);
|
|
185
|
+
// Fragments of the word between its break opportunities: where the
|
|
186
|
+
// hyphenator would hyphenate it, or, in a word it leaves alone, at its
|
|
187
|
+
// soft and explicit hyphens.
|
|
188
|
+
let from = i;
|
|
189
|
+
for (const at of autoPoints(i, end)) {
|
|
190
|
+
push(box(widthOf(from, at)), { kind: 'box', start: from, end: at });
|
|
191
|
+
push(hyphenationPoint(breakWidth(measurer, segAt(at - 1), text.slice(i, end), at - i, '-'), hyphenPenalty), { kind: 'break', at, hyphen: '-', auto: true });
|
|
192
|
+
from = at;
|
|
193
|
+
}
|
|
194
|
+
const url = URL_START.test(text.slice(i, end));
|
|
195
|
+
for (let j = i; j < end; j++) {
|
|
196
|
+
const c = text[j];
|
|
197
|
+
if (url && j > from && urlBreakBefore(text, j, end)) {
|
|
198
|
+
// A URL may break before a slash or a full stop, as Chicago breaks one (14.18), with no hyphen added.
|
|
199
|
+
push(box(widthOf(from, j)), { kind: 'box', start: from, end: j });
|
|
200
|
+
push(penalty(exHyphenPenalty, breakWidth(measurer, segAt(j - 1), text.slice(i, end), j - i, ''), true), { kind: 'break', at: j, hyphen: '' });
|
|
201
|
+
from = j;
|
|
202
|
+
}
|
|
203
|
+
if (c === SOFT_HYPHEN && hyphensOf(segAt(j).computed) === 'none')
|
|
204
|
+
continue;
|
|
205
|
+
if (c === SOFT_HYPHEN || (EXPLICIT_HYPHENS.test(c) && j > i && j + 1 < end)) {
|
|
206
|
+
const after = j + 1;
|
|
207
|
+
push(box(widthOf(from, after)), { kind: 'box', start: from, end: after });
|
|
208
|
+
if (c === SOFT_HYPHEN) {
|
|
209
|
+
push(penalty(hyphenPenalty, breakWidth(measurer, segAt(j), text.slice(i, end), after - i, '-'), true), { kind: 'break', at: after, hyphen: '-' });
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
push(penalty(exHyphenPenalty, breakWidth(measurer, segAt(j), text.slice(i, end), after - i, ''), true), { kind: 'break', at: after, hyphen: '' });
|
|
213
|
+
}
|
|
214
|
+
from = after;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (from < end)
|
|
218
|
+
push(box(widthOf(from, end)), { kind: 'box', start: from, end });
|
|
219
|
+
i = end;
|
|
220
|
+
}
|
|
221
|
+
// The browser's lines break where it started a new one: at the glue or
|
|
222
|
+
// penalty before the box there, and, where the browser broke where the
|
|
223
|
+
// list has no break (after a dash it doesn't know, between ideographs),
|
|
224
|
+
// at a penalty put there.
|
|
225
|
+
const chosen = [];
|
|
226
|
+
if (lineStarts) {
|
|
227
|
+
const listed = items.splice(0);
|
|
228
|
+
const from = origins.splice(0);
|
|
229
|
+
for (const [k, item] of listed.entries()) {
|
|
230
|
+
const o = from[k];
|
|
231
|
+
if (o.kind !== 'box' || o.end <= o.start) {
|
|
232
|
+
push(item, o);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
let start = o.start;
|
|
236
|
+
for (const at of lineStarts) {
|
|
237
|
+
if (at < start || at >= o.end)
|
|
238
|
+
continue;
|
|
239
|
+
// Never just after a leader, which the browser didn't know.
|
|
240
|
+
if (at === start && from[k - 1]?.kind === 'leader')
|
|
241
|
+
continue;
|
|
242
|
+
if (at > start)
|
|
243
|
+
push(box(widthOf(start, at)), { kind: 'box', start, end: at });
|
|
244
|
+
// What the cut changes in a word's width is left out: a break the list didn't have is rare.
|
|
245
|
+
if (at > start || items.at(-1)?.type === 'box')
|
|
246
|
+
push(penalty(0), { kind: 'break', at, hyphen: '' });
|
|
247
|
+
chosen.push(items.length - 1);
|
|
248
|
+
start = at;
|
|
249
|
+
}
|
|
250
|
+
push(start === o.start ? item : box(widthOf(start, o.end)), { kind: 'box', start, end: o.end });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const finished = finishParagraph(items, skips.parFillSkip);
|
|
254
|
+
while (origins.length > finished.length - 3)
|
|
255
|
+
origins.pop();
|
|
256
|
+
origins.push({ kind: 'end' }, { kind: 'end' }, { kind: 'end' });
|
|
257
|
+
const breaks = lineStarts
|
|
258
|
+
? setLines(finished, chosen, { measure, leftSkip: skips.start, rightSkip: skips.end })
|
|
259
|
+
: (opts.lineBreaker?.(el) ?? breakLines)(finished, { measure, ...parameters(pcs), leftSkip: skips.start, rightSkip: skips.end });
|
|
260
|
+
/** Whether line `n` fills its measure: a justified line, not left at its natural width. */
|
|
261
|
+
const fills = (n) => justify && breaks.lines[n].glueOrder === 0;
|
|
262
|
+
// Each leader as wide as its line set its glue: what the line's widths below count it as.
|
|
263
|
+
const leaderLines = new Map();
|
|
264
|
+
for (const [n, line] of breaks.lines.entries()) {
|
|
265
|
+
for (let k = line.start; k < line.end; k++) {
|
|
266
|
+
const o = origins[k];
|
|
267
|
+
const item = finished[k];
|
|
268
|
+
if (o.kind !== 'leader' || item.type !== 'glue')
|
|
269
|
+
continue;
|
|
270
|
+
const atom = atomAt.get(o.at);
|
|
271
|
+
atom.width = item.width + (line.ratio > 0 && (item.stretchOrder ?? 0) === line.glueOrder ? line.ratio * item.stretch : 0);
|
|
272
|
+
leaderLines.set(atom, n);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* A Chromium line with spaces after sentences, which are spans of their
|
|
277
|
+
* own: Chromium shapes each run of text between element boundaries apart
|
|
278
|
+
* and lays it out at its width rounded up to its 1/64 px layout unit, so
|
|
279
|
+
* each span costs the kerning across it and a rounding either side. The
|
|
280
|
+
* runs are measured as Chromium will set them, and each span is given
|
|
281
|
+
* the width that puts its end where the engine set it, rounded, the
|
|
282
|
+
* last one the width that puts the line's end on `target`, a justified
|
|
283
|
+
* line's measure. Returns where the line ends.
|
|
284
|
+
*/
|
|
285
|
+
const setSentenceSpaces = (l, indent, target) => {
|
|
286
|
+
const ceil = (v) => Math.ceil(v * 64 - 1e-6) / 64;
|
|
287
|
+
const round = (v) => Math.round(v * 64) / 64;
|
|
288
|
+
let common = 0;
|
|
289
|
+
for (const [at, v] of l.spacing)
|
|
290
|
+
if (!l.sentences.has(at))
|
|
291
|
+
common = v;
|
|
292
|
+
/** The width of the runs from `a` to `b` as Chromium lays them out, each alone and rounded up. */
|
|
293
|
+
const runs = (a, b, hyphen = '') => {
|
|
294
|
+
let w = 0;
|
|
295
|
+
const parts = segments.filter((s) => s.end > a && s.start < b);
|
|
296
|
+
for (const [i, s] of parts.entries()) {
|
|
297
|
+
const t = text.slice(Math.max(a, s.start), Math.min(b, s.end)) + (i === parts.length - 1 ? hyphen : '');
|
|
298
|
+
w += ceil(measurer.shape(s.font, t, { ...s.style, wordSpacingPx: common }).width);
|
|
299
|
+
}
|
|
300
|
+
for (const atom of atoms)
|
|
301
|
+
if (atom.at >= a && atom.at < b)
|
|
302
|
+
w += atom.width;
|
|
303
|
+
return w;
|
|
304
|
+
};
|
|
305
|
+
const spaces = [...l.sentences.keys()].sort((x, y) => x - y);
|
|
306
|
+
let pos = round(indent);
|
|
307
|
+
let ideal = indent;
|
|
308
|
+
let from = l.start;
|
|
309
|
+
for (const [j, at] of spaces.entries()) {
|
|
310
|
+
pos += runs(from, at);
|
|
311
|
+
// Where the engine set the span's end: the words, the word spaces as set, then the span.
|
|
312
|
+
let k = from;
|
|
313
|
+
for (const [sp, v] of l.spacing) {
|
|
314
|
+
if (sp < from || sp >= at)
|
|
315
|
+
continue;
|
|
316
|
+
ideal += widthOf(k, sp) + spaceWidth(sp) + v;
|
|
317
|
+
k = sp + 1;
|
|
318
|
+
}
|
|
319
|
+
ideal += widthOf(k, at) + l.sentences.get(at);
|
|
320
|
+
const end = j === spaces.length - 1 && target !== undefined ? round(target) - runs(at + 1, l.end, l.hyphen) : round(ideal);
|
|
321
|
+
const seg = segAt(at);
|
|
322
|
+
const glyph = measurer.shape(seg.font, ' ', { ...seg.style, wordSpacingPx: 0 }).width;
|
|
323
|
+
// A little under, so the width rounds up to the unit meant.
|
|
324
|
+
l.spacing.set(at, end - pos - glyph - 1 / 256);
|
|
325
|
+
pos = end;
|
|
326
|
+
from = at + 1;
|
|
327
|
+
}
|
|
328
|
+
return pos + runs(from, l.end, l.hyphen);
|
|
329
|
+
};
|
|
330
|
+
// Where each line's text starts and ends, and how each space on it is set.
|
|
331
|
+
const lines = [];
|
|
332
|
+
for (const line of breaks.lines) {
|
|
333
|
+
let start = text.length;
|
|
334
|
+
for (let k = line.start; k <= line.end && k < origins.length; k++) {
|
|
335
|
+
const o = origins[k];
|
|
336
|
+
if (o.kind === 'box' && o.end > o.start) {
|
|
337
|
+
start = o.start;
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (lines.length === 0)
|
|
342
|
+
start = 0;
|
|
343
|
+
const brk = origins[line.end];
|
|
344
|
+
const end = brk.kind === 'space' ? brk.at : brk.kind === 'break' ? brk.at : text.length;
|
|
345
|
+
const hyphen = line.hyphenated && brk.kind === 'break' ? brk.hyphen : '';
|
|
346
|
+
// Each space's word-spacing: its glue as set, less what the browser
|
|
347
|
+
// gives a space anyway.
|
|
348
|
+
const spacing = new Map();
|
|
349
|
+
// Spaces after a sentence, and the width each is set to.
|
|
350
|
+
const sentences = new Map();
|
|
351
|
+
for (let k = line.start; k < line.end; k++) {
|
|
352
|
+
const o = origins[k];
|
|
353
|
+
const item = finished[k];
|
|
354
|
+
if (o.kind !== 'space' || item.type !== 'glue')
|
|
355
|
+
continue;
|
|
356
|
+
const order = item.stretchOrder ?? 0;
|
|
357
|
+
let set = item.width;
|
|
358
|
+
if (line.ratio > 0 && order === line.glueOrder)
|
|
359
|
+
set += line.ratio * item.stretch;
|
|
360
|
+
else if (line.ratio < 0)
|
|
361
|
+
set += line.ratio * item.shrink;
|
|
362
|
+
if (o.sentence)
|
|
363
|
+
sentences.set(o.at, set);
|
|
364
|
+
spacing.set(o.at, set - spaceWidth(o.at));
|
|
365
|
+
}
|
|
366
|
+
// A break inside a word adds what its penalty's width says: the hyphen,
|
|
367
|
+
// and what cutting the word there changes.
|
|
368
|
+
const brokenAt = finished[line.end];
|
|
369
|
+
const breakAdds = brk.kind === 'break' && brokenAt.type === 'penalty' ? brokenAt.width : 0;
|
|
370
|
+
lines.push({ start, end, hyphen, auto: !!hyphen && brk.kind === 'break' && !!brk.auto, spacing, sentences, width: breakAdds });
|
|
371
|
+
}
|
|
372
|
+
// Chromium shapes across a space only within one element, so a span
|
|
373
|
+
// around a space would lose its kerning (fonts kern against the space):
|
|
374
|
+
// a line's word spaces share one word-spacing there, which keeps their
|
|
375
|
+
// total, and so the line's right edge, exact; only a space after a
|
|
376
|
+
// sentence, set wider, gets a span. Firefox rounds spacing to app units,
|
|
377
|
+
// and a span changes nothing there, so the remainder of a justified line
|
|
378
|
+
// goes one unit at a time to spaces of their own.
|
|
379
|
+
const unit = model.advanceUnit;
|
|
380
|
+
if (!unit) {
|
|
381
|
+
for (const l of lines) {
|
|
382
|
+
const words = [...l.spacing.keys()].filter((at) => !l.sentences.has(at));
|
|
383
|
+
let sum = 0;
|
|
384
|
+
for (const at of words)
|
|
385
|
+
sum += l.spacing.get(at);
|
|
386
|
+
for (const at of words)
|
|
387
|
+
l.spacing.set(at, sum / words.length);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
for (const [n, l] of lines.entries()) {
|
|
391
|
+
const brLine = breaks.lines[n];
|
|
392
|
+
if (!unit && l.sentences.size) {
|
|
393
|
+
l.width = setSentenceSpaces(l, n === 0 ? indent : 0, fills(n) ? brLine.measure : undefined);
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
let natural = l.width;
|
|
397
|
+
let k = l.start;
|
|
398
|
+
for (const [at, s] of l.spacing) {
|
|
399
|
+
natural += widthOf(k, at) + spaceWidth(at);
|
|
400
|
+
const applied = appliedSpacing(model, s);
|
|
401
|
+
natural += applied;
|
|
402
|
+
l.spacing.set(at, applied);
|
|
403
|
+
k = at + 1;
|
|
404
|
+
}
|
|
405
|
+
natural += widthOf(k, l.end) + (n === 0 ? indent : 0);
|
|
406
|
+
const justified = fills(n) && l.spacing.size > 0;
|
|
407
|
+
if (unit && justified) {
|
|
408
|
+
let units = Math.round((brLine.measure - natural) / unit);
|
|
409
|
+
const spaces = [...l.spacing.keys()];
|
|
410
|
+
for (let s = 0; units !== 0 && s < spaces.length * 4; s++) {
|
|
411
|
+
const at = spaces[s % spaces.length];
|
|
412
|
+
const step = Math.sign(units) * unit;
|
|
413
|
+
l.spacing.set(at, l.spacing.get(at) + step);
|
|
414
|
+
natural += step;
|
|
415
|
+
units -= Math.sign(units);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
l.width = natural;
|
|
419
|
+
}
|
|
420
|
+
// The spacing a line's own word-spacing gives; any other space gets a span.
|
|
421
|
+
const commons = lines.map((l) => {
|
|
422
|
+
if (unit)
|
|
423
|
+
return mostCommon([...l.spacing.values()]);
|
|
424
|
+
for (const [at, v] of l.spacing)
|
|
425
|
+
if (!l.sentences.has(at))
|
|
426
|
+
return v;
|
|
427
|
+
return undefined;
|
|
428
|
+
});
|
|
429
|
+
const { elements, hyphens } = render(el, segments, atoms, lines.map((l) => ({ start: l.start, end: l.end, hyphen: l.hyphen })), lines.map((l) => l.spacing), commons, lineShape, indent);
|
|
430
|
+
setLeaders(el, pcs, [...leaderLines.keys()]);
|
|
431
|
+
// Firefox's model leaves a few advances rounded the other way (#4's
|
|
432
|
+
// unmodelled cases), so each justified line is read back once and its
|
|
433
|
+
// spacing corrected by whole app units, as the plan allows
|
|
434
|
+
// (https://plans.inkylabs.com/pulpweaver#measuring-text).
|
|
435
|
+
if (model.engine === 'firefox' && unit) {
|
|
436
|
+
for (const [n, l] of lines.entries()) {
|
|
437
|
+
const brLine = breaks.lines[n];
|
|
438
|
+
const line = elements[n];
|
|
439
|
+
const width = textWidth(line) + (n === 0 ? indent : 0);
|
|
440
|
+
if (!fills(n) || !l.spacing.size) {
|
|
441
|
+
// A line left at its natural width ends where the browser put it.
|
|
442
|
+
l.width = width;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
const units = Math.round((brLine.measure - width) / unit);
|
|
446
|
+
l.width = width + (units ? spreadUnits(line, units, unit) : 0);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
// Each line not filling its measure is placed in it as the skips at its
|
|
450
|
+
// ends would set it (the last line by `text-align-last`): its share of
|
|
451
|
+
// the room left goes before its text as padding, so the line's block stays
|
|
452
|
+
// the measure wide, as TeX's line holds its `\leftskip`. None of it is
|
|
453
|
+
// left to the browser's own alignment, which rounds otherwise.
|
|
454
|
+
const rtl = pcs.direction === 'rtl';
|
|
455
|
+
for (const [n, l] of lines.entries()) {
|
|
456
|
+
const a = n === lines.length - 1 ? align.last : align.body;
|
|
457
|
+
const k = a === 'end' ? 1 : a === 'center' ? 0.5 : 0;
|
|
458
|
+
const skip = Math.max(0, breaks.lines[n].measure - l.width) * k;
|
|
459
|
+
// A line with a leader fills its measure, whatever its alignment.
|
|
460
|
+
if (!skip || fills(n) || [...leaderLines.values()].includes(n))
|
|
461
|
+
continue;
|
|
462
|
+
const style = elements[n].style;
|
|
463
|
+
const side = rtl ? 'paddingRight' : 'paddingLeft';
|
|
464
|
+
style.width = `${Number.parseFloat(style.width) - skip}px`;
|
|
465
|
+
style[side] = `${(Number.parseFloat(style[side]) || 0) + skip}px`;
|
|
466
|
+
}
|
|
467
|
+
// The line a migrated element was on: a removed one's, the line of the
|
|
468
|
+
// character before it, so a footnote stays with its call.
|
|
469
|
+
const lineOf = (offset) => {
|
|
470
|
+
let n = 0;
|
|
471
|
+
while (n + 1 < lines.length && lines[n + 1].start <= offset)
|
|
472
|
+
n++;
|
|
473
|
+
return n;
|
|
474
|
+
};
|
|
475
|
+
const migrated = anchors.map((m) => ({ ...m, line: lineOf(m.removed ? Math.max(0, m.offset - 1) : m.offset) }));
|
|
476
|
+
return {
|
|
477
|
+
text,
|
|
478
|
+
items: finished,
|
|
479
|
+
breaks,
|
|
480
|
+
migrated,
|
|
481
|
+
lines: lines.map((l, n) => ({
|
|
482
|
+
start: l.start, end: l.end, measure: breaks.lines[n].measure, ratio: breaks.lines[n].ratio,
|
|
483
|
+
hyphenated: l.hyphen !== '', width: l.width, element: elements[n],
|
|
484
|
+
...(hyphens[n] ? { hyphen: { text: l.hyphen, offset: l.end, auto: l.auto, element: hyphens[n] } } : {}),
|
|
485
|
+
})),
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
/** Where the word starting at `start` ends: at a space, an atomic inline, or the text's end. */
|
|
489
|
+
function wordEnd(text, atomAt, start) {
|
|
490
|
+
let end = start;
|
|
491
|
+
while (end < text.length && text[end] !== ' ' && !atomAt.has(end))
|
|
492
|
+
end++;
|
|
493
|
+
return end;
|
|
494
|
+
}
|
|
495
|
+
/** The paragraph's words, as `[start, end)` offsets in its text. */
|
|
496
|
+
function words(text, atomAt) {
|
|
497
|
+
const out = [];
|
|
498
|
+
for (let i = 0; i < text.length;) {
|
|
499
|
+
if (text[i] === ' ' || atomAt.has(i)) {
|
|
500
|
+
i++;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
const end = wordEnd(text, atomAt, i);
|
|
504
|
+
out.push([i, end]);
|
|
505
|
+
i = end;
|
|
506
|
+
}
|
|
507
|
+
return out;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Where the browser starts each line of a paragraph but the first, as
|
|
511
|
+
* offsets in its text, in order: read from where it puts each character
|
|
512
|
+
* and atomic inline, as the painter reads text the browser laid out. A line
|
|
513
|
+
* starts at a character whose middle is lower than the last one's by more
|
|
514
|
+
* than half the taller one's height, which a superscript, a subscript or a
|
|
515
|
+
* tall inline never is. While it is read, the browser has the engine's
|
|
516
|
+
* hyphenation `points` as soft hyphens, and its own hyphenation off.
|
|
517
|
+
*/
|
|
518
|
+
function browserLineStarts(text, segments, atoms, points) {
|
|
519
|
+
const restore = [];
|
|
520
|
+
/** For each segment, the text offset of each character of its node as read, or -1 for an inserted soft hyphen. */
|
|
521
|
+
const offsets = new Map();
|
|
522
|
+
const styled = new Set();
|
|
523
|
+
const wanted = new Set(points);
|
|
524
|
+
try {
|
|
525
|
+
for (const s of segments) {
|
|
526
|
+
const data = s.node.data;
|
|
527
|
+
const map = [];
|
|
528
|
+
let out = '';
|
|
529
|
+
for (let k = 0; k < data.length; k++) {
|
|
530
|
+
if (k > 0 && wanted.has(s.start + k)) {
|
|
531
|
+
out += SOFT_HYPHEN;
|
|
532
|
+
map.push(-1);
|
|
533
|
+
}
|
|
534
|
+
out += data[k];
|
|
535
|
+
map.push(s.start + k);
|
|
536
|
+
}
|
|
537
|
+
// A point between two elements' text goes at the end of the first's.
|
|
538
|
+
if (wanted.has(s.end)) {
|
|
539
|
+
out += SOFT_HYPHEN;
|
|
540
|
+
map.push(-1);
|
|
541
|
+
}
|
|
542
|
+
offsets.set(s, map);
|
|
543
|
+
if (out !== data) {
|
|
544
|
+
s.node.data = out;
|
|
545
|
+
restore.push(() => { s.node.data = data; });
|
|
546
|
+
}
|
|
547
|
+
const e = s.element;
|
|
548
|
+
if (hyphensOf(s.computed) === 'auto' && !styled.has(e)) {
|
|
549
|
+
styled.add(e);
|
|
550
|
+
const style = e.getAttribute('style');
|
|
551
|
+
e.style.setProperty('hyphens', 'manual', 'important');
|
|
552
|
+
e.style.setProperty('-webkit-hyphens', 'manual', 'important');
|
|
553
|
+
restore.push(() => (style === null ? e.removeAttribute('style') : e.setAttribute('style', style)));
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const pieces = [
|
|
557
|
+
...segments.map((s) => ({ at: s.start, segment: s })),
|
|
558
|
+
...atoms.map((a) => ({ at: a.at, atom: a })),
|
|
559
|
+
].sort((a, b) => a.at - b.at);
|
|
560
|
+
const starts = [];
|
|
561
|
+
let last;
|
|
562
|
+
const see = (offset, rect) => {
|
|
563
|
+
if (rect.height <= 0)
|
|
564
|
+
return;
|
|
565
|
+
if (last && rect.top + rect.bottom - last.top - last.bottom > Math.max(rect.height, last.height))
|
|
566
|
+
starts.push(offset);
|
|
567
|
+
last = rect;
|
|
568
|
+
};
|
|
569
|
+
const range = document.createRange();
|
|
570
|
+
for (const piece of pieces) {
|
|
571
|
+
if ('atom' in piece) {
|
|
572
|
+
see(piece.at, piece.atom.element.getBoundingClientRect());
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
const s = piece.segment;
|
|
576
|
+
for (const [k, offset] of offsets.get(s).entries()) {
|
|
577
|
+
if (offset < 0)
|
|
578
|
+
continue;
|
|
579
|
+
range.setStart(s.node, k);
|
|
580
|
+
range.setEnd(s.node, k + 1);
|
|
581
|
+
// Chromium gives the hyphen it draws at a soft hyphen a box of its
|
|
582
|
+
// own, which a range over the next character returns first.
|
|
583
|
+
const rect = [...range.getClientRects()].at(-1);
|
|
584
|
+
if (rect)
|
|
585
|
+
see(offset, rect);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
// A line starts after the space that ends the last, wherever the browser puts that.
|
|
589
|
+
return [...new Set(starts.map((at) => (text[at] === ' ' ? at + 1 : at)))].filter((at) => at < text.length);
|
|
590
|
+
}
|
|
591
|
+
finally {
|
|
592
|
+
for (const r of restore.reverse())
|
|
593
|
+
r();
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* What breaking a word `cut` characters in adds to the line it ends: the
|
|
598
|
+
* hyphen, if one is inserted, and the change from cutting the word, whose
|
|
599
|
+
* last letter before the cut no longer kerns (or forms a ligature) with the
|
|
600
|
+
* next, since the browser shapes each line's text apart. The hyphen kerns
|
|
601
|
+
* with the letter before it, though it is a span of its own: both Chromium
|
|
602
|
+
* and Firefox were measured shaping across that boundary.
|
|
603
|
+
*/
|
|
604
|
+
function breakWidth(measurer, seg, word, cut, hyphen) {
|
|
605
|
+
const atEnd = measurer.shape(seg.font, word.slice(0, cut) + hyphen, seg.style).width;
|
|
606
|
+
return atEnd - measurer.shape(seg.font, word, seg.style).widthBetween(0, cut);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Whether the space at `at` follows a sentence, as TeX's space factor
|
|
610
|
+
* decides: after `.`, `?`, `!` or `:` (factor 2000 or more), looking through
|
|
611
|
+
* closing brackets and quotes, but not after a capital letter (factor 999:
|
|
612
|
+
* “J. S. Bach”).
|
|
613
|
+
*/
|
|
614
|
+
export function endsSentence(text, at) {
|
|
615
|
+
let j = at - 1;
|
|
616
|
+
while (j >= 0 && CLOSERS.test(text[j]))
|
|
617
|
+
j--;
|
|
618
|
+
if (j < 0 || !'.?!:'.includes(text[j]))
|
|
619
|
+
return false;
|
|
620
|
+
const before = [...text.slice(Math.max(0, j - 2), j)].at(-1) ?? '';
|
|
621
|
+
return !/\p{Lu}/u.test(before);
|
|
622
|
+
}
|
|
623
|
+
/** A paragraph's `text-align` and `text-align-last`, `left` and `right` read in its direction. */
|
|
624
|
+
export function textAlignment(cs) {
|
|
625
|
+
const rtl = cs.direction === 'rtl';
|
|
626
|
+
const read = (v) => {
|
|
627
|
+
switch (v.replace(/^-(webkit|moz)-/, '')) {
|
|
628
|
+
case 'left': return rtl ? 'end' : 'start';
|
|
629
|
+
case 'right': return rtl ? 'start' : 'end';
|
|
630
|
+
case 'end': return 'end';
|
|
631
|
+
case 'center': return 'center';
|
|
632
|
+
case 'justify': return 'justify';
|
|
633
|
+
case 'start': return 'start';
|
|
634
|
+
default: return undefined;
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
const body = read(cs.textAlign) ?? 'start';
|
|
638
|
+
const last = read(cs.getPropertyValue('text-align-last')) ?? (body === 'justify' ? 'start' : body);
|
|
639
|
+
return { body, last };
|
|
640
|
+
}
|
|
641
|
+
/** Plain TeX's `\raggedright`: `\rightskip` 0pt plus 2em. */
|
|
642
|
+
const RAGGED_STRETCH = 2;
|
|
643
|
+
/**
|
|
644
|
+
* TeX's glue at the start and end of every line, and `\parfillskip`, for an
|
|
645
|
+
* alignment. Justified, there is none, and `\parfillskip` is TeX's own
|
|
646
|
+
* unless the last line is justified too. Ragged right is plain TeX's
|
|
647
|
+
* `\raggedright`, finite stretch, so the breaker evens the rag; ragged left
|
|
648
|
+
* and centred are LaTeX's `\raggedleft` and `\centering`, `fil` stretch at
|
|
649
|
+
* the start or both ends and none at the paragraph's end, so the last line
|
|
650
|
+
* is aligned as the others are.
|
|
651
|
+
*/
|
|
652
|
+
function alignmentSkips(align, fontSize) {
|
|
653
|
+
const none = { width: 0, stretch: 0, shrink: 0 };
|
|
654
|
+
const fil = { width: 0, stretch: 1, shrink: 0, stretchOrder: 1 };
|
|
655
|
+
switch (align.body) {
|
|
656
|
+
case 'justify': return { start: none, end: none, ...(align.last === 'justify' ? { parFillSkip: none } : {}) };
|
|
657
|
+
case 'start': return { start: none, end: { width: 0, stretch: RAGGED_STRETCH * fontSize, shrink: 0 } };
|
|
658
|
+
case 'end': return { start: fil, end: none, parFillSkip: none };
|
|
659
|
+
case 'center': return { start: fil, end: fil, parFillSkip: none };
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
/** TeX's paragraph parameters, from their custom properties. */
|
|
663
|
+
function parameters(cs) {
|
|
664
|
+
const fontSize = Number.parseFloat(cs.fontSize);
|
|
665
|
+
const out = {};
|
|
666
|
+
const ints = [
|
|
667
|
+
['--pw-tolerance', 'tolerance'], ['--pw-pretolerance', 'pretolerance'], ['--pw-line-penalty', 'linePenalty'],
|
|
668
|
+
['--pw-adj-demerits', 'adjDemerits'], ['--pw-double-hyphen-demerits', 'doubleHyphenDemerits'],
|
|
669
|
+
['--pw-final-hyphen-demerits', 'finalHyphenDemerits'], ['--pw-looseness', 'looseness'],
|
|
670
|
+
];
|
|
671
|
+
for (const [prop, key] of ints) {
|
|
672
|
+
const v = cs.getPropertyValue(prop).trim();
|
|
673
|
+
if (v)
|
|
674
|
+
out[key] = Number.parseInt(v, 10);
|
|
675
|
+
}
|
|
676
|
+
const es = cs.getPropertyValue('--pw-emergency-stretch').trim();
|
|
677
|
+
if (es)
|
|
678
|
+
out.emergencyStretch = parseLength(es, fontSize);
|
|
679
|
+
return out;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* CSS's `hyphens`: `auto` hyphenates where the patterns allow, `manual`
|
|
683
|
+
* (its initial value) only at soft hyphens, and `none` nowhere, not even at
|
|
684
|
+
* a soft hyphen. A break after an explicit hyphen isn't hyphenation, and
|
|
685
|
+
* none of them stops it.
|
|
686
|
+
*/
|
|
687
|
+
function hyphensOf(cs) {
|
|
688
|
+
const v = cs.getPropertyValue('hyphens') || cs.getPropertyValue('-webkit-hyphens');
|
|
689
|
+
return v === 'auto' || v === 'none' ? v : 'manual';
|
|
690
|
+
}
|
|
691
|
+
function intProperty(cs, prop, fallback) {
|
|
692
|
+
const v = cs.getPropertyValue(prop).trim();
|
|
693
|
+
return v ? Number.parseInt(v, 10) : fallback;
|
|
694
|
+
}
|
|
695
|
+
function contentWidth(el, cs) {
|
|
696
|
+
const w = el.getBoundingClientRect().width;
|
|
697
|
+
const px = (p) => Number.parseFloat(cs.getPropertyValue(p)) || 0;
|
|
698
|
+
return w - px('padding-left') - px('padding-right') - px('border-left-width') - px('border-right-width');
|
|
699
|
+
}
|
|
700
|
+
/** Replaced elements, which are atomic inlines whatever their `display`. */
|
|
701
|
+
const REPLACED = new Set(['img', 'svg', 'math', 'video', 'canvas', 'iframe', 'object', 'embed', 'input', 'select', 'textarea', 'button', 'audio']);
|
|
702
|
+
/** Whether an element in a paragraph is an atomic inline: a box the browser lays out, which the engine doesn't look inside. */
|
|
703
|
+
export function isAtomicInline(el, cs) {
|
|
704
|
+
if (REPLACED.has(el.localName))
|
|
705
|
+
return true;
|
|
706
|
+
const display = cs.display;
|
|
707
|
+
// Chromium gives inline MathML's `display: inline math` as `math`.
|
|
708
|
+
return /^inline[- ](block|flex|grid|table|flow-root)$/.test(display) || display === 'inline math' || display === 'math';
|
|
709
|
+
}
|
|
710
|
+
/** TeX's `\@dotsep`, 4.5mu: the space either side of a leader's text when `--pw-leader-space` is unset. */
|
|
711
|
+
const LEADER_SPACE = '0.25em';
|
|
712
|
+
/** Whether an element in a paragraph is a leader: its `--pw-leader` is set, even to `none`. */
|
|
713
|
+
function isLeader(cs) {
|
|
714
|
+
return cs.getPropertyValue('--pw-leader').trim() !== '';
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* A leader's box, from its element's style: `--pw-leader`'s string (`"."`;
|
|
718
|
+
* `none` for blank glue, as `\hfill`), with `--pw-leader-space` either side,
|
|
719
|
+
* measured in the element's font.
|
|
720
|
+
*/
|
|
721
|
+
function leaderOf(el, cs, opts) {
|
|
722
|
+
const raw = cs.getPropertyValue('--pw-leader').trim();
|
|
723
|
+
const quoted = /^(["'])(.*)\1$/.exec(raw);
|
|
724
|
+
const text = quoted ? quoted[2].replace(/\\(.)/g, '$1') : '';
|
|
725
|
+
const fontSize = Number.parseFloat(cs.fontSize);
|
|
726
|
+
const space = parseLength(cs.getPropertyValue('--pw-leader-space').trim() || LEADER_SPACE, fontSize);
|
|
727
|
+
if (!text)
|
|
728
|
+
return { text, space, textWidth: 0, box: 0, spaceWidth: 0 };
|
|
729
|
+
const { fonts } = opts;
|
|
730
|
+
const font = fonts.lookup(cs.fontFamily, cs) ?? fonts.fallback();
|
|
731
|
+
if (!font)
|
|
732
|
+
throw new Error(`no font registered for font-family ${cs.fontFamily}`);
|
|
733
|
+
const style = fontStyleFromComputed(cs, el.closest('[lang]')?.getAttribute('lang') ?? '');
|
|
734
|
+
style.setSizePx = calibrateSize(fonts.measurer, el, font, style, text);
|
|
735
|
+
const plain = { ...style, letterSpacingPx: 0, wordSpacingPx: 0 };
|
|
736
|
+
const textWidth = fonts.measurer.shape(font, text, plain).width;
|
|
737
|
+
const spaceWidth = fonts.measurer.shape(font, ' ', plain).width;
|
|
738
|
+
return { text, space, textWidth, box: textWidth + 2 * space, spaceWidth };
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Sets each leader, its line broken, as TeX's `\leaders` sets its box: an
|
|
742
|
+
* inline block as wide as its glue was set, holding a copy of its text for
|
|
743
|
+
* each multiple of the box's width from the paragraph's edge (its padding
|
|
744
|
+
* box's, where TeX's line starts with `\leftskip`) whose box fits inside
|
|
745
|
+
* it, each copy centred in its box; the room before the first and after
|
|
746
|
+
* the last is left blank. The copies are text, a space between each two,
|
|
747
|
+
* so the painter paints them as it paints any text.
|
|
748
|
+
*/
|
|
749
|
+
function setLeaders(paragraph, pcs, atoms) {
|
|
750
|
+
if (!atoms.length)
|
|
751
|
+
return;
|
|
752
|
+
const rtl = pcs.direction === 'rtl';
|
|
753
|
+
for (const atom of atoms) {
|
|
754
|
+
const el = atom.element;
|
|
755
|
+
el.replaceChildren();
|
|
756
|
+
el.style.cssText += `;display:inline-block;box-sizing:border-box;width:${Math.max(0, atom.width)}px;` +
|
|
757
|
+
'margin:0;padding:0;border:0;white-space:pre;text-indent:0;letter-spacing:0;font-kerning:none';
|
|
758
|
+
}
|
|
759
|
+
// Read every place before any is written.
|
|
760
|
+
const edge = paragraph.getBoundingClientRect();
|
|
761
|
+
const px = (p) => Number.parseFloat(pcs.getPropertyValue(p)) || 0;
|
|
762
|
+
const origin = rtl ? edge.right - px('border-right-width') : edge.left + px('border-left-width');
|
|
763
|
+
const places = atoms.map((atom) => {
|
|
764
|
+
const r = atom.element.getBoundingClientRect();
|
|
765
|
+
return rtl ? origin - r.right : r.left - origin;
|
|
766
|
+
});
|
|
767
|
+
for (const [i, atom] of atoms.entries()) {
|
|
768
|
+
const leader = atom.leader;
|
|
769
|
+
if (!leader.text || leader.box <= 0)
|
|
770
|
+
continue;
|
|
771
|
+
const x = places[i];
|
|
772
|
+
const first = Math.ceil(x / leader.box - 1e-6);
|
|
773
|
+
const count = Math.floor((x + atom.width) / leader.box + 1e-6) - first;
|
|
774
|
+
if (count <= 0)
|
|
775
|
+
continue;
|
|
776
|
+
const el = atom.element;
|
|
777
|
+
el.style.paddingInlineStart = `${first * leader.box - x + leader.space}px`;
|
|
778
|
+
el.style.wordSpacing = `${leader.box - leader.textWidth - leader.spaceWidth}px`;
|
|
779
|
+
el.textContent = Array.from({ length: count }, () => leader.text).join(' ');
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* The paragraph's text nodes and atomic inlines, whitespace collapsed as
|
|
784
|
+
* `white-space: normal` collapses it (written back into the nodes), each
|
|
785
|
+
* text shaped in the context of the whole paragraph, and the elements that
|
|
786
|
+
* migrate out of it, taken out if they go.
|
|
787
|
+
*/
|
|
788
|
+
function collect(el, opts) {
|
|
789
|
+
const { fonts } = opts;
|
|
790
|
+
const pieces = [];
|
|
791
|
+
const anchors = [];
|
|
792
|
+
const atomic = new Set();
|
|
793
|
+
const walk = (parent) => {
|
|
794
|
+
for (const child of [...parent.childNodes]) {
|
|
795
|
+
if (child.nodeType === Node.TEXT_NODE) {
|
|
796
|
+
pieces.push(child);
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
if (child.nodeType !== Node.ELEMENT_NODE)
|
|
800
|
+
continue;
|
|
801
|
+
const e = child;
|
|
802
|
+
const cs = getComputedStyle(e);
|
|
803
|
+
if (cs.display === 'none')
|
|
804
|
+
continue;
|
|
805
|
+
const how = opts.migrate?.(e, cs);
|
|
806
|
+
if (how)
|
|
807
|
+
anchors.push({ element: e, piece: pieces.length, removed: how !== 'keep' });
|
|
808
|
+
if (how === 'remove') {
|
|
809
|
+
e.remove();
|
|
810
|
+
}
|
|
811
|
+
else if (how === 'hold') {
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
else if (isLeader(cs)) {
|
|
815
|
+
pieces.push(e);
|
|
816
|
+
atomic.add(e);
|
|
817
|
+
}
|
|
818
|
+
else if (isAtomicInline(e, cs)) {
|
|
819
|
+
pieces.push(e);
|
|
820
|
+
atomic.add(e);
|
|
821
|
+
}
|
|
822
|
+
else {
|
|
823
|
+
walk(e);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
walk(el);
|
|
828
|
+
// An atomic inline is like a letter to collapsing: spaces either side stay.
|
|
829
|
+
let lastWasSpace = true;
|
|
830
|
+
for (const piece of pieces) {
|
|
831
|
+
if (!(piece instanceof Text)) {
|
|
832
|
+
lastWasSpace = false;
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
let out = '';
|
|
836
|
+
for (const c of piece.data.replace(/[\t\n\r\f ]+/g, ' ')) {
|
|
837
|
+
if (c === ' ' && lastWasSpace)
|
|
838
|
+
continue;
|
|
839
|
+
out += c;
|
|
840
|
+
lastWasSpace = c === ' ';
|
|
841
|
+
}
|
|
842
|
+
piece.data = out;
|
|
843
|
+
}
|
|
844
|
+
for (let n = pieces.length - 1; n >= 0; n--) {
|
|
845
|
+
const piece = pieces[n];
|
|
846
|
+
if (!(piece instanceof Text) || (!piece.data.endsWith(' ') && piece.data))
|
|
847
|
+
break;
|
|
848
|
+
piece.data = piece.data.trimEnd();
|
|
849
|
+
}
|
|
850
|
+
const text = pieces.map((p) => (p instanceof Text ? p.data : OBJECT_REPLACEMENT)).join('');
|
|
851
|
+
const segments = [];
|
|
852
|
+
const atoms = [];
|
|
853
|
+
const starts = [];
|
|
854
|
+
let offset = 0;
|
|
855
|
+
for (const piece of pieces) {
|
|
856
|
+
const start = offset;
|
|
857
|
+
starts.push(start);
|
|
858
|
+
if (!(piece instanceof Text)) {
|
|
859
|
+
offset++;
|
|
860
|
+
const cs = getComputedStyle(piece);
|
|
861
|
+
if (isLeader(cs)) {
|
|
862
|
+
atoms.push({ at: start, element: piece, width: 0, leader: leaderOf(piece, cs, opts) });
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
const margins = (Number.parseFloat(cs.marginLeft) || 0) + (Number.parseFloat(cs.marginRight) || 0);
|
|
866
|
+
atoms.push({ at: start, element: piece, width: piece.getBoundingClientRect().width + margins });
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
offset += piece.data.length;
|
|
870
|
+
if (start === offset)
|
|
871
|
+
continue;
|
|
872
|
+
const element = piece.parentElement;
|
|
873
|
+
const computed = getComputedStyle(element);
|
|
874
|
+
// A family the project lacks is the `fonts` rule's problem; the paragraph is set in a face it has.
|
|
875
|
+
const font = fonts.lookup(computed.fontFamily, computed) ?? (opts.givenFontsOnly ? undefined : fonts.fallback());
|
|
876
|
+
if (!font)
|
|
877
|
+
throw new Error(`no font registered for font-family ${computed.fontFamily}`);
|
|
878
|
+
const style = fontStyleFromComputed(computed, element.closest('[lang]')?.getAttribute('lang') ?? '');
|
|
879
|
+
style.setSizePx = calibrateSize(fonts.measurer, element, font, style, text.slice(start, offset));
|
|
880
|
+
const run = fonts.measurer.shape(font, text, style, { start, end: offset });
|
|
881
|
+
segments.push({ node: piece, start, end: offset, style, font, run, element, computed });
|
|
882
|
+
}
|
|
883
|
+
starts.push(offset);
|
|
884
|
+
if (!segments.length && !atoms.length)
|
|
885
|
+
throw new Error('a paragraph with no text');
|
|
886
|
+
if (!segments.length)
|
|
887
|
+
throw new Error('a paragraph of atomic inlines alone: it needs text, for its font');
|
|
888
|
+
const migrated = anchors.map((a) => ({ element: a.element, offset: starts[a.piece], removed: a.removed }));
|
|
889
|
+
return { segments, atoms, text, migrated };
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Moves each line's content into a block of its own, cloning the inline
|
|
893
|
+
* elements a line breaks inside, and sets its spacing. Returns the lines and
|
|
894
|
+
* the hyphen spans it inserted, by line.
|
|
895
|
+
*/
|
|
896
|
+
function render(el, segments, atoms, lines, spacing, commons, shapeOf, indent) {
|
|
897
|
+
// Each inline element is marked, so its pieces (the clones a range's
|
|
898
|
+
// extraction makes of an element it cuts, and those made here of one a
|
|
899
|
+
// line lies inside) can be found and joined afterwards.
|
|
900
|
+
let marked = 0;
|
|
901
|
+
for (const e of el.querySelectorAll('*')) {
|
|
902
|
+
if (!atoms.some((a) => a.element.contains(e)))
|
|
903
|
+
e.setAttribute(PIECE, String(marked++));
|
|
904
|
+
}
|
|
905
|
+
/** `range`'s content, in shallow clones of the inline elements it lies inside, outermost first. */
|
|
906
|
+
const extract = (range) => {
|
|
907
|
+
const inside = [];
|
|
908
|
+
const common = range.commonAncestorContainer;
|
|
909
|
+
for (let e = common.nodeType === Node.ELEMENT_NODE ? common : common.parentElement; e && e !== el; e = e.parentElement)
|
|
910
|
+
inside.push(e);
|
|
911
|
+
let content = range.extractContents();
|
|
912
|
+
for (const e of inside) {
|
|
913
|
+
const clone = e.cloneNode(false);
|
|
914
|
+
clone.append(content);
|
|
915
|
+
content = clone;
|
|
916
|
+
}
|
|
917
|
+
return content;
|
|
918
|
+
};
|
|
919
|
+
// Every boundary as a live range, made before the DOM changes: ranges
|
|
920
|
+
// follow the text through the splits that extracting lines makes. An
|
|
921
|
+
// atomic inline's offset is just before it, the next just after.
|
|
922
|
+
const at = (offset, length = 0) => {
|
|
923
|
+
const r = document.createRange();
|
|
924
|
+
const atom = atoms.find((a) => a.at === offset);
|
|
925
|
+
const seg = segments.find((s) => offset >= s.start && offset < s.end);
|
|
926
|
+
const after = atoms.find((a) => a.at === offset - 1);
|
|
927
|
+
if (atom) {
|
|
928
|
+
r.setStartBefore(atom.element);
|
|
929
|
+
r.collapse(true);
|
|
930
|
+
}
|
|
931
|
+
else if (!seg && after) {
|
|
932
|
+
r.setStartAfter(after.element);
|
|
933
|
+
r.collapse(true);
|
|
934
|
+
}
|
|
935
|
+
else {
|
|
936
|
+
const s = seg ?? segments.at(-1);
|
|
937
|
+
const o = Math.min(offset - s.start, s.node.length);
|
|
938
|
+
r.setStart(s.node, o);
|
|
939
|
+
r.setEnd(s.node, Math.min(o + length, s.node.length));
|
|
940
|
+
}
|
|
941
|
+
return r;
|
|
942
|
+
};
|
|
943
|
+
// The first line starts at the paragraph's own start, so an empty element
|
|
944
|
+
// before its text (an index term's mark, `[]{index="Cru|("}`) goes with it;
|
|
945
|
+
// one after its text is moved to the last line's end below.
|
|
946
|
+
const start = document.createRange();
|
|
947
|
+
start.selectNodeContents(el);
|
|
948
|
+
start.collapse(true);
|
|
949
|
+
const last = Math.max(segments.at(-1).end, (atoms.at(-1)?.at ?? -1) + 1);
|
|
950
|
+
const boundaries = [start, ...lines.slice(1).map((l) => at(l.start)), at(last)];
|
|
951
|
+
const empty = [...el.querySelectorAll('*')].filter((e) => !e.textContent && !e.childElementCount);
|
|
952
|
+
const ends = lines.map((l) => at(l.end));
|
|
953
|
+
// Spaces whose spacing differs from their line's get a span of their own.
|
|
954
|
+
const odd = spacing.flatMap((m, n) => [...m].filter(([, v]) => v !== commons[n]).map(([offset, v]) => ({ range: at(offset, 1), v })));
|
|
955
|
+
for (const { range, v } of odd) {
|
|
956
|
+
const span = document.createElement('span');
|
|
957
|
+
span.className = 'pw-space';
|
|
958
|
+
span.style.wordSpacing = `${v}px`;
|
|
959
|
+
range.surroundContents(span);
|
|
960
|
+
}
|
|
961
|
+
const out = [];
|
|
962
|
+
const hyphens = [];
|
|
963
|
+
for (const [n, line] of lines.entries()) {
|
|
964
|
+
const common = commons[n];
|
|
965
|
+
const range = document.createRange();
|
|
966
|
+
range.setStart(boundaries[n].startContainer, boundaries[n].startOffset);
|
|
967
|
+
range.setEnd(ends[n].startContainer, ends[n].startOffset);
|
|
968
|
+
const content = extract(range);
|
|
969
|
+
const lineEl = document.createElement('span');
|
|
970
|
+
lineEl.className = 'pw-line';
|
|
971
|
+
const { measure, left } = shapeOf(n);
|
|
972
|
+
const w = n === 0 ? measure - indent : measure;
|
|
973
|
+
lineEl.style.cssText = `display:block;width:${w}px;white-space:pre;text-align:start;text-align-last:auto;text-indent:0;` +
|
|
974
|
+
`text-rendering:geometricPrecision;word-spacing:${common ?? 0}px` +
|
|
975
|
+
// A hanging indent (a negative \parindent, as an index's entries have) moves the line out into the padding;
|
|
976
|
+
// a \parshape's indent (beside a left float) moves it in.
|
|
977
|
+
(n === 0 && indent > 0 ? `;padding-left:${indent}px` : '') +
|
|
978
|
+
(left + (n === 0 && indent < 0 ? indent : 0) ? `;margin-left:${left + (n === 0 && indent < 0 ? indent : 0)}px` : '');
|
|
979
|
+
lineEl.append(content);
|
|
980
|
+
if (line.hyphen) {
|
|
981
|
+
// In the element of the line's last character, so it has its font.
|
|
982
|
+
const hyphen = document.createElement('span');
|
|
983
|
+
hyphen.className = 'pw-hyphen';
|
|
984
|
+
hyphen.setAttribute('aria-hidden', 'true');
|
|
985
|
+
hyphen.textContent = line.hyphen;
|
|
986
|
+
const last = lastText(lineEl);
|
|
987
|
+
if (last)
|
|
988
|
+
last.after(hyphen);
|
|
989
|
+
else
|
|
990
|
+
lineEl.append(hyphen);
|
|
991
|
+
hyphens[n] = hyphen;
|
|
992
|
+
}
|
|
993
|
+
// What lies between this line's end and the next line's start (the space
|
|
994
|
+
// at the break) stays with this line, after its measure.
|
|
995
|
+
const gap = document.createRange();
|
|
996
|
+
gap.setStart(ends[n].startContainer, ends[n].startOffset);
|
|
997
|
+
gap.setEnd(boundaries[n + 1].startContainer, boundaries[n + 1].startOffset);
|
|
998
|
+
if (!gap.collapsed) {
|
|
999
|
+
const brk = document.createElement('span');
|
|
1000
|
+
brk.className = 'pw-break';
|
|
1001
|
+
brk.append(extract(gap));
|
|
1002
|
+
lineEl.append(brk);
|
|
1003
|
+
}
|
|
1004
|
+
out.push(lineEl);
|
|
1005
|
+
}
|
|
1006
|
+
// What is left after the text is dropped, but for elements that were empty to begin with: marks.
|
|
1007
|
+
out.at(-1)?.append(...empty.filter((e) => el.contains(e) && !e.closest('.pw-line')));
|
|
1008
|
+
el.replaceChildren(...out);
|
|
1009
|
+
joinPieces(out);
|
|
1010
|
+
return { elements: out, hyphens };
|
|
1011
|
+
}
|
|
1012
|
+
/** The attribute that marks an inline element's pieces while a paragraph is rendered. */
|
|
1013
|
+
export const PIECE = 'data-pw-piece';
|
|
1014
|
+
/**
|
|
1015
|
+
* Makes the pieces of each inline element a line break cut into one
|
|
1016
|
+
* element broken across lines, as the browser breaks an inline box: only
|
|
1017
|
+
* the first piece set (not one in the space at a break) keeps its `id`, and
|
|
1018
|
+
* the pieces lose their padding, border, margin and radii where the element
|
|
1019
|
+
* goes on, unless it asks for `box-decoration-break: clone`. An empty piece
|
|
1020
|
+
* in the space at a break is dropped.
|
|
1021
|
+
*/
|
|
1022
|
+
export function joinPieces(lines) {
|
|
1023
|
+
const groups = new Map();
|
|
1024
|
+
for (const line of lines) {
|
|
1025
|
+
for (const e of line.querySelectorAll(`[${PIECE}]`)) {
|
|
1026
|
+
const k = e.getAttribute(PIECE);
|
|
1027
|
+
e.removeAttribute(PIECE);
|
|
1028
|
+
const group = groups.get(k);
|
|
1029
|
+
if (group)
|
|
1030
|
+
group.push(e);
|
|
1031
|
+
else
|
|
1032
|
+
groups.set(k, [e]);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
const cuts = [];
|
|
1036
|
+
for (let pieces of groups.values()) {
|
|
1037
|
+
if (pieces.length < 2)
|
|
1038
|
+
continue;
|
|
1039
|
+
const atBreak = (p) => !!p.closest('.pw-break');
|
|
1040
|
+
for (const p of pieces)
|
|
1041
|
+
if (atBreak(p) && !p.hasChildNodes())
|
|
1042
|
+
p.remove();
|
|
1043
|
+
pieces = pieces.filter((p) => p.parentNode);
|
|
1044
|
+
const set = pieces.filter((p) => !atBreak(p));
|
|
1045
|
+
const first = set[0] ?? pieces[0];
|
|
1046
|
+
const last = set.at(-1) ?? pieces.at(-1);
|
|
1047
|
+
for (const p of pieces)
|
|
1048
|
+
if (p !== first)
|
|
1049
|
+
p.removeAttribute('id');
|
|
1050
|
+
const cs = getComputedStyle(first);
|
|
1051
|
+
if ((cs.getPropertyValue('box-decoration-break') || cs.getPropertyValue('-webkit-box-decoration-break')) === 'clone')
|
|
1052
|
+
continue;
|
|
1053
|
+
const [start, end] = cs.direction === 'rtl' ? ['right', 'left'] : ['left', 'right'];
|
|
1054
|
+
for (const p of pieces) {
|
|
1055
|
+
const sides = [...(p !== first ? [start] : []), ...(p !== last ? [end] : [])];
|
|
1056
|
+
if (sides.length)
|
|
1057
|
+
cuts.push({ piece: p, sides });
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
// Read before any is written, so the styles are worked out once.
|
|
1061
|
+
const sliced = cuts.map(({ piece, sides }) => {
|
|
1062
|
+
const cs = getComputedStyle(piece);
|
|
1063
|
+
return { piece, props: sides.flatMap((side) => SLICED(side).filter((prop) => (Number.parseFloat(cs.getPropertyValue(prop)) || 0) !== 0)) };
|
|
1064
|
+
});
|
|
1065
|
+
for (const { piece, props } of sliced)
|
|
1066
|
+
for (const prop of props)
|
|
1067
|
+
piece.style.setProperty(prop, prop.startsWith('--') ? '0px' : '0');
|
|
1068
|
+
}
|
|
1069
|
+
/** What a box loses on a side where it is broken: as `box-decoration-break: slice`, and the print stylesheet's exact border width. */
|
|
1070
|
+
const SLICED = (side) => [
|
|
1071
|
+
`padding-${side}`, `border-${side}-width`, `--pw-border-${side}-width`, `margin-${side}`,
|
|
1072
|
+
`border-top-${side}-radius`, `border-bottom-${side}-radius`,
|
|
1073
|
+
];
|
|
1074
|
+
/** How wide a line's text is, the space at its break left out. */
|
|
1075
|
+
function textWidth(line) {
|
|
1076
|
+
const r = document.createRange();
|
|
1077
|
+
r.setStart(line, 0);
|
|
1078
|
+
const brk = line.querySelector(':scope > .pw-break');
|
|
1079
|
+
if (brk)
|
|
1080
|
+
r.setEndBefore(brk);
|
|
1081
|
+
else
|
|
1082
|
+
r.setEnd(line, line.childNodes.length);
|
|
1083
|
+
return r.getBoundingClientRect().width;
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Adds `units` (negative: takes them) of `unit` px of spacing to a line's
|
|
1087
|
+
* spaces, one each, in a span of its own where a space has none. Returns
|
|
1088
|
+
* the width added.
|
|
1089
|
+
*/
|
|
1090
|
+
function spreadUnits(line, units, unit) {
|
|
1091
|
+
const spaces = [];
|
|
1092
|
+
const walker = document.createTreeWalker(line, NodeFilter.SHOW_TEXT);
|
|
1093
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
1094
|
+
if (n.parentElement?.closest('.pw-break'))
|
|
1095
|
+
continue;
|
|
1096
|
+
for (let i = 0; i < n.length; i++)
|
|
1097
|
+
if (n.data[i] === ' ')
|
|
1098
|
+
spaces.push({ node: n, offset: i });
|
|
1099
|
+
}
|
|
1100
|
+
if (!spaces.length)
|
|
1101
|
+
return 0;
|
|
1102
|
+
const base = Number.parseFloat(line.style.wordSpacing) || 0;
|
|
1103
|
+
const step = Math.sign(units) * unit;
|
|
1104
|
+
const chosen = new Map();
|
|
1105
|
+
for (let k = 0; k < Math.abs(units); k++)
|
|
1106
|
+
chosen.set(k % spaces.length, (chosen.get(k % spaces.length) ?? 0) + step);
|
|
1107
|
+
// Last first, so splitting a text node moves no space still to come.
|
|
1108
|
+
for (const [k, add] of [...chosen].sort(([a], [b]) => b - a)) {
|
|
1109
|
+
const { node, offset } = spaces[k];
|
|
1110
|
+
const parent = node.parentElement;
|
|
1111
|
+
if (parent.classList.contains('pw-space')) {
|
|
1112
|
+
parent.style.wordSpacing = `${(Number.parseFloat(parent.style.wordSpacing) || 0) + add}px`;
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
const r = document.createRange();
|
|
1116
|
+
r.setStart(node, offset);
|
|
1117
|
+
r.setEnd(node, offset + 1);
|
|
1118
|
+
const span = document.createElement('span');
|
|
1119
|
+
span.className = 'pw-space';
|
|
1120
|
+
span.style.wordSpacing = `${base + add}px`;
|
|
1121
|
+
r.surroundContents(span);
|
|
1122
|
+
}
|
|
1123
|
+
return units * unit;
|
|
1124
|
+
}
|
|
1125
|
+
function lastText(root) {
|
|
1126
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
1127
|
+
let last;
|
|
1128
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode())
|
|
1129
|
+
if (n.length)
|
|
1130
|
+
last = n;
|
|
1131
|
+
return last;
|
|
1132
|
+
}
|
|
1133
|
+
function mostCommon(values) {
|
|
1134
|
+
const counts = new Map();
|
|
1135
|
+
let best;
|
|
1136
|
+
let bestCount = 0;
|
|
1137
|
+
for (const v of values) {
|
|
1138
|
+
const c = (counts.get(v) ?? 0) + 1;
|
|
1139
|
+
counts.set(v, c);
|
|
1140
|
+
if (c > bestCount) {
|
|
1141
|
+
best = v;
|
|
1142
|
+
bestCount = c;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
return best;
|
|
1146
|
+
}
|
|
1147
|
+
export { INFINITE_PENALTY };
|
|
1148
|
+
//# sourceMappingURL=paragraph.js.map
|