odf.js 5.0.9 → 5.1.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 (146) hide show
  1. package/README.md +16 -2
  2. package/dist/{cascade-qYa3mgnE.d.cts → cascade-BmvsXcAz.d.cts} +2 -2
  3. package/dist/{cascade-8u4q16_U.d.ts → cascade-rhqUQrUa.d.ts} +2 -2
  4. package/dist/{codec-jKlS0rWl.d.cts → codec-BAz7YIru.d.cts} +26 -25
  5. package/dist/{codec-DqldvlN5.d.ts → codec-BxxFEqvT.d.ts} +26 -25
  6. package/dist/codec.d.cts +1 -1
  7. package/dist/codec.d.ts +1 -1
  8. package/dist/constructs-CJpDDQV0.d.ts +63 -0
  9. package/dist/constructs-Dy_DMFs3.d.cts +63 -0
  10. package/dist/embedded-BPhuSEEI.d.ts +18 -0
  11. package/dist/embedded-J3M3kDvY.d.cts +18 -0
  12. package/dist/form-BGCT81ss.d.cts +13 -0
  13. package/dist/form-D3H5H2NL.d.ts +13 -0
  14. package/dist/forms-D1-0spCe.d.ts +27 -0
  15. package/dist/forms-cIjw-Jf-.d.cts +27 -0
  16. package/dist/index.cjs +5 -2
  17. package/dist/index.d.cts +28 -27
  18. package/dist/index.d.ts +28 -27
  19. package/dist/index.js +4 -3
  20. package/dist/{list-C35tiDYU.d.cts → list-KZeXA0mR.d.cts} +1 -1
  21. package/dist/{list-acGU0xLo.d.ts → list-Qeuawtew.d.ts} +1 -1
  22. package/dist/{manifest-xxJ4FpSe.d.ts → manifest-BALwu2JR.d.cts} +1 -1
  23. package/dist/{manifest-CmsCOCEi.d.cts → manifest-CP1sqyGU.d.ts} +1 -1
  24. package/dist/manifest.d.cts +1 -1
  25. package/dist/manifest.d.ts +1 -1
  26. package/dist/{masterpage-7nBnqFj-.d.ts → masterpage-C1McDhMv.d.ts} +1 -1
  27. package/dist/{masterpage-EmefIRgy.d.cts → masterpage-XJ2v2khe.d.cts} +1 -1
  28. package/dist/{metadata-32LoP2TK.d.ts → metadata-1j1zm9Cx.d.cts} +1 -1
  29. package/dist/{metadata-frJqeeSB.d.cts → metadata-BXpjrAS-.d.ts} +1 -1
  30. package/dist/{mimetype-uF-RHNpR.d.ts → mimetype-BfkwTeaW.d.ts} +1 -1
  31. package/dist/{mimetype-BcLX0N-N.d.cts → mimetype-CPNMj04s.d.cts} +1 -1
  32. package/dist/mimetype.d.cts +1 -1
  33. package/dist/mimetype.d.ts +1 -1
  34. package/dist/model/package.d.cts +1 -113
  35. package/dist/model/package.d.ts +1 -113
  36. package/dist/package-BUojjTXf.d.ts +114 -0
  37. package/dist/package-L24lkba-.d.cts +114 -0
  38. package/dist/package-io/read.d.cts +1 -1
  39. package/dist/package-io/read.d.ts +1 -1
  40. package/dist/package-io/write.d.cts +1 -1
  41. package/dist/package-io/write.d.ts +1 -1
  42. package/dist/paragraph-6hzAZpmi.d.ts +16 -0
  43. package/dist/paragraph-BBmSl_sK.d.cts +16 -0
  44. package/dist/read-B4238IGr.d.cts +12 -0
  45. package/dist/{read-DrdmKX0x.d.cts → read-BV2an1ok.d.cts} +1 -1
  46. package/dist/{read-DOuXgPhP.d.ts → read-BnN7u9Y2.d.ts} +1 -1
  47. package/dist/{read-DhLNXgiM.d.ts → read-CMDEXqGw.d.ts} +1 -1
  48. package/dist/{read-YSIwlhrk.d.ts → read-CTfeWaWq.d.cts} +1 -1
  49. package/dist/read-CdvX2qnz.d.ts +12 -0
  50. package/dist/read-Cs1ktkWB.d.cts +15 -0
  51. package/dist/{read-BoIUENWq.d.ts → read-CvjbdgH3.d.ts} +1 -1
  52. package/dist/read-DHuiGh_y.d.ts +15 -0
  53. package/dist/{read-BM8KaFQS.d.cts → read-DOYWO6BM.d.cts} +1 -1
  54. package/dist/{read-xCmo7cec.d.cts → read-DUCm1nUv.d.cts} +1 -1
  55. package/dist/{read-BkFbEves.d.ts → read-DYYxbvfo.d.ts} +1 -1
  56. package/dist/{read-KpU38maT.d.cts → read-Db_GZ0ZH.d.ts} +1 -1
  57. package/dist/{read-CFMsXSl7.d.cts → read-DzmMJPHd.d.cts} +1 -1
  58. package/dist/{read-B9zz_ax1.d.ts → read-lc0t0UHK.d.ts} +1 -1
  59. package/dist/{read-DNNf5_6n.d.cts → read-ydLJ8bid.d.cts} +1 -1
  60. package/dist/{registry-R43n1hcL.d.ts → registry-BVeEpUMI.d.ts} +1 -1
  61. package/dist/{registry-Dy6pjoh3.d.cts → registry-CaJpWDke.d.cts} +1 -1
  62. package/dist/{report-MpwUgXbA.d.ts → report-D6WNYaVn.d.cts} +1 -1
  63. package/dist/{report-BuCJ7_YU.d.cts → report-DbslT2OR.d.ts} +1 -1
  64. package/dist/{shapes-BqcccDK8.d.cts → shapes-8o3NjBLU.d.cts} +3 -3
  65. package/dist/{shapes-BB59aIC8.d.ts → shapes-CCB8ydqD.d.ts} +3 -3
  66. package/dist/styles/registry.d.cts +1 -1
  67. package/dist/styles/registry.d.ts +1 -1
  68. package/dist/{subdocument-CIxH3a5V.d.cts → subdocument-BwW3FZC_.d.ts} +1 -1
  69. package/dist/{subdocument-DQNQF7wV.d.ts → subdocument-yY8ASE4N.d.cts} +1 -1
  70. package/dist/{table-sweV3r9n.d.cts → table-BH_Q2n_N.d.cts} +1 -1
  71. package/dist/{table-D81TZyBn.d.ts → table-ByOoGcq_.d.ts} +1 -1
  72. package/dist/{text-Cal14ZaX.d.cts → text-BAi1tapc.d.cts} +3 -1
  73. package/dist/{text-CkNojpZm.d.ts → text-gJ5R0q3u.d.ts} +3 -1
  74. package/dist/typed/draw/embedded.cjs +38 -0
  75. package/dist/typed/draw/embedded.d.cts +2 -2
  76. package/dist/typed/draw/embedded.d.ts +2 -2
  77. package/dist/typed/draw/embedded.js +39 -2
  78. package/dist/typed/draw/shapes.cjs +20 -3
  79. package/dist/typed/draw/shapes.d.cts +1 -1
  80. package/dist/typed/draw/shapes.d.ts +1 -1
  81. package/dist/typed/draw/shapes.js +20 -3
  82. package/dist/typed/formula/read.d.cts +1 -1
  83. package/dist/typed/formula/read.d.ts +1 -1
  84. package/dist/typed/odb/form.cjs +2 -59
  85. package/dist/typed/odb/form.d.cts +2 -2
  86. package/dist/typed/odb/form.d.ts +2 -2
  87. package/dist/typed/odb/form.js +3 -60
  88. package/dist/typed/odb/read.d.cts +1 -1
  89. package/dist/typed/odb/read.d.ts +1 -1
  90. package/dist/typed/odb/report.d.cts +1 -1
  91. package/dist/typed/odb/report.d.ts +1 -1
  92. package/dist/typed/odb/subdocument.d.cts +1 -1
  93. package/dist/typed/odb/subdocument.d.ts +1 -1
  94. package/dist/typed/odg/read.d.cts +1 -1
  95. package/dist/typed/odg/read.d.ts +1 -1
  96. package/dist/typed/odm/read.d.cts +1 -1
  97. package/dist/typed/odm/read.d.ts +1 -1
  98. package/dist/typed/odp/read.d.cts +1 -1
  99. package/dist/typed/odp/read.d.ts +1 -1
  100. package/dist/typed/ods/read.cjs +28 -7
  101. package/dist/typed/ods/read.d.cts +1 -1
  102. package/dist/typed/ods/read.d.ts +1 -1
  103. package/dist/typed/ods/read.js +29 -8
  104. package/dist/typed/odt/read.cjs +215 -15
  105. package/dist/typed/odt/read.d.cts +2 -2
  106. package/dist/typed/odt/read.d.ts +2 -2
  107. package/dist/typed/odt/read.js +215 -15
  108. package/dist/typed/shared/cascade.d.cts +1 -1
  109. package/dist/typed/shared/cascade.d.ts +1 -1
  110. package/dist/typed/shared/constructs.cjs +392 -0
  111. package/dist/typed/shared/constructs.d.cts +2 -0
  112. package/dist/typed/shared/constructs.d.ts +2 -0
  113. package/dist/typed/shared/constructs.js +374 -0
  114. package/dist/typed/shared/forms.cjs +128 -0
  115. package/dist/typed/shared/forms.d.cts +2 -0
  116. package/dist/typed/shared/forms.d.ts +2 -0
  117. package/dist/typed/shared/forms.js +126 -0
  118. package/dist/typed/shared/list.d.cts +1 -1
  119. package/dist/typed/shared/list.d.ts +1 -1
  120. package/dist/typed/shared/masterpage.d.cts +1 -1
  121. package/dist/typed/shared/masterpage.d.ts +1 -1
  122. package/dist/typed/shared/metadata.d.cts +1 -1
  123. package/dist/typed/shared/metadata.d.ts +1 -1
  124. package/dist/typed/shared/paragraph.cjs +189 -10
  125. package/dist/typed/shared/paragraph.d.cts +2 -2
  126. package/dist/typed/shared/paragraph.d.ts +2 -2
  127. package/dist/typed/shared/paragraph.js +192 -13
  128. package/dist/typed/shared/table.d.cts +1 -1
  129. package/dist/typed/shared/table.d.ts +1 -1
  130. package/dist/typed/shared/text.cjs +57 -2
  131. package/dist/typed/shared/text.d.cts +2 -2
  132. package/dist/typed/shared/text.d.ts +2 -2
  133. package/dist/typed/shared/text.js +56 -3
  134. package/dist/{write-C0nwVuPI.d.ts → write-BxVkPZID.d.ts} +1 -1
  135. package/dist/{write-Dfb2tirK.d.cts → write-D3kyj1Xw.d.cts} +1 -1
  136. package/package.json +2 -2
  137. package/dist/embedded-CNMqOrnt.d.ts +0 -13
  138. package/dist/embedded-D7Kr1Sce.d.cts +0 -13
  139. package/dist/form-BsAAx5-p.d.ts +0 -31
  140. package/dist/form-DSIbHxog.d.cts +0 -31
  141. package/dist/paragraph-9ii2naJC.d.cts +0 -7
  142. package/dist/paragraph-DWNnedIE.d.ts +0 -7
  143. package/dist/read-B4zS8bGb.d.ts +0 -11
  144. package/dist/read-BHpPvhzR.d.cts +0 -11
  145. package/dist/read-C6MhadqG.d.ts +0 -11
  146. package/dist/read-CszvDMMt.d.cts +0 -11
@@ -1,11 +1,33 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_xml_entities = require("../../xml/entities.cjs");
3
+ const require_styles_properties = require("../../styles/properties.cjs");
3
4
  const require_xml_query = require("../../xml/query.cjs");
4
5
  const require_typed_shared_text = require("./text.cjs");
5
6
  const require_typed_shared_cascade = require("./cascade.cjs");
7
+ const require_typed_shared_list = require("./list.cjs");
8
+ const require_typed_shared_constructs = require("./constructs.cjs");
6
9
  //#region src/typed/shared/paragraph.ts
7
- function collectRuns(nodes, baseProperties, pkg, out, hyperlinkTarget = void 0) {
8
- for (const node of nodes) {
10
+ function readOdfConstructBodyBlocks(body, pkg, context, listIdState) {
11
+ const blocks = [];
12
+ const bodyContext = {
13
+ ...context,
14
+ listIdState
15
+ };
16
+ for (const child of body.children) {
17
+ if (child.type !== "element") continue;
18
+ if (child.tag === "text:p" || child.tag === "text:h") blocks.push(readOdfParagraph(child, pkg, bodyContext));
19
+ else if (child.tag === "text:list") {
20
+ const numId = require_typed_shared_list.mintOdfListNumId(pkg, child, listIdState);
21
+ blocks.push(...require_typed_shared_list.readOdfListParagraphs(child, {
22
+ numId,
23
+ level: 0
24
+ }, (element) => readOdfParagraph(element, pkg, bodyContext)));
25
+ }
26
+ }
27
+ return blocks;
28
+ }
29
+ function collectRuns(container, baseProperties, pkg, out, walk, hyperlinkTarget = void 0) {
30
+ for (const node of container.children) {
9
31
  if (node.type === "text") {
10
32
  if (node.value.length > 0) pushRun(out, runFromText(require_xml_entities.decodeXmlText(node.value), baseProperties), hyperlinkTarget);
11
33
  continue;
@@ -16,14 +38,145 @@ function collectRuns(nodes, baseProperties, pkg, out, hyperlinkTarget = void 0)
16
38
  else if (node.tag === "text:line-break") pushRun(out, runFromText("\n", baseProperties), hyperlinkTarget);
17
39
  else if (node.tag === "text:span") {
18
40
  const styleName = require_xml_query.attrValue(node, "text:style-name");
19
- const spanProperties = {
41
+ collectRuns(node, {
20
42
  ...baseProperties,
21
43
  ...require_typed_shared_cascade.resolveStyle(styleName, "text", pkg).properties
22
- };
23
- collectRuns(node.children, spanProperties, pkg, out, hyperlinkTarget);
24
- } else if (node.tag === "text:a") {
25
- const href = require_xml_query.attrValue(node, "xlink:href");
26
- collectRuns(node.children, baseProperties, pkg, out, href ?? hyperlinkTarget);
44
+ }, pkg, out, walk, hyperlinkTarget);
45
+ } else if (node.tag === "text:a") collectRuns(node, baseProperties, pkg, out, walk, require_xml_query.attrValue(node, "xlink:href") ?? hyperlinkTarget);
46
+ else if (require_typed_shared_text.isOdfFieldElement(node)) {
47
+ const startRun = out.length;
48
+ collectRuns(node, baseProperties, pkg, out, walk, hyperlinkTarget);
49
+ walk.extents.push({
50
+ descriptor: require_typed_shared_constructs.odfFieldDescriptor(node),
51
+ startRun,
52
+ endRun: out.length
53
+ });
54
+ } else if (node.tag === "text:bookmark") {
55
+ const name = require_xml_query.attrValue(node, "text:name");
56
+ if (name !== void 0) {
57
+ const runPosition = out.length;
58
+ walk.extents.push({
59
+ descriptor: require_typed_shared_constructs.odfBookmarkAnchorDescriptor(require_xml_entities.decodeXmlText(name)),
60
+ startRun: runPosition,
61
+ endRun: runPosition
62
+ });
63
+ }
64
+ } else if (node.tag === "text:bookmark-start" || node.tag === "text:bookmark-end") {
65
+ const name = require_xml_query.attrValue(node, "text:name");
66
+ if (name !== void 0) walk.halves.push({
67
+ kind: "bookmark",
68
+ side: node.tag === "text:bookmark-start" ? "start" : "end",
69
+ key: require_xml_entities.decodeXmlText(name),
70
+ element: node,
71
+ parent: container,
72
+ runPosition: out.length,
73
+ order: walk.order++,
74
+ descriptor: () => require_typed_shared_constructs.odfBookmarkAnchorDescriptor(require_xml_entities.decodeXmlText(name))
75
+ });
76
+ } else if (node.tag === "text:change") {
77
+ const changeId = require_xml_query.attrValue(node, "text:change-id");
78
+ const descriptor = changeId === void 0 ? void 0 : walk.provenanceRegions?.get(require_xml_entities.decodeXmlText(changeId));
79
+ if (descriptor !== void 0) {
80
+ const runPosition = out.length;
81
+ walk.extents.push({
82
+ descriptor,
83
+ startRun: runPosition,
84
+ endRun: runPosition
85
+ });
86
+ }
87
+ } else if (node.tag === "text:change-start" || node.tag === "text:change-end") {
88
+ const changeId = require_xml_query.attrValue(node, "text:change-id");
89
+ if (changeId !== void 0) walk.halves.push({
90
+ kind: "change",
91
+ side: node.tag === "text:change-start" ? "start" : "end",
92
+ key: require_xml_entities.decodeXmlText(changeId),
93
+ element: node,
94
+ parent: container,
95
+ runPosition: out.length,
96
+ order: walk.order++,
97
+ descriptor: () => walk.provenanceRegions?.get(require_xml_entities.decodeXmlText(changeId))
98
+ });
99
+ } else if (node.tag === "text:note") {
100
+ const noteClass = require_xml_query.attrValue(node, "text:note-class");
101
+ if (noteClass === "footnote" || noteClass === "endnote") {
102
+ const rawId = require_xml_query.attrValue(node, "text:id");
103
+ const name = rawId !== void 0 ? require_xml_entities.decodeXmlText(rawId) : walk.definitions === void 0 ? void 0 : `note${walk.definitions.nextNoteOrdinal++}`;
104
+ const startRun = out.length;
105
+ const citationElement = require_xml_query.findChildElement(node.children, "text:note-citation");
106
+ const citation = citationElement === void 0 ? "" : require_typed_shared_text.decodeOdfText(citationElement);
107
+ if (citation.length > 0) pushRun(out, runFromText(citation, baseProperties), hyperlinkTarget);
108
+ if (name !== void 0) {
109
+ if (walk.definitions !== void 0) {
110
+ const entry = {
111
+ kind: noteClass,
112
+ body: []
113
+ };
114
+ if (citation.length > 0) entry.citation = citation;
115
+ const bodyElement = require_xml_query.findChildElement(node.children, "text:note-body");
116
+ if (bodyElement !== void 0) entry.body = readOdfConstructBodyBlocks(bodyElement, pkg, {
117
+ provenanceRegions: walk.provenanceRegions,
118
+ definitions: walk.definitions
119
+ }, walk.listIdState);
120
+ walk.definitions.entries[`note:${name}`] = entry;
121
+ }
122
+ walk.extents.push({
123
+ descriptor: {
124
+ kind: "anchor",
125
+ anchorType: noteClass,
126
+ name,
127
+ definition: `note:${name}`
128
+ },
129
+ startRun,
130
+ endRun: out.length
131
+ });
132
+ }
133
+ }
134
+ } else if (node.tag === "office:annotation") {
135
+ if (walk.definitions !== void 0) {
136
+ const rawName = require_xml_query.attrValue(node, "office:name");
137
+ const name = rawName !== void 0 ? require_xml_entities.decodeXmlText(rawName) : `annotation${walk.definitions.nextAnnotationOrdinal++}`;
138
+ const entry = {
139
+ kind: "comment",
140
+ body: []
141
+ };
142
+ for (const child of node.children) {
143
+ if (child.type !== "element") continue;
144
+ if (child.tag === "dc:creator") entry.author = require_typed_shared_text.decodeOdfText(child);
145
+ else if (child.tag === "dc:date") entry.dateIso = require_typed_shared_text.decodeOdfText(child);
146
+ }
147
+ entry.body = readOdfConstructBodyBlocks(node, pkg, {
148
+ provenanceRegions: walk.provenanceRegions,
149
+ definitions: walk.definitions
150
+ }, walk.listIdState);
151
+ walk.definitions.entries[`comment:${name}`] = entry;
152
+ walk.halves.push({
153
+ kind: "annotation",
154
+ side: "start",
155
+ key: name,
156
+ element: node,
157
+ parent: container,
158
+ runPosition: out.length,
159
+ order: walk.order++,
160
+ descriptor: () => ({
161
+ kind: "anchor",
162
+ anchorType: "comment",
163
+ name,
164
+ definition: `comment:${name}`
165
+ })
166
+ });
167
+ }
168
+ } else if (node.tag === "office:annotation-end") {
169
+ const rawName = require_xml_query.attrValue(node, "office:name");
170
+ if (rawName !== void 0) walk.halves.push({
171
+ kind: "annotation",
172
+ side: "end",
173
+ key: require_xml_entities.decodeXmlText(rawName),
174
+ element: node,
175
+ parent: container,
176
+ runPosition: out.length,
177
+ order: walk.order++,
178
+ descriptor: () => void 0
179
+ });
27
180
  }
28
181
  }
29
182
  }
@@ -45,14 +198,40 @@ function runFromText(text, properties) {
45
198
  color: properties.color
46
199
  };
47
200
  }
48
- function readOdfParagraph(pElement, pkg) {
201
+ function readOdfParagraph(pElement, pkg, context = {}) {
49
202
  const styleName = require_xml_query.attrValue(pElement, "text:style-name");
50
203
  const paragraphProperties = require_typed_shared_cascade.resolveStyle(styleName, "paragraph", pkg).properties;
204
+ let source;
205
+ if (context.format !== void 0 && styleName !== void 0) {
206
+ const unknownElements = require_typed_shared_cascade.resolveStyleElementChain(styleName, "paragraph", pkg).elements.flatMap((style) => [...require_xml_query.childrenWithTag(style, "style:paragraph-properties").filter((properties) => require_styles_properties.parseParagraphProperties(properties).hasUnknown), ...require_xml_query.childrenWithTag(style, "style:text-properties").filter((properties) => require_styles_properties.parseTextProperties(properties).hasUnknown)]);
207
+ if (unknownElements.length > 0) source = require_typed_shared_constructs.odfResidue(context.format, ...unknownElements);
208
+ }
51
209
  const runs = [];
52
- collectRuns(pElement.children, paragraphProperties, pkg, runs);
210
+ const walk = {
211
+ extents: [],
212
+ halves: [],
213
+ order: 0,
214
+ provenanceRegions: context.provenanceRegions,
215
+ definitions: context.definitions,
216
+ listIdState: context.listIdState ?? { next: 1 }
217
+ };
218
+ collectRuns(pElement, paragraphProperties, pkg, runs, walk);
219
+ const { extents: pairedExtents, paired } = require_typed_shared_constructs.pairOdfMarkerHalves(walk.halves, pElement);
220
+ walk.extents.push(...pairedExtents);
221
+ for (const half of walk.halves) if (half.kind === "annotation" && half.side === "start" && !paired.has(half.element) && !require_typed_shared_constructs.isOdfBlockScopedHalf(half, pElement)) {
222
+ const descriptor = half.descriptor();
223
+ if (descriptor !== void 0) walk.extents.push({
224
+ descriptor,
225
+ startRun: half.runPosition,
226
+ endRun: half.runPosition
227
+ });
228
+ }
229
+ if (context.markersOut !== void 0) context.markersOut.push(...walk.halves);
53
230
  return {
54
231
  kind: "paragraph",
55
232
  runs,
233
+ ...source !== void 0 ? { source } : {},
234
+ ...walk.extents.length > 0 ? { constructs: walk.extents } : {},
56
235
  styleId: styleName,
57
236
  alignment: paragraphProperties.alignment,
58
237
  spacingBeforePt: paragraphProperties.spacingBeforePt,
@@ -1,2 +1,2 @@
1
- import { t as readOdfParagraph } from "../../paragraph-9ii2naJC.cjs";
2
- export { readOdfParagraph };
1
+ import { n as readOdfParagraph, t as OdfParagraphContext } from "../../paragraph-BBmSl_sK.cjs";
2
+ export { OdfParagraphContext, readOdfParagraph };
@@ -1,2 +1,2 @@
1
- import { t as readOdfParagraph } from "../../paragraph-DWNnedIE.js";
2
- export { readOdfParagraph };
1
+ import { n as readOdfParagraph, t as OdfParagraphContext } from "../../paragraph-6hzAZpmi.js";
2
+ export { OdfParagraphContext, readOdfParagraph };
@@ -1,10 +1,32 @@
1
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";
2
+ import { parseParagraphProperties, parseTextProperties } from "../../styles/properties.js";
3
+ import { attrValue, childrenWithTag, findChildElement } from "../../xml/query.js";
4
+ import { decodeOdfText, getOdfSpaceCount, isOdfFieldElement } from "./text.js";
5
+ import { resolveStyle, resolveStyleElementChain } from "./cascade.js";
6
+ import { mintOdfListNumId, readOdfListParagraphs } from "./list.js";
7
+ import { isOdfBlockScopedHalf, odfBookmarkAnchorDescriptor, odfFieldDescriptor, odfResidue, pairOdfMarkerHalves } from "./constructs.js";
5
8
  //#region src/typed/shared/paragraph.ts
6
- function collectRuns(nodes, baseProperties, pkg, out, hyperlinkTarget = void 0) {
7
- for (const node of nodes) {
9
+ function readOdfConstructBodyBlocks(body, pkg, context, listIdState) {
10
+ const blocks = [];
11
+ const bodyContext = {
12
+ ...context,
13
+ listIdState
14
+ };
15
+ for (const child of body.children) {
16
+ if (child.type !== "element") continue;
17
+ if (child.tag === "text:p" || child.tag === "text:h") blocks.push(readOdfParagraph(child, pkg, bodyContext));
18
+ else if (child.tag === "text:list") {
19
+ const numId = mintOdfListNumId(pkg, child, listIdState);
20
+ blocks.push(...readOdfListParagraphs(child, {
21
+ numId,
22
+ level: 0
23
+ }, (element) => readOdfParagraph(element, pkg, bodyContext)));
24
+ }
25
+ }
26
+ return blocks;
27
+ }
28
+ function collectRuns(container, baseProperties, pkg, out, walk, hyperlinkTarget = void 0) {
29
+ for (const node of container.children) {
8
30
  if (node.type === "text") {
9
31
  if (node.value.length > 0) pushRun(out, runFromText(decodeXmlText(node.value), baseProperties), hyperlinkTarget);
10
32
  continue;
@@ -15,14 +37,145 @@ function collectRuns(nodes, baseProperties, pkg, out, hyperlinkTarget = void 0)
15
37
  else if (node.tag === "text:line-break") pushRun(out, runFromText("\n", baseProperties), hyperlinkTarget);
16
38
  else if (node.tag === "text:span") {
17
39
  const styleName = attrValue(node, "text:style-name");
18
- const spanProperties = {
40
+ collectRuns(node, {
19
41
  ...baseProperties,
20
42
  ...resolveStyle(styleName, "text", pkg).properties
21
- };
22
- collectRuns(node.children, spanProperties, pkg, out, hyperlinkTarget);
23
- } else if (node.tag === "text:a") {
24
- const href = attrValue(node, "xlink:href");
25
- collectRuns(node.children, baseProperties, pkg, out, href ?? hyperlinkTarget);
43
+ }, pkg, out, walk, hyperlinkTarget);
44
+ } else if (node.tag === "text:a") collectRuns(node, baseProperties, pkg, out, walk, attrValue(node, "xlink:href") ?? hyperlinkTarget);
45
+ else if (isOdfFieldElement(node)) {
46
+ const startRun = out.length;
47
+ collectRuns(node, baseProperties, pkg, out, walk, hyperlinkTarget);
48
+ walk.extents.push({
49
+ descriptor: odfFieldDescriptor(node),
50
+ startRun,
51
+ endRun: out.length
52
+ });
53
+ } else if (node.tag === "text:bookmark") {
54
+ const name = attrValue(node, "text:name");
55
+ if (name !== void 0) {
56
+ const runPosition = out.length;
57
+ walk.extents.push({
58
+ descriptor: odfBookmarkAnchorDescriptor(decodeXmlText(name)),
59
+ startRun: runPosition,
60
+ endRun: runPosition
61
+ });
62
+ }
63
+ } else if (node.tag === "text:bookmark-start" || node.tag === "text:bookmark-end") {
64
+ const name = attrValue(node, "text:name");
65
+ if (name !== void 0) walk.halves.push({
66
+ kind: "bookmark",
67
+ side: node.tag === "text:bookmark-start" ? "start" : "end",
68
+ key: decodeXmlText(name),
69
+ element: node,
70
+ parent: container,
71
+ runPosition: out.length,
72
+ order: walk.order++,
73
+ descriptor: () => odfBookmarkAnchorDescriptor(decodeXmlText(name))
74
+ });
75
+ } else if (node.tag === "text:change") {
76
+ const changeId = attrValue(node, "text:change-id");
77
+ const descriptor = changeId === void 0 ? void 0 : walk.provenanceRegions?.get(decodeXmlText(changeId));
78
+ if (descriptor !== void 0) {
79
+ const runPosition = out.length;
80
+ walk.extents.push({
81
+ descriptor,
82
+ startRun: runPosition,
83
+ endRun: runPosition
84
+ });
85
+ }
86
+ } else if (node.tag === "text:change-start" || node.tag === "text:change-end") {
87
+ const changeId = attrValue(node, "text:change-id");
88
+ if (changeId !== void 0) walk.halves.push({
89
+ kind: "change",
90
+ side: node.tag === "text:change-start" ? "start" : "end",
91
+ key: decodeXmlText(changeId),
92
+ element: node,
93
+ parent: container,
94
+ runPosition: out.length,
95
+ order: walk.order++,
96
+ descriptor: () => walk.provenanceRegions?.get(decodeXmlText(changeId))
97
+ });
98
+ } else if (node.tag === "text:note") {
99
+ const noteClass = attrValue(node, "text:note-class");
100
+ if (noteClass === "footnote" || noteClass === "endnote") {
101
+ const rawId = attrValue(node, "text:id");
102
+ const name = rawId !== void 0 ? decodeXmlText(rawId) : walk.definitions === void 0 ? void 0 : `note${walk.definitions.nextNoteOrdinal++}`;
103
+ const startRun = out.length;
104
+ const citationElement = findChildElement(node.children, "text:note-citation");
105
+ const citation = citationElement === void 0 ? "" : decodeOdfText(citationElement);
106
+ if (citation.length > 0) pushRun(out, runFromText(citation, baseProperties), hyperlinkTarget);
107
+ if (name !== void 0) {
108
+ if (walk.definitions !== void 0) {
109
+ const entry = {
110
+ kind: noteClass,
111
+ body: []
112
+ };
113
+ if (citation.length > 0) entry.citation = citation;
114
+ const bodyElement = findChildElement(node.children, "text:note-body");
115
+ if (bodyElement !== void 0) entry.body = readOdfConstructBodyBlocks(bodyElement, pkg, {
116
+ provenanceRegions: walk.provenanceRegions,
117
+ definitions: walk.definitions
118
+ }, walk.listIdState);
119
+ walk.definitions.entries[`note:${name}`] = entry;
120
+ }
121
+ walk.extents.push({
122
+ descriptor: {
123
+ kind: "anchor",
124
+ anchorType: noteClass,
125
+ name,
126
+ definition: `note:${name}`
127
+ },
128
+ startRun,
129
+ endRun: out.length
130
+ });
131
+ }
132
+ }
133
+ } else if (node.tag === "office:annotation") {
134
+ if (walk.definitions !== void 0) {
135
+ const rawName = attrValue(node, "office:name");
136
+ const name = rawName !== void 0 ? decodeXmlText(rawName) : `annotation${walk.definitions.nextAnnotationOrdinal++}`;
137
+ const entry = {
138
+ kind: "comment",
139
+ body: []
140
+ };
141
+ for (const child of node.children) {
142
+ if (child.type !== "element") continue;
143
+ if (child.tag === "dc:creator") entry.author = decodeOdfText(child);
144
+ else if (child.tag === "dc:date") entry.dateIso = decodeOdfText(child);
145
+ }
146
+ entry.body = readOdfConstructBodyBlocks(node, pkg, {
147
+ provenanceRegions: walk.provenanceRegions,
148
+ definitions: walk.definitions
149
+ }, walk.listIdState);
150
+ walk.definitions.entries[`comment:${name}`] = entry;
151
+ walk.halves.push({
152
+ kind: "annotation",
153
+ side: "start",
154
+ key: name,
155
+ element: node,
156
+ parent: container,
157
+ runPosition: out.length,
158
+ order: walk.order++,
159
+ descriptor: () => ({
160
+ kind: "anchor",
161
+ anchorType: "comment",
162
+ name,
163
+ definition: `comment:${name}`
164
+ })
165
+ });
166
+ }
167
+ } else if (node.tag === "office:annotation-end") {
168
+ const rawName = attrValue(node, "office:name");
169
+ if (rawName !== void 0) walk.halves.push({
170
+ kind: "annotation",
171
+ side: "end",
172
+ key: decodeXmlText(rawName),
173
+ element: node,
174
+ parent: container,
175
+ runPosition: out.length,
176
+ order: walk.order++,
177
+ descriptor: () => void 0
178
+ });
26
179
  }
27
180
  }
28
181
  }
@@ -44,14 +197,40 @@ function runFromText(text, properties) {
44
197
  color: properties.color
45
198
  };
46
199
  }
47
- function readOdfParagraph(pElement, pkg) {
200
+ function readOdfParagraph(pElement, pkg, context = {}) {
48
201
  const styleName = attrValue(pElement, "text:style-name");
49
202
  const paragraphProperties = resolveStyle(styleName, "paragraph", pkg).properties;
203
+ let source;
204
+ if (context.format !== void 0 && styleName !== void 0) {
205
+ const unknownElements = resolveStyleElementChain(styleName, "paragraph", pkg).elements.flatMap((style) => [...childrenWithTag(style, "style:paragraph-properties").filter((properties) => parseParagraphProperties(properties).hasUnknown), ...childrenWithTag(style, "style:text-properties").filter((properties) => parseTextProperties(properties).hasUnknown)]);
206
+ if (unknownElements.length > 0) source = odfResidue(context.format, ...unknownElements);
207
+ }
50
208
  const runs = [];
51
- collectRuns(pElement.children, paragraphProperties, pkg, runs);
209
+ const walk = {
210
+ extents: [],
211
+ halves: [],
212
+ order: 0,
213
+ provenanceRegions: context.provenanceRegions,
214
+ definitions: context.definitions,
215
+ listIdState: context.listIdState ?? { next: 1 }
216
+ };
217
+ collectRuns(pElement, paragraphProperties, pkg, runs, walk);
218
+ const { extents: pairedExtents, paired } = pairOdfMarkerHalves(walk.halves, pElement);
219
+ walk.extents.push(...pairedExtents);
220
+ for (const half of walk.halves) if (half.kind === "annotation" && half.side === "start" && !paired.has(half.element) && !isOdfBlockScopedHalf(half, pElement)) {
221
+ const descriptor = half.descriptor();
222
+ if (descriptor !== void 0) walk.extents.push({
223
+ descriptor,
224
+ startRun: half.runPosition,
225
+ endRun: half.runPosition
226
+ });
227
+ }
228
+ if (context.markersOut !== void 0) context.markersOut.push(...walk.halves);
52
229
  return {
53
230
  kind: "paragraph",
54
231
  runs,
232
+ ...source !== void 0 ? { source } : {},
233
+ ...walk.extents.length > 0 ? { constructs: walk.extents } : {},
55
234
  styleId: styleName,
56
235
  alignment: paragraphProperties.alignment,
57
236
  spacingBeforePt: paragraphProperties.spacingBeforePt,
@@ -1,2 +1,2 @@
1
- import { n as readCellStyleDecoration, r as readOdfTable, t as CellStyleDecoration } from "../../table-sweV3r9n.cjs";
1
+ import { n as readCellStyleDecoration, r as readOdfTable, t as CellStyleDecoration } from "../../table-BH_Q2n_N.cjs";
2
2
  export { CellStyleDecoration, readCellStyleDecoration, readOdfTable };
@@ -1,2 +1,2 @@
1
- import { n as readCellStyleDecoration, r as readOdfTable, t as CellStyleDecoration } from "../../table-D81TZyBn.js";
1
+ import { n as readCellStyleDecoration, r as readOdfTable, t as CellStyleDecoration } from "../../table-ByOoGcq_.js";
2
2
  export { CellStyleDecoration, readCellStyleDecoration, readOdfTable };
@@ -2,6 +2,59 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_xml_entities = require("../../xml/entities.cjs");
3
3
  const require_xml_query = require("../../xml/query.cjs");
4
4
  //#region src/typed/shared/text.ts
5
+ const ODF_FIELD_TAGS = /* @__PURE__ */ new Set([
6
+ "text:date",
7
+ "text:time",
8
+ "text:page-number",
9
+ "text:page-count",
10
+ "text:page-continuation",
11
+ "text:file-name",
12
+ "text:sheet-name",
13
+ "text:title",
14
+ "text:subject",
15
+ "text:keywords",
16
+ "text:description",
17
+ "text:author-name",
18
+ "text:author-initials",
19
+ "text:sender-firstname",
20
+ "text:sender-lastname",
21
+ "text:sender-initials",
22
+ "text:sender-title",
23
+ "text:sender-position",
24
+ "text:sender-email",
25
+ "text:sender-phone-private",
26
+ "text:sender-phone-work",
27
+ "text:sender-fax",
28
+ "text:sender-company",
29
+ "text:sender-street",
30
+ "text:sender-postal-code",
31
+ "text:sender-city",
32
+ "text:sender-country",
33
+ "text:sender-state-or-province",
34
+ "text:expression",
35
+ "text:measure",
36
+ "text:text-input",
37
+ "text:placeholder",
38
+ "text:drop-down",
39
+ "text:conditional-text",
40
+ "text:hidden-text",
41
+ "text:execute",
42
+ "text:variable-set",
43
+ "text:variable-get",
44
+ "text:variable-input",
45
+ "text:user-field-get",
46
+ "text:user-field-input",
47
+ "text:sequence",
48
+ "text:sequence-ref",
49
+ "text:database-display",
50
+ "text:database-name",
51
+ "text:database-next",
52
+ "text:database-row-select",
53
+ "text:database-value"
54
+ ]);
55
+ function isOdfFieldElement(element) {
56
+ return ODF_FIELD_TAGS.has(element.tag);
57
+ }
5
58
  function getOdfSpaceCount(element) {
6
59
  const raw = require_xml_query.attrValue(element, "text:c");
7
60
  if (raw === void 0) return 1;
@@ -14,7 +67,7 @@ function measureOdfNodeLength(node) {
14
67
  if (node.type !== "element") return 0;
15
68
  if (node.tag === "text:s") return getOdfSpaceCount(node);
16
69
  if (node.tag === "text:tab" || node.tag === "text:line-break") return 1;
17
- if (node.tag === "text:span") return sumOdfNodeLength(node.children);
70
+ if (node.tag === "text:span" || isOdfFieldElement(node)) return sumOdfNodeLength(node.children);
18
71
  return 0;
19
72
  }
20
73
  function sumOdfNodeLength(nodes) {
@@ -28,7 +81,7 @@ function decodeOdfNode(node) {
28
81
  if (node.tag === "text:s") return " ".repeat(getOdfSpaceCount(node));
29
82
  if (node.tag === "text:tab") return " ";
30
83
  if (node.tag === "text:line-break") return "\n";
31
- if (node.tag === "text:span") return decodeOdfText(node);
84
+ if (node.tag === "text:span" || isOdfFieldElement(node)) return decodeOdfText(node);
32
85
  return "";
33
86
  }
34
87
  function decodeOdfText(container) {
@@ -37,7 +90,9 @@ function decodeOdfText(container) {
37
90
  return text;
38
91
  }
39
92
  //#endregion
93
+ exports.ODF_FIELD_TAGS = ODF_FIELD_TAGS;
40
94
  exports.decodeOdfText = decodeOdfText;
41
95
  exports.getOdfSpaceCount = getOdfSpaceCount;
96
+ exports.isOdfFieldElement = isOdfFieldElement;
42
97
  exports.measureOdfNodeLength = measureOdfNodeLength;
43
98
  exports.sumOdfNodeLength = sumOdfNodeLength;
@@ -1,2 +1,2 @@
1
- import { i as sumOdfNodeLength, n as getOdfSpaceCount, r as measureOdfNodeLength, t as decodeOdfText } from "../../text-Cal14ZaX.cjs";
2
- export { decodeOdfText, getOdfSpaceCount, measureOdfNodeLength, sumOdfNodeLength };
1
+ import { a as measureOdfNodeLength, i as isOdfFieldElement, n as decodeOdfText, o as sumOdfNodeLength, r as getOdfSpaceCount, t as ODF_FIELD_TAGS } from "../../text-BAi1tapc.cjs";
2
+ export { ODF_FIELD_TAGS, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, measureOdfNodeLength, sumOdfNodeLength };
@@ -1,2 +1,2 @@
1
- import { i as sumOdfNodeLength, n as getOdfSpaceCount, r as measureOdfNodeLength, t as decodeOdfText } from "../../text-CkNojpZm.js";
2
- export { decodeOdfText, getOdfSpaceCount, measureOdfNodeLength, sumOdfNodeLength };
1
+ import { a as measureOdfNodeLength, i as isOdfFieldElement, n as decodeOdfText, o as sumOdfNodeLength, r as getOdfSpaceCount, t as ODF_FIELD_TAGS } from "../../text-gJ5R0q3u.js";
2
+ export { ODF_FIELD_TAGS, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, measureOdfNodeLength, sumOdfNodeLength };
@@ -1,6 +1,59 @@
1
1
  import { decodeXmlText } from "../../xml/entities.js";
2
2
  import { attrValue } from "../../xml/query.js";
3
3
  //#region src/typed/shared/text.ts
4
+ const ODF_FIELD_TAGS = /* @__PURE__ */ new Set([
5
+ "text:date",
6
+ "text:time",
7
+ "text:page-number",
8
+ "text:page-count",
9
+ "text:page-continuation",
10
+ "text:file-name",
11
+ "text:sheet-name",
12
+ "text:title",
13
+ "text:subject",
14
+ "text:keywords",
15
+ "text:description",
16
+ "text:author-name",
17
+ "text:author-initials",
18
+ "text:sender-firstname",
19
+ "text:sender-lastname",
20
+ "text:sender-initials",
21
+ "text:sender-title",
22
+ "text:sender-position",
23
+ "text:sender-email",
24
+ "text:sender-phone-private",
25
+ "text:sender-phone-work",
26
+ "text:sender-fax",
27
+ "text:sender-company",
28
+ "text:sender-street",
29
+ "text:sender-postal-code",
30
+ "text:sender-city",
31
+ "text:sender-country",
32
+ "text:sender-state-or-province",
33
+ "text:expression",
34
+ "text:measure",
35
+ "text:text-input",
36
+ "text:placeholder",
37
+ "text:drop-down",
38
+ "text:conditional-text",
39
+ "text:hidden-text",
40
+ "text:execute",
41
+ "text:variable-set",
42
+ "text:variable-get",
43
+ "text:variable-input",
44
+ "text:user-field-get",
45
+ "text:user-field-input",
46
+ "text:sequence",
47
+ "text:sequence-ref",
48
+ "text:database-display",
49
+ "text:database-name",
50
+ "text:database-next",
51
+ "text:database-row-select",
52
+ "text:database-value"
53
+ ]);
54
+ function isOdfFieldElement(element) {
55
+ return ODF_FIELD_TAGS.has(element.tag);
56
+ }
4
57
  function getOdfSpaceCount(element) {
5
58
  const raw = attrValue(element, "text:c");
6
59
  if (raw === void 0) return 1;
@@ -13,7 +66,7 @@ function measureOdfNodeLength(node) {
13
66
  if (node.type !== "element") return 0;
14
67
  if (node.tag === "text:s") return getOdfSpaceCount(node);
15
68
  if (node.tag === "text:tab" || node.tag === "text:line-break") return 1;
16
- if (node.tag === "text:span") return sumOdfNodeLength(node.children);
69
+ if (node.tag === "text:span" || isOdfFieldElement(node)) return sumOdfNodeLength(node.children);
17
70
  return 0;
18
71
  }
19
72
  function sumOdfNodeLength(nodes) {
@@ -27,7 +80,7 @@ function decodeOdfNode(node) {
27
80
  if (node.tag === "text:s") return " ".repeat(getOdfSpaceCount(node));
28
81
  if (node.tag === "text:tab") return " ";
29
82
  if (node.tag === "text:line-break") return "\n";
30
- if (node.tag === "text:span") return decodeOdfText(node);
83
+ if (node.tag === "text:span" || isOdfFieldElement(node)) return decodeOdfText(node);
31
84
  return "";
32
85
  }
33
86
  function decodeOdfText(container) {
@@ -36,4 +89,4 @@ function decodeOdfText(container) {
36
89
  return text;
37
90
  }
38
91
  //#endregion
39
- export { decodeOdfText, getOdfSpaceCount, measureOdfNodeLength, sumOdfNodeLength };
92
+ export { ODF_FIELD_TAGS, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, measureOdfNodeLength, sumOdfNodeLength };
@@ -1,4 +1,4 @@
1
- import { Package } from "./model/package.js";
1
+ import { r as Package } from "./package-BUojjTXf.js";
2
2
  //#region src/package-io/write.d.ts
3
3
  declare const MIMETYPE_PART = "mimetype";
4
4
  declare const MANIFEST_PART = "META-INF/manifest.xml";