@uniweb/press 0.4.13 → 0.4.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/press",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "description": "Press your React components into downloadable files — Word, Excel, PDF. Registration-based pattern with lazy-loaded format adapters.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -31,7 +31,7 @@
31
31
  import JSZip from 'jszip'
32
32
  import { parseFragment } from 'parse5'
33
33
  import { fetchAssets } from '../assets/fetch.js'
34
- import { MATH_CSS } from './math-css.js'
34
+ import { MATH_CSS, numberEquations } from './math-css.js'
35
35
 
36
36
  // ============================================================================
37
37
  // Public API
@@ -77,7 +77,16 @@ export async function compileEpub(input, options = {}) {
77
77
  // Walk each HTML fragment, collect image URLs, capture a chapter title.
78
78
  // The parsed tree is kept so we can re-serialize as XHTML after
79
79
  // rewriting <img src> to manifest-relative paths.
80
- const chapters = sections.map((html, i) => buildChapter(html, i))
80
+ // Numbered straight through the book rather than restarting per chapter,
81
+ // and as text rather than a CSS counter — reader support for counters is
82
+ // not something an EPUB can find out.
83
+ let eqnNo = 1
84
+ const numbered = sections.map((html) => {
85
+ const result = numberEquations(html, eqnNo)
86
+ eqnNo = result.next
87
+ return result.html
88
+ })
89
+ const chapters = numbered.map((html, i) => buildChapter(html, i))
81
90
 
82
91
  // Deduplicate image URLs across all chapters — and the cover, if any —
83
92
  // and fetch them in parallel. Failed fetches are logged and the original
@@ -43,12 +43,21 @@ export const MATH_CSS = `/* Temml's own class hooks — without these an aligned
43
43
  MathML-Core default here; Temml's own CSS only adjusts it for jot. */
44
44
  math mtd { padding-top: 0.5ex; padding-bottom: 0.5ex; }
45
45
  math mtable.tml-jot mtd { padding-top: 0.7ex; padding-bottom: 0.7ex; }
46
- /* AMS auto-numbering. Which equations number is the AUTHOR's choice, made in
46
+ /* AMS auto-numbering, for lanes that keep our CSS counter.
47
+
48
+ Scoped to :empty because the document lanes cannot rely on it -- Paged.js
49
+ rewrites counters for its own pagination and strips counter-increment, so
50
+ every equation rendered as "(0)" (measured 2026-07-31; the declaration
51
+ survives intact without the polyfill). press therefore writes the numbers
52
+ into the spans as text, and a span carrying a number is no longer :empty, so
53
+ the two can never both fire.
54
+
55
+ AMS auto-numbering. Which equations number is the AUTHOR's choice, made in
47
56
  LaTeX: align and equation number, aligned and the starred forms do not.
48
57
  Without these two rules that choice was discarded -- align and align-star
49
58
  rendered identically, so an author who asked for numbers silently got none.
50
59
  (No backticks in here: this string is a JS template literal.) */
51
- .tml-eqn::before {
60
+ .tml-eqn:empty::before {
52
61
  counter-increment: tmlEqnNo;
53
62
  content: "(" counter(tmlEqnNo) ")";
54
63
  }
@@ -74,3 +83,35 @@ math.tml-display:has(.tml-eqn) {
74
83
  display: block !important;
75
84
  width: 100%;
76
85
  }`
86
+
87
+ /**
88
+ * Write equation numbers into Temml's tag spans as text.
89
+ *
90
+ * Temml leaves `<span class="tml-eqn"></span>` empty and expects a CSS counter
91
+ * to draw the number. That works in a browser and not in a document: Paged.js
92
+ * rewrites counters for its own pagination and strips `counter-increment`, so
93
+ * every equation renders as "(0)" -- measured, and confirmed by the declaration
94
+ * surviving intact once the polyfill is removed. EPUB readers vary at least as
95
+ * widely, and neither lane offers a way to find out.
96
+ *
97
+ * So the document lanes stop asking CSS to count. A span that carries its
98
+ * number is no longer `:empty`, and the stylesheet's counter rule is scoped to
99
+ * `:empty`, so the two can never both fire and double up.
100
+ *
101
+ * A regex rather than a parse: Temml emits this span in exactly one shape, and
102
+ * the epub adapter would otherwise have to thread a counter through its parse5
103
+ * tree for no gain.
104
+ *
105
+ * @param {string} html
106
+ * @param {number} [start=1] - First number to use; lets a caller continue the
107
+ * sequence across sections so a book numbers straight through.
108
+ * @returns {{ html: string, next: number }}
109
+ */
110
+ export function numberEquations(html, start = 1) {
111
+ let n = start
112
+ const out = String(html ?? '').replace(
113
+ /<span class="tml-eqn"><\/span>/g,
114
+ () => `<span class="tml-eqn">(${n++})</span>`,
115
+ )
116
+ return { html: out, next: n }
117
+ }
@@ -129,6 +129,11 @@ async function compileServerSide(htmlDoc, options = {}) {
129
129
  * want to inspect the emitted document before handing it to a browser.
130
130
  */
131
131
  export function emitDocument({ body = '', meta = {}, stylesheet, polyfillUrl } = {}) {
132
+ // Equation numbers are written in as text rather than left to the CSS
133
+ // counter: Paged.js strips counter-increment while rewriting counters for
134
+ // its own pagination, which rendered every equation as "(0)".
135
+ body = numberEquations(body).html
136
+
132
137
  const lang = meta.language ?? 'en'
133
138
  const title = meta.title ?? 'Book'
134
139
  // Math CSS is emitted ahead of the design stylesheet, not inside it.
@@ -238,7 +243,7 @@ export const DEFAULT_POLYFILL_URL =
238
243
  * book PDF without a custom foundation stylesheet. Foundations override by
239
244
  * passing `options.stylesheet`.
240
245
  */
241
- import { MATH_CSS } from './math-css.js'
246
+ import { MATH_CSS, numberEquations } from './math-css.js'
242
247
 
243
248
  export const DEFAULT_STYLESHEET = `
244
249
  /* Hidden metadata block — the DOM carries it for CSS string-set / string() */