@evotecit/officeimo 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +1222 -2
- package/bundles/officeimo-canopyx.js +11741 -0
- package/bundles/officeimo-canopyx.mjs +11639 -0
- package/bundles/officeimo-csv.js +1264 -0
- package/bundles/officeimo-csv.mjs +1239 -0
- package/bundles/officeimo-datatables.js +12018 -0
- package/bundles/officeimo-datatables.mjs +11915 -0
- package/bundles/officeimo-execution.js +1513 -0
- package/bundles/officeimo-execution.mjs +1489 -0
- package/bundles/officeimo-pdf.js +7009 -0
- package/bundles/officeimo-pdf.mjs +6946 -0
- package/bundles/officeimo-xlsx.js +5344 -0
- package/bundles/officeimo-xlsx.mjs +5290 -0
- package/bundles/officeimo.js +11468 -0
- package/bundles/officeimo.mjs +11369 -0
- package/dist/core/dates.d.ts +1 -0
- package/dist/core/dates.js +16 -0
- package/dist/core/errors.d.ts +12 -0
- package/dist/core/errors.js +31 -0
- package/dist/core/grouped-report.d.ts +87 -0
- package/dist/core/grouped-report.js +252 -0
- package/dist/core/index.d.ts +74 -0
- package/dist/core/index.js +37 -0
- package/dist/core/iteration.d.ts +7 -0
- package/dist/core/iteration.js +149 -0
- package/dist/core/limits.d.ts +7 -0
- package/dist/core/limits.js +56 -0
- package/dist/core/links.d.ts +5 -0
- package/dist/core/links.js +14 -0
- package/dist/core/presentation.d.ts +29 -0
- package/dist/core/presentation.js +59 -0
- package/dist/core/progress.d.ts +1 -0
- package/dist/core/progress.js +10 -0
- package/dist/core/sinks.d.ts +33 -0
- package/dist/core/sinks.js +102 -0
- package/dist/core/table.d.ts +8 -0
- package/dist/core/table.js +1 -0
- package/dist/core/value-text.d.ts +7 -0
- package/dist/core/value-text.js +13 -0
- package/dist/csv/index.d.ts +44 -0
- package/dist/csv/index.js +133 -0
- package/dist/csv/options.d.ts +1 -0
- package/dist/csv/options.js +8 -0
- package/dist/csv/structured-rows.d.ts +3 -0
- package/dist/csv/structured-rows.js +15 -0
- package/dist/execution/host.d.ts +5 -0
- package/dist/execution/host.js +164 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/protocol.d.ts +48 -0
- package/dist/execution/protocol.js +173 -0
- package/dist/execution/types.d.ts +42 -0
- package/dist/execution/types.js +1 -0
- package/dist/execution/worker.d.ts +3 -0
- package/dist/execution/worker.js +147 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -0
- package/dist/integrations/canopyx/dates.d.ts +1 -0
- package/dist/integrations/canopyx/dates.js +34 -0
- package/dist/integrations/canopyx/index.d.ts +10 -0
- package/dist/integrations/canopyx/index.js +45 -0
- package/dist/integrations/canopyx/source.d.ts +3 -0
- package/dist/integrations/canopyx/source.js +122 -0
- package/dist/integrations/canopyx/types.d.ts +83 -0
- package/dist/integrations/canopyx/types.js +1 -0
- package/dist/integrations/datatables/api.d.ts +1 -0
- package/dist/integrations/datatables/api.js +27 -0
- package/dist/integrations/datatables/headings.d.ts +1 -0
- package/dist/integrations/datatables/headings.js +65 -0
- package/dist/integrations/datatables/index.d.ts +12 -0
- package/dist/integrations/datatables/index.js +167 -0
- package/dist/integrations/datatables/snapshot.d.ts +3 -0
- package/dist/integrations/datatables/snapshot.js +206 -0
- package/dist/integrations/datatables/types.d.ts +98 -0
- package/dist/integrations/datatables/types.js +1 -0
- package/dist/integrations/options.d.ts +13 -0
- package/dist/integrations/options.js +34 -0
- package/dist/internal/capture.d.ts +4 -0
- package/dist/internal/capture.js +14 -0
- package/dist/internal/columns.d.ts +27 -0
- package/dist/internal/columns.js +1 -0
- package/dist/internal/crc32.d.ts +6 -0
- package/dist/internal/crc32.js +17 -0
- package/dist/internal/export-values.d.ts +3 -0
- package/dist/internal/export-values.js +14 -0
- package/dist/internal/rows.d.ts +6 -0
- package/dist/internal/rows.js +77 -0
- package/dist/internal/table-spans.d.ts +11 -0
- package/dist/internal/table-spans.js +58 -0
- package/dist/internal/totals.d.ts +15 -0
- package/dist/internal/totals.js +42 -0
- package/dist/opc/index.d.ts +67 -0
- package/dist/opc/index.js +233 -0
- package/dist/opc/properties.d.ts +15 -0
- package/dist/opc/properties.js +18 -0
- package/dist/opc/uri.d.ts +5 -0
- package/dist/opc/uri.js +41 -0
- package/dist/pdf/annotations.d.ts +1 -0
- package/dist/pdf/annotations.js +38 -0
- package/dist/pdf/binary.d.ts +6 -0
- package/dist/pdf/binary.js +24 -0
- package/dist/pdf/document-drawings.d.ts +15 -0
- package/dist/pdf/document-drawings.js +237 -0
- package/dist/pdf/document-grouped.d.ts +1 -0
- package/dist/pdf/document-grouped.js +244 -0
- package/dist/pdf/document-images.d.ts +19 -0
- package/dist/pdf/document-images.js +125 -0
- package/dist/pdf/document-types.d.ts +160 -0
- package/dist/pdf/document-types.js +1 -0
- package/dist/pdf/document-vectors.d.ts +11 -0
- package/dist/pdf/document-vectors.js +77 -0
- package/dist/pdf/document.d.ts +9 -0
- package/dist/pdf/document.js +270 -0
- package/dist/pdf/drawing-types.d.ts +53 -0
- package/dist/pdf/drawing-types.js +1 -0
- package/dist/pdf/font-resources.d.ts +43 -0
- package/dist/pdf/font-resources.js +202 -0
- package/dist/pdf/font-support.d.ts +1 -0
- package/dist/pdf/font-support.js +60 -0
- package/dist/pdf/font.d.ts +17 -0
- package/dist/pdf/font.js +56 -0
- package/dist/pdf/grouped-table.d.ts +6 -0
- package/dist/pdf/grouped-table.js +40 -0
- package/dist/pdf/grouped-types.d.ts +34 -0
- package/dist/pdf/grouped-types.js +1 -0
- package/dist/pdf/grouped.d.ts +10 -0
- package/dist/pdf/grouped.js +37 -0
- package/dist/pdf/index.d.ts +22 -0
- package/dist/pdf/index.js +8 -0
- package/dist/pdf/inline-text.d.ts +30 -0
- package/dist/pdf/inline-text.js +183 -0
- package/dist/pdf/inline-types.d.ts +15 -0
- package/dist/pdf/inline-types.js +1 -0
- package/dist/pdf/list-layout.d.ts +6 -0
- package/dist/pdf/list-layout.js +49 -0
- package/dist/pdf/objects.d.ts +2 -0
- package/dist/pdf/objects.js +320 -0
- package/dist/pdf/outlines.d.ts +1 -0
- package/dist/pdf/outlines.js +55 -0
- package/dist/pdf/page-context.d.ts +1 -0
- package/dist/pdf/page-context.js +12 -0
- package/dist/pdf/pages.d.ts +1 -0
- package/dist/pdf/pages.js +678 -0
- package/dist/pdf/paragraph-layout.d.ts +21 -0
- package/dist/pdf/paragraph-layout.js +71 -0
- package/dist/pdf/paragraph-styles.d.ts +1 -0
- package/dist/pdf/paragraph-styles.js +66 -0
- package/dist/pdf/png.d.ts +9 -0
- package/dist/pdf/png.js +259 -0
- package/dist/pdf/preflight.d.ts +7 -0
- package/dist/pdf/preflight.js +32 -0
- package/dist/pdf/presentation-settings.d.ts +5 -0
- package/dist/pdf/presentation-settings.js +28 -0
- package/dist/pdf/providers/harfbuzz.d.ts +60 -0
- package/dist/pdf/providers/harfbuzz.js +112 -0
- package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
- package/dist/pdf/providers/unicode13-profile.js +115 -0
- package/dist/pdf/section-types.d.ts +15 -0
- package/dist/pdf/section-types.js +40 -0
- package/dist/pdf/session.d.ts +25 -0
- package/dist/pdf/session.js +55 -0
- package/dist/pdf/settings.d.ts +17 -0
- package/dist/pdf/settings.js +196 -0
- package/dist/pdf/shaped-text.d.ts +5 -0
- package/dist/pdf/shaped-text.js +205 -0
- package/dist/pdf/standard-widths.d.ts +1 -0
- package/dist/pdf/standard-widths.js +317 -0
- package/dist/pdf/structure-parent-tree.d.ts +1 -0
- package/dist/pdf/structure-parent-tree.js +57 -0
- package/dist/pdf/structure.d.ts +6 -0
- package/dist/pdf/structure.js +302 -0
- package/dist/pdf/table-band-flow.d.ts +34 -0
- package/dist/pdf/table-band-flow.js +129 -0
- package/dist/pdf/table-band-plan.d.ts +10 -0
- package/dist/pdf/table-band-plan.js +83 -0
- package/dist/pdf/table-layout.d.ts +75 -0
- package/dist/pdf/table-layout.js +217 -0
- package/dist/pdf/table-structure.d.ts +1 -0
- package/dist/pdf/table-structure.js +108 -0
- package/dist/pdf/text-shaping-types.d.ts +39 -0
- package/dist/pdf/text-shaping-types.js +1 -0
- package/dist/pdf/text.d.ts +13 -0
- package/dist/pdf/text.js +101 -0
- package/dist/pdf/truetype-subset.d.ts +5 -0
- package/dist/pdf/truetype-subset.js +217 -0
- package/dist/pdf/truetype.d.ts +1 -0
- package/dist/pdf/truetype.js +235 -0
- package/dist/pdf/types.d.ts +171 -0
- package/dist/pdf/types.js +1 -0
- package/dist/pdf/write.d.ts +6 -0
- package/dist/pdf/write.js +57 -0
- package/dist/pdf/xref.d.ts +1 -0
- package/dist/pdf/xref.js +30 -0
- package/dist/xlsx/attachments.d.ts +30 -0
- package/dist/xlsx/attachments.js +67 -0
- package/dist/xlsx/chart-bindings.d.ts +1 -0
- package/dist/xlsx/chart-bindings.js +122 -0
- package/dist/xlsx/chart-types.d.ts +73 -0
- package/dist/xlsx/chart-types.js +1 -0
- package/dist/xlsx/chart-xml.d.ts +2 -0
- package/dist/xlsx/chart-xml.js +103 -0
- package/dist/xlsx/charts.d.ts +1 -0
- package/dist/xlsx/charts.js +159 -0
- package/dist/xlsx/conditional-formatting.d.ts +1 -0
- package/dist/xlsx/conditional-formatting.js +158 -0
- package/dist/xlsx/conditional-types.d.ts +64 -0
- package/dist/xlsx/conditional-types.js +1 -0
- package/dist/xlsx/data-row-ranges.d.ts +5 -0
- package/dist/xlsx/data-row-ranges.js +39 -0
- package/dist/xlsx/differential-styles.d.ts +1 -0
- package/dist/xlsx/differential-styles.js +102 -0
- package/dist/xlsx/formula.d.ts +8 -0
- package/dist/xlsx/formula.js +104 -0
- package/dist/xlsx/grouped-layout.d.ts +61 -0
- package/dist/xlsx/grouped-layout.js +79 -0
- package/dist/xlsx/grouped.d.ts +16 -0
- package/dist/xlsx/grouped.js +161 -0
- package/dist/xlsx/index.d.ts +24 -0
- package/dist/xlsx/index.js +10 -0
- package/dist/xlsx/layout.d.ts +1 -0
- package/dist/xlsx/layout.js +186 -0
- package/dist/xlsx/options.d.ts +1 -0
- package/dist/xlsx/options.js +16 -0
- package/dist/xlsx/portable.d.ts +27 -0
- package/dist/xlsx/portable.js +44 -0
- package/dist/xlsx/preservation.d.ts +1 -0
- package/dist/xlsx/preservation.js +60 -0
- package/dist/xlsx/ranges.d.ts +1 -0
- package/dist/xlsx/ranges.js +24 -0
- package/dist/xlsx/regions.d.ts +1 -0
- package/dist/xlsx/regions.js +97 -0
- package/dist/xlsx/structured-rows.d.ts +11 -0
- package/dist/xlsx/structured-rows.js +28 -0
- package/dist/xlsx/style-xml.d.ts +1 -0
- package/dist/xlsx/style-xml.js +6 -0
- package/dist/xlsx/styles.d.ts +70 -0
- package/dist/xlsx/styles.js +203 -0
- package/dist/xlsx/table.d.ts +12 -0
- package/dist/xlsx/table.js +35 -0
- package/dist/xlsx/types.d.ts +180 -0
- package/dist/xlsx/types.js +1 -0
- package/dist/xlsx/validation-types.d.ts +18 -0
- package/dist/xlsx/validation-types.js +1 -0
- package/dist/xlsx/validation.d.ts +1 -0
- package/dist/xlsx/validation.js +92 -0
- package/dist/xlsx/values.d.ts +13 -0
- package/dist/xlsx/values.js +87 -0
- package/dist/xlsx/workbook.d.ts +50 -0
- package/dist/xlsx/workbook.js +452 -0
- package/dist/xlsx/worksheet.d.ts +71 -0
- package/dist/xlsx/worksheet.js +700 -0
- package/dist/xlsx/write.d.ts +15 -0
- package/dist/xlsx/write.js +47 -0
- package/dist/xml/index.d.ts +24 -0
- package/dist/xml/index.js +74 -0
- package/dist/zip/entry.d.ts +39 -0
- package/dist/zip/entry.js +122 -0
- package/dist/zip/index.d.ts +44 -0
- package/dist/zip/index.js +248 -0
- package/package.json +104 -4
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { checkAbort } from "../core/iteration.js";
|
|
2
|
+
import { NotSupportedError, OfficeIMOError } from "../core/errors.js";
|
|
3
|
+
import { cleanXml } from "../xml/index.js";
|
|
4
|
+
import { copyDrawingAnchor } from "./attachments.js";
|
|
5
|
+
import { captureFields } from "../internal/capture.js";
|
|
6
|
+
import { captureChartRange, prepareChartBinding } from "./chart-bindings.js";
|
|
7
|
+
function fields(value, allowed, context) {
|
|
8
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
9
|
+
throw new TypeError(context + " must be an object.");
|
|
10
|
+
for (const key of Object.keys(value))
|
|
11
|
+
if (!allowed.includes(key))
|
|
12
|
+
throw new NotSupportedError(context + "." + key);
|
|
13
|
+
}
|
|
14
|
+
function snapshot(value, allowed, context) {
|
|
15
|
+
fields(value, allowed, context);
|
|
16
|
+
return captureFields(value, allowed);
|
|
17
|
+
}
|
|
18
|
+
/** @internal Preflight bounds before copying any chart data. Failed registration reserves nothing. */
|
|
19
|
+
export function prepareChart(input, policy, availablePoints, availableText, signal, resolveBinding) {
|
|
20
|
+
checkAbort(signal);
|
|
21
|
+
input = snapshot(input, ["type", "data", "row", "column", "width", "height", "description", "title", "language", "legend", "dataLabels", "categoryAxis", "valueAxis"], "chart");
|
|
22
|
+
if (!["columnClustered", "barClustered", "line", "pie"].includes(input.type))
|
|
23
|
+
throw new NotSupportedError("chart type " + input.type);
|
|
24
|
+
const type = input.type;
|
|
25
|
+
const requested = snapshot(input.data, ["kind", "sheet", "firstRow", "rowCount", "categoryColumn", "categories", "series"], "chart.data");
|
|
26
|
+
const bound = requested.kind === "range" ? captureChartRange(requested) : undefined;
|
|
27
|
+
if (!bound)
|
|
28
|
+
fields(requested, ["categories", "series"], "chart.data");
|
|
29
|
+
const categories = bound ? undefined : requested.categories, series = bound?.series ?? requested.series;
|
|
30
|
+
if (!bound && !Array.isArray(categories))
|
|
31
|
+
throw new TypeError("Chart categories must be a nonempty array of strings.");
|
|
32
|
+
if (!Array.isArray(series))
|
|
33
|
+
throw new RangeError("A chart needs from 1 through 255 series.");
|
|
34
|
+
const categoryCount = bound?.rowCount ?? categories.length, seriesCount = series.length;
|
|
35
|
+
if (!categoryCount)
|
|
36
|
+
throw new TypeError("Chart categories must be a nonempty array of strings.");
|
|
37
|
+
if (!seriesCount || seriesCount > 255)
|
|
38
|
+
throw new RangeError("A chart needs from 1 through 255 series.");
|
|
39
|
+
if (!bound && categoryCount > 1048575)
|
|
40
|
+
throw new RangeError("Chart data must fit Excel's rows including its header.");
|
|
41
|
+
if (type === "pie" && seriesCount !== 1)
|
|
42
|
+
throw new TypeError("A pie chart supports exactly one series.");
|
|
43
|
+
const points = categoryCount * seriesCount;
|
|
44
|
+
if (points > availablePoints)
|
|
45
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxChartPoints exceeded.");
|
|
46
|
+
let textCharacters = 0;
|
|
47
|
+
const text = (value, context) => {
|
|
48
|
+
if (typeof value !== "string")
|
|
49
|
+
throw new TypeError(context + " must be a string.");
|
|
50
|
+
if (value.length > 32767)
|
|
51
|
+
throw new RangeError(context + " exceeds 32,767 UTF-16 units.");
|
|
52
|
+
textCharacters += value.length;
|
|
53
|
+
if (textCharacters > availableText)
|
|
54
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxChartTextCharacters exceeded.");
|
|
55
|
+
return cleanXml(value, policy);
|
|
56
|
+
};
|
|
57
|
+
const optionalText = (value, context) => value === undefined ? undefined : text(value, context);
|
|
58
|
+
const title = optionalText(input.title, "Chart title"), description = optionalText(input.description, "Chart description");
|
|
59
|
+
const requestedLanguage = optionalText(input.language, "Chart language");
|
|
60
|
+
let language;
|
|
61
|
+
if (requestedLanguage !== undefined) {
|
|
62
|
+
try {
|
|
63
|
+
language = Intl.getCanonicalLocales(requestedLanguage)[0];
|
|
64
|
+
if (!language)
|
|
65
|
+
throw new RangeError();
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
throw new TypeError("Chart language must be a language tag such as pl or pl-PL.");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const anchor = copyDrawingAnchor({ row: input.row, column: input.column, width: input.width, height: input.height,
|
|
72
|
+
...(description === undefined ? {} : { description }) }, policy);
|
|
73
|
+
if (input.legend !== undefined && input.legend !== false && !["right", "bottom", "left", "top"].includes(input.legend))
|
|
74
|
+
throw new TypeError("Unsupported chart legend position.");
|
|
75
|
+
let dataLabels;
|
|
76
|
+
if (input.dataLabels !== undefined) {
|
|
77
|
+
const labels = snapshot(input.dataLabels, ["showValue", "showCategoryName", "showSeriesName", "showPercent", "position", "numberFormat"], "chart.dataLabels");
|
|
78
|
+
for (const key of ["showValue", "showCategoryName", "showSeriesName", "showPercent"])
|
|
79
|
+
if (labels[key] !== undefined && typeof labels[key] !== "boolean")
|
|
80
|
+
throw new TypeError("Chart label flags must be booleans.");
|
|
81
|
+
if (labels.showPercent && type !== "pie")
|
|
82
|
+
throw new TypeError("Percent data labels require a pie chart.");
|
|
83
|
+
const positions = type === "pie" ? ["center", "insideEnd", "outsideEnd", "bestFit"] : type === "line" ? ["center", "above", "below", "left", "right"] : ["center", "insideEnd", "outsideEnd"];
|
|
84
|
+
if (labels.position !== undefined && !positions.includes(labels.position))
|
|
85
|
+
throw new TypeError("Data label position is unsupported for this chart type.");
|
|
86
|
+
const numberFormat = optionalText(labels.numberFormat, "Data label number format");
|
|
87
|
+
if (numberFormat !== undefined && !numberFormat.trim())
|
|
88
|
+
throw new TypeError("Data label number format cannot be blank.");
|
|
89
|
+
dataLabels = Object.freeze({ ...labels, ...(numberFormat === undefined ? {} : { numberFormat }) });
|
|
90
|
+
}
|
|
91
|
+
if (type === "pie" && (input.categoryAxis !== undefined || input.valueAxis !== undefined))
|
|
92
|
+
throw new TypeError("Pie charts have no axes.");
|
|
93
|
+
let categoryAxis, valueAxis;
|
|
94
|
+
if (input.categoryAxis !== undefined) {
|
|
95
|
+
const axisTitle = optionalText(snapshot(input.categoryAxis, ["title"], "chart.categoryAxis").title, "Category axis title");
|
|
96
|
+
categoryAxis = Object.freeze(axisTitle === undefined ? {} : { title: axisTitle });
|
|
97
|
+
}
|
|
98
|
+
if (input.valueAxis !== undefined) {
|
|
99
|
+
const axis = snapshot(input.valueAxis, ["title", "minimum", "maximum", "numberFormat"], "chart.valueAxis");
|
|
100
|
+
for (const value of [axis.minimum, axis.maximum])
|
|
101
|
+
if (value !== undefined && !Number.isFinite(value))
|
|
102
|
+
throw new TypeError("Chart axis bounds must be finite numbers.");
|
|
103
|
+
if (axis.minimum !== undefined && axis.maximum !== undefined && axis.minimum >= axis.maximum)
|
|
104
|
+
throw new RangeError("Chart axis minimum must be below its maximum.");
|
|
105
|
+
const axisTitle = optionalText(axis.title, "Value axis title"), numberFormat = optionalText(axis.numberFormat, "Value axis number format");
|
|
106
|
+
if (numberFormat !== undefined && !numberFormat.trim())
|
|
107
|
+
throw new TypeError("Value axis number format cannot be blank.");
|
|
108
|
+
valueAxis = Object.freeze({ ...axis, ...(axisTitle === undefined ? {} : { title: axisTitle }), ...(numberFormat === undefined ? {} : { numberFormat }) });
|
|
109
|
+
}
|
|
110
|
+
const common = { ...anchor, type,
|
|
111
|
+
...(language === undefined ? {} : { language }),
|
|
112
|
+
...(title === undefined ? {} : { title }), ...(description === undefined ? {} : { description }),
|
|
113
|
+
...(input.legend === undefined ? {} : { legend: input.legend }), ...(dataLabels === undefined ? {} : { dataLabels }),
|
|
114
|
+
...(categoryAxis === undefined ? {} : { categoryAxis }), ...(valueAxis === undefined ? {} : { valueAxis }) };
|
|
115
|
+
if (bound) {
|
|
116
|
+
if (!resolveBinding)
|
|
117
|
+
throw new TypeError("A chart range must belong to the current workbook.");
|
|
118
|
+
const { descriptor, retainText } = resolveBinding(bound);
|
|
119
|
+
const binding = prepareChartBinding(bound, descriptor, { availablePoints, availableText: availableText - textCharacters, retainText, policy }, signal, type);
|
|
120
|
+
return Object.freeze({ ...common, data: binding.data, binding, points, textCharacters: textCharacters + binding.textCharacters });
|
|
121
|
+
}
|
|
122
|
+
// Length budgets precede allocation; each source property/array element is read once.
|
|
123
|
+
const categoryValues = categories;
|
|
124
|
+
const copiedCategories = [], copiedSeries = [];
|
|
125
|
+
for (let i = 0; i < categoryCount; i++) {
|
|
126
|
+
if ((i & 255) === 0)
|
|
127
|
+
checkAbort(signal);
|
|
128
|
+
copiedCategories.push(text(categoryValues[i], "Chart category"));
|
|
129
|
+
}
|
|
130
|
+
for (let seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) {
|
|
131
|
+
const item = series[seriesIndex];
|
|
132
|
+
const captured = snapshot(item, ["name", "values", "color"], "chart.series");
|
|
133
|
+
const name = text(captured.name, "Chart series name"), values = captured.values, color = captured.color;
|
|
134
|
+
if (!Array.isArray(values) || values.length !== categoryCount)
|
|
135
|
+
throw new TypeError("Chart series values must match the category count.");
|
|
136
|
+
if (color !== undefined && (typeof color !== "string" || !/^#?[0-9a-fA-F]{6}$/.test(color)))
|
|
137
|
+
throw new TypeError("Chart colors must be opaque six-digit RGB hex values.");
|
|
138
|
+
let positive = false;
|
|
139
|
+
const copiedValues = [];
|
|
140
|
+
for (let i = 0; i < categoryCount; i++) {
|
|
141
|
+
if ((i & 255) === 0)
|
|
142
|
+
checkAbort(signal);
|
|
143
|
+
const value = values[i];
|
|
144
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
145
|
+
throw new TypeError("Chart values must be finite numbers.");
|
|
146
|
+
if (type === "pie" && value < 0)
|
|
147
|
+
throw new RangeError("Pie charts require nonnegative values.");
|
|
148
|
+
if (value > 0)
|
|
149
|
+
positive = true;
|
|
150
|
+
copiedValues.push(value);
|
|
151
|
+
}
|
|
152
|
+
if (type === "pie" && !positive)
|
|
153
|
+
throw new RangeError("A pie chart needs at least one positive value.");
|
|
154
|
+
copiedSeries.push(Object.freeze({ name, values: Object.freeze(copiedValues), ...(color === undefined ? {} : { color: color.replace(/^#/, "").toUpperCase() }) }));
|
|
155
|
+
}
|
|
156
|
+
return Object.freeze({ ...common,
|
|
157
|
+
data: Object.freeze({ categories: Object.freeze(copiedCategories), series: Object.freeze(copiedSeries) }),
|
|
158
|
+
points, textCharacters });
|
|
159
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { cleanXml, escapeXml, escapeOoxmlAttribute } from "../xml/index.js";
|
|
2
|
+
import { cellPosition } from "./attachments.js";
|
|
3
|
+
import { colorArgb } from "./style-xml.js";
|
|
4
|
+
import { fields, optionalBoolean, differentialXml } from "./differential-styles.js";
|
|
5
|
+
import { resolveDataColumn } from "./ranges.js";
|
|
6
|
+
import { dataRowReference } from "./data-row-ranges.js";
|
|
7
|
+
function target(range, columns) {
|
|
8
|
+
if (typeof range === "string") {
|
|
9
|
+
const parts = range.split(":");
|
|
10
|
+
if (parts.length > 2)
|
|
11
|
+
throw new TypeError("Conditional ranges require one uppercase A1 cell or rectangle.");
|
|
12
|
+
const first = cellPosition(parts[0]), last = cellPosition(parts[1] ?? parts[0]);
|
|
13
|
+
if (last.row < first.row || last.column < first.column || last.column > columns.length)
|
|
14
|
+
throw new RangeError("Conditional ranges require ordered cells within declared columns.");
|
|
15
|
+
return { first: first.column, last: last.column, reference: range, bottom: last.row };
|
|
16
|
+
}
|
|
17
|
+
fields(range, ["column", "through"], "conditional data range");
|
|
18
|
+
const first = resolveDataColumn(columns, range.column, "Conditional"), last = range.through === undefined ? first : resolveDataColumn(columns, range.through, "Conditional");
|
|
19
|
+
if (last < first)
|
|
20
|
+
throw new RangeError("Conditional data ranges require ordered columns.");
|
|
21
|
+
return { first, last };
|
|
22
|
+
}
|
|
23
|
+
function finite(value) {
|
|
24
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
25
|
+
throw new TypeError("Conditional values must be finite numbers.");
|
|
26
|
+
return String(value);
|
|
27
|
+
}
|
|
28
|
+
function comparisonValue(value, operator) {
|
|
29
|
+
if (typeof value !== "string")
|
|
30
|
+
return finite(value);
|
|
31
|
+
if (operator !== "equal" && operator !== "notEqual")
|
|
32
|
+
throw new TypeError("Text conditional comparisons support only equal and notEqual.");
|
|
33
|
+
if (value.length > 8190)
|
|
34
|
+
throw new RangeError("Conditional comparison formulas must fit 8,192 characters including quotes.");
|
|
35
|
+
cleanXml(value, "reject");
|
|
36
|
+
const literal = '"' + value.replace(/"/g, '""') + '"';
|
|
37
|
+
if (literal.length > 8192)
|
|
38
|
+
throw new RangeError("Conditional comparison formulas must fit 8,192 characters including quotes.");
|
|
39
|
+
return literal;
|
|
40
|
+
}
|
|
41
|
+
function formula(value) {
|
|
42
|
+
if (typeof value !== "string")
|
|
43
|
+
throw new TypeError("Conditional formulas must be strings.");
|
|
44
|
+
const text = value.trim().replace(/^=/, "");
|
|
45
|
+
if (!text.trim() || text.length > 8192)
|
|
46
|
+
throw new RangeError("Conditional formulas require 1 through 8,192 characters.");
|
|
47
|
+
// Stripping invalid characters could change a calculation; reject them even under the text-strip policy.
|
|
48
|
+
cleanXml(text, "reject");
|
|
49
|
+
return text;
|
|
50
|
+
}
|
|
51
|
+
function threshold(value, position) {
|
|
52
|
+
fields(value, value.type === "min" || value.type === "max" ? ["type"] : ["type", "value"], "conditional threshold");
|
|
53
|
+
if (value.type === "min" || value.type === "max") {
|
|
54
|
+
if (value.type !== (position === "first" ? "min" : position === "last" ? "max" : ""))
|
|
55
|
+
throw new TypeError("Use min only at the start and max only at the end of a scale.");
|
|
56
|
+
return '<cfvo type="' + value.type + '"/>';
|
|
57
|
+
}
|
|
58
|
+
if (value.type === "formula")
|
|
59
|
+
return '<cfvo type="formula" val="' + escapeOoxmlAttribute(formula(value.value), "reject") + '"/>';
|
|
60
|
+
if (!["number", "percent", "percentile"].includes(value.type))
|
|
61
|
+
throw new TypeError("Unsupported conditional threshold type.");
|
|
62
|
+
if (!("value" in value))
|
|
63
|
+
throw new TypeError("A numeric threshold requires a value.");
|
|
64
|
+
const number = finite(value.value);
|
|
65
|
+
if (value.type !== "number" && (value.value < 0 || value.value > 100))
|
|
66
|
+
throw new RangeError("Conditional percent/percentile thresholds must be from 0 through 100.");
|
|
67
|
+
return '<cfvo type="' + (value.type === "number" ? "num" : value.type) + '" val="' + number + '"/>';
|
|
68
|
+
}
|
|
69
|
+
function ordered(values) {
|
|
70
|
+
for (let i = 1; i < values.length; i++) {
|
|
71
|
+
const before = values[i - 1], after = values[i];
|
|
72
|
+
if ("value" in before && "value" in after && before.type === after.type && typeof before.value === "number" && typeof after.value === "number" && before.value > after.value)
|
|
73
|
+
throw new RangeError("Conditional thresholds of the same numeric type must be ordered.");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** @internal Compile bounded metadata once, outside the row hot path. */
|
|
77
|
+
export function prepareConditionalFormats(rules, columns, policy) {
|
|
78
|
+
if (rules === undefined)
|
|
79
|
+
return [];
|
|
80
|
+
if (!Array.isArray(rules))
|
|
81
|
+
throw new TypeError("conditionalFormats must be an array.");
|
|
82
|
+
return rules.map(rule => {
|
|
83
|
+
const common = ["type", "range"], highlighting = ["style", "stopIfTrue"];
|
|
84
|
+
fields(rule, [...common, ...(rule?.type === "cellIs" ? [...highlighting, "operator", "value", "values"] : rule?.type === "expression" ? [...highlighting, "formula"] : rule?.type === "colorScale" ? ["stops"] : rule?.type === "dataBar" ? ["color", "minimum", "maximum", "showValue"] : [])], "conditional rule");
|
|
85
|
+
const selected = target(rule.range, columns);
|
|
86
|
+
let attributes = "", body = "", style;
|
|
87
|
+
if (rule.type === "cellIs" || rule.type === "expression") {
|
|
88
|
+
optionalBoolean(rule.stopIfTrue, "stopIfTrue");
|
|
89
|
+
differentialXml(rule.style, policy, () => 164);
|
|
90
|
+
style = { ...rule.style, ...(rule.style.font ? { font: { ...rule.style.font } } : {}), ...(rule.style.fill ? { fill: { ...rule.style.fill } } : {}),
|
|
91
|
+
...(rule.style.border ? { border: Object.fromEntries(Object.entries(rule.style.border).filter(([, edge]) => edge !== undefined).map(([side, edge]) => [side, { ...edge }])) } : {}) };
|
|
92
|
+
if (rule.stopIfTrue !== undefined)
|
|
93
|
+
attributes += ' stopIfTrue="' + (rule.stopIfTrue ? 1 : 0) + '"';
|
|
94
|
+
if (rule.type === "expression")
|
|
95
|
+
body = '<formula>' + escapeXml(formula(rule.formula), "reject") + '</formula>';
|
|
96
|
+
else {
|
|
97
|
+
const pair = rule.operator === "between" || rule.operator === "notBetween";
|
|
98
|
+
if (!["equal", "notEqual", "greaterThan", "greaterThanOrEqual", "lessThan", "lessThanOrEqual", "between", "notBetween"].includes(rule.operator))
|
|
99
|
+
throw new TypeError("Unsupported conditional comparison operator.");
|
|
100
|
+
if (pair) {
|
|
101
|
+
if ("value" in rule || !Array.isArray(rule.values) || rule.values.length !== 2)
|
|
102
|
+
throw new TypeError("between/notBetween require exactly two values.");
|
|
103
|
+
body = rule.values.map(value => '<formula>' + finite(value) + '</formula>').join("");
|
|
104
|
+
if (rule.values[0] > rule.values[1])
|
|
105
|
+
throw new RangeError("Conditional comparison bounds must be ordered.");
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if ("values" in rule || !("value" in rule))
|
|
109
|
+
throw new TypeError("A conditional comparison requires one value.");
|
|
110
|
+
body = '<formula>' + escapeXml(comparisonValue(rule.value, rule.operator), "reject") + '</formula>';
|
|
111
|
+
}
|
|
112
|
+
attributes += ' operator="' + rule.operator + '"';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (rule.type === "colorScale") {
|
|
116
|
+
if (!Array.isArray(rule.stops) || (rule.stops.length !== 2 && rule.stops.length !== 3))
|
|
117
|
+
throw new TypeError("Color scales require two or three stops.");
|
|
118
|
+
const colors = [], thresholds = [];
|
|
119
|
+
body = '<colorScale>' + rule.stops.map((stop, i) => {
|
|
120
|
+
fields(stop, ["threshold", "color"], "color stop");
|
|
121
|
+
colors.push(colorArgb(stop.color));
|
|
122
|
+
thresholds.push(stop.threshold);
|
|
123
|
+
return threshold(stop.threshold, i === 0 ? "first" : i === rule.stops.length - 1 ? "last" : "middle");
|
|
124
|
+
}).join("") + colors.map(color => '<color rgb="' + color + '"/>').join("") + '</colorScale>';
|
|
125
|
+
ordered(thresholds);
|
|
126
|
+
}
|
|
127
|
+
else if (rule.type === "dataBar") {
|
|
128
|
+
optionalBoolean(rule.showValue, "showValue");
|
|
129
|
+
const lower = rule.minimum === undefined ? { type: "min" } : rule.minimum, upper = rule.maximum === undefined ? { type: "max" } : rule.maximum;
|
|
130
|
+
body = '<dataBar showValue="' + (rule.showValue === false ? 0 : 1) + '">' + threshold(lower, "first") + threshold(upper, "last") + '<color rgb="' + colorArgb(rule.color) + '"/></dataBar>';
|
|
131
|
+
ordered([lower, upper]);
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
throw new TypeError("Unsupported conditional rule type.");
|
|
135
|
+
return { target: selected, type: rule.type, attributes, body, ...(style ? { style } : {}) };
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/** @internal Immutable worksheet-owned rule metadata; no cells or rows are retained. */
|
|
139
|
+
export class ConditionalFormats {
|
|
140
|
+
rules;
|
|
141
|
+
constructor(prepared, styles) {
|
|
142
|
+
const differential = styles.addDifferentials(prepared.flatMap(rule => rule.style ? [rule.style] : []));
|
|
143
|
+
let styleIndex = 0;
|
|
144
|
+
this.rules = prepared.map((rule, i) => ({ target: rule.target,
|
|
145
|
+
xml: '<cfRule type="' + rule.type + '" priority="' + (i + 1) + '"' + (rule.style ? ' dxfId="' + differential[styleIndex++] + '"' : "") + rule.attributes + '>' + rule.body + '</cfRule>' }));
|
|
146
|
+
}
|
|
147
|
+
get count() { return this.rules.length; }
|
|
148
|
+
*xml(headerRows, dataRows, totalRows, ranges) {
|
|
149
|
+
for (const rule of this.rules) {
|
|
150
|
+
if (rule.target.bottom !== undefined && rule.target.bottom > totalRows)
|
|
151
|
+
throw new RangeError("Conditional ranges must stay within exported rows.");
|
|
152
|
+
const reference = rule.target.reference ?? dataRowReference(rule.target.first, rule.target.last, headerRows, dataRows, ranges);
|
|
153
|
+
if (!reference)
|
|
154
|
+
continue;
|
|
155
|
+
yield '<conditionalFormatting sqref="' + reference + '">' + rule.xml + '</conditionalFormatting>';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Border, Font } from "./styles.js";
|
|
2
|
+
/** A1 cell/range, or data-only columns resolved after streaming finishes. Column numbers are one-based; strings are declared column keys. */
|
|
3
|
+
export type ConditionalRange = string | {
|
|
4
|
+
readonly column: string | number;
|
|
5
|
+
readonly through?: string | number;
|
|
6
|
+
};
|
|
7
|
+
/** Only supplied properties override the cell. Omitting numberFormat preserves the existing number/date format. */
|
|
8
|
+
export interface ConditionalStyle {
|
|
9
|
+
readonly font?: Pick<Font, "bold" | "italic" | "underline" | "strike" | "color">;
|
|
10
|
+
readonly fill?: {
|
|
11
|
+
readonly color: string;
|
|
12
|
+
};
|
|
13
|
+
readonly border?: Border;
|
|
14
|
+
readonly numberFormat?: string;
|
|
15
|
+
}
|
|
16
|
+
export type ConditionalOperator = "equal" | "notEqual" | "greaterThan" | "greaterThanOrEqual" | "lessThan" | "lessThanOrEqual";
|
|
17
|
+
/** Formula text uses Excel's invariant syntax. It is stored, never evaluated by this writer. */
|
|
18
|
+
export type ConditionalThreshold = {
|
|
19
|
+
readonly type: "min" | "max";
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "number" | "percent" | "percentile";
|
|
22
|
+
readonly value: number;
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "formula";
|
|
25
|
+
readonly value: string;
|
|
26
|
+
};
|
|
27
|
+
export interface ConditionalColorStop {
|
|
28
|
+
readonly threshold: ConditionalThreshold;
|
|
29
|
+
readonly color: string;
|
|
30
|
+
}
|
|
31
|
+
interface ConditionalBase {
|
|
32
|
+
readonly range: ConditionalRange;
|
|
33
|
+
}
|
|
34
|
+
interface ConditionalHighlight extends ConditionalBase {
|
|
35
|
+
readonly style: ConditionalStyle;
|
|
36
|
+
readonly stopIfTrue?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Array order sets worksheet-wide priority, starting at one. Overlapping ranges are allowed. */
|
|
39
|
+
export type ConditionalFormat = (ConditionalHighlight & {
|
|
40
|
+
readonly type: "cellIs";
|
|
41
|
+
readonly operator: ConditionalOperator;
|
|
42
|
+
readonly value: number;
|
|
43
|
+
}) | (ConditionalHighlight & {
|
|
44
|
+
readonly type: "cellIs";
|
|
45
|
+
readonly operator: "equal" | "notEqual";
|
|
46
|
+
readonly value: string;
|
|
47
|
+
}) | (ConditionalHighlight & {
|
|
48
|
+
readonly type: "cellIs";
|
|
49
|
+
readonly operator: "between" | "notBetween";
|
|
50
|
+
readonly values: readonly [number, number];
|
|
51
|
+
}) | (ConditionalHighlight & {
|
|
52
|
+
readonly type: "expression";
|
|
53
|
+
readonly formula: string;
|
|
54
|
+
}) | (ConditionalBase & {
|
|
55
|
+
readonly type: "colorScale";
|
|
56
|
+
readonly stops: readonly [ConditionalColorStop, ConditionalColorStop] | readonly [ConditionalColorStop, ConditionalColorStop, ConditionalColorStop];
|
|
57
|
+
}) | (ConditionalBase & {
|
|
58
|
+
readonly type: "dataBar";
|
|
59
|
+
readonly color: string;
|
|
60
|
+
readonly minimum?: ConditionalThreshold;
|
|
61
|
+
readonly maximum?: ConditionalThreshold;
|
|
62
|
+
readonly showValue?: boolean;
|
|
63
|
+
});
|
|
64
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
2
|
+
import { columnName } from "./values.js";
|
|
3
|
+
const scopes = new WeakMap();
|
|
4
|
+
/** @internal A format adapter owns this bounded list until worksheet completion. */
|
|
5
|
+
export function retainDataRowRanges(worksheet, ranges) { scopes.set(worksheet, ranges); }
|
|
6
|
+
/** @internal Ordinary worksheets retain their contiguous data-column contract. */
|
|
7
|
+
export function dataRowRanges(worksheet) { return scopes.get(worksheet); }
|
|
8
|
+
/** @internal Count accepted details while preserving physical row counts for native references. */
|
|
9
|
+
export function dataRowCount(worksheet, headerRows, serializedRows) {
|
|
10
|
+
const ranges = scopes.get(worksheet);
|
|
11
|
+
if (ranges === undefined)
|
|
12
|
+
return serializedRows;
|
|
13
|
+
const lastSerialized = headerRows + serializedRows;
|
|
14
|
+
let rows = 0;
|
|
15
|
+
for (const range of ranges) {
|
|
16
|
+
if (range.firstRow > lastSerialized)
|
|
17
|
+
break;
|
|
18
|
+
rows += Math.min(range.lastRow, lastSerialized) - range.firstRow + 1;
|
|
19
|
+
}
|
|
20
|
+
return rows;
|
|
21
|
+
}
|
|
22
|
+
/** @internal Native editing rules share one finite, bounded space-separated reference. */
|
|
23
|
+
export function dataRowReference(firstColumn, lastColumn, headerRows, dataRows, ranges) {
|
|
24
|
+
if (ranges === undefined)
|
|
25
|
+
return dataRows ? columnName(firstColumn) + (headerRows + 1) + ":" + columnName(lastColumn) + (headerRows + dataRows) : undefined;
|
|
26
|
+
const first = columnName(firstColumn), last = columnName(lastColumn);
|
|
27
|
+
let reference = "", previous = headerRows;
|
|
28
|
+
for (const range of ranges) {
|
|
29
|
+
if (!Number.isSafeInteger(range.firstRow) || !Number.isSafeInteger(range.lastRow) || range.firstRow <= previous ||
|
|
30
|
+
range.lastRow < range.firstRow || range.lastRow > headerRows + dataRows)
|
|
31
|
+
throw new RangeError("Detail editing ranges must be ordered within serialized worksheet rows.");
|
|
32
|
+
const next = first + range.firstRow + ":" + last + range.lastRow;
|
|
33
|
+
if (reference.length + (reference ? 1 : 0) + next.length > 32767)
|
|
34
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Detail editing references exceed 32,767 UTF-16 characters; split the worksheet.");
|
|
35
|
+
reference += (reference ? " " : "") + next;
|
|
36
|
+
previous = range.lastRow;
|
|
37
|
+
}
|
|
38
|
+
return reference || undefined;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
2
|
+
import { cleanXml, escapeOoxmlAttribute } from "../xml/index.js";
|
|
3
|
+
import { colorArgb } from "./style-xml.js";
|
|
4
|
+
/** @internal Reject unsupported properties rather than silently losing presentation. */
|
|
5
|
+
export function fields(value, allowed, label) {
|
|
6
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
7
|
+
throw new TypeError(label + " must be an object.");
|
|
8
|
+
if (typeof value.then === "function") {
|
|
9
|
+
void Promise.resolve(value).catch(() => { });
|
|
10
|
+
throw new TypeError(label + " must be synchronous.");
|
|
11
|
+
}
|
|
12
|
+
for (const key of Object.keys(value))
|
|
13
|
+
if (!allowed.includes(key))
|
|
14
|
+
throw new TypeError("Unsupported " + label + " property: " + key);
|
|
15
|
+
}
|
|
16
|
+
/** @internal */
|
|
17
|
+
export function optionalBoolean(value, name) {
|
|
18
|
+
if (value !== undefined && typeof value !== "boolean")
|
|
19
|
+
throw new TypeError(name + " must be boolean.");
|
|
20
|
+
}
|
|
21
|
+
/** @internal Differential styles contain no default font/fill/border properties. */
|
|
22
|
+
export class DifferentialStyles {
|
|
23
|
+
policy;
|
|
24
|
+
maximum;
|
|
25
|
+
numberFormat;
|
|
26
|
+
definitions = new Map();
|
|
27
|
+
constructor(policy, maximum, numberFormat) {
|
|
28
|
+
this.policy = policy;
|
|
29
|
+
this.maximum = maximum;
|
|
30
|
+
this.numberFormat = numberFormat;
|
|
31
|
+
}
|
|
32
|
+
keys(styles) {
|
|
33
|
+
// Validation and canonical XML precede registration, so equivalent property order shares a dxf.
|
|
34
|
+
const keys = styles.map(style => differentialXml(style, this.policy, () => 164));
|
|
35
|
+
const pending = new Set(keys.filter(definition => !this.definitions.has(definition)));
|
|
36
|
+
if (this.definitions.size + pending.size > this.maximum)
|
|
37
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxDifferentialStyles exceeded.");
|
|
38
|
+
return keys;
|
|
39
|
+
}
|
|
40
|
+
check(styles) { this.keys(styles); }
|
|
41
|
+
add(styles) {
|
|
42
|
+
const keys = this.keys(styles);
|
|
43
|
+
for (let i = 0; i < styles.length; i++)
|
|
44
|
+
if (!this.definitions.has(keys[i]))
|
|
45
|
+
this.definitions.set(keys[i], { id: this.definitions.size, xml: differentialXml(styles[i], this.policy, this.numberFormat) });
|
|
46
|
+
return keys.map(key => this.definitions.get(key).id);
|
|
47
|
+
}
|
|
48
|
+
toXml() {
|
|
49
|
+
return this.definitions.size ? '<dxfs count="' + this.definitions.size + '">' + [...this.definitions.values()].map(style => '<dxf>' + style.xml + '</dxf>').join("") + '</dxfs>' : "";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** @internal Also used for preflight before registering a worksheet name. */
|
|
53
|
+
export function differentialXml(style, policy, numberFormat) {
|
|
54
|
+
fields(style, ["font", "fill", "border", "numberFormat"], "conditional style");
|
|
55
|
+
let xml = "";
|
|
56
|
+
if (style.font !== undefined) {
|
|
57
|
+
fields(style.font, ["bold", "italic", "underline", "strike", "color"], "conditional font");
|
|
58
|
+
let font = "";
|
|
59
|
+
for (const [name, tag] of [["bold", "b"], ["italic", "i"], ["strike", "strike"]]) {
|
|
60
|
+
optionalBoolean(style.font[name], name);
|
|
61
|
+
if (style.font[name] !== undefined)
|
|
62
|
+
font += '<' + tag + ' val="' + (style.font[name] ? 1 : 0) + '"/>';
|
|
63
|
+
}
|
|
64
|
+
optionalBoolean(style.font.underline, "underline");
|
|
65
|
+
if (style.font.underline !== undefined)
|
|
66
|
+
font += '<u val="' + (style.font.underline ? "single" : "none") + '"/>';
|
|
67
|
+
if (style.font.color !== undefined)
|
|
68
|
+
font += '<color rgb="' + colorArgb(style.font.color) + '"/>';
|
|
69
|
+
if (font)
|
|
70
|
+
xml += '<font>' + font + '</font>';
|
|
71
|
+
}
|
|
72
|
+
if (style.numberFormat !== undefined) {
|
|
73
|
+
const format = style.numberFormat;
|
|
74
|
+
if (typeof format !== "string" || !format || format.length > 255 || !cleanXml(format, policy))
|
|
75
|
+
throw new TypeError("Conditional number format requires 1 through 255 XML-valid characters.");
|
|
76
|
+
xml += '<numFmt numFmtId="' + numberFormat(format) + '" formatCode="' + escapeOoxmlAttribute(format, policy) + '"/>';
|
|
77
|
+
}
|
|
78
|
+
if (style.fill !== undefined) {
|
|
79
|
+
fields(style.fill, ["color"], "conditional fill");
|
|
80
|
+
const color = colorArgb(style.fill.color);
|
|
81
|
+
// Excel reads the background color for a differential solid fill; keep both channels explicit.
|
|
82
|
+
xml += '<fill><patternFill patternType="solid"><fgColor rgb="' + color + '"/><bgColor rgb="' + color + '"/></patternFill></fill>';
|
|
83
|
+
}
|
|
84
|
+
if (style.border !== undefined) {
|
|
85
|
+
fields(style.border, ["left", "right", "top", "bottom"], "conditional border");
|
|
86
|
+
let border = "";
|
|
87
|
+
for (const side of ["left", "right", "top", "bottom"]) {
|
|
88
|
+
const edge = style.border[side];
|
|
89
|
+
if (edge !== undefined) {
|
|
90
|
+
fields(edge, ["style", "color"], "conditional border edge");
|
|
91
|
+
if (!["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"].includes(edge.style))
|
|
92
|
+
throw new TypeError("Invalid conditional border style.");
|
|
93
|
+
border += '<' + side + ' style="' + edge.style + '">' + (edge.color !== undefined ? '<color rgb="' + colorArgb(edge.color) + '"/>' : "") + '</' + side + '>';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (border)
|
|
97
|
+
xml += '<border>' + border + '</border>';
|
|
98
|
+
}
|
|
99
|
+
if (!xml)
|
|
100
|
+
throw new TypeError("A conditional style must change at least one property.");
|
|
101
|
+
return xml;
|
|
102
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** An authored XLSX storage expression and its initial numeric or blank result. Future functions retain their required _xlfn prefixes; the writer does not evaluate or normalize function names. */
|
|
2
|
+
export declare class FormulaCell {
|
|
3
|
+
readonly cachedValue: number | null;
|
|
4
|
+
readonly style?: number | undefined;
|
|
5
|
+
static [Symbol.hasInstance](value: unknown): boolean;
|
|
6
|
+
readonly formula: string;
|
|
7
|
+
constructor(formula: string, cachedValue: number | null, style?: number | undefined);
|
|
8
|
+
}
|