reamkit 1.31.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 (83) hide show
  1. package/README.md +10 -0
  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 +1 -0
  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/document-model/index.d.ts +1 -1
  10. package/dist/esm/core/document-model/types.d.ts +112 -0
  11. package/dist/esm/core/drawingml/chart-geometry.d.ts +21 -8
  12. package/dist/esm/core/drawingml/chart-geometry.js +198 -108
  13. package/dist/esm/core/drawingml/chart-parser.js +73 -2
  14. package/dist/esm/core/drawingml/colors.d.ts +6 -0
  15. package/dist/esm/core/drawingml/colors.js +23 -3
  16. package/dist/esm/core/drawingml/shape-render.d.ts +3 -1
  17. package/dist/esm/core/drawingml/shape-render.js +4 -2
  18. package/dist/esm/core/font/measure.d.ts +9 -0
  19. package/dist/esm/core/font/measure.js +9 -1
  20. package/dist/esm/core/fonts/families.js +4 -2
  21. package/dist/esm/core/fonts/scripts.js +4 -2
  22. package/dist/esm/core/ir/flow.d.ts +6 -0
  23. package/dist/esm/core/ir/sheet.d.ts +43 -0
  24. package/dist/esm/core/number-format.js +16 -11
  25. package/dist/esm/core/spreadsheet-model/index.d.ts +1 -1
  26. package/dist/esm/core/spreadsheet-model/types.d.ts +96 -0
  27. package/dist/esm/core/style-cascade/resolver.js +4 -2
  28. package/dist/esm/excel/column-bands.d.ts +39 -6
  29. package/dist/esm/excel/column-bands.js +41 -17
  30. package/dist/esm/excel/comments-parser.js +19 -0
  31. package/dist/esm/excel/conditional-format.d.ts +7 -3
  32. package/dist/esm/excel/conditional-format.js +77 -39
  33. package/dist/esm/excel/formula/context.d.ts +18 -0
  34. package/dist/esm/excel/formula/eval.js +51 -0
  35. package/dist/esm/excel/formula/index.d.ts +2 -2
  36. package/dist/esm/excel/formula/lexer.d.ts +1 -1
  37. package/dist/esm/excel/formula/lexer.js +41 -0
  38. package/dist/esm/excel/formula/parser.d.ts +25 -0
  39. package/dist/esm/excel/formula/parser.js +95 -0
  40. package/dist/esm/excel/print-model.d.ts +38 -1
  41. package/dist/esm/excel/print-model.js +522 -80
  42. package/dist/esm/excel/shared-strings-parser.d.ts +9 -0
  43. package/dist/esm/excel/shared-strings-parser.js +11 -1
  44. package/dist/esm/excel/sheet-drawing.d.ts +38 -2
  45. package/dist/esm/excel/sheet-drawing.js +47 -13
  46. package/dist/esm/excel/sheet-shape-parser.d.ts +6 -2
  47. package/dist/esm/excel/sheet-shape-parser.js +18 -6
  48. package/dist/esm/excel/sheet-to-flow.d.ts +17 -0
  49. package/dist/esm/excel/sheet-to-flow.js +434 -47
  50. package/dist/esm/excel/styles-parser.d.ts +9 -0
  51. package/dist/esm/excel/styles-parser.js +80 -26
  52. package/dist/esm/excel/table-parser.js +5 -0
  53. package/dist/esm/excel/table-style-presets.d.ts +26 -0
  54. package/dist/esm/excel/table-style-presets.js +1555 -0
  55. package/dist/esm/excel/table-style.d.ts +13 -0
  56. package/dist/esm/excel/table-style.js +75 -0
  57. package/dist/esm/excel/tint.d.ts +10 -0
  58. package/dist/esm/excel/tint.js +75 -0
  59. package/dist/esm/excel/vml-drawing.d.ts +41 -3
  60. package/dist/esm/excel/vml-drawing.js +143 -10
  61. package/dist/esm/excel/worksheet-parser.js +89 -15
  62. package/dist/esm/excel/xls/biff-reader.js +10 -2
  63. package/dist/esm/excel/xlsx-reader.js +195 -14
  64. package/dist/esm/excel/xlsx-writer.js +8 -7
  65. package/dist/esm/html/html-writer.js +202 -20
  66. package/dist/esm/layout/fit-pages.d.ts +11 -0
  67. package/dist/esm/layout/fit-pages.js +86 -0
  68. package/dist/esm/layout/line-paint.d.ts +58 -0
  69. package/dist/esm/layout/line-paint.js +107 -0
  70. package/dist/esm/layout/page-doc.d.ts +51 -0
  71. package/dist/esm/layout/page-doc.js +141 -1
  72. package/dist/esm/layout/styled-layout.d.ts +7 -0
  73. package/dist/esm/layout/styled-layout.js +274 -51
  74. package/dist/esm/layout/turned-section.js +14 -2
  75. package/dist/esm/markdown/markdown-writer.js +17 -6
  76. package/dist/esm/pdf/styled-page-emitter.js +49 -71
  77. package/dist/esm/pdf/styled-page-renderer.js +1 -1
  78. package/dist/esm/pdf-reader/font.js +3 -3
  79. package/dist/esm/svg/svg-text.d.ts +58 -0
  80. package/dist/esm/svg/svg-text.js +322 -0
  81. package/dist/esm/svg/svg-writer.js +135 -71
  82. package/dist/esm/word/docx-writer.js +11 -2
  83. package/package.json +5 -1
@@ -1,7 +1,7 @@
1
1
  import { INDEXED_COLORS } from "../core/indexed-colors.js";
2
- import { applyColorMods } from "../core/drawingml/colors.js";
3
2
  import { resolveAlternateContent } from "../core/opc/alternate-content.js";
4
3
  import { resolveInternalEntities } from "../core/opc/xml-entities.js";
4
+ import { applyTint } from "./tint.js";
5
5
  import { XMLParser } from "fast-xml-parser";
6
6
  //#region src/excel/styles-parser.ts
7
7
  var decoder = new TextDecoder("utf-8");
@@ -43,15 +43,55 @@ function parseXlsxStyles(data, theme) {
43
43
  indexed: parseIndexedColors(root)
44
44
  };
45
45
  const dxfs = parseDxfs(root, colors);
46
+ const tableStyles = parseTableStyles(root);
46
47
  return {
47
48
  numFmts: parseNumFmts(root),
48
49
  fonts: parseFonts(root, colors),
49
50
  fills: parseFills(root, colors),
50
51
  borders: parseBorders(root, colors),
51
52
  cellXfs: parseCellXfs(root),
52
- ...dxfs.length > 0 ? { dxfs } : {}
53
+ ...dxfs.length > 0 ? { dxfs } : {},
54
+ ...tableStyles.size > 0 ? { tableStyles } : {}
53
55
  };
54
56
  }
57
+ var TABLE_STYLE_TYPES = new Set([
58
+ "wholeTable",
59
+ "firstColumnStripe",
60
+ "secondColumnStripe",
61
+ "firstRowStripe",
62
+ "secondRowStripe",
63
+ "lastColumn",
64
+ "firstColumn",
65
+ "headerRow",
66
+ "totalRow",
67
+ "firstHeaderCell",
68
+ "lastHeaderCell",
69
+ "firstTotalCell",
70
+ "lastTotalCell"
71
+ ]);
72
+ function parseTableStyles(root) {
73
+ const out = /* @__PURE__ */ new Map();
74
+ for (const raw of asArray(asObject(root["tableStyles"])?.["tableStyle"])) {
75
+ const style = asObject(raw);
76
+ const name = style ? strAttr(style, "name") : void 0;
77
+ if (!style || name === void 0) continue;
78
+ const elements = [];
79
+ for (const el of asArray(style["tableStyleElement"])) {
80
+ const node = asObject(el);
81
+ const type = node ? strAttr(node, "type") : void 0;
82
+ const dxfId = node ? numAttr(node, "dxfId") : void 0;
83
+ if (!node || type === void 0 || !TABLE_STYLE_TYPES.has(type) || dxfId === void 0) continue;
84
+ const size = numAttr(node, "size");
85
+ elements.push({
86
+ type,
87
+ dxfId,
88
+ ...size !== void 0 && size > 1 ? { size } : {}
89
+ });
90
+ }
91
+ out.set(name, { elements });
92
+ }
93
+ return out;
94
+ }
55
95
  function parseDxfs(root, colors) {
56
96
  const node = asObject(root["dxfs"]);
57
97
  if (!node) return [];
@@ -103,7 +143,9 @@ function parseDxf(item, colors) {
103
143
  "top",
104
144
  "right",
105
145
  "bottom",
106
- "left"
146
+ "left",
147
+ "vertical",
148
+ "horizontal"
107
149
  ]) {
108
150
  const edge = parseBorderEdge(asObject(borderObj[side]), colors);
109
151
  if (edge) border[side] = edge;
@@ -201,8 +243,11 @@ function parseFonts(root, colors) {
201
243
  if (hasChild(obj, "i")) font.italic = childToggle(obj, "i");
202
244
  if (hasChild(obj, "u")) font.underline = childUnderline(obj);
203
245
  if (hasChild(obj, "strike")) font.strike = childToggle(obj, "strike");
204
- const colorRgb = colorOf(asObject(obj["color"]), colors);
246
+ const colorNode = asObject(obj["color"]);
247
+ const colorRgb = colorOf(colorNode, colors);
205
248
  if (colorRgb) font.colorHex = colorRgb;
249
+ const colorRef = colorNode ? colorRefOf(colorNode) : void 0;
250
+ if (colorRef !== void 0) font.colorRef = colorRef;
206
251
  const nameVal = childValAttr(obj, "name");
207
252
  if (nameVal) font.name = nameVal;
208
253
  out.push(font);
@@ -285,6 +330,9 @@ function parseCellXfs(root) {
285
330
  const rotation = numAttr(align, "textRotation");
286
331
  if (rotation !== void 0 && rotation !== 0) a.textRotation = rotation;
287
332
  if (boolAttr(align, "shrinkToFit")) a.shrinkToFit = true;
333
+ const order = numAttr(align, "readingOrder");
334
+ if (order === 1) a.readingOrder = "ltr";
335
+ else if (order === 2) a.readingOrder = "rtl";
288
336
  if (Object.keys(a).length > 0) xf.alignment = a;
289
337
  }
290
338
  out.push(xf);
@@ -357,8 +405,34 @@ function averageGradientColor(gf, colors) {
357
405
  const h = (x) => Math.round(x / n).toString(16).padStart(2, "0").toUpperCase();
358
406
  return `${h(r)}${h(g)}${h(b)}`;
359
407
  }
408
+ /**
409
+ * A `<color>` of this workbook as 6-hex: its `rgb`, its `indexed` entry or its
410
+ * `theme` slot, with the `tint` applied (§18.8.3).
411
+ *
412
+ * @param node The `<color>` element, parsed.
413
+ * @param colors What the workbook's colours point at.
414
+ * @returns The colour, or undefined for one that names nothing reachable.
415
+ */
416
+ function workbookColorHex(node, colors) {
417
+ return colorOf(asObject(node), colors);
418
+ }
360
419
  function colorOf(node, colors) {
361
420
  if (!node) return void 0;
421
+ const base = baseColorOf(node, colors);
422
+ return base === void 0 ? void 0 : applyTint(base, Number(strAttr(node, "tint") ?? "0"));
423
+ }
424
+ /** A `<color>` element's own spelling of its colour (see {@link XlsxFont.colorRef}). */
425
+ function colorRefOf(node) {
426
+ const theme = strAttr(node, "theme");
427
+ const tint = Number(strAttr(node, "tint") ?? "0") || 0;
428
+ if (theme !== void 0) return `theme:${theme}:${tint}`;
429
+ const rgb = strAttr(node, "rgb");
430
+ if (rgb !== void 0) return `rgb:${rgb.toUpperCase()}:${tint}`;
431
+ const indexed = strAttr(node, "indexed");
432
+ if (indexed !== void 0) return `indexed:${indexed}:${tint}`;
433
+ return "auto";
434
+ }
435
+ function baseColorOf(node, colors) {
362
436
  const rgb = strAttr(node, "rgb");
363
437
  if (rgb) {
364
438
  if (/^[0-9A-Fa-f]{8}$/.test(rgb)) return rgb.substring(2).toUpperCase();
@@ -372,8 +446,7 @@ function colorOf(node, colors) {
372
446
  const themeIdx = strAttr(node, "theme");
373
447
  if (themeIdx !== void 0 && colors.theme) {
374
448
  const slot = THEME_SLOTS[Number(themeIdx)];
375
- const base = slot ? colors.theme.get(slot) : void 0;
376
- if (base) return applyTint(base, Number(strAttr(node, "tint") ?? "0"));
449
+ return slot ? colors.theme.get(slot) : void 0;
377
450
  }
378
451
  }
379
452
  /** §18.8.27 — the indexed palette proper; 56 and 57+ are system colours. */
@@ -421,24 +494,5 @@ var THEME_SLOTS = [
421
494
  "hlink",
422
495
  "folHlink"
423
496
  ];
424
- /**
425
- * §18.8.19 `tint` — lighten (positive) or darken (negative) a theme colour by
426
- * scaling its HSL luminance. Excel writes it on nearly every theme colour it
427
- * uses, so ignoring it is not much better than ignoring the colour: a `theme="2"
428
- * tint="-0.5"` band is half as light as its slot.
429
- */
430
- function applyTint(hex, tint) {
431
- if (!Number.isFinite(tint) || tint === 0) return hex;
432
- return tint < 0 ? applyColorMods(hex, [{
433
- kind: "lumMod",
434
- val: 1 + tint
435
- }]) : applyColorMods(hex, [{
436
- kind: "lumMod",
437
- val: 1 - tint
438
- }, {
439
- kind: "lumOff",
440
- val: tint
441
- }]);
442
- }
443
497
  //#endregion
444
- export { EMPTY_XLSX_STYLES, parseDxf, parseXlsxStyles };
498
+ export { EMPTY_XLSX_STYLES, parseDxf, parseXlsxStyles, workbookColorHex };
@@ -25,11 +25,16 @@ function parseTablePartFull(data) {
25
25
  const name = strAttr(t, "name");
26
26
  const styleName = si ? strAttr(si, "name") : void 0;
27
27
  const af = asObj(t["autoFilter"]);
28
+ const totalsRowCount = numAttr(t, "totalsRowCount");
29
+ const named = asArray(asObj(t["tableColumns"])?.["tableColumn"]).map((c) => asObj(c) ? strAttr(asObj(c), "name") : void 0);
30
+ const columns = Array.from({ length: ref.endColumn - ref.startColumn + 1 }, (_, i) => named[i] ?? `Column${i + 1}`);
28
31
  const table = {
29
32
  ref,
30
33
  ...name ? { name } : {},
31
34
  ...styleName ? { styleName } : {},
32
35
  headerRowCount: numAttr(t, "headerRowCount") ?? 1,
36
+ ...totalsRowCount !== void 0 && totalsRowCount > 0 ? { totalsRowCount } : {},
37
+ ...columns.length > 0 ? { columns } : {},
33
38
  showRowStripes: si ? boolAttr(si, "showRowStripes") : false,
34
39
  showColumnStripes: si ? boolAttr(si, "showColumnStripes") : false,
35
40
  showFirstColumn: si ? boolAttr(si, "showFirstColumn") : false,
@@ -0,0 +1,26 @@
1
+ import { TableStyleElementType } from '../core/spreadsheet-model/index.js';
2
+ /** A theme colour: its slot and the tint applied to it (0 = none). */
3
+ export type PresetColor = readonly [theme: number, tint: number];
4
+ /** One line of a preset: its style and colour. */
5
+ export type PresetEdge = readonly ['thin' | 'medium' | 'thick' | 'double', PresetColor];
6
+ /** A preset's differential format: what one region of a table takes. */
7
+ export interface PresetDxf {
8
+ readonly bold?: boolean;
9
+ readonly color?: PresetColor;
10
+ readonly fill?: PresetColor;
11
+ readonly border?: {
12
+ readonly left?: PresetEdge;
13
+ readonly right?: PresetEdge;
14
+ readonly top?: PresetEdge;
15
+ readonly bottom?: PresetEdge;
16
+ readonly vertical?: PresetEdge;
17
+ readonly horizontal?: PresetEdge;
18
+ };
19
+ }
20
+ /**
21
+ * A built-in table style by its name, each region with its format.
22
+ *
23
+ * @param name The style's name as a workbook gives it (`TableStyleMedium2`).
24
+ * @returns Its regions' formats, or undefined for a name Excel does not build in.
25
+ */
26
+ export declare function presetTableStyle(name: string): Partial<Record<TableStyleElementType, PresetDxf>> | undefined;