ooxml-core 1.36.0 → 1.37.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 (245) hide show
  1. package/dist/PptxHandler-2JSQ22VD.cjs +14 -0
  2. package/dist/{PptxHandler-XCYX5DVX.mjs → PptxHandler-3T5DTNKA.mjs} +2 -2
  3. package/dist/PptxHandler-7T7ZS7IK.mjs +5 -0
  4. package/dist/{PresentationBuilder-JBTNOIL7.mjs → PresentationBuilder-D6ZICJWN.mjs} +3 -3
  5. package/dist/{PresentationBuilder-HA56ZY23.cjs → PresentationBuilder-HCMXZQDK.cjs} +6 -6
  6. package/dist/{PresentationBuilder-IVLUEB4K.mjs → PresentationBuilder-XHKNDJMD.mjs} +2 -2
  7. package/dist/automation/index.cjs +21750 -19661
  8. package/dist/automation/index.mjs +21731 -19661
  9. package/dist/chart/index.cjs +1 -1
  10. package/dist/chart/index.mjs +1 -1
  11. package/dist/chart/region-map/index.cjs +1 -1
  12. package/dist/chart/region-map/index.mjs +1 -1
  13. package/dist/{chunk-UQMAPY6D.mjs → chunk-2TQJHNVU.mjs} +1 -1
  14. package/dist/{chunk-RI56PFGL.mjs → chunk-4YBSHQ76.mjs} +5 -5
  15. package/dist/{chunk-XF6ZRA2D.cjs → chunk-AFALJ5TA.cjs} +3 -3
  16. package/dist/{chunk-MK2IBZU6.mjs → chunk-CNIKTXAV.mjs} +1 -1
  17. package/dist/{chunk-PA5ADSTX.cjs → chunk-GZOYXHDF.cjs} +1269 -1269
  18. package/dist/{chunk-LSO5SSFX.mjs → chunk-H2Q42P6P.mjs} +1 -1
  19. package/dist/{chunk-EGBNPVBA.mjs → chunk-J43V3QOA.mjs} +2 -2
  20. package/dist/{chunk-TJXK4D4U.mjs → chunk-M2DFN3SP.mjs} +4 -4
  21. package/dist/{chunk-RPJHMPEL.mjs → chunk-OEM2ECAJ.mjs} +1 -1
  22. package/dist/{chunk-GNGL4BO7.mjs → chunk-RHQQS6LJ.mjs} +4 -4
  23. package/dist/{chunk-A27O7M5X.cjs → chunk-SNID2FDY.cjs} +1 -1
  24. package/dist/{chunk-EDRS3OSM.mjs → chunk-WNAPUUAT.mjs} +1 -0
  25. package/dist/color/theme-palette.d.ts +1 -1
  26. package/dist/color/theme-palette.d.ts.map +1 -1
  27. package/dist/crypto/index.cjs +1 -1
  28. package/dist/crypto/index.mjs +1 -1
  29. package/dist/diagram/index.cjs +1 -1
  30. package/dist/diagram/index.mjs +1 -1
  31. package/dist/docx/block-parser.d.ts.map +1 -1
  32. package/dist/docx/comment-parts.d.ts +33 -0
  33. package/dist/docx/comment-parts.d.ts.map +1 -0
  34. package/dist/docx/comments.d.ts +5 -2
  35. package/dist/docx/comments.d.ts.map +1 -1
  36. package/dist/docx/embedded.cjs +15231 -14731
  37. package/dist/docx/embedded.mjs +15231 -14731
  38. package/dist/docx/glossary.d.ts.map +1 -1
  39. package/dist/docx/index.cjs +10771 -10329
  40. package/dist/docx/index.mjs +10771 -10329
  41. package/dist/docx/layout/index.cjs +81 -73
  42. package/dist/docx/layout/index.mjs +81 -73
  43. package/dist/docx/load/index.cjs +16891 -16391
  44. package/dist/docx/load/index.mjs +16891 -16391
  45. package/dist/docx/page-background.d.ts +4 -3
  46. package/dist/docx/page-background.d.ts.map +1 -1
  47. package/dist/docx/paragraph-text.d.ts +5 -0
  48. package/dist/docx/paragraph-text.d.ts.map +1 -0
  49. package/dist/docx/parse.d.ts.map +1 -1
  50. package/dist/docx/save.d.ts.map +1 -1
  51. package/dist/docx/special-characters.d.ts +2 -0
  52. package/dist/docx/special-characters.d.ts.map +1 -1
  53. package/dist/docx/theme-color.d.ts.map +1 -1
  54. package/dist/docx/ui/index.cjs +135 -135
  55. package/dist/docx/ui/index.mjs +135 -135
  56. package/dist/docx/write-comment-identities.d.ts +8 -0
  57. package/dist/docx/write-comment-identities.d.ts.map +1 -0
  58. package/dist/docx/write-comment-metadata.d.ts +12 -0
  59. package/dist/docx/write-comment-metadata.d.ts.map +1 -0
  60. package/dist/docx/write-comment-text.d.ts +3 -0
  61. package/dist/docx/write-comment-text.d.ts.map +1 -0
  62. package/dist/docx/write-comments.d.ts +1 -4
  63. package/dist/docx/write-comments.d.ts.map +1 -1
  64. package/dist/drawingml/index.cjs +1 -1
  65. package/dist/drawingml/index.mjs +1 -1
  66. package/dist/index.cjs +110 -6
  67. package/dist/index.mjs +91 -6
  68. package/dist/math/index.cjs +1 -1
  69. package/dist/math/index.mjs +1 -1
  70. package/dist/opc/index.cjs +78 -3
  71. package/dist/opc/index.mjs +78 -3
  72. package/dist/opc/signature/index.d.ts +1 -0
  73. package/dist/opc/signature/index.d.ts.map +1 -1
  74. package/dist/opc/signature/package.d.ts +12 -0
  75. package/dist/opc/signature/package.d.ts.map +1 -0
  76. package/dist/pptx/automation/index.cjs +21 -4
  77. package/dist/pptx/automation/index.d.ts +1 -0
  78. package/dist/pptx/automation/index.d.ts.map +1 -1
  79. package/dist/pptx/automation/index.mjs +16 -6
  80. package/dist/pptx/automation/schemas/index.cjs +1 -0
  81. package/dist/pptx/automation/schemas/index.mjs +1 -1
  82. package/dist/pptx/automation/schemas/presentation-schemas.cjs +1 -0
  83. package/dist/pptx/automation/schemas/presentation-schemas.d.ts +1 -0
  84. package/dist/pptx/automation/schemas/presentation-schemas.d.ts.map +1 -1
  85. package/dist/pptx/automation/schemas/presentation-schemas.mjs +1 -1
  86. package/dist/pptx/cli/index.cjs +10 -4
  87. package/dist/pptx/cli/index.mjs +4 -4
  88. package/dist/pptx/converter/index.cjs +7 -1
  89. package/dist/pptx/converter/index.mjs +2 -2
  90. package/dist/pptx/editor/render/custom-show-operations.cjs +2 -2
  91. package/dist/pptx/editor/render/custom-show-operations.mjs +1 -1
  92. package/dist/pptx/editor/render/find-replace.cjs +15 -15
  93. package/dist/pptx/editor/render/find-replace.mjs +2 -2
  94. package/dist/pptx/editor/render/slide-operations.cjs +9 -9
  95. package/dist/pptx/editor/render/slide-operations.mjs +3 -3
  96. package/dist/pptx/index.cjs +10 -4
  97. package/dist/pptx/index.mjs +5 -5
  98. package/dist/pptx/ui/index.d.ts +1 -1
  99. package/dist/teams/index.cjs +812 -95
  100. package/dist/teams/index.mjs +811 -95
  101. package/dist/visio/bevel-3d.d.ts +6 -10
  102. package/dist/visio/bevel-3d.d.ts.map +1 -1
  103. package/dist/visio/bevel-shading.d.ts +72 -0
  104. package/dist/visio/bevel-shading.d.ts.map +1 -0
  105. package/dist/visio/cff-recalc.d.ts.map +1 -1
  106. package/dist/visio/collab/index.cjs +1 -1
  107. package/dist/visio/collab/index.mjs +1 -1
  108. package/dist/visio/data-graphic-instance.d.ts +44 -0
  109. package/dist/visio/data-graphic-instance.d.ts.map +1 -0
  110. package/dist/visio/data-graphic-masters.d.ts +38 -0
  111. package/dist/visio/data-graphic-masters.d.ts.map +1 -0
  112. package/dist/visio/data-graphic-place.d.ts +34 -0
  113. package/dist/visio/data-graphic-place.d.ts.map +1 -0
  114. package/dist/visio/edit-commands.d.ts +3 -1
  115. package/dist/visio/edit-commands.d.ts.map +1 -1
  116. package/dist/visio/edit-data-graphic-guard.d.ts +13 -0
  117. package/dist/visio/edit-data-graphic-guard.d.ts.map +1 -0
  118. package/dist/visio/edit-data-graphic-owner.d.ts +9 -0
  119. package/dist/visio/edit-data-graphic-owner.d.ts.map +1 -0
  120. package/dist/visio/edit-data-graphic-refresh.d.ts +14 -0
  121. package/dist/visio/edit-data-graphic-refresh.d.ts.map +1 -0
  122. package/dist/visio/edit-data-graphic.d.ts +33 -0
  123. package/dist/visio/edit-data-graphic.d.ts.map +1 -0
  124. package/dist/visio/edit-formatting-text-commands.d.ts +8 -0
  125. package/dist/visio/edit-formatting-text-commands.d.ts.map +1 -1
  126. package/dist/visio/edit-formatting-text-extra.d.ts +14 -0
  127. package/dist/visio/edit-formatting-text-extra.d.ts.map +1 -1
  128. package/dist/visio/edit-formatting-text.d.ts.map +1 -1
  129. package/dist/visio/edit-formatting.d.ts.map +1 -1
  130. package/dist/visio/edit-shape-data.d.ts.map +1 -1
  131. package/dist/visio/edit-swimlane-cff.d.ts +28 -0
  132. package/dist/visio/edit-swimlane-cff.d.ts.map +1 -0
  133. package/dist/visio/edit-swimlane-clone.d.ts +8 -4
  134. package/dist/visio/edit-swimlane-clone.d.ts.map +1 -1
  135. package/dist/visio/edit-swimlane-layout.d.ts +6 -1
  136. package/dist/visio/edit-swimlane-layout.d.ts.map +1 -1
  137. package/dist/visio/edit-swimlane-ops.d.ts.map +1 -1
  138. package/dist/visio/edit.d.ts.map +1 -1
  139. package/dist/visio/formula-analyze.d.ts.map +1 -1
  140. package/dist/visio/formula-evaluate.d.ts.map +1 -1
  141. package/dist/visio/formula.d.ts.map +1 -1
  142. package/dist/visio/index.cjs +2980 -1707
  143. package/dist/visio/index.d.ts +2 -1
  144. package/dist/visio/index.d.ts.map +1 -1
  145. package/dist/visio/index.mjs +2971 -1708
  146. package/dist/visio/master-list.d.ts +3 -3
  147. package/dist/visio/master-list.d.ts.map +1 -1
  148. package/dist/visio/model.d.ts +6 -1
  149. package/dist/visio/model.d.ts.map +1 -1
  150. package/dist/visio/rotation-presets.d.ts +25 -0
  151. package/dist/visio/rotation-presets.d.ts.map +1 -0
  152. package/dist/visio/shape-structure.d.ts.map +1 -1
  153. package/dist/visio/shapes.d.ts +2 -0
  154. package/dist/visio/shapes.d.ts.map +1 -1
  155. package/dist/visio/solid-3d.d.ts +9 -0
  156. package/dist/visio/solid-3d.d.ts.map +1 -1
  157. package/dist/visio/style.d.ts.map +1 -1
  158. package/dist/visio/ui/data-graphic-config.d.ts +4 -19
  159. package/dist/visio/ui/data-graphic-config.d.ts.map +1 -1
  160. package/dist/visio/ui/data-graphic-items.d.ts.map +1 -1
  161. package/dist/visio/ui/data-graphic-native.d.ts +20 -0
  162. package/dist/visio/ui/data-graphic-native.d.ts.map +1 -0
  163. package/dist/visio/ui/data-graphics.d.ts.map +1 -1
  164. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  165. package/dist/visio/ui/index.cjs +3130 -1821
  166. package/dist/visio/ui/index.mjs +3128 -1822
  167. package/dist/visio/ui/org-chart-belt.d.ts.map +1 -1
  168. package/dist/visio/ui/scene-validation.d.ts.map +1 -1
  169. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  170. package/dist/visio/ui/swimlane.d.ts.map +1 -1
  171. package/dist/visio/ui/text-dialog.d.ts +12 -0
  172. package/dist/visio/ui/text-dialog.d.ts.map +1 -1
  173. package/dist/xlsx/collab/index.cjs +45 -2
  174. package/dist/xlsx/collab/index.mjs +45 -2
  175. package/dist/xlsx/collab/part-specs.d.ts.map +1 -1
  176. package/dist/xlsx/collab/sheets.d.ts +1 -0
  177. package/dist/xlsx/collab/sheets.d.ts.map +1 -1
  178. package/dist/xlsx/edit/annotations.d.ts +4 -0
  179. package/dist/xlsx/edit/annotations.d.ts.map +1 -1
  180. package/dist/xlsx/edit/clipboard-annotations.d.ts.map +1 -1
  181. package/dist/xlsx/edit/comment-identities.d.ts +4 -0
  182. package/dist/xlsx/edit/comment-identities.d.ts.map +1 -0
  183. package/dist/xlsx/edit/session.d.ts.map +1 -1
  184. package/dist/xlsx/edit/sheets.d.ts.map +1 -1
  185. package/dist/xlsx/edit/types.d.ts +3 -0
  186. package/dist/xlsx/edit/types.d.ts.map +1 -1
  187. package/dist/xlsx/formula/functions/filterxml.d.ts +2 -0
  188. package/dist/xlsx/formula/functions/filterxml.d.ts.map +1 -0
  189. package/dist/xlsx/formula/functions/registry.d.ts.map +1 -1
  190. package/dist/xlsx/index.cjs +1007 -285
  191. package/dist/xlsx/index.mjs +988 -285
  192. package/dist/xlsx/layout/split.d.ts +3 -1
  193. package/dist/xlsx/layout/split.d.ts.map +1 -1
  194. package/dist/xlsx/load/index.cjs +809 -126
  195. package/dist/xlsx/load/index.mjs +790 -126
  196. package/dist/xlsx/model.d.ts +19 -7
  197. package/dist/xlsx/model.d.ts.map +1 -1
  198. package/dist/xlsx/read/comments.d.ts +3 -1
  199. package/dist/xlsx/read/comments.d.ts.map +1 -1
  200. package/dist/xlsx/read/conditional.d.ts +2 -2
  201. package/dist/xlsx/read/conditional.d.ts.map +1 -1
  202. package/dist/xlsx/read/data-validations.d.ts +7 -0
  203. package/dist/xlsx/read/data-validations.d.ts.map +1 -0
  204. package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
  205. package/dist/xlsx/read/worksheet.d.ts.map +1 -1
  206. package/dist/xlsx/ui/commands/i18n/messages.d.ts.map +1 -1
  207. package/dist/xlsx/ui/commands/i18n/navigation.d.ts.map +1 -1
  208. package/dist/xlsx/ui/grid/geometry.d.ts +3 -0
  209. package/dist/xlsx/ui/grid/geometry.d.ts.map +1 -1
  210. package/dist/xlsx/ui/index.cjs +952 -168
  211. package/dist/xlsx/ui/index.mjs +933 -169
  212. package/dist/xlsx/ui/selection.d.ts +3 -0
  213. package/dist/xlsx/ui/selection.d.ts.map +1 -1
  214. package/dist/xlsx/validation-extensions.d.ts +6 -0
  215. package/dist/xlsx/validation-extensions.d.ts.map +1 -0
  216. package/dist/xlsx/write/comment-ids.d.ts +14 -0
  217. package/dist/xlsx/write/comment-ids.d.ts.map +1 -0
  218. package/dist/xlsx/write/comment-mentions.d.ts +6 -0
  219. package/dist/xlsx/write/comment-mentions.d.ts.map +1 -0
  220. package/dist/xlsx/write/comment-persons.d.ts +16 -0
  221. package/dist/xlsx/write/comment-persons.d.ts.map +1 -0
  222. package/dist/xlsx/write/comments.d.ts +5 -11
  223. package/dist/xlsx/write/comments.d.ts.map +1 -1
  224. package/dist/xlsx/write/conditional.d.ts +2 -2
  225. package/dist/xlsx/write/conditional.d.ts.map +1 -1
  226. package/dist/xlsx/write/data-validations.d.ts +6 -0
  227. package/dist/xlsx/write/data-validations.d.ts.map +1 -0
  228. package/dist/xlsx/write/save.d.ts.map +1 -1
  229. package/dist/xlsx/write/sheet-parts.d.ts +4 -0
  230. package/dist/xlsx/write/sheet-parts.d.ts.map +1 -1
  231. package/dist/xlsx/write/sheet-props.d.ts.map +1 -1
  232. package/dist/xlsx/write/threaded-comments.d.ts +19 -0
  233. package/dist/xlsx/write/threaded-comments.d.ts.map +1 -0
  234. package/dist/xlsx/write/worksheet.d.ts.map +1 -1
  235. package/dist/xml/index.cjs +31 -1
  236. package/dist/xml/index.d.ts +1 -0
  237. package/dist/xml/index.d.ts.map +1 -1
  238. package/dist/xml/index.mjs +11 -2
  239. package/dist/xml/xml.d.ts +2 -0
  240. package/dist/xml/xml.d.ts.map +1 -1
  241. package/dist/xml/xpath.d.ts +9 -0
  242. package/dist/xml/xpath.d.ts.map +1 -0
  243. package/package.json +2 -1
  244. package/dist/PptxHandler-5UDSMCBG.cjs +0 -14
  245. package/dist/PptxHandler-TTRTAQAR.mjs +0 -5
@@ -1,4 +1,5 @@
1
1
  import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
2
+ import * as xpath from 'xpath';
2
3
  import JSZip3 from 'jszip';
3
4
  import * as Y15 from 'yjs';
4
5
  import * as decoding from 'lib0/decoding';
@@ -455,7 +456,7 @@ function parseXml(xml, options = {}) {
455
456
  try {
456
457
  parsed = new DOMParser({
457
458
  onError: (level4, message) => {
458
- if (level4 !== "warning") parseError = message;
459
+ if (level4 !== "warning" || options.warningsAsErrors) parseError = message;
459
460
  }
460
461
  }).parseFromString(xml, "application/xml");
461
462
  } catch (error) {
@@ -522,6 +523,19 @@ var init_lite = __esm({
522
523
  "xml/lite.ts"() {
523
524
  }
524
525
  });
526
+ function selectXmlNodes(expression, node2, options = {}) {
527
+ return compiler.parse(expression).select({
528
+ node: node2,
529
+ ...options.namespaces ? { namespaces: options.namespaces } : {},
530
+ allowAnyNamespaceForNoPrefix: options.matchDefaultNamespace ?? false
531
+ });
532
+ }
533
+ var compiler;
534
+ var init_xpath = __esm({
535
+ "xml/xpath.ts"() {
536
+ compiler = xpath;
537
+ }
538
+ });
525
539
 
526
540
  // xml/index.ts
527
541
  var init_xml2 = __esm({
@@ -529,6 +543,7 @@ var init_xml2 = __esm({
529
543
  init_namespaces();
530
544
  init_xml();
531
545
  init_lite();
546
+ init_xpath();
532
547
  }
533
548
  });
534
549
 
@@ -1287,31 +1302,90 @@ function parsePersons(xml) {
1287
1302
  }
1288
1303
  return persons;
1289
1304
  }
1290
- function parseThreadedComments(xml, persons) {
1305
+ function parseThreadedComments(xml, persons, personsXml) {
1291
1306
  if (!xml) return [];
1292
1307
  const root = parseXml(xml, { label: "XLSX threaded comments" }).documentElement;
1293
1308
  const roots = /* @__PURE__ */ new Map();
1309
+ const personNames = new Map([...persons].map(([id, name2]) => [id.toUpperCase(), name2]));
1294
1310
  const order = [];
1295
- for (const node2 of children(root, "threadedComment", NS.tc)) {
1296
- const address2 = parseAddress(att(node2, "ref") ?? "");
1311
+ const nodes = children(root, "threadedComment", NS.tc);
1312
+ const byId = new Map(nodes.map((node2) => [(att(node2, "id") ?? "").toUpperCase(), node2]));
1313
+ const parentRoot = (parent) => {
1314
+ const seen = /* @__PURE__ */ new Set();
1315
+ while (parent) {
1316
+ parent = parent.toUpperCase();
1317
+ if (seen.has(parent)) break;
1318
+ if (roots.has(parent)) return roots.get(parent);
1319
+ seen.add(parent);
1320
+ parent = att(byId.get(parent), "parentId");
1321
+ }
1322
+ return void 0;
1323
+ };
1324
+ for (const node2 of [
1325
+ ...nodes.filter((n) => !att(n, "parentId")),
1326
+ ...nodes.filter((n) => att(n, "parentId"))
1327
+ ]) {
1328
+ const parentComment = parentRoot(att(node2, "parentId"));
1329
+ const address2 = parseAddress(att(node2, "ref") ?? "") ?? parentComment?.address;
1297
1330
  if (!address2) continue;
1298
- const author = persons.get(att(node2, "personId") ?? "") ?? "";
1331
+ const author = personNames.get((att(node2, "personId") ?? "").toUpperCase()) ?? "";
1299
1332
  const text = xText(children(node2, "text", NS.tc)[0]);
1300
1333
  const date = att(node2, "dT");
1301
- const parent = att(node2, "parentId");
1302
- const parentComment = parent ? roots.get(parent) : void 0;
1303
1334
  if (parentComment) {
1304
- const reply = { author, text };
1335
+ const reply = { author, text, threadedXml: selfContainedXml(node2) };
1305
1336
  if (date) reply.date = date;
1306
1337
  (parentComment.replies ??= []).push(reply);
1307
1338
  continue;
1308
1339
  }
1309
- const comment = { address: address2, author, text, replies: [] };
1310
- roots.set(att(node2, "id") ?? `${order.length}`, comment);
1340
+ const comment = {
1341
+ address: address2,
1342
+ author,
1343
+ text,
1344
+ replies: [],
1345
+ threadedXml: selfContainedXml(node2)
1346
+ };
1347
+ if (date) comment.date = date;
1348
+ const resolved = boolAttr(node2, "done");
1349
+ if (resolved !== void 0) comment.resolved = resolved;
1350
+ roots.set((att(node2, "id") ?? `${order.length}`).toUpperCase(), comment);
1311
1351
  order.push(comment);
1312
1352
  }
1353
+ for (const comment of order)
1354
+ comment.replies?.sort((a2, b) => {
1355
+ const aDate = a2.date ? Date.parse(a2.date) : NaN;
1356
+ const bDate = b.date ? Date.parse(b.date) : NaN;
1357
+ return Number.isFinite(aDate) && Number.isFinite(bDate) ? aDate - bDate : 0;
1358
+ });
1359
+ if (personsXml) {
1360
+ const records = /* @__PURE__ */ new Map();
1361
+ for (const person of children(parseXml(personsXml).documentElement, "person", NS.tc)) {
1362
+ const id = att(person, "id") ?? "";
1363
+ records.set(id.toUpperCase(), [id, selfContainedXml(person)]);
1364
+ }
1365
+ for (const comment of order) {
1366
+ const ids = /* @__PURE__ */ new Set();
1367
+ for (const message of [comment, ...comment.replies ?? []]) {
1368
+ const node2 = parseXml(message.threadedXml).documentElement;
1369
+ ids.add((att(node2, "personId") ?? "").toUpperCase());
1370
+ const mentions = first(node2, "mentions", NS.tc);
1371
+ if (mentions)
1372
+ for (const mention of children(mentions, "mention", NS.tc))
1373
+ ids.add((att(mention, "mentionpersonId") ?? "").toUpperCase());
1374
+ }
1375
+ const kept = [...ids].flatMap((id) => records.has(id) ? [records.get(id)] : []);
1376
+ if (kept.length) comment.threadedPersons = Object.fromEntries(kept);
1377
+ }
1378
+ }
1313
1379
  return order;
1314
1380
  }
1381
+ function threadedCommentEnvelope(xml) {
1382
+ if (!xml) return void 0;
1383
+ const doc = parseXml(xml);
1384
+ for (const node2 of children(doc.documentElement, "threadedComment", NS.tc)) {
1385
+ doc.documentElement.removeChild(node2);
1386
+ }
1387
+ return buildXml(doc);
1388
+ }
1315
1389
  function mergeComments(legacy, threaded) {
1316
1390
  if (!threaded.length) return legacy;
1317
1391
  const key = (c2) => `${c2.address.row}:${c2.address.col}`;
@@ -1466,7 +1540,7 @@ var init_xml_out = __esm({
1466
1540
  }
1467
1541
  });
1468
1542
 
1469
- // xlsx/write/comments.ts
1543
+ // xlsx/write/comment-ids.ts
1470
1544
  function guidFrom(seed) {
1471
1545
  let h1 = 2166136261;
1472
1546
  let h2 = 16777619;
@@ -1482,6 +1556,440 @@ function guidFrom(seed) {
1482
1556
  const s = hex.join("");
1483
1557
  return `{${s.slice(0, 8)}-${s.slice(8, 12)}-4${s.slice(13, 16)}-8${s.slice(17, 20)}-${s.slice(20, 32)}}`;
1484
1558
  }
1559
+ var validGuid, CommentIds;
1560
+ var init_comment_ids = __esm({
1561
+ "xlsx/write/comment-ids.ts"() {
1562
+ init_xml2();
1563
+ init_address();
1564
+ validGuid = (id) => /^\{[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}\}$/i.test(id);
1565
+ CommentIds = class {
1566
+ reserved = /* @__PURE__ */ new Map();
1567
+ used = /* @__PURE__ */ new Set();
1568
+ mentions = /* @__PURE__ */ new WeakMap();
1569
+ constructor(workbook) {
1570
+ for (const matching2 of [true, false])
1571
+ for (const sheet of workbook?.sheets ?? []) {
1572
+ for (const comment of sheet.comments)
1573
+ for (const message of [comment, ...comment.replies ?? []]) {
1574
+ if (comment.regenerateThreadIds) continue;
1575
+ if (!message.threadedXml) continue;
1576
+ const node2 = parseXml(message.threadedXml).documentElement;
1577
+ if (node2.getAttribute("ref") === formatAddress(comment.address) !== matching2)
1578
+ continue;
1579
+ this.reserve(node2.getAttribute("id") ?? "", message);
1580
+ const mentions = first(node2, "mentions", NS.tc);
1581
+ if (mentions)
1582
+ children(mentions, "mention", NS.tc).forEach((mention, index2) => {
1583
+ this.reserve(
1584
+ mention.getAttribute("mentionId") ?? "",
1585
+ this.mentionOwner(message, index2)
1586
+ );
1587
+ });
1588
+ }
1589
+ }
1590
+ }
1591
+ reserve(id, owner) {
1592
+ const key = id.toUpperCase();
1593
+ if (validGuid(id) && !this.reserved.has(key)) this.reserved.set(key, owner);
1594
+ }
1595
+ mentionOwner(message, index2) {
1596
+ let owners = this.mentions.get(message);
1597
+ if (!owners) this.mentions.set(message, owners = []);
1598
+ return owners[index2] ??= {};
1599
+ }
1600
+ claim(source3, seed, owner, preserve = true) {
1601
+ const key = source3.toUpperCase();
1602
+ if (preserve && validGuid(source3) && !this.used.has(key) && (!this.reserved.has(key) || this.reserved.get(key) === owner)) {
1603
+ this.used.add(key);
1604
+ return source3;
1605
+ }
1606
+ let index2 = 0;
1607
+ let id = guidFrom(seed);
1608
+ while (this.used.has(id) || this.reserved.has(id)) id = guidFrom(`${seed}:${++index2}`);
1609
+ this.used.add(id);
1610
+ return id;
1611
+ }
1612
+ };
1613
+ }
1614
+ });
1615
+
1616
+ // text/text-diff.ts
1617
+ function shortestEdit(n, m, same8, maxEdits) {
1618
+ const max = Math.min(n + m, maxEdits);
1619
+ const offset2 = max + 1;
1620
+ const v = new Int32Array(2 * max + 3);
1621
+ const trace = [];
1622
+ for (let d = 0; d <= max; d++) {
1623
+ for (let k = -d; k <= d; k += 2) {
1624
+ const down = k === -d || k !== d && v[offset2 + k - 1] < v[offset2 + k + 1];
1625
+ let x = down ? v[offset2 + k + 1] : v[offset2 + k - 1] + 1;
1626
+ let y = x - k;
1627
+ while (x < n && y < m && same8(x, y)) {
1628
+ x++;
1629
+ y++;
1630
+ }
1631
+ v[offset2 + k] = x;
1632
+ if (x >= n && y >= m) return backtrack(trace, n, m, d);
1633
+ }
1634
+ trace.push(v.slice(offset2 - d, offset2 + d + 1));
1635
+ }
1636
+ return void 0;
1637
+ }
1638
+ function backtrack(trace, n, m, d) {
1639
+ const edits = [];
1640
+ let x = n;
1641
+ let y = m;
1642
+ for (let step = d; step > 0; step--) {
1643
+ const previous = trace[step - 1];
1644
+ const at = (k2) => previous[k2 + step - 1];
1645
+ const k = x - y;
1646
+ const down = k === -step || k !== step && at(k - 1) < at(k + 1);
1647
+ const before = down ? k + 1 : k - 1;
1648
+ const startX = at(before);
1649
+ const startY = startX - before;
1650
+ edits.push(down ? [startX, startY, true] : [startX, startY, false]);
1651
+ x = startX;
1652
+ y = startY;
1653
+ }
1654
+ return edits.reverse();
1655
+ }
1656
+ function changesOf(edits) {
1657
+ const changes = [];
1658
+ for (const [x, y, inserts] of edits) {
1659
+ const last = changes.at(-1);
1660
+ if (last && last.fromEnd === x && last.toEnd === y) {
1661
+ if (inserts) last.toEnd++;
1662
+ else last.fromEnd++;
1663
+ } else
1664
+ changes.push({
1665
+ fromStart: x,
1666
+ fromEnd: inserts ? x : x + 1,
1667
+ toStart: y,
1668
+ toEnd: inserts ? y + 1 : y
1669
+ });
1670
+ }
1671
+ return changes;
1672
+ }
1673
+ function characterChanges(a2, b, maxEdits) {
1674
+ const edits = shortestEdit(
1675
+ a2.length,
1676
+ b.length,
1677
+ (x, y) => a2.charCodeAt(x) === b.charCodeAt(y),
1678
+ maxEdits
1679
+ );
1680
+ return edits && changesOf(edits);
1681
+ }
1682
+ function tokensOf(text, ids) {
1683
+ const tokens2 = [];
1684
+ const starts = [];
1685
+ for (const match2 of text.matchAll(TOKEN)) {
1686
+ let id = ids.get(match2[0]);
1687
+ if (id === void 0) ids.set(match2[0], id = ids.size);
1688
+ tokens2.push(id);
1689
+ starts.push(match2.index);
1690
+ }
1691
+ starts.push(text.length);
1692
+ return { tokens: tokens2, starts };
1693
+ }
1694
+ function tokenChanges(a2, b, maxEdits) {
1695
+ const ids = /* @__PURE__ */ new Map();
1696
+ const from = tokensOf(a2, ids);
1697
+ const to = tokensOf(b, ids);
1698
+ const edits = shortestEdit(
1699
+ from.tokens.length,
1700
+ to.tokens.length,
1701
+ (x, y) => from.tokens[x] === to.tokens[y],
1702
+ maxEdits
1703
+ );
1704
+ if (!edits) return void 0;
1705
+ let budget = maxEdits;
1706
+ return changesOf(edits).flatMap((stretch) => {
1707
+ const change = {
1708
+ fromStart: from.starts[stretch.fromStart],
1709
+ fromEnd: from.starts[stretch.fromEnd],
1710
+ toStart: to.starts[stretch.toStart],
1711
+ toEnd: to.starts[stretch.toEnd]
1712
+ };
1713
+ const inner = change.fromEnd > change.fromStart && change.toEnd > change.toStart ? characterChanges(
1714
+ a2.slice(change.fromStart, change.fromEnd),
1715
+ b.slice(change.toStart, change.toEnd),
1716
+ budget
1717
+ ) : void 0;
1718
+ if (!inner) return [change];
1719
+ for (const found of inner)
1720
+ budget -= found.fromEnd - found.fromStart + found.toEnd - found.toStart;
1721
+ return inner.map((found) => ({
1722
+ fromStart: found.fromStart + change.fromStart,
1723
+ fromEnd: found.fromEnd + change.fromStart,
1724
+ toStart: found.toStart + change.toStart,
1725
+ toEnd: found.toEnd + change.toStart
1726
+ }));
1727
+ });
1728
+ }
1729
+ function diffText(from, to, maxEdits = 500) {
1730
+ let start = 0;
1731
+ while (start < from.length && start < to.length && from.charCodeAt(start) === to.charCodeAt(start))
1732
+ start++;
1733
+ let end = 0;
1734
+ while (end < from.length - start && end < to.length - start && from.charCodeAt(from.length - 1 - end) === to.charCodeAt(to.length - 1 - end))
1735
+ end++;
1736
+ const a2 = from.slice(start, from.length - end);
1737
+ const b = to.slice(start, to.length - end);
1738
+ if (!a2.length && !b.length) return [];
1739
+ const found = a2.length && b.length ? characterChanges(a2, b, maxEdits) ?? tokenChanges(a2, b, maxEdits) : void 0;
1740
+ const changes = found ?? [{ fromStart: 0, fromEnd: a2.length, toStart: 0, toEnd: b.length }];
1741
+ const result2 = [];
1742
+ for (const change of changes) {
1743
+ const placed = {
1744
+ fromStart: change.fromStart + start,
1745
+ fromEnd: change.fromEnd + start,
1746
+ toStart: change.toStart + start,
1747
+ toEnd: change.toEnd + start
1748
+ };
1749
+ if (placed.fromStart > 0 && placed.toStart > 0 && (isLowSurrogate(from, placed.fromStart) || isLowSurrogate(to, placed.toStart))) {
1750
+ placed.fromStart--;
1751
+ placed.toStart--;
1752
+ }
1753
+ if (isLowSurrogate(from, placed.fromEnd) || isLowSurrogate(to, placed.toEnd)) {
1754
+ placed.fromEnd++;
1755
+ placed.toEnd++;
1756
+ }
1757
+ const last = result2.at(-1);
1758
+ if (last && placed.fromStart <= last.fromEnd) {
1759
+ last.fromEnd = Math.max(last.fromEnd, placed.fromEnd);
1760
+ last.toEnd = Math.max(last.toEnd, placed.toEnd);
1761
+ } else result2.push(placed);
1762
+ }
1763
+ return result2;
1764
+ }
1765
+ var isLowSurrogate, TOKEN;
1766
+ var init_text_diff = __esm({
1767
+ "text/text-diff.ts"() {
1768
+ isLowSurrogate = (text, at) => {
1769
+ const code = text.charCodeAt(at);
1770
+ return code >= 56320 && code <= 57343;
1771
+ };
1772
+ TOKEN = /[\p{L}\p{N}\p{M}]+|\s+|[\s\S]/gu;
1773
+ }
1774
+ });
1775
+
1776
+ // xlsx/write/comment-mentions.ts
1777
+ function patchCommentMentions(node2, before, message, ids, commentId, preserveIds) {
1778
+ const container = first(node2, "mentions", NS.tc);
1779
+ if (!container) return;
1780
+ const changes = diffText(before, message.text);
1781
+ children(container, "mention", NS.tc).forEach((mention, index2) => {
1782
+ const start = Number(mention.getAttribute("startIndex"));
1783
+ const length = Number(mention.getAttribute("length"));
1784
+ const end = start + length;
1785
+ let shift3 = 0;
1786
+ let intact = Number.isInteger(start) && start >= 0 && Number.isInteger(length) && length > 0 && end <= before.length;
1787
+ for (const change of changes) {
1788
+ if (change.fromEnd <= start)
1789
+ shift3 += change.toEnd - change.toStart - (change.fromEnd - change.fromStart);
1790
+ else if (change.fromStart < end) intact = false;
1791
+ }
1792
+ if (!intact) {
1793
+ container.removeChild(mention);
1794
+ return;
1795
+ }
1796
+ mention.setAttribute("startIndex", String(start + shift3));
1797
+ mention.setAttribute(
1798
+ "mentionId",
1799
+ ids.claim(
1800
+ mention.getAttribute("mentionId") ?? "",
1801
+ `${commentId}:mention:${index2}`,
1802
+ ids.mentionOwner(message, index2),
1803
+ preserveIds
1804
+ )
1805
+ );
1806
+ });
1807
+ if (!children(container, "mention", NS.tc).length) node2.removeChild(container);
1808
+ }
1809
+ var init_comment_mentions = __esm({
1810
+ "xlsx/write/comment-mentions.ts"() {
1811
+ init_text_diff();
1812
+ init_xml2();
1813
+ }
1814
+ });
1815
+
1816
+ // xlsx/write/threaded-comments.ts
1817
+ var ThreadedCommentsWriter;
1818
+ var init_threaded_comments = __esm({
1819
+ "xlsx/write/threaded-comments.ts"() {
1820
+ init_xml2();
1821
+ init_comment_ids();
1822
+ init_comment_mentions();
1823
+ init_xml_out();
1824
+ ThreadedCommentsWriter = class {
1825
+ constructor(persons, options = {}) {
1826
+ this.persons = persons;
1827
+ this.doc = parseXml(
1828
+ options.envelope ?? `${XML_HEADER}<ThreadedComments xmlns="${NS.tc}" xmlns:x="${NS.x}"/>`
1829
+ );
1830
+ for (const node2 of children(this.doc.documentElement, "threadedComment", NS.tc))
1831
+ this.doc.documentElement.removeChild(node2);
1832
+ this.ids = options.ids ?? new CommentIds();
1833
+ }
1834
+ persons;
1835
+ doc;
1836
+ ids;
1837
+ count = 0;
1838
+ add(comment, ref, sheetName) {
1839
+ this.persons.retain(comment.threadedPersons);
1840
+ const preserve = !comment.regenerateThreadIds;
1841
+ const prepare2 = (message, seed) => {
1842
+ const source3 = parseXml(message.threadedXml ?? `<threadedComment xmlns="${NS.tc}"/>`);
1843
+ const priorId = source3.documentElement.getAttribute("id") ?? "";
1844
+ const id = this.ids.claim(priorId, seed, message, preserve);
1845
+ return { message, source: source3, priorId, id };
1846
+ };
1847
+ const root = prepare2(comment, `${sheetName}!${ref}:${comment.text}`);
1848
+ const replies = (comment.replies ?? []).map(
1849
+ (reply, index2) => prepare2(reply, `${root.id}:reply:${index2}:${reply.text}`)
1850
+ );
1851
+ const identities = new Map(
1852
+ [root, ...replies].filter((item2) => item2.priorId).map((item2) => [item2.priorId.toUpperCase(), item2.id])
1853
+ );
1854
+ this.message(comment, ref, root.source, root.id, preserve, void 0, comment.resolved);
1855
+ for (const reply of replies)
1856
+ this.message(
1857
+ reply.message,
1858
+ ref,
1859
+ reply.source,
1860
+ reply.id,
1861
+ preserve,
1862
+ identities.get(
1863
+ (reply.source.documentElement.getAttribute("parentId") ?? "").toUpperCase()
1864
+ ) ?? root.id
1865
+ );
1866
+ return root.id;
1867
+ }
1868
+ message(message, ref, source3, id, preserve, parent, resolved) {
1869
+ const node2 = source3.documentElement;
1870
+ const personId = this.persons.id(message.author, node2.getAttribute("personId") ?? void 0);
1871
+ for (const [key, value] of Object.entries({
1872
+ id,
1873
+ ref,
1874
+ personId,
1875
+ dT: message.date,
1876
+ parentId: parent
1877
+ })) {
1878
+ if (value === void 0) node2.removeAttribute(key);
1879
+ else node2.setAttribute(key, value);
1880
+ }
1881
+ if (!parent) {
1882
+ if (resolved === void 0) node2.removeAttribute("done");
1883
+ else node2.setAttribute("done", resolved ? "1" : "0");
1884
+ }
1885
+ let text = first(node2, "text", NS.tc);
1886
+ patchCommentMentions(node2, text?.textContent ?? "", message, this.ids, id, preserve);
1887
+ if (!text) {
1888
+ text = source3.createElementNS(NS.tc, node2.prefix ? `${node2.prefix}:text` : "text");
1889
+ node2.insertBefore(text, node2.firstChild);
1890
+ }
1891
+ text.textContent = message.text;
1892
+ const root = this.doc.documentElement;
1893
+ root.insertBefore(this.doc.importNode(node2, true), first(root, "extLst", NS.tc) ?? null);
1894
+ this.count++;
1895
+ }
1896
+ xml() {
1897
+ return this.count ? buildXml(this.doc) : void 0;
1898
+ }
1899
+ };
1900
+ }
1901
+ });
1902
+
1903
+ // xlsx/write/comment-persons.ts
1904
+ var PersonRegistry;
1905
+ var init_comment_persons = __esm({
1906
+ "xlsx/write/comment-persons.ts"() {
1907
+ init_xml2();
1908
+ init_comment_ids();
1909
+ init_xml_out();
1910
+ PersonRegistry = class {
1911
+ constructor(existing, source3) {
1912
+ this.source = source3;
1913
+ for (const [id, name2] of existing ?? []) {
1914
+ this.names.set(id, name2);
1915
+ this.identities.set(id.toUpperCase(), id);
1916
+ if (!this.byName.has(name2)) this.byName.set(name2, id);
1917
+ }
1918
+ }
1919
+ source;
1920
+ names = /* @__PURE__ */ new Map();
1921
+ byName = /* @__PURE__ */ new Map();
1922
+ identities = /* @__PURE__ */ new Map();
1923
+ added = /* @__PURE__ */ new Map();
1924
+ retained = /* @__PURE__ */ new Map();
1925
+ get changed() {
1926
+ return this.added.size > 0;
1927
+ }
1928
+ /** Bring referenced account records along with a thread copied from another workbook. */
1929
+ retain(records) {
1930
+ for (const [sourceId, xml] of Object.entries(records ?? {})) {
1931
+ const known = this.identities.get(sourceId.toUpperCase());
1932
+ if (known && (this.source || this.retained.has(known))) continue;
1933
+ const node2 = parseXml(xml).documentElement;
1934
+ if (node2.localName !== "person" || node2.namespaceURI !== NS.tc || node2.getAttribute("id")?.toUpperCase() !== sourceId.toUpperCase())
1935
+ continue;
1936
+ const name2 = node2.getAttribute("displayName") ?? "";
1937
+ const id = known ?? node2.getAttribute("id");
1938
+ this.retained.set(id, xml);
1939
+ this.names.set(id, name2);
1940
+ this.identities.set(id.toUpperCase(), id);
1941
+ this.added.set(id, name2);
1942
+ if (!this.byName.has(name2)) this.byName.set(name2, id);
1943
+ }
1944
+ }
1945
+ id(name2, preferred) {
1946
+ const preferredId = preferred ? this.identities.get(preferred.toUpperCase()) : void 0;
1947
+ if (preferredId && this.names.get(preferredId) === name2) return preferredId;
1948
+ let id = this.byName.get(name2);
1949
+ if (!id) {
1950
+ let index2 = 0;
1951
+ id = guidFrom(`person:${name2}`);
1952
+ while (this.identities.has(id.toUpperCase())) id = guidFrom(`person:${name2}:${++index2}`);
1953
+ this.byName.set(name2, id);
1954
+ this.names.set(id, name2);
1955
+ this.identities.set(id.toUpperCase(), id);
1956
+ this.added.set(id, name2);
1957
+ }
1958
+ return id;
1959
+ }
1960
+ xml() {
1961
+ if (this.source && !this.changed) return this.source;
1962
+ const doc = parseXml(
1963
+ this.source ?? `${XML_HEADER}<personList xmlns="${NS.tc}" xmlns:x="${NS.x}"/>`
1964
+ );
1965
+ const root = doc.documentElement;
1966
+ for (const [id, name2] of this.source ? this.added : this.names) {
1967
+ const retained = this.retained.get(id);
1968
+ if (retained) {
1969
+ root.insertBefore(
1970
+ doc.importNode(parseXml(retained).documentElement, true),
1971
+ first(root, "extLst", NS.tc) ?? null
1972
+ );
1973
+ continue;
1974
+ }
1975
+ const person = doc.createElementNS(NS.tc, root.prefix ? `${root.prefix}:person` : "person");
1976
+ for (const [key, value] of Object.entries({
1977
+ id,
1978
+ displayName: name2,
1979
+ userId: name2,
1980
+ providerId: "None"
1981
+ })) {
1982
+ person.setAttribute(key, value);
1983
+ }
1984
+ root.insertBefore(person, first(root, "extLst", NS.tc) ?? null);
1985
+ }
1986
+ return buildXml(doc);
1987
+ }
1988
+ };
1989
+ }
1990
+ });
1991
+
1992
+ // xlsx/write/comments.ts
1485
1993
  function vmlShape(comment, index2, id) {
1486
1994
  const { row: row2, col } = comment.address;
1487
1995
  const anchor = `${col + 1}, 15, ${Math.max(0, row2 - 1)}, 10, ${col + 3}, 15, ${row2 + 3}, 4`;
@@ -1502,7 +2010,7 @@ function vmlXml(comments, layout2) {
1502
2010
  }
1503
2011
  return `<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="${data}"/></o:shapelayout>` + NOTE_SHAPETYPE + shapes + "</xml>";
1504
2012
  }
1505
- function commentParts(comments, sheetNumber, persons, sheetName, layout2) {
2013
+ function commentParts(comments, sheetNumber, persons, sheetName, layout2, threadOptions) {
1506
2014
  const authors = [];
1507
2015
  const authorId = (name2) => {
1508
2016
  let id = authors.indexOf(name2);
@@ -1512,18 +2020,11 @@ function commentParts(comments, sheetNumber, persons, sheetName, layout2) {
1512
2020
  const sorted2 = [...comments].sort(
1513
2021
  (a2, b) => a2.address.row - b.address.row || a2.address.col - b.address.col
1514
2022
  );
1515
- let threaded = "";
2023
+ const threads = new ThreadedCommentsWriter(persons, threadOptions);
1516
2024
  const list2 = sorted2.map((comment) => {
1517
2025
  const ref = formatAddress(comment.address);
1518
2026
  if (comment.replies) {
1519
- const id = guidFrom(`${sheetName}!${ref}:${comment.text}`);
1520
- const personId = persons.id(comment.author);
1521
- threaded += `<threadedComment ref="${ref}" personId="${personId}" id="${id}"><text>${escapeText2(comment.text)}</text></threadedComment>`;
1522
- comment.replies.forEach((reply, index2) => {
1523
- const replyId = guidFrom(`${id}:reply:${index2}:${reply.text}`);
1524
- const dT = reply.date ? ` dT="${escapeAttr3(reply.date)}"` : "";
1525
- threaded += `<threadedComment ref="${ref}"${dT} personId="${persons.id(reply.author)}" id="${replyId}" parentId="${id}"><text>${escapeText2(reply.text)}</text></threadedComment>`;
1526
- });
2027
+ const id = threads.add(comment, ref, sheetName);
1527
2028
  const fallback = `${THREADED_NOTE}${comment.text}${comment.replies.map((r) => `
1528
2029
  Reply:
1529
2030
  ${r.text}`).join("")}`;
@@ -1541,42 +2042,19 @@ Reply:
1541
2042
  }
1542
2043
  );
1543
2044
  const parts = { comments: commentsXml, vml };
1544
- if (threaded)
1545
- parts.threaded = `${XML_HEADER}<ThreadedComments xmlns="${NS.tc}" xmlns:x="${NS.x}">${threaded}</ThreadedComments>`;
2045
+ const threaded = threads.xml();
2046
+ if (threaded) parts.threaded = threaded;
1546
2047
  return parts;
1547
2048
  }
1548
- var THREADED_NOTE, PersonRegistry, NOTE_SHAPETYPE;
2049
+ var THREADED_NOTE, NOTE_SHAPETYPE;
1549
2050
  var init_comments2 = __esm({
1550
2051
  "xlsx/write/comments.ts"() {
1551
2052
  init_xml2();
1552
2053
  init_address();
1553
2054
  init_xml_out();
2055
+ init_threaded_comments();
2056
+ init_comment_persons();
1554
2057
  THREADED_NOTE = "[Threaded comment]\n\nYour version of Excel allows you to read this threaded comment; however, any edits to it will get removed if the file is opened in a newer version of Excel. Learn more: https://go.microsoft.com/fwlink/?linkid=870924\n\nComment:\n ";
1555
- PersonRegistry = class {
1556
- names = /* @__PURE__ */ new Map();
1557
- byName = /* @__PURE__ */ new Map();
1558
- constructor(existing) {
1559
- for (const [id, name2] of existing ?? []) {
1560
- this.names.set(id, name2);
1561
- if (!this.byName.has(name2)) this.byName.set(name2, id);
1562
- }
1563
- }
1564
- id(name2) {
1565
- let id = this.byName.get(name2);
1566
- if (!id) {
1567
- id = guidFrom(`person:${name2}`);
1568
- this.byName.set(name2, id);
1569
- this.names.set(id, name2);
1570
- }
1571
- return id;
1572
- }
1573
- xml() {
1574
- const people = [...this.names].map(
1575
- ([id, name2]) => `<person displayName="${escapeAttr3(name2)}" id="${id}" userId="${escapeAttr3(name2)}" providerId="None"/>`
1576
- ).join("");
1577
- return `${XML_HEADER}<personList xmlns="${NS.tc}" xmlns:x="${NS.x}">${people}</personList>`;
1578
- }
1579
- };
1580
2058
  NOTE_SHAPETYPE = '<v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path gradientshapeok="t" o:connecttype="rect"/></v:shapetype>';
1581
2059
  }
1582
2060
  });
@@ -8811,7 +9289,7 @@ function readSheetView(sheetViews) {
8811
9289
  const cols = Math.max(0, Math.round(numAttr(pane, "xSplit") ?? 0));
8812
9290
  if (rows || cols) view.freeze = { rows, cols };
8813
9291
  }
8814
- const split2 = pane && state === "split";
9292
+ const split2 = pane && (state === void 0 || state === "split");
8815
9293
  if (split2) {
8816
9294
  const x = Math.max(0, Math.round(numAttr(pane, "xSplit") ?? 0));
8817
9295
  const y = Math.max(0, Math.round(numAttr(pane, "ySplit") ?? 0));
@@ -8819,9 +9297,8 @@ function readSheetView(sheetViews) {
8819
9297
  view.split = { x, y };
8820
9298
  const first2 = parseAddress(att(node2, "topLeftCell") ?? "");
8821
9299
  if (first2) view.split.topLeft = first2;
8822
- const active = att(pane, "activePane");
8823
- if (active && PANES.has(active))
8824
- view.split.activePane = active;
9300
+ const active = att(pane, "activePane") ?? "topLeft";
9301
+ if (PANES.has(active)) view.split.activePane = active;
8825
9302
  }
8826
9303
  }
8827
9304
  const topLeft = parseAddress(
@@ -8978,6 +9455,146 @@ var init_sheet_props = __esm({
8978
9455
  }
8979
9456
  });
8980
9457
 
9458
+ // xlsx/read/data-validations.ts
9459
+ var VALIDATION_XM;
9460
+ var init_data_validations = __esm({
9461
+ "xlsx/read/data-validations.ts"() {
9462
+ VALIDATION_XM = "http://schemas.microsoft.com/office/excel/2006/main";
9463
+ }
9464
+ });
9465
+
9466
+ // xlsx/write/data-validations.ts
9467
+ function usesValidationExtension(dv) {
9468
+ if (dv.extensionXml) return true;
9469
+ return [dv.formula1, dv.formula2].some((formula2) => {
9470
+ if (!formula2) return false;
9471
+ try {
9472
+ return tokenize(formula2).some((token2) => token2.prefix !== void 0);
9473
+ } catch {
9474
+ return false;
9475
+ }
9476
+ });
9477
+ }
9478
+ function validationAttributes(dv) {
9479
+ return {
9480
+ type: dv.type === "none" ? void 0 : dv.type,
9481
+ errorStyle: dv.errorStyle,
9482
+ operator: dv.operator,
9483
+ allowBlank: dv.allowBlank || void 0,
9484
+ showDropDown: dv.showDropDown === false ? true : void 0,
9485
+ showInputMessage: dv.showInputMessage || void 0,
9486
+ showErrorMessage: dv.showErrorMessage || void 0,
9487
+ errorTitle: dv.errorTitle,
9488
+ error: dv.error,
9489
+ promptTitle: dv.promptTitle,
9490
+ prompt: dv.prompt
9491
+ };
9492
+ }
9493
+ function dataValidationXml(dv, extended) {
9494
+ const sqref2 = dv.ranges.map(formatRange).join(" ");
9495
+ if (!extended) {
9496
+ const formulas = ["formula1", "formula2"].map(
9497
+ (key) => dv[key] === void 0 ? "" : `<${key}>${escapeText2(addFuturePrefixes(dv[key]))}</${key}>`
9498
+ ).join("");
9499
+ const values2 = attrs({ ...validationAttributes(dv), sqref: sqref2 });
9500
+ return formulas ? `<dataValidation${values2}>${formulas}</dataValidation>` : `<dataValidation${values2}/>`;
9501
+ }
9502
+ const doc = parseXml(
9503
+ dv.extensionXml || `<x14:dataValidation xmlns:x14="${NS.x14}" xmlns:xm="${VALIDATION_XM}"/>`
9504
+ );
9505
+ const node2 = doc.documentElement;
9506
+ for (const [key, value] of Object.entries(validationAttributes(dv))) {
9507
+ if (value === void 0) node2.removeAttribute(key);
9508
+ else node2.setAttribute(key, typeof value === "boolean" ? "1" : value);
9509
+ }
9510
+ for (const key of ["formula1", "formula2"]) {
9511
+ let container = first(node2, key, NS.x14);
9512
+ if (dv[key] === void 0) {
9513
+ if (container) node2.removeChild(container);
9514
+ continue;
9515
+ }
9516
+ if (!container) {
9517
+ container = doc.createElementNS(NS.x14, `x14:${key}`);
9518
+ const next = key === "formula1" ? first(node2, "formula2", NS.x14) : void 0;
9519
+ node2.insertBefore(container, next ?? first(node2, "sqref", VALIDATION_XM) ?? null);
9520
+ }
9521
+ let formula2 = first(container, "f", VALIDATION_XM);
9522
+ if (!formula2) {
9523
+ formula2 = doc.createElementNS(VALIDATION_XM, "xm:f");
9524
+ container.appendChild(formula2);
9525
+ }
9526
+ formula2.textContent = addFuturePrefixes(dv[key]);
9527
+ }
9528
+ let ranges = first(node2, "sqref", VALIDATION_XM);
9529
+ if (!ranges) {
9530
+ ranges = doc.createElementNS(VALIDATION_XM, "xm:sqref");
9531
+ node2.appendChild(ranges);
9532
+ }
9533
+ ranges.textContent = sqref2;
9534
+ return buildXml(doc);
9535
+ }
9536
+ function dataValidationsXml(validations) {
9537
+ const items = validations.filter((dv) => dv.ranges.length && !usesValidationExtension(dv)).map((dv) => dataValidationXml(dv, false));
9538
+ return items.length ? `<dataValidations count="${items.length}">${items.join("")}</dataValidations>` : "";
9539
+ }
9540
+ var init_data_validations2 = __esm({
9541
+ "xlsx/write/data-validations.ts"() {
9542
+ init_xml2();
9543
+ init_address();
9544
+ init_tokenizer();
9545
+ init_data_validations();
9546
+ init_formula_text();
9547
+ init_xml_out();
9548
+ }
9549
+ });
9550
+
9551
+ // xlsx/validation-extensions.ts
9552
+ function validationExtensionsXml(sheet, extensions, ids = /* @__PURE__ */ new Set()) {
9553
+ const rules = sheet.dataValidations.filter(
9554
+ (dv) => dv.ranges.length && usesValidationExtension(dv)
9555
+ );
9556
+ const doc = parseXml(extensions || `<extLst xmlns="${NS.x}"/>`);
9557
+ let ext = elements(doc.documentElement).find(
9558
+ (node2) => node2.getAttribute("uri")?.toUpperCase() === URI.toUpperCase()
9559
+ );
9560
+ if (!rules.length) {
9561
+ const collection2 = first(ext, "dataValidations", NS.x14);
9562
+ if (ext && collection2 && !elements(collection2).length) {
9563
+ ext.removeChild(collection2);
9564
+ if (!elements(ext).length) doc.documentElement.removeChild(ext);
9565
+ }
9566
+ return elements(doc.documentElement).length ? inlineFragment(buildXml(doc)) : "";
9567
+ }
9568
+ if (!ext) {
9569
+ ext = doc.createElementNS(NS.x, "ext");
9570
+ ext.setAttribute("uri", URI);
9571
+ doc.documentElement.appendChild(ext);
9572
+ }
9573
+ let collection = first(ext, "dataValidations", NS.x14);
9574
+ if (!collection) {
9575
+ collection = doc.createElementNS(NS.x14, "x14:dataValidations");
9576
+ ext.appendChild(collection);
9577
+ }
9578
+ for (const rule of rules) {
9579
+ const node2 = doc.importNode(parseXml(dataValidationXml(rule, true)).documentElement, true);
9580
+ const id = node2.getAttributeNS(NS.xr, "uid");
9581
+ if (id && ids.has(id)) node2.removeAttributeNS(NS.xr, "uid");
9582
+ else if (id) ids.add(id);
9583
+ collection.appendChild(node2);
9584
+ }
9585
+ collection.setAttribute("count", String(children(collection, "dataValidation", NS.x14).length));
9586
+ return inlineFragment(buildXml(doc));
9587
+ }
9588
+ var URI;
9589
+ var init_validation_extensions = __esm({
9590
+ "xlsx/validation-extensions.ts"() {
9591
+ init_xml2();
9592
+ init_data_validations2();
9593
+ init_xml_out();
9594
+ URI = "{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}";
9595
+ }
9596
+ });
9597
+
8981
9598
  // xlsx/conditional-extensions.ts
8982
9599
  function writeSettings(node2, rule) {
8983
9600
  const bar = first(node2, "dataBar", NS.x14);
@@ -9021,14 +9638,14 @@ function conditionalExtensionsXml(sheet) {
9021
9638
  for (const xml of preserved.slice(1))
9022
9639
  for (const node2 of elements(parseXml(xml).documentElement))
9023
9640
  doc.documentElement.appendChild(doc.importNode(node2, true));
9024
- let ext = elements(doc.documentElement).find((e) => e.getAttribute("uri") === URI);
9641
+ let ext = elements(doc.documentElement).find((e) => e.getAttribute("uri") === URI2);
9025
9642
  let collection = first(ext, "conditionalFormattings", NS.x14);
9026
9643
  for (const format of sheet.conditionalFormats)
9027
9644
  for (const rule of format.rules) {
9028
9645
  if (rule.type !== "dataBar" || !rule.extensionXml || !rule.extensionId) continue;
9029
9646
  if (!ext) {
9030
9647
  ext = doc.createElementNS(NS.x, "ext");
9031
- ext.setAttribute("uri", URI);
9648
+ ext.setAttribute("uri", URI2);
9032
9649
  doc.documentElement.appendChild(ext);
9033
9650
  }
9034
9651
  if (!collection) {
@@ -9048,7 +9665,7 @@ function conditionalExtensionsXml(sheet) {
9048
9665
  }
9049
9666
  return elements(doc.documentElement).length ? inlineFragment(buildXml(doc)) : "";
9050
9667
  }
9051
- var XM, URI;
9668
+ var XM, URI2;
9052
9669
  var init_conditional_extensions = __esm({
9053
9670
  "xlsx/conditional-extensions.ts"() {
9054
9671
  init_xml2();
@@ -9056,7 +9673,7 @@ var init_conditional_extensions = __esm({
9056
9673
  init_xml_util();
9057
9674
  init_xml_out();
9058
9675
  XM = "http://schemas.microsoft.com/office/excel/2006/main";
9059
- URI = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}";
9676
+ URI2 = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}";
9060
9677
  }
9061
9678
  });
9062
9679
 
@@ -44382,6 +44999,92 @@ var init_text_extra = __esm({
44382
44999
  }
44383
45000
  });
44384
45001
 
45002
+ // xlsx/formula/functions/filterxml.ts
45003
+ function preservesSpace(node2) {
45004
+ for (let current = node2; current; current = current.parentNode) {
45005
+ if (current.nodeType !== 1) continue;
45006
+ const value = current.getAttributeNS(XML, "space");
45007
+ if (value) return value === "preserve";
45008
+ }
45009
+ return false;
45010
+ }
45011
+ function prepare(root) {
45012
+ const namespaces = /* @__PURE__ */ Object.create(null);
45013
+ const visit = (element3) => {
45014
+ for (const attr3 of Array.from(element3.attributes)) {
45015
+ if (attr3.namespaceURI !== XMLNS2 || attr3.localName === "xmlns") continue;
45016
+ const prior = namespaces[attr3.localName];
45017
+ if (prior !== void 0 && prior !== attr3.value) throw new Error("Conflicting namespaces");
45018
+ namespaces[attr3.localName] = attr3.value;
45019
+ }
45020
+ for (const child5 of Array.from(element3.childNodes)) {
45021
+ if (child5.nodeType === 1) visit(child5);
45022
+ else if (child5.nodeType === 3 && !child5.nodeValue?.trim() && !preservesSpace(element3))
45023
+ element3.removeChild(child5);
45024
+ }
45025
+ };
45026
+ visit(root);
45027
+ return namespaces;
45028
+ }
45029
+ function nodeValue(node2) {
45030
+ let text;
45031
+ if (node2.nodeType === 2) text = (node2.nodeValue ?? "").trim();
45032
+ else if (node2.nodeType === 1) {
45033
+ const preserve = preservesSpace(node2);
45034
+ text = Array.from(node2.childNodes).filter((child5) => child5.nodeType === 3 || child5.nodeType === 4).map((child5) => {
45035
+ const value = child5.nodeValue ?? "";
45036
+ return preserve || child5.nodeType === 4 ? value : value.trim();
45037
+ }).join("");
45038
+ } else return ERR.VALUE;
45039
+ if (!text) return ERR.VALUE;
45040
+ if (/^(true|false)$/i.test(text)) return text.toLowerCase() === "true";
45041
+ const date = /^(\d{1,4})[-/](\d{1,2})[-/](\d{1,4})(.*)$/.exec(text.trim());
45042
+ let numberText = text;
45043
+ if (date) {
45044
+ let year = Number(date[1]);
45045
+ if (year < 100) year += year < 30 ? 2e3 : 1900;
45046
+ numberText = `${year}-${date[2]}-${date[3]}${date[4]?.replace(/^T/, " ") ?? ""}`;
45047
+ }
45048
+ return parseNumberText(numberText) ?? text;
45049
+ }
45050
+ var XML, XMLNS2, FILTERXML;
45051
+ var init_filterxml = __esm({
45052
+ "xlsx/formula/functions/filterxml.ts"() {
45053
+ init_xml2();
45054
+ init_text_number();
45055
+ init_values();
45056
+ init_helpers();
45057
+ XML = "http://www.w3.org/XML/1998/namespace";
45058
+ XMLNS2 = "http://www.w3.org/2000/xmlns/";
45059
+ FILTERXML = spec(
45060
+ "FILTERXML",
45061
+ "Web",
45062
+ "FILTERXML(xml, xpath)",
45063
+ "Returns XML element or attribute values selected by XPath, as a column.",
45064
+ 2,
45065
+ 2,
45066
+ (args) => {
45067
+ const xml = str(args[0]);
45068
+ const expression = str(args[1]);
45069
+ if (xml.length > 32767 || expression.length > 32767) return ERR.VALUE;
45070
+ let nodes;
45071
+ try {
45072
+ const doc = parseXml(xml, { warningsAsErrors: true, label: "FILTERXML" });
45073
+ nodes = selectXmlNodes(expression, doc, {
45074
+ namespaces: prepare(doc.documentElement),
45075
+ matchDefaultNamespace: true
45076
+ });
45077
+ } catch {
45078
+ return ERR.VALUE;
45079
+ }
45080
+ if (!nodes.length) return ERR.VALUE;
45081
+ chargeArrayCells(nodes.length);
45082
+ return new Matrix(nodes.map((node2) => [nodeValue(node2)]));
45083
+ }
45084
+ );
45085
+ }
45086
+ });
45087
+
44385
45088
  // xlsx/formula/functions/registry.ts
44386
45089
  var ALL, REGISTRY, getFunction;
44387
45090
  var init_registry2 = __esm({
@@ -44404,6 +45107,7 @@ var init_registry2 = __esm({
44404
45107
  init_groupby();
44405
45108
  init_modern();
44406
45109
  init_text_extra();
45110
+ init_filterxml();
44407
45111
  ALL = [
44408
45112
  ...MATH_FUNCTIONS,
44409
45113
  ...MATRIX_FUNCTIONS,
@@ -44412,6 +45116,7 @@ var init_registry2 = __esm({
44412
45116
  ...LOGICAL_FUNCTIONS,
44413
45117
  ...TEXT_FUNCTIONS,
44414
45118
  ...TEXT_EXTRA_FUNCTIONS,
45119
+ FILTERXML,
44415
45120
  BAHTTEXT,
44416
45121
  GETPIVOTDATA,
44417
45122
  ...GROUPBY_FUNCTIONS,
@@ -45749,6 +46454,16 @@ var init_page_setup = __esm({
45749
46454
  }
45750
46455
  });
45751
46456
 
46457
+ // xlsx/layout/split.ts
46458
+ function splitActivePane(split2) {
46459
+ const valid2 = split2.x > 0 && split2.y > 0 ? ["topLeft", "topRight", "bottomLeft", "bottomRight"] : split2.y > 0 ? ["topLeft", "bottomLeft"] : ["topLeft", "topRight"];
46460
+ return split2.activePane && valid2.includes(split2.activePane) ? split2.activePane : valid2[valid2.length - 1];
46461
+ }
46462
+ var init_split = __esm({
46463
+ "xlsx/layout/split.ts"() {
46464
+ }
46465
+ });
46466
+
45752
46467
  // xlsx/write/filter-columns.ts
45753
46468
  function criteriaOf(column2) {
45754
46469
  const { values: values2, blank, dateGroups, custom, top10, dynamic, color, icon, hiddenButton } = column2;
@@ -45927,16 +46642,14 @@ function dimensionXml(sheet) {
45927
46642
  const used = usedRange(sheet);
45928
46643
  return `<dimension ref="${used ? formatRange(used) : "A1"}"/>`;
45929
46644
  }
45930
- function splitActivePane(split2) {
45931
- const both = split2.x > 0 && split2.y > 0;
45932
- const valid2 = both ? ["topLeft", "topRight", "bottomLeft", "bottomRight"] : split2.y > 0 ? ["topLeft", "bottomLeft"] : ["topLeft", "topRight"];
45933
- if (split2.activePane && valid2.includes(split2.activePane)) return split2.activePane;
45934
- return both ? "bottomRight" : split2.y > 0 ? "bottomLeft" : "topRight";
45935
- }
45936
46645
  function selectionXml(selection, pane) {
46646
+ const activeCellId = selection.ranges.findIndex(
46647
+ (range) => rangeContains(range, selection.active)
46648
+ );
45937
46649
  return el("selection", {
45938
46650
  pane,
45939
46651
  activeCell: formatAddress(selection.active),
46652
+ activeCellId: activeCellId > 0 ? activeCellId : void 0,
45940
46653
  sqref: sqref(selection.ranges) || formatAddress(selection.active)
45941
46654
  });
45942
46655
  }
@@ -46090,6 +46803,7 @@ var init_sheet_props2 = __esm({
46090
46803
  init_xml2();
46091
46804
  init_address();
46092
46805
  init_cells();
46806
+ init_split();
46093
46807
  init_sheet_props();
46094
46808
  init_xml_util();
46095
46809
  init_filter_columns2();
@@ -46575,28 +47289,6 @@ function conditionalFormatsXml(formats, styles) {
46575
47289
  return `<conditionalFormatting sqref="${format.ranges.map((r) => formatRange(r)).join(" ")}">${rules}</conditionalFormatting>`;
46576
47290
  }).join("");
46577
47291
  }
46578
- function dataValidationsXml(validations) {
46579
- const items = validations.filter((dv) => dv.ranges.length).map((dv) => {
46580
- const hideDropDown = dv.showDropDown === false ? true : void 0;
46581
- const values2 = attrs({
46582
- type: dv.type === "none" ? void 0 : dv.type,
46583
- errorStyle: dv.errorStyle,
46584
- operator: dv.operator,
46585
- allowBlank: dv.allowBlank || void 0,
46586
- showDropDown: hideDropDown,
46587
- showInputMessage: dv.showInputMessage || void 0,
46588
- showErrorMessage: dv.showErrorMessage || void 0,
46589
- errorTitle: dv.errorTitle,
46590
- error: dv.error,
46591
- promptTitle: dv.promptTitle,
46592
- prompt: dv.prompt,
46593
- sqref: dv.ranges.map((r) => formatRange(r)).join(" ")
46594
- });
46595
- const formulas = (dv.formula1 !== void 0 ? formulaXml2(dv.formula1, "formula1") : "") + (dv.formula2 !== void 0 ? formulaXml2(dv.formula2, "formula2") : "");
46596
- return formulas ? `<dataValidation${values2}>${formulas}</dataValidation>` : `<dataValidation${values2}/>`;
46597
- });
46598
- return items.length ? `<dataValidations count="${items.length}">${items.join("")}</dataValidations>` : "";
46599
- }
46600
47292
  var cfvoXml, formulaXml2, quote, TEXT_OPERATORS;
46601
47293
  var init_conditional = __esm({
46602
47294
  "xlsx/write/conditional.ts"() {
@@ -47569,6 +48261,8 @@ function writeComments(ctx, sheet, index2, partName, rels) {
47569
48261
  const { writer, source: source3 } = ctx;
47570
48262
  const name2 = (pattern) => writer.uniqueName(pattern, ctx.reserved);
47571
48263
  const fromSource = source3 && sheet.partName && source3.has(sheet.partName);
48264
+ const sourceThreaded = fromSource ? source3.targetOfType(sheet.partName ?? "", RELATIONSHIP_TYPES.threadedComment) : void 0;
48265
+ const threadEnvelope = sheet.threadedCommentsXml ?? threadedCommentEnvelope(sourceThreaded ? source3?.text(sourceThreaded) : void 0);
47572
48266
  const sourceVml = fromSource ? sourceVmlPart(source3, sheet.partName ?? "") : void 0;
47573
48267
  const kept = source3 && sourceVml && !writer.has(sourceVml) ? stripNoteShapes(source3.text(sourceVml) ?? "") : void 0;
47574
48268
  const base = kept && kept.kept > 0 ? kept.xml : void 0;
@@ -47593,11 +48287,13 @@ function writeComments(ctx, sheet, index2, partName, rels) {
47593
48287
  parseLegacyComments(legacyPart ? source3.text(legacyPart) : void 0),
47594
48288
  parseThreadedComments(
47595
48289
  threadedPart ? source3.text(threadedPart) : void 0,
47596
- parsePersons(personsPart ? source3.text(personsPart) : void 0)
48290
+ parsePersons(personsPart ? source3.text(personsPart) : void 0),
48291
+ personsPart ? source3.text(personsPart) : void 0
47597
48292
  )
47598
48293
  );
47599
48294
  const free = [legacyPart, threadedPart, vmlPart].every((p) => !p || !writer.has(p));
47600
- if (legacyPart && vmlPart && free && sameModel(before, sheet.comments)) {
48295
+ const envelope = threadedCommentEnvelope(threadedPart ? source3.text(threadedPart) : void 0);
48296
+ if (legacyPart && vmlPart && free && sameModel(before, sheet.comments) && (sheet.threadedCommentsXml === void 0 || sheet.threadedCommentsXml === envelope)) {
47601
48297
  writer.carry(legacyPart);
47602
48298
  writer.carry(vmlPart);
47603
48299
  rels.add(RELATIONSHIP_TYPES.comments, relativeTarget(partName, legacyPart));
@@ -47611,10 +48307,20 @@ function writeComments(ctx, sheet, index2, partName, rels) {
47611
48307
  }
47612
48308
  const own = base ? vmlIdmapBlocks(base) : [];
47613
48309
  const layout2 = vmlAllocatorFor(ctx, source3).allocate(sheet.comments.length, index2 + 1, own);
47614
- const parts = commentParts(sheet.comments, index2 + 1, ctx.persons, sheet.name, {
47615
- ...layout2,
47616
- ...base ? { base } : {}
47617
- });
48310
+ const parts = commentParts(
48311
+ sheet.comments,
48312
+ index2 + 1,
48313
+ ctx.persons,
48314
+ sheet.name,
48315
+ {
48316
+ ...layout2,
48317
+ ...base ? { base } : {}
48318
+ },
48319
+ {
48320
+ ...threadEnvelope ? { envelope: threadEnvelope } : {},
48321
+ ids: ctx.commentIds ??= new CommentIds(ctx.workbook)
48322
+ }
48323
+ );
47618
48324
  const commentsPart = name2((n) => `xl/comments${n}.xml`);
47619
48325
  writer.add(commentsPart, parts.comments, CONTENT_TYPES.comments);
47620
48326
  rels.add(RELATIONSHIP_TYPES.comments, relativeTarget(partName, commentsPart));
@@ -47693,6 +48399,7 @@ var init_sheet_parts = __esm({
47693
48399
  init_tables();
47694
48400
  init_chart_cache();
47695
48401
  init_comments2();
48402
+ init_comment_ids();
47696
48403
  init_drawing4();
47697
48404
  init_snapshot();
47698
48405
  init_vml_ids();
@@ -47823,13 +48530,17 @@ function writeWorksheet(ctx, sheet, index2, partName) {
47823
48530
  blocks.set("legacyDrawing", writeComments(ctx, sheet, index2, partName, rels));
47824
48531
  blocks.set("tableParts", tableParts);
47825
48532
  ctx.pivots?.writeSheet(writer, sheet, partName, rels);
47826
- const extensions = conditionalExtensionsXml(sheet);
48533
+ const extensions = validationExtensionsXml(
48534
+ sheet,
48535
+ conditionalExtensionsXml(sheet),
48536
+ ctx.validationIds ??= /* @__PURE__ */ new Set()
48537
+ );
47827
48538
  blocks.set(
47828
48539
  "extLst",
47829
48540
  ctx.slicers?.active ? ctx.slicers.writeSheet(sheet, partName, rels, extensions) : extensions
47830
48541
  );
47831
48542
  for (const [key, list2] of sheet.preserved) {
47832
- if (key.startsWith("source:") || !WORKSHEET_CHILD_ORDER.includes(key) || (blocks.get(key) ?? "") !== "" || key === "extLst" && ctx.slicers?.active)
48543
+ if (key.startsWith("source:") || !WORKSHEET_CHILD_ORDER.includes(key) || (blocks.get(key) ?? "") !== "" || key === "extLst")
47833
48544
  continue;
47834
48545
  const valid2 = list2.filter(
47835
48546
  (xml) => [...xml.matchAll(/\br:(?:id|embed|link|pict)="([^"]*)"/g)].every(
@@ -47853,6 +48564,8 @@ var init_worksheet2 = __esm({
47853
48564
  init_package2();
47854
48565
  init_print_options();
47855
48566
  init_conditional();
48567
+ init_data_validations2();
48568
+ init_validation_extensions();
47856
48569
  init_conditional_extensions();
47857
48570
  init_package_writer();
47858
48571
  init_page_setup();
@@ -48794,7 +49507,8 @@ async function saveXlsx(workbook) {
48794
49507
  styles: new StyleWriter(workbook, stylesPart ? source3?.text(stylesPart) : void 0),
48795
49508
  strings: new SharedStringTable(),
48796
49509
  persons: new PersonRegistry(
48797
- parsePersons(personsSource ? source3?.text(personsSource) : void 0)
49510
+ parsePersons(personsSource ? source3?.text(personsSource) : void 0),
49511
+ personsSource ? source3?.text(personsSource) : void 0
48798
49512
  ),
48799
49513
  reserved,
48800
49514
  tableIds: /* @__PURE__ */ new Set(),
@@ -48869,7 +49583,9 @@ async function saveXlsx(workbook) {
48869
49583
  rels.add(RELATIONSHIP_TYPES.theme, relativeTarget(bookPart, outTheme));
48870
49584
  if (ctx.threaded.used) {
48871
49585
  const personsPart = personsSource ?? "xl/persons/person.xml";
48872
- writer.add(personsPart, ctx.persons.xml(), CONTENT_TYPES.persons);
49586
+ if (personsSource) writer.carry(personsSource);
49587
+ if (!personsSource || ctx.persons.changed)
49588
+ writer.add(personsPart, ctx.persons.xml(), CONTENT_TYPES.persons);
48873
49589
  rels.add(RELATIONSHIP_TYPES.person, relativeTarget(bookPart, personsPart));
48874
49590
  }
48875
49591
  writeMetadataPart(