odf.js 1.12.0 → 1.13.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 (178) hide show
  1. package/README.md +39 -0
  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/image/sniff.cjs +28 -0
  7. package/dist/image/sniff.d.cts +5 -0
  8. package/dist/image/sniff.d.ts +5 -0
  9. package/dist/image/sniff.js +27 -0
  10. package/dist/index.cjs +156 -3242
  11. package/dist/index.d.cts +42 -679
  12. package/dist/index.d.ts +42 -679
  13. package/dist/index.js +42 -3129
  14. package/dist/manifest.cjs +252 -0
  15. package/dist/manifest.d.cts +41 -0
  16. package/dist/manifest.d.ts +41 -0
  17. package/dist/manifest.js +242 -0
  18. package/dist/media-type.cjs +27 -0
  19. package/dist/media-type.d.cts +20 -0
  20. package/dist/media-type.d.ts +20 -0
  21. package/dist/media-type.js +25 -0
  22. package/dist/mimetype.cjs +19 -0
  23. package/dist/mimetype.d.cts +7 -0
  24. package/dist/mimetype.d.ts +7 -0
  25. package/dist/mimetype.js +16 -0
  26. package/dist/model/node.cjs +67 -0
  27. package/dist/model/node.d.cts +2 -0
  28. package/dist/model/node.d.ts +2 -0
  29. package/dist/model/node.js +58 -0
  30. package/dist/model/package.cjs +19 -0
  31. package/dist/model/package.d.cts +114 -0
  32. package/dist/model/package.d.ts +114 -0
  33. package/dist/model/package.js +15 -0
  34. package/dist/node-CkBWRjNR.d.cts +83 -0
  35. package/dist/node-CkBWRjNR.d.ts +83 -0
  36. package/dist/ns.cjs +37 -0
  37. package/dist/ns.d.cts +32 -0
  38. package/dist/ns.d.ts +32 -0
  39. package/dist/ns.js +35 -0
  40. package/dist/package-io/read.cjs +35 -0
  41. package/dist/package-io/read.d.cts +5 -0
  42. package/dist/package-io/read.d.ts +5 -0
  43. package/dist/package-io/read.js +34 -0
  44. package/dist/package-io/write.cjs +36 -0
  45. package/dist/package-io/write.d.cts +7 -0
  46. package/dist/package-io/write.d.ts +7 -0
  47. package/dist/package-io/write.js +33 -0
  48. package/dist/styles/properties.cjs +286 -0
  49. package/dist/styles/properties.d.cts +45 -0
  50. package/dist/styles/properties.d.ts +45 -0
  51. package/dist/styles/properties.js +277 -0
  52. package/dist/styles/registry.cjs +212 -0
  53. package/dist/styles/registry.d.cts +37 -0
  54. package/dist/styles/registry.d.ts +37 -0
  55. package/dist/styles/registry.js +209 -0
  56. package/dist/styles/serialize.cjs +23 -0
  57. package/dist/styles/serialize.d.cts +7 -0
  58. package/dist/styles/serialize.d.ts +7 -0
  59. package/dist/styles/serialize.js +21 -0
  60. package/dist/styles/span.cjs +114 -0
  61. package/dist/styles/span.d.cts +5 -0
  62. package/dist/styles/span.d.ts +5 -0
  63. package/dist/styles/span.js +113 -0
  64. package/dist/typed/draw/shapes.cjs +314 -0
  65. package/dist/typed/draw/shapes.d.cts +14 -0
  66. package/dist/typed/draw/shapes.d.ts +14 -0
  67. package/dist/typed/draw/shapes.js +311 -0
  68. package/dist/typed/formula/read.cjs +48 -0
  69. package/dist/typed/formula/read.d.cts +12 -0
  70. package/dist/typed/formula/read.d.ts +12 -0
  71. package/dist/typed/formula/read.js +47 -0
  72. package/dist/typed/odb/read.cjs +112 -0
  73. package/dist/typed/odb/read.d.cts +17 -0
  74. package/dist/typed/odb/read.d.ts +17 -0
  75. package/dist/typed/odb/read.js +111 -0
  76. package/dist/typed/odg/read.cjs +30 -0
  77. package/dist/typed/odg/read.d.cts +10 -0
  78. package/dist/typed/odg/read.d.ts +10 -0
  79. package/dist/typed/odg/read.js +29 -0
  80. package/dist/typed/odm/read.cjs +37 -0
  81. package/dist/typed/odm/read.d.cts +15 -0
  82. package/dist/typed/odm/read.d.ts +15 -0
  83. package/dist/typed/odm/read.js +36 -0
  84. package/dist/typed/odp/read.cjs +39 -0
  85. package/dist/typed/odp/read.d.cts +10 -0
  86. package/dist/typed/odp/read.d.ts +10 -0
  87. package/dist/typed/odp/read.js +38 -0
  88. package/dist/typed/ods/read.cjs +318 -0
  89. package/dist/typed/ods/read.d.cts +10 -0
  90. package/dist/typed/ods/read.d.ts +10 -0
  91. package/dist/typed/ods/read.js +317 -0
  92. package/dist/typed/odt/read.cjs +112 -0
  93. package/dist/typed/odt/read.d.cts +10 -0
  94. package/dist/typed/odt/read.d.ts +10 -0
  95. package/dist/typed/odt/read.js +111 -0
  96. package/dist/typed/shared/a1.cjs +68 -0
  97. package/dist/typed/shared/a1.d.cts +18 -0
  98. package/dist/typed/shared/a1.d.ts +18 -0
  99. package/dist/typed/shared/a1.js +63 -0
  100. package/dist/typed/shared/cascade.cjs +102 -0
  101. package/dist/typed/shared/cascade.d.cts +22 -0
  102. package/dist/typed/shared/cascade.d.ts +22 -0
  103. package/dist/typed/shared/cascade.js +99 -0
  104. package/dist/typed/shared/color.cjs +14 -0
  105. package/dist/typed/shared/color.d.cts +6 -0
  106. package/dist/typed/shared/color.d.ts +6 -0
  107. package/dist/typed/shared/color.js +12 -0
  108. package/dist/typed/shared/geometry.cjs +79 -0
  109. package/dist/typed/shared/geometry.d.cts +12 -0
  110. package/dist/typed/shared/geometry.d.ts +12 -0
  111. package/dist/typed/shared/geometry.js +75 -0
  112. package/dist/typed/shared/masterpage.cjs +39 -0
  113. package/dist/typed/shared/masterpage.d.cts +8 -0
  114. package/dist/typed/shared/masterpage.d.ts +8 -0
  115. package/dist/typed/shared/masterpage.js +37 -0
  116. package/dist/typed/shared/metadata.cjs +42 -0
  117. package/dist/typed/shared/metadata.d.cts +7 -0
  118. package/dist/typed/shared/metadata.d.ts +7 -0
  119. package/dist/typed/shared/metadata.js +40 -0
  120. package/dist/typed/shared/paragraph.cjs +57 -0
  121. package/dist/typed/shared/paragraph.d.cts +7 -0
  122. package/dist/typed/shared/paragraph.d.ts +7 -0
  123. package/dist/typed/shared/paragraph.js +56 -0
  124. package/dist/typed/shared/path.cjs +261 -0
  125. package/dist/typed/shared/path.d.cts +34 -0
  126. package/dist/typed/shared/path.d.ts +34 -0
  127. package/dist/typed/shared/path.js +255 -0
  128. package/dist/typed/shared/style.cjs +8 -0
  129. package/dist/typed/shared/style.d.cts +2 -0
  130. package/dist/typed/shared/style.d.ts +2 -0
  131. package/dist/typed/shared/style.js +2 -0
  132. package/dist/typed/shared/table.cjs +84 -0
  133. package/dist/typed/shared/table.d.cts +7 -0
  134. package/dist/typed/shared/table.d.ts +7 -0
  135. package/dist/typed/shared/table.js +83 -0
  136. package/dist/typed/shared/text.cjs +43 -0
  137. package/dist/typed/shared/text.d.cts +8 -0
  138. package/dist/typed/shared/text.d.ts +8 -0
  139. package/dist/typed/shared/text.js +39 -0
  140. package/dist/typed/shared/transform.cjs +112 -0
  141. package/dist/typed/shared/transform.d.cts +26 -0
  142. package/dist/typed/shared/transform.d.ts +26 -0
  143. package/dist/typed/shared/transform.js +107 -0
  144. package/dist/typed/shared/units.cjs +35 -0
  145. package/dist/typed/shared/units.d.cts +2 -0
  146. package/dist/typed/shared/units.d.ts +2 -0
  147. package/dist/typed/shared/units.js +33 -0
  148. package/dist/units-7pCiECuP.d.cts +6 -0
  149. package/dist/units-7pCiECuP.d.ts +6 -0
  150. package/dist/util/base64.cjs +48 -0
  151. package/dist/util/base64.d.cts +5 -0
  152. package/dist/util/base64.d.ts +5 -0
  153. package/dist/util/base64.js +46 -0
  154. package/dist/xml/build.cjs +46 -0
  155. package/dist/xml/build.d.cts +5 -0
  156. package/dist/xml/build.d.ts +5 -0
  157. package/dist/xml/build.js +46 -0
  158. package/dist/xml/entities.cjs +19 -0
  159. package/dist/xml/entities.d.cts +5 -0
  160. package/dist/xml/entities.d.ts +5 -0
  161. package/dist/xml/entities.js +17 -0
  162. package/dist/xml/fragment.cjs +22 -0
  163. package/dist/xml/fragment.d.cts +6 -0
  164. package/dist/xml/fragment.d.ts +6 -0
  165. package/dist/xml/fragment.js +20 -0
  166. package/dist/xml/parse.cjs +88 -0
  167. package/dist/xml/parse.d.cts +5 -0
  168. package/dist/xml/parse.d.ts +5 -0
  169. package/dist/xml/parse.js +88 -0
  170. package/dist/xml/query.cjs +33 -0
  171. package/dist/xml/query.d.cts +9 -0
  172. package/dist/xml/query.d.ts +9 -0
  173. package/dist/xml/query.js +28 -0
  174. package/dist/zip.cjs +15 -0
  175. package/dist/zip.d.cts +9 -0
  176. package/dist/zip.d.ts +9 -0
  177. package/dist/zip.js +13 -0
  178. package/package.json +9 -1
@@ -0,0 +1,5 @@
1
+ import { d as XmlNode } from "../node-CkBWRjNR.cjs";
2
+ //#region src/xml/parse.d.ts
3
+ declare function parseXml(xml: string): XmlNode[];
4
+ //#endregion
5
+ export { parseXml };
@@ -0,0 +1,5 @@
1
+ import { d as XmlNode } from "../node-CkBWRjNR.js";
2
+ //#region src/xml/parse.d.ts
3
+ declare function parseXml(xml: string): XmlNode[];
4
+ //#endregion
5
+ export { parseXml };
@@ -0,0 +1,88 @@
1
+ import { XMLParser } from "fast-xml-parser";
2
+ //#region src/xml/parse.ts
3
+ const PARSER = new XMLParser({
4
+ preserveOrder: true,
5
+ attributeNamePrefix: "@_",
6
+ ignoreAttributes: false,
7
+ textNodeName: "#text",
8
+ cdataPropName: "__cdata",
9
+ commentPropName: "__comment",
10
+ processEntities: false,
11
+ parseTagValue: false,
12
+ trimValues: false
13
+ });
14
+ function parseXml(xml) {
15
+ return parseNodes(PARSER.parse(xml));
16
+ }
17
+ function isRecord(value) {
18
+ return typeof value === "object" && value !== null && !Array.isArray(value);
19
+ }
20
+ function isUnknownArray(value) {
21
+ return Array.isArray(value);
22
+ }
23
+ function asString(value) {
24
+ if (typeof value !== "string") throw new Error(`expected string while parsing XML, got ${typeof value}`);
25
+ return value;
26
+ }
27
+ function parseNodes(raw) {
28
+ if (!isUnknownArray(raw)) throw new Error("fast-xml-parser output was not an ordered array");
29
+ return raw.map(parseNode);
30
+ }
31
+ function parseNode(raw) {
32
+ if (!isRecord(raw)) throw new Error("fast-xml-parser node was not an object");
33
+ let tagKey;
34
+ for (const key of Object.keys(raw)) if (key !== ":@") {
35
+ if (tagKey !== void 0) throw new Error("XML node had multiple tag keys");
36
+ tagKey = key;
37
+ }
38
+ if (tagKey === void 0) throw new Error("XML node had no tag key");
39
+ const attributes = parseAttributes(raw[":@"]);
40
+ if (tagKey === "#text") return {
41
+ type: "text",
42
+ value: asString(raw["#text"])
43
+ };
44
+ if (tagKey === "__comment") return {
45
+ type: "comment",
46
+ value: scalarText(raw.__comment)
47
+ };
48
+ if (tagKey === "__cdata") return {
49
+ type: "cdata",
50
+ value: scalarText(raw.__cdata)
51
+ };
52
+ if (tagKey === "?xml") return {
53
+ type: "declaration",
54
+ attributes
55
+ };
56
+ if (tagKey.startsWith("?")) return {
57
+ type: "pi",
58
+ target: tagKey.slice(1),
59
+ content: scalarText(raw[tagKey])
60
+ };
61
+ return {
62
+ type: "element",
63
+ tag: tagKey,
64
+ attributes,
65
+ children: parseNodes(raw[tagKey])
66
+ };
67
+ }
68
+ function parseAttributes(raw) {
69
+ if (raw === void 0) return [];
70
+ if (!isRecord(raw)) throw new Error("XML attributes were not an object");
71
+ const attrs = [];
72
+ for (const key of Object.keys(raw)) {
73
+ if (!key.startsWith("@_")) throw new Error(`unexpected attribute key without @_ prefix: ${key}`);
74
+ attrs.push({
75
+ name: key.slice(2),
76
+ value: asString(raw[key])
77
+ });
78
+ }
79
+ return attrs;
80
+ }
81
+ function scalarText(raw) {
82
+ if (!isUnknownArray(raw) || raw.length === 0) throw new Error("expected a scalar-text wrapper array");
83
+ const first = raw[0];
84
+ if (!isRecord(first)) throw new Error("scalar-text wrapper was not an object");
85
+ return asString(first["#text"]);
86
+ }
87
+ //#endregion
88
+ export { parseXml };
@@ -0,0 +1,33 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/xml/query.ts
3
+ function rootElement(nodes) {
4
+ for (const node of nodes) if (node.type === "element") return node;
5
+ }
6
+ function findChildElement(nodes, tag) {
7
+ for (const node of nodes) if (node.type === "element" && node.tag === tag) return node;
8
+ }
9
+ function childrenWithTag(element, tag) {
10
+ const out = [];
11
+ for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
12
+ return out;
13
+ }
14
+ function* walk(nodes) {
15
+ for (const node of nodes) {
16
+ yield node;
17
+ if (node.type === "element") yield* walk(node.children);
18
+ }
19
+ }
20
+ function elementsWithTag(nodes, tag) {
21
+ const out = [];
22
+ for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
23
+ return out;
24
+ }
25
+ function attrValue(element, name) {
26
+ return element.attributes.find((attribute) => attribute.name === name)?.value;
27
+ }
28
+ //#endregion
29
+ exports.attrValue = attrValue;
30
+ exports.childrenWithTag = childrenWithTag;
31
+ exports.elementsWithTag = elementsWithTag;
32
+ exports.findChildElement = findChildElement;
33
+ exports.rootElement = rootElement;
@@ -0,0 +1,9 @@
1
+ import { d as XmlNode, l as XmlElement } from "../node-CkBWRjNR.cjs";
2
+ //#region src/xml/query.d.ts
3
+ declare function rootElement(nodes: readonly XmlNode[]): XmlElement | undefined;
4
+ declare function findChildElement(nodes: readonly XmlNode[], tag: string): XmlElement | undefined;
5
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
6
+ declare function elementsWithTag(nodes: readonly XmlNode[], tag: string): XmlElement[];
7
+ declare function attrValue(element: XmlElement, name: string): string | undefined;
8
+ //#endregion
9
+ export { attrValue, childrenWithTag, elementsWithTag, findChildElement, rootElement };
@@ -0,0 +1,9 @@
1
+ import { d as XmlNode, l as XmlElement } from "../node-CkBWRjNR.js";
2
+ //#region src/xml/query.d.ts
3
+ declare function rootElement(nodes: readonly XmlNode[]): XmlElement | undefined;
4
+ declare function findChildElement(nodes: readonly XmlNode[], tag: string): XmlElement | undefined;
5
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
6
+ declare function elementsWithTag(nodes: readonly XmlNode[], tag: string): XmlElement[];
7
+ declare function attrValue(element: XmlElement, name: string): string | undefined;
8
+ //#endregion
9
+ export { attrValue, childrenWithTag, elementsWithTag, findChildElement, rootElement };
@@ -0,0 +1,28 @@
1
+ //#region src/xml/query.ts
2
+ function rootElement(nodes) {
3
+ for (const node of nodes) if (node.type === "element") return node;
4
+ }
5
+ function findChildElement(nodes, tag) {
6
+ for (const node of nodes) if (node.type === "element" && node.tag === tag) return node;
7
+ }
8
+ function childrenWithTag(element, tag) {
9
+ const out = [];
10
+ for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
11
+ return out;
12
+ }
13
+ function* walk(nodes) {
14
+ for (const node of nodes) {
15
+ yield node;
16
+ if (node.type === "element") yield* walk(node.children);
17
+ }
18
+ }
19
+ function elementsWithTag(nodes, tag) {
20
+ const out = [];
21
+ for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
22
+ return out;
23
+ }
24
+ function attrValue(element, name) {
25
+ return element.attributes.find((attribute) => attribute.name === name)?.value;
26
+ }
27
+ //#endregion
28
+ export { attrValue, childrenWithTag, elementsWithTag, findChildElement, rootElement };
package/dist/zip.cjs ADDED
@@ -0,0 +1,15 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let fflate = require("fflate");
3
+ //#region src/zip.ts
4
+ function unzipPackage(bytes) {
5
+ return (0, fflate.unzipSync)(bytes);
6
+ }
7
+ function zipPackage(entries) {
8
+ const data = {};
9
+ for (const [path, entry] of entries) if (entry.stored === true) data[path] = [entry.bytes, { level: 0 }];
10
+ else data[path] = entry.bytes;
11
+ return (0, fflate.zipSync)(data);
12
+ }
13
+ //#endregion
14
+ exports.unzipPackage = unzipPackage;
15
+ exports.zipPackage = zipPackage;
package/dist/zip.d.cts ADDED
@@ -0,0 +1,9 @@
1
+ //#region src/zip.d.ts
2
+ interface ZipEntry {
3
+ readonly bytes: Uint8Array<ArrayBuffer>;
4
+ readonly stored?: boolean;
5
+ }
6
+ declare function unzipPackage(bytes: Uint8Array<ArrayBuffer>): Record<string, Uint8Array<ArrayBuffer>>;
7
+ declare function zipPackage(entries: readonly (readonly [string, ZipEntry])[]): Uint8Array<ArrayBuffer>;
8
+ //#endregion
9
+ export { ZipEntry, unzipPackage, zipPackage };
package/dist/zip.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ //#region src/zip.d.ts
2
+ interface ZipEntry {
3
+ readonly bytes: Uint8Array<ArrayBuffer>;
4
+ readonly stored?: boolean;
5
+ }
6
+ declare function unzipPackage(bytes: Uint8Array<ArrayBuffer>): Record<string, Uint8Array<ArrayBuffer>>;
7
+ declare function zipPackage(entries: readonly (readonly [string, ZipEntry])[]): Uint8Array<ArrayBuffer>;
8
+ //#endregion
9
+ export { ZipEntry, unzipPackage, zipPackage };
package/dist/zip.js ADDED
@@ -0,0 +1,13 @@
1
+ import { unzipSync, zipSync } from "fflate";
2
+ //#region src/zip.ts
3
+ function unzipPackage(bytes) {
4
+ return unzipSync(bytes);
5
+ }
6
+ function zipPackage(entries) {
7
+ const data = {};
8
+ for (const [path, entry] of entries) if (entry.stored === true) data[path] = [entry.bytes, { level: 0 }];
9
+ else data[path] = entry.bytes;
10
+ return zipSync(data);
11
+ }
12
+ //#endregion
13
+ export { unzipPackage, zipPackage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "odf.js",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Type-safe, lossless round-trip conversion between OpenDocument Format packages (odt, ods, odp) and JSON, hand-written and dependency-minimal, built on Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -19,6 +19,14 @@
19
19
  },
20
20
  "import": "./dist/index.js",
21
21
  "require": "./dist/index.cjs"
22
+ },
23
+ "./*": {
24
+ "types": {
25
+ "import": "./dist/*.d.ts",
26
+ "require": "./dist/*.d.cts"
27
+ },
28
+ "import": "./dist/*.js",
29
+ "require": "./dist/*.cjs"
22
30
  }
23
31
  },
24
32
  "main": "./dist/index.cjs",