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
package/dist/compact.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { PackageSchema } from "./model/package.js";
|
|
2
|
+
import { decodePackage, encodePackage } from "./codec.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/compact.ts
|
|
5
|
+
function isUnknownArray(value) {
|
|
6
|
+
return Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function isCompactAttrPairs(value) {
|
|
9
|
+
return isUnknownArray(value) && value.every((v) => typeof v === "number");
|
|
10
|
+
}
|
|
11
|
+
function isCompactXmlNode(value) {
|
|
12
|
+
if (!isUnknownArray(value)) return false;
|
|
13
|
+
const code = value[0];
|
|
14
|
+
if (code === 1 || code === 2 || code === 3) return value.length === 2 && typeof value[1] === "number";
|
|
15
|
+
if (code === 4) return value.length === 2 && isCompactAttrPairs(value[1]);
|
|
16
|
+
if (code === 5) return value.length === 3 && typeof value[1] === "number" && typeof value[2] === "number";
|
|
17
|
+
if (code === 0) return value.length === 4 && typeof value[1] === "number" && isCompactAttrPairs(value[2]) && Array.isArray(value[3]) && value[3].every(isCompactXmlNode);
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const CompactXmlNodeSchema = z.custom(isCompactXmlNode);
|
|
21
|
+
const CompactPartSchema = z.union([z.array(CompactXmlNodeSchema), z.number()]);
|
|
22
|
+
const CompactPackageSchema = z.object({
|
|
23
|
+
s: z.array(z.string()),
|
|
24
|
+
p: z.record(z.string(), CompactPartSchema)
|
|
25
|
+
});
|
|
26
|
+
var StringTable = class {
|
|
27
|
+
indices = /* @__PURE__ */ new Map();
|
|
28
|
+
strings = [];
|
|
29
|
+
intern(value) {
|
|
30
|
+
const existing = this.indices.get(value);
|
|
31
|
+
if (existing !== void 0) return existing;
|
|
32
|
+
const index = this.strings.length;
|
|
33
|
+
this.indices.set(value, index);
|
|
34
|
+
this.strings.push(value);
|
|
35
|
+
return index;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
function encodeAttrs(attributes, table) {
|
|
39
|
+
const pairs = [];
|
|
40
|
+
for (const attribute of attributes) pairs.push(table.intern(attribute.name), table.intern(attribute.value));
|
|
41
|
+
return pairs;
|
|
42
|
+
}
|
|
43
|
+
function encodeNode(node, table) {
|
|
44
|
+
switch (node.type) {
|
|
45
|
+
case "text": return [1, table.intern(node.value)];
|
|
46
|
+
case "cdata": return [2, table.intern(node.value)];
|
|
47
|
+
case "comment": return [3, table.intern(node.value)];
|
|
48
|
+
case "declaration": return [4, encodeAttrs(node.attributes, table)];
|
|
49
|
+
case "pi": return [
|
|
50
|
+
5,
|
|
51
|
+
table.intern(node.target),
|
|
52
|
+
table.intern(node.content)
|
|
53
|
+
];
|
|
54
|
+
case "element": return [
|
|
55
|
+
0,
|
|
56
|
+
table.intern(node.tag),
|
|
57
|
+
encodeAttrs(node.attributes, table),
|
|
58
|
+
node.children.map((child) => encodeNode(child, table))
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function packageToCompact(pkg) {
|
|
63
|
+
const table = new StringTable();
|
|
64
|
+
const p = {};
|
|
65
|
+
for (const [path, part] of Object.entries(pkg.parts)) p[path] = part.kind === "binary" ? table.intern(part.base64) : part.nodes.map((node) => encodeNode(node, table));
|
|
66
|
+
return {
|
|
67
|
+
s: table.strings,
|
|
68
|
+
p
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function stringAt(strings, index) {
|
|
72
|
+
const value = strings[index];
|
|
73
|
+
if (value === void 0) throw new Error(`fromCompact: string table index ${index} is out of range`);
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
function decodeAttrs(pairs, strings) {
|
|
77
|
+
const attributes = [];
|
|
78
|
+
for (let i = 0; i < pairs.length; i += 2) {
|
|
79
|
+
const nameIdx = pairs[i];
|
|
80
|
+
const valueIdx = pairs[i + 1];
|
|
81
|
+
if (nameIdx === void 0 || valueIdx === void 0) throw new Error("fromCompact: attribute index pairs array has odd length");
|
|
82
|
+
attributes.push({
|
|
83
|
+
name: stringAt(strings, nameIdx),
|
|
84
|
+
value: stringAt(strings, valueIdx)
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return attributes;
|
|
88
|
+
}
|
|
89
|
+
function decodeNode(node, strings) {
|
|
90
|
+
switch (node[0]) {
|
|
91
|
+
case 1: return {
|
|
92
|
+
type: "text",
|
|
93
|
+
value: stringAt(strings, node[1])
|
|
94
|
+
};
|
|
95
|
+
case 2: return {
|
|
96
|
+
type: "cdata",
|
|
97
|
+
value: stringAt(strings, node[1])
|
|
98
|
+
};
|
|
99
|
+
case 3: return {
|
|
100
|
+
type: "comment",
|
|
101
|
+
value: stringAt(strings, node[1])
|
|
102
|
+
};
|
|
103
|
+
case 4: return {
|
|
104
|
+
type: "declaration",
|
|
105
|
+
attributes: decodeAttrs(node[1], strings)
|
|
106
|
+
};
|
|
107
|
+
case 5: return {
|
|
108
|
+
type: "pi",
|
|
109
|
+
target: stringAt(strings, node[1]),
|
|
110
|
+
content: stringAt(strings, node[2])
|
|
111
|
+
};
|
|
112
|
+
case 0: return {
|
|
113
|
+
type: "element",
|
|
114
|
+
tag: stringAt(strings, node[1]),
|
|
115
|
+
attributes: decodeAttrs(node[2], strings),
|
|
116
|
+
children: node[3].map((child) => decodeNode(child, strings))
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function compactToPackage(cpkg) {
|
|
121
|
+
const parts = {};
|
|
122
|
+
for (const [path, part] of Object.entries(cpkg.p)) parts[path] = typeof part === "number" ? {
|
|
123
|
+
kind: "binary",
|
|
124
|
+
base64: stringAt(cpkg.s, part)
|
|
125
|
+
} : {
|
|
126
|
+
kind: "xml",
|
|
127
|
+
nodes: part.map((node) => decodeNode(node, cpkg.s))
|
|
128
|
+
};
|
|
129
|
+
return { parts };
|
|
130
|
+
}
|
|
131
|
+
const compactCodec = z.codec(PackageSchema, CompactPackageSchema, {
|
|
132
|
+
decode: (pkg) => packageToCompact(pkg),
|
|
133
|
+
encode: (cpkg) => compactToPackage(cpkg)
|
|
134
|
+
});
|
|
135
|
+
function toCompact(pkg) {
|
|
136
|
+
return z.decode(compactCodec, pkg);
|
|
137
|
+
}
|
|
138
|
+
function fromCompact(cpkg) {
|
|
139
|
+
return z.encode(compactCodec, cpkg);
|
|
140
|
+
}
|
|
141
|
+
const compactPackageCodec = z.codec(z.instanceof(Uint8Array), CompactPackageSchema, {
|
|
142
|
+
decode: (bytes) => toCompact(decodePackage(bytes)),
|
|
143
|
+
encode: (cpkg) => encodePackage(fromCompact(cpkg))
|
|
144
|
+
});
|
|
145
|
+
function decodeCompactPackage(bytes) {
|
|
146
|
+
return z.decode(compactPackageCodec, bytes);
|
|
147
|
+
}
|
|
148
|
+
function encodeCompactPackage(cpkg) {
|
|
149
|
+
return z.encode(compactPackageCodec, cpkg);
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { CompactPackageSchema, CompactPartSchema, CompactXmlNodeSchema, compactCodec, compactPackageCodec, decodeCompactPackage, encodeCompactPackage, fromCompact, isCompactXmlNode, toCompact };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/image/sniff.ts
|
|
3
|
+
const PNG_SIGNATURE = [
|
|
4
|
+
137,
|
|
5
|
+
80,
|
|
6
|
+
78,
|
|
7
|
+
71,
|
|
8
|
+
13,
|
|
9
|
+
10,
|
|
10
|
+
26,
|
|
11
|
+
10
|
|
12
|
+
];
|
|
13
|
+
const JPEG_SIGNATURE = [
|
|
14
|
+
255,
|
|
15
|
+
216,
|
|
16
|
+
255
|
|
17
|
+
];
|
|
18
|
+
function startsWith(bytes, signature) {
|
|
19
|
+
if (bytes.length < signature.length) return false;
|
|
20
|
+
for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
function sniffImageFormat(bytes) {
|
|
24
|
+
if (startsWith(bytes, PNG_SIGNATURE)) return "png";
|
|
25
|
+
if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.sniffImageFormat = sniffImageFormat;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/image/sniff.ts
|
|
2
|
+
const PNG_SIGNATURE = [
|
|
3
|
+
137,
|
|
4
|
+
80,
|
|
5
|
+
78,
|
|
6
|
+
71,
|
|
7
|
+
13,
|
|
8
|
+
10,
|
|
9
|
+
26,
|
|
10
|
+
10
|
|
11
|
+
];
|
|
12
|
+
const JPEG_SIGNATURE = [
|
|
13
|
+
255,
|
|
14
|
+
216,
|
|
15
|
+
255
|
|
16
|
+
];
|
|
17
|
+
function startsWith(bytes, signature) {
|
|
18
|
+
if (bytes.length < signature.length) return false;
|
|
19
|
+
for (let i = 0; i < signature.length; i++) if (bytes[i] !== signature[i]) return false;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
function sniffImageFormat(bytes) {
|
|
23
|
+
if (startsWith(bytes, PNG_SIGNATURE)) return "png";
|
|
24
|
+
if (startsWith(bytes, JPEG_SIGNATURE)) return "jpeg";
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { sniffImageFormat };
|