reamkit 1.30.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +70 -24
  2. package/dist/esm/core/bidi/index.d.ts +10 -0
  3. package/dist/esm/core/bidi/index.js +18 -2
  4. package/dist/esm/core/converter/facade.js +10 -5
  5. package/dist/esm/core/converter/project.js +4 -1
  6. package/dist/esm/core/converter/ream.js +17 -6
  7. package/dist/esm/core/converter/sheet-images.d.ts +17 -0
  8. package/dist/esm/core/converter/sheet-images.js +33 -0
  9. package/dist/esm/core/crypto/offcrypto.js +1 -1
  10. package/dist/esm/core/document-model/index.d.ts +1 -1
  11. package/dist/esm/core/document-model/types.d.ts +175 -0
  12. package/dist/esm/core/drawingml/chart-geometry.d.ts +21 -8
  13. package/dist/esm/core/drawingml/chart-geometry.js +198 -108
  14. package/dist/esm/core/drawingml/chart-parser.js +73 -2
  15. package/dist/esm/core/drawingml/colors.d.ts +6 -0
  16. package/dist/esm/core/drawingml/colors.js +23 -3
  17. package/dist/esm/core/drawingml/shape-render.d.ts +3 -1
  18. package/dist/esm/core/drawingml/shape-render.js +4 -2
  19. package/dist/esm/core/font/index.d.ts +2 -0
  20. package/dist/esm/core/font/measure.d.ts +9 -0
  21. package/dist/esm/core/font/measure.js +9 -1
  22. package/dist/esm/core/font/ttf-build.d.ts +113 -0
  23. package/dist/esm/core/font/ttf-build.js +1224 -0
  24. package/dist/esm/core/font/ttf-subset.d.ts +19 -0
  25. package/dist/esm/core/font/ttf-subset.js +14 -1
  26. package/dist/esm/core/fonts/families.js +4 -2
  27. package/dist/esm/core/fonts/provider.d.ts +17 -0
  28. package/dist/esm/core/fonts/provider.js +27 -2
  29. package/dist/esm/core/fonts/remote-fonts.js +8 -1
  30. package/dist/esm/core/fonts/scripts.js +4 -2
  31. package/dist/esm/core/ir/flow.d.ts +77 -1
  32. package/dist/esm/core/ir/sheet.d.ts +43 -0
  33. package/dist/esm/core/number-format.js +16 -11
  34. package/dist/esm/core/numbering/index.d.ts +1 -1
  35. package/dist/esm/core/numbering/state.d.ts +11 -1
  36. package/dist/esm/core/numbering/state.js +10 -1
  37. package/dist/esm/core/spreadsheet-model/index.d.ts +1 -1
  38. package/dist/esm/core/spreadsheet-model/types.d.ts +96 -0
  39. package/dist/esm/core/style-cascade/resolver.js +39 -6
  40. package/dist/esm/core/style-cascade/types.d.ts +19 -1
  41. package/dist/esm/core/style-cascade/types.js +3 -0
  42. package/dist/esm/excel/column-bands.d.ts +39 -6
  43. package/dist/esm/excel/column-bands.js +41 -17
  44. package/dist/esm/excel/comments-parser.js +19 -0
  45. package/dist/esm/excel/conditional-format.d.ts +7 -3
  46. package/dist/esm/excel/conditional-format.js +77 -39
  47. package/dist/esm/excel/formula/context.d.ts +18 -0
  48. package/dist/esm/excel/formula/eval.js +51 -0
  49. package/dist/esm/excel/formula/index.d.ts +2 -2
  50. package/dist/esm/excel/formula/lexer.d.ts +1 -1
  51. package/dist/esm/excel/formula/lexer.js +41 -0
  52. package/dist/esm/excel/formula/parser.d.ts +25 -0
  53. package/dist/esm/excel/formula/parser.js +95 -0
  54. package/dist/esm/excel/print-model.d.ts +38 -1
  55. package/dist/esm/excel/print-model.js +522 -80
  56. package/dist/esm/excel/shared-strings-parser.d.ts +9 -0
  57. package/dist/esm/excel/shared-strings-parser.js +11 -1
  58. package/dist/esm/excel/sheet-drawing.d.ts +38 -2
  59. package/dist/esm/excel/sheet-drawing.js +47 -13
  60. package/dist/esm/excel/sheet-shape-parser.d.ts +6 -2
  61. package/dist/esm/excel/sheet-shape-parser.js +18 -6
  62. package/dist/esm/excel/sheet-to-flow.d.ts +17 -0
  63. package/dist/esm/excel/sheet-to-flow.js +434 -47
  64. package/dist/esm/excel/styles-parser.d.ts +9 -0
  65. package/dist/esm/excel/styles-parser.js +80 -26
  66. package/dist/esm/excel/table-parser.js +5 -0
  67. package/dist/esm/excel/table-style-presets.d.ts +26 -0
  68. package/dist/esm/excel/table-style-presets.js +1555 -0
  69. package/dist/esm/excel/table-style.d.ts +13 -0
  70. package/dist/esm/excel/table-style.js +75 -0
  71. package/dist/esm/excel/tint.d.ts +10 -0
  72. package/dist/esm/excel/tint.js +75 -0
  73. package/dist/esm/excel/vml-drawing.d.ts +41 -3
  74. package/dist/esm/excel/vml-drawing.js +143 -10
  75. package/dist/esm/excel/worksheet-parser.js +89 -15
  76. package/dist/esm/excel/xls/biff-reader.js +10 -2
  77. package/dist/esm/excel/xlsx-reader.js +195 -14
  78. package/dist/esm/excel/xlsx-writer.js +8 -7
  79. package/dist/esm/html/html-writer.js +202 -20
  80. package/dist/esm/index.d.ts +2 -2
  81. package/dist/esm/layout/fit-pages.d.ts +11 -0
  82. package/dist/esm/layout/fit-pages.js +86 -0
  83. package/dist/esm/layout/line-paint.d.ts +58 -0
  84. package/dist/esm/layout/line-paint.js +107 -0
  85. package/dist/esm/layout/page-doc.d.ts +61 -3
  86. package/dist/esm/layout/page-doc.js +141 -1
  87. package/dist/esm/layout/styled-layout.d.ts +55 -7
  88. package/dist/esm/layout/styled-layout.js +1154 -169
  89. package/dist/esm/layout/turned-section.d.ts +38 -0
  90. package/dist/esm/layout/turned-section.js +205 -0
  91. package/dist/esm/markdown/markdown-writer.js +17 -6
  92. package/dist/esm/pdf/styled-page-emitter.js +114 -60
  93. package/dist/esm/pdf/styled-page-renderer.js +1 -1
  94. package/dist/esm/pdf-reader/cff-outline.d.ts +27 -0
  95. package/dist/esm/pdf-reader/cff-outline.js +169 -21
  96. package/dist/esm/pdf-reader/content.d.ts +53 -0
  97. package/dist/esm/pdf-reader/content.js +9 -1
  98. package/dist/esm/pdf-reader/display.d.ts +36 -0
  99. package/dist/esm/pdf-reader/display.js +66 -1
  100. package/dist/esm/pdf-reader/document.js +5 -1
  101. package/dist/esm/pdf-reader/embedded-fonts.d.ts +2 -1
  102. package/dist/esm/pdf-reader/embedded-fonts.js +32 -2
  103. package/dist/esm/pdf-reader/encodings.d.ts +8 -0
  104. package/dist/esm/pdf-reader/encodings.js +25 -3
  105. package/dist/esm/pdf-reader/face-outlines.d.ts +78 -0
  106. package/dist/esm/pdf-reader/face-outlines.js +362 -0
  107. package/dist/esm/pdf-reader/figures.d.ts +52 -0
  108. package/dist/esm/pdf-reader/figures.js +433 -0
  109. package/dist/esm/pdf-reader/flow-build.d.ts +131 -5
  110. package/dist/esm/pdf-reader/flow-build.js +345 -26
  111. package/dist/esm/pdf-reader/font.js +321 -36
  112. package/dist/esm/pdf-reader/glyf-outline.d.ts +33 -0
  113. package/dist/esm/pdf-reader/glyf-outline.js +135 -1
  114. package/dist/esm/pdf-reader/glyph-names.js +154 -1
  115. package/dist/esm/pdf-reader/layout.d.ts +93 -0
  116. package/dist/esm/pdf-reader/layout.js +1703 -214
  117. package/dist/esm/pdf-reader/page-numbers.d.ts +53 -0
  118. package/dist/esm/pdf-reader/page-numbers.js +167 -0
  119. package/dist/esm/pdf-reader/tagged.js +182 -23
  120. package/dist/esm/pdf-reader/text.d.ts +6 -3
  121. package/dist/esm/pdf-reader/text.js +98 -9
  122. package/dist/esm/pdf-reader/type1-outline.d.ts +11 -0
  123. package/dist/esm/pdf-reader/type1-outline.js +63 -8
  124. package/dist/esm/pdf-reader/vector.js +71 -1
  125. package/dist/esm/svg/svg-text.d.ts +58 -0
  126. package/dist/esm/svg/svg-text.js +322 -0
  127. package/dist/esm/svg/svg-writer.js +135 -71
  128. package/dist/esm/word/doc/doc-reader.js +6 -2
  129. package/dist/esm/word/doc/doc-text.d.ts +6 -0
  130. package/dist/esm/word/doc/doc-text.js +19 -1
  131. package/dist/esm/word/document-parser.d.ts +2 -2
  132. package/dist/esm/word/document-parser.js +11 -1
  133. package/dist/esm/word/docx-reader.js +5 -3
  134. package/dist/esm/word/docx-writer.js +218 -23
  135. package/dist/esm/word/drawing-parser.d.ts +5 -3
  136. package/dist/esm/word/drawing-parser.js +49 -8
  137. package/dist/esm/word/font-embed.d.ts +30 -0
  138. package/dist/esm/word/font-embed.js +173 -0
  139. package/dist/esm/word/font-table.d.ts +10 -0
  140. package/dist/esm/word/font-table.js +13 -1
  141. package/dist/esm/word/index.js +1 -1
  142. package/dist/esm/word/numbering-parser.d.ts +3 -1
  143. package/dist/esm/word/numbering-parser.js +2 -1
  144. package/dist/esm/word/paragraph-properties.d.ts +7 -6
  145. package/dist/esm/word/paragraph-properties.js +14 -2
  146. package/dist/esm/word/run-properties.js +26 -0
  147. package/package.json +12 -3
@@ -22,3 +22,22 @@ export declare function subsetTtf(parsed: ParsedTtf, usedGids: Iterable<number>)
22
22
  * @returns The closed set of glyph ids.
23
23
  */
24
24
  export declare function glyphClosure(parsed: ParsedTtf, usedGids: Iterable<number>): Set<number>;
25
+ /**
26
+ * The sfnt table directory's binary-search fields for `numTables` tables.
27
+ *
28
+ * @param numTables How many tables the font holds.
29
+ * @returns `searchRange`, `entrySelector` and `rangeShift`, as the header states them.
30
+ */
31
+ export declare function directoryGeometry(numTables: number): {
32
+ searchRange: number;
33
+ entrySelector: number;
34
+ rangeShift: number;
35
+ };
36
+ /**
37
+ * An sfnt table checksum: the sum of its big-endian 32-bit words, the last one
38
+ * padded with zeros.
39
+ *
40
+ * @param data The table's bytes (or the whole font's).
41
+ * @returns The checksum, as an unsigned 32-bit value.
42
+ */
43
+ export declare function paddedChecksum(data: Uint8Array): number;
@@ -193,6 +193,12 @@ function assembleSubsetTtf(parsed, newGlyf, newLoca) {
193
193
  outView.setUint32(head.offset + HEAD_CHECKSUM_ADJUSTMENT_OFFSET, adjustment, false);
194
194
  return out;
195
195
  }
196
+ /**
197
+ * The sfnt table directory's binary-search fields for `numTables` tables.
198
+ *
199
+ * @param numTables How many tables the font holds.
200
+ * @returns `searchRange`, `entrySelector` and `rangeShift`, as the header states them.
201
+ */
196
202
  function directoryGeometry(numTables) {
197
203
  let entrySelector = 0;
198
204
  let pow2 = 1;
@@ -208,6 +214,13 @@ function directoryGeometry(numTables) {
208
214
  rangeShift
209
215
  };
210
216
  }
217
+ /**
218
+ * An sfnt table checksum: the sum of its big-endian 32-bit words, the last one
219
+ * padded with zeros.
220
+ *
221
+ * @param data The table's bytes (or the whole font's).
222
+ * @returns The checksum, as an unsigned 32-bit value.
223
+ */
211
224
  function paddedChecksum(data) {
212
225
  let sum = 0;
213
226
  const len = data.length;
@@ -244,4 +257,4 @@ function concatBytes(parts) {
244
257
  return out;
245
258
  }
246
259
  //#endregion
247
- export { glyphClosure, subsetTtf };
260
+ export { directoryGeometry, glyphClosure, paddedChecksum, subsetTtf };
@@ -28,8 +28,10 @@ function familiesInFlow(flow) {
28
28
  for (const el of elements) if (el.kind === "paragraph") {
29
29
  add(el.paragraph.properties.runProperties?.fontFamily?.ascii);
30
30
  for (const run of el.paragraph.runs) add(run.properties.fontFamily?.ascii);
31
- } else if (el.kind === "table") for (const row of el.table.rows) for (const cell of row.cells) visit(cell.content);
32
- else if (el.kind === "shape") shapeText(el.shape);
31
+ } else if (el.kind === "table") {
32
+ for (const row of el.table.rows) for (const cell of row.cells) visit(cell.content);
33
+ visit(el.table.overlay?.drawings ?? []);
34
+ } else if (el.kind === "shape") shapeText(el.shape);
33
35
  };
34
36
  visit(flow.body);
35
37
  for (const band of flow.headersFooters?.values() ?? []) visit(band);
@@ -45,6 +45,23 @@ export declare function embeddedDocFontProvider(embedded: ReadonlyMap<string, Fo
45
45
  * Open CDN substitutes (Arimo / Tinos / Cousine / Carlito / Caladea — the
46
46
  * LibreOffice metric-compatible mapping).
47
47
  * Always answers; the chain reports it as a substitution.
48
+ *
49
+ * A family's set is shared by every request for it, those made while the
50
+ * download is in flight included, and a whole set is downloaded once per
51
+ * provider. A set whose regular face cannot be downloaded rejects `resolve`
52
+ * with {@link fetchFontSet}'s error rather than answering {@link NO_FONT}: this
53
+ * is the chain's last resort, and a chain that answers none sends the
54
+ * conversion to the auto-download path, which records no substitution. The
55
+ * failed set is not kept, so the next request asks the network again.
56
+ *
57
+ * Nor is a set kept that came without a bold or italic face. The requests that
58
+ * waited on it fall back to the faces it has, and the next request assembles
59
+ * the set anew: a face the network lost is asked for again, and one the CDN
60
+ * answered with an HTTP error is not, since the download cache beneath
61
+ * {@link fetchFontSet} remembers it as missing.
62
+ *
63
+ * @param options An injectable `fetch` (defaults to the global one).
64
+ * @returns The `'remote'` provider.
48
65
  */
49
66
  export declare function remoteFontProvider(options?: {
50
67
  readonly fetch?: FetchLike;
@@ -66,6 +66,23 @@ function embeddedDocFontProvider(embedded) {
66
66
  * Open CDN substitutes (Arimo / Tinos / Cousine / Carlito / Caladea — the
67
67
  * LibreOffice metric-compatible mapping).
68
68
  * Always answers; the chain reports it as a substitution.
69
+ *
70
+ * A family's set is shared by every request for it, those made while the
71
+ * download is in flight included, and a whole set is downloaded once per
72
+ * provider. A set whose regular face cannot be downloaded rejects `resolve`
73
+ * with {@link fetchFontSet}'s error rather than answering {@link NO_FONT}: this
74
+ * is the chain's last resort, and a chain that answers none sends the
75
+ * conversion to the auto-download path, which records no substitution. The
76
+ * failed set is not kept, so the next request asks the network again.
77
+ *
78
+ * Nor is a set kept that came without a bold or italic face. The requests that
79
+ * waited on it fall back to the faces it has, and the next request assembles
80
+ * the set anew: a face the network lost is asked for again, and one the CDN
81
+ * answered with an HTTP error is not, since the download cache beneath
82
+ * {@link fetchFontSet} remembers it as missing.
83
+ *
84
+ * @param options An injectable `fetch` (defaults to the global one).
85
+ * @returns The `'remote'` provider.
69
86
  */
70
87
  function remoteFontProvider(options = {}) {
71
88
  const cache = /* @__PURE__ */ new Map();
@@ -81,10 +98,18 @@ function remoteFontProvider(options = {}) {
81
98
  });
82
99
  cache.set(family, set);
83
100
  }
84
- const fonts = await set;
101
+ let fonts;
102
+ try {
103
+ fonts = await set;
104
+ } catch (error) {
105
+ if (cache.get(family) === set) cache.delete(family);
106
+ throw error;
107
+ }
108
+ if ((fonts.bold === void 0 || fonts.italic === void 0 || fonts.boldItalic === void 0) && cache.get(family) === set) cache.delete(family);
109
+ const picked = pickVariant((x) => fonts[x] !== void 0, req.bold, req.italic) ?? "regular";
85
110
  return {
86
111
  kind: "bytes",
87
- bytes: fonts[pickVariant((x) => fonts[x] !== void 0, req.bold, req.italic) ?? "regular"] ?? fonts.regular,
112
+ bytes: fonts[picked] ?? fonts.regular,
88
113
  faceName: family,
89
114
  providerId: "remote"
90
115
  };
@@ -330,7 +330,14 @@ async function fetchTtf(url, fetchImpl, required) {
330
330
  })();
331
331
  cache.set(url, pending);
332
332
  }
333
- const result = await pending;
333
+ let result;
334
+ try {
335
+ result = await pending;
336
+ } catch (cause) {
337
+ if (cache.get(url) === pending) cache.delete(url);
338
+ if (!required) return void 0;
339
+ throw new Error(`Failed to download font from ${url}`, { cause });
340
+ }
334
341
  if (!result && required) {
335
342
  cache.delete(url);
336
343
  throw new Error(`Failed to download font from ${url}`);
@@ -163,8 +163,10 @@ function scriptsInFlow(flow) {
163
163
  };
164
164
  const visit = (elements) => {
165
165
  for (const el of elements) if (el.kind === "paragraph") for (const run of el.paragraph.runs) read(run.text);
166
- else if (el.kind === "table") for (const row of el.table.rows) for (const cell of row.cells) visit(cell.content);
167
- else if (el.kind === "shape") shapeText(el.shape);
166
+ else if (el.kind === "table") {
167
+ for (const row of el.table.rows) for (const cell of row.cells) visit(cell.content);
168
+ visit(el.table.overlay?.drawings ?? []);
169
+ } else if (el.kind === "shape") shapeText(el.shape);
168
170
  };
169
171
  visit(flow.body);
170
172
  for (const band of flow.headersFooters?.values() ?? []) visit(band);
@@ -1,5 +1,5 @@
1
1
  import { BodyElement, Chart, Comment, DocumentInfo, Numbering, Section, SectionProperties, ShapeFill, StyleSheet } from '../document-model/index.js';
2
- import { FontRegistry } from '../font/index.js';
2
+ import { FontRegistry, GlyphSeg } from '../font/index.js';
3
3
  import { ResourceStore } from './resources.js';
4
4
  /**
5
5
  * A face's family as a word processor names it (ECMA-376 §17.8.3.9 `w:font`).
@@ -10,6 +10,55 @@ export interface FaceFamily {
10
10
  /** §17.8.3.10 `w:family` — the kind of face, for a reader that has to substitute. */
11
11
  readonly generic: 'roman' | 'swiss' | 'modern';
12
12
  }
13
+ /**
14
+ * The outlines a face drew a document's characters with — what a writer needs
15
+ * to EMBED the face, so a reader that lacks it sets the text in the face the
16
+ * source was set in instead of a substitute (ECMA-376 §17.8.1).
17
+ */
18
+ export interface FaceOutlines {
19
+ /** Each character (one code point) the document shows in the face → its glyph. */
20
+ readonly glyphs: ReadonlyMap<string, FaceGlyph>;
21
+ /**
22
+ * The pairs the source KERNED the face by: two characters → the adjustment
23
+ * to the first one's advance, in thousandths of an em (negative tightens).
24
+ */
25
+ readonly kerning?: ReadonlyMap<string, number>;
26
+ /**
27
+ * The ligatures the source drew in the face: the letters one glyph stands
28
+ * for ("fi", "ffl") → that glyph.
29
+ */
30
+ readonly ligatures?: ReadonlyMap<string, FaceGlyph>;
31
+ /**
32
+ * OS/2 `fsType` — the embedding the face's licence allows, as its program
33
+ * states it; absent where the program states nothing.
34
+ */
35
+ readonly fsType?: number;
36
+ /** The style the face IS, which is the slot a family embeds it in. */
37
+ readonly bold: boolean;
38
+ readonly italic: boolean;
39
+ /** The program's own name for the face, without a subset tag. */
40
+ readonly postScriptName: string;
41
+ /**
42
+ * The line to set the face in, above and below the baseline, in thousandths
43
+ * of an em — `descent` negative. A reader that reconstructs a page gives the
44
+ * line it measured the page against, so a paragraph set in the face's single
45
+ * spacing lands where the page put it.
46
+ */
47
+ readonly ascent: number;
48
+ readonly descent: number;
49
+ readonly capHeight?: number;
50
+ readonly xHeight?: number;
51
+ /** Degrees counterclockwise from the vertical; a face slanted right is negative. */
52
+ readonly italicAngle: number;
53
+ readonly fixedPitch: boolean;
54
+ }
55
+ /** One glyph of a {@link FaceOutlines}: what it draws and how far it advances. */
56
+ export interface FaceGlyph {
57
+ /** Its contours in a one-unit em, y up, filled by the nonzero rule; empty when blank. */
58
+ readonly outline: ReadonlyArray<GlyphSeg>;
59
+ /** How far the pen moves after it, in thousandths of an em. */
60
+ readonly advance: number;
61
+ }
13
62
  /**
14
63
  * The semantic IR tree (ir-design §5): everything a reader extracts from the
15
64
  * document bytes, format-neutrally — the flow `body` plus its document-scoped
@@ -59,6 +108,11 @@ export interface FlowDoc {
59
108
  * to another program names the family, which is the name that program knows.
60
109
  */
61
110
  readonly faceFamilies?: ReadonlyMap<string, FaceFamily>;
111
+ /**
112
+ * The outlines of the faces a run names, keyed as {@link faceFamilies} is —
113
+ * for a writer that embeds them (see {@link FaceOutlines}).
114
+ */
115
+ readonly faceOutlines?: ReadonlyMap<string, FaceOutlines>;
62
116
  /** Document metadata from docProps/core.xml. */
63
117
  readonly info?: DocumentInfo;
64
118
  /** Document natural language hint (BCP-47), e.g. for tagged-PDF /Lang. */
@@ -85,4 +139,26 @@ export interface FlowDoc {
85
139
  * @w:gutter` reserves belongs to the TOP margin rather than the left.
86
140
  */
87
141
  readonly gutterAtTop?: boolean;
142
+ /**
143
+ * [MS-DOCX] `w:compatSetting` `compatibilityMode` — the version of Word
144
+ * whose layout the document asks for: 15 is Word 2013's, which every Word
145
+ * since sets a new document by. Word opens a document that states none in
146
+ * Compatibility Mode, and forms there none of the OpenType ligatures its
147
+ * faces carry.
148
+ */
149
+ readonly compatibilityMode?: number;
150
+ /**
151
+ * The application whose rules the document is set by: `'word'` for one Word
152
+ * sets — lines as tall as the faces on them make them (§17.3.1.33), table
153
+ * rows as tall as their borders make them (§17.4.38); see the layout's
154
+ * `TypesetBy`. Absent, the layout's flat 1.2× lines and borders that take no
155
+ * room.
156
+ */
157
+ readonly typesetBy?: 'word';
158
+ /**
159
+ * The document's front floats cover the text under them, as a spreadsheet's
160
+ * drawings cover its cells: a note's box hides the value beside its cell,
161
+ * and a chart the figures it sits on. Absent, the text is painted over them.
162
+ */
163
+ readonly floatsOverText?: true;
88
164
  }
@@ -13,6 +13,11 @@ export interface SheetChartRef {
13
13
  /** Where the anchor puts it, in points from the grid's top-left. */
14
14
  readonly xPt?: number;
15
15
  readonly yPt?: number;
16
+ /**
17
+ * §20.5.2.3 `fPrintsWithSheet="0"` — on the sheet, not on its paper: a
18
+ * window shows it, a print leaves it out.
19
+ */
20
+ readonly screenOnly?: true;
16
21
  }
17
22
  /**
18
23
  * §20.5.2.1 xdr:pic — a picture anchored over a sheet's grid, sized from its
@@ -26,6 +31,11 @@ export interface SheetImageRef {
26
31
  /** Where the anchor puts it, in points from the grid's top-left. */
27
32
  readonly xPt?: number;
28
33
  readonly yPt?: number;
34
+ /**
35
+ * §20.5.2.3 `fPrintsWithSheet="0"` — on the sheet, not on its paper: a
36
+ * window shows it, a print leaves it out.
37
+ */
38
+ readonly screenOnly?: true;
29
39
  }
30
40
  /** One item (label + selection state) in a {@link SheetSlicer}. */
31
41
  export interface SheetSlicerItem {
@@ -70,7 +80,35 @@ export interface SheetComment {
70
80
  readonly ref: string;
71
81
  readonly author?: string;
72
82
  readonly text: string;
83
+ /** The note as written, run by run with each run's own font — the bold "Author:" line included. */
84
+ readonly runs?: ReadonlyArray<SheetRichRun>;
73
85
  readonly threaded: boolean;
86
+ /**
87
+ * The note's box, when its legacy VML shape SHOWS it (`<x:Visible/>`):
88
+ * Excel draws a shown note on the sheet beside its cell, with a line to the
89
+ * cell's corner, and prints it there when `<pageSetup cellComments>` is
90
+ * `asDisplayed`. Absent ⇒ the note is only flagged in its cell.
91
+ */
92
+ readonly shown?: SheetNoteBox;
93
+ }
94
+ /**
95
+ * Where a shown note stands and how it is painted. Distances are in points
96
+ * from the sheet's top-left corner, measured in the file's own column order —
97
+ * a sheet that reads from the right mirrors them with everything else.
98
+ */
99
+ export interface SheetNoteBox {
100
+ readonly xPt: number;
101
+ readonly yPt: number;
102
+ readonly widthPt: number;
103
+ readonly heightPt: number;
104
+ /** The top-right corner of the cell (or merge) the note belongs to — its line ends there. */
105
+ readonly cornerXPt: number;
106
+ readonly cornerYPt: number;
107
+ readonly fillHex: string;
108
+ readonly lineHex: string;
109
+ readonly shadow: boolean;
110
+ /** The side the note's text is set to; absent ⇒ its start. */
111
+ readonly textAlign?: 'left' | 'center' | 'right';
74
112
  }
75
113
  /**
76
114
  * A form control resolved against its ctrlProp part (E-SHEET W8): the display
@@ -150,6 +188,11 @@ export interface Sheet {
150
188
  readonly images?: ReadonlyArray<SheetImageRef>;
151
189
  /** Drawing shapes on this sheet (E-SHEET W2), fully resolved + anchor-ordered. */
152
190
  readonly shapes?: ReadonlyArray<ShapeBlock>;
191
+ /**
192
+ * The indexes into {@link shapes} of those that do not print with the sheet
193
+ * (§20.5.2.3 `fPrintsWithSheet="0"`): a window shows them, paper does not.
194
+ */
195
+ readonly screenOnlyShapes?: ReadonlySet<number>;
153
196
  /**
154
197
  * Cell hyperlinks resolved to external URLs (E-SHEET W3); the projection sets
155
198
  * `run.href` on covered cells. In-workbook (location-only) links are not carried.
@@ -713,20 +713,25 @@ function applyNumericSection(value, format, negativeSection) {
713
713
  if (isPercent) magnitude *= 100;
714
714
  const { intFormat, decFormat, literalPrefix, literalSuffix, scaleCommas } = splitNumberFormat(cleaned);
715
715
  if (scaleCommas > 0) magnitude /= 1e3 ** scaleCommas;
716
- let decimals = 0;
717
- for (const c of decFormat) if (c === "0" || c === "#") decimals++;
716
+ const decPlaceholders = [...decFormat].filter((c) => c === "0" || c === "#" || c === "?");
717
+ const decimals = decPlaceholders.length;
718
718
  const [intRaw, decRaw] = toFixedDecimal(magnitude, decimals).split(".");
719
- const intStr = /,(?=\d)/.test(intFormat) || /[0#],[0#]/.test(intFormat) ? intRaw.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : intRaw;
720
- let numberPart = intRaw === "0" && !/[0?]/.test(intFormat) ? "" : intStr;
719
+ const useThousands = /,(?=\d)/.test(intFormat) || /[0#?],[0#?]/.test(intFormat);
720
+ const intPlaceholders = [...intFormat].filter((c) => c === "0" || c === "#" || c === "?");
721
+ const significant = intRaw === "0" && !intFormat.includes("0") ? "" : intRaw;
722
+ let zeros = "";
723
+ let spaces = "";
724
+ for (let i = 0; i < intPlaceholders.length - significant.length; i++) if (intPlaceholders[i] === "0") zeros += "0";
725
+ else if (intPlaceholders[i] === "?") spaces += " ";
726
+ const intDigits = zeros + significant;
727
+ let numberPart = spaces + (useThousands ? intDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : intDigits);
721
728
  if (decimals > 0) {
722
729
  let dec = decRaw ?? "".padEnd(decimals, "0");
723
730
  if (dec.length < decimals) dec = dec.padEnd(decimals, "0");
724
- let kept = "";
725
- for (let i = 0; i < decFormat.length; i++) {
726
- const placeholder = decFormat[i];
727
- if (placeholder === "0" || placeholder === "#") kept += dec[i] ?? "0";
728
- }
729
- for (let i = kept.length - 1; i >= 0 && kept[i] === "0" && decFormat[i] === "#"; i--) kept = kept.substring(0, i);
731
+ let kept = dec.substring(0, decimals);
732
+ for (let i = kept.length - 1; i >= 0 && kept[i] === "0"; i--) if (decPlaceholders[i] === "#") kept = kept.substring(0, i);
733
+ else if (decPlaceholders[i] === "?") kept = `${kept.substring(0, i)} ${kept.substring(i + 1)}`;
734
+ else break;
730
735
  if (kept.length > 0) numberPart += "." + kept;
731
736
  else if (decFormat.includes("0")) numberPart += "." + dec;
732
737
  }
@@ -739,7 +744,7 @@ function splitNumberFormat(cleaned) {
739
744
  let lastDigit = -1;
740
745
  for (let i = 0; i < cleaned.length; i++) {
741
746
  const ch = cleaned[i];
742
- if (ch === "0" || ch === "#") {
747
+ if (ch === "0" || ch === "#" || ch === "?") {
743
748
  if (firstDigit < 0) firstDigit = i;
744
749
  lastDigit = i;
745
750
  }
@@ -1,2 +1,2 @@
1
- export { NumberingState, formatLevelMarker } from './state.js';
1
+ export { NumberingState, formatCounter, formatLevelMarker } from './state.js';
2
2
  export { applyNumbering, applyNumberingToHeadersFooters } from './apply.js';
@@ -1,4 +1,4 @@
1
- import { AbstractNumbering, Numbering, NumberingInstance, NumberingLevel, NumberingReference } from '../document-model/index.js';
1
+ import { AbstractNumbering, Numbering, NumberingFormat, NumberingInstance, NumberingLevel, NumberingReference } from '../document-model/index.js';
2
2
  /**
3
3
  * §17.9.27 — the levels an INSTANCE actually numbers by: its abstract
4
4
  * definition's, with any `w:lvlOverride/w:lvl` shadowing them. Cached per
@@ -31,3 +31,13 @@ export declare class NumberingState {
31
31
  resolveMarker(numbering: Numbering, ref: NumberingReference): string | null;
32
32
  }
33
33
  export declare function formatLevelMarker(abstractNum: AbstractNumbering, currentLevel: NumberingLevel, counters: ReadonlyArray<number>): string;
34
+ /**
35
+ * A counter in the numerals a §17.18.59 format names: `lowerRoman` 4 is "iv".
36
+ * A format with no numeral for the number — a letter or a roman zero — gives
37
+ * the empty string.
38
+ *
39
+ * @param format The number format.
40
+ * @param n The counter's value.
41
+ * @returns The counter as that format writes it.
42
+ */
43
+ export declare function formatCounter(format: NumberingFormat, n: number): string;
@@ -77,6 +77,15 @@ function formatLevelMarker(abstractNum, currentLevel, counters) {
77
77
  return formatCounter(currentLevel.isLegal === true && lvlIdx !== currentLevel.ilvl ? "decimal" : level?.format ?? "decimal", counter);
78
78
  });
79
79
  }
80
+ /**
81
+ * A counter in the numerals a §17.18.59 format names: `lowerRoman` 4 is "iv".
82
+ * A format with no numeral for the number — a letter or a roman zero — gives
83
+ * the empty string.
84
+ *
85
+ * @param format The number format.
86
+ * @param n The counter's value.
87
+ * @returns The counter as that format writes it.
88
+ */
80
89
  function formatCounter(format, n) {
81
90
  if (n < 0) return "";
82
91
  switch (format) {
@@ -336,4 +345,4 @@ function normalizeBullet(lvlText) {
336
345
  return lvlText;
337
346
  }
338
347
  //#endregion
339
- export { NumberingState, effectiveAbstract, formatLevelMarker };
348
+ export { NumberingState, effectiveAbstract, formatCounter, formatLevelMarker };
@@ -1 +1 @@
1
- export type { CellType, WorksheetCell, ColumnStyle, ColumnWidth, MergedRange, RowHeight, RowStyle, XlsxPageMargins, XlsxPageSetup, XlsxPrintOptions, ParsedWorksheet, XlsxFont, XlsxFill, XlsxBorderStyleName, XlsxBorderEdge, XlsxBorder, XlsxHorizontalAlign, XlsxVerticalAlign, XlsxCellAlignment, XlsxCellXf, XlsxStyles, DefinedName, Dxf, CfOperator, CfRuleCellIs, CfvoType, Cfvo, CfRuleColorScale, CfRuleDataBar, CfRuleIconSet, CfRuleTop10, CfRuleAboveAverage, CfRuleDupUnique, CfRuleText, CfRuleExpression, CfRuleTimePeriod, TimePeriodKind, CfRule, ConditionalFormat, DataValidationType, DataValidation, HyperlinkRef, HeaderFooter, FormControlRef, OleObjectRef, SheetRichRun, SparklineKind, ParsedSparkline, ExcelTable, PivotTable, SheetPane, } from './types.js';
1
+ export type { CellType, WorksheetCell, ColumnStyle, ColumnWidth, MergedRange, RowHeight, RowStyle, XlsxPageMargins, XlsxPageSetup, XlsxPrintOptions, ParsedWorksheet, XlsxFont, XlsxFill, XlsxBorderStyleName, XlsxBorderEdge, XlsxBorder, XlsxHorizontalAlign, XlsxVerticalAlign, XlsxCellAlignment, XlsxCellXf, XlsxStyles, DefinedName, Dxf, CfOperator, CfRuleCellIs, CfvoType, Cfvo, CfRuleColorScale, CfRuleDataBar, CfRuleIconSet, CfRuleTop10, CfRuleAboveAverage, CfRuleDupUnique, CfRuleText, CfRuleExpression, CfRuleTimePeriod, TimePeriodKind, CfRule, ConditionalFormat, DataValidationType, DataValidation, HyperlinkRef, HeaderFooter, FormControlRef, OleObjectRef, SheetRichRun, SparklineKind, ParsedSparkline, ExcelTable, TableStyleElementType, TableStyleRegion, TableStyleFormat, XlsxTableStyle, PivotTable, SheetPane, } from './types.js';
@@ -171,6 +171,12 @@ export interface ParsedWorksheet {
171
171
  readonly colBreaks?: ReadonlyArray<number>;
172
172
  /** §18.3.1.36 `<drawing r:id>` — the sheet's drawing part (charts/shapes). */
173
173
  readonly drawingRelId?: string;
174
+ /**
175
+ * §18.3.1.99 — the sheet is a `<chartsheet>`: nothing but a chart, which
176
+ * prints filling the page, and on a landscape one unless the sheet says
177
+ * otherwise.
178
+ */
179
+ readonly chartSheet?: boolean;
174
180
  /**
175
181
  * §18.3.1.36 `<legacyDrawing r:id>` — the relationship to the sheet's VML
176
182
  * drawing part. A form control put on the sheet by Excel's Forms toolbar is
@@ -226,6 +232,22 @@ export interface ParsedWorksheet {
226
232
  * (E-SHEET SE2/SE3).
227
233
  */
228
234
  readonly pane?: SheetPane;
235
+ /**
236
+ * ECMA-376 §18.3.1.87 `<sheetView showGridLines>` — whether the sheet's
237
+ * window draws the cell gridlines. A VIEW setting, like the pane: what
238
+ * prints is `<printOptions gridLines>`. Carried for a screen projection and
239
+ * the round trip; absent ⇒ shown, the default.
240
+ */
241
+ readonly showGridLines?: boolean;
242
+ /**
243
+ * ECMA-376 §18.3.1.87 `<sheetView rightToLeft>` — the sheet reads from the
244
+ * right: column A stands at the right edge and the columns run leftward,
245
+ * and each cell's left and right borders cross over with it. What a cell's
246
+ * text does is unchanged — it keeps the side its alignment names. Unlike
247
+ * the pane and the gridlines this one prints: Excel puts the sheet on the
248
+ * paper the way the window shows it. Absent ⇒ left to right.
249
+ */
250
+ readonly rightToLeft?: boolean;
229
251
  }
230
252
  /**
231
253
  * A frozen pane: the count of leading rows / columns frozen in the worksheet
@@ -236,6 +258,28 @@ export interface SheetPane {
236
258
  readonly frozenRows: number;
237
259
  readonly frozenCols: number;
238
260
  }
261
+ /**
262
+ * §18.18.77 ST_TableStyleType — the regions of a table a table style formats,
263
+ * in the order they apply (§18.8.41): a later region's format wins where both
264
+ * say something.
265
+ */
266
+ export type TableStyleElementType = 'wholeTable' | 'firstColumnStripe' | 'secondColumnStripe' | 'firstRowStripe' | 'secondRowStripe' | 'lastColumn' | 'firstColumn' | 'headerRow' | 'totalRow' | 'firstHeaderCell' | 'lastHeaderCell' | 'firstTotalCell' | 'lastTotalCell';
267
+ /** §18.8.40 — one region's format in a table style: its dxf, and a stripe's band size. */
268
+ export interface TableStyleRegion {
269
+ readonly dxf: Dxf;
270
+ /** §18.8.41 `size` — rows (or columns) in one band of a stripe; default 1. */
271
+ readonly size?: number;
272
+ }
273
+ /** §18.8.40 — a table style, region by region, its colours resolved. */
274
+ export type TableStyleFormat = Partial<Record<TableStyleElementType, TableStyleRegion>>;
275
+ /** §18.8.40 `<tableStyle>` — a style a workbook defines itself: each region's dxf. */
276
+ export interface XlsxTableStyle {
277
+ readonly elements: ReadonlyArray<{
278
+ readonly type: TableStyleElementType;
279
+ readonly dxfId: number;
280
+ readonly size?: number;
281
+ }>;
282
+ }
239
283
  /**
240
284
  * ECMA-376 §18.5.1.2 `<table>` — a structured table over a cell range with a
241
285
  * banded style. The raw parse carries the range, header rows and style flags;
@@ -247,6 +291,13 @@ export interface ExcelTable {
247
291
  readonly name?: string;
248
292
  readonly styleName?: string;
249
293
  readonly headerRowCount: number;
294
+ /** §18.5.1.2 `totalsRowCount` — the totals rows at the foot of the table (default 0). */
295
+ readonly totalsRowCount?: number;
296
+ /**
297
+ * §18.5.1.3 `<tableColumn name>` — the columns' names, left to right: what a
298
+ * structured reference (`tblIncome[Amount]`) names a column by.
299
+ */
300
+ readonly columns?: ReadonlyArray<string>;
250
301
  readonly showRowStripes: boolean;
251
302
  readonly showColumnStripes: boolean;
252
303
  readonly showFirstColumn: boolean;
@@ -259,6 +310,12 @@ export interface ExcelTable {
259
310
  readonly headerHex?: string;
260
311
  readonly bandHex?: string;
261
312
  readonly headerTextHex?: string;
313
+ /**
314
+ * §18.8.40 — the style the table names, region by region: one Excel builds
315
+ * in (TableStyleMedium2) or one the workbook defines, its colours resolved
316
+ * against the workbook's theme.
317
+ */
318
+ readonly style?: TableStyleFormat;
262
319
  }
263
320
  /**
264
321
  * ECMA-376 §18.10.1.73 `<pivotTableDefinition>` — a pivot table. Its OUTPUT
@@ -314,6 +371,14 @@ export interface XlsxFont {
314
371
  /** §18.8.37 `<strike/>` — the font is struck through. */
315
372
  readonly strike?: boolean;
316
373
  readonly colorHex?: string;
374
+ /**
375
+ * §18.8.3 — how the `<color>` names the colour, not what it comes to:
376
+ * `theme:1:0`, `rgb:FF000000`, `indexed:8`, `auto`; undefined for a font with
377
+ * no `<color>`. Excel lets a table style colour a cell's text only where the
378
+ * cell names its colour as the Normal style does — `theme="1"` black takes
379
+ * the style's white, `rgb="FF000000"` black keeps its own.
380
+ */
381
+ readonly colorRef?: string;
317
382
  readonly name?: string;
318
383
  }
319
384
  /** §18.8.20 `<fill>` — one fill record: pattern type plus foreground/background colours. */
@@ -343,6 +408,13 @@ export interface XlsxBorder {
343
408
  readonly diagonal?: XlsxBorderEdge;
344
409
  readonly diagonalUp?: boolean;
345
410
  readonly diagonalDown?: boolean;
411
+ /**
412
+ * §18.8.4 `<vertical>`/`<horizontal>` — the lines BETWEEN the cells of a range
413
+ * a differential format covers: a table style's rules between its columns
414
+ * and between its rows. A cell's own border has no use for them.
415
+ */
416
+ readonly vertical?: XlsxBorderEdge;
417
+ readonly horizontal?: XlsxBorderEdge;
346
418
  }
347
419
  /** §18.18.40 ST_HorizontalAlignment — `<alignment horizontal>`. */
348
420
  export type XlsxHorizontalAlign = 'left' | 'center' | 'right' | 'fill' | 'justify' | 'centerContinuous' | 'distributed';
@@ -362,6 +434,12 @@ export interface XlsxCellAlignment {
362
434
  readonly textRotation?: number;
363
435
  /** §18.8.1 `shrinkToFit` — scale the text down so it fits the cell on one line (W6). */
364
436
  readonly shrinkToFit?: boolean;
437
+ /**
438
+ * §18.8.1 `readingOrder` — `1` left to right, `2` right to left. Absent (or
439
+ * `0`) is "context": the direction of the text's first strong character,
440
+ * which is also what a General cell aligns its text by.
441
+ */
442
+ readonly readingOrder?: 'ltr' | 'rtl';
365
443
  }
366
444
  /**
367
445
  * §18.8.45 `<xf>` — one cell format record: indices into the font/fill/border/
@@ -395,6 +473,11 @@ export interface XlsxStyles {
395
473
  * rules (E-SHEET SC1); only the properties a dxf sets override the base.
396
474
  */
397
475
  readonly dxfs?: ReadonlyArray<Dxf>;
476
+ /**
477
+ * §18.8.42 `<tableStyles>` — the table styles the workbook defines itself,
478
+ * by name; their regions point into {@link XlsxStyles.dxfs}.
479
+ */
480
+ readonly tableStyles?: ReadonlyMap<string, XlsxTableStyle>;
398
481
  }
399
482
  /** §18.8.14 `<dxf>` — a differential (override) format a `cfRule` applies on match. */
400
483
  export interface Dxf {
@@ -489,6 +572,11 @@ export interface CfRuleDataBar {
489
572
  * figure does not sit on top of its own gauge.
490
573
  */
491
574
  readonly showValue?: boolean;
575
+ /**
576
+ * The 2009 extension's `<x14:dataBar gradient>` — false paints the bar in
577
+ * one solid colour, where Excel's default fades it from the axis.
578
+ */
579
+ readonly gradient?: boolean;
492
580
  }
493
581
  /**
494
582
  * §18.3.1.49 `<cfRule type="iconSet">` — picks one glyph per cell from a named
@@ -501,6 +589,12 @@ export interface CfRuleIconSet {
501
589
  readonly iconSet: string;
502
590
  readonly cfvos: ReadonlyArray<Cfvo>;
503
591
  readonly reverse?: boolean;
592
+ /**
593
+ * §18.3.1.49 `showValue` — false means the cell shows its ICON ONLY, as a
594
+ * status column of ticks and crosses does: the figure is what the icon
595
+ * already says.
596
+ */
597
+ readonly showValue?: boolean;
504
598
  }
505
599
  /**
506
600
  * §18.3.1.10 `<cfRule type="top10">` — the top (or `bottom`) N values of the
@@ -708,6 +802,8 @@ export interface SheetRichRun {
708
802
  readonly sizePt?: number;
709
803
  /** §18.4.2 `<vertAlign>` — superscript / subscript within the cell text. */
710
804
  readonly vertAlign?: 'superscript' | 'subscript';
805
+ /** §18.4.5 `<rFont>` — the run's typeface, where the producer names one. */
806
+ readonly fontName?: string;
711
807
  }
712
808
  /**
713
809
  * §18.18.18 ST_DataValidationType — the constraint a `<dataValidation>`