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,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,5 @@
1
+ //#region src/image/sniff.d.ts
2
+ type ImageFormat = 'png' | 'jpeg';
3
+ declare function sniffImageFormat(bytes: Uint8Array<ArrayBuffer>): ImageFormat | undefined;
4
+ //#endregion
5
+ export { ImageFormat, sniffImageFormat };
@@ -0,0 +1,5 @@
1
+ //#region src/image/sniff.d.ts
2
+ type ImageFormat = 'png' | 'jpeg';
3
+ declare function sniffImageFormat(bytes: Uint8Array<ArrayBuffer>): ImageFormat | undefined;
4
+ //#endregion
5
+ export { ImageFormat, 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 };