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
@@ -148,6 +148,25 @@ var DEFAULT_THEME_PALETTE = new Map([
148
148
  ["hlink", "0563C1"],
149
149
  ["folHlink", "954F72"]
150
150
  ]);
151
+ /**
152
+ * The Office 2023 theme's palette — what Excel colours a workbook that carries
153
+ * no theme part with. Its own PDF of theme slots 0…9 in such a workbook
154
+ * (2026-10-01) paints exactly these: accent1 is 156082, not 2013's 4472C4.
155
+ */
156
+ var OFFICE_2023_THEME_PALETTE = new Map([
157
+ ["dk1", "000000"],
158
+ ["lt1", "FFFFFF"],
159
+ ["dk2", "0E2841"],
160
+ ["lt2", "E8E8E8"],
161
+ ["accent1", "156082"],
162
+ ["accent2", "E97132"],
163
+ ["accent3", "196B24"],
164
+ ["accent4", "0F9ED5"],
165
+ ["accent5", "A02B93"],
166
+ ["accent6", "4EA72E"],
167
+ ["hlink", "467886"],
168
+ ["folHlink", "96607D"]
169
+ ]);
151
170
  var DEFAULT_SCHEME_ALIAS = {
152
171
  tx1: "dk1",
153
172
  bg1: "lt1",
@@ -284,8 +303,9 @@ var SYSTEM_COLORS = new Map([
284
303
  function resolveColorNode(c, resolveColor) {
285
304
  if (poIs(c, "a:sysClr")) {
286
305
  const last = poAttr(c, "lastClr");
287
- if (last && /^[0-9A-Fa-f]{6}$/.test(last)) return last.toUpperCase();
288
- return SYSTEM_COLORS.get(poAttr(c, "val") ?? "");
306
+ const hex = last && /^[0-9A-Fa-f]{6}$/.test(last) ? last.toUpperCase() : SYSTEM_COLORS.get(poAttr(c, "val") ?? "");
307
+ const sysMods = readColorMods(c);
308
+ return hex !== void 0 && sysMods.length > 0 ? applyColorMods(hex, sysMods) : hex;
289
309
  }
290
310
  if (poIs(c, "a:prstClr")) {
291
311
  const hex = PRESET_COLORS.get((poAttr(c, "val") ?? "").toLowerCase());
@@ -305,4 +325,4 @@ function resolveColorNode(c, resolveColor) {
305
325
  } : raw);
306
326
  }
307
327
  //#endregion
308
- export { DEFAULT_SCHEME_ALIAS, DEFAULT_THEME_PALETTE, applyColorMods, defaultColorResolver, makeColorResolver, placeholderColors, readColorMods, resolveColorNode };
328
+ export { DEFAULT_SCHEME_ALIAS, DEFAULT_THEME_PALETTE, OFFICE_2023_THEME_PALETTE, defaultColorResolver, makeColorResolver, placeholderColors, readColorMods, resolveColorNode };
@@ -30,7 +30,9 @@ export declare function gradientToSolid(gradient: ShapeGradient): string;
30
30
  * An SVG `<linearGradient>` / `<radialGradient>` definition for a gradient fill
31
31
  * (EP16), shared by the SVG and HTML writers. The linear vector is expressed in
32
32
  * `objectBoundingBox` space; the angle is negated because the shape's own path
33
- * transform flips y (local y-up → page y-down).
33
+ * transform flips y (local y-up → page y-down) — and a radial centre, given in
34
+ * fractions down from the box's top, is measured up from its bottom for the
35
+ * same reason.
34
36
  *
35
37
  * @param id The gradient element id (referenced by `fill="url(#id)"`).
36
38
  * @param g The gradient fill.
@@ -51,7 +51,9 @@ function gradientToSolid(gradient) {
51
51
  * An SVG `<linearGradient>` / `<radialGradient>` definition for a gradient fill
52
52
  * (EP16), shared by the SVG and HTML writers. The linear vector is expressed in
53
53
  * `objectBoundingBox` space; the angle is negated because the shape's own path
54
- * transform flips y (local y-up → page y-down).
54
+ * transform flips y (local y-up → page y-down) — and a radial centre, given in
55
+ * fractions down from the box's top, is measured up from its bottom for the
56
+ * same reason.
55
57
  *
56
58
  * @param id The gradient element id (referenced by `fill="url(#id)"`).
57
59
  * @param g The gradient fill.
@@ -64,7 +66,7 @@ function gradientSvgDef(id, g) {
64
66
  const c = g.center;
65
67
  if (!c) return `<radialGradient id="${id}">${stops}</radialGradient>`;
66
68
  const r = Math.SQRT2 / 2;
67
- return `<radialGradient id="${id}" cx="${n(c.x)}" cy="${n(c.y)}" r="${n(r)}">${stops}</radialGradient>`;
69
+ return `<radialGradient id="${id}" cx="${n(c.x)}" cy="${n(1 - c.y)}" r="${n(r)}">${stops}</radialGradient>`;
68
70
  }
69
71
  const rad = -(g.angle ?? 0) * Math.PI / 180;
70
72
  const dx = Math.cos(rad) / 2;
@@ -9,3 +9,5 @@ export type { KerningMap, LigatureMap, ShapedRun } from './opentype-layout.js';
9
9
  export { hasSubstitutable, lettersForLigature, substituteLetters } from './ligatures.js';
10
10
  export { createFontMeasure } from './measure.js';
11
11
  export type { FontMeasure } from './measure.js';
12
+ export { buildTrueType, editableEmbedding, MAX_BUILT_GLYPHS } from './ttf-build.js';
13
+ export type { BuiltFace, BuiltGlyph, BuiltKernPair, BuiltLigature, GlyphSeg, } from './ttf-build.js';
@@ -29,6 +29,15 @@ export interface FontMeasure {
29
29
  * `[…] TJ` array when shaping moved a glyph off its own advance.
30
30
  */
31
31
  readonly showText: (text: string) => string;
32
+ /**
33
+ * The glyphs `text` is drawn with and the advance each one takes, in font
34
+ * units — exactly what {@link showText} shows, kerning and ligatures
35
+ * included — for a writer that places each glyph itself.
36
+ */
37
+ readonly glyphRun: (text: string) => {
38
+ readonly gids: ReadonlyArray<number>;
39
+ readonly advances: ReadonlyArray<number>;
40
+ };
32
41
  }
33
42
  /**
34
43
  * Build a {@link FontMeasure} over a parsed font.
@@ -52,6 +52,13 @@ function createFontMeasure(parsed, kern = true) {
52
52
  if (hex !== "") parts.push(`<${hex}>`);
53
53
  return `[${parts.join(" ")}] TJ`;
54
54
  };
55
+ const glyphRun = (text) => {
56
+ const shaped = shapeText(text, parsed.glyphForCodepoint, parsed.advanceWidths, parsed.ligatures, kerning, parsed.joiningForms);
57
+ return {
58
+ gids: shaped.gids,
59
+ advances: shaped.advances
60
+ };
61
+ };
55
62
  const glyf = parsed.tables.get("glyf");
56
63
  const glyphInk = (gid) => {
57
64
  if (!glyf || gid < 0 || gid >= parsed.numGlyphs) return void 0;
@@ -92,7 +99,8 @@ function createFontMeasure(parsed, kern = true) {
92
99
  textWidthPt,
93
100
  textInkPt,
94
101
  encodeTextAsCidHex,
95
- showText
102
+ showText,
103
+ glyphRun
96
104
  };
97
105
  }
98
106
  //#endregion
@@ -0,0 +1,113 @@
1
+ /** One piece of a glyph's outline, in a one-unit em with y up. */
2
+ export type GlyphSeg = {
3
+ readonly op: 'move';
4
+ readonly x: number;
5
+ readonly y: number;
6
+ } | {
7
+ readonly op: 'line';
8
+ readonly x: number;
9
+ readonly y: number;
10
+ } | {
11
+ readonly op: 'cubic';
12
+ readonly x1: number;
13
+ readonly y1: number;
14
+ readonly x2: number;
15
+ readonly y2: number;
16
+ readonly x: number;
17
+ readonly y: number;
18
+ } | {
19
+ readonly op: 'close';
20
+ };
21
+ /** One glyph of a {@link BuiltFace}. */
22
+ export interface BuiltGlyph {
23
+ /** The characters that select it, as code points. */
24
+ readonly codePoints: ReadonlyArray<number>;
25
+ /** Its contours, filled by the nonzero rule; empty for a blank glyph. */
26
+ readonly outline: ReadonlyArray<GlyphSeg>;
27
+ /** How far the pen moves after it, in thousandths of an em. */
28
+ readonly advance: number;
29
+ }
30
+ /** Everything {@link buildTrueType} needs to know about the face it builds. */
31
+ export interface BuiltFace {
32
+ /** The family the font is installed under (`name` ID 1). */
33
+ readonly family: string;
34
+ /** The style within the family: its bold and italic slot (`name` ID 2). */
35
+ readonly bold: boolean;
36
+ readonly italic: boolean;
37
+ /** The PostScript name (`name` ID 6); only its printable ASCII is kept. */
38
+ readonly postScriptName: string;
39
+ readonly glyphs: ReadonlyArray<BuiltGlyph>;
40
+ /** Above and below the baseline, in thousandths of an em — `descent` negative. */
41
+ readonly ascent: number;
42
+ readonly descent: number;
43
+ readonly capHeight?: number;
44
+ readonly xHeight?: number;
45
+ /** Degrees counterclockwise from the vertical; a face slanted right is negative. */
46
+ readonly italicAngle?: number;
47
+ readonly fixedPitch?: boolean;
48
+ /**
49
+ * OS/2 `fsType` — the embedding the face's licence allows, carried over from
50
+ * the program the outlines came from.
51
+ */
52
+ readonly fsType: number;
53
+ /** The pairs the face is kerned by: how far the second glyph moves in towards the first. */
54
+ readonly kerning?: ReadonlyArray<BuiltKernPair>;
55
+ /** The glyphs the face draws for a run of characters at once: its ligatures. */
56
+ readonly ligatures?: ReadonlyArray<BuiltLigature>;
57
+ }
58
+ /**
59
+ * One ligature of a {@link BuiltFace}: a glyph no character reaches alone,
60
+ * substituted for the characters it joins wherever they meet (GSUB `liga`).
61
+ */
62
+ export interface BuiltLigature {
63
+ /** The characters it stands for, in order — two or more. */
64
+ readonly codePoints: ReadonlyArray<number>;
65
+ readonly outline: ReadonlyArray<GlyphSeg>;
66
+ /** How far the pen moves after it, in thousandths of an em. */
67
+ readonly advance: number;
68
+ }
69
+ /** One kerning pair of a {@link BuiltFace}, by the characters it joins. */
70
+ export interface BuiltKernPair {
71
+ /** The code point of the glyph on the left, and of the one after it. */
72
+ readonly left: number;
73
+ readonly right: number;
74
+ /** The adjustment to the left glyph's advance, in thousandths of an em — negative tightens. */
75
+ readonly value: number;
76
+ }
77
+ /**
78
+ * Whether a face's licence lets it be embedded, as outlines and subset, in a
79
+ * document that stays EDITABLE: OS/2 `fsType` states installable embedding (no
80
+ * usage bit) or grants editable embedding, and neither forbids subsetting nor
81
+ * allows bitmaps only. Restricted-licence and preview-and-print faces are
82
+ * refused — the second may travel only in a document opened read-only.
83
+ *
84
+ * Several usage bits at once is an old font's way of stating permissions, and
85
+ * the least restrictive of them applies (OS/2 versions 0–2).
86
+ *
87
+ * @param fsType The field, or `undefined` where the program states none —
88
+ * which restricts nothing.
89
+ * @returns Whether an editable document may carry the face.
90
+ */
91
+ export declare function editableEmbedding(fsType: number | undefined): boolean;
92
+ /**
93
+ * The most glyphs a built face holds. A `cmap` format 4 subtable is limited to
94
+ * 64 KB, and past this many characters it may not fit; a face that large is a
95
+ * whole CJK font, which is no subset.
96
+ */
97
+ export declare const MAX_BUILT_GLYPHS = 8000;
98
+ /**
99
+ * Build a TrueType font from outlines (ISO/IEC 14496-22): `.notdef` first, then
100
+ * one glyph per {@link BuiltGlyph} in the order given, reachable through a
101
+ * Unicode `cmap`.
102
+ *
103
+ * Cubic curves become quadratic ones. A cubic that is a raised quadratic — what
104
+ * a TrueType source's outline arrives as — comes back as exactly that
105
+ * quadratic; any other is cut into as many quadratics as keep within half a
106
+ * unit of it. Each glyph's contours are turned to run clockwise round their
107
+ * ink, as TrueType's are.
108
+ *
109
+ * @param face The face: its names, metrics, licence and glyphs.
110
+ * @returns The font program's bytes.
111
+ * @throws When the face holds more than {@link MAX_BUILT_GLYPHS} glyphs.
112
+ */
113
+ export declare function buildTrueType(face: BuiltFace): Uint8Array;