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,10 +1,30 @@
1
1
  'use strict';
2
2
 
3
3
  var xmldom = require('@xmldom/xmldom');
4
+ var xpath = require('xpath');
4
5
  var JSZip2 = require('jszip');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
8
 
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var xpath__namespace = /*#__PURE__*/_interopNamespace(xpath);
8
28
  var JSZip2__default = /*#__PURE__*/_interopDefault(JSZip2);
9
29
 
10
30
  // crypto/errors.ts
@@ -3351,7 +3371,7 @@ function parseXml(xml, options = {}) {
3351
3371
  try {
3352
3372
  parsed = new xmldom.DOMParser({
3353
3373
  onError: (level4, message) => {
3354
- if (level4 !== "warning") parseError = message;
3374
+ if (level4 !== "warning" || options.warningsAsErrors) parseError = message;
3355
3375
  }
3356
3376
  }).parseFromString(xml, "application/xml");
3357
3377
  } catch (error) {
@@ -3816,6 +3836,14 @@ function startTag(source3, from, namespaces) {
3816
3836
  if (i2 < n && !isSpace(after) && after !== 62 && after !== 47) return void 0;
3817
3837
  }
3818
3838
  }
3839
+ var compiler = xpath__namespace;
3840
+ function selectXmlNodes(expression, node2, options = {}) {
3841
+ return compiler.parse(expression).select({
3842
+ node: node2,
3843
+ ...options.namespaces ? { namespaces: options.namespaces } : {},
3844
+ allowAnyNamespaceForNoPrefix: options.matchDefaultNamespace ?? false
3845
+ });
3846
+ }
3819
3847
 
3820
3848
  // opc/relationships.ts
3821
3849
  function parseRelationships(xml) {
@@ -9910,31 +9938,90 @@ function parsePersons(xml) {
9910
9938
  }
9911
9939
  return persons;
9912
9940
  }
9913
- function parseThreadedComments(xml, persons) {
9941
+ function parseThreadedComments(xml, persons, personsXml) {
9914
9942
  if (!xml) return [];
9915
9943
  const root = parseXml(xml, { label: "XLSX threaded comments" }).documentElement;
9916
9944
  const roots = /* @__PURE__ */ new Map();
9945
+ const personNames = new Map([...persons].map(([id, name]) => [id.toUpperCase(), name]));
9917
9946
  const order = [];
9918
- for (const node2 of children(root, "threadedComment", NS.tc)) {
9919
- const address2 = parseAddress(att(node2, "ref") ?? "");
9947
+ const nodes = children(root, "threadedComment", NS.tc);
9948
+ const byId = new Map(nodes.map((node2) => [(att(node2, "id") ?? "").toUpperCase(), node2]));
9949
+ const parentRoot = (parent) => {
9950
+ const seen = /* @__PURE__ */ new Set();
9951
+ while (parent) {
9952
+ parent = parent.toUpperCase();
9953
+ if (seen.has(parent)) break;
9954
+ if (roots.has(parent)) return roots.get(parent);
9955
+ seen.add(parent);
9956
+ parent = att(byId.get(parent), "parentId");
9957
+ }
9958
+ return void 0;
9959
+ };
9960
+ for (const node2 of [
9961
+ ...nodes.filter((n) => !att(n, "parentId")),
9962
+ ...nodes.filter((n) => att(n, "parentId"))
9963
+ ]) {
9964
+ const parentComment = parentRoot(att(node2, "parentId"));
9965
+ const address2 = parseAddress(att(node2, "ref") ?? "") ?? parentComment?.address;
9920
9966
  if (!address2) continue;
9921
- const author = persons.get(att(node2, "personId") ?? "") ?? "";
9967
+ const author = personNames.get((att(node2, "personId") ?? "").toUpperCase()) ?? "";
9922
9968
  const text = xText(children(node2, "text", NS.tc)[0]);
9923
9969
  const date = att(node2, "dT");
9924
- const parent = att(node2, "parentId");
9925
- const parentComment = parent ? roots.get(parent) : void 0;
9926
9970
  if (parentComment) {
9927
- const reply = { author, text };
9971
+ const reply = { author, text, threadedXml: selfContainedXml(node2) };
9928
9972
  if (date) reply.date = date;
9929
9973
  (parentComment.replies ??= []).push(reply);
9930
9974
  continue;
9931
9975
  }
9932
- const comment = { address: address2, author, text, replies: [] };
9933
- roots.set(att(node2, "id") ?? `${order.length}`, comment);
9976
+ const comment = {
9977
+ address: address2,
9978
+ author,
9979
+ text,
9980
+ replies: [],
9981
+ threadedXml: selfContainedXml(node2)
9982
+ };
9983
+ if (date) comment.date = date;
9984
+ const resolved = boolAttr(node2, "done");
9985
+ if (resolved !== void 0) comment.resolved = resolved;
9986
+ roots.set((att(node2, "id") ?? `${order.length}`).toUpperCase(), comment);
9934
9987
  order.push(comment);
9935
9988
  }
9989
+ for (const comment of order)
9990
+ comment.replies?.sort((a2, b) => {
9991
+ const aDate = a2.date ? Date.parse(a2.date) : NaN;
9992
+ const bDate = b.date ? Date.parse(b.date) : NaN;
9993
+ return Number.isFinite(aDate) && Number.isFinite(bDate) ? aDate - bDate : 0;
9994
+ });
9995
+ if (personsXml) {
9996
+ const records = /* @__PURE__ */ new Map();
9997
+ for (const person of children(parseXml(personsXml).documentElement, "person", NS.tc)) {
9998
+ const id = att(person, "id") ?? "";
9999
+ records.set(id.toUpperCase(), [id, selfContainedXml(person)]);
10000
+ }
10001
+ for (const comment of order) {
10002
+ const ids = /* @__PURE__ */ new Set();
10003
+ for (const message of [comment, ...comment.replies ?? []]) {
10004
+ const node2 = parseXml(message.threadedXml).documentElement;
10005
+ ids.add((att(node2, "personId") ?? "").toUpperCase());
10006
+ const mentions = first(node2, "mentions", NS.tc);
10007
+ if (mentions)
10008
+ for (const mention of children(mentions, "mention", NS.tc))
10009
+ ids.add((att(mention, "mentionpersonId") ?? "").toUpperCase());
10010
+ }
10011
+ const kept = [...ids].flatMap((id) => records.has(id) ? [records.get(id)] : []);
10012
+ if (kept.length) comment.threadedPersons = Object.fromEntries(kept);
10013
+ }
10014
+ }
9936
10015
  return order;
9937
10016
  }
10017
+ function threadedCommentEnvelope(xml) {
10018
+ if (!xml) return void 0;
10019
+ const doc = parseXml(xml);
10020
+ for (const node2 of children(doc.documentElement, "threadedComment", NS.tc)) {
10021
+ doc.documentElement.removeChild(node2);
10022
+ }
10023
+ return buildXml(doc);
10024
+ }
9938
10025
  function mergeComments(legacy, threaded) {
9939
10026
  if (!threaded.length) return legacy;
9940
10027
  const key = (c2) => `${c2.address.row}:${c2.address.col}`;
@@ -12435,7 +12522,7 @@ function readSheetView(sheetViews) {
12435
12522
  const cols = Math.max(0, Math.round(numAttr(pane, "xSplit") ?? 0));
12436
12523
  if (rows || cols) view.freeze = { rows, cols };
12437
12524
  }
12438
- const split2 = pane && state === "split";
12525
+ const split2 = pane && (state === void 0 || state === "split");
12439
12526
  if (split2) {
12440
12527
  const x = Math.max(0, Math.round(numAttr(pane, "xSplit") ?? 0));
12441
12528
  const y = Math.max(0, Math.round(numAttr(pane, "ySplit") ?? 0));
@@ -12443,9 +12530,8 @@ function readSheetView(sheetViews) {
12443
12530
  view.split = { x, y };
12444
12531
  const first2 = parseAddress(att(node2, "topLeftCell") ?? "");
12445
12532
  if (first2) view.split.topLeft = first2;
12446
- const active = att(pane, "activePane");
12447
- if (active && PANES.has(active))
12448
- view.split.activePane = active;
12533
+ const active = att(pane, "activePane") ?? "topLeft";
12534
+ if (PANES.has(active)) view.split.activePane = active;
12449
12535
  }
12450
12536
  }
12451
12537
  const topLeft = parseAddress(
@@ -31727,6 +31813,49 @@ var WORKSHEET_CHILD_ORDER = [
31727
31813
  "extLst"
31728
31814
  ];
31729
31815
 
31816
+ // xlsx/read/data-validations.ts
31817
+ var VALIDATION_XM = "http://schemas.microsoft.com/office/excel/2006/main";
31818
+ var TYPES = /* @__PURE__ */ new Set(["none", "whole", "decimal", "list", "date", "time", "textLength", "custom"]);
31819
+ var ERROR_STYLES = /* @__PURE__ */ new Set(["stop", "warning", "information"]);
31820
+ function readDataValidation(dv) {
31821
+ const extended = dv.namespaceURI === NS.x14;
31822
+ const ns = extended ? NS.x14 : NS.x;
31823
+ const ranges = parseSqref(
31824
+ extended ? first(dv, "sqref", VALIDATION_XM)?.textContent ?? "" : att(dv, "sqref")
31825
+ );
31826
+ if (!ranges.length) return void 0;
31827
+ const type = att(dv, "type") ?? "none";
31828
+ const validation = {
31829
+ ranges,
31830
+ type: TYPES.has(type) ? type : "none"
31831
+ };
31832
+ const operator = att(dv, "operator");
31833
+ if (operator) validation.operator = operator;
31834
+ for (const key of ["formula1", "formula2"]) {
31835
+ const container2 = first(dv, key, ns);
31836
+ const formula2 = extended ? first(container2, "f", VALIDATION_XM) : container2;
31837
+ if (formula2) validation[key] = stripFuturePrefixes(formula2.textContent ?? "");
31838
+ }
31839
+ if (boolAttr(dv, "allowBlank")) validation.allowBlank = true;
31840
+ const hideDropDown = boolAttr(dv, "showDropDown");
31841
+ if (validation.type === "list") validation.showDropDown = !hideDropDown;
31842
+ else if (hideDropDown) validation.showDropDown = false;
31843
+ if (boolAttr(dv, "showErrorMessage")) validation.showErrorMessage = true;
31844
+ if (boolAttr(dv, "showInputMessage")) validation.showInputMessage = true;
31845
+ const errorStyle = att(dv, "errorStyle");
31846
+ if (errorStyle && ERROR_STYLES.has(errorStyle))
31847
+ validation.errorStyle = errorStyle;
31848
+ for (const key of ["errorTitle", "error", "promptTitle", "prompt"]) {
31849
+ const value2 = att(dv, key);
31850
+ if (value2 !== void 0) validation[key] = value2;
31851
+ }
31852
+ if (extended) validation.extensionXml = selfContainedXml(dv);
31853
+ return validation;
31854
+ }
31855
+ function readDataValidations(node2) {
31856
+ return node2 ? children(node2, "dataValidation", NS.x).flatMap((dv) => readDataValidation(dv) ?? []) : [];
31857
+ }
31858
+
31730
31859
  // xlsx/read/conditional.ts
31731
31860
  var CFVO_TYPES = /* @__PURE__ */ new Set(["min", "max", "num", "percent", "percentile", "formula"]);
31732
31861
  function cfvo(node2) {
@@ -31853,55 +31982,151 @@ function readConditionalFormats(blocks, dxfs, palette, warn) {
31853
31982
  }
31854
31983
  return out;
31855
31984
  }
31856
- var VALIDATION_TYPES = /* @__PURE__ */ new Set([
31857
- "none",
31858
- "whole",
31859
- "decimal",
31860
- "list",
31861
- "date",
31862
- "time",
31863
- "textLength",
31864
- "custom"
31865
- ]);
31866
- var ERROR_STYLES = /* @__PURE__ */ new Set(["stop", "warning", "information"]);
31867
- function readDataValidations(node2) {
31868
- if (!node2) return [];
31869
- const out = [];
31870
- for (const dv of xChildren(node2, "dataValidation")) {
31871
- const ranges = parseSqref(att(dv, "sqref"));
31872
- if (!ranges.length) continue;
31873
- const type = att(dv, "type") ?? "none";
31874
- const validation = {
31875
- ranges,
31876
- type: VALIDATION_TYPES.has(type) ? type : "none"
31877
- };
31878
- const operator = att(dv, "operator");
31879
- if (operator) validation.operator = operator;
31880
- const f13 = xFirst(dv, "formula1");
31881
- if (f13) validation.formula1 = stripFuturePrefixes(f13.textContent ?? "");
31882
- const f23 = xFirst(dv, "formula2");
31883
- if (f23) validation.formula2 = stripFuturePrefixes(f23.textContent ?? "");
31884
- if (boolAttr(dv, "allowBlank")) validation.allowBlank = true;
31885
- const hideDropDown = boolAttr(dv, "showDropDown");
31886
- if (validation.type === "list") validation.showDropDown = !hideDropDown;
31887
- else if (hideDropDown) validation.showDropDown = false;
31888
- if (boolAttr(dv, "showErrorMessage")) validation.showErrorMessage = true;
31889
- if (boolAttr(dv, "showInputMessage")) validation.showInputMessage = true;
31890
- const errorStyle = att(dv, "errorStyle");
31891
- if (errorStyle && ERROR_STYLES.has(errorStyle))
31892
- validation.errorStyle = errorStyle;
31893
- for (const key of ["errorTitle", "error", "promptTitle", "prompt"]) {
31894
- const value2 = att(dv, key);
31895
- if (value2 !== void 0) validation[key] = value2;
31896
- }
31897
- out.push(validation);
31985
+
31986
+ // xlsx/write/data-validations.ts
31987
+ function usesValidationExtension(dv) {
31988
+ if (dv.extensionXml) return true;
31989
+ return [dv.formula1, dv.formula2].some((formula2) => {
31990
+ if (!formula2) return false;
31991
+ try {
31992
+ return tokenize(formula2).some((token2) => token2.prefix !== void 0);
31993
+ } catch {
31994
+ return false;
31995
+ }
31996
+ });
31997
+ }
31998
+ function validationAttributes(dv) {
31999
+ return {
32000
+ type: dv.type === "none" ? void 0 : dv.type,
32001
+ errorStyle: dv.errorStyle,
32002
+ operator: dv.operator,
32003
+ allowBlank: dv.allowBlank || void 0,
32004
+ showDropDown: dv.showDropDown === false ? true : void 0,
32005
+ showInputMessage: dv.showInputMessage || void 0,
32006
+ showErrorMessage: dv.showErrorMessage || void 0,
32007
+ errorTitle: dv.errorTitle,
32008
+ error: dv.error,
32009
+ promptTitle: dv.promptTitle,
32010
+ prompt: dv.prompt
32011
+ };
32012
+ }
32013
+ function dataValidationXml(dv, extended) {
32014
+ const sqref2 = dv.ranges.map(formatRange).join(" ");
32015
+ if (!extended) {
32016
+ const formulas = ["formula1", "formula2"].map(
32017
+ (key) => dv[key] === void 0 ? "" : `<${key}>${escapeText2(addFuturePrefixes(dv[key]))}</${key}>`
32018
+ ).join("");
32019
+ const values2 = attrs({ ...validationAttributes(dv), sqref: sqref2 });
32020
+ return formulas ? `<dataValidation${values2}>${formulas}</dataValidation>` : `<dataValidation${values2}/>`;
31898
32021
  }
31899
- return out;
32022
+ const doc = parseXml(
32023
+ dv.extensionXml || `<x14:dataValidation xmlns:x14="${NS.x14}" xmlns:xm="${VALIDATION_XM}"/>`
32024
+ );
32025
+ const node2 = doc.documentElement;
32026
+ for (const [key, value2] of Object.entries(validationAttributes(dv))) {
32027
+ if (value2 === void 0) node2.removeAttribute(key);
32028
+ else node2.setAttribute(key, typeof value2 === "boolean" ? "1" : value2);
32029
+ }
32030
+ for (const key of ["formula1", "formula2"]) {
32031
+ let container2 = first(node2, key, NS.x14);
32032
+ if (dv[key] === void 0) {
32033
+ if (container2) node2.removeChild(container2);
32034
+ continue;
32035
+ }
32036
+ if (!container2) {
32037
+ container2 = doc.createElementNS(NS.x14, `x14:${key}`);
32038
+ const next = key === "formula1" ? first(node2, "formula2", NS.x14) : void 0;
32039
+ node2.insertBefore(container2, next ?? first(node2, "sqref", VALIDATION_XM) ?? null);
32040
+ }
32041
+ let formula2 = first(container2, "f", VALIDATION_XM);
32042
+ if (!formula2) {
32043
+ formula2 = doc.createElementNS(VALIDATION_XM, "xm:f");
32044
+ container2.appendChild(formula2);
32045
+ }
32046
+ formula2.textContent = addFuturePrefixes(dv[key]);
32047
+ }
32048
+ let ranges = first(node2, "sqref", VALIDATION_XM);
32049
+ if (!ranges) {
32050
+ ranges = doc.createElementNS(VALIDATION_XM, "xm:sqref");
32051
+ node2.appendChild(ranges);
32052
+ }
32053
+ ranges.textContent = sqref2;
32054
+ return buildXml(doc);
32055
+ }
32056
+ function dataValidationsXml(validations) {
32057
+ const items = validations.filter((dv) => dv.ranges.length && !usesValidationExtension(dv)).map((dv) => dataValidationXml(dv, false));
32058
+ return items.length ? `<dataValidations count="${items.length}">${items.join("")}</dataValidations>` : "";
32059
+ }
32060
+
32061
+ // xlsx/validation-extensions.ts
32062
+ var URI = "{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}";
32063
+ function readValidationExtensions(sheet) {
32064
+ const kept = [];
32065
+ for (const xml of sheet.preserved.get("extLst") ?? []) {
32066
+ const doc = parseXml(xml);
32067
+ let changed = false;
32068
+ for (const ext of children(doc.documentElement, "ext", NS.x)) {
32069
+ if (ext.getAttribute("uri")?.toUpperCase() !== URI.toUpperCase()) continue;
32070
+ const collection = first(ext, "dataValidations", NS.x14);
32071
+ if (!collection) continue;
32072
+ for (const node2 of children(collection, "dataValidation", NS.x14)) {
32073
+ const rule = readDataValidation(node2);
32074
+ if (!rule) continue;
32075
+ sheet.dataValidations.push(rule);
32076
+ collection.removeChild(node2);
32077
+ changed = true;
32078
+ }
32079
+ collection.setAttribute(
32080
+ "count",
32081
+ String(children(collection, "dataValidation", NS.x14).length)
32082
+ );
32083
+ }
32084
+ if (!changed) kept.push(xml);
32085
+ else if (elements(doc.documentElement).length) kept.push(buildXml(doc));
32086
+ }
32087
+ if (kept.length) sheet.preserved.set("extLst", kept);
32088
+ else sheet.preserved.delete("extLst");
32089
+ }
32090
+ function validationExtensionsXml(sheet, extensions, ids = /* @__PURE__ */ new Set()) {
32091
+ const rules = sheet.dataValidations.filter(
32092
+ (dv) => dv.ranges.length && usesValidationExtension(dv)
32093
+ );
32094
+ const doc = parseXml(extensions || `<extLst xmlns="${NS.x}"/>`);
32095
+ let ext = elements(doc.documentElement).find(
32096
+ (node2) => node2.getAttribute("uri")?.toUpperCase() === URI.toUpperCase()
32097
+ );
32098
+ if (!rules.length) {
32099
+ const collection2 = first(ext, "dataValidations", NS.x14);
32100
+ if (ext && collection2 && !elements(collection2).length) {
32101
+ ext.removeChild(collection2);
32102
+ if (!elements(ext).length) doc.documentElement.removeChild(ext);
32103
+ }
32104
+ return elements(doc.documentElement).length ? inlineFragment(buildXml(doc)) : "";
32105
+ }
32106
+ if (!ext) {
32107
+ ext = doc.createElementNS(NS.x, "ext");
32108
+ ext.setAttribute("uri", URI);
32109
+ doc.documentElement.appendChild(ext);
32110
+ }
32111
+ let collection = first(ext, "dataValidations", NS.x14);
32112
+ if (!collection) {
32113
+ collection = doc.createElementNS(NS.x14, "x14:dataValidations");
32114
+ ext.appendChild(collection);
32115
+ }
32116
+ for (const rule of rules) {
32117
+ const node2 = doc.importNode(parseXml(dataValidationXml(rule, true)).documentElement, true);
32118
+ const id = node2.getAttributeNS(NS.xr, "uid");
32119
+ if (id && ids.has(id)) node2.removeAttributeNS(NS.xr, "uid");
32120
+ else if (id) ids.add(id);
32121
+ collection.appendChild(node2);
32122
+ }
32123
+ collection.setAttribute("count", String(children(collection, "dataValidation", NS.x14).length));
32124
+ return inlineFragment(buildXml(doc));
31900
32125
  }
31901
32126
 
31902
32127
  // xlsx/conditional-extensions.ts
31903
32128
  var XM = "http://schemas.microsoft.com/office/excel/2006/main";
31904
- var URI = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}";
32129
+ var URI2 = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}";
31905
32130
  function writeSettings(node2, rule) {
31906
32131
  const bar = first(node2, "dataBar", NS.x14);
31907
32132
  if (!bar) return;
@@ -31981,14 +32206,14 @@ function conditionalExtensionsXml(sheet) {
31981
32206
  for (const xml of preserved.slice(1))
31982
32207
  for (const node2 of elements(parseXml(xml).documentElement))
31983
32208
  doc.documentElement.appendChild(doc.importNode(node2, true));
31984
- let ext = elements(doc.documentElement).find((e) => e.getAttribute("uri") === URI);
32209
+ let ext = elements(doc.documentElement).find((e) => e.getAttribute("uri") === URI2);
31985
32210
  let collection = first(ext, "conditionalFormattings", NS.x14);
31986
32211
  for (const format of sheet.conditionalFormats)
31987
32212
  for (const rule of format.rules) {
31988
32213
  if (rule.type !== "dataBar" || !rule.extensionXml || !rule.extensionId) continue;
31989
32214
  if (!ext) {
31990
32215
  ext = doc.createElementNS(NS.x, "ext");
31991
- ext.setAttribute("uri", URI);
32216
+ ext.setAttribute("uri", URI2);
31992
32217
  doc.documentElement.appendChild(ext);
31993
32218
  }
31994
32219
  if (!collection) {
@@ -35198,7 +35423,7 @@ function readSlicerFrame(content2, anchor, sourceXml) {
35198
35423
  }
35199
35424
 
35200
35425
  // xlsx/read/form-control.ts
35201
- var TYPES = {
35426
+ var TYPES2 = {
35202
35427
  checkbox: "checkbox",
35203
35428
  radio: "radio",
35204
35429
  drop: "dropdown",
@@ -35240,7 +35465,7 @@ var num3 = (value2) => {
35240
35465
  };
35241
35466
  function readProps(control, xml) {
35242
35467
  const props = parseXml(xml, { label: "XLSX form control" }).documentElement;
35243
- control.controlType = TYPES[(att(props, "objectType") ?? "").toLowerCase()] ?? "other";
35468
+ control.controlType = TYPES2[(att(props, "objectType") ?? "").toLowerCase()] ?? "other";
35244
35469
  const link = att(props, "fmlaLink");
35245
35470
  if (link) control.linkedCell = link;
35246
35471
  const range = att(props, "fmlaRange");
@@ -36015,12 +36240,21 @@ function readTables(ctx, partName, node2, sheet) {
36015
36240
  function readComments(ctx, partName, sheet) {
36016
36241
  const legacyPart = ctx.source.targetOfType(partName, RELATIONSHIP_TYPES.comments);
36017
36242
  const threadedPart = ctx.source.targetOfType(partName, RELATIONSHIP_TYPES.threadedComment);
36243
+ const personsPart = ctx.source.targetOfType(
36244
+ ctx.source.workbookPart() ?? "",
36245
+ RELATIONSHIP_TYPES.person
36246
+ );
36018
36247
  const legacy = parseLegacyComments(legacyPart ? ctx.source.text(legacyPart) : void 0);
36019
36248
  const threaded = parseThreadedComments(
36020
36249
  threadedPart ? ctx.source.text(threadedPart) : void 0,
36021
- ctx.persons
36250
+ ctx.persons,
36251
+ personsPart ? ctx.source.text(personsPart) : void 0
36022
36252
  );
36023
36253
  sheet.comments = mergeComments(legacy, threaded);
36254
+ const envelope = threadedCommentEnvelope(
36255
+ threadedPart ? ctx.source.text(threadedPart) : void 0
36256
+ );
36257
+ if (envelope) sheet.threadedCommentsXml = envelope;
36024
36258
  }
36025
36259
  function parseWorksheet(ctx, partName, name, sheetId) {
36026
36260
  const xml = ctx.source.text(partName);
@@ -36091,6 +36325,7 @@ function readWorksheet(ctx, partName, name, sheetId, xml, rows) {
36091
36325
  const scenarios = readScenarios(byName.get("scenarios"));
36092
36326
  if (scenarios) sheet.scenarios = scenarios;
36093
36327
  sheet.dataValidations = readDataValidations(byName.get("dataValidations"));
36328
+ readValidationExtensions(sheet);
36094
36329
  readConditionalExtensions(sheet);
36095
36330
  sheet.hyperlinks = readHyperlinks(ctx, partName, byName.get("hyperlinks"));
36096
36331
  const page = readPageSetup(
@@ -36250,7 +36485,7 @@ function readProperties(core, app, custom, warn) {
36250
36485
  };
36251
36486
  }
36252
36487
 
36253
- // xlsx/write/comments.ts
36488
+ // xlsx/write/comment-ids.ts
36254
36489
  function guidFrom(seed) {
36255
36490
  let h1 = 2166136261;
36256
36491
  let h2 = 16777619;
@@ -36266,32 +36501,406 @@ function guidFrom(seed) {
36266
36501
  const s = hex.join("");
36267
36502
  return `{${s.slice(0, 8)}-${s.slice(8, 12)}-4${s.slice(13, 16)}-8${s.slice(17, 20)}-${s.slice(20, 32)}}`;
36268
36503
  }
36269
- var 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 ";
36504
+ var validGuid = (id) => /^\{[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}\}$/i.test(id);
36505
+ var CommentIds = class {
36506
+ reserved = /* @__PURE__ */ new Map();
36507
+ used = /* @__PURE__ */ new Set();
36508
+ mentions = /* @__PURE__ */ new WeakMap();
36509
+ constructor(workbook) {
36510
+ for (const matching2 of [true, false])
36511
+ for (const sheet of workbook?.sheets ?? []) {
36512
+ for (const comment of sheet.comments)
36513
+ for (const message of [comment, ...comment.replies ?? []]) {
36514
+ if (comment.regenerateThreadIds) continue;
36515
+ if (!message.threadedXml) continue;
36516
+ const node2 = parseXml(message.threadedXml).documentElement;
36517
+ if (node2.getAttribute("ref") === formatAddress(comment.address) !== matching2)
36518
+ continue;
36519
+ this.reserve(node2.getAttribute("id") ?? "", message);
36520
+ const mentions = first(node2, "mentions", NS.tc);
36521
+ if (mentions)
36522
+ children(mentions, "mention", NS.tc).forEach((mention, index3) => {
36523
+ this.reserve(
36524
+ mention.getAttribute("mentionId") ?? "",
36525
+ this.mentionOwner(message, index3)
36526
+ );
36527
+ });
36528
+ }
36529
+ }
36530
+ }
36531
+ reserve(id, owner) {
36532
+ const key = id.toUpperCase();
36533
+ if (validGuid(id) && !this.reserved.has(key)) this.reserved.set(key, owner);
36534
+ }
36535
+ mentionOwner(message, index3) {
36536
+ let owners = this.mentions.get(message);
36537
+ if (!owners) this.mentions.set(message, owners = []);
36538
+ return owners[index3] ??= {};
36539
+ }
36540
+ claim(source3, seed, owner, preserve = true) {
36541
+ const key = source3.toUpperCase();
36542
+ if (preserve && validGuid(source3) && !this.used.has(key) && (!this.reserved.has(key) || this.reserved.get(key) === owner)) {
36543
+ this.used.add(key);
36544
+ return source3;
36545
+ }
36546
+ let index3 = 0;
36547
+ let id = guidFrom(seed);
36548
+ while (this.used.has(id) || this.reserved.has(id)) id = guidFrom(`${seed}:${++index3}`);
36549
+ this.used.add(id);
36550
+ return id;
36551
+ }
36552
+ };
36553
+
36554
+ // text/text-diff.ts
36555
+ var isLowSurrogate = (text, at) => {
36556
+ const code = text.charCodeAt(at);
36557
+ return code >= 56320 && code <= 57343;
36558
+ };
36559
+ function shortestEdit(n, m, same8, maxEdits) {
36560
+ const max = Math.min(n + m, maxEdits);
36561
+ const offset2 = max + 1;
36562
+ const v = new Int32Array(2 * max + 3);
36563
+ const trace = [];
36564
+ for (let d = 0; d <= max; d++) {
36565
+ for (let k = -d; k <= d; k += 2) {
36566
+ const down = k === -d || k !== d && v[offset2 + k - 1] < v[offset2 + k + 1];
36567
+ let x = down ? v[offset2 + k + 1] : v[offset2 + k - 1] + 1;
36568
+ let y = x - k;
36569
+ while (x < n && y < m && same8(x, y)) {
36570
+ x++;
36571
+ y++;
36572
+ }
36573
+ v[offset2 + k] = x;
36574
+ if (x >= n && y >= m) return backtrack(trace, n, m, d);
36575
+ }
36576
+ trace.push(v.slice(offset2 - d, offset2 + d + 1));
36577
+ }
36578
+ return void 0;
36579
+ }
36580
+ function backtrack(trace, n, m, d) {
36581
+ const edits = [];
36582
+ let x = n;
36583
+ let y = m;
36584
+ for (let step = d; step > 0; step--) {
36585
+ const previous = trace[step - 1];
36586
+ const at = (k2) => previous[k2 + step - 1];
36587
+ const k = x - y;
36588
+ const down = k === -step || k !== step && at(k - 1) < at(k + 1);
36589
+ const before = down ? k + 1 : k - 1;
36590
+ const startX = at(before);
36591
+ const startY = startX - before;
36592
+ edits.push(down ? [startX, startY, true] : [startX, startY, false]);
36593
+ x = startX;
36594
+ y = startY;
36595
+ }
36596
+ return edits.reverse();
36597
+ }
36598
+ function changesOf(edits) {
36599
+ const changes = [];
36600
+ for (const [x, y, inserts] of edits) {
36601
+ const last = changes.at(-1);
36602
+ if (last && last.fromEnd === x && last.toEnd === y) {
36603
+ if (inserts) last.toEnd++;
36604
+ else last.fromEnd++;
36605
+ } else
36606
+ changes.push({
36607
+ fromStart: x,
36608
+ fromEnd: inserts ? x : x + 1,
36609
+ toStart: y,
36610
+ toEnd: inserts ? y + 1 : y
36611
+ });
36612
+ }
36613
+ return changes;
36614
+ }
36615
+ function characterChanges(a2, b, maxEdits) {
36616
+ const edits = shortestEdit(
36617
+ a2.length,
36618
+ b.length,
36619
+ (x, y) => a2.charCodeAt(x) === b.charCodeAt(y),
36620
+ maxEdits
36621
+ );
36622
+ return edits && changesOf(edits);
36623
+ }
36624
+ var TOKEN = /[\p{L}\p{N}\p{M}]+|\s+|[\s\S]/gu;
36625
+ function tokensOf(text, ids) {
36626
+ const tokens2 = [];
36627
+ const starts = [];
36628
+ for (const match2 of text.matchAll(TOKEN)) {
36629
+ let id = ids.get(match2[0]);
36630
+ if (id === void 0) ids.set(match2[0], id = ids.size);
36631
+ tokens2.push(id);
36632
+ starts.push(match2.index);
36633
+ }
36634
+ starts.push(text.length);
36635
+ return { tokens: tokens2, starts };
36636
+ }
36637
+ function tokenChanges(a2, b, maxEdits) {
36638
+ const ids = /* @__PURE__ */ new Map();
36639
+ const from = tokensOf(a2, ids);
36640
+ const to = tokensOf(b, ids);
36641
+ const edits = shortestEdit(
36642
+ from.tokens.length,
36643
+ to.tokens.length,
36644
+ (x, y) => from.tokens[x] === to.tokens[y],
36645
+ maxEdits
36646
+ );
36647
+ if (!edits) return void 0;
36648
+ let budget = maxEdits;
36649
+ return changesOf(edits).flatMap((stretch) => {
36650
+ const change = {
36651
+ fromStart: from.starts[stretch.fromStart],
36652
+ fromEnd: from.starts[stretch.fromEnd],
36653
+ toStart: to.starts[stretch.toStart],
36654
+ toEnd: to.starts[stretch.toEnd]
36655
+ };
36656
+ const inner = change.fromEnd > change.fromStart && change.toEnd > change.toStart ? characterChanges(
36657
+ a2.slice(change.fromStart, change.fromEnd),
36658
+ b.slice(change.toStart, change.toEnd),
36659
+ budget
36660
+ ) : void 0;
36661
+ if (!inner) return [change];
36662
+ for (const found of inner)
36663
+ budget -= found.fromEnd - found.fromStart + found.toEnd - found.toStart;
36664
+ return inner.map((found) => ({
36665
+ fromStart: found.fromStart + change.fromStart,
36666
+ fromEnd: found.fromEnd + change.fromStart,
36667
+ toStart: found.toStart + change.toStart,
36668
+ toEnd: found.toEnd + change.toStart
36669
+ }));
36670
+ });
36671
+ }
36672
+ function diffText(from, to, maxEdits = 500) {
36673
+ let start = 0;
36674
+ while (start < from.length && start < to.length && from.charCodeAt(start) === to.charCodeAt(start))
36675
+ start++;
36676
+ let end = 0;
36677
+ while (end < from.length - start && end < to.length - start && from.charCodeAt(from.length - 1 - end) === to.charCodeAt(to.length - 1 - end))
36678
+ end++;
36679
+ const a2 = from.slice(start, from.length - end);
36680
+ const b = to.slice(start, to.length - end);
36681
+ if (!a2.length && !b.length) return [];
36682
+ const found = a2.length && b.length ? characterChanges(a2, b, maxEdits) ?? tokenChanges(a2, b, maxEdits) : void 0;
36683
+ const changes = found ?? [{ fromStart: 0, fromEnd: a2.length, toStart: 0, toEnd: b.length }];
36684
+ const result2 = [];
36685
+ for (const change of changes) {
36686
+ const placed = {
36687
+ fromStart: change.fromStart + start,
36688
+ fromEnd: change.fromEnd + start,
36689
+ toStart: change.toStart + start,
36690
+ toEnd: change.toEnd + start
36691
+ };
36692
+ if (placed.fromStart > 0 && placed.toStart > 0 && (isLowSurrogate(from, placed.fromStart) || isLowSurrogate(to, placed.toStart))) {
36693
+ placed.fromStart--;
36694
+ placed.toStart--;
36695
+ }
36696
+ if (isLowSurrogate(from, placed.fromEnd) || isLowSurrogate(to, placed.toEnd)) {
36697
+ placed.fromEnd++;
36698
+ placed.toEnd++;
36699
+ }
36700
+ const last = result2.at(-1);
36701
+ if (last && placed.fromStart <= last.fromEnd) {
36702
+ last.fromEnd = Math.max(last.fromEnd, placed.fromEnd);
36703
+ last.toEnd = Math.max(last.toEnd, placed.toEnd);
36704
+ } else result2.push(placed);
36705
+ }
36706
+ return result2;
36707
+ }
36708
+
36709
+ // xlsx/write/comment-mentions.ts
36710
+ function patchCommentMentions(node2, before, message, ids, commentId, preserveIds) {
36711
+ const container2 = first(node2, "mentions", NS.tc);
36712
+ if (!container2) return;
36713
+ const changes = diffText(before, message.text);
36714
+ children(container2, "mention", NS.tc).forEach((mention, index3) => {
36715
+ const start = Number(mention.getAttribute("startIndex"));
36716
+ const length = Number(mention.getAttribute("length"));
36717
+ const end = start + length;
36718
+ let shift3 = 0;
36719
+ let intact = Number.isInteger(start) && start >= 0 && Number.isInteger(length) && length > 0 && end <= before.length;
36720
+ for (const change of changes) {
36721
+ if (change.fromEnd <= start)
36722
+ shift3 += change.toEnd - change.toStart - (change.fromEnd - change.fromStart);
36723
+ else if (change.fromStart < end) intact = false;
36724
+ }
36725
+ if (!intact) {
36726
+ container2.removeChild(mention);
36727
+ return;
36728
+ }
36729
+ mention.setAttribute("startIndex", String(start + shift3));
36730
+ mention.setAttribute(
36731
+ "mentionId",
36732
+ ids.claim(
36733
+ mention.getAttribute("mentionId") ?? "",
36734
+ `${commentId}:mention:${index3}`,
36735
+ ids.mentionOwner(message, index3),
36736
+ preserveIds
36737
+ )
36738
+ );
36739
+ });
36740
+ if (!children(container2, "mention", NS.tc).length) node2.removeChild(container2);
36741
+ }
36742
+
36743
+ // xlsx/write/threaded-comments.ts
36744
+ var ThreadedCommentsWriter = class {
36745
+ constructor(persons, options = {}) {
36746
+ this.persons = persons;
36747
+ this.doc = parseXml(
36748
+ options.envelope ?? `${XML_HEADER}<ThreadedComments xmlns="${NS.tc}" xmlns:x="${NS.x}"/>`
36749
+ );
36750
+ for (const node2 of children(this.doc.documentElement, "threadedComment", NS.tc))
36751
+ this.doc.documentElement.removeChild(node2);
36752
+ this.ids = options.ids ?? new CommentIds();
36753
+ }
36754
+ persons;
36755
+ doc;
36756
+ ids;
36757
+ count = 0;
36758
+ add(comment, ref, sheetName) {
36759
+ this.persons.retain(comment.threadedPersons);
36760
+ const preserve = !comment.regenerateThreadIds;
36761
+ const prepare2 = (message, seed) => {
36762
+ const source3 = parseXml(message.threadedXml ?? `<threadedComment xmlns="${NS.tc}"/>`);
36763
+ const priorId = source3.documentElement.getAttribute("id") ?? "";
36764
+ const id = this.ids.claim(priorId, seed, message, preserve);
36765
+ return { message, source: source3, priorId, id };
36766
+ };
36767
+ const root = prepare2(comment, `${sheetName}!${ref}:${comment.text}`);
36768
+ const replies = (comment.replies ?? []).map(
36769
+ (reply, index3) => prepare2(reply, `${root.id}:reply:${index3}:${reply.text}`)
36770
+ );
36771
+ const identities = new Map(
36772
+ [root, ...replies].filter((item2) => item2.priorId).map((item2) => [item2.priorId.toUpperCase(), item2.id])
36773
+ );
36774
+ this.message(comment, ref, root.source, root.id, preserve, void 0, comment.resolved);
36775
+ for (const reply of replies)
36776
+ this.message(
36777
+ reply.message,
36778
+ ref,
36779
+ reply.source,
36780
+ reply.id,
36781
+ preserve,
36782
+ identities.get(
36783
+ (reply.source.documentElement.getAttribute("parentId") ?? "").toUpperCase()
36784
+ ) ?? root.id
36785
+ );
36786
+ return root.id;
36787
+ }
36788
+ message(message, ref, source3, id, preserve, parent, resolved) {
36789
+ const node2 = source3.documentElement;
36790
+ const personId = this.persons.id(message.author, node2.getAttribute("personId") ?? void 0);
36791
+ for (const [key, value2] of Object.entries({
36792
+ id,
36793
+ ref,
36794
+ personId,
36795
+ dT: message.date,
36796
+ parentId: parent
36797
+ })) {
36798
+ if (value2 === void 0) node2.removeAttribute(key);
36799
+ else node2.setAttribute(key, value2);
36800
+ }
36801
+ if (!parent) {
36802
+ if (resolved === void 0) node2.removeAttribute("done");
36803
+ else node2.setAttribute("done", resolved ? "1" : "0");
36804
+ }
36805
+ let text = first(node2, "text", NS.tc);
36806
+ patchCommentMentions(node2, text?.textContent ?? "", message, this.ids, id, preserve);
36807
+ if (!text) {
36808
+ text = source3.createElementNS(NS.tc, node2.prefix ? `${node2.prefix}:text` : "text");
36809
+ node2.insertBefore(text, node2.firstChild);
36810
+ }
36811
+ text.textContent = message.text;
36812
+ const root = this.doc.documentElement;
36813
+ root.insertBefore(this.doc.importNode(node2, true), first(root, "extLst", NS.tc) ?? null);
36814
+ this.count++;
36815
+ }
36816
+ xml() {
36817
+ return this.count ? buildXml(this.doc) : void 0;
36818
+ }
36819
+ };
36820
+
36821
+ // xlsx/write/comment-persons.ts
36270
36822
  var PersonRegistry = class {
36823
+ constructor(existing, source3) {
36824
+ this.source = source3;
36825
+ for (const [id, name] of existing ?? []) {
36826
+ this.names.set(id, name);
36827
+ this.identities.set(id.toUpperCase(), id);
36828
+ if (!this.byName.has(name)) this.byName.set(name, id);
36829
+ }
36830
+ }
36831
+ source;
36271
36832
  names = /* @__PURE__ */ new Map();
36272
36833
  byName = /* @__PURE__ */ new Map();
36273
- constructor(existing) {
36274
- for (const [id, name] of existing ?? []) {
36834
+ identities = /* @__PURE__ */ new Map();
36835
+ added = /* @__PURE__ */ new Map();
36836
+ retained = /* @__PURE__ */ new Map();
36837
+ get changed() {
36838
+ return this.added.size > 0;
36839
+ }
36840
+ /** Bring referenced account records along with a thread copied from another workbook. */
36841
+ retain(records) {
36842
+ for (const [sourceId, xml] of Object.entries(records ?? {})) {
36843
+ const known = this.identities.get(sourceId.toUpperCase());
36844
+ if (known && (this.source || this.retained.has(known))) continue;
36845
+ const node2 = parseXml(xml).documentElement;
36846
+ if (node2.localName !== "person" || node2.namespaceURI !== NS.tc || node2.getAttribute("id")?.toUpperCase() !== sourceId.toUpperCase())
36847
+ continue;
36848
+ const name = node2.getAttribute("displayName") ?? "";
36849
+ const id = known ?? node2.getAttribute("id");
36850
+ this.retained.set(id, xml);
36275
36851
  this.names.set(id, name);
36852
+ this.identities.set(id.toUpperCase(), id);
36853
+ this.added.set(id, name);
36276
36854
  if (!this.byName.has(name)) this.byName.set(name, id);
36277
36855
  }
36278
36856
  }
36279
- id(name) {
36857
+ id(name, preferred) {
36858
+ const preferredId = preferred ? this.identities.get(preferred.toUpperCase()) : void 0;
36859
+ if (preferredId && this.names.get(preferredId) === name) return preferredId;
36280
36860
  let id = this.byName.get(name);
36281
36861
  if (!id) {
36862
+ let index3 = 0;
36282
36863
  id = guidFrom(`person:${name}`);
36864
+ while (this.identities.has(id.toUpperCase())) id = guidFrom(`person:${name}:${++index3}`);
36283
36865
  this.byName.set(name, id);
36284
36866
  this.names.set(id, name);
36867
+ this.identities.set(id.toUpperCase(), id);
36868
+ this.added.set(id, name);
36285
36869
  }
36286
36870
  return id;
36287
36871
  }
36288
36872
  xml() {
36289
- const people = [...this.names].map(
36290
- ([id, name]) => `<person displayName="${escapeAttr3(name)}" id="${id}" userId="${escapeAttr3(name)}" providerId="None"/>`
36291
- ).join("");
36292
- return `${XML_HEADER}<personList xmlns="${NS.tc}" xmlns:x="${NS.x}">${people}</personList>`;
36873
+ if (this.source && !this.changed) return this.source;
36874
+ const doc = parseXml(
36875
+ this.source ?? `${XML_HEADER}<personList xmlns="${NS.tc}" xmlns:x="${NS.x}"/>`
36876
+ );
36877
+ const root = doc.documentElement;
36878
+ for (const [id, name] of this.source ? this.added : this.names) {
36879
+ const retained = this.retained.get(id);
36880
+ if (retained) {
36881
+ root.insertBefore(
36882
+ doc.importNode(parseXml(retained).documentElement, true),
36883
+ first(root, "extLst", NS.tc) ?? null
36884
+ );
36885
+ continue;
36886
+ }
36887
+ const person = doc.createElementNS(NS.tc, root.prefix ? `${root.prefix}:person` : "person");
36888
+ for (const [key, value2] of Object.entries({
36889
+ id,
36890
+ displayName: name,
36891
+ userId: name,
36892
+ providerId: "None"
36893
+ })) {
36894
+ person.setAttribute(key, value2);
36895
+ }
36896
+ root.insertBefore(person, first(root, "extLst", NS.tc) ?? null);
36897
+ }
36898
+ return buildXml(doc);
36293
36899
  }
36294
36900
  };
36901
+
36902
+ // xlsx/write/comments.ts
36903
+ var 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 ";
36295
36904
  function vmlShape(comment, index3, id) {
36296
36905
  const { row: row2, col } = comment.address;
36297
36906
  const anchor = `${col + 1}, 15, ${Math.max(0, row2 - 1)}, 10, ${col + 3}, 15, ${row2 + 3}, 4`;
@@ -36313,7 +36922,7 @@ function vmlXml(comments, layout3) {
36313
36922
  }
36314
36923
  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>";
36315
36924
  }
36316
- function commentParts(comments, sheetNumber, persons, sheetName, layout3) {
36925
+ function commentParts(comments, sheetNumber, persons, sheetName, layout3, threadOptions) {
36317
36926
  const authors = [];
36318
36927
  const authorId = (name) => {
36319
36928
  let id = authors.indexOf(name);
@@ -36323,18 +36932,11 @@ function commentParts(comments, sheetNumber, persons, sheetName, layout3) {
36323
36932
  const sorted2 = [...comments].sort(
36324
36933
  (a2, b) => a2.address.row - b.address.row || a2.address.col - b.address.col
36325
36934
  );
36326
- let threaded = "";
36935
+ const threads = new ThreadedCommentsWriter(persons, threadOptions);
36327
36936
  const list2 = sorted2.map((comment) => {
36328
36937
  const ref = formatAddress(comment.address);
36329
36938
  if (comment.replies) {
36330
- const id = guidFrom(`${sheetName}!${ref}:${comment.text}`);
36331
- const personId = persons.id(comment.author);
36332
- threaded += `<threadedComment ref="${ref}" personId="${personId}" id="${id}"><text>${escapeText2(comment.text)}</text></threadedComment>`;
36333
- comment.replies.forEach((reply, index3) => {
36334
- const replyId = guidFrom(`${id}:reply:${index3}:${reply.text}`);
36335
- const dT = reply.date ? ` dT="${escapeAttr3(reply.date)}"` : "";
36336
- threaded += `<threadedComment ref="${ref}"${dT} personId="${persons.id(reply.author)}" id="${replyId}" parentId="${id}"><text>${escapeText2(reply.text)}</text></threadedComment>`;
36337
- });
36939
+ const id = threads.add(comment, ref, sheetName);
36338
36940
  const fallback = `${THREADED_NOTE}${comment.text}${comment.replies.map((r) => `
36339
36941
  Reply:
36340
36942
  ${r.text}`).join("")}`;
@@ -36352,8 +36954,8 @@ Reply:
36352
36954
  }
36353
36955
  );
36354
36956
  const parts = { comments: commentsXml, vml };
36355
- if (threaded)
36356
- parts.threaded = `${XML_HEADER}<ThreadedComments xmlns="${NS.tc}" xmlns:x="${NS.x}">${threaded}</ThreadedComments>`;
36957
+ const threaded = threads.xml();
36958
+ if (threaded) parts.threaded = threaded;
36357
36959
  return parts;
36358
36960
  }
36359
36961
 
@@ -48007,6 +48609,83 @@ var TEXT_EXTRA_FUNCTIONS = [
48007
48609
  )
48008
48610
  ];
48009
48611
 
48612
+ // xlsx/formula/functions/filterxml.ts
48613
+ var XML = "http://www.w3.org/XML/1998/namespace";
48614
+ var XMLNS2 = "http://www.w3.org/2000/xmlns/";
48615
+ function preservesSpace(node2) {
48616
+ for (let current = node2; current; current = current.parentNode) {
48617
+ if (current.nodeType !== 1) continue;
48618
+ const value2 = current.getAttributeNS(XML, "space");
48619
+ if (value2) return value2 === "preserve";
48620
+ }
48621
+ return false;
48622
+ }
48623
+ function prepare(root) {
48624
+ const namespaces = /* @__PURE__ */ Object.create(null);
48625
+ const visit = (element3) => {
48626
+ for (const attr3 of Array.from(element3.attributes)) {
48627
+ if (attr3.namespaceURI !== XMLNS2 || attr3.localName === "xmlns") continue;
48628
+ const prior = namespaces[attr3.localName];
48629
+ if (prior !== void 0 && prior !== attr3.value) throw new Error("Conflicting namespaces");
48630
+ namespaces[attr3.localName] = attr3.value;
48631
+ }
48632
+ for (const child6 of Array.from(element3.childNodes)) {
48633
+ if (child6.nodeType === 1) visit(child6);
48634
+ else if (child6.nodeType === 3 && !child6.nodeValue?.trim() && !preservesSpace(element3))
48635
+ element3.removeChild(child6);
48636
+ }
48637
+ };
48638
+ visit(root);
48639
+ return namespaces;
48640
+ }
48641
+ function nodeValue(node2) {
48642
+ let text;
48643
+ if (node2.nodeType === 2) text = (node2.nodeValue ?? "").trim();
48644
+ else if (node2.nodeType === 1) {
48645
+ const preserve = preservesSpace(node2);
48646
+ text = Array.from(node2.childNodes).filter((child6) => child6.nodeType === 3 || child6.nodeType === 4).map((child6) => {
48647
+ const value2 = child6.nodeValue ?? "";
48648
+ return preserve || child6.nodeType === 4 ? value2 : value2.trim();
48649
+ }).join("");
48650
+ } else return ERR.VALUE;
48651
+ if (!text) return ERR.VALUE;
48652
+ if (/^(true|false)$/i.test(text)) return text.toLowerCase() === "true";
48653
+ const date = /^(\d{1,4})[-/](\d{1,2})[-/](\d{1,4})(.*)$/.exec(text.trim());
48654
+ let numberText = text;
48655
+ if (date) {
48656
+ let year = Number(date[1]);
48657
+ if (year < 100) year += year < 30 ? 2e3 : 1900;
48658
+ numberText = `${year}-${date[2]}-${date[3]}${date[4]?.replace(/^T/, " ") ?? ""}`;
48659
+ }
48660
+ return parseNumberText(numberText) ?? text;
48661
+ }
48662
+ var FILTERXML = spec(
48663
+ "FILTERXML",
48664
+ "Web",
48665
+ "FILTERXML(xml, xpath)",
48666
+ "Returns XML element or attribute values selected by XPath, as a column.",
48667
+ 2,
48668
+ 2,
48669
+ (args) => {
48670
+ const xml = str(args[0]);
48671
+ const expression = str(args[1]);
48672
+ if (xml.length > 32767 || expression.length > 32767) return ERR.VALUE;
48673
+ let nodes;
48674
+ try {
48675
+ const doc = parseXml(xml, { warningsAsErrors: true, label: "FILTERXML" });
48676
+ nodes = selectXmlNodes(expression, doc, {
48677
+ namespaces: prepare(doc.documentElement),
48678
+ matchDefaultNamespace: true
48679
+ });
48680
+ } catch {
48681
+ return ERR.VALUE;
48682
+ }
48683
+ if (!nodes.length) return ERR.VALUE;
48684
+ chargeArrayCells(nodes.length);
48685
+ return new Matrix(nodes.map((node2) => [nodeValue(node2)]));
48686
+ }
48687
+ );
48688
+
48010
48689
  // xlsx/formula/functions/registry.ts
48011
48690
  var ALL = [
48012
48691
  ...MATH_FUNCTIONS,
@@ -48016,6 +48695,7 @@ var ALL = [
48016
48695
  ...LOGICAL_FUNCTIONS,
48017
48696
  ...TEXT_FUNCTIONS,
48018
48697
  ...TEXT_EXTRA_FUNCTIONS,
48698
+ FILTERXML,
48019
48699
  BAHTTEXT,
48020
48700
  GETPIVOTDATA,
48021
48701
  ...GROUPBY_FUNCTIONS,
@@ -49022,6 +49702,12 @@ function pageXml(sheet) {
49022
49702
  return result2;
49023
49703
  }
49024
49704
 
49705
+ // xlsx/layout/split.ts
49706
+ function splitActivePane(split2) {
49707
+ const valid = split2.x > 0 && split2.y > 0 ? ["topLeft", "topRight", "bottomLeft", "bottomRight"] : split2.y > 0 ? ["topLeft", "bottomLeft"] : ["topLeft", "topRight"];
49708
+ return split2.activePane && valid.includes(split2.activePane) ? split2.activePane : valid[valid.length - 1];
49709
+ }
49710
+
49025
49711
  // xlsx/write/filter-columns.ts
49026
49712
  function criteriaOf(column2) {
49027
49713
  const { values: values2, blank, dateGroups, custom, top10, dynamic, color, icon, hiddenButton } = column2;
@@ -49183,16 +49869,14 @@ function dimensionXml(sheet) {
49183
49869
  const used = usedRange(sheet);
49184
49870
  return `<dimension ref="${used ? formatRange(used) : "A1"}"/>`;
49185
49871
  }
49186
- function splitActivePane(split2) {
49187
- const both = split2.x > 0 && split2.y > 0;
49188
- const valid = both ? ["topLeft", "topRight", "bottomLeft", "bottomRight"] : split2.y > 0 ? ["topLeft", "bottomLeft"] : ["topLeft", "topRight"];
49189
- if (split2.activePane && valid.includes(split2.activePane)) return split2.activePane;
49190
- return both ? "bottomRight" : split2.y > 0 ? "bottomLeft" : "topRight";
49191
- }
49192
49872
  function selectionXml(selection, pane) {
49873
+ const activeCellId = selection.ranges.findIndex(
49874
+ (range) => rangeContains(range, selection.active)
49875
+ );
49193
49876
  return el("selection", {
49194
49877
  pane,
49195
49878
  activeCell: formatAddress(selection.active),
49879
+ activeCellId: activeCellId > 0 ? activeCellId : void 0,
49196
49880
  sqref: sqref(selection.ranges) || formatAddress(selection.active)
49197
49881
  });
49198
49882
  }
@@ -49778,28 +50462,6 @@ function conditionalFormatsXml(formats, styles) {
49778
50462
  return `<conditionalFormatting sqref="${format.ranges.map((r) => formatRange(r)).join(" ")}">${rules}</conditionalFormatting>`;
49779
50463
  }).join("");
49780
50464
  }
49781
- function dataValidationsXml(validations) {
49782
- const items = validations.filter((dv) => dv.ranges.length).map((dv) => {
49783
- const hideDropDown = dv.showDropDown === false ? true : void 0;
49784
- const values2 = attrs({
49785
- type: dv.type === "none" ? void 0 : dv.type,
49786
- errorStyle: dv.errorStyle,
49787
- operator: dv.operator,
49788
- allowBlank: dv.allowBlank || void 0,
49789
- showDropDown: hideDropDown,
49790
- showInputMessage: dv.showInputMessage || void 0,
49791
- showErrorMessage: dv.showErrorMessage || void 0,
49792
- errorTitle: dv.errorTitle,
49793
- error: dv.error,
49794
- promptTitle: dv.promptTitle,
49795
- prompt: dv.prompt,
49796
- sqref: dv.ranges.map((r) => formatRange(r)).join(" ")
49797
- });
49798
- const formulas = (dv.formula1 !== void 0 ? formulaXml2(dv.formula1, "formula1") : "") + (dv.formula2 !== void 0 ? formulaXml2(dv.formula2, "formula2") : "");
49799
- return formulas ? `<dataValidation${values2}>${formulas}</dataValidation>` : `<dataValidation${values2}/>`;
49800
- });
49801
- return items.length ? `<dataValidations count="${items.length}">${items.join("")}</dataValidations>` : "";
49802
- }
49803
50465
 
49804
50466
  // xlsx/write/sheet-data.ts
49805
50467
  var MAX_CELL_TEXT = 32767;
@@ -50652,6 +51314,8 @@ function writeComments(ctx, sheet, index3, partName, rels) {
50652
51314
  const { writer, source: source3 } = ctx;
50653
51315
  const name = (pattern) => writer.uniqueName(pattern, ctx.reserved);
50654
51316
  const fromSource = source3 && sheet.partName && source3.has(sheet.partName);
51317
+ const sourceThreaded = fromSource ? source3.targetOfType(sheet.partName ?? "", RELATIONSHIP_TYPES.threadedComment) : void 0;
51318
+ const threadEnvelope = sheet.threadedCommentsXml ?? threadedCommentEnvelope(sourceThreaded ? source3?.text(sourceThreaded) : void 0);
50655
51319
  const sourceVml = fromSource ? sourceVmlPart(source3, sheet.partName ?? "") : void 0;
50656
51320
  const kept = source3 && sourceVml && !writer.has(sourceVml) ? stripNoteShapes(source3.text(sourceVml) ?? "") : void 0;
50657
51321
  const base = kept && kept.kept > 0 ? kept.xml : void 0;
@@ -50676,11 +51340,13 @@ function writeComments(ctx, sheet, index3, partName, rels) {
50676
51340
  parseLegacyComments(legacyPart ? source3.text(legacyPart) : void 0),
50677
51341
  parseThreadedComments(
50678
51342
  threadedPart ? source3.text(threadedPart) : void 0,
50679
- parsePersons(personsPart ? source3.text(personsPart) : void 0)
51343
+ parsePersons(personsPart ? source3.text(personsPart) : void 0),
51344
+ personsPart ? source3.text(personsPart) : void 0
50680
51345
  )
50681
51346
  );
50682
51347
  const free = [legacyPart, threadedPart, vmlPart].every((p) => !p || !writer.has(p));
50683
- if (legacyPart && vmlPart && free && sameModel(before, sheet.comments)) {
51348
+ const envelope = threadedCommentEnvelope(threadedPart ? source3.text(threadedPart) : void 0);
51349
+ if (legacyPart && vmlPart && free && sameModel(before, sheet.comments) && (sheet.threadedCommentsXml === void 0 || sheet.threadedCommentsXml === envelope)) {
50684
51350
  writer.carry(legacyPart);
50685
51351
  writer.carry(vmlPart);
50686
51352
  rels.add(RELATIONSHIP_TYPES.comments, relativeTarget(partName, legacyPart));
@@ -50694,10 +51360,20 @@ function writeComments(ctx, sheet, index3, partName, rels) {
50694
51360
  }
50695
51361
  const own = base ? vmlIdmapBlocks(base) : [];
50696
51362
  const layout3 = vmlAllocatorFor(ctx, source3).allocate(sheet.comments.length, index3 + 1, own);
50697
- const parts = commentParts(sheet.comments, index3 + 1, ctx.persons, sheet.name, {
50698
- ...layout3,
50699
- ...base ? { base } : {}
50700
- });
51363
+ const parts = commentParts(
51364
+ sheet.comments,
51365
+ index3 + 1,
51366
+ ctx.persons,
51367
+ sheet.name,
51368
+ {
51369
+ ...layout3,
51370
+ ...base ? { base } : {}
51371
+ },
51372
+ {
51373
+ ...threadEnvelope ? { envelope: threadEnvelope } : {},
51374
+ ids: ctx.commentIds ??= new CommentIds(ctx.workbook)
51375
+ }
51376
+ );
50701
51377
  const commentsPart = name((n) => `xl/comments${n}.xml`);
50702
51378
  writer.add(commentsPart, parts.comments, CONTENT_TYPES.comments);
50703
51379
  rels.add(RELATIONSHIP_TYPES.comments, relativeTarget(partName, commentsPart));
@@ -50888,13 +51564,17 @@ function writeWorksheet(ctx, sheet, index3, partName) {
50888
51564
  blocks.set("legacyDrawing", writeComments(ctx, sheet, index3, partName, rels));
50889
51565
  blocks.set("tableParts", tableParts);
50890
51566
  ctx.pivots?.writeSheet(writer, sheet, partName, rels);
50891
- const extensions = conditionalExtensionsXml(sheet);
51567
+ const extensions = validationExtensionsXml(
51568
+ sheet,
51569
+ conditionalExtensionsXml(sheet),
51570
+ ctx.validationIds ??= /* @__PURE__ */ new Set()
51571
+ );
50892
51572
  blocks.set(
50893
51573
  "extLst",
50894
51574
  ctx.slicers?.active ? ctx.slicers.writeSheet(sheet, partName, rels, extensions) : extensions
50895
51575
  );
50896
51576
  for (const [key, list2] of sheet.preserved) {
50897
- if (key.startsWith("source:") || !WORKSHEET_CHILD_ORDER.includes(key) || (blocks.get(key) ?? "") !== "" || key === "extLst" && ctx.slicers?.active)
51577
+ if (key.startsWith("source:") || !WORKSHEET_CHILD_ORDER.includes(key) || (blocks.get(key) ?? "") !== "" || key === "extLst")
50898
51578
  continue;
50899
51579
  const valid = list2.filter(
50900
51580
  (xml) => [...xml.matchAll(/\br:(?:id|embed|link|pict)="([^"]*)"/g)].every(
@@ -51170,7 +51850,7 @@ function dateFilterXml(pivot, filter2) {
51170
51850
  }
51171
51851
 
51172
51852
  // xlsx/pivot/write.ts
51173
- var TYPES2 = {
51853
+ var TYPES3 = {
51174
51854
  table: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",
51175
51855
  definition: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
51176
51856
  records: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"
@@ -51236,14 +51916,14 @@ var PivotWritePlan = class {
51236
51916
  `${NS.r}/pivotCacheRecords`,
51237
51917
  relativeTarget(definition, records)
51238
51918
  );
51239
- writer.add(records, pivotCacheRecordsXml(pivot, cache2), TYPES2.records);
51919
+ writer.add(records, pivotCacheRecordsXml(pivot, cache2), TYPES3.records);
51240
51920
  writer.add(
51241
51921
  definition,
51242
51922
  pivotCacheDefinitionXml(pivot, workbook, cache2, recordRel),
51243
- TYPES2.definition
51923
+ TYPES3.definition
51244
51924
  );
51245
51925
  writer.rels(definition, cacheRels);
51246
- writer.add(table2, pivotTableXml(pivot, cacheId, cache2), TYPES2.table);
51926
+ writer.add(table2, pivotTableXml(pivot, cacheId, cache2), TYPES3.table);
51247
51927
  const tableRels = new RelationshipSet();
51248
51928
  tableRels.add(RELATIONSHIP_TYPES.pivotCacheDefinition, relativeTarget(table2, definition));
51249
51929
  writer.rels(table2, tableRels);
@@ -51695,7 +52375,8 @@ async function saveXlsx(workbook) {
51695
52375
  styles: new StyleWriter(workbook, stylesPart ? source3?.text(stylesPart) : void 0),
51696
52376
  strings: new SharedStringTable(),
51697
52377
  persons: new PersonRegistry(
51698
- parsePersons(personsSource ? source3?.text(personsSource) : void 0)
52378
+ parsePersons(personsSource ? source3?.text(personsSource) : void 0),
52379
+ personsSource ? source3?.text(personsSource) : void 0
51699
52380
  ),
51700
52381
  reserved,
51701
52382
  tableIds: /* @__PURE__ */ new Set(),
@@ -51770,7 +52451,9 @@ async function saveXlsx(workbook) {
51770
52451
  rels.add(RELATIONSHIP_TYPES.theme, relativeTarget(bookPart, outTheme));
51771
52452
  if (ctx.threaded.used) {
51772
52453
  const personsPart = personsSource ?? "xl/persons/person.xml";
51773
- writer.add(personsPart, ctx.persons.xml(), CONTENT_TYPES.persons);
52454
+ if (personsSource) writer.carry(personsSource);
52455
+ if (!personsSource || ctx.persons.changed)
52456
+ writer.add(personsPart, ctx.persons.xml(), CONTENT_TYPES.persons);
51774
52457
  rels.add(RELATIONSHIP_TYPES.person, relativeTarget(bookPart, personsPart));
51775
52458
  }
51776
52459
  writeMetadataPart(