ooxml.js 2.4.1 → 2.5.1
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.
- package/README.md +15 -2
- package/dist/codec.cjs +28 -0
- package/dist/codec.d.cts +72 -0
- package/dist/codec.d.ts +72 -0
- package/dist/codec.js +24 -0
- package/dist/compact.cjs +162 -0
- package/dist/compact.d.cts +70 -0
- package/dist/compact.d.ts +70 -0
- package/dist/compact.js +152 -0
- package/dist/image/sniff.cjs +28 -0
- package/dist/image/sniff.d.cts +5 -0
- package/dist/image/sniff.d.ts +5 -0
- package/dist/image/sniff.js +27 -0
- package/dist/index.cjs +83 -3025
- package/dist/index.d.cts +22 -527
- package/dist/index.d.ts +22 -527
- package/dist/index.js +22 -2964
- package/dist/model/node.cjs +67 -0
- package/dist/model/node.d.cts +2 -0
- package/dist/model/node.d.ts +2 -0
- package/dist/model/node.js +58 -0
- package/dist/model/package.cjs +19 -0
- package/dist/model/package.d.cts +2 -0
- package/dist/model/package.d.ts +2 -0
- package/dist/model/package.js +15 -0
- package/dist/node-CkBWRjNR.d.cts +83 -0
- package/dist/node-CkBWRjNR.d.ts +83 -0
- package/dist/package-BUojjTXf.d.ts +114 -0
- package/dist/package-L24lkba-.d.cts +114 -0
- package/dist/package-io/read.cjs +33 -0
- package/dist/package-io/read.d.cts +5 -0
- package/dist/package-io/read.d.ts +5 -0
- package/dist/package-io/read.js +32 -0
- package/dist/package-io/write.cjs +18 -0
- package/dist/package-io/write.d.cts +5 -0
- package/dist/package-io/write.d.ts +5 -0
- package/dist/package-io/write.js +17 -0
- package/dist/typed/docx/read.cjs +332 -0
- package/dist/typed/docx/read.d.cts +52 -0
- package/dist/typed/docx/read.d.ts +52 -0
- package/dist/typed/docx/read.js +328 -0
- package/dist/typed/docx/styles.cjs +148 -0
- package/dist/typed/docx/styles.d.cts +29 -0
- package/dist/typed/docx/styles.d.ts +29 -0
- package/dist/typed/docx/styles.js +146 -0
- package/dist/typed/pptx/inherit.cjs +96 -0
- package/dist/typed/pptx/inherit.d.cts +30 -0
- package/dist/typed/pptx/inherit.d.ts +30 -0
- package/dist/typed/pptx/inherit.js +90 -0
- package/dist/typed/pptx/read.cjs +364 -0
- package/dist/typed/pptx/read.d.cts +44 -0
- package/dist/typed/pptx/read.d.ts +44 -0
- package/dist/typed/pptx/read.js +362 -0
- package/dist/typed/shared/color.cjs +85 -0
- package/dist/typed/shared/color.d.cts +9 -0
- package/dist/typed/shared/color.d.ts +9 -0
- package/dist/typed/shared/color.js +84 -0
- package/dist/typed/shared/drawingml.cjs +191 -0
- package/dist/typed/shared/drawingml.d.cts +40 -0
- package/dist/typed/shared/drawingml.d.ts +40 -0
- package/dist/typed/shared/drawingml.js +180 -0
- package/dist/typed/shared/metadata.cjs +44 -0
- package/dist/typed/shared/metadata.d.cts +16 -0
- package/dist/typed/shared/metadata.d.ts +16 -0
- package/dist/typed/shared/metadata.js +42 -0
- package/dist/typed/shared/source-path.cjs +18 -0
- package/dist/typed/shared/source-path.d.cts +5 -0
- package/dist/typed/shared/source-path.d.ts +5 -0
- package/dist/typed/shared/source-path.js +17 -0
- package/dist/typed/shared/units.cjs +55 -0
- package/dist/typed/shared/units.d.cts +20 -0
- package/dist/typed/shared/units.d.ts +20 -0
- package/dist/typed/shared/units.js +38 -0
- package/dist/typed/util.cjs +85 -0
- package/dist/typed/util.d.cts +18 -0
- package/dist/typed/util.d.ts +18 -0
- package/dist/typed/util.js +77 -0
- package/dist/typed/xlsx/a1.cjs +64 -0
- package/dist/typed/xlsx/a1.d.cts +19 -0
- package/dist/typed/xlsx/a1.d.ts +19 -0
- package/dist/typed/xlsx/a1.js +58 -0
- package/dist/typed/xlsx/build.cjs +456 -0
- package/dist/typed/xlsx/build.d.cts +6 -0
- package/dist/typed/xlsx/build.d.ts +6 -0
- package/dist/typed/xlsx/build.js +455 -0
- package/dist/typed/xlsx/content.cjs +257 -0
- package/dist/typed/xlsx/content.d.cts +6 -0
- package/dist/typed/xlsx/content.d.ts +6 -0
- package/dist/typed/xlsx/content.js +256 -0
- package/dist/typed/xlsx/defined-names.cjs +90 -0
- package/dist/typed/xlsx/defined-names.d.cts +20 -0
- package/dist/typed/xlsx/defined-names.d.ts +20 -0
- package/dist/typed/xlsx/defined-names.js +83 -0
- package/dist/typed/xlsx/print-settings.cjs +116 -0
- package/dist/typed/xlsx/print-settings.d.cts +8 -0
- package/dist/typed/xlsx/print-settings.d.ts +8 -0
- package/dist/typed/xlsx/print-settings.js +114 -0
- package/dist/typed/xlsx/shared-strings.cjs +35 -0
- package/dist/typed/xlsx/shared-strings.d.cts +12 -0
- package/dist/typed/xlsx/shared-strings.d.ts +12 -0
- package/dist/typed/xlsx/shared-strings.js +33 -0
- package/dist/typed/xlsx/units.cjs +21 -0
- package/dist/typed/xlsx/units.d.cts +8 -0
- package/dist/typed/xlsx/units.d.ts +8 -0
- package/dist/typed/xlsx/units.js +16 -0
- package/dist/typed/xlsx/util.cjs +53 -0
- package/dist/typed/xlsx/util.d.cts +10 -0
- package/dist/typed/xlsx/util.d.ts +10 -0
- package/dist/typed/xlsx/util.js +47 -0
- package/dist/typed/xlsx.cjs +140 -0
- package/dist/typed/xlsx.d.cts +43 -0
- package/dist/typed/xlsx.d.ts +43 -0
- package/dist/typed/xlsx.js +135 -0
- package/dist/util/base64.cjs +48 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +46 -0
- package/dist/xml/build.cjs +46 -0
- package/dist/xml/build.d.cts +5 -0
- package/dist/xml/build.d.ts +5 -0
- package/dist/xml/build.js +46 -0
- package/dist/xml/entities.cjs +7 -0
- package/dist/xml/entities.d.cts +4 -0
- package/dist/xml/entities.d.ts +4 -0
- package/dist/xml/entities.js +6 -0
- package/dist/xml/fragment.cjs +22 -0
- package/dist/xml/fragment.d.cts +6 -0
- package/dist/xml/fragment.d.ts +6 -0
- package/dist/xml/fragment.js +20 -0
- package/dist/xml/parse.cjs +88 -0
- package/dist/xml/parse.d.cts +5 -0
- package/dist/xml/parse.d.ts +5 -0
- package/dist/xml/parse.js +88 -0
- package/dist/zip.cjs +12 -0
- package/dist/zip.d.cts +5 -0
- package/dist/zip.d.ts +5 -0
- package/dist/zip.js +10 -0
- 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 "<": return "<";
|
|
31
|
+
case ">": return ">";
|
|
32
|
+
case """: return "\"";
|
|
33
|
+
case "'": 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 "&": return "&";
|
|
29
|
+
case "<": return "<";
|
|
30
|
+
case ">": return ">";
|
|
31
|
+
case """: return "\"";
|
|
32
|
+
case "'": 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 };
|