reamkit 0.1.0-alpha.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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/dist/esm/bidi/algorithm.d.ts +9 -0
  4. package/dist/esm/bidi/algorithm.js +458 -0
  5. package/dist/esm/bidi/char-types.d.ts +2 -0
  6. package/dist/esm/bidi/char-types.js +439 -0
  7. package/dist/esm/bidi/index.d.ts +14 -0
  8. package/dist/esm/bidi/index.js +25 -0
  9. package/dist/esm/converter/docx-to-pdf.d.ts +15 -0
  10. package/dist/esm/converter/docx-to-pdf.js +227 -0
  11. package/dist/esm/converter/index.d.ts +4 -0
  12. package/dist/esm/converter/index.js +2 -0
  13. package/dist/esm/converter/xlsx-to-pdf.d.ts +13 -0
  14. package/dist/esm/converter/xlsx-to-pdf.js +515 -0
  15. package/dist/esm/crypto/asn1.d.ts +23 -0
  16. package/dist/esm/crypto/asn1.js +123 -0
  17. package/dist/esm/crypto/cms.d.ts +9 -0
  18. package/dist/esm/crypto/cms.js +34 -0
  19. package/dist/esm/crypto/index.d.ts +2 -0
  20. package/dist/esm/crypto/index.js +1 -0
  21. package/dist/esm/document-model/index.d.ts +1 -0
  22. package/dist/esm/document-model/index.js +0 -0
  23. package/dist/esm/document-model/types.d.ts +403 -0
  24. package/dist/esm/font/arabic-joining.d.ts +4 -0
  25. package/dist/esm/font/arabic-joining.js +97 -0
  26. package/dist/esm/font/binary-reader.d.ts +13 -0
  27. package/dist/esm/font/binary-reader.js +44 -0
  28. package/dist/esm/font/font-registry.d.ts +19 -0
  29. package/dist/esm/font/font-registry.js +39 -0
  30. package/dist/esm/font/index.d.ts +7 -0
  31. package/dist/esm/font/opentype-layout.d.ts +21 -0
  32. package/dist/esm/font/opentype-layout.js +329 -0
  33. package/dist/esm/font/ttf-parser.d.ts +29 -0
  34. package/dist/esm/font/ttf-parser.js +290 -0
  35. package/dist/esm/font/ttf-subset.d.ts +3 -0
  36. package/dist/esm/font/ttf-subset.js +201 -0
  37. package/dist/esm/fonts/index.d.ts +2 -0
  38. package/dist/esm/fonts/remote-fonts.d.ts +13 -0
  39. package/dist/esm/fonts/remote-fonts.js +94 -0
  40. package/dist/esm/hyphenation/index.d.ts +10 -0
  41. package/dist/esm/hyphenation/index.js +38 -0
  42. package/dist/esm/hyphenation/liang.d.ts +10 -0
  43. package/dist/esm/hyphenation/liang.js +79 -0
  44. package/dist/esm/hyphenation/patterns-en-us.d.ts +2 -0
  45. package/dist/esm/hyphenation/patterns-en-us.js +5 -0
  46. package/dist/esm/hyphenation/patterns-ru.d.ts +2 -0
  47. package/dist/esm/hyphenation/patterns-ru.js +5 -0
  48. package/dist/esm/index.d.ts +12 -0
  49. package/dist/esm/index.js +13 -0
  50. package/dist/esm/line-breaker/index.d.ts +2 -0
  51. package/dist/esm/line-breaker/knuth-plass.d.ts +30 -0
  52. package/dist/esm/line-breaker/knuth-plass.js +172 -0
  53. package/dist/esm/numbering/index.d.ts +1 -0
  54. package/dist/esm/numbering/state.d.ts +6 -0
  55. package/dist/esm/numbering/state.js +83 -0
  56. package/dist/esm/ooxml/drawingml/chart-parser.d.ts +3 -0
  57. package/dist/esm/ooxml/drawingml/chart-parser.js +218 -0
  58. package/dist/esm/ooxml/drawingml/colors.d.ts +17 -0
  59. package/dist/esm/ooxml/drawingml/colors.js +125 -0
  60. package/dist/esm/ooxml/drawingml/theme-parser.d.ts +1 -0
  61. package/dist/esm/ooxml/drawingml/theme-parser.js +55 -0
  62. package/dist/esm/ooxml/index.d.ts +1 -0
  63. package/dist/esm/ooxml/math/omml-parser.d.ts +4 -0
  64. package/dist/esm/ooxml/math/omml-parser.js +217 -0
  65. package/dist/esm/ooxml/spreadsheet/cell-reference.d.ts +6 -0
  66. package/dist/esm/ooxml/spreadsheet/cell-reference.js +26 -0
  67. package/dist/esm/ooxml/spreadsheet/defined-name-ref.d.ts +11 -0
  68. package/dist/esm/ooxml/spreadsheet/defined-name-ref.js +64 -0
  69. package/dist/esm/ooxml/spreadsheet/index.d.ts +12 -0
  70. package/dist/esm/ooxml/spreadsheet/index.js +7 -0
  71. package/dist/esm/ooxml/spreadsheet/number-format.d.ts +1 -0
  72. package/dist/esm/ooxml/spreadsheet/number-format.js +438 -0
  73. package/dist/esm/ooxml/spreadsheet/shared-strings-parser.d.ts +1 -0
  74. package/dist/esm/ooxml/spreadsheet/shared-strings-parser.js +47 -0
  75. package/dist/esm/ooxml/spreadsheet/styles-parser.d.ts +52 -0
  76. package/dist/esm/ooxml/spreadsheet/styles-parser.js +225 -0
  77. package/dist/esm/ooxml/spreadsheet/workbook-parser.d.ts +16 -0
  78. package/dist/esm/ooxml/spreadsheet/workbook-parser.js +90 -0
  79. package/dist/esm/ooxml/spreadsheet/worksheet-parser.d.ts +60 -0
  80. package/dist/esm/ooxml/spreadsheet/worksheet-parser.js +311 -0
  81. package/dist/esm/ooxml/wordproc/document-parser.d.ts +9 -0
  82. package/dist/esm/ooxml/wordproc/document-parser.js +274 -0
  83. package/dist/esm/ooxml/wordproc/drawing-parser.d.ts +33 -0
  84. package/dist/esm/ooxml/wordproc/drawing-parser.js +374 -0
  85. package/dist/esm/ooxml/wordproc/font-table.d.ts +15 -0
  86. package/dist/esm/ooxml/wordproc/font-table.js +82 -0
  87. package/dist/esm/ooxml/wordproc/index.d.ts +10 -0
  88. package/dist/esm/ooxml/wordproc/index.js +9 -0
  89. package/dist/esm/ooxml/wordproc/numbering-parser.d.ts +3 -0
  90. package/dist/esm/ooxml/wordproc/numbering-parser.js +89 -0
  91. package/dist/esm/ooxml/wordproc/paragraph-properties.d.ts +2 -0
  92. package/dist/esm/ooxml/wordproc/paragraph-properties.js +85 -0
  93. package/dist/esm/ooxml/wordproc/po-helpers.d.ts +14 -0
  94. package/dist/esm/ooxml/wordproc/po-helpers.js +76 -0
  95. package/dist/esm/ooxml/wordproc/po-to-flat.d.ts +2 -0
  96. package/dist/esm/ooxml/wordproc/po-to-flat.js +28 -0
  97. package/dist/esm/ooxml/wordproc/run-properties.d.ts +2 -0
  98. package/dist/esm/ooxml/wordproc/run-properties.js +82 -0
  99. package/dist/esm/ooxml/wordproc/settings-parser.d.ts +5 -0
  100. package/dist/esm/ooxml/wordproc/settings-parser.js +26 -0
  101. package/dist/esm/ooxml/wordproc/styles-parser.d.ts +3 -0
  102. package/dist/esm/ooxml/wordproc/styles-parser.js +67 -0
  103. package/dist/esm/ooxml/wordproc/table-parser.d.ts +3 -0
  104. package/dist/esm/ooxml/wordproc/table-parser.js +162 -0
  105. package/dist/esm/ooxml/wordproc/text-extractor.d.ts +1 -0
  106. package/dist/esm/ooxml/wordproc/text-extractor.js +1 -0
  107. package/dist/esm/ooxml/wordproc/xml-helpers.d.ts +9 -0
  108. package/dist/esm/ooxml/wordproc/xml-helpers.js +36 -0
  109. package/dist/esm/opc/core-properties.d.ts +11 -0
  110. package/dist/esm/opc/core-properties.js +51 -0
  111. package/dist/esm/opc/index.d.ts +5 -0
  112. package/dist/esm/opc/index.js +3 -0
  113. package/dist/esm/opc/package.d.ts +26 -0
  114. package/dist/esm/opc/package.js +113 -0
  115. package/dist/esm/opc/relationship-types.d.ts +3 -0
  116. package/dist/esm/opc/relationship-types.js +4 -0
  117. package/dist/esm/opc/relationships.d.ts +7 -0
  118. package/dist/esm/opc/relationships.js +28 -0
  119. package/dist/esm/pdf/arc-to-bezier.d.ts +5 -0
  120. package/dist/esm/pdf/arc-to-bezier.js +58 -0
  121. package/dist/esm/pdf/builtin-fonts.d.ts +2 -0
  122. package/dist/esm/pdf/chart-geometry.d.ts +64 -0
  123. package/dist/esm/pdf/chart-geometry.js +674 -0
  124. package/dist/esm/pdf/cid-font.d.ts +15 -0
  125. package/dist/esm/pdf/cid-font.js +174 -0
  126. package/dist/esm/pdf/embedded-file.d.ts +11 -0
  127. package/dist/esm/pdf/embedded-file.js +23 -0
  128. package/dist/esm/pdf/icc-profile.d.ts +1 -0
  129. package/dist/esm/pdf/icc-profile.js +166 -0
  130. package/dist/esm/pdf/image-xobject.d.ts +13 -0
  131. package/dist/esm/pdf/image-xobject.js +335 -0
  132. package/dist/esm/pdf/index.d.ts +11 -0
  133. package/dist/esm/pdf/index.js +5 -0
  134. package/dist/esm/pdf/math-layout.d.ts +45 -0
  135. package/dist/esm/pdf/math-layout.js +1138 -0
  136. package/dist/esm/pdf/objects.d.ts +32 -0
  137. package/dist/esm/pdf/objects.js +54 -0
  138. package/dist/esm/pdf/preset-geometry.d.ts +6 -0
  139. package/dist/esm/pdf/preset-geometry.js +199 -0
  140. package/dist/esm/pdf/serialize.d.ts +3 -0
  141. package/dist/esm/pdf/serialize.js +54 -0
  142. package/dist/esm/pdf/signature.d.ts +25 -0
  143. package/dist/esm/pdf/signature.js +126 -0
  144. package/dist/esm/pdf/struct-tree.d.ts +31 -0
  145. package/dist/esm/pdf/struct-tree.js +109 -0
  146. package/dist/esm/pdf/styled-page-renderer.d.ts +43 -0
  147. package/dist/esm/pdf/styled-page-renderer.js +2317 -0
  148. package/dist/esm/pdf/text-encoding.d.ts +2 -0
  149. package/dist/esm/pdf/text-page-renderer.d.ts +16 -0
  150. package/dist/esm/pdf/text-page-renderer.js +4 -0
  151. package/dist/esm/pdf/vector-graphics.d.ts +46 -0
  152. package/dist/esm/pdf/vector-graphics.js +103 -0
  153. package/dist/esm/pdf/writer.d.ts +10 -0
  154. package/dist/esm/pdf/writer.js +81 -0
  155. package/dist/esm/pdf/xmp.d.ts +13 -0
  156. package/dist/esm/pdf/xmp.js +38 -0
  157. package/dist/esm/style-cascade/index.d.ts +3 -0
  158. package/dist/esm/style-cascade/resolver.d.ts +4 -0
  159. package/dist/esm/style-cascade/resolver.js +96 -0
  160. package/dist/esm/style-cascade/types.d.ts +29 -0
  161. package/dist/esm/style-cascade/types.js +26 -0
  162. package/package.json +90 -0
@@ -0,0 +1,162 @@
1
+ import { poAttr, poChildren, poChildrenWith, poFirstChild, poIntAttr, poToggle, poVal } from "./po-helpers.js";
2
+ import { parseBodyElements } from "./document-parser.js";
3
+ //#region src/ooxml/wordproc/table-parser.ts
4
+ var BORDER_STYLES = new Set([
5
+ "none",
6
+ "single",
7
+ "double",
8
+ "thick",
9
+ "dotted",
10
+ "dashed"
11
+ ]);
12
+ var WIDTH_TYPES = new Set([
13
+ "auto",
14
+ "dxa",
15
+ "pct",
16
+ "nil"
17
+ ]);
18
+ var HEIGHT_RULES = new Set([
19
+ "auto",
20
+ "atLeast",
21
+ "exact"
22
+ ]);
23
+ function parseTable(tbl) {
24
+ const properties = parseTableProperties(poFirstChild(tbl, "w:tblPr"));
25
+ const grid = parseTableGrid(poFirstChild(tbl, "w:tblGrid"));
26
+ const rows = [];
27
+ for (const tr of poChildrenWith(tbl, "w:tr")) rows.push(parseTableRow(tr));
28
+ return {
29
+ properties,
30
+ grid,
31
+ rows
32
+ };
33
+ }
34
+ function parseTableProperties(tblPr) {
35
+ if (!tblPr) return {};
36
+ const out = {};
37
+ const tblW = poFirstChild(tblPr, "w:tblW");
38
+ if (tblW) {
39
+ const w = poIntAttr(tblW, "w");
40
+ const type = poAttr(tblW, "type");
41
+ if (w !== void 0) out.widthTwips = w;
42
+ if (type && WIDTH_TYPES.has(type)) out.widthType = type;
43
+ }
44
+ const tblLayout = poFirstChild(tblPr, "w:tblLayout");
45
+ if (tblLayout) {
46
+ const t = poAttr(tblLayout, "type");
47
+ if (t === "fixed" || t === "auto") out.layout = t;
48
+ }
49
+ const borders = parseBorders(poFirstChild(tblPr, "w:tblBorders"));
50
+ if (borders) out.borders = borders;
51
+ const margins = parseCellMargins(poFirstChild(tblPr, "w:tblCellMar"));
52
+ if (margins) out.defaultCellMargins = margins;
53
+ return out;
54
+ }
55
+ function parseTableGrid(tblGrid) {
56
+ if (!tblGrid) return [];
57
+ const cols = [];
58
+ for (const gridCol of poChildrenWith(tblGrid, "w:gridCol")) {
59
+ const w = poIntAttr(gridCol, "w");
60
+ cols.push(w ?? 0);
61
+ }
62
+ return cols;
63
+ }
64
+ function parseTableRow(tr) {
65
+ const properties = parseRowProperties(poFirstChild(tr, "w:trPr"));
66
+ const cells = [];
67
+ for (const tc of poChildrenWith(tr, "w:tc")) cells.push(parseTableCell(tc));
68
+ return {
69
+ properties,
70
+ cells
71
+ };
72
+ }
73
+ function parseRowProperties(trPr) {
74
+ if (!trPr) return {};
75
+ const out = {};
76
+ const trHeight = poFirstChild(trPr, "w:trHeight");
77
+ if (trHeight) {
78
+ const val = poIntAttr(trHeight, "val");
79
+ const rule = poAttr(trHeight, "hRule");
80
+ if (val !== void 0) out.heightTwips = val;
81
+ if (rule && HEIGHT_RULES.has(rule)) out.heightRule = rule;
82
+ }
83
+ if (poFirstChild(trPr, "w:cantSplit")) out.cantSplit = poToggle(poFirstChild(trPr, "w:cantSplit")) ?? true;
84
+ if (poFirstChild(trPr, "w:tblHeader")) out.isHeader = poToggle(poFirstChild(trPr, "w:tblHeader")) ?? true;
85
+ return out;
86
+ }
87
+ function parseTableCell(tc) {
88
+ return {
89
+ properties: parseCellProperties(poFirstChild(tc, "w:tcPr")),
90
+ content: parseBodyElements(poChildren(tc))
91
+ };
92
+ }
93
+ function parseCellProperties(tcPr) {
94
+ if (!tcPr) return {};
95
+ const out = {};
96
+ const tcW = poFirstChild(tcPr, "w:tcW");
97
+ if (tcW) {
98
+ const w = poIntAttr(tcW, "w");
99
+ if (w !== void 0) out.widthTwips = w;
100
+ }
101
+ const gridSpan = poFirstChild(tcPr, "w:gridSpan");
102
+ if (gridSpan) {
103
+ const v = poIntAttr(gridSpan, "val");
104
+ if (v !== void 0) out.gridSpan = v;
105
+ }
106
+ const vMerge = poFirstChild(tcPr, "w:vMerge");
107
+ if (vMerge) if (poVal(vMerge) === "restart") out.vMerge = "restart";
108
+ else out.vMerge = "continue";
109
+ const borders = parseBorders(poFirstChild(tcPr, "w:tcBorders"));
110
+ if (borders) out.borders = borders;
111
+ const margins = parseCellMargins(poFirstChild(tcPr, "w:tcMar"));
112
+ if (margins) out.margins = margins;
113
+ const shd = poFirstChild(tcPr, "w:shd");
114
+ if (shd) {
115
+ const fill = poAttr(shd, "fill");
116
+ if (fill && fill !== "auto" && /^[0-9A-Fa-f]{6}$/.test(fill)) out.shading = { colorHex: fill.toUpperCase() };
117
+ }
118
+ return out;
119
+ }
120
+ function parseBorders(node) {
121
+ if (!node) return void 0;
122
+ const out = {};
123
+ const top = parseBorder(poFirstChild(node, "w:top"));
124
+ const right = parseBorder(poFirstChild(node, "w:right") ?? poFirstChild(node, "w:end"));
125
+ const bottom = parseBorder(poFirstChild(node, "w:bottom"));
126
+ const left = parseBorder(poFirstChild(node, "w:left") ?? poFirstChild(node, "w:start"));
127
+ const insideH = parseBorder(poFirstChild(node, "w:insideH"));
128
+ const insideV = parseBorder(poFirstChild(node, "w:insideV"));
129
+ if (top) out.top = top;
130
+ if (right) out.right = right;
131
+ if (bottom) out.bottom = bottom;
132
+ if (left) out.left = left;
133
+ if (insideH) out.insideH = insideH;
134
+ if (insideV) out.insideV = insideV;
135
+ return Object.keys(out).length > 0 ? out : void 0;
136
+ }
137
+ function parseBorder(node) {
138
+ if (!node) return void 0;
139
+ const val = poVal(node);
140
+ if (!val || !BORDER_STYLES.has(val)) return void 0;
141
+ const sz = poIntAttr(node, "sz");
142
+ const color = poAttr(node, "color");
143
+ const out = { style: val };
144
+ if (sz !== void 0) out.sizeEighthPt = sz;
145
+ if (color && color !== "auto" && /^[0-9A-Fa-f]{6}$/.test(color)) out.colorHex = color.toUpperCase();
146
+ return out;
147
+ }
148
+ function parseCellMargins(node) {
149
+ if (!node) return void 0;
150
+ const out = {};
151
+ const top = poIntAttr(poFirstChild(node, "w:top"), "w");
152
+ const bottom = poIntAttr(poFirstChild(node, "w:bottom"), "w");
153
+ const left = poIntAttr(poFirstChild(node, "w:left") ?? poFirstChild(node, "w:start"), "w");
154
+ const right = poIntAttr(poFirstChild(node, "w:right") ?? poFirstChild(node, "w:end"), "w");
155
+ if (top !== void 0) out.topTwips = top;
156
+ if (bottom !== void 0) out.bottomTwips = bottom;
157
+ if (left !== void 0) out.leftTwips = left;
158
+ if (right !== void 0) out.rightTwips = right;
159
+ return Object.keys(out).length > 0 ? out : void 0;
160
+ }
161
+ //#endregion
162
+ export { parseTable };
@@ -0,0 +1 @@
1
+ export declare function extractParagraphs(documentXml: Uint8Array): Array<string>;
@@ -0,0 +1 @@
1
+ import "./document-parser.js";
@@ -0,0 +1,9 @@
1
+ export type XmlAttrValue = string;
2
+ export type XmlElement = Record<string, unknown>;
3
+ export declare function asElement(v: unknown): XmlElement | undefined;
4
+ export declare function asArray(v: unknown): ReadonlyArray<unknown>;
5
+ export declare function getAttr(node: unknown, name: string): string | undefined;
6
+ export declare function getVal(node: unknown): string | undefined;
7
+ export declare function parseIntAttr(node: unknown, name: string): number | undefined;
8
+ export declare function parseToggle(node: unknown): boolean | undefined;
9
+ export declare function getText(node: unknown): string;
@@ -0,0 +1,36 @@
1
+ //#region src/ooxml/wordproc/xml-helpers.ts
2
+ function asElement(v) {
3
+ if (v === null || v === void 0) return void 0;
4
+ if (typeof v !== "object" || Array.isArray(v)) return void 0;
5
+ return v;
6
+ }
7
+ function asArray(v) {
8
+ if (v === null || v === void 0) return [];
9
+ return Array.isArray(v) ? v : [v];
10
+ }
11
+ function getAttr(node, name) {
12
+ const el = asElement(node);
13
+ if (!el) return void 0;
14
+ const v = el[`@_w:${name}`] ?? el[`@_${name}`];
15
+ return typeof v === "string" ? v : void 0;
16
+ }
17
+ function getVal(node) {
18
+ return getAttr(node, "val");
19
+ }
20
+ function parseIntAttr(node, name) {
21
+ const v = getAttr(node, name);
22
+ if (v === void 0) return void 0;
23
+ const n = Number(v);
24
+ if (!Number.isFinite(n)) return void 0;
25
+ return n;
26
+ }
27
+ function parseToggle(node) {
28
+ if (node === void 0) return void 0;
29
+ if (node === null || node === "" || typeof node === "boolean" || typeof node === "number") return true;
30
+ if (typeof node === "string") return true;
31
+ const v = getAttr(node, "val");
32
+ if (v === void 0) return true;
33
+ return !(v === "false" || v === "0" || v === "off");
34
+ }
35
+ //#endregion
36
+ export { asArray, asElement, getAttr, getVal, parseIntAttr, parseToggle };
@@ -0,0 +1,11 @@
1
+ export interface CoreProperties {
2
+ readonly title?: string;
3
+ readonly subject?: string;
4
+ readonly creator?: string;
5
+ readonly keywords?: string;
6
+ readonly description?: string;
7
+ readonly lastModifiedBy?: string;
8
+ readonly created?: Date;
9
+ readonly modified?: Date;
10
+ }
11
+ export declare function parseCoreProperties(data: Uint8Array): CoreProperties;
@@ -0,0 +1,51 @@
1
+ import { XMLParser } from "fast-xml-parser";
2
+ //#region src/opc/core-properties.ts
3
+ var decoder = new TextDecoder("utf-8");
4
+ var parser = new XMLParser({
5
+ ignoreAttributes: false,
6
+ attributeNamePrefix: "@_",
7
+ textNodeName: "#text",
8
+ parseAttributeValue: false,
9
+ parseTagValue: false,
10
+ trimValues: false
11
+ });
12
+ function parseCoreProperties(data) {
13
+ const tree = parser.parse(decoder.decode(data));
14
+ const root = tree["cp:coreProperties"] ?? tree["coreProperties"];
15
+ if (!root) return {};
16
+ const out = {};
17
+ const title = textValue(root["dc:title"] ?? root["title"]);
18
+ if (title) out.title = title;
19
+ const subject = textValue(root["dc:subject"] ?? root["subject"]);
20
+ if (subject) out.subject = subject;
21
+ const creator = textValue(root["dc:creator"] ?? root["creator"]);
22
+ if (creator) out.creator = creator;
23
+ const keywords = textValue(root["cp:keywords"] ?? root["keywords"]);
24
+ if (keywords) out.keywords = keywords;
25
+ const description = textValue(root["dc:description"] ?? root["description"]);
26
+ if (description) out.description = description;
27
+ const lastModifiedBy = textValue(root["cp:lastModifiedBy"] ?? root["lastModifiedBy"]);
28
+ if (lastModifiedBy) out.lastModifiedBy = lastModifiedBy;
29
+ const created = parseIsoDate(textValue(root["dcterms:created"] ?? root["created"]));
30
+ if (created) out.created = created;
31
+ const modified = parseIsoDate(textValue(root["dcterms:modified"] ?? root["modified"]));
32
+ if (modified) out.modified = modified;
33
+ return out;
34
+ }
35
+ function textValue(node) {
36
+ if (node === void 0 || node === null) return void 0;
37
+ if (typeof node === "string") return node.length > 0 ? node : void 0;
38
+ if (typeof node === "number") return String(node);
39
+ if (typeof node === "object") {
40
+ const inner = node["#text"];
41
+ if (typeof inner === "string" && inner.length > 0) return inner;
42
+ if (typeof inner === "number") return String(inner);
43
+ }
44
+ }
45
+ function parseIsoDate(value) {
46
+ if (!value) return void 0;
47
+ const d = new Date(value);
48
+ return Number.isFinite(d.getTime()) ? d : void 0;
49
+ }
50
+ //#endregion
51
+ export { parseCoreProperties };
@@ -0,0 +1,5 @@
1
+ export { OpcPackage } from './package.js';
2
+ export type { Relationship } from './relationships.js';
3
+ export { REL_OFFICE_DOCUMENT, REL_CORE_PROPERTIES, REL_EXTENDED_PROPERTIES, } from './relationship-types.js';
4
+ export { parseCoreProperties } from './core-properties.js';
5
+ export type { CoreProperties } from './core-properties.js';
@@ -0,0 +1,3 @@
1
+ import "./relationship-types.js";
2
+ import "./package.js";
3
+ import "./core-properties.js";
@@ -0,0 +1,26 @@
1
+ import { Relationship } from './relationships.js';
2
+ export interface OpcOpenOptions {
3
+ readonly maxArchiveBytes?: number;
4
+ readonly maxEntryBytes?: number;
5
+ readonly maxTotalBytes?: number;
6
+ readonly maxEntries?: number;
7
+ }
8
+ export declare class OpcPackage {
9
+ private readonly parts;
10
+ private readonly rootRelationships;
11
+ private constructor();
12
+ static open(buffer: Uint8Array, options?: OpcOpenOptions): OpcPackage;
13
+ getPart(path: string): Uint8Array | undefined;
14
+ requirePart(path: string): Uint8Array;
15
+ listParts(): Array<string>;
16
+ getPartRelationships(partPath: string): Array<Relationship>;
17
+ resolveRelatedPart(sourcePartPath: string, relationship: Relationship): {
18
+ readonly path: string;
19
+ readonly data: Uint8Array;
20
+ } | undefined;
21
+ getMainDocumentPath(): string;
22
+ getMainDocument(): {
23
+ path: string;
24
+ data: Uint8Array;
25
+ };
26
+ }
@@ -0,0 +1,113 @@
1
+ import { parseRelationships } from "./relationships.js";
2
+ import "./relationship-types.js";
3
+ import { unzipSync } from "fflate";
4
+ //#region src/opc/package.ts
5
+ var ROOT_RELS_PATH = "_rels/.rels";
6
+ var MIB = 1024 * 1024;
7
+ var OpcPackage = class OpcPackage {
8
+ constructor(parts, rootRelationships) {
9
+ this.parts = parts;
10
+ this.rootRelationships = rootRelationships;
11
+ }
12
+ static open(buffer, options = {}) {
13
+ const maxArchive = options.maxArchiveBytes ?? 128 * MIB;
14
+ const maxEntry = options.maxEntryBytes ?? 256 * MIB;
15
+ const maxTotal = options.maxTotalBytes ?? 512 * MIB;
16
+ const maxEntries = options.maxEntries ?? 65536;
17
+ if (buffer.byteLength > maxArchive) throw new Error(`OPC archive too large: ${buffer.byteLength} bytes (limit ${maxArchive}); refusing to unzip`);
18
+ let total = 0;
19
+ let count = 0;
20
+ let violation;
21
+ const entries = unzipSync(buffer, { filter: (info) => {
22
+ if (++count > maxEntries) {
23
+ violation ??= `more than ${maxEntries} entries`;
24
+ return false;
25
+ }
26
+ if (info.originalSize > maxEntry) {
27
+ violation ??= `entry "${info.name}" declares ${info.originalSize} bytes (limit ${maxEntry})`;
28
+ return false;
29
+ }
30
+ total += info.originalSize;
31
+ if (total > maxTotal) {
32
+ violation ??= `total uncompressed size exceeds ${maxTotal} bytes`;
33
+ return false;
34
+ }
35
+ return true;
36
+ } });
37
+ if (violation) throw new Error(`OPC archive rejected (zip-bomb guard): ${violation}`);
38
+ const parts = /* @__PURE__ */ new Map();
39
+ for (const [path, data] of Object.entries(entries)) parts.set(normalizePath(path), data);
40
+ const relsBytes = parts.get(ROOT_RELS_PATH);
41
+ if (!relsBytes) throw new Error(`OPC package missing ${ROOT_RELS_PATH}`);
42
+ return new OpcPackage(parts, parseRelationships(relsBytes));
43
+ }
44
+ getPart(path) {
45
+ return this.parts.get(normalizePath(path));
46
+ }
47
+ requirePart(path) {
48
+ const data = this.getPart(path);
49
+ if (!data) throw new Error(`OPC part not found: ${path}`);
50
+ return data;
51
+ }
52
+ listParts() {
53
+ return [...this.parts.keys()];
54
+ }
55
+ getPartRelationships(partPath) {
56
+ const normalized = normalizePath(partPath);
57
+ const slash = normalized.lastIndexOf("/");
58
+ const dir = slash >= 0 ? normalized.substring(0, slash) : "";
59
+ const base = slash >= 0 ? normalized.substring(slash + 1) : normalized;
60
+ const relsPath = dir.length > 0 ? `${dir}/_rels/${base}.rels` : `_rels/${base}.rels`;
61
+ const data = this.parts.get(relsPath);
62
+ if (!data) return [];
63
+ return parseRelationships(data);
64
+ }
65
+ resolveRelatedPart(sourcePartPath, relationship) {
66
+ if (relationship.targetMode !== "Internal") return void 0;
67
+ const resolved = resolveTarget(`/${normalizePath(sourcePartPath)}`, relationship.target);
68
+ const data = this.getPart(resolved);
69
+ if (!data) return void 0;
70
+ return {
71
+ path: resolved,
72
+ data
73
+ };
74
+ }
75
+ getMainDocumentPath() {
76
+ const candidates = this.rootRelationships.filter((r) => r.type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" && r.targetMode === "Internal");
77
+ if (candidates.length === 0) throw new Error("OPC package has no officeDocument relationship");
78
+ if (candidates.length > 1) throw new Error(`OPC package has multiple officeDocument relationships (${candidates.length})`);
79
+ return resolveTarget("/", candidates[0].target);
80
+ }
81
+ getMainDocument() {
82
+ const path = this.getMainDocumentPath();
83
+ return {
84
+ path,
85
+ data: this.requirePart(path)
86
+ };
87
+ }
88
+ };
89
+ function normalizePath(p) {
90
+ return p.startsWith("/") ? p.slice(1) : p;
91
+ }
92
+ function resolveTarget(sourcePath, target) {
93
+ if (target.startsWith("/")) return normalizePath(target);
94
+ return normalizePath(collapseDotSegments(`${sourcePath.endsWith("/") ? sourcePath : sourcePath.substring(0, sourcePath.lastIndexOf("/") + 1)}${target}`));
95
+ }
96
+ function collapseDotSegments(p) {
97
+ const segments = p.split("/");
98
+ const out = [];
99
+ for (const s of segments) {
100
+ if (s === "." || s === "") {
101
+ if (out.length === 0) out.push("");
102
+ continue;
103
+ }
104
+ if (s === "..") {
105
+ if (out.length > 1) out.pop();
106
+ continue;
107
+ }
108
+ out.push(s);
109
+ }
110
+ return out.join("/");
111
+ }
112
+ //#endregion
113
+ export { OpcPackage };
@@ -0,0 +1,3 @@
1
+ export declare const REL_OFFICE_DOCUMENT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
2
+ export declare const REL_CORE_PROPERTIES = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
3
+ export declare const REL_EXTENDED_PROPERTIES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
@@ -0,0 +1,4 @@
1
+ //#region src/opc/relationship-types.ts
2
+ var REL_OFFICE_DOCUMENT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
3
+ //#endregion
4
+ export { REL_OFFICE_DOCUMENT };
@@ -0,0 +1,7 @@
1
+ export interface Relationship {
2
+ readonly id: string;
3
+ readonly type: string;
4
+ readonly target: string;
5
+ readonly targetMode: 'Internal' | 'External';
6
+ }
7
+ export declare function parseRelationships(data: Uint8Array): Array<Relationship>;
@@ -0,0 +1,28 @@
1
+ import { XMLParser } from "fast-xml-parser";
2
+ //#region src/opc/relationships.ts
3
+ var decoder = new TextDecoder("utf-8");
4
+ var parser = new XMLParser({
5
+ ignoreAttributes: false,
6
+ attributeNamePrefix: "@_",
7
+ parseAttributeValue: false,
8
+ trimValues: false,
9
+ isArray: (tagName) => tagName === "Relationship"
10
+ });
11
+ function parseRelationships(data) {
12
+ const xml = decoder.decode(data);
13
+ const list = parser.parse(xml).Relationships?.Relationship;
14
+ if (!list) return [];
15
+ return list.map((r) => ({
16
+ id: requireAttr(r, "Id"),
17
+ type: requireAttr(r, "Type"),
18
+ target: requireAttr(r, "Target"),
19
+ targetMode: r["@_TargetMode"] === "External" ? "External" : "Internal"
20
+ }));
21
+ }
22
+ function requireAttr(r, name) {
23
+ const v = r[`@_${name}`];
24
+ if (v === void 0) throw new Error(`Relationship missing required attribute: ${name}`);
25
+ return v;
26
+ }
27
+ //#endregion
28
+ export { parseRelationships };
@@ -0,0 +1,5 @@
1
+ import { PathSegment } from './vector-graphics.js';
2
+ export declare function arcPoint(cx: number, cy: number, rx: number, ry: number, angleRad: number): readonly [number, number];
3
+ export declare function arcToBeziers(cx: number, cy: number, rx: number, ry: number, startAngleRad: number, sweepAngleRad: number): Array<PathSegment>;
4
+ export declare function ellipseSegments(w: number, h: number): ReadonlyArray<PathSegment>;
5
+ export declare function roundRectSegments(w: number, h: number, r: number): ReadonlyArray<PathSegment>;
@@ -0,0 +1,58 @@
1
+ import { PathBuilder } from "./vector-graphics.js";
2
+ //#region src/pdf/arc-to-bezier.ts
3
+ function arcPoint(cx, cy, rx, ry, angleRad) {
4
+ return [cx + rx * Math.cos(angleRad), cy + ry * Math.sin(angleRad)];
5
+ }
6
+ function arcToBeziers(cx, cy, rx, ry, startAngleRad, sweepAngleRad) {
7
+ const segments = [];
8
+ if (!(rx > 0) || !(ry > 0) || sweepAngleRad === 0 || !Number.isFinite(sweepAngleRad)) return segments;
9
+ const nSegs = Math.max(1, Math.ceil(Math.abs(sweepAngleRad) / (Math.PI / 2 + 1e-9)));
10
+ const delta = sweepAngleRad / nSegs;
11
+ const alpha = 4 / 3 * Math.tan(delta / 4);
12
+ let theta = startAngleRad;
13
+ for (let i = 0; i < nSegs; i++) {
14
+ const t2 = theta + delta;
15
+ const cos1 = Math.cos(theta);
16
+ const sin1 = Math.sin(theta);
17
+ const cos2 = Math.cos(t2);
18
+ const sin2 = Math.sin(t2);
19
+ segments.push({
20
+ op: "cubic",
21
+ x1: cx + rx * cos1 - alpha * rx * sin1,
22
+ y1: cy + ry * sin1 + alpha * ry * cos1,
23
+ x2: cx + rx * cos2 + alpha * rx * sin2,
24
+ y2: cy + ry * sin2 - alpha * ry * cos2,
25
+ x: cx + rx * cos2,
26
+ y: cy + ry * sin2
27
+ });
28
+ theta = t2;
29
+ }
30
+ return segments;
31
+ }
32
+ function ellipseSegments(w, h) {
33
+ const rx = w / 2;
34
+ const ry = h / 2;
35
+ const cx = rx;
36
+ const cy = ry;
37
+ const start = arcPoint(cx, cy, rx, ry, 0);
38
+ return new PathBuilder().moveTo(start[0], start[1]).append(arcToBeziers(cx, cy, rx, ry, 0, 2 * Math.PI)).close().build().segments;
39
+ }
40
+ function roundRectSegments(w, h, r) {
41
+ const rr = Math.max(0, Math.min(r, Math.min(w, h) / 2));
42
+ const b = new PathBuilder();
43
+ if (rr === 0) return b.moveTo(0, 0).lineTo(w, 0).lineTo(w, h).lineTo(0, h).close().build().segments;
44
+ const Q = Math.PI / 2;
45
+ b.moveTo(rr, 0);
46
+ b.lineTo(w - rr, 0);
47
+ b.append(arcToBeziers(w - rr, rr, rr, rr, -Q, Q));
48
+ b.lineTo(w, h - rr);
49
+ b.append(arcToBeziers(w - rr, h - rr, rr, rr, 0, Q));
50
+ b.lineTo(rr, h);
51
+ b.append(arcToBeziers(rr, h - rr, rr, rr, Q, Q));
52
+ b.lineTo(0, rr);
53
+ b.append(arcToBeziers(rr, rr, rr, rr, Math.PI, Q));
54
+ b.close();
55
+ return b.build().segments;
56
+ }
57
+ //#endregion
58
+ export { arcPoint, arcToBeziers, ellipseSegments, roundRectSegments };
@@ -0,0 +1,2 @@
1
+ export type BuiltinFontName = 'Helvetica' | 'Helvetica-Bold' | 'Helvetica-Oblique' | 'Helvetica-BoldOblique' | 'Times-Roman' | 'Times-Bold' | 'Times-Italic' | 'Times-BoldItalic' | 'Courier' | 'Courier-Bold' | 'Courier-Oblique' | 'Courier-BoldOblique' | 'Symbol' | 'ZapfDingbats';
2
+ export declare const BUILTIN_FONTS: ReadonlyArray<BuiltinFontName>;
@@ -0,0 +1,64 @@
1
+ import { Chart, ChartSeries } from '../document-model/index.js';
2
+ export interface ChartRect {
3
+ readonly x: number;
4
+ readonly y: number;
5
+ readonly w: number;
6
+ readonly h: number;
7
+ readonly fillHex?: string;
8
+ readonly strokeHex?: string;
9
+ readonly strokeWidthPt?: number;
10
+ }
11
+ export interface ChartPolyline {
12
+ readonly points: ReadonlyArray<readonly [number, number]>;
13
+ readonly strokeHex: string;
14
+ readonly widthPt: number;
15
+ }
16
+ export interface ChartPolygon {
17
+ readonly points: ReadonlyArray<readonly [number, number]>;
18
+ readonly fillHex: string;
19
+ readonly strokeHex?: string;
20
+ readonly widthPt?: number;
21
+ }
22
+ export interface ChartWedge {
23
+ readonly cx: number;
24
+ readonly cy: number;
25
+ readonly r: number;
26
+ readonly startRad: number;
27
+ readonly sweepRad: number;
28
+ readonly fillHex: string;
29
+ readonly strokeHex?: string;
30
+ }
31
+ export type LabelAlign = 'left' | 'center' | 'right';
32
+ export interface ChartLabel {
33
+ readonly text: string;
34
+ readonly x: number;
35
+ readonly y: number;
36
+ readonly sizePt: number;
37
+ readonly colorHex: string;
38
+ readonly align: LabelAlign;
39
+ }
40
+ export interface ChartScene {
41
+ readonly rects: ReadonlyArray<ChartRect>;
42
+ readonly polylines: ReadonlyArray<ChartPolyline>;
43
+ readonly wedges: ReadonlyArray<ChartWedge>;
44
+ readonly labels: ReadonlyArray<ChartLabel>;
45
+ readonly polygons?: ReadonlyArray<ChartPolygon>;
46
+ }
47
+ export type MeasureText = (text: string, sizePt: number) => number;
48
+ export declare const CHART_LABEL_PT = 9;
49
+ export declare const CHART_TITLE_PT = 13;
50
+ export declare const SERIES_COLORS: string[];
51
+ export declare const seriesColor: (s: ChartSeries, i: number) => string;
52
+ export interface Scale {
53
+ readonly min: number;
54
+ readonly max: number;
55
+ readonly step: number;
56
+ }
57
+ export declare function niceScale(dataMin: number, dataMax: number, maxTicks?: number): Scale;
58
+ export declare function formatTick(v: number, step: number): string;
59
+ export declare function buildBarScene(chart: Chart, wPt: number, hPt: number, measure: MeasureText): ChartScene;
60
+ export declare function buildAreaScene(chart: Chart, wPt: number, hPt: number, measure: MeasureText): ChartScene;
61
+ export declare function buildScatterScene(chart: Chart, wPt: number, hPt: number, measure: MeasureText): ChartScene;
62
+ export declare function buildLineScene(chart: Chart, wPt: number, hPt: number, measure: MeasureText): ChartScene;
63
+ export declare function buildPieScene(chart: Chart, wPt: number, hPt: number, measure: MeasureText): ChartScene;
64
+ export declare function buildChartScene(chart: Chart, wPt: number, hPt: number, measure: MeasureText): ChartScene | null;