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
package/dist/ns.d.cts ADDED
@@ -0,0 +1,32 @@
1
+ //#region src/ns.d.ts
2
+ declare const ODF_NAMESPACES: Readonly<{
3
+ office: "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
4
+ style: "urn:oasis:names:tc:opendocument:xmlns:style:1.0";
5
+ text: "urn:oasis:names:tc:opendocument:xmlns:text:1.0";
6
+ table: "urn:oasis:names:tc:opendocument:xmlns:table:1.0";
7
+ draw: "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0";
8
+ fo: "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0";
9
+ svg: "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0";
10
+ xlink: "http://www.w3.org/1999/xlink";
11
+ dc: "http://purl.org/dc/elements/1.1/";
12
+ meta: "urn:oasis:names:tc:opendocument:xmlns:meta:1.0";
13
+ number: "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0";
14
+ chart: "urn:oasis:names:tc:opendocument:xmlns:chart:1.0";
15
+ dr3d: "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0";
16
+ math: "http://www.w3.org/1998/Math/MathML";
17
+ form: "urn:oasis:names:tc:opendocument:xmlns:form:1.0";
18
+ script: "urn:oasis:names:tc:opendocument:xmlns:script:1.0";
19
+ config: "urn:oasis:names:tc:opendocument:xmlns:config:1.0";
20
+ presentation: "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0";
21
+ smil: "urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0";
22
+ anim: "urn:oasis:names:tc:opendocument:xmlns:animation:1.0";
23
+ xforms: "http://www.w3.org/2002/xforms";
24
+ xsd: "http://www.w3.org/2001/XMLSchema";
25
+ xsi: "http://www.w3.org/2001/XMLSchema-instance";
26
+ manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0";
27
+ db: "urn:oasis:names:tc:opendocument:xmlns:database:1.0";
28
+ }>;
29
+ type OdfNamespacePrefix = keyof typeof ODF_NAMESPACES;
30
+ declare function xmlnsAttributes(prefixes: readonly OdfNamespacePrefix[]): Record<string, string>;
31
+ //#endregion
32
+ export { ODF_NAMESPACES, OdfNamespacePrefix, xmlnsAttributes };
package/dist/ns.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ //#region src/ns.d.ts
2
+ declare const ODF_NAMESPACES: Readonly<{
3
+ office: "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
4
+ style: "urn:oasis:names:tc:opendocument:xmlns:style:1.0";
5
+ text: "urn:oasis:names:tc:opendocument:xmlns:text:1.0";
6
+ table: "urn:oasis:names:tc:opendocument:xmlns:table:1.0";
7
+ draw: "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0";
8
+ fo: "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0";
9
+ svg: "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0";
10
+ xlink: "http://www.w3.org/1999/xlink";
11
+ dc: "http://purl.org/dc/elements/1.1/";
12
+ meta: "urn:oasis:names:tc:opendocument:xmlns:meta:1.0";
13
+ number: "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0";
14
+ chart: "urn:oasis:names:tc:opendocument:xmlns:chart:1.0";
15
+ dr3d: "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0";
16
+ math: "http://www.w3.org/1998/Math/MathML";
17
+ form: "urn:oasis:names:tc:opendocument:xmlns:form:1.0";
18
+ script: "urn:oasis:names:tc:opendocument:xmlns:script:1.0";
19
+ config: "urn:oasis:names:tc:opendocument:xmlns:config:1.0";
20
+ presentation: "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0";
21
+ smil: "urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0";
22
+ anim: "urn:oasis:names:tc:opendocument:xmlns:animation:1.0";
23
+ xforms: "http://www.w3.org/2002/xforms";
24
+ xsd: "http://www.w3.org/2001/XMLSchema";
25
+ xsi: "http://www.w3.org/2001/XMLSchema-instance";
26
+ manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0";
27
+ db: "urn:oasis:names:tc:opendocument:xmlns:database:1.0";
28
+ }>;
29
+ type OdfNamespacePrefix = keyof typeof ODF_NAMESPACES;
30
+ declare function xmlnsAttributes(prefixes: readonly OdfNamespacePrefix[]): Record<string, string>;
31
+ //#endregion
32
+ export { ODF_NAMESPACES, OdfNamespacePrefix, xmlnsAttributes };
package/dist/ns.js ADDED
@@ -0,0 +1,35 @@
1
+ //#region src/ns.ts
2
+ const ODF_NAMESPACES = Object.freeze({
3
+ office: "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
4
+ style: "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
5
+ text: "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
6
+ table: "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
7
+ draw: "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0",
8
+ fo: "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
9
+ svg: "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0",
10
+ xlink: "http://www.w3.org/1999/xlink",
11
+ dc: "http://purl.org/dc/elements/1.1/",
12
+ meta: "urn:oasis:names:tc:opendocument:xmlns:meta:1.0",
13
+ number: "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0",
14
+ chart: "urn:oasis:names:tc:opendocument:xmlns:chart:1.0",
15
+ dr3d: "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0",
16
+ math: "http://www.w3.org/1998/Math/MathML",
17
+ form: "urn:oasis:names:tc:opendocument:xmlns:form:1.0",
18
+ script: "urn:oasis:names:tc:opendocument:xmlns:script:1.0",
19
+ config: "urn:oasis:names:tc:opendocument:xmlns:config:1.0",
20
+ presentation: "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0",
21
+ smil: "urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0",
22
+ anim: "urn:oasis:names:tc:opendocument:xmlns:animation:1.0",
23
+ xforms: "http://www.w3.org/2002/xforms",
24
+ xsd: "http://www.w3.org/2001/XMLSchema",
25
+ xsi: "http://www.w3.org/2001/XMLSchema-instance",
26
+ manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",
27
+ db: "urn:oasis:names:tc:opendocument:xmlns:database:1.0"
28
+ });
29
+ function xmlnsAttributes(prefixes) {
30
+ const attrs = {};
31
+ for (const prefix of prefixes) attrs[`xmlns:${prefix}`] = ODF_NAMESPACES[prefix];
32
+ return attrs;
33
+ }
34
+ //#endregion
35
+ export { ODF_NAMESPACES, xmlnsAttributes };
@@ -0,0 +1,35 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_util_base64 = require("../util/base64.cjs");
3
+ const require_xml_parse = require("../xml/parse.cjs");
4
+ const require_zip = require("../zip.cjs");
5
+ //#region src/package-io/read.ts
6
+ function parsePackage(bytes) {
7
+ const entries = require_zip.unzipPackage(bytes);
8
+ const parts = {};
9
+ for (const [path, partBytes] of Object.entries(entries)) if (looksLikeXml(partBytes)) {
10
+ const xml = new TextDecoder("utf-8").decode(partBytes);
11
+ parts[path] = {
12
+ kind: "xml",
13
+ nodes: require_xml_parse.parseXml(xml)
14
+ };
15
+ } else parts[path] = {
16
+ kind: "binary",
17
+ base64: require_util_base64.bytesToBase64(partBytes)
18
+ };
19
+ return { parts };
20
+ }
21
+ function looksLikeXml(bytes) {
22
+ let i = 0;
23
+ if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) i = 3;
24
+ while (i < bytes.length) {
25
+ const b = bytes[i];
26
+ if (b === 32 || b === 9 || b === 10 || b === 13) {
27
+ i = i + 1;
28
+ continue;
29
+ }
30
+ return b === 60;
31
+ }
32
+ return false;
33
+ }
34
+ //#endregion
35
+ exports.parsePackage = parsePackage;
@@ -0,0 +1,5 @@
1
+ import { Package } from "../model/package.cjs";
2
+ //#region src/package-io/read.d.ts
3
+ declare function parsePackage(bytes: Uint8Array<ArrayBuffer>): Package;
4
+ //#endregion
5
+ export { parsePackage };
@@ -0,0 +1,5 @@
1
+ import { Package } from "../model/package.js";
2
+ //#region src/package-io/read.d.ts
3
+ declare function parsePackage(bytes: Uint8Array<ArrayBuffer>): Package;
4
+ //#endregion
5
+ export { parsePackage };
@@ -0,0 +1,34 @@
1
+ import { bytesToBase64 } from "../util/base64.js";
2
+ import { parseXml } from "../xml/parse.js";
3
+ import { unzipPackage } from "../zip.js";
4
+ //#region src/package-io/read.ts
5
+ function parsePackage(bytes) {
6
+ const entries = unzipPackage(bytes);
7
+ const parts = {};
8
+ for (const [path, partBytes] of Object.entries(entries)) if (looksLikeXml(partBytes)) {
9
+ const xml = new TextDecoder("utf-8").decode(partBytes);
10
+ parts[path] = {
11
+ kind: "xml",
12
+ nodes: parseXml(xml)
13
+ };
14
+ } else parts[path] = {
15
+ kind: "binary",
16
+ base64: bytesToBase64(partBytes)
17
+ };
18
+ return { parts };
19
+ }
20
+ function looksLikeXml(bytes) {
21
+ let i = 0;
22
+ if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) i = 3;
23
+ while (i < bytes.length) {
24
+ const b = bytes[i];
25
+ if (b === 32 || b === 9 || b === 10 || b === 13) {
26
+ i = i + 1;
27
+ continue;
28
+ }
29
+ return b === 60;
30
+ }
31
+ return false;
32
+ }
33
+ //#endregion
34
+ export { parsePackage };
@@ -0,0 +1,36 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_util_base64 = require("../util/base64.cjs");
3
+ const require_zip = require("../zip.cjs");
4
+ const require_xml_build = require("../xml/build.cjs");
5
+ //#region src/package-io/write.ts
6
+ const MIMETYPE_PART = "mimetype";
7
+ const MANIFEST_PART = "META-INF/manifest.xml";
8
+ function serializePackage(pkg) {
9
+ const remaining = new Map(Object.entries(pkg.parts));
10
+ const entries = [];
11
+ const mimetype = remaining.get(MIMETYPE_PART);
12
+ if (mimetype !== void 0) {
13
+ entries.push([MIMETYPE_PART, {
14
+ bytes: partToBytes(mimetype),
15
+ stored: true
16
+ }]);
17
+ remaining.delete(MIMETYPE_PART);
18
+ }
19
+ const manifest = remaining.get(MANIFEST_PART);
20
+ if (manifest !== void 0) {
21
+ entries.push([MANIFEST_PART, { bytes: partToBytes(manifest) }]);
22
+ remaining.delete(MANIFEST_PART);
23
+ }
24
+ for (const [path, part] of remaining) entries.push([path, { bytes: partToBytes(part) }]);
25
+ return require_zip.zipPackage(entries);
26
+ }
27
+ function partToBytes(part) {
28
+ switch (part.kind) {
29
+ case "xml": return new TextEncoder().encode(require_xml_build.buildXml(part.nodes));
30
+ case "binary": return require_util_base64.base64ToBytes(part.base64);
31
+ }
32
+ }
33
+ //#endregion
34
+ exports.MANIFEST_PART = MANIFEST_PART;
35
+ exports.MIMETYPE_PART = MIMETYPE_PART;
36
+ exports.serializePackage = serializePackage;
@@ -0,0 +1,7 @@
1
+ import { Package } from "../model/package.cjs";
2
+ //#region src/package-io/write.d.ts
3
+ declare const MIMETYPE_PART = "mimetype";
4
+ declare const MANIFEST_PART = "META-INF/manifest.xml";
5
+ declare function serializePackage(pkg: Package): Uint8Array<ArrayBuffer>;
6
+ //#endregion
7
+ export { MANIFEST_PART, MIMETYPE_PART, serializePackage };
@@ -0,0 +1,7 @@
1
+ import { Package } from "../model/package.js";
2
+ //#region src/package-io/write.d.ts
3
+ declare const MIMETYPE_PART = "mimetype";
4
+ declare const MANIFEST_PART = "META-INF/manifest.xml";
5
+ declare function serializePackage(pkg: Package): Uint8Array<ArrayBuffer>;
6
+ //#endregion
7
+ export { MANIFEST_PART, MIMETYPE_PART, serializePackage };
@@ -0,0 +1,33 @@
1
+ import { base64ToBytes } from "../util/base64.js";
2
+ import { zipPackage } from "../zip.js";
3
+ import { buildXml } from "../xml/build.js";
4
+ //#region src/package-io/write.ts
5
+ const MIMETYPE_PART = "mimetype";
6
+ const MANIFEST_PART = "META-INF/manifest.xml";
7
+ function serializePackage(pkg) {
8
+ const remaining = new Map(Object.entries(pkg.parts));
9
+ const entries = [];
10
+ const mimetype = remaining.get(MIMETYPE_PART);
11
+ if (mimetype !== void 0) {
12
+ entries.push([MIMETYPE_PART, {
13
+ bytes: partToBytes(mimetype),
14
+ stored: true
15
+ }]);
16
+ remaining.delete(MIMETYPE_PART);
17
+ }
18
+ const manifest = remaining.get(MANIFEST_PART);
19
+ if (manifest !== void 0) {
20
+ entries.push([MANIFEST_PART, { bytes: partToBytes(manifest) }]);
21
+ remaining.delete(MANIFEST_PART);
22
+ }
23
+ for (const [path, part] of remaining) entries.push([path, { bytes: partToBytes(part) }]);
24
+ return zipPackage(entries);
25
+ }
26
+ function partToBytes(part) {
27
+ switch (part.kind) {
28
+ case "xml": return new TextEncoder().encode(buildXml(part.nodes));
29
+ case "binary": return base64ToBytes(part.base64);
30
+ }
31
+ }
32
+ //#endregion
33
+ export { MANIFEST_PART, MIMETYPE_PART, serializePackage };
@@ -0,0 +1,286 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_entities = require("../xml/entities.cjs");
3
+ const require_typed_shared_units = require("../typed/shared/units.cjs");
4
+ const require_typed_shared_color = require("../typed/shared/color.cjs");
5
+ let zod = require("zod");
6
+ let document_schema_js = require("document-schema.js");
7
+ //#region src/styles/properties.ts
8
+ const StylePropertiesSchema = zod.z.object({
9
+ bold: zod.z.boolean().optional(),
10
+ italic: zod.z.boolean().optional(),
11
+ underline: zod.z.boolean().optional(),
12
+ strike: zod.z.boolean().optional(),
13
+ fontFamily: zod.z.string().optional(),
14
+ sizePt: zod.z.number().optional(),
15
+ color: document_schema_js.ColorSchema.optional(),
16
+ alignment: document_schema_js.AlignmentSchema.optional(),
17
+ spacingBeforePt: zod.z.number().optional(),
18
+ spacingAfterPt: zod.z.number().optional(),
19
+ lineSpacing: zod.z.number().optional(),
20
+ indentLeftPt: zod.z.number().optional(),
21
+ indentFirstLinePt: zod.z.number().optional()
22
+ });
23
+ const ATTR = {
24
+ fontWeight: "fo:font-weight",
25
+ fontStyle: "fo:font-style",
26
+ underlineStyle: "style:text-underline-style",
27
+ underlineWidth: "style:text-underline-width",
28
+ underlineColor: "style:text-underline-color",
29
+ lineThroughStyle: "style:text-line-through-style",
30
+ lineThroughType: "style:text-line-through-type",
31
+ fontFamily: "fo:font-family",
32
+ fontSize: "fo:font-size",
33
+ color: "fo:color",
34
+ textAlign: "fo:text-align",
35
+ marginTop: "fo:margin-top",
36
+ marginBottom: "fo:margin-bottom",
37
+ lineHeight: "fo:line-height",
38
+ marginLeft: "fo:margin-left",
39
+ textIndent: "fo:text-indent"
40
+ };
41
+ const TEXT_ATTR_NAMES = /* @__PURE__ */ new Set([
42
+ ATTR.fontWeight,
43
+ ATTR.fontStyle,
44
+ ATTR.underlineStyle,
45
+ ATTR.underlineWidth,
46
+ ATTR.underlineColor,
47
+ ATTR.lineThroughStyle,
48
+ ATTR.lineThroughType,
49
+ ATTR.fontFamily,
50
+ ATTR.fontSize,
51
+ ATTR.color
52
+ ]);
53
+ const PARAGRAPH_ATTR_NAMES = /* @__PURE__ */ new Set([
54
+ ATTR.textAlign,
55
+ ATTR.marginTop,
56
+ ATTR.marginBottom,
57
+ ATTR.lineHeight,
58
+ ATTR.marginLeft,
59
+ ATTR.textIndent
60
+ ]);
61
+ function attributeMap(element) {
62
+ const map = /* @__PURE__ */ new Map();
63
+ for (const attribute of element.attributes) map.set(attribute.name, attribute.value);
64
+ return map;
65
+ }
66
+ function formatPt(valuePt) {
67
+ return require_typed_shared_units.formatOdfLength(valuePt, "pt");
68
+ }
69
+ const PERCENTAGE_PATTERN = /^(-?(?:\d+(?:\.\d+)?|\.\d+))%$/;
70
+ function parsePercentageMultiplier(value) {
71
+ const match = PERCENTAGE_PATTERN.exec(value);
72
+ if (match === null) return;
73
+ const numeric = match[1];
74
+ if (numeric === void 0) return;
75
+ return Number(numeric) / 100;
76
+ }
77
+ function formatPercentageMultiplier(multiplier) {
78
+ return `${multiplier * 100}%`;
79
+ }
80
+ function parseLineDecoration(style, companionA, companionAOnValue, companionB, companionBOnValue) {
81
+ if (style === void 0 && companionA === void 0 && companionB === void 0) return;
82
+ if (style === "solid" && (companionA === void 0 || companionA === companionAOnValue) && (companionB === void 0 || companionB === companionBOnValue)) return true;
83
+ if (style === "none" && companionA === void 0 && companionB === void 0) return false;
84
+ return "unknown";
85
+ }
86
+ const RISKY_STYLE_ELEMENT_ATTRS = /* @__PURE__ */ new Set(["style:master-page-name", "style:next-style-name"]);
87
+ function parseTextProperties(element) {
88
+ const attrs = attributeMap(element);
89
+ const properties = {};
90
+ let hasUnknown = false;
91
+ for (const name of attrs.keys()) if (!TEXT_ATTR_NAMES.has(name)) hasUnknown = true;
92
+ const fontWeight = attrs.get(ATTR.fontWeight);
93
+ if (fontWeight === "bold") properties.bold = true;
94
+ else if (fontWeight === "normal") properties.bold = false;
95
+ else if (fontWeight !== void 0) hasUnknown = true;
96
+ const fontStyle = attrs.get(ATTR.fontStyle);
97
+ if (fontStyle === "italic") properties.italic = true;
98
+ else if (fontStyle === "normal") properties.italic = false;
99
+ else if (fontStyle !== void 0) hasUnknown = true;
100
+ const underline = parseLineDecoration(attrs.get(ATTR.underlineStyle), attrs.get(ATTR.underlineWidth), "auto", attrs.get(ATTR.underlineColor), "font-color");
101
+ if (underline === "unknown") hasUnknown = true;
102
+ else if (underline !== void 0) properties.underline = underline;
103
+ const strike = parseLineDecoration(attrs.get(ATTR.lineThroughStyle), attrs.get(ATTR.lineThroughType), "single", void 0, "");
104
+ if (strike === "unknown") hasUnknown = true;
105
+ else if (strike !== void 0) properties.strike = strike;
106
+ const fontFamily = attrs.get(ATTR.fontFamily);
107
+ if (fontFamily !== void 0) properties.fontFamily = fontFamily;
108
+ const fontSize = attrs.get(ATTR.fontSize);
109
+ if (fontSize !== void 0) {
110
+ const pt = require_typed_shared_units.parseOdfLength(fontSize);
111
+ if (pt === void 0) hasUnknown = true;
112
+ else properties.sizePt = pt;
113
+ }
114
+ const color = attrs.get(ATTR.color);
115
+ if (color !== void 0) {
116
+ const parsed = require_typed_shared_color.parseOdfColor(color);
117
+ if (parsed === void 0) hasUnknown = true;
118
+ else properties.color = parsed;
119
+ }
120
+ return {
121
+ properties,
122
+ hasUnknown
123
+ };
124
+ }
125
+ function parseParagraphProperties(element) {
126
+ const attrs = attributeMap(element);
127
+ const properties = {};
128
+ let hasUnknown = false;
129
+ for (const name of attrs.keys()) if (!PARAGRAPH_ATTR_NAMES.has(name)) hasUnknown = true;
130
+ const textAlign = attrs.get(ATTR.textAlign);
131
+ if (textAlign === "left" || textAlign === "center" || textAlign === "right" || textAlign === "justify") properties.alignment = textAlign;
132
+ else if (textAlign !== void 0) hasUnknown = true;
133
+ const marginTop = attrs.get(ATTR.marginTop);
134
+ if (marginTop !== void 0) {
135
+ const pt = require_typed_shared_units.parseOdfLength(marginTop);
136
+ if (pt === void 0) hasUnknown = true;
137
+ else properties.spacingBeforePt = pt;
138
+ }
139
+ const marginBottom = attrs.get(ATTR.marginBottom);
140
+ if (marginBottom !== void 0) {
141
+ const pt = require_typed_shared_units.parseOdfLength(marginBottom);
142
+ if (pt === void 0) hasUnknown = true;
143
+ else properties.spacingAfterPt = pt;
144
+ }
145
+ const marginLeft = attrs.get(ATTR.marginLeft);
146
+ if (marginLeft !== void 0) {
147
+ const pt = require_typed_shared_units.parseOdfLength(marginLeft);
148
+ if (pt === void 0) hasUnknown = true;
149
+ else properties.indentLeftPt = pt;
150
+ }
151
+ const textIndent = attrs.get(ATTR.textIndent);
152
+ if (textIndent !== void 0) {
153
+ const pt = require_typed_shared_units.parseOdfLength(textIndent);
154
+ if (pt === void 0) hasUnknown = true;
155
+ else properties.indentFirstLinePt = pt;
156
+ }
157
+ const lineHeight = attrs.get(ATTR.lineHeight);
158
+ if (lineHeight !== void 0) {
159
+ const multiplier = parsePercentageMultiplier(lineHeight);
160
+ if (multiplier === void 0) hasUnknown = true;
161
+ else properties.lineSpacing = multiplier;
162
+ }
163
+ return {
164
+ properties,
165
+ hasUnknown
166
+ };
167
+ }
168
+ function parseStyleElementProperties(styleElement) {
169
+ let properties = {};
170
+ let hasUnknown = false;
171
+ for (const attribute of styleElement.attributes) if (RISKY_STYLE_ELEMENT_ATTRS.has(attribute.name)) hasUnknown = true;
172
+ for (const child of styleElement.children) {
173
+ if (child.type !== "element") continue;
174
+ if (child.tag === "style:text-properties") {
175
+ const result = parseTextProperties(child);
176
+ properties = {
177
+ ...properties,
178
+ ...result.properties
179
+ };
180
+ if (result.hasUnknown) hasUnknown = true;
181
+ } else if (child.tag === "style:paragraph-properties") {
182
+ const result = parseParagraphProperties(child);
183
+ properties = {
184
+ ...properties,
185
+ ...result.properties
186
+ };
187
+ if (result.hasUnknown) hasUnknown = true;
188
+ } else hasUnknown = true;
189
+ }
190
+ return {
191
+ properties,
192
+ hasUnknown
193
+ };
194
+ }
195
+ function textPropertiesToAttributes(properties) {
196
+ const attributes = [];
197
+ if (properties.bold !== void 0) attributes.push({
198
+ name: ATTR.fontWeight,
199
+ value: properties.bold ? "bold" : "normal"
200
+ });
201
+ if (properties.italic !== void 0) attributes.push({
202
+ name: ATTR.fontStyle,
203
+ value: properties.italic ? "italic" : "normal"
204
+ });
205
+ if (properties.underline !== void 0) if (properties.underline) {
206
+ attributes.push({
207
+ name: ATTR.underlineStyle,
208
+ value: "solid"
209
+ });
210
+ attributes.push({
211
+ name: ATTR.underlineWidth,
212
+ value: "auto"
213
+ });
214
+ attributes.push({
215
+ name: ATTR.underlineColor,
216
+ value: "font-color"
217
+ });
218
+ } else attributes.push({
219
+ name: ATTR.underlineStyle,
220
+ value: "none"
221
+ });
222
+ if (properties.strike !== void 0) if (properties.strike) {
223
+ attributes.push({
224
+ name: ATTR.lineThroughStyle,
225
+ value: "solid"
226
+ });
227
+ attributes.push({
228
+ name: ATTR.lineThroughType,
229
+ value: "single"
230
+ });
231
+ } else attributes.push({
232
+ name: ATTR.lineThroughStyle,
233
+ value: "none"
234
+ });
235
+ if (properties.fontFamily !== void 0) attributes.push({
236
+ name: ATTR.fontFamily,
237
+ value: require_xml_entities.encodeXmlText(properties.fontFamily)
238
+ });
239
+ if (properties.sizePt !== void 0) attributes.push({
240
+ name: ATTR.fontSize,
241
+ value: formatPt(properties.sizePt)
242
+ });
243
+ if (properties.color !== void 0) attributes.push({
244
+ name: ATTR.color,
245
+ value: require_typed_shared_color.formatOdfColor(properties.color)
246
+ });
247
+ return attributes;
248
+ }
249
+ function paragraphPropertiesToAttributes(properties) {
250
+ const attributes = [];
251
+ if (properties.alignment !== void 0) attributes.push({
252
+ name: ATTR.textAlign,
253
+ value: properties.alignment
254
+ });
255
+ if (properties.spacingBeforePt !== void 0) attributes.push({
256
+ name: ATTR.marginTop,
257
+ value: formatPt(properties.spacingBeforePt)
258
+ });
259
+ if (properties.spacingAfterPt !== void 0) attributes.push({
260
+ name: ATTR.marginBottom,
261
+ value: formatPt(properties.spacingAfterPt)
262
+ });
263
+ if (properties.lineSpacing !== void 0) attributes.push({
264
+ name: ATTR.lineHeight,
265
+ value: formatPercentageMultiplier(properties.lineSpacing)
266
+ });
267
+ if (properties.indentLeftPt !== void 0) attributes.push({
268
+ name: ATTR.marginLeft,
269
+ value: formatPt(properties.indentLeftPt)
270
+ });
271
+ if (properties.indentFirstLinePt !== void 0) attributes.push({
272
+ name: ATTR.textIndent,
273
+ value: formatPt(properties.indentFirstLinePt)
274
+ });
275
+ return attributes;
276
+ }
277
+ //#endregion
278
+ exports.StylePropertiesSchema = StylePropertiesSchema;
279
+ exports.formatPercentageMultiplier = formatPercentageMultiplier;
280
+ exports.formatPt = formatPt;
281
+ exports.paragraphPropertiesToAttributes = paragraphPropertiesToAttributes;
282
+ exports.parseLength = require_typed_shared_units.parseOdfLength;
283
+ exports.parseParagraphProperties = parseParagraphProperties;
284
+ exports.parseStyleElementProperties = parseStyleElementProperties;
285
+ exports.parseTextProperties = parseTextProperties;
286
+ exports.textPropertiesToAttributes = textPropertiesToAttributes;
@@ -0,0 +1,45 @@
1
+ import { l as XmlElement, t as Attribute } from "../node-CkBWRjNR.cjs";
2
+ import { r as parseOdfLength } from "../units-7pCiECuP.cjs";
3
+ import { z } from "zod";
4
+ //#region src/styles/properties.d.ts
5
+ declare const StylePropertiesSchema: z.ZodObject<{
6
+ bold: z.ZodOptional<z.ZodBoolean>;
7
+ italic: z.ZodOptional<z.ZodBoolean>;
8
+ underline: z.ZodOptional<z.ZodBoolean>;
9
+ strike: z.ZodOptional<z.ZodBoolean>;
10
+ fontFamily: z.ZodOptional<z.ZodString>;
11
+ sizePt: z.ZodOptional<z.ZodNumber>;
12
+ color: z.ZodOptional<z.ZodObject<{
13
+ r: z.ZodNumber;
14
+ g: z.ZodNumber;
15
+ b: z.ZodNumber;
16
+ }, z.core.$strip>>;
17
+ alignment: z.ZodOptional<z.ZodEnum<{
18
+ left: "left";
19
+ center: "center";
20
+ right: "right";
21
+ justify: "justify";
22
+ }>>;
23
+ spacingBeforePt: z.ZodOptional<z.ZodNumber>;
24
+ spacingAfterPt: z.ZodOptional<z.ZodNumber>;
25
+ lineSpacing: z.ZodOptional<z.ZodNumber>;
26
+ indentLeftPt: z.ZodOptional<z.ZodNumber>;
27
+ indentFirstLinePt: z.ZodOptional<z.ZodNumber>;
28
+ }, z.core.$strip>;
29
+ type StyleProperties = z.infer<typeof StylePropertiesSchema>;
30
+ interface ParsedProperties {
31
+ properties: Partial<StyleProperties>;
32
+ hasUnknown: boolean;
33
+ }
34
+ declare function formatPt(valuePt: number): string;
35
+ declare function formatPercentageMultiplier(multiplier: number): string;
36
+ declare function parseTextProperties(element: XmlElement): ParsedProperties;
37
+ declare function parseParagraphProperties(element: XmlElement): ParsedProperties;
38
+ declare function parseStyleElementProperties(styleElement: XmlElement): {
39
+ properties: StyleProperties;
40
+ hasUnknown: boolean;
41
+ };
42
+ declare function textPropertiesToAttributes(properties: StyleProperties): Attribute[];
43
+ declare function paragraphPropertiesToAttributes(properties: StyleProperties): Attribute[];
44
+ //#endregion
45
+ export { ParsedProperties, StyleProperties, StylePropertiesSchema, formatPercentageMultiplier, formatPt, paragraphPropertiesToAttributes, parseOdfLength as parseLength, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, textPropertiesToAttributes };
@@ -0,0 +1,45 @@
1
+ import { l as XmlElement, t as Attribute } from "../node-CkBWRjNR.js";
2
+ import { r as parseOdfLength } from "../units-7pCiECuP.js";
3
+ import { z } from "zod";
4
+ //#region src/styles/properties.d.ts
5
+ declare const StylePropertiesSchema: z.ZodObject<{
6
+ bold: z.ZodOptional<z.ZodBoolean>;
7
+ italic: z.ZodOptional<z.ZodBoolean>;
8
+ underline: z.ZodOptional<z.ZodBoolean>;
9
+ strike: z.ZodOptional<z.ZodBoolean>;
10
+ fontFamily: z.ZodOptional<z.ZodString>;
11
+ sizePt: z.ZodOptional<z.ZodNumber>;
12
+ color: z.ZodOptional<z.ZodObject<{
13
+ r: z.ZodNumber;
14
+ g: z.ZodNumber;
15
+ b: z.ZodNumber;
16
+ }, z.core.$strip>>;
17
+ alignment: z.ZodOptional<z.ZodEnum<{
18
+ left: "left";
19
+ center: "center";
20
+ right: "right";
21
+ justify: "justify";
22
+ }>>;
23
+ spacingBeforePt: z.ZodOptional<z.ZodNumber>;
24
+ spacingAfterPt: z.ZodOptional<z.ZodNumber>;
25
+ lineSpacing: z.ZodOptional<z.ZodNumber>;
26
+ indentLeftPt: z.ZodOptional<z.ZodNumber>;
27
+ indentFirstLinePt: z.ZodOptional<z.ZodNumber>;
28
+ }, z.core.$strip>;
29
+ type StyleProperties = z.infer<typeof StylePropertiesSchema>;
30
+ interface ParsedProperties {
31
+ properties: Partial<StyleProperties>;
32
+ hasUnknown: boolean;
33
+ }
34
+ declare function formatPt(valuePt: number): string;
35
+ declare function formatPercentageMultiplier(multiplier: number): string;
36
+ declare function parseTextProperties(element: XmlElement): ParsedProperties;
37
+ declare function parseParagraphProperties(element: XmlElement): ParsedProperties;
38
+ declare function parseStyleElementProperties(styleElement: XmlElement): {
39
+ properties: StyleProperties;
40
+ hasUnknown: boolean;
41
+ };
42
+ declare function textPropertiesToAttributes(properties: StyleProperties): Attribute[];
43
+ declare function paragraphPropertiesToAttributes(properties: StyleProperties): Attribute[];
44
+ //#endregion
45
+ export { ParsedProperties, StyleProperties, StylePropertiesSchema, formatPercentageMultiplier, formatPt, paragraphPropertiesToAttributes, parseOdfLength as parseLength, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, textPropertiesToAttributes };