ooxml.js 2.4.1 → 2.5.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 (138) hide show
  1. package/README.md +11 -2
  2. package/dist/codec.cjs +28 -0
  3. package/dist/codec.d.cts +72 -0
  4. package/dist/codec.d.ts +72 -0
  5. package/dist/codec.js +24 -0
  6. package/dist/compact.cjs +162 -0
  7. package/dist/compact.d.cts +70 -0
  8. package/dist/compact.d.ts +70 -0
  9. package/dist/compact.js +152 -0
  10. package/dist/image/sniff.cjs +28 -0
  11. package/dist/image/sniff.d.cts +5 -0
  12. package/dist/image/sniff.d.ts +5 -0
  13. package/dist/image/sniff.js +27 -0
  14. package/dist/index.cjs +83 -3025
  15. package/dist/index.d.cts +22 -527
  16. package/dist/index.d.ts +22 -527
  17. package/dist/index.js +22 -2964
  18. package/dist/model/node.cjs +67 -0
  19. package/dist/model/node.d.cts +2 -0
  20. package/dist/model/node.d.ts +2 -0
  21. package/dist/model/node.js +58 -0
  22. package/dist/model/package.cjs +19 -0
  23. package/dist/model/package.d.cts +2 -0
  24. package/dist/model/package.d.ts +2 -0
  25. package/dist/model/package.js +15 -0
  26. package/dist/node-CkBWRjNR.d.cts +83 -0
  27. package/dist/node-CkBWRjNR.d.ts +83 -0
  28. package/dist/package-BUojjTXf.d.ts +114 -0
  29. package/dist/package-L24lkba-.d.cts +114 -0
  30. package/dist/package-io/read.cjs +33 -0
  31. package/dist/package-io/read.d.cts +5 -0
  32. package/dist/package-io/read.d.ts +5 -0
  33. package/dist/package-io/read.js +32 -0
  34. package/dist/package-io/write.cjs +18 -0
  35. package/dist/package-io/write.d.cts +5 -0
  36. package/dist/package-io/write.d.ts +5 -0
  37. package/dist/package-io/write.js +17 -0
  38. package/dist/typed/docx/read.cjs +332 -0
  39. package/dist/typed/docx/read.d.cts +52 -0
  40. package/dist/typed/docx/read.d.ts +52 -0
  41. package/dist/typed/docx/read.js +328 -0
  42. package/dist/typed/docx/styles.cjs +148 -0
  43. package/dist/typed/docx/styles.d.cts +29 -0
  44. package/dist/typed/docx/styles.d.ts +29 -0
  45. package/dist/typed/docx/styles.js +146 -0
  46. package/dist/typed/pptx/inherit.cjs +96 -0
  47. package/dist/typed/pptx/inherit.d.cts +30 -0
  48. package/dist/typed/pptx/inherit.d.ts +30 -0
  49. package/dist/typed/pptx/inherit.js +90 -0
  50. package/dist/typed/pptx/read.cjs +364 -0
  51. package/dist/typed/pptx/read.d.cts +44 -0
  52. package/dist/typed/pptx/read.d.ts +44 -0
  53. package/dist/typed/pptx/read.js +362 -0
  54. package/dist/typed/shared/color.cjs +85 -0
  55. package/dist/typed/shared/color.d.cts +9 -0
  56. package/dist/typed/shared/color.d.ts +9 -0
  57. package/dist/typed/shared/color.js +84 -0
  58. package/dist/typed/shared/drawingml.cjs +191 -0
  59. package/dist/typed/shared/drawingml.d.cts +40 -0
  60. package/dist/typed/shared/drawingml.d.ts +40 -0
  61. package/dist/typed/shared/drawingml.js +180 -0
  62. package/dist/typed/shared/metadata.cjs +44 -0
  63. package/dist/typed/shared/metadata.d.cts +16 -0
  64. package/dist/typed/shared/metadata.d.ts +16 -0
  65. package/dist/typed/shared/metadata.js +42 -0
  66. package/dist/typed/shared/source-path.cjs +18 -0
  67. package/dist/typed/shared/source-path.d.cts +5 -0
  68. package/dist/typed/shared/source-path.d.ts +5 -0
  69. package/dist/typed/shared/source-path.js +17 -0
  70. package/dist/typed/shared/units.cjs +55 -0
  71. package/dist/typed/shared/units.d.cts +20 -0
  72. package/dist/typed/shared/units.d.ts +20 -0
  73. package/dist/typed/shared/units.js +38 -0
  74. package/dist/typed/util.cjs +85 -0
  75. package/dist/typed/util.d.cts +18 -0
  76. package/dist/typed/util.d.ts +18 -0
  77. package/dist/typed/util.js +77 -0
  78. package/dist/typed/xlsx/a1.cjs +64 -0
  79. package/dist/typed/xlsx/a1.d.cts +19 -0
  80. package/dist/typed/xlsx/a1.d.ts +19 -0
  81. package/dist/typed/xlsx/a1.js +58 -0
  82. package/dist/typed/xlsx/build.cjs +456 -0
  83. package/dist/typed/xlsx/build.d.cts +6 -0
  84. package/dist/typed/xlsx/build.d.ts +6 -0
  85. package/dist/typed/xlsx/build.js +455 -0
  86. package/dist/typed/xlsx/content.cjs +257 -0
  87. package/dist/typed/xlsx/content.d.cts +6 -0
  88. package/dist/typed/xlsx/content.d.ts +6 -0
  89. package/dist/typed/xlsx/content.js +256 -0
  90. package/dist/typed/xlsx/defined-names.cjs +90 -0
  91. package/dist/typed/xlsx/defined-names.d.cts +20 -0
  92. package/dist/typed/xlsx/defined-names.d.ts +20 -0
  93. package/dist/typed/xlsx/defined-names.js +83 -0
  94. package/dist/typed/xlsx/print-settings.cjs +116 -0
  95. package/dist/typed/xlsx/print-settings.d.cts +8 -0
  96. package/dist/typed/xlsx/print-settings.d.ts +8 -0
  97. package/dist/typed/xlsx/print-settings.js +114 -0
  98. package/dist/typed/xlsx/shared-strings.cjs +35 -0
  99. package/dist/typed/xlsx/shared-strings.d.cts +12 -0
  100. package/dist/typed/xlsx/shared-strings.d.ts +12 -0
  101. package/dist/typed/xlsx/shared-strings.js +33 -0
  102. package/dist/typed/xlsx/units.cjs +21 -0
  103. package/dist/typed/xlsx/units.d.cts +8 -0
  104. package/dist/typed/xlsx/units.d.ts +8 -0
  105. package/dist/typed/xlsx/units.js +16 -0
  106. package/dist/typed/xlsx/util.cjs +53 -0
  107. package/dist/typed/xlsx/util.d.cts +10 -0
  108. package/dist/typed/xlsx/util.d.ts +10 -0
  109. package/dist/typed/xlsx/util.js +47 -0
  110. package/dist/typed/xlsx.cjs +140 -0
  111. package/dist/typed/xlsx.d.cts +43 -0
  112. package/dist/typed/xlsx.d.ts +43 -0
  113. package/dist/typed/xlsx.js +135 -0
  114. package/dist/util/base64.cjs +48 -0
  115. package/dist/util/base64.d.cts +5 -0
  116. package/dist/util/base64.d.ts +5 -0
  117. package/dist/util/base64.js +46 -0
  118. package/dist/xml/build.cjs +46 -0
  119. package/dist/xml/build.d.cts +5 -0
  120. package/dist/xml/build.d.ts +5 -0
  121. package/dist/xml/build.js +46 -0
  122. package/dist/xml/entities.cjs +7 -0
  123. package/dist/xml/entities.d.cts +4 -0
  124. package/dist/xml/entities.d.ts +4 -0
  125. package/dist/xml/entities.js +6 -0
  126. package/dist/xml/fragment.cjs +22 -0
  127. package/dist/xml/fragment.d.cts +6 -0
  128. package/dist/xml/fragment.d.ts +6 -0
  129. package/dist/xml/fragment.js +20 -0
  130. package/dist/xml/parse.cjs +88 -0
  131. package/dist/xml/parse.d.cts +5 -0
  132. package/dist/xml/parse.d.ts +5 -0
  133. package/dist/xml/parse.js +88 -0
  134. package/dist/zip.cjs +12 -0
  135. package/dist/zip.d.cts +5 -0
  136. package/dist/zip.d.ts +5 -0
  137. package/dist/zip.js +10 -0
  138. package/package.json +9 -1
@@ -0,0 +1,20 @@
1
+ //#region src/typed/shared/units.d.ts
2
+ declare const POINTS_PER_INCH = 72;
3
+ declare const EMU_PER_INCH = 914400;
4
+ declare const TWIPS_PER_INCH = 1440;
5
+ declare const EMU_PER_POINT: number;
6
+ declare const TWIPS_PER_POINT: number;
7
+ declare const HALF_POINTS_PER_POINT = 2;
8
+ declare const DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT = 100;
9
+ declare const LINE_UNITS_PER_LINE = 240;
10
+ declare function emuToPt(emu: number): number;
11
+ declare function ptToEmu(pt: number): number;
12
+ declare function twipsToPt(twips: number): number;
13
+ declare function ptToTwips(pt: number): number;
14
+ declare function halfPointsToPt(halfPoints: number): number;
15
+ declare function ptToHalfPoints(pt: number): number;
16
+ declare function drawingMlFontSizeToPt(hundredths: number): number;
17
+ declare function ptToDrawingMlFontSize(pt: number): number;
18
+ declare function lineUnitsToMultiplier(lineUnits: number): number;
19
+ //#endregion
20
+ export { DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT, EMU_PER_INCH, EMU_PER_POINT, HALF_POINTS_PER_POINT, LINE_UNITS_PER_LINE, POINTS_PER_INCH, TWIPS_PER_INCH, TWIPS_PER_POINT, drawingMlFontSizeToPt, emuToPt, halfPointsToPt, lineUnitsToMultiplier, ptToDrawingMlFontSize, ptToEmu, ptToHalfPoints, ptToTwips, twipsToPt };
@@ -0,0 +1,20 @@
1
+ //#region src/typed/shared/units.d.ts
2
+ declare const POINTS_PER_INCH = 72;
3
+ declare const EMU_PER_INCH = 914400;
4
+ declare const TWIPS_PER_INCH = 1440;
5
+ declare const EMU_PER_POINT: number;
6
+ declare const TWIPS_PER_POINT: number;
7
+ declare const HALF_POINTS_PER_POINT = 2;
8
+ declare const DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT = 100;
9
+ declare const LINE_UNITS_PER_LINE = 240;
10
+ declare function emuToPt(emu: number): number;
11
+ declare function ptToEmu(pt: number): number;
12
+ declare function twipsToPt(twips: number): number;
13
+ declare function ptToTwips(pt: number): number;
14
+ declare function halfPointsToPt(halfPoints: number): number;
15
+ declare function ptToHalfPoints(pt: number): number;
16
+ declare function drawingMlFontSizeToPt(hundredths: number): number;
17
+ declare function ptToDrawingMlFontSize(pt: number): number;
18
+ declare function lineUnitsToMultiplier(lineUnits: number): number;
19
+ //#endregion
20
+ export { DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT, EMU_PER_INCH, EMU_PER_POINT, HALF_POINTS_PER_POINT, LINE_UNITS_PER_LINE, POINTS_PER_INCH, TWIPS_PER_INCH, TWIPS_PER_POINT, drawingMlFontSizeToPt, emuToPt, halfPointsToPt, lineUnitsToMultiplier, ptToDrawingMlFontSize, ptToEmu, ptToHalfPoints, ptToTwips, twipsToPt };
@@ -0,0 +1,38 @@
1
+ //#region src/typed/shared/units.ts
2
+ const POINTS_PER_INCH = 72;
3
+ const EMU_PER_INCH = 914400;
4
+ const TWIPS_PER_INCH = 1440;
5
+ const EMU_PER_POINT = EMU_PER_INCH / 72;
6
+ const TWIPS_PER_POINT = TWIPS_PER_INCH / 72;
7
+ const HALF_POINTS_PER_POINT = 2;
8
+ const DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT = 100;
9
+ const LINE_UNITS_PER_LINE = 240;
10
+ function emuToPt(emu) {
11
+ return emu / EMU_PER_POINT;
12
+ }
13
+ function ptToEmu(pt) {
14
+ return Math.round(pt * EMU_PER_POINT);
15
+ }
16
+ function twipsToPt(twips) {
17
+ return twips / 20;
18
+ }
19
+ function ptToTwips(pt) {
20
+ return Math.round(pt * 20);
21
+ }
22
+ function halfPointsToPt(halfPoints) {
23
+ return halfPoints / 2;
24
+ }
25
+ function ptToHalfPoints(pt) {
26
+ return Math.round(pt * 2);
27
+ }
28
+ function drawingMlFontSizeToPt(hundredths) {
29
+ return hundredths / 100;
30
+ }
31
+ function ptToDrawingMlFontSize(pt) {
32
+ return Math.round(pt * 100);
33
+ }
34
+ function lineUnitsToMultiplier(lineUnits) {
35
+ return lineUnits / 240;
36
+ }
37
+ //#endregion
38
+ export { DRAWINGML_FONT_SIZE_HUNDREDTHS_PER_POINT, EMU_PER_INCH, EMU_PER_POINT, HALF_POINTS_PER_POINT, LINE_UNITS_PER_LINE, POINTS_PER_INCH, TWIPS_PER_INCH, TWIPS_PER_POINT, drawingMlFontSizeToPt, emuToPt, halfPointsToPt, lineUnitsToMultiplier, ptToDrawingMlFontSize, ptToEmu, ptToHalfPoints, ptToTwips, twipsToPt };
@@ -0,0 +1,85 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/typed/util.ts
3
+ function* walk(nodes) {
4
+ for (const node of nodes) {
5
+ yield node;
6
+ if (node.type === "element") yield* walk(node.children);
7
+ }
8
+ }
9
+ function elementsWithTag(nodes, tag) {
10
+ const out = [];
11
+ for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
12
+ return out;
13
+ }
14
+ function childrenWithTag(element, tag) {
15
+ const out = [];
16
+ for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
17
+ return out;
18
+ }
19
+ function attr(element, name) {
20
+ for (const a of element.attributes) if (a.name === name) return a.value;
21
+ }
22
+ function rootElement(part) {
23
+ if (part?.kind !== "xml") return;
24
+ for (const node of part.nodes) if (node.type === "element") return node;
25
+ }
26
+ function decodeEntities(value) {
27
+ return value.replace(/&(?:amp|lt|gt|quot|apos);/g, (entity) => {
28
+ switch (entity) {
29
+ case "&": return "&";
30
+ case "&lt;": return "<";
31
+ case "&gt;": return ">";
32
+ case "&quot;": return "\"";
33
+ case "&apos;": return "'";
34
+ default: return entity;
35
+ }
36
+ });
37
+ }
38
+ function textContent(element) {
39
+ let text = "";
40
+ for (const node of walk(element.children)) if (node.type === "text" || node.type === "cdata") text += node.value;
41
+ return decodeEntities(text);
42
+ }
43
+ function relsPathFor(partPath) {
44
+ const lastSlash = partPath.lastIndexOf("/");
45
+ return `${lastSlash === -1 ? "" : partPath.slice(0, lastSlash)}/_rels/${lastSlash === -1 ? partPath : partPath.slice(lastSlash + 1)}.rels`;
46
+ }
47
+ function resolveRelTarget(partPath, target) {
48
+ if (target.startsWith("/")) return target.slice(1);
49
+ const lastSlash = partPath.lastIndexOf("/");
50
+ const baseDir = lastSlash === -1 ? "" : partPath.slice(0, lastSlash);
51
+ const resolved = [];
52
+ for (const segment of `${baseDir}/${target}`.split("/")) {
53
+ if (segment === "" || segment === ".") continue;
54
+ if (segment === "..") resolved.pop();
55
+ else resolved.push(segment);
56
+ }
57
+ return resolved.join("/");
58
+ }
59
+ function resolveRelationships(pkg, partPath) {
60
+ const map = /* @__PURE__ */ new Map();
61
+ const rels = rootElement(pkg.parts[relsPathFor(partPath)]);
62
+ if (rels === void 0) return map;
63
+ for (const rel of childrenWithTag(rels, "Relationship")) {
64
+ const id = attr(rel, "Id");
65
+ const type = attr(rel, "Type");
66
+ const target = attr(rel, "Target");
67
+ if (id === void 0 || type === void 0 || target === void 0) continue;
68
+ const targetMode = attr(rel, "TargetMode");
69
+ map.set(id, {
70
+ type,
71
+ target: targetMode === "External" ? target : resolveRelTarget(partPath, target),
72
+ targetMode
73
+ });
74
+ }
75
+ return map;
76
+ }
77
+ //#endregion
78
+ exports.attr = attr;
79
+ exports.childrenWithTag = childrenWithTag;
80
+ exports.decodeEntities = decodeEntities;
81
+ exports.elementsWithTag = elementsWithTag;
82
+ exports.resolveRelationships = resolveRelationships;
83
+ exports.rootElement = rootElement;
84
+ exports.textContent = textContent;
85
+ exports.walk = walk;
@@ -0,0 +1,18 @@
1
+ import { d as XmlNode, l as XmlElement } from "../node-CkBWRjNR.cjs";
2
+ import { a as Part, r as Package } from "../package-L24lkba-.cjs";
3
+ //#region src/typed/util.d.ts
4
+ declare function walk(nodes: XmlNode[]): Generator<XmlNode>;
5
+ declare function elementsWithTag(nodes: XmlNode[], tag: string): XmlElement[];
6
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
7
+ declare function attr(element: XmlElement, name: string): string | undefined;
8
+ declare function rootElement(part: Part | undefined): XmlElement | undefined;
9
+ declare function decodeEntities(value: string): string;
10
+ declare function textContent(element: XmlElement): string;
11
+ interface Relationship {
12
+ type: string;
13
+ target: string;
14
+ targetMode?: string;
15
+ }
16
+ declare function resolveRelationships(pkg: Package, partPath: string): Map<string, Relationship>;
17
+ //#endregion
18
+ export { Relationship, attr, childrenWithTag, decodeEntities, elementsWithTag, resolveRelationships, rootElement, textContent, walk };
@@ -0,0 +1,18 @@
1
+ import { d as XmlNode, l as XmlElement } from "../node-CkBWRjNR.js";
2
+ import { a as Part, r as Package } from "../package-BUojjTXf.js";
3
+ //#region src/typed/util.d.ts
4
+ declare function walk(nodes: XmlNode[]): Generator<XmlNode>;
5
+ declare function elementsWithTag(nodes: XmlNode[], tag: string): XmlElement[];
6
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
7
+ declare function attr(element: XmlElement, name: string): string | undefined;
8
+ declare function rootElement(part: Part | undefined): XmlElement | undefined;
9
+ declare function decodeEntities(value: string): string;
10
+ declare function textContent(element: XmlElement): string;
11
+ interface Relationship {
12
+ type: string;
13
+ target: string;
14
+ targetMode?: string;
15
+ }
16
+ declare function resolveRelationships(pkg: Package, partPath: string): Map<string, Relationship>;
17
+ //#endregion
18
+ export { Relationship, attr, childrenWithTag, decodeEntities, elementsWithTag, resolveRelationships, rootElement, textContent, walk };
@@ -0,0 +1,77 @@
1
+ //#region src/typed/util.ts
2
+ function* walk(nodes) {
3
+ for (const node of nodes) {
4
+ yield node;
5
+ if (node.type === "element") yield* walk(node.children);
6
+ }
7
+ }
8
+ function elementsWithTag(nodes, tag) {
9
+ const out = [];
10
+ for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
11
+ return out;
12
+ }
13
+ function childrenWithTag(element, tag) {
14
+ const out = [];
15
+ for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
16
+ return out;
17
+ }
18
+ function attr(element, name) {
19
+ for (const a of element.attributes) if (a.name === name) return a.value;
20
+ }
21
+ function rootElement(part) {
22
+ if (part?.kind !== "xml") return;
23
+ for (const node of part.nodes) if (node.type === "element") return node;
24
+ }
25
+ function decodeEntities(value) {
26
+ return value.replace(/&(?:amp|lt|gt|quot|apos);/g, (entity) => {
27
+ switch (entity) {
28
+ case "&amp;": return "&";
29
+ case "&lt;": return "<";
30
+ case "&gt;": return ">";
31
+ case "&quot;": return "\"";
32
+ case "&apos;": return "'";
33
+ default: return entity;
34
+ }
35
+ });
36
+ }
37
+ function textContent(element) {
38
+ let text = "";
39
+ for (const node of walk(element.children)) if (node.type === "text" || node.type === "cdata") text += node.value;
40
+ return decodeEntities(text);
41
+ }
42
+ function relsPathFor(partPath) {
43
+ const lastSlash = partPath.lastIndexOf("/");
44
+ return `${lastSlash === -1 ? "" : partPath.slice(0, lastSlash)}/_rels/${lastSlash === -1 ? partPath : partPath.slice(lastSlash + 1)}.rels`;
45
+ }
46
+ function resolveRelTarget(partPath, target) {
47
+ if (target.startsWith("/")) return target.slice(1);
48
+ const lastSlash = partPath.lastIndexOf("/");
49
+ const baseDir = lastSlash === -1 ? "" : partPath.slice(0, lastSlash);
50
+ const resolved = [];
51
+ for (const segment of `${baseDir}/${target}`.split("/")) {
52
+ if (segment === "" || segment === ".") continue;
53
+ if (segment === "..") resolved.pop();
54
+ else resolved.push(segment);
55
+ }
56
+ return resolved.join("/");
57
+ }
58
+ function resolveRelationships(pkg, partPath) {
59
+ const map = /* @__PURE__ */ new Map();
60
+ const rels = rootElement(pkg.parts[relsPathFor(partPath)]);
61
+ if (rels === void 0) return map;
62
+ for (const rel of childrenWithTag(rels, "Relationship")) {
63
+ const id = attr(rel, "Id");
64
+ const type = attr(rel, "Type");
65
+ const target = attr(rel, "Target");
66
+ if (id === void 0 || type === void 0 || target === void 0) continue;
67
+ const targetMode = attr(rel, "TargetMode");
68
+ map.set(id, {
69
+ type,
70
+ target: targetMode === "External" ? target : resolveRelTarget(partPath, target),
71
+ targetMode
72
+ });
73
+ }
74
+ return map;
75
+ }
76
+ //#endregion
77
+ export { attr, childrenWithTag, decodeEntities, elementsWithTag, resolveRelationships, rootElement, textContent, walk };
@@ -0,0 +1,64 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/typed/xlsx/a1.ts
3
+ const CELL_REFERENCE_RE = /^([A-Za-z]+)(\d+)$/;
4
+ function columnLettersToIndex(letters) {
5
+ if (letters.length === 0) return;
6
+ let index = 0;
7
+ for (const ch of letters.toUpperCase()) {
8
+ const code = ch.charCodeAt(0);
9
+ if (code < 65 || code > 90) return;
10
+ index = index * 26 + (code - 64);
11
+ }
12
+ return index - 1;
13
+ }
14
+ function columnIndexToLetters(index) {
15
+ let remaining = index + 1;
16
+ let letters = "";
17
+ while (remaining > 0) {
18
+ const digit = (remaining - 1) % 26;
19
+ letters = String.fromCharCode(65 + digit) + letters;
20
+ remaining = Math.trunc((remaining - 1) / 26);
21
+ }
22
+ return letters;
23
+ }
24
+ function parseCellReference(ref) {
25
+ const match = CELL_REFERENCE_RE.exec(ref);
26
+ if (match === null) return;
27
+ const letters = match[1];
28
+ const digits = match[2];
29
+ if (letters === void 0 || digits === void 0) return;
30
+ const column = columnLettersToIndex(letters);
31
+ const rowNumber = Number.parseInt(digits, 10);
32
+ if (column === void 0 || !Number.isInteger(rowNumber) || rowNumber < 1) return;
33
+ return {
34
+ row: rowNumber - 1,
35
+ column
36
+ };
37
+ }
38
+ function cellReference(row, column) {
39
+ return `${columnIndexToLetters(column)}${row + 1}`;
40
+ }
41
+ function parseRangeReference(ref) {
42
+ const separatorIndex = ref.indexOf(":");
43
+ const startRaw = separatorIndex === -1 ? ref : ref.slice(0, separatorIndex);
44
+ const endRaw = separatorIndex === -1 ? ref : ref.slice(separatorIndex + 1);
45
+ const start = parseCellReference(startRaw);
46
+ const end = parseCellReference(endRaw);
47
+ if (start === void 0 || end === void 0) return;
48
+ return {
49
+ startRow: Math.min(start.row, end.row),
50
+ startColumn: Math.min(start.column, end.column),
51
+ endRow: Math.max(start.row, end.row),
52
+ endColumn: Math.max(start.column, end.column)
53
+ };
54
+ }
55
+ function rangeReference(range) {
56
+ return `${cellReference(range.startRow, range.startColumn)}:${cellReference(range.endRow, range.endColumn)}`;
57
+ }
58
+ //#endregion
59
+ exports.cellReference = cellReference;
60
+ exports.columnIndexToLetters = columnIndexToLetters;
61
+ exports.columnLettersToIndex = columnLettersToIndex;
62
+ exports.parseCellReference = parseCellReference;
63
+ exports.parseRangeReference = parseRangeReference;
64
+ exports.rangeReference = rangeReference;
@@ -0,0 +1,19 @@
1
+ //#region src/typed/xlsx/a1.d.ts
2
+ declare function columnLettersToIndex(letters: string): number | undefined;
3
+ declare function columnIndexToLetters(index: number): string;
4
+ interface CellPosition {
5
+ row: number;
6
+ column: number;
7
+ }
8
+ declare function parseCellReference(ref: string): CellPosition | undefined;
9
+ declare function cellReference(row: number, column: number): string;
10
+ interface CellRange {
11
+ startRow: number;
12
+ startColumn: number;
13
+ endRow: number;
14
+ endColumn: number;
15
+ }
16
+ declare function parseRangeReference(ref: string): CellRange | undefined;
17
+ declare function rangeReference(range: CellRange): string;
18
+ //#endregion
19
+ export { CellPosition, CellRange, cellReference, columnIndexToLetters, columnLettersToIndex, parseCellReference, parseRangeReference, rangeReference };
@@ -0,0 +1,19 @@
1
+ //#region src/typed/xlsx/a1.d.ts
2
+ declare function columnLettersToIndex(letters: string): number | undefined;
3
+ declare function columnIndexToLetters(index: number): string;
4
+ interface CellPosition {
5
+ row: number;
6
+ column: number;
7
+ }
8
+ declare function parseCellReference(ref: string): CellPosition | undefined;
9
+ declare function cellReference(row: number, column: number): string;
10
+ interface CellRange {
11
+ startRow: number;
12
+ startColumn: number;
13
+ endRow: number;
14
+ endColumn: number;
15
+ }
16
+ declare function parseRangeReference(ref: string): CellRange | undefined;
17
+ declare function rangeReference(range: CellRange): string;
18
+ //#endregion
19
+ export { CellPosition, CellRange, cellReference, columnIndexToLetters, columnLettersToIndex, parseCellReference, parseRangeReference, rangeReference };
@@ -0,0 +1,58 @@
1
+ //#region src/typed/xlsx/a1.ts
2
+ const CELL_REFERENCE_RE = /^([A-Za-z]+)(\d+)$/;
3
+ function columnLettersToIndex(letters) {
4
+ if (letters.length === 0) return;
5
+ let index = 0;
6
+ for (const ch of letters.toUpperCase()) {
7
+ const code = ch.charCodeAt(0);
8
+ if (code < 65 || code > 90) return;
9
+ index = index * 26 + (code - 64);
10
+ }
11
+ return index - 1;
12
+ }
13
+ function columnIndexToLetters(index) {
14
+ let remaining = index + 1;
15
+ let letters = "";
16
+ while (remaining > 0) {
17
+ const digit = (remaining - 1) % 26;
18
+ letters = String.fromCharCode(65 + digit) + letters;
19
+ remaining = Math.trunc((remaining - 1) / 26);
20
+ }
21
+ return letters;
22
+ }
23
+ function parseCellReference(ref) {
24
+ const match = CELL_REFERENCE_RE.exec(ref);
25
+ if (match === null) return;
26
+ const letters = match[1];
27
+ const digits = match[2];
28
+ if (letters === void 0 || digits === void 0) return;
29
+ const column = columnLettersToIndex(letters);
30
+ const rowNumber = Number.parseInt(digits, 10);
31
+ if (column === void 0 || !Number.isInteger(rowNumber) || rowNumber < 1) return;
32
+ return {
33
+ row: rowNumber - 1,
34
+ column
35
+ };
36
+ }
37
+ function cellReference(row, column) {
38
+ return `${columnIndexToLetters(column)}${row + 1}`;
39
+ }
40
+ function parseRangeReference(ref) {
41
+ const separatorIndex = ref.indexOf(":");
42
+ const startRaw = separatorIndex === -1 ? ref : ref.slice(0, separatorIndex);
43
+ const endRaw = separatorIndex === -1 ? ref : ref.slice(separatorIndex + 1);
44
+ const start = parseCellReference(startRaw);
45
+ const end = parseCellReference(endRaw);
46
+ if (start === void 0 || end === void 0) return;
47
+ return {
48
+ startRow: Math.min(start.row, end.row),
49
+ startColumn: Math.min(start.column, end.column),
50
+ endRow: Math.max(start.row, end.row),
51
+ endColumn: Math.max(start.column, end.column)
52
+ };
53
+ }
54
+ function rangeReference(range) {
55
+ return `${cellReference(range.startRow, range.startColumn)}:${cellReference(range.endRow, range.endColumn)}`;
56
+ }
57
+ //#endregion
58
+ export { cellReference, columnIndexToLetters, columnLettersToIndex, parseCellReference, parseRangeReference, rangeReference };