@evotecit/officeimo 0.1.2 → 0.1.4

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 (54) hide show
  1. package/README.md +59 -51
  2. package/bundles/officeimo-canopyx.js +1553 -314
  3. package/bundles/officeimo-canopyx.mjs +1497 -269
  4. package/bundles/officeimo-csv.js +18 -15
  5. package/bundles/officeimo-csv.mjs +16 -13
  6. package/bundles/officeimo-datatables.js +463 -301
  7. package/bundles/officeimo-datatables.mjs +420 -259
  8. package/bundles/officeimo-pdf.js +148 -65
  9. package/bundles/officeimo-pdf.mjs +124 -41
  10. package/bundles/officeimo-xlsx.js +177 -101
  11. package/bundles/officeimo-xlsx.mjs +149 -74
  12. package/bundles/officeimo.js +461 -299
  13. package/bundles/officeimo.mjs +419 -258
  14. package/dist/csv/index.js +16 -13
  15. package/dist/integrations/canopyx/diagnostics.d.ts +3 -0
  16. package/dist/integrations/canopyx/diagnostics.js +17 -0
  17. package/dist/integrations/canopyx/grouping.d.ts +6 -0
  18. package/dist/integrations/canopyx/grouping.js +198 -0
  19. package/dist/integrations/canopyx/index.d.ts +2 -2
  20. package/dist/integrations/canopyx/index.js +89 -15
  21. package/dist/integrations/canopyx/metadata.d.ts +4 -0
  22. package/dist/integrations/canopyx/metadata.js +51 -0
  23. package/dist/integrations/canopyx/pdf-layout.d.ts +5 -0
  24. package/dist/integrations/canopyx/pdf-layout.js +97 -0
  25. package/dist/integrations/canopyx/pdf-number.d.ts +3 -0
  26. package/dist/integrations/canopyx/pdf-number.js +64 -0
  27. package/dist/integrations/canopyx/pivot.d.ts +15 -0
  28. package/dist/integrations/canopyx/pivot.js +67 -0
  29. package/dist/integrations/canopyx/presentation.d.ts +8 -0
  30. package/dist/integrations/canopyx/presentation.js +40 -0
  31. package/dist/integrations/canopyx/rule-predicates.d.ts +3 -0
  32. package/dist/integrations/canopyx/rule-predicates.js +110 -0
  33. package/dist/integrations/canopyx/rules.d.ts +6 -0
  34. package/dist/integrations/canopyx/rules.js +176 -0
  35. package/dist/integrations/canopyx/source.js +69 -31
  36. package/dist/integrations/canopyx/types.d.ts +134 -10
  37. package/dist/integrations/canopyx/workbook.d.ts +6 -0
  38. package/dist/integrations/canopyx/workbook.js +52 -0
  39. package/dist/opc/index.js +9 -0
  40. package/dist/pdf/font-resources.js +33 -14
  41. package/dist/pdf/pages.js +60 -14
  42. package/dist/pdf/table-band-flow.js +7 -2
  43. package/dist/pdf/table-band-plan.js +9 -1
  44. package/dist/pdf/table-layout.js +6 -2
  45. package/dist/pdf/table-structure.js +9 -8
  46. package/dist/xlsx/index.d.ts +1 -1
  47. package/dist/xlsx/options.js +1 -1
  48. package/dist/xlsx/outlines.d.ts +3 -0
  49. package/dist/xlsx/outlines.js +39 -0
  50. package/dist/xlsx/types.d.ts +9 -0
  51. package/dist/xlsx/values.js +11 -2
  52. package/dist/xlsx/workbook.js +2 -0
  53. package/dist/xlsx/worksheet.js +14 -6
  54. package/package.json +2 -2
@@ -1409,13 +1409,13 @@ _modules.set("4a089607f7cbe50e13d4382d1cc4e5f6ce32c5773bbec2df84178710f54d9a38",
1409
1409
  return _exports;
1410
1410
  })();
1411
1411
 
1412
- const _m22 = _modules.get("e00bc0213b723678d050e3e1f11b39ed3d6b0b0fd6a39b403beb1a6bef69e282") ?? (() => {
1412
+ const _m22 = _modules.get("477ff98f49343b8ec4213008254b57a60dd42d07cb9843b3791d5e5f8e295865") ?? (() => {
1413
1413
  const { captureFields } = _m10;
1414
1414
 
1415
1415
  /** @internal The workbook owner captures these settings before validation or adapter merging. */
1416
1416
  const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "creator", "title", "subject", "description", "created", "modified"];
1417
1417
  /** @internal Worksheet settings also used by the portable sheet owner. */
1418
- const sheetOptionFields = ["columns", "includeHeader", "headerRows", "freezeHeader", "autoFilter", "boldHeader", "headerFill", "headerStyle", "alternatingRowStyle", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel", "rowHeight", "headerHeight", "defaultColumnWidth", "freezeColumns", "table", "autoSize", "footer", "print", "title", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation"];
1418
+ const sheetOptionFields = ["columns", "includeHeader", "headerRows", "freezeHeader", "autoFilter", "boldHeader", "headerFill", "headerStyle", "alternatingRowStyle", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel", "outlineSummaryBelow", "outlineSummaryRight", "columnOutlines", "rowHeight", "headerHeight", "defaultColumnWidth", "freezeColumns", "table", "autoSize", "footer", "print", "title", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation"];
1419
1419
  /** @internal Includes inherited format-specific ceilings before a wrapper combines stream settings. */
1420
1420
  const workbookLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxStyles", "maxSheets", "maxOverflowCharacters", "maxHyperlinks", "maxImageBytes", "maxBufferedCells", "maxBufferedCharacters", "maxMergedRanges", "maxConditionalFormats", "maxDifferentialStyles", "maxCharts", "maxChartPoints", "maxChartTextCharacters", "maxFormulaCharacters", "maxDataValidations", "maxValidationTextCharacters"];
1421
1421
  /** @internal Capture the workbook's known ceilings without dropping supported prototype fields. */
@@ -1428,11 +1428,11 @@ function captureWorkbookOptions(options) {
1428
1428
  return { ...captured, ...(captured.limits === undefined ? {} : { limits: captureWorkbookLimits(captured.limits) }) };
1429
1429
  }
1430
1430
  const _exports = Object.freeze({ workbookOptionFields: workbookOptionFields, sheetOptionFields: sheetOptionFields, workbookLimitFields: workbookLimitFields, captureWorkbookLimits: captureWorkbookLimits, captureWorkbookOptions: captureWorkbookOptions });
1431
- _modules.set("e00bc0213b723678d050e3e1f11b39ed3d6b0b0fd6a39b403beb1a6bef69e282", _exports);
1431
+ _modules.set("477ff98f49343b8ec4213008254b57a60dd42d07cb9843b3791d5e5f8e295865", _exports);
1432
1432
  return _exports;
1433
1433
  })();
1434
1434
 
1435
- const _m15 = _modules.get("58066519dce31ad3bb7f5f5c377585d3374a84578358ad519e2c021efa1a26f8") ?? (() => {
1435
+ const _m15 = _modules.get("7b12a415e92cc9ef7212fb3a88007cb6dc37f9f30077165d4897cfa8052f9a3c") ?? (() => {
1436
1436
  const { captureFields } = _m10;
1437
1437
 
1438
1438
  const { ExportBudget } = _m9;
@@ -1473,7 +1473,7 @@ function capturePdfOptions(input = {}) {
1473
1473
  return { ...options, ...(options.limits === undefined ? {} : { limits: capturePdfLimits(options.limits) }) };
1474
1474
  }
1475
1475
  const _exports = Object.freeze({ captureCommonLimits: captureCommonLimits, mergeAdapterLimits: mergeAdapterLimits, captureXlsxOptions: captureXlsxOptions, captureCsvOptions: captureCsvOptions, capturePdfOptions: capturePdfOptions });
1476
- _modules.set("58066519dce31ad3bb7f5f5c377585d3374a84578358ad519e2c021efa1a26f8", _exports);
1476
+ _modules.set("7b12a415e92cc9ef7212fb3a88007cb6dc37f9f30077165d4897cfa8052f9a3c", _exports);
1477
1477
  return _exports;
1478
1478
  })();
1479
1479
 
@@ -2048,7 +2048,7 @@ _modules.set("699a019e0c3f317a62bf3a6e59b76b6cf1645908b0f1b1f157c18f4d4f368dfb",
2048
2048
  return _exports;
2049
2049
  })();
2050
2050
 
2051
- const _m25 = _modules.get("4d4856357f94ecbeea67d111ff5e97f916ccc6be6aaefde219d461c6ad10a8c5") ?? (() => {
2051
+ const _m25 = _modules.get("945379594834125fea38bc00f02ef077409dd15f6ed67279e63e89afe0bb944b") ?? (() => {
2052
2052
 
2053
2053
 
2054
2054
 
@@ -2126,7 +2126,16 @@ class OpcPackage {
2126
2126
  throw new OfficeIMOError("INVALID_STATE", "OPC package is finalized."); }
2127
2127
  reserve(uri, type) {
2128
2128
  this.open();
2129
+ // OPC part names become ZIP entry names. Reject oversized and deeply nested
2130
+ // names before collecting every ancestor prefix.
2131
+ if (typeof uri === "string" && uri.length > 65536)
2132
+ throw new OfficeIMOError("RESOURCE_LIMIT", "OPC part name exceeds the ZIP entry-name limit.");
2129
2133
  uri = partUri(uri);
2134
+ let depth = 0;
2135
+ for (let index = 0; index < uri.length; index++) {
2136
+ if (uri[index] === "/" && ++depth > 64)
2137
+ throw new OfficeIMOError("RESOURCE_LIMIT", "OPC part name exceeds the directory-depth limit.");
2138
+ }
2130
2139
  if (/\/_rels(?:\/|$)/i.test(uri) || uri.toLowerCase() === "/[content_types].xml")
2131
2140
  throw new TypeError("Package metadata part names are reserved.");
2132
2141
  const key = uri.toLowerCase();
@@ -2298,7 +2307,7 @@ class OpcPackage {
2298
2307
  }
2299
2308
  }
2300
2309
  const _exports = Object.freeze({ partUri: _m26.partUri, relationshipPartUri: _m26.relationshipPartUri, relativePartTarget: _m26.relativePartTarget, corePropertiesXml: _m27.corePropertiesXml, appPropertiesXml: _m27.appPropertiesXml, relationshipsNamespace: relationshipsNamespace, officeRelationshipsNamespace: officeRelationshipsNamespace, contentTypesNamespace: contentTypesNamespace, relationshipTypes: relationshipTypes, ContentTypes: ContentTypes, OpcPackage: OpcPackage });
2301
- _modules.set("4d4856357f94ecbeea67d111ff5e97f916ccc6be6aaefde219d461c6ad10a8c5", _exports);
2310
+ _modules.set("945379594834125fea38bc00f02ef077409dd15f6ed67279e63e89afe0bb944b", _exports);
2302
2311
  return _exports;
2303
2312
  })();
2304
2313
 
@@ -2751,7 +2760,7 @@ _modules.set("f1de2157d2aefa347a314940eb7f89c16545e11f69923920e605409433742f93",
2751
2760
  return _exports;
2752
2761
  })();
2753
2762
 
2754
- const _m35 = _modules.get("4bce839e90e3ef590aa1b224ffd9c4bdf24d7639b93bdf879f9a0d79de4cd0e4") ?? (() => {
2763
+ const _m35 = _modules.get("e88a83ca79cd099fc2de29689554c913c7d04b17018098f81c43044064fcdfb8") ?? (() => {
2755
2764
  const { cleanXml, escapeXml } = _m28;
2756
2765
 
2757
2766
  const { assertExportValue, assertScalar } = _m5;
@@ -2810,14 +2819,23 @@ function columnName(index) {
2810
2819
  return name;
2811
2820
  }
2812
2821
  function clipName(text, length) { return text.slice(0, length).replace(/[\ud800-\udbff]$/, ""); }
2822
+ function trimSheetNameEdges(text) {
2823
+ let start = 0, end = text.length;
2824
+ const removable = (character) => character === "'" || /\s/u.test(character);
2825
+ while (start < end && removable(text[start]))
2826
+ start++;
2827
+ while (end > start && removable(text[end - 1]))
2828
+ end--;
2829
+ return text.slice(start, end);
2830
+ }
2813
2831
  function sheetName(requested, names, policy, register = true) {
2814
2832
  if (typeof requested !== "string")
2815
2833
  throw new TypeError("Sheet name must be a string.");
2816
2834
  // Validate and deduplicate the decoded literal value, before ST_Xstring attribute encoding.
2817
2835
  // A requested _xHHHH_ token is literal text; the serializer protects its leading underscore.
2818
- let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").replace(/^[\s']+|[\s']+$/g, "");
2836
+ let base = trimSheetNameEdges(cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_"));
2819
2837
  // Clipping can expose an internal apostrophe or the reserved History name.
2820
- base = clipName(base, 31).replace(/[\s']+$/g, "");
2838
+ base = trimSheetNameEdges(clipName(base, 31));
2821
2839
  if (!base)
2822
2840
  base = "Sheet";
2823
2841
  if (base.toLowerCase() === "history")
@@ -2844,11 +2862,57 @@ function excelDate(date, mode) {
2844
2862
  return (time - Date.UTC(1899, 11, 31)) / 86400000 + (time >= Date.UTC(1900, 2, 1) ? 1 : 0);
2845
2863
  }
2846
2864
  const _exports = Object.freeze({ Cell: Cell, assertXlsxValue: assertXlsxValue, copyValue: copyValue, cellText: cellText, inlineText: inlineText, columnName: columnName, sheetName: sheetName, excelDate: excelDate });
2847
- _modules.set("4bce839e90e3ef590aa1b224ffd9c4bdf24d7639b93bdf879f9a0d79de4cd0e4", _exports);
2865
+ _modules.set("e88a83ca79cd099fc2de29689554c913c7d04b17018098f81c43044064fcdfb8", _exports);
2848
2866
  return _exports;
2849
2867
  })();
2850
2868
 
2851
- const _m39 = _modules.get("84c16159c55cf4c0af5d3c67510302694946ae99c6c685fc09314069ee3da5c5") ?? (() => {
2869
+ const _m37 = _modules.get("e92456dbf0c50db97c8b6cf9a09365489ca3a882b4d506ad4dd841805b1146d1") ?? (() => {
2870
+ const { captureFields } = _m10;
2871
+
2872
+ /** Capture bounded disjoint ranges before asynchronous serialization; absent columns stay visible. */
2873
+ function captureColumnOutlines(input, columns) {
2874
+ if (input === undefined)
2875
+ return undefined;
2876
+ if (!Array.isArray(input) || input.length > columns)
2877
+ throw new TypeError("Column outlines must be bounded, non-overlapping ranges.");
2878
+ let end = 0;
2879
+ return Object.freeze(input.map(range => {
2880
+ if (!range || typeof range !== "object")
2881
+ throw new TypeError("Column outlines require range metadata.");
2882
+ return captureFields(range, ["firstColumn", "columnCount", "level", "hidden", "collapsed"]);
2883
+ }).sort((a, b) => a.firstColumn - b.firstColumn).map(range => {
2884
+ const { firstColumn, columnCount, level = 0, hidden, collapsed } = range;
2885
+ if (!Number.isSafeInteger(firstColumn) || firstColumn < end || !Number.isSafeInteger(columnCount) || columnCount < 1 || firstColumn + columnCount > columns)
2886
+ throw new RangeError("Column outline ranges must be disjoint and within the declared columns.");
2887
+ if (!Number.isInteger(level) || level < 0 || level > 7)
2888
+ throw new RangeError("Column outline level must be from zero through seven.");
2889
+ for (const flag of [hidden, collapsed])
2890
+ if (flag !== undefined && typeof flag !== "boolean")
2891
+ throw new TypeError("Column outline flags must be booleans.");
2892
+ end = firstColumn + columnCount;
2893
+ return Object.freeze({ firstColumn, columnCount, level, ...(hidden === undefined ? {} : { hidden }), ...(collapsed === undefined ? {} : { collapsed }) });
2894
+ }));
2895
+ }
2896
+ /** @internal Positions are captured even when a sheet has only column outlines. */
2897
+ function validateOutlinePositions(options) {
2898
+ for (const flag of [options.outlineSummaryBelow, options.outlineSummaryRight])
2899
+ if (flag !== undefined && typeof flag !== "boolean")
2900
+ throw new TypeError("Outline summary positions must be booleans.");
2901
+ }
2902
+ /** @internal Resolve at most 16,384 columns once, without retaining any worksheet body. */
2903
+ function columnOutlineMap(ranges) {
2904
+ const result = new Map();
2905
+ for (const range of ranges ?? [])
2906
+ for (let index = range.firstColumn; index < range.firstColumn + range.columnCount; index++)
2907
+ result.set(index, range);
2908
+ return result;
2909
+ }
2910
+ const _exports = Object.freeze({ captureColumnOutlines: captureColumnOutlines, validateOutlinePositions: validateOutlinePositions, columnOutlineMap: columnOutlineMap });
2911
+ _modules.set("e92456dbf0c50db97c8b6cf9a09365489ca3a882b4d506ad4dd841805b1146d1", _exports);
2912
+ return _exports;
2913
+ })();
2914
+
2915
+ const _m40 = _modules.get("aaf6808e1812a251687fd513480fe845b5677ffa493bccf519409807fe4d250c") ?? (() => {
2852
2916
  const { ChunkedTextSink } = _m3;
2853
2917
 
2854
2918
  const { escapeXml, xmlDeclaration } = _m28;
@@ -2957,18 +3021,18 @@ async function writeChartXml(chart, destination, policy, signal) {
2957
3021
  await text.close();
2958
3022
  }
2959
3023
  const _exports = Object.freeze({ chartNamespace: chartNamespace, chartContentType: chartContentType, chartAnchorXml: chartAnchorXml, writeChartXml: writeChartXml });
2960
- _modules.set("84c16159c55cf4c0af5d3c67510302694946ae99c6c685fc09314069ee3da5c5", _exports);
3024
+ _modules.set("aaf6808e1812a251687fd513480fe845b5677ffa493bccf519409807fe4d250c", _exports);
2961
3025
  return _exports;
2962
3026
  })();
2963
3027
 
2964
- const _m38 = _modules.get("9d4496a1ff3d58ac0b9dcd7304e6861184df30700c344329157899639df7b5e4") ?? (() => {
3028
+ const _m39 = _modules.get("d599dca57105b9cc787ba2498051ed0193cbdb1e5f23116e35bc77cd67a233f1") ?? (() => {
2965
3029
  const { cleanXml, escapeXml, escapeOoxmlAttribute, xmlDeclaration } = _m28;
2966
3030
 
2967
3031
  const { copyExportLink } = _m7;
2968
3032
 
2969
3033
  const { officeRelationshipsNamespace } = _m25;
2970
3034
 
2971
- const { chartAnchorXml } = _m39;
3035
+ const { chartAnchorXml } = _m40;
2972
3036
 
2973
3037
  const { captureFields } = _m10;
2974
3038
 
@@ -3035,14 +3099,14 @@ function drawingXml(images, policy, charts = []) {
3035
3099
  }
3036
3100
  const drawingContentType = "application/vnd.openxmlformats-officedocument.drawing+xml";
3037
3101
  const _exports = Object.freeze({ copyDrawingAnchor: copyDrawingAnchor, cellPosition: cellPosition, copyHyperlink: copyHyperlink, copyImage: copyImage, hyperlinksXml: hyperlinksXml, drawingXml: drawingXml, drawingContentType: drawingContentType });
3038
- _modules.set("9d4496a1ff3d58ac0b9dcd7304e6861184df30700c344329157899639df7b5e4", _exports);
3102
+ _modules.set("d599dca57105b9cc787ba2498051ed0193cbdb1e5f23116e35bc77cd67a233f1", _exports);
3039
3103
  return _exports;
3040
3104
  })();
3041
3105
 
3042
- const _m41 = _modules.get("4c91e257806f805b473340527db7ce3404c98ac27db0a775ff047dc3dded10cc") ?? (() => {
3106
+ const _m42 = _modules.get("39155eb25a58694b2caf100529b6c13dbe91f583741807b46232a2a567e19ecb") ?? (() => {
3043
3107
  const { OfficeIMOError } = _m2;
3044
3108
 
3045
- const { cellPosition } = _m38;
3109
+ const { cellPosition } = _m39;
3046
3110
 
3047
3111
  function indexRows(regions) {
3048
3112
  if (!regions.length)
@@ -3140,11 +3204,11 @@ class MergeRegions {
3140
3204
  throw new RangeError("Merged ranges must stay within exported rows."); }
3141
3205
  }
3142
3206
  const _exports = Object.freeze({ MergeRegions: MergeRegions });
3143
- _modules.set("4c91e257806f805b473340527db7ce3404c98ac27db0a775ff047dc3dded10cc", _exports);
3207
+ _modules.set("39155eb25a58694b2caf100529b6c13dbe91f583741807b46232a2a567e19ecb", _exports);
3144
3208
  return _exports;
3145
3209
  })();
3146
3210
 
3147
- const _m42 = _modules.get("47efdc8f108b0e995accdd63fd1addea0e4de507010cbf0975417e7151636360") ?? (() => {
3211
+ const _m43 = _modules.get("2a51a034ac74f5a0656731f46740bb80adee48101e7a4b51253d9399df11d238") ?? (() => {
3148
3212
  const { ExportCell } = _m5;
3149
3213
 
3150
3214
  const { tableSpans } = _m18;
@@ -3177,11 +3241,11 @@ class StructuredRows {
3177
3241
  }
3178
3242
  }
3179
3243
  const _exports = Object.freeze({ StructuredRows: StructuredRows });
3180
- _modules.set("47efdc8f108b0e995accdd63fd1addea0e4de507010cbf0975417e7151636360", _exports);
3244
+ _modules.set("2a51a034ac74f5a0656731f46740bb80adee48101e7a4b51253d9399df11d238", _exports);
3181
3245
  return _exports;
3182
3246
  })();
3183
3247
 
3184
- const _m40 = _modules.get("23615ba776e7025e5e40cde325ad13799a7eeae6c88cb2ed74395222f91e6a81") ?? (() => {
3248
+ const _m41 = _modules.get("b732883d8635c0adf27cef2a3900f08374d02c9ce1b005d02af6853c8be627cc") ?? (() => {
3185
3249
  const { ExportCell } = _m5;
3186
3250
 
3187
3251
  const { isDate } = _m6;
@@ -3192,13 +3256,13 @@ const { FormulaCell } = _m36;
3192
3256
 
3193
3257
  const { escapeOoxmlAttribute } = _m28;
3194
3258
 
3195
- const { MergeRegions } = _m41;
3259
+ const { MergeRegions } = _m42;
3196
3260
 
3197
3261
  const { OfficeIMOError } = _m2;
3198
3262
 
3199
3263
  const { createTotals } = _m12;
3200
3264
 
3201
- const { StructuredRows } = _m42;
3265
+ const { StructuredRows } = _m43;
3202
3266
 
3203
3267
  /** @internal A computed formula with a numeric cache; no public arbitrary-formula input. */
3204
3268
  class ComputedTotal {
@@ -3378,11 +3442,11 @@ function printXml(options, policy) {
3378
3442
  (options.footer === undefined ? "" : '<oddFooter>' + escapeOoxmlAttribute("&C" + options.footer.replace(/&/g, "&&"), policy) + '</oddFooter>') + '</headerFooter>' : "");
3379
3443
  }
3380
3444
  const _exports = Object.freeze({ ComputedTotal: ComputedTotal, ReportLayout: ReportLayout, totalFormula: totalFormula, printXml: printXml });
3381
- _modules.set("23615ba776e7025e5e40cde325ad13799a7eeae6c88cb2ed74395222f91e6a81", _exports);
3445
+ _modules.set("b732883d8635c0adf27cef2a3900f08374d02c9ce1b005d02af6853c8be627cc", _exports);
3382
3446
  return _exports;
3383
3447
  })();
3384
3448
 
3385
- const _m44 = _modules.get("7845d79cd22590bbefc767802abfe3f805e8f68807521cef8d07ecc42db0b491") ?? (() => {
3449
+ const _m45 = _modules.get("09d589ff8f82302ce4c17411c7b811a87fb034e61e4b3013b7f8b18853a90449") ?? (() => {
3386
3450
  const { columnName } = _m35;
3387
3451
 
3388
3452
  /** @internal Data-column selectors use stable keys or one-based worksheet columns. */
@@ -3409,11 +3473,11 @@ function qualifiedCell(sheetName, column, row) {
3409
3473
  return qualifiedColumnRange(sheetName, column, row, 1).split(":")[0];
3410
3474
  }
3411
3475
  const _exports = Object.freeze({ resolveDataColumn: resolveDataColumn, qualifiedColumnRange: qualifiedColumnRange, qualifiedCell: qualifiedCell });
3412
- _modules.set("7845d79cd22590bbefc767802abfe3f805e8f68807521cef8d07ecc42db0b491", _exports);
3476
+ _modules.set("09d589ff8f82302ce4c17411c7b811a87fb034e61e4b3013b7f8b18853a90449", _exports);
3413
3477
  return _exports;
3414
3478
  })();
3415
3479
 
3416
- const _m45 = _modules.get("4892a7dafefc4d82567cd2bd4cc8da5470cee4dbf546e6473f782f44bd4bbe35") ?? (() => {
3480
+ const _m46 = _modules.get("55a9bd1fb59ea19bf98a03859769a119fdc71a44075e560937e7184720e53514") ?? (() => {
3417
3481
  const { OfficeIMOError } = _m2;
3418
3482
 
3419
3483
  const { columnName } = _m35;
@@ -3456,22 +3520,22 @@ function dataRowReference(firstColumn, lastColumn, headerRows, dataRows, ranges)
3456
3520
  return reference || undefined;
3457
3521
  }
3458
3522
  const _exports = Object.freeze({ retainDataRowRanges: retainDataRowRanges, dataRowRanges: dataRowRanges, dataRowCount: dataRowCount, dataRowReference: dataRowReference });
3459
- _modules.set("4892a7dafefc4d82567cd2bd4cc8da5470cee4dbf546e6473f782f44bd4bbe35", _exports);
3523
+ _modules.set("55a9bd1fb59ea19bf98a03859769a119fdc71a44075e560937e7184720e53514", _exports);
3460
3524
  return _exports;
3461
3525
  })();
3462
3526
 
3463
- const _m43 = _modules.get("736b2b2fc3489642263dbaf677544e8a270eea6b8efb0cc26c67346e66cab118") ?? (() => {
3527
+ const _m44 = _modules.get("a1b616256344317787b0b102f35d062009d6a2e9c873b9f106c99c095c92ace3") ?? (() => {
3464
3528
  const { cleanXml, escapeXml, escapeOoxmlAttribute } = _m28;
3465
3529
 
3466
- const { cellPosition } = _m38;
3530
+ const { cellPosition } = _m39;
3467
3531
 
3468
3532
  const { colorArgb } = _m33;
3469
3533
 
3470
3534
  const { fields, optionalBoolean, differentialXml } = _m34;
3471
3535
 
3472
- const { resolveDataColumn } = _m44;
3536
+ const { resolveDataColumn } = _m45;
3473
3537
 
3474
- const { dataRowReference } = _m45;
3538
+ const { dataRowReference } = _m46;
3475
3539
 
3476
3540
  function target(range, columns) {
3477
3541
  if (typeof range === "string") {
@@ -3626,11 +3690,11 @@ class ConditionalFormats {
3626
3690
  }
3627
3691
  }
3628
3692
  const _exports = Object.freeze({ prepareConditionalFormats: prepareConditionalFormats, ConditionalFormats: ConditionalFormats });
3629
- _modules.set("736b2b2fc3489642263dbaf677544e8a270eea6b8efb0cc26c67346e66cab118", _exports);
3693
+ _modules.set("a1b616256344317787b0b102f35d062009d6a2e9c873b9f106c99c095c92ace3", _exports);
3630
3694
  return _exports;
3631
3695
  })();
3632
3696
 
3633
- const _m46 = _modules.get("860c88d97ba76e8713c14d56967152e369d2f08f50ffada68827a9c220881c61") ?? (() => {
3697
+ const _m47 = _modules.get("13fa96d976e4dec7343dd3a392829567f1fcb574324a98f5a5d3a61c9a0dc27d") ?? (() => {
3634
3698
  const { OfficeIMOError } = _m2;
3635
3699
 
3636
3700
  const { checkAbort } = _m4;
@@ -3639,9 +3703,9 @@ const { cleanXml, escapeOoxmlAttribute, escapeXml } = _m28;
3639
3703
 
3640
3704
  const { fields, optionalBoolean } = _m34;
3641
3705
 
3642
- const { resolveDataColumn } = _m44;
3706
+ const { resolveDataColumn } = _m45;
3643
3707
 
3644
- const { dataRowReference } = _m45;
3708
+ const { dataRowReference } = _m46;
3645
3709
 
3646
3710
  function message(value, maximum, name) {
3647
3711
  if (value === undefined)
@@ -3730,11 +3794,11 @@ function* dataValidationsXml(prepared, headerRows, dataRows, ranges) {
3730
3794
  yield '</dataValidations>';
3731
3795
  }
3732
3796
  const _exports = Object.freeze({ prepareDataValidations: prepareDataValidations, dataValidationsXml: dataValidationsXml });
3733
- _modules.set("860c88d97ba76e8713c14d56967152e369d2f08f50ffada68827a9c220881c61", _exports);
3797
+ _modules.set("13fa96d976e4dec7343dd3a392829567f1fcb574324a98f5a5d3a61c9a0dc27d", _exports);
3734
3798
  return _exports;
3735
3799
  })();
3736
3800
 
3737
- const _m37 = _modules.get("b99287e3e329b75007119103112a699c368d8237b37fa79e083b0014a21952e4") ?? (() => {
3801
+ const _m38 = _modules.get("a61e744201bb537b635b367b1764bd85892101d55e00b8c78faec8be89577376") ?? (() => {
3738
3802
  const { checkAbort, consumeRows, inputRows, pause, taskYieldDue } = _m4;
3739
3803
 
3740
3804
  const { ChunkedTextSink, BlobByteSink } = _m3;
@@ -3755,25 +3819,27 @@ const { Cell, cellText, columnName, inlineText, excelDate, copyValue } = _m35;
3755
3819
 
3756
3820
  const { spreadsheetNamespace, colorArgb, validateStylePatch, copyStylePatch } = _m32;
3757
3821
 
3758
- const { copyHyperlink, copyImage, hyperlinksXml, cellPosition } = _m38;
3822
+ const { copyHyperlink, copyImage, hyperlinksXml, cellPosition } = _m39;
3759
3823
 
3760
3824
  const { ExportCell, assertScalar } = _m5;
3761
3825
 
3762
- const { ReportLayout, ComputedTotal, printXml } = _m40;
3826
+ const { ReportLayout, ComputedTotal, printXml } = _m41;
3763
3827
 
3764
3828
  const { cleanXml } = _m28;
3765
3829
 
3766
- const { ConditionalFormats, prepareConditionalFormats } = _m43;
3830
+ const { ConditionalFormats, prepareConditionalFormats } = _m44;
3767
3831
 
3768
3832
  const { isDate } = _m6;
3769
3833
 
3770
3834
  const { FormulaCell, formulaXml, isSubtotalFormula } = _m36;
3771
3835
 
3772
- const { prepareDataValidations, dataValidationsXml } = _m46;
3836
+ const { prepareDataValidations, dataValidationsXml } = _m47;
3773
3837
 
3774
- const { qualifiedCell, qualifiedColumnRange, resolveDataColumn } = _m44;
3838
+ const { qualifiedCell, qualifiedColumnRange, resolveDataColumn } = _m45;
3775
3839
 
3776
- const { dataRowRanges, dataRowCount } = _m45;
3840
+ const { dataRowRanges, dataRowCount } = _m46;
3841
+
3842
+ const { captureColumnOutlines, columnOutlineMap, validateOutlinePositions } = _m37;
3777
3843
 
3778
3844
  const maximumHyperlinks = 65530;
3779
3845
  function checkHyperlinkCount(count) {
@@ -3905,6 +3971,8 @@ class Worksheet {
3905
3971
  throw new TypeError("Row and style callbacks must be functions.");
3906
3972
  if (options.maxOutlineLevel !== undefined && (!Number.isInteger(options.maxOutlineLevel) || options.maxOutlineLevel < 0 || options.maxOutlineLevel > 7))
3907
3973
  throw new RangeError("Maximum outline level must be an integer from zero through seven.");
3974
+ validateOutlinePositions(options);
3975
+ captureColumnOutlines(options.columnOutlines, columns.length);
3908
3976
  if (options.rowOutline && options.maxOutlineLevel === undefined)
3909
3977
  throw new TypeError("A row outline callback requires maxOutlineLevel before streamed rows are written.");
3910
3978
  if (!options.rowOutline && options.maxOutlineLevel !== undefined)
@@ -4189,17 +4257,22 @@ class Worksheet {
4189
4257
  const buffer = this.buffer = new ChunkedTextSink(this.entry, this.book.settings.signal), opts = this.options;
4190
4258
  const x = opts.freezeColumns ?? 0, y = opts.freezeHeader ? this.headerRows : 0;
4191
4259
  const pane = x && y ? "bottomRight" : x ? "topRight" : "bottomLeft", cell = columnName(x + 1) + (y + 1);
4260
+ const outlines = columnOutlineMap(opts.columnOutlines), hasOutline = !!opts.rowOutline || outlines.size > 0;
4261
+ const maxColumnLevel = Math.max(0, ...Array.from(outlines.values(), value => value.level ?? 0));
4192
4262
  await buffer.write(xmlDeclaration + '<worksheet xmlns="' + spreadsheetNamespace + '" xmlns:r="' + officeRelationshipsNamespace + '">' +
4193
- (opts.print || opts.rowOutline ? '<sheetPr>' + (opts.rowOutline ? '<outlinePr summaryBelow="1" showOutlineSymbols="1"/>' : "") + (opts.print ? '<pageSetUpPr fitToPage="1"/>' : "") + '</sheetPr>' : "") + '<sheetViews><sheetView workbookViewId="0">' +
4263
+ (opts.print || hasOutline ? '<sheetPr>' + (hasOutline ? '<outlinePr summaryBelow="' + (opts.outlineSummaryBelow === false ? "0" : "1") + '"' + (opts.outlineSummaryRight === undefined ? "" : ' summaryRight="' + (opts.outlineSummaryRight ? "1" : "0") + '"') + ' showOutlineSymbols="1"/>' : "") + (opts.print ? '<pageSetUpPr fitToPage="1"/>' : "") + '</sheetPr>' : "") + '<sheetViews><sheetView workbookViewId="0">' +
4194
4264
  (x || y ? '<pane' + (x ? ' xSplit="' + x + '"' : "") + (y ? ' ySplit="' + y + '"' : "") + ' topLeftCell="' + cell + '" activePane="' + pane + '" state="frozen"/><selection pane="' + pane + '" activeCell="' + cell + '" sqref="' + cell + '"/>' : "") + '</sheetView></sheetViews>' +
4195
- (opts.rowOutline ? '<sheetFormatPr defaultRowHeight="15" outlineLevelRow="' + opts.maxOutlineLevel + '"/>' : ""));
4265
+ (hasOutline ? '<sheetFormatPr defaultRowHeight="15"' + (opts.rowOutline ? ' outlineLevelRow="' + opts.maxOutlineLevel + '"' : "") + (outlines.size ? ' outlineLevelCol="' + maxColumnLevel + '"' : "") + '/>' : ""));
4196
4266
  const defaultWidth = opts.defaultColumnWidth ?? (this.table ? 20 : undefined);
4197
- if (this.columns.some((_, i) => this.layout.widths[i] !== undefined || defaultWidth !== undefined)) {
4267
+ if (this.columns.some((_, i) => this.layout.widths[i] !== undefined || defaultWidth !== undefined || outlines.has(i))) {
4198
4268
  await buffer.write('<cols>');
4199
4269
  for (let i = 0; i < this.columns.length; i++) {
4200
- const width = this.layout.widths[i] ?? defaultWidth;
4201
- if (width !== undefined)
4202
- await buffer.write('<col min="' + (i + 1) + '" max="' + (i + 1) + '" width="' + width + '" customWidth="1"/>');
4270
+ const width = this.layout.widths[i] ?? defaultWidth, outline = outlines.get(i);
4271
+ if (width !== undefined || outline)
4272
+ await buffer.write('<col min="' + (i + 1) + '" max="' + (i + 1) + '"' +
4273
+ (width === undefined ? "" : ' width="' + width + '" customWidth="1"') +
4274
+ (outline?.level ? ' outlineLevel="' + outline.level + '"' : "") + (outline?.hidden ? ' hidden="1"' : "") +
4275
+ (outline?.collapsed ? ' collapsed="1"' : "") + '/>');
4203
4276
  }
4204
4277
  await buffer.write('</cols>');
4205
4278
  }
@@ -4457,11 +4530,11 @@ class Worksheet {
4457
4530
  async discard(error) { this.failed = true; this.error = error; this.pending = []; this.pendingCharacters = 0; this.prepared = undefined; this.buffer = undefined; this.nativeCharts.length = 0; this.chartSources.length = 0; this.output.discard(); await this.entry?.discard(error); }
4458
4531
  }
4459
4532
  const _exports = Object.freeze({ Worksheet: Worksheet });
4460
- _modules.set("b99287e3e329b75007119103112a699c368d8237b37fa79e083b0014a21952e4", _exports);
4533
+ _modules.set("a61e744201bb537b635b367b1764bd85892101d55e00b8c78faec8be89577376", _exports);
4461
4534
  return _exports;
4462
4535
  })();
4463
4536
 
4464
- const _m47 = _modules.get("7f1b6bb321e8055ba5269c0fe0933cf02f9a4ce269d3b8e4a64cc63d8398954a") ?? (() => {
4537
+ const _m48 = _modules.get("1b4698baf9a9c9b3505988abac9f83967c32cf37483d70a949ae89c4485532a4") ?? (() => {
4465
4538
  const { escapeOoxmlAttribute, escapeXml, xmlDeclaration } = _m28;
4466
4539
 
4467
4540
  const { cellText, columnName } = _m35;
@@ -4472,7 +4545,7 @@ const { ExportCell } = _m5;
4472
4545
 
4473
4546
  const { Cell } = _m35;
4474
4547
 
4475
- const { totalFormula } = _m40;
4548
+ const { totalFormula } = _m41;
4476
4549
 
4477
4550
  function defineTable(id, options, columns, policy) {
4478
4551
  const name = options.name ?? "Table" + id;
@@ -4504,11 +4577,11 @@ function tableXml(table, rowCount, policy, headerRow = 1, footer) {
4504
4577
  '" showColumnStripes="' + (options.bandedColumns ? 1 : 0) + '"/></table>';
4505
4578
  }
4506
4579
  const _exports = Object.freeze({ defineTable: defineTable, tableXml: tableXml });
4507
- _modules.set("7f1b6bb321e8055ba5269c0fe0933cf02f9a4ce269d3b8e4a64cc63d8398954a", _exports);
4580
+ _modules.set("1b4698baf9a9c9b3505988abac9f83967c32cf37483d70a949ae89c4485532a4", _exports);
4508
4581
  return _exports;
4509
4582
  })();
4510
4583
 
4511
- const _m48 = _modules.get("0c395783b9d7cc62dd39a21adeb698ad4a61e2c89f7b1fc8712e2eb2ccfe9d92") ?? (() => {
4584
+ const _m49 = _modules.get("0c395783b9d7cc62dd39a21adeb698ad4a61e2c89f7b1fc8712e2eb2ccfe9d92") ?? (() => {
4512
4585
  const { OfficeIMOError } = _m2;
4513
4586
 
4514
4587
  const { cleanXml } = _m28;
@@ -4576,7 +4649,7 @@ _modules.set("0c395783b9d7cc62dd39a21adeb698ad4a61e2c89f7b1fc8712e2eb2ccfe9d92",
4576
4649
  return _exports;
4577
4650
  })();
4578
4651
 
4579
- const _m50 = _modules.get("35db01801a6b2e3e0c5acd7493e56f04b5b41b1d57afa8be28b8358378ad6494") ?? (() => {
4652
+ const _m51 = _modules.get("35db01801a6b2e3e0c5acd7493e56f04b5b41b1d57afa8be28b8358378ad6494") ?? (() => {
4580
4653
  const { checkAbort } = _m4;
4581
4654
 
4582
4655
  const { NotSupportedError, OfficeIMOError } = _m2;
@@ -4708,18 +4781,18 @@ _modules.set("35db01801a6b2e3e0c5acd7493e56f04b5b41b1d57afa8be28b8358378ad6494",
4708
4781
  return _exports;
4709
4782
  })();
4710
4783
 
4711
- const _m49 = _modules.get("6ff482aba6cf0b524cf20f6a4f8af16b842a49f36448b14e73beaf838885d219") ?? (() => {
4784
+ const _m50 = _modules.get("24f1417c3c320a8a41137c28f70b72091256c63010be0c88b684dce85f54950c") ?? (() => {
4712
4785
  const { checkAbort } = _m4;
4713
4786
 
4714
4787
  const { NotSupportedError, OfficeIMOError } = _m2;
4715
4788
 
4716
4789
  const { cleanXml } = _m28;
4717
4790
 
4718
- const { copyDrawingAnchor } = _m38;
4791
+ const { copyDrawingAnchor } = _m39;
4719
4792
 
4720
4793
  const { captureFields } = _m10;
4721
4794
 
4722
- const { captureChartRange, prepareChartBinding } = _m50;
4795
+ const { captureChartRange, prepareChartBinding } = _m51;
4723
4796
 
4724
4797
  function fields(value, allowed, context) {
4725
4798
  if (!value || typeof value !== "object" || Array.isArray(value))
@@ -4875,11 +4948,11 @@ function prepareChart(input, policy, availablePoints, availableText, signal, res
4875
4948
  points, textCharacters });
4876
4949
  }
4877
4950
  const _exports = Object.freeze({ prepareChart: prepareChart });
4878
- _modules.set("6ff482aba6cf0b524cf20f6a4f8af16b842a49f36448b14e73beaf838885d219", _exports);
4951
+ _modules.set("24f1417c3c320a8a41137c28f70b72091256c63010be0c88b684dce85f54950c", _exports);
4879
4952
  return _exports;
4880
4953
  })();
4881
4954
 
4882
- const _m24 = _modules.get("0f11efc0d52501e827898643b33f7fa42365115a892aa801634ecea3f3603681") ?? (() => {
4955
+ const _m24 = _modules.get("e89ecd2f5e1738c6e88f72ac2bcac70dfaa81b4aa86edf333e9b395cf2212e2a") ?? (() => {
4883
4956
  const { beginTask, checkAbort, pause, taskYieldDue } = _m4;
4884
4957
 
4885
4958
  const { OfficeIMOError } = _m2;
@@ -4902,25 +4975,27 @@ const { copyColumns } = _m11;
4902
4975
 
4903
4976
  const { captureFields } = _m10;
4904
4977
 
4978
+ const { captureColumnOutlines } = _m37;
4979
+
4905
4980
  const { captureTableSpans } = _m18;
4906
4981
 
4907
4982
  const { assertExportValue } = _m5;
4908
4983
 
4909
- const { Worksheet } = _m37;
4984
+ const { Worksheet } = _m38;
4910
4985
 
4911
- const { defineTable, tableXml } = _m47;
4986
+ const { defineTable, tableXml } = _m48;
4912
4987
 
4913
- const { copyHyperlink, drawingXml, drawingContentType } = _m38;
4988
+ const { copyHyperlink, drawingXml, drawingContentType } = _m39;
4914
4989
 
4915
- const { TextOverflow } = _m48;
4990
+ const { TextOverflow } = _m49;
4916
4991
 
4917
4992
  const { captureWorkbookOptions, sheetOptionFields } = _m22;
4918
4993
 
4919
- const { prepareChart } = _m49;
4994
+ const { prepareChart } = _m50;
4920
4995
 
4921
- const { qualifiedColumnRange, resolveDataColumn } = _m44;
4996
+ const { qualifiedColumnRange, resolveDataColumn } = _m45;
4922
4997
 
4923
- const { chartContentType, writeChartXml } = _m39;
4998
+ const { chartContentType, writeChartXml } = _m40;
4924
4999
 
4925
5000
  const xlsxMime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
4926
5001
  const formatType = (name) => "application/vnd.openxmlformats-officedocument.spreadsheetml." + name + "+xml";
@@ -4931,6 +5006,7 @@ function captureSheet(options, policy) {
4931
5006
  const footer = captured.footer && captureFields(captured.footer, ["rows", "values", "totals", "style"]);
4932
5007
  const print = captured.print && captureFields(captured.print, ["paper", "orientation", "fitToWidth", "fitToHeight", "repeatHeaders", "margins", "header", "footer"]);
4933
5008
  return { ...captured, columns,
5009
+ ...(captured.columnOutlines === undefined ? {} : { columnOutlines: captureColumnOutlines(captured.columnOutlines, columns.length) }),
4934
5010
  ...(captured.headerRows === undefined ? {} : { headerRows: captureTableSpans(captured.headerRows, columns.length) }),
4935
5011
  ...(footer ? { footer: { ...footer,
4936
5012
  ...(footer.rows === undefined ? {} : { rows: captureTableSpans(footer.rows, columns.length) }),
@@ -5357,11 +5433,11 @@ class Workbook {
5357
5433
  }
5358
5434
  }
5359
5435
  const _exports = Object.freeze({ Workbook: Workbook });
5360
- _modules.set("0f11efc0d52501e827898643b33f7fa42365115a892aa801634ecea3f3603681", _exports);
5436
+ _modules.set("e89ecd2f5e1738c6e88f72ac2bcac70dfaa81b4aa86edf333e9b395cf2212e2a", _exports);
5361
5437
  return _exports;
5362
5438
  })();
5363
5439
 
5364
- const _m52 = _modules.get("89111eab1f3857529c2d0cd849f16598097e62bd73841211b9c66ccc7b1b7ca2") ?? (() => {
5440
+ const _m53 = _modules.get("a10003e971cd5ec2cee127bc9b029a0aa06fe3d50112838929d7a04a55e177c0") ?? (() => {
5365
5441
  const { ExportCell, assertScalar } = _m5;
5366
5442
 
5367
5443
  const { captureWorkbookOptions, sheetOptionFields } = _m22;
@@ -5410,18 +5486,18 @@ function portableWorkbook(options = {}) {
5410
5486
  return { ...options, cellValueWriters: wrapped };
5411
5487
  }
5412
5488
  const _exports = Object.freeze({ portableSheet: portableSheet, portableWorkbook: portableWorkbook });
5413
- _modules.set("89111eab1f3857529c2d0cd849f16598097e62bd73841211b9c66ccc7b1b7ca2", _exports);
5489
+ _modules.set("a10003e971cd5ec2cee127bc9b029a0aa06fe3d50112838929d7a04a55e177c0", _exports);
5414
5490
  return _exports;
5415
5491
  })();
5416
5492
 
5417
- const _m51 = _modules.get("8d425cd3abec2c5e0140f71239bbeacbae0e57524ed70a8e545f80286c4a1308") ?? (() => {
5493
+ const _m52 = _modules.get("5bfd5c9c5e179305b9bebd6cb0d6a0d75e974b223e119e0fd4fbb773325f1e63") ?? (() => {
5418
5494
  const { withDestination } = _m3;
5419
5495
 
5420
5496
  const { copyColumns } = _m11;
5421
5497
 
5422
5498
  const { Workbook } = _m24;
5423
5499
 
5424
- const { portableSheet, portableWorkbook } = _m52;
5500
+ const { portableSheet, portableWorkbook } = _m53;
5425
5501
 
5426
5502
  const { captureFields } = _m10;
5427
5503
 
@@ -5469,11 +5545,11 @@ async function writeXlsxTo(rows, destination, configuration) {
5469
5545
  });
5470
5546
  }
5471
5547
  const _exports = Object.freeze({ writeXlsx: writeXlsx, writeXlsxTo: writeXlsxTo });
5472
- _modules.set("8d425cd3abec2c5e0140f71239bbeacbae0e57524ed70a8e545f80286c4a1308", _exports);
5548
+ _modules.set("5bfd5c9c5e179305b9bebd6cb0d6a0d75e974b223e119e0fd4fbb773325f1e63", _exports);
5473
5549
  return _exports;
5474
5550
  })();
5475
5551
 
5476
- const _m54 = _modules.get("02f1b8fe9368420b22d79efc01f2b37794fc40aaf8150161b3b7623fcdc0d71f") ?? (() => {
5552
+ const _m55 = _modules.get("dd34d5fd89869a0f953f3f2b3fd27ac83be29e68f76c9087fae3d33095aeda7c") ?? (() => {
5477
5553
  const { assertGroupedReportSource } = _m8;
5478
5554
 
5479
5555
  const { captureFields } = _m10;
@@ -5484,9 +5560,9 @@ const { fields } = _m34;
5484
5560
 
5485
5561
  const { sheetOptionFields } = _m22;
5486
5562
 
5487
- const { portableSheet } = _m52;
5563
+ const { portableSheet } = _m53;
5488
5564
 
5489
- const { resolveDataColumn } = _m44;
5565
+ const { resolveDataColumn } = _m45;
5490
5566
 
5491
5567
  const { copyStylePatch } = _m32;
5492
5568
 
@@ -5562,11 +5638,11 @@ function prepareGroupedSheet(report, configuration, maxConditionalFormats = 1000
5562
5638
  ...(options.grandTotalStyle ? { grandTotalStyle: copyStylePatch(options.grandTotalStyle) } : {}) };
5563
5639
  }
5564
5640
  const _exports = Object.freeze({ groupedOptionFields: groupedOptionFields, prepareGroupedSheet: prepareGroupedSheet });
5565
- _modules.set("02f1b8fe9368420b22d79efc01f2b37794fc40aaf8150161b3b7623fcdc0d71f", _exports);
5641
+ _modules.set("dd34d5fd89869a0f953f3f2b3fd27ac83be29e68f76c9087fae3d33095aeda7c", _exports);
5566
5642
  return _exports;
5567
5643
  })();
5568
5644
 
5569
- const _m53 = _modules.get("6b646c4d57b8f8f452eaa7e61d2935bab09681aceb6064b8600bf73ca10b8f4e") ?? (() => {
5645
+ const _m54 = _modules.get("2ba62cdf88d559804bb84b20e9816b2de0f232401b7431ac414699a607d554a4") ?? (() => {
5570
5646
  const { groupedReportOperation } = _m8;
5571
5647
 
5572
5648
  const { checkAbort, withAbort } = _m4;
@@ -5583,9 +5659,9 @@ const { columnName } = _m35;
5583
5659
 
5584
5660
  const { captureWorkbookLimits, workbookOptionFields } = _m22;
5585
5661
 
5586
- const { retainDataRowRanges } = _m45;
5662
+ const { retainDataRowRanges } = _m46;
5587
5663
 
5588
- const { groupedOptionFields, prepareGroupedSheet } = _m54;
5664
+ const { groupedOptionFields, prepareGroupedSheet } = _m55;
5589
5665
 
5590
5666
  const subtotalOperations = { average: 1, count: 2, max: 4, min: 5, sum: 9 };
5591
5667
  function label(value) {
@@ -5739,18 +5815,18 @@ async function writeGroupedXlsxTo(report, destination, options) {
5739
5815
  return withDestination(destination, async (sink) => (await write(report, prepared, sink)).result);
5740
5816
  }
5741
5817
  const _exports = Object.freeze({ addGroupedXlsx: addGroupedXlsx, writeGroupedXlsx: writeGroupedXlsx, writeGroupedXlsxTo: writeGroupedXlsxTo });
5742
- _modules.set("6b646c4d57b8f8f452eaa7e61d2935bab09681aceb6064b8600bf73ca10b8f4e", _exports);
5818
+ _modules.set("2ba62cdf88d559804bb84b20e9816b2de0f232401b7431ac414699a607d554a4", _exports);
5743
5819
  return _exports;
5744
5820
  })();
5745
5821
 
5746
- const _m23 = _modules.get("9fbdb5c6f6af75d87ac6cb47771fe48fa6527be2cb7d16dbad56e4213e2f7195") ?? (() => {
5822
+ const _m23 = _modules.get("d6587a933b36ccfdba9a2a252389924ac8461f672b3a500082cceb5e53c8b0b6") ?? (() => {
5747
5823
 
5748
- const _exports = Object.freeze({ Workbook: _m24.Workbook, writeXlsx: _m51.writeXlsx, writeXlsxTo: _m51.writeXlsxTo, writeGroupedXlsx: _m53.writeGroupedXlsx, writeGroupedXlsxTo: _m53.writeGroupedXlsxTo, addGroupedXlsx: _m53.addGroupedXlsx, createGroupedReport: _m8.createGroupedReport, Worksheet: _m37.Worksheet, Cell: _m35.Cell, FormulaCell: _m36.FormulaCell, StyleRegistry: _m32.StyleRegistry, NumberFormats: _m32.NumberFormats, saveBlob: _m1.saveBlob, ExportCell: _m5.ExportCell });
5749
- _modules.set("9fbdb5c6f6af75d87ac6cb47771fe48fa6527be2cb7d16dbad56e4213e2f7195", _exports);
5824
+ const _exports = Object.freeze({ Workbook: _m24.Workbook, writeXlsx: _m52.writeXlsx, writeXlsxTo: _m52.writeXlsxTo, writeGroupedXlsx: _m54.writeGroupedXlsx, writeGroupedXlsxTo: _m54.writeGroupedXlsxTo, addGroupedXlsx: _m54.addGroupedXlsx, createGroupedReport: _m8.createGroupedReport, Worksheet: _m38.Worksheet, Cell: _m35.Cell, FormulaCell: _m36.FormulaCell, StyleRegistry: _m32.StyleRegistry, NumberFormats: _m32.NumberFormats, saveBlob: _m1.saveBlob, ExportCell: _m5.ExportCell });
5825
+ _modules.set("d6587a933b36ccfdba9a2a252389924ac8461f672b3a500082cceb5e53c8b0b6", _exports);
5750
5826
  return _exports;
5751
5827
  })();
5752
5828
 
5753
- const _m56 = _modules.get("2f5c0823847e9209017d01b2a753f36056df2a9988fae1f3a1bd5fd186545220") ?? (() => {
5829
+ const _m57 = _modules.get("2f5c0823847e9209017d01b2a753f36056df2a9988fae1f3a1bd5fd186545220") ?? (() => {
5754
5830
  const { captureTableSpans, tableSpans } = _m18;
5755
5831
 
5756
5832
  /** Snapshot small report matrices; flattening is an explicit format decision, never inferred from labels. */
@@ -5772,7 +5848,7 @@ _modules.set("2f5c0823847e9209017d01b2a753f36056df2a9988fae1f3a1bd5fd186545220",
5772
5848
  return _exports;
5773
5849
  })();
5774
5850
 
5775
- const _m55 = _modules.get("b6dbf755b495baef5c7d7651e6a55b2098f2ee304edca2c8b285a0bd7ec127a1") ?? (() => {
5851
+ const _m56 = _modules.get("b48bcab805d4c75294dd8d8e8dc57f96d9db3f5af31a8f0ddc6562f010f566e4") ?? (() => {
5776
5852
  const { beginTask, checkAbort, consumeRows, taskYieldDue, withAbort } = _m4;
5777
5853
 
5778
5854
  const { BlobByteSink, ChunkedTextSink, withDestination } = _m3;
@@ -5787,7 +5863,7 @@ const { notifyProgress } = _m14;
5787
5863
 
5788
5864
  const { copyColumns, createRowProjector } = _m11;
5789
5865
 
5790
- const { csvStructuredRows } = _m56;
5866
+ const { csvStructuredRows } = _m57;
5791
5867
 
5792
5868
  const { captureBooleanText } = _m21;
5793
5869
 
@@ -5797,29 +5873,32 @@ const { captureCsvOptions } = _m16;
5797
5873
 
5798
5874
 
5799
5875
 
5800
- function csvField(value, delimiter, protect, quote, booleanText, nullValue) {
5801
- if (value == null && nullValue !== undefined)
5802
- value = nullValue;
5876
+ function csvField(value, delimiter, protect, quote, booleanText) {
5877
+ const kind = typeof value;
5803
5878
  let text;
5804
5879
  if (value == null)
5805
5880
  text = "";
5881
+ else if (kind === "string")
5882
+ text = value;
5883
+ else if (kind === "number") {
5884
+ text = Number.isFinite(value) ? String(value) : "";
5885
+ // Numeric text has no CSV delimiter, quote or line break to escape.
5886
+ return quote === "all" ? '"' + text + '"' : text;
5887
+ }
5888
+ else if (kind === "boolean")
5889
+ text = booleanText[value ? "true" : "false"];
5806
5890
  else if (isDate(value))
5807
5891
  text = Number.isFinite(value.getTime()) ? value.toISOString() : "";
5808
- else if (typeof value === "boolean")
5809
- text = booleanText[value ? "true" : "false"];
5810
- else if (typeof value === "number")
5811
- text = Number.isFinite(value) ? String(value) : "";
5812
- else if (typeof value === "string")
5813
- text = value;
5814
5892
  else {
5815
5893
  if (typeof value.then === "function")
5816
5894
  void Promise.resolve(value).catch(() => { });
5817
5895
  throw new TypeError("CSV cells and formatter results must be synchronous strings, numbers, booleans, Dates or null.");
5818
5896
  }
5819
- if (protect && (typeof value === "string" || typeof value === "boolean") && /^ *[=+\-@\t\r\n]/.test(text))
5897
+ // Only ASCII spaces, controls and markers through @ can begin the protected prefix.
5898
+ if (protect && (kind === "string" || kind === "boolean") && text.charCodeAt(0) <= 64 && /^ *[=+\-@\t\r\n]/.test(text))
5820
5899
  text = "'" + text;
5821
- return quote === "all" || (quote === "strings" && typeof value === "string") || text.includes(delimiter) || /["\r\n]/.test(text)
5822
- ? '"' + text.replace(/"/g, '""') + '"' : text;
5900
+ return quote === "all" || (quote === "strings" && kind === "string") || text.includes(delimiter) || /["\r\n]/.test(text)
5901
+ ? '"' + (text.includes('"') ? text.replace(/"/g, '""') : text) + '"' : text;
5823
5902
  }
5824
5903
  async function writeCsvTo(rows, destination, configuration) {
5825
5904
  const options = captureCsvOptions(configuration);
@@ -5871,7 +5950,7 @@ async function write(rows, sink, options) {
5871
5950
  value = options.nullValue;
5872
5951
  budget.cell(typeof value === "boolean" ? booleanText[value ? "true" : "false"] : value);
5873
5952
  checkAbort(signal);
5874
- text += (i ? delimiter : "") + csvField(value, delimiter, protect, quote, booleanText, options.nullValue);
5953
+ text += (i ? delimiter : "") + csvField(value, delimiter, protect, quote, booleanText);
5875
5954
  if (text.length >= buffer.chunkSize || (i & 127) === 127 && taskYieldDue()) {
5876
5955
  if (buffer.append(text))
5877
5956
  return buffer.flush().then(() => record(values, header, i + 1, snapshot));
@@ -5919,11 +5998,11 @@ async function writeCsv(rows, configuration) {
5919
5998
  }
5920
5999
  }
5921
6000
  const _exports = Object.freeze({ saveBlob: _m1.saveBlob, ExportCell: _m5.ExportCell, writeCsvTo: writeCsvTo, writeCsv: writeCsv });
5922
- _modules.set("b6dbf755b495baef5c7d7651e6a55b2098f2ee304edca2c8b285a0bd7ec127a1", _exports);
6001
+ _modules.set("b48bcab805d4c75294dd8d8e8dc57f96d9db3f5af31a8f0ddc6562f010f566e4", _exports);
5923
6002
  return _exports;
5924
6003
  })();
5925
6004
 
5926
- const _m61 = _modules.get("e3d39f39aebcbaf063fd8221df0d9cb5902ad2545a9d9e474bb59d47f15e2c01") ?? (() => {
6005
+ const _m62 = _modules.get("e3d39f39aebcbaf063fd8221df0d9cb5902ad2545a9d9e474bb59d47f15e2c01") ?? (() => {
5927
6006
  /** @internal One type byte, an eight-byte offset/container number and a two-byte generation/index. */
5928
6007
  const pdfXrefEntryBytes = 11;
5929
6008
  function unsigned(bytes, offset, value, width) {
@@ -5959,12 +6038,12 @@ _modules.set("e3d39f39aebcbaf063fd8221df0d9cb5902ad2545a9d9e474bb59d47f15e2c01",
5959
6038
  return _exports;
5960
6039
  })();
5961
6040
 
5962
- const _m60 = _modules.get("e716b8b1da464094622f5f671518493c78e63ff22a029d61544d2d193b63ce8f") ?? (() => {
6041
+ const _m61 = _modules.get("e716b8b1da464094622f5f671518493c78e63ff22a029d61544d2d193b63ce8f") ?? (() => {
5963
6042
  const { checkAbort, withAbort, pause, taskYieldDue } = _m4;
5964
6043
 
5965
6044
  const { OfficeIMOError } = _m2;
5966
6045
 
5967
- const { pdfXrefChunks, pdfXrefEntryBytes } = _m61;
6046
+ const { pdfXrefChunks, pdfXrefEntryBytes } = _m62;
5968
6047
 
5969
6048
  const compactObjectCount = 256, compactObjectBytes = 32768;
5970
6049
  const compactIndexChunkEntries = 4096;
@@ -6288,7 +6367,7 @@ _modules.set("e716b8b1da464094622f5f671518493c78e63ff22a029d61544d2d193b63ce8f",
6288
6367
  return _exports;
6289
6368
  })();
6290
6369
 
6291
- const _m65 = _modules.get("1e169e6ecdeceff319b5da4bf01f4c653c1a3d9e8ad696b141bf8ac52d9f446c") ?? (() => {
6370
+ const _m66 = _modules.get("1e169e6ecdeceff319b5da4bf01f4c653c1a3d9e8ad696b141bf8ac52d9f446c") ?? (() => {
6292
6371
  /** @internal Bounded big-endian reader used for caller-provided TrueType programs. */
6293
6372
  class FontReader {
6294
6373
  bytes;
@@ -6318,8 +6397,8 @@ _modules.set("1e169e6ecdeceff319b5da4bf01f4c653c1a3d9e8ad696b141bf8ac52d9f446c",
6318
6397
  return _exports;
6319
6398
  })();
6320
6399
 
6321
- const _m66 = _modules.get("ecf6c6ab2f9c5f747338d0d59d9f2cae0b006d9d2a210bcb1545db1f046eb80c") ?? (() => {
6322
- const { align4 } = _m65;
6400
+ const _m67 = _modules.get("ecf6c6ab2f9c5f747338d0d59d9f2cae0b006d9d2a210bcb1545db1f046eb80c") ?? (() => {
6401
+ const { align4 } = _m66;
6323
6402
 
6324
6403
  const { checkAbort, pause, taskYieldDue } = _m4;
6325
6404
 
@@ -6543,12 +6622,12 @@ _modules.set("ecf6c6ab2f9c5f747338d0d59d9f2cae0b006d9d2a210bcb1545db1f046eb80c",
6543
6622
  return _exports;
6544
6623
  })();
6545
6624
 
6546
- const _m64 = _modules.get("2e1fa1582af797386e2e2914c0a27237309b1692a3cc2be688f46590eb74480d") ?? (() => {
6625
+ const _m65 = _modules.get("2e1fa1582af797386e2e2914c0a27237309b1692a3cc2be688f46590eb74480d") ?? (() => {
6547
6626
  const { NotSupportedError } = _m2;
6548
6627
 
6549
- const { FontReader } = _m65;
6628
+ const { FontReader } = _m66;
6550
6629
 
6551
- const { subsetTrueType, subsetTrueTypeCooperatively } = _m66;
6630
+ const { subsetTrueType, subsetTrueTypeCooperatively } = _m67;
6552
6631
 
6553
6632
  const { checkAbort, pause, taskYieldDue } = _m4;
6554
6633
 
@@ -6788,8 +6867,8 @@ _modules.set("2e1fa1582af797386e2e2914c0a27237309b1692a3cc2be688f46590eb74480d",
6788
6867
  return _exports;
6789
6868
  })();
6790
6869
 
6791
- const _m63 = _modules.get("d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596") ?? (() => {
6792
- const { TrueTypeFont } = _m64;
6870
+ const _m64 = _modules.get("d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596") ?? (() => {
6871
+ const { TrueTypeFont } = _m65;
6793
6872
 
6794
6873
  const { beginTask, checkAbort } = _m4;
6795
6874
 
@@ -6852,7 +6931,7 @@ _modules.set("d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596",
6852
6931
  return _exports;
6853
6932
  })();
6854
6933
 
6855
- const _m68 = _modules.get("1ed4965a6e2963a91190baa8a58ada8ce0edde8fe653bcb6609002e872af0d61") ?? (() => {
6934
+ const _m69 = _modules.get("1ed4965a6e2963a91190baa8a58ada8ce0edde8fe653bcb6609002e872af0d61") ?? (() => {
6856
6935
  // Generated by scripts/pdf-widths.mjs from OfficeIMO.Pdf's Adobe AFM-derived metrics.
6857
6936
  const helveticaWidths = new Map([
6858
6937
  [32, [278, 278]],
@@ -7175,12 +7254,12 @@ _modules.set("1ed4965a6e2963a91190baa8a58ada8ce0edde8fe653bcb6609002e872af0d61",
7175
7254
  return _exports;
7176
7255
  })();
7177
7256
 
7178
- const _m67 = _modules.get("59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070") ?? (() => {
7257
+ const _m68 = _modules.get("59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070") ?? (() => {
7179
7258
  const { OfficeIMOError } = _m2;
7180
7259
 
7181
- const { PdfFont, fontProgram } = _m63;
7260
+ const { PdfFont, fontProgram } = _m64;
7182
7261
 
7183
- const { helveticaWidths } = _m68;
7262
+ const { helveticaWidths } = _m69;
7184
7263
 
7185
7264
  const winAnsiExtras = new Map([0x20ac, 0, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0x160, 0x2039, 0x152, 0, 0x17d, 0, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122, 0x161, 0x203a, 0x153, 0, 0x17e, 0x178].map((cp, i) => [cp, i + 128]));
7186
7265
  /** @internal Called after scalar support succeeds when encoding a standard-font run. */
@@ -7244,18 +7323,19 @@ _modules.set("59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070",
7244
7323
  return _exports;
7245
7324
  })();
7246
7325
 
7247
- const _m62 = _modules.get("7da602b40c346a3838e75963f9a3f10c95ac5ce08a7b0a23b9d96f8898a01db7") ?? (() => {
7326
+ const _m63 = _modules.get("4d4736e6b8e2aaecc6f6c1b124b7e6bc0a5e141dcc725edf0ad4847d87fca1b3") ?? (() => {
7248
7327
  const { NotSupportedError, OfficeIMOError } = _m2;
7249
7328
 
7250
- const { fontProgram } = _m63;
7329
+ const { fontProgram } = _m64;
7251
7330
 
7252
- const { resolveScalar, selectFont, standardCode, validateFonts } = _m67;
7331
+ const { resolveScalar, selectFont, standardCode, validateFonts } = _m68;
7253
7332
 
7254
- const { pdfNumber, unicodeHex } = _m60;
7333
+ const { pdfNumber, unicodeHex } = _m61;
7255
7334
 
7256
7335
  const { checkAbort, pause, taskYieldDue } = _m4;
7257
7336
 
7258
- const standardHexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
7337
+ const hexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
7338
+ function cidHex(cid) { return hexBytes[cid >>> 8] + hexBytes[cid & 255]; }
7259
7339
  class PdfFontResource {
7260
7340
  index;
7261
7341
  bold;
@@ -7286,12 +7366,16 @@ class PdfFontResource {
7286
7366
  width(scalar) {
7287
7367
  if (this.shared)
7288
7368
  return this.shared.width(scalar);
7289
- const existing = this.mappings.get(scalar);
7290
- if (existing)
7291
- return existing.width;
7292
- const standard = this.standardWidths.get(scalar);
7293
- if (standard !== undefined)
7294
- return standard;
7369
+ if (this.program) {
7370
+ const existing = this.mappings.get(scalar);
7371
+ if (existing)
7372
+ return existing.width;
7373
+ }
7374
+ else {
7375
+ const standard = this.standardWidths.get(scalar);
7376
+ if (standard !== undefined)
7377
+ return standard;
7378
+ }
7295
7379
  const resolved = resolveScalar(scalar, this.program, this.bold);
7296
7380
  if (!resolved.supported) {
7297
7381
  if (resolved.code === "unpaired-surrogate")
@@ -7304,7 +7388,8 @@ class PdfFontResource {
7304
7388
  }
7305
7389
  if (this.mappings.size >= 65535)
7306
7390
  throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct Unicode scalars.");
7307
- const mapping = { cid: this.mappings.size + 1, glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
7391
+ const cid = this.mappings.size + 1;
7392
+ const mapping = { cid, hex: cidHex(cid), glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
7308
7393
  this.mappings.set(scalar, mapping);
7309
7394
  return mapping.width;
7310
7395
  }
@@ -7317,8 +7402,20 @@ class PdfFontResource {
7317
7402
  let hex = "";
7318
7403
  for (const char of text) {
7319
7404
  const cp = char.codePointAt(0);
7320
- this.width(cp);
7321
- hex += this.program ? this.mappings.get(cp).cid.toString(16).padStart(4, "0") : standardHexBytes[standardCode(cp)];
7405
+ if (this.program) {
7406
+ let mapping = this.mappings.get(cp);
7407
+ // Layout normally registered the scalar already; validate only a newly painted scalar.
7408
+ if (!mapping) {
7409
+ this.width(cp);
7410
+ mapping = this.mappings.get(cp);
7411
+ }
7412
+ hex += mapping.hex;
7413
+ }
7414
+ else {
7415
+ if (!this.standardWidths.has(cp))
7416
+ this.width(cp);
7417
+ hex += hexBytes[standardCode(cp)];
7418
+ }
7322
7419
  }
7323
7420
  return "<" + hex + ">";
7324
7421
  }
@@ -7333,10 +7430,11 @@ class PdfFontResource {
7333
7430
  if (!mapping) {
7334
7431
  if (this.mappings.size >= 65535)
7335
7432
  throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct CID mappings.");
7336
- mapping = { cid: this.mappings.size + 1, glyph, width: this.program.widths[glyph], text };
7433
+ const cid = this.mappings.size + 1;
7434
+ mapping = { cid, hex: cidHex(cid), glyph, width: this.program.widths[glyph], text };
7337
7435
  this.mappings.set(key, mapping);
7338
7436
  }
7339
- return "<" + mapping.cid.toString(16).padStart(4, "0") + ">";
7437
+ return "<" + mapping.hex + ">";
7340
7438
  }
7341
7439
  async write(objects, compression) {
7342
7440
  checkAbort(this.signal);
@@ -7385,7 +7483,7 @@ class PdfFontResource {
7385
7483
  const batch = mapped.slice(i, i + 100);
7386
7484
  cmap += batch.length + " beginbfchar\n";
7387
7485
  for (const [, m] of batch)
7388
- cmap += "<" + m.cid.toString(16).padStart(4, "0") + "> <" + unicodeHex(m.text) + ">\n";
7486
+ cmap += "<" + m.hex + "> <" + unicodeHex(m.text) + ">\n";
7389
7487
  cmap += "endbfchar\n";
7390
7488
  if (taskYieldDue())
7391
7489
  await pause();
@@ -7436,7 +7534,7 @@ class PdfFontResources {
7436
7534
  if (!found)
7437
7535
  this.explicitSelections.set(explicit, selections);
7438
7536
  }
7439
- const key = String(bold) + String(italic), existing = selections.get(key);
7537
+ const key = (bold ? 2 : 0) | (italic ? 1 : 0), existing = selections.get(key);
7440
7538
  if (existing)
7441
7539
  return existing;
7442
7540
  const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } : selectFont(this.fonts, bold, italic);
@@ -7453,11 +7551,11 @@ class PdfFontResources {
7453
7551
  dictionary() { return "<< " + this.resources.map(f => "/" + f.name + " " + f.object + " 0 R").join(" ") + " >>"; }
7454
7552
  }
7455
7553
  const _exports = Object.freeze({ PdfFontResource: PdfFontResource, PdfFontResources: PdfFontResources });
7456
- _modules.set("7da602b40c346a3838e75963f9a3f10c95ac5ce08a7b0a23b9d96f8898a01db7", _exports);
7554
+ _modules.set("4d4736e6b8e2aaecc6f6c1b124b7e6bc0a5e141dcc725edf0ad4847d87fca1b3", _exports);
7457
7555
  return _exports;
7458
7556
  })();
7459
7557
 
7460
- const _m70 = _modules.get("253db2c0eab1f298fda61fb40a5ddaacbf6ad12a7408ee3d8c12d27f88e7ca27") ?? (() => {
7558
+ const _m71 = _modules.get("253db2c0eab1f298fda61fb40a5ddaacbf6ad12a7408ee3d8c12d27f88e7ca27") ?? (() => {
7461
7559
  const { OfficeIMOError } = _m2;
7462
7560
 
7463
7561
  const { ExportCell, assertExportValue } = _m5;
@@ -7569,7 +7667,7 @@ _modules.set("253db2c0eab1f298fda61fb40a5ddaacbf6ad12a7408ee3d8c12d27f88e7ca27",
7569
7667
  return _exports;
7570
7668
  })();
7571
7669
 
7572
- const _m72 = _modules.get("8be3fb029e08d100ce8ffcf50916d5ba7f7bc00d62156cc33815fd58554a9ed6") ?? (() => {
7670
+ const _m73 = _modules.get("8be3fb029e08d100ce8ffcf50916d5ba7f7bc00d62156cc33815fd58554a9ed6") ?? (() => {
7573
7671
  const { NotSupportedError, OfficeIMOError } = _m2;
7574
7672
 
7575
7673
  const { checkAbort, pause, taskYieldDue, withAbort } = _m4;
@@ -7782,7 +7880,7 @@ _modules.set("8be3fb029e08d100ce8ffcf50916d5ba7f7bc00d62156cc33815fd58554a9ed6",
7782
7880
  return _exports;
7783
7881
  })();
7784
7882
 
7785
- const _m71 = _modules.get("0a1c79b51ac9a164b86197239117df6497f45ca2892b423b1ec77a663ccc1c47") ?? (() => {
7883
+ const _m72 = _modules.get("0a1c79b51ac9a164b86197239117df6497f45ca2892b423b1ec77a663ccc1c47") ?? (() => {
7786
7884
  const { NotSupportedError, OfficeIMOError } = _m2;
7787
7885
 
7788
7886
  const { copyExportLink } = _m7;
@@ -7791,11 +7889,11 @@ const { checkAbort, pause, taskYieldDue } = _m4;
7791
7889
 
7792
7890
  const { presentation, color } = _m17;
7793
7891
 
7794
- const { wrapShapedPdfText } = _m72;
7892
+ const { wrapShapedPdfText } = _m73;
7795
7893
 
7796
- const { PdfFont } = _m63;
7894
+ const { PdfFont } = _m64;
7797
7895
 
7798
- const { pdfBudgetText } = _m70;
7896
+ const { pdfBudgetText } = _m71;
7799
7897
 
7800
7898
  /** @internal Callers supply an owned, validated, frozen base presentation. A run list is a PDF presentation value, never an alternate shared table value model. */
7801
7899
  function capturePdfText(value, base, settings, fonts, countEmpty = true, reserveBudget = true) {
@@ -7978,10 +8076,10 @@ _modules.set("0a1c79b51ac9a164b86197239117df6497f45ca2892b423b1ec77a663ccc1c47",
7978
8076
  return _exports;
7979
8077
  })();
7980
8078
 
7981
- const _m73 = _modules.get("9a88773878eacc51df9f05bb5ee90cc2b683b083ebea8fb54375092301388e96") ?? (() => {
8079
+ const _m74 = _modules.get("2f40af05ba09102fe440c1d46385b64cecdd233371771796c9ae4e8d523f2cea") ?? (() => {
7982
8080
  const { OfficeIMOError } = _m2;
7983
8081
 
7984
- const { wrapPdfText } = _m71;
8082
+ const { wrapPdfText } = _m72;
7985
8083
 
7986
8084
  /** Plan without opening a source. Exact column widths never shrink in band mode. */
7987
8085
  function planTableBands(widths, settings) {
@@ -8026,6 +8124,14 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
8026
8124
  for (const row of rows) {
8027
8125
  const cells = [];
8028
8126
  for (const cell of row.cells) {
8127
+ // Ordinary data and leaf headings keep their captured width and lines in every band.
8128
+ // Look up their physical position without allocating another per-row column index.
8129
+ if (cell.span === 1) {
8130
+ const first = band.columns.indexOf(cell.first);
8131
+ if (first >= 0)
8132
+ cells.push({ ...cell, source: cell.source ?? cell, first });
8133
+ continue;
8134
+ }
8029
8135
  for (let first = 0; first < band.columns.length;) {
8030
8136
  const source = band.columns[first];
8031
8137
  if (source < cell.first || source >= cell.first + cell.span) {
@@ -8036,7 +8142,7 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
8036
8142
  while (end < band.columns.length && band.columns[end] === band.columns[end - 1] + 1 && band.columns[end] < cell.first + cell.span)
8037
8143
  end++;
8038
8144
  const width = band.columns.slice(first, end).reduce((sum, index) => sum + widths[index], 0);
8039
- const lines = cell.span === 1 ? cell.lines : await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
8145
+ const lines = await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
8040
8146
  cells.push({ ...cell, source: cell.source ?? cell, first, span: end - first, width, lines,
8041
8147
  lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), cell.font.lineHeight(settings.fontSize)) });
8042
8148
  first = end;
@@ -8065,11 +8171,11 @@ function alignBandBlocks(bands, settings) {
8065
8171
  cells: row.cells.map(cell => ({ ...cell, height: heights.slice(index, index + (cell.rowSpan ?? 1)).reduce((sum, value) => sum + value, 0) })) })));
8066
8172
  }
8067
8173
  const _exports = Object.freeze({ planTableBands: planTableBands, projectBandRows: projectBandRows, alignBandBlocks: alignBandBlocks });
8068
- _modules.set("9a88773878eacc51df9f05bb5ee90cc2b683b083ebea8fb54375092301388e96", _exports);
8174
+ _modules.set("2f40af05ba09102fe440c1d46385b64cecdd233371771796c9ae4e8d523f2cea", _exports);
8069
8175
  return _exports;
8070
8176
  })();
8071
8177
 
8072
- const _m69 = _modules.get("07d2da8d8b93f12f172a48b97c1807e485555cf608e2eaa5b7610aa91d4a5305") ?? (() => {
8178
+ const _m70 = _modules.get("ad81357e627d3100e1068a8ce521aa1c1cd65de5c6c6ab36f807a3e5da50d874") ?? (() => {
8073
8179
  const { ExportCell } = _m5;
8074
8180
 
8075
8181
  const { copyExportLink } = _m7;
@@ -8080,11 +8186,11 @@ const { createTotals } = _m12;
8080
8186
 
8081
8187
  const { presentation, positive } = _m17;
8082
8188
 
8083
- const { displayText, pdfBudgetText } = _m70;
8189
+ const { displayText, pdfBudgetText } = _m71;
8084
8190
 
8085
- const { capturePdfText, wrapPdfText } = _m71;
8191
+ const { capturePdfText, wrapPdfText } = _m72;
8086
8192
 
8087
- const { planTableBands, projectBandRows, alignBandBlocks } = _m73;
8193
+ const { planTableBands, projectBandRows, alignBandBlocks } = _m74;
8088
8194
 
8089
8195
  class PdfTableLayout {
8090
8196
  settings;
@@ -8189,8 +8295,12 @@ class PdfTableLayout {
8189
8295
  lines };
8190
8296
  }
8191
8297
  row(cells) {
8192
- const lines = Math.max(1, ...cells.map(c => c.lines.length));
8193
- const lineHeight = Math.max(this.lineHeight, ...cells.map(c => c.lineHeight));
8298
+ let lines = 1, lineHeight = this.lineHeight;
8299
+ for (let index = 0; index < cells.length; index++) {
8300
+ const cell = cells[index];
8301
+ lines = Math.max(lines, cell.lines.length);
8302
+ lineHeight = Math.max(lineHeight, cell.lineHeight);
8303
+ }
8194
8304
  return { cells, lines, lineHeight, height: lines * lineHeight + this.settings.padding * 2 };
8195
8305
  }
8196
8306
  async headers() {
@@ -8296,11 +8406,11 @@ class PdfTableLayout {
8296
8406
  }
8297
8407
  }
8298
8408
  const _exports = Object.freeze({ PdfTableLayout: PdfTableLayout });
8299
- _modules.set("07d2da8d8b93f12f172a48b97c1807e485555cf608e2eaa5b7610aa91d4a5305", _exports);
8409
+ _modules.set("ad81357e627d3100e1068a8ce521aa1c1cd65de5c6c6ab36f807a3e5da50d874", _exports);
8300
8410
  return _exports;
8301
8411
  })();
8302
8412
 
8303
- const _m75 = _modules.get("67ad5f4adbd6bc0dddafe5cf82638d46d150237f4ff0bee15c0ace652d5095f4") ?? (() => {
8413
+ const _m76 = _modules.get("9ea74d93c18250e809a7be745444b886bcd5ec924a78e6ab004d649789db1f72") ?? (() => {
8304
8414
  const { OfficeIMOError } = _m2;
8305
8415
 
8306
8416
  const { checkAbort } = _m4;
@@ -8344,7 +8454,7 @@ class PdfTableBandFlow {
8344
8454
  await this.flush();
8345
8455
  }
8346
8456
  async row(row, allowFirstFragment = false) {
8347
- const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
8457
+ const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = minimumLines * row.lineHeight + padding * 2;
8348
8458
  if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
8349
8459
  throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
8350
8460
  // Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
@@ -8378,9 +8488,14 @@ class PdfTableBandFlow {
8378
8488
  let remaining = false;
8379
8489
  const cells = rows[0].cells.map(cell => {
8380
8490
  const source = this.layout.bands[index].columns[cell.first];
8381
- const repeated = this.layout.repeatedColumn(source), visible = repeated ? cell.lines : cell.lines.slice(first, first + lines);
8491
+ const repeated = this.layout.repeatedColumn(source), reusable = cell.span === 1 && (cell.source?.span ?? 1) === 1 && (cell.rowSpan ?? 1) === 1 &&
8492
+ cell.height === undefined && first === 0 && (repeated || lines >= cell.lines.length);
8493
+ const visible = repeated || reusable ? cell.lines : cell.lines.slice(first, first + lines);
8382
8494
  if (!repeated && (visible.length > 0 || cell.link !== undefined))
8383
8495
  remaining = true;
8496
+ // A complete first fragment already owns these lines and their maximum font metrics.
8497
+ if (reusable)
8498
+ return cell;
8384
8499
  const { height: _height, ...plain } = cell;
8385
8500
  return { ...plain, lines: visible,
8386
8501
  lineHeight: visible.reduce((value, line) => Math.max(value, line.lineHeight), cell.font.lineHeight(fontSize)),
@@ -8433,11 +8548,11 @@ class PdfTableBandFlow {
8433
8548
  }
8434
8549
  }
8435
8550
  const _exports = Object.freeze({ PdfTableBandFlow: PdfTableBandFlow });
8436
- _modules.set("67ad5f4adbd6bc0dddafe5cf82638d46d150237f4ff0bee15c0ace652d5095f4", _exports);
8551
+ _modules.set("9ea74d93c18250e809a7be745444b886bcd5ec924a78e6ab004d649789db1f72", _exports);
8437
8552
  return _exports;
8438
8553
  })();
8439
8554
 
8440
- const _m76 = _modules.get("b52424ed74721dce3a2621456888fe1c6af0490627063e56f690df9abcb1dfff") ?? (() => {
8555
+ const _m77 = _modules.get("9deed79565a5da5009f7a01579df8d6a3f019b78eb7b17d831c7964840e9a6bf") ?? (() => {
8441
8556
  /** @internal Source-cell identities survive page fragments and horizontal band projections.
8442
8557
  * Only column headers and still-owned row objects remain reachable from this table owner. */
8443
8558
  class PdfTableStructure {
@@ -8489,30 +8604,31 @@ class PdfTableStructure {
8489
8604
  return row.cells.map(cell => this.cells.get(cell));
8490
8605
  const rowId = this.structure.element("TR", parent);
8491
8606
  this.rows.set(row, rowId);
8492
- const headers = row.cells.map((cell, index) => rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex);
8493
8607
  // Allocate in source order, then resolve every row header before associating even earlier data cells.
8494
8608
  // Generated summary labels override detail roles so numeric subtotal cells never become row headers.
8495
8609
  const ids = row.cells.map((cell, index) => {
8496
- const id = this.structure.element(headers[index] ? "TH" : "TD", rowId);
8610
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
8611
+ const id = this.structure.element(header ? "TH" : "TD", rowId);
8497
8612
  this.cells.set(cell, id);
8498
8613
  return id;
8499
8614
  });
8500
- const rowHeaders = [];
8615
+ let rowHeaders;
8501
8616
  for (let index = 0; index < ids.length; index++)
8502
- if (headers[index])
8503
- rowHeaders.push(await this.structure.identifier(ids[index]));
8617
+ if (rowHeaderIndex === undefined ? row.cells[index].rowHeader === true : index === rowHeaderIndex)
8618
+ (rowHeaders ??= []).push(await this.structure.identifier(ids[index]));
8504
8619
  for (let index = 0; index < row.cells.length; index++) {
8505
8620
  const cell = row.cells[index];
8506
- if (!rowHeaders.length && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
8621
+ if (!rowHeaders && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
8507
8622
  const attributes = this.ordinaryAttributes[cell.first] ??=
8508
8623
  await this.structure.attributeReference(this.attributeDictionary(cell, this.associations(cell)));
8509
8624
  this.structure.setAttributes(ids[index], attributes);
8510
8625
  continue;
8511
8626
  }
8512
8627
  const associations = this.associations(cell);
8513
- if (!headers[index])
8628
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
8629
+ if (!header && rowHeaders)
8514
8630
  associations.push(...rowHeaders);
8515
- this.structure.setAttributes(ids[index], this.attributes(cell, associations, headers[index] ? "Row" : undefined));
8631
+ this.structure.setAttributes(ids[index], this.attributes(cell, associations, header ? "Row" : undefined));
8516
8632
  }
8517
8633
  return ids;
8518
8634
  }
@@ -8547,14 +8663,14 @@ class PdfTableStructure {
8547
8663
  }
8548
8664
  }
8549
8665
  const _exports = Object.freeze({ PdfTableStructure: PdfTableStructure });
8550
- _modules.set("b52424ed74721dce3a2621456888fe1c6af0490627063e56f690df9abcb1dfff", _exports);
8666
+ _modules.set("9deed79565a5da5009f7a01579df8d6a3f019b78eb7b17d831c7964840e9a6bf", _exports);
8551
8667
  return _exports;
8552
8668
  })();
8553
8669
 
8554
- const _m77 = _modules.get("09c712096a1028af340e275d5a273e870546413797e71ed709657ad0482ea170") ?? (() => {
8670
+ const _m78 = _modules.get("09c712096a1028af340e275d5a273e870546413797e71ed709657ad0482ea170") ?? (() => {
8555
8671
  const { OfficeIMOError } = _m2;
8556
8672
 
8557
- const { pdfNumber, unicodeHex } = _m60;
8673
+ const { pdfNumber, unicodeHex } = _m61;
8558
8674
 
8559
8675
  const encoder = new TextEncoder();
8560
8676
  /** @internal URI actions are byte strings; tooltips are Unicode PDF text strings. */
@@ -8597,10 +8713,10 @@ _modules.set("09c712096a1028af340e275d5a273e870546413797e71ed709657ad0482ea170",
8597
8713
  return _exports;
8598
8714
  })();
8599
8715
 
8600
- const _m78 = _modules.get("c68d18d668366fb9b96d1b53c79dc6305f84cb83c05e4942fcf1cdf96ed1a73f") ?? (() => {
8716
+ const _m79 = _modules.get("c68d18d668366fb9b96d1b53c79dc6305f84cb83c05e4942fcf1cdf96ed1a73f") ?? (() => {
8601
8717
  const { OfficeIMOError } = _m2;
8602
8718
 
8603
- const { unicodeHex } = _m60;
8719
+ const { unicodeHex } = _m61;
8604
8720
 
8605
8721
  const { captureFields } = _m10;
8606
8722
 
@@ -8646,7 +8762,7 @@ _modules.set("c68d18d668366fb9b96d1b53c79dc6305f84cb83c05e4942fcf1cdf96ed1a73f",
8646
8762
  return _exports;
8647
8763
  })();
8648
8764
 
8649
- const _m79 = _modules.get("a66257a32f03d958aa57be4de9da7f80b708cebca26b5cc6404de0ee11bfe052") ?? (() => {
8765
+ const _m80 = _modules.get("a66257a32f03d958aa57be4de9da7f80b708cebca26b5cc6404de0ee11bfe052") ?? (() => {
8650
8766
  const { settings } = _m17;
8651
8767
 
8652
8768
  /** @internal Every section derives from captured document defaults, never the preceding section. */
@@ -8665,28 +8781,28 @@ _modules.set("a66257a32f03d958aa57be4de9da7f80b708cebca26b5cc6404de0ee11bfe052",
8665
8781
  return _exports;
8666
8782
  })();
8667
8783
 
8668
- const _m74 = _modules.get("a7fca40cb8c75af206111c90db36839b4648982beeb4179efda0ddd1ee366210") ?? (() => {
8784
+ const _m75 = _modules.get("3ed7114181be5a3066742336da574fef7f2fc04ee6dfc5e64211f3bedad4cab9") ?? (() => {
8669
8785
  const { OfficeIMOError } = _m2;
8670
8786
 
8671
8787
  const { checkAbort } = _m4;
8672
8788
 
8673
- const { pdfNumber } = _m60;
8789
+ const { pdfNumber } = _m61;
8674
8790
 
8675
8791
  const { color } = _m17;
8676
8792
 
8677
- const { PdfTableBandFlow } = _m75;
8793
+ const { PdfTableBandFlow } = _m76;
8678
8794
 
8679
- const { PdfTableStructure } = _m76;
8795
+ const { PdfTableStructure } = _m77;
8680
8796
 
8681
- const { wrapText, wrapTextCooperatively, synchronousText, pdfBudgetText } = _m70;
8797
+ const { wrapText, wrapTextCooperatively, synchronousText, pdfBudgetText } = _m71;
8682
8798
 
8683
- const { linkAnnotation } = _m77;
8799
+ const { linkAnnotation } = _m78;
8684
8800
 
8685
- const { unicodeHex } = _m60;
8801
+ const { unicodeHex } = _m61;
8686
8802
 
8687
- const { captureSection, captureBookmark } = _m78;
8803
+ const { captureSection, captureBookmark } = _m79;
8688
8804
 
8689
- const { sectionSettings } = _m79;
8805
+ const { sectionSettings } = _m80;
8690
8806
 
8691
8807
  /** @internal One page of drawing commands and O(page count) references, never the complete report body. */
8692
8808
  class PdfPages {
@@ -8700,7 +8816,8 @@ class PdfPages {
8700
8816
  outlines;
8701
8817
  references = [];
8702
8818
  current = 0;
8703
- commands = [];
8819
+ commands = "";
8820
+ commandParts = [];
8704
8821
  commandBytes = 0;
8705
8822
  annotations = [];
8706
8823
  hyperlinks = 0;
@@ -8718,6 +8835,12 @@ class PdfPages {
8718
8835
  pendingBookmarks = [];
8719
8836
  pageNumberWidth = 0;
8720
8837
  colors = new Map();
8838
+ textFont;
8839
+ textSize = 0;
8840
+ textColor = "";
8841
+ textPrefix = "";
8842
+ rectangleLefts;
8843
+ rectangleColumns = [];
8721
8844
  externalObjects = new Map();
8722
8845
  bandFlow;
8723
8846
  bandCellBudget = false;
@@ -8784,7 +8907,7 @@ class PdfPages {
8784
8907
  }
8785
8908
  add(command) {
8786
8909
  this.retainPageBytes(command.length);
8787
- this.commands.push(command);
8910
+ this.commands += command;
8788
8911
  }
8789
8912
  retainPageBytes(length) {
8790
8913
  this.commandBytes += length;
@@ -8804,9 +8927,17 @@ class PdfPages {
8804
8927
  return this.structure ? "/Artifact << /Type /" + type + " >> BDC\n" + command + "EMC\n" : command;
8805
8928
  }
8806
8929
  text(text, font, size, x, baseline, foreground = "111827", element) {
8807
- const n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
8808
- const command = "q " + this.rgb(foreground) + " rg " + this.rgb(foreground) + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
8809
- (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ") + "1 0 " + n(shear) + " 1 " + n(x) + " " + n(baseline) + " Tm " + font.encode(text) + " Tj ET Q\n";
8930
+ const n = pdfNumber;
8931
+ if (font !== this.textFont || size !== this.textSize || foreground !== this.textColor) {
8932
+ const shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(foreground);
8933
+ // Keep one prefix, independent of report size. Resource identity includes synthetic styling.
8934
+ this.textPrefix = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
8935
+ (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ") + "1 0 " + n(shear) + " 1 ";
8936
+ this.textFont = font;
8937
+ this.textSize = size;
8938
+ this.textColor = foreground;
8939
+ }
8940
+ const command = this.textPrefix + n(x) + " " + n(baseline) + " Tm " + font.encode(text) + " Tj ET Q\n";
8810
8941
  this.add(this.structure && element !== undefined ? this.structure.mark(element) + command + "EMC\n" : this.artifact(command, "Pagination"));
8811
8942
  }
8812
8943
  link(link, x, bottom, width, height, element) {
@@ -8836,8 +8967,8 @@ class PdfPages {
8836
8967
  for (const segment of line.segments) {
8837
8968
  const registered = marks?.get(segment), owner = registered?.owner ?? (segment.link && this.structure && element !== undefined ? this.structure.link(element, segment.link) : element);
8838
8969
  if (segment.glyphs) {
8839
- const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
8840
- let cursor = x, command = "q " + this.rgb(segment.color ?? "111827") + " rg " + this.rgb(segment.color ?? "111827") + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
8970
+ const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(segment.color ?? "111827");
8971
+ let cursor = x, command = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
8841
8972
  (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ");
8842
8973
  for (const glyph of segment.glyphs) {
8843
8974
  command += "1 0 " + n(shear) + " 1 " + n(cursor + (glyph.xOffset + shear * glyph.yOffset) * size / 1000) + " " + n(baseline + glyph.yOffset * size / 1000) + " Tm " + font.encodeGlyph(glyph.id, glyph.logicalText) + " Tj\n";
@@ -8885,7 +9016,8 @@ class PdfPages {
8885
9016
  this.current = this.objects.reserve();
8886
9017
  this.references.push(this.current);
8887
9018
  }
8888
- this.commands = [];
9019
+ this.commands = "";
9020
+ this.commandParts = [];
8889
9021
  this.annotations = [];
8890
9022
  this.commandBytes = 0;
8891
9023
  this.bodyAdded = false;
@@ -8968,15 +9100,32 @@ class PdfPages {
8968
9100
  if (!this.layout)
8969
9101
  throw new Error("A table layout is required before drawing rows.");
8970
9102
  this.bodyAdded = true;
8971
- const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
9103
+ const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2, lefts = this.layout.lefts;
9104
+ // One geometry token per active physical column; table/band changes release the old tokens.
9105
+ if (this.rectangleLefts !== lefts) {
9106
+ this.rectangleLefts = lefts;
9107
+ this.rectangleColumns = [];
9108
+ }
9109
+ let rectangleHeight, rectangleBottom = "", rectangleHeightText = "";
8972
9110
  for (const [index, cell] of row.cells.entries()) {
8973
9111
  if (this.bandCellBudget)
8974
9112
  this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
8975
9113
  (cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
8976
- const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
9114
+ const x = lefts[cell.first], cellHeight = cell.height ?? height;
9115
+ if (cellHeight !== rectangleHeight) {
9116
+ rectangleBottom = n(this.y - cellHeight);
9117
+ rectangleHeightText = n(cellHeight);
9118
+ rectangleHeight = cellHeight;
9119
+ }
9120
+ let horizontal = this.rectangleColumns[cell.first];
9121
+ if (!horizontal || horizontal.x !== x || horizontal.width !== cell.width) {
9122
+ horizontal = { x, width: cell.width, left: n(x), widthText: n(cell.width) };
9123
+ this.rectangleColumns[cell.first] = horizontal;
9124
+ }
9125
+ const rectangle = horizontal.left + " " + rectangleBottom + " " + horizontal.widthText + " " + rectangleHeightText;
8977
9126
  if (cell.style.background)
8978
- this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + n(x) + " " + n(this.y - cellHeight) + " " + n(cell.width) + " " + n(cellHeight) + " re f Q\n"));
8979
- this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " + n(x) + " " + n(this.y - cellHeight) + " " + n(cell.width) + " " + n(cellHeight) + " re S Q\n"));
9127
+ this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + rectangle + " re f Q\n"));
9128
+ this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " + rectangle + " re S Q\n"));
8980
9129
  const element = elements?.[index], artifact = cell.semanticArtifact || repeated[index], owner = cell.link && this.structure && element !== undefined ? this.structure.link(element, cell.link) : element;
8981
9130
  for (let line = firstLine; line < Math.min(cell.lines.length, cell.height ? cell.lines.length : firstLine + lineCount); line++) {
8982
9131
  const text = cell.lines[line], left = cell.style.alignment === "right" ? cell.width - padding - text.width : cell.style.alignment === "center" ? (cell.width - text.width) / 2 : padding;
@@ -8986,6 +9135,7 @@ class PdfPages {
8986
9135
  this.link(cell.link, x, this.y - cellHeight, cell.width, cellHeight, owner);
8987
9136
  }
8988
9137
  this.y -= row.structured ? row.height : height;
9138
+ this.sealCommands();
8989
9139
  }
8990
9140
  async block(rows) {
8991
9141
  if (this.bandFlow)
@@ -9311,9 +9461,22 @@ class PdfPages {
9311
9461
  marker: { line: item.marker, gap: item.markerGap, ...(label === undefined ? {} : { owner: label }) } });
9312
9462
  await this.structure?.complete(li);
9313
9463
  }
9464
+ sealCommands() {
9465
+ if (this.commands) {
9466
+ this.commandParts.push(this.commands);
9467
+ this.commands = "";
9468
+ }
9469
+ }
9470
+ takeCommands() {
9471
+ this.sealCommands();
9472
+ const content = this.commandParts.join("");
9473
+ // Encoding and awaited delivery own the page value; the next page starts independently.
9474
+ this.commandParts = [];
9475
+ return content;
9476
+ }
9314
9477
  async finishPage() {
9315
9478
  const contents = this.objects.reserve(), { page, options } = this.settings;
9316
- await this.objects.stream(contents, this.commands.join(""), "", options.compression !== false);
9479
+ await this.objects.stream(contents, this.takeCommands(), "", options.compression !== false);
9317
9480
  const annotations = [];
9318
9481
  for (const annotation of this.annotations) {
9319
9482
  annotations.push(annotation.id);
@@ -9325,7 +9488,6 @@ class PdfPages {
9325
9488
  (annotations.length ? " /Annots [" + annotations.map(id => id + " 0 R").join(" ") + "]" : "") + " >>");
9326
9489
  if (this.structure)
9327
9490
  await this.structure.finishPage();
9328
- this.commands = [];
9329
9491
  this.annotations = [];
9330
9492
  this.commandBytes = 0;
9331
9493
  this.current = 0;
@@ -9357,11 +9519,11 @@ class PdfPages {
9357
9519
  }
9358
9520
  }
9359
9521
  const _exports = Object.freeze({ PdfPages: PdfPages });
9360
- _modules.set("a7fca40cb8c75af206111c90db36839b4648982beeb4179efda0ddd1ee366210", _exports);
9522
+ _modules.set("3ed7114181be5a3066742336da574fef7f2fc04ee6dfc5e64211f3bedad4cab9", _exports);
9361
9523
  return _exports;
9362
9524
  })();
9363
9525
 
9364
- const _m81 = _modules.get("7a58e8ccb5164de51db14e39ca9695af6487c354df909509f0ae6bfac8ae3887") ?? (() => {
9526
+ const _m82 = _modules.get("7a58e8ccb5164de51db14e39ca9695af6487c354df909509f0ae6bfac8ae3887") ?? (() => {
9365
9527
  /** @internal Incremental PDF number tree: at most 64 entries/children per retained level. */
9366
9528
  class PdfParentTree {
9367
9529
  objects;
@@ -9424,14 +9586,14 @@ _modules.set("7a58e8ccb5164de51db14e39ca9695af6487c354df909509f0ae6bfac8ae3887",
9424
9586
  return _exports;
9425
9587
  })();
9426
9588
 
9427
- const _m80 = _modules.get("1c1828a3d6dfc2edda674566203e7aa8e97c984114b7928df13cb373859977d0") ?? (() => {
9589
+ const _m81 = _modules.get("1c1828a3d6dfc2edda674566203e7aa8e97c984114b7928df13cb373859977d0") ?? (() => {
9428
9590
  const { OfficeIMOError } = _m2;
9429
9591
 
9430
9592
  const { checkAbort } = _m4;
9431
9593
 
9432
- const { unicodeHex } = _m60;
9594
+ const { unicodeHex } = _m61;
9433
9595
 
9434
- const { PdfParentTree } = _m81;
9596
+ const { PdfParentTree } = _m82;
9435
9597
 
9436
9598
  /** Same-page marked content uses integer K; cross-page MCR and annotation OBJR stay explicit. */
9437
9599
  function structureChild(child) {
@@ -9736,12 +9898,12 @@ _modules.set("1c1828a3d6dfc2edda674566203e7aa8e97c984114b7928df13cb373859977d0",
9736
9898
  return _exports;
9737
9899
  })();
9738
9900
 
9739
- const _m82 = _modules.get("52c78ca6833cee7e5a96b657e2c00172d550176daf2c95e742692f8416977bea") ?? (() => {
9901
+ const _m83 = _modules.get("52c78ca6833cee7e5a96b657e2c00172d550176daf2c95e742692f8416977bea") ?? (() => {
9740
9902
  const { OfficeIMOError } = _m2;
9741
9903
 
9742
9904
  const { checkAbort } = _m4;
9743
9905
 
9744
- const { pdfNumber, unicodeHex } = _m60;
9906
+ const { pdfNumber, unicodeHex } = _m61;
9745
9907
 
9746
9908
  /** @internal Bounded native bookmarks; destinations are captured only when their content is painted. */
9747
9909
  class PdfOutlines {
@@ -9800,18 +9962,18 @@ _modules.set("52c78ca6833cee7e5a96b657e2c00172d550176daf2c95e742692f8416977bea",
9800
9962
  return _exports;
9801
9963
  })();
9802
9964
 
9803
- const _m59 = _modules.get("eb2c981b4568b33deca2137956ace31ea621b6a6287755ec234336d0a7c23cfc") ?? (() => {
9804
- const { PdfObjects, unicodeHex } = _m60;
9965
+ const _m60 = _modules.get("afdad27eb363e8de0c3bd69ebf358860eb76f5c6fb29f43a87635807cb7fc273") ?? (() => {
9966
+ const { PdfObjects, unicodeHex } = _m61;
9805
9967
 
9806
- const { PdfFontResources } = _m62;
9968
+ const { PdfFontResources } = _m63;
9807
9969
 
9808
- const { PdfTableLayout } = _m69;
9970
+ const { PdfTableLayout } = _m70;
9809
9971
 
9810
- const { PdfPages } = _m74;
9972
+ const { PdfPages } = _m75;
9811
9973
 
9812
- const { PdfStructure } = _m80;
9974
+ const { PdfStructure } = _m81;
9813
9975
 
9814
- const { PdfOutlines } = _m82;
9976
+ const { PdfOutlines } = _m83;
9815
9977
 
9816
9978
  /** One resource/catalog owner shared by table convenience exports and composed documents. */
9817
9979
  class PdfWriteSession {
@@ -9863,11 +10025,11 @@ class PdfWriteSession {
9863
10025
  }
9864
10026
  }
9865
10027
  const _exports = Object.freeze({ PdfWriteSession: PdfWriteSession });
9866
- _modules.set("eb2c981b4568b33deca2137956ace31ea621b6a6287755ec234336d0a7c23cfc", _exports);
10028
+ _modules.set("afdad27eb363e8de0c3bd69ebf358860eb76f5c6fb29f43a87635807cb7fc273", _exports);
9867
10029
  return _exports;
9868
10030
  })();
9869
10031
 
9870
- const _m58 = _modules.get("98eb735e985f873ed0ffc628449a20d1f3bb729a87b6d6b3099b6f308438fcb5") ?? (() => {
10032
+ const _m59 = _modules.get("45cf9fd6b6293c1a83bc8554e1bcb5cf119f44701fbad7849f39a712cab5074b") ?? (() => {
9871
10033
  const { BlobByteSink, withDestination } = _m3;
9872
10034
 
9873
10035
  const { beginTask, checkAbort, consumeRows, pause, taskYieldDue } = _m4;
@@ -9878,7 +10040,7 @@ const { createRowProjector } = _m11;
9878
10040
 
9879
10041
  const { settings } = _m17;
9880
10042
 
9881
- const { PdfWriteSession } = _m59;
10043
+ const { PdfWriteSession } = _m60;
9882
10044
 
9883
10045
  async function writePdf(rows, configuration) {
9884
10046
  const sink = new BlobByteSink();
@@ -9932,11 +10094,11 @@ async function writePdfTo(rows, destination, configuration) {
9932
10094
  });
9933
10095
  }
9934
10096
  const _exports = Object.freeze({ writePdf: writePdf, writePdfTo: writePdfTo });
9935
- _modules.set("98eb735e985f873ed0ffc628449a20d1f3bb729a87b6d6b3099b6f308438fcb5", _exports);
10097
+ _modules.set("45cf9fd6b6293c1a83bc8554e1bcb5cf119f44701fbad7849f39a712cab5074b", _exports);
9936
10098
  return _exports;
9937
10099
  })();
9938
10100
 
9939
- const _m86 = _modules.get("749d1ec5422c0087787f525ef42e3b8d3a94d2b70eb5e42d2e3723a870777ad6") ?? (() => {
10101
+ const _m87 = _modules.get("749d1ec5422c0087787f525ef42e3b8d3a94d2b70eb5e42d2e3723a870777ad6") ?? (() => {
9940
10102
  const { NotSupportedError, OfficeIMOError } = _m2;
9941
10103
 
9942
10104
  const { checkAbort, pause, taskYieldDue, withAbort } = _m4;
@@ -10204,12 +10366,12 @@ _modules.set("749d1ec5422c0087787f525ef42e3b8d3a94d2b70eb5e42d2e3723a870777ad6",
10204
10366
  return _exports;
10205
10367
  })();
10206
10368
 
10207
- const _m85 = _modules.get("7dca2d9ca5c43893abdaf86df5b1bcb1f3de3d5d33532d082fdfe04711999d21") ?? (() => {
10369
+ const _m86 = _modules.get("7dca2d9ca5c43893abdaf86df5b1bcb1f3de3d5d33532d082fdfe04711999d21") ?? (() => {
10208
10370
  const { NotSupportedError, OfficeIMOError } = _m2;
10209
10371
 
10210
10372
  const { checkAbort, pause, taskYieldDue } = _m4;
10211
10373
 
10212
- const { pngPixels } = _m86;
10374
+ const { pngPixels } = _m87;
10213
10375
 
10214
10376
  /** Shared document image resources; source objects are captured on first consumption. */
10215
10377
  class PdfDocumentImages {
@@ -10338,14 +10500,14 @@ _modules.set("7dca2d9ca5c43893abdaf86df5b1bcb1f3de3d5d33532d082fdfe04711999d21",
10338
10500
  return _exports;
10339
10501
  })();
10340
10502
 
10341
- const _m87 = _modules.get("3290c84fdf80725af802f497d947bc088aa8d93d9db0a33f6f829f9153aa6fd6") ?? (() => {
10503
+ const _m88 = _modules.get("3290c84fdf80725af802f497d947bc088aa8d93d9db0a33f6f829f9153aa6fd6") ?? (() => {
10342
10504
  const { OfficeIMOError } = _m2;
10343
10505
 
10344
10506
  const { checkAbort, pause, taskYieldDue } = _m4;
10345
10507
 
10346
10508
  const { color, positive } = _m17;
10347
10509
 
10348
- const { pdfNumber: n } = _m60;
10510
+ const { pdfNumber: n } = _m61;
10349
10511
 
10350
10512
  /** Capture and serialize one bounded display path, with no markup parser or resource loading. */
10351
10513
  async function vectorCommands(block, settings, used) {
@@ -10425,14 +10587,14 @@ _modules.set("3290c84fdf80725af802f497d947bc088aa8d93d9db0a33f6f829f9153aa6fd6",
10425
10587
  return _exports;
10426
10588
  })();
10427
10589
 
10428
- const _m88 = _modules.get("da9ad00f94b9ae28e2e3de796928ff0c4eab1d73382b1441e7d779fad4278ef7") ?? (() => {
10590
+ const _m89 = _modules.get("da9ad00f94b9ae28e2e3de796928ff0c4eab1d73382b1441e7d779fad4278ef7") ?? (() => {
10429
10591
  const { NotSupportedError, OfficeIMOError } = _m2;
10430
10592
 
10431
10593
  const { checkAbort, pause, taskYieldDue } = _m4;
10432
10594
 
10433
10595
  const { color, positive } = _m17;
10434
10596
 
10435
- const { pdfNumber: n } = _m60;
10597
+ const { pdfNumber: n } = _m61;
10436
10598
 
10437
10599
  /** Portable drawings are an exact schema: unsupported data must never be silently discarded. */
10438
10600
  function record(value, keys, name) {
@@ -10672,20 +10834,20 @@ _modules.set("da9ad00f94b9ae28e2e3de796928ff0c4eab1d73382b1441e7d779fad4278ef7",
10672
10834
  return _exports;
10673
10835
  })();
10674
10836
 
10675
- const _m89 = _modules.get("5e4503b77b357ee6d9fad1f52690085b0f0b140cd3b550b63c5100ed95a92f88") ?? (() => {
10837
+ const _m90 = _modules.get("5e4503b77b357ee6d9fad1f52690085b0f0b140cd3b550b63c5100ed95a92f88") ?? (() => {
10676
10838
  const { OfficeIMOError } = _m2;
10677
10839
 
10678
- const { capturePdfText, wrapPdfText } = _m71;
10840
+ const { capturePdfText, wrapPdfText } = _m72;
10679
10841
 
10680
10842
  const { positive } = _m17;
10681
10843
 
10682
10844
  const { resolveParagraphStyle } = _m19;
10683
10845
 
10684
- const { captureBookmark } = _m78;
10846
+ const { captureBookmark } = _m79;
10685
10847
 
10686
10848
  const { captureFields } = _m10;
10687
10849
 
10688
- const { pdfBudgetText } = _m70;
10850
+ const { pdfBudgetText } = _m71;
10689
10851
 
10690
10852
  /** @internal Copy public paragraph input before any cooperative layout or source enumeration. */
10691
10853
  function captureParagraph(block, settings, fonts, budgetOnPaint = false) {
@@ -10756,10 +10918,10 @@ _modules.set("5e4503b77b357ee6d9fad1f52690085b0f0b140cd3b550b63c5100ed95a92f88",
10756
10918
  return _exports;
10757
10919
  })();
10758
10920
 
10759
- const _m90 = _modules.get("1d57c429705ae0cbc14d98dcfef4c8a6c2df06f391c8f58e99cacb02f2d1cbc7") ?? (() => {
10760
- const { capturePdfText, wrapPdfText } = _m71;
10921
+ const _m91 = _modules.get("1d57c429705ae0cbc14d98dcfef4c8a6c2df06f391c8f58e99cacb02f2d1cbc7") ?? (() => {
10922
+ const { capturePdfText, wrapPdfText } = _m72;
10761
10923
 
10762
- const { captureParagraph, prepareParagraph } = _m89;
10924
+ const { captureParagraph, prepareParagraph } = _m90;
10763
10925
 
10764
10926
  const { resolveParagraphStyle } = _m19;
10765
10927
 
@@ -10814,7 +10976,7 @@ _modules.set("1d57c429705ae0cbc14d98dcfef4c8a6c2df06f391c8f58e99cacb02f2d1cbc7",
10814
10976
  return _exports;
10815
10977
  })();
10816
10978
 
10817
- const _m92 = _modules.get("d04686d2c067355dfd215333b83eb5f79f96e9e4be49f942e050f21ac0795343") ?? (() => {
10979
+ const _m93 = _modules.get("d04686d2c067355dfd215333b83eb5f79f96e9e4be49f942e050f21ac0795343") ?? (() => {
10818
10980
  const { assertGroupedReportSource } = _m8;
10819
10981
 
10820
10982
  const { captureFields } = _m10;
@@ -10864,22 +11026,22 @@ _modules.set("d04686d2c067355dfd215333b83eb5f79f96e9e4be49f942e050f21ac0795343",
10864
11026
  return _exports;
10865
11027
  })();
10866
11028
 
10867
- const _m91 = _modules.get("d43e573fd5bad18a7ec2d71752168c422c4f8fabbc51f1cef8e3ba389f298715") ?? (() => {
11029
+ const _m92 = _modules.get("289fa3a052c7fbab2a3ca0fb91fb9974db709d24b7d850f1175810258f0409a0") ?? (() => {
10868
11030
  const { assertGroupedReportSource, groupedReportOperation } = _m8;
10869
11031
 
10870
11032
  const { consumeRows } = _m4;
10871
11033
 
10872
11034
  const { ExportCell } = _m5;
10873
11035
 
10874
- const { captureGroupedPdfTableOptions } = _m92;
11036
+ const { captureGroupedPdfTableOptions } = _m93;
10875
11037
 
10876
11038
  const { settings } = _m17;
10877
11039
 
10878
- const { PdfTableLayout } = _m69;
11040
+ const { PdfTableLayout } = _m70;
10879
11041
 
10880
- const { captureCaption, captureParagraph, prepareParagraph } = _m89;
11042
+ const { captureCaption, captureParagraph, prepareParagraph } = _m90;
10881
11043
 
10882
- const { synchronousText } = _m70;
11044
+ const { synchronousText } = _m71;
10883
11045
 
10884
11046
  /** @internal Render one analytical source in the existing document session. Retain one detail row and
10885
11047
  * at most four closing subtotals. All captions, rows, pages, bytes and fonts use the document owners. */
@@ -11118,11 +11280,11 @@ async function renderGroupedPdfTable(block, context) {
11118
11280
  }
11119
11281
  }
11120
11282
  const _exports = Object.freeze({ renderGroupedPdfTable: renderGroupedPdfTable });
11121
- _modules.set("d43e573fd5bad18a7ec2d71752168c422c4f8fabbc51f1cef8e3ba389f298715", _exports);
11283
+ _modules.set("289fa3a052c7fbab2a3ca0fb91fb9974db709d24b7d850f1175810258f0409a0", _exports);
11122
11284
  return _exports;
11123
11285
  })();
11124
11286
 
11125
- const _m84 = _modules.get("f6c70e9a0bed09b5a1c61a662ad7d3faf731c911f574e2df285f669bd643b947") ?? (() => {
11287
+ const _m85 = _modules.get("9051bf9fc3168e24b53b16c123a42816198456846003fb49191c03a18cdab904") ?? (() => {
11126
11288
  const { BlobByteSink, withDestination } = _m3;
11127
11289
 
11128
11290
  const { OfficeIMOError } = _m2;
@@ -11137,27 +11299,27 @@ const { captureFields } = _m10;
11137
11299
 
11138
11300
  const { settings, captureWideTable } = _m17;
11139
11301
 
11140
- const { pdfNumber: n } = _m60;
11302
+ const { pdfNumber: n } = _m61;
11141
11303
 
11142
- const { PdfTableLayout } = _m69;
11304
+ const { PdfTableLayout } = _m70;
11143
11305
 
11144
- const { PdfWriteSession } = _m59;
11306
+ const { PdfWriteSession } = _m60;
11145
11307
 
11146
- const { PdfDocumentImages } = _m85;
11308
+ const { PdfDocumentImages } = _m86;
11147
11309
 
11148
- const { vectorCommands } = _m87;
11310
+ const { vectorCommands } = _m88;
11149
11311
 
11150
- const { graphicAlternative } = _m80;
11312
+ const { graphicAlternative } = _m81;
11151
11313
 
11152
- const { checkDrawingBlock, prepareDrawing } = _m88;
11314
+ const { checkDrawingBlock, prepareDrawing } = _m89;
11153
11315
 
11154
- const { captureParagraph, captureCaption, prepareParagraph, checkParagraphBuffer, paragraphStartHeight } = _m89;
11316
+ const { captureParagraph, captureCaption, prepareParagraph, checkParagraphBuffer, paragraphStartHeight } = _m90;
11155
11317
 
11156
- const { captureListOptions, prepareListItem } = _m90;
11318
+ const { captureListOptions, prepareListItem } = _m91;
11157
11319
 
11158
- const { captureSection } = _m78;
11320
+ const { captureSection } = _m79;
11159
11321
 
11160
- const { renderGroupedPdfTable } = _m91;
11322
+ const { renderGroupedPdfTable } = _m92;
11161
11323
 
11162
11324
  const tableOptionFields = ["columns", "includeHeader", "headerRows", "footer", "headerPresentation", "footerPresentation", "alternateRowColor", "columnWidths", "wideTable", "formatValue", "formatRuns"];
11163
11325
  /** Capture typed columns for a single-use table source in a composed document. */
@@ -11412,22 +11574,22 @@ function captureTableOptions(options) {
11412
11574
  return { ...captured, ...(captured.wideTable === undefined ? {} : { wideTable: captureWideTable(captured.wideTable) }) };
11413
11575
  }
11414
11576
  const _exports = Object.freeze({ pdfTable: pdfTable, writePdfDocument: writePdfDocument, writePdfDocumentTo: writePdfDocumentTo });
11415
- _modules.set("f6c70e9a0bed09b5a1c61a662ad7d3faf731c911f574e2df285f669bd643b947", _exports);
11577
+ _modules.set("9051bf9fc3168e24b53b16c123a42816198456846003fb49191c03a18cdab904", _exports);
11416
11578
  return _exports;
11417
11579
  })();
11418
11580
 
11419
- const _m83 = _modules.get("879a0adeb3c62918085a071cbc37f221eb89a0fd73d56ebb5e9cfe0d49db8ee9") ?? (() => {
11581
+ const _m84 = _modules.get("abe76e52ffeed11ab42477c83ddde1d1d7de28b803096436b5b23cb153af58ba") ?? (() => {
11420
11582
  const { assertGroupedReportSource } = _m8;
11421
11583
 
11422
11584
  const { BlobByteSink } = _m3;
11423
11585
 
11424
- const { writePdfDocumentTo } = _m84;
11586
+ const { writePdfDocumentTo } = _m85;
11425
11587
 
11426
11588
  const { pdfOptionFields } = _m17;
11427
11589
 
11428
11590
  const { captureFields } = _m10;
11429
11591
 
11430
- const { pdfGroupedTable, groupedPdfLabelFields, groupedPdfTableFields } = _m92;
11592
+ const { pdfGroupedTable, groupedPdfLabelFields, groupedPdfTableFields } = _m93;
11431
11593
 
11432
11594
 
11433
11595
 
@@ -11461,15 +11623,15 @@ async function writeGroupedPdfTo(report, destination, configuration) {
11461
11623
  delete documentOptions.footer;
11462
11624
  return writePdfDocumentTo([pdfGroupedTable(report, tableOptions)], destination, documentOptions);
11463
11625
  }
11464
- const _exports = Object.freeze({ pdfGroupedTable: _m92.pdfGroupedTable, writeGroupedPdf: writeGroupedPdf, writeGroupedPdfTo: writeGroupedPdfTo });
11465
- _modules.set("879a0adeb3c62918085a071cbc37f221eb89a0fd73d56ebb5e9cfe0d49db8ee9", _exports);
11626
+ const _exports = Object.freeze({ pdfGroupedTable: _m93.pdfGroupedTable, writeGroupedPdf: writeGroupedPdf, writeGroupedPdfTo: writeGroupedPdfTo });
11627
+ _modules.set("abe76e52ffeed11ab42477c83ddde1d1d7de28b803096436b5b23cb153af58ba", _exports);
11466
11628
  return _exports;
11467
11629
  })();
11468
11630
 
11469
- const _m93 = _modules.get("3d777096288d1be55a05a80bc015d4674212e587703f25a7e7cf99a8065feb86") ?? (() => {
11470
- const { fontProgram } = _m63;
11631
+ const _m94 = _modules.get("3d777096288d1be55a05a80bc015d4674212e587703f25a7e7cf99a8065feb86") ?? (() => {
11632
+ const { fontProgram } = _m64;
11471
11633
 
11472
- const { resolveScalar, selectFont, validateFonts } = _m67;
11634
+ const { resolveScalar, selectFont, validateFonts } = _m68;
11473
11635
 
11474
11636
  /**
11475
11637
  * Check one text run against the writer's selected font and scalar-layout rules.
@@ -11506,14 +11668,110 @@ _modules.set("3d777096288d1be55a05a80bc015d4674212e587703f25a7e7cf99a8065feb86",
11506
11668
  return _exports;
11507
11669
  })();
11508
11670
 
11509
- const _m57 = _modules.get("2deab7b4ccb08bed297341ddb563d8fcf74277aff38c1dfc3d9edd61c0d98481") ?? (() => {
11671
+ const _m58 = _modules.get("027aafa08408056b10d7d717d63d1f7c0ee20ecfc68213aa66feacc75ec525fe") ?? (() => {
11672
+
11673
+ const _exports = Object.freeze({ writePdf: _m59.writePdf, writePdfTo: _m59.writePdfTo, writeGroupedPdf: _m84.writeGroupedPdf, writeGroupedPdfTo: _m84.writeGroupedPdfTo, pdfGroupedTable: _m84.pdfGroupedTable, createGroupedReport: _m8.createGroupedReport, writePdfDocument: _m85.writePdfDocument, writePdfDocumentTo: _m85.writePdfDocumentTo, pdfTable: _m85.pdfTable, PdfFont: _m64.PdfFont, preflightPdfText: _m94.preflightPdfText, ExportCell: _m5.ExportCell, saveBlob: _m1.saveBlob });
11674
+ _modules.set("027aafa08408056b10d7d717d63d1f7c0ee20ecfc68213aa66feacc75ec525fe", _exports);
11675
+ return _exports;
11676
+ })();
11677
+
11678
+ const _m95 = _modules.get("3d1862d8ab32171bca4b3ba5fe0bdcc073f67ce940aaff0ee735635893f86ee8") ?? (() => {
11679
+ /** One policy for capture diagnostics and unsupported adapter mappings; callbacks stay synchronous. */
11680
+ function canopyDiagnostics(format, options) {
11681
+ const policy = options.unsupportedPresentation ?? (format === "csv" ? "text" : "reject"), notify = options.onDiagnostic;
11682
+ if (policy !== "reject" && policy !== "text")
11683
+ throw new TypeError("unsupportedPresentation must be reject or text.");
11684
+ if (notify !== undefined && typeof notify !== "function")
11685
+ throw new TypeError("onDiagnostic must be a synchronous function.");
11686
+ return diagnostic => {
11687
+ if (policy === "reject")
11688
+ throw new TypeError("Unsupported Canopy presentation: " + diagnostic.code + (diagnostic.columnId ? " (" + diagnostic.columnId + ")" : ""));
11689
+ const result = notify?.(Object.freeze(diagnostic));
11690
+ if (result && typeof result.then === "function") {
11691
+ void Promise.resolve(result).catch(() => { });
11692
+ throw new TypeError("onDiagnostic must be synchronous.");
11693
+ }
11694
+ };
11695
+ }
11696
+ const _exports = Object.freeze({ canopyDiagnostics: canopyDiagnostics });
11697
+ _modules.set("3d1862d8ab32171bca4b3ba5fe0bdcc073f67ce940aaff0ee735635893f86ee8", _exports);
11698
+ return _exports;
11699
+ })();
11510
11700
 
11511
- const _exports = Object.freeze({ writePdf: _m58.writePdf, writePdfTo: _m58.writePdfTo, writeGroupedPdf: _m83.writeGroupedPdf, writeGroupedPdfTo: _m83.writeGroupedPdfTo, pdfGroupedTable: _m83.pdfGroupedTable, createGroupedReport: _m8.createGroupedReport, writePdfDocument: _m84.writePdfDocument, writePdfDocumentTo: _m84.writePdfDocumentTo, pdfTable: _m84.pdfTable, PdfFont: _m63.PdfFont, preflightPdfText: _m93.preflightPdfText, ExportCell: _m5.ExportCell, saveBlob: _m1.saveBlob });
11512
- _modules.set("2deab7b4ccb08bed297341ddb563d8fcf74277aff38c1dfc3d9edd61c0d98481", _exports);
11701
+ const _m97 = _modules.get("9914b45196123264d883d65b074b339b224324876baa3f157c0ddec6ad1f67f9") ?? (() => {
11702
+ function presentation(input, axes) {
11703
+ const { axisKey, outlineLevel, summary, grandTotal, hidden, collapsed } = input;
11704
+ if (typeof axisKey !== "string" || !axes.has(axisKey) || !Number.isInteger(outlineLevel) || outlineLevel < 0 || outlineLevel > 7 ||
11705
+ [summary, grandTotal, hidden, collapsed].some(flag => typeof flag !== "boolean"))
11706
+ throw new TypeError("Invalid frozen Canopy pivot axis presentation.");
11707
+ return Object.freeze({ level: outlineLevel, hidden: hidden, collapsed: collapsed });
11708
+ }
11709
+ /** Qualify the explicit pivot path before flat/grouped handling; never evaluate query or aggregate data. */
11710
+ function canopyPivot(request) {
11711
+ if (request.pivot === undefined)
11712
+ return undefined;
11713
+ const pivot = request.pivot;
11714
+ if (!pivot || typeof pivot !== "object" || request.grouping !== undefined || !Array.isArray(request.columns) ||
11715
+ request.scope !== "filtered" || !Number.isSafeInteger(request.recordCount) || request.recordCount < 0 ||
11716
+ !pivot.definition || !Array.isArray(pivot.definition.rows) || pivot.definition.rows.length > 4 ||
11717
+ !Array.isArray(pivot.definition.columns) || pivot.definition.columns.length > 2 ||
11718
+ !Array.isArray(pivot.definition.values) || !pivot.definition.values.length || pivot.definition.values.length > 32 ||
11719
+ pivot.definition.values.some(value => typeof value !== "string") ||
11720
+ !Number.isSafeInteger(pivot.distinctColumns) || pivot.distinctColumns < 0 || typeof pivot.columnsLimited !== "boolean" ||
11721
+ !Array.isArray(pivot.retainedColumns) || !Array.isArray(pivot.columnGroups))
11722
+ throw new TypeError("Invalid explicit Canopy pivot descriptor.");
11723
+ const axes = (nodes) => {
11724
+ if (!Array.isArray(nodes) || nodes.length > 100001)
11725
+ throw new TypeError("Pivot axes require bounded accepted identities.");
11726
+ const keys = new Set();
11727
+ for (const node of nodes) {
11728
+ if (!node || typeof node.key !== "string" || !node.key || keys.has(node.key) || !Array.isArray(node.path) || typeof node.other !== "boolean")
11729
+ throw new TypeError("Invalid or duplicate Canopy pivot axis identity.");
11730
+ keys.add(node.key);
11731
+ }
11732
+ for (const node of nodes)
11733
+ if (node.parent !== undefined && !keys.has(node.parent))
11734
+ throw new TypeError("Unknown Canopy pivot parent identity.");
11735
+ return keys;
11736
+ };
11737
+ const rowKeys = axes(pivot.rowAxis), columnKeys = axes(pivot.columnAxis);
11738
+ const columns = request.columns.map((column, index) => {
11739
+ if (index === 0 && column.axisKey === undefined && column.kind === "text")
11740
+ return Object.freeze({ ...column });
11741
+ const outline = presentation(column, columnKeys);
11742
+ return Object.freeze({ ...column, outlineLevel: outline.level, hidden: outline.hidden, collapsed: outline.collapsed });
11743
+ });
11744
+ // Ranges are descriptor metadata, not another body. Validate them against the same ordered columns.
11745
+ if (pivot.columnGroups.length > columns.length)
11746
+ throw new RangeError("Pivot column group count exceeds projected columns.");
11747
+ for (const group of pivot.columnGroups) {
11748
+ if (!group || !columnKeys.has(group.key) || !Number.isSafeInteger(group.firstColumn) || group.firstColumn < 0 ||
11749
+ !Number.isSafeInteger(group.columnCount) || group.columnCount < 1 || group.firstColumn + group.columnCount > columns.length ||
11750
+ !Number.isInteger(group.depth) || group.depth < 1 || group.depth > 7 ||
11751
+ typeof group.hidden !== "boolean" || typeof group.collapsed !== "boolean")
11752
+ throw new TypeError("Invalid Canopy pivot column range.");
11753
+ }
11754
+ let current;
11755
+ const sheet = Object.freeze({ outlineSummaryBelow: false, outlineSummaryRight: false,
11756
+ maxOutlineLevel: 7, rowOutline: () => current,
11757
+ columnOutlines: Object.freeze(columns.flatMap((column, firstColumn) => column.axisKey === undefined ? [] :
11758
+ [Object.freeze({ firstColumn, columnCount: 1, level: column.outlineLevel, hidden: column.hidden, collapsed: column.collapsed })])) });
11759
+ return Object.freeze({ columns: Object.freeze(columns), sheet,
11760
+ observe(row) { current = presentation(row, rowKeys); } });
11761
+ }
11762
+ /** Per-cell formats preserve already-computed fractional percentages, ranks and differences. */
11763
+ function pivotNumberFormat(cell) {
11764
+ if (!["value", "percentGrandTotal", "percentParent", "percentColumn", "percentRow", "runningTotal", "rank", "difference", "percentChange"].includes(cell.mode ?? "") ||
11765
+ typeof cell.numberFormat !== "string" || !cell.numberFormat.length)
11766
+ throw new TypeError("Numeric pivot cells require a frozen mode and native numberFormat.");
11767
+ return cell.numberFormat;
11768
+ }
11769
+ const _exports = Object.freeze({ canopyPivot: canopyPivot, pivotNumberFormat: pivotNumberFormat });
11770
+ _modules.set("9914b45196123264d883d65b074b339b224324876baa3f157c0ddec6ad1f67f9", _exports);
11513
11771
  return _exports;
11514
11772
  })();
11515
11773
 
11516
- const _m95 = _modules.get("c0aee2c5df0df3e62ca31fc685243cdd4b449f083834e8d28cf92c20dfa7b27f") ?? (() => {
11774
+ const _m98 = _modules.get("c0aee2c5df0df3e62ca31fc685243cdd4b449f083834e8d28cf92c20dfa7b27f") ?? (() => {
11517
11775
  /** @internal Typed conversion follows declared datetime intent, never localized display text. */
11518
11776
  function datetime(value, mode, clock) {
11519
11777
  if (mode === "text")
@@ -11553,10 +11811,58 @@ _modules.set("c0aee2c5df0df3e62ca31fc685243cdd4b449f083834e8d28cf92c20dfa7b27f",
11553
11811
  return _exports;
11554
11812
  })();
11555
11813
 
11556
- const _m94 = _modules.get("91dbdf35d8f192b3c0ea92dfab6b9812872fbe3c8d85a5d2afe389bd61262ba2") ?? (() => {
11814
+ const _m99 = _modules.get("040752afe195985e6f2e91f8c62fc13464c455fc44034b8cef4828851e05b83d") ?? (() => {
11815
+ /** Calibri 11, 96-DPI CSS pixels, seven-pixel maximum digit and five-pixel cell padding.
11816
+ * Quantize to native 1/256-character units; this is a reproducible profile, not pixel-identical rendering. */
11817
+ function canopyXlsxWidth(pixels) {
11818
+ const width = Math.floor((pixels < 12 ? pixels / 12 : (pixels - 5) / 7) * 256) / 256;
11819
+ if (!Number.isFinite(width) || width <= 0 || width > 255)
11820
+ throw new RangeError("Captured width exceeds the Calibri-11 XLSX width profile.");
11821
+ return width;
11822
+ }
11823
+ /** Escape literal prefixes/suffixes; no browser formatter or CSS becomes workbook code. */
11824
+ function canopyNumberFormat(input, report, id) {
11825
+ if (!input || typeof input !== "object" || Array.isArray(input))
11826
+ throw new TypeError("Canopy numeric format must be an object.");
11827
+ if (Object.keys(input).some(key => !["minimumFractionDigits", "maximumFractionDigits", "prefix", "suffix"].includes(key))) {
11828
+ report({ code: "UNSUPPORTED_NUMBER_FORMAT", columnId: id });
11829
+ return undefined;
11830
+ }
11831
+ const { minimumFractionDigits: minimum = 0, maximumFractionDigits: maximum = 3, prefix = "", suffix = "" } = input;
11832
+ if (!Number.isInteger(minimum) || !Number.isInteger(maximum) || minimum < 0 || maximum < minimum || maximum > 10 ||
11833
+ typeof prefix !== "string" || typeof suffix !== "string" || prefix.length > 16 || suffix.length > 16)
11834
+ throw new TypeError("Canopy numeric fraction bounds must be ordered integers from zero through ten, with literal affixes of at most sixteen characters.");
11835
+ const literal = (value) => value ? '"' + value.replace(/"/g, '"\\""') + '"' : "";
11836
+ return literal(prefix) + "0" + (maximum ? "." + "0".repeat(minimum) + "#".repeat(maximum - minimum) : "") + literal(suffix);
11837
+ }
11838
+ /** Only a contiguous leading left pin can be represented by an Excel freeze pane. */
11839
+ function canopyPins(columns, report) {
11840
+ let leading = 0, ended = false;
11841
+ for (const column of columns) {
11842
+ const pin = column.pinned;
11843
+ if (pin !== undefined && pin !== null && pin !== "left" && pin !== "right")
11844
+ throw new TypeError("Invalid Canopy pin.");
11845
+ if (!ended && pin === "left")
11846
+ leading++;
11847
+ else {
11848
+ ended = true;
11849
+ if (pin === "left" || pin === "right")
11850
+ report({ code: "UNREPRESENTABLE_PIN:" + pin, columnId: column.id });
11851
+ }
11852
+ }
11853
+ return leading;
11854
+ }
11855
+ const _exports = Object.freeze({ canopyXlsxWidth: canopyXlsxWidth, canopyNumberFormat: canopyNumberFormat, canopyPins: canopyPins });
11856
+ _modules.set("040752afe195985e6f2e91f8c62fc13464c455fc44034b8cef4828851e05b83d", _exports);
11857
+ return _exports;
11858
+ })();
11859
+
11860
+ const _m96 = _modules.get("965483034a9b849ca9359aaecae287d9a4a8ea4d64379af0f665743df7baa403") ?? (() => {
11557
11861
  const { ExportCell, checkAbort, inputRows } = _m1;
11558
11862
 
11559
- const { datetime } = _m95;
11863
+ const { canopyPivot, pivotNumberFormat } = _m97;
11864
+
11865
+ const { datetime } = _m98;
11560
11866
 
11561
11867
  const { captureFields } = _m10;
11562
11868
 
@@ -11564,48 +11870,56 @@ const { copyColumns } = _m11;
11564
11870
 
11565
11871
  const { copyCellPresentation } = _m5;
11566
11872
 
11873
+ const { canopyDiagnostics } = _m95;
11874
+
11875
+ const { canopyNumberFormat, canopyXlsxWidth } = _m99;
11876
+
11567
11877
  const columnFields = ["width", "format", "wrapText", "alignment", "rowHeader", "groups"];
11878
+ const rawIdentities = new WeakMap();
11879
+ /** @internal Grouping uses captured identity even when a detail cell displays a relative-link label. */
11880
+ function canopyIdentityValue(value) {
11881
+ if (!(value instanceof ExportCell))
11882
+ return value;
11883
+ const original = rawIdentities.get(value);
11884
+ return original === undefined ? value.value : original;
11885
+ }
11568
11886
  /** Map an immutable CanopyX record capture to a writer without querying the grid or retaining its body. */
11569
11887
  function createCanopyExport(capture, format, options = {}) {
11888
+ return prepareCanopyExport(capture, format, options).source;
11889
+ }
11890
+ /** @internal Capture the input once before full-writer metadata mapping and asynchronous enumeration. */
11891
+ function prepareCanopyExport(capture, format, options = {}) {
11570
11892
  options = captureFields(options, ["tones", "columnOptions", "unsupportedPresentation", "datetime", "xlsx", "signal", "onDiagnostic"]);
11571
11893
  if (format !== "xlsx" && format !== "csv" && format !== "pdf")
11572
11894
  throw new TypeError("Canopy export format must be xlsx, csv or pdf.");
11573
11895
  if (!capture || typeof capture.rows !== "function" || !capture.request)
11574
11896
  throw new TypeError("A portable CanopyX capture with request and rows() is required.");
11575
- const { request } = capture, signal = options.signal, values = request.values;
11897
+ const request = captureFields(capture.request, ["columns", "recordCount", "values", "presentation", "timeZone", "revision", "scope", "total", "matched", "selection", "query", "generatedAt", "grouping", "pivot", "formatRules"]);
11898
+ const pivot = canopyPivot(request);
11899
+ const signal = options.signal, values = request.values;
11576
11900
  if (!Array.isArray(request.columns) || !request.columns.length || (request.recordCount !== null && (!Number.isSafeInteger(request.recordCount) || request.recordCount < 0)) ||
11577
11901
  (values !== "raw" && values !== "display") || (request.timeZone !== "utc" && request.timeZone !== "local") || typeof request.revision !== "string")
11578
11902
  throw new TypeError("Invalid portable CanopyX capture metadata.");
11579
- const policy = options.unsupportedPresentation ?? (format === "csv" ? "text" : "reject"), dateMode = options.datetime ?? "preserve", notify = options.onDiagnostic;
11903
+ const dateMode = options.datetime ?? "preserve", report = canopyDiagnostics(format, options);
11904
+ // These captured presentations have a complete scalar/text projection. Report
11905
+ // their visual loss without treating an ordinary report export as unsupported.
11906
+ const fallback = canopyDiagnostics(format, { ...options, unsupportedPresentation: "text" });
11580
11907
  const clock = options.xlsx?.dateMode ?? request.timeZone;
11581
11908
  if (clock !== "utc" && clock !== "local")
11582
11909
  throw new TypeError("XLSX dateMode must be utc or local.");
11583
- if (policy !== "reject" && policy !== "text")
11584
- throw new TypeError("unsupportedPresentation must be reject or text.");
11585
11910
  if (dateMode !== "preserve" && dateMode !== "typed" && dateMode !== "text")
11586
11911
  throw new TypeError("datetime must be preserve, typed or text.");
11587
- if (notify !== undefined && typeof notify !== "function")
11588
- throw new TypeError("onDiagnostic must be a synchronous function.");
11589
- const report = (diagnostic) => {
11590
- if (policy === "reject")
11591
- throw new TypeError("Unsupported Canopy presentation: " + diagnostic.code + (diagnostic.columnId ? " (" + diagnostic.columnId + ")" : ""));
11592
- const result = notify?.(Object.freeze(diagnostic));
11593
- if (result && typeof result.then === "function") {
11594
- void Promise.resolve(result).catch(() => { });
11595
- throw new TypeError("onDiagnostic must be synchronous.");
11596
- }
11597
- };
11598
11912
  const diagnostics = (items, rowId, columnId) => {
11599
11913
  if (items === undefined)
11600
11914
  return;
11601
11915
  if (!Array.isArray(items) || items.some(item => typeof item !== "string"))
11602
11916
  throw new TypeError("Canopy presentation diagnostics must be strings.");
11603
- for (const code of items)
11604
- report({ code, ...(rowId === undefined ? {} : { rowId }), ...(columnId === undefined ? {} : { columnId }) });
11917
+ for (const code of items) {
11918
+ const diagnostic = { code, ...(rowId === undefined ? {} : { rowId }), ...(columnId === undefined ? {} : { columnId }) };
11919
+ (code === "relative-link" || code === "history-series" ? fallback : report)(diagnostic);
11920
+ }
11605
11921
  };
11606
- if (request.presentation === "text")
11607
- report({ code: "TEXT_ONLY_CAPTURE" });
11608
- else if (request.presentation !== "semantic")
11922
+ if (request.presentation !== "text" && request.presentation !== "semantic")
11609
11923
  throw new TypeError("Canopy captures must declare text or semantic presentation.");
11610
11924
  const tones = new Map(Object.entries(options.tones ?? {}).map(([name, style]) => {
11611
11925
  if (!style || typeof style !== "object" || Array.isArray(style))
@@ -11618,19 +11932,23 @@ function createCanopyExport(capture, format, options = {}) {
11618
11932
  if (typeof name !== "string")
11619
11933
  throw new TypeError("Canopy tones must be strings.");
11620
11934
  const style = tones.get(name);
11621
- if (!style)
11622
- report({ code: "UNMAPPED_TONE:" + name, rowId, ...(columnId === undefined ? {} : { columnId }) });
11935
+ if (!style && name !== "neutral")
11936
+ fallback({ code: "UNMAPPED_TONE:" + name, rowId, ...(columnId === undefined ? {} : { columnId }) });
11623
11937
  return style;
11624
11938
  };
11625
11939
  const ids = new Set();
11626
- const specs = request.columns.map(column => {
11940
+ const specs = (pivot?.columns ?? request.columns).map(input => {
11941
+ const fields = captureFields(input, ["id", "title", "kind", "width", "pinned", "format", "wrap", "alignment", "diagnostics"]);
11942
+ const column = Object.freeze({ ...fields,
11943
+ ...(fields.width === undefined ? {} : { width: Object.freeze(captureFields(fields.width, ["unit", "preferred", "minimum", "maximum"])) }),
11944
+ ...(fields.format === undefined ? {} : { format: Object.freeze(captureFields(fields.format, ["minimumFractionDigits", "maximumFractionDigits", "prefix", "suffix"])) }) });
11627
11945
  if (!column || typeof column.id !== "string" || !column.id || ids.has(column.id) || typeof column.title !== "string" ||
11628
11946
  !["text", "number", "datetime"].includes(column.kind) ||
11629
11947
  (column.wrap !== undefined && typeof column.wrap !== "boolean") || (column.alignment !== undefined && !["left", "right"].includes(column.alignment)) ||
11630
11948
  (column.width !== undefined && (column.width.unit !== "css-px" || !Number.isFinite(column.width.preferred) ||
11631
11949
  !Number.isFinite(column.width.minimum) || column.width.minimum <= 0 || column.width.preferred < column.width.minimum ||
11632
11950
  column.width.maximum !== undefined && (!Number.isFinite(column.width.maximum) || column.width.maximum < column.width.preferred))) ||
11633
- (request.presentation === "semantic" && (column.wrap === undefined || column.alignment === undefined || column.width === undefined)))
11951
+ (!pivot && request.presentation === "semantic" && (column.wrap === undefined || column.alignment === undefined || column.width === undefined)))
11634
11952
  throw new TypeError("Invalid or duplicate Canopy export column.");
11635
11953
  ids.add(column.id);
11636
11954
  diagnostics(column.diagnostics, undefined, column.id);
@@ -11639,20 +11957,30 @@ function createCanopyExport(capture, format, options = {}) {
11639
11957
  if (!columnFields.includes(key))
11640
11958
  throw new TypeError("Unsupported Canopy column option: " + key);
11641
11959
  const override = captureFields(selected, columnFields);
11960
+ const numericFormat = (format === "xlsx" || format === "pdf") && values === "raw" && column.kind === "number" && column.format !== undefined && override.format === undefined
11961
+ ? canopyNumberFormat(column.format, report, column.id) : undefined;
11642
11962
  const [captured] = copyColumns([{ ...override, key: column.id, header: column.title,
11963
+ ...(format === "xlsx" && override.width === undefined && column.width !== undefined ? { width: canopyXlsxWidth(column.width.preferred) } : {}),
11964
+ ...(override.format === undefined && numericFormat !== undefined ? { format: numericFormat } : {}),
11965
+ ...(format === "xlsx" && values === "raw" && column.kind === "datetime" && override.format === undefined ? { format: "yyyy-mm-dd hh:mm:ss.000" } : {}),
11643
11966
  ...(values === "raw" && column.kind === "number" ? { type: "number" } : {}),
11644
- ...(override.wrapText === undefined && column.wrap === undefined ? {} : { wrapText: override.wrapText ?? column.wrap }),
11645
- ...(override.alignment === undefined && column.alignment === undefined ? {} : { alignment: override.alignment ?? column.alignment }) }]);
11646
- return Object.freeze({ id: column.id, kind: column.kind, column: Object.freeze(captured) });
11967
+ // Screen nowrap is not a promise that its CSS width will survive PDF fitting.
11968
+ // PDF defaults to lossless wrapping; an explicit writer override stays strict.
11969
+ ...(format === "pdf" ? { wrapText: override.wrapText ?? true } :
11970
+ override.wrapText === undefined && column.wrap === undefined ? {} : { wrapText: override.wrapText ?? column.wrap }),
11971
+ ...(override.alignment === undefined && column.alignment === undefined ?
11972
+ format === "pdf" && column.kind === "number" ? { alignment: "right" } : {} : { alignment: override.alignment ?? column.alignment }) }]);
11973
+ return Object.freeze({ id: column.id, kind: column.kind, input: column, nativeFormatOverride: override.format, column: Object.freeze(captured) });
11647
11974
  });
11648
11975
  const rowCount = request.recordCount;
11649
- return Object.freeze({ columns: Object.freeze(specs.map(spec => spec.column)), rowCount, async *rows() {
11976
+ const source = Object.freeze({ columns: Object.freeze(specs.map(spec => spec.column)), rowCount, async *rows() {
11650
11977
  checkAbort(signal);
11651
11978
  let count = 0;
11652
11979
  for await (const row of inputRows(capture.rows(signal ? { signal } : {}), signal)) {
11653
11980
  checkAbort(signal);
11654
11981
  if (!row || typeof row.id !== "string" || !row.cells || typeof row.cells !== "object")
11655
11982
  throw new TypeError("Invalid Canopy export record.");
11983
+ pivot?.observe(row);
11656
11984
  diagnostics(row.diagnostics, row.id);
11657
11985
  const rowStyle = tone(row.tone, row.id), result = [];
11658
11986
  for (const spec of specs) {
@@ -11664,13 +11992,29 @@ function createCanopyExport(capture, format, options = {}) {
11664
11992
  (typeof cell.value === "number" && (!Number.isFinite(cell.value) || Math.abs(cell.value) > Number.MAX_SAFE_INTEGER)))
11665
11993
  throw new TypeError("A portable Canopy GridExportCell with scalar value and resolved text is required.");
11666
11994
  diagnostics(cell.diagnostics, row.id, spec.id);
11667
- let value = values === "display" ? cell.text : cell.value;
11995
+ // A relative destination is navigation metadata, not the visible label.
11996
+ // History captures already carry their frozen latest scalar (or null).
11997
+ const relativeLabel = spec.kind === "text" && cell.diagnostics?.includes("relative-link");
11998
+ let value = values === "display" || relativeLabel ? cell.text : cell.value;
11668
11999
  if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
11669
12000
  value = datetime(value, dateMode, clock);
11670
- const cellStyle = tone(cell.tone, row.id, spec.id), presentation = rowStyle || cellStyle ? { ...rowStyle, ...cellStyle } : undefined;
12001
+ const capturedFormat = pivot && spec.kind === "number" && cell.value !== null ? pivotNumberFormat(cell) : undefined;
12002
+ const nativeFormat = capturedFormat === undefined ? undefined : spec.nativeFormatOverride === "" ? "General" : spec.nativeFormatOverride ?? capturedFormat;
12003
+ const summary = format === "pdf" && pivot && (row.summary || row.grandTotal);
12004
+ const cellStyle = tone(cell.tone, row.id, spec.id), presentation = rowStyle || cellStyle || nativeFormat || summary ? {
12005
+ ...rowStyle, ...(summary ? { bold: true } : {}), ...cellStyle,
12006
+ ...((format === "xlsx" || format === "pdf") && values === "raw" && nativeFormat !== undefined ? { numberFormat: nativeFormat } : {})
12007
+ } : undefined;
11671
12008
  // CSV has no presentation or link metadata: emit its selected scalar directly.
11672
12009
  // This also avoids a frozen wrapper for every cell in large CSV captures.
11673
- result.push(format === "csv" ? value : new ExportCell(value, { text: cell.text, ...(presentation ? { presentation } : {}), ...(cell.link === undefined ? {} : { link: cell.link }) }));
12010
+ if (format === "csv")
12011
+ result.push(value);
12012
+ else {
12013
+ const exported = new ExportCell(value, { text: cell.text, ...(presentation ? { presentation } : {}), ...(cell.link === undefined ? {} : { link: cell.link }) });
12014
+ if (relativeLabel)
12015
+ rawIdentities.set(exported, cell.value);
12016
+ result.push(exported);
12017
+ }
11674
12018
  }
11675
12019
  if (rowCount !== null && count >= rowCount)
11676
12020
  throw new TypeError("Canopy capture exceeded its declared recordCount.");
@@ -11680,14 +12024,828 @@ function createCanopyExport(capture, format, options = {}) {
11680
12024
  if (rowCount !== null && count !== rowCount)
11681
12025
  throw new TypeError("Canopy capture did not produce its declared recordCount.");
11682
12026
  } });
12027
+ return Object.freeze({ source, request: Object.freeze({ ...request, columns: Object.freeze(specs.map(spec => spec.input)) }), report, tones, pivot });
12028
+ }
12029
+ const _exports = Object.freeze({ canopyIdentityValue: canopyIdentityValue, createCanopyExport: createCanopyExport, prepareCanopyExport: prepareCanopyExport });
12030
+ _modules.set("965483034a9b849ca9359aaecae287d9a4a8ea4d64379af0f665743df7baa403", _exports);
12031
+ return _exports;
12032
+ })();
12033
+
12034
+ const _m101 = _modules.get("2b0b73e8c376d24e6a5b498c0f710966b00de0eff44f474d7b2aece7af64fa96") ?? (() => {
12035
+ const { columnName, excelDate } = _m35;
12036
+
12037
+ const { captureFields } = _m10;
12038
+
12039
+ const { datetime } = _m98;
12040
+
12041
+ /** Compile only comparisons whose raw types and native encodings have a faithful bounded mapping. */
12042
+ function canopyPredicate(request, grouped, options, root, unsupported, cellTypes) {
12043
+ let nodes = 0;
12044
+ const operations = { eq: "=", ne: "<>", gt: ">", ge: ">=", lt: "<", le: "<=" };
12045
+ const numeric = (value) => {
12046
+ const number = typeof value === "boolean" ? Number(value) : typeof value === "string" ? Number(value) : value;
12047
+ // Use platform decimal conversion; separator/culture profiles need a diagnostic, not a second parser.
12048
+ if (typeof value === "string") {
12049
+ const text = value.trim().toLowerCase();
12050
+ if (Number.parseFloat(value) !== number || ["0x", "0b", "0o"].some(prefix => text.startsWith(prefix)))
12051
+ return unsupported("UNSUPPORTED_NUMERIC_RULE_LITERAL");
12052
+ }
12053
+ if (!Number.isFinite(number) || Math.abs(number) > Number.MAX_SAFE_INTEGER)
12054
+ throw new TypeError("Canopy rule comparison values must be finite safe-range numbers.");
12055
+ return number;
12056
+ };
12057
+ const date = (value) => {
12058
+ if (options.datetime !== "typed" || (options.xlsx?.dateMode ?? request.timeZone) !== "utc")
12059
+ return unsupported("DATETIME_RULE_REQUIRES_TYPED_UTC");
12060
+ if (typeof value === "boolean")
12061
+ return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
12062
+ if (typeof value === "number" && !Number.isSafeInteger(value))
12063
+ return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
12064
+ try {
12065
+ const literal = typeof value === "number" ? new Date(value).toISOString() : value;
12066
+ const captured = datetime(literal, "typed", "utc");
12067
+ if (!(captured instanceof Date))
12068
+ return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
12069
+ const serial = excelDate(captured, "utc");
12070
+ if (serial === null)
12071
+ return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
12072
+ return serial;
12073
+ }
12074
+ catch (error) {
12075
+ if (!(error instanceof TypeError) && !(error instanceof RangeError))
12076
+ throw error;
12077
+ return unsupported("UNSUPPORTED_DATETIME_RULE_LITERAL");
12078
+ }
12079
+ };
12080
+ const leaf = (input) => {
12081
+ if (++nodes > 64)
12082
+ return unsupported("RULE_PREDICATE_LIMIT");
12083
+ const filter = captureFields(input, ["column", "operator", "values"]), operation = operations[filter.operator];
12084
+ if (Object.keys(filter).some(key => !["column", "operator", "values"].includes(key)))
12085
+ return unsupported("UNSUPPORTED_RULE_FILTER_OPTIONS");
12086
+ const index = request.columns.findIndex(column => column.id === filter.column);
12087
+ if (index < 0)
12088
+ return unsupported("RULE_COLUMN_NOT_EXPORTED:" + filter.column);
12089
+ const column = request.columns[index], letter = columnName(index + 1 + (grouped ? 1 : 0));
12090
+ const reference = "INDEX($" + letter + ":$" + letter + ",ROW())", present = "NOT(ISBLANK(" + reference + "))";
12091
+ if (column.kind === "number")
12092
+ cellTypes.set(index, "number");
12093
+ if (column.kind === "datetime") {
12094
+ if (options.datetime !== "typed" || (options.xlsx?.dateMode ?? request.timeZone) !== "utc")
12095
+ return unsupported("DATETIME_RULE_REQUIRES_TYPED_UTC");
12096
+ cellTypes.set(index, "date");
12097
+ }
12098
+ if (filter.operator === "isNull" || filter.operator === "isNotNull") {
12099
+ if (filter.values !== undefined && filter.values.length)
12100
+ return unsupported("UNSUPPORTED_NULL_RULE_OPERANDS");
12101
+ return filter.operator === "isNull" ? "ISBLANK(" + reference + ")" : present;
12102
+ }
12103
+ if (!operation || !Array.isArray(filter.values) || filter.values.length !== 1)
12104
+ return unsupported("UNSUPPORTED_RULE_FILTER:" + filter.operator);
12105
+ const value = filter.values[0];
12106
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean")
12107
+ throw new TypeError("Canopy rule values must be portable scalars.");
12108
+ if (column.kind === "number" || column.kind === "datetime") {
12109
+ const operand = column.kind === "number" ? numeric(value) : date(value);
12110
+ return "AND(" + present + ",ISNUMBER(" + reference + ")," + reference + operation + String(operand) + ")";
12111
+ }
12112
+ if (filter.operator !== "eq" && filter.operator !== "ne")
12113
+ return unsupported("UNSUPPORTED_TEXT_RULE_COMPARISON");
12114
+ // Canopy's Unicode text folding is not the native workbook's comparison contract.
12115
+ if (typeof value === "string")
12116
+ return unsupported("UNQUALIFIED_NATIVE_TEXT_COMPARISON");
12117
+ const kind = typeof value === "boolean" ? "ISLOGICAL" : "ISNUMBER";
12118
+ const literal = typeof value === "boolean" ? value ? "TRUE" : "FALSE" : String(numeric(value));
12119
+ const sameType = kind + "(" + reference + ")", comparison = reference + operation + literal;
12120
+ return filter.operator === "eq" ? "AND(" + present + "," + sameType + "," + comparison + ")"
12121
+ : "AND(" + present + ",OR(NOT(" + sameType + ")," + comparison + "))";
12122
+ };
12123
+ const visit = (input, depth) => {
12124
+ if (depth > 4 || ++nodes > 64)
12125
+ return unsupported("RULE_PREDICATE_LIMIT");
12126
+ if (!input || typeof input !== "object")
12127
+ throw new TypeError("Canopy rule predicate must be an object.");
12128
+ const captured = captureFields(input, ["operator", "filters", "groups"]);
12129
+ if (captured.operator !== "and" && captured.operator !== "or")
12130
+ return unsupported("UNSUPPORTED_RULE_BOOLEAN:" + captured.operator);
12131
+ const filters = captured.filters ?? [], groups = captured.groups ?? [];
12132
+ if (!Array.isArray(filters) || !Array.isArray(groups))
12133
+ throw new TypeError("Canopy predicate filters and groups must be arrays.");
12134
+ const terms = [];
12135
+ for (const filter of filters)
12136
+ terms.push(leaf(filter));
12137
+ for (const group of groups)
12138
+ terms.push(visit(group, depth + 1));
12139
+ if (!terms.length)
12140
+ return unsupported("EMPTY_RULE_PREDICATE");
12141
+ return captured.operator.toUpperCase() + "(" + terms.join(",") + ")";
12142
+ };
12143
+ const formula = visit(root, 1);
12144
+ if (formula.length > 8192)
12145
+ return unsupported("RULE_FORMULA_LIMIT");
12146
+ return formula;
12147
+ }
12148
+ const _exports = Object.freeze({ canopyPredicate: canopyPredicate });
12149
+ _modules.set("2b0b73e8c376d24e6a5b498c0f710966b00de0eff44f474d7b2aece7af64fa96", _exports);
12150
+ return _exports;
12151
+ })();
12152
+
12153
+ const _m100 = _modules.get("eb8cf81d2a340cdb41301d59c667cef44f3ad1d6a19f717eb8137257b545115e") ?? (() => {
12154
+ const { captureFields } = _m10;
12155
+
12156
+ const { canopyPredicate } = _m101;
12157
+
12158
+ // Stable document palette. Browser CSS variables and resolved cell.format are never interpreted.
12159
+ const palette = {
12160
+ info: { color: "4472C4", background: "DDEBF7", foreground: "1F4E78" },
12161
+ success: { color: "70AD47", background: "E2F0D9", foreground: "375623" },
12162
+ warning: { color: "FFC000", background: "FFF2CC", foreground: "9C6500" },
12163
+ danger: { color: "C00000", background: "FFC7CE", foreground: "9C0006" }
12164
+ };
12165
+ class UnsupportedRule extends Error {
12166
+ }
12167
+ const unsupported = (message) => { throw new UnsupportedRule(message); };
12168
+ /** Compile declarations in source order, then emit native target/aspect priorities.
12169
+ * Data-column selectors let grouped writers exclude generated headings, subtotals and grand totals. */
12170
+ function canopyRules(request, format, grouped, tones, report, options = {}, cellTypes) {
12171
+ if (request.formatRules === undefined || format === "csv")
12172
+ return [];
12173
+ if (!Array.isArray(request.formatRules) || request.formatRules.length > 1000)
12174
+ throw new TypeError("Canopy formatRules must be a bounded array of at most 1,000 declarations.");
12175
+ const visuals = [], cells = [], rows = [], ids = new Set(), columns = request.columns;
12176
+ const inputs = request.formatRules;
12177
+ const declarations = inputs.map(input => {
12178
+ if (!input || typeof input !== "object")
12179
+ throw new TypeError("Canopy rule declarations must be objects.");
12180
+ const rule = captureFields(input, ["id", "enabled", "stopIfTrue", "column", "when", "target", "style"]);
12181
+ if (typeof rule.id !== "string" || !rule.id || ids.has(rule.id))
12182
+ throw new TypeError("Canopy rule IDs must be unique nonempty strings.");
12183
+ ids.add(rule.id);
12184
+ if (rule.enabled !== undefined && typeof rule.enabled !== "boolean" || rule.stopIfTrue !== undefined && typeof rule.stopIfTrue !== "boolean")
12185
+ throw new TypeError("Canopy rule flags must be boolean.");
12186
+ const style = rule.style && typeof rule.style === "object" ? captureFields(rule.style, ["tone", "bar", "scale"]) : rule.style;
12187
+ return { ...rule, style };
12188
+ });
12189
+ if (format === "pdf") {
12190
+ for (const rule of declarations)
12191
+ if (rule.enabled !== false)
12192
+ report({ code: "PDF_NATIVE_RULE_NOT_RENDERED:" + rule.id });
12193
+ return [];
12194
+ }
12195
+ const hasStops = declarations.some(rule => rule.enabled !== false && rule.stopIfTrue);
12196
+ if (hasStops && declarations.some(rule => rule.enabled !== false && (rule.style?.bar !== undefined || rule.style?.scale !== undefined))) {
12197
+ report({ code: "UNSUPPORTED_GLOBAL_STOP_WITH_NATIVE_VISUALS" });
12198
+ return [];
12199
+ }
12200
+ const barColumns = new Set(declarations.filter(rule => rule.enabled !== false && rule.style?.bar !== undefined).map(rule => rule.column));
12201
+ const barTone = declarations.find(rule => rule.enabled !== false && rule.target !== "row" && rule.style?.tone !== undefined && rule.column !== undefined && barColumns.has(rule.column));
12202
+ if (barTone) {
12203
+ // Canopy suppresses a cell tone's fill only where its bar resolves. A single native tone patch cannot express both cases.
12204
+ report({ code: "UNSUPPORTED_CELL_TONE_WITH_DATA_BAR", columnId: barTone.column });
12205
+ return [];
12206
+ }
12207
+ const priorStops = [];
12208
+ const priorRows = [], priorCells = new Map();
12209
+ const requiredCells = new Map();
12210
+ const column = (id) => {
12211
+ const index = columns.findIndex(column => column.id === id);
12212
+ if (index < 0)
12213
+ return unsupported("RULE_COLUMN_NOT_EXPORTED:" + id);
12214
+ return index;
12215
+ };
12216
+ const numeric = (id) => {
12217
+ if (columns[column(id)].kind !== "number")
12218
+ unsupported("RULE_COLUMN_NOT_NUMERIC:" + id);
12219
+ };
12220
+ const color = (name) => {
12221
+ const mapping = tones.get(name), value = mapping?.background ?? mapping?.color ?? palette[name]?.color;
12222
+ if (value === undefined)
12223
+ return unsupported("UNMAPPED_RULE_TONE:" + name);
12224
+ return value;
12225
+ };
12226
+ const style = (name) => {
12227
+ const defaults = palette[name];
12228
+ const mapping = tones.get(name) ?? (defaults ? { background: defaults.background, color: defaults.foreground } : undefined);
12229
+ if (!mapping)
12230
+ return unsupported("UNMAPPED_RULE_TONE:" + name);
12231
+ if ("alignment" in mapping || "wrapText" in mapping)
12232
+ return unsupported("UNSUPPORTED_RULE_TONE_STYLE:" + name);
12233
+ return {
12234
+ ...("background" in mapping && mapping.background !== undefined ? { fill: { color: mapping.background } } : {}),
12235
+ font: { ...(mapping.color === undefined ? {} : { color: mapping.color }),
12236
+ ...("bold" in mapping && mapping.bold !== undefined ? { bold: mapping.bold } : {}),
12237
+ ...("italic" in mapping && mapping.italic !== undefined ? { italic: mapping.italic } : {}) },
12238
+ ...("numberFormat" in mapping && mapping.numberFormat !== undefined ? { numberFormat: mapping.numberFormat } : {})
12239
+ };
12240
+ };
12241
+ for (const rule of declarations) {
12242
+ if (rule.enabled === false)
12243
+ continue;
12244
+ try {
12245
+ if (request.values !== "raw")
12246
+ unsupported("NATIVE_RULE_REQUIRES_RAW_VALUES");
12247
+ if (rule.target === "columns" || "columns" in rule && rule.columns !== undefined)
12248
+ unsupported("UNSUPPORTED_RULE_COLUMNS_TARGET");
12249
+ if (!rule.style || typeof rule.style !== "object" || Array.isArray(rule.style))
12250
+ throw new TypeError("Canopy rule style must be an object.");
12251
+ const styleInput = captureFields(rule.style, ["tone", "bar", "scale"]);
12252
+ if (Object.keys(styleInput).some(key => !["tone", "bar", "scale"].includes(key)))
12253
+ unsupported("UNSUPPORTED_RULE_STYLE");
12254
+ const supplied = [styleInput.bar, styleInput.scale, styleInput.tone].filter(value => value !== undefined);
12255
+ if (supplied.length !== 1)
12256
+ unsupported("UNSUPPORTED_RULE_STYLE_COMBINATION");
12257
+ if (styleInput.bar !== undefined) {
12258
+ if (rule.column === undefined || rule.when !== undefined || rule.target === "row")
12259
+ unsupported("UNSUPPORTED_BAR_TARGET");
12260
+ numeric(rule.column);
12261
+ if (rule.stopIfTrue)
12262
+ unsupported("UNSUPPORTED_BAR_STOP");
12263
+ const { minimum, maximum, tone = "info", showValue } = captureFields(styleInput.bar, ["minimum", "maximum", "tone", "showValue"]);
12264
+ if (minimum === undefined || maximum === undefined)
12265
+ return unsupported("UNBOUNDED_CANOPY_BAR");
12266
+ if (!Number.isFinite(minimum) || !Number.isFinite(maximum) || maximum <= minimum)
12267
+ throw new TypeError("Canopy bar bounds must be finite and increasing.");
12268
+ visuals.push({ type: "dataBar", range: { column: rule.column }, color: color(tone),
12269
+ minimum: { type: "number", value: minimum }, maximum: { type: "number", value: maximum }, ...(showValue === undefined ? {} : { showValue }) });
12270
+ requiredCells.set(column(rule.column), "number");
12271
+ }
12272
+ else if (styleInput.scale !== undefined) {
12273
+ if (rule.stopIfTrue)
12274
+ unsupported("UNSUPPORTED_SCALE_STOP");
12275
+ if (rule.column === undefined || rule.when !== undefined || rule.target === "row")
12276
+ unsupported("UNSUPPORTED_SCALE_TARGET");
12277
+ numeric(rule.column);
12278
+ const { stops } = captureFields(styleInput.scale, ["stops"]);
12279
+ if (!Array.isArray(stops) || stops.length < 2 || stops.length > 3)
12280
+ unsupported("UNSUPPORTED_SCALE_STOPS");
12281
+ const mapped = stops.map((input) => {
12282
+ const stop = captureFields(input, ["type", "value", "tone"]);
12283
+ if (!["min", "max", "number", "percent", "percentile"].includes(stop.type))
12284
+ unsupported("UNSUPPORTED_SCALE_THRESHOLD:" + stop.type);
12285
+ const threshold = stop.type === "min" || stop.type === "max" ? { type: stop.type }
12286
+ : { type: stop.type, value: stop.value };
12287
+ return { threshold, color: color(stop.tone) };
12288
+ });
12289
+ visuals.push({ type: "colorScale", range: { column: rule.column },
12290
+ stops: mapped });
12291
+ requiredCells.set(column(rule.column), "number");
12292
+ }
12293
+ else {
12294
+ if (rule.when === undefined || styleInput.tone === undefined || rule.target !== "row" && rule.column === undefined)
12295
+ unsupported("UNSUPPORTED_HIGHLIGHT_TARGET");
12296
+ if (rule.target !== undefined && rule.target !== "row" && rule.target !== "cell")
12297
+ unsupported("UNSUPPORTED_RULE_TARGET");
12298
+ const range = rule.target === "row" ? { column: columns[0].id, through: columns.at(-1).id } : { column: rule.column };
12299
+ if (rule.column !== undefined)
12300
+ column(rule.column);
12301
+ const ruleCells = new Map();
12302
+ const ownPredicate = canopyPredicate(request, grouped, options, rule.when, unsupported, ruleCells);
12303
+ const reachable = priorStops.length ? "AND(" + ownPredicate + ",NOT(OR(" + priorStops.join(",") + ")))" : ownPredicate;
12304
+ const previous = rule.target === "row" ? priorRows : priorCells.get(rule.column) ?? [];
12305
+ const formula = previous.length ? "AND(" + reachable + ",NOT(OR(" + previous.join(",") + ")))" : reachable;
12306
+ if (formula.length > 8192)
12307
+ unsupported("RULE_FORMULA_LIMIT");
12308
+ (rule.target === "row" ? rows : cells).push({ type: "expression", range, formula, style: style(styleInput.tone) });
12309
+ previous.push(ownPredicate);
12310
+ if (rule.target !== "row")
12311
+ priorCells.set(rule.column, previous);
12312
+ for (const [column, type] of ruleCells)
12313
+ requiredCells.set(column, type);
12314
+ // A matched declaration still stops the row when an earlier tone on that target already won.
12315
+ if (rule.stopIfTrue)
12316
+ priorStops.push(ownPredicate);
12317
+ }
12318
+ }
12319
+ catch (error) {
12320
+ if (!(error instanceof UnsupportedRule))
12321
+ throw error;
12322
+ report({ code: error.message + ":" + rule.id, ...(rule.column === undefined ? {} : { columnId: rule.column }) });
12323
+ if (hasStops)
12324
+ return []; // A partial sequence cannot claim to preserve its row-global stopping behavior.
12325
+ }
12326
+ }
12327
+ for (const [column, type] of requiredCells)
12328
+ cellTypes?.set(column, type);
12329
+ // Canopy paints cell visuals/tones over the row tint. Build masks before changing native priority order.
12330
+ return Object.freeze([...visuals, ...cells, ...rows]);
11683
12331
  }
11684
- const _exports = Object.freeze({ createCanopyExport: createCanopyExport });
11685
- _modules.set("91dbdf35d8f192b3c0ea92dfab6b9812872fbe3c8d85a5d2afe389bd61262ba2", _exports);
12332
+ const _exports = Object.freeze({ canopyRules: canopyRules });
12333
+ _modules.set("eb8cf81d2a340cdb41301d59c667cef44f3ad1d6a19f717eb8137257b545115e", _exports);
11686
12334
  return _exports;
11687
12335
  })();
11688
12336
 
11689
- const _m0 = _modules.get("3e66cc3ead243255e3903dfabd767d39c2507193c6631b6a40caad66216c13ed") ?? (() => {
11690
- const { BlobByteSink } = _m1;
12337
+ const _m102 = _modules.get("4aefd89b060b86e8e6e50a47a502f9ee7e64a2a1df334e0e9482f7ed30f0bee2") ?? (() => {
12338
+ const { createGroupedReport } = _m8;
12339
+
12340
+ const { checkAbort } = _m4;
12341
+
12342
+ const { createTotals } = _m12;
12343
+
12344
+ const { captureFields } = _m10;
12345
+
12346
+ const { datetime } = _m98;
12347
+
12348
+ const { canopyIdentityValue } = _m96;
12349
+
12350
+ const identity = (value) => value instanceof Date ? "date:" + value.getTime() : typeof value + ":" + String(value);
12351
+ const scalar = canopyIdentityValue;
12352
+ /** Validate captured ranges, then use the owned grouping factory and its existing writers.
12353
+ * Only ranges, labels and at most four active aggregate vectors are retained; no detail body is buffered. */
12354
+ function canopyGrouped(source, request, options, limits, report, format) {
12355
+ const input = request.grouping;
12356
+ if (input === undefined)
12357
+ return undefined; // query.groupBy never manufactures a group snapshot.
12358
+ if (request.values !== "raw") {
12359
+ report({ code: "GROUPING_REQUIRES_RAW_VALUES" });
12360
+ return undefined;
12361
+ }
12362
+ if (source.rowCount === null)
12363
+ throw new TypeError("Captured grouping requires its exact scope recordCount.");
12364
+ const grouping = captureFields(input, ["levels", "aggregates", "totals", "groups"]);
12365
+ if (!Array.isArray(grouping.levels) || grouping.levels.length < 1 || grouping.levels.length > 4 || !Array.isArray(grouping.aggregates) || !Array.isArray(grouping.groups))
12366
+ throw new TypeError("Canopy grouping needs one through four levels, aggregates and ordered groups.");
12367
+ const levels = grouping.levels.map(level => Object.freeze(captureFields(level, ["column", "direction", "title"])));
12368
+ if (levels.some(level => typeof level.column !== "string" || !level.column || level.direction !== "asc" && level.direction !== "desc") ||
12369
+ new Set(levels.map(level => level.column)).size !== levels.length)
12370
+ throw new TypeError("Canopy grouping levels need unique stable columns and directions.");
12371
+ const declarations = grouping.aggregates.map(aggregate => Object.freeze(captureFields(aggregate, ["id", "column", "operation", "label"])));
12372
+ const ids = new Set(), totals = Object.create(null);
12373
+ const operations = { sum: "sum", count: "count", average: "average", minimum: "min", maximum: "max" };
12374
+ for (const aggregate of declarations) {
12375
+ if (typeof aggregate.id !== "string" || !aggregate.id || ids.has(aggregate.id))
12376
+ throw new TypeError("Canopy aggregate IDs must be unique nonempty strings.");
12377
+ ids.add(aggregate.id);
12378
+ const column = source.columns.find(column => column.key === aggregate.column);
12379
+ if (!column || column.type !== "number")
12380
+ throw new TypeError("Canopy aggregate declarations require an exported raw numeric column.");
12381
+ if (Object.hasOwn(totals, aggregate.column))
12382
+ throw new TypeError("The grouped report supports one aggregate operation per column.");
12383
+ const operation = operations[aggregate.operation];
12384
+ if (operation === undefined) {
12385
+ report({ code: "UNSUPPORTED_GROUP_AGGREGATE:" + aggregate.operation, columnId: aggregate.column });
12386
+ return undefined;
12387
+ }
12388
+ totals[aggregate.column] = operation;
12389
+ }
12390
+ // Reuse the canonical operation validator rather than implementing aggregate semantics here.
12391
+ createTotals(source.columns, totals);
12392
+ const expected = (input) => {
12393
+ if (!input || typeof input !== "object" || Array.isArray(input))
12394
+ throw new TypeError("Canopy aggregate values must be an ID-keyed object.");
12395
+ const snapshot = { ...input };
12396
+ if (Object.keys(snapshot).some(key => !ids.has(key)) || declarations.some(aggregate => !Object.hasOwn(snapshot, aggregate.id)))
12397
+ throw new TypeError("Canopy aggregate values must reference exactly the captured declarations.");
12398
+ for (const value of Object.values(snapshot))
12399
+ if (value !== null && (typeof value !== "number" || !Number.isFinite(value)))
12400
+ throw new TypeError("Canopy aggregate values must be finite numbers or null.");
12401
+ return Object.freeze(snapshot);
12402
+ };
12403
+ const grandExpected = expected(grouping.totals), byDepth = levels.map(() => []), labels = levels.map(() => new Map());
12404
+ let groups = 0, characters = 0;
12405
+ const ranges = (inputs, offset, end, depth) => {
12406
+ if (!Array.isArray(inputs))
12407
+ throw new TypeError("Canopy groups must be ordered arrays.");
12408
+ let cursor = offset;
12409
+ const keys = new Set(), values = new Set();
12410
+ for (const input of inputs) {
12411
+ const group = captureFields(input, ["key", "value", "text", "offset", "count", "aggregates", "groups"]);
12412
+ if (!group || typeof group.key !== "string" || keys.has(group.key) || !Number.isSafeInteger(group.offset) || !Number.isSafeInteger(group.count) ||
12413
+ group.count <= 0 || group.offset !== cursor || group.count > end - group.offset)
12414
+ throw new TypeError("Canopy group ranges must be nonempty contiguous half-open partitions within their parent.");
12415
+ if (group.value !== null && !["string", "number", "boolean"].includes(typeof group.value) ||
12416
+ typeof group.value === "number" && !Number.isFinite(group.value))
12417
+ throw new TypeError("Canopy group values must be portable finite scalars.");
12418
+ const dateColumn = request.columns.find(column => column.id === levels[depth].column)?.kind === "datetime";
12419
+ const value = format === "xlsx" && dateColumn && typeof group.value === "string"
12420
+ ? datetime(group.value, options.datetime ?? "preserve", options.xlsx?.dateMode ?? request.timeZone) : group.value;
12421
+ const key = identity(value), text = group.text ?? String(group.value ?? "");
12422
+ if (typeof text !== "string" || values.has(key))
12423
+ throw new TypeError("A Canopy group key cannot recur within the same parent.");
12424
+ const previousLabel = labels[depth].get(key);
12425
+ if (previousLabel !== undefined && previousLabel !== text)
12426
+ throw new TypeError("The same grouping value needs consistent captured text at one level.");
12427
+ labels[depth].set(key, text);
12428
+ keys.add(group.key);
12429
+ values.add(key);
12430
+ if (++groups > 1000 || (characters += group.key.length + key.length + text.length) > 1000000)
12431
+ throw new RangeError("Canopy group metadata exceeds the existing bounded report profile.");
12432
+ const next = group.offset + group.count;
12433
+ byDepth[depth].push(Object.freeze({ offset: group.offset, end: next, value, text, expected: expected(group.aggregates) }));
12434
+ if (depth + 1 < levels.length)
12435
+ ranges(group.groups ?? [], group.offset, next, depth + 1);
12436
+ else if (group.groups !== undefined && group.groups.length)
12437
+ throw new TypeError("Canopy nested groups exceed their declared levels.");
12438
+ cursor = next;
12439
+ }
12440
+ if (cursor !== end)
12441
+ throw new TypeError("Canopy grouping does not cover its complete exported detail range.");
12442
+ };
12443
+ ranges(grouping.groups, 0, source.rowCount, 0);
12444
+ // Validate the producer's wire arithmetic separately from the grouped writer's native formula caches.
12445
+ // Canopy sum/average use compensated accumulation and return null without numeric inputs.
12446
+ const wireTotals = () => {
12447
+ const ordinary = createTotals(source.columns, totals), sums = source.columns.map(() => 0), corrections = source.columns.map(() => 0), counts = source.columns.map(() => 0);
12448
+ return {
12449
+ accept(values) {
12450
+ for (let index = 0; index < values.length; index++) {
12451
+ const value = scalar(values[index]), operation = totals[source.columns[index].key];
12452
+ if (operation !== "sum" && operation !== "average") {
12453
+ ordinary[index].accept(value);
12454
+ continue;
12455
+ }
12456
+ if (typeof value !== "number" || !Number.isFinite(value))
12457
+ continue;
12458
+ counts[index] = counts[index] + 1;
12459
+ const next = value - corrections[index], total = sums[index] + next;
12460
+ corrections[index] = total - sums[index] - next;
12461
+ sums[index] = total;
12462
+ }
12463
+ },
12464
+ value(index) {
12465
+ const operation = totals[source.columns[index].key];
12466
+ return operation === "sum" || operation === "average" ? !counts[index] ? null
12467
+ : operation === "sum" ? sums[index] : sums[index] / counts[index] : ordinary[index].value();
12468
+ }
12469
+ };
12470
+ };
12471
+ const indexes = levels.map(() => 0), active = levels.map(() => undefined);
12472
+ const at = (depth, row) => {
12473
+ const list = byDepth[depth];
12474
+ while (list[indexes[depth]] && list[indexes[depth]].end <= row)
12475
+ indexes[depth] = indexes[depth] + 1;
12476
+ const range = list[indexes[depth]];
12477
+ if (!range || row < range.offset || row >= range.end)
12478
+ throw new TypeError("A detail row is outside its captured Canopy grouping.");
12479
+ return range;
12480
+ };
12481
+ const verify = (actual, expected) => {
12482
+ for (const declaration of declarations) {
12483
+ const position = source.columns.findIndex(column => column.key === declaration.column), observed = actual.value(position), declared = expected[declaration.id];
12484
+ // Exact producer-wire comparison retains wrong-scope rejection without rounding native caches or applying an epsilon.
12485
+ if (observed !== declared)
12486
+ throw new TypeError("Canopy captured aggregate differs from its consumed rows: " + declaration.id + ".");
12487
+ }
12488
+ };
12489
+ const same = (actual, expected) => actual instanceof Date && expected instanceof Date
12490
+ ? actual.getTime() === expected.getTime() : actual === expected;
12491
+ async function* rows() {
12492
+ let index = 0;
12493
+ const grand = wireTotals();
12494
+ for await (const values of source.rows()) {
12495
+ checkAbort(options.signal);
12496
+ for (let depth = 0; depth < levels.length; depth++) {
12497
+ const range = at(depth, index), column = source.columns.findIndex(column => column.key === levels[depth].column);
12498
+ if (column >= 0 && !same(scalar(values[column]), range.value))
12499
+ throw new TypeError("Canopy detail value disagrees with its captured group range.");
12500
+ if (range.offset === index)
12501
+ active[depth] = { range, aggregates: wireTotals() };
12502
+ }
12503
+ grand.accept(values);
12504
+ for (const group of active)
12505
+ group.aggregates.accept(values);
12506
+ yield values;
12507
+ index++;
12508
+ for (let depth = levels.length - 1; depth >= 0; depth--) {
12509
+ const group = active[depth];
12510
+ if (group.range.end === index) {
12511
+ verify(group.aggregates, group.range.expected);
12512
+ active[depth] = undefined;
12513
+ }
12514
+ }
12515
+ }
12516
+ verify(grand, grandExpected);
12517
+ }
12518
+ // The factory's hidden fields keep raw group identity separate from projected
12519
+ // detail labels. Never override a declared output column's value getter.
12520
+ const groupKeys = new Set([...source.columns.map(column => column.key), ...levels.map(level => level.column)]);
12521
+ const groupBy = levels.map((level, depth) => {
12522
+ const column = source.columns.findIndex(column => column.key === level.column);
12523
+ let key = level.column;
12524
+ if (column >= 0) {
12525
+ do {
12526
+ key += "#raw";
12527
+ } while (groupKeys.has(key));
12528
+ groupKeys.add(key);
12529
+ }
12530
+ return { key,
12531
+ value: (row, context) => column < 0 ? at(depth, context.rowIndex).value : scalar(row[column]),
12532
+ label: (value) => labels[depth].get(identity(value)) ?? String(value ?? "") };
12533
+ });
12534
+ const sourceLimits = limits === undefined ? undefined : {
12535
+ ...(limits.maxRows === undefined ? {} : { maxRows: limits.maxRows }),
12536
+ ...(limits.maxCells === undefined ? {} : { maxCells: limits.maxCells }),
12537
+ ...(limits.maxTextCharacters === undefined ? {} : { maxTextCharacters: limits.maxTextCharacters })
12538
+ };
12539
+ return createGroupedReport(rows(), { columns: source.columns, groupBy, totals,
12540
+ ...(options.signal === undefined ? {} : { signal: options.signal }), ...(sourceLimits === undefined ? {} : { limits: sourceLimits }) });
12541
+ }
12542
+ const _exports = Object.freeze({ canopyGrouped: canopyGrouped });
12543
+ _modules.set("4aefd89b060b86e8e6e50a47a502f9ee7e64a2a1df334e0e9482f7ed30f0bee2", _exports);
12544
+ return _exports;
12545
+ })();
12546
+
12547
+ const _m103 = _modules.get("9ee68b08aff01ebcd88790854ac27b71235c5df5cab4a9575ffcf267e8fea5ea") ?? (() => {
12548
+ const { cellText } = _m35;
12549
+
12550
+ const { cleanXml } = _m28;
12551
+
12552
+ /** Snapshot optional About metadata before enumeration. The accepted query is serialized, never evaluated. */
12553
+ function canopyAbout(request, options) {
12554
+ const result = [["revision", request.revision], ["recordCount", request.recordCount === null ? "unknown" : request.recordCount]];
12555
+ if (request.scope !== undefined) {
12556
+ if (!["filtered", "selected", "all"].includes(request.scope))
12557
+ throw new TypeError("Invalid Canopy export scope.");
12558
+ result.push(["scope", request.scope]);
12559
+ }
12560
+ for (const key of ["total", "matched"])
12561
+ if (request[key] !== undefined) {
12562
+ const value = request[key];
12563
+ if (value === null) {
12564
+ result.push([key, "unknown"]);
12565
+ continue;
12566
+ }
12567
+ if (!Number.isSafeInteger(value) || value < 0)
12568
+ throw new TypeError("Canopy metadata counts must be nonnegative safe integers.");
12569
+ result.push([key, value]);
12570
+ }
12571
+ if (request.generatedAt !== undefined) {
12572
+ if (typeof request.generatedAt !== "string" || !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d{1,9})?Z$/.test(request.generatedAt) || !Number.isFinite(new Date(request.generatedAt).getTime()))
12573
+ throw new TypeError("Canopy generatedAt must be a captured UTC ISO instant.");
12574
+ result.push(["generatedAt", request.generatedAt]);
12575
+ }
12576
+ if (request.selection !== undefined) {
12577
+ if (!Array.isArray(request.selection) || request.selection.some(id => typeof id !== "string"))
12578
+ throw new TypeError("Canopy selection metadata must contain stable string IDs.");
12579
+ result.push(["selection", JSON.stringify(request.selection)]);
12580
+ }
12581
+ if (request.query !== undefined) {
12582
+ if (!request.query || typeof request.query !== "object" || Array.isArray(request.query))
12583
+ throw new TypeError("Canopy accepted query must be a captured object.");
12584
+ const query = JSON.stringify(request.query);
12585
+ if (typeof query !== "string")
12586
+ throw new TypeError("Canopy accepted query must serialize as JSON metadata.");
12587
+ result.push(["query", query]);
12588
+ }
12589
+ if (result.reduce((sum, row) => sum + row[0].length + String(row[1]).length, 0) > 65536)
12590
+ throw new RangeError("Canopy About metadata exceeds 65,536 captured characters.");
12591
+ // Validate known cell text before consuming details; overflow preservation and XML policy stay workbook-owned.
12592
+ for (const [field, value] of result) {
12593
+ cellText(field, options.invalidCharacterPolicy);
12594
+ if (options.oversizedText === "preserve")
12595
+ cleanXml(value, options.invalidCharacterPolicy);
12596
+ else
12597
+ cellText(value, options.invalidCharacterPolicy);
12598
+ }
12599
+ return Object.freeze(result.map(row => Object.freeze(row)));
12600
+ }
12601
+ const _exports = Object.freeze({ canopyAbout: canopyAbout });
12602
+ _modules.set("9ee68b08aff01ebcd88790854ac27b71235c5df5cab4a9575ffcf267e8fea5ea", _exports);
12603
+ return _exports;
12604
+ })();
12605
+
12606
+ const _m104 = _modules.get("ccfefc97a47cc288f2c9a2eed33fff323570e35193cedbd876ebb3e8fb78a42e") ?? (() => {
12607
+ const { Workbook, addGroupedXlsx } = _m23;
12608
+
12609
+ const { portableWorkbook } = _m53;
12610
+
12611
+ const { withDestination } = _m3;
12612
+
12613
+ /** Compose only the adapter's data/grouped sheet and optional metadata sheet in the existing workbook owner. */
12614
+ async function writeCanopyWorkbook(source, grouped, destination, options, labels, about) {
12615
+ const { sheet: sheetSettings = {}, columns: _columns, ...settings } = options;
12616
+ const { name = "Data", ...sheet } = sheetSettings;
12617
+ if (about && name.toLowerCase() === "about")
12618
+ throw new TypeError("The optional About worksheet needs a distinct data-sheet name.");
12619
+ if (grouped && settings.cellValueWriters !== undefined)
12620
+ throw new TypeError("Grouped Canopy exports use resolved source values rather than custom cellValueWriters.");
12621
+ return withDestination(destination, async (sink) => {
12622
+ const workbookOptions = { ...portableWorkbook(settings), sink };
12623
+ // Grouped worksheets generate native FormulaCells; flat tables keep the portable-value boundary.
12624
+ const book = grouped ? new Workbook(workbookOptions) : Workbook.forTable(workbookOptions);
12625
+ try {
12626
+ let rows, columns;
12627
+ if (grouped) {
12628
+ const { conditionalFormats, ...groupedSheet } = sheet;
12629
+ const written = await addGroupedXlsx(book, grouped, {
12630
+ labelColumn: { header: labels?.labelColumn?.header ?? "Group", width: 18 },
12631
+ subtotalLabel: labels?.subtotalLabel ?? (group => group.label + " total"),
12632
+ grandTotalLabel: labels?.grandTotalLabel ?? (() => "Grand total"),
12633
+ ...(labels?.includeGrandTotal === undefined ? {} : { includeGrandTotal: labels.includeGrandTotal }),
12634
+ sheet: { ...groupedSheet, name }, ...(conditionalFormats === undefined ? {} : { conditionalFormats })
12635
+ });
12636
+ rows = written.rows;
12637
+ columns = written.columns;
12638
+ }
12639
+ else {
12640
+ const data = book.addWorksheet(name, { boldHeader: true, autoFilter: sheet.includeHeader !== false,
12641
+ autoSize: { minWidth: 6, maxWidth: 54 }, ...sheet, columns: source.columns });
12642
+ await data.addRows(source.rows());
12643
+ await data.close();
12644
+ rows = data.rowCount;
12645
+ columns = source.columns.length;
12646
+ }
12647
+ if (about) {
12648
+ const metadata = book.addWorksheet("About", { columns: [{ header: "Field", width: 18 }, { header: "Value", width: 72, wrapText: true }],
12649
+ boldHeader: true, freezeHeader: true });
12650
+ await metadata.addRows(about);
12651
+ await metadata.close();
12652
+ }
12653
+ const result = await book.finish();
12654
+ return { rows, columns, bytes: result.bytes };
12655
+ }
12656
+ catch (error) {
12657
+ await book.discard(error);
12658
+ throw error;
12659
+ }
12660
+ });
12661
+ }
12662
+ const _exports = Object.freeze({ writeCanopyWorkbook: writeCanopyWorkbook });
12663
+ _modules.set("ccfefc97a47cc288f2c9a2eed33fff323570e35193cedbd876ebb3e8fb78a42e", _exports);
12664
+ return _exports;
12665
+ })();
12666
+
12667
+ const _m106 = _modules.get("0fb3a852d2d81b9921e07024df980295e7d9ad436f8f1640d90456dd4e36e2e0") ?? (() => {
12668
+ const { ExportCell } = _m1;
12669
+
12670
+ /** Fixed numeric formats affect PDF text, not the frozen numeric value used by other writers. */
12671
+ function numericProfile(format) {
12672
+ if (format === undefined)
12673
+ return undefined;
12674
+ const match = /^((?:"[^"\\]*")*)(#,##)?0(?:\.([0#]+))?(%)?((?:"[^"\\]*")*)$/.exec(format);
12675
+ if (!match || (match[3]?.length ?? 0) > 10)
12676
+ return undefined;
12677
+ return { minimumFractionDigits: (match[3]?.match(/0/g) ?? []).length, maximumFractionDigits: match[3]?.length ?? 0,
12678
+ percent: !!match[4], grouping: !!match[2], prefix: match[1].replace(/"/g, ""), suffix: match[5].replace(/"/g, "") };
12679
+ }
12680
+ /** Preserve the captured decimal convention across a column, including whole percentages without a separator. */
12681
+ function canopyPdfNumbers(sample, columns) {
12682
+ const formatters = new Map();
12683
+ const decimal = columns.map((column, index) => {
12684
+ let fallback = ".";
12685
+ for (const row of sample) {
12686
+ const cell = row[index];
12687
+ if (!(cell instanceof ExportCell) || typeof cell.value !== "number")
12688
+ continue;
12689
+ const profile = numericProfile(cell.presentation?.numberFormat ?? column.format);
12690
+ if (!profile?.maximumFractionDigits)
12691
+ continue;
12692
+ const match = /([.,])(\d+)[^\d.,]*$/.exec(cell.text ?? "");
12693
+ if (match && match[2].length <= profile.maximumFractionDigits) {
12694
+ const numeric = /([+-]?\d[\d.,]*)[^\d]*$/.exec(cell.text ?? "")?.[1] ?? "";
12695
+ const scaled = cell.value * (profile.percent ? 100 : 1);
12696
+ if (/^[+-]?\d{1,3}(?:,\d{3})+$/.test(numeric) || /^[+-]?\d{1,3}(?:\.\d{3})+$/.test(numeric)) {
12697
+ if (Math.abs(Number(numeric.replace(/[.,]/g, "")) - scaled) < .5) {
12698
+ fallback = match[1] === "," ? "." : ",";
12699
+ continue;
12700
+ }
12701
+ }
12702
+ return match[1];
12703
+ }
12704
+ }
12705
+ return fallback;
12706
+ });
12707
+ return row => row.map((value, index) => {
12708
+ if (!(value instanceof ExportCell) || typeof value.value !== "number")
12709
+ return value;
12710
+ const profile = numericProfile(value.presentation?.numberFormat ?? columns[index].format);
12711
+ if (!profile)
12712
+ return value;
12713
+ const captured = /^([^0-9+-]*)([+-]?\d[\d., \u00a0\u202f]*?)([^0-9]*)$/.exec(value.text ?? "");
12714
+ if (value.text && !captured)
12715
+ return value;
12716
+ const key = [decimal[index], profile.minimumFractionDigits, profile.maximumFractionDigits, profile.grouping].join(":");
12717
+ let formatter = formatters.get(key);
12718
+ if (!formatter) {
12719
+ formatter = new Intl.NumberFormat(decimal[index] === "," ? "de-DE" : "en-US", {
12720
+ minimumFractionDigits: profile.minimumFractionDigits, maximumFractionDigits: profile.maximumFractionDigits, useGrouping: profile.grouping
12721
+ });
12722
+ formatters.set(key, formatter);
12723
+ }
12724
+ const formatted = formatter.format(value.value * (profile.percent ? 100 : 1));
12725
+ const prefix = profile.prefix || captured?.[1] || "";
12726
+ let suffix = profile.suffix || captured?.[3] || "";
12727
+ if (profile.percent && !profile.suffix)
12728
+ suffix = suffix.replace(/%/g, "");
12729
+ return new ExportCell(value.value, { text: prefix + formatted + (profile.percent ? "%" : "") + suffix,
12730
+ ...(value.presentation ? { presentation: value.presentation } : {}), ...(value.link ? { link: value.link } : {}) });
12731
+ });
12732
+ }
12733
+ const _exports = Object.freeze({ canopyPdfNumbers: canopyPdfNumbers });
12734
+ _modules.set("0fb3a852d2d81b9921e07024df980295e7d9ad436f8f1640d90456dd4e36e2e0", _exports);
12735
+ return _exports;
12736
+ })();
12737
+
12738
+ const _m105 = _modules.get("8cf0b0de5a9930ea2c50a459ce70b695b69483978ca9343cb2c22982845ff142") ?? (() => {
12739
+ const { ExportCell, NotSupportedError, OfficeIMOError } = _m1;
12740
+
12741
+ const { inputRows, checkAbort, pause, taskYieldDue } = _m4;
12742
+
12743
+ const { fontProgram } = _m64;
12744
+
12745
+ const { resolveScalar, selectFont, validateFonts } = _m68;
12746
+
12747
+ const { settings } = _m17;
12748
+
12749
+ const { canopyPdfNumbers } = _m106;
12750
+
12751
+ /** A bounded lookahead is replayed once; no second capture, full-dataset copy or smaller font is needed. */
12752
+ async function withCanopyPdfLayout(source, captured, options, write) {
12753
+ const prepared = settings({ ...options, columns: source.columns }), { fontSize, padding, page, margins, limits } = prepared;
12754
+ options = prepared.options;
12755
+ validateFonts(options.fonts, limits.maxFontBytes);
12756
+ const available = page.width - margins.left - margins.right;
12757
+ const iterator = inputRows(source.rows(), options.signal)[Symbol.asyncIterator](), sample = [];
12758
+ let done = false, characters = 0;
12759
+ try {
12760
+ while (sample.length < Math.min(128, options.limits?.maxRows ?? 128) && characters < 262144) {
12761
+ const item = await iterator.next();
12762
+ if (item.done) {
12763
+ done = true;
12764
+ break;
12765
+ }
12766
+ sample.push(item.value);
12767
+ characters += item.value.reduce((n, cell) => n + (cell instanceof ExportCell ? cell.text?.length ?? 0 : String(cell ?? "").length), 0);
12768
+ }
12769
+ const format = canopyPdfNumbers(sample, source.columns), rows = sample.map(format);
12770
+ const measure = (text, bold = false, italic = false) => {
12771
+ if (text.length > limits.maxCellCharacters)
12772
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded.");
12773
+ const face = selectFont(options.fonts, bold, italic), program = face.font ? fontProgram(face.font) : undefined;
12774
+ let width = 0;
12775
+ for (const character of text.replace(/\t/g, " ")) {
12776
+ const scalar = resolveScalar(character.codePointAt(0), program, bold);
12777
+ if (!scalar.supported)
12778
+ throw new NotSupportedError(scalar.message);
12779
+ width += scalar.width * fontSize / 1000;
12780
+ }
12781
+ return width;
12782
+ };
12783
+ const largest = (parts, bold = false, italic = false) => parts.reduce((width, part) => Math.max(width, measure(part, bold, italic)), 0);
12784
+ let layout = {};
12785
+ // Explicit points/bands and shaping providers retain their own layout policy.
12786
+ if (!options.columnWidths && typeof options.wideTable !== "object" && !options.textShaper) {
12787
+ const minimum = source.columns.map(column => Math.min(available, largest(column.header.split(/\s+/), prepared.options.headerPresentation?.bold) + padding * 2 + .01));
12788
+ const natural = source.columns.map((column, index) => Math.min(available, Math.max(minimum[index], largest(column.header.split(/\r\n?|\n/), prepared.options.headerPresentation?.bold) + padding * 2 + .01)));
12789
+ for (const row of rows) {
12790
+ for (let i = 0; i < row.length; i++) {
12791
+ const cell = row[i], text = cell instanceof ExportCell ? cell.text ?? String(cell.value ?? "") : String(cell ?? "");
12792
+ const style = cell instanceof ExportCell ? cell.presentation : undefined;
12793
+ const line = largest(text.split(/\r\n?|\n/), style?.bold, style?.italic) + padding * 2 + .01;
12794
+ const word = largest(text.split(/\s+/), style?.bold, style?.italic) + padding * 2 + .01;
12795
+ natural[i] = Math.min(available, Math.max(natural[i], line));
12796
+ minimum[i] = Math.min(available, Math.max(minimum[i], captured[i].kind === "text" ? word : line));
12797
+ }
12798
+ if (taskYieldDue())
12799
+ await pause();
12800
+ checkAbort(options.signal);
12801
+ }
12802
+ const sum = minimum.reduce((total, width) => total + width, 0), widths = [...minimum];
12803
+ if (sum > available + .001)
12804
+ layout = { columnWidths: widths, wideTable: options.wideTable === "reject" ? "reject" : {
12805
+ mode: "bands", repeatColumns: widths[0] + Math.max(...widths.slice(1)) <= available ? [0] : []
12806
+ } };
12807
+ else {
12808
+ let spare = available - sum;
12809
+ const needs = natural.map((width, index) => Math.max(0, width - widths[index])), total = needs.reduce((n, width) => n + width, 0);
12810
+ for (let i = 0; i < widths.length; i++)
12811
+ widths[i] += total ? needs[i] * Math.min(1, spare / total) : 0;
12812
+ spare = available - widths.reduce((n, width) => n + width, 0);
12813
+ const text = captured.flatMap((column, index) => column.kind === "text" ? [index] : []);
12814
+ for (const i of text.length ? text : widths.map((_, index) => index))
12815
+ widths[i] += spare / (text.length || widths.length);
12816
+ layout = { columnWidths: widths };
12817
+ }
12818
+ }
12819
+ const replay = async function* () {
12820
+ for (const row of rows)
12821
+ yield row;
12822
+ while (!done) {
12823
+ const item = await iterator.next();
12824
+ if (item.done) {
12825
+ done = true;
12826
+ break;
12827
+ }
12828
+ yield format(item.value);
12829
+ }
12830
+ };
12831
+ return await write(replay(), layout, prepared.options);
12832
+ }
12833
+ finally {
12834
+ if (!done) {
12835
+ try {
12836
+ void iterator.return(undefined).catch(() => { });
12837
+ }
12838
+ catch { /* Keep the writer's original failure. */ }
12839
+ }
12840
+ }
12841
+ }
12842
+ const _exports = Object.freeze({ withCanopyPdfLayout: withCanopyPdfLayout });
12843
+ _modules.set("8cf0b0de5a9930ea2c50a459ce70b695b69483978ca9343cb2c22982845ff142", _exports);
12844
+ return _exports;
12845
+ })();
12846
+
12847
+ const _m0 = _modules.get("8a4acb328f0d0bd6089df8bcce4099064ea408bdef1e20d13fdbe59b083c76c9") ?? (() => {
12848
+ const { BlobByteSink, ExportCell } = _m1;
11691
12849
 
11692
12850
  const { notifyProgress } = _m14;
11693
12851
 
@@ -11697,38 +12855,119 @@ const { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOp
11697
12855
 
11698
12856
  const { writeXlsxTo } = _m23;
11699
12857
 
11700
- const { writeCsvTo } = _m55;
12858
+ const { writeCsvTo } = _m56;
12859
+
12860
+ const { writePdfTo, writeGroupedPdfTo } = _m58;
12861
+
12862
+ const { canopyDiagnostics } = _m95;
12863
+
12864
+ const { prepareCanopyExport } = _m96;
12865
+
12866
+ const { canopyPins } = _m99;
12867
+
12868
+ const { canopyRules } = _m100;
11701
12869
 
11702
- const { writePdfTo } = _m57;
12870
+ const { canopyGrouped } = _m102;
11703
12871
 
11704
- const { createCanopyExport } = _m94;
12872
+ const { canopyAbout } = _m103;
11705
12873
 
12874
+ const { writeCanopyWorkbook } = _m104;
11706
12875
 
12876
+ const { withCanopyPdfLayout } = _m105;
11707
12877
 
11708
12878
 
11709
12879
 
11710
12880
 
11711
12881
 
11712
- /** Write a captured CanopyX grid to a caller-owned destination; its partial bytes remain caller-owned on failure. */
12882
+
12883
+
12884
+ /** Write a captured CanopyX grid to a caller-owned destination; partial bytes remain caller-owned on failure. */
11713
12885
  async function writeCanopyTo(capture, format, destination, options = {}) {
11714
- const selected = captureFields(options, ["tones", "columnOptions", "unsupportedPresentation", "datetime", "xlsx", "csv", "pdf", "signal", "onDiagnostic", "limits", "onProgress"]);
12886
+ const selected = captureFields(options, ["tones", "columnOptions", "unsupportedPresentation", "datetime", "xlsx", "csv", "pdf", "signal", "onDiagnostic", "limits", "onProgress", "grouped", "about"]);
11715
12887
  const { signal, onProgress } = selected, limits = captureCommonLimits(selected.limits);
11716
12888
  const xlsx = captureXlsxOptions(format === "xlsx" ? selected.xlsx : undefined);
11717
12889
  const csv = captureCsvOptions(format === "csv" ? selected.csv : undefined);
11718
12890
  const pdf = capturePdfOptions(format === "pdf" ? selected.pdf : undefined);
11719
- const source = createCanopyExport(capture, format, { ...selected, xlsx });
12891
+ const prepared = prepareCanopyExport(capture, format, { ...selected, xlsx }), { request, report, tones, pivot } = prepared;
12892
+ if (selected.about !== undefined && typeof selected.about !== "boolean")
12893
+ throw new TypeError("Canopy about must be boolean.");
12894
+ const labels = selected.grouped === undefined ? undefined : captureFields(selected.grouped, ["labelColumn", "subtotalLabel", "grandTotalLabel", "includeGrandTotal", "continuationLabel", "groupHeadingLevel"]);
12895
+ const capturedLabels = labels && { ...labels, ...(labels.labelColumn === undefined ? {} : { labelColumn: Object.freeze({ header: labels.labelColumn.header }) }) };
12896
+ const about = format === "xlsx" && selected.about ? canopyAbout(request, xlsx) : undefined;
12897
+ const ruleCellTypes = new Map();
12898
+ let consumed = 0;
12899
+ const source = Object.freeze({ ...prepared.source, async *rows() {
12900
+ for await (const row of prepared.source.rows()) {
12901
+ for (const [column, type] of ruleCellTypes) {
12902
+ const cell = row[column], raw = cell instanceof ExportCell ? cell.value : cell;
12903
+ if (raw == null || type === "number" && typeof raw === "number" && Number.isFinite(raw) || type === "date" && raw instanceof Date && Number.isFinite(raw.getTime()))
12904
+ continue;
12905
+ const code = "UNSUPPORTED_NATIVE_RULE_CELL_TYPE:" + type;
12906
+ report({ code, columnId: source.columns[column].key });
12907
+ // Text fallback cannot retract an already captured native declaration after streaming starts.
12908
+ throw new TypeError("Unsupported Canopy presentation: " + code + " (" + source.columns[column].key + ")");
12909
+ }
12910
+ consumed++;
12911
+ yield row;
12912
+ }
12913
+ } });
11720
12914
  const progress = onProgress ? { onProgress: (event) => {
11721
- notifyProgress(onProgress, { ...event, ...(source.rowCount === null ? {} : { totalRows: source.rowCount }) });
12915
+ // About and generated group rows consume output budgets, but never become exported source details.
12916
+ notifyProgress(onProgress, { ...event, rows: consumed,
12917
+ ...(event.sheetRows === undefined ? {} : { sheetRows: about !== undefined && event.sheetName === "About" ? 0 : consumed }),
12918
+ ...(source.rowCount === null ? {} : { totalRows: source.rowCount }) });
11722
12919
  } } : {};
11723
12920
  const stream = { ...(signal ? { signal } : {}), ...progress };
11724
- if (format === "xlsx")
11725
- return writeXlsxTo(source.rows(), destination, { ...xlsx, ...stream, columns: source.columns,
11726
- dateMode: xlsx.dateMode ?? capture.request.timeZone,
11727
- limits: mergeAdapterLimits(xlsx.limits, limits) });
11728
- if (format === "pdf")
11729
- return writePdfTo(source.rows(), destination, { ...pdf, ...stream, columns: source.columns,
11730
- limits: mergeAdapterLimits(pdf.limits, limits) });
11731
- return writeCsvTo(source.rows(), destination, { ...csv, ...stream, columns: source.columns, valueMode: capture.request.values,
12921
+ if (format === "xlsx") {
12922
+ const formatLimits = mergeAdapterLimits(xlsx.limits, limits), grouped = pivot ? undefined : canopyGrouped(source, request, { ...selected, xlsx }, formatLimits, report, format);
12923
+ const pinned = canopyPins(request.columns, report), rules = canopyRules(request, format, grouped !== undefined, tones, report, { ...selected, xlsx }, ruleCellTypes);
12924
+ if (pivot && (xlsx.sheet?.rowOutline !== undefined || xlsx.sheet?.columnOutlines !== undefined || xlsx.sheet?.maxOutlineLevel !== undefined ||
12925
+ xlsx.sheet?.outlineSummaryBelow !== undefined || xlsx.sheet?.outlineSummaryRight !== undefined || xlsx.sheet?.table !== undefined || xlsx.sheet?.footer !== undefined))
12926
+ throw new TypeError("Captured pivot metadata owns outlines and totals; worksheet overrides cannot regroup or recalculate it.");
12927
+ if (pivot && xlsx.cellValueWriters !== undefined)
12928
+ throw new TypeError("Captured pivot exports use frozen values rather than custom cellValueWriters.");
12929
+ const sheet = { ...xlsx.sheet, ...(pivot?.sheet ?? {}), ...(pivot ? { autoFilter: false } : {}),
12930
+ freezeHeader: xlsx.sheet?.freezeHeader ?? (xlsx.sheet?.includeHeader !== false),
12931
+ freezeColumns: xlsx.sheet?.freezeColumns ?? (pinned ? pinned + (grouped ? 1 : 0) : 0),
12932
+ conditionalFormats: [...rules, ...(xlsx.sheet?.conditionalFormats ?? [])] };
12933
+ const settings = { ...xlsx, ...stream, columns: source.columns, sheet, dateMode: xlsx.dateMode ?? request.timeZone, limits: formatLimits };
12934
+ if (grouped || about)
12935
+ return writeCanopyWorkbook(source, grouped, destination, settings, capturedLabels, about);
12936
+ return writeXlsxTo(source.rows(), destination, settings);
12937
+ }
12938
+ if (pivot)
12939
+ canopyDiagnostics(format, { ...selected, unsupportedPresentation: "text" })({ code: "PIVOT_OUTLINES_XLSX_ONLY" });
12940
+ if (format === "pdf") {
12941
+ if (pivot && pdf.footer?.totals !== undefined)
12942
+ throw new TypeError("Captured pivot metadata owns totals; PDF footer totals cannot recalculate it.");
12943
+ const formatLimits = mergeAdapterLimits(pdf.limits, limits), grouped = pivot ? undefined : canopyGrouped(source, request, selected, formatLimits, report, format);
12944
+ canopyRules(request, format, grouped !== undefined, tones, report, selected);
12945
+ // CSS pixels become points before the existing fit/band policy. Explicit PDF point widths win.
12946
+ const fitted = request.columns.every(column => column.width !== undefined) ? request.columns.map(column => column.width.preferred * 72 / 96) : undefined;
12947
+ const widths = pdf.columnWidths ?? fitted;
12948
+ const settings = { orientation: "landscape", wideTable: "fit", ...pdf, ...stream, limits: formatLimits };
12949
+ if (grouped) {
12950
+ if (pdf.headerRows !== undefined || pdf.footer !== undefined)
12951
+ throw new TypeError("Grouped Canopy PDF owns heading and summary rows.");
12952
+ const { headerRows: _headers, footer: _footer, ...groupedSettings } = settings;
12953
+ return writeGroupedPdfTo(grouped, destination, { ...groupedSettings,
12954
+ ...(widths === undefined ? {} : { columnWidths: [72, ...widths] }),
12955
+ labelColumn: { header: capturedLabels?.labelColumn?.header ?? "Group", width: 12 },
12956
+ subtotalLabel: capturedLabels?.subtotalLabel ?? (group => group.label + " total"),
12957
+ grandTotalLabel: capturedLabels?.grandTotalLabel ?? (() => "Grand total"),
12958
+ ...(capturedLabels?.includeGrandTotal === undefined ? {} : { includeGrandTotal: capturedLabels.includeGrandTotal }),
12959
+ ...(capturedLabels?.continuationLabel === undefined ? {} : { continuationLabel: capturedLabels.continuationLabel }),
12960
+ ...(capturedLabels?.groupHeadingLevel === undefined ? {} : { groupHeadingLevel: capturedLabels.groupHeadingLevel }) });
12961
+ }
12962
+ return withCanopyPdfLayout(prepared.source, request.columns, settings, async (rows, layout, captured) => {
12963
+ const counted = async function* () { for await (const row of rows) {
12964
+ consumed++;
12965
+ yield row;
12966
+ } };
12967
+ return writePdfTo(counted(), destination, { ...captured, ...layout, columns: source.columns });
12968
+ });
12969
+ }
12970
+ return writeCsvTo(source.rows(), destination, { ...csv, ...stream, columns: source.columns, valueMode: request.values,
11732
12971
  limits: mergeAdapterLimits(csv.limits, limits) });
11733
12972
  }
11734
12973
  /** Export an immutable native capture as a Blob without loading or registering CanopyX. */
@@ -11743,8 +12982,8 @@ async function exportCanopy(capture, format, options = {}) {
11743
12982
  throw error;
11744
12983
  }
11745
12984
  }
11746
- const _exports = Object.freeze({ createCanopyExport: _m94.createCanopyExport, ExportCell: _m5.ExportCell, PdfFont: _m63.PdfFont, writeCanopyTo: writeCanopyTo, exportCanopy: exportCanopy });
11747
- _modules.set("3e66cc3ead243255e3903dfabd767d39c2507193c6631b6a40caad66216c13ed", _exports);
12985
+ const _exports = Object.freeze({ createCanopyExport: _m96.createCanopyExport, ExportCell: _m5.ExportCell, PdfFont: _m64.PdfFont, writeCanopyTo: writeCanopyTo, exportCanopy: exportCanopy });
12986
+ _modules.set("8a4acb328f0d0bd6089df8bcce4099064ea408bdef1e20d13fdbe59b083c76c9", _exports);
11748
12987
  return _exports;
11749
12988
  })();
11750
12989
  Object.assign(officeimo, _m0);