reamkit 1.32.1 → 1.33.1

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 (165) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +16 -11
  3. package/dist/esm/core/bidi/algorithm.js +2 -2
  4. package/dist/esm/core/bidi/char-types.js +1 -1
  5. package/dist/esm/core/bidi/index.js +3 -3
  6. package/dist/esm/core/bytes.js +1 -1
  7. package/dist/esm/core/converter/facade.js +10 -5
  8. package/dist/esm/core/converter/ream.d.ts +9 -0
  9. package/dist/esm/core/converter/ream.js +40 -10
  10. package/dist/esm/core/crypto/asn1.js +2 -2
  11. package/dist/esm/core/crypto/cms.js +5 -3
  12. package/dist/esm/core/crypto/index.js +2 -1
  13. package/dist/esm/core/crypto/offcrypto.d.ts +2 -5
  14. package/dist/esm/core/crypto/offcrypto.js +9 -15
  15. package/dist/esm/core/crypto/password-error.d.ts +8 -0
  16. package/dist/esm/core/crypto/password-error.js +14 -0
  17. package/dist/esm/core/crypto/primitives.js +16 -16
  18. package/dist/esm/core/document-model/index.d.ts +1 -1
  19. package/dist/esm/core/document-model/types.d.ts +174 -2
  20. package/dist/esm/core/drawingml/chart-geometry.d.ts +24 -6
  21. package/dist/esm/core/drawingml/chart-geometry.js +905 -208
  22. package/dist/esm/core/drawingml/chart-parser.d.ts +5 -1
  23. package/dist/esm/core/drawingml/chart-parser.js +275 -19
  24. package/dist/esm/core/drawingml/chart-text.d.ts +41 -0
  25. package/dist/esm/core/drawingml/chart-text.js +93 -0
  26. package/dist/esm/core/drawingml/colors.js +5 -5
  27. package/dist/esm/core/drawingml/diagram/layout-engine.js +1 -4
  28. package/dist/esm/core/drawingml/diagram/run.js +2 -1
  29. package/dist/esm/core/drawingml/preset-geometry.js +4 -6
  30. package/dist/esm/core/drawingml/shape-render.js +1 -1
  31. package/dist/esm/core/drawingml/text-warp.js +4 -16
  32. package/dist/esm/core/drawingml/theme-parser.js +14 -8
  33. package/dist/esm/core/font/arabic-joining.js +2 -2
  34. package/dist/esm/core/font/binary-reader.js +2 -0
  35. package/dist/esm/core/font/font-registry.js +1 -0
  36. package/dist/esm/core/font/ligatures.js +1 -1
  37. package/dist/esm/core/font/opentype-layout.js +11 -5
  38. package/dist/esm/core/font/ttf-build.js +6 -10
  39. package/dist/esm/core/font/ttf-parser.js +2 -1
  40. package/dist/esm/core/font/ttf-subset.js +8 -8
  41. package/dist/esm/core/fonts/families.js +1 -1
  42. package/dist/esm/core/fonts/remote-fonts.js +4 -4
  43. package/dist/esm/core/hyphenation/index.js +1 -1
  44. package/dist/esm/core/images.js +8 -8
  45. package/dist/esm/core/ir/adapters.d.ts +9 -0
  46. package/dist/esm/core/ir/loss.js +1 -0
  47. package/dist/esm/core/line-breaker/cjk.js +1 -1
  48. package/dist/esm/core/line-breaker/index.js +4 -3
  49. package/dist/esm/core/links.js +1 -1
  50. package/dist/esm/core/lzw.js +1 -1
  51. package/dist/esm/core/metafile/blit.js +1 -1
  52. package/dist/esm/core/metafile/emf.js +5 -7
  53. package/dist/esm/core/metafile/picture.js +1 -1
  54. package/dist/esm/core/metafile/symbol-fonts.js +7 -7
  55. package/dist/esm/core/metafile/wmf.js +5 -7
  56. package/dist/esm/core/number-format.js +4 -6
  57. package/dist/esm/core/numbering/index.js +3 -2
  58. package/dist/esm/core/ole/cfb.js +4 -4
  59. package/dist/esm/core/ole/escher-blip.js +1 -1
  60. package/dist/esm/core/opc/index.js +5 -4
  61. package/dist/esm/core/opc/package.js +3 -1
  62. package/dist/esm/core/opc/xml-entities.js +1 -1
  63. package/dist/esm/core/outline.js +1 -1
  64. package/dist/esm/core/png-encode.js +3 -3
  65. package/dist/esm/core/po-helpers.js +1 -1
  66. package/dist/esm/core/spreadsheet-model/types.d.ts +6 -0
  67. package/dist/esm/core/style-cascade/index.js +4 -3
  68. package/dist/esm/core/tiff.js +3 -1
  69. package/dist/esm/excel/activex-parser.js +1 -1
  70. package/dist/esm/excel/conditional-format.js +7 -7
  71. package/dist/esm/excel/formula/functions.js +8 -4
  72. package/dist/esm/excel/formula/index.js +3 -3
  73. package/dist/esm/excel/formula/lexer.js +2 -2
  74. package/dist/esm/excel/formula/parser.js +4 -3
  75. package/dist/esm/excel/formula/value.js +1 -1
  76. package/dist/esm/excel/index.js +7 -6
  77. package/dist/esm/excel/print-model.d.ts +1 -0
  78. package/dist/esm/excel/print-model.js +7 -32
  79. package/dist/esm/excel/printer-settings.js +6 -7
  80. package/dist/esm/excel/rich-value.js +1 -1
  81. package/dist/esm/excel/sheet-shape-parser.js +4 -2
  82. package/dist/esm/excel/sheet-to-flow.d.ts +8 -0
  83. package/dist/esm/excel/sheet-to-flow.js +14 -11
  84. package/dist/esm/excel/styles-parser.js +5 -3
  85. package/dist/esm/excel/tint.js +5 -5
  86. package/dist/esm/excel/vml-drawing.js +2 -2
  87. package/dist/esm/excel/worksheet-parser.js +5 -5
  88. package/dist/esm/excel/xls/biff-chart.js +1 -3
  89. package/dist/esm/excel/xls/biff-reader.js +10 -11
  90. package/dist/esm/excel/xls/xls-reader.js +1 -1
  91. package/dist/esm/excel/xlsx-reader.js +17 -4
  92. package/dist/esm/excel/xlsx-to-pdf.js +1 -1
  93. package/dist/esm/excel/xlsx-writer.js +2 -2
  94. package/dist/esm/html/html-writer.js +18 -10
  95. package/dist/esm/index.js +2 -1
  96. package/dist/esm/layout/line-paint.js +1 -1
  97. package/dist/esm/layout/math-layout.js +5 -8
  98. package/dist/esm/layout/styled-layout.js +133 -75
  99. package/dist/esm/layout/turned-section.js +2 -2
  100. package/dist/esm/markdown/markdown-writer.js +50 -9
  101. package/dist/esm/pdf/encryption.js +9 -9
  102. package/dist/esm/pdf/icc-profile.js +2 -2
  103. package/dist/esm/pdf/index.js +3 -2
  104. package/dist/esm/pdf/objects.js +7 -0
  105. package/dist/esm/pdf/serialize.js +1 -1
  106. package/dist/esm/pdf/struct-tree.js +3 -1
  107. package/dist/esm/pdf/styled-page-emitter.js +23 -15
  108. package/dist/esm/pdf/styled-page-renderer.js +9 -5
  109. package/dist/esm/pdf-reader/annot-draw.js +3 -3
  110. package/dist/esm/pdf-reader/ccitt.js +2 -1
  111. package/dist/esm/pdf-reader/cff-outline.js +1 -4
  112. package/dist/esm/pdf-reader/content.js +13 -15
  113. package/dist/esm/pdf-reader/decrypt.d.ts +18 -6
  114. package/dist/esm/pdf-reader/decrypt.js +90 -45
  115. package/dist/esm/pdf-reader/document.d.ts +7 -1
  116. package/dist/esm/pdf-reader/document.js +18 -4
  117. package/dist/esm/pdf-reader/encodings.js +1 -1
  118. package/dist/esm/pdf-reader/flow-build.js +4 -6
  119. package/dist/esm/pdf-reader/font.js +3 -3
  120. package/dist/esm/pdf-reader/function.js +8 -7
  121. package/dist/esm/pdf-reader/icc.js +1 -1
  122. package/dist/esm/pdf-reader/images.js +1 -1
  123. package/dist/esm/pdf-reader/jbig2.js +36 -38
  124. package/dist/esm/pdf-reader/jpeg.js +14 -13
  125. package/dist/esm/pdf-reader/layout.js +12 -9
  126. package/dist/esm/pdf-reader/lexer.js +2 -1
  127. package/dist/esm/pdf-reader/math-rows.js +2 -2
  128. package/dist/esm/pdf-reader/optional-content.js +1 -1
  129. package/dist/esm/pdf-reader/page-numbers.js +1 -1
  130. package/dist/esm/pdf-reader/pattern-tint.js +1 -2
  131. package/dist/esm/pdf-reader/reader.d.ts +5 -1
  132. package/dist/esm/pdf-reader/reader.js +83 -16
  133. package/dist/esm/pdf-reader/struct-tree.js +1 -1
  134. package/dist/esm/pdf-reader/tagged.js +3 -2
  135. package/dist/esm/pdf-reader/text.js +2 -2
  136. package/dist/esm/pdf-reader/type1-outline.js +1 -3
  137. package/dist/esm/pptx/embedded-fonts.js +3 -5
  138. package/dist/esm/pptx/placeholder-cascade.js +1 -1
  139. package/dist/esm/pptx/ppt/ppt-reader.js +5 -4
  140. package/dist/esm/pptx/ppt/ppt-text.js +9 -10
  141. package/dist/esm/pptx/pptx-reader.js +6 -5
  142. package/dist/esm/pptx/preset-table-styles.js +1 -1
  143. package/dist/esm/pptx/slide-parser.js +6 -4
  144. package/dist/esm/pptx/sp-helpers.js +1 -1
  145. package/dist/esm/pptx/table-style.js +2 -1
  146. package/dist/esm/svg/svg-writer.js +1 -1
  147. package/dist/esm/word/doc/doc-reader.js +2 -2
  148. package/dist/esm/word/doc/doc-text.js +20 -22
  149. package/dist/esm/word/document-parser.js +26 -21
  150. package/dist/esm/word/docx-reader.js +2 -2
  151. package/dist/esm/word/docx-to-pdf.js +3 -3
  152. package/dist/esm/word/docx-writer.js +10 -6
  153. package/dist/esm/word/drawing-parser.js +18 -18
  154. package/dist/esm/word/font-table.js +1 -1
  155. package/dist/esm/word/index.js +6 -5
  156. package/dist/esm/word/numbering-parser.js +4 -3
  157. package/dist/esm/word/omml-parser.js +1 -1
  158. package/dist/esm/word/paragraph-properties.js +11 -10
  159. package/dist/esm/word/run-properties.js +4 -4
  160. package/dist/esm/word/settings-parser.js +2 -1
  161. package/dist/esm/word/shading.js +1 -1
  162. package/dist/esm/word/styles-parser.js +5 -4
  163. package/dist/esm/word/table-parser.js +4 -4
  164. package/dist/esm/word/theme-fonts.js +1 -1
  165. package/package.json +9 -3
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Alex Krassavin
3
+ Copyright (c) 2026 Alexandr Krassavin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -59,8 +59,9 @@ and `doc.convertWithReport(...)` returns `{ bytes, losses }` (pass
59
59
  are plain `Uint8Array`s, so wiring this to files, the network, or disk is up
60
60
  to you.
61
61
 
62
- An encrypted source opens with its password — a PDF's user password, or an
63
- Office package's (MS-OFFCRYPTO, Agile and Standard):
62
+ An encrypted source opens with its password — a PDF's user or owner password,
63
+ or an Office package's (MS-OFFCRYPTO, Agile and Standard). A wrong one, or none
64
+ where one is needed, throws `WrongPasswordError`:
64
65
 
65
66
  ```ts
66
67
  const doc = Ream.parse(bytes, { password: 'secret' });
@@ -213,10 +214,11 @@ own PDF: columns in the Normal font's digit as Excel counts it, a table in the
213
214
  style it names, a theme colour's tint to the digit, a sheet that reads from the
214
215
  right turned round, the notes it shows beside their cells, its drawings over
215
216
  the cells and cut where its pages are, a chart's axes scaled and crossed where
216
- Excel puts them. As HTML a workbook comes out as Excel's window shows it —
217
- every tab, its gridlines, a noted cell flagged with the note on hover — and as
218
- SVG as pictures of its sheets, each whole, its text drawn from the faces' own
219
- outlines.
217
+ Excel puts them, its text in the face Excel sets it in, its 3-D bars and pies
218
+ standing in three dimensions. As HTML a workbook comes out as Excel's window
219
+ shows it — every tab, its gridlines, a noted cell flagged with the note on
220
+ hover — and as SVG as pictures of its sheets, each whole, its text drawn from
221
+ the faces' own outlines.
220
222
 
221
223
  **Reads PDF, too.** `Ream.parse` accepts a PDF and reconstructs a `FlowDoc` — a
222
224
  tagged PDF from its structure tree (headings, tables, lists, reading order), an
@@ -252,14 +254,17 @@ itself whether a file is a document to re-flow or a page to keep — a paper is
252
254
  mostly lines, a form is mostly marks — and there is nothing to configure: a
253
255
  caller cannot know which of the two it was handed. It reads modern compressed
254
256
  files (cross-reference + object streams) and encrypted ones (RC4 / AES — the
255
- user password is passed to `Ream.parse(bytes, { password })`, defaulting to the
256
- permissions-only case); a filter it does not carry can be handed to it through
257
- `Ream.parse(bytes, { filters })`.
257
+ user or owner password is passed to `Ream.parse(bytes, { password })`,
258
+ defaulting to the permissions-only case, and one that opens the file as neither
259
+ throws `WrongPasswordError`); a filter it does not carry can be handed to it
260
+ through `Ream.parse(bytes, { filters })`.
258
261
 
259
262
  A form or a drawing is not a reflowable document, so the reader keeps it as a
260
263
  page instead: every line stands where its glyphs stand, beside the artwork, the
261
264
  way up the page is shown. Which of the two readings a file gets it decides
262
- itself and records in the losses.
265
+ itself and records in the losses. Markdown, which places nothing, reads a page
266
+ kept only for its table's rules, or for letters the file names no character
267
+ for, as the document it is without them.
263
268
 
264
269
  **Reads PowerPoint, too.** `Ream.parse` accepts a `.pptx` and turns each slide
265
270
  into a page at the deck size — text boxes (with run formatting, alignment,
@@ -290,4 +295,4 @@ and known limitations.
290
295
 
291
296
  ## License
292
297
 
293
- [MIT](./LICENSE) © Alex Krassavin
298
+ [MIT](./LICENSE) — Copyright (c) 2026 Alexandr Krassavin
@@ -268,7 +268,7 @@ function resolveWeakTypes(types, seq) {
268
268
  else if (t === "EN" && lastStrong === "L") types[i] = "L";
269
269
  }
270
270
  }
271
- var BRACKET_OPEN_TO_CLOSE = new Map([
271
+ var BRACKET_OPEN_TO_CLOSE = /* @__PURE__ */ new Map([
272
272
  [40, 41],
273
273
  [91, 93],
274
274
  [123, 125],
@@ -447,7 +447,7 @@ function reorderVisual(levels) {
447
447
  const order = Array.from({ length: n }, (_, i) => i);
448
448
  if (n === 0) return order;
449
449
  let highest = 0;
450
- let lowestOdd = MAX_DEPTH + 1;
450
+ let lowestOdd = 126;
451
451
  for (const lvl of levels) {
452
452
  if (lvl > highest) highest = lvl;
453
453
  if (lvl % 2 === 1 && lvl < lowestOdd) lowestOdd = lvl;
@@ -1,5 +1,5 @@
1
1
  //#region src/core/bidi/char-types.ts
2
- var SINGLE = new Map([
2
+ var SINGLE = /* @__PURE__ */ new Map([
3
3
  [9, "S"],
4
4
  [10, "B"],
5
5
  [11, "S"],
@@ -1,6 +1,6 @@
1
1
  import { bidiClass } from "./char-types.js";
2
- import { computeBidi } from "./algorithm.js";
3
- import "./segments.js";
2
+ import { computeBidi, reorderVisual } from "./algorithm.js";
3
+ import { segmentLevels } from "./segments.js";
4
4
  //#region src/core/bidi/index.ts
5
5
  /**
6
6
  * Run the UAX #9 algorithm over a string, returning per-code-point embedding
@@ -66,4 +66,4 @@ function reverseByCodePoint(text) {
66
66
  return [...text].reverse().join("");
67
67
  }
68
68
  //#endregion
69
- export { analyzeString, firstStrongDirection, hasBidiCharacters, reverseByCodePoint };
69
+ export { analyzeString, bidiClass, firstStrongDirection, hasBidiCharacters, reorderVisual, reverseByCodePoint, segmentLevels };
@@ -104,4 +104,4 @@ function bytesInclude(haystack, needle) {
104
104
  return false;
105
105
  }
106
106
  //#endregion
107
- export { bytesInclude, packageHasPart, toBase64 };
107
+ export { bytesInclude, bytesIncludePartName, packageHasPart, toBase64 };
@@ -35,8 +35,9 @@ import { pdfReader } from "../../pdf-reader/reader.js";
35
35
  function toFlowDoc(doc, options = {}) {
36
36
  return doc.kind === "sheet" ? projectSheetDoc(doc, options) : doc;
37
37
  }
38
- function readToFlow(reader, bytes, options = {}) {
39
- const { doc, losses } = reader.read(bytes);
38
+ function readToFlow(reader, bytes, options = {}, placesNothing = false) {
39
+ const read = reader.read(bytes);
40
+ const { doc, losses } = (placesNothing ? read.flowing?.() : void 0) ?? read;
40
41
  return {
41
42
  doc: toFlowDoc(doc, options),
42
43
  losses
@@ -93,7 +94,10 @@ function createConverter(opts = {}) {
93
94
  };
94
95
  }
95
96
  if (to === "md") {
96
- const { doc: flow, losses: readLosses } = readToFlow(reader, bytes, rest.now ? { now: rest.now } : void 0);
97
+ const { doc: flow, losses: readLosses } = readToFlow(reader, bytes, {
98
+ ...rest.now ? { now: rest.now } : {},
99
+ spill: false
100
+ }, true);
97
101
  losses.push(...readLosses);
98
102
  const markdown = writeMarkdown(flow);
99
103
  losses.push(...markdown.losses);
@@ -129,10 +133,11 @@ function createConverter(opts = {}) {
129
133
  if (!fonts) throw new Error("to: 'svg' requires options.fonts/fontBytes or fontProviders");
130
134
  const { doc } = reader.read(bytes);
131
135
  const registry = FontRegistry.fromBytes(fonts);
132
- const svg = writeSvg(doc.kind === "sheet" ? layoutSheetImages(doc, { registry }, rest.now ? { now: rest.now } : {}) : layoutStyledDocument(doc.body, {
136
+ const laid = doc.kind === "sheet" ? layoutSheetImages(doc, { registry }, rest.now ? { now: rest.now } : {}) : layoutStyledDocument(doc.body, {
133
137
  registry,
134
138
  ...flowRenderOptions(doc)
135
- }));
139
+ });
140
+ const svg = writeSvg(laid);
136
141
  losses.push(...svg.losses);
137
142
  if (strict && losses.length > 0) throw new ConversionLossError(losses[0]);
138
143
  return {
@@ -130,6 +130,7 @@ export declare class Ream {
130
130
  readonly losses: ReadonlyArray<Loss>;
131
131
  private readonly source;
132
132
  private readonly readerId;
133
+ private readonly flowing?;
133
134
  /**
134
135
  * @param flow The interlayer — the parsed, format-neutral document tree.
135
136
  * @param sheet The native SpreadsheetML tree when the source is a spreadsheet
@@ -138,8 +139,13 @@ export declare class Ream {
138
139
  * @param source The original source bytes (kept only for docx auto-fonts and
139
140
  * PDF/A-3 `embedSource`).
140
141
  * @param readerId The id of the reader that parsed the source.
142
+ * @param flowing The source read as a document that flows, where the reader
143
+ * kept it as a page for marks Markdown drops anyway (see
144
+ * {@link ReadResult.flowing}).
141
145
  */
142
146
  private constructor();
147
+ /** The flowing reading, once Markdown has asked for it. */
148
+ private flowingRead;
143
149
  /**
144
150
  * Sniff the format and parse the bytes once into the {@link FlowDoc} interlayer.
145
151
  *
@@ -148,6 +154,9 @@ export declare class Ream {
148
154
  * encrypted source.
149
155
  * @returns A reusable {@link Ream} instance.
150
156
  * @throws Error when no registered reader recognizes the bytes.
157
+ * @throws WrongPasswordError when the bytes are encrypted — an Office package
158
+ * or a PDF — and the password does not open them, or none was given
159
+ * where one is needed.
151
160
  */
152
161
  static parse(bytes: Uint8Array, options?: ReamParseOptions): Ream;
153
162
  /** The source format id (`'docx'`, `'xlsx'`, …). */
@@ -15,6 +15,7 @@ import { writeXlsx } from "../../excel/xlsx-writer.js";
15
15
  import { writeHtml } from "../../html/html-writer.js";
16
16
  import { writeMarkdown } from "../../markdown/markdown-writer.js";
17
17
  import { writeSvg } from "../../svg/svg-writer.js";
18
+ import { WrongPasswordError } from "../crypto/password-error.js";
18
19
  import { DEFAULT_READERS, resolveFontsViaChain, toFlowDoc } from "./facade.js";
19
20
  import { familiesInFlow } from "../fonts/families.js";
20
21
  import { decryptPackage, isEncryptedPackage } from "../crypto/offcrypto.js";
@@ -53,6 +54,12 @@ var SOURCE_MIME = {
53
54
  * substitute-font auto-detection and PDF/A-3 `embedSource`.
54
55
  */
55
56
  var Ream = class Ream {
57
+ flow;
58
+ sheet;
59
+ losses;
60
+ source;
61
+ readerId;
62
+ flowing;
56
63
  /**
57
64
  * @param flow The interlayer — the parsed, format-neutral document tree.
58
65
  * @param sheet The native SpreadsheetML tree when the source is a spreadsheet
@@ -61,14 +68,20 @@ var Ream = class Ream {
61
68
  * @param source The original source bytes (kept only for docx auto-fonts and
62
69
  * PDF/A-3 `embedSource`).
63
70
  * @param readerId The id of the reader that parsed the source.
71
+ * @param flowing The source read as a document that flows, where the reader
72
+ * kept it as a page for marks Markdown drops anyway (see
73
+ * {@link ReadResult.flowing}).
64
74
  */
65
- constructor(flow, sheet, losses, source, readerId) {
75
+ constructor(flow, sheet, losses, source, readerId, flowing) {
66
76
  this.flow = flow;
67
77
  this.sheet = sheet;
68
78
  this.losses = losses;
69
79
  this.source = source;
70
80
  this.readerId = readerId;
81
+ this.flowing = flowing;
71
82
  }
83
+ /** The flowing reading, once Markdown has asked for it. */
84
+ flowingRead;
72
85
  /**
73
86
  * Sniff the format and parse the bytes once into the {@link FlowDoc} interlayer.
74
87
  *
@@ -77,22 +90,32 @@ var Ream = class Ream {
77
90
  * encrypted source.
78
91
  * @returns A reusable {@link Ream} instance.
79
92
  * @throws Error when no registered reader recognizes the bytes.
93
+ * @throws WrongPasswordError when the bytes are encrypted — an Office package
94
+ * or a PDF — and the password does not open them, or none was given
95
+ * where one is needed.
80
96
  */
81
97
  static parse(bytes, options = {}) {
82
98
  const readers = options.readers ?? DEFAULT_READERS;
83
99
  let source = bytes;
84
100
  if (isEncryptedPackage(bytes)) {
85
- if (options.password === void 0) throw new Error("Password-protected OOXML document (ECMA-376 §2.3 EncryptedPackage) — pass the password as `password`");
101
+ if (options.password === void 0) throw new WrongPasswordError("Password-protected OOXML document (ECMA-376 §2.3 EncryptedPackage) — pass the password as `password`");
86
102
  source = decryptPackage(bytes, options.password);
87
103
  }
88
104
  const reader = readers.find((r) => r.sniff(source));
89
105
  if (!reader) throw new Error(`Unrecognized document format (readers: ${readers.map((r) => r.id).join(", ")})`);
90
- const { doc, losses } = reader.read(source, {
106
+ const { doc, losses, flowing } = reader.read(source, {
91
107
  password: options.password,
92
108
  ...options.filters ? { filters: options.filters } : {}
93
109
  });
94
110
  const sheet = doc.kind === "sheet" ? doc : void 0;
95
- return new Ream(toFlowDoc(doc), sheet, losses, bytes, reader.id);
111
+ const reflow = flowing ? () => {
112
+ const read = flowing();
113
+ return {
114
+ doc: toFlowDoc(read.doc),
115
+ losses: read.losses
116
+ };
117
+ } : void 0;
118
+ return new Ream(toFlowDoc(doc), sheet, losses, bytes, reader.id, reflow);
96
119
  }
97
120
  /** The source format id (`'docx'`, `'xlsx'`, …). */
98
121
  get format() {
@@ -142,11 +165,17 @@ var Ream = class Ream {
142
165
  };
143
166
  }
144
167
  if (to === "md") {
145
- const markdown = writeMarkdown(this.sheet && options.sheetNames !== false ? projectSheetDoc(this.sheet, {
168
+ if (this.flowing) {
169
+ this.flowingRead ??= this.flowing();
170
+ losses.splice(0, this.losses.length, ...this.flowingRead.losses);
171
+ }
172
+ const source = this.sheet && options.sheetNames !== false ? projectSheetDoc(this.sheet, {
146
173
  ...options.now ? { now: options.now } : {},
147
174
  ...options.fileName ? { fileName: options.fileName } : {},
148
- sheetHeadings: true
149
- }) : flow, {
175
+ sheetHeadings: true,
176
+ spill: false
177
+ }) : this.flowingRead?.doc ?? flow;
178
+ const markdown = writeMarkdown(source, {
150
179
  ...options.images ? { images: options.images } : {},
151
180
  ...options.pageBreaks ? { pageBreaks: options.pageBreaks } : {}
152
181
  });
@@ -189,11 +218,12 @@ var Ream = class Ream {
189
218
  registry,
190
219
  ...registriesByFamily ? { registriesByFamily } : {}
191
220
  };
192
- const svg = writeSvg(this.sheet ? layoutSheetImages(this.sheet, faces, sheetOptions, renderOptions) : layoutStyledDocument(flow.body, {
221
+ const laid = this.sheet ? layoutSheetImages(this.sheet, faces, sheetOptions, renderOptions) : layoutStyledDocument(flow.body, {
193
222
  ...faces,
194
223
  ...flowRenderOptions(flow),
195
224
  ...renderOptions
196
- }));
225
+ });
226
+ const svg = writeSvg(laid);
197
227
  losses.push(...svg.losses);
198
228
  this.enforceStrict(options, losses);
199
229
  return {
@@ -250,7 +280,7 @@ var Ream = class Ream {
250
280
  if (fonts) return { fonts };
251
281
  }
252
282
  const fetchOpt = options.fontFetch ? { fetch: options.fontFetch } : {};
253
- const keys = options.fontFamily ? new Set([resolveFamilyKey(options.fontFamily)]) : familiesInFlow(flow);
283
+ const keys = options.fontFamily ? /* @__PURE__ */ new Set([resolveFamilyKey(options.fontFamily)]) : familiesInFlow(flow);
254
284
  if (keys.size <= 1 && scriptsInFlow(flow).scripts.size === 0) {
255
285
  const family = keys.values().next().value;
256
286
  return { fonts: await fetchFontSet({
@@ -49,7 +49,7 @@ var set = (...items) => tlv(49, concat(items));
49
49
  /** OCTET STRING (tag `0x04`) wrapping raw `bytes`. */
50
50
  var octetString = (bytes) => tlv(4, bytes);
51
51
  /** NULL (tag `0x05`, empty content). */
52
- var nullValue = () => tlv(5, new Uint8Array(0));
52
+ var nullValue = () => tlv(5, /* @__PURE__ */ new Uint8Array(0));
53
53
  /** `[n]` context-tag, constructed (EXPLICIT or IMPLICIT-over-constructed). */
54
54
  var explicit = (tagNum, content) => tlv(160 | tagNum, content);
55
55
  function base128(v) {
@@ -185,4 +185,4 @@ function certIssuerAndSerial(cert) {
185
185
  };
186
186
  }
187
187
  //#endregion
188
- export { certIssuerAndSerial, cmsTime, concat, explicit, integer, nullValue, octetString, oid, seq, set, setOfBody, tlv };
188
+ export { certIssuerAndSerial, cmsTime, concat, explicit, integer, nullValue, octetString, oid, readTlv, seq, set, setOfBody, tlv };
@@ -24,17 +24,19 @@ var attribute = (oidStr, value) => seq(oid(oidStr), set(value));
24
24
  */
25
25
  async function buildPkcs7Detached(params) {
26
26
  const { issuer, serial } = certIssuerAndSerial(params.certificate);
27
- const attrsBody = setOfBody([
27
+ const attrs = [
28
28
  attribute(OID.contentType, oid(OID.idData)),
29
29
  attribute(OID.messageDigest, octetString(params.messageDigest)),
30
30
  attribute(OID.signingTime, cmsTime(params.signingTime))
31
- ]);
31
+ ];
32
+ const attrsBody = setOfBody(attrs);
32
33
  const signedAttrsForSigning = tlv(49, attrsBody);
33
34
  const signedAttrsTagged = tlv(160, attrsBody);
34
35
  const signature = await params.sign(signedAttrsForSigning);
35
36
  const sigAlgId = params.signatureAlgorithm === "ecdsa" ? ecdsaAlgId() : rsaAlgId();
36
37
  const signerInfo = seq(integer(1), seq(issuer, serial), sha256AlgId(), signedAttrsTagged, sigAlgId, octetString(signature));
37
- const certificates = tlv(160, concat([params.certificate, ...params.extraCertificates ?? []]));
38
+ const certBlobs = [params.certificate, ...params.extraCertificates ?? []];
39
+ const certificates = tlv(160, concat(certBlobs));
38
40
  const signedData = seq(integer(1), set(sha256AlgId()), seq(oid(OID.idData)), certificates, set(signerInfo));
39
41
  return seq(oid(OID.idSignedData), explicit(0, signedData));
40
42
  }
@@ -1 +1,2 @@
1
- import "./cms.js";
1
+ import { buildPkcs7Detached } from "./cms.js";
2
+ export { buildPkcs7Detached };
@@ -1,8 +1,5 @@
1
- /** Thrown when the bytes are encrypted and the password does not open them. */
2
- export declare class WrongPasswordError extends Error {
3
- /** @param message The message to carry; the default states the failure. */
4
- constructor(message?: string);
5
- }
1
+ import { WrongPasswordError } from './password-error.js';
2
+ export { WrongPasswordError };
6
3
  /** Whether the bytes are an OOXML package encrypted per ECMA-376 §2.3. */
7
4
  export declare function isEncryptedPackage(bytes: Uint8Array): boolean;
8
5
  /**
@@ -1,14 +1,7 @@
1
1
  import { aesCbcDecrypt, aesEcbDecrypt, sha1, sha256, sha384, sha512 } from "./primitives.js";
2
2
  import { openCfb } from "../ole/cfb.js";
3
+ import { WrongPasswordError } from "./password-error.js";
3
4
  //#region src/core/crypto/offcrypto.ts
4
- /** Thrown when the bytes are encrypted and the password does not open them. */
5
- var WrongPasswordError = class extends Error {
6
- /** @param message The message to carry; the default states the failure. */
7
- constructor(message = "Wrong password for this document") {
8
- super(message);
9
- this.name = "WrongPasswordError";
10
- }
11
- };
12
5
  /** Whether the bytes are an OOXML package encrypted per ECMA-376 §2.3. */
13
6
  function isEncryptedPackage(bytes) {
14
7
  try {
@@ -69,16 +62,16 @@ function standard(info, payload, password) {
69
62
  }
70
63
  function standardKey(password, salt, keyLength) {
71
64
  let h = sha1(concat(salt, utf16le(password)));
72
- const counter = new Uint8Array(4);
65
+ const counter = /* @__PURE__ */ new Uint8Array(4);
73
66
  for (let i = 0; i < 5e4; i++) {
74
67
  new DataView(counter.buffer).setUint32(0, i, true);
75
68
  h = sha1(concat(counter, h));
76
69
  }
77
- h = sha1(concat(h, new Uint8Array(4)));
70
+ h = sha1(concat(h, /* @__PURE__ */ new Uint8Array(4)));
78
71
  return concat(sha1(padded(h, 54)), sha1(padded(h, 92))).subarray(0, keyLength);
79
72
  }
80
73
  function padded(h, byte) {
81
- const buf = new Uint8Array(64).fill(byte);
74
+ const buf = (/* @__PURE__ */ new Uint8Array(64)).fill(byte);
82
75
  for (let i = 0; i < h.length && i < 64; i++) buf[i] = buf[i] ^ h[i];
83
76
  return buf;
84
77
  }
@@ -104,7 +97,7 @@ function agile(info, payload, password) {
104
97
  const packageKey = decryptAgile(keyFor(BLOCK_KEY_VALUE), enc.saltValue, encryptedKeyValue, enc.cbc).subarray(0, keyData.keyBits / 8);
105
98
  const cipher = payload.subarray(8);
106
99
  const out = new Uint8Array(cipher.length);
107
- const counter = new Uint8Array(4);
100
+ const counter = /* @__PURE__ */ new Uint8Array(4);
108
101
  for (let i = 0; i * SEGMENT < cipher.length; i++) {
109
102
  new DataView(counter.buffer).setUint32(0, i, true);
110
103
  const iv = keyData.hash(concat(keyData.saltValue, counter)).subarray(0, keyData.blockSize || 16);
@@ -115,7 +108,7 @@ function agile(info, payload, password) {
115
108
  }
116
109
  function agileSpin(password, enc, spinCount) {
117
110
  let h = enc.hash(concat(enc.saltValue, utf16le(password)));
118
- const counter = new Uint8Array(4);
111
+ const counter = /* @__PURE__ */ new Uint8Array(4);
119
112
  for (let i = 0; i < spinCount; i++) {
120
113
  new DataView(counter.buffer).setUint32(0, i, true);
121
114
  h = enc.hash(concat(counter, h));
@@ -132,9 +125,10 @@ function agileBlockKey(spun, enc, block) {
132
125
  }
133
126
  function decryptAgile(key, iv, data, cbc) {
134
127
  if (!cbc) return aesEcbDecrypt(key, data);
135
- return aesCbcDecrypt(key, iv.length >= 16 ? iv.subarray(0, 16) : concat(iv, new Uint8Array(16 - iv.length)), data, false);
128
+ const block = iv.length >= 16 ? iv.subarray(0, 16) : concat(iv, new Uint8Array(16 - iv.length));
129
+ return aesCbcDecrypt(key, block, data, false);
136
130
  }
137
- var HASHES = new Map([
131
+ var HASHES = /* @__PURE__ */ new Map([
138
132
  ["sha1", sha1],
139
133
  ["sha-1", sha1],
140
134
  ["sha256", sha256],
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Thrown when the bytes are encrypted and the password does not open them —
3
+ * the wrong one, or none where one is needed.
4
+ */
5
+ export declare class WrongPasswordError extends Error {
6
+ /** @param message The message to carry; the default states the failure. */
7
+ constructor(message?: string);
8
+ }
@@ -0,0 +1,14 @@
1
+ //#region src/core/crypto/password-error.ts
2
+ /**
3
+ * Thrown when the bytes are encrypted and the password does not open them —
4
+ * the wrong one, or none where one is needed.
5
+ */
6
+ var WrongPasswordError = class extends Error {
7
+ /** @param message The message to carry; the default states the failure. */
8
+ constructor(message = "Wrong password for this document") {
9
+ super(message);
10
+ this.name = "WrongPasswordError";
11
+ }
12
+ };
13
+ //#endregion
14
+ export { WrongPasswordError };
@@ -4,7 +4,7 @@
4
4
  * decrypts; used by the legacy V1/V2/V4 Standard security handlers.
5
5
  */
6
6
  function rc4(key, data) {
7
- const s = new Uint8Array(256);
7
+ const s = /* @__PURE__ */ new Uint8Array(256);
8
8
  for (let i = 0; i < 256; i++) s[i] = i;
9
9
  let j = 0;
10
10
  for (let i = 0; i < 256; i++) {
@@ -137,7 +137,7 @@ function md5(input) {
137
137
  c0 = c0 + c | 0;
138
138
  d0 = d0 + d | 0;
139
139
  }
140
- const out = new Uint8Array(16);
140
+ const out = /* @__PURE__ */ new Uint8Array(16);
141
141
  [
142
142
  a0,
143
143
  b0,
@@ -234,7 +234,7 @@ function sha1(input) {
234
234
  let h2 = 2562383102;
235
235
  let h3 = 271733878;
236
236
  let h4 = 3285377520;
237
- const w = new Uint32Array(80);
237
+ const w = /* @__PURE__ */ new Uint32Array(80);
238
238
  for (let off = 0; off < withPad.length; off += 64) {
239
239
  for (let i = 0; i < 16; i++) w[i] = view.getUint32(off + i * 4, false);
240
240
  for (let i = 16; i < 80; i++) {
@@ -261,7 +261,7 @@ function sha1(input) {
261
261
  h3 = h3 + d >>> 0;
262
262
  h4 = h4 + e >>> 0;
263
263
  }
264
- const out = new Uint8Array(20);
264
+ const out = /* @__PURE__ */ new Uint8Array(20);
265
265
  new DataView(out.buffer).setUint32(0, h0, false);
266
266
  new DataView(out.buffer).setUint32(4, h1, false);
267
267
  new DataView(out.buffer).setUint32(8, h2, false);
@@ -322,7 +322,7 @@ function sha256(input) {
322
322
  h[6] = h[6] + g | 0;
323
323
  h[7] = h[7] + hh | 0;
324
324
  }
325
- const out = new Uint8Array(32);
325
+ const out = /* @__PURE__ */ new Uint8Array(32);
326
326
  new DataView(out.buffer).setUint32(0, h[0] >>> 0);
327
327
  for (let i = 0; i < 8; i++) new DataView(out.buffer).setUint32(i * 4, h[i] >>> 0);
328
328
  return out;
@@ -409,15 +409,15 @@ var SHA512_K = [
409
409
  6902733635092675308n,
410
410
  7801388544844847127n
411
411
  ];
412
- var SHA512_KH = new Int32Array(80);
413
- var SHA512_KL = new Int32Array(80);
412
+ var SHA512_KH = /* @__PURE__ */ new Int32Array(80);
413
+ var SHA512_KL = /* @__PURE__ */ new Int32Array(80);
414
414
  for (let i = 0; i < 80; i++) {
415
415
  SHA512_KH[i] = Number(SHA512_K[i] >> 32n & 4294967295n) | 0;
416
416
  SHA512_KL[i] = Number(SHA512_K[i] & 4294967295n) | 0;
417
417
  }
418
418
  function sha512Core(iv, input, outLen) {
419
- const hh = new Int32Array(8);
420
- const hl = new Int32Array(8);
419
+ const hh = /* @__PURE__ */ new Int32Array(8);
420
+ const hl = /* @__PURE__ */ new Int32Array(8);
421
421
  for (let i = 0; i < 8; i++) {
422
422
  hh[i] = Number(iv[i] >> 32n & 4294967295n) | 0;
423
423
  hl[i] = Number(iv[i] & 4294967295n) | 0;
@@ -431,8 +431,8 @@ function sha512Core(iv, input, outLen) {
431
431
  const bits = len * 8;
432
432
  view.setUint32(msg.length - 4, bits >>> 0, false);
433
433
  view.setUint32(msg.length - 8, Math.floor(bits / 4294967296), false);
434
- const wh = new Int32Array(80);
435
- const wl = new Int32Array(80);
434
+ const wh = /* @__PURE__ */ new Int32Array(80);
435
+ const wl = /* @__PURE__ */ new Int32Array(80);
436
436
  for (let off = 0; off < msg.length; off += 128) {
437
437
  for (let i = 0; i < 16; i++) {
438
438
  wh[i] = view.getInt32(off + i * 8, false);
@@ -527,7 +527,7 @@ function sha512Core(iv, input, outLen) {
527
527
  add(6, gh, gl);
528
528
  add(7, xh, xl);
529
529
  }
530
- const out = new Uint8Array(64);
530
+ const out = /* @__PURE__ */ new Uint8Array(64);
531
531
  const ov = new DataView(out.buffer);
532
532
  for (let i = 0; i < 8; i++) {
533
533
  ov.setInt32(i * 8, hh[i], false);
@@ -561,8 +561,8 @@ function sha384(input) {
561
561
  }
562
562
  var AES = buildAesTables();
563
563
  function buildAesTables() {
564
- const exp = new Uint8Array(256);
565
- const log = new Uint8Array(256);
564
+ const exp = /* @__PURE__ */ new Uint8Array(256);
565
+ const log = /* @__PURE__ */ new Uint8Array(256);
566
566
  let x = 1;
567
567
  for (let i = 0; i < 255; i++) {
568
568
  exp[i] = x;
@@ -570,8 +570,8 @@ function buildAesTables() {
570
570
  x ^= x << 1 ^ (x & 128 ? 283 : 0);
571
571
  x &= 255;
572
572
  }
573
- const sbox = new Uint8Array(256);
574
- const inv = new Uint8Array(256);
573
+ const sbox = /* @__PURE__ */ new Uint8Array(256);
574
+ const inv = /* @__PURE__ */ new Uint8Array(256);
575
575
  for (let i = 0; i < 256; i++) {
576
576
  const invByte = i === 0 ? 0 : exp[(255 - log[i]) % 255];
577
577
  let s = invByte;
@@ -5,4 +5,4 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */
8
- export type { AbstractNumbering, Alignment, Border, BorderStyle, BodyElement, Comment, CellBorders, CellMerge, DocumentInfo, CellMargins, CellProperties, CellShading, CellDataBar, CellIcon, CellNoteFlag, CellIconShape, CellSparkline, Chart, ChartBlock, ChartDataPoint, ChartLineStyle, ChartMarker, ChartMarkerSymbol, ChartSeries, ChartType, CustomGeometry, CustomPathCmd, DocumentModel, FontFamilyMap, HeaderFooterReference, HeaderFooterType, ImageBlock, ImageCrop, InlineImage, MathAccent, MathBar, MathDelimiter, MathEqArray, MathFraction, MathFunc, MathGroupChr, MathLimit, MathMatrix, MathNary, MathNode, MathRadical, MathRow, MathRun, MathScript, Numbering, NumberingFormat, NumberingInstance, NumberingLevel, PictureBullet, PictureOutline, NumberingReference, PageMargins, PageSize, Paragraph, ParagraphProperties, FrameProperties, RelativeSize, TabStop, Run, RunProperties, TextOutline, Ligatures, RowConditionalFormat, RowProperties, Section, FloatAnchor, SectionColumns, SectionProperties, ShapeBlock, ShapeShadow, ShapeDash, ShapeFill, ShapeFillKind, ShapeGeometry, ShapeGroupChild, ShapeLine, LineEnd, ShapeTextBody, ShapeTransform, Style, StyleSheet, StyleType, Table, TableCell, TableLook, TableOverlay, TableProperties, TableStyleCondition, TableStyleConditionType, TableStyleLayer, TableRow, UnderlineStyle, VerticalAlign, } from './types.js';
8
+ export type { AbstractNumbering, Alignment, Border, BorderStyle, BodyElement, Comment, CellBorders, CellMerge, DocumentInfo, CellMargins, CellProperties, CellShading, CellDataBar, CellIcon, CellNoteFlag, CellIconShape, CellSparkline, Chart, ChartBlock, ChartDataLabels, ChartDataPoint, ChartLabelPosition, ChartLineStyle, ChartMarker, ChartMarkerSymbol, ChartSeries, ChartSurface, ChartTextStyle, ChartTextStyles, ChartType, CustomGeometry, CustomPathCmd, DocumentModel, FontFamilyMap, HeaderFooterReference, HeaderFooterType, ImageBlock, ImageCrop, InlineImage, MathAccent, MathBar, MathDelimiter, MathEqArray, MathFraction, MathFunc, MathGroupChr, MathLimit, MathMatrix, MathNary, MathNode, MathRadical, MathRow, MathRun, MathScript, Numbering, NumberingFormat, NumberingInstance, NumberingLevel, PictureBullet, PictureOutline, NumberingReference, PageMargins, PageSize, Paragraph, ParagraphProperties, FrameProperties, RelativeSize, TabStop, Run, RunProperties, TextOutline, Ligatures, RowConditionalFormat, RowProperties, Section, FloatAnchor, SectionColumns, SectionProperties, ShapeBlock, ShapeShadow, ShapeDash, ShapeFill, ShapeFillKind, ShapeGeometry, ShapeGroupChild, ShapeLine, LineEnd, ShapeTextBody, ShapeTransform, Style, StyleSheet, StyleType, Table, TableCell, TableLook, TableOverlay, TableProperties, TableStyleCondition, TableStyleConditionType, TableStyleLayer, TableRow, UnderlineStyle, VerticalAlign, } from './types.js';