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,42 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_entities = require("../../xml/entities.cjs");
3
+ const require_xml_query = require("../../xml/query.cjs");
4
+ //#region src/typed/shared/metadata.ts
5
+ const META_PART = "meta.xml";
6
+ function elementText(element) {
7
+ let text = "";
8
+ for (const child of element.children) if (child.type === "text") text += require_xml_entities.decodeXmlText(child.value);
9
+ return text;
10
+ }
11
+ function firstElementText(container, tag) {
12
+ const element = require_xml_query.childrenWithTag(container, tag)[0];
13
+ if (element === void 0) return;
14
+ const text = elementText(element);
15
+ return text.length > 0 ? text : void 0;
16
+ }
17
+ function readOdfMetadata(pkg) {
18
+ const part = pkg.parts[META_PART];
19
+ if (part?.kind !== "xml") return {};
20
+ const root = require_xml_query.rootElement(part.nodes);
21
+ const meta = root === void 0 ? void 0 : require_xml_query.findChildElement(root.children, "office:meta");
22
+ if (meta === void 0) return {};
23
+ const metadata = {};
24
+ const title = firstElementText(meta, "dc:title");
25
+ if (title !== void 0) metadata.title = title;
26
+ const author = firstElementText(meta, "meta:initial-creator");
27
+ if (author !== void 0) metadata.author = author;
28
+ const subject = firstElementText(meta, "dc:subject");
29
+ if (subject !== void 0) metadata.subject = subject;
30
+ const keywords = require_xml_query.childrenWithTag(meta, "meta:keyword").map(elementText).filter((keyword) => keyword.length > 0);
31
+ if (keywords.length > 0) metadata.keywords = keywords;
32
+ const creator = firstElementText(meta, "meta:generator");
33
+ if (creator !== void 0) metadata.creator = creator;
34
+ const createdIso = firstElementText(meta, "meta:creation-date");
35
+ if (createdIso !== void 0) metadata.createdIso = createdIso;
36
+ const modifiedIso = firstElementText(meta, "dc:date");
37
+ if (modifiedIso !== void 0) metadata.modifiedIso = modifiedIso;
38
+ return metadata;
39
+ }
40
+ //#endregion
41
+ exports.META_PART = META_PART;
42
+ exports.readOdfMetadata = readOdfMetadata;
@@ -0,0 +1,7 @@
1
+ import { Package } from "../../model/package.cjs";
2
+ import { LayoutMetadata } from "document-schema.js";
3
+ //#region src/typed/shared/metadata.d.ts
4
+ declare const META_PART = "meta.xml";
5
+ declare function readOdfMetadata(pkg: Package): LayoutMetadata;
6
+ //#endregion
7
+ export { META_PART, readOdfMetadata };
@@ -0,0 +1,7 @@
1
+ import { Package } from "../../model/package.js";
2
+ import { LayoutMetadata } from "document-schema.js";
3
+ //#region src/typed/shared/metadata.d.ts
4
+ declare const META_PART = "meta.xml";
5
+ declare function readOdfMetadata(pkg: Package): LayoutMetadata;
6
+ //#endregion
7
+ export { META_PART, readOdfMetadata };
@@ -0,0 +1,40 @@
1
+ import { decodeXmlText } from "../../xml/entities.js";
2
+ import { childrenWithTag, findChildElement, rootElement } from "../../xml/query.js";
3
+ //#region src/typed/shared/metadata.ts
4
+ const META_PART = "meta.xml";
5
+ function elementText(element) {
6
+ let text = "";
7
+ for (const child of element.children) if (child.type === "text") text += decodeXmlText(child.value);
8
+ return text;
9
+ }
10
+ function firstElementText(container, tag) {
11
+ const element = childrenWithTag(container, tag)[0];
12
+ if (element === void 0) return;
13
+ const text = elementText(element);
14
+ return text.length > 0 ? text : void 0;
15
+ }
16
+ function readOdfMetadata(pkg) {
17
+ const part = pkg.parts[META_PART];
18
+ if (part?.kind !== "xml") return {};
19
+ const root = rootElement(part.nodes);
20
+ const meta = root === void 0 ? void 0 : findChildElement(root.children, "office:meta");
21
+ if (meta === void 0) return {};
22
+ const metadata = {};
23
+ const title = firstElementText(meta, "dc:title");
24
+ if (title !== void 0) metadata.title = title;
25
+ const author = firstElementText(meta, "meta:initial-creator");
26
+ if (author !== void 0) metadata.author = author;
27
+ const subject = firstElementText(meta, "dc:subject");
28
+ if (subject !== void 0) metadata.subject = subject;
29
+ const keywords = childrenWithTag(meta, "meta:keyword").map(elementText).filter((keyword) => keyword.length > 0);
30
+ if (keywords.length > 0) metadata.keywords = keywords;
31
+ const creator = firstElementText(meta, "meta:generator");
32
+ if (creator !== void 0) metadata.creator = creator;
33
+ const createdIso = firstElementText(meta, "meta:creation-date");
34
+ if (createdIso !== void 0) metadata.createdIso = createdIso;
35
+ const modifiedIso = firstElementText(meta, "dc:date");
36
+ if (modifiedIso !== void 0) metadata.modifiedIso = modifiedIso;
37
+ return metadata;
38
+ }
39
+ //#endregion
40
+ export { META_PART, readOdfMetadata };
@@ -0,0 +1,57 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_entities = require("../../xml/entities.cjs");
3
+ const require_xml_query = require("../../xml/query.cjs");
4
+ const require_typed_shared_text = require("./text.cjs");
5
+ const require_typed_shared_cascade = require("./cascade.cjs");
6
+ //#region src/typed/shared/paragraph.ts
7
+ function collectRuns(nodes, baseProperties, pkg, out) {
8
+ for (const node of nodes) {
9
+ if (node.type === "text") {
10
+ if (node.value.length > 0) out.push(runFromText(require_xml_entities.decodeXmlText(node.value), baseProperties));
11
+ continue;
12
+ }
13
+ if (node.type !== "element") continue;
14
+ if (node.tag === "text:s") out.push(runFromText(" ".repeat(require_typed_shared_text.getOdfSpaceCount(node)), baseProperties));
15
+ else if (node.tag === "text:tab") out.push(runFromText(" ", baseProperties));
16
+ else if (node.tag === "text:line-break") out.push(runFromText("\n", baseProperties));
17
+ else if (node.tag === "text:span") {
18
+ const styleName = require_xml_query.attrValue(node, "text:style-name");
19
+ const spanProperties = {
20
+ ...baseProperties,
21
+ ...require_typed_shared_cascade.resolveStyle(styleName, "text", pkg).properties
22
+ };
23
+ collectRuns(node.children, spanProperties, pkg, out);
24
+ }
25
+ }
26
+ }
27
+ function runFromText(text, properties) {
28
+ return {
29
+ text,
30
+ bold: properties.bold,
31
+ italic: properties.italic,
32
+ underline: properties.underline,
33
+ strike: properties.strike,
34
+ fontFamily: properties.fontFamily,
35
+ sizePt: properties.sizePt,
36
+ color: properties.color
37
+ };
38
+ }
39
+ function readOdfParagraph(pElement, pkg) {
40
+ const styleName = require_xml_query.attrValue(pElement, "text:style-name");
41
+ const paragraphProperties = require_typed_shared_cascade.resolveStyle(styleName, "paragraph", pkg).properties;
42
+ const runs = [];
43
+ collectRuns(pElement.children, paragraphProperties, pkg, runs);
44
+ return {
45
+ kind: "paragraph",
46
+ runs,
47
+ styleId: styleName,
48
+ alignment: paragraphProperties.alignment,
49
+ spacingBeforePt: paragraphProperties.spacingBeforePt,
50
+ spacingAfterPt: paragraphProperties.spacingAfterPt,
51
+ lineSpacing: paragraphProperties.lineSpacing,
52
+ indentLeftPt: paragraphProperties.indentLeftPt,
53
+ indentFirstLinePt: paragraphProperties.indentFirstLinePt
54
+ };
55
+ }
56
+ //#endregion
57
+ exports.readOdfParagraph = readOdfParagraph;
@@ -0,0 +1,7 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.cjs";
2
+ import { Package } from "../../model/package.cjs";
3
+ import { ContentParagraph } from "document-schema.js";
4
+ //#region src/typed/shared/paragraph.d.ts
5
+ declare function readOdfParagraph(pElement: XmlElement, pkg: Package): ContentParagraph;
6
+ //#endregion
7
+ export { readOdfParagraph };
@@ -0,0 +1,7 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.js";
2
+ import { Package } from "../../model/package.js";
3
+ import { ContentParagraph } from "document-schema.js";
4
+ //#region src/typed/shared/paragraph.d.ts
5
+ declare function readOdfParagraph(pElement: XmlElement, pkg: Package): ContentParagraph;
6
+ //#endregion
7
+ export { readOdfParagraph };
@@ -0,0 +1,56 @@
1
+ import { decodeXmlText } from "../../xml/entities.js";
2
+ import { attrValue } from "../../xml/query.js";
3
+ import { getOdfSpaceCount } from "./text.js";
4
+ import { resolveStyle } from "./cascade.js";
5
+ //#region src/typed/shared/paragraph.ts
6
+ function collectRuns(nodes, baseProperties, pkg, out) {
7
+ for (const node of nodes) {
8
+ if (node.type === "text") {
9
+ if (node.value.length > 0) out.push(runFromText(decodeXmlText(node.value), baseProperties));
10
+ continue;
11
+ }
12
+ if (node.type !== "element") continue;
13
+ if (node.tag === "text:s") out.push(runFromText(" ".repeat(getOdfSpaceCount(node)), baseProperties));
14
+ else if (node.tag === "text:tab") out.push(runFromText(" ", baseProperties));
15
+ else if (node.tag === "text:line-break") out.push(runFromText("\n", baseProperties));
16
+ else if (node.tag === "text:span") {
17
+ const styleName = attrValue(node, "text:style-name");
18
+ const spanProperties = {
19
+ ...baseProperties,
20
+ ...resolveStyle(styleName, "text", pkg).properties
21
+ };
22
+ collectRuns(node.children, spanProperties, pkg, out);
23
+ }
24
+ }
25
+ }
26
+ function runFromText(text, properties) {
27
+ return {
28
+ text,
29
+ bold: properties.bold,
30
+ italic: properties.italic,
31
+ underline: properties.underline,
32
+ strike: properties.strike,
33
+ fontFamily: properties.fontFamily,
34
+ sizePt: properties.sizePt,
35
+ color: properties.color
36
+ };
37
+ }
38
+ function readOdfParagraph(pElement, pkg) {
39
+ const styleName = attrValue(pElement, "text:style-name");
40
+ const paragraphProperties = resolveStyle(styleName, "paragraph", pkg).properties;
41
+ const runs = [];
42
+ collectRuns(pElement.children, paragraphProperties, pkg, runs);
43
+ return {
44
+ kind: "paragraph",
45
+ runs,
46
+ styleId: styleName,
47
+ alignment: paragraphProperties.alignment,
48
+ spacingBeforePt: paragraphProperties.spacingBeforePt,
49
+ spacingAfterPt: paragraphProperties.spacingAfterPt,
50
+ lineSpacing: paragraphProperties.lineSpacing,
51
+ indentLeftPt: paragraphProperties.indentLeftPt,
52
+ indentFirstLinePt: paragraphProperties.indentFirstLinePt
53
+ };
54
+ }
55
+ //#endregion
56
+ export { readOdfParagraph };
@@ -0,0 +1,261 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/typed/shared/path.ts
3
+ const VIEW_BOX_PATTERN = /^(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)$/;
4
+ function parseOdfViewBox(value) {
5
+ const match = VIEW_BOX_PATTERN.exec(value.trim());
6
+ if (match === null) return;
7
+ const minX = Number(match[1]);
8
+ const minY = Number(match[2]);
9
+ const width = Number(match[3]);
10
+ const height = Number(match[4]);
11
+ if (width <= 0 || height <= 0) return;
12
+ return {
13
+ minX,
14
+ minY,
15
+ width,
16
+ height
17
+ };
18
+ }
19
+ function parseOdfPointsList(value) {
20
+ const points = [];
21
+ for (const pair of value.trim().split(/\s+/)) {
22
+ if (pair.length === 0) continue;
23
+ const [xRaw, yRaw] = pair.split(",");
24
+ if (xRaw === void 0 || yRaw === void 0) continue;
25
+ const x = Number(xRaw);
26
+ const y = Number(yRaw);
27
+ if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
28
+ points.push({
29
+ x,
30
+ y
31
+ });
32
+ }
33
+ return points;
34
+ }
35
+ function rawSubpathFromPoints(points, closed) {
36
+ const start = points[0];
37
+ if (start === void 0) return;
38
+ return {
39
+ start,
40
+ segments: points.slice(1).map((to) => ({
41
+ kind: "line",
42
+ to
43
+ })),
44
+ closed
45
+ };
46
+ }
47
+ const COMMAND_LETTERS = /* @__PURE__ */ new Set([
48
+ "M",
49
+ "m",
50
+ "L",
51
+ "l",
52
+ "H",
53
+ "h",
54
+ "V",
55
+ "v",
56
+ "C",
57
+ "c",
58
+ "S",
59
+ "s",
60
+ "Q",
61
+ "q",
62
+ "T",
63
+ "t",
64
+ "A",
65
+ "a",
66
+ "Z",
67
+ "z"
68
+ ]);
69
+ function isCommandLetter(token) {
70
+ return COMMAND_LETTERS.has(token);
71
+ }
72
+ const PATH_TOKEN_PATTERN = /[MmLlHhVvCcSsQqTtAaZz]|-?(?:\d+\.\d+|\.\d+|\d+)(?:[eE][-+]?\d+)?/g;
73
+ function tokenizePathData(d) {
74
+ return d.match(PATH_TOKEN_PATTERN) ?? [];
75
+ }
76
+ function parseOdfPathData(d) {
77
+ const tokens = tokenizePathData(d);
78
+ const subpaths = [];
79
+ let current = {
80
+ x: 0,
81
+ y: 0
82
+ };
83
+ let subpathStart = {
84
+ x: 0,
85
+ y: 0
86
+ };
87
+ let activeSubpath;
88
+ let command;
89
+ let firstMInCommand = true;
90
+ function startSubpath(point) {
91
+ activeSubpath = {
92
+ start: point,
93
+ segments: [],
94
+ closed: false
95
+ };
96
+ subpaths.push(activeSubpath);
97
+ subpathStart = point;
98
+ current = point;
99
+ }
100
+ function pushSegment(segment, to) {
101
+ if (activeSubpath !== void 0) activeSubpath.segments.push(segment);
102
+ current = to;
103
+ }
104
+ let i = 0;
105
+ while (i < tokens.length) {
106
+ const token = tokens[i];
107
+ if (token === void 0) break;
108
+ if (isCommandLetter(token)) {
109
+ if (token === "Z" || token === "z") {
110
+ if (activeSubpath !== void 0) {
111
+ activeSubpath.closed = true;
112
+ current = subpathStart;
113
+ }
114
+ command = void 0;
115
+ i += 1;
116
+ continue;
117
+ }
118
+ command = token;
119
+ firstMInCommand = true;
120
+ i += 1;
121
+ continue;
122
+ }
123
+ if (command === void 0) {
124
+ i += 1;
125
+ continue;
126
+ }
127
+ const upper = command.toUpperCase();
128
+ const relative = command !== upper;
129
+ if (upper === "M" || upper === "L") {
130
+ const xTok = tokens[i];
131
+ const yTok = tokens[i + 1];
132
+ i += 2;
133
+ if (xTok === void 0 || yTok === void 0) break;
134
+ const x = Number(xTok);
135
+ const y = Number(yTok);
136
+ if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
137
+ const point = relative ? {
138
+ x: current.x + x,
139
+ y: current.y + y
140
+ } : {
141
+ x,
142
+ y
143
+ };
144
+ if (upper === "M" && firstMInCommand) {
145
+ startSubpath(point);
146
+ firstMInCommand = false;
147
+ } else pushSegment({
148
+ kind: "line",
149
+ to: point
150
+ }, point);
151
+ } else if (upper === "H") {
152
+ const xTok = tokens[i];
153
+ i += 1;
154
+ if (xTok === void 0) break;
155
+ const x = Number(xTok);
156
+ if (!Number.isFinite(x)) continue;
157
+ const point = relative ? {
158
+ x: current.x + x,
159
+ y: current.y
160
+ } : {
161
+ x,
162
+ y: current.y
163
+ };
164
+ pushSegment({
165
+ kind: "line",
166
+ to: point
167
+ }, point);
168
+ } else if (upper === "V") {
169
+ const yTok = tokens[i];
170
+ i += 1;
171
+ if (yTok === void 0) break;
172
+ const y = Number(yTok);
173
+ if (!Number.isFinite(y)) continue;
174
+ const point = relative ? {
175
+ x: current.x,
176
+ y: current.y + y
177
+ } : {
178
+ x: current.x,
179
+ y
180
+ };
181
+ pushSegment({
182
+ kind: "line",
183
+ to: point
184
+ }, point);
185
+ } else if (upper === "C") {
186
+ const rawArgs = tokens.slice(i, i + 6);
187
+ i += 6;
188
+ if (rawArgs.length < 6) break;
189
+ const x1 = Number(rawArgs[0]);
190
+ const y1 = Number(rawArgs[1]);
191
+ const x2 = Number(rawArgs[2]);
192
+ const y2 = Number(rawArgs[3]);
193
+ const x = Number(rawArgs[4]);
194
+ const y = Number(rawArgs[5]);
195
+ if (![
196
+ x1,
197
+ y1,
198
+ x2,
199
+ y2,
200
+ x,
201
+ y
202
+ ].every(Number.isFinite)) continue;
203
+ const control1 = relative ? {
204
+ x: current.x + x1,
205
+ y: current.y + y1
206
+ } : {
207
+ x: x1,
208
+ y: y1
209
+ };
210
+ const control2 = relative ? {
211
+ x: current.x + x2,
212
+ y: current.y + y2
213
+ } : {
214
+ x: x2,
215
+ y: y2
216
+ };
217
+ const to = relative ? {
218
+ x: current.x + x,
219
+ y: current.y + y
220
+ } : {
221
+ x,
222
+ y
223
+ };
224
+ pushSegment({
225
+ kind: "cubic",
226
+ control1,
227
+ control2,
228
+ to
229
+ }, to);
230
+ } else i += 1;
231
+ }
232
+ return subpaths;
233
+ }
234
+ function scaleOdfRawPoint(point, viewBox, frame) {
235
+ return {
236
+ xPt: (point.x - viewBox.minX) * (frame.widthPt / viewBox.width),
237
+ yPt: (point.y - viewBox.minY) * (frame.heightPt / viewBox.height)
238
+ };
239
+ }
240
+ function buildOdfSubpaths(rawSubpaths, viewBox, frame) {
241
+ return rawSubpaths.map((raw) => ({
242
+ start: scaleOdfRawPoint(raw.start, viewBox, frame),
243
+ closed: raw.closed,
244
+ segments: raw.segments.map((segment) => segment.kind === "line" ? {
245
+ kind: "line",
246
+ to: scaleOdfRawPoint(segment.to, viewBox, frame)
247
+ } : {
248
+ kind: "cubic",
249
+ control1: scaleOdfRawPoint(segment.control1, viewBox, frame),
250
+ control2: scaleOdfRawPoint(segment.control2, viewBox, frame),
251
+ to: scaleOdfRawPoint(segment.to, viewBox, frame)
252
+ })
253
+ }));
254
+ }
255
+ //#endregion
256
+ exports.buildOdfSubpaths = buildOdfSubpaths;
257
+ exports.parseOdfPathData = parseOdfPathData;
258
+ exports.parseOdfPointsList = parseOdfPointsList;
259
+ exports.parseOdfViewBox = parseOdfViewBox;
260
+ exports.rawSubpathFromPoints = rawSubpathFromPoints;
261
+ exports.scaleOdfRawPoint = scaleOdfRawPoint;
@@ -0,0 +1,34 @@
1
+ import { Box, ContentPathPoint, ContentSubpath } from "document-schema.js";
2
+ //#region src/typed/shared/path.d.ts
3
+ interface OdfRawPoint {
4
+ readonly x: number;
5
+ readonly y: number;
6
+ }
7
+ type OdfRawSegment = {
8
+ readonly kind: 'line';
9
+ readonly to: OdfRawPoint;
10
+ } | {
11
+ readonly kind: 'cubic';
12
+ readonly control1: OdfRawPoint;
13
+ readonly control2: OdfRawPoint;
14
+ readonly to: OdfRawPoint;
15
+ };
16
+ interface OdfRawSubpath {
17
+ readonly start: OdfRawPoint;
18
+ readonly segments: readonly OdfRawSegment[];
19
+ readonly closed: boolean;
20
+ }
21
+ interface OdfViewBox {
22
+ readonly minX: number;
23
+ readonly minY: number;
24
+ readonly width: number;
25
+ readonly height: number;
26
+ }
27
+ declare function parseOdfViewBox(value: string): OdfViewBox | undefined;
28
+ declare function parseOdfPointsList(value: string): OdfRawPoint[];
29
+ declare function rawSubpathFromPoints(points: readonly OdfRawPoint[], closed: boolean): OdfRawSubpath | undefined;
30
+ declare function parseOdfPathData(d: string): OdfRawSubpath[];
31
+ declare function scaleOdfRawPoint(point: OdfRawPoint, viewBox: OdfViewBox, frame: Box): ContentPathPoint;
32
+ declare function buildOdfSubpaths(rawSubpaths: readonly OdfRawSubpath[], viewBox: OdfViewBox, frame: Box): ContentSubpath[];
33
+ //#endregion
34
+ export { OdfRawPoint, OdfRawSegment, OdfRawSubpath, OdfViewBox, buildOdfSubpaths, parseOdfPathData, parseOdfPointsList, parseOdfViewBox, rawSubpathFromPoints, scaleOdfRawPoint };
@@ -0,0 +1,34 @@
1
+ import { Box, ContentPathPoint, ContentSubpath } from "document-schema.js";
2
+ //#region src/typed/shared/path.d.ts
3
+ interface OdfRawPoint {
4
+ readonly x: number;
5
+ readonly y: number;
6
+ }
7
+ type OdfRawSegment = {
8
+ readonly kind: 'line';
9
+ readonly to: OdfRawPoint;
10
+ } | {
11
+ readonly kind: 'cubic';
12
+ readonly control1: OdfRawPoint;
13
+ readonly control2: OdfRawPoint;
14
+ readonly to: OdfRawPoint;
15
+ };
16
+ interface OdfRawSubpath {
17
+ readonly start: OdfRawPoint;
18
+ readonly segments: readonly OdfRawSegment[];
19
+ readonly closed: boolean;
20
+ }
21
+ interface OdfViewBox {
22
+ readonly minX: number;
23
+ readonly minY: number;
24
+ readonly width: number;
25
+ readonly height: number;
26
+ }
27
+ declare function parseOdfViewBox(value: string): OdfViewBox | undefined;
28
+ declare function parseOdfPointsList(value: string): OdfRawPoint[];
29
+ declare function rawSubpathFromPoints(points: readonly OdfRawPoint[], closed: boolean): OdfRawSubpath | undefined;
30
+ declare function parseOdfPathData(d: string): OdfRawSubpath[];
31
+ declare function scaleOdfRawPoint(point: OdfRawPoint, viewBox: OdfViewBox, frame: Box): ContentPathPoint;
32
+ declare function buildOdfSubpaths(rawSubpaths: readonly OdfRawSubpath[], viewBox: OdfViewBox, frame: Box): ContentSubpath[];
33
+ //#endregion
34
+ export { OdfRawPoint, OdfRawSegment, OdfRawSubpath, OdfViewBox, buildOdfSubpaths, parseOdfPathData, parseOdfPointsList, parseOdfViewBox, rawSubpathFromPoints, scaleOdfRawPoint };