ooxml-core 1.9.0 → 1.11.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 (202) hide show
  1. package/dist/PptxHandler-DNZHAHUY.cjs +12 -0
  2. package/dist/PptxHandler-E44KDHMQ.mjs +3 -0
  3. package/dist/{PptxHandler-EX4WBIQQ.mjs → PptxHandler-NROFYT2N.mjs} +2 -2
  4. package/dist/automation/index.cjs +3236 -2258
  5. package/dist/automation/index.mjs +3236 -2258
  6. package/dist/{chunk-SWF7KVL5.cjs → chunk-2UVH6RHI.cjs} +1608 -1163
  7. package/dist/{chunk-M76PHYRR.mjs → chunk-7DSZI7S6.mjs} +1 -1
  8. package/dist/{chunk-AT66SA5M.cjs → chunk-7QZGRB3T.cjs} +28 -10
  9. package/dist/chunk-ANZ4Q6I3.cjs +21 -0
  10. package/dist/{chunk-CPKNMQLX.cjs → chunk-AWIDASUW.cjs} +25 -2
  11. package/dist/{chunk-SVQZXP3F.mjs → chunk-CBNKBVX5.mjs} +25 -2
  12. package/dist/{chunk-FIELY5PI.mjs → chunk-EC2W2MDY.mjs} +30 -2
  13. package/dist/chunk-EGTRL3QJ.mjs +19 -0
  14. package/dist/chunk-GXHKNSZX.mjs +9 -0
  15. package/dist/{chunk-OXHMZS7B.mjs → chunk-HCXUI5UC.mjs} +943 -273
  16. package/dist/chunk-HDQXPSHY.cjs +17 -0
  17. package/dist/chunk-KTYBFGEY.mjs +14 -0
  18. package/dist/chunk-QOO36KG4.cjs +42 -0
  19. package/dist/chunk-R2KZXD6U.mjs +39 -0
  20. package/dist/{chunk-IGOA57LE.mjs → chunk-U2DF3EGK.mjs} +1 -1
  21. package/dist/{chunk-OB277ZGE.mjs → chunk-UAY26XOI.mjs} +27 -9
  22. package/dist/{chunk-WSO4T2LJ.mjs → chunk-W5ARCUJB.mjs} +26 -3
  23. package/dist/chunk-XZPZHXV4.cjs +12 -0
  24. package/dist/{chunk-LCS3J3QI.mjs → chunk-YB5SRNFS.mjs} +717 -272
  25. package/dist/docx/layout/adapt-table.d.ts +2 -2
  26. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  27. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  28. package/dist/docx/layout/index.cjs +554 -83
  29. package/dist/docx/layout/index.mjs +554 -84
  30. package/dist/docx/layout/nested-fragment-edges.d.ts +9 -0
  31. package/dist/docx/layout/nested-fragment-edges.d.ts.map +1 -0
  32. package/dist/docx/layout/nested-frame-profile.d.ts +9 -0
  33. package/dist/docx/layout/nested-frame-profile.d.ts.map +1 -0
  34. package/dist/docx/layout/page-cursor.d.ts +2 -0
  35. package/dist/docx/layout/page-cursor.d.ts.map +1 -1
  36. package/dist/docx/layout/result.d.ts +20 -0
  37. package/dist/docx/layout/result.d.ts.map +1 -1
  38. package/dist/docx/layout/table-border-layout.d.ts +16 -0
  39. package/dist/docx/layout/table-border-layout.d.ts.map +1 -0
  40. package/dist/docx/layout/table-cell-layout.d.ts +3 -2
  41. package/dist/docx/layout/table-cell-layout.d.ts.map +1 -1
  42. package/dist/docx/layout/table-content.d.ts +4 -0
  43. package/dist/docx/layout/table-content.d.ts.map +1 -0
  44. package/dist/docx/layout/table-footnotes.d.ts +5 -0
  45. package/dist/docx/layout/table-footnotes.d.ts.map +1 -1
  46. package/dist/docx/layout/table-frames.d.ts +4 -0
  47. package/dist/docx/layout/table-frames.d.ts.map +1 -0
  48. package/dist/docx/layout/table-layout.d.ts +8 -3
  49. package/dist/docx/layout/table-layout.d.ts.map +1 -1
  50. package/dist/docx/layout/table-note-completion.d.ts +5 -0
  51. package/dist/docx/layout/table-note-completion.d.ts.map +1 -0
  52. package/dist/docx/layout/table-note-stories.d.ts +6 -0
  53. package/dist/docx/layout/table-note-stories.d.ts.map +1 -0
  54. package/dist/pptx/automation/index.cjs +801 -296
  55. package/dist/pptx/automation/index.d.ts +5 -4
  56. package/dist/pptx/automation/index.d.ts.map +1 -1
  57. package/dist/pptx/automation/index.mjs +5 -5
  58. package/dist/pptx/chunks/{text-operations-BLodkuXE.d.ts → elements-DD3UGOMd.d.ts} +27 -3248
  59. package/dist/pptx/chunks/elements-DD3UGOMd.d.ts.map +1 -0
  60. package/dist/pptx/chunks/{index-B4cnSPNz.d.ts → index-BZrFyNtU.d.ts} +113 -5
  61. package/dist/pptx/chunks/index-BZrFyNtU.d.ts.map +1 -0
  62. package/dist/pptx/chunks/{index-BZh-IMkN.d.ts → index-DdX02BSm.d.ts} +19 -3
  63. package/dist/pptx/chunks/index-DdX02BSm.d.ts.map +1 -0
  64. package/dist/pptx/chunks/smart-art-ENMMEbmW.d.ts +1512 -0
  65. package/dist/pptx/chunks/smart-art-ENMMEbmW.d.ts.map +1 -0
  66. package/dist/pptx/chunks/text-D49FKllA.d.ts +1473 -0
  67. package/dist/pptx/chunks/text-D49FKllA.d.ts.map +1 -0
  68. package/dist/pptx/chunks/text-operations-CyMTMfID.d.ts +3261 -0
  69. package/dist/pptx/chunks/text-operations-CyMTMfID.d.ts.map +1 -0
  70. package/dist/pptx/cli/index.cjs +801 -296
  71. package/dist/pptx/cli/index.d.ts +1 -1
  72. package/dist/pptx/cli/index.mjs +4 -4
  73. package/dist/pptx/converter/index.cjs +1 -0
  74. package/dist/pptx/converter/index.d.ts +1 -1
  75. package/dist/pptx/converter/index.mjs +2 -2
  76. package/dist/pptx/editor/render/collaboration-live-patch-target.cjs +2 -2
  77. package/dist/pptx/editor/render/collaboration-live-patch-target.mjs +1 -1
  78. package/dist/pptx/editor/render/find-replace.cjs +19 -18
  79. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  80. package/dist/pptx/editor/render/find-replace.mjs +3 -2
  81. package/dist/pptx/editor/render/font-family-update.cjs +14 -0
  82. package/dist/pptx/editor/render/font-family-update.d.ts +17 -0
  83. package/dist/pptx/editor/render/font-family-update.d.ts.map +1 -0
  84. package/dist/pptx/editor/render/font-family-update.mjs +1 -0
  85. package/dist/pptx/editor/render/paragraph-geometry-overrides.cjs +14 -0
  86. package/dist/pptx/editor/render/paragraph-geometry-overrides.d.ts +17 -0
  87. package/dist/pptx/editor/render/paragraph-geometry-overrides.d.ts.map +1 -0
  88. package/dist/pptx/editor/render/paragraph-geometry-overrides.mjs +12 -0
  89. package/dist/pptx/editor/render/remap-text.cjs +2 -2
  90. package/dist/pptx/editor/render/remap-text.d.ts.map +1 -1
  91. package/dist/pptx/editor/render/remap-text.mjs +1 -1
  92. package/dist/pptx/editor/render/slide-operations.cjs +9 -8
  93. package/dist/pptx/editor/render/slide-operations.mjs +3 -2
  94. package/dist/pptx/editor/render/table-data-grid-ops.cjs +1 -1
  95. package/dist/pptx/editor/render/table-data-grid-ops.mjs +1 -1
  96. package/dist/pptx/editor/render/text-content-style.cjs +18 -0
  97. package/dist/pptx/editor/render/text-content-style.d.ts +9 -0
  98. package/dist/pptx/editor/render/text-content-style.d.ts.map +1 -0
  99. package/dist/pptx/editor/render/text-content-style.mjs +5 -0
  100. package/dist/pptx/editor/render/text-runs-style-patch.cjs +17 -0
  101. package/dist/pptx/editor/render/text-runs-style-patch.d.ts +7 -0
  102. package/dist/pptx/editor/render/text-runs-style-patch.d.ts.map +1 -0
  103. package/dist/pptx/editor/render/text-runs-style-patch.mjs +15 -0
  104. package/dist/pptx/editor/render/text-style-scope.cjs +173 -0
  105. package/dist/pptx/editor/render/text-style-scope.d.ts +76 -0
  106. package/dist/pptx/editor/render/text-style-scope.d.ts.map +1 -0
  107. package/dist/pptx/editor/render/text-style-scope.mjs +164 -0
  108. package/dist/pptx/editor/render/theme-editor-model.cjs +1 -1
  109. package/dist/pptx/editor/render/theme-editor-model.mjs +1 -1
  110. package/dist/pptx/editor/render/update-text-segment-style.cjs +11 -0
  111. package/dist/pptx/editor/render/update-text-segment-style.d.ts +14 -0
  112. package/dist/pptx/editor/render/update-text-segment-style.d.ts.map +1 -0
  113. package/dist/pptx/editor/render/update-text-segment-style.mjs +2 -0
  114. package/dist/pptx/index.cjs +1091 -296
  115. package/dist/pptx/index.d.ts +7 -5
  116. package/dist/pptx/index.mjs +5 -5
  117. package/dist/pptx/smartart-layouts/index.d.ts +1 -1
  118. package/dist/teams/index.cjs +590 -122
  119. package/dist/teams/index.mjs +590 -122
  120. package/dist/visio/date-cache.d.ts +3 -0
  121. package/dist/visio/date-cache.d.ts.map +1 -0
  122. package/dist/visio/edit-commands.d.ts +3 -3
  123. package/dist/visio/edit-commands.d.ts.map +1 -1
  124. package/dist/visio/edit-formatting-scope.d.ts.map +1 -1
  125. package/dist/visio/edit-recalculate-index.d.ts.map +1 -1
  126. package/dist/visio/edit-text-field-commands.d.ts +15 -0
  127. package/dist/visio/edit-text-field-commands.d.ts.map +1 -1
  128. package/dist/visio/edit-text-field.d.ts +2 -2
  129. package/dist/visio/edit-text-field.d.ts.map +1 -1
  130. package/dist/visio/edit.d.ts +1 -1
  131. package/dist/visio/edit.d.ts.map +1 -1
  132. package/dist/visio/index.cjs +501 -220
  133. package/dist/visio/index.d.ts +1 -1
  134. package/dist/visio/index.d.ts.map +1 -1
  135. package/dist/visio/index.mjs +501 -220
  136. package/dist/visio/model.d.ts +6 -0
  137. package/dist/visio/model.d.ts.map +1 -1
  138. package/dist/visio/shape-metadata.d.ts.map +1 -1
  139. package/dist/visio/shapes.d.ts.map +1 -1
  140. package/dist/visio/style.d.ts +1 -1
  141. package/dist/visio/style.d.ts.map +1 -1
  142. package/dist/visio/text-field-display.d.ts +3 -0
  143. package/dist/visio/text-field-display.d.ts.map +1 -1
  144. package/dist/visio/text-field-editability.d.ts +6 -0
  145. package/dist/visio/text-field-editability.d.ts.map +1 -0
  146. package/dist/visio/text-field-fraction.d.ts +3 -0
  147. package/dist/visio/text-field-fraction.d.ts.map +1 -0
  148. package/dist/visio/text-field-independent.d.ts +4 -0
  149. package/dist/visio/text-field-independent.d.ts.map +1 -0
  150. package/dist/visio/text-field-numeric.d.ts +1 -1
  151. package/dist/visio/text-field-numeric.d.ts.map +1 -1
  152. package/dist/visio/text-field-source.d.ts +6 -0
  153. package/dist/visio/text-field-source.d.ts.map +1 -0
  154. package/dist/visio/text-field-system-date.d.ts +4 -0
  155. package/dist/visio/text-field-system-date.d.ts.map +1 -0
  156. package/dist/visio/text-fields.d.ts +1 -0
  157. package/dist/visio/text-fields.d.ts.map +1 -1
  158. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  159. package/dist/visio/ui/index.cjs +514 -221
  160. package/dist/visio/ui/index.mjs +514 -221
  161. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  162. package/dist/visio/ui/text-field-catalog.d.ts.map +1 -1
  163. package/dist/xlsx/edit/pivots.d.ts.map +1 -1
  164. package/dist/xlsx/index.cjs +1362 -659
  165. package/dist/xlsx/index.mjs +1361 -660
  166. package/dist/xlsx/load/index.cjs +1091 -430
  167. package/dist/xlsx/load/index.mjs +1091 -430
  168. package/dist/xlsx/model-pivots.d.ts +31 -2
  169. package/dist/xlsx/model-pivots.d.ts.map +1 -1
  170. package/dist/xlsx/pivot/admission.d.ts.map +1 -1
  171. package/dist/xlsx/pivot/aggregate.d.ts +3 -1
  172. package/dist/xlsx/pivot/aggregate.d.ts.map +1 -1
  173. package/dist/xlsx/pivot/data.d.ts +2 -2
  174. package/dist/xlsx/pivot/data.d.ts.map +1 -1
  175. package/dist/xlsx/pivot/hierarchy-first.d.ts +21 -0
  176. package/dist/xlsx/pivot/hierarchy-first.d.ts.map +1 -0
  177. package/dist/xlsx/pivot/hierarchy.d.ts +2 -4
  178. package/dist/xlsx/pivot/hierarchy.d.ts.map +1 -1
  179. package/dist/xlsx/pivot/index.d.ts +2 -0
  180. package/dist/xlsx/pivot/index.d.ts.map +1 -1
  181. package/dist/xlsx/pivot/measures.d.ts +13 -0
  182. package/dist/xlsx/pivot/measures.d.ts.map +1 -0
  183. package/dist/xlsx/pivot/page-filter-admission.d.ts +5 -0
  184. package/dist/xlsx/pivot/page-filter-admission.d.ts.map +1 -0
  185. package/dist/xlsx/pivot/page-filter.d.ts +11 -0
  186. package/dist/xlsx/pivot/page-filter.d.ts.map +1 -0
  187. package/dist/xlsx/pivot/read.d.ts.map +1 -1
  188. package/dist/xlsx/pivot/table-xml.d.ts.map +1 -1
  189. package/dist/xlsx/pivot/values-axis.d.ts +12 -0
  190. package/dist/xlsx/pivot/values-axis.d.ts.map +1 -0
  191. package/dist/xlsx/ui/commands/i18n/navigation.d.ts.map +1 -1
  192. package/dist/xlsx/ui/commands/i18n/pivots.d.ts.map +1 -1
  193. package/dist/xlsx/ui/index.cjs +640 -137
  194. package/dist/xlsx/ui/index.mjs +640 -137
  195. package/package.json +2 -2
  196. package/dist/PptxHandler-AT7FVG5Q.mjs +0 -2
  197. package/dist/PptxHandler-VFSCECPL.cjs +0 -11
  198. package/dist/pptx/chunks/index-B4cnSPNz.d.ts.map +0 -1
  199. package/dist/pptx/chunks/index-BZh-IMkN.d.ts.map +0 -1
  200. package/dist/pptx/chunks/smart-art-Q2kZQtHh.d.ts +0 -2970
  201. package/dist/pptx/chunks/smart-art-Q2kZQtHh.d.ts.map +0 -1
  202. package/dist/pptx/chunks/text-operations-BLodkuXE.d.ts.map +0 -1
@@ -3450,6 +3450,208 @@ function takeDeferredTextSizes(root2) {
3450
3450
  return shapes;
3451
3451
  }
3452
3452
 
3453
+ // visio/text-fields.ts
3454
+ var PROPERTY_FUNCTIONS = {
3455
+ TITLE: "title",
3456
+ SUBJECT: "subject",
3457
+ CREATOR: "creator",
3458
+ KEYWORDS: "keywords",
3459
+ DESCRIPTION: "description",
3460
+ CATEGORY: "category",
3461
+ COMPANY: "company",
3462
+ MANAGER: "manager"
3463
+ };
3464
+ var DATE_FUNCTIONS = {
3465
+ NOW: void 0,
3466
+ DOCCREATION: "created",
3467
+ DOCLASTSAVE: "modified",
3468
+ DOCLASTEDIT: "modified",
3469
+ DOCLASTPRINT: "lastPrinted"
3470
+ };
3471
+ var VISIO_FIELD_FUNCTIONS = [
3472
+ ...Object.keys(PROPERTY_FUNCTIONS),
3473
+ ...Object.keys(DATE_FUNCTIONS),
3474
+ "PAGENAME"
3475
+ ];
3476
+ function visioWallClock(date2) {
3477
+ return new Date(
3478
+ Date.UTC(
3479
+ date2.getFullYear(),
3480
+ date2.getMonth(),
3481
+ date2.getDate(),
3482
+ date2.getHours(),
3483
+ date2.getMinutes(),
3484
+ date2.getSeconds()
3485
+ )
3486
+ );
3487
+ }
3488
+ var EPOCH = Date.UTC(1899, 11, 30);
3489
+ var visioSerialDate = (serial) => Number.isFinite(serial) && Math.abs(serial) < 3e6 ? new Date(EPOCH + Math.round(serial * 864e5)) : void 0;
3490
+ function evaluateVisioTextField(formula, context) {
3491
+ let ast;
3492
+ try {
3493
+ ast = parseVisioFormula(formula, { maxLength: 4096 });
3494
+ } catch {
3495
+ return void 0;
3496
+ }
3497
+ if (ast.kind === "call") {
3498
+ const name3 = ast.name;
3499
+ if (Object.hasOwn(PROPERTY_FUNCTIONS, name3) && !ast.args.length) {
3500
+ const value = context.properties?.[PROPERTY_FUNCTIONS[name3]];
3501
+ return value === void 0 ? void 0 : { kind: "string", text: value };
3502
+ }
3503
+ if (Object.hasOwn(DATE_FUNCTIONS, name3) && !ast.args.length) {
3504
+ if (name3 === "NOW") return context.now ? { kind: "date", date: context.now } : void 0;
3505
+ const stamp = context.properties?.[DATE_FUNCTIONS[name3]];
3506
+ const time = stamp ? Date.parse(stamp) : Number.NaN;
3507
+ return Number.isFinite(time) ? { kind: "date", date: visioWallClock(new Date(time)) } : void 0;
3508
+ }
3509
+ if (name3 === "PAGENAME" && ast.args.length <= 1)
3510
+ return context.pageName === void 0 ? void 0 : { kind: "string", text: context.pageName };
3511
+ }
3512
+ try {
3513
+ const result = evaluateVisioFormula(
3514
+ ast,
3515
+ context.resolve ?? (() => {
3516
+ throw new Error("No cell context");
3517
+ }),
3518
+ {
3519
+ ...context.pageNumber === void 0 ? {} : { pageNumber: context.pageNumber },
3520
+ ...context.pageCount === void 0 ? {} : { pageCount: context.pageCount }
3521
+ }
3522
+ );
3523
+ return { kind: "number", value: result.value, unit: result.unit };
3524
+ } catch {
3525
+ return void 0;
3526
+ }
3527
+ }
3528
+ var MONTHS = [
3529
+ "January",
3530
+ "February",
3531
+ "March",
3532
+ "April",
3533
+ "May",
3534
+ "June",
3535
+ "July",
3536
+ "August",
3537
+ "September",
3538
+ "October",
3539
+ "November",
3540
+ "December"
3541
+ ];
3542
+ var DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
3543
+ var pad = (value, length = 2) => String(value).padStart(length, "0");
3544
+ function dateToken(date2, token) {
3545
+ const hours = date2.getUTCHours();
3546
+ switch (token) {
3547
+ case "yyyy":
3548
+ return pad(date2.getUTCFullYear(), 4);
3549
+ case "yy":
3550
+ return pad(date2.getUTCFullYear() % 100);
3551
+ case "MMMM":
3552
+ return MONTHS[date2.getUTCMonth()];
3553
+ case "MMM":
3554
+ return MONTHS[date2.getUTCMonth()].slice(0, 3);
3555
+ case "MM":
3556
+ return pad(date2.getUTCMonth() + 1);
3557
+ case "M":
3558
+ return String(date2.getUTCMonth() + 1);
3559
+ case "dddd":
3560
+ return DAYS[date2.getUTCDay()];
3561
+ case "ddd":
3562
+ return DAYS[date2.getUTCDay()].slice(0, 3);
3563
+ case "dd":
3564
+ return pad(date2.getUTCDate());
3565
+ case "d":
3566
+ return String(date2.getUTCDate());
3567
+ case "HH":
3568
+ return pad(hours);
3569
+ case "H":
3570
+ return String(hours);
3571
+ case "hh":
3572
+ return pad(hours % 12 || 12);
3573
+ case "h":
3574
+ return String(hours % 12 || 12);
3575
+ case "mm":
3576
+ return pad(date2.getUTCMinutes());
3577
+ case "ss":
3578
+ return pad(date2.getUTCSeconds());
3579
+ case "tt":
3580
+ return hours < 12 ? "AM" : "PM";
3581
+ default:
3582
+ return void 0;
3583
+ }
3584
+ }
3585
+ function formatDate(date2, picture) {
3586
+ return picture.replace(
3587
+ /yyyy|yy|MMMM|MMM|MM|M|dddd|ddd|dd|d|HH|H|hh|h|mm|ss|tt|"[^"]*"/g,
3588
+ (token) => {
3589
+ if (token.startsWith('"')) return token.slice(1, -1);
3590
+ return dateToken(date2, token) ?? token;
3591
+ }
3592
+ );
3593
+ }
3594
+ function formatNumber(value, picture) {
3595
+ const match = /^(#,##)?0(?:\.(0+|#+))?$/.exec(picture);
3596
+ if (!match) return void 0;
3597
+ const decimals = match[2]?.length ?? 0;
3598
+ const optional = match[2]?.startsWith("#") ?? false;
3599
+ const [coefficient, exponent = "0"] = Math.abs(value).toString().split("e");
3600
+ const shifted = Number(coefficient + "e" + (Number(exponent) + decimals));
3601
+ const rounded = Math.floor(shifted + 0.5) / 10 ** decimals;
3602
+ let text5 = (Math.sign(value) * rounded).toFixed(decimals);
3603
+ if (optional && text5.includes(".")) text5 = text5.replace(/\.?0+$/, "");
3604
+ if (match[1]) {
3605
+ const [whole, fraction] = text5.split(".");
3606
+ text5 = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (fraction ? `.${fraction}` : "");
3607
+ }
3608
+ return text5 === "-0" ? "0" : text5;
3609
+ }
3610
+ var VISIO_FIELD_FORMATS = {
3611
+ shortDate: "{{M/d/yyyy}}",
3612
+ isoDate: "{{yyyy-MM-dd}}",
3613
+ longDate: "{{dddd, MMMM d, yyyy}}",
3614
+ time: "{{h:mm tt}}",
3615
+ dateTime: "{{M/d/yyyy h:mm tt}}",
3616
+ text: "@",
3617
+ integer: "0",
3618
+ decimal: "0.00",
3619
+ decimalUnits: "0.00 u",
3620
+ integerUnits: "0 u"
3621
+ };
3622
+ function formatVisioFieldValue(value, format4 = "") {
3623
+ const picture = format4.trim();
3624
+ if (value.kind === "string") return picture === "" || picture === "@" ? value.text : void 0;
3625
+ if (value.kind === "date") {
3626
+ const date2 = /^\{\{(.+)\}\}$/.exec(picture)?.[1] ?? (picture ? void 0 : "M/d/yyyy");
3627
+ return date2 === void 0 ? void 0 : formatDate(value.date, date2);
3628
+ }
3629
+ const units2 = / u$/.test(picture);
3630
+ const body = picture.replace(/ u$/, "");
3631
+ let number5 = value.value, suffix = "";
3632
+ if (value.unit === "angle") {
3633
+ number5 = number5 * 180 / Math.PI;
3634
+ suffix = " deg.";
3635
+ } else if (value.unit === "length") suffix = " in.";
3636
+ else if (value.unit !== "scalar") return void 0;
3637
+ const text5 = body === "" || body === "@" ? String(Number(number5.toFixed(4))) : formatNumber(Number(number5.toFixed(10)), body);
3638
+ if (text5 === void 0) return void 0;
3639
+ return units2 || body === "" ? `${text5}${suffix}` : text5;
3640
+ }
3641
+
3642
+ // visio/text-field-independent.ts
3643
+ function independentTextFieldFormula(cell, formula) {
3644
+ const row2 = cell.parentNode, section3 = row2?.parentNode;
3645
+ if (cell.localName !== "Cell" || row2?.localName !== "Row" || section3?.localName !== "Section" || attribute2(section3, "N") !== "Field" || row2.hasAttribute("Del") || section3.hasAttribute("Del") || row2.hasAttribute("N") || row2.hasAttribute("T") || !/^(0|[1-9]\d*)$/.test(attribute2(row2, "IX") ?? "0") || (attribute2(section3, "IX") ?? "0") !== "0" || cell.hasAttribute("E"))
3646
+ return false;
3647
+ if (attribute2(cell, "N") === "Format")
3648
+ return /^\s*FIELDPICTURE\(\s*(2|37|204)\s*\)\s*$/i.test(formula);
3649
+ if (attribute2(cell, "N") !== "Value") return false;
3650
+ if (/^\s*DATE\(\s*\d{1,4}\s*,\s*\d{1,2}\s*,\s*\d{1,2}\s*\)\s*$/i.test(formula)) return true;
3651
+ const direct = /^\s*([A-Z]+)\(\s*\)\s*$/i.exec(formula)?.[1]?.toUpperCase();
3652
+ return direct !== void 0 && VISIO_FIELD_FUNCTIONS.includes(direct);
3653
+ }
3654
+
3453
3655
  // visio/edit-connector-glue.ts
3454
3656
  var VISIO_WALK_GLUE = "_WALKGLUE(BegTrigger,EndTrigger,WalkPreference)";
3455
3657
  var walkGlue = /^\s*_WALKGLUE\((?:BegTrigger,EndTrigger|EndTrigger,BegTrigger),WalkPreference\)\s*$/i;
@@ -3559,7 +3761,7 @@ function indexCells(roots, options) {
3559
3761
  unit: cellUnit(cell, relative)
3560
3762
  };
3561
3763
  const source = attribute2(node2, "F");
3562
- if (executableCellFormula(source) && !inertDoubleClickFormula(cell, source) && !(glue2 && isNativeGlueCell(cell, source)) && // A trigger only counts events of the sheet it names; an unglued connector keeps one
3764
+ if (executableCellFormula(source) && !independentTextFieldFormula(node2, source) && !inertDoubleClickFormula(cell, source) && !(glue2 && isNativeGlueCell(cell, source)) && // A trigger only counts events of the sheet it names; an unglued connector keeps one
3563
3765
  // (Visio's freshly dropped connector names its own sheet).
3564
3766
  !(/^(BegTrigger|EndTrigger)$/.test(cell) && isNativeGlueCell(cell, source))) {
3565
3767
  try {
@@ -6776,6 +6978,77 @@ async function prepareImages(shapes, pkg, sourcePart, report, options, converter
6776
6978
  }
6777
6979
  }
6778
6980
 
6981
+ // visio/text-field-source.ts
6982
+ var proofs = /* @__PURE__ */ new WeakMap();
6983
+ function textFieldSourceKey(cells4) {
6984
+ if (proofs.has(cells4)) return proofs.get(cells4);
6985
+ if (cells4.size > 64) {
6986
+ proofs.set(cells4, void 0);
6987
+ return void 0;
6988
+ }
6989
+ const key2 = JSON.stringify(
6990
+ [...cells4].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name3, cell]) => [
6991
+ name3,
6992
+ cell.value ?? null,
6993
+ cell.formula ?? null,
6994
+ cell.unit ?? null,
6995
+ cell.error ?? null
6996
+ ])
6997
+ );
6998
+ const bounded6 = key2.length <= 2048 ? key2 : void 0;
6999
+ proofs.set(cells4, bounded6);
7000
+ return bounded6;
7001
+ }
7002
+
7003
+ // visio/text-field-editability.ts
7004
+ function assertEditableFieldRow(existing) {
7005
+ for (const name3 of ["Calendar", "ObjectKind"]) {
7006
+ const cell = children2(existing, "Cell").find((cell2) => attribute2(cell2, "N") === name3);
7007
+ if (cell && (attribute2(cell, "V") !== "0" || cell.hasAttribute("F") || cell.hasAttribute("E")))
7008
+ fail(
7009
+ "UNSUPPORTED_TEXT_FIELD",
7010
+ "Nonstandard field calendar or object profiles cannot be edited."
7011
+ );
7012
+ }
7013
+ for (const cell of children2(existing, "Cell")) {
7014
+ const name3 = attribute2(cell, "N") ?? "";
7015
+ if (/^(value|format|type|calendar|objectkind)$/i.test(name3) && !["Value", "Format", "Type", "Calendar", "ObjectKind"].includes(name3))
7016
+ fail("UNSUPPORTED_TEXT_FIELD", "Noncanonical field cell names cannot be edited.");
7017
+ if (["Value", "Format", "Type"].includes(attribute2(cell, "N") ?? "") && (cell.hasAttribute("E") || /^\s*(Inh|GUARD\s*\()/i.test(attribute2(cell, "F") ?? "")))
7018
+ fail("UNSUPPORTED_TEXT_FIELD", "Protected or inherited field cells cannot be edited.");
7019
+ }
7020
+ }
7021
+ function assertEditableFieldShape(shape) {
7022
+ if (shape.localName !== "Shape" || shape.parentNode?.parentNode?.localName !== "PageContents" || shape.hasAttribute("Master") || shape.hasAttribute("MasterShape") || attribute2(shape, "Type") === "Group" || ["Shapes", "ForeignData", "Rel"].some((name3) => children2(shape, name3).length))
7023
+ fail("UNSUPPORTED_TEXT_FIELD", "Existing field edits require a top-level plain local shape.");
7024
+ }
7025
+ function editableTextFieldIndices(text5, allowed) {
7026
+ const result = /* @__PURE__ */ new Set();
7027
+ if (!allowed || !text5) return result;
7028
+ const shape = text5.parentNode;
7029
+ try {
7030
+ assertEditableFieldShape(shape);
7031
+ assertFormattingText(shape);
7032
+ const rows = formattingRows(shape, "Field");
7033
+ const markers = children2(text5, "fld");
7034
+ const counts = /* @__PURE__ */ new Map();
7035
+ for (const marker2 of markers) {
7036
+ const index = attribute2(marker2, "IX");
7037
+ counts.set(index, (counts.get(index) ?? 0) + 1);
7038
+ }
7039
+ for (const [index, row2] of rows) {
7040
+ if (counts.get(index) !== 1 || textFieldSourceKey(readCells(row2)) === void 0) continue;
7041
+ try {
7042
+ assertEditableFieldRow(row2);
7043
+ result.add(index);
7044
+ } catch {
7045
+ }
7046
+ }
7047
+ } catch {
7048
+ }
7049
+ return result;
7050
+ }
7051
+
6779
7052
  // geometry/svg-path-curves.ts
6780
7053
  function sampleCubic(p0, p1, p2, p3, segments, out) {
6781
7054
  for (let i = 1; i <= segments; i++) {
@@ -8875,195 +9148,35 @@ function visioFieldCase(text5, upper) {
8875
9148
  }).join("");
8876
9149
  }
8877
9150
 
8878
- // visio/text-fields.ts
8879
- var PROPERTY_FUNCTIONS = {
8880
- TITLE: "title",
8881
- SUBJECT: "subject",
8882
- CREATOR: "creator",
8883
- KEYWORDS: "keywords",
8884
- DESCRIPTION: "description",
8885
- CATEGORY: "category",
8886
- COMPANY: "company",
8887
- MANAGER: "manager"
8888
- };
8889
- var DATE_FUNCTIONS = {
8890
- NOW: void 0,
8891
- DOCCREATION: "created",
8892
- DOCLASTSAVE: "modified",
8893
- DOCLASTEDIT: "modified",
8894
- DOCLASTPRINT: "lastPrinted"
8895
- };
8896
- var VISIO_FIELD_FUNCTIONS = [
8897
- ...Object.keys(PROPERTY_FUNCTIONS),
8898
- ...Object.keys(DATE_FUNCTIONS),
8899
- "PAGENAME"
8900
- ];
8901
- function visioWallClock(date2) {
8902
- return new Date(
8903
- Date.UTC(
8904
- date2.getFullYear(),
8905
- date2.getMonth(),
8906
- date2.getDate(),
8907
- date2.getHours(),
8908
- date2.getMinutes(),
8909
- date2.getSeconds()
8910
- )
8911
- );
8912
- }
8913
- var EPOCH = Date.UTC(1899, 11, 30);
8914
- var visioDateSerial = (date2) => Number(((date2.getTime() - EPOCH) / 864e5).toFixed(8));
8915
- var visioSerialDate = (serial) => Number.isFinite(serial) && Math.abs(serial) < 3e6 ? new Date(EPOCH + Math.round(serial * 864e5)) : void 0;
8916
- function evaluateVisioTextField(formula, context) {
8917
- let ast;
8918
- try {
8919
- ast = parseVisioFormula(formula, { maxLength: 4096 });
8920
- } catch {
8921
- return void 0;
8922
- }
8923
- if (ast.kind === "call") {
8924
- const name3 = ast.name;
8925
- if (Object.hasOwn(PROPERTY_FUNCTIONS, name3) && !ast.args.length) {
8926
- const value = context.properties?.[PROPERTY_FUNCTIONS[name3]];
8927
- return value === void 0 ? void 0 : { kind: "string", text: value };
8928
- }
8929
- if (Object.hasOwn(DATE_FUNCTIONS, name3) && !ast.args.length) {
8930
- if (name3 === "NOW") return context.now ? { kind: "date", date: context.now } : void 0;
8931
- const stamp = context.properties?.[DATE_FUNCTIONS[name3]];
8932
- const time = stamp ? Date.parse(stamp) : Number.NaN;
8933
- return Number.isFinite(time) ? { kind: "date", date: visioWallClock(new Date(time)) } : void 0;
8934
- }
8935
- if (name3 === "PAGENAME" && ast.args.length <= 1)
8936
- return context.pageName === void 0 ? void 0 : { kind: "string", text: context.pageName };
8937
- }
8938
- try {
8939
- const result = evaluateVisioFormula(
8940
- ast,
8941
- context.resolve ?? (() => {
8942
- throw new Error("No cell context");
8943
- }),
8944
- {
8945
- ...context.pageNumber === void 0 ? {} : { pageNumber: context.pageNumber },
8946
- ...context.pageCount === void 0 ? {} : { pageCount: context.pageCount }
8947
- }
8948
- );
8949
- return { kind: "number", value: result.value, unit: result.unit };
8950
- } catch {
8951
- return void 0;
8952
- }
8953
- }
8954
- var MONTHS = [
8955
- "January",
8956
- "February",
8957
- "March",
8958
- "April",
8959
- "May",
8960
- "June",
8961
- "July",
8962
- "August",
8963
- "September",
8964
- "October",
8965
- "November",
8966
- "December"
8967
- ];
8968
- var DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
8969
- var pad = (value, length = 2) => String(value).padStart(length, "0");
8970
- function dateToken(date2, token) {
8971
- const hours = date2.getUTCHours();
8972
- switch (token) {
8973
- case "yyyy":
8974
- return pad(date2.getUTCFullYear(), 4);
8975
- case "yy":
8976
- return pad(date2.getUTCFullYear() % 100);
8977
- case "MMMM":
8978
- return MONTHS[date2.getUTCMonth()];
8979
- case "MMM":
8980
- return MONTHS[date2.getUTCMonth()].slice(0, 3);
8981
- case "MM":
8982
- return pad(date2.getUTCMonth() + 1);
8983
- case "M":
8984
- return String(date2.getUTCMonth() + 1);
8985
- case "dddd":
8986
- return DAYS[date2.getUTCDay()];
8987
- case "ddd":
8988
- return DAYS[date2.getUTCDay()].slice(0, 3);
8989
- case "dd":
8990
- return pad(date2.getUTCDate());
8991
- case "d":
8992
- return String(date2.getUTCDate());
8993
- case "HH":
8994
- return pad(hours);
8995
- case "H":
8996
- return String(hours);
8997
- case "hh":
8998
- return pad(hours % 12 || 12);
8999
- case "h":
9000
- return String(hours % 12 || 12);
9001
- case "mm":
9002
- return pad(date2.getUTCMinutes());
9003
- case "ss":
9004
- return pad(date2.getUTCSeconds());
9005
- case "tt":
9006
- return hours < 12 ? "AM" : "PM";
9007
- default:
9008
- return void 0;
9009
- }
9010
- }
9011
- function formatDate(date2, picture) {
9012
- return picture.replace(
9013
- /yyyy|yy|MMMM|MMM|MM|M|dddd|ddd|dd|d|HH|H|hh|h|mm|ss|tt|"[^"]*"/g,
9014
- (token) => {
9015
- if (token.startsWith('"')) return token.slice(1, -1);
9016
- return dateToken(date2, token) ?? token;
9151
+ // visio/text-field-fraction.ts
9152
+ function fractionalFieldNumber(value, maxDenominator) {
9153
+ if (!Number.isFinite(value) || Math.abs(value) > 1e15) return void 0;
9154
+ const absolute = Math.abs(value);
9155
+ let whole = Math.floor(absolute);
9156
+ const remainder = absolute - whole;
9157
+ let numerator = 0, denominator = 1, error = remainder;
9158
+ for (let candidate = 1; candidate <= maxDenominator; candidate++) {
9159
+ const top = Math.round(remainder * candidate);
9160
+ const fraction = top / candidate;
9161
+ const distance4 = Math.abs(remainder - fraction);
9162
+ if (distance4 < error || distance4 === error && fraction > numerator / denominator) {
9163
+ numerator = top;
9164
+ denominator = candidate;
9165
+ error = distance4;
9017
9166
  }
9018
- );
9019
- }
9020
- function formatNumber(value, picture) {
9021
- const match = /^(#,##)?0(?:\.(0+|#+))?$/.exec(picture);
9022
- if (!match) return void 0;
9023
- const decimals = match[2]?.length ?? 0;
9024
- const optional = match[2]?.startsWith("#") ?? false;
9025
- let text5 = value.toFixed(decimals);
9026
- if (optional && text5.includes(".")) text5 = text5.replace(/\.?0+$/, "");
9027
- if (match[1]) {
9028
- const [whole, fraction] = text5.split(".");
9029
- text5 = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (fraction ? `.${fraction}` : "");
9030
9167
  }
9031
- return text5 === "-0" ? "0" : text5;
9032
- }
9033
- var VISIO_FIELD_FORMATS = {
9034
- shortDate: "{{M/d/yyyy}}",
9035
- longDate: "{{dddd, MMMM d, yyyy}}",
9036
- time: "{{h:mm tt}}",
9037
- dateTime: "{{M/d/yyyy h:mm tt}}",
9038
- text: "@",
9039
- integer: "0",
9040
- decimal: "0.00",
9041
- decimalUnits: "0.00 u",
9042
- integerUnits: "0 u"
9043
- };
9044
- function formatVisioFieldValue(value, format4 = "") {
9045
- const picture = format4.trim();
9046
- if (value.kind === "string") return picture === "" || picture === "@" ? value.text : void 0;
9047
- if (value.kind === "date") {
9048
- const date2 = /^\{\{(.+)\}\}$/.exec(picture)?.[1] ?? (picture ? void 0 : "M/d/yyyy");
9049
- return date2 === void 0 ? void 0 : formatDate(value.date, date2);
9168
+ if (numerator === denominator) {
9169
+ whole++;
9170
+ numerator = 0;
9050
9171
  }
9051
- const units2 = / u$/.test(picture);
9052
- const body = picture.replace(/ u$/, "");
9053
- let number5 = value.value, suffix = "";
9054
- if (value.unit === "angle") {
9055
- number5 = number5 * 180 / Math.PI;
9056
- suffix = " deg.";
9057
- } else if (value.unit === "length") suffix = " in.";
9058
- else if (value.unit !== "scalar") return void 0;
9059
- const text5 = body === "" || body === "@" ? String(Number(number5.toFixed(4))) : formatNumber(Number(number5.toFixed(10)), body);
9060
- if (text5 === void 0) return void 0;
9061
- return units2 || body === "" ? `${text5}${suffix}` : text5;
9172
+ const text5 = numerator ? `${whole ? whole + " " : ""}${numerator}/${denominator}` : String(whole);
9173
+ return value < 0 && text5 !== "0" ? "-" + text5 : text5;
9062
9174
  }
9063
9175
 
9064
9176
  // visio/text-field-numeric.ts
9065
9177
  function numericFieldPicture(value, code, displayUnit) {
9066
- if (value.kind !== "number" || code < 2 || code > 9 || !Number.isInteger(code)) return void 0;
9178
+ if (value.kind !== "number" || code < 0 || code > 18 || code > 9 && code < 15 || !Number.isInteger(code))
9179
+ return void 0;
9067
9180
  const unit3 = displayUnit?.toUpperCase() ?? "NUM";
9068
9181
  const units2 = {
9069
9182
  NUM: ["scalar", 1, ""],
@@ -9076,21 +9189,106 @@ function numericFieldPicture(value, code, displayUnit) {
9076
9189
  };
9077
9190
  const definition = Object.hasOwn(units2, unit3) ? units2[unit3] : void 0;
9078
9191
  if (!definition || definition[0] !== value.unit) return void 0;
9079
- const decimals = Math.floor((code - 2) / 2);
9080
- const picture = decimals ? `0.${"0".repeat(decimals)}` : "0";
9081
- const text5 = formatVisioFieldValue(
9082
- { kind: "number", value: value.value * definition[1], unit: "scalar" },
9083
- picture
9084
- );
9192
+ const general = code < 2;
9193
+ const decimals = general ? 4 : Math.floor((code - 2) / 2);
9194
+ const picture = general ? "0.####" : decimals ? `0.${"0".repeat(decimals)}` : "0";
9195
+ const displayed = value.value * definition[1];
9196
+ if (!Number.isFinite(displayed)) return void 0;
9197
+ if (code >= 15) {
9198
+ const fraction = fractionalFieldNumber(displayed, code < 17 ? 9 : 99);
9199
+ return fraction === void 0 ? void 0 : fraction + (code % 2 === 0 ? definition[2] : "");
9200
+ }
9201
+ if ((general || !decimals) && Math.abs(displayed) > 1e15) return void 0;
9202
+ const scientific = decimals > 0 && (Math.abs(displayed) >= 1e15 || displayed !== 0 && Math.abs(displayed) < 0.5 / 10 ** decimals);
9203
+ let text5;
9204
+ if (scientific) {
9205
+ const [coefficient, power] = displayed.toExponential().split("e");
9206
+ let exponent = Number(power);
9207
+ let precision = Math.abs(displayed) >= 1e15 ? decimals : decimals - 1;
9208
+ const mantissaPicture = precision ? `0.${"0".repeat(precision)}` : "0";
9209
+ let mantissa = formatVisioFieldValue(
9210
+ { kind: "number", value: Number(coefficient), unit: "scalar" },
9211
+ mantissaPicture
9212
+ );
9213
+ if (mantissa === void 0) return void 0;
9214
+ if (Math.abs(Number(mantissa)) >= 10) {
9215
+ exponent += 1;
9216
+ precision = decimals;
9217
+ mantissa = Math.sign(displayed).toFixed(precision);
9218
+ }
9219
+ if (general) mantissa = mantissa.replace(/\.?0+$/, "");
9220
+ else if (!mantissa.includes(".")) mantissa += ".";
9221
+ text5 = mantissa + (code % 2 ? "e" : "E") + exponent;
9222
+ } else {
9223
+ text5 = formatVisioFieldValue({ kind: "number", value: displayed, unit: "scalar" }, picture);
9224
+ }
9085
9225
  return text5 === void 0 ? void 0 : text5 + (code % 2 ? definition[2] : "");
9086
9226
  }
9087
9227
 
9228
+ // visio/date-cache.ts
9229
+ function visioIsoDateSerial(text5) {
9230
+ const match = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?)?$/.exec(
9231
+ text5.trim()
9232
+ );
9233
+ if (!match) return void 0;
9234
+ const year = Number(match[1]), month = Number(match[2]), day = Number(match[3]);
9235
+ const hour = Number(match[4] ?? 0), minute = Number(match[5] ?? 0), second = Number(match[6] ?? 0);
9236
+ const millisecond = Number((match[7] ?? "").padEnd(3, "0").slice(0, 3));
9237
+ if (year < 1 || hour > 23 || minute > 59 || second > 59) return void 0;
9238
+ const date2 = /* @__PURE__ */ new Date(0);
9239
+ date2.setUTCFullYear(year, month - 1, day);
9240
+ date2.setUTCHours(hour, minute, second, millisecond);
9241
+ if (date2.getUTCFullYear() !== year || date2.getUTCMonth() !== month - 1 || date2.getUTCDate() !== day)
9242
+ return void 0;
9243
+ return (date2.getTime() - Date.UTC(1899, 11, 30)) / 864e5;
9244
+ }
9245
+
9246
+ // visio/text-field-system-date.ts
9247
+ var LONG_DATE = "{{dddd, MMMM d, yyyy}}";
9248
+ function englishLongDateProfile(cached5) {
9249
+ const match = /^[A-Za-z]+, [A-Za-z]+ ([1-9]|[12]\d|3[01]), (\d{4})$/.exec(cached5);
9250
+ if (!match) return false;
9251
+ for (let month = 0; month < 12; month++) {
9252
+ const candidate = /* @__PURE__ */ new Date(0);
9253
+ candidate.setUTCFullYear(Number(match[2]), month, Number(match[1]));
9254
+ if (candidate.getUTCMonth() === month && candidate.getTime() >= Date.UTC(1899, 11, 30) && formatVisioFieldValue({ kind: "date", date: candidate }, LONG_DATE) === cached5)
9255
+ return true;
9256
+ }
9257
+ return false;
9258
+ }
9259
+ function systemDatePicture(date2, code, cached5) {
9260
+ if (!Number.isFinite(date2.getTime()) || date2.getTime() < Date.UTC(1899, 11, 30) || date2.getUTCFullYear() > 9999)
9261
+ return void 0;
9262
+ if (code === "204") return formatVisioFieldValue({ kind: "date", date: date2 }, "{{yyyy-MM-dd}}");
9263
+ if (code === "21" || code === "201")
9264
+ return englishLongDateProfile(cached5) ? formatVisioFieldValue({ kind: "date", date: date2 }, LONG_DATE) : void 0;
9265
+ if (code === "20" || code === "200") {
9266
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(cached5) || visioIsoDateSerial(cached5) === void 0)
9267
+ return void 0;
9268
+ return formatVisioFieldValue({ kind: "date", date: date2 }, "{{yyyy-MM-dd}}");
9269
+ }
9270
+ if (code !== "211" && code !== "212") return void 0;
9271
+ const match = /^(\d{4}-\d{2}-\d{2}) ([1-9]|1[0-2]):([0-5]\d)(?::([0-5]\d))? (AM|PM)$/.exec(
9272
+ cached5
9273
+ );
9274
+ if (!match || code === "212" !== (match[4] !== void 0)) return void 0;
9275
+ const hour = Number(match[2]) % 12 + (match[5] === "PM" ? 12 : 0);
9276
+ if (visioIsoDateSerial(
9277
+ `${match[1]}T${String(hour).padStart(2, "0")}:${match[3]}:${match[4] ?? "00"}`
9278
+ ) === void 0)
9279
+ return void 0;
9280
+ return formatVisioFieldValue(
9281
+ { kind: "date", date: date2 },
9282
+ code === "211" ? "{{yyyy-MM-dd h:mm tt}}" : "{{yyyy-MM-dd h:mm:ss tt}}"
9283
+ );
9284
+ }
9285
+
9088
9286
  // visio/text-field-display.ts
9089
9287
  function cachedValue(value, unit3) {
9090
9288
  if (value === void 0) return void 0;
9091
9289
  if (unit3 === "STR") return { kind: "string", text: value };
9092
9290
  if (unit3 === "DATE") {
9093
- const date2 = visioSerialDate(Number(value));
9291
+ const date2 = visioSerialDate(visioIsoDateSerial(value) ?? Number(value));
9094
9292
  return date2 ? { kind: "date", date: date2 } : void 0;
9095
9293
  }
9096
9294
  try {
@@ -9106,7 +9304,12 @@ function textFieldDisplay(element2, sheet, context) {
9106
9304
  const row2 = sectionRows(sheet, "Field").find((candidate) => candidate.index === index);
9107
9305
  const value = row2?.cells.get("Value"), format4 = row2?.cells.get("Format");
9108
9306
  const formula = value?.formula && value.formula !== "Inh" ? value.formula : void 0;
9109
- const result = { cached: cached5, ...formula ? { formula } : {} };
9307
+ const sourceKey = row2 ? textFieldSourceKey(row2.cells) : void 0;
9308
+ const result = {
9309
+ cached: cached5,
9310
+ ...formula ? { formula } : {},
9311
+ ...sourceKey !== void 0 ? { index, format: format4?.value ?? "", sourceKey } : {}
9312
+ };
9110
9313
  if (!row2 || !context) return { text: cached5, ...result };
9111
9314
  const picture = format4?.value ?? "";
9112
9315
  const evaluated = formula ? evaluateVisioTextField(formula, context) : void 0;
@@ -9120,6 +9323,8 @@ function textFieldDisplay(element2, sheet, context) {
9120
9323
  }
9121
9324
  if (source?.kind === "number" && code !== void 0)
9122
9325
  text6 = numericFieldPicture(source, Number(code), value?.unit) ?? cached5;
9326
+ if (source?.kind === "date" && code !== void 0)
9327
+ text6 = systemDatePicture(source.date, code, cached5) ?? cached5;
9123
9328
  return { text: text6, ...result };
9124
9329
  }
9125
9330
  const text5 = source ? formatVisioFieldValue(source, picture) : void 0;
@@ -9978,7 +10183,8 @@ function runStyle(cells4, resources, report, themeCells) {
9978
10183
  ...characterExtras(cells4, report)
9979
10184
  };
9980
10185
  }
9981
- function shapeText(sheet, node2, width, height, resources, report, consume, consumeParagraph) {
10186
+ function shapeText(sheet, node2, width, height, resources, report, consume, consumeParagraph, allowFieldEditing = false) {
10187
+ const editableFields = editableTextFieldIndices(node2, allowFieldEditing);
9982
10188
  const cells4 = sheet.cells;
9983
10189
  const characters = new Map(sectionRows(sheet, "Character").map((row2) => [row2.index, row2.cells]));
9984
10190
  const defaultCells = characters.get("0") ?? /* @__PURE__ */ new Map();
@@ -10013,7 +10219,9 @@ function shapeText(sheet, node2, width, height, resources, report, consume, cons
10013
10219
  start: textOffset,
10014
10220
  end: textOffset + field2.text.length,
10015
10221
  cached: field2.cached,
10016
- ...field2.formula ? { formula: field2.formula } : {}
10222
+ ...field2.index !== void 0 && editableFields.has(field2.index) ? { editable: true } : {},
10223
+ ...field2.formula ? { formula: field2.formula } : {},
10224
+ ...field2.index === void 0 ? {} : { index: field2.index, format: field2.format, sourceKey: field2.sourceKey }
10017
10225
  });
10018
10226
  append(field2.text);
10019
10227
  } else if (element2.localName !== "pp" && element2.localName !== "tp") {
@@ -10576,15 +10784,6 @@ function booleanValue(text5) {
10576
10784
  const value = numeric3(text5);
10577
10785
  return value === void 0 ? void 0 : value !== 0;
10578
10786
  }
10579
- function isoSerialDays(text5) {
10580
- const match = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2}(?:\.\d+)?))?)?$/.exec(
10581
- text5.trim()
10582
- );
10583
- if (!match) return void 0;
10584
- const [year, month, day, hour, minute, second] = match.slice(1).map((part) => Number(part ?? 0));
10585
- const time = Date.UTC(year, month - 1, day, hour, minute, second);
10586
- return Number.isFinite(time) ? (time - Date.UTC(1899, 11, 30)) / 864e5 : void 0;
10587
- }
10588
10787
  function property(row2, budget, report) {
10589
10788
  const get = (key2) => cached(row2.cells, key2, budget, report);
10590
10789
  const rawType = get("Type"), rawValue = get("Value");
@@ -10595,7 +10794,7 @@ function property(row2, budget, report) {
10595
10794
  if (rawValue !== void 0 && row2.cells.get("Value")?.error === void 0) {
10596
10795
  if (type === 0 || type === 1 || type === 4) value = budget.retain(rawValue);
10597
10796
  else if (type === 3) value = booleanValue(rawValue);
10598
- else if (type === 5) value = numeric3(rawValue) ?? isoSerialDays(rawValue);
10797
+ else if (type === 5) value = numeric3(rawValue) ?? visioIsoDateSerial(rawValue);
10599
10798
  else if (valueKind !== "unparsed") value = numeric3(rawValue);
10600
10799
  }
10601
10800
  if (value === void 0) {
@@ -11301,7 +11500,8 @@ function normalizeShapes(raw, context, depth = 0, masterStack = []) {
11301
11500
  context.resources,
11302
11501
  report,
11303
11502
  context.consumeText,
11304
- context.consumeParagraph
11503
+ context.consumeParagraph,
11504
+ depth === 0 && masterId === void 0 && !sheet.cells.get("LockTextEdit")?.error && !sheet.cells.get("LockTextEdit")?.formula && number(sheet.cells, "LockTextEdit", 0, report) === 0
11305
11505
  ),
11306
11506
  hidden: membership.hidden || type === "Guide" || number(sheet.cells, "NoShow", 0, report) !== 0,
11307
11507
  visibility: {
@@ -21944,6 +22144,7 @@ async function assertFormattingDependencies(pkg, pagePaths, roots, pageId2, shap
21944
22144
  continue;
21945
22145
  const source = executableCellFormula(attribute2(node2, "F"));
21946
22146
  if (!source || inertDoubleClickFormula(attribute2(node2, "N") ?? "", source)) continue;
22147
+ if (independentTextFieldFormula(node2, source)) continue;
21947
22148
  if (attribute2(node2, "V") === "Themed" && isThemeLookupFormula(source)) continue;
21948
22149
  if (isConnectedGlueCell(node2, source)) continue;
21949
22150
  const owner = node2.parentNode;
@@ -26813,7 +27014,8 @@ function shapeResolver(shape) {
26813
27014
  }
26814
27015
  function valueCell(value) {
26815
27016
  if (value.kind === "string") return { v: value.text, u: "STR", type: 0 };
26816
- if (value.kind === "date") return { v: String(visioDateSerial(value.date)), u: "DATE", type: 5 };
27017
+ if (value.kind === "date")
27018
+ return { v: value.date.toISOString().replace(/Z$/, ""), u: "DATE", type: 5 };
26817
27019
  const unit3 = value.unit === "length" ? "IN" : value.unit === "angle" ? "DEG" : void 0;
26818
27020
  return { v: String(Number(value.value.toFixed(10))), ...unit3 ? { u: unit3 } : {}, type: 2 };
26819
27021
  }
@@ -26853,9 +27055,23 @@ async function insertVisioTextField(pkg, pagePaths, roots, document, edit, check
26853
27055
  effectiveFormattingRows(shape, document, "Paragraph")
26854
27056
  );
26855
27057
  const rows = formattingRows(shape, "Field");
26856
- const point2 = insertionPoint(text5, edit.offset);
26857
- if (edit.offset !== void 0 && point2.logical !== edit.expectedText)
27058
+ const updating = edit.type === "update-text-field";
27059
+ if (updating) assertEditableFieldShape(shape);
27060
+ const point2 = insertionPoint(text5, updating ? void 0 : edit.offset);
27061
+ if ((updating || edit.offset !== void 0) && point2.logical !== edit.expectedText)
26858
27062
  fail("EDIT_STALE_TEXT", "The shape text changed since the field position was chosen.");
27063
+ const existing = updating ? rows.get(edit.fieldIndex) : void 0;
27064
+ const markers = updating ? children2(text5, "fld").filter((field3) => attribute2(field3, "IX") === edit.fieldIndex) : [];
27065
+ if (updating) {
27066
+ if (!existing || markers.length !== 1)
27067
+ fail(
27068
+ "UNSUPPORTED_TEXT_FIELD",
27069
+ "Existing fields require one live local row and unique text marker."
27070
+ );
27071
+ if (markers[0].textContent !== edit.expectedCached || textFieldSourceKey(readCells(existing)) !== edit.expectedSourceKey)
27072
+ fail("EDIT_STALE_TEXT", "The field source changed since it was selected.");
27073
+ assertEditableFieldRow(existing);
27074
+ }
26859
27075
  const context = { ...await pageContext(pkg, edit.pageId), resolve: shapeResolver(shape) };
26860
27076
  let value;
26861
27077
  try {
@@ -26868,9 +27084,19 @@ async function insertVisioTextField(pkg, pagePaths, roots, document, edit, check
26868
27084
  "UNSUPPORTED_TEXT_FIELD",
26869
27085
  `This editor cannot evaluate the field formula. Supported: ${VISIO_FIELD_FUNCTIONS.join(", ")}, PAGENUMBER, PAGECOUNT and numeric formulas on this shape.`
26870
27086
  );
26871
- const display = formatVisioFieldValue(value, edit.format ?? "");
27087
+ const format4 = edit.format ?? "";
27088
+ const display = formatVisioFieldValue(value, format4);
26872
27089
  if (display === void 0)
26873
27090
  fail("UNSUPPORTED_TEXT_FIELD", "The field format does not suit the field value.");
27091
+ const prepared = valueCell(value);
27092
+ if (existing && markers[0].textContent === display) {
27093
+ const same5 = (name3, v, u, f) => {
27094
+ const cell2 = children2(existing, "Cell").find((cell3) => attribute2(cell3, "N") === name3);
27095
+ return attribute2(cell2, "V") === v && attribute2(cell2, "U") === u && attribute2(cell2, "F") === f;
27096
+ };
27097
+ if (same5("Value", prepared.v, prepared.u, edit.formula) && same5("Format", format4, "STR", `"${format4.replaceAll('"', '""')}"`) && same5("Type", String(prepared.type), void 0, void 0))
27098
+ return false;
27099
+ }
26874
27100
  if (texts[0])
26875
27101
  await assertFormattingDependencies(
26876
27102
  pkg,
@@ -26878,31 +27104,49 @@ async function insertVisioTextField(pkg, pagePaths, roots, document, edit, check
26878
27104
  roots,
26879
27105
  edit.pageId,
26880
27106
  shape,
26881
- /* @__PURE__ */ new Map([["TheText", text5]]),
27107
+ new Map([
27108
+ ["TheText", text5],
27109
+ ...existing ? ["Value", "Format", "Type"].flatMap((name3) => {
27110
+ const cell2 = children2(existing, "Cell").find((cell3) => attribute2(cell3, "N") === name3);
27111
+ return [
27112
+ [`Field.${updating ? edit.fieldIndex : ""}.${name3}`, cell2],
27113
+ [`Fields.${name3}`, cell2]
27114
+ ];
27115
+ }) : []
27116
+ ]),
26882
27117
  check
26883
27118
  );
26884
27119
  check();
26885
- const index = String(rows.size ? Math.max(...[...rows.keys()].map(Number)) + 1 : 0);
27120
+ const index = updating ? edit.fieldIndex : String(rows.size ? Math.max(...[...rows.keys()].map(Number)) + 1 : 0);
26886
27121
  let section3 = children2(shape, "Section").find((node2) => attribute2(node2, "N") === "Field");
26887
27122
  if (!section3) {
26888
27123
  section3 = owner.createElementNS(ns, "Section");
26889
27124
  section3.setAttribute("N", "Field");
26890
27125
  shape.insertBefore(section3, texts[0] ?? null);
26891
27126
  }
26892
- const row2 = owner.createElementNS(ns, "Row");
26893
- row2.setAttribute("IX", index);
27127
+ const row2 = existing ?? owner.createElementNS(ns, "Row");
27128
+ if (!existing) row2.setAttribute("IX", index);
26894
27129
  const cell = (name3, v, extra = {}) => {
26895
- const node2 = owner.createElementNS(ns, "Cell");
27130
+ const node2 = children2(row2, "Cell").find((cell2) => attribute2(cell2, "N") === name3) ?? owner.createElementNS(ns, "Cell");
26896
27131
  node2.setAttribute("N", name3);
26897
27132
  node2.setAttribute("V", v);
27133
+ if (updating) {
27134
+ node2.removeAttribute("U");
27135
+ node2.removeAttribute("F");
27136
+ }
26898
27137
  for (const [key2, item] of Object.entries(extra)) node2.setAttribute(key2, item);
26899
- row2.appendChild(node2);
27138
+ if (!node2.parentNode) row2.appendChild(node2);
26900
27139
  };
26901
- const stored = valueCell(value);
27140
+ const stored = prepared;
26902
27141
  cell("Value", stored.v, { ...stored.u ? { U: stored.u } : {}, F: edit.formula });
26903
- if (edit.format) cell("Format", edit.format, { F: `"${edit.format.replaceAll('"', '""')}"` });
27142
+ if (format4 || updating)
27143
+ cell("Format", format4, { U: "STR", F: `"${format4.replaceAll('"', '""')}"` });
26904
27144
  cell("Type", String(stored.type));
26905
- section3.appendChild(row2);
27145
+ if (!row2.parentNode) section3.appendChild(row2);
27146
+ if (updating) {
27147
+ markers[0].textContent = display;
27148
+ return true;
27149
+ }
26906
27150
  const field2 = owner.createElementNS(ns, "fld");
26907
27151
  field2.setAttribute("IX", index);
26908
27152
  field2.appendChild(owner.createTextNode(display));
@@ -29300,6 +29544,35 @@ function snapshotGuideEdit(edit) {
29300
29544
  }
29301
29545
 
29302
29546
  // visio/edit-text-field-commands.ts
29547
+ function snapshotTextFieldUpdate(edit) {
29548
+ const insert = snapshotTextFieldInsert({
29549
+ pageId: edit.pageId,
29550
+ shapeId: edit.shapeId,
29551
+ formula: edit.formula,
29552
+ ...edit.format === void 0 ? {} : { format: edit.format }
29553
+ });
29554
+ if (analyzeVisioFormula(parseVisioFormula(insert.formula)).references.some(
29555
+ (ref) => /^fields?\./i.test(ref.cell)
29556
+ ))
29557
+ fail("UNSUPPORTED_TEXT_FIELD", "Existing field formulas cannot reference Field rows.");
29558
+ if (typeof edit.fieldIndex !== "string" || !/^(0|[1-9]\d{0,9})$/.test(edit.fieldIndex) || Number(edit.fieldIndex) > 4294967295)
29559
+ fail("INVALID_EDIT", "An existing field needs a canonical row index.");
29560
+ if ([edit.expectedText, edit.expectedCached, edit.expectedSourceKey].some(
29561
+ (value) => typeof value !== "string" || value.length > 1e6
29562
+ ) || !edit.expectedSourceKey)
29563
+ fail("INVALID_EDIT", "An existing field needs its source text and row identity.");
29564
+ return {
29565
+ type: "update-text-field",
29566
+ pageId: insert.pageId,
29567
+ shapeId: insert.shapeId,
29568
+ fieldIndex: edit.fieldIndex,
29569
+ formula: insert.formula,
29570
+ format: insert.format,
29571
+ expectedText: edit.expectedText,
29572
+ expectedCached: edit.expectedCached,
29573
+ expectedSourceKey: edit.expectedSourceKey
29574
+ };
29575
+ }
29303
29576
  function snapshotTextFieldInsert(edit) {
29304
29577
  const { pageId: pageId2, shapeId: shapeId2 } = edit;
29305
29578
  if ([pageId2, shapeId2].some((id3) => typeof id3 !== "string" || !id3 || id3.length > 256))
@@ -30053,6 +30326,14 @@ function snapshotVisioEdits(edits, maxEdits, maxText) {
30053
30326
  return { ...target2, type: edit.type, text: text5(edit.text) };
30054
30327
  if (edit.type === "replace-text-ranges") return snapshotTextRanges(edit, text5);
30055
30328
  if (edit.type === "insert-text-field") return snapshotTextFieldInsert(edit);
30329
+ if (edit.type === "update-text-field") {
30330
+ const update = snapshotTextFieldUpdate(edit);
30331
+ update.formula = text5(update.formula);
30332
+ update.expectedText = text5(update.expectedText);
30333
+ update.expectedCached = text5(update.expectedCached);
30334
+ update.expectedSourceKey = text5(update.expectedSourceKey);
30335
+ return update;
30336
+ }
30056
30337
  if (isVisioFormatEdit(edit)) return snapshotFormatting(edit);
30057
30338
  if (edit.type === "reorder-shape") {
30058
30339
  if (!["front", "back", "forward", "backward"].includes(edit.order))
@@ -35480,7 +35761,7 @@ async function editVsdxTransaction(input, edits, options, clock = {
35480
35761
  const dirty = /* @__PURE__ */ new Map();
35481
35762
  const roots = /* @__PURE__ */ new Map();
35482
35763
  const geometryCommands = commands.filter(
35483
- (command2) => command2.type !== "replace-plain-text" && command2.type !== "replace-text-ranges" && command2.type !== "insert-text-field" && command2.type !== "reorder-shape" && command2.type !== "duplicate-shapes" && command2.type !== "paste-shapes" && command2.type !== "change-shape" && command2.type !== "insert-picture" && command2.type !== "set-page-theme" && !isVisioMetadataEdit(command2) && command2.type !== "set-shape-data" && !isVisioGroupEdit(command2) && !isVisioDiagramPartEdit(command2) && !isVisioGuideEdit(command2) && !isVisioFormatEdit(command2)
35764
+ (command2) => command2.type !== "replace-plain-text" && command2.type !== "replace-text-ranges" && command2.type !== "insert-text-field" && command2.type !== "update-text-field" && command2.type !== "reorder-shape" && command2.type !== "duplicate-shapes" && command2.type !== "paste-shapes" && command2.type !== "change-shape" && command2.type !== "insert-picture" && command2.type !== "set-page-theme" && !isVisioMetadataEdit(command2) && command2.type !== "set-shape-data" && !isVisioGroupEdit(command2) && !isVisioDiagramPartEdit(command2) && !isVisioGuideEdit(command2) && !isVisioFormatEdit(command2)
35484
35765
  );
35485
35766
  let document;
35486
35767
  let masterMovePins = emptyMasterMoveProof();
@@ -35488,7 +35769,7 @@ async function editVsdxTransaction(input, edits, options, clock = {
35488
35769
  let instanceDeletes = /* @__PURE__ */ new Set();
35489
35770
  let groupMembers = /* @__PURE__ */ new Map();
35490
35771
  if (geometryCommands.length || commands.some(
35491
- (command2) => command2.type === "replace-plain-text" || command2.type === "replace-text-ranges" || command2.type === "insert-text-field" || isVisioFormatEdit(command2) || isVisioMetadataEdit(command2) || command2.type === "set-shape-data" || command2.type === "reorder-shape" || command2.type === "duplicate-shapes" || command2.type === "paste-shapes" || command2.type === "change-shape" || isVisioGroupEdit(command2) || isVisioDiagramPartEdit(command2) || isVisioGuideEdit(command2)
35772
+ (command2) => command2.type === "replace-plain-text" || command2.type === "replace-text-ranges" || command2.type === "insert-text-field" || command2.type === "update-text-field" || isVisioFormatEdit(command2) || isVisioMetadataEdit(command2) || command2.type === "set-shape-data" || command2.type === "reorder-shape" || command2.type === "duplicate-shapes" || command2.type === "paste-shapes" || command2.type === "change-shape" || isVisioGroupEdit(command2) || isVisioDiagramPartEdit(command2) || isVisioGuideEdit(command2)
35492
35773
  )) {
35493
35774
  for (const [pageId2, path2] of pages) {
35494
35775
  const sourceRoot = await visioXml(pkg, path2, "PageContents");
@@ -35599,7 +35880,7 @@ async function editVsdxTransaction(input, edits, options, clock = {
35599
35880
  textChanged = true;
35600
35881
  await noteTextSize(command2, root2);
35601
35882
  }
35602
- } else if (command2.type === "insert-text-field") {
35883
+ } else if (command2.type === "insert-text-field" || command2.type === "update-text-field") {
35603
35884
  if (await insertVisioTextField(pkg, new Set(pages.values()), roots, document, command2, check)) {
35604
35885
  dirty.set(path, root2);
35605
35886
  textChanged = true;