ooxml-core 1.10.0 → 1.12.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 (205) hide show
  1. package/dist/PptxHandler-DNZHAHUY.cjs +12 -0
  2. package/dist/PptxHandler-E44KDHMQ.mjs +3 -0
  3. package/dist/{PptxHandler-ADEFY476.mjs → PptxHandler-NROFYT2N.mjs} +2 -2
  4. package/dist/automation/index.cjs +3504 -2888
  5. package/dist/automation/index.mjs +3504 -2888
  6. package/dist/{chunk-3N6XMMTT.cjs → chunk-2UVH6RHI.cjs} +1138 -996
  7. package/dist/{chunk-ZOUGMAZG.mjs → chunk-7DSZI7S6.mjs} +1 -1
  8. package/dist/{chunk-S6DOCMQC.cjs → chunk-7QZGRB3T.cjs} +0 -10
  9. package/dist/chunk-ANZ4Q6I3.cjs +21 -0
  10. package/dist/{chunk-5NVJN4E6.mjs → chunk-EC2W2MDY.mjs} +1 -1
  11. package/dist/chunk-EGTRL3QJ.mjs +19 -0
  12. package/dist/chunk-GXHKNSZX.mjs +9 -0
  13. package/dist/{chunk-CCHYFCPD.mjs → chunk-HCXUI5UC.mjs} +296 -103
  14. package/dist/chunk-HDQXPSHY.cjs +17 -0
  15. package/dist/chunk-KTYBFGEY.mjs +14 -0
  16. package/dist/chunk-QOO36KG4.cjs +42 -0
  17. package/dist/chunk-R2KZXD6U.mjs +39 -0
  18. package/dist/{chunk-A6P7G3UK.mjs → chunk-U2DF3EGK.mjs} +1 -1
  19. package/dist/{chunk-R6KSBNKX.mjs → chunk-UAY26XOI.mjs} +1 -9
  20. package/dist/{chunk-WUE5ZHU3.mjs → chunk-W5ARCUJB.mjs} +3 -3
  21. package/dist/chunk-XZPZHXV4.cjs +12 -0
  22. package/dist/{chunk-ZE53K7DH.mjs → chunk-YB5SRNFS.mjs} +244 -102
  23. package/dist/docx/embedded.cjs +1 -1
  24. package/dist/docx/embedded.mjs +1 -1
  25. package/dist/docx/index.cjs +1 -1
  26. package/dist/docx/index.mjs +1 -1
  27. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  28. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  29. package/dist/docx/layout/index.cjs +266 -61
  30. package/dist/docx/layout/index.d.ts +1 -0
  31. package/dist/docx/layout/index.d.ts.map +1 -1
  32. package/dist/docx/layout/index.mjs +266 -62
  33. package/dist/docx/layout/input.d.ts +5 -0
  34. package/dist/docx/layout/input.d.ts.map +1 -1
  35. package/dist/docx/layout/layout-session.d.ts +10 -0
  36. package/dist/docx/layout/layout-session.d.ts.map +1 -0
  37. package/dist/docx/layout/nested-fragment-edges.d.ts +9 -0
  38. package/dist/docx/layout/nested-fragment-edges.d.ts.map +1 -0
  39. package/dist/docx/layout/paragraph-cache.d.ts +8 -0
  40. package/dist/docx/layout/paragraph-cache.d.ts.map +1 -0
  41. package/dist/docx/layout/paragraph-layout.d.ts.map +1 -1
  42. package/dist/docx/layout/paragraph-tokens.d.ts +1 -1
  43. package/dist/docx/layout/paragraph-tokens.d.ts.map +1 -1
  44. package/dist/docx/layout/result.d.ts +7 -0
  45. package/dist/docx/layout/result.d.ts.map +1 -1
  46. package/dist/docx/layout/table-border-layout.d.ts +1 -1
  47. package/dist/docx/layout/table-border-layout.d.ts.map +1 -1
  48. package/dist/docx/layout/table-cell-layout.d.ts +1 -1
  49. package/dist/docx/layout/table-cell-layout.d.ts.map +1 -1
  50. package/dist/docx/layout/table-frames.d.ts.map +1 -1
  51. package/dist/docx/layout/table-layout.d.ts +1 -1
  52. package/dist/docx/layout/table-layout.d.ts.map +1 -1
  53. package/dist/docx/layout/table-paragraph-keeps.d.ts +14 -0
  54. package/dist/docx/layout/table-paragraph-keeps.d.ts.map +1 -0
  55. package/dist/docx/load/index.cjs +1 -1
  56. package/dist/docx/load/index.mjs +1 -1
  57. package/dist/docx/ui/index.cjs +83 -6
  58. package/dist/docx/ui/index.mjs +83 -7
  59. package/dist/docx/ui/ribbon-action-ids.d.ts +1 -1
  60. package/dist/docx/ui/ribbon-action-ids.d.ts.map +1 -1
  61. package/dist/docx/ui/word-count.d.ts +3 -0
  62. package/dist/docx/ui/word-count.d.ts.map +1 -1
  63. package/dist/geometry/element-transform.d.ts +90 -0
  64. package/dist/geometry/element-transform.d.ts.map +1 -0
  65. package/dist/geometry/index.cjs +90 -0
  66. package/dist/geometry/index.d.ts +1 -0
  67. package/dist/geometry/index.d.ts.map +1 -1
  68. package/dist/geometry/index.mjs +83 -1
  69. package/dist/index.cjs +90 -0
  70. package/dist/index.mjs +90 -0
  71. package/dist/pptx/automation/index.cjs +266 -114
  72. package/dist/pptx/automation/index.d.ts +5 -4
  73. package/dist/pptx/automation/index.d.ts.map +1 -1
  74. package/dist/pptx/automation/index.mjs +5 -5
  75. package/dist/pptx/chunks/{text-operations-BqHmLaLA.d.ts → elements-DD3UGOMd.d.ts} +17 -3262
  76. package/dist/pptx/chunks/elements-DD3UGOMd.d.ts.map +1 -0
  77. package/dist/pptx/chunks/{index-DUCGeZh7.d.ts → index-BZrFyNtU.d.ts} +53 -5
  78. package/dist/pptx/chunks/index-BZrFyNtU.d.ts.map +1 -0
  79. package/dist/pptx/chunks/{index-Cuxtr76Y.d.ts → index-DdX02BSm.d.ts} +5 -3
  80. package/dist/pptx/chunks/index-DdX02BSm.d.ts.map +1 -0
  81. package/dist/pptx/chunks/smart-art-ENMMEbmW.d.ts +1512 -0
  82. package/dist/pptx/chunks/smart-art-ENMMEbmW.d.ts.map +1 -0
  83. package/dist/pptx/chunks/text-D49FKllA.d.ts +1473 -0
  84. package/dist/pptx/chunks/text-D49FKllA.d.ts.map +1 -0
  85. package/dist/pptx/chunks/text-operations-CyMTMfID.d.ts +3261 -0
  86. package/dist/pptx/chunks/text-operations-CyMTMfID.d.ts.map +1 -0
  87. package/dist/pptx/cli/index.cjs +266 -114
  88. package/dist/pptx/cli/index.d.ts +1 -1
  89. package/dist/pptx/cli/index.mjs +4 -4
  90. package/dist/pptx/converter/index.d.ts +1 -1
  91. package/dist/pptx/converter/index.mjs +2 -2
  92. package/dist/pptx/editor/render/find-replace.cjs +17 -16
  93. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  94. package/dist/pptx/editor/render/find-replace.mjs +2 -1
  95. package/dist/pptx/editor/render/font-family-update.cjs +14 -0
  96. package/dist/pptx/editor/render/font-family-update.d.ts +17 -0
  97. package/dist/pptx/editor/render/font-family-update.d.ts.map +1 -0
  98. package/dist/pptx/editor/render/font-family-update.mjs +1 -0
  99. package/dist/pptx/editor/render/paragraph-geometry-overrides.cjs +14 -0
  100. package/dist/pptx/editor/render/paragraph-geometry-overrides.d.ts +17 -0
  101. package/dist/pptx/editor/render/paragraph-geometry-overrides.d.ts.map +1 -0
  102. package/dist/pptx/editor/render/paragraph-geometry-overrides.mjs +12 -0
  103. package/dist/pptx/editor/render/slide-operations.cjs +9 -8
  104. package/dist/pptx/editor/render/slide-operations.mjs +3 -2
  105. package/dist/pptx/editor/render/table-data-grid-ops.cjs +1 -1
  106. package/dist/pptx/editor/render/table-data-grid-ops.mjs +1 -1
  107. package/dist/pptx/editor/render/text-content-style.cjs +18 -0
  108. package/dist/pptx/editor/render/text-content-style.d.ts +9 -0
  109. package/dist/pptx/editor/render/text-content-style.d.ts.map +1 -0
  110. package/dist/pptx/editor/render/text-content-style.mjs +5 -0
  111. package/dist/pptx/editor/render/text-runs-style-patch.cjs +17 -0
  112. package/dist/pptx/editor/render/text-runs-style-patch.d.ts +7 -0
  113. package/dist/pptx/editor/render/text-runs-style-patch.d.ts.map +1 -0
  114. package/dist/pptx/editor/render/text-runs-style-patch.mjs +15 -0
  115. package/dist/pptx/editor/render/text-style-scope.cjs +173 -0
  116. package/dist/pptx/editor/render/text-style-scope.d.ts +76 -0
  117. package/dist/pptx/editor/render/text-style-scope.d.ts.map +1 -0
  118. package/dist/pptx/editor/render/text-style-scope.mjs +164 -0
  119. package/dist/pptx/editor/render/theme-editor-model.cjs +1 -1
  120. package/dist/pptx/editor/render/theme-editor-model.mjs +1 -1
  121. package/dist/pptx/editor/render/update-text-segment-style.cjs +11 -0
  122. package/dist/pptx/editor/render/update-text-segment-style.d.ts +14 -0
  123. package/dist/pptx/editor/render/update-text-segment-style.d.ts.map +1 -0
  124. package/dist/pptx/editor/render/update-text-segment-style.mjs +2 -0
  125. package/dist/pptx/index.cjs +329 -114
  126. package/dist/pptx/index.d.ts +7 -5
  127. package/dist/pptx/index.mjs +5 -5
  128. package/dist/pptx/smartart-layouts/index.d.ts +1 -1
  129. package/dist/teams/index.cjs +112 -16
  130. package/dist/teams/index.mjs +112 -16
  131. package/dist/visio/edit-commands.d.ts +3 -3
  132. package/dist/visio/edit-commands.d.ts.map +1 -1
  133. package/dist/visio/edit-formatting-scope.d.ts.map +1 -1
  134. package/dist/visio/edit-recalculate-index.d.ts.map +1 -1
  135. package/dist/visio/edit-text-field-commands.d.ts +15 -0
  136. package/dist/visio/edit-text-field-commands.d.ts.map +1 -1
  137. package/dist/visio/edit-text-field.d.ts +2 -2
  138. package/dist/visio/edit-text-field.d.ts.map +1 -1
  139. package/dist/visio/edit.d.ts +1 -1
  140. package/dist/visio/edit.d.ts.map +1 -1
  141. package/dist/visio/index.cjs +696 -249
  142. package/dist/visio/index.d.ts +2 -1
  143. package/dist/visio/index.d.ts.map +1 -1
  144. package/dist/visio/index.mjs +695 -250
  145. package/dist/visio/model.d.ts +18 -0
  146. package/dist/visio/model.d.ts.map +1 -1
  147. package/dist/visio/paper-sizes.d.ts +5 -0
  148. package/dist/visio/paper-sizes.d.ts.map +1 -1
  149. package/dist/visio/parser.d.ts.map +1 -1
  150. package/dist/visio/print-count.d.ts +20 -0
  151. package/dist/visio/print-count.d.ts.map +1 -0
  152. package/dist/visio/print-settings.d.ts +14 -0
  153. package/dist/visio/print-settings.d.ts.map +1 -0
  154. package/dist/visio/shapes.d.ts.map +1 -1
  155. package/dist/visio/style.d.ts +1 -1
  156. package/dist/visio/style.d.ts.map +1 -1
  157. package/dist/visio/text-field-display.d.ts +3 -0
  158. package/dist/visio/text-field-display.d.ts.map +1 -1
  159. package/dist/visio/text-field-editability.d.ts +6 -0
  160. package/dist/visio/text-field-editability.d.ts.map +1 -0
  161. package/dist/visio/text-field-independent.d.ts +4 -0
  162. package/dist/visio/text-field-independent.d.ts.map +1 -0
  163. package/dist/visio/text-field-source.d.ts +6 -0
  164. package/dist/visio/text-field-source.d.ts.map +1 -0
  165. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  166. package/dist/visio/ui/index.cjs +588 -215
  167. package/dist/visio/ui/index.mjs +588 -215
  168. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  169. package/dist/xlsx/edit/pivots.d.ts.map +1 -1
  170. package/dist/xlsx/index.cjs +773 -514
  171. package/dist/xlsx/index.mjs +772 -515
  172. package/dist/xlsx/load/index.cjs +541 -292
  173. package/dist/xlsx/load/index.mjs +541 -292
  174. package/dist/xlsx/model-pivots.d.ts +8 -0
  175. package/dist/xlsx/model-pivots.d.ts.map +1 -1
  176. package/dist/xlsx/pivot/admission.d.ts.map +1 -1
  177. package/dist/xlsx/pivot/aggregate.d.ts.map +1 -1
  178. package/dist/xlsx/pivot/data.d.ts +2 -2
  179. package/dist/xlsx/pivot/data.d.ts.map +1 -1
  180. package/dist/xlsx/pivot/index.d.ts +2 -0
  181. package/dist/xlsx/pivot/index.d.ts.map +1 -1
  182. package/dist/xlsx/pivot/measures.d.ts +1 -1
  183. package/dist/xlsx/pivot/measures.d.ts.map +1 -1
  184. package/dist/xlsx/pivot/page-filter-admission.d.ts +5 -0
  185. package/dist/xlsx/pivot/page-filter-admission.d.ts.map +1 -0
  186. package/dist/xlsx/pivot/page-filter.d.ts +11 -0
  187. package/dist/xlsx/pivot/page-filter.d.ts.map +1 -0
  188. package/dist/xlsx/pivot/read.d.ts.map +1 -1
  189. package/dist/xlsx/pivot/table-xml.d.ts.map +1 -1
  190. package/dist/xlsx/pivot/values-axis.d.ts +4 -1
  191. package/dist/xlsx/pivot/values-axis.d.ts.map +1 -1
  192. package/dist/xlsx/ui/commands/i18n/navigation.d.ts.map +1 -1
  193. package/dist/xlsx/ui/commands/i18n/pivots.d.ts.map +1 -1
  194. package/dist/xlsx/ui/index.cjs +95 -12
  195. package/dist/xlsx/ui/index.mjs +95 -12
  196. package/dist/xlsx/ui/ribbon/parts.d.ts +1 -0
  197. package/dist/xlsx/ui/ribbon/parts.d.ts.map +1 -1
  198. package/package.json +2 -2
  199. package/dist/PptxHandler-5UURGJEV.mjs +0 -2
  200. package/dist/PptxHandler-U5XB2HUE.cjs +0 -11
  201. package/dist/pptx/chunks/index-Cuxtr76Y.d.ts.map +0 -1
  202. package/dist/pptx/chunks/index-DUCGeZh7.d.ts.map +0 -1
  203. package/dist/pptx/chunks/smart-art-D-sXa_Nb.d.ts +0 -2980
  204. package/dist/pptx/chunks/smart-art-D-sXa_Nb.d.ts.map +0 -1
  205. package/dist/pptx/chunks/text-operations-BqHmLaLA.d.ts.map +0 -1
@@ -3814,6 +3814,208 @@ function takeDeferredTextSizes(root2) {
3814
3814
  return shapes;
3815
3815
  }
3816
3816
 
3817
+ // visio/text-fields.ts
3818
+ var PROPERTY_FUNCTIONS = {
3819
+ TITLE: "title",
3820
+ SUBJECT: "subject",
3821
+ CREATOR: "creator",
3822
+ KEYWORDS: "keywords",
3823
+ DESCRIPTION: "description",
3824
+ CATEGORY: "category",
3825
+ COMPANY: "company",
3826
+ MANAGER: "manager"
3827
+ };
3828
+ var DATE_FUNCTIONS = {
3829
+ NOW: void 0,
3830
+ DOCCREATION: "created",
3831
+ DOCLASTSAVE: "modified",
3832
+ DOCLASTEDIT: "modified",
3833
+ DOCLASTPRINT: "lastPrinted"
3834
+ };
3835
+ var VISIO_FIELD_FUNCTIONS = [
3836
+ ...Object.keys(PROPERTY_FUNCTIONS),
3837
+ ...Object.keys(DATE_FUNCTIONS),
3838
+ "PAGENAME"
3839
+ ];
3840
+ function visioWallClock(date2) {
3841
+ return new Date(
3842
+ Date.UTC(
3843
+ date2.getFullYear(),
3844
+ date2.getMonth(),
3845
+ date2.getDate(),
3846
+ date2.getHours(),
3847
+ date2.getMinutes(),
3848
+ date2.getSeconds()
3849
+ )
3850
+ );
3851
+ }
3852
+ var EPOCH = Date.UTC(1899, 11, 30);
3853
+ var visioSerialDate = (serial) => Number.isFinite(serial) && Math.abs(serial) < 3e6 ? new Date(EPOCH + Math.round(serial * 864e5)) : void 0;
3854
+ function evaluateVisioTextField(formula, context) {
3855
+ let ast;
3856
+ try {
3857
+ ast = parseVisioFormula(formula, { maxLength: 4096 });
3858
+ } catch {
3859
+ return void 0;
3860
+ }
3861
+ if (ast.kind === "call") {
3862
+ const name3 = ast.name;
3863
+ if (Object.hasOwn(PROPERTY_FUNCTIONS, name3) && !ast.args.length) {
3864
+ const value = context.properties?.[PROPERTY_FUNCTIONS[name3]];
3865
+ return value === void 0 ? void 0 : { kind: "string", text: value };
3866
+ }
3867
+ if (Object.hasOwn(DATE_FUNCTIONS, name3) && !ast.args.length) {
3868
+ if (name3 === "NOW") return context.now ? { kind: "date", date: context.now } : void 0;
3869
+ const stamp = context.properties?.[DATE_FUNCTIONS[name3]];
3870
+ const time = stamp ? Date.parse(stamp) : Number.NaN;
3871
+ return Number.isFinite(time) ? { kind: "date", date: visioWallClock(new Date(time)) } : void 0;
3872
+ }
3873
+ if (name3 === "PAGENAME" && ast.args.length <= 1)
3874
+ return context.pageName === void 0 ? void 0 : { kind: "string", text: context.pageName };
3875
+ }
3876
+ try {
3877
+ const result = evaluateVisioFormula(
3878
+ ast,
3879
+ context.resolve ?? (() => {
3880
+ throw new Error("No cell context");
3881
+ }),
3882
+ {
3883
+ ...context.pageNumber === void 0 ? {} : { pageNumber: context.pageNumber },
3884
+ ...context.pageCount === void 0 ? {} : { pageCount: context.pageCount }
3885
+ }
3886
+ );
3887
+ return { kind: "number", value: result.value, unit: result.unit };
3888
+ } catch {
3889
+ return void 0;
3890
+ }
3891
+ }
3892
+ var MONTHS = [
3893
+ "January",
3894
+ "February",
3895
+ "March",
3896
+ "April",
3897
+ "May",
3898
+ "June",
3899
+ "July",
3900
+ "August",
3901
+ "September",
3902
+ "October",
3903
+ "November",
3904
+ "December"
3905
+ ];
3906
+ var DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
3907
+ var pad = (value, length = 2) => String(value).padStart(length, "0");
3908
+ function dateToken(date2, token) {
3909
+ const hours = date2.getUTCHours();
3910
+ switch (token) {
3911
+ case "yyyy":
3912
+ return pad(date2.getUTCFullYear(), 4);
3913
+ case "yy":
3914
+ return pad(date2.getUTCFullYear() % 100);
3915
+ case "MMMM":
3916
+ return MONTHS[date2.getUTCMonth()];
3917
+ case "MMM":
3918
+ return MONTHS[date2.getUTCMonth()].slice(0, 3);
3919
+ case "MM":
3920
+ return pad(date2.getUTCMonth() + 1);
3921
+ case "M":
3922
+ return String(date2.getUTCMonth() + 1);
3923
+ case "dddd":
3924
+ return DAYS[date2.getUTCDay()];
3925
+ case "ddd":
3926
+ return DAYS[date2.getUTCDay()].slice(0, 3);
3927
+ case "dd":
3928
+ return pad(date2.getUTCDate());
3929
+ case "d":
3930
+ return String(date2.getUTCDate());
3931
+ case "HH":
3932
+ return pad(hours);
3933
+ case "H":
3934
+ return String(hours);
3935
+ case "hh":
3936
+ return pad(hours % 12 || 12);
3937
+ case "h":
3938
+ return String(hours % 12 || 12);
3939
+ case "mm":
3940
+ return pad(date2.getUTCMinutes());
3941
+ case "ss":
3942
+ return pad(date2.getUTCSeconds());
3943
+ case "tt":
3944
+ return hours < 12 ? "AM" : "PM";
3945
+ default:
3946
+ return void 0;
3947
+ }
3948
+ }
3949
+ function formatDate(date2, picture) {
3950
+ return picture.replace(
3951
+ /yyyy|yy|MMMM|MMM|MM|M|dddd|ddd|dd|d|HH|H|hh|h|mm|ss|tt|"[^"]*"/g,
3952
+ (token) => {
3953
+ if (token.startsWith('"')) return token.slice(1, -1);
3954
+ return dateToken(date2, token) ?? token;
3955
+ }
3956
+ );
3957
+ }
3958
+ function formatNumber(value, picture) {
3959
+ const match = /^(#,##)?0(?:\.(0+|#+))?$/.exec(picture);
3960
+ if (!match) return void 0;
3961
+ const decimals = match[2]?.length ?? 0;
3962
+ const optional = match[2]?.startsWith("#") ?? false;
3963
+ const [coefficient, exponent = "0"] = Math.abs(value).toString().split("e");
3964
+ const shifted = Number(coefficient + "e" + (Number(exponent) + decimals));
3965
+ const rounded = Math.floor(shifted + 0.5) / 10 ** decimals;
3966
+ let text7 = (Math.sign(value) * rounded).toFixed(decimals);
3967
+ if (optional && text7.includes(".")) text7 = text7.replace(/\.?0+$/, "");
3968
+ if (match[1]) {
3969
+ const [whole, fraction] = text7.split(".");
3970
+ text7 = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (fraction ? `.${fraction}` : "");
3971
+ }
3972
+ return text7 === "-0" ? "0" : text7;
3973
+ }
3974
+ var VISIO_FIELD_FORMATS = {
3975
+ shortDate: "{{M/d/yyyy}}",
3976
+ isoDate: "{{yyyy-MM-dd}}",
3977
+ longDate: "{{dddd, MMMM d, yyyy}}",
3978
+ time: "{{h:mm tt}}",
3979
+ dateTime: "{{M/d/yyyy h:mm tt}}",
3980
+ text: "@",
3981
+ integer: "0",
3982
+ decimal: "0.00",
3983
+ decimalUnits: "0.00 u",
3984
+ integerUnits: "0 u"
3985
+ };
3986
+ function formatVisioFieldValue(value, format4 = "") {
3987
+ const picture = format4.trim();
3988
+ if (value.kind === "string") return picture === "" || picture === "@" ? value.text : void 0;
3989
+ if (value.kind === "date") {
3990
+ const date2 = /^\{\{(.+)\}\}$/.exec(picture)?.[1] ?? (picture ? void 0 : "M/d/yyyy");
3991
+ return date2 === void 0 ? void 0 : formatDate(value.date, date2);
3992
+ }
3993
+ const units2 = / u$/.test(picture);
3994
+ const body = picture.replace(/ u$/, "");
3995
+ let number5 = value.value, suffix = "";
3996
+ if (value.unit === "angle") {
3997
+ number5 = number5 * 180 / Math.PI;
3998
+ suffix = " deg.";
3999
+ } else if (value.unit === "length") suffix = " in.";
4000
+ else if (value.unit !== "scalar") return void 0;
4001
+ const text7 = body === "" || body === "@" ? String(Number(number5.toFixed(4))) : formatNumber(Number(number5.toFixed(10)), body);
4002
+ if (text7 === void 0) return void 0;
4003
+ return units2 || body === "" ? `${text7}${suffix}` : text7;
4004
+ }
4005
+
4006
+ // visio/text-field-independent.ts
4007
+ function independentTextFieldFormula(cell, formula) {
4008
+ const row2 = cell.parentNode, section3 = row2?.parentNode;
4009
+ 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"))
4010
+ return false;
4011
+ if (attribute2(cell, "N") === "Format")
4012
+ return /^\s*FIELDPICTURE\(\s*(2|37|204)\s*\)\s*$/i.test(formula);
4013
+ if (attribute2(cell, "N") !== "Value") return false;
4014
+ if (/^\s*DATE\(\s*\d{1,4}\s*,\s*\d{1,2}\s*,\s*\d{1,2}\s*\)\s*$/i.test(formula)) return true;
4015
+ const direct = /^\s*([A-Z]+)\(\s*\)\s*$/i.exec(formula)?.[1]?.toUpperCase();
4016
+ return direct !== void 0 && VISIO_FIELD_FUNCTIONS.includes(direct);
4017
+ }
4018
+
3817
4019
  // visio/edit-connector-glue.ts
3818
4020
  var VISIO_WALK_GLUE = "_WALKGLUE(BegTrigger,EndTrigger,WalkPreference)";
3819
4021
  var walkGlue = /^\s*_WALKGLUE\((?:BegTrigger,EndTrigger|EndTrigger,BegTrigger),WalkPreference\)\s*$/i;
@@ -3923,7 +4125,7 @@ function indexCells(roots2, options) {
3923
4125
  unit: cellUnit(cell, relative)
3924
4126
  };
3925
4127
  const source = attribute2(node2, "F");
3926
- 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
4128
+ 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
3927
4129
  // (Visio's freshly dropped connector names its own sheet).
3928
4130
  !(/^(BegTrigger|EndTrigger)$/.test(cell) && isNativeGlueCell(cell, source))) {
3929
4131
  try {
@@ -9760,6 +9962,77 @@ async function prepareImages(shapes, pkg, sourcePart, report, options, converter
9760
9962
  }
9761
9963
  }
9762
9964
 
9965
+ // visio/text-field-source.ts
9966
+ var proofs = /* @__PURE__ */ new WeakMap();
9967
+ function textFieldSourceKey(cells4) {
9968
+ if (proofs.has(cells4)) return proofs.get(cells4);
9969
+ if (cells4.size > 64) {
9970
+ proofs.set(cells4, void 0);
9971
+ return void 0;
9972
+ }
9973
+ const key2 = JSON.stringify(
9974
+ [...cells4].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name3, cell]) => [
9975
+ name3,
9976
+ cell.value ?? null,
9977
+ cell.formula ?? null,
9978
+ cell.unit ?? null,
9979
+ cell.error ?? null
9980
+ ])
9981
+ );
9982
+ const bounded6 = key2.length <= 2048 ? key2 : void 0;
9983
+ proofs.set(cells4, bounded6);
9984
+ return bounded6;
9985
+ }
9986
+
9987
+ // visio/text-field-editability.ts
9988
+ function assertEditableFieldRow(existing) {
9989
+ for (const name3 of ["Calendar", "ObjectKind"]) {
9990
+ const cell = children2(existing, "Cell").find((cell2) => attribute2(cell2, "N") === name3);
9991
+ if (cell && (attribute2(cell, "V") !== "0" || cell.hasAttribute("F") || cell.hasAttribute("E")))
9992
+ fail(
9993
+ "UNSUPPORTED_TEXT_FIELD",
9994
+ "Nonstandard field calendar or object profiles cannot be edited."
9995
+ );
9996
+ }
9997
+ for (const cell of children2(existing, "Cell")) {
9998
+ const name3 = attribute2(cell, "N") ?? "";
9999
+ if (/^(value|format|type|calendar|objectkind)$/i.test(name3) && !["Value", "Format", "Type", "Calendar", "ObjectKind"].includes(name3))
10000
+ fail("UNSUPPORTED_TEXT_FIELD", "Noncanonical field cell names cannot be edited.");
10001
+ if (["Value", "Format", "Type"].includes(attribute2(cell, "N") ?? "") && (cell.hasAttribute("E") || /^\s*(Inh|GUARD\s*\()/i.test(attribute2(cell, "F") ?? "")))
10002
+ fail("UNSUPPORTED_TEXT_FIELD", "Protected or inherited field cells cannot be edited.");
10003
+ }
10004
+ }
10005
+ function assertEditableFieldShape(shape) {
10006
+ 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))
10007
+ fail("UNSUPPORTED_TEXT_FIELD", "Existing field edits require a top-level plain local shape.");
10008
+ }
10009
+ function editableTextFieldIndices(text7, allowed) {
10010
+ const result = /* @__PURE__ */ new Set();
10011
+ if (!allowed || !text7) return result;
10012
+ const shape = text7.parentNode;
10013
+ try {
10014
+ assertEditableFieldShape(shape);
10015
+ assertFormattingText(shape);
10016
+ const rows = formattingRows(shape, "Field");
10017
+ const markers = children2(text7, "fld");
10018
+ const counts = /* @__PURE__ */ new Map();
10019
+ for (const marker2 of markers) {
10020
+ const index = attribute2(marker2, "IX");
10021
+ counts.set(index, (counts.get(index) ?? 0) + 1);
10022
+ }
10023
+ for (const [index, row2] of rows) {
10024
+ if (counts.get(index) !== 1 || textFieldSourceKey(readCells(row2)) === void 0) continue;
10025
+ try {
10026
+ assertEditableFieldRow(row2);
10027
+ result.add(index);
10028
+ } catch {
10029
+ }
10030
+ }
10031
+ } catch {
10032
+ }
10033
+ return result;
10034
+ }
10035
+
9763
10036
  // geometry/svg-path-curves.ts
9764
10037
  function sampleCubic(p0, p1, p2, p3, segments, out) {
9765
10038
  for (let i = 1; i <= segments; i++) {
@@ -12175,195 +12448,6 @@ function visioFieldCase(text7, upper) {
12175
12448
  }).join("");
12176
12449
  }
12177
12450
 
12178
- // visio/text-fields.ts
12179
- var PROPERTY_FUNCTIONS = {
12180
- TITLE: "title",
12181
- SUBJECT: "subject",
12182
- CREATOR: "creator",
12183
- KEYWORDS: "keywords",
12184
- DESCRIPTION: "description",
12185
- CATEGORY: "category",
12186
- COMPANY: "company",
12187
- MANAGER: "manager"
12188
- };
12189
- var DATE_FUNCTIONS = {
12190
- NOW: void 0,
12191
- DOCCREATION: "created",
12192
- DOCLASTSAVE: "modified",
12193
- DOCLASTEDIT: "modified",
12194
- DOCLASTPRINT: "lastPrinted"
12195
- };
12196
- var VISIO_FIELD_FUNCTIONS = [
12197
- ...Object.keys(PROPERTY_FUNCTIONS),
12198
- ...Object.keys(DATE_FUNCTIONS),
12199
- "PAGENAME"
12200
- ];
12201
- function visioWallClock(date2) {
12202
- return new Date(
12203
- Date.UTC(
12204
- date2.getFullYear(),
12205
- date2.getMonth(),
12206
- date2.getDate(),
12207
- date2.getHours(),
12208
- date2.getMinutes(),
12209
- date2.getSeconds()
12210
- )
12211
- );
12212
- }
12213
- var EPOCH = Date.UTC(1899, 11, 30);
12214
- var visioSerialDate = (serial) => Number.isFinite(serial) && Math.abs(serial) < 3e6 ? new Date(EPOCH + Math.round(serial * 864e5)) : void 0;
12215
- function evaluateVisioTextField(formula, context) {
12216
- let ast;
12217
- try {
12218
- ast = parseVisioFormula(formula, { maxLength: 4096 });
12219
- } catch {
12220
- return void 0;
12221
- }
12222
- if (ast.kind === "call") {
12223
- const name3 = ast.name;
12224
- if (Object.hasOwn(PROPERTY_FUNCTIONS, name3) && !ast.args.length) {
12225
- const value = context.properties?.[PROPERTY_FUNCTIONS[name3]];
12226
- return value === void 0 ? void 0 : { kind: "string", text: value };
12227
- }
12228
- if (Object.hasOwn(DATE_FUNCTIONS, name3) && !ast.args.length) {
12229
- if (name3 === "NOW") return context.now ? { kind: "date", date: context.now } : void 0;
12230
- const stamp = context.properties?.[DATE_FUNCTIONS[name3]];
12231
- const time = stamp ? Date.parse(stamp) : Number.NaN;
12232
- return Number.isFinite(time) ? { kind: "date", date: visioWallClock(new Date(time)) } : void 0;
12233
- }
12234
- if (name3 === "PAGENAME" && ast.args.length <= 1)
12235
- return context.pageName === void 0 ? void 0 : { kind: "string", text: context.pageName };
12236
- }
12237
- try {
12238
- const result = evaluateVisioFormula(
12239
- ast,
12240
- context.resolve ?? (() => {
12241
- throw new Error("No cell context");
12242
- }),
12243
- {
12244
- ...context.pageNumber === void 0 ? {} : { pageNumber: context.pageNumber },
12245
- ...context.pageCount === void 0 ? {} : { pageCount: context.pageCount }
12246
- }
12247
- );
12248
- return { kind: "number", value: result.value, unit: result.unit };
12249
- } catch {
12250
- return void 0;
12251
- }
12252
- }
12253
- var MONTHS = [
12254
- "January",
12255
- "February",
12256
- "March",
12257
- "April",
12258
- "May",
12259
- "June",
12260
- "July",
12261
- "August",
12262
- "September",
12263
- "October",
12264
- "November",
12265
- "December"
12266
- ];
12267
- var DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
12268
- var pad = (value, length = 2) => String(value).padStart(length, "0");
12269
- function dateToken(date2, token) {
12270
- const hours = date2.getUTCHours();
12271
- switch (token) {
12272
- case "yyyy":
12273
- return pad(date2.getUTCFullYear(), 4);
12274
- case "yy":
12275
- return pad(date2.getUTCFullYear() % 100);
12276
- case "MMMM":
12277
- return MONTHS[date2.getUTCMonth()];
12278
- case "MMM":
12279
- return MONTHS[date2.getUTCMonth()].slice(0, 3);
12280
- case "MM":
12281
- return pad(date2.getUTCMonth() + 1);
12282
- case "M":
12283
- return String(date2.getUTCMonth() + 1);
12284
- case "dddd":
12285
- return DAYS[date2.getUTCDay()];
12286
- case "ddd":
12287
- return DAYS[date2.getUTCDay()].slice(0, 3);
12288
- case "dd":
12289
- return pad(date2.getUTCDate());
12290
- case "d":
12291
- return String(date2.getUTCDate());
12292
- case "HH":
12293
- return pad(hours);
12294
- case "H":
12295
- return String(hours);
12296
- case "hh":
12297
- return pad(hours % 12 || 12);
12298
- case "h":
12299
- return String(hours % 12 || 12);
12300
- case "mm":
12301
- return pad(date2.getUTCMinutes());
12302
- case "ss":
12303
- return pad(date2.getUTCSeconds());
12304
- case "tt":
12305
- return hours < 12 ? "AM" : "PM";
12306
- default:
12307
- return void 0;
12308
- }
12309
- }
12310
- function formatDate(date2, picture) {
12311
- return picture.replace(
12312
- /yyyy|yy|MMMM|MMM|MM|M|dddd|ddd|dd|d|HH|H|hh|h|mm|ss|tt|"[^"]*"/g,
12313
- (token) => {
12314
- if (token.startsWith('"')) return token.slice(1, -1);
12315
- return dateToken(date2, token) ?? token;
12316
- }
12317
- );
12318
- }
12319
- function formatNumber(value, picture) {
12320
- const match = /^(#,##)?0(?:\.(0+|#+))?$/.exec(picture);
12321
- if (!match) return void 0;
12322
- const decimals = match[2]?.length ?? 0;
12323
- const optional = match[2]?.startsWith("#") ?? false;
12324
- const [coefficient, exponent = "0"] = Math.abs(value).toString().split("e");
12325
- const shifted = Number(coefficient + "e" + (Number(exponent) + decimals));
12326
- const rounded = Math.floor(shifted + 0.5) / 10 ** decimals;
12327
- let text7 = (Math.sign(value) * rounded).toFixed(decimals);
12328
- if (optional && text7.includes(".")) text7 = text7.replace(/\.?0+$/, "");
12329
- if (match[1]) {
12330
- const [whole, fraction] = text7.split(".");
12331
- text7 = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (fraction ? `.${fraction}` : "");
12332
- }
12333
- return text7 === "-0" ? "0" : text7;
12334
- }
12335
- var VISIO_FIELD_FORMATS = {
12336
- shortDate: "{{M/d/yyyy}}",
12337
- isoDate: "{{yyyy-MM-dd}}",
12338
- longDate: "{{dddd, MMMM d, yyyy}}",
12339
- time: "{{h:mm tt}}",
12340
- dateTime: "{{M/d/yyyy h:mm tt}}",
12341
- text: "@",
12342
- integer: "0",
12343
- decimal: "0.00",
12344
- decimalUnits: "0.00 u",
12345
- integerUnits: "0 u"
12346
- };
12347
- function formatVisioFieldValue(value, format4 = "") {
12348
- const picture = format4.trim();
12349
- if (value.kind === "string") return picture === "" || picture === "@" ? value.text : void 0;
12350
- if (value.kind === "date") {
12351
- const date2 = /^\{\{(.+)\}\}$/.exec(picture)?.[1] ?? (picture ? void 0 : "M/d/yyyy");
12352
- return date2 === void 0 ? void 0 : formatDate(value.date, date2);
12353
- }
12354
- const units2 = / u$/.test(picture);
12355
- const body = picture.replace(/ u$/, "");
12356
- let number5 = value.value, suffix = "";
12357
- if (value.unit === "angle") {
12358
- number5 = number5 * 180 / Math.PI;
12359
- suffix = " deg.";
12360
- } else if (value.unit === "length") suffix = " in.";
12361
- else if (value.unit !== "scalar") return void 0;
12362
- const text7 = body === "" || body === "@" ? String(Number(number5.toFixed(4))) : formatNumber(Number(number5.toFixed(10)), body);
12363
- if (text7 === void 0) return void 0;
12364
- return units2 || body === "" ? `${text7}${suffix}` : text7;
12365
- }
12366
-
12367
12451
  // visio/text-field-fraction.ts
12368
12452
  function fractionalFieldNumber(value, maxDenominator) {
12369
12453
  if (!Number.isFinite(value) || Math.abs(value) > 1e15) return void 0;
@@ -12520,7 +12604,12 @@ function textFieldDisplay(element2, sheet, context) {
12520
12604
  const row2 = sectionRows(sheet, "Field").find((candidate) => candidate.index === index);
12521
12605
  const value = row2?.cells.get("Value"), format4 = row2?.cells.get("Format");
12522
12606
  const formula = value?.formula && value.formula !== "Inh" ? value.formula : void 0;
12523
- const result = { cached: cached5, ...formula ? { formula } : {} };
12607
+ const sourceKey = row2 ? textFieldSourceKey(row2.cells) : void 0;
12608
+ const result = {
12609
+ cached: cached5,
12610
+ ...formula ? { formula } : {},
12611
+ ...sourceKey !== void 0 ? { index, format: format4?.value ?? "", sourceKey } : {}
12612
+ };
12524
12613
  if (!row2 || !context) return { text: cached5, ...result };
12525
12614
  const picture = format4?.value ?? "";
12526
12615
  const evaluated = formula ? evaluateVisioTextField(formula, context) : void 0;
@@ -13305,7 +13394,8 @@ function runStyle(cells4, resources, report, themeCells) {
13305
13394
  ...characterExtras(cells4, report)
13306
13395
  };
13307
13396
  }
13308
- function shapeText(sheet, node2, width, height, resources, report, consume, consumeParagraph) {
13397
+ function shapeText(sheet, node2, width, height, resources, report, consume, consumeParagraph, allowFieldEditing = false) {
13398
+ const editableFields = editableTextFieldIndices(node2, allowFieldEditing);
13309
13399
  const cells4 = sheet.cells;
13310
13400
  const characters = new Map(sectionRows(sheet, "Character").map((row2) => [row2.index, row2.cells]));
13311
13401
  const defaultCells = characters.get("0") ?? /* @__PURE__ */ new Map();
@@ -13340,7 +13430,9 @@ function shapeText(sheet, node2, width, height, resources, report, consume, cons
13340
13430
  start: textOffset,
13341
13431
  end: textOffset + field3.text.length,
13342
13432
  cached: field3.cached,
13343
- ...field3.formula ? { formula: field3.formula } : {}
13433
+ ...field3.index !== void 0 && editableFields.has(field3.index) ? { editable: true } : {},
13434
+ ...field3.formula ? { formula: field3.formula } : {},
13435
+ ...field3.index === void 0 ? {} : { index: field3.index, format: field3.format, sourceKey: field3.sourceKey }
13344
13436
  });
13345
13437
  append(field3.text);
13346
13438
  } else if (element2.localName !== "pp" && element2.localName !== "tp") {
@@ -14381,7 +14473,8 @@ function normalizeShapes(raw, context, depth = 0, masterStack = []) {
14381
14473
  context.resources,
14382
14474
  report,
14383
14475
  context.consumeText,
14384
- context.consumeParagraph
14476
+ context.consumeParagraph,
14477
+ depth === 0 && masterId === void 0 && !sheet.cells.get("LockTextEdit")?.error && !sheet.cells.get("LockTextEdit")?.formula && number(sheet.cells, "LockTextEdit", 0, report) === 0
14385
14478
  ),
14386
14479
  hidden: membership.hidden || type === "Guide" || number(sheet.cells, "NoShow", 0, report) !== 0,
14387
14480
  visibility: {
@@ -14572,6 +14665,177 @@ function readVisioPageSetup(cells4) {
14572
14665
  return Object.keys(result).length ? result : void 0;
14573
14666
  }
14574
14667
 
14668
+ // visio/print-settings.ts
14669
+ var NAMES2 = [
14670
+ "PaperKind",
14671
+ "PrintPageOrientation",
14672
+ "PageLeftMargin",
14673
+ "PageRightMargin",
14674
+ "PageTopMargin",
14675
+ "PageBottomMargin",
14676
+ "ScaleX",
14677
+ "ScaleY",
14678
+ "OnPage",
14679
+ "PagesX",
14680
+ "PagesY",
14681
+ "CenterX",
14682
+ "CenterY"
14683
+ ];
14684
+ var BOOLEAN = /* @__PURE__ */ new Set(["OnPage", "CenterX", "CenterY"]);
14685
+ var LENGTH = /* @__PURE__ */ new Set(["PageLeftMargin", "PageRightMargin", "PageTopMargin", "PageBottomMargin"]);
14686
+ var CANONICAL = new Map(
14687
+ [...NAMES2, "PageWidth", "PageHeight", "PageScale", "DrawingScale"].map((name3) => [
14688
+ name3.toLowerCase(),
14689
+ name3
14690
+ ])
14691
+ );
14692
+ function indexCells2(sheet) {
14693
+ const cells4 = /* @__PURE__ */ new Map();
14694
+ let duplicate = false;
14695
+ for (const node2 of children2(sheet, "Cell")) {
14696
+ const name3 = attribute2(node2, "N") ?? "", canonical2 = CANONICAL.get(name3.toLowerCase());
14697
+ if (!canonical2) continue;
14698
+ if (canonical2 !== name3) duplicate = true;
14699
+ const values = cells4.get(canonical2) ?? [];
14700
+ if (values.length < 2) values.push(node2);
14701
+ cells4.set(canonical2, values);
14702
+ if (values.length > 1) duplicate = true;
14703
+ }
14704
+ return { cells: cells4, duplicate };
14705
+ }
14706
+ function createVisioPrintSettingsReader(documentSheets, rootStyles) {
14707
+ const indexes = { document: indexCells2(documentSheets[0]), root: indexCells2(rootStyles[0]) };
14708
+ return (pageSheets) => readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes);
14709
+ }
14710
+ function readVisioPrintCountSettings(pageSheets, documentSheets, rootStyles, indexes) {
14711
+ let refusal;
14712
+ const refuse4 = (reason) => {
14713
+ refusal ??= reason;
14714
+ };
14715
+ if (pageSheets.length !== 1) refuse4("ambiguous-page-sheet");
14716
+ if (documentSheets.length > 1) refuse4("ambiguous-document-sheet");
14717
+ if (!documentSheets.length) refuse4("missing-setting");
14718
+ if (rootStyles.length > 1) refuse4("duplicate-setting");
14719
+ const root2 = rootStyles[0];
14720
+ if (!root2 || attribute2(root2, "ID") !== "0" || attribute2(root2, "NameU") !== "No Style")
14721
+ refuse4("unsupported-print-style");
14722
+ for (const sheet of [...pageSheets, ...documentSheets])
14723
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
14724
+ if (attribute2(sheet, name3) !== "0") refuse4("unsupported-print-style");
14725
+ for (const name3 of ["LineStyle", "FillStyle", "TextStyle"])
14726
+ if (attribute2(root2, name3) !== void 0) refuse4("unsupported-print-style");
14727
+ const localIndex = indexCells2(pageSheets[0]), rootIndex = indexes?.root ?? indexCells2(root2);
14728
+ const documentIndex = indexes?.document ?? indexCells2(documentSheets[0]);
14729
+ if (localIndex.duplicate || rootIndex.duplicate || documentIndex.duplicate)
14730
+ refuse4("duplicate-setting");
14731
+ const local = localIndex.cells, inherited = rootIndex.cells;
14732
+ const read = (node2, name3, origin) => {
14733
+ const invalid5 = () => {
14734
+ refuse4(origin === "local" ? "invalid-local-setting" : "invalid-document-setting");
14735
+ return void 0;
14736
+ };
14737
+ if (node2.hasAttribute("E")) return invalid5();
14738
+ let raw = (attribute2(node2, "V") ?? "").trim();
14739
+ if (!raw || raw.length > 128) return invalid5();
14740
+ if (BOOLEAN.has(name3)) {
14741
+ if (!["0", "1", "false", "true"].includes(raw)) return invalid5();
14742
+ raw = raw === "true" ? "1" : raw === "false" ? "0" : raw;
14743
+ }
14744
+ try {
14745
+ const value = visioFormulaCachedValue(raw, attribute2(node2, "U"));
14746
+ const length = LENGTH.has(name3) || /^(PageWidth|PageHeight|PageScale|DrawingScale)$/.test(name3);
14747
+ if (!["scalar", ...length ? ["length"] : []].includes(value.unit) || Math.abs(value.value) > 1e9)
14748
+ return invalid5();
14749
+ const formula = attribute2(node2, "F");
14750
+ if (formula !== void 0) {
14751
+ const source = formula.trim();
14752
+ if (/^(true|false)$/i.test(source)) {
14753
+ if ((source.toLowerCase() === "true" ? 1 : 0) !== value.value) return invalid5();
14754
+ } else {
14755
+ if (!source || source === "Inh") return invalid5();
14756
+ const limits = { maxLength: 512, maxNodes: 64, maxDepth: 16, maxSteps: 128 };
14757
+ const analysis = analyzeVisioFormula(source, limits);
14758
+ if (analysis.dynamic || analysis.guarded || analysis.references.length || analysis.unsupportedFunctions.length) {
14759
+ refuse4("dynamic-setting");
14760
+ return void 0;
14761
+ }
14762
+ const evaluated = evaluateVisioFormula(
14763
+ source,
14764
+ () => {
14765
+ throw new Error("Unexpected reference");
14766
+ },
14767
+ limits
14768
+ );
14769
+ if (evaluated.value !== value.value || !["scalar", ...length ? ["length"] : []].includes(evaluated.unit))
14770
+ return invalid5();
14771
+ }
14772
+ }
14773
+ return value.value;
14774
+ } catch {
14775
+ return invalid5();
14776
+ }
14777
+ };
14778
+ const values = /* @__PURE__ */ new Map();
14779
+ for (const name3 of NAMES2) {
14780
+ const nodes = local.get(name3) ?? inherited.get(name3);
14781
+ if (!nodes?.length) continue;
14782
+ if (nodes.length !== 1) continue;
14783
+ const value = read(nodes[0], name3, local.has(name3) ? "local" : "document");
14784
+ if (value !== void 0) values.set(name3, value);
14785
+ }
14786
+ for (const name3 of ["PageWidth", "PageHeight", "PageScale", "DrawingScale"]) {
14787
+ const nodes = local.get(name3);
14788
+ if (!nodes || nodes.length !== 1 || !(read(nodes[0], name3, "local") > 0))
14789
+ refuse4("unusable-drawing-scale");
14790
+ }
14791
+ const setup = {};
14792
+ const paper = values.get("PaperKind");
14793
+ if (paper !== void 0 && Number.isSafeInteger(paper) && paper >= 0 && paper <= 65535)
14794
+ setup.paperKind = paper;
14795
+ else if (paper !== void 0)
14796
+ refuse4(local.has("PaperKind") ? "invalid-local-setting" : "invalid-document-setting");
14797
+ const orientation = values.get("PrintPageOrientation");
14798
+ if (orientation === 0 || orientation === 1 || orientation === 2)
14799
+ setup.printPageOrientation = orientation;
14800
+ else if (orientation !== void 0)
14801
+ refuse4(
14802
+ local.has("PrintPageOrientation") ? "invalid-local-setting" : "invalid-document-setting"
14803
+ );
14804
+ const margins = ["Left", "Right", "Top", "Bottom"].map((side2) => values.get(`Page${side2}Margin`));
14805
+ if (margins.every((n) => n !== void 0 && n >= 0 && n <= 1e3))
14806
+ setup.margins = {
14807
+ left: margins[0],
14808
+ right: margins[1],
14809
+ top: margins[2],
14810
+ bottom: margins[3]
14811
+ };
14812
+ else if (margins.some((n) => n !== void 0 && (n < 0 || n > 1e3)))
14813
+ refuse4("unusable-print-area");
14814
+ for (const [name3, key2] of [
14815
+ ["ScaleX", "printZoom"],
14816
+ ["ScaleY", "printZoomY"],
14817
+ ["PagesX", "printPagesAcross"],
14818
+ ["PagesY", "printPagesDown"]
14819
+ ]) {
14820
+ const value = values.get(name3);
14821
+ if (value !== void 0) {
14822
+ if ((name3 === "PagesX" || name3 === "PagesY") && (!Number.isSafeInteger(value) || value < 1))
14823
+ refuse4(local.has(name3) ? "invalid-local-setting" : "invalid-document-setting");
14824
+ else setup[key2] = value;
14825
+ }
14826
+ }
14827
+ for (const [name3, key2] of [
14828
+ ["OnPage", "printFitToPages"],
14829
+ ["CenterX", "printCenterX"],
14830
+ ["CenterY", "printCenterY"]
14831
+ ]) {
14832
+ const value = values.get(name3);
14833
+ if (value !== void 0) setup[key2] = value === 1;
14834
+ }
14835
+ if (refusal) setup.printCountRefusal = refusal;
14836
+ return setup;
14837
+ }
14838
+
14575
14839
  // visio/master-list.ts
14576
14840
  var MAX_LISTED_MASTERS = 500;
14577
14841
  var PREVIEW_SHAPES = 5e3;
@@ -15173,6 +15437,11 @@ async function parseVsdx(input, options = {}) {
15173
15437
  });
15174
15438
  const rootStyle = styles.get("0");
15175
15439
  if (rootStyle?.attributes.get("NameU") === "No Style") resources.rootSheet = rootStyle.sheet;
15440
+ const printStyleGroups = children2(documentRoot, "StyleSheets");
15441
+ const readPrintSettings = createVisioPrintSettingsReader(
15442
+ children2(documentRoot, "DocumentSheet"),
15443
+ printStyleGroups.length === 1 ? children2(printStyleGroups[0], "StyleSheet").filter((node2) => attribute2(node2, "ID") === "0") : []
15444
+ );
15176
15445
  const masters = /* @__PURE__ */ new Map();
15177
15446
  const masterRecords = [];
15178
15447
  const mastersPart = await related(pkg, documentPart2, "masters", false);
@@ -15336,7 +15605,17 @@ async function parseVsdx(input, options = {}) {
15336
15605
  const value = number(sheet.cells, name3, Number.NaN, localReport);
15337
15606
  if (Number.isSafeInteger(value) && value >= 0 && value <= 255) pageModes[key2] = value;
15338
15607
  }
15339
- const pageSetup = readVisioPageSetup(sheet.cells);
15608
+ const { paperKind, printPageOrientation, margins, printZoom, ...countMetadata } = readPrintSettings(children2(page, "PageSheet"));
15609
+ const pageSetup = {
15610
+ ...readVisioPageSetup(sheet.cells),
15611
+ ...countMetadata,
15612
+ printCountSettings: {
15613
+ ...paperKind === void 0 ? {} : { paperKind },
15614
+ ...printPageOrientation === void 0 ? {} : { printPageOrientation },
15615
+ ...margins === void 0 ? {} : { margins },
15616
+ ...printZoom === void 0 ? {} : { printZoom }
15617
+ }
15618
+ };
15340
15619
  const layout = readVisioPageLayout(sheet.cells);
15341
15620
  for (const connection of connectors)
15342
15621
  if (!seen.has(connection.fromShapeId) || !seen.has(connection.toShapeId))
@@ -15435,15 +15714,19 @@ var VISIO_PAPER_SIZES = Object.freeze([
15435
15714
  function visioPaperSize(paperKind) {
15436
15715
  return VISIO_PAPER_SIZES.find((item) => item.paperKind === paperKind);
15437
15716
  }
15717
+ function visioOrientedPaperSize(paper, landscape) {
15718
+ const short = Math.min(paper.width, paper.height), long = Math.max(paper.width, paper.height);
15719
+ return { width: landscape ? long : short, height: landscape ? short : long };
15720
+ }
15438
15721
  function visioPrintTile(page, paper = page.pageSetup?.paperKind === void 0 ? void 0 : visioPaperSize(page.pageSetup.paperKind)) {
15439
15722
  if (!paper) return void 0;
15440
15723
  const setup = page.pageSetup;
15441
15724
  const landscape = setup?.printPageOrientation === 2 || setup?.printPageOrientation !== 1 && page.width > page.height;
15442
- const short = Math.min(paper.width, paper.height), long = Math.max(paper.width, paper.height);
15725
+ const oriented = visioOrientedPaperSize(paper, landscape);
15443
15726
  const margins = setup?.margins ?? { left: 0, right: 0, top: 0, bottom: 0 };
15444
15727
  const zoom = setup?.printZoom ?? 1;
15445
- const width = ((landscape ? long : short) - margins.left - margins.right) / zoom;
15446
- const height = ((landscape ? short : long) - margins.top - margins.bottom) / zoom;
15728
+ const width = (oriented.width - margins.left - margins.right) / zoom;
15729
+ const height = (oriented.height - margins.top - margins.bottom) / zoom;
15447
15730
  return width > 0.01 && height > 0.01 ? { width, height } : void 0;
15448
15731
  }
15449
15732
 
@@ -16101,6 +16384,35 @@ function snapshotGuideEdit(edit) {
16101
16384
  }
16102
16385
 
16103
16386
  // visio/edit-text-field-commands.ts
16387
+ function snapshotTextFieldUpdate(edit) {
16388
+ const insert = snapshotTextFieldInsert({
16389
+ pageId: edit.pageId,
16390
+ shapeId: edit.shapeId,
16391
+ formula: edit.formula,
16392
+ ...edit.format === void 0 ? {} : { format: edit.format }
16393
+ });
16394
+ if (analyzeVisioFormula(parseVisioFormula(insert.formula)).references.some(
16395
+ (ref) => /^fields?\./i.test(ref.cell)
16396
+ ))
16397
+ fail("UNSUPPORTED_TEXT_FIELD", "Existing field formulas cannot reference Field rows.");
16398
+ if (typeof edit.fieldIndex !== "string" || !/^(0|[1-9]\d{0,9})$/.test(edit.fieldIndex) || Number(edit.fieldIndex) > 4294967295)
16399
+ fail("INVALID_EDIT", "An existing field needs a canonical row index.");
16400
+ if ([edit.expectedText, edit.expectedCached, edit.expectedSourceKey].some(
16401
+ (value) => typeof value !== "string" || value.length > 1e6
16402
+ ) || !edit.expectedSourceKey)
16403
+ fail("INVALID_EDIT", "An existing field needs its source text and row identity.");
16404
+ return {
16405
+ type: "update-text-field",
16406
+ pageId: insert.pageId,
16407
+ shapeId: insert.shapeId,
16408
+ fieldIndex: edit.fieldIndex,
16409
+ formula: insert.formula,
16410
+ format: insert.format,
16411
+ expectedText: edit.expectedText,
16412
+ expectedCached: edit.expectedCached,
16413
+ expectedSourceKey: edit.expectedSourceKey
16414
+ };
16415
+ }
16104
16416
  function snapshotTextFieldInsert(edit) {
16105
16417
  const { pageId: pageId2, shapeId: shapeId2 } = edit;
16106
16418
  if ([pageId2, shapeId2].some((id3) => typeof id3 !== "string" || !id3 || id3.length > 256))
@@ -16835,6 +17147,14 @@ function snapshotVisioEdits(edits, maxEdits, maxText) {
16835
17147
  return { ...target2, type: edit.type, text: text7(edit.text) };
16836
17148
  if (edit.type === "replace-text-ranges") return snapshotTextRanges(edit, text7);
16837
17149
  if (edit.type === "insert-text-field") return snapshotTextFieldInsert(edit);
17150
+ if (edit.type === "update-text-field") {
17151
+ const update = snapshotTextFieldUpdate(edit);
17152
+ update.formula = text7(update.formula);
17153
+ update.expectedText = text7(update.expectedText);
17154
+ update.expectedCached = text7(update.expectedCached);
17155
+ update.expectedSourceKey = text7(update.expectedSourceKey);
17156
+ return update;
17157
+ }
16838
17158
  if (isVisioFormatEdit(edit)) return snapshotFormatting(edit);
16839
17159
  if (edit.type === "reorder-shape") {
16840
17160
  if (!["front", "back", "forward", "backward"].includes(edit.order))
@@ -17042,6 +17362,8 @@ function snapshotEdits(edits) {
17042
17362
  return snapshotTextRanges(command2, text7);
17043
17363
  case "insert-text-field":
17044
17364
  return snapshotTextFieldInsert(command2);
17365
+ case "update-text-field":
17366
+ return snapshotTextFieldUpdate(command2);
17045
17367
  case "delete-shape":
17046
17368
  return { type: command2.type, ...target2 };
17047
17369
  case "rotate-shape":
@@ -17687,6 +18009,7 @@ async function assertFormattingDependencies(pkg, pagePaths, roots2, pageId2, sha
17687
18009
  continue;
17688
18010
  const source = executableCellFormula(attribute2(node2, "F"));
17689
18011
  if (!source || inertDoubleClickFormula(attribute2(node2, "N") ?? "", source)) continue;
18012
+ if (independentTextFieldFormula(node2, source)) continue;
17690
18013
  if (attribute2(node2, "V") === "Themed" && isThemeLookupFormula(source)) continue;
17691
18014
  if (isConnectedGlueCell(node2, source)) continue;
17692
18015
  const owner = node2.parentNode;
@@ -21496,9 +21819,23 @@ async function insertVisioTextField(pkg, pagePaths, roots2, document, edit, chec
21496
21819
  effectiveFormattingRows(shape, document, "Paragraph")
21497
21820
  );
21498
21821
  const rows = formattingRows(shape, "Field");
21499
- const point2 = insertionPoint(text7, edit.offset);
21500
- if (edit.offset !== void 0 && point2.logical !== edit.expectedText)
21822
+ const updating = edit.type === "update-text-field";
21823
+ if (updating) assertEditableFieldShape(shape);
21824
+ const point2 = insertionPoint(text7, updating ? void 0 : edit.offset);
21825
+ if ((updating || edit.offset !== void 0) && point2.logical !== edit.expectedText)
21501
21826
  fail("EDIT_STALE_TEXT", "The shape text changed since the field position was chosen.");
21827
+ const existing = updating ? rows.get(edit.fieldIndex) : void 0;
21828
+ const markers = updating ? children2(text7, "fld").filter((field4) => attribute2(field4, "IX") === edit.fieldIndex) : [];
21829
+ if (updating) {
21830
+ if (!existing || markers.length !== 1)
21831
+ fail(
21832
+ "UNSUPPORTED_TEXT_FIELD",
21833
+ "Existing fields require one live local row and unique text marker."
21834
+ );
21835
+ if (markers[0].textContent !== edit.expectedCached || textFieldSourceKey(readCells(existing)) !== edit.expectedSourceKey)
21836
+ fail("EDIT_STALE_TEXT", "The field source changed since it was selected.");
21837
+ assertEditableFieldRow(existing);
21838
+ }
21502
21839
  const context = { ...await pageContext(pkg, edit.pageId), resolve: shapeResolver(shape) };
21503
21840
  let value;
21504
21841
  try {
@@ -21511,9 +21848,19 @@ async function insertVisioTextField(pkg, pagePaths, roots2, document, edit, chec
21511
21848
  "UNSUPPORTED_TEXT_FIELD",
21512
21849
  `This editor cannot evaluate the field formula. Supported: ${VISIO_FIELD_FUNCTIONS.join(", ")}, PAGENUMBER, PAGECOUNT and numeric formulas on this shape.`
21513
21850
  );
21514
- const display = formatVisioFieldValue(value, edit.format ?? "");
21851
+ const format4 = edit.format ?? "";
21852
+ const display = formatVisioFieldValue(value, format4);
21515
21853
  if (display === void 0)
21516
21854
  fail("UNSUPPORTED_TEXT_FIELD", "The field format does not suit the field value.");
21855
+ const prepared = valueCell(value);
21856
+ if (existing && markers[0].textContent === display) {
21857
+ const same5 = (name3, v, u, f) => {
21858
+ const cell2 = children2(existing, "Cell").find((cell3) => attribute2(cell3, "N") === name3);
21859
+ return attribute2(cell2, "V") === v && attribute2(cell2, "U") === u && attribute2(cell2, "F") === f;
21860
+ };
21861
+ if (same5("Value", prepared.v, prepared.u, edit.formula) && same5("Format", format4, "STR", `"${format4.replaceAll('"', '""')}"`) && same5("Type", String(prepared.type), void 0, void 0))
21862
+ return false;
21863
+ }
21517
21864
  if (texts[0])
21518
21865
  await assertFormattingDependencies(
21519
21866
  pkg,
@@ -21521,32 +21868,49 @@ async function insertVisioTextField(pkg, pagePaths, roots2, document, edit, chec
21521
21868
  roots2,
21522
21869
  edit.pageId,
21523
21870
  shape,
21524
- /* @__PURE__ */ new Map([["TheText", text7]]),
21871
+ new Map([
21872
+ ["TheText", text7],
21873
+ ...existing ? ["Value", "Format", "Type"].flatMap((name3) => {
21874
+ const cell2 = children2(existing, "Cell").find((cell3) => attribute2(cell3, "N") === name3);
21875
+ return [
21876
+ [`Field.${updating ? edit.fieldIndex : ""}.${name3}`, cell2],
21877
+ [`Fields.${name3}`, cell2]
21878
+ ];
21879
+ }) : []
21880
+ ]),
21525
21881
  check
21526
21882
  );
21527
21883
  check();
21528
- const index = String(rows.size ? Math.max(...[...rows.keys()].map(Number)) + 1 : 0);
21884
+ const index = updating ? edit.fieldIndex : String(rows.size ? Math.max(...[...rows.keys()].map(Number)) + 1 : 0);
21529
21885
  let section3 = children2(shape, "Section").find((node2) => attribute2(node2, "N") === "Field");
21530
21886
  if (!section3) {
21531
21887
  section3 = owner.createElementNS(ns, "Section");
21532
21888
  section3.setAttribute("N", "Field");
21533
21889
  shape.insertBefore(section3, texts[0] ?? null);
21534
21890
  }
21535
- const row2 = owner.createElementNS(ns, "Row");
21536
- row2.setAttribute("IX", index);
21891
+ const row2 = existing ?? owner.createElementNS(ns, "Row");
21892
+ if (!existing) row2.setAttribute("IX", index);
21537
21893
  const cell = (name3, v, extra = {}) => {
21538
- const node2 = owner.createElementNS(ns, "Cell");
21894
+ const node2 = children2(row2, "Cell").find((cell2) => attribute2(cell2, "N") === name3) ?? owner.createElementNS(ns, "Cell");
21539
21895
  node2.setAttribute("N", name3);
21540
21896
  node2.setAttribute("V", v);
21897
+ if (updating) {
21898
+ node2.removeAttribute("U");
21899
+ node2.removeAttribute("F");
21900
+ }
21541
21901
  for (const [key2, item] of Object.entries(extra)) node2.setAttribute(key2, item);
21542
- row2.appendChild(node2);
21902
+ if (!node2.parentNode) row2.appendChild(node2);
21543
21903
  };
21544
- const stored = valueCell(value);
21904
+ const stored = prepared;
21545
21905
  cell("Value", stored.v, { ...stored.u ? { U: stored.u } : {}, F: edit.formula });
21546
- if (edit.format)
21547
- cell("Format", edit.format, { U: "STR", F: `"${edit.format.replaceAll('"', '""')}"` });
21906
+ if (format4 || updating)
21907
+ cell("Format", format4, { U: "STR", F: `"${format4.replaceAll('"', '""')}"` });
21548
21908
  cell("Type", String(stored.type));
21549
- section3.appendChild(row2);
21909
+ if (!row2.parentNode) section3.appendChild(row2);
21910
+ if (updating) {
21911
+ markers[0].textContent = display;
21912
+ return true;
21913
+ }
21550
21914
  const field3 = owner.createElementNS(ns, "fld");
21551
21915
  field3.setAttribute("IX", index);
21552
21916
  field3.appendChild(owner.createTextNode(display));
@@ -26898,7 +27262,7 @@ async function editVsdxTransaction(input, edits, options, clock = {
26898
27262
  const dirty = /* @__PURE__ */ new Map();
26899
27263
  const roots2 = /* @__PURE__ */ new Map();
26900
27264
  const geometryCommands = commands.filter(
26901
- (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)
27265
+ (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)
26902
27266
  );
26903
27267
  let document;
26904
27268
  let masterMovePins = emptyMasterMoveProof();
@@ -26906,7 +27270,7 @@ async function editVsdxTransaction(input, edits, options, clock = {
26906
27270
  let instanceDeletes = /* @__PURE__ */ new Set();
26907
27271
  let groupMembers = /* @__PURE__ */ new Map();
26908
27272
  if (geometryCommands.length || commands.some(
26909
- (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)
27273
+ (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)
26910
27274
  )) {
26911
27275
  for (const [pageId2, path2] of pages) {
26912
27276
  const sourceRoot = await visioXml(pkg, path2, "PageContents");
@@ -27017,7 +27381,7 @@ async function editVsdxTransaction(input, edits, options, clock = {
27017
27381
  textChanged = true;
27018
27382
  await noteTextSize(command2, root2);
27019
27383
  }
27020
- } else if (command2.type === "insert-text-field") {
27384
+ } else if (command2.type === "insert-text-field" || command2.type === "update-text-field") {
27021
27385
  if (await insertVisioTextField(pkg, new Set(pages.values()), roots2, document, command2, check)) {
27022
27386
  dirty.set(path, root2);
27023
27387
  textChanged = true;
@@ -28208,7 +28572,16 @@ function copySnapshotScene(model) {
28208
28572
  source.fields,
28209
28573
  "text fields",
28210
28574
  1e4,
28211
- (field3) => fields(field3, ["start", "end", "cached", "formula"])
28575
+ (field3) => fields(field3, [
28576
+ "start",
28577
+ "end",
28578
+ "cached",
28579
+ "formula",
28580
+ "index",
28581
+ "format",
28582
+ "sourceKey",
28583
+ "editable"
28584
+ ])
28212
28585
  )
28213
28586
  },
28214
28587
  runs: list2(source.runs, "text runs", 1e5, (run) => ({