reamkit 1.29.0 → 1.31.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 (106) hide show
  1. package/README.md +60 -24
  2. package/dist/esm/core/converter/project.js +3 -1
  3. package/dist/esm/core/crypto/offcrypto.js +1 -1
  4. package/dist/esm/core/document-model/index.d.ts +1 -1
  5. package/dist/esm/core/document-model/types.d.ts +65 -0
  6. package/dist/esm/core/drawingml/shape-render.js +13 -1
  7. package/dist/esm/core/font/index.d.ts +2 -0
  8. package/dist/esm/core/font/ttf-build.d.ts +113 -0
  9. package/dist/esm/core/font/ttf-build.js +1224 -0
  10. package/dist/esm/core/font/ttf-subset.d.ts +19 -0
  11. package/dist/esm/core/font/ttf-subset.js +14 -1
  12. package/dist/esm/core/fonts/index.d.ts +1 -1
  13. package/dist/esm/core/fonts/provider.d.ts +17 -0
  14. package/dist/esm/core/fonts/provider.js +27 -2
  15. package/dist/esm/core/fonts/remote-fonts.d.ts +8 -0
  16. package/dist/esm/core/fonts/remote-fonts.js +108 -18
  17. package/dist/esm/core/ir/flow.d.ts +88 -1
  18. package/dist/esm/core/numbering/index.d.ts +1 -1
  19. package/dist/esm/core/numbering/state.d.ts +11 -1
  20. package/dist/esm/core/numbering/state.js +10 -1
  21. package/dist/esm/core/style-cascade/resolver.js +35 -4
  22. package/dist/esm/core/style-cascade/types.d.ts +19 -1
  23. package/dist/esm/core/style-cascade/types.js +3 -0
  24. package/dist/esm/index.d.ts +2 -2
  25. package/dist/esm/layout/page-doc.d.ts +10 -3
  26. package/dist/esm/layout/styled-layout.d.ts +48 -7
  27. package/dist/esm/layout/styled-layout.js +881 -119
  28. package/dist/esm/layout/turned-section.d.ts +38 -0
  29. package/dist/esm/layout/turned-section.js +193 -0
  30. package/dist/esm/pdf/styled-page-emitter.js +78 -2
  31. package/dist/esm/pdf-reader/annot-draw.js +93 -1
  32. package/dist/esm/pdf-reader/annots.d.ts +18 -0
  33. package/dist/esm/pdf-reader/annots.js +86 -9
  34. package/dist/esm/pdf-reader/cff-outline.d.ts +27 -0
  35. package/dist/esm/pdf-reader/cff-outline.js +169 -21
  36. package/dist/esm/pdf-reader/cmap.js +5 -2
  37. package/dist/esm/pdf-reader/content.d.ts +70 -4
  38. package/dist/esm/pdf-reader/content.js +172 -12
  39. package/dist/esm/pdf-reader/display.d.ts +36 -0
  40. package/dist/esm/pdf-reader/display.js +82 -1
  41. package/dist/esm/pdf-reader/document.js +5 -1
  42. package/dist/esm/pdf-reader/embedded-fonts.d.ts +25 -0
  43. package/dist/esm/pdf-reader/embedded-fonts.js +78 -9
  44. package/dist/esm/pdf-reader/encodings.d.ts +8 -0
  45. package/dist/esm/pdf-reader/encodings.js +25 -3
  46. package/dist/esm/pdf-reader/face-outlines.d.ts +78 -0
  47. package/dist/esm/pdf-reader/face-outlines.js +362 -0
  48. package/dist/esm/pdf-reader/figures.d.ts +52 -0
  49. package/dist/esm/pdf-reader/figures.js +433 -0
  50. package/dist/esm/pdf-reader/flow-build.d.ts +224 -7
  51. package/dist/esm/pdf-reader/flow-build.js +545 -39
  52. package/dist/esm/pdf-reader/font.d.ts +27 -1
  53. package/dist/esm/pdf-reader/font.js +632 -63
  54. package/dist/esm/pdf-reader/glyf-outline.d.ts +33 -0
  55. package/dist/esm/pdf-reader/glyf-outline.js +148 -3
  56. package/dist/esm/pdf-reader/glyph-names.js +154 -1
  57. package/dist/esm/pdf-reader/glyph-shapes.d.ts +18 -0
  58. package/dist/esm/pdf-reader/glyph-shapes.js +57 -0
  59. package/dist/esm/pdf-reader/image-decode.js +70 -4
  60. package/dist/esm/pdf-reader/images.d.ts +5 -0
  61. package/dist/esm/pdf-reader/images.js +4 -2
  62. package/dist/esm/pdf-reader/jbig2.d.ts +40 -1
  63. package/dist/esm/pdf-reader/jbig2.js +78 -16
  64. package/dist/esm/pdf-reader/jpeg.d.ts +6 -3
  65. package/dist/esm/pdf-reader/jpeg.js +21 -1
  66. package/dist/esm/pdf-reader/layout.d.ts +119 -2
  67. package/dist/esm/pdf-reader/layout.js +2219 -184
  68. package/dist/esm/pdf-reader/lexer.d.ts +10 -0
  69. package/dist/esm/pdf-reader/lexer.js +17 -0
  70. package/dist/esm/pdf-reader/page-numbers.d.ts +53 -0
  71. package/dist/esm/pdf-reader/page-numbers.js +167 -0
  72. package/dist/esm/pdf-reader/pattern-tint.d.ts +11 -1
  73. package/dist/esm/pdf-reader/pattern-tint.js +21 -3
  74. package/dist/esm/pdf-reader/regions.d.ts +25 -0
  75. package/dist/esm/pdf-reader/regions.js +167 -0
  76. package/dist/esm/pdf-reader/shading.d.ts +58 -2
  77. package/dist/esm/pdf-reader/shading.js +181 -11
  78. package/dist/esm/pdf-reader/struct-tree.js +112 -8
  79. package/dist/esm/pdf-reader/tagged.js +207 -28
  80. package/dist/esm/pdf-reader/text-rules.js +1 -1
  81. package/dist/esm/pdf-reader/text.d.ts +6 -3
  82. package/dist/esm/pdf-reader/text.js +106 -22
  83. package/dist/esm/pdf-reader/type1-outline.d.ts +11 -0
  84. package/dist/esm/pdf-reader/type1-outline.js +63 -8
  85. package/dist/esm/pdf-reader/vector.d.ts +8 -2
  86. package/dist/esm/pdf-reader/vector.js +105 -6
  87. package/dist/esm/word/doc/doc-reader.js +6 -2
  88. package/dist/esm/word/doc/doc-text.d.ts +6 -0
  89. package/dist/esm/word/doc/doc-text.js +19 -1
  90. package/dist/esm/word/document-parser.d.ts +2 -2
  91. package/dist/esm/word/document-parser.js +11 -1
  92. package/dist/esm/word/docx-reader.js +5 -3
  93. package/dist/esm/word/docx-writer.js +341 -54
  94. package/dist/esm/word/drawing-parser.d.ts +5 -3
  95. package/dist/esm/word/drawing-parser.js +56 -10
  96. package/dist/esm/word/font-embed.d.ts +30 -0
  97. package/dist/esm/word/font-embed.js +173 -0
  98. package/dist/esm/word/font-table.d.ts +10 -0
  99. package/dist/esm/word/font-table.js +13 -1
  100. package/dist/esm/word/index.js +1 -1
  101. package/dist/esm/word/numbering-parser.d.ts +3 -1
  102. package/dist/esm/word/numbering-parser.js +2 -1
  103. package/dist/esm/word/paragraph-properties.d.ts +7 -6
  104. package/dist/esm/word/paragraph-properties.js +16 -2
  105. package/dist/esm/word/run-properties.js +26 -0
  106. package/package.json +12 -5
@@ -1,7 +1,8 @@
1
- import { BodyElement, ParagraphProperties, Section, SectionProperties, TextOutline } from '../core/document-model/index.js';
2
- import { FlowDoc } from '../core/ir/flow.js';
1
+ import { BodyElement, Ligatures, ParagraphProperties, Section, SectionProperties, ShapeBlock, TextOutline } from '../core/document-model/index.js';
2
+ import { FaceFamily, FaceOutlines, FlowDoc } from '../core/ir/flow.js';
3
3
  import { FontRegistry } from '../core/font/index.js';
4
- import { Loss, ResourceStore } from '../core/ir/index.js';
4
+ import { Loss, Pt, ResourceStore } from '../core/ir/index.js';
5
+ import { Display } from './display.js';
5
6
  import { PdfImage } from './images.js';
6
7
  import { PdfPage } from './document.js';
7
8
  import { PdfVector } from './vector.js';
@@ -36,6 +37,28 @@ export interface PageFrame {
36
37
  */
37
38
  export declare function paragraphBlock(text: string, outlineLevel?: number): BodyElement;
38
39
  /** One piece of reconstructed text, carrying any hyperlink (E-PDF EP8). */
40
+ /**
41
+ * The space set between a span and what follows it, in the span's own size and
42
+ * face: a word space is as wide as the type it stands in.
43
+ *
44
+ * Written bare, the space took the document's default size, whatever the words
45
+ * around it were set at: issue10665_reduced.pdf sets "78" and "110" twenty
46
+ * points apart in 60-point type, and the eleven-point space between them closed
47
+ * them up to "78110"; in 7-point footnotes the same space is half as wide
48
+ * again as the page's, and pushes their lines over.
49
+ *
50
+ * A space between two words one text markup marks is marked with them: the
51
+ * band a highlighter lays runs across the gap. comments.pdf highlights two
52
+ * lines on its sixth page, and with its spaces left bare the band came back
53
+ * broken at every word.
54
+ *
55
+ * @param before The span the space follows, where there is one.
56
+ * @param after What follows the space, where anything does.
57
+ * @returns The space.
58
+ */
59
+ export declare function spaceAfter(before: TextSpan | undefined, after?: {
60
+ readonly markup?: TextMarkup;
61
+ }): TextSpan;
39
62
  export interface TextSpan {
40
63
  readonly text: string;
41
64
  readonly href?: string;
@@ -59,6 +82,12 @@ export interface TextSpan {
59
82
  readonly script?: 'superscript' | 'subscript';
60
83
  /** §12.5.6.10 — a text-markup annotation marks these words. */
61
84
  readonly markup?: TextMarkup;
85
+ /**
86
+ * §17.3.2.43 — the share of their own width the characters are set at: a
87
+ * word space the page set narrower than the face's own (see `fittedSpace` in
88
+ * ./layout).
89
+ */
90
+ readonly widthScale?: number;
62
91
  }
63
92
  /**
64
93
  * Build a paragraph {@link BodyElement} from positioned {@link TextSpan}s,
@@ -66,7 +95,21 @@ export interface TextSpan {
66
95
  * survives as its own run) and squashing whitespace. With no hrefs this
67
96
  * collapses to a single run — the same shape {@link paragraphBlock} produces.
68
97
  */
69
- export declare function paragraphFromRuns(spans: ReadonlyArray<TextSpan>, outlineLevel?: number, placement?: Pick<ParagraphProperties, 'alignment' | 'spacingBefore' | 'indentLeft' | 'indentFirstLine' | 'tabs'>): BodyElement;
98
+ export declare function paragraphFromRuns(spans: ReadonlyArray<TextSpan>, outlineLevel?: number, placement?: Pick<ParagraphProperties, 'alignment' | 'spacingBefore' | 'spacingLine' | 'spacingLineRule' | 'indentLeft' | 'indentRight' | 'indentFirstLine' | 'tabs'>): BodyElement;
99
+ /**
100
+ * The height of a line that carries nothing to read: one twip, the least
101
+ * §17.3.1.33 can state. Zero is not a height a writer states at all — it is
102
+ * read as "no line spacing given", and the reader's single spacing comes back.
103
+ */
104
+ export declare const CARRIER_LINE_PT: Pt;
105
+ /**
106
+ * §17.3.1.33 — the paragraph a floating mark is anchored in, which takes no
107
+ * room: the mark stands where the page drew it and the line carrying it is on
108
+ * no page. Left at a reader's single spacing, every rule and fill an invoice
109
+ * draws was a blank line in the flow, and the text under it moved down a line
110
+ * for each.
111
+ */
112
+ export declare const FLOAT_CARRIER: ParagraphProperties;
70
113
  /**
71
114
  * Store a {@link PdfImage}'s bytes (content-addressed dedup) and build the image
72
115
  * {@link BodyElement} that references them, sized in points from the placement
@@ -97,6 +140,53 @@ export declare function positionedText(spans: ReadonlyArray<TextSpan>, box: {
97
140
  width: number;
98
141
  height: number;
99
142
  }, frame: PageFrame, zOrder: number, rotation60k?: number): BodyElement;
143
+ /**
144
+ * One part of a figure (see `./figures`): the shape it is drawn as, and where
145
+ * its box stands on the page — its left edge and its top, y-up.
146
+ */
147
+ export interface FigureMember {
148
+ readonly shape: ShapeBlock;
149
+ readonly left: number;
150
+ readonly top: number;
151
+ }
152
+ /** A path of a figure, drawn where the page drew it. */
153
+ export declare function vectorMember(v: PdfVector): FigureMember;
154
+ /**
155
+ * A picture of a figure: a box filled with it (§20.1.8.14), which is what a
156
+ * `pic:pic` inside a group is — the shadows comments.pdf lays under each of
157
+ * its boxes.
158
+ */
159
+ export declare function imageMember(image: PdfImage, resources: ResourceStore): FigureMember;
160
+ /**
161
+ * A label of a figure: a line of its words, in a box as wide as they are.
162
+ * The box never wraps — set in a face a little wider than the page's, one
163
+ * word would break in two.
164
+ */
165
+ export declare function labelMember(spans: ReadonlyArray<TextSpan>, box: {
166
+ x: number;
167
+ y: number;
168
+ width: number;
169
+ height: number;
170
+ }, rotation60k?: number): FigureMember;
171
+ /** The box a figure's parts stand in, on the page (y-up). */
172
+ export declare function membersBox(members: ReadonlyArray<FigureMember>): {
173
+ left: number;
174
+ top: number;
175
+ right: number;
176
+ bottom: number;
177
+ };
178
+ /**
179
+ * §20.5.2.17 — a figure as the one drawing it is: a group holding its paths,
180
+ * its pictures and its labels at their places in it, set in a paragraph of
181
+ * its own. An inline drawing takes the room it is tall (a line holding
182
+ * nothing but a picture is the picture's height in Word), so the text after
183
+ * it follows it, and the figure goes with its paragraph wherever the text
184
+ * puts that.
185
+ *
186
+ * @param members Its parts, in the order they are painted.
187
+ * @param properties The paragraph it stands in.
188
+ */
189
+ export declare function figureBlock(members: ReadonlyArray<FigureMember>, properties: ParagraphProperties): BodyElement;
100
190
  /** Collapse losses sharing a `detail` message (the same colour space dropped on many pages). */
101
191
  export declare function dedupeLosses(losses: ReadonlyArray<Loss>): Array<Loss>;
102
192
  /**
@@ -122,7 +212,106 @@ export declare function shapeBlock(v: PdfVector, frame?: PageFrame, zOrder?: num
122
212
  * this single geometry — a known approximation, still far better than a fixed
123
213
  * `A4`. Returns `undefined` when there is no usable first-page box.
124
214
  */
125
- export declare function sectionFromPdfPages(pages: ReadonlyArray<PdfPage>): SectionProperties | undefined;
215
+ export declare function sectionFromPdfPages(pages: ReadonlyArray<PdfPage>, display?: Display): SectionProperties | undefined;
216
+ /**
217
+ * §17.6.20 — a section read in a page's text frame (see `textFrameOf`), set
218
+ * back on the sheet the page is shown on, its lines running down it (`tbRl`).
219
+ *
220
+ * The frame is the sheet turned back a quarter, so its measurements carry
221
+ * over edge for edge: the frame's left margin is where each line starts, the
222
+ * sheet's top one; its top margin is where the first line stands, the
223
+ * sheet's right one.
224
+ *
225
+ * @param section The section as the frame measured it.
226
+ * @param display The geometry its pages were read in.
227
+ * @returns The section on the sheet, or the section unchanged for a page read
228
+ * on its sheet.
229
+ */
230
+ export declare function sectionOnSheet(section: SectionProperties | undefined, display: Display | undefined): SectionProperties | undefined;
231
+ /**
232
+ * A mark anchored to a page read in its text frame, set on the SHEET the page
233
+ * is shown on: where the page drew it, turned with the page.
234
+ *
235
+ * Word lays a `tbRl` section's text down the sheet but stands a drawing
236
+ * anchored to the page at its offsets on the sheet, upright (§17.6.20) — so a
237
+ * picture the frame placed is carried onto the sheet, and turned a quarter
238
+ * clockwise as the words around it are.
239
+ *
240
+ * @param el A body element, anchored or not.
241
+ * @param sheetWidth The sheet's width, which is the frame's height.
242
+ * @returns The element, anchored on the sheet.
243
+ */
244
+ export declare function floatOntoSheet(el: BodyElement, sheetWidth: number): BodyElement;
245
+ /** How many lines a sheet must hold before where they end says where its measure does. */
246
+ export declare const MEASURE_LINES = 3;
247
+ /**
248
+ * How far in, as a share of the sheet, a right margin the lines do not show
249
+ * may come: what a sheet of a line or two is re-set across is at least the
250
+ * rest of it.
251
+ */
252
+ export declare const GUESSED_MARGIN: number;
253
+ /**
254
+ * §17.3.1.33 — where the baseline of an EXACT line stands in its box, from the
255
+ * top. LibreOffice puts it at four fifths of the height; Word at the height
256
+ * less the face's descent, which for the faces documents use is within a tenth
257
+ * of a line of the same place.
258
+ */
259
+ export declare const BASELINE_AT = 0.8;
260
+ /** A line's box where no pitch was measured: the ordinary single spacing, in ems. */
261
+ export declare const NATURAL_LINE_EM = 1.2;
262
+ /**
263
+ * How far above its baseline the first line's BOX reaches, as a fraction of the
264
+ * size — which is what the top margin has to leave room for. The lines are set
265
+ * in exact boxes (see `groupIntoParagraphs`), so this is where the box's top
266
+ * stands, not where a face's ascender happens to.
267
+ */
268
+ export declare const ASCENDER: number;
269
+ /**
270
+ * The size a document's text is set in: the middle of every size its runs
271
+ * carry.
272
+ *
273
+ * @param pageRuns Each page's runs.
274
+ * @returns The size, in points; 0 where no run states one.
275
+ */
276
+ export declare function textSizeOf(pageRuns: ReadonlyArray<ReadonlyArray<TextRun>>): number;
277
+ /**
278
+ * Whether a run is set too small to be read, beside the text of its document —
279
+ * a mark the producer leaves on the sheet, not a line of the page.
280
+ *
281
+ * TCPDF signs the last page of everything it makes "Powered by TCPDF
282
+ * (www.tcpdf.org)" in type one point high, three points from the corner of the
283
+ * paper. Taken for text it was the leftmost and the lowest thing on the page:
284
+ * the margins came in at the edge of the sheet and every line of basicapi.pdf
285
+ * and alphatrans.pdf was set against it.
286
+ *
287
+ * @param run The run.
288
+ * @param textSize The size the document's text is set in (see {@link textSizeOf}).
289
+ * @returns `true` where the run is a mark rather than text.
290
+ */
291
+ export declare function tooSmallToRead(run: TextRun, textSize: number): boolean;
292
+ /**
293
+ * The margins the SOURCE used, measured off where its words actually sit.
294
+ *
295
+ * A PDF states none — text is placed anywhere on the MediaBox — so the reader
296
+ * used to leave them at zero rather than invent an inch. But the words
297
+ * themselves say where the margin was: the leftmost glyph on the page is the
298
+ * left margin, and reflowing inside it keeps the measure the author set instead
299
+ * of running the text from edge to edge.
300
+ *
301
+ * Measured on the MEDIAN page rather than the extreme one, so a single full-
302
+ * bleed rule or a page number in the corner does not collapse the margin for
303
+ * the whole document, and clamped so a strange page cannot leave no text area
304
+ * at all.
305
+ *
306
+ * @param section The section the page box gave, or `undefined`.
307
+ * @param shown Each page as it is shown, for its own width and height.
308
+ * @param pageRuns Each page's runs, already placed on the shown page.
309
+ * @param pageMarks Each page's pictures, which the measure has to hold.
310
+ * @param foot The running foot lifted off the pages, as the first page
311
+ * showed it — the band the text block stands above.
312
+ * @returns The section with measured margins, or `section` when nothing is
313
+ * measurable.
314
+ */
126
315
  export declare function withMeasuredMargins(section: SectionProperties | undefined, shown: ReadonlyArray<{
127
316
  width: number;
128
317
  height: number;
@@ -131,7 +320,35 @@ export declare function withMeasuredMargins(section: SectionProperties | undefin
131
320
  y: number;
132
321
  widthPt: number;
133
322
  heightPt: number;
134
- }>>): SectionProperties | undefined;
323
+ }>>, foot?: ReadonlyArray<TextRun>): SectionProperties | undefined;
324
+ /** What a face's runs ask of a word processor to be set as the page set them. */
325
+ export interface Typesetting {
326
+ /** §17.3.2.19 — kerned from this size up. */
327
+ readonly kerningMinPt?: Pt;
328
+ /** [MS-DOCX] `w14:ligatures` — set with these ligatures. */
329
+ readonly ligatures?: Ligatures;
330
+ }
331
+ /**
332
+ * The runs set in a face the page KERNED or LIGATED, marked so (see
333
+ * `pageSpacing`, `FaceOutlines.ligatures`): a word processor kerns nothing a
334
+ * run does not ask it to, and set unkerned, a line kerned on the page runs
335
+ * longer than it did there; a ligature the embedded face carries is formed
336
+ * where the run asks for its face's ligatures.
337
+ *
338
+ * @param blocks The blocks to mark, tables and text boxes within them too.
339
+ * @param typeset Run font name → what its runs ask for.
340
+ * @returns The blocks, their runs in those faces asking for it.
341
+ */
342
+ export declare function typesetRuns(blocks: ReadonlyArray<BodyElement>, typeset: ReadonlyMap<string, Typesetting>): Array<BodyElement>;
343
+ /**
344
+ * What each face's runs ask for: kerning where the page kerned the face, and
345
+ * its standard ligatures where the page drew one of them (the ligatures the
346
+ * face's embedded font then forms are exactly the ones the page drew).
347
+ *
348
+ * @param kerned The run font names of the faces the page kerned.
349
+ * @param faceOutlines Run font name → the face's outlines, ligatures among them.
350
+ */
351
+ export declare function typesetting(kerned: ReadonlySet<string>, faceOutlines: ReadonlyMap<string, FaceOutlines> | undefined): Map<string, Typesetting>;
135
352
  /**
136
353
  * Assemble the final {@link FlowDoc} for a reconstruction: the body elements
137
354
  * with their styles resolved against the empty style sheet, the lifted-image
@@ -139,4 +356,4 @@ export declare function withMeasuredMargins(section: SectionProperties | undefin
139
356
  * both reconstruction paths (the tagged fast-path EP3 and the heuristic layout
140
357
  * path EP4).
141
358
  */
142
- export declare function buildFlowDoc(body: ReadonlyArray<BodyElement>, resources?: ResourceStore, section?: SectionProperties, embeddedFonts?: ReadonlyMap<string, FontRegistry>, sections?: ReadonlyArray<Section>, headersFooters?: ReadonlyMap<string, ReadonlyArray<BodyElement>>): FlowDoc;
359
+ export declare function buildFlowDoc(body: ReadonlyArray<BodyElement>, resources?: ResourceStore, section?: SectionProperties, embeddedFonts?: ReadonlyMap<string, FontRegistry>, sections?: ReadonlyArray<Section>, headersFooters?: ReadonlyMap<string, ReadonlyArray<BodyElement>>, faceFamilies?: ReadonlyMap<string, FaceFamily>, faceOutlines?: ReadonlyMap<string, FaceOutlines>, kerned?: ReadonlySet<string>): FlowDoc;