ooxml.js 2.4.0 → 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.
- package/README.md +40 -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,140 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_typed_util = require("./util.cjs");
|
|
3
|
+
const require_typed_xlsx_shared_strings = require("./xlsx/shared-strings.cjs");
|
|
4
|
+
let zod = require("zod");
|
|
5
|
+
//#region src/typed/xlsx.ts
|
|
6
|
+
const XlsxCellSchema = zod.z.object({
|
|
7
|
+
reference: zod.z.string(),
|
|
8
|
+
value: zod.z.string(),
|
|
9
|
+
formula: zod.z.string().optional()
|
|
10
|
+
});
|
|
11
|
+
const XlsxSheetSchema = zod.z.object({
|
|
12
|
+
name: zod.z.string(),
|
|
13
|
+
cells: zod.z.array(XlsxCellSchema),
|
|
14
|
+
mergedRanges: zod.z.array(zod.z.string())
|
|
15
|
+
});
|
|
16
|
+
const DefinedNameSchema = zod.z.object({
|
|
17
|
+
name: zod.z.string(),
|
|
18
|
+
refersTo: zod.z.string()
|
|
19
|
+
});
|
|
20
|
+
const XlsxWorkbookSchema = zod.z.object({
|
|
21
|
+
sheets: zod.z.array(XlsxSheetSchema),
|
|
22
|
+
definedNames: zod.z.array(DefinedNameSchema)
|
|
23
|
+
});
|
|
24
|
+
const SHEET_PATH_RE = /^xl\/worksheets\/sheet(\d+)\.xml$/;
|
|
25
|
+
function resolveRelTarget(target) {
|
|
26
|
+
if (target.startsWith("/")) return target.slice(1);
|
|
27
|
+
return `xl/${target}`;
|
|
28
|
+
}
|
|
29
|
+
function relTargets(pkg) {
|
|
30
|
+
const map = /* @__PURE__ */ new Map();
|
|
31
|
+
const rels = require_typed_util.rootElement(pkg.parts["xl/_rels/workbook.xml.rels"]);
|
|
32
|
+
if (rels === void 0) return map;
|
|
33
|
+
for (const rel of require_typed_util.childrenWithTag(rels, "Relationship")) {
|
|
34
|
+
const id = require_typed_util.attr(rel, "Id");
|
|
35
|
+
const target = require_typed_util.attr(rel, "Target");
|
|
36
|
+
if (id !== void 0 && target !== void 0) map.set(id, resolveRelTarget(target));
|
|
37
|
+
}
|
|
38
|
+
return map;
|
|
39
|
+
}
|
|
40
|
+
function resolveSheetNames(pkg) {
|
|
41
|
+
const names = /* @__PURE__ */ new Map();
|
|
42
|
+
const workbook = require_typed_util.rootElement(pkg.parts["xl/workbook.xml"]);
|
|
43
|
+
if (workbook === void 0) return names;
|
|
44
|
+
const targets = relTargets(pkg);
|
|
45
|
+
for (const sheet of require_typed_util.elementsWithTag(workbook.children, "sheet")) {
|
|
46
|
+
const name = require_typed_util.attr(sheet, "name");
|
|
47
|
+
const rid = require_typed_util.attr(sheet, "r:id");
|
|
48
|
+
if (name !== void 0 && rid !== void 0) {
|
|
49
|
+
const partName = targets.get(rid);
|
|
50
|
+
if (partName !== void 0) names.set(partName, name);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return names;
|
|
54
|
+
}
|
|
55
|
+
function readDefinedNames(pkg) {
|
|
56
|
+
const names = [];
|
|
57
|
+
const workbook = require_typed_util.rootElement(pkg.parts["xl/workbook.xml"]);
|
|
58
|
+
if (workbook === void 0) return names;
|
|
59
|
+
for (const container of require_typed_util.elementsWithTag(workbook.children, "definedNames")) for (const definedName of require_typed_util.childrenWithTag(container, "definedName")) {
|
|
60
|
+
const name = require_typed_util.attr(definedName, "name");
|
|
61
|
+
if (name === void 0) continue;
|
|
62
|
+
names.push({
|
|
63
|
+
name,
|
|
64
|
+
refersTo: require_typed_util.textContent(definedName)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return names;
|
|
68
|
+
}
|
|
69
|
+
function sheetNumberOf(path) {
|
|
70
|
+
const match = SHEET_PATH_RE.exec(path);
|
|
71
|
+
const digits = match === null ? void 0 : match[1];
|
|
72
|
+
if (digits === void 0) return;
|
|
73
|
+
return Number.parseInt(digits, 10);
|
|
74
|
+
}
|
|
75
|
+
function readCell(cell, sharedStrings) {
|
|
76
|
+
const reference = require_typed_util.attr(cell, "r");
|
|
77
|
+
if (reference === void 0) return;
|
|
78
|
+
const valueEl = require_typed_util.childrenWithTag(cell, "v")[0];
|
|
79
|
+
if (valueEl === void 0) return;
|
|
80
|
+
const raw = require_typed_util.textContent(valueEl);
|
|
81
|
+
let value;
|
|
82
|
+
if (require_typed_util.attr(cell, "t") === "s") {
|
|
83
|
+
const index = Number.parseInt(raw, 10);
|
|
84
|
+
value = Number.isInteger(index) ? sharedStrings[index] : void 0;
|
|
85
|
+
} else value = raw;
|
|
86
|
+
if (value === void 0) return;
|
|
87
|
+
const projected = {
|
|
88
|
+
reference,
|
|
89
|
+
value
|
|
90
|
+
};
|
|
91
|
+
const formulaEl = require_typed_util.childrenWithTag(cell, "f")[0];
|
|
92
|
+
if (formulaEl !== void 0) projected.formula = require_typed_util.textContent(formulaEl);
|
|
93
|
+
return projected;
|
|
94
|
+
}
|
|
95
|
+
function readCells(worksheet, sharedStrings) {
|
|
96
|
+
const cells = [];
|
|
97
|
+
for (const row of require_typed_util.elementsWithTag(worksheet.children, "row")) for (const cell of require_typed_util.childrenWithTag(row, "c")) {
|
|
98
|
+
const projected = readCell(cell, sharedStrings);
|
|
99
|
+
if (projected !== void 0) cells.push(projected);
|
|
100
|
+
}
|
|
101
|
+
return cells;
|
|
102
|
+
}
|
|
103
|
+
function readMergedRanges(worksheet) {
|
|
104
|
+
const ranges = [];
|
|
105
|
+
for (const mergeCells of require_typed_util.elementsWithTag(worksheet.children, "mergeCells")) for (const mergeCell of require_typed_util.childrenWithTag(mergeCells, "mergeCell")) {
|
|
106
|
+
const ref = require_typed_util.attr(mergeCell, "ref");
|
|
107
|
+
if (ref !== void 0) ranges.push(ref);
|
|
108
|
+
}
|
|
109
|
+
return ranges;
|
|
110
|
+
}
|
|
111
|
+
function readXlsx(pkg) {
|
|
112
|
+
const sharedStrings = require_typed_xlsx_shared_strings.loadSharedStrings(pkg);
|
|
113
|
+
const names = resolveSheetNames(pkg);
|
|
114
|
+
const definedNames = readDefinedNames(pkg);
|
|
115
|
+
const worksheets = Object.keys(pkg.parts).map((path) => ({
|
|
116
|
+
path,
|
|
117
|
+
number: sheetNumberOf(path)
|
|
118
|
+
})).filter((entry) => entry.number !== void 0).sort((a, b) => a.number - b.number);
|
|
119
|
+
const sheets = [];
|
|
120
|
+
for (const { path, number } of worksheets) {
|
|
121
|
+
const root = require_typed_util.rootElement(pkg.parts[path]);
|
|
122
|
+
if (root === void 0) continue;
|
|
123
|
+
const name = names.get(path) ?? `Sheet${number}`;
|
|
124
|
+
sheets.push({
|
|
125
|
+
name,
|
|
126
|
+
cells: readCells(root, sharedStrings),
|
|
127
|
+
mergedRanges: readMergedRanges(root)
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
sheets,
|
|
132
|
+
definedNames
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
exports.DefinedNameSchema = DefinedNameSchema;
|
|
137
|
+
exports.XlsxCellSchema = XlsxCellSchema;
|
|
138
|
+
exports.XlsxSheetSchema = XlsxSheetSchema;
|
|
139
|
+
exports.XlsxWorkbookSchema = XlsxWorkbookSchema;
|
|
140
|
+
exports.readXlsx = readXlsx;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { r as Package } from "../package-L24lkba-.cjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/typed/xlsx.d.ts
|
|
4
|
+
declare const XlsxCellSchema: z.ZodObject<{
|
|
5
|
+
reference: z.ZodString;
|
|
6
|
+
value: z.ZodString;
|
|
7
|
+
formula: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type XlsxCell = z.infer<typeof XlsxCellSchema>;
|
|
10
|
+
declare const XlsxSheetSchema: z.ZodObject<{
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
cells: z.ZodArray<z.ZodObject<{
|
|
13
|
+
reference: z.ZodString;
|
|
14
|
+
value: z.ZodString;
|
|
15
|
+
formula: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>>;
|
|
17
|
+
mergedRanges: z.ZodArray<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
type XlsxSheet = z.infer<typeof XlsxSheetSchema>;
|
|
20
|
+
declare const DefinedNameSchema: z.ZodObject<{
|
|
21
|
+
name: z.ZodString;
|
|
22
|
+
refersTo: z.ZodString;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
type DefinedName = z.infer<typeof DefinedNameSchema>;
|
|
25
|
+
declare const XlsxWorkbookSchema: z.ZodObject<{
|
|
26
|
+
sheets: z.ZodArray<z.ZodObject<{
|
|
27
|
+
name: z.ZodString;
|
|
28
|
+
cells: z.ZodArray<z.ZodObject<{
|
|
29
|
+
reference: z.ZodString;
|
|
30
|
+
value: z.ZodString;
|
|
31
|
+
formula: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, z.core.$strip>>;
|
|
33
|
+
mergedRanges: z.ZodArray<z.ZodString>;
|
|
34
|
+
}, z.core.$strip>>;
|
|
35
|
+
definedNames: z.ZodArray<z.ZodObject<{
|
|
36
|
+
name: z.ZodString;
|
|
37
|
+
refersTo: z.ZodString;
|
|
38
|
+
}, z.core.$strip>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
type XlsxWorkbook = z.infer<typeof XlsxWorkbookSchema>;
|
|
41
|
+
declare function readXlsx(pkg: Package): XlsxWorkbook;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { DefinedName, DefinedNameSchema, XlsxCell, XlsxCellSchema, XlsxSheet, XlsxSheetSchema, XlsxWorkbook, XlsxWorkbookSchema, readXlsx };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { r as Package } from "../package-BUojjTXf.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/typed/xlsx.d.ts
|
|
4
|
+
declare const XlsxCellSchema: z.ZodObject<{
|
|
5
|
+
reference: z.ZodString;
|
|
6
|
+
value: z.ZodString;
|
|
7
|
+
formula: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type XlsxCell = z.infer<typeof XlsxCellSchema>;
|
|
10
|
+
declare const XlsxSheetSchema: z.ZodObject<{
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
cells: z.ZodArray<z.ZodObject<{
|
|
13
|
+
reference: z.ZodString;
|
|
14
|
+
value: z.ZodString;
|
|
15
|
+
formula: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>>;
|
|
17
|
+
mergedRanges: z.ZodArray<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
type XlsxSheet = z.infer<typeof XlsxSheetSchema>;
|
|
20
|
+
declare const DefinedNameSchema: z.ZodObject<{
|
|
21
|
+
name: z.ZodString;
|
|
22
|
+
refersTo: z.ZodString;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
type DefinedName = z.infer<typeof DefinedNameSchema>;
|
|
25
|
+
declare const XlsxWorkbookSchema: z.ZodObject<{
|
|
26
|
+
sheets: z.ZodArray<z.ZodObject<{
|
|
27
|
+
name: z.ZodString;
|
|
28
|
+
cells: z.ZodArray<z.ZodObject<{
|
|
29
|
+
reference: z.ZodString;
|
|
30
|
+
value: z.ZodString;
|
|
31
|
+
formula: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, z.core.$strip>>;
|
|
33
|
+
mergedRanges: z.ZodArray<z.ZodString>;
|
|
34
|
+
}, z.core.$strip>>;
|
|
35
|
+
definedNames: z.ZodArray<z.ZodObject<{
|
|
36
|
+
name: z.ZodString;
|
|
37
|
+
refersTo: z.ZodString;
|
|
38
|
+
}, z.core.$strip>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
type XlsxWorkbook = z.infer<typeof XlsxWorkbookSchema>;
|
|
41
|
+
declare function readXlsx(pkg: Package): XlsxWorkbook;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { DefinedName, DefinedNameSchema, XlsxCell, XlsxCellSchema, XlsxSheet, XlsxSheetSchema, XlsxWorkbook, XlsxWorkbookSchema, readXlsx };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { attr, childrenWithTag, elementsWithTag, rootElement, textContent } from "./util.js";
|
|
2
|
+
import { loadSharedStrings } from "./xlsx/shared-strings.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/typed/xlsx.ts
|
|
5
|
+
const XlsxCellSchema = z.object({
|
|
6
|
+
reference: z.string(),
|
|
7
|
+
value: z.string(),
|
|
8
|
+
formula: z.string().optional()
|
|
9
|
+
});
|
|
10
|
+
const XlsxSheetSchema = z.object({
|
|
11
|
+
name: z.string(),
|
|
12
|
+
cells: z.array(XlsxCellSchema),
|
|
13
|
+
mergedRanges: z.array(z.string())
|
|
14
|
+
});
|
|
15
|
+
const DefinedNameSchema = z.object({
|
|
16
|
+
name: z.string(),
|
|
17
|
+
refersTo: z.string()
|
|
18
|
+
});
|
|
19
|
+
const XlsxWorkbookSchema = z.object({
|
|
20
|
+
sheets: z.array(XlsxSheetSchema),
|
|
21
|
+
definedNames: z.array(DefinedNameSchema)
|
|
22
|
+
});
|
|
23
|
+
const SHEET_PATH_RE = /^xl\/worksheets\/sheet(\d+)\.xml$/;
|
|
24
|
+
function resolveRelTarget(target) {
|
|
25
|
+
if (target.startsWith("/")) return target.slice(1);
|
|
26
|
+
return `xl/${target}`;
|
|
27
|
+
}
|
|
28
|
+
function relTargets(pkg) {
|
|
29
|
+
const map = /* @__PURE__ */ new Map();
|
|
30
|
+
const rels = rootElement(pkg.parts["xl/_rels/workbook.xml.rels"]);
|
|
31
|
+
if (rels === void 0) return map;
|
|
32
|
+
for (const rel of childrenWithTag(rels, "Relationship")) {
|
|
33
|
+
const id = attr(rel, "Id");
|
|
34
|
+
const target = attr(rel, "Target");
|
|
35
|
+
if (id !== void 0 && target !== void 0) map.set(id, resolveRelTarget(target));
|
|
36
|
+
}
|
|
37
|
+
return map;
|
|
38
|
+
}
|
|
39
|
+
function resolveSheetNames(pkg) {
|
|
40
|
+
const names = /* @__PURE__ */ new Map();
|
|
41
|
+
const workbook = rootElement(pkg.parts["xl/workbook.xml"]);
|
|
42
|
+
if (workbook === void 0) return names;
|
|
43
|
+
const targets = relTargets(pkg);
|
|
44
|
+
for (const sheet of elementsWithTag(workbook.children, "sheet")) {
|
|
45
|
+
const name = attr(sheet, "name");
|
|
46
|
+
const rid = attr(sheet, "r:id");
|
|
47
|
+
if (name !== void 0 && rid !== void 0) {
|
|
48
|
+
const partName = targets.get(rid);
|
|
49
|
+
if (partName !== void 0) names.set(partName, name);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return names;
|
|
53
|
+
}
|
|
54
|
+
function readDefinedNames(pkg) {
|
|
55
|
+
const names = [];
|
|
56
|
+
const workbook = rootElement(pkg.parts["xl/workbook.xml"]);
|
|
57
|
+
if (workbook === void 0) return names;
|
|
58
|
+
for (const container of elementsWithTag(workbook.children, "definedNames")) for (const definedName of childrenWithTag(container, "definedName")) {
|
|
59
|
+
const name = attr(definedName, "name");
|
|
60
|
+
if (name === void 0) continue;
|
|
61
|
+
names.push({
|
|
62
|
+
name,
|
|
63
|
+
refersTo: textContent(definedName)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return names;
|
|
67
|
+
}
|
|
68
|
+
function sheetNumberOf(path) {
|
|
69
|
+
const match = SHEET_PATH_RE.exec(path);
|
|
70
|
+
const digits = match === null ? void 0 : match[1];
|
|
71
|
+
if (digits === void 0) return;
|
|
72
|
+
return Number.parseInt(digits, 10);
|
|
73
|
+
}
|
|
74
|
+
function readCell(cell, sharedStrings) {
|
|
75
|
+
const reference = attr(cell, "r");
|
|
76
|
+
if (reference === void 0) return;
|
|
77
|
+
const valueEl = childrenWithTag(cell, "v")[0];
|
|
78
|
+
if (valueEl === void 0) return;
|
|
79
|
+
const raw = textContent(valueEl);
|
|
80
|
+
let value;
|
|
81
|
+
if (attr(cell, "t") === "s") {
|
|
82
|
+
const index = Number.parseInt(raw, 10);
|
|
83
|
+
value = Number.isInteger(index) ? sharedStrings[index] : void 0;
|
|
84
|
+
} else value = raw;
|
|
85
|
+
if (value === void 0) return;
|
|
86
|
+
const projected = {
|
|
87
|
+
reference,
|
|
88
|
+
value
|
|
89
|
+
};
|
|
90
|
+
const formulaEl = childrenWithTag(cell, "f")[0];
|
|
91
|
+
if (formulaEl !== void 0) projected.formula = textContent(formulaEl);
|
|
92
|
+
return projected;
|
|
93
|
+
}
|
|
94
|
+
function readCells(worksheet, sharedStrings) {
|
|
95
|
+
const cells = [];
|
|
96
|
+
for (const row of elementsWithTag(worksheet.children, "row")) for (const cell of childrenWithTag(row, "c")) {
|
|
97
|
+
const projected = readCell(cell, sharedStrings);
|
|
98
|
+
if (projected !== void 0) cells.push(projected);
|
|
99
|
+
}
|
|
100
|
+
return cells;
|
|
101
|
+
}
|
|
102
|
+
function readMergedRanges(worksheet) {
|
|
103
|
+
const ranges = [];
|
|
104
|
+
for (const mergeCells of elementsWithTag(worksheet.children, "mergeCells")) for (const mergeCell of childrenWithTag(mergeCells, "mergeCell")) {
|
|
105
|
+
const ref = attr(mergeCell, "ref");
|
|
106
|
+
if (ref !== void 0) ranges.push(ref);
|
|
107
|
+
}
|
|
108
|
+
return ranges;
|
|
109
|
+
}
|
|
110
|
+
function readXlsx(pkg) {
|
|
111
|
+
const sharedStrings = loadSharedStrings(pkg);
|
|
112
|
+
const names = resolveSheetNames(pkg);
|
|
113
|
+
const definedNames = readDefinedNames(pkg);
|
|
114
|
+
const worksheets = Object.keys(pkg.parts).map((path) => ({
|
|
115
|
+
path,
|
|
116
|
+
number: sheetNumberOf(path)
|
|
117
|
+
})).filter((entry) => entry.number !== void 0).sort((a, b) => a.number - b.number);
|
|
118
|
+
const sheets = [];
|
|
119
|
+
for (const { path, number } of worksheets) {
|
|
120
|
+
const root = rootElement(pkg.parts[path]);
|
|
121
|
+
if (root === void 0) continue;
|
|
122
|
+
const name = names.get(path) ?? `Sheet${number}`;
|
|
123
|
+
sheets.push({
|
|
124
|
+
name,
|
|
125
|
+
cells: readCells(root, sharedStrings),
|
|
126
|
+
mergedRanges: readMergedRanges(root)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
sheets,
|
|
131
|
+
definedNames
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
export { DefinedNameSchema, XlsxCellSchema, XlsxSheetSchema, XlsxWorkbookSchema, readXlsx };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/util/base64.ts
|
|
3
|
+
const TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4
|
+
const DECODE = (() => {
|
|
5
|
+
const map = (/* @__PURE__ */ new Uint8Array(256)).fill(255);
|
|
6
|
+
for (let i = 0; i < 64; i = i + 1) map[TABLE.charCodeAt(i)] = i;
|
|
7
|
+
return map;
|
|
8
|
+
})();
|
|
9
|
+
function bytesToBase64(bytes) {
|
|
10
|
+
let out = "";
|
|
11
|
+
const len = bytes.length;
|
|
12
|
+
for (let i = 0; i < len; i = i + 3) {
|
|
13
|
+
const b0 = bytes[i];
|
|
14
|
+
const b1 = i + 1 < len ? bytes[i + 1] : 0;
|
|
15
|
+
const b2 = i + 2 < len ? bytes[i + 2] : 0;
|
|
16
|
+
out += TABLE[b0 >> 2];
|
|
17
|
+
out += TABLE[(b0 & 3) << 4 | b1 >> 4];
|
|
18
|
+
out += i + 1 < len ? TABLE[(b1 & 15) << 2 | b2 >> 6] : "=";
|
|
19
|
+
out += i + 2 < len ? TABLE[b2 & 63] : "=";
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function base64ToBytes(b64) {
|
|
24
|
+
const clean = b64.replace(/[^A-Za-z0-9+/=]/g, "");
|
|
25
|
+
const len = clean.length;
|
|
26
|
+
const out = new Uint8Array(len * 3 / 4 | 0);
|
|
27
|
+
let p = 0;
|
|
28
|
+
for (let i = 0; i < len; i = i + 4) {
|
|
29
|
+
const c0 = DECODE[clean.charCodeAt(i)];
|
|
30
|
+
const c1 = DECODE[clean.charCodeAt(i + 1)];
|
|
31
|
+
const c2 = clean.charCodeAt(i + 2);
|
|
32
|
+
const c3 = clean.charCodeAt(i + 3);
|
|
33
|
+
if (c0 === 255 || c1 === 255) throw new Error("invalid base64 input");
|
|
34
|
+
out[p++] = c0 << 2 | c1 >> 4;
|
|
35
|
+
if (c2 !== 61) {
|
|
36
|
+
const d2 = DECODE[c2];
|
|
37
|
+
out[p++] = (c1 & 15) << 4 | d2 >> 2;
|
|
38
|
+
if (c3 !== 61) {
|
|
39
|
+
const d3 = DECODE[c3];
|
|
40
|
+
out[p++] = (d2 & 3) << 6 | d3;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return out.subarray(0, p);
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.base64ToBytes = base64ToBytes;
|
|
48
|
+
exports.bytesToBase64 = bytesToBase64;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region src/util/base64.ts
|
|
2
|
+
const TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
3
|
+
const DECODE = (() => {
|
|
4
|
+
const map = (/* @__PURE__ */ new Uint8Array(256)).fill(255);
|
|
5
|
+
for (let i = 0; i < 64; i = i + 1) map[TABLE.charCodeAt(i)] = i;
|
|
6
|
+
return map;
|
|
7
|
+
})();
|
|
8
|
+
function bytesToBase64(bytes) {
|
|
9
|
+
let out = "";
|
|
10
|
+
const len = bytes.length;
|
|
11
|
+
for (let i = 0; i < len; i = i + 3) {
|
|
12
|
+
const b0 = bytes[i];
|
|
13
|
+
const b1 = i + 1 < len ? bytes[i + 1] : 0;
|
|
14
|
+
const b2 = i + 2 < len ? bytes[i + 2] : 0;
|
|
15
|
+
out += TABLE[b0 >> 2];
|
|
16
|
+
out += TABLE[(b0 & 3) << 4 | b1 >> 4];
|
|
17
|
+
out += i + 1 < len ? TABLE[(b1 & 15) << 2 | b2 >> 6] : "=";
|
|
18
|
+
out += i + 2 < len ? TABLE[b2 & 63] : "=";
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
function base64ToBytes(b64) {
|
|
23
|
+
const clean = b64.replace(/[^A-Za-z0-9+/=]/g, "");
|
|
24
|
+
const len = clean.length;
|
|
25
|
+
const out = new Uint8Array(len * 3 / 4 | 0);
|
|
26
|
+
let p = 0;
|
|
27
|
+
for (let i = 0; i < len; i = i + 4) {
|
|
28
|
+
const c0 = DECODE[clean.charCodeAt(i)];
|
|
29
|
+
const c1 = DECODE[clean.charCodeAt(i + 1)];
|
|
30
|
+
const c2 = clean.charCodeAt(i + 2);
|
|
31
|
+
const c3 = clean.charCodeAt(i + 3);
|
|
32
|
+
if (c0 === 255 || c1 === 255) throw new Error("invalid base64 input");
|
|
33
|
+
out[p++] = c0 << 2 | c1 >> 4;
|
|
34
|
+
if (c2 !== 61) {
|
|
35
|
+
const d2 = DECODE[c2];
|
|
36
|
+
out[p++] = (c1 & 15) << 4 | d2 >> 2;
|
|
37
|
+
if (c3 !== 61) {
|
|
38
|
+
const d3 = DECODE[c3];
|
|
39
|
+
out[p++] = (d2 & 3) << 6 | d3;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out.subarray(0, p);
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { base64ToBytes, bytesToBase64 };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/xml/build.ts
|
|
3
|
+
const BUILDER = new (require("fast-xml-parser")).XMLBuilder({
|
|
4
|
+
preserveOrder: true,
|
|
5
|
+
attributeNamePrefix: "@_",
|
|
6
|
+
ignoreAttributes: false,
|
|
7
|
+
textNodeName: "#text",
|
|
8
|
+
cdataPropName: "__cdata",
|
|
9
|
+
commentPropName: "__comment",
|
|
10
|
+
processEntities: false,
|
|
11
|
+
format: false,
|
|
12
|
+
suppressEmptyNode: false
|
|
13
|
+
});
|
|
14
|
+
function buildXml(nodes) {
|
|
15
|
+
const out = BUILDER.build(toOrdered(nodes));
|
|
16
|
+
if (typeof out !== "string") throw new Error("XMLBuilder did not return a string");
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
function toOrdered(nodes) {
|
|
20
|
+
return nodes.map(toOrderedNode);
|
|
21
|
+
}
|
|
22
|
+
function attrsObject(attributes) {
|
|
23
|
+
const obj = {};
|
|
24
|
+
for (const a of attributes) obj[`@_${a.name}`] = a.value;
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function toOrderedNode(node) {
|
|
28
|
+
switch (node.type) {
|
|
29
|
+
case "text": return { "#text": node.value };
|
|
30
|
+
case "comment": return { __comment: [{ "#text": node.value }] };
|
|
31
|
+
case "cdata": return { __cdata: [{ "#text": node.value }] };
|
|
32
|
+
case "pi": return { [`?${node.target}`]: [{ "#text": node.content }] };
|
|
33
|
+
case "declaration": return {
|
|
34
|
+
"?xml": [{ "#text": "" }],
|
|
35
|
+
":@": attrsObject(node.attributes)
|
|
36
|
+
};
|
|
37
|
+
case "element": {
|
|
38
|
+
const obj = { [node.tag]: toOrdered(node.children) };
|
|
39
|
+
const attrs = attrsObject(node.attributes);
|
|
40
|
+
if (Object.keys(attrs).length > 0) obj[":@"] = attrs;
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.buildXml = buildXml;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { XMLBuilder } from "fast-xml-parser";
|
|
2
|
+
//#region src/xml/build.ts
|
|
3
|
+
const BUILDER = new XMLBuilder({
|
|
4
|
+
preserveOrder: true,
|
|
5
|
+
attributeNamePrefix: "@_",
|
|
6
|
+
ignoreAttributes: false,
|
|
7
|
+
textNodeName: "#text",
|
|
8
|
+
cdataPropName: "__cdata",
|
|
9
|
+
commentPropName: "__comment",
|
|
10
|
+
processEntities: false,
|
|
11
|
+
format: false,
|
|
12
|
+
suppressEmptyNode: false
|
|
13
|
+
});
|
|
14
|
+
function buildXml(nodes) {
|
|
15
|
+
const out = BUILDER.build(toOrdered(nodes));
|
|
16
|
+
if (typeof out !== "string") throw new Error("XMLBuilder did not return a string");
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
function toOrdered(nodes) {
|
|
20
|
+
return nodes.map(toOrderedNode);
|
|
21
|
+
}
|
|
22
|
+
function attrsObject(attributes) {
|
|
23
|
+
const obj = {};
|
|
24
|
+
for (const a of attributes) obj[`@_${a.name}`] = a.value;
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function toOrderedNode(node) {
|
|
28
|
+
switch (node.type) {
|
|
29
|
+
case "text": return { "#text": node.value };
|
|
30
|
+
case "comment": return { __comment: [{ "#text": node.value }] };
|
|
31
|
+
case "cdata": return { __cdata: [{ "#text": node.value }] };
|
|
32
|
+
case "pi": return { [`?${node.target}`]: [{ "#text": node.content }] };
|
|
33
|
+
case "declaration": return {
|
|
34
|
+
"?xml": [{ "#text": "" }],
|
|
35
|
+
":@": attrsObject(node.attributes)
|
|
36
|
+
};
|
|
37
|
+
case "element": {
|
|
38
|
+
const obj = { [node.tag]: toOrdered(node.children) };
|
|
39
|
+
const attrs = attrsObject(node.attributes);
|
|
40
|
+
if (Object.keys(attrs).length > 0) obj[":@"] = attrs;
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { buildXml };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/xml/entities.ts
|
|
3
|
+
function encodeXmlText(value) {
|
|
4
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.encodeXmlText = encodeXmlText;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/xml/fragment.ts
|
|
3
|
+
function el(tag, attrs = {}, children = []) {
|
|
4
|
+
return {
|
|
5
|
+
type: "element",
|
|
6
|
+
tag,
|
|
7
|
+
attributes: Object.entries(attrs).map(([name, value]) => ({
|
|
8
|
+
name,
|
|
9
|
+
value
|
|
10
|
+
})),
|
|
11
|
+
children
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function txt(value) {
|
|
15
|
+
return {
|
|
16
|
+
type: "text",
|
|
17
|
+
value
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.el = el;
|
|
22
|
+
exports.txt = txt;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { d as XmlNode, h as XmlText, l as XmlElement } from "../node-CkBWRjNR.cjs";
|
|
2
|
+
//#region src/xml/fragment.d.ts
|
|
3
|
+
declare function el(tag: string, attrs?: Record<string, string>, children?: XmlNode[]): XmlElement;
|
|
4
|
+
declare function txt(value: string): XmlText;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { el, txt };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { d as XmlNode, h as XmlText, l as XmlElement } from "../node-CkBWRjNR.js";
|
|
2
|
+
//#region src/xml/fragment.d.ts
|
|
3
|
+
declare function el(tag: string, attrs?: Record<string, string>, children?: XmlNode[]): XmlElement;
|
|
4
|
+
declare function txt(value: string): XmlText;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { el, txt };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/xml/fragment.ts
|
|
2
|
+
function el(tag, attrs = {}, children = []) {
|
|
3
|
+
return {
|
|
4
|
+
type: "element",
|
|
5
|
+
tag,
|
|
6
|
+
attributes: Object.entries(attrs).map(([name, value]) => ({
|
|
7
|
+
name,
|
|
8
|
+
value
|
|
9
|
+
})),
|
|
10
|
+
children
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function txt(value) {
|
|
14
|
+
return {
|
|
15
|
+
type: "text",
|
|
16
|
+
value
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { el, txt };
|