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,82 @@
1
+ import { FontRegistry } from "../../font/font-registry.js";
2
+ //#region src/ooxml/wordproc/font-table.ts
3
+ var FONT_TABLE_PART = "word/fontTable.xml";
4
+ var REL_FONT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font";
5
+ var VARIANT_BY_TAG = {
6
+ Regular: "regular",
7
+ Bold: "bold",
8
+ Italic: "italic",
9
+ BoldItalic: "boldItalic"
10
+ };
11
+ function deobfuscateEmbeddedFont(data, fontKey) {
12
+ const hex = fontKey.replace(/[{}-]/g, "");
13
+ if (hex.length !== 32) return data;
14
+ const key = new Uint8Array(16);
15
+ for (let i = 0; i < 16; i++) key[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
16
+ key.reverse();
17
+ const out = new Uint8Array(data);
18
+ const n = Math.min(32, out.length);
19
+ for (let i = 0; i < n; i++) out[i] = out[i] ^ key[i % 16];
20
+ return out;
21
+ }
22
+ function parseFontTable(data) {
23
+ const xml = new TextDecoder("utf-8").decode(data);
24
+ const out = [];
25
+ const fontRe = /<w:font\b[^>]*\bw:name="([^"]+)"[^>]*>([\s\S]*?)<\/w:font>/g;
26
+ let fm;
27
+ while ((fm = fontRe.exec(xml)) !== null) {
28
+ const name = fm[1];
29
+ const inner = fm[2];
30
+ const embeds = {};
31
+ const embedRe = /<w:embed(Regular|Bold|Italic|BoldItalic)\b[^>]*\br:id="([^"]+)"[^>]*\bw:fontKey="([^"]+)"/g;
32
+ let em;
33
+ while ((em = embedRe.exec(inner)) !== null) {
34
+ const variant = VARIANT_BY_TAG[em[1]];
35
+ if (variant) embeds[variant] = {
36
+ rId: em[2],
37
+ fontKey: em[3]
38
+ };
39
+ }
40
+ if (Object.keys(embeds).length > 0) out.push({
41
+ name,
42
+ embeds
43
+ });
44
+ }
45
+ return out;
46
+ }
47
+ function loadEmbeddedFonts(pkg) {
48
+ const out = /* @__PURE__ */ new Map();
49
+ const ftData = pkg.getPart(FONT_TABLE_PART);
50
+ if (!ftData) return out;
51
+ const relById = new Map(pkg.getPartRelationships(FONT_TABLE_PART).map((r) => [r.id, r]));
52
+ for (const entry of parseFontTable(ftData)) {
53
+ const bytes = {};
54
+ for (const variant of [
55
+ "regular",
56
+ "bold",
57
+ "italic",
58
+ "boldItalic"
59
+ ]) {
60
+ const ref = entry.embeds[variant];
61
+ if (!ref) continue;
62
+ const rel = relById.get(ref.rId);
63
+ if (!rel || rel.type !== REL_FONT) continue;
64
+ const resolved = pkg.resolveRelatedPart(FONT_TABLE_PART, rel);
65
+ if (!resolved) continue;
66
+ try {
67
+ const ttf = deobfuscateEmbeddedFont(resolved.data, ref.fontKey);
68
+ const sig = (ttf[0] << 24 | ttf[1] << 16 | ttf[2] << 8 | ttf[3]) >>> 0;
69
+ if (sig === 65536 || sig === 1330926671 || sig === 1953658213 || sig === 1953784678) bytes[variant] = ttf;
70
+ } catch {}
71
+ }
72
+ if (bytes.regular) try {
73
+ out.set(entry.name.trim().toLowerCase(), FontRegistry.fromBytes({
74
+ ...bytes,
75
+ regular: bytes.regular
76
+ }));
77
+ } catch {}
78
+ }
79
+ return out;
80
+ }
81
+ //#endregion
82
+ export { deobfuscateEmbeddedFont, loadEmbeddedFonts, parseFontTable };
@@ -0,0 +1,10 @@
1
+ export { extractParagraphs } from './text-extractor.js';
2
+ export { parseDocument, parseBodyElements, parseSection, parseSections, parseHeaderFooter, EMPTY_SECTION, } from './document-parser.js';
3
+ export { parseRunProperties } from './run-properties.js';
4
+ export { parseParagraphProperties } from './paragraph-properties.js';
5
+ export { parseStyles, EMPTY_STYLE_SHEET } from './styles-parser.js';
6
+ export { parseTable } from './table-parser.js';
7
+ export { loadEmbeddedFonts, deobfuscateEmbeddedFont, parseFontTable, } from './font-table.js';
8
+ export { parseNumbering, EMPTY_NUMBERING } from './numbering-parser.js';
9
+ export { parseSettings, EMPTY_SETTINGS } from './settings-parser.js';
10
+ export type { DocumentSettings } from './settings-parser.js';
@@ -0,0 +1,9 @@
1
+ import "./run-properties.js";
2
+ import "./paragraph-properties.js";
3
+ import "./table-parser.js";
4
+ import "./document-parser.js";
5
+ import "./text-extractor.js";
6
+ import "./styles-parser.js";
7
+ import "./font-table.js";
8
+ import "./numbering-parser.js";
9
+ import "./settings-parser.js";
@@ -0,0 +1,3 @@
1
+ import { Numbering } from '../../document-model/index.js';
2
+ export declare const EMPTY_NUMBERING: Numbering;
3
+ export declare function parseNumbering(data: Uint8Array): Numbering;
@@ -0,0 +1,89 @@
1
+ import { asArray, asElement, getAttr } from "./xml-helpers.js";
2
+ import { parseRunProperties } from "./run-properties.js";
3
+ import { parseParagraphProperties } from "./paragraph-properties.js";
4
+ import { XMLParser } from "fast-xml-parser";
5
+ //#region src/ooxml/wordproc/numbering-parser.ts
6
+ var decoder = new TextDecoder("utf-8");
7
+ var parser = new XMLParser({
8
+ ignoreAttributes: false,
9
+ attributeNamePrefix: "@_",
10
+ textNodeName: "#text",
11
+ parseAttributeValue: false,
12
+ parseTagValue: false,
13
+ trimValues: false
14
+ });
15
+ var FORMATS = new Set([
16
+ "decimal",
17
+ "lowerLetter",
18
+ "upperLetter",
19
+ "lowerRoman",
20
+ "upperRoman",
21
+ "bullet",
22
+ "none"
23
+ ]);
24
+ var EMPTY_NUMBERING = {
25
+ abstractNums: /* @__PURE__ */ new Map(),
26
+ numInstances: /* @__PURE__ */ new Map()
27
+ };
28
+ function parseNumbering(data) {
29
+ const xml = decoder.decode(data);
30
+ const root = asElement(parser.parse(xml)["w:numbering"]);
31
+ if (!root) return EMPTY_NUMBERING;
32
+ const abstractNums = /* @__PURE__ */ new Map();
33
+ for (const a of asArray(root["w:abstractNum"])) {
34
+ const el = asElement(a);
35
+ if (!el) continue;
36
+ const id = getAttr(el, "abstractNumId");
37
+ if (!id) continue;
38
+ const levels = /* @__PURE__ */ new Map();
39
+ for (const lvlNode of asArray(el["w:lvl"])) {
40
+ const lvlEl = asElement(lvlNode);
41
+ if (!lvlEl) continue;
42
+ const ilvlStr = getAttr(lvlEl, "ilvl");
43
+ if (!ilvlStr) continue;
44
+ const ilvl = Number(ilvlStr);
45
+ if (!Number.isFinite(ilvl)) continue;
46
+ const startAttr = getValVal(lvlEl["w:start"]);
47
+ const start = startAttr !== void 0 ? Number(startAttr) : 1;
48
+ const fmtStr = getValVal(lvlEl["w:numFmt"]) ?? "decimal";
49
+ const format = FORMATS.has(fmtStr) ? fmtStr : "decimal";
50
+ const lvlText = getValVal(lvlEl["w:lvlText"]) ?? "";
51
+ levels.set(ilvl, {
52
+ ilvl,
53
+ start: Number.isFinite(start) ? start : 1,
54
+ format,
55
+ lvlText,
56
+ paragraphProperties: parseParagraphProperties(lvlEl["w:pPr"]),
57
+ runProperties: parseRunProperties(lvlEl["w:rPr"])
58
+ });
59
+ }
60
+ abstractNums.set(id, {
61
+ id,
62
+ levels
63
+ });
64
+ }
65
+ const numInstances = /* @__PURE__ */ new Map();
66
+ for (const n of asArray(root["w:num"])) {
67
+ const el = asElement(n);
68
+ if (!el) continue;
69
+ const numId = getAttr(el, "numId");
70
+ if (!numId) continue;
71
+ const abstractNumId = getValVal(el["w:abstractNumId"]);
72
+ if (!abstractNumId) continue;
73
+ numInstances.set(numId, {
74
+ numId,
75
+ abstractNumId
76
+ });
77
+ }
78
+ return {
79
+ abstractNums,
80
+ numInstances
81
+ };
82
+ }
83
+ function getValVal(node) {
84
+ if (!node || typeof node !== "object") return void 0;
85
+ const v = node["@_w:val"] ?? node["@_val"];
86
+ return typeof v === "string" ? v : void 0;
87
+ }
88
+ //#endregion
89
+ export { EMPTY_NUMBERING, parseNumbering };
@@ -0,0 +1,2 @@
1
+ import { ParagraphProperties } from '../../document-model/index.js';
2
+ export declare function parseParagraphProperties(pPr: unknown): ParagraphProperties;
@@ -0,0 +1,85 @@
1
+ import { asElement, getAttr, getVal, parseIntAttr, parseToggle } from "./xml-helpers.js";
2
+ import { parseRunProperties } from "./run-properties.js";
3
+ //#region src/ooxml/wordproc/paragraph-properties.ts
4
+ var ALIGNMENTS = new Set([
5
+ "left",
6
+ "right",
7
+ "center",
8
+ "both",
9
+ "distribute"
10
+ ]);
11
+ var LINE_RULES = new Set([
12
+ "auto",
13
+ "exact",
14
+ "atLeast"
15
+ ]);
16
+ function parseParagraphProperties(pPr) {
17
+ const el = asElement(pPr);
18
+ if (!el) return {};
19
+ const out = {};
20
+ if ("w:pStyle" in el) {
21
+ const v = getVal(el["w:pStyle"]);
22
+ if (v) out.styleId = v;
23
+ }
24
+ if ("w:jc" in el) {
25
+ const v = getVal(el["w:jc"]);
26
+ if (v && ALIGNMENTS.has(v)) out.alignment = v;
27
+ }
28
+ if ("w:spacing" in el) {
29
+ const node = el["w:spacing"];
30
+ const before = parseIntAttr(node, "before");
31
+ const after = parseIntAttr(node, "after");
32
+ const line = parseIntAttr(node, "line");
33
+ const lineRule = getAttr(node, "lineRule");
34
+ if (before !== void 0) out.spacingBeforeTwips = before;
35
+ if (after !== void 0) out.spacingAfterTwips = after;
36
+ if (line !== void 0) out.spacingLineTwips = line;
37
+ if (lineRule && LINE_RULES.has(lineRule)) out.spacingLineRule = lineRule;
38
+ }
39
+ if ("w:ind" in el) {
40
+ const node = el["w:ind"];
41
+ const left = parseIntAttr(node, "left");
42
+ const right = parseIntAttr(node, "right");
43
+ const firstLine = parseIntAttr(node, "firstLine");
44
+ const hanging = parseIntAttr(node, "hanging");
45
+ if (left !== void 0) out.indentLeftTwips = left;
46
+ if (right !== void 0) out.indentRightTwips = right;
47
+ if (firstLine !== void 0) out.indentFirstLineTwips = firstLine;
48
+ else if (hanging !== void 0) out.indentFirstLineTwips = -hanging;
49
+ }
50
+ if ("w:pageBreakBefore" in el) {
51
+ const v = parseToggle(el["w:pageBreakBefore"]);
52
+ if (v !== void 0) out.pageBreakBefore = v;
53
+ }
54
+ if ("w:bidi" in el) {
55
+ const v = parseToggle(el["w:bidi"]);
56
+ if (v !== void 0) out.bidi = v;
57
+ }
58
+ if ("w:outlineLvl" in el) {
59
+ const v = parseIntAttr(el["w:outlineLvl"], "val");
60
+ if (v !== void 0) out.outlineLevel = v;
61
+ }
62
+ if ("w:numPr" in el) {
63
+ const numPr = asElement(el["w:numPr"]);
64
+ if (numPr) {
65
+ const numIdVal = numPr["w:numId"];
66
+ const ilvlVal = numPr["w:ilvl"];
67
+ const numIdAttr = typeof numIdVal === "object" && numIdVal !== null ? getAttr(numIdVal, "val") : void 0;
68
+ const ilvlAttr = typeof ilvlVal === "object" && ilvlVal !== null ? getAttr(ilvlVal, "val") : void 0;
69
+ if (numIdAttr !== void 0) {
70
+ const ilvlNum = ilvlAttr !== void 0 ? Number(ilvlAttr) : 0;
71
+ out.numbering = {
72
+ numId: numIdAttr,
73
+ ilvl: Number.isFinite(ilvlNum) ? ilvlNum : 0
74
+ };
75
+ }
76
+ }
77
+ }
78
+ if ("w:rPr" in el) {
79
+ const rPr = parseRunProperties(el["w:rPr"]);
80
+ if (Object.keys(rPr).length > 0) out.runProperties = rPr;
81
+ }
82
+ return out;
83
+ }
84
+ //#endregion
85
+ export { parseParagraphProperties };
@@ -0,0 +1,14 @@
1
+ export type PoNode = Record<string, unknown>;
2
+ export type PoTree = ReadonlyArray<PoNode>;
3
+ export declare function poTag(node: PoNode | undefined): string | undefined;
4
+ export declare function poIs(node: PoNode | undefined, tag: string): boolean;
5
+ export declare function poChildren(node: PoNode | undefined): ReadonlyArray<PoNode>;
6
+ export declare function poChildrenWith(node: PoNode | undefined, tag: string): Array<PoNode>;
7
+ export declare function poFirstChild(node: PoNode | undefined, tag: string): PoNode | undefined;
8
+ export declare function poAttr(node: PoNode | undefined, name: string): string | undefined;
9
+ export declare function poIntAttr(node: PoNode | undefined, name: string): number | undefined;
10
+ export declare function poVal(node: PoNode | undefined): string | undefined;
11
+ export declare function poToggle(node: PoNode | undefined): boolean | undefined;
12
+ export declare function poText(node: PoNode | undefined): string;
13
+ export declare function poFindByPath(tree: PoTree, path: ReadonlyArray<string>): PoNode | undefined;
14
+ export declare function poFindDescendant(node: PoNode | undefined, tag: string): PoNode | undefined;
@@ -0,0 +1,76 @@
1
+ //#region src/ooxml/wordproc/po-helpers.ts
2
+ var ATTRS_KEY = ":@";
3
+ var TEXT_KEY = "#text";
4
+ function poTag(node) {
5
+ if (!node || typeof node !== "object") return void 0;
6
+ for (const key of Object.keys(node)) if (key !== ATTRS_KEY && key !== TEXT_KEY) return key;
7
+ }
8
+ function poIs(node, tag) {
9
+ return poTag(node) === tag;
10
+ }
11
+ function poChildren(node) {
12
+ const tag = poTag(node);
13
+ if (!tag || !node) return [];
14
+ const arr = node[tag];
15
+ return Array.isArray(arr) ? arr : [];
16
+ }
17
+ function poChildrenWith(node, tag) {
18
+ return poChildren(node).filter((c) => poIs(c, tag));
19
+ }
20
+ function poFirstChild(node, tag) {
21
+ return poChildren(node).find((c) => poIs(c, tag));
22
+ }
23
+ function poAttr(node, name) {
24
+ if (!node || typeof node !== "object") return void 0;
25
+ const attrs = node[ATTRS_KEY];
26
+ if (!attrs || typeof attrs !== "object") return void 0;
27
+ const a = attrs;
28
+ const v = a[`@_w:${name}`] ?? a[`@_r:${name}`] ?? a[`@_m:${name}`] ?? a[`@_xml:${name}`] ?? a[`@_${name}`];
29
+ return typeof v === "string" ? v : void 0;
30
+ }
31
+ function poIntAttr(node, name) {
32
+ const v = poAttr(node, name);
33
+ if (v === void 0) return void 0;
34
+ const n = Number(v);
35
+ return Number.isFinite(n) ? n : void 0;
36
+ }
37
+ function poVal(node) {
38
+ return poAttr(node, "val");
39
+ }
40
+ function poToggle(node) {
41
+ if (!node) return void 0;
42
+ const v = poAttr(node, "val");
43
+ if (v === void 0) return true;
44
+ return !(v === "false" || v === "0" || v === "off");
45
+ }
46
+ function poText(node) {
47
+ if (!node) return "";
48
+ const children = poChildren(node);
49
+ let out = "";
50
+ for (const c of children) if (c && typeof c === "object" && TEXT_KEY in c) {
51
+ const t = c[TEXT_KEY];
52
+ if (typeof t === "string") out += t;
53
+ else if (typeof t === "number") out += String(t);
54
+ }
55
+ return out;
56
+ }
57
+ function poFindByPath(tree, path) {
58
+ let cursor = tree;
59
+ let current;
60
+ for (const seg of path) {
61
+ current = cursor.find((n) => poIs(n, seg));
62
+ if (!current) return void 0;
63
+ cursor = poChildren(current);
64
+ }
65
+ return current;
66
+ }
67
+ function poFindDescendant(node, tag) {
68
+ if (!node) return void 0;
69
+ for (const child of poChildren(node)) {
70
+ if (poIs(child, tag)) return child;
71
+ const found = poFindDescendant(child, tag);
72
+ if (found) return found;
73
+ }
74
+ }
75
+ //#endregion
76
+ export { poAttr, poChildren, poChildrenWith, poFindByPath, poFindDescendant, poFirstChild, poIntAttr, poIs, poTag, poText, poToggle, poVal };
@@ -0,0 +1,2 @@
1
+ import { PoNode } from './po-helpers.js';
2
+ export declare function poElementToFlat(node: PoNode | undefined): Record<string, unknown>;
@@ -0,0 +1,28 @@
1
+ import { poChildren, poTag } from "./po-helpers.js";
2
+ //#region src/ooxml/wordproc/po-to-flat.ts
3
+ var ATTRS_KEY = ":@";
4
+ var TEXT_KEY = "#text";
5
+ function poElementToFlat(node) {
6
+ const out = {};
7
+ if (!node) return out;
8
+ const attrs = node[ATTRS_KEY];
9
+ if (attrs && typeof attrs === "object") for (const [k, v] of Object.entries(attrs)) out[k] = v;
10
+ for (const child of poChildren(node)) {
11
+ if (TEXT_KEY in child) {
12
+ const t = child[TEXT_KEY];
13
+ const str = typeof t === "string" ? t : typeof t === "number" ? String(t) : "";
14
+ out[TEXT_KEY] = out[TEXT_KEY] === void 0 ? str : `${out[TEXT_KEY]}${str}`;
15
+ continue;
16
+ }
17
+ const childTag = poTag(child);
18
+ if (!childTag) continue;
19
+ const childFlat = poElementToFlat(child);
20
+ const existing = out[childTag];
21
+ if (existing === void 0) out[childTag] = childFlat;
22
+ else if (Array.isArray(existing)) existing.push(childFlat);
23
+ else out[childTag] = [existing, childFlat];
24
+ }
25
+ return out;
26
+ }
27
+ //#endregion
28
+ export { poElementToFlat };
@@ -0,0 +1,2 @@
1
+ import { RunProperties } from '../../document-model/index.js';
2
+ export declare function parseRunProperties(rPr: unknown): RunProperties;
@@ -0,0 +1,82 @@
1
+ import { asElement, getAttr, getVal, parseIntAttr, parseToggle } from "./xml-helpers.js";
2
+ //#region src/ooxml/wordproc/run-properties.ts
3
+ var UNDERLINE_STYLES = new Set([
4
+ "none",
5
+ "single",
6
+ "double",
7
+ "thick",
8
+ "dotted",
9
+ "dottedHeavy",
10
+ "dash",
11
+ "dashHeavy",
12
+ "wave"
13
+ ]);
14
+ var VERTICAL_ALIGNS = new Set([
15
+ "baseline",
16
+ "superscript",
17
+ "subscript"
18
+ ]);
19
+ function parseRunProperties(rPr) {
20
+ const el = asElement(rPr);
21
+ if (!el) return {};
22
+ const out = {};
23
+ if ("w:rStyle" in el) {
24
+ const v = getVal(el["w:rStyle"]);
25
+ if (v) out.styleId = v;
26
+ }
27
+ if ("w:b" in el) {
28
+ const v = parseToggle(el["w:b"]);
29
+ if (v !== void 0) out.bold = v;
30
+ }
31
+ if ("w:i" in el) {
32
+ const v = parseToggle(el["w:i"]);
33
+ if (v !== void 0) out.italic = v;
34
+ }
35
+ if ("w:strike" in el) {
36
+ const v = parseToggle(el["w:strike"]);
37
+ if (v !== void 0) out.strike = v;
38
+ }
39
+ if ("w:u" in el) {
40
+ const v = getVal(el["w:u"]);
41
+ if (v && UNDERLINE_STYLES.has(v)) out.underline = v;
42
+ }
43
+ if ("w:sz" in el) {
44
+ const v = parseIntAttr(el["w:sz"], "val");
45
+ if (v !== void 0) out.fontSizeHalfPoints = v;
46
+ }
47
+ if ("w:color" in el) {
48
+ const v = getVal(el["w:color"]);
49
+ if (v && /^[0-9A-Fa-f]{6}$/.test(v)) out.colorHex = v.toUpperCase();
50
+ }
51
+ if ("w:rFonts" in el) {
52
+ const ff = parseFontFamily(el["w:rFonts"]);
53
+ if (ff) out.fontFamily = ff;
54
+ }
55
+ if ("w:vertAlign" in el) {
56
+ const v = getVal(el["w:vertAlign"]);
57
+ if (v && VERTICAL_ALIGNS.has(v)) out.verticalAlign = v;
58
+ }
59
+ if ("w:rtl" in el) {
60
+ const v = parseToggle(el["w:rtl"]);
61
+ if (v !== void 0) out.rtl = v;
62
+ }
63
+ if ("w:lang" in el) {
64
+ const v = getAttr(el["w:lang"], "val");
65
+ if (v) out.lang = v;
66
+ }
67
+ return out;
68
+ }
69
+ function parseFontFamily(node) {
70
+ const ff = {};
71
+ const ascii = getAttr(node, "ascii");
72
+ const hAnsi = getAttr(node, "hAnsi");
73
+ const cs = getAttr(node, "cs");
74
+ const eastAsia = getAttr(node, "eastAsia");
75
+ if (ascii) ff.ascii = ascii;
76
+ if (hAnsi) ff.hAnsi = hAnsi;
77
+ if (cs) ff.cs = cs;
78
+ if (eastAsia) ff.eastAsia = eastAsia;
79
+ return Object.keys(ff).length > 0 ? ff : void 0;
80
+ }
81
+ //#endregion
82
+ export { parseRunProperties };
@@ -0,0 +1,5 @@
1
+ export interface DocumentSettings {
2
+ readonly evenAndOddHeaders: boolean;
3
+ }
4
+ export declare const EMPTY_SETTINGS: DocumentSettings;
5
+ export declare function parseSettings(data: Uint8Array): DocumentSettings;
@@ -0,0 +1,26 @@
1
+ import { poAttr, poChildren, poFindByPath, poIs } from "./po-helpers.js";
2
+ import { XMLParser } from "fast-xml-parser";
3
+ //#region src/ooxml/wordproc/settings-parser.ts
4
+ var decoder = new TextDecoder("utf-8");
5
+ var parser = new XMLParser({
6
+ ignoreAttributes: false,
7
+ attributeNamePrefix: "@_",
8
+ preserveOrder: true,
9
+ parseAttributeValue: false,
10
+ parseTagValue: false,
11
+ trimValues: false
12
+ });
13
+ var EMPTY_SETTINGS = { evenAndOddHeaders: false };
14
+ function parseSettings(data) {
15
+ const xml = decoder.decode(data);
16
+ const settings = poFindByPath(parser.parse(xml), ["w:settings"]);
17
+ if (!settings) return EMPTY_SETTINGS;
18
+ let evenAndOddHeaders = false;
19
+ for (const child of poChildren(settings)) if (poIs(child, "w:evenAndOddHeaders")) {
20
+ const val = poAttr(child, "val");
21
+ evenAndOddHeaders = val === void 0 || val === "" || val !== "0" && val !== "false";
22
+ }
23
+ return { evenAndOddHeaders };
24
+ }
25
+ //#endregion
26
+ export { EMPTY_SETTINGS, parseSettings };
@@ -0,0 +1,3 @@
1
+ import { StyleSheet } from '../../document-model/index.js';
2
+ export declare const EMPTY_STYLE_SHEET: StyleSheet;
3
+ export declare function parseStyles(stylesXml: Uint8Array): StyleSheet;
@@ -0,0 +1,67 @@
1
+ import { asArray, asElement, getAttr, getVal } from "./xml-helpers.js";
2
+ import { parseRunProperties } from "./run-properties.js";
3
+ import { parseParagraphProperties } from "./paragraph-properties.js";
4
+ import { XMLParser } from "fast-xml-parser";
5
+ //#region src/ooxml/wordproc/styles-parser.ts
6
+ var decoder = new TextDecoder("utf-8");
7
+ var parser = new XMLParser({
8
+ ignoreAttributes: false,
9
+ attributeNamePrefix: "@_",
10
+ textNodeName: "#text",
11
+ parseAttributeValue: false,
12
+ parseTagValue: false,
13
+ trimValues: false
14
+ });
15
+ var STYLE_TYPES = new Set([
16
+ "paragraph",
17
+ "character",
18
+ "table",
19
+ "numbering"
20
+ ]);
21
+ var EMPTY_STYLE_SHEET = {
22
+ defaultRunProperties: {},
23
+ defaultParagraphProperties: {},
24
+ styles: /* @__PURE__ */ new Map()
25
+ };
26
+ function parseStyles(stylesXml) {
27
+ const xml = decoder.decode(stylesXml);
28
+ const root = asElement(parser.parse(xml)["w:styles"]);
29
+ if (!root) return EMPTY_STYLE_SHEET;
30
+ const docDefaults = asElement(root["w:docDefaults"]);
31
+ let defaultRunProperties = {};
32
+ let defaultParagraphProperties = {};
33
+ if (docDefaults) {
34
+ const rPrDef = asElement(docDefaults["w:rPrDefault"]);
35
+ if (rPrDef) defaultRunProperties = parseRunProperties(rPrDef["w:rPr"]);
36
+ const pPrDef = asElement(docDefaults["w:pPrDefault"]);
37
+ if (pPrDef) defaultParagraphProperties = parseParagraphProperties(pPrDef["w:pPr"]);
38
+ }
39
+ const styles = /* @__PURE__ */ new Map();
40
+ for (const s of asArray(root["w:style"])) {
41
+ const el = asElement(s);
42
+ if (!el) continue;
43
+ const id = getAttr(el, "styleId");
44
+ const typeAttr = getAttr(el, "type");
45
+ if (!id || !typeAttr) continue;
46
+ if (!STYLE_TYPES.has(typeAttr)) continue;
47
+ const type = typeAttr;
48
+ const basedOnVal = getVal(el["w:basedOn"]);
49
+ const isDefault = getAttr(el, "default") === "1";
50
+ const style = {
51
+ id,
52
+ type,
53
+ ...basedOnVal ? { basedOn: basedOnVal } : {},
54
+ isDefault,
55
+ runProperties: parseRunProperties(el["w:rPr"]),
56
+ paragraphProperties: parseParagraphProperties(el["w:pPr"])
57
+ };
58
+ styles.set(id, style);
59
+ }
60
+ return {
61
+ defaultRunProperties,
62
+ defaultParagraphProperties,
63
+ styles
64
+ };
65
+ }
66
+ //#endregion
67
+ export { EMPTY_STYLE_SHEET, parseStyles };
@@ -0,0 +1,3 @@
1
+ import { Table } from '../../document-model/index.js';
2
+ import { PoNode } from './po-helpers.js';
3
+ export declare function parseTable(tbl: PoNode): Table;