@evotecit/officeimo 0.1.4 → 0.1.5
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.
- package/README.md +3 -1
- package/bundles/officeimo-canopyx.js +107 -50
- package/bundles/officeimo-canopyx.mjs +95 -38
- package/dist/integrations/canopyx/pdf-number.d.ts +1 -1
- package/dist/integrations/canopyx/pdf-number.js +88 -35
- package/dist/integrations/canopyx/pivot.d.ts +1 -1
- package/dist/integrations/canopyx/pivot.js +4 -0
- package/dist/integrations/canopyx/source.js +2 -2
- package/dist/integrations/canopyx/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -207,7 +207,7 @@ const blob = await exportCanopy(capture, "xlsx", {
|
|
|
207
207
|
|
|
208
208
|
The width profile provides reproducible conversion; it does not promise pixel-identical rendering in native Excel. `columnOptions[id].width` overrides the XLSX character width, and `pdf.columnWidths` overrides PDF point widths. Right and nonleading pins retain their column order and require an explicit text fallback diagnostic. `columnOptions` applies only to selected IDs; native `columnOptions[id].format` remains the explicit Excel-format override.
|
|
209
209
|
|
|
210
|
-
For a pivot table, pass the frozen `prepareExport({ pivot: true, scope: "filtered", values: "raw" })` capture through the same entry point. Numeric cells retain their already-computed `mode` and native `numberFormat`: a fractional share stays numeric and receives a percent format without multiplying or parsing its text. Empty intersections need neither field; an explicit empty column format selects `General`. Row and column identities are opaque. `recordCount` counts physical projected rows, including summaries; `matched` still describes the underlying accepted records.
|
|
210
|
+
For a pivot table, pass the frozen `prepareExport({ pivot: true, scope: "filtered", values: "raw" })` capture through the same entry point. Numeric cells retain their already-computed `mode` and native `numberFormat`: a fractional share stays numeric and receives a percent format without multiplying or parsing its text. Plain `mode: "value"` cells may omit `numberFormat`; transformed modes still require it. Empty intersections need neither field; an explicit empty column format selects `General`. Row and column identities are opaque. `recordCount` counts physical projected rows, including summaries; `matched` still describes the underlying accepted records.
|
|
211
211
|
|
|
212
212
|
XLSX places pivot summaries above their descendants and to their left, preserving captured outline levels, hidden descendants and collapsed summaries. It does not add `SUBTOTAL` formulas, a table or an autofilter over the pre-aggregated projection. Captured pivot outlines and totals reject conflicting worksheet overrides. Pivot exports also reject XLSX `cellValueWriters` and PDF `footer.totals`, preserving frozen values and aggregates. PDF and CSV include the complete projection, including initially hidden descendants; `PIVOT_OUTLINES_XLSX_ONLY` reports that the interactive outline controls belong to Excel. PDF retains resolved display text, headings and normal fit/band policies. A malformed explicit pivot rejects instead of silently becoming an ordinary flat export.
|
|
213
213
|
|
|
@@ -221,6 +221,8 @@ Datetime rule filters require `datetime: "typed"` and the UTC XLSX clock. Operan
|
|
|
221
221
|
|
|
222
222
|
PDF defaults to landscape without shrinking the font. Flat and pivot captures measure the selected PDF font against a bounded lookahead of up to 128 rows or 262,144 displayed UTF-16 code units, then replay that single source. Column minimums protect the longest sampled header/content word; numeric and date columns reserve their natural value width. Remaining width first satisfies full header/content preferences, then goes to text columns. If the minimums exceed the printable width, horizontal bands retain readable widths. A word wider than a page can still break at scalar boundaries; later rows use the writer's ordinary lossless wrapping. Explicit `pdf.columnWidths`, horizontal-band settings and shaping providers retain their own layout policy.
|
|
223
223
|
|
|
224
|
+
The same flat/pivot PDF lookahead chooses one numeric convention for the entire document, including later streamed rows. A captured percentage's decimal comma or point takes precedence; otherwise the first numeric decimal mark is used, with a point when the sample has no signal. Grouping marks are distinguished from decimal marks using the frozen numeric value. Supported fixed number formats share that convention while retaining their declared precision and literal affixes. Unformatted whole values, including count aggregates, render as integers; an explicit `0.00` still requests two decimal places. Unformatted fractional values retain their captured precision. For example, with comma percentages a declared two-decimal amount is `1234,50`, an undeclared count is `3`, and an explicitly two-decimal count is `3,00`. CSV/XLSX keep their raw numeric values.
|
|
225
|
+
|
|
224
226
|
Canopy PDF cells wrap independently of the grid's screen `wrap` setting. A seven-column grid with screen `wrap: false` still exports its full text, dates and numbers. An explicit `columnOptions[id].wrapText: false` retains strict nonwrapping behavior and rejects content that cannot fit; use suitable `pdf.columnWidths` or horizontal bands for that contract. Pivot summary and total rows are bold, and numeric columns default to right alignment. Raw numeric captures apply simple declared decimal/percentage/grouping formats to PDF text, retaining the sampled column's decimal separator and captured affixes. Complex native formats retain their resolved text. Missing values remain blank and computed zero values remain zero; neither is invented from the other. XLSX retains the captured screen wrapping unless overridden. Group headings, repeated column headings and continuation context use the existing grouped layout. Supply embedding-permitted TrueType fonts through `pdf.fonts` for Unicode, and a declared language through `pdf.tagged` for tagged reports. XLSX's native rule declarations do not render PDF bars or scales: PDF reports that loss and requires `unsupportedPresentation: "text"` to accept it. This option does not remove typed values, resolved text or valid links.
|
|
225
227
|
|
|
226
228
|
Ordinary text-only grid/tree captures are accepted as flat output. Tree indentation does not create analytical groups. Relative links, history-series presentation and unmapped row/cell tones use the scalar/text projections above and report their presentation loss through synchronous `onDiagnostic` when supplied. Genuine unsupported presentation diagnostics and unsupported declarations still reject by default in XLSX/PDF. Explicit `unsupportedPresentation: "text"` accepts their text fallback and reports each diagnostic through the same callback. CSV defaults to text. Unsafe hyperlinks remain rejected. No unbounded diagnostic list or whole-table body is retained.
|
|
@@ -11698,7 +11698,7 @@ _modules.set("3d1862d8ab32171bca4b3ba5fe0bdcc073f67ce940aaff0ee735635893f86ee8",
|
|
|
11698
11698
|
return _exports;
|
|
11699
11699
|
})();
|
|
11700
11700
|
|
|
11701
|
-
const _m97 = _modules.get("
|
|
11701
|
+
const _m97 = _modules.get("5e0a9bdc75106268fcdff0cc6d7778080db216c7597514163f5fe5ff8ce93be1") ?? (() => {
|
|
11702
11702
|
function presentation(input, axes) {
|
|
11703
11703
|
const { axisKey, outlineLevel, summary, grandTotal, hidden, collapsed } = input;
|
|
11704
11704
|
if (typeof axisKey !== "string" || !axes.has(axisKey) || !Number.isInteger(outlineLevel) || outlineLevel < 0 || outlineLevel > 7 ||
|
|
@@ -11761,13 +11761,17 @@ function canopyPivot(request) {
|
|
|
11761
11761
|
}
|
|
11762
11762
|
/** Per-cell formats preserve already-computed fractional percentages, ranks and differences. */
|
|
11763
11763
|
function pivotNumberFormat(cell) {
|
|
11764
|
+
// Raw-value aggregates need no decimal declaration. Transformed values still
|
|
11765
|
+
// require the producer's frozen format (especially percent scaling).
|
|
11766
|
+
if (cell.mode === "value" && cell.numberFormat === undefined)
|
|
11767
|
+
return undefined;
|
|
11764
11768
|
if (!["value", "percentGrandTotal", "percentParent", "percentColumn", "percentRow", "runningTotal", "rank", "difference", "percentChange"].includes(cell.mode ?? "") ||
|
|
11765
11769
|
typeof cell.numberFormat !== "string" || !cell.numberFormat.length)
|
|
11766
11770
|
throw new TypeError("Numeric pivot cells require a frozen mode and native numberFormat.");
|
|
11767
11771
|
return cell.numberFormat;
|
|
11768
11772
|
}
|
|
11769
11773
|
const _exports = Object.freeze({ canopyPivot: canopyPivot, pivotNumberFormat: pivotNumberFormat });
|
|
11770
|
-
_modules.set("
|
|
11774
|
+
_modules.set("5e0a9bdc75106268fcdff0cc6d7778080db216c7597514163f5fe5ff8ce93be1", _exports);
|
|
11771
11775
|
return _exports;
|
|
11772
11776
|
})();
|
|
11773
11777
|
|
|
@@ -11857,7 +11861,7 @@ _modules.set("040752afe195985e6f2e91f8c62fc13464c455fc44034b8cef4828851e05b83d",
|
|
|
11857
11861
|
return _exports;
|
|
11858
11862
|
})();
|
|
11859
11863
|
|
|
11860
|
-
const _m96 = _modules.get("
|
|
11864
|
+
const _m96 = _modules.get("40e200b77947621ffacdfa2e1326760a78a52a7dfb6d0cbaa7c7a71607b119a2") ?? (() => {
|
|
11861
11865
|
const { ExportCell, checkAbort, inputRows } = _m1;
|
|
11862
11866
|
|
|
11863
11867
|
const { canopyPivot, pivotNumberFormat } = _m97;
|
|
@@ -11999,11 +12003,11 @@ function prepareCanopyExport(capture, format, options = {}) {
|
|
|
11999
12003
|
if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
|
|
12000
12004
|
value = datetime(value, dateMode, clock);
|
|
12001
12005
|
const capturedFormat = pivot && spec.kind === "number" && cell.value !== null ? pivotNumberFormat(cell) : undefined;
|
|
12002
|
-
const nativeFormat =
|
|
12006
|
+
const nativeFormat = spec.nativeFormatOverride === "" ? "General" : spec.nativeFormatOverride ?? capturedFormat;
|
|
12003
12007
|
const summary = format === "pdf" && pivot && (row.summary || row.grandTotal);
|
|
12004
12008
|
const cellStyle = tone(cell.tone, row.id, spec.id), presentation = rowStyle || cellStyle || nativeFormat || summary ? {
|
|
12005
12009
|
...rowStyle, ...(summary ? { bold: true } : {}), ...cellStyle,
|
|
12006
|
-
...((format === "
|
|
12010
|
+
...((format === "pdf" || (format === "xlsx" && pivot)) && values === "raw" && nativeFormat !== undefined ? { numberFormat: nativeFormat } : {})
|
|
12007
12011
|
} : undefined;
|
|
12008
12012
|
// CSV has no presentation or link metadata: emit its selected scalar directly.
|
|
12009
12013
|
// This also avoids a frozen wrapper for every cell in large CSV captures.
|
|
@@ -12027,7 +12031,7 @@ function prepareCanopyExport(capture, format, options = {}) {
|
|
|
12027
12031
|
return Object.freeze({ source, request: Object.freeze({ ...request, columns: Object.freeze(specs.map(spec => spec.input)) }), report, tones, pivot });
|
|
12028
12032
|
}
|
|
12029
12033
|
const _exports = Object.freeze({ canopyIdentityValue: canopyIdentityValue, createCanopyExport: createCanopyExport, prepareCanopyExport: prepareCanopyExport });
|
|
12030
|
-
_modules.set("
|
|
12034
|
+
_modules.set("40e200b77947621ffacdfa2e1326760a78a52a7dfb6d0cbaa7c7a71607b119a2", _exports);
|
|
12031
12035
|
return _exports;
|
|
12032
12036
|
})();
|
|
12033
12037
|
|
|
@@ -12334,7 +12338,7 @@ _modules.set("eb8cf81d2a340cdb41301d59c667cef44f3ad1d6a19f717eb8137257b545115e",
|
|
|
12334
12338
|
return _exports;
|
|
12335
12339
|
})();
|
|
12336
12340
|
|
|
12337
|
-
const _m102 = _modules.get("
|
|
12341
|
+
const _m102 = _modules.get("97b7bd3037e8060328387470a7e471b6933f1fa062e9562c7908f8ea9a29044b") ?? (() => {
|
|
12338
12342
|
const { createGroupedReport } = _m8;
|
|
12339
12343
|
|
|
12340
12344
|
const { checkAbort } = _m4;
|
|
@@ -12540,7 +12544,7 @@ function canopyGrouped(source, request, options, limits, report, format) {
|
|
|
12540
12544
|
...(options.signal === undefined ? {} : { signal: options.signal }), ...(sourceLimits === undefined ? {} : { limits: sourceLimits }) });
|
|
12541
12545
|
}
|
|
12542
12546
|
const _exports = Object.freeze({ canopyGrouped: canopyGrouped });
|
|
12543
|
-
_modules.set("
|
|
12547
|
+
_modules.set("97b7bd3037e8060328387470a7e471b6933f1fa062e9562c7908f8ea9a29044b", _exports);
|
|
12544
12548
|
return _exports;
|
|
12545
12549
|
})();
|
|
12546
12550
|
|
|
@@ -12664,78 +12668,131 @@ _modules.set("ccfefc97a47cc288f2c9a2eed33fff323570e35193cedbd876ebb3e8fb78a42e",
|
|
|
12664
12668
|
return _exports;
|
|
12665
12669
|
})();
|
|
12666
12670
|
|
|
12667
|
-
const _m106 = _modules.get("
|
|
12671
|
+
const _m106 = _modules.get("ac2d9b4299940637c2762e636ef75d8c1339cd95cdd8d53c48b26583e5f1e561") ?? (() => {
|
|
12668
12672
|
const { ExportCell } = _m1;
|
|
12669
12673
|
|
|
12670
12674
|
/** Fixed numeric formats affect PDF text, not the frozen numeric value used by other writers. */
|
|
12671
12675
|
function numericProfile(format) {
|
|
12672
|
-
|
|
12673
|
-
|
|
12674
|
-
|
|
12676
|
+
// No declared precision: whole values (including counts) stay whole.
|
|
12677
|
+
if (format === undefined || format === "General")
|
|
12678
|
+
return { minimumFractionDigits: 0, maximumFractionDigits: 20,
|
|
12679
|
+
percent: false, grouping: false, prefix: "", suffix: "" };
|
|
12680
|
+
const match = /^((?:"[^"]*"|\\["%])*)(#,##)?0(?:\.([0#]+))?(%)?((?:"[^"]*"|\\["%])*)$/.exec(format);
|
|
12675
12681
|
if (!match || (match[3]?.length ?? 0) > 10)
|
|
12676
12682
|
return undefined;
|
|
12683
|
+
const literal = (text) => text.replace(/"([^"]*)"|\\(["%])/g, (_, quoted, escaped) => quoted ?? escaped);
|
|
12677
12684
|
return { minimumFractionDigits: (match[3]?.match(/0/g) ?? []).length, maximumFractionDigits: match[3]?.length ?? 0,
|
|
12678
|
-
percent: !!match[4], grouping: !!match[2], prefix: match[1]
|
|
12679
|
-
}
|
|
12680
|
-
/**
|
|
12681
|
-
function
|
|
12682
|
-
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
|
|
12686
|
-
|
|
12687
|
-
|
|
12688
|
-
|
|
12689
|
-
|
|
12690
|
-
|
|
12691
|
-
|
|
12692
|
-
|
|
12693
|
-
|
|
12694
|
-
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
|
|
12685
|
+
percent: !!match[4], grouping: !!match[2], prefix: literal(match[1]), suffix: literal(match[5]) };
|
|
12686
|
+
}
|
|
12687
|
+
/** Separate declared literal units before recognizing the captured numeric token. */
|
|
12688
|
+
function capturedNumber(text, profile) {
|
|
12689
|
+
let body = text, signBeforePrefix = false;
|
|
12690
|
+
if (profile.prefix && body.startsWith(profile.prefix))
|
|
12691
|
+
body = body.slice(profile.prefix.length);
|
|
12692
|
+
else if (profile.prefix && /^[+-]/.test(body) && body.slice(1).startsWith(profile.prefix)) {
|
|
12693
|
+
signBeforePrefix = true;
|
|
12694
|
+
body = body[0] + body.slice(1 + profile.prefix.length);
|
|
12695
|
+
}
|
|
12696
|
+
if (profile.suffix && body.endsWith(profile.suffix))
|
|
12697
|
+
body = body.slice(0, -profile.suffix.length);
|
|
12698
|
+
const match = /^([^0-9+-]*)([+-]?\d[\d., \u00a0\u202f]*?)([^0-9]*)$/.exec(body);
|
|
12699
|
+
return match ? { prefix: profile.prefix || match[1], number: match[2], suffix: profile.suffix || match[3], signBeforePrefix } : undefined;
|
|
12700
|
+
}
|
|
12701
|
+
/** Distinguish a captured thousands mark from a decimal, using the raw value. */
|
|
12702
|
+
function groupedInteger(numeric, value) {
|
|
12703
|
+
if (!/^[+-]?\d{1,3}(?:,\d{3})+$/.test(numeric) && !/^[+-]?\d{1,3}(?:\.\d{3})+$/.test(numeric))
|
|
12704
|
+
return false;
|
|
12705
|
+
const grouped = Number(numeric.replace(/[.,]/g, ""));
|
|
12706
|
+
return grouped !== 0 && Math.abs(grouped - value) <= .5;
|
|
12707
|
+
}
|
|
12708
|
+
/** Choose once for the document; percent text is the strongest captured culture signal. */
|
|
12709
|
+
function documentDecimal(sample, columns) {
|
|
12710
|
+
let fallback;
|
|
12711
|
+
for (const percent of [true, false]) {
|
|
12712
|
+
for (const row of sample)
|
|
12713
|
+
for (let index = 0; index < columns.length; index++) {
|
|
12714
|
+
const cell = row[index], column = columns[index];
|
|
12715
|
+
if (!(cell instanceof ExportCell) || typeof cell.value !== "number")
|
|
12716
|
+
continue;
|
|
12717
|
+
const profile = numericProfile(cell.presentation?.numberFormat ?? column.format);
|
|
12718
|
+
if (!profile)
|
|
12719
|
+
continue;
|
|
12720
|
+
const captured = capturedNumber(cell.text ?? "", profile);
|
|
12721
|
+
if (!captured)
|
|
12722
|
+
continue;
|
|
12723
|
+
// A literal percent label is a culture signal without requesting numeric scaling.
|
|
12724
|
+
const percentageSignal = profile.percent || profile.prefix.includes("%") || profile.suffix.includes("%") || (cell.text ?? "").includes("%");
|
|
12725
|
+
if (percentageSignal !== percent)
|
|
12726
|
+
continue;
|
|
12727
|
+
const match = /([.,])(\d+)$/.exec(captured.number.trimEnd());
|
|
12728
|
+
if (match) {
|
|
12729
|
+
const numeric = captured.number;
|
|
12730
|
+
// An override changes output scaling/precision, not the captured label.
|
|
12731
|
+
if (groupedInteger(numeric, cell.value) || (percentageSignal && groupedInteger(numeric, cell.value * 100))) {
|
|
12698
12732
|
fallback = match[1] === "," ? "." : ",";
|
|
12699
12733
|
continue;
|
|
12700
12734
|
}
|
|
12735
|
+
return match[1];
|
|
12701
12736
|
}
|
|
12702
|
-
return match[1];
|
|
12703
12737
|
}
|
|
12704
|
-
|
|
12705
|
-
|
|
12706
|
-
}
|
|
12738
|
+
if (fallback !== undefined)
|
|
12739
|
+
return fallback;
|
|
12740
|
+
}
|
|
12741
|
+
return ".";
|
|
12742
|
+
}
|
|
12743
|
+
/** Apply one captured numeric convention to every supported numeric cell, including later streamed rows. */
|
|
12744
|
+
function canopyPdfNumbers(sample, columns) {
|
|
12745
|
+
const formatters = new Map(), decimal = documentDecimal(sample, columns);
|
|
12707
12746
|
return row => row.map((value, index) => {
|
|
12708
12747
|
if (!(value instanceof ExportCell) || typeof value.value !== "number")
|
|
12709
12748
|
return value;
|
|
12710
|
-
const
|
|
12711
|
-
|
|
12749
|
+
const format = value.presentation?.numberFormat ?? columns[index].format;
|
|
12750
|
+
let profile = numericProfile(format);
|
|
12751
|
+
if (!profile || value.text === "")
|
|
12712
12752
|
return value;
|
|
12713
|
-
const captured =
|
|
12753
|
+
const captured = capturedNumber(value.text ?? "", profile);
|
|
12714
12754
|
if (value.text && !captured)
|
|
12715
12755
|
return value;
|
|
12716
|
-
|
|
12756
|
+
// Undeclared formats normalize only plain numeric labels; a decoration
|
|
12757
|
+
// alone does not declare how the raw value was transformed for display.
|
|
12758
|
+
if ((format === undefined || format === "General") && captured && (captured.prefix.trim() || captured.suffix.trim()))
|
|
12759
|
+
return value;
|
|
12760
|
+
if (format === undefined || format === "General") {
|
|
12761
|
+
const digits = Number.isInteger(value.value) || (captured && groupedInteger(captured.number, value.value)) ? 0 :
|
|
12762
|
+
captured ? /[.,](\d+)$/.exec(captured.number.trimEnd())?.[1]?.length ?? 0 : undefined;
|
|
12763
|
+
// Retain a fractional value's captured precision, without padding an
|
|
12764
|
+
// undeclared whole aggregate merely because its display text was padded.
|
|
12765
|
+
if (digits !== undefined && digits <= 20)
|
|
12766
|
+
profile = { ...profile, minimumFractionDigits: digits, maximumFractionDigits: digits };
|
|
12767
|
+
}
|
|
12768
|
+
const key = [profile.minimumFractionDigits, profile.maximumFractionDigits, profile.grouping].join(":");
|
|
12717
12769
|
let formatter = formatters.get(key);
|
|
12718
12770
|
if (!formatter) {
|
|
12719
|
-
formatter = new Intl.NumberFormat(decimal
|
|
12771
|
+
formatter = new Intl.NumberFormat(decimal === "," ? "de-DE" : "en-US", {
|
|
12720
12772
|
minimumFractionDigits: profile.minimumFractionDigits, maximumFractionDigits: profile.maximumFractionDigits, useGrouping: profile.grouping
|
|
12721
12773
|
});
|
|
12722
12774
|
formatters.set(key, formatter);
|
|
12723
12775
|
}
|
|
12724
|
-
|
|
12725
|
-
|
|
12726
|
-
|
|
12776
|
+
let formatted = formatter.format(value.value * (profile.percent ? 100 : 1));
|
|
12777
|
+
if (captured?.number.startsWith("+") && !formatted.startsWith("-"))
|
|
12778
|
+
formatted = "+" + formatted;
|
|
12779
|
+
const leadingSign = captured?.signBeforePrefix ? /^[+-]/.exec(formatted)?.[0] ?? "" : "";
|
|
12780
|
+
if (leadingSign)
|
|
12781
|
+
formatted = formatted.slice(1);
|
|
12782
|
+
const prefix = captured?.prefix || profile.prefix;
|
|
12783
|
+
let suffix = captured?.suffix || profile.suffix;
|
|
12727
12784
|
if (profile.percent && !profile.suffix)
|
|
12728
12785
|
suffix = suffix.replace(/%/g, "");
|
|
12729
|
-
return new ExportCell(value.value, { text: prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
12786
|
+
return new ExportCell(value.value, { text: leadingSign + prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
12730
12787
|
...(value.presentation ? { presentation: value.presentation } : {}), ...(value.link ? { link: value.link } : {}) });
|
|
12731
12788
|
});
|
|
12732
12789
|
}
|
|
12733
12790
|
const _exports = Object.freeze({ canopyPdfNumbers: canopyPdfNumbers });
|
|
12734
|
-
_modules.set("
|
|
12791
|
+
_modules.set("ac2d9b4299940637c2762e636ef75d8c1339cd95cdd8d53c48b26583e5f1e561", _exports);
|
|
12735
12792
|
return _exports;
|
|
12736
12793
|
})();
|
|
12737
12794
|
|
|
12738
|
-
const _m105 = _modules.get("
|
|
12795
|
+
const _m105 = _modules.get("77da9b842a46b99cb3478438e27f47c1f794ab03bac5e64844fb923f2756df71") ?? (() => {
|
|
12739
12796
|
const { ExportCell, NotSupportedError, OfficeIMOError } = _m1;
|
|
12740
12797
|
|
|
12741
12798
|
const { inputRows, checkAbort, pause, taskYieldDue } = _m4;
|
|
@@ -12840,11 +12897,11 @@ async function withCanopyPdfLayout(source, captured, options, write) {
|
|
|
12840
12897
|
}
|
|
12841
12898
|
}
|
|
12842
12899
|
const _exports = Object.freeze({ withCanopyPdfLayout: withCanopyPdfLayout });
|
|
12843
|
-
_modules.set("
|
|
12900
|
+
_modules.set("77da9b842a46b99cb3478438e27f47c1f794ab03bac5e64844fb923f2756df71", _exports);
|
|
12844
12901
|
return _exports;
|
|
12845
12902
|
})();
|
|
12846
12903
|
|
|
12847
|
-
const _m0 = _modules.get("
|
|
12904
|
+
const _m0 = _modules.get("2e24380844e3dba4335b7d834825b712f857aaffd5b30b161e3533d4ff95cbb4") ?? (() => {
|
|
12848
12905
|
const { BlobByteSink, ExportCell } = _m1;
|
|
12849
12906
|
|
|
12850
12907
|
const { notifyProgress } = _m14;
|
|
@@ -12983,7 +13040,7 @@ async function exportCanopy(capture, format, options = {}) {
|
|
|
12983
13040
|
}
|
|
12984
13041
|
}
|
|
12985
13042
|
const _exports = Object.freeze({ createCanopyExport: _m96.createCanopyExport, ExportCell: _m5.ExportCell, PdfFont: _m64.PdfFont, writeCanopyTo: writeCanopyTo, exportCanopy: exportCanopy });
|
|
12986
|
-
_modules.set("
|
|
13043
|
+
_modules.set("2e24380844e3dba4335b7d834825b712f857aaffd5b30b161e3533d4ff95cbb4", _exports);
|
|
12987
13044
|
return _exports;
|
|
12988
13045
|
})();
|
|
12989
13046
|
Object.assign(officeimo, _m0);
|
|
@@ -11660,6 +11660,10 @@ function canopyPivot(request) {
|
|
|
11660
11660
|
}
|
|
11661
11661
|
/** Per-cell formats preserve already-computed fractional percentages, ranks and differences. */
|
|
11662
11662
|
function pivotNumberFormat(cell) {
|
|
11663
|
+
// Raw-value aggregates need no decimal declaration. Transformed values still
|
|
11664
|
+
// require the producer's frozen format (especially percent scaling).
|
|
11665
|
+
if (cell.mode === "value" && cell.numberFormat === undefined)
|
|
11666
|
+
return undefined;
|
|
11663
11667
|
if (!["value", "percentGrandTotal", "percentParent", "percentColumn", "percentRow", "runningTotal", "rank", "difference", "percentChange"].includes(cell.mode ?? "") ||
|
|
11664
11668
|
typeof cell.numberFormat !== "string" || !cell.numberFormat.length)
|
|
11665
11669
|
throw new TypeError("Numeric pivot cells require a frozen mode and native numberFormat.");
|
|
@@ -11895,11 +11899,11 @@ function prepareCanopyExport(capture, format, options = {}) {
|
|
|
11895
11899
|
if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
|
|
11896
11900
|
value = datetime(value, dateMode, clock);
|
|
11897
11901
|
const capturedFormat = pivot && spec.kind === "number" && cell.value !== null ? pivotNumberFormat(cell) : undefined;
|
|
11898
|
-
const nativeFormat =
|
|
11902
|
+
const nativeFormat = spec.nativeFormatOverride === "" ? "General" : spec.nativeFormatOverride ?? capturedFormat;
|
|
11899
11903
|
const summary = format === "pdf" && pivot && (row.summary || row.grandTotal);
|
|
11900
11904
|
const cellStyle = tone(cell.tone, row.id, spec.id), presentation = rowStyle || cellStyle || nativeFormat || summary ? {
|
|
11901
11905
|
...rowStyle, ...(summary ? { bold: true } : {}), ...cellStyle,
|
|
11902
|
-
...((format === "
|
|
11906
|
+
...((format === "pdf" || (format === "xlsx" && pivot)) && values === "raw" && nativeFormat !== undefined ? { numberFormat: nativeFormat } : {})
|
|
11903
11907
|
} : undefined;
|
|
11904
11908
|
// CSV has no presentation or link metadata: emit its selected scalar directly.
|
|
11905
11909
|
// This also avoids a frozen wrapper for every cell in large CSV captures.
|
|
@@ -12559,64 +12563,117 @@ const { ExportCell } = _m1;
|
|
|
12559
12563
|
|
|
12560
12564
|
/** Fixed numeric formats affect PDF text, not the frozen numeric value used by other writers. */
|
|
12561
12565
|
function numericProfile(format) {
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
|
|
12566
|
+
// No declared precision: whole values (including counts) stay whole.
|
|
12567
|
+
if (format === undefined || format === "General")
|
|
12568
|
+
return { minimumFractionDigits: 0, maximumFractionDigits: 20,
|
|
12569
|
+
percent: false, grouping: false, prefix: "", suffix: "" };
|
|
12570
|
+
const match = /^((?:"[^"]*"|\\["%])*)(#,##)?0(?:\.([0#]+))?(%)?((?:"[^"]*"|\\["%])*)$/.exec(format);
|
|
12565
12571
|
if (!match || (match[3]?.length ?? 0) > 10)
|
|
12566
12572
|
return undefined;
|
|
12573
|
+
const literal = (text) => text.replace(/"([^"]*)"|\\(["%])/g, (_, quoted, escaped) => quoted ?? escaped);
|
|
12567
12574
|
return { minimumFractionDigits: (match[3]?.match(/0/g) ?? []).length, maximumFractionDigits: match[3]?.length ?? 0,
|
|
12568
|
-
percent: !!match[4], grouping: !!match[2], prefix: match[1]
|
|
12569
|
-
}
|
|
12570
|
-
/**
|
|
12571
|
-
function
|
|
12572
|
-
|
|
12573
|
-
|
|
12574
|
-
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12575
|
+
percent: !!match[4], grouping: !!match[2], prefix: literal(match[1]), suffix: literal(match[5]) };
|
|
12576
|
+
}
|
|
12577
|
+
/** Separate declared literal units before recognizing the captured numeric token. */
|
|
12578
|
+
function capturedNumber(text, profile) {
|
|
12579
|
+
let body = text, signBeforePrefix = false;
|
|
12580
|
+
if (profile.prefix && body.startsWith(profile.prefix))
|
|
12581
|
+
body = body.slice(profile.prefix.length);
|
|
12582
|
+
else if (profile.prefix && /^[+-]/.test(body) && body.slice(1).startsWith(profile.prefix)) {
|
|
12583
|
+
signBeforePrefix = true;
|
|
12584
|
+
body = body[0] + body.slice(1 + profile.prefix.length);
|
|
12585
|
+
}
|
|
12586
|
+
if (profile.suffix && body.endsWith(profile.suffix))
|
|
12587
|
+
body = body.slice(0, -profile.suffix.length);
|
|
12588
|
+
const match = /^([^0-9+-]*)([+-]?\d[\d., \u00a0\u202f]*?)([^0-9]*)$/.exec(body);
|
|
12589
|
+
return match ? { prefix: profile.prefix || match[1], number: match[2], suffix: profile.suffix || match[3], signBeforePrefix } : undefined;
|
|
12590
|
+
}
|
|
12591
|
+
/** Distinguish a captured thousands mark from a decimal, using the raw value. */
|
|
12592
|
+
function groupedInteger(numeric, value) {
|
|
12593
|
+
if (!/^[+-]?\d{1,3}(?:,\d{3})+$/.test(numeric) && !/^[+-]?\d{1,3}(?:\.\d{3})+$/.test(numeric))
|
|
12594
|
+
return false;
|
|
12595
|
+
const grouped = Number(numeric.replace(/[.,]/g, ""));
|
|
12596
|
+
return grouped !== 0 && Math.abs(grouped - value) <= .5;
|
|
12597
|
+
}
|
|
12598
|
+
/** Choose once for the document; percent text is the strongest captured culture signal. */
|
|
12599
|
+
function documentDecimal(sample, columns) {
|
|
12600
|
+
let fallback;
|
|
12601
|
+
for (const percent of [true, false]) {
|
|
12602
|
+
for (const row of sample)
|
|
12603
|
+
for (let index = 0; index < columns.length; index++) {
|
|
12604
|
+
const cell = row[index], column = columns[index];
|
|
12605
|
+
if (!(cell instanceof ExportCell) || typeof cell.value !== "number")
|
|
12606
|
+
continue;
|
|
12607
|
+
const profile = numericProfile(cell.presentation?.numberFormat ?? column.format);
|
|
12608
|
+
if (!profile)
|
|
12609
|
+
continue;
|
|
12610
|
+
const captured = capturedNumber(cell.text ?? "", profile);
|
|
12611
|
+
if (!captured)
|
|
12612
|
+
continue;
|
|
12613
|
+
// A literal percent label is a culture signal without requesting numeric scaling.
|
|
12614
|
+
const percentageSignal = profile.percent || profile.prefix.includes("%") || profile.suffix.includes("%") || (cell.text ?? "").includes("%");
|
|
12615
|
+
if (percentageSignal !== percent)
|
|
12616
|
+
continue;
|
|
12617
|
+
const match = /([.,])(\d+)$/.exec(captured.number.trimEnd());
|
|
12618
|
+
if (match) {
|
|
12619
|
+
const numeric = captured.number;
|
|
12620
|
+
// An override changes output scaling/precision, not the captured label.
|
|
12621
|
+
if (groupedInteger(numeric, cell.value) || (percentageSignal && groupedInteger(numeric, cell.value * 100))) {
|
|
12588
12622
|
fallback = match[1] === "," ? "." : ",";
|
|
12589
12623
|
continue;
|
|
12590
12624
|
}
|
|
12625
|
+
return match[1];
|
|
12591
12626
|
}
|
|
12592
|
-
return match[1];
|
|
12593
12627
|
}
|
|
12594
|
-
|
|
12595
|
-
|
|
12596
|
-
}
|
|
12628
|
+
if (fallback !== undefined)
|
|
12629
|
+
return fallback;
|
|
12630
|
+
}
|
|
12631
|
+
return ".";
|
|
12632
|
+
}
|
|
12633
|
+
/** Apply one captured numeric convention to every supported numeric cell, including later streamed rows. */
|
|
12634
|
+
function canopyPdfNumbers(sample, columns) {
|
|
12635
|
+
const formatters = new Map(), decimal = documentDecimal(sample, columns);
|
|
12597
12636
|
return row => row.map((value, index) => {
|
|
12598
12637
|
if (!(value instanceof ExportCell) || typeof value.value !== "number")
|
|
12599
12638
|
return value;
|
|
12600
|
-
const
|
|
12601
|
-
|
|
12639
|
+
const format = value.presentation?.numberFormat ?? columns[index].format;
|
|
12640
|
+
let profile = numericProfile(format);
|
|
12641
|
+
if (!profile || value.text === "")
|
|
12602
12642
|
return value;
|
|
12603
|
-
const captured =
|
|
12643
|
+
const captured = capturedNumber(value.text ?? "", profile);
|
|
12604
12644
|
if (value.text && !captured)
|
|
12605
12645
|
return value;
|
|
12606
|
-
|
|
12646
|
+
// Undeclared formats normalize only plain numeric labels; a decoration
|
|
12647
|
+
// alone does not declare how the raw value was transformed for display.
|
|
12648
|
+
if ((format === undefined || format === "General") && captured && (captured.prefix.trim() || captured.suffix.trim()))
|
|
12649
|
+
return value;
|
|
12650
|
+
if (format === undefined || format === "General") {
|
|
12651
|
+
const digits = Number.isInteger(value.value) || (captured && groupedInteger(captured.number, value.value)) ? 0 :
|
|
12652
|
+
captured ? /[.,](\d+)$/.exec(captured.number.trimEnd())?.[1]?.length ?? 0 : undefined;
|
|
12653
|
+
// Retain a fractional value's captured precision, without padding an
|
|
12654
|
+
// undeclared whole aggregate merely because its display text was padded.
|
|
12655
|
+
if (digits !== undefined && digits <= 20)
|
|
12656
|
+
profile = { ...profile, minimumFractionDigits: digits, maximumFractionDigits: digits };
|
|
12657
|
+
}
|
|
12658
|
+
const key = [profile.minimumFractionDigits, profile.maximumFractionDigits, profile.grouping].join(":");
|
|
12607
12659
|
let formatter = formatters.get(key);
|
|
12608
12660
|
if (!formatter) {
|
|
12609
|
-
formatter = new Intl.NumberFormat(decimal
|
|
12661
|
+
formatter = new Intl.NumberFormat(decimal === "," ? "de-DE" : "en-US", {
|
|
12610
12662
|
minimumFractionDigits: profile.minimumFractionDigits, maximumFractionDigits: profile.maximumFractionDigits, useGrouping: profile.grouping
|
|
12611
12663
|
});
|
|
12612
12664
|
formatters.set(key, formatter);
|
|
12613
12665
|
}
|
|
12614
|
-
|
|
12615
|
-
|
|
12616
|
-
|
|
12666
|
+
let formatted = formatter.format(value.value * (profile.percent ? 100 : 1));
|
|
12667
|
+
if (captured?.number.startsWith("+") && !formatted.startsWith("-"))
|
|
12668
|
+
formatted = "+" + formatted;
|
|
12669
|
+
const leadingSign = captured?.signBeforePrefix ? /^[+-]/.exec(formatted)?.[0] ?? "" : "";
|
|
12670
|
+
if (leadingSign)
|
|
12671
|
+
formatted = formatted.slice(1);
|
|
12672
|
+
const prefix = captured?.prefix || profile.prefix;
|
|
12673
|
+
let suffix = captured?.suffix || profile.suffix;
|
|
12617
12674
|
if (profile.percent && !profile.suffix)
|
|
12618
12675
|
suffix = suffix.replace(/%/g, "");
|
|
12619
|
-
return new ExportCell(value.value, { text: prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
12676
|
+
return new ExportCell(value.value, { text: leadingSign + prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
12620
12677
|
...(value.presentation ? { presentation: value.presentation } : {}), ...(value.link ? { link: value.link } : {}) });
|
|
12621
12678
|
});
|
|
12622
12679
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ExportValue, ColumnSettings } from "../../core/index.js";
|
|
2
|
-
/**
|
|
2
|
+
/** Apply one captured numeric convention to every supported numeric cell, including later streamed rows. */
|
|
3
3
|
export declare function canopyPdfNumbers(sample: readonly (readonly ExportValue[])[], columns: readonly ColumnSettings[]): (row: readonly ExportValue[]) => readonly ExportValue[];
|
|
@@ -1,64 +1,117 @@
|
|
|
1
1
|
import { ExportCell } from "../../core/index.js";
|
|
2
2
|
/** Fixed numeric formats affect PDF text, not the frozen numeric value used by other writers. */
|
|
3
3
|
function numericProfile(format) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
// No declared precision: whole values (including counts) stay whole.
|
|
5
|
+
if (format === undefined || format === "General")
|
|
6
|
+
return { minimumFractionDigits: 0, maximumFractionDigits: 20,
|
|
7
|
+
percent: false, grouping: false, prefix: "", suffix: "" };
|
|
8
|
+
const match = /^((?:"[^"]*"|\\["%])*)(#,##)?0(?:\.([0#]+))?(%)?((?:"[^"]*"|\\["%])*)$/.exec(format);
|
|
7
9
|
if (!match || (match[3]?.length ?? 0) > 10)
|
|
8
10
|
return undefined;
|
|
11
|
+
const literal = (text) => text.replace(/"([^"]*)"|\\(["%])/g, (_, quoted, escaped) => quoted ?? escaped);
|
|
9
12
|
return { minimumFractionDigits: (match[3]?.match(/0/g) ?? []).length, maximumFractionDigits: match[3]?.length ?? 0,
|
|
10
|
-
percent: !!match[4], grouping: !!match[2], prefix: match[1]
|
|
13
|
+
percent: !!match[4], grouping: !!match[2], prefix: literal(match[1]), suffix: literal(match[5]) };
|
|
11
14
|
}
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
/** Separate declared literal units before recognizing the captured numeric token. */
|
|
16
|
+
function capturedNumber(text, profile) {
|
|
17
|
+
let body = text, signBeforePrefix = false;
|
|
18
|
+
if (profile.prefix && body.startsWith(profile.prefix))
|
|
19
|
+
body = body.slice(profile.prefix.length);
|
|
20
|
+
else if (profile.prefix && /^[+-]/.test(body) && body.slice(1).startsWith(profile.prefix)) {
|
|
21
|
+
signBeforePrefix = true;
|
|
22
|
+
body = body[0] + body.slice(1 + profile.prefix.length);
|
|
23
|
+
}
|
|
24
|
+
if (profile.suffix && body.endsWith(profile.suffix))
|
|
25
|
+
body = body.slice(0, -profile.suffix.length);
|
|
26
|
+
const match = /^([^0-9+-]*)([+-]?\d[\d., \u00a0\u202f]*?)([^0-9]*)$/.exec(body);
|
|
27
|
+
return match ? { prefix: profile.prefix || match[1], number: match[2], suffix: profile.suffix || match[3], signBeforePrefix } : undefined;
|
|
28
|
+
}
|
|
29
|
+
/** Distinguish a captured thousands mark from a decimal, using the raw value. */
|
|
30
|
+
function groupedInteger(numeric, value) {
|
|
31
|
+
if (!/^[+-]?\d{1,3}(?:,\d{3})+$/.test(numeric) && !/^[+-]?\d{1,3}(?:\.\d{3})+$/.test(numeric))
|
|
32
|
+
return false;
|
|
33
|
+
const grouped = Number(numeric.replace(/[.,]/g, ""));
|
|
34
|
+
return grouped !== 0 && Math.abs(grouped - value) <= .5;
|
|
35
|
+
}
|
|
36
|
+
/** Choose once for the document; percent text is the strongest captured culture signal. */
|
|
37
|
+
function documentDecimal(sample, columns) {
|
|
38
|
+
let fallback;
|
|
39
|
+
for (const percent of [true, false]) {
|
|
40
|
+
for (const row of sample)
|
|
41
|
+
for (let index = 0; index < columns.length; index++) {
|
|
42
|
+
const cell = row[index], column = columns[index];
|
|
43
|
+
if (!(cell instanceof ExportCell) || typeof cell.value !== "number")
|
|
44
|
+
continue;
|
|
45
|
+
const profile = numericProfile(cell.presentation?.numberFormat ?? column.format);
|
|
46
|
+
if (!profile)
|
|
47
|
+
continue;
|
|
48
|
+
const captured = capturedNumber(cell.text ?? "", profile);
|
|
49
|
+
if (!captured)
|
|
50
|
+
continue;
|
|
51
|
+
// A literal percent label is a culture signal without requesting numeric scaling.
|
|
52
|
+
const percentageSignal = profile.percent || profile.prefix.includes("%") || profile.suffix.includes("%") || (cell.text ?? "").includes("%");
|
|
53
|
+
if (percentageSignal !== percent)
|
|
54
|
+
continue;
|
|
55
|
+
const match = /([.,])(\d+)$/.exec(captured.number.trimEnd());
|
|
56
|
+
if (match) {
|
|
57
|
+
const numeric = captured.number;
|
|
58
|
+
// An override changes output scaling/precision, not the captured label.
|
|
59
|
+
if (groupedInteger(numeric, cell.value) || (percentageSignal && groupedInteger(numeric, cell.value * 100))) {
|
|
30
60
|
fallback = match[1] === "," ? "." : ",";
|
|
31
61
|
continue;
|
|
32
62
|
}
|
|
63
|
+
return match[1];
|
|
33
64
|
}
|
|
34
|
-
return match[1];
|
|
35
65
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
66
|
+
if (fallback !== undefined)
|
|
67
|
+
return fallback;
|
|
68
|
+
}
|
|
69
|
+
return ".";
|
|
70
|
+
}
|
|
71
|
+
/** Apply one captured numeric convention to every supported numeric cell, including later streamed rows. */
|
|
72
|
+
export function canopyPdfNumbers(sample, columns) {
|
|
73
|
+
const formatters = new Map(), decimal = documentDecimal(sample, columns);
|
|
39
74
|
return row => row.map((value, index) => {
|
|
40
75
|
if (!(value instanceof ExportCell) || typeof value.value !== "number")
|
|
41
76
|
return value;
|
|
42
|
-
const
|
|
43
|
-
|
|
77
|
+
const format = value.presentation?.numberFormat ?? columns[index].format;
|
|
78
|
+
let profile = numericProfile(format);
|
|
79
|
+
if (!profile || value.text === "")
|
|
44
80
|
return value;
|
|
45
|
-
const captured =
|
|
81
|
+
const captured = capturedNumber(value.text ?? "", profile);
|
|
46
82
|
if (value.text && !captured)
|
|
47
83
|
return value;
|
|
48
|
-
|
|
84
|
+
// Undeclared formats normalize only plain numeric labels; a decoration
|
|
85
|
+
// alone does not declare how the raw value was transformed for display.
|
|
86
|
+
if ((format === undefined || format === "General") && captured && (captured.prefix.trim() || captured.suffix.trim()))
|
|
87
|
+
return value;
|
|
88
|
+
if (format === undefined || format === "General") {
|
|
89
|
+
const digits = Number.isInteger(value.value) || (captured && groupedInteger(captured.number, value.value)) ? 0 :
|
|
90
|
+
captured ? /[.,](\d+)$/.exec(captured.number.trimEnd())?.[1]?.length ?? 0 : undefined;
|
|
91
|
+
// Retain a fractional value's captured precision, without padding an
|
|
92
|
+
// undeclared whole aggregate merely because its display text was padded.
|
|
93
|
+
if (digits !== undefined && digits <= 20)
|
|
94
|
+
profile = { ...profile, minimumFractionDigits: digits, maximumFractionDigits: digits };
|
|
95
|
+
}
|
|
96
|
+
const key = [profile.minimumFractionDigits, profile.maximumFractionDigits, profile.grouping].join(":");
|
|
49
97
|
let formatter = formatters.get(key);
|
|
50
98
|
if (!formatter) {
|
|
51
|
-
formatter = new Intl.NumberFormat(decimal
|
|
99
|
+
formatter = new Intl.NumberFormat(decimal === "," ? "de-DE" : "en-US", {
|
|
52
100
|
minimumFractionDigits: profile.minimumFractionDigits, maximumFractionDigits: profile.maximumFractionDigits, useGrouping: profile.grouping
|
|
53
101
|
});
|
|
54
102
|
formatters.set(key, formatter);
|
|
55
103
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
104
|
+
let formatted = formatter.format(value.value * (profile.percent ? 100 : 1));
|
|
105
|
+
if (captured?.number.startsWith("+") && !formatted.startsWith("-"))
|
|
106
|
+
formatted = "+" + formatted;
|
|
107
|
+
const leadingSign = captured?.signBeforePrefix ? /^[+-]/.exec(formatted)?.[0] ?? "" : "";
|
|
108
|
+
if (leadingSign)
|
|
109
|
+
formatted = formatted.slice(1);
|
|
110
|
+
const prefix = captured?.prefix || profile.prefix;
|
|
111
|
+
let suffix = captured?.suffix || profile.suffix;
|
|
59
112
|
if (profile.percent && !profile.suffix)
|
|
60
113
|
suffix = suffix.replace(/%/g, "");
|
|
61
|
-
return new ExportCell(value.value, { text: prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
114
|
+
return new ExportCell(value.value, { text: leadingSign + prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
62
115
|
...(value.presentation ? { presentation: value.presentation } : {}), ...(value.link ? { link: value.link } : {}) });
|
|
63
116
|
});
|
|
64
117
|
}
|
|
@@ -60,6 +60,10 @@ export function canopyPivot(request) {
|
|
|
60
60
|
}
|
|
61
61
|
/** Per-cell formats preserve already-computed fractional percentages, ranks and differences. */
|
|
62
62
|
export function pivotNumberFormat(cell) {
|
|
63
|
+
// Raw-value aggregates need no decimal declaration. Transformed values still
|
|
64
|
+
// require the producer's frozen format (especially percent scaling).
|
|
65
|
+
if (cell.mode === "value" && cell.numberFormat === undefined)
|
|
66
|
+
return undefined;
|
|
63
67
|
if (!["value", "percentGrandTotal", "percentParent", "percentColumn", "percentRow", "runningTotal", "rank", "difference", "percentChange"].includes(cell.mode ?? "") ||
|
|
64
68
|
typeof cell.numberFormat !== "string" || !cell.numberFormat.length)
|
|
65
69
|
throw new TypeError("Numeric pivot cells require a frozen mode and native numberFormat.");
|
|
@@ -131,11 +131,11 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
131
131
|
if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
|
|
132
132
|
value = datetime(value, dateMode, clock);
|
|
133
133
|
const capturedFormat = pivot && spec.kind === "number" && cell.value !== null ? pivotNumberFormat(cell) : undefined;
|
|
134
|
-
const nativeFormat =
|
|
134
|
+
const nativeFormat = spec.nativeFormatOverride === "" ? "General" : spec.nativeFormatOverride ?? capturedFormat;
|
|
135
135
|
const summary = format === "pdf" && pivot && (row.summary || row.grandTotal);
|
|
136
136
|
const cellStyle = tone(cell.tone, row.id, spec.id), presentation = rowStyle || cellStyle || nativeFormat || summary ? {
|
|
137
137
|
...rowStyle, ...(summary ? { bold: true } : {}), ...cellStyle,
|
|
138
|
-
...((format === "
|
|
138
|
+
...((format === "pdf" || (format === "xlsx" && pivot)) && values === "raw" && nativeFormat !== undefined ? { numberFormat: nativeFormat } : {})
|
|
139
139
|
} : undefined;
|
|
140
140
|
// CSV has no presentation or link metadata: emit its selected scalar directly.
|
|
141
141
|
// This also avoids a frozen wrapper for every cell in large CSV captures.
|
|
@@ -9,6 +9,7 @@ export interface CanopyExportCell {
|
|
|
9
9
|
readonly text: string;
|
|
10
10
|
/** Frozen pivot display semantics; values are already computed by CanopyX. */
|
|
11
11
|
readonly mode?: "value" | "percentGrandTotal" | "percentParent" | "percentColumn" | "percentRow" | "runningTotal" | "rank" | "difference" | "percentChange";
|
|
12
|
+
/** Native format; optional for mode=value, whose unformatted integer values stay whole in PDF. */
|
|
12
13
|
readonly numberFormat?: string;
|
|
13
14
|
readonly tone?: string;
|
|
14
15
|
readonly link?: ExportLink;
|