ooxml.js 6.1.0 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/typed/xlsx/build.cjs +12 -4
- package/dist/typed/xlsx/build.js +12 -4
- package/dist/typed/xlsx/conditional-format.cjs +519 -0
- package/dist/typed/xlsx/conditional-format.d.cts +16 -0
- package/dist/typed/xlsx/conditional-format.d.ts +16 -0
- package/dist/typed/xlsx/conditional-format.js +516 -0
- package/dist/typed/xlsx/content.cjs +12 -7
- package/dist/typed/xlsx/content.js +13 -8
- package/dist/typed/xlsx/data-validation.cjs +116 -0
- package/dist/typed/xlsx/data-validation.d.cts +11 -0
- package/dist/typed/xlsx/data-validation.d.ts +11 -0
- package/dist/typed/xlsx/data-validation.js +114 -0
- package/dist/typed/xlsx/rule-residue.cjs +29 -0
- package/dist/typed/xlsx/rule-residue.d.cts +7 -0
- package/dist/typed/xlsx/rule-residue.d.ts +7 -0
- package/dist/typed/xlsx/rule-residue.js +27 -0
- package/dist/typed/xlsx/sqref.cjs +24 -0
- package/dist/typed/xlsx/sqref.d.cts +7 -0
- package/dist/typed/xlsx/sqref.d.ts +7 -0
- package/dist/typed/xlsx/sqref.js +21 -0
- package/dist/typed/xlsx/styles.cjs +14 -2
- package/dist/typed/xlsx/styles.d.cts +5 -1
- package/dist/typed/xlsx/styles.d.ts +5 -1
- package/dist/typed/xlsx/styles.js +12 -3
- package/package.json +2 -2
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_parse = require("../../xml/parse.cjs");
|
|
3
|
+
const require_xml_build = require("../../xml/build.cjs");
|
|
4
|
+
const require_xml_fragment = require("../../xml/fragment.cjs");
|
|
5
|
+
const require_xml_entities = require("../../xml/entities.cjs");
|
|
6
|
+
const require_typed_util = require("../util.cjs");
|
|
7
|
+
const require_typed_xlsx_util = require("./util.cjs");
|
|
8
|
+
const require_typed_xlsx_styles = require("./styles.cjs");
|
|
9
|
+
const require_typed_xlsx_rule_residue = require("./rule-residue.cjs");
|
|
10
|
+
const require_typed_xlsx_sqref = require("./sqref.cjs");
|
|
11
|
+
let document_schema_js = require("document-schema.js");
|
|
12
|
+
//#region src/typed/xlsx/conditional-format.ts
|
|
13
|
+
const CF_RULE_MANAGED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
14
|
+
"type",
|
|
15
|
+
"dxfId",
|
|
16
|
+
"priority",
|
|
17
|
+
"stopIfTrue",
|
|
18
|
+
"operator",
|
|
19
|
+
"text",
|
|
20
|
+
"rank",
|
|
21
|
+
"percent",
|
|
22
|
+
"bottom",
|
|
23
|
+
"aboveAverage",
|
|
24
|
+
"equalAverage",
|
|
25
|
+
"stdDev",
|
|
26
|
+
"timePeriod",
|
|
27
|
+
"iconSet",
|
|
28
|
+
"reverse",
|
|
29
|
+
"showValue"
|
|
30
|
+
]);
|
|
31
|
+
function readConditionalFormats(worksheet, dxfs) {
|
|
32
|
+
const formats = [];
|
|
33
|
+
const residueElements = [];
|
|
34
|
+
for (const wrapper of require_typed_util.childrenWithTag(worksheet, "conditionalFormatting")) {
|
|
35
|
+
const ranges = require_typed_xlsx_sqref.parseSqref(require_typed_util.attr(wrapper, "sqref"));
|
|
36
|
+
for (const cfRule of require_typed_util.childrenWithTag(wrapper, "cfRule")) {
|
|
37
|
+
const promoted = ranges.length === 0 ? void 0 : readCfRule(cfRule, ranges, dxfs);
|
|
38
|
+
if (promoted === void 0) {
|
|
39
|
+
residueElements.push({
|
|
40
|
+
type: "element",
|
|
41
|
+
tag: "conditionalFormatting",
|
|
42
|
+
attributes: wrapper.attributes,
|
|
43
|
+
children: [cfRule]
|
|
44
|
+
});
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
formats.push(promoted);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
formats,
|
|
52
|
+
residueElements
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function readCommonFields(cfRule, ranges) {
|
|
56
|
+
const result = { ranges: [...ranges] };
|
|
57
|
+
const priorityRaw = require_typed_util.attr(cfRule, "priority");
|
|
58
|
+
if (priorityRaw !== void 0) {
|
|
59
|
+
const priority = Number.parseInt(priorityRaw, 10);
|
|
60
|
+
if (Number.isInteger(priority)) result.priority = priority;
|
|
61
|
+
}
|
|
62
|
+
if (require_typed_xlsx_util.readXmlBool(require_typed_util.attr(cfRule, "stopIfTrue"))) result.stopIfTrue = true;
|
|
63
|
+
const source = require_typed_xlsx_rule_residue.captureResidualAttributes(cfRule, CF_RULE_MANAGED_ATTRIBUTES);
|
|
64
|
+
if (source !== void 0) result.source = source;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function readFormula(cfRule, index) {
|
|
68
|
+
const formulaEl = require_typed_util.childrenWithTag(cfRule, "formula")[index];
|
|
69
|
+
return formulaEl === void 0 ? void 0 : require_typed_util.textContent(formulaEl);
|
|
70
|
+
}
|
|
71
|
+
function isSheetRuleOperator(value) {
|
|
72
|
+
return value === "between" || value === "notBetween" || value === "equal" || value === "notEqual" || value === "greaterThan" || value === "greaterThanOrEqual" || value === "lessThan" || value === "lessThanOrEqual";
|
|
73
|
+
}
|
|
74
|
+
const TEXT_PREDICATE_TYPES = /* @__PURE__ */ new Set([
|
|
75
|
+
"containsText",
|
|
76
|
+
"notContainsText",
|
|
77
|
+
"beginsWith",
|
|
78
|
+
"endsWith"
|
|
79
|
+
]);
|
|
80
|
+
function isTextPredicateType(value) {
|
|
81
|
+
return value !== void 0 && TEXT_PREDICATE_TYPES.has(value);
|
|
82
|
+
}
|
|
83
|
+
const OPERAND_FREE_TYPES = /* @__PURE__ */ new Set([
|
|
84
|
+
"containsBlanks",
|
|
85
|
+
"notContainsBlanks",
|
|
86
|
+
"containsErrors",
|
|
87
|
+
"notContainsErrors",
|
|
88
|
+
"uniqueValues",
|
|
89
|
+
"duplicateValues"
|
|
90
|
+
]);
|
|
91
|
+
function isOperandFreeType(value) {
|
|
92
|
+
return value !== void 0 && OPERAND_FREE_TYPES.has(value);
|
|
93
|
+
}
|
|
94
|
+
const TIME_PERIODS = /* @__PURE__ */ new Set([
|
|
95
|
+
"yesterday",
|
|
96
|
+
"today",
|
|
97
|
+
"tomorrow",
|
|
98
|
+
"last7Days",
|
|
99
|
+
"thisMonth",
|
|
100
|
+
"lastMonth",
|
|
101
|
+
"nextMonth",
|
|
102
|
+
"thisWeek",
|
|
103
|
+
"lastWeek",
|
|
104
|
+
"nextWeek"
|
|
105
|
+
]);
|
|
106
|
+
function isTimePeriod(value) {
|
|
107
|
+
return value !== void 0 && TIME_PERIODS.has(value);
|
|
108
|
+
}
|
|
109
|
+
function isCfvoType(value) {
|
|
110
|
+
return value === "num" || value === "percent" || value === "max" || value === "min" || value === "formula" || value === "percentile";
|
|
111
|
+
}
|
|
112
|
+
function readCfvo(cfvoEl) {
|
|
113
|
+
const type = require_typed_util.attr(cfvoEl, "type");
|
|
114
|
+
if (!isCfvoType(type)) return;
|
|
115
|
+
if (type === "min" || type === "max") return { type };
|
|
116
|
+
const valRaw = require_typed_util.attr(cfvoEl, "val");
|
|
117
|
+
if (valRaw === void 0) return;
|
|
118
|
+
return {
|
|
119
|
+
type,
|
|
120
|
+
value: require_typed_util.decodeEntities(valRaw)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function readColorScaleStops(colorScaleEl) {
|
|
124
|
+
const cfvoEls = require_typed_util.childrenWithTag(colorScaleEl, "cfvo");
|
|
125
|
+
const colorEls = require_typed_util.childrenWithTag(colorScaleEl, "color");
|
|
126
|
+
if (cfvoEls.length !== colorEls.length || cfvoEls.length < 2 || cfvoEls.length > 3) return;
|
|
127
|
+
const stops = [];
|
|
128
|
+
for (let index = 0; index < cfvoEls.length; index++) {
|
|
129
|
+
const cfvoEl = cfvoEls[index];
|
|
130
|
+
const colorEl = colorEls[index];
|
|
131
|
+
if (cfvoEl === void 0 || colorEl === void 0) return;
|
|
132
|
+
const value = readCfvo(cfvoEl);
|
|
133
|
+
const color = require_typed_xlsx_styles.colorFromElement(colorEl);
|
|
134
|
+
if (value === void 0 || color === void 0) return;
|
|
135
|
+
stops.push({
|
|
136
|
+
value,
|
|
137
|
+
color
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return stops;
|
|
141
|
+
}
|
|
142
|
+
function readDataBar(dataBarEl) {
|
|
143
|
+
const cfvoEls = require_typed_util.childrenWithTag(dataBarEl, "cfvo");
|
|
144
|
+
const minEl = cfvoEls[0];
|
|
145
|
+
const maxEl = cfvoEls[1];
|
|
146
|
+
const min = minEl === void 0 ? void 0 : readCfvo(minEl);
|
|
147
|
+
const max = maxEl === void 0 ? void 0 : readCfvo(maxEl);
|
|
148
|
+
const color = require_typed_xlsx_styles.colorFromElement(require_typed_util.childrenWithTag(dataBarEl, "color")[0]);
|
|
149
|
+
if (min === void 0 || max === void 0 || color === void 0) return;
|
|
150
|
+
const result = {
|
|
151
|
+
min,
|
|
152
|
+
max,
|
|
153
|
+
color
|
|
154
|
+
};
|
|
155
|
+
const showValueRaw = require_typed_util.attr(dataBarEl, "showValue");
|
|
156
|
+
if (showValueRaw !== void 0 && !require_typed_xlsx_util.readXmlBool(showValueRaw)) result.showValue = false;
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
const DEFAULT_ICON_SET_TYPE = "3TrafficLights1";
|
|
160
|
+
function readIconSet(iconSetEl) {
|
|
161
|
+
const thresholds = [];
|
|
162
|
+
for (const cfvoEl of require_typed_util.childrenWithTag(iconSetEl, "cfvo")) {
|
|
163
|
+
const value = readCfvo(cfvoEl);
|
|
164
|
+
if (value === void 0) return;
|
|
165
|
+
thresholds.push(value);
|
|
166
|
+
}
|
|
167
|
+
if (thresholds.length === 0) return;
|
|
168
|
+
const result = {
|
|
169
|
+
iconSetType: require_typed_util.attr(iconSetEl, "iconSet") ?? DEFAULT_ICON_SET_TYPE,
|
|
170
|
+
thresholds
|
|
171
|
+
};
|
|
172
|
+
if (require_typed_xlsx_util.readXmlBool(require_typed_util.attr(iconSetEl, "reverse"))) result.reverse = true;
|
|
173
|
+
const showValueRaw = require_typed_util.attr(iconSetEl, "showValue");
|
|
174
|
+
if (showValueRaw !== void 0 && !require_typed_xlsx_util.readXmlBool(showValueRaw)) result.showValue = false;
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
function styleFromDxf(dxf) {
|
|
178
|
+
const fontEl = require_typed_util.childrenWithTag(dxf, "font")[0];
|
|
179
|
+
const textColor = fontEl === void 0 ? void 0 : require_typed_xlsx_styles.readColorRgb(fontEl, "color");
|
|
180
|
+
const fillEl = require_typed_util.childrenWithTag(dxf, "fill")[0];
|
|
181
|
+
const patternFillEl = fillEl === void 0 ? void 0 : require_typed_util.childrenWithTag(fillEl, "patternFill")[0];
|
|
182
|
+
const background = patternFillEl === void 0 ? void 0 : require_typed_xlsx_styles.readColorRgb(patternFillEl, "bgColor");
|
|
183
|
+
const residueChildren = dxfResidueChildren(dxf, textColor !== void 0, background !== void 0);
|
|
184
|
+
const style = {};
|
|
185
|
+
if (textColor !== void 0) style.textColor = textColor;
|
|
186
|
+
if (background !== void 0) style.background = background;
|
|
187
|
+
if (residueChildren.length > 0) style.source = {
|
|
188
|
+
format: "xlsx",
|
|
189
|
+
xml: require_xml_build.buildXml(residueChildren)
|
|
190
|
+
};
|
|
191
|
+
return style.textColor === void 0 && style.background === void 0 && style.source === void 0 ? void 0 : style;
|
|
192
|
+
}
|
|
193
|
+
function withoutChildTag(element, tag) {
|
|
194
|
+
const remaining = element.children.filter((child) => !(child.type === "element" && child.tag === tag));
|
|
195
|
+
if (remaining.length === 0 && element.attributes.length === 0) return;
|
|
196
|
+
return {
|
|
197
|
+
...element,
|
|
198
|
+
children: remaining
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function fillResidue(fillEl) {
|
|
202
|
+
const patternFillEl = require_typed_util.childrenWithTag(fillEl, "patternFill")[0];
|
|
203
|
+
const otherFillChildren = fillEl.children.filter((child) => !(child.type === "element" && child.tag === "patternFill"));
|
|
204
|
+
if (patternFillEl === void 0) return otherFillChildren.length === 0 && fillEl.attributes.length === 0 ? void 0 : {
|
|
205
|
+
...fillEl,
|
|
206
|
+
children: otherFillChildren
|
|
207
|
+
};
|
|
208
|
+
const patternFillResidue = withoutChildTag(patternFillEl, "bgColor");
|
|
209
|
+
if (patternFillResidue === void 0) return otherFillChildren.length === 0 && fillEl.attributes.length === 0 ? void 0 : {
|
|
210
|
+
...fillEl,
|
|
211
|
+
children: otherFillChildren
|
|
212
|
+
};
|
|
213
|
+
return {
|
|
214
|
+
...fillEl,
|
|
215
|
+
children: [patternFillResidue, ...otherFillChildren]
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function dxfResidueChildren(dxf, textColorCaptured, backgroundCaptured) {
|
|
219
|
+
const residue = [];
|
|
220
|
+
for (const child of dxf.children) {
|
|
221
|
+
if (child.type !== "element") continue;
|
|
222
|
+
if (child.tag === "font" && textColorCaptured) {
|
|
223
|
+
const remainder = withoutChildTag(child, "color");
|
|
224
|
+
if (remainder !== void 0) residue.push(remainder);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (child.tag === "fill" && backgroundCaptured) {
|
|
228
|
+
const remainder = fillResidue(child);
|
|
229
|
+
if (remainder !== void 0) residue.push(remainder);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
residue.push(child);
|
|
233
|
+
}
|
|
234
|
+
return residue;
|
|
235
|
+
}
|
|
236
|
+
function resolveStyle(cfRule, dxfs) {
|
|
237
|
+
const dxfIdRaw = require_typed_util.attr(cfRule, "dxfId");
|
|
238
|
+
if (dxfIdRaw === void 0) return;
|
|
239
|
+
const dxfId = Number.parseInt(dxfIdRaw, 10);
|
|
240
|
+
const dxf = Number.isInteger(dxfId) ? dxfs[dxfId] : void 0;
|
|
241
|
+
return dxf === void 0 ? void 0 : styleFromDxf(dxf);
|
|
242
|
+
}
|
|
243
|
+
function readCfRule(cfRule, ranges, dxfs) {
|
|
244
|
+
const type = require_typed_util.attr(cfRule, "type");
|
|
245
|
+
const common = readCommonFields(cfRule, ranges);
|
|
246
|
+
const style = resolveStyle(cfRule, dxfs);
|
|
247
|
+
const styleField = style === void 0 ? {} : { style };
|
|
248
|
+
if (type === "cellIs") {
|
|
249
|
+
const operatorRaw = require_typed_util.attr(cfRule, "operator");
|
|
250
|
+
const formula1 = readFormula(cfRule, 0);
|
|
251
|
+
if (!isSheetRuleOperator(operatorRaw) || formula1 === void 0) return;
|
|
252
|
+
const formula2 = operatorRaw === "between" || operatorRaw === "notBetween" ? readFormula(cfRule, 1) : void 0;
|
|
253
|
+
return {
|
|
254
|
+
type: "cellIs",
|
|
255
|
+
...common,
|
|
256
|
+
operator: operatorRaw,
|
|
257
|
+
formula1,
|
|
258
|
+
...formula2 === void 0 ? {} : { formula2 },
|
|
259
|
+
...styleField
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if (isTextPredicateType(type)) {
|
|
263
|
+
const text = require_typed_util.attr(cfRule, "text");
|
|
264
|
+
if (text === void 0) return;
|
|
265
|
+
return {
|
|
266
|
+
type,
|
|
267
|
+
...common,
|
|
268
|
+
text: require_typed_util.decodeEntities(text),
|
|
269
|
+
...styleField
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
if (isOperandFreeType(type)) return {
|
|
273
|
+
type,
|
|
274
|
+
...common,
|
|
275
|
+
...styleField
|
|
276
|
+
};
|
|
277
|
+
if (type === "top10") {
|
|
278
|
+
const rankRaw = require_typed_util.attr(cfRule, "rank");
|
|
279
|
+
const rank = rankRaw === void 0 ? void 0 : Number(rankRaw);
|
|
280
|
+
if (rank === void 0 || !Number.isFinite(rank) || rank <= 0) return;
|
|
281
|
+
return {
|
|
282
|
+
type: "top10",
|
|
283
|
+
...common,
|
|
284
|
+
rank,
|
|
285
|
+
...require_typed_xlsx_util.readXmlBool(require_typed_util.attr(cfRule, "percent")) ? { percent: true } : {},
|
|
286
|
+
...require_typed_xlsx_util.readXmlBool(require_typed_util.attr(cfRule, "bottom")) ? { bottom: true } : {},
|
|
287
|
+
...styleField
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
if (type === "aboveAverage") {
|
|
291
|
+
const aboveAverageRaw = require_typed_util.attr(cfRule, "aboveAverage");
|
|
292
|
+
const stdDevRaw = require_typed_util.attr(cfRule, "stdDev");
|
|
293
|
+
const stdDev = stdDevRaw === void 0 ? void 0 : Number.parseInt(stdDevRaw, 10);
|
|
294
|
+
return {
|
|
295
|
+
type: "aboveAverage",
|
|
296
|
+
...common,
|
|
297
|
+
...aboveAverageRaw !== void 0 && !require_typed_xlsx_util.readXmlBool(aboveAverageRaw) ? { aboveAverage: false } : {},
|
|
298
|
+
...require_typed_xlsx_util.readXmlBool(require_typed_util.attr(cfRule, "equalAverage")) ? { equalAverage: true } : {},
|
|
299
|
+
...stdDev !== void 0 && Number.isInteger(stdDev) && stdDev > 0 ? { stdDev } : {},
|
|
300
|
+
...styleField
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (type === "timePeriod") {
|
|
304
|
+
const timePeriod = require_typed_util.attr(cfRule, "timePeriod");
|
|
305
|
+
if (!isTimePeriod(timePeriod)) return;
|
|
306
|
+
return {
|
|
307
|
+
type: "timePeriod",
|
|
308
|
+
...common,
|
|
309
|
+
timePeriod,
|
|
310
|
+
...styleField
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
if (type === "colorScale") {
|
|
314
|
+
const colorScaleEl = require_typed_util.childrenWithTag(cfRule, "colorScale")[0];
|
|
315
|
+
const stops = colorScaleEl === void 0 ? void 0 : readColorScaleStops(colorScaleEl);
|
|
316
|
+
if (stops === void 0) return;
|
|
317
|
+
return {
|
|
318
|
+
type: "colorScale",
|
|
319
|
+
...common,
|
|
320
|
+
stops
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
if (type === "dataBar") {
|
|
324
|
+
const dataBarEl = require_typed_util.childrenWithTag(cfRule, "dataBar")[0];
|
|
325
|
+
const parsed = dataBarEl === void 0 ? void 0 : readDataBar(dataBarEl);
|
|
326
|
+
if (parsed === void 0) return;
|
|
327
|
+
return {
|
|
328
|
+
type: "dataBar",
|
|
329
|
+
...common,
|
|
330
|
+
min: parsed.min,
|
|
331
|
+
max: parsed.max,
|
|
332
|
+
color: parsed.color,
|
|
333
|
+
...parsed.showValue === void 0 ? {} : { showValue: parsed.showValue }
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
if (type === "iconSet") {
|
|
337
|
+
const iconSetEl = require_typed_util.childrenWithTag(cfRule, "iconSet")[0];
|
|
338
|
+
const parsed = iconSetEl === void 0 ? void 0 : readIconSet(iconSetEl);
|
|
339
|
+
if (parsed === void 0) return;
|
|
340
|
+
return {
|
|
341
|
+
type: "iconSet",
|
|
342
|
+
...common,
|
|
343
|
+
iconSetType: parsed.iconSetType,
|
|
344
|
+
thresholds: parsed.thresholds,
|
|
345
|
+
...parsed.reverse === void 0 ? {} : { reverse: parsed.reverse },
|
|
346
|
+
...parsed.showValue === void 0 ? {} : { showValue: parsed.showValue }
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
var DxfTable = class {
|
|
351
|
+
elements = [];
|
|
352
|
+
intern(style) {
|
|
353
|
+
const index = this.elements.length;
|
|
354
|
+
this.elements.push(buildDxfElement(style));
|
|
355
|
+
return index;
|
|
356
|
+
}
|
|
357
|
+
dxfElements() {
|
|
358
|
+
return this.elements;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
function attrsRecord(attributes) {
|
|
362
|
+
const result = {};
|
|
363
|
+
for (const attribute of attributes) result[attribute.name] = attribute.value;
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
function extractResidueElements(source) {
|
|
367
|
+
if (source?.format !== "xlsx") return [];
|
|
368
|
+
const elements = [];
|
|
369
|
+
for (const node of require_xml_parse.parseXml(source.xml)) if (node.type === "element") elements.push(node);
|
|
370
|
+
return elements;
|
|
371
|
+
}
|
|
372
|
+
function buildDxfElement(style) {
|
|
373
|
+
const residueByTag = /* @__PURE__ */ new Map();
|
|
374
|
+
for (const element of extractResidueElements(style.source)) residueByTag.set(element.tag, element);
|
|
375
|
+
const children = [];
|
|
376
|
+
const residualFont = residueByTag.get("font");
|
|
377
|
+
if (style.textColor !== void 0) {
|
|
378
|
+
const fontChildren = residualFont === void 0 ? [] : residualFont.children;
|
|
379
|
+
const fontAttrs = residualFont === void 0 ? {} : attrsRecord(residualFont.attributes);
|
|
380
|
+
children.push(require_xml_fragment.el("font", fontAttrs, [...fontChildren, require_xml_fragment.el("color", { rgb: `FF${(0, document_schema_js.colorToRgbHex)(style.textColor)}` })]));
|
|
381
|
+
} else if (residualFont !== void 0) children.push(residualFont);
|
|
382
|
+
const residualNumFmt = residueByTag.get("numFmt");
|
|
383
|
+
if (residualNumFmt !== void 0) children.push(residualNumFmt);
|
|
384
|
+
const residualFill = residueByTag.get("fill");
|
|
385
|
+
if (style.background !== void 0) {
|
|
386
|
+
const residualPatternFill = residualFill === void 0 ? void 0 : require_typed_util.childrenWithTag(residualFill, "patternFill")[0];
|
|
387
|
+
const patternFillChildren = residualPatternFill === void 0 ? [] : residualPatternFill.children;
|
|
388
|
+
const patternFillAttrs = residualPatternFill === void 0 ? {} : attrsRecord(residualPatternFill.attributes);
|
|
389
|
+
const otherFillChildren = residualFill === void 0 ? [] : residualFill.children.filter((child) => !(child.type === "element" && child.tag === "patternFill"));
|
|
390
|
+
children.push(require_xml_fragment.el("fill", residualFill === void 0 ? {} : attrsRecord(residualFill.attributes), [require_xml_fragment.el("patternFill", patternFillAttrs, [...patternFillChildren, require_xml_fragment.el("bgColor", { rgb: `FF${(0, document_schema_js.colorToRgbHex)(style.background)}` })]), ...otherFillChildren]));
|
|
391
|
+
} else if (residualFill !== void 0) children.push(residualFill);
|
|
392
|
+
for (const tag of [
|
|
393
|
+
"alignment",
|
|
394
|
+
"border",
|
|
395
|
+
"protection"
|
|
396
|
+
]) {
|
|
397
|
+
const residual = residueByTag.get(tag);
|
|
398
|
+
if (residual !== void 0) children.push(residual);
|
|
399
|
+
}
|
|
400
|
+
return require_xml_fragment.el("dxf", {}, children);
|
|
401
|
+
}
|
|
402
|
+
function rangeSetKey(ranges) {
|
|
403
|
+
return ranges.map((range) => `${range.startRow}:${range.startColumn}:${range.endRow}:${range.endColumn}`).join("|");
|
|
404
|
+
}
|
|
405
|
+
const TEXT_PREDICATE_OPERATOR = {
|
|
406
|
+
containsText: "containsText",
|
|
407
|
+
notContainsText: "notContains",
|
|
408
|
+
beginsWith: "beginsWith",
|
|
409
|
+
endsWith: "endsWith"
|
|
410
|
+
};
|
|
411
|
+
function buildCfvoElement(value) {
|
|
412
|
+
const attrs = { type: value.type };
|
|
413
|
+
if (value.value !== void 0) attrs.val = require_xml_entities.encodeXmlText(value.value);
|
|
414
|
+
return require_xml_fragment.el("cfvo", attrs);
|
|
415
|
+
}
|
|
416
|
+
function buildCfRuleElement(rule, priority, dxfTable) {
|
|
417
|
+
const attrs = require_typed_xlsx_rule_residue.residualAttributesFor(rule.source, "cfRule");
|
|
418
|
+
attrs.type = rule.type;
|
|
419
|
+
attrs.priority = String(priority);
|
|
420
|
+
if (rule.stopIfTrue === true) attrs.stopIfTrue = require_typed_xlsx_util.writeXmlBool(true);
|
|
421
|
+
const children = [];
|
|
422
|
+
let style;
|
|
423
|
+
switch (rule.type) {
|
|
424
|
+
case "cellIs":
|
|
425
|
+
attrs.operator = rule.operator;
|
|
426
|
+
children.push(require_xml_fragment.el("formula", {}, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(rule.formula1))]));
|
|
427
|
+
if (rule.formula2 !== void 0) children.push(require_xml_fragment.el("formula", {}, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(rule.formula2))]));
|
|
428
|
+
style = rule.style;
|
|
429
|
+
break;
|
|
430
|
+
case "containsText":
|
|
431
|
+
case "notContainsText":
|
|
432
|
+
case "beginsWith":
|
|
433
|
+
case "endsWith":
|
|
434
|
+
attrs.operator = TEXT_PREDICATE_OPERATOR[rule.type];
|
|
435
|
+
attrs.text = require_xml_entities.encodeXmlText(rule.text);
|
|
436
|
+
style = rule.style;
|
|
437
|
+
break;
|
|
438
|
+
case "containsBlanks":
|
|
439
|
+
case "notContainsBlanks":
|
|
440
|
+
case "containsErrors":
|
|
441
|
+
case "notContainsErrors":
|
|
442
|
+
case "uniqueValues":
|
|
443
|
+
case "duplicateValues":
|
|
444
|
+
style = rule.style;
|
|
445
|
+
break;
|
|
446
|
+
case "top10":
|
|
447
|
+
attrs.rank = String(rule.rank);
|
|
448
|
+
if (rule.percent === true) attrs.percent = require_typed_xlsx_util.writeXmlBool(true);
|
|
449
|
+
if (rule.bottom === true) attrs.bottom = require_typed_xlsx_util.writeXmlBool(true);
|
|
450
|
+
style = rule.style;
|
|
451
|
+
break;
|
|
452
|
+
case "aboveAverage":
|
|
453
|
+
if (rule.aboveAverage === false) attrs.aboveAverage = require_typed_xlsx_util.writeXmlBool(false);
|
|
454
|
+
if (rule.equalAverage === true) attrs.equalAverage = require_typed_xlsx_util.writeXmlBool(true);
|
|
455
|
+
if (rule.stdDev !== void 0) attrs.stdDev = String(rule.stdDev);
|
|
456
|
+
style = rule.style;
|
|
457
|
+
break;
|
|
458
|
+
case "timePeriod":
|
|
459
|
+
attrs.timePeriod = rule.timePeriod;
|
|
460
|
+
style = rule.style;
|
|
461
|
+
break;
|
|
462
|
+
case "colorScale":
|
|
463
|
+
children.push(require_xml_fragment.el("colorScale", {}, [...rule.stops.map((stop) => buildCfvoElement(stop.value)), ...rule.stops.map((stop) => require_xml_fragment.el("color", { rgb: `FF${(0, document_schema_js.colorToRgbHex)(stop.color)}` }))]));
|
|
464
|
+
break;
|
|
465
|
+
case "dataBar": {
|
|
466
|
+
const dataBarChildren = [
|
|
467
|
+
buildCfvoElement(rule.min),
|
|
468
|
+
buildCfvoElement(rule.max),
|
|
469
|
+
require_xml_fragment.el("color", { rgb: `FF${(0, document_schema_js.colorToRgbHex)(rule.color)}` })
|
|
470
|
+
];
|
|
471
|
+
const dataBarAttrs = rule.showValue === false ? { showValue: require_typed_xlsx_util.writeXmlBool(false) } : {};
|
|
472
|
+
children.push(require_xml_fragment.el("dataBar", dataBarAttrs, dataBarChildren));
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
case "iconSet": {
|
|
476
|
+
const iconSetAttrs = {};
|
|
477
|
+
if (rule.iconSetType !== DEFAULT_ICON_SET_TYPE) iconSetAttrs.iconSet = rule.iconSetType;
|
|
478
|
+
if (rule.reverse === true) iconSetAttrs.reverse = require_typed_xlsx_util.writeXmlBool(true);
|
|
479
|
+
if (rule.showValue === false) iconSetAttrs.showValue = require_typed_xlsx_util.writeXmlBool(false);
|
|
480
|
+
children.push(require_xml_fragment.el("iconSet", iconSetAttrs, rule.thresholds.map(buildCfvoElement)));
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (style !== void 0) attrs.dxfId = String(dxfTable.intern(style));
|
|
485
|
+
return require_xml_fragment.el("cfRule", attrs, children);
|
|
486
|
+
}
|
|
487
|
+
function buildConditionalFormattingElements(formats, dxfTable) {
|
|
488
|
+
const groupsByKey = /* @__PURE__ */ new Map();
|
|
489
|
+
const groupOrder = [];
|
|
490
|
+
for (const format of formats) {
|
|
491
|
+
const key = rangeSetKey(format.ranges);
|
|
492
|
+
const existing = groupsByKey.get(key);
|
|
493
|
+
if (existing === void 0) {
|
|
494
|
+
const group = {
|
|
495
|
+
ranges: format.ranges,
|
|
496
|
+
rules: [format]
|
|
497
|
+
};
|
|
498
|
+
groupsByKey.set(key, group);
|
|
499
|
+
groupOrder.push(group);
|
|
500
|
+
} else existing.rules.push(format);
|
|
501
|
+
}
|
|
502
|
+
const usedPriorities = /* @__PURE__ */ new Set();
|
|
503
|
+
for (const format of formats) if (format.priority !== void 0) usedPriorities.add(format.priority);
|
|
504
|
+
let nextPriority = 1;
|
|
505
|
+
const assignPriority = (explicit) => {
|
|
506
|
+
if (explicit !== void 0) return explicit;
|
|
507
|
+
while (usedPriorities.has(nextPriority)) nextPriority++;
|
|
508
|
+
usedPriorities.add(nextPriority);
|
|
509
|
+
return nextPriority++;
|
|
510
|
+
};
|
|
511
|
+
return groupOrder.map((group) => {
|
|
512
|
+
const cfRuleElements = group.rules.map((rule) => buildCfRuleElement(rule, assignPriority(rule.priority), dxfTable));
|
|
513
|
+
return require_xml_fragment.el("conditionalFormatting", { sqref: require_typed_xlsx_sqref.formatSqref(group.ranges) }, cfRuleElements);
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
//#endregion
|
|
517
|
+
exports.DxfTable = DxfTable;
|
|
518
|
+
exports.buildConditionalFormattingElements = buildConditionalFormattingElements;
|
|
519
|
+
exports.readConditionalFormats = readConditionalFormats;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { l as XmlElement } from "../../node-B6JX5CRX.cjs";
|
|
2
|
+
import { ContentSheetConditionalFormat, ContentSheetConditionalFormatStyle } from "document-schema.js";
|
|
3
|
+
//#region src/typed/xlsx/conditional-format.d.ts
|
|
4
|
+
interface ConditionalFormatReadResult {
|
|
5
|
+
formats: ContentSheetConditionalFormat[];
|
|
6
|
+
residueElements: XmlElement[];
|
|
7
|
+
}
|
|
8
|
+
declare function readConditionalFormats(worksheet: XmlElement, dxfs: readonly XmlElement[]): ConditionalFormatReadResult;
|
|
9
|
+
declare class DxfTable {
|
|
10
|
+
private readonly elements;
|
|
11
|
+
intern(style: ContentSheetConditionalFormatStyle): number;
|
|
12
|
+
dxfElements(): readonly XmlElement[];
|
|
13
|
+
}
|
|
14
|
+
declare function buildConditionalFormattingElements(formats: readonly ContentSheetConditionalFormat[], dxfTable: DxfTable): XmlElement[];
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ConditionalFormatReadResult, DxfTable, buildConditionalFormattingElements, readConditionalFormats };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { l as XmlElement } from "../../node-B6JX5CRX.js";
|
|
2
|
+
import { ContentSheetConditionalFormat, ContentSheetConditionalFormatStyle } from "document-schema.js";
|
|
3
|
+
//#region src/typed/xlsx/conditional-format.d.ts
|
|
4
|
+
interface ConditionalFormatReadResult {
|
|
5
|
+
formats: ContentSheetConditionalFormat[];
|
|
6
|
+
residueElements: XmlElement[];
|
|
7
|
+
}
|
|
8
|
+
declare function readConditionalFormats(worksheet: XmlElement, dxfs: readonly XmlElement[]): ConditionalFormatReadResult;
|
|
9
|
+
declare class DxfTable {
|
|
10
|
+
private readonly elements;
|
|
11
|
+
intern(style: ContentSheetConditionalFormatStyle): number;
|
|
12
|
+
dxfElements(): readonly XmlElement[];
|
|
13
|
+
}
|
|
14
|
+
declare function buildConditionalFormattingElements(formats: readonly ContentSheetConditionalFormat[], dxfTable: DxfTable): XmlElement[];
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ConditionalFormatReadResult, DxfTable, buildConditionalFormattingElements, readConditionalFormats };
|